From d44efce2251001cbfaab5d5913f93786bde3244d Mon Sep 17 00:00:00 2001 From: "nicolas.dorier" Date: Wed, 11 Oct 2023 21:49:51 +0900 Subject: [PATCH] Simplify code --- .../Reporting/OnChainWalletReportProvider.cs | 36 +++++++++---------- 1 file changed, 16 insertions(+), 20 deletions(-) diff --git a/BTCPayServer/Services/Reporting/OnChainWalletReportProvider.cs b/BTCPayServer/Services/Reporting/OnChainWalletReportProvider.cs index 2cdf3172f..7e8b06df2 100644 --- a/BTCPayServer/Services/Reporting/OnChainWalletReportProvider.cs +++ b/BTCPayServer/Services/Reporting/OnChainWalletReportProvider.cs @@ -81,12 +81,13 @@ public class OnChainWalletReportProvider : ReportProvider var walletId = new WalletId(store.Id, settings.Network.CryptoCode); var command = new CommandDefinition( commandText: - "SELECT r.tx_id, r.seen_at, t.blk_id, t.blk_height, r.balance_change, r.asset_id " + - "FROM get_wallets_recent(@wallet_id, @code, @interval, NULL, NULL) r " + + "SELECT r.tx_id, r.seen_at, t.blk_id, t.blk_height, r.balance_change " + + "FROM get_wallets_recent(@wallet_id, @code, @asset_id, @interval, NULL, NULL) r " + "JOIN txs t USING (code, tx_id) " + "ORDER BY r.seen_at", parameters: new { + asset_id = GetAssetId(settings.Network), wallet_id = NBXplorer.Client.DBUtils.nbxv1_get_wallet_id(settings.Network.CryptoCode, settings.AccountDerivation.ToString()), code = settings.Network.CryptoCode, interval @@ -99,24 +100,6 @@ public class OnChainWalletReportProvider : ReportProvider var date = (DateTimeOffset)r.seen_at; if (date > queryContext.To) continue; - -#if ALTCOINS - if (settings.Network is ElementsBTCPayNetwork elementsBTCPayNetwork) - { - var assetId = (string?)r.asset_id; - // if this is an asset scheme, check if the asset id is the same as the network asset id - if (elementsBTCPayNetwork.CryptoCode != elementsBTCPayNetwork.NetworkCryptoCode && - assetId is not null && assetId != elementsBTCPayNetwork.AssetId?.ToString()) - { - continue; - } - else if (elementsBTCPayNetwork.CryptoCode == elementsBTCPayNetwork.NetworkCryptoCode && - !(assetId is null || assetId == elementsBTCPayNetwork.AssetId?.ToString())) - { - continue; - } - } -#endif var values = queryContext.AddData(); var balanceChange = Money.Satoshis((long)r.balance_change).ToDecimal(MoneyUnit.BTC); values.Add(date); @@ -141,4 +124,17 @@ public class OnChainWalletReportProvider : ReportProvider } } } + + private string? GetAssetId(BTCPayNetwork network) + { +#if ALTCOINS + if (network is ElementsBTCPayNetwork elNetwork) + { + if (elNetwork.CryptoCode == elNetwork.NetworkCryptoCode) + return ""; + return elNetwork.AssetId.ToString(); + } +#endif + return null; + } }