Last active
August 13, 2021 20:06
-
-
Save EmaBord/52d832175a31dcec4e6889f0568d5aff to your computer and use it in GitHub Desktop.
Plutus Playground Smart Contract
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- This is a starter contract, based on the Game contract, | |
-- containing the bare minimum required scaffolding. | |
-- | |
-- What you should change to something more suitable for | |
-- your use case: | |
-- * The MyDatum type | |
-- * The MyMyRedeemerValue type | |
-- | |
-- And add function implementations (and rename them to | |
-- something suitable) for the endpoints: | |
-- * publish | |
-- * redeem | |
import Control.Monad (void) | |
import qualified Data.ByteString.Char8 as C | |
import Language.Plutus.Contract | |
import qualified Language.PlutusTx as PlutusTx | |
import Language.PlutusTx.Prelude hiding (Applicative (..)) | |
import Ledger (Address, ValidatorCtx, scriptAddress, PubKeyHash) | |
import qualified Ledger.Constraints as Constraints | |
import qualified Ledger.Typed.Scripts as Scripts | |
import Ledger.Value (Value) | |
import qualified Prelude | |
import Playground.Contract | |
data ProductData = | |
ProductData | |
{ | |
pid :: Integer | |
, owner :: PubKeyHash | |
, toDelegate :: PubKeyHash | |
, status :: Integer | |
, name :: String | |
} | |
deriving Show | |
PlutusTx.makeIsData ''ProductData | |
PlutusTx.makeLift ''ProductData | |
newtype ClearString = ClearString ByteString deriving newtype PlutusTx.IsData | |
PlutusTx.makeLift ''ClearString | |
type Schema = | |
BlockchainActions | |
.\/ Endpoint "new" (String) | |
.\/ Endpoint "delegate" (PubKeyHash, Integer) | |
newtype GuessParams = GuessParams | |
{ nameProduct :: String | |
} | |
deriving stock (Prelude.Eq, Prelude.Show, Generic) | |
deriving anyclass (FromJSON, ToJSON, IotsType, ToSchema, ToArgument) | |
clearString :: String -> ClearString | |
clearString = ClearString . C.pack | |
contract :: AsContractError e => Contract Schema e () | |
contract = new | |
-- | The "new" contract endpoint. | |
new :: AsContractError e => Contract Schema e () | |
new = do | |
(nameProduct) <- endpoint @"new" | |
let productInstance = ProductData{ | |
name = nameProduct, | |
status=0 | |
} | |
let tx = Constraints. (ProductData productInstance) | |
void $ submitTxConstraints productInstance tx | |
-- | The "delegate" contract endpoint. | |
--delegate :: AsContractError e => Contract Schema e () | |
--delegate s@ProductData{toDelegate, pid} = do | |
-- void $ submitTxConstraints splitInstance tx | |
endpoints :: AsContractError e => Contract Schema e () | |
endpoints = contract | |
mkSchemaDefinitions ''Schema | |
$(mkKnownCurrencies []) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[0,[]] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment