Skip to content

Commit

Permalink
Add transaction list CLI command.
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanknowles committed Jul 16, 2019
1 parent bde5cce commit 19d982b
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions lib/cli/src/Cardano/CLI.hs
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,7 @@ cmdWalletDelete = command "delete" $ info (helper <*> cmd) $ mempty
cardano-wallet transaction create [--port=INT] <wallet-id> --payment=PAYMENT...
cardano-wallet transaction fees [--port=INT] <wallet-id> --payment=PAYMENT...
cardano-wallet transaction list [--port=INT] <wallet-id> [--after=TIME] [--before=TIME]
-------------------------------------------------------------------------------}

-- | cardano-wallet transaction
Expand All @@ -502,6 +503,7 @@ cmdTransaction = command "transaction" $ info (helper <*> cmds) mempty
cmds = subparser $ mempty
<> cmdTransactionCreate @t
<> cmdTransactionFees @t
<> cmdTransactionList @t

-- | Arguments for 'transaction create' command
data TransactionCreateArgs t = TransactionCreateArgs
Expand Down Expand Up @@ -554,6 +556,34 @@ cmdTransactionFees = command "fees" $ info (helper <*> cmd) $ mempty
Left _ ->
handleResponse Aeson.encodePretty res

-- | Arguments for 'transaction list' command.
data TransactionListArgs = TransactionListArgs
{ _port :: Port "Wallet"
, _walletId :: WalletId
, _timeAfter :: Maybe Iso8601Time
, _timeBefore :: Maybe Iso8601Time
}

-- cardano-wallet transaction list [--port=INT] <wallet-id> [--after=TIME] [--before=TIME]
cmdTransactionList
:: forall t. (DecodeAddress t, EncodeAddress t)
=> Mod CommandFields (IO ())
cmdTransactionList = command "list" $ info (helper <*> cmd) $ mempty
<> progDesc "List the transactions associated with a wallet"
where
cmd = fmap exec $ TransactionListArgs
<$> portOption
<*> walletIdArgument
<*> optional timeAfterOption
<*> optional timeBeforeOption
exec (TransactionListArgs wPort wId mTimeAfter mTimeBefore) =
runClient wPort Aeson.encodePretty $ listTransactions
(walletClient @t)
(ApiT wId)
(pure $ Iso8601Range
(getIso8601Time <$> mTimeAfter)
(getIso8601Time <$> mTimeBefore))

{-------------------------------------------------------------------------------
Commands - 'address'
Expand Down Expand Up @@ -717,6 +747,22 @@ stateDirOption = optionT $ mempty
<> value "$HOME/.cardano-wallet"
<> showDefaultWith show

-- | [--after=TIME]
timeAfterOption :: Parser Iso8601Time
timeAfterOption = optionT $ mempty
<> long "after"
<> metavar "TIME"
<> help "specifies an earliest time"
<> showDefaultWith showT

-- | [--before=TIME]
timeBeforeOption :: Parser Iso8601Time
timeBeforeOption = optionT $ mempty
<> long "before"
<> metavar "TIME"
<> help "specifies a latest time"
<> showDefaultWith showT

-- | [(--quiet|--verbose)]
verbosityOption :: Parser Verbosity
verbosityOption = (Quiet <$ quiet) <|> (Verbose <$ verbose) <|> (pure Default)
Expand Down

0 comments on commit 19d982b

Please sign in to comment.