allow effect datum to be stored inline
This commit is contained in:
parent
8c6d189c08
commit
044a4d03b5
2 changed files with 33 additions and 4 deletions
|
|
@ -41,7 +41,7 @@ import Agora.Stake (
|
||||||
pnumCreatedProposals,
|
pnumCreatedProposals,
|
||||||
presolveStakeInputDatum,
|
presolveStakeInputDatum,
|
||||||
)
|
)
|
||||||
import Agora.Utils (ptaggedSymbolValueOf, ptoScottEncodingT, puntag)
|
import Agora.Utils (phashDatum, ptaggedSymbolValueOf, ptoScottEncodingT, puntag)
|
||||||
import Data.Function (on)
|
import Data.Function (on)
|
||||||
import Plutarch.Api.V1 (PCurrencySymbol)
|
import Plutarch.Api.V1 (PCurrencySymbol)
|
||||||
import Plutarch.Api.V1.AssocMap (plookup)
|
import Plutarch.Api.V1.AssocMap (plookup)
|
||||||
|
|
@ -54,6 +54,7 @@ import Plutarch.Api.V2 (
|
||||||
PTxOutRef,
|
PTxOutRef,
|
||||||
PValidator,
|
PValidator,
|
||||||
)
|
)
|
||||||
|
import Plutarch.Api.V2.Tx (POutputDatum (..))
|
||||||
import Plutarch.Extra.AssetClass (PAssetClassData, passetClass)
|
import Plutarch.Extra.AssetClass (PAssetClassData, passetClass)
|
||||||
import Plutarch.Extra.Field (pletAll, pletAllC)
|
import Plutarch.Extra.Field (pletAll, pletAllC)
|
||||||
import Plutarch.Extra.Maybe (passertPJust, pfromJust, pjust, pmaybeData, pnothing)
|
import Plutarch.Extra.Maybe (passertPJust, pfromJust, pjust, pmaybeData, pnothing)
|
||||||
|
|
@ -64,7 +65,6 @@ import Plutarch.Extra.ScriptContext (
|
||||||
pisUTXOSpent,
|
pisUTXOSpent,
|
||||||
pscriptHashFromAddress,
|
pscriptHashFromAddress,
|
||||||
pscriptHashToTokenName,
|
pscriptHashToTokenName,
|
||||||
ptryFromDatumHash,
|
|
||||||
ptryFromOutputDatum,
|
ptryFromOutputDatum,
|
||||||
pvalueSpent,
|
pvalueSpent,
|
||||||
)
|
)
|
||||||
|
|
@ -541,8 +541,13 @@ governorValidator =
|
||||||
# outputF.value
|
# outputF.value
|
||||||
#== 1
|
#== 1
|
||||||
|
|
||||||
let hasCorrectDatum =
|
let outputDatumHash = pmatch outputF.datum $ \case
|
||||||
effect.datumHash #== ptryFromDatumHash # outputF.datum
|
POutputDatum d -> phashDatum # d
|
||||||
|
POutputDatumHash h -> pfield @"datumHash" # h
|
||||||
|
_ -> ptraceError "expcted effect datum, got nothing"
|
||||||
|
|
||||||
|
hasCorrectDatum =
|
||||||
|
effect.datumHash #== outputDatumHash
|
||||||
|
|
||||||
pguardC "Authority output valid" $
|
pguardC "Authority output valid" $
|
||||||
foldr1
|
foldr1
|
||||||
|
|
|
||||||
|
|
@ -17,8 +17,10 @@ module Agora.Utils (
|
||||||
ptaggedSymbolValueOf,
|
ptaggedSymbolValueOf,
|
||||||
ptag,
|
ptag,
|
||||||
puntag,
|
puntag,
|
||||||
|
phashDatum,
|
||||||
) where
|
) where
|
||||||
|
|
||||||
|
import Plutarch.Api.V1.Scripts (PDatumHash (PDatumHash))
|
||||||
import Plutarch.Api.V2 (
|
import Plutarch.Api.V2 (
|
||||||
AmountGuarantees,
|
AmountGuarantees,
|
||||||
KeyGuarantees,
|
KeyGuarantees,
|
||||||
|
|
@ -26,6 +28,8 @@ import Plutarch.Api.V2 (
|
||||||
PMaybeData (PDNothing),
|
PMaybeData (PDNothing),
|
||||||
PValue,
|
PValue,
|
||||||
)
|
)
|
||||||
|
import Plutarch.Builtin (pforgetData, pserialiseData)
|
||||||
|
import Plutarch.Crypto (pblake2b_256)
|
||||||
import Plutarch.Extra.AssetClass (PAssetClass, PAssetClassData, ptoScottEncoding)
|
import Plutarch.Extra.AssetClass (PAssetClass, PAssetClassData, ptoScottEncoding)
|
||||||
import Plutarch.Extra.Tagged (PTagged)
|
import Plutarch.Extra.Tagged (PTagged)
|
||||||
import Plutarch.Extra.Value (psymbolValueOf)
|
import Plutarch.Extra.Value (psymbolValueOf)
|
||||||
|
|
@ -115,3 +119,23 @@ puntag ::
|
||||||
Term s (PTagged tag a) ->
|
Term s (PTagged tag a) ->
|
||||||
Term s a
|
Term s a
|
||||||
puntag = pto
|
puntag = pto
|
||||||
|
|
||||||
|
{- | Hash the given datum using the correct algorithm(blake2b_256).
|
||||||
|
|
||||||
|
Note: check the discussion here: https://github.com/input-output-hk/cardano-ledger/issues/2941.
|
||||||
|
|
||||||
|
@since 1.0.0
|
||||||
|
-}
|
||||||
|
phashDatum ::
|
||||||
|
forall (a :: PType) (s :: S).
|
||||||
|
PIsData a =>
|
||||||
|
Term s (a :--> PDatumHash)
|
||||||
|
phashDatum =
|
||||||
|
phoistAcyclic $
|
||||||
|
plam $
|
||||||
|
pcon
|
||||||
|
. PDatumHash
|
||||||
|
. (pblake2b_256 #)
|
||||||
|
. (pserialiseData #)
|
||||||
|
. pforgetData
|
||||||
|
. pdata
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue