mirror of
https://github.com/lightningnetwork/lnd.git
synced 2024-11-19 01:43:16 +01:00
lnrpc: add new locked balance field for WalletBalance
In this commit, we add a new field to the WalletBalance call that permits users to account for the set of outputs that may be locked due to a pending transaction. Without this field any time users locked outputs for things like PSBT signing, then they disappear from the WalletBalance call, which may cause a panic.
This commit is contained in:
parent
d287884ff4
commit
4ecd153be2
File diff suppressed because it is too large
Load Diff
@ -2502,6 +2502,10 @@ message WalletBalanceResponse {
|
||||
// The unconfirmed balance of a wallet(with 0 confirmations)
|
||||
int64 unconfirmed_balance = 3;
|
||||
|
||||
// The total amount of wallet UTXOs held in outputs that are locked for
|
||||
// other usage.
|
||||
int64 locked_balance = 5;
|
||||
|
||||
// A mapping of each wallet account's name to its balance.
|
||||
map<string, WalletAccountBalance> account_balance = 4;
|
||||
}
|
||||
|
@ -6540,6 +6540,11 @@
|
||||
"format": "int64",
|
||||
"title": "The unconfirmed balance of a wallet(with 0 confirmations)"
|
||||
},
|
||||
"locked_balance": {
|
||||
"type": "string",
|
||||
"format": "int64",
|
||||
"description": "The total amount of wallet UTXOs held in outputs that are locked for\nother usage."
|
||||
},
|
||||
"account_balance": {
|
||||
"type": "object",
|
||||
"additionalProperties": {
|
||||
|
22
rpcserver.go
22
rpcserver.go
@ -3087,6 +3087,27 @@ func (r *rpcServer) WalletBalance(ctx context.Context,
|
||||
}
|
||||
}
|
||||
|
||||
// Now that we have the base balance accounted for with each account,
|
||||
// we'll look at the set of locked UTXOs to tally that as well. If we
|
||||
// don't display this, then anytime we attempt a funding reservation,
|
||||
// the outputs will chose as being "gone" until they're confirmed on
|
||||
// chain.
|
||||
var lockedBalance btcutil.Amount
|
||||
leases, err := r.server.cc.Wallet.ListLeasedOutputs()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, leasedOutput := range leases {
|
||||
utxoInfo, err := r.server.cc.Wallet.FetchInputInfo(
|
||||
&leasedOutput.Outpoint,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
lockedBalance += utxoInfo.Value
|
||||
}
|
||||
|
||||
rpcsLog.Debugf("[walletbalance] Total balance=%v (confirmed=%v, "+
|
||||
"unconfirmed=%v)", totalBalance, confirmedBalance,
|
||||
unconfirmedBalance)
|
||||
@ -3095,6 +3116,7 @@ func (r *rpcServer) WalletBalance(ctx context.Context,
|
||||
TotalBalance: int64(totalBalance),
|
||||
ConfirmedBalance: int64(confirmedBalance),
|
||||
UnconfirmedBalance: int64(unconfirmedBalance),
|
||||
LockedBalance: int64(lockedBalance),
|
||||
AccountBalance: rpcAccountBalances,
|
||||
}, nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user