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 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)]
@ -46,8 +47,7 @@ pub enum Action {
TransferTo(String),
TransferBalance(String, [u8; 32], u128),
WalletLog(String, ActionLevel),
ValidatorLog(String, ActionLevel),
EventLog(String, ActionLevel, ActionTarget),
NewBestBlock(u32),
NewBestHash(H256),

View File

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

View File

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

View File

@ -29,7 +29,7 @@ use std::sync::mpsc::Sender;
use super::{PartialComponent, Component, CurrentTab};
use crate::casper::CasperConfig;
use crate::types::ActionLevel;
use crate::types::{ActionLevel, ActionTarget};
use crate::{
types::SessionKeyInfo,
action::Action,
@ -76,7 +76,8 @@ impl StashInfo {
fn log_event(&mut self, message: String, level: ActionLevel) {
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 super::{PartialComponent, Component, CurrentTab};
use crate::types::{SystemAccount, ActionLevel};
use crate::types::{ActionLevel, ActionTarget, SystemAccount};
use crate::widgets::DotSpinner;
use crate::{
action::Action,
@ -96,7 +96,8 @@ impl Accounts {
fn log_event(&mut self, message: String, level: ActionLevel) {
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 super::{Component, PartialComponent, CurrentTab};
use crate::types::{ActionLevel, SystemAccount};
use crate::types::{ActionLevel, ActionTarget, SystemAccount};
use crate::widgets::DotSpinner;
use crate::{
action::Action,
@ -94,7 +94,8 @@ impl AddressBook {
fn log_event(&mut self, message: String, level: ActionLevel) {
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 crate::{
types::ActionLevel,
action::Action,
config::Config,
palette::StylePalette,
types::{ActionLevel, ActionTarget},
};
#[derive(Debug, Default)]
struct WalletLog {
struct LogDetails {
time: chrono::DateTime<chrono::Local>,
level: ActionLevel,
message: String,
@ -31,7 +31,7 @@ pub struct EventLogs {
is_active: bool,
scroll_state: ScrollbarState,
table_state: TableState,
logs: std::collections::VecDeque<WalletLog>,
logs: std::collections::VecDeque<LogDetails>,
palette: StylePalette
}
@ -39,7 +39,7 @@ impl EventLogs {
const MAX_LOGS: usize = 50;
fn add_new_log(&mut self, message: String, level: ActionLevel) {
self.logs.push_front(WalletLog {
self.logs.push_front(LogDetails {
time: chrono::Local::now(),
level,
message,
@ -137,7 +137,8 @@ impl Component for EventLogs {
fn update(&mut self, action: Action) -> Result<Option<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)

View File

@ -17,7 +17,7 @@ use crate::{
action::Action,
config::Config,
palette::StylePalette,
types::ActionLevel,
types::{ActionLevel, ActionTarget},
widgets::{Input, InputRequest},
};
@ -61,7 +61,8 @@ impl Transfer {
fn log_event(&mut self, message: String, level: ActionLevel) {
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};
use crate::{
types::ActionLevel,
types::{ActionLevel, ActionTarget},
action::Action,
casper::CasperConfig,
};
pub use subscriptions::{FinalizedSubscription, BestSubscription};
struct TxToWatch {
tx_progress: TxProgress<CasperConfig, OnlineClient<CasperConfig>>,
target: ActionTarget,
}
pub struct Network {
action_tx: UnboundedSender<Action>,
online_client_api: OnlineClient<CasperConfig>,
@ -32,7 +37,7 @@ pub struct Network {
finalized_hash: Option<H256>,
stash_to_watch: Option<[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>,
}
@ -103,34 +108,35 @@ impl Network {
let length = self.transactions_to_watch.len();
for i in (0..length).rev() {
let pending_tx = &mut self.transactions_to_watch[i];
let ext_hash = pending_tx.extrinsic_hash();
match (*pending_tx).next().await {
let ext_hash = pending_tx.tx_progress.extrinsic_hash();
let log_target = pending_tx.target.clone();
match (*pending_tx).tx_progress.next().await {
Some(Ok(status)) => {
match status {
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::WalletLog(format!("transaction {} has been broardcasted to {} nodes", ext_hash, num_peers), ActionLevel::Info))?,
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::WalletLog(format!("transaction {} included in the block header {}", b.extrinsic_hash(), b.block_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::EventLog(format!("transaction {} has been broardcasted to {} nodes", ext_hash, num_peers), ActionLevel::Info, log_target))?,
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::EventLog(format!("transaction {} included in the block header {}", b.extrinsic_hash(), b.block_hash()), ActionLevel::Info, log_target))?,
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);
}
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);
}
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);
}
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.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);
}
}
@ -222,7 +228,10 @@ impl Network {
&amount,
maybe_nonce,
).await {
self.transactions_to_watch.push(tx_progress);
self.transactions_to_watch.push(TxToWatch {
tx_progress,
target: ActionTarget::WalletLog,
});
}
Ok(())
}

View File

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

View File

@ -8,3 +8,11 @@ pub enum ActionLevel {
Warn,
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 era::{EraRewardPoints, EraInfo};
pub use log::ActionLevel;
pub use log::ActionTarget;
pub use account::SystemAccount;
pub use peer::PeerInformation;
pub use session::SessionKeyInfo;