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

Height in history pr #59

Merged
merged 2 commits into from
Oct 15, 2023
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
20 changes: 12 additions & 8 deletions src/bin/dashboard_src/history_screen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand All @@ -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<std::sync::Mutex<Vec<BalanceUpdate>>>;
type DashboardEventArc = Arc<std::sync::Mutex<Option<DashboardEvent>>>;
type JoinHandleArc = Arc<Mutex<JoinHandle<()>>>;
Expand Down Expand Up @@ -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 => {
Expand All @@ -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));
Expand Down Expand Up @@ -255,23 +256,26 @@ 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()
.unwrap()
.iter()
.rev()
.map(|bu| {
let (height, duration, amount, sign, balance) = *bu;
vec![
DateTime::<Utc>::from(UNIX_EPOCH + bu.0).to_string(),
if bu.2 == Sign::NonNegative {
height.to_string(),
DateTime::<Utc>::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();
Expand Down
10 changes: 5 additions & 5 deletions src/rpc_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<(Digest, BlockHeight, Duration, Amount, Sign)>;

async fn get_wallet_status() -> WalletStatus;

Expand Down Expand Up @@ -161,7 +161,7 @@ impl RPC for NeptuneRPCServer {
type GetReceivingAddressFut = Ready<generation_address::ReceivingAddress>;
type GetMempoolTxCountFut = Ready<usize>;
type GetMempoolSizeFut = Ready<usize>;
type GetHistoryFut = Ready<Vec<(Duration, Amount, Sign)>>;
type GetHistoryFut = Ready<Vec<(Digest, BlockHeight, Duration, Amount, Sign)>>;
type GetDashboardOverviewDataFut = Ready<DashBoardOverviewDataFromClient>;
type PauseMinerFut = Ready<()>;
type RestartMinerFut = Ready<()>;
Expand Down Expand Up @@ -346,11 +346,11 @@ 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<(Digest, BlockHeight, Duration, Amount, Sign)> = history
.iter()
.map(|(_h, t, _bh, a, s)| (*t, *a, *s))
.map(|(h, t, bh, a, s)| (*h, *bh, *t, *a, *s))
.collect::<Vec<_>>();
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)
Expand Down
Loading