Safe Haskell | None |
---|---|
Language | Haskell2010 |
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
- contract :: Contract () GameStateMachineSchema GameError ()
- typedValidator :: GameParam -> TypedValidator GameStateMachine
- data GameParam = GameParam {
- gameParamPayeePkh :: Address
- gameParamStartTime :: POSIXTime
- data GameState
- = Initialised MintingPolicyHash TokenName HashedString
- | Locked MintingPolicyHash TokenName HashedString
- | Finished
- data GameInput
- data GuessToken
- mkValidator :: GameParam -> ValidatorType GameStateMachine
- mintingPolicy :: GameParam -> MintingPolicy
- data LockArgs = LockArgs {
- lockArgsGameParam :: GameParam
- lockArgsSecret :: SecretArgument String
- lockArgsValue :: Value
- data GuessArgs = GuessArgs {
- guessArgsGameParam :: GameParam
- guessTokenTarget :: Address
- guessArgsOldSecret :: String
- guessArgsNewSecret :: SecretArgument String
- guessArgsValueTakenOut :: Value
- type GameStateMachineSchema = Endpoint "lock" LockArgs .\/ Endpoint "guess" GuessArgs
- data GameError
- token :: MintingPolicyHash -> TokenName -> Value
- covIdx :: CoverageIndex
Documentation
contract :: Contract () GameStateMachineSchema GameError () Source #
Top-level contract, exposing both endpoints.
typedValidator :: GameParam -> TypedValidator GameStateMachine Source #
Datatype for creating a parameterized validator.
GameParam | |
|
Instances
State of the guessing game
Initialised MintingPolicyHash TokenName HashedString | Initial state. In this state only the |
Locked MintingPolicyHash TokenName HashedString | Funds have been locked. In this state only the |
Finished | All funds were unlocked. |
Instances
Inputs (actions)
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
Show GameInput Source # | |
Generic GameInput Source # | |
FromJSON GameInput Source # | |
Defined in Plutus.Contracts.GameStateMachine parseJSON :: Value -> Parser GameInput parseJSONList :: Value -> Parser [GameInput] | |
ToJSON GameInput Source # | |
Defined in Plutus.Contracts.GameStateMachine toEncoding :: GameInput -> Encoding toJSONList :: [GameInput] -> Value toEncodingList :: [GameInput] -> Encoding | |
ToData GameInput Source # | |
Defined in Plutus.Contracts.GameStateMachine toBuiltinData :: GameInput -> BuiltinData | |
FromData GameInput Source # | |
Defined in Plutus.Contracts.GameStateMachine fromBuiltinData :: BuiltinData -> Maybe GameInput | |
UnsafeFromData GameInput Source # | |
Defined in Plutus.Contracts.GameStateMachine unsafeFromBuiltinData :: BuiltinData -> GameInput | |
Lift DefaultUni GameInput Source # | |
Defined in Plutus.Contracts.GameStateMachine | |
Typeable DefaultUni GameInput Source # | |
Defined in Plutus.Contracts.GameStateMachine | |
type Rep GameInput Source # | |
Defined in Plutus.Contracts.GameStateMachine |
data GuessToken Source #
The token that represents the right to make a guess
Instances
Show GuessToken Source # | |
Defined in Plutus.Contracts.GameStateMachine | |
ToData GuessToken Source # | |
Defined in Plutus.Contracts.GameStateMachine toBuiltinData :: GuessToken -> BuiltinData | |
FromData GuessToken Source # | |
Defined in Plutus.Contracts.GameStateMachine fromBuiltinData :: BuiltinData -> Maybe GuessToken | |
Eq GuessToken Source # | |
Defined in Plutus.Contracts.GameStateMachine (==) :: GuessToken -> GuessToken -> Bool | |
UnsafeFromData GuessToken Source # | |
Defined in Plutus.Contracts.GameStateMachine unsafeFromBuiltinData :: BuiltinData -> GuessToken | |
Lift DefaultUni GuessToken Source # | |
Defined in Plutus.Contracts.GameStateMachine lift :: GuessToken -> RTCompile DefaultUni fun (Term TyName Name DefaultUni fun ()) | |
Typeable DefaultUni GuessToken Source # | |
Defined in Plutus.Contracts.GameStateMachine typeRep :: Proxy GuessToken -> RTCompile DefaultUni fun (Type TyName DefaultUni ()) |
mkValidator :: GameParam -> ValidatorType GameStateMachine Source #
mintingPolicy :: GameParam -> MintingPolicy Source #
Arguments for the "lock"
endpoint
LockArgs | |
|
Instances
Show LockArgs Source # | |
Generic LockArgs Source # | |
FromJSON LockArgs Source # | |
Defined in Plutus.Contracts.GameStateMachine parseJSON :: Value -> Parser LockArgs parseJSONList :: Value -> Parser [LockArgs] | |
ToJSON LockArgs Source # | |
Defined in Plutus.Contracts.GameStateMachine toEncoding :: LockArgs -> Encoding toJSONList :: [LockArgs] -> Value toEncodingList :: [LockArgs] -> Encoding | |
type Rep LockArgs Source # | |
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)))) |
Arguments for the "guess"
endpoint
GuessArgs | |
|
Instances
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.