1
module Cardano.CLI.Mary.TxOutParser
7
import Data.Char (isAsciiLower, isAsciiUpper, isDigit)
8
import Data.Text (Text)
9
import qualified Data.Text as Text
11
import Control.Applicative (some)
12
import Text.Parsec (option, satisfy, (<?>))
13
import Text.Parsec.Char (char, spaces)
14
import Text.Parsec.String (Parser)
16
import Cardano.Api (AddressAny (..), AsType (..), deserialiseAddress)
17
import Cardano.CLI.Mary.ValueParser (parseValue)
18
import Cardano.CLI.Types (TxOutAnyEra (..))
21
parseTxOutAnyEra :: Parser TxOutAnyEra
23
addr <- parseAddressAny
25
-- Accept the old style of separating the address and value in a
26
-- transaction output:
27
option () (char '+' >> spaces)
28
TxOutAnyEra addr <$> parseValue
30
parseAddressAny :: Parser AddressAny
32
str <- plausibleAddressString <?> "address"
33
case deserialiseAddress AsAddressAny str of
34
Nothing -> fail "expecting valid address"
35
Just addr -> pure addr
37
plausibleAddressString :: Parser Text
38
plausibleAddressString =
39
Text.pack <$> some (satisfy isPlausibleAddressChar)
41
-- Covers both base58 and bech32 (with constrained prefixes)
42
isPlausibleAddressChar c =