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
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 8 deletions

View File

@ -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<IActionResult> ShowOnChainWalletTransactions(string storeId, string cryptoCode,
[FromQuery]TransactionStatus[] statusFilter = null)
public async Task<IActionResult> 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<string, LabelData>(),
Comment = walletTransactionsInfoAsync?.Comment ?? string.Empty,
Labels = walletTransactionsInfoAsync?.Labels ?? new Dictionary<string, LabelData>(),
Amount = tx.BalanceChange.GetValue(wallet.Network),
BlockHash = tx.BlockHash,
BlockHeight = tx.Height,

View File

@ -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",