completed validation

This commit is contained in:
Lars Brünjes 2021-04-02 00:43:05 +02:00
parent 55a6783edc
commit ab53d5f3d7
No known key found for this signature in database
GPG key ID: B488B9045DC1A087

View file

@ -116,10 +116,18 @@ mkAuctionValidator ad redeemer ctx =
case redeemer of case redeemer of
MkBid b@Bid{..} -> MkBid b@Bid{..} ->
traceIfFalse "bid too low" (sufficientBid bBid) && traceIfFalse "bid too low" (sufficientBid bBid) &&
traceIfFalse "wrong output datum" (correctOutputDatum b) && traceIfFalse "wrong output datum" (correctBidOutputDatum b) &&
traceIfFalse "wrong output value" (correctOutputValue bBid) && traceIfFalse "wrong output value" (correctBidOutputValue bBid) &&
traceIfFalse "wrong refund" correctRefund traceIfFalse "wrong refund" correctBidRefund &&
Close -> True traceIfFalse "too late" correctBidSlotRange
Close ->
traceIfFalse "too early" correctCloseSlotRange &&
case adHighestBid ad of
Nothing ->
traceIfFalse "expected seller to get token" (getsValue (aSeller auction) tokenValue)
Just Bid{..} ->
traceIfFalse "expected highest bidder to get token" (getsValue bBidder tokenValue) &&
traceIfFalse "expected seller to get highest bid" (getsValue (aSeller auction) $ Ada.lovelaceValueOf bBid)
where where
info :: TxInfo info :: TxInfo
@ -166,16 +174,16 @@ mkAuctionValidator ad redeemer ctx =
Nothing -> traceError "error decoding data" Nothing -> traceError "error decoding data"
_ -> traceError "expected exactly one continuing output" _ -> traceError "expected exactly one continuing output"
correctOutputDatum :: Bid -> Bool correctBidOutputDatum :: Bid -> Bool
correctOutputDatum b = (adAuction outputDatum == auction) && correctBidOutputDatum b = (adAuction outputDatum == auction) &&
(adHighestBid outputDatum == Just b) (adHighestBid outputDatum == Just b)
correctOutputValue :: Integer -> Bool correctBidOutputValue :: Integer -> Bool
correctOutputValue amount = correctBidOutputValue amount =
txOutValue ownOutput == tokenValue Plutus.<> Ada.lovelaceValueOf amount txOutValue ownOutput == tokenValue Plutus.<> Ada.lovelaceValueOf amount
correctRefund :: Bool correctBidRefund :: Bool
correctRefund = case adHighestBid ad of correctBidRefund = case adHighestBid ad of
Nothing -> True Nothing -> True
Just Bid{..} -> Just Bid{..} ->
let let
@ -188,6 +196,22 @@ mkAuctionValidator ad redeemer ctx =
[o] -> txOutValue o == Ada.lovelaceValueOf bBid [o] -> txOutValue o == Ada.lovelaceValueOf bBid
_ -> traceError "expected exactly one refund output" _ -> traceError "expected exactly one refund output"
correctBidSlotRange :: Bool
correctBidSlotRange = to (aDeadline auction) `contains` txInfoValidRange info
correctCloseSlotRange :: Bool
correctCloseSlotRange = from (aDeadline auction) `contains` txInfoValidRange info
getsValue :: PubKeyHash -> Value -> Bool
getsValue h v =
let
[o] = [ o'
| o' <- txInfoOutputs info
, txOutValue o' == v
]
in
txOutAddress o == PubKeyAddress h
auctionInstance :: Scripts.ScriptInstance Auctioning auctionInstance :: Scripts.ScriptInstance Auctioning
auctionInstance = Scripts.validator @Auctioning auctionInstance = Scripts.validator @Auctioning
$$(PlutusTx.compile [|| mkAuctionValidator ||]) $$(PlutusTx.compile [|| mkAuctionValidator ||])