From dc3b4fdbf31ba6adf07b035ffe729a4cc06dc689 Mon Sep 17 00:00:00 2001 From: danda Date: Sat, 7 Oct 2023 13:09:34 -0700 Subject: [PATCH 1/2] add height to get_history() rpc and dashboard Returns `height` field from get_history() rpc and displays it in the dashboard's history screen. --- src/bin/dashboard_src/history_screen.rs | 20 ++++++++++++-------- src/rpc_server.rs | 8 ++++---- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/bin/dashboard_src/history_screen.rs b/src/bin/dashboard_src/history_screen.rs index 01a6dc360..09d616e6a 100644 --- a/src/bin/dashboard_src/history_screen.rs +++ b/src/bin/dashboard_src/history_screen.rs @@ -9,6 +9,7 @@ use chrono::{DateTime, Utc}; use crossterm::event::{Event, KeyCode, KeyEventKind}; use itertools::Itertools; use neptune_core::{ + models::blockchain::block::block_height::BlockHeight, models::blockchain::transaction::amount::{Amount, Sign}, rpc_server::RPCClient, }; @@ -23,7 +24,7 @@ use tokio::time::sleep; use tokio::{select, task::JoinHandle}; use unicode_width::UnicodeWidthStr; -type BalanceUpdate = (Duration, Amount, Sign, Amount); +type BalanceUpdate = (BlockHeight, Duration, Amount, Sign, Amount); type BalanceUpdateArc = Arc>>; type DashboardEventArc = Arc>>; type JoinHandleArc = Arc>>; @@ -148,7 +149,7 @@ impl HistoryScreen { let bh = rpc_client.get_history(context::current()).await.unwrap(); let mut history_builder = Vec::with_capacity(bh.len()); let mut balance = Amount::zero(); - for (timestamp, amount, sign) in bh.iter() { + for (block_height, timestamp, amount, sign) in bh.iter() { match sign { Sign::NonNegative => { balance = balance + *amount; } Sign::Negative => { @@ -158,7 +159,7 @@ impl HistoryScreen { }; } } - history_builder.push((*timestamp, *amount, *sign, balance)); + history_builder.push((*block_height, *timestamp, *amount, *sign, balance)); } *balance_updates.lock().unwrap() = history_builder; reset_poller!(balance_history, Duration::from_secs(10)); @@ -255,7 +256,8 @@ impl Widget for HistoryScreen { // table let style = Style::default().fg(self.fg).bg(self.bg); let selected_style = style.add_modifier(Modifier::REVERSED); - let header = vec!["date", " ", "amount", "balance after"]; + let header = vec!["height", "date", " ", "amount", "balance after"]; + let matrix = self .data .lock() @@ -263,15 +265,17 @@ impl Widget for HistoryScreen { .iter() .rev() .map(|bu| { + let (height, duration, amount, sign, balance) = *bu; vec![ - DateTime::::from(UNIX_EPOCH + bu.0).to_string(), - if bu.2 == Sign::NonNegative { + height.to_string(), + DateTime::::from(UNIX_EPOCH + duration).to_string(), + if sign == Sign::NonNegative { "↘".to_string() } else { "↗".to_string() }, - bu.1.to_string(), - bu.3.to_string(), + amount.to_string(), + balance.to_string(), ] }) .collect_vec(); diff --git a/src/rpc_server.rs b/src/rpc_server.rs index 61e33d083..5289d5e6a 100644 --- a/src/rpc_server.rs +++ b/src/rpc_server.rs @@ -79,7 +79,7 @@ pub trait RPC { // Get sum of unspent UTXOs. async fn get_synced_balance() -> Amount; - async fn get_history() -> Vec<(Duration, Amount, Sign)>; + async fn get_history() -> Vec<(BlockHeight, Duration, Amount, Sign)>; async fn get_wallet_status() -> WalletStatus; @@ -161,7 +161,7 @@ impl RPC for NeptuneRPCServer { type GetReceivingAddressFut = Ready; type GetMempoolTxCountFut = Ready; type GetMempoolSizeFut = Ready; - type GetHistoryFut = Ready>; + type GetHistoryFut = Ready>; type GetDashboardOverviewDataFut = Ready; type PauseMinerFut = Ready<()>; type RestartMinerFut = Ready<()>; @@ -346,9 +346,9 @@ impl RPC for NeptuneRPCServer { let history = executor::block_on(self.state.get_balance_history()); // sort - let mut display_history: Vec<(Duration, Amount, Sign)> = history + let mut display_history: Vec<(BlockHeight, Duration, Amount, Sign)> = history .iter() - .map(|(_h, t, _bh, a, s)| (*t, *a, *s)) + .map(|(_h, t, bh, a, s)| (*bh, *t, *a, *s)) .collect::>(); display_history.sort_by(|a, b| a.0.partial_cmp(&b.0).unwrap()); From 5a1f08c61dd508304a66836949d3e8f43c9db200 Mon Sep 17 00:00:00 2001 From: danda Date: Wed, 11 Oct 2023 10:52:38 -0700 Subject: [PATCH 2/2] adds block digest field to get_history() rpc Addresses https://github.com/Neptune-Crypto/neptune-core/pull/59#issuecomment-1751958112 --- src/bin/dashboard_src/history_screen.rs | 2 +- src/rpc_server.rs | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/bin/dashboard_src/history_screen.rs b/src/bin/dashboard_src/history_screen.rs index 09d616e6a..c9e077937 100644 --- a/src/bin/dashboard_src/history_screen.rs +++ b/src/bin/dashboard_src/history_screen.rs @@ -149,7 +149,7 @@ impl HistoryScreen { let bh = rpc_client.get_history(context::current()).await.unwrap(); let mut history_builder = Vec::with_capacity(bh.len()); let mut balance = Amount::zero(); - for (block_height, timestamp, amount, sign) in bh.iter() { + for (_, block_height, timestamp, amount, sign) in bh.iter() { match sign { Sign::NonNegative => { balance = balance + *amount; } Sign::Negative => { diff --git a/src/rpc_server.rs b/src/rpc_server.rs index 5289d5e6a..fc31a0997 100644 --- a/src/rpc_server.rs +++ b/src/rpc_server.rs @@ -79,7 +79,7 @@ pub trait RPC { // Get sum of unspent UTXOs. async fn get_synced_balance() -> Amount; - async fn get_history() -> Vec<(BlockHeight, Duration, Amount, Sign)>; + async fn get_history() -> Vec<(Digest, BlockHeight, Duration, Amount, Sign)>; async fn get_wallet_status() -> WalletStatus; @@ -161,7 +161,7 @@ impl RPC for NeptuneRPCServer { type GetReceivingAddressFut = Ready; type GetMempoolTxCountFut = Ready; type GetMempoolSizeFut = Ready; - type GetHistoryFut = Ready>; + type GetHistoryFut = Ready>; type GetDashboardOverviewDataFut = Ready; type PauseMinerFut = Ready<()>; type RestartMinerFut = Ready<()>; @@ -346,11 +346,11 @@ impl RPC for NeptuneRPCServer { let history = executor::block_on(self.state.get_balance_history()); // sort - let mut display_history: Vec<(BlockHeight, Duration, Amount, Sign)> = history + let mut display_history: Vec<(Digest, BlockHeight, Duration, Amount, Sign)> = history .iter() - .map(|(_h, t, bh, a, s)| (*bh, *t, *a, *s)) + .map(|(h, t, bh, a, s)| (*h, *bh, *t, *a, *s)) .collect::>(); - display_history.sort_by(|a, b| a.0.partial_cmp(&b.0).unwrap()); + display_history.sort_by(|a, b| a.1.partial_cmp(&b.1).unwrap()); // return future::ready(display_history)