Skip to content

Commit

Permalink
fix(wallet-grpc): return correct available balance and add timelocked…
Browse files Browse the repository at this point in the history
…_balance (#5181)

Description
---
get_balance call to returns timelocked_balance
get_balance call returns funds that are immediately spendable

Motivation and Context
---
Calls to get_balance seemingly do not yield the correct balance, e.g your wallet ui says available balance == 0 but the grpc call says available_balance > 0 (because it includes the timelocked funds). This PR changes the available_balance to reflect the amount of funds immediately spendable. This only happens on the grpc level to avoid a breaking change in other code (FFI etc)

How Has This Been Tested?
---
Existing cucumber. Tested with VN that queries the balance.

<!-- Does this include a breaking change? If so, include this line as a footer -->
BREAKING CHANGE: get_balance grpc call has changed, available_balance no longer includes timelocked funds only immediately available funds. This probably only is used currently in cucumber tests.
  • Loading branch information
sdbondi authored Feb 14, 2023
1 parent d732845 commit e001125
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions applications/tari_app_grpc/proto/wallet.proto
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ message GetBalanceResponse {
uint64 available_balance = 1;
uint64 pending_incoming_balance = 2;
uint64 pending_outgoing_balance = 3;
uint64 timelocked_balance = 4;
}

message GetUnspentAmountsResponse {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,9 +266,13 @@ impl wallet_server::Wallet for WalletGrpcServer {
Err(e) => return Err(Status::not_found(format!("GetBalance error! {}", e))),
};
Ok(Response::new(GetBalanceResponse {
available_balance: balance.available_balance.0,
available_balance: balance
.available_balance
.saturating_sub(balance.time_locked_balance.unwrap_or_default())
.0,
pending_incoming_balance: balance.pending_incoming_balance.0,
pending_outgoing_balance: balance.pending_outgoing_balance.0,
timelocked_balance: balance.time_locked_balance.unwrap_or_default().0,
}))
}

Expand Down

0 comments on commit e001125

Please sign in to comment.