From e386cc5e755a889cc1979c86d3fcbc550e375a27 Mon Sep 17 00:00:00 2001 From: Seungheon Oh Date: Fri, 17 Jun 2022 14:29:00 -0500 Subject: [PATCH] Remove `either error id` pattern in Samples --- agora-specs/Property/MultiSig.hs | 5 +++-- agora-specs/Sample/Governor.hs | 12 ++++++------ agora-specs/Sample/Proposal.hs | 12 ++++++------ agora-specs/Sample/Stake.hs | 8 ++++---- agora-specs/Sample/Treasury.hs | 6 +++--- flake.lock | 18 +++++++++--------- 6 files changed, 31 insertions(+), 30 deletions(-) diff --git a/agora-specs/Property/MultiSig.hs b/agora-specs/Property/MultiSig.hs index caa35cc..3d0d98c 100644 --- a/agora-specs/Property/MultiSig.hs +++ b/agora-specs/Property/MultiSig.hs @@ -67,8 +67,9 @@ genMultiSigProp prop = do MeetsMinSigs -> chooseInt (minSig, length pkhs) DoesNotMeetMinSigs -> chooseInt (0, minSig - 1) - let builder = mconcat $ signedWith <$> take n pkhs <> othersigners - txinfo = either error id $ buildTxInfo builder + let builder :: BaseBuilder + builder = mconcat $ signedWith <$> take n pkhs <> othersigners + txinfo = buildTxInfoUnsafe builder pure (ms, ScriptContext txinfo (Spending (TxOutRef "" 0))) -- | Classify model into propositions. diff --git a/agora-specs/Sample/Governor.hs b/agora-specs/Sample/Governor.hs index cd6d688..1641640 100644 --- a/agora-specs/Sample/Governor.hs +++ b/agora-specs/Sample/Governor.hs @@ -34,8 +34,8 @@ import Plutarch.Api.V1 (mkValidator, validatorHash) import Plutarch.Context ( MintingBuilder, SpendingBuilder, - buildMinting, - buildSpending, + buildMintingUnsafe, + buildSpendingUnsafe, fee, input, mint, @@ -139,7 +139,7 @@ mintGST = . withValue (gst <> minAda) . withDatum governorOutputDatum ] - in either error id $ buildMinting builder + in buildMintingUnsafe builder {- | A valid script context to create a proposal. @@ -259,7 +259,7 @@ createProposal = . withValue gst . withDatum governorInputDatum ] - in either error id $ buildSpending builder + in buildSpendingUnsafe builder {- This script context should be a valid transaction for minting authority for the effect scrips. @@ -378,7 +378,7 @@ mintGATs = . withValue gst . withDatum governorInputDatum ] - in either error id $ buildSpending builder + in buildSpendingUnsafe builder {- | A valid script context for changing the state datum of the governor. @@ -458,4 +458,4 @@ mutateState = . withValue gst . withDatum governorInputDatum ] - in either error id $ buildSpending builder + in buildSpendingUnsafe builder diff --git a/agora-specs/Sample/Proposal.hs b/agora-specs/Sample/Proposal.hs index 7955228..0ec892d 100644 --- a/agora-specs/Sample/Proposal.hs +++ b/agora-specs/Sample/Proposal.hs @@ -46,8 +46,8 @@ import Data.Tagged (Tagged (..), untag) import Plutarch.Context ( BaseBuilder, MintingBuilder, - buildMinting, - buildTxInfo, + buildMintingUnsafe, + buildTxInfoUnsafe, input, mint, output, @@ -162,7 +162,7 @@ proposalCreation = ) . withDatum govAfter ] - in either error id $ buildMinting builder + in buildMintingUnsafe builder proposalRef :: TxOutRef proposalRef = TxOutRef "0b2086cbf8b6900f8cb65e012de4516cb66b5cb08a9aaba12a8b88be" 1 @@ -236,7 +236,7 @@ cosignProposal newSigners = ) . withDatum stakeDatum ] - in either error id $ buildTxInfo builder + in buildTxInfoUnsafe builder -------------------------------------------------------------------------------- @@ -377,7 +377,7 @@ voteOnProposal params = ) . withDatum stakeOutputDatum ] - in either error id $ buildTxInfo builder + in buildTxInfoUnsafe builder -------------------------------------------------------------------------------- @@ -442,7 +442,7 @@ mkTransitionTxInfo from to effects votes startingTime validTime = . withValue (pst <> minAda) . withDatum proposalOutputDatum ] - in either error id $ buildTxInfo builder + in buildTxInfoUnsafe builder {- | Create a valid 'TxInfo' that advances a proposal, given the parameters. Note that 'TransitionParameters.initialProposalStatus' should not be 'Finished'. diff --git a/agora-specs/Sample/Stake.hs b/agora-specs/Sample/Stake.hs index 51611e6..88e5dc7 100644 --- a/agora-specs/Sample/Stake.hs +++ b/agora-specs/Sample/Stake.hs @@ -31,8 +31,8 @@ import Plutarch.Api.V1 (mkValidator, validatorHash) import Plutarch.Context ( MintingBuilder, SpendingBuilder, - buildMinting, - buildSpending, + buildMintingUnsafe, + buildSpendingUnsafe, input, mint, output, @@ -87,7 +87,7 @@ stakeCreation = . withValue (st <> Value.singleton "da8c30857834c6ae7203935b89278c532b3995245295456f993e1d24" "LQ" 424242424242) . withDatum datum ] - in either error id $ buildMinting builder + in buildMintingUnsafe builder -- | This ScriptContext should fail because the datum has too much GT. stakeCreationWrongDatum :: ScriptContext @@ -150,4 +150,4 @@ stakeDepositWithdraw config = . withValue (st <> Value.assetClassValue (untag stake.gtClassRef) (untag stakeBefore.stakedAmount)) . withDatum stakeAfter ] - in either error id $ buildSpending builder + in buildSpendingUnsafe builder diff --git a/agora-specs/Sample/Treasury.hs b/agora-specs/Sample/Treasury.hs index 39d0303..632f559 100644 --- a/agora-specs/Sample/Treasury.hs +++ b/agora-specs/Sample/Treasury.hs @@ -20,7 +20,7 @@ module Sample.Treasury ( import Plutarch.Context ( MintingBuilder, UTXO, - buildMinting, + buildMintingUnsafe, credential, input, mint, @@ -83,7 +83,7 @@ validCtx = . withValue (Value.singleton gatCs gatTn 1 <> minAda) . withTxId "52b67b60260da3937510ad545c7f46f8d9915bd27e1082e76947fb309f913bd3" ] - in either error id $ buildMinting builder + in buildMintingUnsafe builder treasuryRef :: TxOutRef treasuryRef = @@ -124,4 +124,4 @@ trCtxGATNameNotAddress = . withValue (Value.singleton gatCs gatTn 1 <> minAda) . withTxId "52b67b60260da3937510ad545c7f46f8d9915bd27e1082e76947fb309f913bd3" ] - in either error id $ buildMinting builder + in buildMintingUnsafe builder diff --git a/flake.lock b/flake.lock index d33722c..0d12bf7 100644 --- a/flake.lock +++ b/flake.lock @@ -6339,11 +6339,11 @@ "plutarch-quickcheck": "plutarch-quickcheck" }, "locked": { - "lastModified": 1655470312, - "narHash": "sha256-O4Dy803SFOS+S1OFEecfCRkjWc8y0iHbO+EVKtBqsGk=", + "lastModified": 1655492974, + "narHash": "sha256-FNshUKtfs8tbxAUlqhP3AgmkjKMiKyw+kEBULmg6bVM=", "owner": "Liqwid-Labs", "repo": "liqwid-plutarch-extra", - "rev": "fd9b2e6e713c36efef30bcef8d97a069fda7d71a", + "rev": "4a9cdc642b85e16e487b789012bb8417c3e197d8", "type": "github" }, "original": { @@ -7459,11 +7459,11 @@ }, "nixpkgs-2111_5": { "locked": { - "lastModified": 1655355951, - "narHash": "sha256-uroxR5FTZWEqpakNtwiZBABj6SpX+TOuUZ4G0PtSy94=", + "lastModified": 1655415671, + "narHash": "sha256-WD7HxxW1m8D/fkV1QlCYlZvnE5gQdg7ckq3myI4gPtE=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "b882c61856522467f866f3d6321e1aa5b0b393b5", + "rev": "f96729212602f15a6a226d2f27f5de70492ad095", "type": "github" }, "original": { @@ -9286,11 +9286,11 @@ "plutarch": "plutarch_4" }, "locked": { - "lastModified": 1654627196, - "narHash": "sha256-OohlZsi0/j55Sq6U/hA7gl6SQyTHIGT9Pg+R61veCJw=", + "lastModified": 1655492019, + "narHash": "sha256-ZwU9wjSaC1BCukLqx3swqD30mwppVr7Fg2Y8jEkQ2c8=", "owner": "Liqwid-Labs", "repo": "plutarch-context-builder", - "rev": "b6c6e50c60c87f2b63d8027ff66728fabbb569fe", + "rev": "fa0e90bf0cdb258c5be500d066d5698fb360cfc3", "type": "github" }, "original": {