allow effect datum to be stored inline
This commit is contained in:
parent
4757bbfc1e
commit
dc51d2219b
2 changed files with 33 additions and 4 deletions
|
|
@ -41,7 +41,7 @@ import Agora.Stake (
|
|||
pnumCreatedProposals,
|
||||
presolveStakeInputDatum,
|
||||
)
|
||||
import Agora.Utils (ptaggedSymbolValueOf, ptoScottEncodingT, puntag)
|
||||
import Agora.Utils (phashDatum, ptaggedSymbolValueOf, ptoScottEncodingT, puntag)
|
||||
import Data.Function (on)
|
||||
import Plutarch.Api.V1 (PCurrencySymbol)
|
||||
import Plutarch.Api.V1.AssocMap (plookup)
|
||||
|
|
@ -54,6 +54,7 @@ import Plutarch.Api.V2 (
|
|||
PTxOutRef,
|
||||
PValidator,
|
||||
)
|
||||
import Plutarch.Api.V2.Tx (POutputDatum (..))
|
||||
import Plutarch.Extra.AssetClass (PAssetClassData, passetClass)
|
||||
import Plutarch.Extra.Field (pletAll, pletAllC)
|
||||
import Plutarch.Extra.Maybe (passertPJust, pfromJust, pjust, pmaybeData, pnothing)
|
||||
|
|
@ -64,7 +65,6 @@ import Plutarch.Extra.ScriptContext (
|
|||
pisUTXOSpent,
|
||||
pscriptHashFromAddress,
|
||||
pscriptHashToTokenName,
|
||||
ptryFromDatumHash,
|
||||
ptryFromOutputDatum,
|
||||
pvalueSpent,
|
||||
)
|
||||
|
|
@ -541,8 +541,13 @@ governorValidator =
|
|||
# outputF.value
|
||||
#== 1
|
||||
|
||||
let hasCorrectDatum =
|
||||
effect.datumHash #== ptryFromDatumHash # outputF.datum
|
||||
let outputDatumHash = pmatch outputF.datum $ \case
|
||||
POutputDatum d -> phashDatum # d
|
||||
POutputDatumHash h -> pfield @"datumHash" # h
|
||||
_ -> ptraceError "expcted effect datum, got nothing"
|
||||
|
||||
hasCorrectDatum =
|
||||
effect.datumHash #== outputDatumHash
|
||||
|
||||
pguardC "Authority output valid" $
|
||||
foldr1
|
||||
|
|
|
|||
|
|
@ -17,8 +17,10 @@ module Agora.Utils (
|
|||
ptaggedSymbolValueOf,
|
||||
ptag,
|
||||
puntag,
|
||||
phashDatum,
|
||||
) where
|
||||
|
||||
import Plutarch.Api.V1.Scripts (PDatumHash (PDatumHash))
|
||||
import Plutarch.Api.V2 (
|
||||
AmountGuarantees,
|
||||
KeyGuarantees,
|
||||
|
|
@ -26,6 +28,8 @@ import Plutarch.Api.V2 (
|
|||
PMaybeData (PDNothing),
|
||||
PValue,
|
||||
)
|
||||
import Plutarch.Builtin (pforgetData, pserialiseData)
|
||||
import Plutarch.Crypto (pblake2b_256)
|
||||
import Plutarch.Extra.AssetClass (PAssetClass, PAssetClassData, ptoScottEncoding)
|
||||
import Plutarch.Extra.Tagged (PTagged)
|
||||
import Plutarch.Extra.Value (psymbolValueOf)
|
||||
|
|
@ -115,3 +119,23 @@ puntag ::
|
|||
Term s (PTagged tag a) ->
|
||||
Term s a
|
||||
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