only allow desired inputs/outputs in an effect tx
This commit is contained in:
parent
c556b3eda5
commit
a65465b494
1 changed files with 23 additions and 38 deletions
|
|
@ -62,8 +62,6 @@ import Agora.Governor.Scripts (
|
||||||
governorSTAssetClassFromGovernor,
|
governorSTAssetClassFromGovernor,
|
||||||
)
|
)
|
||||||
import Agora.Utils (
|
import Agora.Utils (
|
||||||
findOutputsToAddress,
|
|
||||||
findTxOutByTxOutRef,
|
|
||||||
mustBePDJust,
|
mustBePDJust,
|
||||||
mustBePJust,
|
mustBePJust,
|
||||||
passert,
|
passert,
|
||||||
|
|
@ -140,62 +138,49 @@ 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) txOutRef txInfo' -> P.do
|
\_gatCs (datum' :: Term _ PMutateGovernorDatum) _ txInfo' -> P.do
|
||||||
datum <- pletFields @'["newDatum", "governorRef"] datum'
|
datum <- pletFields @'["newDatum", "governorRef"] datum'
|
||||||
|
|
||||||
txInfo <- pletFields @'["mint", "inputs", "outputs", "datums"] txInfo'
|
txInfo <- pletFields @'["mint", "inputs", "outputs", "datums"] txInfo'
|
||||||
|
|
||||||
let selfAddress =
|
|
||||||
pfield @"address"
|
|
||||||
#$ mustBePJust # "Self input not found"
|
|
||||||
#$ findTxOutByTxOutRef # txOutRef # txInfo.inputs
|
|
||||||
|
|
||||||
passert "No output to the effect validator" $
|
|
||||||
pnull #$ findOutputsToAddress # txInfo.outputs # selfAddress
|
|
||||||
|
|
||||||
let mint :: Term _ (PBuiltinList _)
|
let mint :: Term _ (PBuiltinList _)
|
||||||
mint = pto $ pto $ pto $ pfromData txInfo.mint
|
mint = pto $ pto $ pto $ pfromData txInfo.mint
|
||||||
|
|
||||||
passert "Nothing should be minted/burnt other than GAT" $
|
passert "Nothing should be minted/burnt other than GAT" $
|
||||||
plength # mint #== 1
|
plength # mint #== 1
|
||||||
|
|
||||||
filteredInputs <-
|
passert "Only self and governor inputs are allowed" $
|
||||||
plet $
|
plength # pfromData txInfo.inputs #== 2
|
||||||
pfilter
|
|
||||||
# plam
|
|
||||||
( \inInfo ->
|
|
||||||
let value = pfield @"value" #$ pfield @"resolved" # inInfo
|
|
||||||
in gstValueOf # value #== 1
|
|
||||||
)
|
|
||||||
# pfromData txInfo.inputs
|
|
||||||
|
|
||||||
passert "Governor's state token must be moved" $
|
let inputWithGST =
|
||||||
plength # filteredInputs #== 1
|
mustBePJust # "Governor input not found" #$ pfind
|
||||||
|
# phoistAcyclic
|
||||||
|
( plam $ \inInfo ->
|
||||||
|
let value = pfield @"value" #$ pfield @"resolved" # inInfo
|
||||||
|
in gstValueOf # value #== 1
|
||||||
|
)
|
||||||
|
# pfromData txInfo.inputs
|
||||||
|
|
||||||
governorInput <- plet $ phead # filteredInputs
|
govInInfo <- pletFields @'["outRef", "resolved"] $ inputWithGST
|
||||||
|
|
||||||
passert "Can only modify the pinned governor" $
|
passert "Can only modify the pinned governor" $
|
||||||
pfield @"outRef" # governorInput #== datum.governorRef
|
govInInfo.outRef #== datum.governorRef
|
||||||
|
|
||||||
let govAddress =
|
passert "Only governor ouput is allowed" $
|
||||||
pfield @"address"
|
plength # pfromData txInfo.outputs #== 1
|
||||||
#$ pfield @"resolved"
|
|
||||||
#$ pfromData governorInput
|
|
||||||
|
|
||||||
filteredOutputs <- plet $ findOutputsToAddress # pfromData txInfo.outputs # govAddress
|
let govAddress = pfield @"address" #$ govInInfo.resolved
|
||||||
|
govOutput' = pfromData $ phead # pfromData txInfo.outputs
|
||||||
|
|
||||||
passert "Exactly one output to the governor" $
|
govOutput <- pletFields @'["address", "value", "datumHash"] govOutput'
|
||||||
plength # filteredOutputs #== 1
|
|
||||||
|
|
||||||
governorOutput <- plet $ phead # filteredOutputs
|
passert "No output to the governor" $
|
||||||
|
govOutput.address #== govAddress
|
||||||
|
|
||||||
passert "Governor's state token must stay at governor's address" $
|
passert "Governor output doesn't carry the GST" $
|
||||||
(gstValueOf #$ pfield @"value" # governorOutput) #== 1
|
gstValueOf # govOutput.value #== 1
|
||||||
|
|
||||||
let governorOutputDatumHash =
|
let governorOutputDatumHash =
|
||||||
mustBePDJust # "Governor output doesn't have datum"
|
mustBePDJust # "Governor output doesn't have datum" # govOutput.datumHash
|
||||||
#$ pfromData
|
|
||||||
$ pfield @"datumHash" # governorOutput
|
|
||||||
governorOutputDatum =
|
governorOutputDatum =
|
||||||
pfromData @PGovernorDatum $
|
pfromData @PGovernorDatum $
|
||||||
mustBePJust # "Governor output datum not found"
|
mustBePJust # "Governor output datum not found"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue