Compare commits
No commits in common. "7e9e6ac329cc58411cb2c7cbddb8384692f29f16" and "853bdcd76e870e402603a6eb70f9ed0c33d9cfb4" have entirely different histories.
7e9e6ac329
...
853bdcd76e
@ -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.18"
|
version = "0.3.17"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
@ -30,11 +30,8 @@ pub enum Action {
|
|||||||
NewAccount(String),
|
NewAccount(String),
|
||||||
NewAddressBookRecord(String, String),
|
NewAddressBookRecord(String, String),
|
||||||
SetSender(String, Option<u32>),
|
SetSender(String, Option<u32>),
|
||||||
RemoveEraToWatch(u32),
|
|
||||||
|
|
||||||
ClosePopup,
|
ClosePopup,
|
||||||
RotateSessionKeys,
|
|
||||||
PayoutValidatorPopup(u32, bool),
|
|
||||||
|
|
||||||
BalanceRequest([u8; 32], bool),
|
BalanceRequest([u8; 32], bool),
|
||||||
BalanceResponse([u8; 32], Option<SystemAccount>),
|
BalanceResponse([u8; 32], Option<SystemAccount>),
|
||||||
@ -51,9 +48,6 @@ pub enum Action {
|
|||||||
AccountDetailsOf(String, Option<SystemAccount>),
|
AccountDetailsOf(String, Option<SystemAccount>),
|
||||||
|
|
||||||
TransferBalance(String, [u8; 32], u128),
|
TransferBalance(String, [u8; 32], u128),
|
||||||
BondValidatorExtraFrom([u8; 32], u128),
|
|
||||||
BondValidatorFrom([u8; 32], u128),
|
|
||||||
PayoutStakers([u8; 32], [u8; 32], u32),
|
|
||||||
EventLog(String, ActionLevel, ActionTarget),
|
EventLog(String, ActionLevel, ActionTarget),
|
||||||
|
|
||||||
NewBestBlock(u32),
|
NewBestBlock(u32),
|
||||||
@ -104,7 +98,6 @@ pub enum Action {
|
|||||||
SetChainName(Option<String>),
|
SetChainName(Option<String>),
|
||||||
SetChainVersion(Option<String>),
|
SetChainVersion(Option<String>),
|
||||||
SetStashAccount([u8; 32]),
|
SetStashAccount([u8; 32]),
|
||||||
SetStashSecret([u8; 32]),
|
|
||||||
|
|
||||||
BestBlockInformation(H256, u32),
|
BestBlockInformation(H256, u32),
|
||||||
FinalizedBlockInformation(H256, u32),
|
FinalizedBlockInformation(H256, u32),
|
||||||
@ -122,7 +115,7 @@ pub enum Action {
|
|||||||
SetValidatorEraClaimed(u32, bool),
|
SetValidatorEraClaimed(u32, bool),
|
||||||
SetValidatorEraSlash(u32, u128),
|
SetValidatorEraSlash(u32, u128),
|
||||||
SetValidatorEraUnlocking(u32, u128),
|
SetValidatorEraUnlocking(u32, u128),
|
||||||
SetIsBonded(bool),
|
SetBondedAmount(bool),
|
||||||
SetStakedAmountRatio(u128, u128),
|
SetStakedAmountRatio(u128, u128),
|
||||||
SetStakedRatio(u128, u128),
|
SetStakedRatio(u128, u128),
|
||||||
SetValidatorPrefs(u32, bool),
|
SetValidatorPrefs(u32, bool),
|
||||||
@ -130,9 +123,7 @@ pub enum Action {
|
|||||||
|
|
||||||
GetTotalIssuance,
|
GetTotalIssuance,
|
||||||
GetExistentialDeposit,
|
GetExistentialDeposit,
|
||||||
GetMinValidatorBond,
|
|
||||||
|
|
||||||
SetExistentialDeposit(u128),
|
SetExistentialDeposit(u128),
|
||||||
SetMinValidatorBond(u128),
|
|
||||||
SetTotalIssuance(Option<u128>),
|
SetTotalIssuance(Option<u128>),
|
||||||
}
|
}
|
||||||
|
@ -1,179 +0,0 @@
|
|||||||
use crossterm::event::{KeyCode, KeyEvent, KeyEventKind};
|
|
||||||
use color_eyre::Result;
|
|
||||||
use ratatui::{
|
|
||||||
layout::{Position, Alignment, Constraint, Flex, Layout, Rect},
|
|
||||||
widgets::{Block, Clear, Paragraph},
|
|
||||||
Frame
|
|
||||||
};
|
|
||||||
use tokio::sync::mpsc::UnboundedSender;
|
|
||||||
use std::sync::mpsc::Sender;
|
|
||||||
|
|
||||||
use super::{Component, PartialComponent, CurrentTab};
|
|
||||||
use crate::{
|
|
||||||
action::Action, config::Config, palette::StylePalette, types::{ActionLevel, ActionTarget}, widgets::{Input, InputRequest}
|
|
||||||
};
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct BondPopup {
|
|
||||||
is_active: bool,
|
|
||||||
action_tx: Option<UnboundedSender<Action>>,
|
|
||||||
network_tx: Option<Sender<Action>>,
|
|
||||||
secret_seed: [u8; 32],
|
|
||||||
minimal_bond: u128,
|
|
||||||
is_bonded: bool,
|
|
||||||
amount: Input,
|
|
||||||
palette: StylePalette
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Default for BondPopup {
|
|
||||||
fn default() -> Self {
|
|
||||||
Self::new()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl BondPopup {
|
|
||||||
pub fn new() -> Self {
|
|
||||||
Self {
|
|
||||||
is_active: false,
|
|
||||||
secret_seed: [0u8; 32],
|
|
||||||
action_tx: None,
|
|
||||||
network_tx: None,
|
|
||||||
minimal_bond: 0u128,
|
|
||||||
is_bonded: false,
|
|
||||||
amount: Input::new(String::new()),
|
|
||||||
palette: StylePalette::default(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl BondPopup {
|
|
||||||
fn log_event(&mut self, message: String, level: ActionLevel) {
|
|
||||||
if let Some(action_tx) = &self.action_tx {
|
|
||||||
let _ = action_tx.send(
|
|
||||||
Action::EventLog(message, level, ActionTarget::ValidatorLog));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn submit_message(&mut self) {
|
|
||||||
if let Some(network_tx) = &self.network_tx {
|
|
||||||
match self.amount.value().parse::<f64>() {
|
|
||||||
Ok(value) => {
|
|
||||||
let amount = (value * 1_000_000_000_000_000_000.0) as u128;
|
|
||||||
let _ = if self.is_bonded {
|
|
||||||
network_tx.send(Action::BondValidatorExtraFrom(self.secret_seed, amount))
|
|
||||||
} else {
|
|
||||||
network_tx.send(Action::BondValidatorFrom(self.secret_seed, amount))
|
|
||||||
};
|
|
||||||
if let Some(action_tx) = &self.action_tx {
|
|
||||||
let _ = action_tx.send(Action::ClosePopup);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
Err(err) => self.log_event(
|
|
||||||
format!("invalid amount, error: {err}"), ActionLevel::Error),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn enter_char(&mut self, new_char: char) {
|
|
||||||
let is_separator_needed = !self.amount.value().contains('.') && new_char == '.';
|
|
||||||
if new_char.is_digit(10) || is_separator_needed {
|
|
||||||
let _ = self.amount.handle(InputRequest::InsertChar(new_char));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn delete_char(&mut self) {
|
|
||||||
let _ = self.amount.handle(InputRequest::DeletePrevChar);
|
|
||||||
}
|
|
||||||
|
|
||||||
fn move_cursor_right(&mut self) {
|
|
||||||
let _ = self.amount.handle(InputRequest::GoToNextChar);
|
|
||||||
}
|
|
||||||
|
|
||||||
fn move_cursor_left(&mut self) {
|
|
||||||
let _ = self.amount.handle(InputRequest::GoToPrevChar);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl PartialComponent for BondPopup {
|
|
||||||
fn set_active(&mut self, current_tab: CurrentTab) {
|
|
||||||
match current_tab {
|
|
||||||
CurrentTab::BondPopup => self.is_active = true,
|
|
||||||
_ => {
|
|
||||||
self.is_active = false;
|
|
||||||
self.amount = Input::new(String::new());
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Component for BondPopup {
|
|
||||||
fn register_network_handler(&mut self, tx: Sender<Action>) -> Result<()> {
|
|
||||||
self.network_tx = Some(tx);
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn register_action_handler(&mut self, tx: UnboundedSender<Action>) -> Result<()> {
|
|
||||||
self.action_tx = Some(tx);
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn register_config_handler(&mut self, config: Config) -> Result<()> {
|
|
||||||
if let Some(style) = config.styles.get(&crate::app::Mode::Wallet) {
|
|
||||||
self.palette.with_normal_style(style.get("normal_style").copied());
|
|
||||||
self.palette.with_normal_border_style(style.get("normal_border_style").copied());
|
|
||||||
self.palette.with_normal_title_style(style.get("normal_title_style").copied());
|
|
||||||
self.palette.with_popup_style(style.get("popup_style").copied());
|
|
||||||
self.palette.with_popup_title_style(style.get("popup_title_style").copied());
|
|
||||||
}
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
fn handle_key_event(&mut self, key: KeyEvent) -> Result<Option<Action>> {
|
|
||||||
if self.is_active && key.kind == KeyEventKind::Press {
|
|
||||||
match key.code {
|
|
||||||
KeyCode::Enter => self.submit_message(),
|
|
||||||
KeyCode::Char(to_insert) => self.enter_char(to_insert),
|
|
||||||
KeyCode::Backspace => self.delete_char(),
|
|
||||||
KeyCode::Left => self.move_cursor_left(),
|
|
||||||
KeyCode::Right => self.move_cursor_right(),
|
|
||||||
KeyCode::Esc => self.is_active = false,
|
|
||||||
_ => {},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
Ok(None)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn update(&mut self, action: Action) -> Result<Option<Action>> {
|
|
||||||
match action {
|
|
||||||
Action::SetIsBonded(is_bonded) => self.is_bonded = is_bonded,
|
|
||||||
Action::SetMinValidatorBond(minimal_bond) => self.minimal_bond = minimal_bond,
|
|
||||||
Action::SetStashSecret(secret_seed) => self.secret_seed = secret_seed,
|
|
||||||
_ => {}
|
|
||||||
};
|
|
||||||
Ok(None)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn draw(&mut self, frame: &mut Frame, area: Rect) -> Result<()> {
|
|
||||||
if self.is_active {
|
|
||||||
let (border_style, border_type) = self.palette.create_popup_style();
|
|
||||||
let input = Paragraph::new(self.amount.value())
|
|
||||||
.block(Block::bordered()
|
|
||||||
.border_style(border_style)
|
|
||||||
.border_type(border_type)
|
|
||||||
.title_style(self.palette.create_popup_title_style())
|
|
||||||
.title_alignment(Alignment::Right)
|
|
||||||
.title(format!("Staking bond amount")));
|
|
||||||
let v = Layout::vertical([Constraint::Max(3)]).flex(Flex::Center);
|
|
||||||
let h = Layout::horizontal([Constraint::Max(50)]).flex(Flex::Center);
|
|
||||||
let [area] = v.areas(area);
|
|
||||||
let [area] = h.areas(area);
|
|
||||||
|
|
||||||
frame.render_widget(Clear, area);
|
|
||||||
frame.render_widget(input, area);
|
|
||||||
frame.set_cursor_position(Position::new(
|
|
||||||
area.x + self.amount.cursor() as u16 + 1,
|
|
||||||
area.y + 1
|
|
||||||
));
|
|
||||||
}
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
@ -62,23 +62,6 @@ impl History {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn payout_by_era_index(&mut self) {
|
|
||||||
if let Some(index) = self.table_state.selected() {
|
|
||||||
let era_index = self.rewards
|
|
||||||
.keys()
|
|
||||||
.nth(index)
|
|
||||||
.expect("BTreeMap of rewards is indexed; qed");
|
|
||||||
let is_claimed = self.rewards
|
|
||||||
.get(era_index)
|
|
||||||
.map(|x| x.is_claimed)
|
|
||||||
.expect("BTreeMap of rewards is indexed; qed");
|
|
||||||
if let Some(action_tx) = &self.action_tx {
|
|
||||||
let _ = action_tx.send(
|
|
||||||
Action::PayoutValidatorPopup(*era_index, is_claimed));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn first_row(&mut self) {
|
fn first_row(&mut self) {
|
||||||
if self.rewards.len() > 0 {
|
if self.rewards.len() > 0 {
|
||||||
self.table_state.select(Some(0));
|
self.table_state.select(Some(0));
|
||||||
@ -139,14 +122,7 @@ impl History {
|
|||||||
|
|
||||||
fn update_claims(&mut self, era_index: u32, is_claimed: bool) {
|
fn update_claims(&mut self, era_index: u32, is_claimed: bool) {
|
||||||
match self.rewards.get_mut(&era_index) {
|
match self.rewards.get_mut(&era_index) {
|
||||||
Some(reward_item) => {
|
Some(reward_item) => reward_item.is_claimed = is_claimed,
|
||||||
if reward_item.is_claimed == false && is_claimed == true {
|
|
||||||
if let Some(network_tx) = &self.network_tx {
|
|
||||||
let _ = network_tx.send(Action::RemoveEraToWatch(era_index));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
reward_item.is_claimed = is_claimed;
|
|
||||||
}
|
|
||||||
None => {
|
None => {
|
||||||
let _ = self.rewards.insert(era_index, EraStakingInfo {
|
let _ = self.rewards.insert(era_index, EraStakingInfo {
|
||||||
reward: 0u128,
|
reward: 0u128,
|
||||||
@ -183,8 +159,8 @@ impl PartialComponent for History {
|
|||||||
CurrentTab::History => self.is_active = true,
|
CurrentTab::History => self.is_active = true,
|
||||||
_ => {
|
_ => {
|
||||||
self.is_active = false;
|
self.is_active = false;
|
||||||
//self.table_state.select(None);
|
self.table_state.select(None);
|
||||||
//self.scroll_state = self.scroll_state.position(0);
|
self.scroll_state = self.scroll_state.position(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -232,7 +208,6 @@ impl Component for History {
|
|||||||
KeyCode::Down | KeyCode::Char('j') => self.next_row(),
|
KeyCode::Down | KeyCode::Char('j') => self.next_row(),
|
||||||
KeyCode::Char('g') => self.first_row(),
|
KeyCode::Char('g') => self.first_row(),
|
||||||
KeyCode::Char('G') => self.last_row(),
|
KeyCode::Char('G') => self.last_row(),
|
||||||
KeyCode::Enter => self.payout_by_era_index(),
|
|
||||||
_ => {},
|
_ => {},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -21,9 +21,6 @@ mod withdrawals;
|
|||||||
mod stash_details;
|
mod stash_details;
|
||||||
mod staking_details;
|
mod staking_details;
|
||||||
mod reward_details;
|
mod reward_details;
|
||||||
mod bond_popup;
|
|
||||||
mod payout_popup;
|
|
||||||
mod rotate_popup;
|
|
||||||
|
|
||||||
use stash_details::StashDetails;
|
use stash_details::StashDetails;
|
||||||
use staking_details::StakingDetails;
|
use staking_details::StakingDetails;
|
||||||
@ -35,11 +32,8 @@ use listen_addresses::ListenAddresses;
|
|||||||
use nominators::NominatorsByValidator;
|
use nominators::NominatorsByValidator;
|
||||||
use history::History;
|
use history::History;
|
||||||
use withdrawals::Withdrawals;
|
use withdrawals::Withdrawals;
|
||||||
use bond_popup::BondPopup;
|
|
||||||
use payout_popup::PayoutPopup;
|
|
||||||
use rotate_popup::RotatePopup;
|
|
||||||
|
|
||||||
#[derive(Debug, Copy, Clone, PartialEq)]
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
pub enum CurrentTab {
|
pub enum CurrentTab {
|
||||||
Nothing,
|
Nothing,
|
||||||
StashInfo,
|
StashInfo,
|
||||||
@ -49,9 +43,6 @@ pub enum CurrentTab {
|
|||||||
Withdrawals,
|
Withdrawals,
|
||||||
Peers,
|
Peers,
|
||||||
EventLogs,
|
EventLogs,
|
||||||
BondPopup,
|
|
||||||
PayoutPopup,
|
|
||||||
RotatePopup,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait PartialComponent: Component {
|
pub trait PartialComponent: Component {
|
||||||
@ -61,7 +52,6 @@ pub trait PartialComponent: Component {
|
|||||||
pub struct Validator {
|
pub struct Validator {
|
||||||
is_active: bool,
|
is_active: bool,
|
||||||
current_tab: CurrentTab,
|
current_tab: CurrentTab,
|
||||||
previous_tab: CurrentTab,
|
|
||||||
components: Vec<Box<dyn PartialComponent>>,
|
components: Vec<Box<dyn PartialComponent>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -70,7 +60,6 @@ impl Default for Validator {
|
|||||||
Self {
|
Self {
|
||||||
is_active: false,
|
is_active: false,
|
||||||
current_tab: CurrentTab::Nothing,
|
current_tab: CurrentTab::Nothing,
|
||||||
previous_tab: CurrentTab::Nothing,
|
|
||||||
components: vec![
|
components: vec![
|
||||||
Box::new(StashInfo::default()),
|
Box::new(StashInfo::default()),
|
||||||
Box::new(NominatorsByValidator::default()),
|
Box::new(NominatorsByValidator::default()),
|
||||||
@ -82,9 +71,6 @@ impl Default for Validator {
|
|||||||
Box::new(Peers::default()),
|
Box::new(Peers::default()),
|
||||||
Box::new(ListenAddresses::default()),
|
Box::new(ListenAddresses::default()),
|
||||||
Box::new(EventLogs::default()),
|
Box::new(EventLogs::default()),
|
||||||
Box::new(BondPopup::default()),
|
|
||||||
Box::new(PayoutPopup::default()),
|
|
||||||
Box::new(RotatePopup::default()),
|
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -142,23 +128,7 @@ impl Component for Validator {
|
|||||||
fn handle_key_event(&mut self, key: KeyEvent) -> Result<Option<Action>> {
|
fn handle_key_event(&mut self, key: KeyEvent) -> Result<Option<Action>> {
|
||||||
if !self.is_active { return Ok(None) }
|
if !self.is_active { return Ok(None) }
|
||||||
|
|
||||||
match self.current_tab {
|
match key.code {
|
||||||
CurrentTab::BondPopup |
|
|
||||||
CurrentTab::RotatePopup |
|
|
||||||
CurrentTab::PayoutPopup => match key.code {
|
|
||||||
KeyCode::Esc => {
|
|
||||||
self.current_tab = self.previous_tab;
|
|
||||||
for component in self.components.iter_mut() {
|
|
||||||
component.set_active(self.current_tab.clone());
|
|
||||||
}
|
|
||||||
},
|
|
||||||
_ => {
|
|
||||||
for component in self.components.iter_mut() {
|
|
||||||
component.handle_key_event(key)?;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
_ => match key.code {
|
|
||||||
KeyCode::Esc => {
|
KeyCode::Esc => {
|
||||||
self.is_active = false;
|
self.is_active = false;
|
||||||
self.current_tab = CurrentTab::Nothing;
|
self.current_tab = CurrentTab::Nothing;
|
||||||
@ -179,27 +149,12 @@ impl Component for Validator {
|
|||||||
component.set_active(self.current_tab.clone());
|
component.set_active(self.current_tab.clone());
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
KeyCode::Char('R') => {
|
|
||||||
self.previous_tab = self.current_tab;
|
|
||||||
self.current_tab = CurrentTab::RotatePopup;
|
|
||||||
for component in self.components.iter_mut() {
|
|
||||||
component.set_active(self.current_tab.clone());
|
|
||||||
}
|
|
||||||
},
|
|
||||||
KeyCode::Char('B') => {
|
|
||||||
self.previous_tab = self.current_tab;
|
|
||||||
self.current_tab = CurrentTab::BondPopup;
|
|
||||||
for component in self.components.iter_mut() {
|
|
||||||
component.set_active(self.current_tab.clone());
|
|
||||||
}
|
|
||||||
},
|
|
||||||
_ => {
|
_ => {
|
||||||
for component in self.components.iter_mut() {
|
for component in self.components.iter_mut() {
|
||||||
component.handle_key_event(key)?;
|
component.handle_key_event(key)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
Ok(None)
|
Ok(None)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -208,13 +163,6 @@ impl Component for Validator {
|
|||||||
Action::SetActiveScreen(Mode::Validator) => {
|
Action::SetActiveScreen(Mode::Validator) => {
|
||||||
self.is_active = true;
|
self.is_active = true;
|
||||||
self.current_tab = CurrentTab::StashInfo;
|
self.current_tab = CurrentTab::StashInfo;
|
||||||
}
|
|
||||||
Action::PayoutValidatorPopup(_, _) => {
|
|
||||||
self.previous_tab = self.current_tab;
|
|
||||||
self.current_tab = CurrentTab::PayoutPopup;
|
|
||||||
}
|
|
||||||
Action::ClosePopup => {
|
|
||||||
self.current_tab = self.previous_tab;
|
|
||||||
},
|
},
|
||||||
_ => {},
|
_ => {},
|
||||||
}
|
}
|
||||||
|
@ -1,152 +0,0 @@
|
|||||||
use crossterm::event::{KeyCode, KeyEvent, KeyEventKind};
|
|
||||||
use color_eyre::Result;
|
|
||||||
use ratatui::{
|
|
||||||
layout::{Alignment, Constraint, Flex, Layout, Rect},
|
|
||||||
widgets::{Block, Clear, Paragraph},
|
|
||||||
Frame
|
|
||||||
};
|
|
||||||
use tokio::sync::mpsc::UnboundedSender;
|
|
||||||
use std::sync::mpsc::Sender;
|
|
||||||
|
|
||||||
use super::{Component, PartialComponent, CurrentTab};
|
|
||||||
use crate::{
|
|
||||||
action::Action,
|
|
||||||
config::Config,
|
|
||||||
palette::StylePalette,
|
|
||||||
types::{ActionLevel, ActionTarget},
|
|
||||||
};
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct PayoutPopup {
|
|
||||||
is_active: bool,
|
|
||||||
action_tx: Option<UnboundedSender<Action>>,
|
|
||||||
network_tx: Option<Sender<Action>>,
|
|
||||||
secret_seed: [u8; 32],
|
|
||||||
stash_account_id: [u8; 32],
|
|
||||||
era_index: u32,
|
|
||||||
is_claimed: bool,
|
|
||||||
palette: StylePalette
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Default for PayoutPopup {
|
|
||||||
fn default() -> Self {
|
|
||||||
Self::new()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl PayoutPopup {
|
|
||||||
pub fn new() -> Self {
|
|
||||||
Self {
|
|
||||||
is_active: false,
|
|
||||||
secret_seed: [0u8; 32],
|
|
||||||
stash_account_id: [0u8; 32],
|
|
||||||
era_index: 0u32,
|
|
||||||
is_claimed: false,
|
|
||||||
action_tx: None,
|
|
||||||
network_tx: None,
|
|
||||||
palette: StylePalette::default(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn store_era_to_claim(&mut self, era_index: u32, is_claimed: bool) {
|
|
||||||
self.is_claimed = is_claimed;
|
|
||||||
self.era_index = era_index;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl PayoutPopup {
|
|
||||||
fn start_payout(&mut self) {
|
|
||||||
if self.is_claimed {
|
|
||||||
if let Some(action_tx) = &self.action_tx {
|
|
||||||
let _ = action_tx.send(Action::EventLog(
|
|
||||||
format!("staking rewards for era index #{} already claimed", self.era_index),
|
|
||||||
ActionLevel::Warn,
|
|
||||||
ActionTarget::ValidatorLog));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if let Some(network_tx) = &self.network_tx {
|
|
||||||
let _ = network_tx.send(Action::PayoutStakers(
|
|
||||||
self.secret_seed,
|
|
||||||
self.stash_account_id,
|
|
||||||
self.era_index));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if let Some(action_tx) = &self.action_tx {
|
|
||||||
let _ = action_tx.send(Action::ClosePopup);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl PartialComponent for PayoutPopup {
|
|
||||||
fn set_active(&mut self, current_tab: CurrentTab) {
|
|
||||||
match current_tab {
|
|
||||||
CurrentTab::PayoutPopup => self.is_active = true,
|
|
||||||
_ => self.is_active = false,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Component for PayoutPopup {
|
|
||||||
fn register_network_handler(&mut self, tx: Sender<Action>) -> Result<()> {
|
|
||||||
self.network_tx = Some(tx);
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn register_action_handler(&mut self, tx: UnboundedSender<Action>) -> Result<()> {
|
|
||||||
self.action_tx = Some(tx);
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn register_config_handler(&mut self, config: Config) -> Result<()> {
|
|
||||||
if let Some(style) = config.styles.get(&crate::app::Mode::Wallet) {
|
|
||||||
self.palette.with_normal_style(style.get("normal_style").copied());
|
|
||||||
self.palette.with_normal_border_style(style.get("normal_border_style").copied());
|
|
||||||
self.palette.with_normal_title_style(style.get("normal_title_style").copied());
|
|
||||||
self.palette.with_popup_style(style.get("popup_style").copied());
|
|
||||||
self.palette.with_popup_title_style(style.get("popup_title_style").copied());
|
|
||||||
}
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
fn handle_key_event(&mut self, key: KeyEvent) -> Result<Option<Action>> {
|
|
||||||
if self.is_active && key.kind == KeyEventKind::Press {
|
|
||||||
match key.code {
|
|
||||||
KeyCode::Enter => self.start_payout(),
|
|
||||||
KeyCode::Esc => self.is_active = false,
|
|
||||||
_ => {},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
Ok(None)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn update(&mut self, action: Action) -> Result<Option<Action>> {
|
|
||||||
match action {
|
|
||||||
Action::PayoutValidatorPopup(era_index, is_claimed) =>
|
|
||||||
self.store_era_to_claim(era_index, is_claimed),
|
|
||||||
Action::SetStashSecret(secret_seed) => self.secret_seed = secret_seed,
|
|
||||||
Action::SetStashAccount(account_id) => self.stash_account_id = account_id,
|
|
||||||
_ => {}
|
|
||||||
};
|
|
||||||
Ok(None)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn draw(&mut self, frame: &mut Frame, area: Rect) -> Result<()> {
|
|
||||||
if self.is_active {
|
|
||||||
let (border_style, border_type) = self.palette.create_popup_style();
|
|
||||||
let popup = Paragraph::new(format!(" Do payout for era #{}", self.era_index))
|
|
||||||
.block(Block::bordered()
|
|
||||||
.border_style(border_style)
|
|
||||||
.border_type(border_type)
|
|
||||||
.title_style(self.palette.create_popup_title_style())
|
|
||||||
.title_alignment(Alignment::Right)
|
|
||||||
.title("Enter to proceed / Esc to close"));
|
|
||||||
let v = Layout::vertical([Constraint::Max(3)]).flex(Flex::Center);
|
|
||||||
let h = Layout::horizontal([Constraint::Max(50)]).flex(Flex::Center);
|
|
||||||
let [area] = v.areas(area);
|
|
||||||
let [area] = h.areas(area);
|
|
||||||
|
|
||||||
frame.render_widget(Clear, area);
|
|
||||||
frame.render_widget(popup, area);
|
|
||||||
}
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,107 +0,0 @@
|
|||||||
use crossterm::event::{KeyCode, KeyEvent, KeyEventKind};
|
|
||||||
use color_eyre::Result;
|
|
||||||
use ratatui::{
|
|
||||||
layout::{Alignment, Constraint, Flex, Layout, Rect},
|
|
||||||
widgets::{Block, Clear, Paragraph},
|
|
||||||
Frame
|
|
||||||
};
|
|
||||||
//use tokio::sync::mpsc::UnboundedSender;
|
|
||||||
use std::sync::mpsc::Sender;
|
|
||||||
|
|
||||||
use super::{Component, PartialComponent, CurrentTab};
|
|
||||||
use crate::{
|
|
||||||
action::Action,
|
|
||||||
config::Config,
|
|
||||||
palette::StylePalette,
|
|
||||||
//types::{ActionLevel, ActionTarget},
|
|
||||||
};
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct RotatePopup {
|
|
||||||
is_active: bool,
|
|
||||||
//action_tx: Option<UnboundedSender<Action>>,
|
|
||||||
network_tx: Option<Sender<Action>>,
|
|
||||||
palette: StylePalette
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Default for RotatePopup {
|
|
||||||
fn default() -> Self {
|
|
||||||
Self::new()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl RotatePopup {
|
|
||||||
pub fn new() -> Self {
|
|
||||||
Self {
|
|
||||||
is_active: false,
|
|
||||||
//action_tx: None,
|
|
||||||
network_tx: None,
|
|
||||||
palette: StylePalette::default(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn rotate_keys(&mut self) {
|
|
||||||
todo!();
|
|
||||||
//if let Some(network_tx) = &self.network_tx {
|
|
||||||
// let _ = network_tx.send(Action::RotateSessionKeys);
|
|
||||||
//}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl PartialComponent for RotatePopup {
|
|
||||||
fn set_active(&mut self, current_tab: CurrentTab) {
|
|
||||||
match current_tab {
|
|
||||||
CurrentTab::RotatePopup => self.is_active = true,
|
|
||||||
_ => self.is_active = false,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Component for RotatePopup {
|
|
||||||
fn register_network_handler(&mut self, tx: Sender<Action>) -> Result<()> {
|
|
||||||
self.network_tx = Some(tx);
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn register_config_handler(&mut self, config: Config) -> Result<()> {
|
|
||||||
if let Some(style) = config.styles.get(&crate::app::Mode::Wallet) {
|
|
||||||
self.palette.with_normal_style(style.get("normal_style").copied());
|
|
||||||
self.palette.with_normal_border_style(style.get("normal_border_style").copied());
|
|
||||||
self.palette.with_normal_title_style(style.get("normal_title_style").copied());
|
|
||||||
self.palette.with_popup_style(style.get("popup_style").copied());
|
|
||||||
self.palette.with_popup_title_style(style.get("popup_title_style").copied());
|
|
||||||
}
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
fn handle_key_event(&mut self, key: KeyEvent) -> Result<Option<Action>> {
|
|
||||||
if self.is_active && key.kind == KeyEventKind::Press {
|
|
||||||
match key.code {
|
|
||||||
KeyCode::Enter => self.rotate_keys(),
|
|
||||||
KeyCode::Esc => self.is_active = false,
|
|
||||||
_ => {},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
Ok(None)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn draw(&mut self, frame: &mut Frame, area: Rect) -> Result<()> {
|
|
||||||
if self.is_active {
|
|
||||||
let (border_style, border_type) = self.palette.create_popup_style();
|
|
||||||
let popup = Paragraph::new(" Do you want to proceed key rotation?")
|
|
||||||
.block(Block::bordered()
|
|
||||||
.border_style(border_style)
|
|
||||||
.border_type(border_type)
|
|
||||||
.title_style(self.palette.create_popup_title_style())
|
|
||||||
.title_alignment(Alignment::Right)
|
|
||||||
.title("Enter to proceed / Esc to close"));
|
|
||||||
let v = Layout::vertical([Constraint::Max(3)]).flex(Flex::Center);
|
|
||||||
let h = Layout::horizontal([Constraint::Max(50)]).flex(Flex::Center);
|
|
||||||
let [area] = v.areas(area);
|
|
||||||
let [area] = h.areas(area);
|
|
||||||
|
|
||||||
frame.render_widget(Clear, area);
|
|
||||||
frame.render_widget(popup, area);
|
|
||||||
}
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
@ -6,7 +6,6 @@ use ratatui::{
|
|||||||
widgets::{Block, Cell, Row, Table},
|
widgets::{Block, Cell, Row, Table},
|
||||||
Frame
|
Frame
|
||||||
};
|
};
|
||||||
use std::sync::mpsc::Sender;
|
|
||||||
|
|
||||||
use super::{PartialComponent, Component, CurrentTab};
|
use super::{PartialComponent, Component, CurrentTab};
|
||||||
use crate::widgets::DotSpinner;
|
use crate::widgets::DotSpinner;
|
||||||
@ -18,7 +17,6 @@ use crate::{
|
|||||||
|
|
||||||
pub struct StashDetails {
|
pub struct StashDetails {
|
||||||
palette: StylePalette,
|
palette: StylePalette,
|
||||||
network_tx: Option<Sender<Action>>,
|
|
||||||
is_bonded: bool,
|
is_bonded: bool,
|
||||||
free_balance: Option<u128>,
|
free_balance: Option<u128>,
|
||||||
staked_total: Option<u128>,
|
staked_total: Option<u128>,
|
||||||
@ -39,7 +37,6 @@ impl StashDetails {
|
|||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self {
|
Self {
|
||||||
palette: StylePalette::default(),
|
palette: StylePalette::default(),
|
||||||
network_tx: None,
|
|
||||||
is_bonded: false,
|
is_bonded: false,
|
||||||
free_balance: None,
|
free_balance: None,
|
||||||
staked_total: None,
|
staked_total: None,
|
||||||
@ -73,11 +70,6 @@ impl PartialComponent for StashDetails {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Component for StashDetails {
|
impl Component for StashDetails {
|
||||||
fn register_network_handler(&mut self, tx: Sender<Action>) -> Result<()> {
|
|
||||||
self.network_tx = Some(tx);
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn register_config_handler(&mut self, config: Config) -> Result<()> {
|
fn register_config_handler(&mut self, config: Config) -> Result<()> {
|
||||||
if let Some(style) = config.styles.get(&crate::app::Mode::Validator) {
|
if let Some(style) = config.styles.get(&crate::app::Mode::Validator) {
|
||||||
self.palette.with_normal_style(style.get("normal_style").copied());
|
self.palette.with_normal_style(style.get("normal_style").copied());
|
||||||
@ -95,17 +87,12 @@ impl Component for StashDetails {
|
|||||||
fn update(&mut self, action: Action) -> Result<Option<Action>> {
|
fn update(&mut self, action: Action) -> Result<Option<Action>> {
|
||||||
match action {
|
match action {
|
||||||
Action::SetStashAccount(account_id) => self.stash_account_id = account_id,
|
Action::SetStashAccount(account_id) => self.stash_account_id = account_id,
|
||||||
Action::SetIsBonded(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 = Some(total);
|
self.staked_total = Some(total);
|
||||||
self.staked_active = Some(active);
|
self.staked_active = Some(active);
|
||||||
},
|
},
|
||||||
Action::BalanceResponse(account_id, maybe_balance) if account_id == self.stash_account_id => {
|
Action::BalanceResponse(account_id, maybe_balance) if account_id == self.stash_account_id => {
|
||||||
if let Some(network_tx) = &self.network_tx {
|
|
||||||
let _ = network_tx.send(Action::SetSender(
|
|
||||||
hex::encode(self.stash_account_id),
|
|
||||||
maybe_balance.clone().map(|b| b.nonce)));
|
|
||||||
}
|
|
||||||
self.free_balance = maybe_balance.map(|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));
|
||||||
|
@ -48,7 +48,7 @@ pub struct StashInfo {
|
|||||||
stash_address: String,
|
stash_address: String,
|
||||||
session_keys: std::collections::HashMap<String, SessionKeyInfo>,
|
session_keys: std::collections::HashMap<String, SessionKeyInfo>,
|
||||||
key_names: &'static [&'static str],
|
key_names: &'static [&'static str],
|
||||||
stash_filepath: PathBuf,
|
file_path: PathBuf,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for StashInfo {
|
impl Default for StashInfo {
|
||||||
@ -70,7 +70,7 @@ impl StashInfo {
|
|||||||
stash_pair: None,
|
stash_pair: None,
|
||||||
session_keys: Default::default(),
|
session_keys: Default::default(),
|
||||||
key_names: &["gran", "babe", "audi", "slow"],
|
key_names: &["gran", "babe", "audi", "slow"],
|
||||||
stash_filepath: PathBuf::from("/etc/ghost/stash-key"),
|
file_path: PathBuf::from("/etc/ghost/stash-key"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -127,7 +127,7 @@ impl StashInfo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn read_or_create_stash(&mut self) -> Result<()> {
|
fn read_or_create_stash(&mut self) -> Result<()> {
|
||||||
match File::open(&self.stash_filepath) {
|
match File::open(&self.file_path) {
|
||||||
Ok(file) => {
|
Ok(file) => {
|
||||||
let reader = BufReader::new(file);
|
let reader = BufReader::new(file);
|
||||||
if let Some(Ok(line)) = reader.lines().next() {
|
if let Some(Ok(line)) = reader.lines().next() {
|
||||||
@ -146,7 +146,7 @@ impl StashInfo {
|
|||||||
.to_ss58check_with_version(Ss58AddressFormat::custom(1996));
|
.to_ss58check_with_version(Ss58AddressFormat::custom(1996));
|
||||||
let pair_signer = PairSigner::<CasperConfig, Pair>::new(pair);
|
let pair_signer = PairSigner::<CasperConfig, Pair>::new(pair);
|
||||||
|
|
||||||
self.initiate_stash_info(account_id, seed);
|
self.initiate_stash_info(account_id);
|
||||||
self.log_event(
|
self.log_event(
|
||||||
format!("stash key {address} read from disk"),
|
format!("stash key {address} read from disk"),
|
||||||
ActionLevel::Info);
|
ActionLevel::Info);
|
||||||
@ -157,7 +157,7 @@ impl StashInfo {
|
|||||||
Ok(())
|
Ok(())
|
||||||
} else {
|
} else {
|
||||||
self.log_event(
|
self.log_event(
|
||||||
format!("file at '{:?}' is empty, trying to create new key", &self.stash_filepath),
|
format!("file at '{:?}' is empty, trying to create new key", &self.file_path),
|
||||||
ActionLevel::Warn);
|
ActionLevel::Warn);
|
||||||
|
|
||||||
self.generate_and_save_new_key()
|
self.generate_and_save_new_key()
|
||||||
@ -165,7 +165,7 @@ impl StashInfo {
|
|||||||
},
|
},
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
self.log_event(
|
self.log_event(
|
||||||
format!("file at '{:?}' not found, trying to create new key", &self.stash_filepath),
|
format!("file at '{:?}' not found, trying to create new key", &self.file_path),
|
||||||
ActionLevel::Warn);
|
ActionLevel::Warn);
|
||||||
|
|
||||||
self.generate_and_save_new_key()
|
self.generate_and_save_new_key()
|
||||||
@ -181,12 +181,12 @@ impl StashInfo {
|
|||||||
.to_ss58check_with_version(Ss58AddressFormat::custom(1996));
|
.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.stash_filepath)?;
|
let mut new_file = File::create(&self.file_path)?;
|
||||||
writeln!(new_file, "0x{}", &secret_seed)?;
|
writeln!(new_file, "0x{}", &secret_seed)?;
|
||||||
|
|
||||||
self.initiate_stash_info(account_id, seed);
|
self.initiate_stash_info(account_id);
|
||||||
self.log_event(
|
self.log_event(
|
||||||
format!("new stash key {} created and stored at {:?}", &address, self.stash_filepath),
|
format!("new stash key {} created and stored at {:?}", &address, self.file_path),
|
||||||
ActionLevel::Info);
|
ActionLevel::Info);
|
||||||
|
|
||||||
self.stash_address = address;
|
self.stash_address = address;
|
||||||
@ -195,10 +195,9 @@ impl StashInfo {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn initiate_stash_info(&self, account_id: [u8; 32], secret_seed: [u8; 32]) {
|
fn initiate_stash_info(&self, account_id: [u8; 32]) {
|
||||||
if let Some(action_tx) = &self.action_tx {
|
if let Some(action_tx) = &self.action_tx {
|
||||||
let _ = action_tx.send(Action::SetStashAccount(account_id));
|
let _ = action_tx.send(Action::SetStashAccount(account_id));
|
||||||
let _ = action_tx.send(Action::SetStashSecret(secret_seed));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(network_tx) = &self.network_tx {
|
if let Some(network_tx) = &self.network_tx {
|
||||||
@ -246,7 +245,6 @@ impl Component for StashInfo {
|
|||||||
self.network_tx = Some(tx);
|
self.network_tx = Some(tx);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn register_action_handler(&mut self, tx: UnboundedSender<Action>) -> Result<()> {
|
fn register_action_handler(&mut self, tx: UnboundedSender<Action>) -> Result<()> {
|
||||||
self.action_tx = Some(tx);
|
self.action_tx = Some(tx);
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -39,7 +39,6 @@ pub struct Network {
|
|||||||
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<TxToWatch>,
|
||||||
eras_to_watch: std::collections::HashSet<u32>,
|
|
||||||
senders: std::collections::HashMap<String, u32>,
|
senders: std::collections::HashMap<String, u32>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -58,7 +57,6 @@ impl Network {
|
|||||||
stash_to_watch: None,
|
stash_to_watch: None,
|
||||||
accounts_to_watch: Default::default(),
|
accounts_to_watch: Default::default(),
|
||||||
transactions_to_watch: Default::default(),
|
transactions_to_watch: Default::default(),
|
||||||
eras_to_watch: Default::default(),
|
|
||||||
senders: Default::default(),
|
senders: Default::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -108,10 +106,6 @@ impl Network {
|
|||||||
predefined_calls::get_staking_value_ratio(&self.action_tx, &self.online_client_api, &stash_to_watch).await?;
|
predefined_calls::get_staking_value_ratio(&self.action_tx, &self.online_client_api, &stash_to_watch).await?;
|
||||||
predefined_calls::get_is_stash_bonded(&self.action_tx, &self.online_client_api, &stash_to_watch).await?;
|
predefined_calls::get_is_stash_bonded(&self.action_tx, &self.online_client_api, &stash_to_watch).await?;
|
||||||
predefined_calls::get_validators_ledger(&self.action_tx, &self.online_client_api, &stash_to_watch).await?;
|
predefined_calls::get_validators_ledger(&self.action_tx, &self.online_client_api, &stash_to_watch).await?;
|
||||||
|
|
||||||
for era_index in self.eras_to_watch.iter() {
|
|
||||||
predefined_calls::get_validator_staking_result(&self.action_tx, &self.online_client_api, &stash_to_watch, *era_index).await?;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
for account_id in self.accounts_to_watch.iter() {
|
for account_id in self.accounts_to_watch.iter() {
|
||||||
predefined_calls::get_balance(&self.action_tx, &self.online_client_api, &account_id).await?;
|
predefined_calls::get_balance(&self.action_tx, &self.online_client_api, &account_id).await?;
|
||||||
@ -171,7 +165,6 @@ impl Network {
|
|||||||
Action::GetActiveEra => predefined_calls::get_active_era(&self.action_tx, &self.online_client_api).await,
|
Action::GetActiveEra => predefined_calls::get_active_era(&self.action_tx, &self.online_client_api).await,
|
||||||
Action::GetCurrentEra => predefined_calls::get_current_era(&self.action_tx, &self.online_client_api).await,
|
Action::GetCurrentEra => predefined_calls::get_current_era(&self.action_tx, &self.online_client_api).await,
|
||||||
Action::GetEpochProgress => predefined_calls::get_epoch_progress(&self.action_tx, &self.online_client_api).await,
|
Action::GetEpochProgress => predefined_calls::get_epoch_progress(&self.action_tx, &self.online_client_api).await,
|
||||||
Action::GetMinValidatorBond => predefined_calls::get_minimal_validator_bond(&self.action_tx, &self.online_client_api).await,
|
|
||||||
|
|
||||||
Action::GetExistentialDeposit => predefined_calls::get_existential_deposit(&self.action_tx, &self.online_client_api).await,
|
Action::GetExistentialDeposit => predefined_calls::get_existential_deposit(&self.action_tx, &self.online_client_api).await,
|
||||||
Action::GetTotalIssuance => predefined_calls::get_total_issuance(&self.action_tx, &self.online_client_api).await,
|
Action::GetTotalIssuance => predefined_calls::get_total_issuance(&self.action_tx, &self.online_client_api).await,
|
||||||
@ -184,10 +177,6 @@ impl Network {
|
|||||||
self.store_sender_nonce(&seed, maybe_nonce);
|
self.store_sender_nonce(&seed, maybe_nonce);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
Action::RemoveEraToWatch(era_index) => {
|
|
||||||
self.eras_to_watch.remove(&era_index);
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
Action::GetValidatorLedger(stash) => {
|
Action::GetValidatorLedger(stash) => {
|
||||||
self.store_stash_if_possible(stash);
|
self.store_stash_if_possible(stash);
|
||||||
@ -256,62 +245,6 @@ impl Network {
|
|||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
Action::BondValidatorExtraFrom(sender, amount) => {
|
|
||||||
let sender_str = hex::encode(sender);
|
|
||||||
let maybe_nonce = self.senders.get_mut(&sender_str);
|
|
||||||
if let Ok(tx_progress) = predefined_txs::bond_extra(
|
|
||||||
&self.action_tx,
|
|
||||||
&self.online_client_api,
|
|
||||||
&sender,
|
|
||||||
&amount,
|
|
||||||
maybe_nonce,
|
|
||||||
).await {
|
|
||||||
self.transactions_to_watch.push(TxToWatch {
|
|
||||||
tx_progress,
|
|
||||||
sender: sender_str,
|
|
||||||
target: ActionTarget::ValidatorLog,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
Action::BondValidatorFrom(sender, amount) => {
|
|
||||||
let sender_str = hex::encode(sender);
|
|
||||||
let maybe_nonce = self.senders.get_mut(&sender_str);
|
|
||||||
if let Ok(tx_progress) = predefined_txs::bond(
|
|
||||||
&self.action_tx,
|
|
||||||
&self.online_client_api,
|
|
||||||
&sender,
|
|
||||||
&amount,
|
|
||||||
maybe_nonce,
|
|
||||||
).await {
|
|
||||||
self.transactions_to_watch.push(TxToWatch {
|
|
||||||
tx_progress,
|
|
||||||
sender: sender_str,
|
|
||||||
target: ActionTarget::ValidatorLog,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
Action::PayoutStakers(sender, stash, era_index) => {
|
|
||||||
let sender_str = hex::encode(sender);
|
|
||||||
let maybe_nonce = self.senders.get_mut(&sender_str);
|
|
||||||
if let Ok(tx_progress) = predefined_txs::payout_stakers(
|
|
||||||
&self.action_tx,
|
|
||||||
&self.online_client_api,
|
|
||||||
&sender,
|
|
||||||
&stash,
|
|
||||||
era_index,
|
|
||||||
maybe_nonce,
|
|
||||||
).await {
|
|
||||||
self.eras_to_watch.insert(era_index);
|
|
||||||
self.transactions_to_watch.push(TxToWatch {
|
|
||||||
tx_progress,
|
|
||||||
sender: sender_str,
|
|
||||||
target: ActionTarget::ValidatorLog,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
_ => Ok(())
|
_ => Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -401,7 +401,7 @@ async fn get_validator_claims_in_era(
|
|||||||
if let Some(claimed_rewards) = maybe_claimed_rewards {
|
if let Some(claimed_rewards) = maybe_claimed_rewards {
|
||||||
let already_claimed = claimed_rewards
|
let already_claimed = claimed_rewards
|
||||||
.first()
|
.first()
|
||||||
.map(|x| *x == 0)
|
.map(|x| *x == 1)
|
||||||
.unwrap_or(false);
|
.unwrap_or(false);
|
||||||
action_tx.send(Action::SetValidatorEraClaimed(era_index, already_claimed))?;
|
action_tx.send(Action::SetValidatorEraClaimed(era_index, already_claimed))?;
|
||||||
}
|
}
|
||||||
@ -483,7 +483,7 @@ pub async fn get_is_stash_bonded(
|
|||||||
let is_bonded = super::raw_calls::staking::bonded(api, None, account_id)
|
let is_bonded = super::raw_calls::staking::bonded(api, None, account_id)
|
||||||
.await?
|
.await?
|
||||||
.is_some();
|
.is_some();
|
||||||
action_tx.send(Action::SetIsBonded(is_bonded))?;
|
action_tx.send(Action::SetBondedAmount(is_bonded))?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -521,14 +521,3 @@ pub async fn get_validator_prefs(
|
|||||||
action_tx.send(Action::SetValidatorPrefs(comission, blocked))?;
|
action_tx.send(Action::SetValidatorPrefs(comission, blocked))?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_minimal_validator_bond(
|
|
||||||
action_tx: &UnboundedSender<Action>,
|
|
||||||
api: &OnlineClient<CasperConfig>,
|
|
||||||
) -> Result<()> {
|
|
||||||
let min_validator_bond = super::raw_calls::staking::min_validator_bond(api, None)
|
|
||||||
.await?
|
|
||||||
.unwrap_or_default();
|
|
||||||
action_tx.send(Action::SetMinValidatorBond(min_validator_bond))?;
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
@ -62,144 +62,3 @@ pub async fn transfer_balance(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn bond_extra(
|
|
||||||
action_tx: &UnboundedSender<Action>,
|
|
||||||
api: &OnlineClient<CasperConfig>,
|
|
||||||
sender: &[u8; 32],
|
|
||||||
amount: &u128,
|
|
||||||
mut maybe_nonce: Option<&mut u32>,
|
|
||||||
) -> Result<TxProgress<CasperConfig, OnlineClient<CasperConfig>>> {
|
|
||||||
let transfer_tx = casper_network::tx()
|
|
||||||
.staking()
|
|
||||||
.bond_extra(*amount);
|
|
||||||
|
|
||||||
let tx_params = match maybe_nonce {
|
|
||||||
Some(ref mut nonce) => {
|
|
||||||
**nonce = nonce.saturating_add(1);
|
|
||||||
CasperExtrinsicParamsBuilder::new()
|
|
||||||
.nonce(nonce.saturating_sub(1) as u64)
|
|
||||||
.build()
|
|
||||||
},
|
|
||||||
None => CasperExtrinsicParamsBuilder::new().build(),
|
|
||||||
};
|
|
||||||
|
|
||||||
let pair = Pair::from_seed(sender);
|
|
||||||
let signer = PairSigner::<CasperConfig, Pair>::new(pair);
|
|
||||||
|
|
||||||
match api
|
|
||||||
.tx()
|
|
||||||
.sign_and_submit_then_watch(&transfer_tx, &signer, tx_params)
|
|
||||||
.await {
|
|
||||||
Ok(tx_progress) => {
|
|
||||||
action_tx.send(Action::EventLog(
|
|
||||||
format!("bond extra transaction {} sent", tx_progress.extrinsic_hash()),
|
|
||||||
ActionLevel::Info,
|
|
||||||
ActionTarget::ValidatorLog))?;
|
|
||||||
Ok(tx_progress)
|
|
||||||
},
|
|
||||||
Err(err) => {
|
|
||||||
action_tx.send(Action::EventLog(
|
|
||||||
format!("error during bond extra: {err}"),
|
|
||||||
ActionLevel::Error,
|
|
||||||
ActionTarget::ValidatorLog))?;
|
|
||||||
Err(err.into())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn bond(
|
|
||||||
action_tx: &UnboundedSender<Action>,
|
|
||||||
api: &OnlineClient<CasperConfig>,
|
|
||||||
sender: &[u8; 32],
|
|
||||||
amount: &u128,
|
|
||||||
mut maybe_nonce: Option<&mut u32>,
|
|
||||||
) -> Result<TxProgress<CasperConfig, OnlineClient<CasperConfig>>> {
|
|
||||||
// auto-stake everything by now
|
|
||||||
let reward_destination =
|
|
||||||
casper_network::runtime_types::pallet_staking::RewardDestination::Staked;
|
|
||||||
|
|
||||||
let transfer_tx = casper_network::tx()
|
|
||||||
.staking()
|
|
||||||
.bond(*amount, reward_destination);
|
|
||||||
|
|
||||||
let tx_params = match maybe_nonce {
|
|
||||||
Some(ref mut nonce) => {
|
|
||||||
**nonce = nonce.saturating_add(1);
|
|
||||||
CasperExtrinsicParamsBuilder::new()
|
|
||||||
.nonce(nonce.saturating_sub(1) as u64)
|
|
||||||
.build()
|
|
||||||
},
|
|
||||||
None => CasperExtrinsicParamsBuilder::new().build(),
|
|
||||||
};
|
|
||||||
|
|
||||||
let pair = Pair::from_seed(sender);
|
|
||||||
let signer = PairSigner::<CasperConfig, Pair>::new(pair);
|
|
||||||
|
|
||||||
match api
|
|
||||||
.tx()
|
|
||||||
.sign_and_submit_then_watch(&transfer_tx, &signer, tx_params)
|
|
||||||
.await {
|
|
||||||
Ok(tx_progress) => {
|
|
||||||
action_tx.send(Action::EventLog(
|
|
||||||
format!("bond transaction {} sent", tx_progress.extrinsic_hash()),
|
|
||||||
ActionLevel::Info,
|
|
||||||
ActionTarget::ValidatorLog))?;
|
|
||||||
Ok(tx_progress)
|
|
||||||
},
|
|
||||||
Err(err) => {
|
|
||||||
action_tx.send(Action::EventLog(
|
|
||||||
format!("error during bond: {err}"),
|
|
||||||
ActionLevel::Error,
|
|
||||||
ActionTarget::ValidatorLog))?;
|
|
||||||
Err(err.into())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn payout_stakers(
|
|
||||||
action_tx: &UnboundedSender<Action>,
|
|
||||||
api: &OnlineClient<CasperConfig>,
|
|
||||||
sender: &[u8; 32],
|
|
||||||
stash: &[u8; 32],
|
|
||||||
era_index: u32,
|
|
||||||
mut maybe_nonce: Option<&mut u32>,
|
|
||||||
) -> Result<TxProgress<CasperConfig, OnlineClient<CasperConfig>>> {
|
|
||||||
let stash_id = subxt::utils::AccountId32::from(*stash);
|
|
||||||
let transfer_tx = casper_network::tx()
|
|
||||||
.staking()
|
|
||||||
.payout_stakers(stash_id, era_index);
|
|
||||||
|
|
||||||
let tx_params = match maybe_nonce {
|
|
||||||
Some(ref mut nonce) => {
|
|
||||||
**nonce = nonce.saturating_add(1);
|
|
||||||
CasperExtrinsicParamsBuilder::new()
|
|
||||||
.nonce(nonce.saturating_sub(1) as u64)
|
|
||||||
.build()
|
|
||||||
},
|
|
||||||
None => CasperExtrinsicParamsBuilder::new().build(),
|
|
||||||
};
|
|
||||||
|
|
||||||
let pair = Pair::from_seed(sender);
|
|
||||||
let signer = PairSigner::<CasperConfig, Pair>::new(pair);
|
|
||||||
|
|
||||||
match api
|
|
||||||
.tx()
|
|
||||||
.sign_and_submit_then_watch(&transfer_tx, &signer, tx_params)
|
|
||||||
.await {
|
|
||||||
Ok(tx_progress) => {
|
|
||||||
action_tx.send(Action::EventLog(
|
|
||||||
format!("payout stakers {} sent", tx_progress.extrinsic_hash()),
|
|
||||||
ActionLevel::Info,
|
|
||||||
ActionTarget::ValidatorLog))?;
|
|
||||||
Ok(tx_progress)
|
|
||||||
},
|
|
||||||
Err(err) => {
|
|
||||||
action_tx.send(Action::EventLog(
|
|
||||||
format!("error during payout stakers: {err}"),
|
|
||||||
ActionLevel::Error,
|
|
||||||
ActionTarget::ValidatorLog))?;
|
|
||||||
Err(err.into())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -171,12 +171,3 @@ pub async fn disabled_validators(
|
|||||||
let maybe_disabled_validators = super::do_storage_call(online_client, &storage_key, at_hash).await?;
|
let maybe_disabled_validators = super::do_storage_call(online_client, &storage_key, at_hash).await?;
|
||||||
Ok(maybe_disabled_validators)
|
Ok(maybe_disabled_validators)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn min_validator_bond(
|
|
||||||
online_client: &OnlineClient<CasperConfig>,
|
|
||||||
at_hash: Option<&H256>,
|
|
||||||
) -> Result<Option<u128>> {
|
|
||||||
let storage_key = casper_network::storage().staking().min_validator_bond();
|
|
||||||
let maybe_min_validator_bond = super::do_storage_call(online_client, &storage_key, at_hash).await?;
|
|
||||||
Ok(maybe_min_validator_bond)
|
|
||||||
}
|
|
||||||
|
@ -119,7 +119,6 @@ impl BestSubscription {
|
|||||||
self.network_tx.send(Action::GetNominatorsNumber)?;
|
self.network_tx.send(Action::GetNominatorsNumber)?;
|
||||||
self.network_tx.send(Action::GetInflation)?;
|
self.network_tx.send(Action::GetInflation)?;
|
||||||
self.network_tx.send(Action::GetCurrentValidatorEraRewards)?;
|
self.network_tx.send(Action::GetCurrentValidatorEraRewards)?;
|
||||||
self.network_tx.send(Action::GetMinValidatorBond)?;
|
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user