From 56fa3fe8f281cd79dc4f2aaa7cab02a253063dd0 Mon Sep 17 00:00:00 2001 From: "nicolas.dorier" Date: Wed, 23 Aug 2023 16:11:25 +0900 Subject: [PATCH] Fix crash on /wallets/transactions with non zero skip parameter (Fix #5183) --- BTCPayServer.Client/BTCPayServerClient.OnChainWallet.cs | 6 +++++- BTCPayServer.Tests/GreenfieldAPITests.cs | 3 +++ .../Controllers/GreenField/LocalBTCPayServerClient.cs | 2 +- BTCPayServer/Services/Wallets/BTCPayWallet.cs | 2 +- 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/BTCPayServer.Client/BTCPayServerClient.OnChainWallet.cs b/BTCPayServer.Client/BTCPayServerClient.OnChainWallet.cs index 449ad33c2..e34cc6d95 100644 --- a/BTCPayServer.Client/BTCPayServerClient.OnChainWallet.cs +++ b/BTCPayServer.Client/BTCPayServerClient.OnChainWallet.cs @@ -55,7 +55,7 @@ namespace BTCPayServer.Client } public virtual async Task> ShowOnChainWalletTransactions( - string storeId, string cryptoCode, TransactionStatus[] statusFilter = null, string labelFilter = null, + string storeId, string cryptoCode, TransactionStatus[] statusFilter = null, string labelFilter = null, int skip = 0, CancellationToken token = default) { var query = new Dictionary(); @@ -67,6 +67,10 @@ namespace BTCPayServer.Client { query.Add(nameof(labelFilter), labelFilter); } + if (skip != 0) + { + query.Add(nameof(skip), skip); + } var response = await _httpClient.SendAsync( CreateHttpRequest($"api/v1/stores/{storeId}/payment-methods/onchain/{cryptoCode}/wallet/transactions", query), token); diff --git a/BTCPayServer.Tests/GreenfieldAPITests.cs b/BTCPayServer.Tests/GreenfieldAPITests.cs index 6242c8c92..0209dfbd2 100644 --- a/BTCPayServer.Tests/GreenfieldAPITests.cs +++ b/BTCPayServer.Tests/GreenfieldAPITests.cs @@ -3212,6 +3212,9 @@ namespace BTCPayServer.Tests }); var transaction = await client.GetOnChainWalletTransaction(walletId.StoreId, walletId.CryptoCode, txdata.TransactionHash.ToString()); + // Check skip doesn't crash + await client.ShowOnChainWalletTransactions(walletId.StoreId, walletId.CryptoCode, skip: 1); + Assert.Equal(transaction.TransactionHash, txdata.TransactionHash); Assert.Equal(String.Empty, transaction.Comment); #pragma warning disable CS0612 // Type or member is obsolete diff --git a/BTCPayServer/Controllers/GreenField/LocalBTCPayServerClient.cs b/BTCPayServer/Controllers/GreenField/LocalBTCPayServerClient.cs index fdb0286a2..e82a94ffd 100644 --- a/BTCPayServer/Controllers/GreenField/LocalBTCPayServerClient.cs +++ b/BTCPayServer/Controllers/GreenField/LocalBTCPayServerClient.cs @@ -759,7 +759,7 @@ namespace BTCPayServer.Controllers.Greenfield } public override async Task> ShowOnChainWalletTransactions( - string storeId, string cryptoCode, TransactionStatus[] statusFilter = null, string labelFilter = null, + string storeId, string cryptoCode, TransactionStatus[] statusFilter = null, string labelFilter = null, int skip = 0, CancellationToken token = default) { return GetFromActionResult>( diff --git a/BTCPayServer/Services/Wallets/BTCPayWallet.cs b/BTCPayServer/Services/Wallets/BTCPayWallet.cs index 3af082c06..ae79d8bf3 100644 --- a/BTCPayServer/Services/Wallets/BTCPayWallet.cs +++ b/BTCPayServer/Services/Wallets/BTCPayWallet.cs @@ -252,7 +252,7 @@ namespace BTCPayServer.Services.Wallets { wallet_id = NBXplorer.Client.DBUtils.nbxv1_get_wallet_id(Network.CryptoCode, derivationStrategyBase.ToString()), code = Network.CryptoCode, - count = count, + count = count == int.MaxValue ? null : count, skip = skip, interval = interval is TimeSpan t ? t : TimeSpan.FromDays(365 * 1000) },