handle proposal creation
* check proposal id
This commit is contained in:
parent
99365a32ae
commit
1e9ff7d8f4
1 changed files with 18 additions and 8 deletions
|
|
@ -30,7 +30,7 @@ import Generics.SOP (Generic, I (I))
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
import Agora.Proposal (PProposalId, PProposalThresholds, ProposalId, ProposalThresholds)
|
import Agora.Proposal (PProposalId, PProposalThresholds, ProposalId, ProposalThresholds)
|
||||||
import Agora.Utils (findOutputsToAddress, passert, passetClassValueOf', pfindTxInByTxOutRef)
|
import Agora.Utils (findOutputsToAddress, passert, passetClassValueOf', pfindTxInByTxOutRef, findTxOutDatum)
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
@ -141,7 +141,7 @@ governorPolicy _ =
|
||||||
-- | Validator for Governors.
|
-- | Validator for Governors.
|
||||||
governorValidator :: Governor -> ClosedTerm PValidator
|
governorValidator :: Governor -> ClosedTerm PValidator
|
||||||
governorValidator params =
|
governorValidator params =
|
||||||
plam $ \_datum' redeemer' ctx' -> P.do
|
plam $ \datum' redeemer' ctx' -> P.do
|
||||||
-- TODO: use `PTryFrom`
|
-- TODO: use `PTryFrom`
|
||||||
redeemer <- pmatch $ pfromData @PGovernorRedeemer $ punsafeCoerce redeemer'
|
redeemer <- pmatch $ pfromData @PGovernorRedeemer $ punsafeCoerce redeemer'
|
||||||
ctx <- pletFields @'["txInfo", "purpose"] ctx'
|
ctx <- pletFields @'["txInfo", "purpose"] ctx'
|
||||||
|
|
@ -153,7 +153,10 @@ governorValidator params =
|
||||||
|
|
||||||
PJust ((pfield @"resolved" #) -> ownInput') <- pmatch $ pfindTxInByTxOutRef # txOutRef # txInfo
|
PJust ((pfield @"resolved" #) -> ownInput') <- pmatch $ pfindTxInByTxOutRef # txOutRef # txInfo
|
||||||
ownInput <- pletFields @'["address", "value", "datumHash"] ownInput'
|
ownInput <- pletFields @'["address", "value", "datumHash"] ownInput'
|
||||||
selfAddress <- plet $ pfromData $ ownInput.address
|
let selfAddress = pfromData $ ownInput.address
|
||||||
|
|
||||||
|
PJust (((pfromData @PGovernorDatum) . punsafeCoerce) -> oldDatum') <- pmatch $ findTxOutDatum # txInfo # ownInput'
|
||||||
|
oldDatum <- pletFields @'["proposalThresholds", "nextProposalId"] oldDatum'
|
||||||
|
|
||||||
let ownInputDatumNFTAmount = datumNFTValueOf # ownInput.value
|
let ownInputDatumNFTAmount = datumNFTValueOf # ownInput.value
|
||||||
passert "own input should have exactly one datum NFT" $ ownInputDatumNFTAmount #== 1
|
passert "own input should have exactly one datum NFT" $ ownInputDatumNFTAmount #== 1
|
||||||
|
|
@ -166,12 +169,19 @@ governorValidator params =
|
||||||
passert "datum NFT should stay at governor's address" $ ownOuputDatumNFTAmount #== 1
|
passert "datum NFT should stay at governor's address" $ ownOuputDatumNFTAmount #== 1
|
||||||
passert "output utxo to governor should have datum" $ pisDJust # ownOutput.datumHash
|
passert "output utxo to governor should have datum" $ pisDJust # ownOutput.datumHash
|
||||||
|
|
||||||
-- datum <- plet $ pfromData @PGovernorDatum $ punsafeCoerce datum'
|
let newDatum' = pfromData @PGovernorDatum $ punsafeCoerce datum'
|
||||||
|
newDatum <- pletFields @'["proposalThresholds", "nextProposalId"] newDatum'
|
||||||
|
|
||||||
case redeemer of
|
case redeemer of
|
||||||
PCreateProposal _ -> P.do
|
PCreateProposal _ -> P.do
|
||||||
perror
|
-- TODO: deriving a PNum instance for PProposalId
|
||||||
_ -> perror
|
let oldPid = pto $ pfromData $ oldDatum.nextProposalId
|
||||||
|
newPid = pto $ pfromData $ newDatum.nextProposalId
|
||||||
|
passert "proposal id should be advanced by 1" $ oldPid + 1 #== newPid
|
||||||
|
|
||||||
|
ptraceError "not implemented yet"
|
||||||
|
PMintGATs _ -> perror
|
||||||
|
PMutateDatum _ -> perror
|
||||||
where
|
where
|
||||||
datumNFTValueOf :: Term s (PValue :--> PInteger)
|
datumNFTValueOf :: Term s (PValue :--> PInteger)
|
||||||
datumNFTValueOf = passetClassValueOf' params.datumNFT
|
datumNFTValueOf = passetClassValueOf' params.datumNFT
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue