Skip to content

Commit 07d2597

Browse files
committed
Move isZero TxOut Check
1 parent c070f79 commit 07d2597

File tree

2 files changed

+24
-23
lines changed

2 files changed

+24
-23
lines changed

src/BotPlutusInterface/Balance.hs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -136,16 +136,20 @@ balanceTxIO' balanceCfg pabConf ownPkh unbalancedTx =
136136
(unBalancedTxValidityTimeRange unbalancedTx)
137137
(unBalancedTxTx unbalancedTx)
138138

139+
-- Checks that there is a non-zero output in the transaction.
139140
-- Adds required collaterals in the `Tx`, if `bcHasScripts`
140141
-- is true. Also adds signatures for fee calculation
141142
preBalancedTx <-
142-
if bcHasScripts balanceCfg
143-
then
144-
maybe
145-
(throwE $ WAPI.OtherError "Tx uses script but no collateral was provided.")
146-
(hoistEither . addSignatories ownPkh privKeys requiredSigs . flip addTxCollaterals tx)
147-
mcollateral
148-
else hoistEither $ addSignatories ownPkh privKeys requiredSigs tx
143+
if all (Value.isZero . txOutValue) (Tx.txOutputs tx)
144+
then throwE $ WAPI.OtherError "When constructing the transaction, no output values were specified."
145+
else
146+
if bcHasScripts balanceCfg
147+
then
148+
maybe
149+
(throwE $ WAPI.OtherError "Tx uses script but no collateral was provided.")
150+
(hoistEither . addSignatories ownPkh privKeys requiredSigs . flip addTxCollaterals tx)
151+
mcollateral
152+
else hoistEither $ addSignatories ownPkh privKeys requiredSigs tx
149153

150154
-- Balance the tx
151155
(balancedTx, minUtxos) <- balanceTxLoop utxoIndex privKeys [] preBalancedTx

src/BotPlutusInterface/CardanoCLI.hs

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -143,22 +143,18 @@ calculateMinUtxo ::
143143
TxOut ->
144144
Eff effs (Either Text Integer)
145145
calculateMinUtxo pabConf datums txOut = do
146-
let outs = txOutOpts pabConf datums [txOut]
147-
case outs of
148-
[] -> pure $ Left "When constructing the transaction, no output values were specified."
149-
_ ->
150-
join
151-
<$> callCommand @w
152-
ShellArgs
153-
{ cmdName = "cardano-cli"
154-
, cmdArgs =
155-
mconcat
156-
[ ["transaction", "calculate-min-required-utxo", "--alonzo-era"]
157-
, outs
158-
, ["--protocol-params-file", pabConf.pcProtocolParamsFile]
159-
]
160-
, cmdOutParser = mapLeft Text.pack . parseOnly UtxoParser.feeParser . Text.pack
161-
}
146+
join
147+
<$> callCommand @w
148+
ShellArgs
149+
{ cmdName = "cardano-cli"
150+
, cmdArgs =
151+
mconcat
152+
[ ["transaction", "calculate-min-required-utxo", "--alonzo-era"]
153+
, txOutOpts pabConf datums [txOut]
154+
, ["--protocol-params-file", pabConf.pcProtocolParamsFile]
155+
]
156+
, cmdOutParser = mapLeft Text.pack . parseOnly UtxoParser.feeParser . Text.pack
157+
}
162158

163159
-- | Calculating fee for an unbalanced transaction
164160
calculateMinFee ::
@@ -212,6 +208,7 @@ buildTx pabConf privKeys txBudget tx = do
212208
[]
213209
)
214210
(Map.keys (Ledger.txSignatures tx))
211+
215212
opts ins mints =
216213
mconcat
217214
[ ["transaction", "build-raw", "--alonzo-era"]

0 commit comments

Comments
 (0)