apply @chfanghr's suggestions
This commit is contained in:
parent
41b524703a
commit
2c068d9b07
3 changed files with 96 additions and 107 deletions
|
|
@ -32,7 +32,9 @@ import Plutarch.Api.V2 (
|
|||
import Plutarch.Extra.AssetClass (passetClass, passetClassValueOf)
|
||||
import Plutarch.Extra.List (plookup)
|
||||
import Plutarch.Extra.ScriptContext (pisTokenSpent)
|
||||
import Plutarch.Extra.TermCont (pguardC, pletFieldsC, pmatchC)
|
||||
import Plutarch.Extra.Sum (PSum (PSum))
|
||||
import Plutarch.Extra.TermCont (pguardC, pletC, pletFieldsC, pmatchC)
|
||||
import Plutarch.Extra.Traversable (pfoldMap)
|
||||
import Plutarch.Extra.Value (psymbolValueOf)
|
||||
import PlutusLedgerApi.V1.Value (AssetClass (AssetClass))
|
||||
|
||||
|
|
@ -111,19 +113,32 @@ singleAuthorityTokenBurned gatCs inputs mint = unTermCont $ do
|
|||
let gatAmountMinted :: Term _ PInteger
|
||||
gatAmountMinted = psymbolValueOf # gatCs # mint
|
||||
|
||||
let inputsWithGAT =
|
||||
pfoldMap
|
||||
# plam
|
||||
( flip pmatch $ \case
|
||||
PTxInInfo txInInfo -> unTermCont $ do
|
||||
resolved <- pletC $ pfield @"resolved" # txInInfo
|
||||
|
||||
pguardC "While counting GATs at inputs: all GATs must be valid" $
|
||||
authorityTokensValidIn # gatCs
|
||||
#$ pfromData
|
||||
$ resolved
|
||||
|
||||
pure . pcon . PSum $
|
||||
psymbolValueOf
|
||||
# gatCs
|
||||
#$ pfield @"value"
|
||||
#$ resolved
|
||||
)
|
||||
# inputs
|
||||
pure $
|
||||
foldr1
|
||||
(#&&)
|
||||
[ ptraceIfFalse "singleAuthorityTokenBurned: Must burn exactly 1 GAT" $ gatAmountMinted #== -1
|
||||
, ptraceIfFalse "singleAuthorityTokenBurned: All GAT tokens must be valid at the inputs" $
|
||||
pall
|
||||
# plam
|
||||
( \txInInfo' -> unTermCont $ do
|
||||
PTxInInfo txInInfo <- pmatchC txInInfo'
|
||||
let txOut' = pfield @"resolved" # txInInfo
|
||||
pure $ authorityTokensValidIn # gatCs # pfromData txOut'
|
||||
)
|
||||
# inputs
|
||||
[ ptraceIfFalse "singleAuthorityTokenBurned: Must burn exactly 1 GAT" $
|
||||
gatAmountMinted #== -1
|
||||
, ptraceIfFalse "Only one GAT must exist at the inputs" $
|
||||
inputsWithGAT #== 1
|
||||
]
|
||||
|
||||
{- | Policy given 'AuthorityToken' params.
|
||||
|
|
|
|||
|
|
@ -10,13 +10,9 @@ module Agora.Effect (makeEffect) where
|
|||
import Agora.AuthorityToken (singleAuthorityTokenBurned)
|
||||
import Plutarch.Api.V1 (
|
||||
PCurrencySymbol,
|
||||
PMap (PMap),
|
||||
PValue (PValue),
|
||||
)
|
||||
import Plutarch.Api.V1.AssocMap (plookup)
|
||||
import Plutarch.Api.V2 (
|
||||
PScriptPurpose (PSpending),
|
||||
PTxInInfo (PTxInInfo),
|
||||
PTxInfo,
|
||||
PTxOutRef,
|
||||
PValidator,
|
||||
|
|
@ -70,28 +66,6 @@ makeEffect gatCs' f =
|
|||
txInfo <- pletFieldsC @'["mint", "inputs"] ctx.txInfo
|
||||
gatCs <- pletC $ pconstant gatCs'
|
||||
|
||||
-- FIXME(emiflake): This is somewhat inefficient, we could roll these two loops together.
|
||||
let inputsWithGAT =
|
||||
pfoldr
|
||||
# plam
|
||||
( \txInInfo' acc ->
|
||||
unTermCont $ do
|
||||
PTxInInfo txInInfo <- pmatchC txInInfo'
|
||||
let txOut' = pfield @"resolved" # txInInfo
|
||||
PValue value <- pmatchC $ pfield @"value" # txOut'
|
||||
pure $
|
||||
pmatch (plookup # gatCs # value) $ \case
|
||||
PNothing -> acc
|
||||
PJust tokenMap' -> unTermCont $ do
|
||||
PMap tokenMap <- pmatchC tokenMap'
|
||||
pure $ acc + plength # tokenMap
|
||||
)
|
||||
# (0 :: Term _ PInteger)
|
||||
# txInfo.inputs
|
||||
|
||||
pguardC "Only one GAT must exist at the inputs" $
|
||||
inputsWithGAT #== 1
|
||||
|
||||
pguardC "A single authority token has been burned" $
|
||||
singleAuthorityTokenBurned gatCs txInfo.inputs txInfo.mint
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue