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"
authors = ["str3tch <stretch@ghostchain.io>"]
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"
[dependencies]

View File

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

View File

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

View File

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

View File

@ -8,6 +8,7 @@ use ratatui::{
};
use super::{PartialComponent, Component, CurrentTab};
use crate::widgets::DotSpinner;
use crate::{
action::Action,
config::Config,
@ -17,9 +18,9 @@ use crate::{
pub struct StashDetails {
palette: StylePalette,
is_bonded: bool,
free_balance: u128,
staked_total: u128,
staked_active: u128,
free_balance: Option<u128>,
staked_total: Option<u128>,
staked_active: Option<u128>,
stash_account_id: [u8; 32],
}
@ -37,17 +38,22 @@ impl StashDetails {
Self {
palette: StylePalette::default(),
is_bonded: false,
free_balance: 0,
staked_total: 0,
staked_active: 0,
free_balance: None,
staked_total: None,
staked_active: None,
stash_account_id: [0u8; 32],
}
}
fn prepare_u128(&self, value: u128) -> String {
let value = value as f64 / 10f64.powi(18);
let after = Self::DECIMALS;
format!("{:.after$}{}", value, Self::TICKER)
fn prepare_u128(&self, maybe_value: Option<u128>) -> String {
match maybe_value {
Some(value) => {
let value = value as f64 / 10f64.powi(18);
let after = Self::DECIMALS;
format!("{:.after$}{}", value, Self::TICKER)
},
None => format!("{}{}", DotSpinner::default().to_string(), Self::TICKER)
}
}
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::SetBondedAmount(is_bonded) => self.is_bonded = is_bonded,
Action::SetStakedAmountRatio(total, active) => {
self.staked_total = total;
self.staked_active = active;
self.staked_total = Some(total);
self.staked_active = Some(active);
},
Action::BalanceResponse(account_id, balance) if account_id == self.stash_account_id => {
self.free_balance = balance.free
Action::BalanceResponse(account_id, maybe_balance) if account_id == self.stash_account_id => {
self.free_balance = maybe_balance.map(|balance| balance.free
.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<()> {
let (pair, seed) = Pair::generate(); // TODO: revisit
let (pair, seed) = Pair::generate();
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 address = AccountId32::from(account_id)
.to_ss58check_with_version(Ss58AddressFormat::custom(1996));
let pair_signer = PairSigner::<CasperConfig, Pair>::new(pair);
let mut new_file = File::create(&self.file_path)?;

View File

@ -15,18 +15,17 @@ use ratatui::{
},
Frame
};
use subxt::{
ext::sp_core::{
Pair as PairT,
sr25519::Pair,
crypto::{Ss58Codec, Ss58AddressFormat, AccountId32},
},
use subxt::ext::sp_core::{
Pair as PairT,
sr25519::Pair,
crypto::{Ss58Codec, Ss58AddressFormat, AccountId32},
};
use tokio::sync::mpsc::UnboundedSender;
use std::sync::mpsc::Sender;
use super::{PartialComponent, Component, CurrentTab};
use crate::types::{SystemAccount, ActionLevel};
use crate::widgets::DotSpinner;
use crate::{
action::Action,
config::Config,
@ -59,6 +58,9 @@ impl Default for Accounts {
}
impl Accounts {
const TICKER: &str = " CSPR";
const DECIMALS: usize = 3;
pub fn new() -> Self {
Self {
is_active: false,
@ -136,10 +138,10 @@ impl Accounts {
}
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 account_id = pair.public().0;
let address = AccountId32::from(seed)
let address = AccountId32::from(account_id)
.to_ss58check_with_version(Ss58AddressFormat::custom(1996));
self.log_event(
@ -278,7 +280,7 @@ impl Accounts {
let secret_seed = hex::encode(seed);
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));
let mut new_file = File::create(file_path)?;
@ -353,9 +355,15 @@ impl Accounts {
self.set_used_account(i);
}
fn prepare_u128(&self, value: u128, after: usize, ticker: Option<&str>) -> String {
let value = value as f64 / 10f64.powi(18);
format!("{:.after$}{}", value, ticker.unwrap_or_default())
fn prepare_u128(&self, maybe_value: Option<u128>) -> String {
match maybe_value {
Some(value) => {
let value = value as f64 / 10f64.powi(18);
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 {
Action::NewAccount(name) => self.create_new_account(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) {
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 self.wallet_keys[index].account_id == account_id {
self.set_balance_active(index);
@ -445,12 +456,11 @@ impl Component for Accounts {
.map(|info| {
let balance = self.balances
.get(&info.account_id)
.map(|b| b.free)
.unwrap_or_default();
.map(|b| b.free);
Row::new(vec![
Cell::from(Text::from(info.name.clone()).alignment(Alignment::Left)),
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 {
const TICKER: &str = " CSPR";
const DECIMALS: usize = 3;
pub fn new() -> Self {
Self {
is_active: false,
@ -305,13 +308,14 @@ impl AddressBook {
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 {
Some(value) => {
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),
Action::NewAddressBookRecord(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) {
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![
Cell::from(Text::from(info.name.clone()).alignment(Alignment::Left)),
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 {
const DECIMALS_FOR_BALANCE: usize = 5;
const TICKER: &str = " CSPR";
const DECIMALS: usize = 6;
pub fn new() -> 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 {
Some(value) => {
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) => {
match maybe_balance {
Some(balance) => {
self.transferable_balance = Some(balance.free);
self.total_balance = Some(balance.free);
self.locked_balance = Some(balance.reserved);
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.frozen);
self.total_balance = Some(total_balance);
self.nonce = Some(balance.nonce);
self.transferable_balance = Some(transferable);
},
None => {
self.transferable_balance = None;
@ -117,38 +119,26 @@ impl Component for Balance {
[
Row::new(vec![
Cell::from(Text::from("nonce: ".to_string()).alignment(Alignment::Left)),
Cell::from(Text::from(self.prepare_u128(
self.nonce.map(|n| n as u128),
None,
0)).alignment(Alignment::Right)),
Cell::from(Text::from(self.nonce
.map(|n| n.to_string())
.unwrap_or(DotSpinner::default().to_string())
).alignment(Alignment::Right)),
]),
Row::new(vec![
Cell::from(Text::from("account: ".to_string()).alignment(Alignment::Left)),
Cell::from(Text::from(self.prepare_u128(
self.total_balance,
Some(" CSPR"),
Self::DECIMALS_FOR_BALANCE)).alignment(Alignment::Right)),
Cell::from(Text::from(self.prepare_u128(self.total_balance)).alignment(Alignment::Right)),
]),
Row::new(vec![
Cell::from(Text::from("free: ".to_string()).alignment(Alignment::Left)),
Cell::from(Text::from(self.prepare_u128(
self.transferable_balance,
Some(" CSPR"),
Self::DECIMALS_FOR_BALANCE)).alignment(Alignment::Right))
Cell::from(Text::from(self.prepare_u128(self.transferable_balance)).alignment(Alignment::Right))
]),
Row::new(vec![
Cell::from(Text::from("locked: ".to_string()).alignment(Alignment::Left)),
Cell::from(Text::from(self.prepare_u128(
self.locked_balance,
Some(" CSPR"),
Self::DECIMALS_FOR_BALANCE)).alignment(Alignment::Right)),
Cell::from(Text::from(self.prepare_u128(self.locked_balance)).alignment(Alignment::Right)),
]),
Row::new(vec![
Cell::from(Text::from("bonded: ".to_string()).alignment(Alignment::Left)),
Cell::from(Text::from(self.prepare_u128(
self.bonded_balance,
Some(" CSPR"),
Self::DECIMALS_FOR_BALANCE)).alignment(Alignment::Right)),
Cell::from(Text::from(self.prepare_u128(self.bonded_balance)).alignment(Alignment::Right)),
]),
],
[

View File

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

View File

@ -64,6 +64,10 @@ impl Network {
match io_event {
Action::NewBestHash(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 {
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?;
@ -78,8 +82,7 @@ impl Network {
}
Ok(())
},
Action::NewFinalizedHash(hash) => {
self.finalized_hash = Some(hash);
Action::CheckPendingTransactions => {
let length = self.transactions_to_watch.len();
for i in (0..length).rev() {
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>,
api: &OnlineClient<CasperConfig>,
) -> Result<()> {
let total_issuance = super::raw_calls::balances::total_issuance(api, None)
.await?
.unwrap_or_default();
action_tx.send(Action::SetTotalIssuance(total_issuance))?;
let maybe_total_issuance = super::raw_calls::balances::total_issuance(api, None)
.await?;
action_tx.send(Action::SetTotalIssuance(maybe_total_issuance))?;
Ok(())
}
@ -133,21 +132,15 @@ pub async fn get_balance(
account_id: &[u8; 32],
) -> Result<()> {
let maybe_balance = super::raw_calls::system::balance(api, None, account_id)
.await?;
let balance = match maybe_balance {
Some(balance) => {
SystemAccount {
.await?
.map(|balance| SystemAccount {
nonce: balance.nonce,
free: balance.data.free,
reserved: balance.data.reserved,
frozen: balance.data.frozen,
}
},
None => SystemAccount::default(),
};
action_tx.send(Action::BalanceResponse(*account_id, balance))?;
);
action_tx.send(Action::BalanceResponse(*account_id, maybe_balance))?;
Ok(())
}
@ -290,7 +283,7 @@ pub async fn get_validator_staking_results(
) -> Result<()> {
let (start, end) = super::raw_calls::historical::stored_range(api, None)
.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));
for era_index in start..end.saturating_sub(2) {
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 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 {
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)
/ (super::CYCLE / self.elements.len() as i64)) as usize]
.to_owned()