diff --git a/BTCPayServer.Client/Models/OnChainWalletOverviewData.cs b/BTCPayServer.Client/Models/OnChainWalletOverviewData.cs index b5c078c06..bee8f4d5e 100644 --- a/BTCPayServer.Client/Models/OnChainWalletOverviewData.cs +++ b/BTCPayServer.Client/Models/OnChainWalletOverviewData.cs @@ -7,5 +7,11 @@ namespace BTCPayServer.Client.Models { [JsonConverter(typeof(NumericStringJsonConverter))] public decimal Balance { get; set; } + [JsonConverter(typeof(NumericStringJsonConverter))] + public decimal UnconfirmedBalance { get; set; } + [JsonConverter(typeof(NumericStringJsonConverter))] + public decimal ConfirmedBalance { get; set; } + + public string Label { get; set; } } } diff --git a/BTCPayServer.Client/Models/OnChainWalletUTXOData.cs b/BTCPayServer.Client/Models/OnChainWalletUTXOData.cs index a10ffd1e1..21f028985 100644 --- a/BTCPayServer.Client/Models/OnChainWalletUTXOData.cs +++ b/BTCPayServer.Client/Models/OnChainWalletUTXOData.cs @@ -1,3 +1,4 @@ +using System; using System.Collections.Generic; using BTCPayServer.JsonConverters; using NBitcoin; @@ -14,7 +15,11 @@ namespace BTCPayServer.Client.Models [JsonConverter(typeof(OutpointJsonConverter))] public OutPoint Outpoint { get; set; } public string Link { get; set; } - public Dictionary Labels { get; set; } + [JsonConverter(typeof(DateTimeToUnixTimeConverter))] + public DateTimeOffset Timestamp { get; set; } + [JsonConverter(typeof(KeyPathJsonConverter))] + public KeyPath KeyPath { get; set; } + public string Address { get; set; } } } diff --git a/BTCPayServer/Controllers/GreenField/StoreOnChainWalletsController.cs b/BTCPayServer/Controllers/GreenField/StoreOnChainWalletsController.cs index b37f3c012..142b25819 100644 --- a/BTCPayServer/Controllers/GreenField/StoreOnChainWalletsController.cs +++ b/BTCPayServer/Controllers/GreenField/StoreOnChainWalletsController.cs @@ -84,9 +84,14 @@ namespace BTCPayServer.Controllers.GreenField out DerivationSchemeSettings derivationScheme, out IActionResult actionResult)) return actionResult; var wallet = _btcPayWalletProvider.GetWallet(network); + var balance = await wallet.GetBalance(derivationScheme.AccountDerivation); + return Ok(new OnChainWalletOverviewData() { - Balance = await wallet.GetBalance(derivationScheme.AccountDerivation) + Label = derivationScheme.ToPrettyString(), + Balance = balance.Total.GetValue(network), + UnconfirmedBalance= balance.Unconfirmed.GetValue(network), + ConfirmedBalance= balance.Confirmed.GetValue(network), }); } @@ -149,7 +154,6 @@ namespace BTCPayServer.Controllers.GreenField var wallet = _btcPayWalletProvider.GetWallet(network); var walletId = new WalletId(storeId, cryptoCode); - var walletBlobAsync = await _walletRepository.GetWalletInfo(walletId); var walletTransactionsInfoAsync = await _walletRepository.GetWalletTransactionsInfo(walletId); var txs = await wallet.FetchTransactions(derivationScheme.AccountDerivation); @@ -222,7 +226,10 @@ namespace BTCPayServer.Controllers.GreenField Comment = info?.Comment, Labels = info?.Labels, Link = string.Format(CultureInfo.InvariantCulture, network.BlockExplorerLink, - coin.OutPoint.Hash.ToString()) + coin.OutPoint.Hash.ToString()), + Timestamp = coin.Timestamp, + KeyPath = coin.KeyPath, + Address = network.NBXplorerNetwork.CreateAddress(derivationScheme.AccountDerivation, coin.KeyPath, coin.ScriptPubKey).ToString() }; }).ToList() ); diff --git a/BTCPayServer/Controllers/WalletsController.cs b/BTCPayServer/Controllers/WalletsController.cs index 56d68a7ff..02083a6d6 100644 --- a/BTCPayServer/Controllers/WalletsController.cs +++ b/BTCPayServer/Controllers/WalletsController.cs @@ -470,7 +470,7 @@ namespace BTCPayServer.Controllers .ToArray(); var balance = _walletProvider.GetWallet(network).GetBalance(paymentMethod.AccountDerivation); model.NBXSeedAvailable = await GetSeed(walletId, network) != null; - model.CurrentBalance = await balance; + model.CurrentBalance = (await balance).Total.GetValue(network); await Task.WhenAll(recommendedFees); model.RecommendedSatoshiPerByte = @@ -1029,17 +1029,14 @@ namespace BTCPayServer.Controllers private static async Task GetBalanceString(BTCPayWallet wallet, DerivationStrategyBase derivationStrategy) { - using (CancellationTokenSource cts = new CancellationTokenSource(TimeSpan.FromSeconds(10))) + using CancellationTokenSource cts = new CancellationTokenSource(TimeSpan.FromSeconds(10)); + try { - try - { - return (await wallet.GetBalance(derivationStrategy, cts.Token)).ShowMoney(wallet.Network - .Divisibility); - } - catch - { - return "--"; - } + return (await wallet.GetBalance(derivationStrategy, cts.Token)).Total.ShowMoney(wallet.Network); + } + catch + { + return "--"; } } diff --git a/BTCPayServer/Services/Wallets/BTCPayWallet.cs b/BTCPayServer/Services/Wallets/BTCPayWallet.cs index ddfa7fbb5..cf1da4f8c 100644 --- a/BTCPayServer/Services/Wallets/BTCPayWallet.cs +++ b/BTCPayServer/Services/Wallets/BTCPayWallet.cs @@ -263,13 +263,13 @@ namespace BTCPayServer.Services.Wallets }).ToArray(); } - public Task GetBalance(DerivationStrategyBase derivationStrategy, CancellationToken cancellation = default(CancellationToken)) + public Task GetBalance(DerivationStrategyBase derivationStrategy, CancellationToken cancellation = default(CancellationToken)) { return _MemoryCache.GetOrCreateAsync("CACHEDBALANCE_" + derivationStrategy.ToString(), async (entry) => { var result = await _Client.GetBalanceAsync(derivationStrategy, cancellation); entry.AbsoluteExpiration = DateTimeOffset.UtcNow + CacheSpan; - return result.Total.GetValue(_Network); + return result; }); } } 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 21755cebf..6727ab97e 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 @@ -511,7 +511,17 @@ "balance": { "type": "string", "format": "decimal", - "description": "The current balance of the wallet" + "description": "The total current balance of the wallet" + }, + "unconfirmedBalance": { + "type": "string", + "format": "decimal", + "description": "The current unconfirmed balance of the wallet" + }, + "confirmedBalance": { + "type": "string", + "format": "decimal", + "description": "The current confirmed balance of the wallet" } } }, @@ -654,6 +664,26 @@ "type": "string", "format": "{txid}:{outputIndex}", "description": "outpoint of this utxo" + }, + "timestamp": { + "description": "The time of the utxo", + "allOf": [ {"$ref": "#/components/schemas/UnixTimestamp"}] + }, + "keyPath": { + "type": "string", + "format": "keypath", + "description": "the derivation path in relation to the HD account" + }, + "address": { + "type": "string", + "description": "The wallet address of this utxo" + }, + "labels": { + "description": "Labels linked to this transaction", + "type": "object", + "additionalProperties": { + "$ref": "#/components/schemas/LabelData" + } } } },