Compare commits
No commits in common. "91fb7380d6a22d2eb468bcd2fc587d472b33d460" and "adf1d94cbeb1c4a54326cec1ec12fa4625db14ad" have entirely different histories.
91fb7380d6
...
adf1d94cbe
@ -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.22"
|
version = "0.3.20"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
@ -59,8 +59,6 @@ pub enum Action {
|
|||||||
ValidateFrom([u8; 32], u32),
|
ValidateFrom([u8; 32], u32),
|
||||||
ChillFrom([u8; 32]),
|
ChillFrom([u8; 32]),
|
||||||
UnbondFrom([u8; 32], u128),
|
UnbondFrom([u8; 32], u128),
|
||||||
RebondFrom([u8; 32], u128),
|
|
||||||
WithdrawUnbondedFrom([u8; 32], u32),
|
|
||||||
EventLog(String, ActionLevel, ActionTarget),
|
EventLog(String, ActionLevel, ActionTarget),
|
||||||
|
|
||||||
NewBestBlock(u32),
|
NewBestBlock(u32),
|
||||||
@ -103,7 +101,6 @@ pub enum Action {
|
|||||||
GetIsStashBonded([u8; 32]),
|
GetIsStashBonded([u8; 32]),
|
||||||
GetErasStakersOverview([u8; 32]),
|
GetErasStakersOverview([u8; 32]),
|
||||||
GetValidatorPrefs([u8; 32]),
|
GetValidatorPrefs([u8; 32]),
|
||||||
GetSlashingSpans([u8; 32]),
|
|
||||||
GetCurrentValidatorEraRewards,
|
GetCurrentValidatorEraRewards,
|
||||||
|
|
||||||
SetNodeName(Option<String>),
|
SetNodeName(Option<String>),
|
||||||
@ -113,8 +110,6 @@ pub enum Action {
|
|||||||
SetChainVersion(Option<String>),
|
SetChainVersion(Option<String>),
|
||||||
SetStashAccount([u8; 32]),
|
SetStashAccount([u8; 32]),
|
||||||
SetStashSecret([u8; 32]),
|
SetStashSecret([u8; 32]),
|
||||||
SetSlashingSpansLength(usize),
|
|
||||||
SetUnlockingIsEmpty(bool),
|
|
||||||
|
|
||||||
BestBlockInformation(H256, u32),
|
BestBlockInformation(H256, u32),
|
||||||
FinalizedBlockInformation(H256, u32),
|
FinalizedBlockInformation(H256, u32),
|
||||||
|
@ -27,8 +27,6 @@ mod rotate_popup;
|
|||||||
mod validate_popup;
|
mod validate_popup;
|
||||||
mod chill_popup;
|
mod chill_popup;
|
||||||
mod unbond_popup;
|
mod unbond_popup;
|
||||||
mod rebond_popup;
|
|
||||||
mod withdraw_popup;
|
|
||||||
|
|
||||||
use stash_details::StashDetails;
|
use stash_details::StashDetails;
|
||||||
use staking_details::StakingDetails;
|
use staking_details::StakingDetails;
|
||||||
@ -46,8 +44,6 @@ use rotate_popup::RotatePopup;
|
|||||||
use validate_popup::ValidatePopup;
|
use validate_popup::ValidatePopup;
|
||||||
use chill_popup::ChillPopup;
|
use chill_popup::ChillPopup;
|
||||||
use unbond_popup::UnbondPopup;
|
use unbond_popup::UnbondPopup;
|
||||||
use rebond_popup::RebondPopup;
|
|
||||||
use withdraw_popup::WithdrawPopup;
|
|
||||||
|
|
||||||
#[derive(Debug, Copy, Clone, PartialEq)]
|
#[derive(Debug, Copy, Clone, PartialEq)]
|
||||||
pub enum CurrentTab {
|
pub enum CurrentTab {
|
||||||
@ -65,8 +61,6 @@ pub enum CurrentTab {
|
|||||||
ValidatePopup,
|
ValidatePopup,
|
||||||
ChillPopup,
|
ChillPopup,
|
||||||
UnbondPopup,
|
UnbondPopup,
|
||||||
RebondPopup,
|
|
||||||
WithdrawPopup,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait PartialComponent: Component {
|
pub trait PartialComponent: Component {
|
||||||
@ -103,8 +97,6 @@ impl Default for Validator {
|
|||||||
Box::new(ValidatePopup::default()),
|
Box::new(ValidatePopup::default()),
|
||||||
Box::new(ChillPopup::default()),
|
Box::new(ChillPopup::default()),
|
||||||
Box::new(UnbondPopup::default()),
|
Box::new(UnbondPopup::default()),
|
||||||
Box::new(RebondPopup::default()),
|
|
||||||
Box::new(WithdrawPopup::default()),
|
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -168,8 +160,6 @@ impl Component for Validator {
|
|||||||
CurrentTab::ValidatePopup |
|
CurrentTab::ValidatePopup |
|
||||||
CurrentTab::ChillPopup |
|
CurrentTab::ChillPopup |
|
||||||
CurrentTab::UnbondPopup |
|
CurrentTab::UnbondPopup |
|
||||||
CurrentTab::RebondPopup |
|
|
||||||
CurrentTab::WithdrawPopup |
|
|
||||||
CurrentTab::PayoutPopup => match key.code {
|
CurrentTab::PayoutPopup => match key.code {
|
||||||
KeyCode::Esc => {
|
KeyCode::Esc => {
|
||||||
self.current_tab = self.previous_tab;
|
self.current_tab = self.previous_tab;
|
||||||
@ -239,20 +229,6 @@ impl Component for Validator {
|
|||||||
component.set_active(self.current_tab.clone());
|
component.set_active(self.current_tab.clone());
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
KeyCode::Char('E') => {
|
|
||||||
self.previous_tab = self.current_tab;
|
|
||||||
self.current_tab = CurrentTab::RebondPopup;
|
|
||||||
for component in self.components.iter_mut() {
|
|
||||||
component.set_active(self.current_tab.clone());
|
|
||||||
}
|
|
||||||
},
|
|
||||||
KeyCode::Char('W') => {
|
|
||||||
self.previous_tab = self.current_tab;
|
|
||||||
self.current_tab = CurrentTab::WithdrawPopup;
|
|
||||||
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)?;
|
||||||
|
@ -1,173 +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 RebondPopup {
|
|
||||||
is_active: bool,
|
|
||||||
action_tx: Option<UnboundedSender<Action>>,
|
|
||||||
network_tx: Option<Sender<Action>>,
|
|
||||||
secret_seed: [u8; 32],
|
|
||||||
amount: Input,
|
|
||||||
palette: StylePalette
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Default for RebondPopup {
|
|
||||||
fn default() -> Self {
|
|
||||||
Self::new()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl RebondPopup {
|
|
||||||
pub fn new() -> Self {
|
|
||||||
Self {
|
|
||||||
is_active: false,
|
|
||||||
secret_seed: [0u8; 32],
|
|
||||||
action_tx: None,
|
|
||||||
network_tx: None,
|
|
||||||
amount: Input::new(String::new()),
|
|
||||||
palette: StylePalette::default(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl RebondPopup {
|
|
||||||
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 _ = network_tx.send(Action::RebondFrom(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 RebondPopup {
|
|
||||||
fn set_active(&mut self, current_tab: CurrentTab) {
|
|
||||||
match current_tab {
|
|
||||||
CurrentTab::RebondPopup => self.is_active = true,
|
|
||||||
_ => {
|
|
||||||
self.is_active = false;
|
|
||||||
self.amount = Input::new(String::new());
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Component for RebondPopup {
|
|
||||||
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::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!("Amount to rebond")));
|
|
||||||
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(())
|
|
||||||
}
|
|
||||||
}
|
|
@ -24,7 +24,6 @@ pub struct StashDetails {
|
|||||||
staked_total: Option<u128>,
|
staked_total: Option<u128>,
|
||||||
staked_active: Option<u128>,
|
staked_active: Option<u128>,
|
||||||
stash_account_id: [u8; 32],
|
stash_account_id: [u8; 32],
|
||||||
stash_secret: [u8; 32],
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for StashDetails {
|
impl Default for StashDetails {
|
||||||
@ -46,7 +45,6 @@ impl StashDetails {
|
|||||||
staked_total: None,
|
staked_total: None,
|
||||||
staked_active: None,
|
staked_active: None,
|
||||||
stash_account_id: [0u8; 32],
|
stash_account_id: [0u8; 32],
|
||||||
stash_secret: [0u8; 32],
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -96,7 +94,6 @@ 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::SetStashSecret(secret) => self.stash_secret = secret,
|
|
||||||
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::SetIsBonded(is_bonded) => self.is_bonded = is_bonded,
|
||||||
Action::SetStakedAmountRatio(total, active) => {
|
Action::SetStakedAmountRatio(total, active) => {
|
||||||
@ -106,7 +103,7 @@ impl Component for StashDetails {
|
|||||||
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 {
|
if let Some(network_tx) = &self.network_tx {
|
||||||
let _ = network_tx.send(Action::SetSender(
|
let _ = network_tx.send(Action::SetSender(
|
||||||
hex::encode(self.stash_secret),
|
hex::encode(self.stash_account_id),
|
||||||
maybe_balance.clone().map(|b| b.nonce)));
|
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
|
||||||
|
@ -211,7 +211,6 @@ impl StashInfo {
|
|||||||
let _ = network_tx.send(Action::GetQueuedSessionKeys(account_id));
|
let _ = network_tx.send(Action::GetQueuedSessionKeys(account_id));
|
||||||
let _ = network_tx.send(Action::GetSessionKeys(account_id));
|
let _ = network_tx.send(Action::GetSessionKeys(account_id));
|
||||||
let _ = network_tx.send(Action::GetValidatorAllRewards(account_id));
|
let _ = network_tx.send(Action::GetValidatorAllRewards(account_id));
|
||||||
let _ = network_tx.send(Action::GetSlashingSpans(account_id));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,156 +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 WithdrawPopup {
|
|
||||||
is_active: bool,
|
|
||||||
action_tx: Option<UnboundedSender<Action>>,
|
|
||||||
network_tx: Option<Sender<Action>>,
|
|
||||||
secret_seed: [u8; 32],
|
|
||||||
slashing_spans_length: u32,
|
|
||||||
unlocking_is_empty: bool,
|
|
||||||
existential_deposit: u128,
|
|
||||||
active_balance: u128,
|
|
||||||
palette: StylePalette
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Default for WithdrawPopup {
|
|
||||||
fn default() -> Self {
|
|
||||||
Self::new()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl WithdrawPopup {
|
|
||||||
pub fn new() -> Self {
|
|
||||||
Self {
|
|
||||||
is_active: false,
|
|
||||||
secret_seed: [0u8; 32],
|
|
||||||
slashing_spans_length: 0u32,
|
|
||||||
unlocking_is_empty: false,
|
|
||||||
existential_deposit: 0u128,
|
|
||||||
active_balance: 0u128,
|
|
||||||
action_tx: None,
|
|
||||||
network_tx: None,
|
|
||||||
palette: StylePalette::default(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn stash_should_be_killed(&self) -> bool {
|
|
||||||
self.unlocking_is_empty && self.active_balance < self.existential_deposit
|
|
||||||
}
|
|
||||||
|
|
||||||
fn proceed(&mut self) {
|
|
||||||
if let Some(network_tx) = &self.network_tx {
|
|
||||||
let spans_needed = if self.stash_should_be_killed() {
|
|
||||||
self.slashing_spans_length
|
|
||||||
} else {
|
|
||||||
0
|
|
||||||
};
|
|
||||||
let _ = network_tx.send(Action::WithdrawUnbondedFrom(
|
|
||||||
self.secret_seed, spans_needed));
|
|
||||||
if let Some(action_tx) = &self.action_tx {
|
|
||||||
let _ = action_tx.send(Action::EventLog(
|
|
||||||
"Current stash account will be killed during this transaction".to_string(),
|
|
||||||
ActionLevel::Warn,
|
|
||||||
ActionTarget::ValidatorLog));
|
|
||||||
let _ = action_tx.send(Action::ClosePopup);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl PartialComponent for WithdrawPopup {
|
|
||||||
fn set_active(&mut self, current_tab: CurrentTab) {
|
|
||||||
match current_tab {
|
|
||||||
CurrentTab::WithdrawPopup => self.is_active = true,
|
|
||||||
_ => self.is_active = false,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Component for WithdrawPopup {
|
|
||||||
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.proceed(),
|
|
||||||
KeyCode::Esc => self.is_active = false,
|
|
||||||
_ => {},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
Ok(None)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn update(&mut self, action: Action) -> Result<Option<Action>> {
|
|
||||||
match action {
|
|
||||||
Action::SetStashSecret(secret_seed) => self.secret_seed = secret_seed,
|
|
||||||
Action::SetSlashingSpansLength(length) => self.slashing_spans_length = length as u32,
|
|
||||||
Action::SetStakedAmountRatio(_, active_balance) => self.active_balance = active_balance,
|
|
||||||
Action::SetUnlockingIsEmpty(is_empty) => self.unlocking_is_empty = is_empty,
|
|
||||||
Action::SetExistentialDeposit(existential_deposit) => self.existential_deposit = existential_deposit,
|
|
||||||
_ => {}
|
|
||||||
};
|
|
||||||
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 text = if self.stash_should_be_killed() {
|
|
||||||
" Do you want to kill current stash account?"
|
|
||||||
} else {
|
|
||||||
" Do you want to withdraw all unbonded funds?"
|
|
||||||
};
|
|
||||||
let input = Paragraph::new(text)
|
|
||||||
.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(input, area);
|
|
||||||
}
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
@ -108,7 +108,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?;
|
||||||
predefined_calls::get_slashing_spans(&self.action_tx, &self.online_client_api, &stash_to_watch).await?;
|
|
||||||
|
|
||||||
for era_index in self.eras_to_watch.iter() {
|
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?;
|
predefined_calls::get_validator_staking_result(&self.action_tx, &self.online_client_api, &stash_to_watch, *era_index).await?;
|
||||||
@ -191,10 +190,6 @@ impl Network {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
Action::GetSlashingSpans(stash) => {
|
|
||||||
self.store_stash_if_possible(stash);
|
|
||||||
predefined_calls::get_slashing_spans(&self.action_tx, &self.online_client_api, &stash).await
|
|
||||||
}
|
|
||||||
Action::GetValidatorLedger(stash) => {
|
Action::GetValidatorLedger(stash) => {
|
||||||
self.store_stash_if_possible(stash);
|
self.store_stash_if_possible(stash);
|
||||||
predefined_calls::get_validators_ledger(&self.action_tx, &self.online_client_api, &stash).await
|
predefined_calls::get_validators_ledger(&self.action_tx, &self.online_client_api, &stash).await
|
||||||
@ -265,7 +260,6 @@ impl Network {
|
|||||||
Action::BondValidatorExtraFrom(sender, amount) => {
|
Action::BondValidatorExtraFrom(sender, amount) => {
|
||||||
let sender_str = hex::encode(sender);
|
let sender_str = hex::encode(sender);
|
||||||
let maybe_nonce = self.senders.get_mut(&sender_str);
|
let maybe_nonce = self.senders.get_mut(&sender_str);
|
||||||
|
|
||||||
if let Ok(tx_progress) = predefined_txs::bond_extra(
|
if let Ok(tx_progress) = predefined_txs::bond_extra(
|
||||||
&self.action_tx,
|
&self.action_tx,
|
||||||
&self.online_client_api,
|
&self.online_client_api,
|
||||||
@ -390,42 +384,6 @@ impl Network {
|
|||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
Action::RebondFrom(sender, amount) => {
|
|
||||||
let sender_str = hex::encode(sender);
|
|
||||||
let maybe_nonce = self.senders.get_mut(&sender_str);
|
|
||||||
if let Ok(tx_progress) = predefined_txs::rebond(
|
|
||||||
&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::WithdrawUnbondedFrom(sender, spans) => {
|
|
||||||
let sender_str = hex::encode(sender);
|
|
||||||
let maybe_nonce = self.senders.get_mut(&sender_str);
|
|
||||||
if let Ok(tx_progress) = predefined_txs::withdraw_unbonded(
|
|
||||||
&self.action_tx,
|
|
||||||
&self.online_client_api,
|
|
||||||
&sender,
|
|
||||||
&spans,
|
|
||||||
maybe_nonce,
|
|
||||||
).await {
|
|
||||||
self.transactions_to_watch.push(TxToWatch {
|
|
||||||
tx_progress,
|
|
||||||
sender: sender_str,
|
|
||||||
target: ActionTarget::ValidatorLog,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
_ => Ok(())
|
_ => Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -435,7 +435,6 @@ pub async fn get_validators_ledger(
|
|||||||
|
|
||||||
if let Some(ledger) = maybe_ledger {
|
if let Some(ledger) = maybe_ledger {
|
||||||
action_tx.send(Action::SetStakedAmountRatio(ledger.total, ledger.active))?;
|
action_tx.send(Action::SetStakedAmountRatio(ledger.total, ledger.active))?;
|
||||||
action_tx.send(Action::SetUnlockingIsEmpty(ledger.unlocking.0.is_empty()))?;
|
|
||||||
for chunk in ledger.unlocking.0.iter() {
|
for chunk in ledger.unlocking.0.iter() {
|
||||||
action_tx.send(Action::SetValidatorEraUnlocking(chunk.era, chunk.value))?;
|
action_tx.send(Action::SetValidatorEraUnlocking(chunk.era, chunk.value))?;
|
||||||
}
|
}
|
||||||
@ -533,16 +532,3 @@ pub async fn get_minimal_validator_bond(
|
|||||||
action_tx.send(Action::SetMinValidatorBond(min_validator_bond))?;
|
action_tx.send(Action::SetMinValidatorBond(min_validator_bond))?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_slashing_spans(
|
|
||||||
action_tx: &UnboundedSender<Action>,
|
|
||||||
api: &OnlineClient<CasperConfig>,
|
|
||||||
account_id: &[u8; 32],
|
|
||||||
) -> Result<()> {
|
|
||||||
let slashing_spans_length = super::raw_calls::staking::slashing_spans(api, None, account_id)
|
|
||||||
.await?
|
|
||||||
.map(|spans| spans.prior.len())
|
|
||||||
.unwrap_or_default();
|
|
||||||
action_tx.send(Action::SetSlashingSpansLength(slashing_spans_length))?;
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
@ -191,44 +191,6 @@ pub async fn unbond(
|
|||||||
).await
|
).await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn rebond(
|
|
||||||
action_tx: &UnboundedSender<Action>,
|
|
||||||
api: &OnlineClient<CasperConfig>,
|
|
||||||
sender: &[u8; 32],
|
|
||||||
amount: &u128,
|
|
||||||
maybe_nonce: Option<&mut u32>,
|
|
||||||
) -> Result<TxProgress<CasperConfig, OnlineClient<CasperConfig>>> {
|
|
||||||
let rebond_tx = casper_network::tx().staking().rebond(*amount);
|
|
||||||
inner_sign_and_submit_then_watch(
|
|
||||||
action_tx,
|
|
||||||
api,
|
|
||||||
sender,
|
|
||||||
maybe_nonce,
|
|
||||||
Box::new(rebond_tx),
|
|
||||||
"rebond",
|
|
||||||
ActionTarget::ValidatorLog,
|
|
||||||
).await
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn withdraw_unbonded(
|
|
||||||
action_tx: &UnboundedSender<Action>,
|
|
||||||
api: &OnlineClient<CasperConfig>,
|
|
||||||
sender: &[u8; 32],
|
|
||||||
spans: &u32,
|
|
||||||
maybe_nonce: Option<&mut u32>,
|
|
||||||
) -> Result<TxProgress<CasperConfig, OnlineClient<CasperConfig>>> {
|
|
||||||
let withdraw_unbonded_tx = casper_network::tx().staking().withdraw_unbonded(*spans);
|
|
||||||
inner_sign_and_submit_then_watch(
|
|
||||||
action_tx,
|
|
||||||
api,
|
|
||||||
sender,
|
|
||||||
maybe_nonce,
|
|
||||||
Box::new(withdraw_unbonded_tx),
|
|
||||||
"withdraw unbonded",
|
|
||||||
ActionTarget::ValidatorLog,
|
|
||||||
).await
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn inner_sign_and_submit_then_watch(
|
async fn inner_sign_and_submit_then_watch(
|
||||||
action_tx: &UnboundedSender<Action>,
|
action_tx: &UnboundedSender<Action>,
|
||||||
api: &OnlineClient<CasperConfig>,
|
api: &OnlineClient<CasperConfig>,
|
||||||
|
@ -8,10 +8,7 @@ use crate::{
|
|||||||
casper_network::{
|
casper_network::{
|
||||||
self,
|
self,
|
||||||
runtime_types::{
|
runtime_types::{
|
||||||
pallet_staking::{
|
pallet_staking::{ActiveEraInfo, EraRewardPoints, StakingLedger, ValidatorPrefs},
|
||||||
slashing::SlashingSpans, ActiveEraInfo, EraRewardPoints,
|
|
||||||
StakingLedger, ValidatorPrefs,
|
|
||||||
},
|
|
||||||
sp_arithmetic::per_things::Perbill,
|
sp_arithmetic::per_things::Perbill,
|
||||||
sp_staking::{Exposure, PagedExposureMetadata},
|
sp_staking::{Exposure, PagedExposureMetadata},
|
||||||
},
|
},
|
||||||
@ -183,14 +180,3 @@ pub async fn min_validator_bond(
|
|||||||
let maybe_min_validator_bond = super::do_storage_call(online_client, &storage_key, at_hash).await?;
|
let maybe_min_validator_bond = super::do_storage_call(online_client, &storage_key, at_hash).await?;
|
||||||
Ok(maybe_min_validator_bond)
|
Ok(maybe_min_validator_bond)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn slashing_spans(
|
|
||||||
online_client: &OnlineClient<CasperConfig>,
|
|
||||||
at_hash: Option<&H256>,
|
|
||||||
account: &[u8; 32],
|
|
||||||
) -> Result<Option<SlashingSpans>> {
|
|
||||||
let account_id = super::convert_array_to_account_id(account);
|
|
||||||
let storage_key = casper_network::storage().staking().slashing_spans(account_id);
|
|
||||||
let maybe_slashing_spans = super::do_storage_call(online_client, &storage_key, at_hash).await?;
|
|
||||||
Ok(maybe_slashing_spans)
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user