Add "skip" and "limit" params for onchain txs API endpoint (#2688)

Discussed here: https://github.com/btcpayserver/btcpayserver/discussions/2667
This commit is contained in:
Umar Bolatov
2021-07-09 21:04:01 -07:00
committed by GitHub
parent 55cc32ce0f
commit aefb81b7f0
2 changed files with 32 additions and 8 deletions

View File

@@ -1,3 +1,4 @@
#nullable enable
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Globalization; using System.Globalization;
@@ -156,8 +157,13 @@ namespace BTCPayServer.Controllers.GreenField
[Authorize(Policy = Policies.CanModifyStoreSettings, AuthenticationSchemes = AuthenticationSchemes.Greenfield)] [Authorize(Policy = Policies.CanModifyStoreSettings, AuthenticationSchemes = AuthenticationSchemes.Greenfield)]
[HttpGet("~/api/v1/stores/{storeId}/payment-methods/onchain/{cryptoCode}/wallet/transactions")] [HttpGet("~/api/v1/stores/{storeId}/payment-methods/onchain/{cryptoCode}/wallet/transactions")]
public async Task<IActionResult> ShowOnChainWalletTransactions(string storeId, string cryptoCode, public async Task<IActionResult> ShowOnChainWalletTransactions(
[FromQuery]TransactionStatus[] statusFilter = null) string storeId,
string cryptoCode,
[FromQuery] TransactionStatus[]? statusFilter = null,
[FromQuery] int skip = 0,
[FromQuery] int limit = int.MaxValue
)
{ {
if (IsInvalidWalletRequest(cryptoCode, out BTCPayNetwork network, if (IsInvalidWalletRequest(cryptoCode, out BTCPayNetwork network,
out DerivationSchemeSettings derivationScheme, out IActionResult actionResult)) return actionResult; out DerivationSchemeSettings derivationScheme, out IActionResult actionResult)) return actionResult;
@@ -183,7 +189,7 @@ namespace BTCPayServer.Controllers.GreenField
filteredFlatList.AddRange(txs.ReplacedTransactions.Transactions); 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); walletTransactionsInfoAsync.TryGetValue(information.TransactionId.ToString(), out var transactionInfo);
return ToModel(transactionInfo, information, wallet); return ToModel(transactionInfo, information, wallet);
@@ -297,7 +303,7 @@ namespace BTCPayServer.Controllers.GreenField
subtractFeesOutputsCount.Add(index); subtractFeesOutputsCount.Add(index);
} }
BitcoinUrlBuilder bip21 = null; BitcoinUrlBuilder? bip21 = null;
var amount = destination.Amount; var amount = destination.Amount;
if (amount.GetValueOrDefault(0) <= 0) if (amount.GetValueOrDefault(0) <= 0)
{ {
@@ -542,15 +548,15 @@ namespace BTCPayServer.Controllers.GreenField
return paymentMethod; return paymentMethod;
} }
private OnChainWalletTransactionData ToModel(WalletTransactionInfo walletTransactionsInfoAsync, private OnChainWalletTransactionData ToModel(WalletTransactionInfo? walletTransactionsInfoAsync,
TransactionInformation tx, TransactionInformation tx,
BTCPayWallet wallet) BTCPayWallet wallet)
{ {
return new OnChainWalletTransactionData() return new OnChainWalletTransactionData()
{ {
TransactionHash = tx.TransactionId, TransactionHash = tx.TransactionId,
Comment = walletTransactionsInfoAsync?.Comment?? string.Empty, Comment = walletTransactionsInfoAsync?.Comment ?? string.Empty,
Labels = walletTransactionsInfoAsync?.Labels?? new Dictionary<string, LabelData>(), Labels = walletTransactionsInfoAsync?.Labels ?? new Dictionary<string, LabelData>(),
Amount = tx.BalanceChange.GetValue(wallet.Network), Amount = tx.BalanceChange.GetValue(wallet.Network),
BlockHash = tx.BlockHash, BlockHash = tx.BlockHash,
BlockHeight = tx.Height, BlockHeight = tx.Height,

View File

@@ -263,13 +263,31 @@
"name": "statusFilter", "name": "statusFilter",
"in": "query", "in": "query",
"required": false, "required": false,
"description": "statuses to filter the transactions with", "description": "Statuses to filter the transactions with",
"schema": { "schema": {
"type": "array", "type": "array",
"items": { "items": {
"$ref": "#/components/schemas/TransactionStatus" "$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", "description": "Get store on-chain wallet transactions",