Compare commits

..

No commits in common. "9b1136e4caa39fa6f8b316fdddf40dc522d3ee52" and "493a4db663e7fa47a6f7d756d00f4f29f833c28c" have entirely different histories.

13 changed files with 53 additions and 88 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.3.17" version = "0.3.16"
edition = "2021" edition = "2021"
[dependencies] [dependencies]

View File

@ -5,8 +5,7 @@ use subxt::utils::H256;
use subxt::config::substrate::DigestItem; use subxt::config::substrate::DigestItem;
use crate::types::{ use crate::types::{
ActionLevel, ActionTarget, CasperExtrinsicDetails, EraInfo, EraRewardPoints, ActionLevel, CasperExtrinsicDetails, EraInfo, EraRewardPoints, Nominator, PeerInformation, SessionKeyInfo, SystemAccount
Nominator, PeerInformation, SessionKeyInfo, SystemAccount,
}; };
#[derive(Debug, Clone, PartialEq, Eq, Display, Serialize, Deserialize)] #[derive(Debug, Clone, PartialEq, Eq, Display, Serialize, Deserialize)]
@ -47,7 +46,8 @@ pub enum Action {
TransferTo(String), TransferTo(String),
TransferBalance(String, [u8; 32], u128), TransferBalance(String, [u8; 32], u128),
EventLog(String, ActionLevel, ActionTarget), WalletLog(String, ActionLevel),
ValidatorLog(String, ActionLevel),
NewBestBlock(u32), NewBestBlock(u32),
NewBestHash(H256), NewBestHash(H256),

View File

@ -20,7 +20,7 @@ use crate::{
}; };
#[derive(Debug, Default)] #[derive(Debug, Default)]
struct LogDetails { struct WalletLog {
time: chrono::DateTime<chrono::Local>, time: chrono::DateTime<chrono::Local>,
level: ActionLevel, level: ActionLevel,
message: String, message: String,
@ -31,7 +31,7 @@ pub struct EventLogs {
is_active: bool, is_active: bool,
scroll_state: ScrollbarState, scroll_state: ScrollbarState,
table_state: TableState, table_state: TableState,
logs: std::collections::VecDeque<LogDetails>, logs: std::collections::VecDeque<WalletLog>,
palette: StylePalette palette: StylePalette
} }
@ -43,7 +43,7 @@ impl Default for EventLogs {
scroll_state: Default::default(), scroll_state: Default::default(),
table_state: Default::default(), table_state: Default::default(),
logs: std::collections::VecDeque::from(vec![ logs: std::collections::VecDeque::from(vec![
LogDetails { WalletLog {
time: chrono::Local::now(), time: chrono::Local::now(),
level: ActionLevel::Warn, level: ActionLevel::Warn,
message: "NOT FINALIZED PAGE! NEEDED IN ORDER TO SEE VALIDATORS POINTS".to_string(), message: "NOT FINALIZED PAGE! NEEDED IN ORDER TO SEE VALIDATORS POINTS".to_string(),
@ -58,7 +58,7 @@ impl EventLogs {
//const MAX_LOGS: usize = 50; //const MAX_LOGS: usize = 50;
//fn add_new_log(&mut self, message: String, level: ActionLevel) { //fn add_new_log(&mut self, message: String, level: ActionLevel) {
// self.logs.push_front(LogDetails { // self.logs.push_front(WalletLog {
// time: chrono::Local::now(), // time: chrono::Local::now(),
// level, // level,
// message, // message,
@ -156,8 +156,7 @@ impl Component for EventLogs {
fn update(&mut self, _action: Action) -> Result<Option<Action>> { fn update(&mut self, _action: Action) -> Result<Option<Action>> {
//match action { //match action {
// Action::EventLog(message, level, target) if target == ActionTarget::NominatorLog => // Action::ValidatorLog(message, level) => self.add_new_log(message, level),
// self.add_new_log(message, level),
// _ => {} // _ => {}
//}; //};
Ok(None) Ok(None)

View File

@ -13,11 +13,14 @@ use ratatui::{
use super::{Component, PartialComponent, CurrentTab}; use super::{Component, PartialComponent, CurrentTab};
use crate::{ use crate::{
action::Action, config::Config, palette::StylePalette, types::{ActionLevel, ActionTarget} types::ActionLevel,
action::Action,
config::Config,
palette::StylePalette,
}; };
#[derive(Debug, Default)] #[derive(Debug, Default)]
struct LogDetails { struct WalletLog {
time: chrono::DateTime<chrono::Local>, time: chrono::DateTime<chrono::Local>,
level: ActionLevel, level: ActionLevel,
message: String, message: String,
@ -28,7 +31,7 @@ pub struct EventLogs {
is_active: bool, is_active: bool,
scroll_state: ScrollbarState, scroll_state: ScrollbarState,
table_state: TableState, table_state: TableState,
logs: std::collections::VecDeque<LogDetails>, logs: std::collections::VecDeque<WalletLog>,
palette: StylePalette palette: StylePalette
} }
@ -36,7 +39,7 @@ impl EventLogs {
const MAX_LOGS: usize = 50; const MAX_LOGS: usize = 50;
fn add_new_log(&mut self, message: String, level: ActionLevel) { fn add_new_log(&mut self, message: String, level: ActionLevel) {
self.logs.push_front(LogDetails { self.logs.push_front(WalletLog {
time: chrono::Local::now(), time: chrono::Local::now(),
level, level,
message, message,
@ -134,8 +137,7 @@ impl Component for EventLogs {
fn update(&mut self, action: Action) -> Result<Option<Action>> { fn update(&mut self, action: Action) -> Result<Option<Action>> {
match action { match action {
Action::EventLog(message, level, target) if target == ActionTarget::ValidatorLog => Action::ValidatorLog(message, level) => self.add_new_log(message, level),
self.add_new_log(message, level),
_ => {} _ => {}
}; };
Ok(None) Ok(None)

View File

@ -29,7 +29,7 @@ use std::sync::mpsc::Sender;
use super::{PartialComponent, Component, CurrentTab}; use super::{PartialComponent, Component, CurrentTab};
use crate::casper::CasperConfig; use crate::casper::CasperConfig;
use crate::types::{ActionLevel, ActionTarget}; use crate::types::ActionLevel;
use crate::{ use crate::{
types::SessionKeyInfo, types::SessionKeyInfo,
action::Action, action::Action,
@ -76,8 +76,7 @@ impl StashInfo {
fn log_event(&mut self, message: String, level: ActionLevel) { fn log_event(&mut self, message: String, level: ActionLevel) {
if let Some(action_tx) = &self.action_tx { if let Some(action_tx) = &self.action_tx {
let _ = action_tx.send( let _ = action_tx.send(Action::ValidatorLog(message, level));
Action::EventLog(message, level, ActionTarget::ValidatorLog));
} }
} }

View File

@ -24,7 +24,7 @@ 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::{ActionLevel, ActionTarget, SystemAccount}; use crate::types::{SystemAccount, ActionLevel};
use crate::widgets::DotSpinner; use crate::widgets::DotSpinner;
use crate::{ use crate::{
action::Action, action::Action,
@ -96,8 +96,7 @@ impl Accounts {
fn log_event(&mut self, message: String, level: ActionLevel) { fn log_event(&mut self, message: String, level: ActionLevel) {
if let Some(action_tx) = &self.action_tx { if let Some(action_tx) = &self.action_tx {
let _ = action_tx.send( let _ = action_tx.send(Action::WalletLog(message, level));
Action::EventLog(message, level, ActionTarget::WalletLog));
} }
} }

View File

@ -19,7 +19,7 @@ use tokio::sync::mpsc::UnboundedSender;
use std::sync::mpsc::Sender; use std::sync::mpsc::Sender;
use super::{Component, PartialComponent, CurrentTab}; use super::{Component, PartialComponent, CurrentTab};
use crate::types::{ActionLevel, ActionTarget, SystemAccount}; use crate::types::{ActionLevel, SystemAccount};
use crate::widgets::DotSpinner; use crate::widgets::DotSpinner;
use crate::{ use crate::{
action::Action, action::Action,
@ -94,8 +94,7 @@ impl AddressBook {
fn log_event(&mut self, message: String, level: ActionLevel) { fn log_event(&mut self, message: String, level: ActionLevel) {
if let Some(action_tx) = &self.action_tx { if let Some(action_tx) = &self.action_tx {
let _ = action_tx.send( let _ = action_tx.send(Action::WalletLog(message, level));
Action::EventLog(message, level, ActionTarget::WalletLog));
} }
} }

View File

@ -13,14 +13,14 @@ use ratatui::{
use super::{Component, PartialComponent, CurrentTab}; use super::{Component, PartialComponent, CurrentTab};
use crate::{ use crate::{
types::ActionLevel,
action::Action, action::Action,
config::Config, config::Config,
palette::StylePalette, palette::StylePalette,
types::{ActionLevel, ActionTarget},
}; };
#[derive(Debug, Default)] #[derive(Debug, Default)]
struct LogDetails { struct WalletLog {
time: chrono::DateTime<chrono::Local>, time: chrono::DateTime<chrono::Local>,
level: ActionLevel, level: ActionLevel,
message: String, message: String,
@ -31,7 +31,7 @@ pub struct EventLogs {
is_active: bool, is_active: bool,
scroll_state: ScrollbarState, scroll_state: ScrollbarState,
table_state: TableState, table_state: TableState,
logs: std::collections::VecDeque<LogDetails>, logs: std::collections::VecDeque<WalletLog>,
palette: StylePalette palette: StylePalette
} }
@ -39,7 +39,7 @@ impl EventLogs {
const MAX_LOGS: usize = 50; const MAX_LOGS: usize = 50;
fn add_new_log(&mut self, message: String, level: ActionLevel) { fn add_new_log(&mut self, message: String, level: ActionLevel) {
self.logs.push_front(LogDetails { self.logs.push_front(WalletLog {
time: chrono::Local::now(), time: chrono::Local::now(),
level, level,
message, message,
@ -137,8 +137,7 @@ impl Component for EventLogs {
fn update(&mut self, action: Action) -> Result<Option<Action>> { fn update(&mut self, action: Action) -> Result<Option<Action>> {
match action { match action {
Action::EventLog(message, level, target) if target == ActionTarget::WalletLog => Action::WalletLog(message, level) => self.add_new_log(message, level),
self.add_new_log(message, level),
_ => {} _ => {}
}; };
Ok(None) Ok(None)

View File

@ -17,7 +17,7 @@ use crate::{
action::Action, action::Action,
config::Config, config::Config,
palette::StylePalette, palette::StylePalette,
types::{ActionLevel, ActionTarget}, types::ActionLevel,
widgets::{Input, InputRequest}, widgets::{Input, InputRequest},
}; };
@ -61,8 +61,7 @@ impl Transfer {
fn log_event(&mut self, message: String, level: ActionLevel) { fn log_event(&mut self, message: String, level: ActionLevel) {
if let Some(action_tx) = &self.action_tx { if let Some(action_tx) = &self.action_tx {
let _ = action_tx.send( let _ = action_tx.send(Action::WalletLog(message, level));
Action::EventLog(message, level, ActionTarget::WalletLog));
} }
} }

View File

@ -17,19 +17,13 @@ mod raw_calls;
pub use miscellaneous::{prepare_perbill_fraction_string, calculate_for_fraction}; pub use miscellaneous::{prepare_perbill_fraction_string, calculate_for_fraction};
use crate::{ use crate::{
types::{ActionLevel, ActionTarget}, types::ActionLevel,
action::Action, action::Action,
casper::CasperConfig, casper::CasperConfig,
}; };
pub use subscriptions::{FinalizedSubscription, BestSubscription}; pub use subscriptions::{FinalizedSubscription, BestSubscription};
struct TxToWatch {
tx_progress: TxProgress<CasperConfig, OnlineClient<CasperConfig>>,
sender: String,
target: ActionTarget,
}
pub struct Network { pub struct Network {
action_tx: UnboundedSender<Action>, action_tx: UnboundedSender<Action>,
online_client_api: OnlineClient<CasperConfig>, online_client_api: OnlineClient<CasperConfig>,
@ -38,7 +32,7 @@ pub struct Network {
finalized_hash: Option<H256>, finalized_hash: Option<H256>,
stash_to_watch: Option<[u8; 32]>, stash_to_watch: Option<[u8; 32]>,
accounts_to_watch: std::collections::HashSet<[u8; 32]>, accounts_to_watch: std::collections::HashSet<[u8; 32]>,
transactions_to_watch: Vec<TxToWatch>, transactions_to_watch: Vec<TxProgress<CasperConfig, OnlineClient<CasperConfig>>>,
senders: std::collections::HashMap<String, u32>, senders: std::collections::HashMap<String, u32>,
} }
@ -83,13 +77,6 @@ impl Network {
} }
} }
fn remove_transaction_and_decrement_nonce(&mut self, index: usize) {
let removed = self.transactions_to_watch.remove(index);
self.senders
.get_mut(&removed.sender)
.map(|nonce| *nonce = nonce.saturating_sub(1));
}
pub async fn handle_network_event(&mut self, io_event: Action) -> Result<()> { pub async fn handle_network_event(&mut self, io_event: Action) -> Result<()> {
match io_event { match io_event {
Action::NewBestHash(hash) => { Action::NewBestHash(hash) => {
@ -116,36 +103,35 @@ impl Network {
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];
let ext_hash = pending_tx.tx_progress.extrinsic_hash(); let ext_hash = pending_tx.extrinsic_hash();
let log_target = pending_tx.target.clone(); match (*pending_tx).next().await {
match (*pending_tx).tx_progress.next().await {
Some(Ok(status)) => { Some(Ok(status)) => {
match status { match status {
TxStatus::Validated => self.action_tx.send(Action::EventLog(format!("transaction {} is part of future queue", ext_hash), ActionLevel::Info, log_target))?, TxStatus::Validated => self.action_tx.send(Action::WalletLog(format!("transaction {} is part of future queue", ext_hash), ActionLevel::Info))?,
TxStatus::Broadcasted { num_peers } => self.action_tx.send(Action::EventLog(format!("transaction {} has been broardcasted to {} nodes", ext_hash, num_peers), ActionLevel::Info, log_target))?, TxStatus::Broadcasted { num_peers } => self.action_tx.send(Action::WalletLog(format!("transaction {} has been broardcasted to {} nodes", ext_hash, num_peers), ActionLevel::Info))?,
TxStatus::NoLongerInBestBlock => self.action_tx.send(Action::EventLog(format!("transaction {} is no longer in a best block", ext_hash), ActionLevel::Warn, log_target))?, TxStatus::NoLongerInBestBlock => self.action_tx.send(Action::WalletLog(format!("transaction {} is no longer in a best block", ext_hash), ActionLevel::Warn))?,
TxStatus::InBestBlock(b) => self.action_tx.send(Action::EventLog(format!("transaction {} included in the block header {}", b.extrinsic_hash(), b.block_hash()), ActionLevel::Info, log_target))?, TxStatus::InBestBlock(b) => self.action_tx.send(Action::WalletLog(format!("transaction {} included in the block header {}", b.extrinsic_hash(), b.block_hash()), ActionLevel::Info))?,
TxStatus::InFinalizedBlock(b) => { TxStatus::InFinalizedBlock(b) => {
self.action_tx.send(Action::EventLog(format!("transaction {} has been finalized in block header {}", b.extrinsic_hash(), b.block_hash()), ActionLevel::Info, log_target))?; self.action_tx.send(Action::WalletLog(format!("transaction {} has been finalized in block header {}", b.extrinsic_hash(), b.block_hash()), ActionLevel::Info))?;
self.transactions_to_watch.remove(i); self.transactions_to_watch.remove(i);
} }
TxStatus::Error { message } => { TxStatus::Error { message } => {
self.action_tx.send(Action::EventLog(format!("transaction {} error, something get wrong: {message}", ext_hash), ActionLevel::Error, log_target))?; self.action_tx.send(Action::WalletLog(format!("transaction {} error, something get wrong: {message}", ext_hash), ActionLevel::Error))?;
self.remove_transaction_and_decrement_nonce(i); self.transactions_to_watch.remove(i);
} }
TxStatus::Invalid { message } => { TxStatus::Invalid { message } => {
self.action_tx.send(Action::EventLog(format!("transaction {} invalid: {message}", ext_hash), ActionLevel::Error, log_target))?; self.action_tx.send(Action::WalletLog(format!("transaction {} invalid: {message}", ext_hash), ActionLevel::Error))?;
self.remove_transaction_and_decrement_nonce(i); self.transactions_to_watch.remove(i);
} }
TxStatus::Dropped { message } => { TxStatus::Dropped { message } => {
self.action_tx.send(Action::EventLog(format!("transaction {} was dropped: {message}", ext_hash), ActionLevel::Error, log_target))?; self.action_tx.send(Action::WalletLog(format!("transaction {} was dropped: {message}", ext_hash), ActionLevel::Error))?;
self.remove_transaction_and_decrement_nonce(i); self.transactions_to_watch.remove(i);
} }
} }
}, },
_ => { _ => {
self.action_tx.send(Action::EventLog(format!("transaction {} was dropped", ext_hash), ActionLevel::Error, log_target))?; self.action_tx.send(Action::WalletLog(format!("transaction {} was dropped", ext_hash), ActionLevel::Error))?;
self.remove_transaction_and_decrement_nonce(i); self.transactions_to_watch.remove(i);
} }
} }
} }
@ -220,7 +206,6 @@ impl Network {
} }
} }
Action::TransferBalance(sender, receiver, amount) => { Action::TransferBalance(sender, receiver, amount) => {
let sender_cloned = sender.clone();
let maybe_nonce = self.senders.get_mut(&sender); let maybe_nonce = self.senders.get_mut(&sender);
let sender: [u8; 32] = hex::decode(sender) let sender: [u8; 32] = hex::decode(sender)
@ -237,11 +222,7 @@ impl Network {
&amount, &amount,
maybe_nonce, maybe_nonce,
).await { ).await {
self.transactions_to_watch.push(TxToWatch { self.transactions_to_watch.push(tx_progress);
tx_progress,
sender: sender_cloned,
target: ActionTarget::WalletLog,
});
} }
Ok(()) Ok(())
} }

View File

@ -8,7 +8,7 @@ use tokio::sync::mpsc::UnboundedSender;
use crate::{ use crate::{
action::Action, action::Action,
types::{ActionLevel, ActionTarget}, types::ActionLevel,
casper::{CasperExtrinsicParamsBuilder, CasperConfig}, casper::{CasperExtrinsicParamsBuilder, CasperConfig},
casper_network, casper_network,
}; };
@ -47,17 +47,14 @@ pub async fn transfer_balance(
.sign_and_submit_then_watch(&transfer_tx, &signer, tx_params) .sign_and_submit_then_watch(&transfer_tx, &signer, tx_params)
.await { .await {
Ok(tx_progress) => { Ok(tx_progress) => {
action_tx.send(Action::EventLog( action_tx.send(Action::WalletLog(
format!("transfer transaction {} sent", tx_progress.extrinsic_hash()), format!("transfer transaction {} sent", tx_progress.extrinsic_hash()),
ActionLevel::Info, ActionLevel::Info))?;
ActionTarget::WalletLog))?;
Ok(tx_progress) Ok(tx_progress)
}, },
Err(err) => { Err(err) => {
action_tx.send(Action::EventLog( action_tx.send(Action::WalletLog(
format!("error during transfer: {err}"), format!("error during transfer: {err}"), ActionLevel::Error))?;
ActionLevel::Error,
ActionTarget::WalletLog))?;
Err(err.into()) Err(err.into())
} }
} }

View File

@ -8,11 +8,3 @@ pub enum ActionLevel {
Warn, Warn,
Error, Error,
} }
#[derive(Default, Debug, Clone, PartialEq, Eq, Display, Serialize, Deserialize)]
pub enum ActionTarget {
#[default]
WalletLog,
ValidatorLog,
NominatorLog,
}

View File

@ -9,7 +9,6 @@ mod nominator;
pub use extrinsics::CasperExtrinsicDetails; pub use extrinsics::CasperExtrinsicDetails;
pub use era::{EraRewardPoints, EraInfo}; pub use era::{EraRewardPoints, EraInfo};
pub use log::ActionLevel; pub use log::ActionLevel;
pub use log::ActionTarget;
pub use account::SystemAccount; pub use account::SystemAccount;
pub use peer::PeerInformation; pub use peer::PeerInformation;
pub use session::SessionKeyInfo; pub use session::SessionKeyInfo;