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 28, 2020
1 parent fffc175 commit e3021cf
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 9 deletions.
45 changes: 37 additions & 8 deletions cardano-cli/src/Cardano/CLI/Shelley/Parsers.hs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import Cardano.CLI.Shelley.Commands
import Cardano.CLI.Shelley.Key (InputFormat (..), VerificationKeyOrFile (..),
VerificationKeyOrHashOrFile (..), VerificationKeyTextOrFile (..),
deserialiseInput, renderInputDecodeError)
import Cardano.CLI.Mary.Parser (stringToValue)
import Cardano.CLI.Types
import Control.Monad.Fail (fail)
import Data.Attoparsec.Combinator ((<?>))
Expand All @@ -44,6 +45,7 @@ import qualified Data.Text.Encoding as Text
import qualified Options.Applicative as Opt
import qualified Shelley.Spec.Ledger.BaseTypes as Shelley
import qualified Shelley.Spec.Ledger.TxBody as Shelley
import qualified Text.ParserCombinators.Parsec.Error as Parsec

--
-- Shelley CLI command parsers
Expand Down Expand Up @@ -1551,13 +1553,25 @@ 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 (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."
)
<|>
TxOutAnyEra
<$> pAddressAny
<*>
Opt.option (eitherReader readValue)
( Opt.long "tx-out-value"
<> Opt.metavar "TX-OUT-VALUE"
<> Opt.help
("The transaction output value formatted in the new "
<> "multi-asset style."
)
)
where
parseTxOut :: Atto.Parser TxOutAnyEra
parseTxOut =
Expand All @@ -1568,6 +1582,14 @@ pTxOut =
pAdaOnlyValue :: Atto.Parser Value
pAdaOnlyValue = lovelaceToValue <$> parseLovelace

pAddressAny :: Parser AddressAny
pAddressAny =
Opt.option (readerFromAttoParser parseAddressAny)
( Opt.long "address"
<> Opt.metavar "ADDRESS"
<> Opt.help "A Cardano address."
)

pMintMultiAsset :: Parser Value
pMintMultiAsset =
Opt.option
Expand All @@ -1578,7 +1600,14 @@ pMintMultiAsset =
)

readValue :: String -> Either String Value
readValue _maCliSyntax = Left "Need 2072 for MA cli syntax parser"
readValue = first renderParseError . stringToValue
where
-- TODO: Improve error message
renderParseError :: Parsec.ParseError -> String
renderParseError =
intercalate ", "
. map Parsec.messageString
. Parsec.errorMessages

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 e3021cf

Please sign in to comment.