add missing docs && consistent naming
This commit is contained in:
parent
ad33b0cbbc
commit
1ba11bc23a
2 changed files with 19 additions and 12 deletions
|
|
@ -138,16 +138,17 @@ instance PTryFrom PData (PAsData PMutateGovernorDatum) where
|
||||||
-}
|
-}
|
||||||
mutateGovernorValidator :: Governor -> ClosedTerm PValidator
|
mutateGovernorValidator :: Governor -> ClosedTerm PValidator
|
||||||
mutateGovernorValidator gov = makeEffect (authorityTokenSymbolFromGovernor gov) $
|
mutateGovernorValidator gov = makeEffect (authorityTokenSymbolFromGovernor gov) $
|
||||||
\_gatCs (datum' :: Term _ PMutateGovernorDatum) _ txInfo' -> unTermCont $ do
|
\_gatCs (datum :: Term _ PMutateGovernorDatum) _ txInfo -> unTermCont $ do
|
||||||
datum <- tcont $ pletFields @'["newDatum", "governorRef"] datum'
|
datumF <- tcont $ pletFields @'["newDatum", "governorRef"] datum
|
||||||
txInfo <- tcont $ pletFields @'["mint", "inputs", "outputs", "datums"] txInfo'
|
txInfoF <- tcont $ pletFields @'["mint", "inputs", "outputs", "datums"] txInfo
|
||||||
|
|
||||||
let mint :: Term _ (PBuiltinList _)
|
let mint :: Term _ (PBuiltinList _)
|
||||||
mint = pto $ pto $ pto $ pfromData txInfo.mint
|
mint = pto $ pto $ pto $ pfromData txInfoF.mint
|
||||||
|
|
||||||
tcassert "Nothing should be minted/burnt other than GAT" $
|
tcassert "Nothing should be minted/burnt other than GAT" $
|
||||||
plength # mint #== 1
|
plength # mint #== 1
|
||||||
|
|
||||||
|
-- Only two script inputs are alloed: one from the effect, one from the governor.
|
||||||
tcassert "Only self and governor script inputs are allowed" $
|
tcassert "Only self and governor script inputs are allowed" $
|
||||||
pfoldr
|
pfoldr
|
||||||
# phoistAcyclic
|
# phoistAcyclic
|
||||||
|
|
@ -159,9 +160,10 @@ mutateGovernorValidator gov = makeEffect (authorityTokenSymbolFromGovernor gov)
|
||||||
count
|
count
|
||||||
)
|
)
|
||||||
# (0 :: Term _ PInteger)
|
# (0 :: Term _ PInteger)
|
||||||
# pfromData txInfo.inputs
|
# pfromData txInfoF.inputs
|
||||||
#== 2
|
#== 2
|
||||||
|
|
||||||
|
-- Find the governor input by looking for GST.
|
||||||
let inputWithGST =
|
let inputWithGST =
|
||||||
mustBePJust # "Governor input not found" #$ pfind
|
mustBePJust # "Governor input not found" #$ pfind
|
||||||
# phoistAcyclic
|
# phoistAcyclic
|
||||||
|
|
@ -169,18 +171,20 @@ mutateGovernorValidator gov = makeEffect (authorityTokenSymbolFromGovernor gov)
|
||||||
let value = pfield @"value" #$ pfield @"resolved" # inInfo
|
let value = pfield @"value" #$ pfield @"resolved" # inInfo
|
||||||
in gstValueOf # value #== 1
|
in gstValueOf # value #== 1
|
||||||
)
|
)
|
||||||
# pfromData txInfo.inputs
|
# pfromData txInfoF.inputs
|
||||||
|
|
||||||
govInInfo <- tcont $ pletFields @'["outRef", "resolved"] $ inputWithGST
|
govInInfo <- tcont $ pletFields @'["outRef", "resolved"] $ inputWithGST
|
||||||
|
|
||||||
|
-- The effect can only modify the governor UTXO referenced in the datum.
|
||||||
tcassert "Can only modify the pinned governor" $
|
tcassert "Can only modify the pinned governor" $
|
||||||
govInInfo.outRef #== datum.governorRef
|
govInInfo.outRef #== datumF.governorRef
|
||||||
|
|
||||||
tcassert "Only governor ouput is allowed" $
|
-- The transaction can only have one output, which should be sent to the governor.
|
||||||
plength # pfromData txInfo.outputs #== 1
|
tcassert "Only governor output is allowed" $
|
||||||
|
plength # pfromData txInfoF.outputs #== 1
|
||||||
|
|
||||||
let govAddress = pfield @"address" #$ govInInfo.resolved
|
let govAddress = pfield @"address" #$ govInInfo.resolved
|
||||||
govOutput' = pfromData $ phead # pfromData txInfo.outputs
|
govOutput' = pfromData $ phead # pfromData txInfoF.outputs
|
||||||
|
|
||||||
govOutput <- tcont $ pletFields @'["address", "value", "datumHash"] govOutput'
|
govOutput <- tcont $ pletFields @'["address", "value", "datumHash"] govOutput'
|
||||||
|
|
||||||
|
|
@ -195,13 +199,15 @@ mutateGovernorValidator gov = makeEffect (authorityTokenSymbolFromGovernor gov)
|
||||||
governorOutputDatum =
|
governorOutputDatum =
|
||||||
pfromData @PGovernorDatum $
|
pfromData @PGovernorDatum $
|
||||||
mustBePJust # "Governor output datum not found"
|
mustBePJust # "Governor output datum not found"
|
||||||
#$ ptryFindDatum # governorOutputDatumHash # txInfo.datums
|
#$ ptryFindDatum # governorOutputDatumHash # txInfoF.datums
|
||||||
|
|
||||||
tcassert "Unexpected governor datum" $ datum.newDatum #== governorOutputDatum
|
-- Ensure the output governor datum is what we want.
|
||||||
|
tcassert "Unexpected governor datum" $ datumF.newDatum #== governorOutputDatum
|
||||||
tcassert "New governor datum should be valid" $ governorDatumValid # governorOutputDatum
|
tcassert "New governor datum should be valid" $ governorDatumValid # governorOutputDatum
|
||||||
|
|
||||||
return $ popaque $ pconstant ()
|
return $ popaque $ pconstant ()
|
||||||
where
|
where
|
||||||
|
-- Get the amount of GST in the a given value.
|
||||||
gstValueOf :: Term s (PValue :--> PInteger)
|
gstValueOf :: Term s (PValue :--> PInteger)
|
||||||
gstValueOf = phoistAcyclic $ plam $ \v -> pvalueOf # v # pconstant cs # pconstant tn
|
gstValueOf = phoistAcyclic $ plam $ \v -> pvalueOf # v # pconstant cs # pconstant tn
|
||||||
where
|
where
|
||||||
|
|
|
||||||
|
|
@ -620,6 +620,7 @@ scriptHashFromAddress = phoistAcyclic $
|
||||||
PScriptCredential ((pfield @"_0" #) -> h) -> pcon $ PJust h
|
PScriptCredential ((pfield @"_0" #) -> h) -> pcon $ PJust h
|
||||||
_ -> pcon PNothing
|
_ -> pcon PNothing
|
||||||
|
|
||||||
|
-- | Return true if the given address is a script address.
|
||||||
isScriptAddress :: Term s (PAddress :--> PBool)
|
isScriptAddress :: Term s (PAddress :--> PBool)
|
||||||
isScriptAddress = phoistAcyclic $
|
isScriptAddress = phoistAcyclic $
|
||||||
plam $ \addr ->
|
plam $ \addr ->
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue