Compare commits

...

10 Commits

Author SHA1 Message Date
8b302a0814
bump the version
Signed-off-by: Uncle Stretch <uncle.stretch@ghostchain.io>
2025-01-21 15:33:45 +03:00
25d0a37aa8
forget to add
Signed-off-by: Uncle Stretch <uncle.stretch@ghostchain.io>
2025-01-21 15:33:12 +03:00
5323363b35
small fixes to make code more readable
Signed-off-by: Uncle Stretch <uncle.stretch@ghostchain.io>
2025-01-21 15:27:49 +03:00
9ebb1d9543
bump version based on all small fixes
Signed-off-by: Uncle Stretch <uncle.stretch@ghostchain.io>
2025-01-20 16:47:13 +03:00
6347474633
bug with index out-of-range in widget fixed with help of lowest common multiple, thanks to @ogenkidu and @metanomad
Signed-off-by: Uncle Stretch <uncle.stretch@ghostchain.io>
2025-01-20 16:00:58 +03:00
f9233c6291
dot spinner for all non-existent balances
Signed-off-by: Uncle Stretch <uncle.stretch@ghostchain.io>
2025-01-20 14:57:18 +03:00
9e77dd816d
make account-driven calls dependent on the finalized block but not latest, thanks to @doctor_k
Signed-off-by: Uncle Stretch <uncle.stretch@ghostchain.io>
2025-01-20 13:52:05 +03:00
ddc8eb062a
make the transacation logs independent from the block finalization or production, thanks to @doctor_k
Signed-off-by: Uncle Stretch <uncle.stretch@ghostchain.io>
2025-01-20 13:50:01 +03:00
3662f9c666
newly generated keys representation fix, thanks to @sargio, @ASB_clown and @metanomad
Signed-off-by: Uncle Stretch <uncle.stretch@ghostchain.io>
2025-01-20 13:39:38 +03:00
3b7aaa7fd2
bump version
Signed-off-by: Uncle Stretch <uncle.stretch@ghostchain.io>
2025-01-20 13:16:04 +03:00
14 changed files with 122 additions and 117 deletions

View File

@ -2,7 +2,7 @@
name = "ghost-eye" name = "ghost-eye"
authors = ["str3tch <stretch@ghostchain.io>"] authors = ["str3tch <stretch@ghostchain.io>"]
description = "Application for interacting with Casper/Ghost nodes that are exposing RPC only to the localhost" description = "Application for interacting with Casper/Ghost nodes that are exposing RPC only to the localhost"
version = "0.2.6" version = "0.3.14"
edition = "2021" edition = "2021"
[dependencies] [dependencies]

View File

@ -19,6 +19,7 @@ pub enum Action {
ClearScreen, ClearScreen,
Error(String), Error(String),
Help, Help,
CheckPendingTransactions,
SetMode(crate::app::Mode), SetMode(crate::app::Mode),
SetActiveScreen(crate::app::Mode), SetActiveScreen(crate::app::Mode),
@ -31,7 +32,7 @@ pub enum Action {
ClosePopup, ClosePopup,
BalanceRequest([u8; 32], bool), BalanceRequest([u8; 32], bool),
BalanceResponse([u8; 32], SystemAccount), BalanceResponse([u8; 32], Option<SystemAccount>),
BalanceSetActive(Option<SystemAccount>), BalanceSetActive(Option<SystemAccount>),
RenameAccount(String), RenameAccount(String),
@ -117,5 +118,5 @@ pub enum Action {
GetExistentialDeposit, GetExistentialDeposit,
SetExistentialDeposit(u128), SetExistentialDeposit(u128),
SetTotalIssuance(u128), SetTotalIssuance(Option<u128>),
} }

View File

@ -162,6 +162,7 @@ impl App {
fn trigger_node_fast_events(&mut self) -> Result<()> { fn trigger_node_fast_events(&mut self) -> Result<()> {
self.network_tx.send(Action::GetPendingExtrinsics)?; self.network_tx.send(Action::GetPendingExtrinsics)?;
self.network_tx.send(Action::GetConnectedPeers)?; self.network_tx.send(Action::GetConnectedPeers)?;
self.network_tx.send(Action::CheckPendingTransactions)?;
Ok(()) Ok(())
} }

View File

@ -52,18 +52,16 @@ impl Health {
} }
pub fn peers_as_string(&self) -> String { pub fn peers_as_string(&self) -> String {
if self.peers.is_some() { match self.peers {
self.peers.unwrap().to_string() Some(peers) => peers.to_string(),
} else { None => DotSpinner::default().to_string(),
DotSpinner::default().to_string()
} }
} }
pub fn name_as_string(&self) -> String { pub fn name_as_string(&self) -> String {
if self.name.is_some() { match &self.name {
self.name.clone().unwrap() Some(name) => name.clone(),
} else { None => OghamCenter::default().to_string(),
OghamCenter::default().to_string()
} }
} }
} }

