Skip to content

Commit 8f88aae

Browse files
committed
Address review comments: fix pLovelaceCoin and align babbageDatumFields
- pLovelaceCoin: parse lovelace as Integer; reject negatives with a clear error - babbageDatumFields TxOutDatumByValue: convert to ledger data first then hash, matching alonzoDatumFields pattern and avoiding a redundant toAlonzoData call
1 parent c99fdc4 commit 8f88aae

2 files changed

Lines changed: 12 additions & 8 deletions

File tree

cardano-cli/src/Cardano/CLI/Byron/Parser.hs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,11 @@ parseTxIxAtto = toEnum <$> Atto.decimal
285285
parseTxOut :: Parser (Address ByronAddr, L.Coin)
286286
parseTxOut =
287287
Opt.option
288-
((\(addr, lovelace) -> (parseByronAddr addr, pLovelaceCoin lovelace)) <$> auto)
288+
( do
289+
(addr, lovelace) <- auto
290+
coin <- pLovelaceCoin lovelace
291+
pure (parseByronAddr addr, coin)
292+
)
289293
$ long "txout"
290294
<> metavar "'(\"ADDR\", LOVELACE)'"
291295
<> help "Specify a transaction output, as a pair of an address and lovelace."
@@ -296,11 +300,10 @@ parseTxOut =
296300
Left err -> error $ "Bad Base58 address: " <> show err
297301
Right byronAddress -> ByronAddress byronAddress
298302

299-
pLovelaceCoin :: Word64 -> L.Coin
300-
pLovelaceCoin l =
301-
if l > (maxBound :: Word64)
302-
then error $ show l <> " lovelace exceeds the Word64 upper bound"
303-
else L.Coin $ toInteger l
303+
pLovelaceCoin :: Integer -> Opt.ReadM L.Coin
304+
pLovelaceCoin l
305+
| l < 0 = Opt.readerError $ show l <> " lovelace is negative"
306+
| otherwise = pure $ L.Coin l
304307

305308
readerFromAttoParser :: Atto.Parser a -> Opt.ReadM a
306309
readerFromAttoParser p =

cardano-cli/src/Cardano/CLI/Compatible/Transaction/TxOut.hs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,9 @@ babbageDatumFields = \case
113113
pure (L.DatumHash (unScriptDataHash (hashScriptDataBytes sData)), mempty)
114114
TxOutDatumByValue sDataOrFile -> do
115115
sData <- fromExceptTCli $ readScriptDataOrFile sDataOrFile
116-
let dh = unScriptDataHash (hashScriptDataBytes sData)
117-
pure (L.DatumHash dh, Map.singleton dh (toAlonzoData sData))
116+
let ld = toAlonzoData sData
117+
dh = L.hashData ld
118+
pure (L.DatumHash dh, Map.singleton dh ld)
118119
TxOutInlineDatumByValue sDataOrFile -> do
119120
sData <- fromExceptTCli $ readScriptDataOrFile sDataOrFile
120121
pure (scriptDataToInlineDatum sData, mempty)

0 commit comments

Comments
 (0)