@@ -44,7 +44,24 @@ buildTransaction ::
44
44
IO (Either (TxBodyErrorAutoBalance Era ) Tx )
45
45
buildTransaction backend changeAddress body utxoToSpend outs = do
46
46
pparams <- queryProtocolParameters backend CardanoClient. QueryTip
47
- buildTransactionWithPParams pparams backend changeAddress body utxoToSpend outs
47
+ buildTransactionWithPParams pparams backend changeAddress body utxoToSpend outs Nothing
48
+
49
+ buildTransactionWithMintingScript ::
50
+ ChainBackend backend =>
51
+ backend ->
52
+ -- | Change address to send
53
+ AddressInEra ->
54
+ -- | Unspent transaction outputs to spend.
55
+ UTxO ->
56
+ -- | Collateral inputs.
57
+ [TxIn ] ->
58
+ -- | Outputs to create.
59
+ [TxOut CtxTx ] ->
60
+ Maybe PlutusScript ->
61
+ IO (Either (TxBodyErrorAutoBalance Era ) Tx )
62
+ buildTransactionWithMintingScript backend changeAddress body utxoToSpend outs mintingScript = do
63
+ pparams <- queryProtocolParameters backend CardanoClient. QueryTip
64
+ buildTransactionWithPParams pparams backend changeAddress body utxoToSpend outs mintingScript
48
65
49
66
-- | Construct a simple payment consuming some inputs and producing some
50
67
-- outputs (no certificates or withdrawals involved).
@@ -64,15 +81,17 @@ buildTransactionWithPParams ::
64
81
[TxIn ] ->
65
82
-- | Outputs to create.
66
83
[TxOut CtxTx ] ->
84
+ Maybe PlutusScript ->
67
85
IO (Either (TxBodyErrorAutoBalance Era ) Tx )
68
- buildTransactionWithPParams pparams backend changeAddress utxoToSpend collateral outs = do
86
+ buildTransactionWithPParams pparams backend changeAddress utxoToSpend collateral outs mintingScript = do
69
87
systemStart <- querySystemStart backend CardanoClient. QueryTip
70
88
eraHistory <- queryEraHistory backend CardanoClient. QueryTip
71
89
stakePools <- queryStakePools backend CardanoClient. QueryTip
72
- pure $ buildTransactionWithPParams' pparams systemStart eraHistory stakePools changeAddress utxoToSpend collateral outs
90
+ pure $ buildTransactionWithPParams' pparams systemStart eraHistory stakePools changeAddress utxoToSpend collateral outs mintingScript
73
91
74
- -- | NOTE: If there are any non ADA assets present in the output 'Value'
75
- -- this function will mint them using 'dummyValidatorScript' as the script witness.
92
+ -- | NOTE: If there are any non ADA assets present in the output 'Value' and
93
+ -- minting scrips is specified this function will mint them using provided
94
+ -- script as the script witness.
76
95
buildTransactionWithPParams' ::
77
96
-- | Protocol parameters
78
97
PParams LedgerEra ->
@@ -87,30 +106,45 @@ buildTransactionWithPParams' ::
87
106
[TxIn ] ->
88
107
-- | Outputs to create.
89
108
[TxOut CtxTx ] ->
109
+ Maybe PlutusScript ->
90
110
Either (TxBodyErrorAutoBalance Era ) Tx
91
- buildTransactionWithPParams' pparams systemStart eraHistory stakePools changeAddress utxoToSpend collateral outs = do
111
+ buildTransactionWithPParams' pparams systemStart eraHistory stakePools changeAddress utxoToSpend collateral outs mintingScript = do
92
112
buildTransactionWithBody pparams systemStart eraHistory stakePools changeAddress bodyContent utxoToSpend
93
113
where
94
- dummyMintingWitness :: ScriptWitness WitCtxMint
95
- dummyMintingWitness =
96
- mkScriptWitness dummyMintingScript NoScriptDatumForMint (toScriptData () )
97
-
98
- setMintValue =
99
- let toMint = valueToPolicyAssets (foldMap txOutValue outs)
100
- in if null toMint
101
- then TxMintValueNone
102
- else
103
- TxMintValue $
104
- Map. fromList $
105
- ( \ (pid, assets) ->
106
- ( pid
107
- ,
108
- ( assets
109
- , BuildTxWith dummyMintingWitness
110
- )
114
+ mintValue =
115
+ case mintingScript of
116
+ Nothing -> TxMintValueNone
117
+ Just _ ->
118
+ let mintingWitness =
119
+ mkScriptWitness dummyMintingScript NoScriptDatumForMint (toScriptData () )
120
+ toMint = valueToPolicyAssets (foldMap txOutValue outs)
121
+ in if null toMint
122
+ then TxMintValueNone
123
+ else
124
+ TxMintValue $
125
+ Map. fromList $
126
+ ( \ (pid, assets) ->
127
+ ( pid
128
+ ,
129
+ ( assets
130
+ , BuildTxWith mintingWitness
131
+ )
132
+ )
111
133
)
134
+ <$> Map. toList toMint
135
+ auxScripts =
136
+ if mintValue == TxMintValueNone
137
+ then TxAuxScriptsNone
138
+ else
139
+ TxAuxScripts
140
+ ( maybeToList $
141
+ toScriptInEra
142
+ ShelleyBasedEraConway
143
+ ( toScriptInAnyLang $
144
+ PlutusScript $
145
+ fromMaybe dummyMintingScript mintingScript
112
146
)
113
- <$> Map. toList toMint
147
+ )
114
148
-- NOTE: 'makeTransactionBodyAutoBalance' overwrites this.
115
149
bodyContent =
116
150
TxBodyContent
@@ -124,16 +158,13 @@ buildTransactionWithPParams' pparams systemStart eraHistory stakePools changeAdd
124
158
, txValidityLowerBound = TxValidityNoLowerBound
125
159
, txValidityUpperBound = TxValidityNoUpperBound
126
160
, txMetadata = TxMetadataNone
127
- , txAuxScripts =
128
- if setMintValue == TxMintValueNone
129
- then TxAuxScriptsNone
130
- else TxAuxScripts (maybeToList $ toScriptInEra ShelleyBasedEraConway (toScriptInAnyLang $ PlutusScript dummyMintingScript))
161
+ , txAuxScripts = auxScripts
131
162
, txExtraKeyWits = TxExtraKeyWitnessesNone
132
163
, txProtocolParams = BuildTxWith $ Just $ LedgerProtocolParameters pparams
133
164
, txWithdrawals = TxWithdrawalsNone
134
165
, txCertificates = TxCertificatesNone
135
166
, txUpdateProposal = TxUpdateProposalNone
136
- , txMintValue = setMintValue
167
+ , txMintValue = mintValue
137
168
, txScriptValidity = TxScriptValidityNone
138
169
, txProposalProcedures = Nothing
139
170
, txVotingProcedures = Nothing
0 commit comments