Skip to content

Commit

Permalink
Add CLI parser for new multi-asset tx output value format
Browse files Browse the repository at this point in the history
  • Loading branch information
intricate committed Nov 30, 2020
1 parent 9059a7b commit 1b5494b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 17 deletions.
30 changes: 14 additions & 16 deletions cardano-cli/src/Cardano/CLI/Shelley/Parsers.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import Cardano.Api.Protocol (Protocol (..))
import Cardano.Api.Typed hiding (PoolId)

import Cardano.Chain.Slotting (EpochSlots (..))
import Cardano.CLI.Mary.TxOutParser (renderTxOutAnyEraParseError, stringToTxOutAnyEra)
import Cardano.CLI.Mary.ValueParser (renderValueParseError, stringToValue)
import Cardano.CLI.Shelley.Commands
import Cardano.CLI.Shelley.Key (InputFormat (..), VerificationKeyOrFile (..),
VerificationKeyOrHashOrFile (..), VerificationKeyTextOrFile (..),
Expand Down Expand Up @@ -1551,22 +1553,18 @@ parseTxIx = toEnum <$> Atto.decimal

pTxOut :: Parser TxOutAnyEra
pTxOut =
Opt.option (readerFromAttoParser parseTxOut)
( Opt.long "tx-out"
<> Opt.metavar "TX-OUT"
<> Opt.help "The transaction output as Address+Lovelace where Address is \
\the Bech32-encoded address followed by the amount in \
\Lovelace."
)
Opt.option (eitherReader readTxOut)
( Opt.long "tx-out"
<> Opt.metavar "TX-OUT"
-- TODO: Update the help text to describe the new syntax as well.
<> Opt.help "The transaction output as Address+Lovelace where Address is \
\the Bech32-encoded address followed by the amount in \
\Lovelace."
)
where
parseTxOut :: Atto.Parser TxOutAnyEra
parseTxOut =
TxOutAnyEra <$> parseAddressAny
<* Atto.char '+'
<*> pAdaOnlyValue

pAdaOnlyValue :: Atto.Parser Value
pAdaOnlyValue = lovelaceToValue <$> parseLovelace
readTxOut :: String -> Either String TxOutAnyEra
readTxOut =
first (Text.unpack . renderTxOutAnyEraParseError) . stringToTxOutAnyEra

pMintMultiAsset :: Parser Value
pMintMultiAsset =
Expand All @@ -1578,7 +1576,7 @@ pMintMultiAsset =
)

readValue :: String -> Either String Value
readValue _maCliSyntax = Left "Need 2072 for MA cli syntax parser"
readValue = first (Text.unpack . renderValueParseError) . stringToValue

pTxLowerBound :: Parser SlotNo
pTxLowerBound =
Expand Down
1 change: 0 additions & 1 deletion cardano-cli/src/Cardano/CLI/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,3 @@ withCardanoEra UseMaryEra f = f MaryEra
--
data TxOutAnyEra = TxOutAnyEra AddressAny Value
deriving (Eq, Show)

0 comments on commit 1b5494b

Please sign in to comment.