Skip to content

Commit

Permalink
Add optional address parameter to listTransaction (#4004)
Browse files Browse the repository at this point in the history
<!--
Detail in a few bullet points the work accomplished in this PR.

Before you submit, don't forget to:

* Make sure the GitHub PR fields are correct:
   ✓ Set a good Title for your PR.
   ✓ Assign yourself to the PR.
   ✓ Assign one or more reviewer(s).
   ✓ Link to a Jira issue, and/or other GitHub issues or PRs.
   ✓ In the PR description delete any empty sections
     and all text commented in <!--, so that this text does not appear
     in merge commit messages.

* Don't waste reviewers' time:
   ✓ If it's a draft, select the Create Draft PR option.
✓ Self-review your changes to make sure nothing unexpected slipped
through.

* Try to make your intent clear:
   ✓ Write a good Description that explains what this PR is meant to do.
   ✓ Jira will detect and link to this PR once created, but you can also
     link this PR in the description of the corresponding Jira ticket.
   ✓ Highlight what Testing you have done.
   ✓ Acknowledge any changes required to the Documentation.
-->

- [x] Add support for optional address in api
- [x] Handle inputs, outputs, collateral inputs and collateral output
- [x] tests for shelley style
- [x] tests for byron style
- [x] tests for shared  style
- [x] swagger update

### Comments

<!-- Additional comments, links, or screenshots to attach, if any. -->

### Issue Number
https://cardanofoundation.atlassian.net/browse/ADP-2817
<!-- Reference the Jira/GitHub issue that this PR relates to, and which
requirements it tackles.
  Note: Jira issues of the form ADP- will be auto-linked. -->
  • Loading branch information
paweljakubas authored Jul 21, 2023
2 parents 3087946 + 212d85d commit 1388223
Show file tree
Hide file tree
Showing 25 changed files with 678 additions and 77 deletions.
1 change: 1 addition & 0 deletions lib/wallet/api/http/Cardano/CLI.hs
Original file line number Diff line number Diff line change
Expand Up @@ -948,6 +948,7 @@ cmdTransactionList mkTxClient =
mTimeRangeEnd
(ApiT <$> mOrder)
(ApiLimit <$> limit)
Nothing
(metadataSchema == TxMetadataNoSchema)

-- | Arguments for 'transaction submit' command
Expand Down
3 changes: 3 additions & 0 deletions lib/wallet/api/http/Cardano/Wallet/Api.hs
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,7 @@ type ListTransactions n = "wallets"
:> QueryParam "end" Iso8601Time
:> QueryParam "order" (ApiT SortOrder)
:> QueryParam "max_count" ApiLimit
:> QueryParam "address" (ApiAddressIdT n)
:> QueryFlag "simple-metadata"
:> Get '[JSON] [ApiTransactionT n]

Expand Down Expand Up @@ -924,6 +925,7 @@ type ListByronTransactions n = "byron-wallets"
:> QueryParam "end" Iso8601Time
:> QueryParam "order" (ApiT SortOrder)
:> QueryParam "max_count" ApiLimit
:> QueryParam "address" (ApiAddressIdT n)
:> Get '[JSON] [ApiTransactionT n]

-- | https://cardano-foundation.github.io/cardano-wallet/api/#operation/getByronTransaction
Expand Down Expand Up @@ -1188,6 +1190,7 @@ type ListSharedTransactions n = "shared-wallets"
:> QueryParam "end" Iso8601Time
:> QueryParam "order" (ApiT SortOrder)
:> QueryParam "max_count" ApiLimit
:> QueryParam "address" (ApiAddressIdT n)
:> QueryFlag "simple-metadata"
:> Get '[JSON] [ApiTransactionT n]

Expand Down
5 changes: 3 additions & 2 deletions lib/wallet/api/http/Cardano/Wallet/Api/Client.hs
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ data TransactionClient = TransactionClient
-> Maybe Iso8601Time
-> Maybe (ApiT SortOrder)
-> Maybe ApiLimit
-> Maybe (ApiAddressIdT Aeson.Value)
-> Bool
-> ClientM [ApiTransactionT Aeson.Value]
, signTransaction
Expand Down Expand Up @@ -366,8 +367,8 @@ byronTransactionClient =
= client (Proxy @("v2" :> Proxy_))

in TransactionClient
{ listTransactions = \wid start end order limit _ ->
_listTransactions wid start end order limit
{ listTransactions = \wid start end order limit addr _ ->
_listTransactions wid start end order limit addr
, postTransaction = _postTransaction
, postTransactionFee = _postTransactionFee
, postExternalTransaction = _postExternalTransaction . fromSerialisedTx
Expand Down
14 changes: 7 additions & 7 deletions lib/wallet/api/http/Cardano/Wallet/Api/Http/Server.hs
Original file line number Diff line number Diff line change
Expand Up @@ -335,9 +335,9 @@ server byron icarus shelley multisig spl ntp blockchainSource =
(getPoolLifeCycleStatus spl)
:<|> signTransaction shelley
:<|>
(\wid mMinWithdrawal mStart mEnd mOrder mLimit simpleMetadataFlag ->
(\wid mMinWithdrawal mStart mEnd mOrder mLimit mAddress simpleMetadataFlag ->
listTransactions shelley wid mMinWithdrawal mStart mEnd mOrder mLimit
(parseSimpleMetadataFlag simpleMetadataFlag)
mAddress (parseSimpleMetadataFlag simpleMetadataFlag)
)
:<|>
(\wid txId simpleMetadataFlag ->
Expand Down Expand Up @@ -479,14 +479,14 @@ server byron icarus shelley multisig spl ntp blockchainSource =

byronTransactions :: Server (ByronTransactions n)
byronTransactions =
(\wid r0 r1 s l -> withLegacyLayer wid
(\wid r0 r1 s l a -> withLegacyLayer wid
( byron
, listTransactions
byron wid Nothing r0 r1 s l TxMetadataDetailedSchema
byron wid Nothing r0 r1 s l a TxMetadataDetailedSchema
)
( icarus
, listTransactions
icarus wid Nothing r0 r1 s l TxMetadataDetailedSchema
icarus wid Nothing r0 r1 s l a TxMetadataDetailedSchema
)
)
:<|>
Expand Down Expand Up @@ -614,9 +614,9 @@ server byron icarus shelley multisig spl ntp blockchainSource =
(parseSimpleMetadataFlag simpleMetadataFlag)
)
:<|>
(\wid mMinWithdrawal mStart mEnd mOrder mLimit simpleMetadataFlag ->
(\wid mMinWithdrawal mStart mEnd mOrder mLimit mAddress simpleMetadataFlag ->
listTransactions apilayer wid mMinWithdrawal mStart mEnd mOrder
mLimit (parseSimpleMetadataFlag simpleMetadataFlag)
mLimit mAddress (parseSimpleMetadataFlag simpleMetadataFlag)
)

blocks :: Handler ApiBlockHeader
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2254,10 +2254,11 @@ listTransactions
-> Maybe Iso8601Time
-> Maybe (ApiT SortOrder)
-> Maybe ApiLimit
-> Maybe (ApiAddress n)
-> TxMetadataSchema
-> Handler [ApiTransaction n]
listTransactions
ctx (ApiT wid) mMinWithdrawal mStart mEnd mOrder mLimit metadataSchema =
ctx (ApiT wid) mMinWithdrawal mStart mEnd mOrder mLimit mAddress metadataSchema =
withWorkerCtx ctx wid liftE liftE $ \wrk -> do
txs <- liftHandler $
W.listTransactions wrk
Expand All @@ -2266,6 +2267,7 @@ listTransactions
(getIso8601Time <$> mEnd)
(maybe defaultSortOrder getApiT mOrder)
(fromApiLimit <$> mLimit)
(apiAddress <$> mAddress)
depo <- liftIO $ W.stakeKeyDeposit <$>
NW.currentProtocolParameters (wrk ^. networkLayer)
forM txs $ \tx ->
Expand Down
14 changes: 9 additions & 5 deletions lib/wallet/api/http/Cardano/Wallet/Api/Link.hs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ import Cardano.Wallet.Address.Derivation
import Cardano.Wallet.Address.Discovery.Shared
( CredentialType (..) )
import Cardano.Wallet.Api.Types
( ApiAddressInspectData (..)
( ApiAddress (..)
, ApiAddressInspectData (..)
, ApiPoolSpecifier
, ApiT (..)
, ApiTxId (ApiTxId)
Expand All @@ -144,7 +145,7 @@ import Cardano.Wallet.Api.Types.Transaction
import Cardano.Wallet.Primitive.Types
( SmashServer, SortOrder, WalletId (..) )
import Cardano.Wallet.Primitive.Types.Address
( AddressState )
( Address, AddressState )
import Cardano.Wallet.Primitive.Types.Coin
( Coin (..) )
import Cardano.Wallet.Primitive.Types.Hash
Expand Down Expand Up @@ -614,7 +615,7 @@ listTransactions
=> w
-> (Method, Text)
listTransactions w =
listTransactions' @style w Nothing Nothing Nothing Nothing Nothing
listTransactions' @style w Nothing Nothing Nothing Nothing Nothing Nothing

listTransactions'
:: forall (style :: WalletStyle) w.
Expand All @@ -627,8 +628,9 @@ listTransactions'
-> Maybe Iso8601Time
-> Maybe SortOrder
-> Maybe ApiLimit
-> Maybe Address
-> (Method, Text)
listTransactions' w minWithdrawal inf sup order limit = discriminate @style
listTransactions' w minWithdrawal inf sup order limit address = discriminate @style
(endpoint @(Api.ListTransactions Net)
(\mk -> mk
wid
Expand All @@ -637,11 +639,12 @@ listTransactions' w minWithdrawal inf sup order limit = discriminate @style
sup
(ApiT <$> order)
limit
(ApiAddress <$> address)
(toSimpleMetadataFlag TxMetadataDetailedSchema)
)
)
(endpoint @(Api.ListByronTransactions Net)
(\mk -> mk wid inf sup (ApiT <$> order) limit))
(\mk -> mk wid inf sup (ApiT <$> order) limit (ApiAddress <$> address)))
(endpoint @(Api.ListSharedTransactions Net)
(\mk -> mk
wid
Expand All @@ -650,6 +653,7 @@ listTransactions' w minWithdrawal inf sup order limit = discriminate @style
sup
(ApiT <$> order)
limit
(ApiAddress <$> address)
(toSimpleMetadataFlag TxMetadataDetailedSchema)
)
)
Expand Down
12 changes: 6 additions & 6 deletions lib/wallet/bench/api-bench.hs
Original file line number Diff line number Diff line change
Expand Up @@ -246,12 +246,12 @@ benchmarksSeq BenchmarkConfig{benchmarkName,ctx} = do
$ fmap (fromIntegral . length)
$ unsafeRunExceptT
$ W.listTransactions ctx
Nothing Nothing Nothing Descending Nothing
Nothing Nothing Nothing Descending Nothing Nothing

(_, listTransactionsLimitedTime) <- bench "listTransactions (max_count=50)"
$ unsafeRunExceptT
$ W.listTransactions ctx
Nothing Nothing Nothing Descending (Just 50)
Nothing Nothing Nothing Descending (Just 50) Nothing

(_, createMigrationPlanTime) <- bench "createMigrationPlan"
$ W.createMigrationPlan ctx Tx.NoWithdrawal
Expand Down Expand Up @@ -326,12 +326,12 @@ benchmarksShared BenchmarkConfig{benchmarkName,ctx} = do
$ fmap (fromIntegral . length)
$ unsafeRunExceptT
$ W.listTransactions ctx
Nothing Nothing Nothing Descending Nothing
Nothing Nothing Nothing Descending Nothing Nothing

(_, listTransactionsLimitedTime) <- bench "listTransactions (max_count=50)"
$ unsafeRunExceptT
$ W.listTransactions ctx
Nothing Nothing Nothing Descending (Just 50)
Nothing Nothing Nothing Descending (Just 50) Nothing

pure BenchSharedResults
{ benchName = benchmarkName
Expand Down Expand Up @@ -395,12 +395,12 @@ benchmarksRnd BenchmarkConfig{benchmarkName,ctx} = do
$ fmap (fromIntegral . length)
$ unsafeRunExceptT
$ W.listTransactions ctx
Nothing Nothing Nothing Descending Nothing
Nothing Nothing Nothing Descending Nothing Nothing

(_, listTransactionsLimitedTime) <- bench "listTransactions (max_count=50)"
$ unsafeRunExceptT
$ W.listTransactions ctx
Nothing Nothing Nothing Descending (Just 50)
Nothing Nothing Nothing Descending (Just 50) Nothing

(_, createMigrationPlanTime) <- bench "createMigrationPlan"
$ W.createMigrationPlan ctx Tx.NoWithdrawal
Expand Down
2 changes: 1 addition & 1 deletion lib/wallet/bench/db-bench.hs
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ benchReadTxHistory
-> DBLayerBench
-> IO [TransactionInfo]
benchReadTxHistory sortOrder (inf, sup) mstatus mlimit DBLayer{..} =
atomically $ readTransactions Nothing sortOrder range mstatus mlimit
atomically $ readTransactions Nothing sortOrder range mstatus mlimit Nothing
where
range = Range
(SlotNo . fromIntegral <$> inf)
Expand Down
8 changes: 4 additions & 4 deletions lib/wallet/bench/restore-bench.hs
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ benchmarksRnd network w wname
$ fmap (fromIntegral . length)
$ unsafeRunExceptT
$ W.listTransactions w Nothing Nothing Nothing Descending
Nothing
Nothing Nothing

-- To aid with debugging, write the current wallet state to the log:
let walletOverview = WalletOverview{utxo,addresses,transactions}
Expand All @@ -486,7 +486,7 @@ benchmarksRnd network w wname
(_, listTransactionsLimitedTime) <- bench "list transactions (max_count = 100)" $ do
unsafeRunExceptT
$ W.listTransactions w Nothing Nothing Nothing Descending
(Just 100)
(Just 100) Nothing

estimateFeesTime <-
withNonEmptyUTxO cp pending CannotEstimateFeeForWalletWithEmptyUTxO $
Expand Down Expand Up @@ -569,7 +569,7 @@ benchmarksSeq network w _wname
$ fmap (fromIntegral . length)
$ unsafeRunExceptT
$ W.listTransactions w Nothing Nothing Nothing Descending
Nothing
Nothing Nothing

-- To aid with debugging, write the current wallet state to the log:
let walletOverview = WalletOverview{utxo,addresses,transactions}
Expand All @@ -582,7 +582,7 @@ benchmarksSeq network w _wname
(_, listTransactionsLimitedTime) <- bench "list transactions (max_count = 100)" $ do
unsafeRunExceptT
$ W.listTransactions w Nothing Nothing Nothing Descending
(Just 100)
(Just 100) Nothing

estimateFeesTime <-
withNonEmptyUTxO cp pending CannotEstimateFeeForWalletWithEmptyUTxO $
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2712,6 +2712,7 @@ listTransactions ctx w mStart mEnd mOrder mLimit = do
(Iso8601Time <$> mEnd)
mOrder
mLimit
Nothing

-- | Delete all wallets
deleteAllWallets :: Context -> IO ()
Expand Down
Loading

0 comments on commit 1388223

Please sign in to comment.