Skip to content

Commit 1e136a3

Browse files
Jimbo4350carbolymer
andcommitted
Update createTxMintValue and propagate the removal of Maybe PolicyId
from PReferenceScript and SReferenceScript constructors Co-authored-by: Mateusz Gałażyn <mateusz.galazyn@gmail.com>
1 parent e72b227 commit 1e136a3

File tree

4 files changed

+22
-13
lines changed

4 files changed

+22
-13
lines changed

cardano-cli/src/Cardano/CLI/EraBased/Run/Transaction.hs

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ import Data.Function ((&))
7777
import qualified Data.List as List
7878
import Data.Map.Strict (Map)
7979
import qualified Data.Map.Strict as Map
80-
import Data.Maybe (catMaybes, fromMaybe, mapMaybe)
80+
import Data.Maybe (catMaybes, fromMaybe, mapMaybe, maybeToList)
8181
import Data.Set (Set)
8282
import qualified Data.Set as Set
8383
import qualified Data.Text as Text
@@ -1248,9 +1248,9 @@ getAllReferenceInputs
12481248
:: ScriptWitness witctx era -> Maybe TxIn
12491249
getReferenceInput sWit =
12501250
case sWit of
1251-
PlutusScriptWitness _ _ (PReferenceScript refIn _) _ _ _ -> Just refIn
1251+
PlutusScriptWitness _ _ (PReferenceScript refIn) _ _ _ -> Just refIn
12521252
PlutusScriptWitness _ _ PScript{} _ _ _ -> Nothing
1253-
SimpleScriptWitness _ (SReferenceScript refIn _) -> Just refIn
1253+
SimpleScriptWitness _ (SReferenceScript refIn) -> Just refIn
12541254
SimpleScriptWitness _ SScript{} -> Nothing
12551255

12561256
toAddressInAnyEra
@@ -1403,19 +1403,26 @@ createTxMintValue era (val, scriptWitnesses) =
14031403
caseShelleyToAllegraOrMaryEraOnwards
14041404
(const (txFeatureMismatchPure (toCardanoEra era) TxFeatureMintValue))
14051405
( \w -> do
1406-
-- The set of policy ids for which we need witnesses:
1407-
let witnessesNeededSet :: Set PolicyId
1408-
witnessesNeededSet =
1409-
fromList [pid | (AssetId pid _, _) <- toList val]
1406+
let policiesWithAssets :: [(PolicyId, AssetName, Quantity)]
1407+
policiesWithAssets = [(pid, assetName, quantity) | (AssetId pid assetName, quantity) <- toList val]
1408+
-- The set of policy ids for which we need witnesses:
1409+
witnessesNeededSet :: Set PolicyId
1410+
witnessesNeededSet = fromList [pid | (pid, _, _) <- policiesWithAssets]
14101411

14111412
let witnessesProvidedMap :: Map PolicyId (ScriptWitness WitCtxMint era)
14121413
witnessesProvidedMap = fromList $ [(polid, sWit) | MintScriptWitnessWithPolicyId polid sWit <- scriptWitnesses]
14131414
witnessesProvidedSet = Map.keysSet witnessesProvidedMap
1414-
1415+
policiesWithWitnesses =
1416+
Map.fromListWith
1417+
(<>)
1418+
[ (pid, [(assetName, quantity, BuildTxWith witness)])
1419+
| (pid, assetName, quantity) <- policiesWithAssets
1420+
, witness <- maybeToList $ Map.lookup pid witnessesProvidedMap
1421+
]
14151422
-- Check not too many, nor too few:
14161423
validateAllWitnessesProvided witnessesNeededSet witnessesProvidedSet
14171424
validateNoUnnecessaryWitnesses witnessesNeededSet witnessesProvidedSet
1418-
return (TxMintValue w val (BuildTxWith witnessesProvidedMap))
1425+
pure $ TxMintValue w policiesWithWitnesses
14191426
)
14201427
era
14211428
where

cardano-cli/src/Cardano/CLI/EraBased/Script/Mint/Read.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,15 @@ readMintScriptWitness sbe (OnDiskSimpleRefScript (SimpleRefScriptCliArgs refTxIn
6666
MintScriptWitnessWithPolicyId polId $
6767
SimpleScriptWitness
6868
(sbeToSimpleScriptLangInEra sbe)
69-
(SReferenceScript refTxIn $ Just $ unPolicyId polId)
69+
(SReferenceScript refTxIn)
7070
readMintScriptWitness
7171
sbe
7272
( OnDiskPlutusRefScript
7373
(PlutusRefScriptCliArgs refTxIn anyPlutusScriptVersion redeemerFile execUnits polId)
7474
) = do
7575
case anyPlutusScriptVersion of
7676
AnyPlutusScriptVersion lang -> do
77-
let pScript = PReferenceScript refTxIn $ Just $ unPolicyId polId
77+
let pScript = PReferenceScript refTxIn
7878
redeemer <-
7979
-- TODO: Implement a new error type to capture this. FileError is not representative of cases
8080
-- where we do not have access to the script.

cardano-cli/src/Cardano/CLI/EraBased/Script/Mint/Types.hs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@ where
1818

1919
import Cardano.Api
2020

21-
import Cardano.CLI.Read
2221
import Cardano.CLI.Types.Common (ScriptDataOrFile)
22+
import Cardano.CLI.Types.Errors.PlutusScriptDecodeError
23+
import Cardano.CLI.Types.Errors.ScriptDataError
24+
import Cardano.CLI.Types.Errors.ScriptDecodeError
2325

2426
-- We always need the policy id when constructing a transaction that mints.
2527
-- In the case of reference scripts, the user currently must provide the policy id (script hash)

cardano-cli/src/Cardano/CLI/Types/Output.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ renderScriptCosts (UTxO utxo) eUnitPrices scriptMapping executionCostMapping =
383383
Left err -> Left (PlutusScriptCostErrExecError sWitInd (Just scriptHash) err) : accum
384384
-- TODO: Create a new sum type to encapsulate the fact that we can also
385385
-- have a txin and render the txin in the case of reference scripts.
386-
Just (AnyScriptWitness (PlutusScriptWitness _ _ (PReferenceScript refTxIn _) _ _ _)) ->
386+
Just (AnyScriptWitness (PlutusScriptWitness _ _ (PReferenceScript refTxIn) _ _ _)) ->
387387
case Map.lookup refTxIn utxo of
388388
Nothing -> Left (PlutusScriptCostErrRefInputNotInUTxO refTxIn) : accum
389389
Just (TxOut _ _ _ refScript) ->

0 commit comments

Comments
 (0)