Skip to content

Commit 3dc9936

Browse files
committed
Error message for missing tx-out value
1 parent 49da0a5 commit 3dc9936

File tree

1 file changed

+35
-28
lines changed

1 file changed

+35
-28
lines changed

src/BotPlutusInterface/CardanoCLI.hs

Lines changed: 35 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -142,19 +142,23 @@ calculateMinUtxo ::
142142
Map DatumHash Datum ->
143143
TxOut ->
144144
Eff effs (Either Text Integer)
145-
calculateMinUtxo pabConf datums txOut =
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-
}
145+
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+
}
158162

159163
-- | Calculating fee for an unbalanced transaction
160164
calculateMinFee ::
@@ -366,22 +370,25 @@ txOutOpts :: PABConfig -> Map DatumHash Datum -> [TxOut] -> [Text]
366370
txOutOpts pabConf datums =
367371
concatMap
368372
( \TxOut {txOutAddress, txOutValue, txOutDatumHash} ->
369-
mconcat
370-
[
371-
[ "--tx-out"
372-
, Text.intercalate
373-
"+"
374-
[ unsafeSerialiseAddress pabConf.pcNetwork txOutAddress
375-
, valueToCliArg txOutValue
373+
if Value.isZero txOutValue
374+
then []
375+
else
376+
mconcat
377+
[
378+
[ "--tx-out"
379+
, Text.intercalate
380+
"+"
381+
[ unsafeSerialiseAddress pabConf.pcNetwork txOutAddress
382+
, valueToCliArg txOutValue
383+
]
376384
]
377-
]
378-
, case txOutDatumHash of
379-
Nothing -> []
380-
Just datumHash@(DatumHash dh) ->
381-
if Map.member datumHash datums
382-
then ["--tx-out-datum-embed-file", datumJsonFilePath pabConf datumHash]
383-
else ["--tx-out-datum-hash", encodeByteString $ fromBuiltin dh]
384-
]
385+
, case txOutDatumHash of
386+
Nothing -> []
387+
Just datumHash@(DatumHash dh) ->
388+
if Map.member datumHash datums
389+
then ["--tx-out-datum-embed-file", datumJsonFilePath pabConf datumHash]
390+
else ["--tx-out-datum-hash", encodeByteString $ fromBuiltin dh]
391+
]
385392
)
386393

387394
networkOpt :: PABConfig -> [Text]

0 commit comments

Comments
 (0)