View File

@ -8,6 +8,7 @@ use ratatui::{
}; };
use super::{PartialComponent, Component, CurrentTab}; use super::{PartialComponent, Component, CurrentTab};
use crate::widgets::DotSpinner;
use crate::{ use crate::{
action::Action, action::Action,
config::Config, config::Config,
@ -17,9 +18,9 @@ use crate::{
pub struct StashDetails { pub struct StashDetails {
palette: StylePalette, palette: StylePalette,
is_bonded: bool, is_bonded: bool,
free_balance: u128, free_balance: Option<u128>,
staked_total: u128, staked_total: Option<u128>,
staked_active: u128, staked_active: Option<u128>,
stash_account_id: [u8; 32], stash_account_id: [u8; 32],
} }
@ -37,17 +38,22 @@ impl StashDetails {
Self { Self {
palette: StylePalette::default(), palette: StylePalette::default(),
is_bonded: false, is_bonded: false,
free_balance: 0, free_balance: None,
staked_total: 0, staked_total: None,
staked_active: 0, staked_active: None,
stash_account_id: [0u8; 32], stash_account_id: [0u8; 32],
} }
} }
fn prepare_u128(&self, value: u128) -> String { fn prepare_u128(&self, maybe_value: Option<u128>) -> String {
match maybe_value {
Some(value) => {
let value = value as f64 / 10f64.powi(18); let value = value as f64 / 10f64.powi(18);
let after = Self::DECIMALS; let after = Self::DECIMALS;
format!("{:.after$}{}", value, Self::TICKER) format!("{:.after$}{}", value, Self::TICKER)
},
None => format!("{}{}", DotSpinner::default().to_string(), Self::TICKER)
}
} }
fn is_bonded_to_string(&self) -> String { fn is_bonded_to_string(&self) -> String {
@ -83,13 +89,13 @@ impl Component for StashDetails {
Action::SetStashAccount(account_id) => self.stash_account_id = account_id, Action::SetStashAccount(account_id) => self.stash_account_id = account_id,
Action::SetBondedAmount(is_bonded) => self.is_bonded = is_bonded, Action::SetBondedAmount(is_bonded) => self.is_bonded = is_bonded,
Action::SetStakedAmountRatio(total, active) => { Action::SetStakedAmountRatio(total, active) => {
self.staked_total = total; self.staked_total = Some(total);
self.staked_active = active; self.staked_active = Some(active);
}, },
Action::BalanceResponse(account_id, balance) if account_id == self.stash_account_id => { Action::BalanceResponse(account_id, maybe_balance) if account_id == self.stash_account_id => {
self.free_balance = balance.free self.free_balance = maybe_balance.map(|balance| balance.free
.saturating_sub(balance.frozen) .saturating_sub(balance.frozen)
.saturating_sub(balance.reserved); .saturating_sub(balance.reserved));
}, },
_ => {} _ => {}
}; };

View File

@ -173,11 +173,11 @@ impl StashInfo {
} }
fn generate_and_save_new_key(&mut self) -> Result<()> { fn generate_and_save_new_key(&mut self) -> Result<()> {
let (pair, seed) = Pair::generate(); // TODO: revisit let (pair, seed) = Pair::generate();
let secret_seed = hex::encode(seed); let secret_seed = hex::encode(seed);
let address = AccountId32::from(pair.public().0)
.to_ss58check_with_version(Ss58AddressFormat::custom(1996));
let account_id = pair.public().0; let account_id = pair.public().0;
let address = AccountId32::from(account_id)
.to_ss58check_with_version(Ss58AddressFormat::custom(1996));
let pair_signer = PairSigner::<CasperConfig, Pair>::new(pair); let pair_signer = PairSigner::<CasperConfig, Pair>::new(pair);
let mut new_file = File::create(&self.file_path)?; let mut new_file = File::create(&self.file_path)?;

View File

@ -15,18 +15,17 @@ use ratatui::{
}, },
Frame Frame
}; };
use subxt::{ use subxt::ext::sp_core::{
ext::sp_core::{
Pair as PairT, Pair as PairT,
sr25519::Pair, sr25519::Pair,
crypto::{Ss58Codec, Ss58AddressFormat, AccountId32}, crypto::{Ss58Codec, Ss58AddressFormat, AccountId32},
},
}; };
use tokio::sync::mpsc::UnboundedSender; use tokio::sync::mpsc::UnboundedSender;
use std::sync::mpsc::Sender; use std::sync::mpsc::Sender;
use super::{PartialComponent, Component, CurrentTab}; use super::{PartialComponent, Component, CurrentTab};
use crate::types::{SystemAccount, ActionLevel}; use crate::types::{SystemAccount, ActionLevel};
use crate::widgets::DotSpinner;
use crate::{ use crate::{
action::Action, action::Action,
config::Config, config::Config,
@ -59,6 +58,9 @@ impl Default for Accounts {
} }
impl Accounts { impl Accounts {
const TICKER: &str = " CSPR";
const DECIMALS: usize = 3;
pub fn new() -> Self { pub fn new() -> Self {
Self { Self {
is_active: false, is_active: false,
@ -136,10 +138,10 @@ impl Accounts {
} }
fn create_new_account(&mut self, name: String) { fn create_new_account(&mut self, name: String) {
let (pair, seed) = Pair::generate(); // TODO: generate_with_phrase() let (pair, seed) = Pair::generate();
let secret_seed = hex::encode(seed); let secret_seed = hex::encode(seed);
let account_id = pair.public().0; let account_id = pair.public().0;
let address = AccountId32::from(seed) let address = AccountId32::from(account_id)
.to_ss58check_with_version(Ss58AddressFormat::custom(1996)); .to_ss58check_with_version(Ss58AddressFormat::custom(1996));
self.log_event( self.log_event(
@ -278,7 +280,7 @@ impl Accounts {
let secret_seed = hex::encode(seed); let secret_seed = hex::encode(seed);
let account_id = pair.public().0; let account_id = pair.public().0;
let address = AccountId32::from(pair.public().0) let address = AccountId32::from(account_id)
.to_ss58check_with_version(Ss58AddressFormat::custom(1996)); .to_ss58check_with_version(Ss58AddressFormat::custom(1996));
let mut new_file = File::create(file_path)?; let mut new_file = File::create(file_path)?;
@ -353,9 +355,15 @@ impl Accounts {
self.set_used_account(i); self.set_used_account(i);
} }
fn prepare_u128(&self, value: u128, after: usize, ticker: Option<&str>) -> String { fn prepare_u128(&self, maybe_value: Option<u128>) -> String {
match maybe_value {
Some(value) => {
let value = value as f64 / 10f64.powi(18); let value = value as f64 / 10f64.powi(18);
format!("{:.after$}{}", value, ticker.unwrap_or_default()) let after = Self::DECIMALS;
format!("{:.after$}{}", value, Self::TICKER)
}
None => format!("{}{}", DotSpinner::default().to_string(), Self::TICKER)
}
} }
} }
@ -402,9 +410,12 @@ impl Component for Accounts {
match action { match action {
Action::NewAccount(name) => self.create_new_account(name), Action::NewAccount(name) => self.create_new_account(name),
Action::UpdateAccountName(new_name) => self.rename_account(new_name), Action::UpdateAccountName(new_name) => self.rename_account(new_name),
Action::BalanceResponse(account_id, balance) => { Action::BalanceResponse(account_id, maybe_balance) => {
if self.wallet_keys.iter().any(|wallet| wallet.account_id == account_id) { if self.wallet_keys.iter().any(|wallet| wallet.account_id == account_id) {
let _ = self.balances.insert(account_id, balance); let _ = match maybe_balance {
Some(balance) => self.balances.insert(account_id, balance),
None => self.balances.remove(&account_id),
};
if let Some(index) = self.table_state.selected() { if let Some(index) = self.table_state.selected() {
if self.wallet_keys[index].account_id == account_id { if self.wallet_keys[index].account_id == account_id {
self.set_balance_active(index); self.set_balance_active(index);
@ -445,12 +456,11 @@ impl Component for Accounts {
.map(|info| { .map(|info| {
let balance = self.balances let balance = self.balances
.get(&info.account_id) .get(&info.account_id)
.map(|b| b.free) .map(|b| b.free);
.unwrap_or_default();
Row::new(vec![ Row::new(vec![
Cell::from(Text::from(info.name.clone()).alignment(Alignment::Left)), Cell::from(Text::from(info.name.clone()).alignment(Alignment::Left)),
Cell::from(Text::from(info.address.clone()).alignment(Alignment::Center)), Cell::from(Text::from(info.address.clone()).alignment(Alignment::Center)),
Cell::from(Text::from(self.prepare_u128(balance, 2, Some(" CSPR"))).alignment(Alignment::Right)), Cell::from(Text::from(self.prepare_u128(balance)).alignment(Alignment::Right)),
]) ])
}), }),
[ [

View File

@ -53,6 +53,9 @@ impl Default for AddressBook {
} }
impl AddressBook { impl AddressBook {
const TICKER: &str = " CSPR";
const DECIMALS: usize = 3;
pub fn new() -> Self { pub fn new() -> Self {
Self { Self {
is_active: false, is_active: false,
@ -305,13 +308,14 @@ impl AddressBook {
self.scroll_state = self.scroll_state.position(i); self.scroll_state = self.scroll_state.position(i);
} }
fn prepare_u128(&self, maybe_value: Option<u128>, ticker: Option<&str>, after: usize) -> String { fn prepare_u128(&self, maybe_value: Option<u128>) -> String {
match maybe_value { match maybe_value {
Some(value) => { Some(value) => {
let value = value as f64 / 10f64.powi(18); let value = value as f64 / 10f64.powi(18);
format!("{:.after$}{}", value, ticker.unwrap_or_default()) let after = Self::DECIMALS;
format!("{:.after$}{}", value, Self::TICKER)
}, },
None => DotSpinner::default().to_string(), None => format!("{}{}", DotSpinner::default().to_string(), Self::TICKER)
} }
} }
} }
@ -360,9 +364,12 @@ impl Component for AddressBook {
self.rename_record(new_name), self.rename_record(new_name),
Action::NewAddressBookRecord(name, address) => Action::NewAddressBookRecord(name, address) =>
self.add_new_record(name, address), self.add_new_record(name, address),
Action::BalanceResponse(account_id, balance) => { Action::BalanceResponse(account_id, maybe_balance) => {
if self.address_book.iter().any(|record| record.account_id == account_id) { if self.address_book.iter().any(|record| record.account_id == account_id) {
let _ = self.balances.insert(account_id, balance); let _ = match maybe_balance {
Some(balance) => self.balances.insert(account_id, balance),
None => self.balances.remove(&account_id),
};
} }
}, },
_ => {} _ => {}
@ -407,7 +414,7 @@ impl Component for AddressBook {
Row::new(vec![ Row::new(vec![
Cell::from(Text::from(info.name.clone()).alignment(Alignment::Left)), Cell::from(Text::from(info.name.clone()).alignment(Alignment::Left)),
Cell::from(Text::from(info.address.clone()).alignment(Alignment::Center)), Cell::from(Text::from(info.address.clone()).alignment(Alignment::Center)),
Cell::from(Text::from(self.prepare_u128(balance, Some(" CSPR"), 2)).alignment(Alignment::Right)), Cell::from(Text::from(self.prepare_u128(balance)).alignment(Alignment::Right)),
]) ])
}), }),
[ [

View File

@ -32,7 +32,8 @@ impl Default for Balance {
} }
impl Balance { impl Balance {
const DECIMALS_FOR_BALANCE: usize = 5; const TICKER: &str = " CSPR";
const DECIMALS: usize = 6;
pub fn new() -> Self { pub fn new() -> Self {
Self { Self {
@ -46,13 +47,14 @@ impl Balance {
} }
} }
fn prepare_u128(&self, maybe_value: Option<u128>, ticker: Option<&str>, after: usize) -> String { fn prepare_u128(&self, maybe_value: Option<u128>) -> String {
match maybe_value { match maybe_value {
Some(value) => { Some(value) => {
let value = value as f64 / 10f64.powi(18); let value = value as f64 / 10f64.powi(18);
format!("{:.after$}{}", value, ticker.unwrap_or_default()) let after = Self::DECIMALS;
format!("{:.after$}{}", value, Self::TICKER)
}, },
None => DotSpinner::default().to_string() None => format!("{}{}", DotSpinner::default().to_string(), Self::TICKER)
} }
} }
} }
@ -84,15 +86,15 @@ impl Component for Balance {
Action::BalanceSetActive(maybe_balance) => { Action::BalanceSetActive(maybe_balance) => {
match maybe_balance { match maybe_balance {
Some(balance) => { Some(balance) => {
self.transferable_balance = Some(balance.free); self.total_balance = Some(balance.free);
self.locked_balance = Some(balance.reserved); self.locked_balance = Some(balance.reserved);
self.bonded_balance = Some(balance.frozen); self.bonded_balance = Some(balance.frozen);
self.nonce = Some(balance.nonce);
let total_balance = balance.free let transferable = balance.free
.saturating_add(balance.reserved) .saturating_add(balance.reserved)
.saturating_add(balance.frozen); .saturating_add(balance.frozen);
self.total_balance = Some(total_balance); self.transferable_balance = Some(transferable);
self.nonce = Some(balance.nonce);
}, },
None => { None => {
self.transferable_balance = None; self.transferable_balance = None;
@ -117,38 +119,26 @@ impl Component for Balance {
[ [
Row::new(vec![ Row::new(vec![
Cell::from(Text::from("nonce: ".to_string()).alignment(Alignment::Left)), Cell::from(Text::from("nonce: ".to_string()).alignment(Alignment::Left)),
Cell::from(Text::from(self.prepare_u128( Cell::from(Text::from(self.nonce
self.nonce.map(|n| n as u128), .map(|n| n.to_string())
None, .unwrap_or(DotSpinner::default().to_string())
0)).alignment(Alignment::Right)), ).alignment(Alignment::Right)),
]), ]),
Row::new(vec![ Row::new(vec![
Cell::from(Text::from("account: ".to_string()).alignment(Alignment::Left)), Cell::from(Text::from("account: ".to_string()).alignment(Alignment::Left)),
Cell::from(Text::from(self.prepare_u128( Cell::from(Text::from(self.prepare_u128(self.total_balance)).alignment(Alignment::Right)),
self.total_balance,
Some(" CSPR"),
Self::DECIMALS_FOR_BALANCE)).alignment(Alignment::Right)),
]), ]),
Row::new(vec![ Row::new(vec![
Cell::from(Text::from("free: ".to_string()).alignment(Alignment::Left)), Cell::from(Text::from("free: ".to_string()).alignment(Alignment::Left)),
Cell::from(Text::from(self.prepare_u128( Cell::from(Text::from(self.prepare_u128(self.transferable_balance)).alignment(Alignment::Right))
self.transferable_balance,
Some(" CSPR"),
Self::DECIMALS_FOR_BALANCE)).alignment(Alignment::Right))
]), ]),
Row::new(vec![ Row::new(vec![
Cell::from(Text::from("locked: ".to_string()).alignment(Alignment::Left)), Cell::from(Text::from("locked: ".to_string()).alignment(Alignment::Left)),
Cell::from(Text::from(self.prepare_u128( Cell::from(Text::from(self.prepare_u128(self.locked_balance)).alignment(Alignment::Right)),
self.locked_balance,
Some(" CSPR"),
Self::DECIMALS_FOR_BALANCE)).alignment(Alignment::Right)),
]), ]),
Row::new(vec![ Row::new(vec![
Cell::from(Text::from("bonded: ".to_string()).alignment(Alignment::Left)), Cell::from(Text::from("bonded: ".to_string()).alignment(Alignment::Left)),
Cell::from(Text::from(self.prepare_u128( Cell::from(Text::from(self.prepare_u128(self.bonded_balance)).alignment(Alignment::Right)),
self.bonded_balance,
Some(" CSPR"),
Self::DECIMALS_FOR_BALANCE)).alignment(Alignment::Right)),
]), ]),
], ],
[ [

View File

@ -10,7 +10,7 @@ use super::{Component, PartialComponent, CurrentTab};
use crate::{ use crate::{
action::Action, action::Action,
config::Config, config::Config,
palette::StylePalette, palette::StylePalette, widgets::DotSpinner,
}; };
#[derive(Debug)] #[derive(Debug)]
@ -28,7 +28,8 @@ impl Default for Overview {
} }
impl Overview { impl Overview {
const DECIMALS_FOR_BALANCE: usize = 6; const TICKER: &str = " CSPR";
const DECIMALS: usize = 6;
pub fn new() -> Self { pub fn new() -> Self {
Self { Self {
@ -39,9 +40,15 @@ impl Overview {
} }
} }
fn prepare_u128(&self, value: u128, after: usize) -> String { fn prepare_u128(&self, maybe_value: Option<u128>) -> String {
match maybe_value {
Some(value) => {
let value = value as f64 / 10f64.powi(18); let value = value as f64 / 10f64.powi(18);
format!("{:.after$}", value) let after = Self::DECIMALS;
format!("{:.after$}{}", value, Self::TICKER)
},
None => format!("{}{}", DotSpinner::default().to_string(), Self::TICKER)
}
} }
} }
@ -70,7 +77,7 @@ impl Component for Overview {
fn update(&mut self, action: Action) -> Result<Option<Action>> { fn update(&mut self, action: Action) -> Result<Option<Action>> {
match action { match action {
Action::SetExistentialDeposit(ed) => self.existential_balance = Some(ed), Action::SetExistentialDeposit(ed) => self.existential_balance = Some(ed),
Action::SetTotalIssuance(issuance) => self.total_issuance = Some(issuance), Action::SetTotalIssuance(maybe_issuance) => self.total_issuance = maybe_issuance,
_ => {} _ => {}
}; };
Ok(None) Ok(None)
@ -85,25 +92,16 @@ impl Component for Overview {
[ [
Row::new(vec![ Row::new(vec![
Cell::from(Text::from("total supply: ".to_string()).alignment(Alignment::Left)), Cell::from(Text::from("total supply: ".to_string()).alignment(Alignment::Left)),
Cell::from(Text::from(self.prepare_u128( Cell::from(Text::from(self.prepare_u128(self.total_issuance)).alignment(Alignment::Right)),
self.total_issuance.unwrap_or_default(),
Self::DECIMALS_FOR_BALANCE,
)).alignment(Alignment::Center)),
Cell::from(Text::from("CSPR".to_string()).alignment(Alignment::Right)),
]), ]),
Row::new(vec![ Row::new(vec![
Cell::from(Text::from("min deposit: ".to_string()).alignment(Alignment::Left)), Cell::from(Text::from("min deposit: ".to_string()).alignment(Alignment::Left)),
Cell::from(Text::from(self.prepare_u128( Cell::from(Text::from(self.prepare_u128(self.existential_balance)).alignment(Alignment::Right)),
self.existential_balance.unwrap_or_default(),
Self::DECIMALS_FOR_BALANCE,
)).alignment(Alignment::Center)),
Cell::from(Text::from("CSPR".to_string()).alignment(Alignment::Right)),
]), ]),
], ],
[ [
Constraint::Max(15), Constraint::Max(15),
Constraint::Min(0), Constraint::Min(0),
Constraint::Length(5),
] ]
) )
.block(Block::bordered() .block(Block::bordered()

View File

@ -64,6 +64,10 @@ impl Network {
match io_event { match io_event {
Action::NewBestHash(hash) => { Action::NewBestHash(hash) => {
self.best_hash = Some(hash); self.best_hash = Some(hash);
Ok(())
},
Action::NewFinalizedHash(hash) => {
self.finalized_hash = Some(hash);
if let Some(stash_to_watch) = self.stash_to_watch { if let Some(stash_to_watch) = self.stash_to_watch {
predefined_calls::get_session_keys(&self.action_tx, &self.online_client_api, &self.rpc_client, &stash_to_watch).await?; predefined_calls::get_session_keys(&self.action_tx, &self.online_client_api, &self.rpc_client, &stash_to_watch).await?;
predefined_calls::get_queued_session_keys(&self.action_tx, &self.online_client_api, &self.rpc_client, &stash_to_watch).await?; predefined_calls::get_queued_session_keys(&self.action_tx, &self.online_client_api, &self.rpc_client, &stash_to_watch).await?;
@ -78,8 +82,7 @@ impl Network {
} }
Ok(()) Ok(())
}, },
Action::NewFinalizedHash(hash) => { Action::CheckPendingTransactions => {
self.finalized_hash = Some(hash);
let length = self.transactions_to_watch.len(); let length = self.transactions_to_watch.len();
for i in (0..length).rev() { for i in (0..length).rev() {
let pending_tx = &mut self.transactions_to_watch[i]; let pending_tx = &mut self.transactions_to_watch[i];

View File

@ -111,10 +111,9 @@ pub async fn get_total_issuance(
action_tx: &UnboundedSender<Action>, action_tx: &UnboundedSender<Action>,
api: &OnlineClient<CasperConfig>, api: &OnlineClient<CasperConfig>,
) -> Result<()> { ) -> Result<()> {
let total_issuance = super::raw_calls::balances::total_issuance(api, None) let maybe_total_issuance = super::raw_calls::balances::total_issuance(api, None)
.await? .await?;
.unwrap_or_default(); action_tx.send(Action::SetTotalIssuance(maybe_total_issuance))?;
action_tx.send(Action::SetTotalIssuance(total_issuance))?;
Ok(()) Ok(())
} }
@ -133,21 +132,15 @@ pub async fn get_balance(
account_id: &[u8; 32], account_id: &[u8; 32],
) -> Result<()> { ) -> Result<()> {
let maybe_balance = super::raw_calls::system::balance(api, None, account_id) let maybe_balance = super::raw_calls::system::balance(api, None, account_id)
.await?; .await?
.map(|balance| SystemAccount {
let balance = match maybe_balance {
Some(balance) => {
SystemAccount {
nonce: balance.nonce, nonce: balance.nonce,
free: balance.data.free, free: balance.data.free,
reserved: balance.data.reserved, reserved: balance.data.reserved,
frozen: balance.data.frozen, frozen: balance.data.frozen,
} }
}, );
None => SystemAccount::default(), action_tx.send(Action::BalanceResponse(*account_id, maybe_balance))?;
};
action_tx.send(Action::BalanceResponse(*account_id, balance))?;
Ok(()) Ok(())
} }
@ -290,7 +283,7 @@ pub async fn get_validator_staking_results(
) -> Result<()> { ) -> Result<()> {
let (start, end) = super::raw_calls::historical::stored_range(api, None) let (start, end) = super::raw_calls::historical::stored_range(api, None)
.await? .await?
.map(|range| (range.0 / 6, range.1 / 6)) .map(|range| (range.0.saturating_div(6), range.1.saturating_div(6)))
.unwrap_or((0, 0)); .unwrap_or((0, 0));
for era_index in start..end.saturating_sub(2) { for era_index in start..end.saturating_sub(2) {
get_validator_staking_result(action_tx, api, account_id, era_index).await?; get_validator_staking_result(action_tx, api, account_id, era_index).await?;

View File

@ -11,4 +11,4 @@ pub use big_text::BigText;
pub use big_text::PixelSize; pub use big_text::PixelSize;
pub use input::{Input, InputRequest}; pub use input::{Input, InputRequest};
const CYCLE: i64 = 1500; const CYCLE: i64 = 1560;

View File

@ -14,8 +14,6 @@ impl Default for VerticalBlocks {
impl ToString for VerticalBlocks { impl ToString for VerticalBlocks {
fn to_string(&self) -> String { fn to_string(&self) -> String {
// TODO: how it can be equal to len()??
// do we really need super::CYCLE in denominator?
self.elements[((chrono::Utc::now().timestamp_millis() % super::CYCLE) self.elements[((chrono::Utc::now().timestamp_millis() % super::CYCLE)
/ (super::CYCLE / self.elements.len() as i64)) as usize] / (super::CYCLE / self.elements.len() as i64)) as usize]
.to_owned() .to_owned()