Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix!: changes balance query #6158

Merged
merged 3 commits into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -264,10 +264,7 @@ 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
.saturating_sub(balance.time_locked_balance.unwrap_or_default())
.0,
available_balance: balance.available_balance.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
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ impl<B: Backend> Component<B> for Balance {
let available_balance = Spans::from(vec![
Span::styled("Available:", Style::default().fg(Color::Magenta)),
Span::raw(" "),
Span::raw(format!("{}", balance.available_balance.saturating_sub(time_locked))),
Span::raw(format!("{}", balance.available_balance)),
Span::raw(format!(" (Time Locked: {})", time_locked)),
]);
let incoming_balance = Spans::from(vec![
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,9 @@ impl BalanceEnquiryDebouncer {
if let Ok(balance) = self.output_manager_service.get_balance().await {
trace!(
target: LOG_TARGET,
"Initial balance: available {}, incoming {}, outgoing {}",
"Initial balance: available {}, time-locked {}, incoming {}, outgoing {}",
balance.available_balance,
balance.time_locked_balance.unwrap_or(0.into()),
balance.pending_incoming_balance,
balance.pending_outgoing_balance
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ impl OutputSql {
let balance_query_result = if let Some(current_tip) = current_tip_for_time_lock_calculation {
let balance_query = sql_query(
"SELECT coalesce(sum(value), 0) as amount, 'available_balance' as category \
FROM outputs WHERE status = ? \
FROM outputs WHERE status = ? AND maturity <= ? AND script_lock_height <= ? \
UNION ALL \
SELECT coalesce(sum(value), 0) as amount, 'time_locked_balance' as category \
FROM outputs WHERE status = ? AND maturity > ? OR script_lock_height > ? \
Expand All @@ -407,6 +407,8 @@ impl OutputSql {
)
// available_balance
.bind::<diesel::sql_types::Integer, _>(OutputStatus::Unspent as i32)
.bind::<diesel::sql_types::BigInt, _>(current_tip as i64)
.bind::<diesel::sql_types::BigInt, _>(current_tip as i64)
// time_locked_balance
.bind::<diesel::sql_types::Integer, _>(OutputStatus::Unspent as i32)
.bind::<diesel::sql_types::BigInt, _>(current_tip as i64)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ pub async fn test_db_backend<T: OutputManagerBackend + 'static>(backend: T) {

let balance = db.get_balance(Some(3)).unwrap();
assert_eq!(balance, Balance {
available_balance,
available_balance: available_balance - time_locked_balance,
time_locked_balance: Some(time_locked_balance),
pending_incoming_balance,
pending_outgoing_balance
Expand Down
Loading