remove pfindDatum', in favour of ptryFindDatum
This commit is contained in:
parent
18622c76d2
commit
ec835b48c9
2 changed files with 9 additions and 15 deletions
|
|
@ -154,19 +154,20 @@ stakeRef = TxOutRef "0ca36f3a357bc69579ab2531aecd1e7d3714d993c7820f40b864be15" 0
|
||||||
cosignProposal :: [PubKeyHash] -> TxInfo
|
cosignProposal :: [PubKeyHash] -> TxInfo
|
||||||
cosignProposal newSigners =
|
cosignProposal newSigners =
|
||||||
let st = Value.singleton proposalPolicySymbol "" 1 -- Proposal ST
|
let st = Value.singleton proposalPolicySymbol "" 1 -- Proposal ST
|
||||||
|
effects =
|
||||||
|
AssocMap.fromList
|
||||||
|
[ (ResultTag 0, [])
|
||||||
|
, (ResultTag 1, [])
|
||||||
|
]
|
||||||
proposalBefore :: ProposalDatum
|
proposalBefore :: ProposalDatum
|
||||||
proposalBefore =
|
proposalBefore =
|
||||||
ProposalDatum
|
ProposalDatum
|
||||||
{ proposalId = ProposalId 0
|
{ proposalId = ProposalId 0
|
||||||
, effects =
|
, effects = effects
|
||||||
AssocMap.fromList
|
|
||||||
[ (ResultTag 0, [])
|
|
||||||
, (ResultTag 1, [])
|
|
||||||
]
|
|
||||||
, status = Draft
|
, status = Draft
|
||||||
, cosigners = [signer]
|
, cosigners = [signer]
|
||||||
, thresholds = defaultProposalThresholds
|
, thresholds = defaultProposalThresholds
|
||||||
, votes = ProposalVotes AssocMap.empty
|
, votes = emptyVotesFor effects
|
||||||
}
|
}
|
||||||
stakeDatum :: StakeDatum
|
stakeDatum :: StakeDatum
|
||||||
stakeDatum = StakeDatum (Tagged 50_000_000) signer2 []
|
stakeDatum = StakeDatum (Tagged 50_000_000) signer2 []
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,6 @@ module Agora.Utils (
|
||||||
passert,
|
passert,
|
||||||
pfind',
|
pfind',
|
||||||
pfindDatum,
|
pfindDatum,
|
||||||
pfindDatum',
|
|
||||||
ptryFindDatum,
|
ptryFindDatum,
|
||||||
pvalueSpent,
|
pvalueSpent,
|
||||||
ptxSignedBy,
|
ptxSignedBy,
|
||||||
|
|
@ -74,7 +73,6 @@ import Plutarch.Api.V1.AssocMap (PMap (PMap))
|
||||||
import Plutarch.Api.V1.Extra (PAssetClass, passetClassValueOf, pvalueOf)
|
import Plutarch.Api.V1.Extra (PAssetClass, passetClassValueOf, pvalueOf)
|
||||||
import Plutarch.Api.V1.Value (PValue (PValue))
|
import Plutarch.Api.V1.Value (PValue (PValue))
|
||||||
import Plutarch.Builtin (ppairDataBuiltin)
|
import Plutarch.Builtin (ppairDataBuiltin)
|
||||||
import Plutarch.Internal (punsafeCoerce)
|
|
||||||
import Plutarch.Map.Extra (pkeys)
|
import Plutarch.Map.Extra (pkeys)
|
||||||
import Plutarch.Monadic qualified as P
|
import Plutarch.Monadic qualified as P
|
||||||
import Plutarch.TryFrom (PTryFrom, ptryFrom)
|
import Plutarch.TryFrom (PTryFrom, ptryFrom)
|
||||||
|
|
@ -102,12 +100,6 @@ ptryFindDatum = phoistAcyclic $
|
||||||
(datum', _) <- ptryFrom (pto datum)
|
(datum', _) <- ptryFrom (pto datum)
|
||||||
pcon (PJust datum')
|
pcon (PJust datum')
|
||||||
|
|
||||||
{- | Find a datum with the given hash.
|
|
||||||
NOTE: this is unsafe in the sense that, if the data layout is wrong, this is UB.
|
|
||||||
-}
|
|
||||||
pfindDatum' :: PIsData a => Term s (PDatumHash :--> PBuiltinList (PAsData (PTuple PDatumHash PDatum)) :--> PMaybe (PAsData a))
|
|
||||||
pfindDatum' = phoistAcyclic $ plam $ \dh x -> punsafeCoerce $ pfindDatum # dh # x
|
|
||||||
|
|
||||||
-- | Check if a PubKeyHash signs this transaction.
|
-- | Check if a PubKeyHash signs this transaction.
|
||||||
ptxSignedBy :: Term s (PBuiltinList (PAsData PPubKeyHash) :--> PAsData PPubKeyHash :--> PBool)
|
ptxSignedBy :: Term s (PBuiltinList (PAsData PPubKeyHash) :--> PAsData PPubKeyHash :--> PBool)
|
||||||
ptxSignedBy = phoistAcyclic $
|
ptxSignedBy = phoistAcyclic $
|
||||||
|
|
@ -416,6 +408,7 @@ allOutputs = phoistAcyclic $
|
||||||
anyInput ::
|
anyInput ::
|
||||||
forall (datum :: PType) s.
|
forall (datum :: PType) s.
|
||||||
( PIsData datum
|
( PIsData datum
|
||||||
|
, PTryFrom PData (PAsData datum)
|
||||||
) =>
|
) =>
|
||||||
Term s (PTxInfo :--> (PValue :--> PAddress :--> datum :--> PBool) :--> PBool)
|
Term s (PTxInfo :--> (PValue :--> PAddress :--> datum :--> PBool) :--> PBool)
|
||||||
anyInput = phoistAcyclic $
|
anyInput = phoistAcyclic $
|
||||||
|
|
@ -429,7 +422,7 @@ anyInput = phoistAcyclic $
|
||||||
PTxOut txOut' <- pmatch (pfromData txOut'')
|
PTxOut txOut' <- pmatch (pfromData txOut'')
|
||||||
txOut <- pletFields @'["value", "datumHash", "address"] txOut'
|
txOut <- pletFields @'["value", "datumHash", "address"] txOut'
|
||||||
PDJust dh <- pmatch txOut.datumHash
|
PDJust dh <- pmatch txOut.datumHash
|
||||||
pmatch (pfindDatum' @datum # (pfield @"_0" # dh) # txInfo.datums) $ \case
|
pmatch (ptryFindDatum @(PAsData datum) # (pfield @"_0" # dh) # txInfo.datums) $ \case
|
||||||
PJust datum -> P.do
|
PJust datum -> P.do
|
||||||
predicate # txOut.value # txOut.address # pfromData datum
|
predicate # txOut.value # txOut.address # pfromData datum
|
||||||
PNothing -> pcon PFalse
|
PNothing -> pcon PFalse
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue