From aefb81b7f0869101c6f5ecb98acbe6e107e10f5d Mon Sep 17 00:00:00 2001 From: Umar Bolatov Date: Fri, 9 Jul 2021 21:04:01 -0700 Subject: [PATCH] Add "skip" and "limit" params for onchain txs API endpoint (#2688) Discussed here: https://github.com/btcpayserver/btcpayserver/discussions/2667 --- .../StoreOnChainWalletsController.cs | 20 ++++++++++++------- ...agger.template.stores-wallet.on-chain.json | 20 ++++++++++++++++++- 2 files changed, 32 insertions(+), 8 deletions(-) diff --git a/BTCPayServer/Controllers/GreenField/StoreOnChainWalletsController.cs b/BTCPayServer/Controllers/GreenField/StoreOnChainWalletsController.cs index 07241870a..6e05f307d 100644 --- a/BTCPayServer/Controllers/GreenField/StoreOnChainWalletsController.cs +++ b/BTCPayServer/Controllers/GreenField/StoreOnChainWalletsController.cs @@ -1,3 +1,4 @@ +#nullable enable using System; using System.Collections.Generic; using System.Globalization; @@ -156,8 +157,13 @@ namespace BTCPayServer.Controllers.GreenField [Authorize(Policy = Policies.CanModifyStoreSettings, AuthenticationSchemes = AuthenticationSchemes.Greenfield)] [HttpGet("~/api/v1/stores/{storeId}/payment-methods/onchain/{cryptoCode}/wallet/transactions")] - public async Task ShowOnChainWalletTransactions(string storeId, string cryptoCode, - [FromQuery]TransactionStatus[] statusFilter = null) + public async Task ShowOnChainWalletTransactions( + string storeId, + string cryptoCode, + [FromQuery] TransactionStatus[]? statusFilter = null, + [FromQuery] int skip = 0, + [FromQuery] int limit = int.MaxValue + ) { if (IsInvalidWalletRequest(cryptoCode, out BTCPayNetwork network, out DerivationSchemeSettings derivationScheme, out IActionResult actionResult)) return actionResult; @@ -183,7 +189,7 @@ namespace BTCPayServer.Controllers.GreenField filteredFlatList.AddRange(txs.ReplacedTransactions.Transactions); } - var result = filteredFlatList.Select(information => + var result = filteredFlatList.Skip(skip).Take(limit).Select(information => { walletTransactionsInfoAsync.TryGetValue(information.TransactionId.ToString(), out var transactionInfo); return ToModel(transactionInfo, information, wallet); @@ -297,7 +303,7 @@ namespace BTCPayServer.Controllers.GreenField subtractFeesOutputsCount.Add(index); } - BitcoinUrlBuilder bip21 = null; + BitcoinUrlBuilder? bip21 = null; var amount = destination.Amount; if (amount.GetValueOrDefault(0) <= 0) { @@ -542,15 +548,15 @@ namespace BTCPayServer.Controllers.GreenField return paymentMethod; } - private OnChainWalletTransactionData ToModel(WalletTransactionInfo walletTransactionsInfoAsync, + private OnChainWalletTransactionData ToModel(WalletTransactionInfo? walletTransactionsInfoAsync, TransactionInformation tx, BTCPayWallet wallet) { return new OnChainWalletTransactionData() { TransactionHash = tx.TransactionId, - Comment = walletTransactionsInfoAsync?.Comment?? string.Empty, - Labels = walletTransactionsInfoAsync?.Labels?? new Dictionary(), + Comment = walletTransactionsInfoAsync?.Comment ?? string.Empty, + Labels = walletTransactionsInfoAsync?.Labels ?? new Dictionary(), Amount = tx.BalanceChange.GetValue(wallet.Network), BlockHash = tx.BlockHash, BlockHeight = tx.Height, diff --git a/BTCPayServer/wwwroot/swagger/v1/swagger.template.stores-wallet.on-chain.json b/BTCPayServer/wwwroot/swagger/v1/swagger.template.stores-wallet.on-chain.json index 4a357c639..f6eb4ee91 100644 --- a/BTCPayServer/wwwroot/swagger/v1/swagger.template.stores-wallet.on-chain.json +++ b/BTCPayServer/wwwroot/swagger/v1/swagger.template.stores-wallet.on-chain.json @@ -263,13 +263,31 @@ "name": "statusFilter", "in": "query", "required": false, - "description": "statuses to filter the transactions with", + "description": "Statuses to filter the transactions with", "schema": { "type": "array", "items": { "$ref": "#/components/schemas/TransactionStatus" } } + }, + { + "name": "skip", + "in": "query", + "required": false, + "description": "Number of transactions to skip from the start", + "schema": { + "type": "integer" + } + }, + { + "name": "limit", + "in": "query", + "required": false, + "description": "Maximum number of transactions to return", + "schema": { + "type": "integer" + } } ], "description": "Get store on-chain wallet transactions",