add parameter target to the log event on each page

Signed-off-by: Uncle Stretch <uncle.stretch@ghostchain.io>
This commit is contained in:
Uncle Stretch 2025-01-24 15:55:47 +03:00
parent 493a4db663
commit 8f63c7483d
Signed by: str3tch
GPG Key ID: 84F3190747EE79AA
12 changed files with 73 additions and 48 deletions

View File

@ -5,7 +5,8 @@ use subxt::utils::H256;
use subxt::config::substrate::DigestItem; use subxt::config::substrate::DigestItem;
use crate::types::{ use crate::types::{
ActionLevel, CasperExtrinsicDetails, EraInfo, EraRewardPoints, Nominator, PeerInformation, SessionKeyInfo, SystemAccount ActionLevel, ActionTarget, CasperExtrinsicDetails, EraInfo, EraRewardPoints,
Nominator, PeerInformation, SessionKeyInfo, SystemAccount,
}; };
#[derive(Debug, Clone, PartialEq, Eq, Display, Serialize, Deserialize)] #[derive(Debug, Clone, PartialEq, Eq, Display, Serialize, Deserialize)]
@ -46,8 +47,7 @@ pub enum Action {
TransferTo(String), TransferTo(String),
TransferBalance(String, [u8; 32], u128), TransferBalance(String, [u8; 32], u128),
WalletLog(String, ActionLevel), EventLog(String, ActionLevel, ActionTarget),
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 WalletLog { struct LogDetails {
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<WalletLog>, logs: std::collections::VecDeque<LogDetails>,
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![
WalletLog { LogDetails {
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(WalletLog { // self.logs.push_front(LogDetails {
// time: chrono::Local::now(), // time: chrono::Local::now(),
// level, // level,
// message, // message,
@ -156,7 +156,8 @@ 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::ValidatorLog(message, level) => self.add_new_log(message, level), // Action::EventLog(message, level, target) if target == ActionTarget::NominatorLog =>
// self.add_new_log(message, level),
// _ => {} // _ => {}
//}; //};
Ok(None) Ok(None)

View File

@ -13,14 +13,11 @@ use ratatui::{
use super::{Component, PartialComponent, CurrentTab}; use super::{Component, PartialComponent, CurrentTab};
use crate::{ use crate::{
types::ActionLevel, action::Action, config::Config, palette::StylePalette, types::{ActionLevel, ActionTarget}
action::Action,
config::Config,
palette::StylePalette,
}; };
#[derive(Debug, Default)] #[derive(Debug, Default)]
struct WalletLog { struct LogDetails {
time: chrono::DateTime<chrono::Local>, time: chrono::DateTime<chrono::Local>,
level: ActionLevel, level: ActionLevel,
message: String, message: String,
@ -31,7 +28,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<WalletLog>, logs: std::collections::VecDeque<LogDetails>,
palette: StylePalette palette: StylePalette
} }
@ -39,7 +36,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(WalletLog { self.logs.push_front(LogDetails {
time: chrono::Local::now(), time: chrono::Local::now(),
level, level,
message, message,
@ -137,7 +134,8 @@ 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::ValidatorLog(message, level) => self.add_new_log(message, level), Action::EventLog(message, level, target) if target == ActionTarget::ValidatorLog =>
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; use crate::types::{ActionLevel, ActionTarget};
use crate::{ use crate::{
types::SessionKeyInfo, types::SessionKeyInfo,
action::Action, action::Action,
@ -76,7 +76,8 @@ 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(Action::ValidatorLog(message, level)); let _ = action_tx.send(
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::{SystemAccount, ActionLevel}; use crate::types::{ActionLevel, ActionTarget, SystemAccount};
use crate::widgets::DotSpinner; use crate::widgets::DotSpinner;
use crate::{ use crate::{
action::Action, action::Action,
@ -96,7 +96,8 @@ 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(Action::WalletLog(message, level)); let _ = action_tx.send(
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, SystemAccount}; use crate::types::{ActionLevel, ActionTarget, SystemAccount};
use crate::widgets::DotSpinner; use crate::widgets::DotSpinner;
use crate::{ use crate::{
action::Action, action::Action,
@ -94,7 +94,8 @@ 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(Action::WalletLog(message, level)); let _ = action_tx.send(
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 WalletLog { struct LogDetails {
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<WalletLog>, logs: std::collections::VecDeque<LogDetails>,
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(WalletLog { self.logs.push_front(LogDetails {
time: chrono::Local::now(), time: chrono::Local::now(),
level, level,
message, message,
@ -137,7 +137,8 @@ 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::WalletLog(message, level) => self.add_new_log(message, level), Action::EventLog(message, level, target) if target == ActionTarget::WalletLog =>
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, types::{ActionLevel, ActionTarget},
widgets::{Input, InputRequest}, widgets::{Input, InputRequest},
}; };
@ -61,7 +61,8 @@ 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(Action::WalletLog(message, level)); let _ = action_tx.send(
Action::EventLog(message, level, ActionTarget::WalletLog));
} }
} }

View File

@ -17,13 +17,18 @@ 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, types::{ActionLevel, ActionTarget},
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>>,
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>,
@ -32,7 +37,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<TxProgress<CasperConfig, OnlineClient<CasperConfig>>>, transactions_to_watch: Vec<TxToWatch>,
senders: std::collections::HashMap<String, u32>, senders: std::collections::HashMap<String, u32>,
} }
@ -103,34 +108,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.extrinsic_hash(); let ext_hash = pending_tx.tx_progress.extrinsic_hash();
match (*pending_tx).next().await { let log_target = pending_tx.target.clone();
match (*pending_tx).tx_progress.next().await {
Some(Ok(status)) => { Some(Ok(status)) => {
match status { match status {
TxStatus::Validated => self.action_tx.send(Action::WalletLog(format!("transaction {} is part of future queue", ext_hash), ActionLevel::Info))?, TxStatus::Validated => self.action_tx.send(Action::EventLog(format!("transaction {} is part of future queue", ext_hash), 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::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::NoLongerInBestBlock => self.action_tx.send(Action::WalletLog(format!("transaction {} is no longer in a best block", ext_hash), ActionLevel::Warn))?, TxStatus::NoLongerInBestBlock => self.action_tx.send(Action::EventLog(format!("transaction {} is no longer in a best block", ext_hash), ActionLevel::Warn, 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::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::InFinalizedBlock(b) => { TxStatus::InFinalizedBlock(b) => {
self.action_tx.send(Action::WalletLog(format!("transaction {} has been finalized in block header {}", b.extrinsic_hash(), b.block_hash()), ActionLevel::Info))?; 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.transactions_to_watch.remove(i); self.transactions_to_watch.remove(i);
} }
TxStatus::Error { message } => { TxStatus::Error { message } => {
self.action_tx.send(Action::WalletLog(format!("transaction {} error, something get wrong: {message}", ext_hash), ActionLevel::Error))?; self.action_tx.send(Action::EventLog(format!("transaction {} error, something get wrong: {message}", ext_hash), ActionLevel::Error, log_target))?;
self.transactions_to_watch.remove(i); self.transactions_to_watch.remove(i);
} }
TxStatus::Invalid { message } => { TxStatus::Invalid { message } => {
self.action_tx.send(Action::WalletLog(format!("transaction {} invalid: {message}", ext_hash), ActionLevel::Error))?; self.action_tx.send(Action::EventLog(format!("transaction {} invalid: {message}", ext_hash), ActionLevel::Error, log_target))?;
self.transactions_to_watch.remove(i); self.transactions_to_watch.remove(i);
} }
TxStatus::Dropped { message } => { TxStatus::Dropped { message } => {
self.action_tx.send(Action::WalletLog(format!("transaction {} was dropped: {message}", ext_hash), ActionLevel::Error))?; self.action_tx.send(Action::EventLog(format!("transaction {} was dropped: {message}", ext_hash), ActionLevel::Error, log_target))?;
self.transactions_to_watch.remove(i); self.transactions_to_watch.remove(i);
} }
} }
}, },
_ => { _ => {
self.action_tx.send(Action::WalletLog(format!("transaction {} was dropped", ext_hash), ActionLevel::Error))?; self.action_tx.send(Action::EventLog(format!("transaction {} was dropped", ext_hash), ActionLevel::Error, log_target))?;
self.transactions_to_watch.remove(i); self.transactions_to_watch.remove(i);
} }
} }
@ -222,7 +228,10 @@ impl Network {
&amount, &amount,
maybe_nonce, maybe_nonce,
).await { ).await {
self.transactions_to_watch.push(tx_progress); self.transactions_to_watch.push(TxToWatch {
tx_progress,
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, types::{ActionLevel, ActionTarget},
casper::{CasperExtrinsicParamsBuilder, CasperConfig}, casper::{CasperExtrinsicParamsBuilder, CasperConfig},
casper_network, casper_network,
}; };
@ -47,14 +47,17 @@ 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::WalletLog( action_tx.send(Action::EventLog(
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::WalletLog( action_tx.send(Action::EventLog(
format!("error during transfer: {err}"), ActionLevel::Error))?; format!("error during transfer: {err}"),
ActionLevel::Error,
ActionTarget::WalletLog))?;
Err(err.into()) Err(err.into())
} }
} }

View File

@ -8,3 +8,11 @@ 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,6 +9,7 @@ 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;