plutus-use-cases-1.2.0.0: Collection of smart contracts to develop the plutus/wallet interface
Safe HaskellNone
LanguageHaskell2010

Plutus.Contracts.GameStateMachine

Description

A guessing game that

  • Uses a state machine to keep track of the current secret word
  • Uses a token to keep track of who is allowed to make a guess
Synopsis

Documentation

contract :: Contract () GameStateMachineSchema GameError () Source #

Top-level contract, exposing both endpoints.

typedValidator :: GameParam -> TypedValidator GameStateMachine Source #

data GameParam Source #

Datatype for creating a parameterized validator.

Constructors

GameParam 

Fields

Instances

Instances details
Show GameParam Source # 
Instance details

Defined in Plutus.Contracts.GameStateMachine

Generic GameParam Source # 
Instance details

Defined in Plutus.Contracts.GameStateMachine

Associated Types

type Rep GameParam :: Type -> Type Source #

FromJSON GameParam Source # 
Instance details

Defined in Plutus.Contracts.GameStateMachine

Methods

parseJSON :: Value -> Parser GameParam

parseJSONList :: Value -> Parser [GameParam]

ToJSON GameParam Source # 
Instance details

Defined in Plutus.Contracts.GameStateMachine

Methods

toJSON :: GameParam -> Value

toEncoding :: GameParam -> Encoding

toJSONList :: [GameParam] -> Value

toEncodingList :: [GameParam] -> Encoding

Lift DefaultUni GameParam Source # 
Instance details

Defined in Plutus.Contracts.GameStateMachine

Methods

lift :: GameParam -> RTCompile DefaultUni fun (Term TyName Name DefaultUni fun ())

Typeable DefaultUni GameParam Source # 
Instance details

Defined in Plutus.Contracts.GameStateMachine

Methods

typeRep :: Proxy GameParam -> RTCompile DefaultUni fun (Type TyName DefaultUni ())

type Rep GameParam Source # 
Instance details

Defined in Plutus.Contracts.GameStateMachine

