Skip to content

Commit

Permalink
Implement POC of same number of argumetns for PlutusV3
Browse files Browse the repository at this point in the history
  • Loading branch information
lehins committed Apr 16, 2024
1 parent a11c2ca commit 03c0db7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
6 changes: 4 additions & 2 deletions eras/alonzo/impl/src/Cardano/Ledger/Alonzo/Plutus/Evaluate.hs
Expand Up @@ -31,7 +31,7 @@ import Cardano.Ledger.BaseTypes (ProtVer (pvMajor), kindObject, natVersion)
import Cardano.Ledger.Binary (DecCBOR (..), EncCBOR (..))
import Cardano.Ledger.Binary.Coders
import Cardano.Ledger.Plutus.CostModels (costModelsValid)
import Cardano.Ledger.Plutus.Data (getPlutusData)
import Cardano.Ledger.Plutus.Data (fromMaybeData, getPlutusData)
import Cardano.Ledger.Plutus.Evaluate (
PlutusDatums (..),
PlutusWithContext (..),
Expand Down Expand Up @@ -187,7 +187,9 @@ collectPlutusScriptsWithContext epochInfo sysStart pp tx utxo =
case mkPlutusScriptContext plutusScript plutusPurpose pp epochInfo sysStart utxo tx of
Right scriptContext ->
let spendingDatum = getSpendingDatum utxo tx $ hoistPlutusPurpose toAsItem plutusPurpose
datums = maybe id (:) spendingDatum [d, scriptContext]
datums
| protVerMajor < natVersion @9 = maybe id (:) spendingDatum [d, scriptContext]
| otherwise = [fromMaybeData spendingDatum, d, scriptContext]
in Right $
withPlutusScript plutusScript $ \plutus ->
PlutusWithContext
Expand Down
7 changes: 7 additions & 0 deletions libs/cardano-ledger-core/src/Cardano/Ledger/Plutus/Data.hs
Expand Up @@ -24,6 +24,7 @@ module Cardano.Ledger.Plutus.Data (
PlutusData (..),
Data (Data),
unData,
fromMaybeData,
DataHash,
upgradeData,
hashData,
Expand Down Expand Up @@ -104,6 +105,12 @@ newtype Data era = DataConstr (MemoBytes PlutusData era)
deriving (Eq, Generic)
deriving newtype (SafeToHash, ToCBOR, NFData)

-- | Convert Maybe data to a List
fromMaybeData :: Era era => Maybe (Data era) -> Data era
fromMaybeData = \case
Nothing -> Data (PV1.List [])
Just (Data d) -> Data (PV1.List [d])

-- | Encodes memoized bytes created upon construction.
instance Typeable era => EncCBOR (Data era)

Expand Down

0 comments on commit 03c0db7

Please sign in to comment.