mirror of
https://github.com/aljazceru/btcpayserver.git
synced 2025-12-18 06:24:24 +01:00
Provide more data through OnChain Wallet API (#2420)
Provides unconf/conf balanaces, keypath + address + timestamp of utxos
This commit is contained in:
@@ -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; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<string, LabelData> Labels { get; set; }
|
||||
[JsonConverter(typeof(DateTimeToUnixTimeConverter))]
|
||||
public DateTimeOffset Timestamp { get; set; }
|
||||
[JsonConverter(typeof(KeyPathJsonConverter))]
|
||||
public KeyPath KeyPath { get; set; }
|
||||
public string Address { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
);
|
||||
|
||||
@@ -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<string> 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 "--";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -263,13 +263,13 @@ namespace BTCPayServer.Services.Wallets
|
||||
}).ToArray();
|
||||
}
|
||||
|
||||
public Task<decimal> GetBalance(DerivationStrategyBase derivationStrategy, CancellationToken cancellation = default(CancellationToken))
|
||||
public Task<GetBalanceResponse> 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;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user