type Rep GameParam = D1 ('MetaData "GameParam" "Plutus.Contracts.GameStateMachine" "plutus-use-cases-1.2.0.0-BuYOLXrynPcLosE012cowc" 'False) (C1 ('MetaCons "GameParam" 'PrefixI 'True) (S1 ('MetaSel ('Just "gameParamPayeePkh") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Address) :*: S1 ('MetaSel ('Just "gameParamStartTime") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 POSIXTime)))

data GameState Source #

State of the guessing game

Constructors

Initialised MintingPolicyHash TokenName HashedString

Initial state. In this state only the MintTokens action is allowed.

Locked MintingPolicyHash TokenName HashedString

Funds have been locked. In this state only the Guess action is allowed.

Finished

All funds were unlocked.

Instances

Instances details
Show GameState Source # 
Instance details

Defined in Plutus.Contracts.GameStateMachine

Generic GameState Source # 
Instance details

Defined in Plutus.Contracts.GameStateMachine

Associated Types

type Rep GameState :: Type -> Type Source #

FromJSON GameState Source # 
Instance details

Defined in Plutus.Contracts.GameStateMachine

Methods

parseJSON :: Value -> Parser GameState

parseJSONList :: Value -> Parser [GameState]

ToJSON GameState Source # 
Instance details

Defined in Plutus.Contracts.GameStateMachine

Methods

toJSON :: GameState -> Value

toEncoding :: GameState -> Encoding

toJSONList :: [GameState] -> Value

toEncodingList :: [GameState] -> Encoding

ToData GameState Source # 
Instance details

Defined in Plutus.Contracts.GameStateMachine

Methods

toBuiltinData :: GameState -> BuiltinData

FromData GameState Source # 
Instance details

Defined in Plutus.Contracts.GameStateMachine

Methods

fromBuiltinData :: BuiltinData -> Maybe GameState

Eq GameState Source # 
Instance details

Defined in Plutus.Contracts.GameStateMachine

Methods

(==) :: GameState -> GameState -> Bool

UnsafeFromData GameState Source # 
Instance details

Defined in Plutus.Contracts.GameStateMachine

Methods

unsafeFromBuiltinData :: BuiltinData -> GameState

Lift DefaultUni GameState Source # 
Instance details

Defined in Plutus.Contracts.GameStateMachine

Methods

lift :: GameState -> RTCompile DefaultUni fun (Term TyName Name DefaultUni fun ())

Typeable DefaultUni GameState Source # 
Instance details

Defined in Plutus.Contracts.GameStateMachine

Methods

typeRep :: Proxy GameState -> RTCompile DefaultUni fun (Type TyName DefaultUni ())

type Rep GameState Source # 
Instance details

Defined in Plutus.Contracts.GameStateMachine

data GameInput Source #

Inputs (actions)

Constructors

MintToken

Mint the "guess" token

Guess Address ClearString HashedString Value

Make a guess, extract the funds, and lock the remaining funds using a new secret word.

Instances

Instances details
Show GameInput Source # 
Instance details

Defined in Plutus.Contracts.GameStateMachine

Generic GameInput Source # 
Instance details

Defined in Plutus.Contracts.GameStateMachine

Associated Types

type Rep GameInput :: Type -> Type Source #

FromJSON GameInput Source # 
Instance details

Defined in Plutus.Contracts.GameStateMachine

Methods

parseJSON :: Value -> Parser GameInput

parseJSONList :: Value -> Parser [GameInput]

ToJSON GameInput Source # 
Instance details

Defined in Plutus.Contracts.GameStateMachine

Methods

toJSON :: GameInput -> Value

toEncoding :: GameInput -> Encoding

toJSONList :: [GameInput] -> Value

toEncodingList :: [GameInput] -> Encoding

ToData GameInput Source # 
Instance details

Defined in Plutus.Contracts.GameStateMachine

Methods

toBuiltinData :: GameInput -> BuiltinData

FromData GameInput Source # 
Instance details

Defined in Plutus.Contracts.GameStateMachine

Methods

fromBuiltinData :: BuiltinData -> Maybe GameInput

UnsafeFromData GameInput Source # 
Instance details

Defined in Plutus.Contracts.GameStateMachine

Methods

unsafeFromBuiltinData :: BuiltinData -> GameInput

Lift DefaultUni GameInput Source # 
Instance details

Defined in Plutus.Contracts.GameStateMachine

Methods

lift :: GameInput -> RTCompile DefaultUni fun (Term TyName Name DefaultUni fun ())

Typeable DefaultUni GameInput Source # 
Instance details

Defined in Plutus.Contracts.GameStateMachine

Methods

typeRep :: Proxy GameInput -> RTCompile DefaultUni fun (Type TyName DefaultUni ())

type Rep GameInput Source # 
Instance details

Defined in Plutus.Contracts.GameStateMachine

data GuessToken Source #

The token that represents the right to make a guess

Instances

Instances details
Show GuessToken Source # 
Instance details

Defined in Plutus.Contracts.GameStateMachine

ToData GuessToken Source # 
Instance details

Defined in Plutus.Contracts.GameStateMachine

Methods

toBuiltinData :: GuessToken -> BuiltinData

FromData GuessToken Source # 
Instance details

Defined in Plutus.Contracts.GameStateMachine

Methods

fromBuiltinData :: BuiltinData -> Maybe GuessToken

Eq GuessToken Source # 
Instance details

Defined in Plutus.Contracts.GameStateMachine

Methods

(==) :: GuessToken -> GuessToken -> Bool

UnsafeFromData GuessToken Source # 
Instance details

Defined in Plutus.Contracts.GameStateMachine

Methods

unsafeFromBuiltinData :: BuiltinData -> GuessToken

Lift DefaultUni GuessToken Source # 
Instance details

Defined in Plutus.Contracts.GameStateMachine

Methods

lift :: GuessToken -> RTCompile DefaultUni fun (Term TyName Name DefaultUni fun ())

Typeable DefaultUni GuessToken Source # 
Instance details

Defined in Plutus.Contracts.GameStateMachine

Methods

typeRep :: Proxy GuessToken -> RTCompile DefaultUni fun (Type TyName DefaultUni ())

mkValidator :: GameParam -> ValidatorType GameStateMachine Source #

mintingPolicy :: GameParam -> MintingPolicy Source #

data LockArgs Source #

Arguments for the "lock" endpoint

Constructors

LockArgs 

Fields

Instances

Instances details
Show LockArgs Source # 
Instance details

Defined in Plutus.Contracts.GameStateMachine

Generic LockArgs Source # 
Instance details

Defined in Plutus.Contracts.GameStateMachine

Associated Types

type Rep LockArgs :: Type -> Type Source #

FromJSON LockArgs Source # 
Instance details

Defined in Plutus.Contracts.GameStateMachine

Methods

parseJSON :: Value -> Parser LockArgs

parseJSONList :: Value -> Parser [LockArgs]

ToJSON LockArgs Source # 
Instance details

Defined in Plutus.Contracts.GameStateMachine

Methods

toJSON :: LockArgs -> Value

toEncoding :: LockArgs -> Encoding

toJSONList :: [LockArgs] -> Value

toEncodingList :: [LockArgs] -> Encoding

type Rep LockArgs Source # 
Instance details

Defined in Plutus.Contracts.GameStateMachine

type Rep LockArgs = D1 ('MetaData "LockArgs" "Plutus.Contracts.GameStateMachine" "plutus-use-cases-1.2.0.0-BuYOLXrynPcLosE012cowc" 'False) (C1 ('MetaCons "LockArgs" 'PrefixI 'True) (S1 ('MetaSel ('Just "lockArgsGameParam") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 GameParam) :*: (S1 ('MetaSel ('Just "lockArgsSecret") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (SecretArgument String)) :*: S1 ('MetaSel ('Just "lockArgsValue") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Value))))

data GuessArgs Source #

Arguments for the "guess" endpoint

Constructors

GuessArgs 

Fields

Instances

Instances details
Show GuessArgs Source # 
Instance details

Defined in Plutus.Contracts.GameStateMachine

Generic GuessArgs Source # 
Instance details

Defined in Plutus.Contracts.GameStateMachine

Associated Types

type Rep GuessArgs :: Type -> Type Source #

FromJSON GuessArgs Source # 
Instance details

Defined in Plutus.Contracts.GameStateMachine

Methods

parseJSON :: Value -> Parser GuessArgs

parseJSONList :: Value -> Parser [GuessArgs]

ToJSON GuessArgs Source # 
Instance details

Defined in Plutus.Contracts.GameStateMachine

Methods

toJSON :: GuessArgs -> Value

toEncoding :: GuessArgs -> Encoding

toJSONList :: [GuessArgs] -> Value

toEncodingList :: [GuessArgs] -> Encoding

type Rep GuessArgs Source # 
Instance details

Defined in Plutus.Contracts.GameStateMachine

type Rep GuessArgs = D1 ('MetaData "GuessArgs" "Plutus.Contracts.GameStateMachine" "plutus-use-cases-1.2.0.0-BuYOLXrynPcLosE012cowc" 'False) (C1 ('MetaCons "GuessArgs" 'PrefixI 'True) ((S1 ('MetaSel ('Just "guessArgsGameParam") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 GameParam) :*: S1 ('MetaSel ('Just "guessTokenTarget") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Address)) :*: (S1 ('MetaSel ('Just "guessArgsOldSecret") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 String) :*: (S1 ('MetaSel ('Just "guessArgsNewSecret") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (SecretArgument String)) :*: S1 ('MetaSel ('Just "guessArgsValueTakenOut") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Value)))))

type GameStateMachineSchema = Endpoint "lock" LockArgs .\/ Endpoint "guess" GuessArgs Source #

The schema of the contract. It consists of the two endpoints "lock" and "guess" with their respective argument types.

data GameError Source #

Instances

Instances details
Show GameError Source # 
Instance details

Defined in Plutus.Contracts.GameStateMachine

Generic GameError Source # 
Instance details

Defined in Plutus.Contracts.GameStateMachine

Associated Types

type Rep GameError :: Type -> Type Source #

FromJSON GameError Source # 
Instance details

Defined in Plutus.Contracts.GameStateMachine

Methods

parseJSON :: Value -> Parser GameError

parseJSONList :: Value -> Parser [GameError]

ToJSON GameError Source # 
Instance details

Defined in Plutus.Contracts.GameStateMachine

Methods

toJSON :: GameError -> Value

toEncoding :: GameError -> Encoding

toJSONList :: [GameError] -> Value

toEncodingList :: [GameError] -> Encoding

AsContractError GameError Source # 
Instance details

Defined in Plutus.Contracts.GameStateMachine

Methods

_ContractError :: Prism' GameError ContractError

_WalletContractError :: Prism' GameError WalletAPIError

_ChainIndexContractError :: Prism' GameError (Text, ChainIndexResponse)

_ConstraintResolutionContractError :: Prism' GameError MkTxError

_ToCardanoConvertContractError :: Prism' GameError ToCardanoError

_ResumableContractError :: Prism' GameError MatchingError

_CCheckpointContractError :: Prism' GameError CheckpointError

_EndpointDecodeContractError :: Prism' GameError (EndpointDescription, EndpointValue Value, Text)

_OtherContractError :: Prism' GameError Text

AsSMContractError GameError Source # 
Instance details

Defined in Plutus.Contracts.GameStateMachine

Methods

_SMContractError :: Prism' GameError SMContractError

_ChooserError :: Prism' GameError Text

_UnableToExtractTransition :: Prism' GameError ()

_SMCContractError :: Prism' GameError ContractError

type Rep GameError Source # 
Instance details

Defined in Plutus.Contracts.GameStateMachine

type Rep GameError = D1 ('MetaData "GameError" "Plutus.Contracts.GameStateMachine" "plutus-use-cases-1.2.0.0-BuYOLXrynPcLosE012cowc" 'False) (C1 ('MetaCons "GameContractError" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 ContractError)) :+: C1 ('MetaCons "GameSMError" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 SMContractError)))

token :: MintingPolicyHash -> TokenName -> Value Source #

covIdx :: CoverageIndex Source #