diff --git a/code/week07/src/Week07/EvenOdd.hs b/code/week07/src/Week07/EvenOdd.hs index d4fda92..c8ae175 100644 --- a/code/week07/src/Week07/EvenOdd.hs +++ b/code/week07/src/Week07/EvenOdd.hs @@ -101,17 +101,20 @@ mkGameValidator game bsZero' bsOne' dat red ctx = traceIfFalse "not signed by first player" (txSignedBy info (gFirst game)) && traceIfFalse "commit mismatch" (checkNonce bs nonce c) && traceIfFalse "missed deadline" (to (gRevealDeadline game) `contains` txInfoValidRange info) && - traceIfFalse "wrong stake" (lovelaces (txOutValue ownInput) == (2 * gStake game)) + traceIfFalse "wrong stake" (lovelaces (txOutValue ownInput) == (2 * gStake game)) && + traceIfFalse "NFT must go to first player" nftToFirst (GameDatum _ Nothing, ClaimFirst) -> traceIfFalse "not signed by first player" (txSignedBy info (gFirst game)) && traceIfFalse "too early" (from (1 + gPlayDeadline game) `contains` txInfoValidRange info) && - traceIfFalse "first player's stake missing" (lovelaces (txOutValue ownInput) == gStake game) + traceIfFalse "first player's stake missing" (lovelaces (txOutValue ownInput) == gStake game) && + traceIfFalse "NFT must go to first player" nftToFirst (GameDatum _ (Just _), ClaimSecond) -> traceIfFalse "not signed by second player" (txSignedBy info (gSecond game)) && - traceIfFalse "to early" (from (1 + gRevealDeadline game) `contains` txInfoValidRange info) && - traceIfFalse "wrong stake" (lovelaces (txOutValue ownInput) == (2 * gStake game)) + traceIfFalse "too early" (from (1 + gRevealDeadline game) `contains` txInfoValidRange info) && + traceIfFalse "wrong stake" (lovelaces (txOutValue ownInput) == (2 * gStake game)) && + traceIfFalse "NFT must go to first player" nftToFirst _ -> False where @@ -141,6 +144,9 @@ mkGameValidator game bsZero' bsOne' dat red ctx = Zero -> bsZero' One -> bsOne' + nftToFirst :: Bool + nftToFirst = assetClassValueOf (valuePaidTo info $ gFirst game) (gToken game) == 1 + data Gaming instance Scripts.ScriptType Gaming where type instance DatumType Gaming = GameDatum diff --git a/code/week07/src/Week07/StateMachine.hs b/code/week07/src/Week07/StateMachine.hs index f878911..03154c5 100644 --- a/code/week07/src/Week07/StateMachine.hs +++ b/code/week07/src/Week07/StateMachine.hs @@ -199,7 +199,7 @@ firstGame fp = do v = lovelaceValueOf (fpStake fp) c = fpChoice fp bs = sha2_256 $ fpNonce fp `concatenate` if c == Zero then bsZero else bsOne - void $ mapError @w @s @SMContractError (pack . show) $ runInitialise client (GameDatum bs Nothing) v + void $ mapError' $ runInitialise client (GameDatum bs Nothing) v logInfo @String $ "made first move: " ++ show (fpChoice fp) void $ awaitSlot $ 1 + fpPlayDeadline fp