From 54ef498727eecab1ddfc74d73026ca1c6f4bcbd1 Mon Sep 17 00:00:00 2001 From: FroVolod Date: Wed, 19 Jul 2023 11:53:24 +0300 Subject: [PATCH 01/44] start --- src/commands/mod.rs | 6 +++ src/commands/staking/delegate/mod.rs | 65 ++++++++++++++++++++++++++++ src/commands/staking/mod.rs | 21 +++++++++ 3 files changed, 92 insertions(+) create mode 100644 src/commands/staking/delegate/mod.rs create mode 100644 src/commands/staking/mod.rs diff --git a/src/commands/mod.rs b/src/commands/mod.rs index 982f2b677..01268079a 100644 --- a/src/commands/mod.rs +++ b/src/commands/mod.rs @@ -4,6 +4,7 @@ use strum::{EnumDiscriminants, EnumIter, EnumMessage}; pub mod account; mod config; mod contract; +mod staking; mod tokens; mod transaction; @@ -25,6 +26,11 @@ pub enum TopLevelCommand { ))] /// Use this for token actions: send or view balances of NEAR, FT, or NFT Tokens(self::tokens::TokensCommands), + #[strum_discriminants(strum( + message = "staking - Manage staking: view, add and withdraw stake" + ))] + /// Use this for manage staking: view, add and withdraw stake + Staking(self::staking::Staking), #[strum_discriminants(strum( message = "contract - Manage smart-contracts: deploy code, call functions" ))] diff --git a/src/commands/staking/delegate/mod.rs b/src/commands/staking/delegate/mod.rs new file mode 100644 index 000000000..f0b1c5bc4 --- /dev/null +++ b/src/commands/staking/delegate/mod.rs @@ -0,0 +1,65 @@ +use strum::{EnumDiscriminants, EnumIter, EnumMessage}; + +#[derive(Debug, Clone, interactive_clap::InteractiveClap)] +#[interactive_clap(input_context = crate::GlobalContext)] +#[interactive_clap(output_context = DelegateStakeContext)] +pub struct DelegateStake { + #[interactive_clap(skip_default_input_arg)] + /// What is validator account ID? + validator_account_id: crate::types::account_id::AccountId, + #[interactive_clap(subcommand)] + delegate_stake_command: DelegateStakingCommand, +} + +#[derive(Debug, Clone)] +pub struct DelegateStakeContext { + global_context: crate::GlobalContext, + validator_account_id: near_primitives::types::AccountId, +} + +impl DelegateStakeContext { + pub fn from_previous_context( + previous_context: crate::GlobalContext, + scope: &::InteractiveClapContextScope, + ) -> color_eyre::eyre::Result { + Ok(Self { + global_context: previous_context, + validator_account_id: scope.validator_account_id.clone().into(), + }) + } +} + +impl DelegateStake { + pub fn input_validator_account_id( + context: &crate::GlobalContext, + ) -> color_eyre::eyre::Result> { + crate::common::input_non_signer_account_id_from_used_account_list( + &context.config.credentials_home_dir, + "What is validator account ID?", + ) + } +} + +#[derive(Debug, EnumDiscriminants, Clone, interactive_clap::InteractiveClap)] +#[interactive_clap(context = DelegateStakeContext)] +#[strum_discriminants(derive(EnumMessage, EnumIter))] +#[non_exhaustive] +/// Select actions with delegated staking: +pub enum DelegateStakingCommand { + #[strum_discriminants(strum(message = "view - "))] + /// The transfer is carried out in NEAR tokens + View, + #[strum_discriminants(strum(message = "stake - "))] + /// The transfer is carried out in NEAR tokens + Stake, + #[strum_discriminants(strum( + message = "unstake - Removing delegated stakes from validators." + ))] + /// The transfer is carried out in NEAR tokens + Unstake, + #[strum_discriminants(strum( + message = "withdraw - Withdrawing the non-staking balance for this account." + ))] + /// The transfer is carried out in NEAR tokens + Withdraw, +} diff --git a/src/commands/staking/mod.rs b/src/commands/staking/mod.rs new file mode 100644 index 000000000..59563cc30 --- /dev/null +++ b/src/commands/staking/mod.rs @@ -0,0 +1,21 @@ +use strum::{EnumDiscriminants, EnumIter, EnumMessage}; + +mod delegate; + +#[derive(Debug, Clone, interactive_clap::InteractiveClap)] +#[interactive_clap(context = crate::GlobalContext)] +pub struct Staking { + #[interactive_clap(subcommand)] + stake: StakingType, +} + +#[derive(Debug, EnumDiscriminants, Clone, interactive_clap::InteractiveClap)] +#[interactive_clap(context = crate::GlobalContext)] +#[strum_discriminants(derive(EnumMessage, EnumIter))] +#[non_exhaustive] +/// Select the type of stake: +pub enum StakingType { + #[strum_discriminants(strum(message = "delegate - "))] + /// + Delegate(self::delegate::DelegateStake), +} From e2f3af7ee48ca1f3b084831fa88ff45c3db58ff9 Mon Sep 17 00:00:00 2001 From: FroVolod Date: Wed, 19 Jul 2023 17:24:34 +0300 Subject: [PATCH 02/44] added Withdraw, WithdrawAll --- src/commands/staking/delegate/mod.rs | 14 ++- src/commands/staking/delegate/withdraw.rs | 93 +++++++++++++++++++ src/commands/staking/delegate/withdraw_all.rs | 85 +++++++++++++++++ 3 files changed, 189 insertions(+), 3 deletions(-) create mode 100644 src/commands/staking/delegate/withdraw.rs create mode 100644 src/commands/staking/delegate/withdraw_all.rs diff --git a/src/commands/staking/delegate/mod.rs b/src/commands/staking/delegate/mod.rs index f0b1c5bc4..73a19abd9 100644 --- a/src/commands/staking/delegate/mod.rs +++ b/src/commands/staking/delegate/mod.rs @@ -1,5 +1,8 @@ use strum::{EnumDiscriminants, EnumIter, EnumMessage}; +mod withdraw; +mod withdraw_all; + #[derive(Debug, Clone, interactive_clap::InteractiveClap)] #[interactive_clap(input_context = crate::GlobalContext)] #[interactive_clap(output_context = DelegateStakeContext)] @@ -58,8 +61,13 @@ pub enum DelegateStakingCommand { /// The transfer is carried out in NEAR tokens Unstake, #[strum_discriminants(strum( - message = "withdraw - Withdrawing the non-staking balance for this account." + message = "withdraw - Withdrawing the non staked balance for given account." ))] - /// The transfer is carried out in NEAR tokens - Withdraw, + /// Withdrawing the non staked balance for given account. + Withdraw(self::withdraw::Withdraw), + #[strum_discriminants(strum( + message = "withdraw-all - Withdrawing the entire unstaked balance from the predecessor account." + ))] + /// Withdrawing the entire unstaked balance from the predecessor account. + WithdrawAll(self::withdraw_all::WithdrawAll), } diff --git a/src/commands/staking/delegate/withdraw.rs b/src/commands/staking/delegate/withdraw.rs new file mode 100644 index 000000000..7181ff5b4 --- /dev/null +++ b/src/commands/staking/delegate/withdraw.rs @@ -0,0 +1,93 @@ +use std::str::FromStr; + +#[derive(Debug, Clone, interactive_clap::InteractiveClap)] +#[interactive_clap(input_context = super::DelegateStakeContext)] +#[interactive_clap(output_context = WithdrawContext)] +pub struct Withdraw { + /// Enter the amount to withdraw from the non staked balance (example: 10NEAR or 0.5near or 10000yoctonear): + amount: crate::common::NearBalance, + #[interactive_clap(skip_default_input_arg)] + /// What is the signer account ID? + signer_account_id: crate::types::account_id::AccountId, + #[interactive_clap(named_arg)] + /// Select network + network_config: crate::network_for_transaction::NetworkForTransactionArgs, +} + +#[derive(Clone)] +pub struct WithdrawContext(crate::commands::ActionContext); + +impl WithdrawContext { + pub fn from_previous_context( + previous_context: super::DelegateStakeContext, + scope: &::InteractiveClapContextScope, + ) -> color_eyre::eyre::Result { + let signer = scope.signer_account_id.clone(); + let signer_id: near_primitives::types::AccountId = scope.signer_account_id.clone().into(); + let validator_account_id = previous_context.validator_account_id.clone(); + let amount = scope.amount.clone(); + + let on_after_getting_network_callback: crate::commands::OnAfterGettingNetworkCallback = + std::sync::Arc::new(move |_network_config| { + Ok(crate::commands::PrepopulatedTransaction { + signer_id: signer_id.clone(), + receiver_id: previous_context.validator_account_id.clone(), + actions: vec![near_primitives::transaction::Action::FunctionCall( + near_primitives::transaction::FunctionCallAction { + method_name: "withdraw".to_string(), + args: serde_json::json!({ + "amount": amount.clone().to_yoctonear().to_string() + }) + .to_string() + .into_bytes(), + gas: crate::common::NearGas::from_str("300 TeraGas") + .unwrap() + .inner, + deposit: crate::common::NearBalance::from_yoctonear(0).to_yoctonear(), + }, + )], + }) + }); + + let amount = scope.amount.clone(); + let on_after_sending_transaction_callback: crate::transaction_signature_options::OnAfterSendingTransactionCallback = std::sync::Arc::new( + move |outcome_view, _network_config| { + if let near_primitives::views::FinalExecutionStatus::SuccessValue(_) = outcome_view.status { + println!("{outcome_view:#?}"); + eprintln!( + "<{signer}> has successfully withdrawn {amount} from <{validator_account_id}>.", + ); + } + Ok(()) + }, + ); + Ok(Self(crate::commands::ActionContext { + global_context: previous_context.global_context, + on_after_getting_network_callback, + on_before_signing_callback: std::sync::Arc::new( + |_prepolulated_unsinged_transaction, _network_config| Ok(()), + ), + on_before_sending_transaction_callback: std::sync::Arc::new( + |_signed_transaction, _network_config, _message| Ok(()), + ), + on_after_sending_transaction_callback, + })) + } +} + +impl From for crate::commands::ActionContext { + fn from(item: WithdrawContext) -> Self { + item.0 + } +} + +impl Withdraw { + pub fn input_signer_account_id( + context: &super::DelegateStakeContext, + ) -> color_eyre::eyre::Result> { + crate::common::input_signer_account_id_from_used_account_list( + &context.global_context.config.credentials_home_dir, + "What is the signer account ID?", + ) + } +} diff --git a/src/commands/staking/delegate/withdraw_all.rs b/src/commands/staking/delegate/withdraw_all.rs new file mode 100644 index 000000000..888faf114 --- /dev/null +++ b/src/commands/staking/delegate/withdraw_all.rs @@ -0,0 +1,85 @@ +use std::str::FromStr; + +#[derive(Debug, Clone, interactive_clap::InteractiveClap)] +#[interactive_clap(input_context = super::DelegateStakeContext)] +#[interactive_clap(output_context = WithdrawAllContext)] +pub struct WithdrawAll { + #[interactive_clap(skip_default_input_arg)] + /// What is the signer account ID? + signer_account_id: crate::types::account_id::AccountId, + #[interactive_clap(named_arg)] + /// Select network + network_config: crate::network_for_transaction::NetworkForTransactionArgs, +} + +#[derive(Clone)] +pub struct WithdrawAllContext(crate::commands::ActionContext); + +impl WithdrawAllContext { + pub fn from_previous_context( + previous_context: super::DelegateStakeContext, + scope: &::InteractiveClapContextScope, + ) -> color_eyre::eyre::Result { + let signer = scope.signer_account_id.clone(); + let signer_id: near_primitives::types::AccountId = scope.signer_account_id.clone().into(); + let validator_account_id = previous_context.validator_account_id.clone(); + + let on_after_getting_network_callback: crate::commands::OnAfterGettingNetworkCallback = + std::sync::Arc::new(move |_network_config| { + Ok(crate::commands::PrepopulatedTransaction { + signer_id: signer_id.clone(), + receiver_id: previous_context.validator_account_id.clone(), + actions: vec![near_primitives::transaction::Action::FunctionCall( + near_primitives::transaction::FunctionCallAction { + method_name: "withdraw_all".to_string(), + args: vec![], + gas: crate::common::NearGas::from_str("300 TeraGas") + .unwrap() + .inner, + deposit: crate::common::NearBalance::from_yoctonear(0).to_yoctonear(), + }, + )], + }) + }); + + let on_after_sending_transaction_callback: crate::transaction_signature_options::OnAfterSendingTransactionCallback = std::sync::Arc::new( + move |outcome_view, _network_config| { + if let near_primitives::views::FinalExecutionStatus::SuccessValue(_) = outcome_view.status { + println!("{outcome_view:#?}"); + eprintln!( + "<{signer}> has successfully withdrawn the entire amount from <{validator_account_id}>.", //XXX + ); + } + Ok(()) + }, + ); + Ok(Self(crate::commands::ActionContext { + global_context: previous_context.global_context, + on_after_getting_network_callback, + on_before_signing_callback: std::sync::Arc::new( + |_prepolulated_unsinged_transaction, _network_config| Ok(()), + ), + on_before_sending_transaction_callback: std::sync::Arc::new( + |_signed_transaction, _network_config, _message| Ok(()), + ), + on_after_sending_transaction_callback, + })) + } +} + +impl From for crate::commands::ActionContext { + fn from(item: WithdrawAllContext) -> Self { + item.0 + } +} + +impl WithdrawAll { + pub fn input_signer_account_id( + context: &super::DelegateStakeContext, + ) -> color_eyre::eyre::Result> { + crate::common::input_signer_account_id_from_used_account_list( + &context.global_context.config.credentials_home_dir, + "What is the signer account ID?", + ) + } +} From 5d00339524a2a8bc4bfda767ac303e7fbeec7a24 Mon Sep 17 00:00:00 2001 From: FroVolod Date: Wed, 19 Jul 2023 21:59:14 +0300 Subject: [PATCH 03/44] added Unstake, UnstakeAll --- src/commands/staking/delegate/mod.rs | 21 +++-- src/commands/staking/delegate/unstake.rs | 92 +++++++++++++++++++ src/commands/staking/delegate/unstake_all.rs | 84 +++++++++++++++++ src/commands/staking/delegate/withdraw.rs | 1 - src/commands/staking/delegate/withdraw_all.rs | 1 - 5 files changed, 190 insertions(+), 9 deletions(-) create mode 100644 src/commands/staking/delegate/unstake.rs create mode 100644 src/commands/staking/delegate/unstake_all.rs diff --git a/src/commands/staking/delegate/mod.rs b/src/commands/staking/delegate/mod.rs index 73a19abd9..20ebda6f1 100644 --- a/src/commands/staking/delegate/mod.rs +++ b/src/commands/staking/delegate/mod.rs @@ -1,5 +1,7 @@ use strum::{EnumDiscriminants, EnumIter, EnumMessage}; +mod unstake; +mod unstake_all; mod withdraw; mod withdraw_all; @@ -56,18 +58,23 @@ pub enum DelegateStakingCommand { /// The transfer is carried out in NEAR tokens Stake, #[strum_discriminants(strum( - message = "unstake - Removing delegated stakes from validators." + message = "unstake - Unstaking the given amount from the inner account of the predecessor" ))] - /// The transfer is carried out in NEAR tokens - Unstake, + /// Unstaking the given amount from the inner account of the predecessor + Unstake(self::unstake::Unstake), + #[strum_discriminants(strum( + message = "unstake-all - Unstaking all staked balance from the inner account of the predecessor" + ))] + /// Unstaking all staked balance from the inner account of the predecessor + UnstakeAll(self::unstake_all::UnstakeAll), #[strum_discriminants(strum( - message = "withdraw - Withdrawing the non staked balance for given account." + message = "withdraw - Withdrawing the non staked balance for given account" ))] - /// Withdrawing the non staked balance for given account. + /// Withdrawing the non staked balance for given account Withdraw(self::withdraw::Withdraw), #[strum_discriminants(strum( - message = "withdraw-all - Withdrawing the entire unstaked balance from the predecessor account." + message = "withdraw-all - Withdrawing the entire unstaked balance from the predecessor account" ))] - /// Withdrawing the entire unstaked balance from the predecessor account. + /// Withdrawing the entire unstaked balance from the predecessor account WithdrawAll(self::withdraw_all::WithdrawAll), } diff --git a/src/commands/staking/delegate/unstake.rs b/src/commands/staking/delegate/unstake.rs new file mode 100644 index 000000000..89889f8c8 --- /dev/null +++ b/src/commands/staking/delegate/unstake.rs @@ -0,0 +1,92 @@ +use std::str::FromStr; + +#[derive(Debug, Clone, interactive_clap::InteractiveClap)] +#[interactive_clap(input_context = super::DelegateStakeContext)] +#[interactive_clap(output_context = UnstakeContext)] +pub struct Unstake { + /// Enter the amount to unstake from the inner account of the predecessor (example: 10NEAR or 0.5near or 10000yoctonear): + amount: crate::common::NearBalance, + #[interactive_clap(skip_default_input_arg)] + /// What is the signer account ID? + signer_account_id: crate::types::account_id::AccountId, + #[interactive_clap(named_arg)] + /// Select network + network_config: crate::network_for_transaction::NetworkForTransactionArgs, +} + +#[derive(Clone)] +pub struct UnstakeContext(crate::commands::ActionContext); + +impl UnstakeContext { + pub fn from_previous_context( + previous_context: super::DelegateStakeContext, + scope: &::InteractiveClapContextScope, + ) -> color_eyre::eyre::Result { + let signer = scope.signer_account_id.clone(); + let signer_id: near_primitives::types::AccountId = scope.signer_account_id.clone().into(); + let validator_account_id = previous_context.validator_account_id.clone(); + let amount = scope.amount.clone(); + + let on_after_getting_network_callback: crate::commands::OnAfterGettingNetworkCallback = + std::sync::Arc::new(move |_network_config| { + Ok(crate::commands::PrepopulatedTransaction { + signer_id: signer_id.clone(), + receiver_id: previous_context.validator_account_id.clone(), + actions: vec![near_primitives::transaction::Action::FunctionCall( + near_primitives::transaction::FunctionCallAction { + method_name: "unstake".to_string(), + args: serde_json::json!({ + "amount": amount.clone().to_yoctonear().to_string() + }) + .to_string() + .into_bytes(), + gas: crate::common::NearGas::from_str("300 TeraGas") + .unwrap() + .inner, + deposit: crate::common::NearBalance::from_yoctonear(0).to_yoctonear(), + }, + )], + }) + }); + + let amount = scope.amount.clone(); + let on_after_sending_transaction_callback: crate::transaction_signature_options::OnAfterSendingTransactionCallback = std::sync::Arc::new( + move |outcome_view, _network_config| { + if let near_primitives::views::FinalExecutionStatus::SuccessValue(_) = outcome_view.status { + eprintln!( + "<{signer}> has successfully unstake {amount} from <{validator_account_id}>.", + ); + } + Ok(()) + }, + ); + Ok(Self(crate::commands::ActionContext { + global_context: previous_context.global_context, + on_after_getting_network_callback, + on_before_signing_callback: std::sync::Arc::new( + |_prepolulated_unsinged_transaction, _network_config| Ok(()), + ), + on_before_sending_transaction_callback: std::sync::Arc::new( + |_signed_transaction, _network_config, _message| Ok(()), + ), + on_after_sending_transaction_callback, + })) + } +} + +impl From for crate::commands::ActionContext { + fn from(item: UnstakeContext) -> Self { + item.0 + } +} + +impl Unstake { + pub fn input_signer_account_id( + context: &super::DelegateStakeContext, + ) -> color_eyre::eyre::Result> { + crate::common::input_signer_account_id_from_used_account_list( + &context.global_context.config.credentials_home_dir, + "What is the signer account ID?", + ) + } +} diff --git a/src/commands/staking/delegate/unstake_all.rs b/src/commands/staking/delegate/unstake_all.rs new file mode 100644 index 000000000..b8057bac6 --- /dev/null +++ b/src/commands/staking/delegate/unstake_all.rs @@ -0,0 +1,84 @@ +use std::str::FromStr; + +#[derive(Debug, Clone, interactive_clap::InteractiveClap)] +#[interactive_clap(input_context = super::DelegateStakeContext)] +#[interactive_clap(output_context = UnstakeAllContext)] +pub struct UnstakeAll { + #[interactive_clap(skip_default_input_arg)] + /// What is the signer account ID? + signer_account_id: crate::types::account_id::AccountId, + #[interactive_clap(named_arg)] + /// Select network + network_config: crate::network_for_transaction::NetworkForTransactionArgs, +} + +#[derive(Clone)] +pub struct UnstakeAllContext(crate::commands::ActionContext); + +impl UnstakeAllContext { + pub fn from_previous_context( + previous_context: super::DelegateStakeContext, + scope: &::InteractiveClapContextScope, + ) -> color_eyre::eyre::Result { + let signer = scope.signer_account_id.clone(); + let signer_id: near_primitives::types::AccountId = scope.signer_account_id.clone().into(); + let validator_account_id = previous_context.validator_account_id.clone(); + + let on_after_getting_network_callback: crate::commands::OnAfterGettingNetworkCallback = + std::sync::Arc::new(move |_network_config| { + Ok(crate::commands::PrepopulatedTransaction { + signer_id: signer_id.clone(), + receiver_id: previous_context.validator_account_id.clone(), + actions: vec![near_primitives::transaction::Action::FunctionCall( + near_primitives::transaction::FunctionCallAction { + method_name: "unstake_all".to_string(), + args: vec![], + gas: crate::common::NearGas::from_str("300 TeraGas") + .unwrap() + .inner, + deposit: crate::common::NearBalance::from_yoctonear(0).to_yoctonear(), + }, + )], + }) + }); + + let on_after_sending_transaction_callback: crate::transaction_signature_options::OnAfterSendingTransactionCallback = std::sync::Arc::new( + move |outcome_view, _network_config| { + if let near_primitives::views::FinalExecutionStatus::SuccessValue(_) = outcome_view.status { + eprintln!( + "<{signer}> has successfully unstake the entire amount from <{validator_account_id}>.", //XXX + ); + } + Ok(()) + }, + ); + Ok(Self(crate::commands::ActionContext { + global_context: previous_context.global_context, + on_after_getting_network_callback, + on_before_signing_callback: std::sync::Arc::new( + |_prepolulated_unsinged_transaction, _network_config| Ok(()), + ), + on_before_sending_transaction_callback: std::sync::Arc::new( + |_signed_transaction, _network_config, _message| Ok(()), + ), + on_after_sending_transaction_callback, + })) + } +} + +impl From for crate::commands::ActionContext { + fn from(item: UnstakeAllContext) -> Self { + item.0 + } +} + +impl UnstakeAll { + pub fn input_signer_account_id( + context: &super::DelegateStakeContext, + ) -> color_eyre::eyre::Result> { + crate::common::input_signer_account_id_from_used_account_list( + &context.global_context.config.credentials_home_dir, + "What is the signer account ID?", + ) + } +} diff --git a/src/commands/staking/delegate/withdraw.rs b/src/commands/staking/delegate/withdraw.rs index 7181ff5b4..826bba856 100644 --- a/src/commands/staking/delegate/withdraw.rs +++ b/src/commands/staking/delegate/withdraw.rs @@ -53,7 +53,6 @@ impl WithdrawContext { let on_after_sending_transaction_callback: crate::transaction_signature_options::OnAfterSendingTransactionCallback = std::sync::Arc::new( move |outcome_view, _network_config| { if let near_primitives::views::FinalExecutionStatus::SuccessValue(_) = outcome_view.status { - println!("{outcome_view:#?}"); eprintln!( "<{signer}> has successfully withdrawn {amount} from <{validator_account_id}>.", ); diff --git a/src/commands/staking/delegate/withdraw_all.rs b/src/commands/staking/delegate/withdraw_all.rs index 888faf114..6f330ce77 100644 --- a/src/commands/staking/delegate/withdraw_all.rs +++ b/src/commands/staking/delegate/withdraw_all.rs @@ -45,7 +45,6 @@ impl WithdrawAllContext { let on_after_sending_transaction_callback: crate::transaction_signature_options::OnAfterSendingTransactionCallback = std::sync::Arc::new( move |outcome_view, _network_config| { if let near_primitives::views::FinalExecutionStatus::SuccessValue(_) = outcome_view.status { - println!("{outcome_view:#?}"); eprintln!( "<{signer}> has successfully withdrawn the entire amount from <{validator_account_id}>.", //XXX ); From 7089c690b6468a17ab1aa41db51261b70dc2ffa4 Mon Sep 17 00:00:00 2001 From: FroVolod Date: Sat, 22 Jul 2023 11:27:51 +0300 Subject: [PATCH 04/44] refactored Withdraw, WithdrawAll --- src/commands/staking/delegate/withdraw.rs | 80 ++++++++++++----- src/commands/staking/delegate/withdraw_all.rs | 89 +++++++++++++------ 2 files changed, 119 insertions(+), 50 deletions(-) diff --git a/src/commands/staking/delegate/withdraw.rs b/src/commands/staking/delegate/withdraw.rs index 826bba856..cf5eef48c 100644 --- a/src/commands/staking/delegate/withdraw.rs +++ b/src/commands/staking/delegate/withdraw.rs @@ -1,5 +1,9 @@ use std::str::FromStr; +use color_eyre::eyre::WrapErr; + +use crate::common::{CallResultExt, JsonRpcClientExt}; + #[derive(Debug, Clone, interactive_clap::InteractiveClap)] #[interactive_clap(input_context = super::DelegateStakeContext)] #[interactive_clap(output_context = WithdrawContext)] @@ -22,35 +26,65 @@ impl WithdrawContext { previous_context: super::DelegateStakeContext, scope: &::InteractiveClapContextScope, ) -> color_eyre::eyre::Result { - let signer = scope.signer_account_id.clone(); - let signer_id: near_primitives::types::AccountId = scope.signer_account_id.clone().into(); let validator_account_id = previous_context.validator_account_id.clone(); - let amount = scope.amount.clone(); let on_after_getting_network_callback: crate::commands::OnAfterGettingNetworkCallback = - std::sync::Arc::new(move |_network_config| { - Ok(crate::commands::PrepopulatedTransaction { - signer_id: signer_id.clone(), - receiver_id: previous_context.validator_account_id.clone(), - actions: vec![near_primitives::transaction::Action::FunctionCall( - near_primitives::transaction::FunctionCallAction { - method_name: "withdraw".to_string(), - args: serde_json::json!({ - "amount": amount.clone().to_yoctonear().to_string() + std::sync::Arc::new({ + let amount = scope.amount.clone(); + let signer_id: near_primitives::types::AccountId = + scope.signer_account_id.clone().into(); + + move |network_config| { + let is_account_unstaked_balance_available = network_config + .json_rpc_client() + .blocking_call_view_function( + &previous_context.validator_account_id, + "is_account_unstaked_balance_available", + serde_json::json!({ + "account_id": signer_id.to_string(), }) .to_string() .into_bytes(), - gas: crate::common::NearGas::from_str("300 TeraGas") - .unwrap() - .inner, - deposit: crate::common::NearBalance::from_yoctonear(0).to_yoctonear(), - }, - )], - }) + near_primitives::types::BlockReference::Finality(near_primitives::types::Finality::Final), + ) + .wrap_err( + "Failed to fetch query for view method: 'is_account_unstaked_balance_available'" + )? + .parse_result_from_json::() + .wrap_err( + "Failed to parse return value of view function call for bool value." + )?; + if !is_account_unstaked_balance_available { + return Err(color_eyre::Report::msg(format!( + "<{signer_id}> can't withdraw tokens in the current epoch." + ))); + } + Ok(crate::commands::PrepopulatedTransaction { + signer_id: signer_id.clone(), + receiver_id: previous_context.validator_account_id.clone(), + actions: vec![near_primitives::transaction::Action::FunctionCall( + near_primitives::transaction::FunctionCallAction { + method_name: "withdraw".to_string(), + args: serde_json::json!({ + "amount": amount.clone().to_yoctonear().to_string() + }) + .to_string() + .into_bytes(), + gas: crate::common::NearGas::from_str("300 TeraGas") + .unwrap() + .inner, + deposit: crate::common::NearBalance::from_yoctonear(0) + .to_yoctonear(), + }, + )], + }) + } }); - let amount = scope.amount.clone(); - let on_after_sending_transaction_callback: crate::transaction_signature_options::OnAfterSendingTransactionCallback = std::sync::Arc::new( + let on_after_sending_transaction_callback: crate::transaction_signature_options::OnAfterSendingTransactionCallback = std::sync::Arc::new({ + let amount = scope.amount.clone(); + let signer = scope.signer_account_id.clone(); + move |outcome_view, _network_config| { if let near_primitives::views::FinalExecutionStatus::SuccessValue(_) = outcome_view.status { eprintln!( @@ -58,8 +92,8 @@ impl WithdrawContext { ); } Ok(()) - }, - ); + } + }); Ok(Self(crate::commands::ActionContext { global_context: previous_context.global_context, on_after_getting_network_callback, diff --git a/src/commands/staking/delegate/withdraw_all.rs b/src/commands/staking/delegate/withdraw_all.rs index 6f330ce77..ad5a736ac 100644 --- a/src/commands/staking/delegate/withdraw_all.rs +++ b/src/commands/staking/delegate/withdraw_all.rs @@ -1,5 +1,9 @@ use std::str::FromStr; +use color_eyre::eyre::WrapErr; + +use crate::common::{CallResultExt, JsonRpcClientExt}; + #[derive(Debug, Clone, interactive_clap::InteractiveClap)] #[interactive_clap(input_context = super::DelegateStakeContext)] #[interactive_clap(output_context = WithdrawAllContext)] @@ -20,38 +24,69 @@ impl WithdrawAllContext { previous_context: super::DelegateStakeContext, scope: &::InteractiveClapContextScope, ) -> color_eyre::eyre::Result { - let signer = scope.signer_account_id.clone(); - let signer_id: near_primitives::types::AccountId = scope.signer_account_id.clone().into(); let validator_account_id = previous_context.validator_account_id.clone(); let on_after_getting_network_callback: crate::commands::OnAfterGettingNetworkCallback = - std::sync::Arc::new(move |_network_config| { - Ok(crate::commands::PrepopulatedTransaction { - signer_id: signer_id.clone(), - receiver_id: previous_context.validator_account_id.clone(), - actions: vec![near_primitives::transaction::Action::FunctionCall( - near_primitives::transaction::FunctionCallAction { - method_name: "withdraw_all".to_string(), - args: vec![], - gas: crate::common::NearGas::from_str("300 TeraGas") - .unwrap() - .inner, - deposit: crate::common::NearBalance::from_yoctonear(0).to_yoctonear(), - }, - )], - }) + std::sync::Arc::new({ + let signer_id: near_primitives::types::AccountId = + scope.signer_account_id.clone().into(); + + move |network_config| { + let is_account_unstaked_balance_available = network_config + .json_rpc_client() + .blocking_call_view_function( + &previous_context.validator_account_id, + "is_account_unstaked_balance_available", + serde_json::json!({ + "account_id": signer_id.to_string(), + }) + .to_string() + .into_bytes(), + near_primitives::types::BlockReference::Finality(near_primitives::types::Finality::Final), + ) + .wrap_err( + "Failed to fetch query for view method: 'is_account_unstaked_balance_available'" + )? + .parse_result_from_json::() + .wrap_err( + "Failed to parse return value of view function call for bool value." + )?; + if !is_account_unstaked_balance_available { + return Err(color_eyre::Report::msg(format!( + "<{signer_id}> can't withdraw tokens in the current epoch." + ))); + } + + Ok(crate::commands::PrepopulatedTransaction { + signer_id: signer_id.clone(), + receiver_id: previous_context.validator_account_id.clone(), + actions: vec![near_primitives::transaction::Action::FunctionCall( + near_primitives::transaction::FunctionCallAction { + method_name: "withdraw_all".to_string(), + args: vec![], + gas: crate::common::NearGas::from_str("300 TeraGas") + .unwrap() + .inner, + deposit: crate::common::NearBalance::from_yoctonear(0) + .to_yoctonear(), + }, + )], + }) + } }); - let on_after_sending_transaction_callback: crate::transaction_signature_options::OnAfterSendingTransactionCallback = std::sync::Arc::new( - move |outcome_view, _network_config| { - if let near_primitives::views::FinalExecutionStatus::SuccessValue(_) = outcome_view.status { - eprintln!( - "<{signer}> has successfully withdrawn the entire amount from <{validator_account_id}>.", //XXX - ); - } - Ok(()) - }, - ); + let on_after_sending_transaction_callback: crate::transaction_signature_options::OnAfterSendingTransactionCallback = std::sync::Arc::new({ + let signer = scope.signer_account_id.clone(); + + move |outcome_view, _network_config| { + if let near_primitives::views::FinalExecutionStatus::SuccessValue(_) = outcome_view.status { + eprintln!( + "<{signer}> has successfully withdrawn the entire amount from <{validator_account_id}>.", //XXX + ); + } + Ok(()) + } + }); Ok(Self(crate::commands::ActionContext { global_context: previous_context.global_context, on_after_getting_network_callback, From 538253c979f928a1cc8a206a3dacfdd2630005a4 Mon Sep 17 00:00:00 2001 From: FroVolod Date: Sat, 22 Jul 2023 14:20:00 +0300 Subject: [PATCH 05/44] added ViewBalance --- src/commands/staking/delegate/mod.rs | 15 ++- src/commands/staking/delegate/view_balance.rs | 119 ++++++++++++++++++ src/common.rs | 2 +- 3 files changed, 130 insertions(+), 6 deletions(-) create mode 100644 src/commands/staking/delegate/view_balance.rs diff --git a/src/commands/staking/delegate/mod.rs b/src/commands/staking/delegate/mod.rs index 20ebda6f1..4443070e5 100644 --- a/src/commands/staking/delegate/mod.rs +++ b/src/commands/staking/delegate/mod.rs @@ -2,6 +2,7 @@ use strum::{EnumDiscriminants, EnumIter, EnumMessage}; mod unstake; mod unstake_all; +mod view_balance; mod withdraw; mod withdraw_all; @@ -51,11 +52,15 @@ impl DelegateStake { #[non_exhaustive] /// Select actions with delegated staking: pub enum DelegateStakingCommand { - #[strum_discriminants(strum(message = "view - "))] - /// The transfer is carried out in NEAR tokens - View, - #[strum_discriminants(strum(message = "stake - "))] - /// The transfer is carried out in NEAR tokens + #[strum_discriminants(strum( + message = "view-balance - View the total balance for a given account" + ))] + /// View the total balance for a given account + ViewBalance(self::view_balance::ViewBalance), + #[strum_discriminants(strum( + message = "stake - Staking the given amount from the inner account of the predecessor" + ))] + /// Staking the given amount from the inner account of the predecessor Stake, #[strum_discriminants(strum( message = "unstake - Unstaking the given amount from the inner account of the predecessor" diff --git a/src/commands/staking/delegate/view_balance.rs b/src/commands/staking/delegate/view_balance.rs new file mode 100644 index 000000000..c41cd57e2 --- /dev/null +++ b/src/commands/staking/delegate/view_balance.rs @@ -0,0 +1,119 @@ +use color_eyre::eyre::WrapErr; + +use crate::common::{CallResultExt, JsonRpcClientExt}; + +#[derive(Debug, Clone, interactive_clap::InteractiveClap)] +#[interactive_clap(input_context = super::DelegateStakeContext)] +#[interactive_clap(output_context = ViewBalanceContext)] +pub struct ViewBalance { + #[interactive_clap(skip_default_input_arg)] + /// On which account ID do you need to view the total balance? + account_id: crate::types::account_id::AccountId, + #[interactive_clap(named_arg)] + /// Select network + network_config: crate::network_view_at_block::NetworkViewAtBlockArgs, +} + +#[derive(Clone)] +pub struct ViewBalanceContext(crate::network_view_at_block::ArgsForViewContext); + +impl ViewBalanceContext { + pub fn from_previous_context( + previous_context: super::DelegateStakeContext, + scope: &::InteractiveClapContextScope, + ) -> color_eyre::eyre::Result { + let on_after_getting_block_reference_callback: crate::network_view_at_block::OnAfterGettingBlockReferenceCallback = std::sync::Arc::new({ + let account_id: near_primitives::types::AccountId = scope.account_id.clone().into(); + let validator_id = previous_context.validator_account_id.clone(); + + move |network_config, block_reference| { + let json_rpc_client = network_config.json_rpc_client(); + let user_staked_balance: u128 = json_rpc_client + .blocking_call_view_function( + &previous_context.validator_account_id, + "get_account_staked_balance", + serde_json::json!({ + "account_id": account_id.to_string(), + }) + .to_string() + .into_bytes(), + block_reference.clone(), + ) + .wrap_err( + "Failed to fetch query for view method: 'get_account_staked_balance'" + )? + .parse_result_from_json::() + .wrap_err( + "Failed to parse return value of view function call for String." + )? + .parse()?; + let user_unstaked_balance: u128 = json_rpc_client + .blocking_call_view_function( + &previous_context.validator_account_id, + "get_account_unstaked_balance", + serde_json::json!({ + "account_id": account_id.to_string(), + }) + .to_string() + .into_bytes(), + block_reference.clone(), + ) + .wrap_err( + "Failed to fetch query for view method: 'get_account_unstaked_balance'" + )? + .parse_result_from_json::() + .wrap_err( + "Failed to parse return value of view function call for String." + )? + .parse()?; + let user_total_balance: u128 = json_rpc_client + .blocking_call_view_function( + &previous_context.validator_account_id, + "get_account_total_balance", + serde_json::json!({ + "account_id": account_id.to_string(), + }) + .to_string() + .into_bytes(), + block_reference.clone(), + ) + .wrap_err( + "Failed to fetch query for view method: 'get_account_total_balance'" + )? + .parse_result_from_json::() + .wrap_err( + "Failed to parse return value of view function call for String." + )? + .parse()?; + + eprintln!("Balance on validator <{validator_id}> for <{account_id}>:"); + eprintln!(" Staked balance: {:>38}", crate::common::NearBalance::from_yoctonear(user_staked_balance).to_string()); + eprintln!(" Unstaked balance: {:>38}", crate::common::NearBalance::from_yoctonear(user_unstaked_balance).to_string()); + eprintln!(" Total balance: {:>38}", crate::common::NearBalance::from_yoctonear(user_total_balance).to_string()); + + Ok(()) + } + }); + Ok(Self(crate::network_view_at_block::ArgsForViewContext { + config: previous_context.global_context.config, + on_after_getting_block_reference_callback, + })) + } +} + +impl From for crate::network_view_at_block::ArgsForViewContext { + fn from(item: ViewBalanceContext) -> Self { + item.0 + } +} + +impl ViewBalance { + pub fn input_account_id( + context: &super::DelegateStakeContext, + ) -> color_eyre::eyre::Result> { + crate::common::input_non_signer_account_id_from_used_account_list( + &context.global_context.config.credentials_home_dir, + "On which account ID do you need to view the total balance?", + ) + } +} diff --git a/src/common.rs b/src/common.rs index e4cc80f4e..58adf8aaa 100644 --- a/src/common.rs +++ b/src/common.rs @@ -100,7 +100,7 @@ impl std::fmt::Display for NearBalance { f, "{}.{} NEAR", self.yoctonear_amount / ONE_NEAR, - format!("{:0>24}", (self.yoctonear_amount % ONE_NEAR)).trim_end_matches('0') + format!("{:0>24}", (self.yoctonear_amount % ONE_NEAR)) //.trim_end_matches('0') XXX ) } } From 2ac06dc6aca409722b896eab0ac5c6fcacec5fe9 Mon Sep 17 00:00:00 2001 From: FroVolod Date: Fri, 28 Jul 2023 17:35:51 +0300 Subject: [PATCH 06/44] added ValidatorList --- src/commands/staking/mod.rs | 10 +- src/commands/staking/validator_list/mod.rs | 224 +++++++++++++++++++++ 2 files changed, 232 insertions(+), 2 deletions(-) create mode 100644 src/commands/staking/validator_list/mod.rs diff --git a/src/commands/staking/mod.rs b/src/commands/staking/mod.rs index 59563cc30..855dc85ed 100644 --- a/src/commands/staking/mod.rs +++ b/src/commands/staking/mod.rs @@ -1,6 +1,7 @@ use strum::{EnumDiscriminants, EnumIter, EnumMessage}; mod delegate; +mod validator_list; #[derive(Debug, Clone, interactive_clap::InteractiveClap)] #[interactive_clap(context = crate::GlobalContext)] @@ -15,7 +16,12 @@ pub struct Staking { #[non_exhaustive] /// Select the type of stake: pub enum StakingType { - #[strum_discriminants(strum(message = "delegate - "))] - /// + #[strum_discriminants(strum( + message = "validator-list - View the list of validators to delegate" + ))] + /// View the list of validators to delegate + ValidatorList(self::validator_list::ValidatorList), + #[strum_discriminants(strum(message = "delegate - Delegation management"))] + /// Delegation management Delegate(self::delegate::DelegateStake), } diff --git a/src/commands/staking/validator_list/mod.rs b/src/commands/staking/validator_list/mod.rs new file mode 100644 index 000000000..524915210 --- /dev/null +++ b/src/commands/staking/validator_list/mod.rs @@ -0,0 +1,224 @@ +use color_eyre::eyre::Context; +use futures::StreamExt; +use prettytable::Table; + +use near_jsonrpc_client::methods::validators::RpcValidatorRequest; + +use crate::common::{CallResultExt, JsonRpcClientExt, RpcQueryResponseExt}; + +#[derive(Debug, Clone, interactive_clap::InteractiveClap)] +#[interactive_clap(input_context = crate::GlobalContext)] +#[interactive_clap(output_context = ValidatorListContext)] +pub struct ValidatorList { + #[interactive_clap(named_arg)] + /// Select network + network_config: crate::network::Network, +} + +#[derive(Clone)] +pub struct ValidatorListContext(crate::network::NetworkContext); + +impl ValidatorListContext { + pub fn from_previous_context( + previous_context: crate::GlobalContext, + _scope: &::InteractiveClapContextScope, + ) -> color_eyre::eyre::Result { + let on_after_getting_network_callback: crate::network::OnAfterGettingNetworkCallback = + std::sync::Arc::new(display_validators_info); + Ok(Self(crate::network::NetworkContext { + config: previous_context.config, + on_after_getting_network_callback, + })) + } +} + +impl From for crate::network::NetworkContext { + fn from(item: ValidatorListContext) -> Self { + item.0 + } +} + +pub fn display_validators_info(network_config: &crate::config::NetworkConfig) -> crate::CliResult { + let mut table = Table::new(); + table.set_titles(prettytable::row![Fg=>"#", "Validator Id", "Fee", "Delegators", "Stake"]); + + for (index, validator) in get_validator_list(network_config)?.into_iter().enumerate() { + table.add_row(prettytable::row![ + Fg->index + 1, + validator.validator_id, + format!("{:>6.2} %", validator.fee.numerator * 100 / validator.fee.denominator), + validator.delegators, + crate::common::NearBalance::from_yoctonear(validator.stake), + ]); + } + table.set_format(*prettytable::format::consts::FORMAT_NO_LINESEP_WITH_TITLE); + table.printstd(); + Ok(()) +} + +#[derive(Debug, Clone, PartialEq, Eq)] +pub struct ValidatorsTable { + pub validator_id: near_primitives::types::AccountId, + pub fee: RewardFeeFraction, + pub delegators: u64, + pub stake: near_primitives::types::Balance, +} + +#[derive(Debug, Clone, PartialEq, Eq, serde::Deserialize)] +pub struct RewardFeeFraction { + pub numerator: u32, + pub denominator: u32, +} + +pub fn get_validator_list( + network_config: &crate::config::NetworkConfig, +) -> color_eyre::eyre::Result> { + let json_rpc_client = network_config.json_rpc_client(); + + let epoch_validator_info = json_rpc_client + .blocking_call(&RpcValidatorRequest { + epoch_reference: near_primitives::types::EpochReference::Latest, + }) + .wrap_err("Failed to get epoch validators information request.")?; + + let current_proposals = epoch_validator_info.current_proposals; + let current_proposals_stake: std::collections::HashMap< + near_primitives::types::AccountId, + near_primitives::types::Balance, + > = current_proposals + .into_iter() + .map(|validator_stake_view| { + let validator_stake = validator_stake_view.into_validator_stake(); + validator_stake.account_and_stake() + }) + .collect(); + + let current_validators = epoch_validator_info.current_validators; + let mut current_validators_stake: std::collections::HashMap< + near_primitives::types::AccountId, + near_primitives::types::Balance, + > = current_validators + .into_iter() + .map(|current_epoch_validator_info| { + ( + current_epoch_validator_info.account_id, + current_epoch_validator_info.stake, + ) + }) + .collect(); + + let next_validators = epoch_validator_info.next_validators; + let next_validators_stake: std::collections::HashMap< + near_primitives::types::AccountId, + near_primitives::types::Balance, + > = next_validators + .into_iter() + .map(|next_epoch_validator_info| { + ( + next_epoch_validator_info.account_id, + next_epoch_validator_info.stake, + ) + }) + .collect(); + + current_validators_stake.extend(next_validators_stake); + current_validators_stake.extend(current_proposals_stake); + + let runtime = tokio::runtime::Builder::new_multi_thread() + .enable_all() + .build()?; + let chunk_size = 15; + let concurrency = 10; + + let combine_validators: std::collections::HashMap< + near_primitives::types::AccountId, + ValidatorsTable, + > = runtime + .block_on( + futures::stream::iter( + current_validators_stake + .iter() + .collect::>() + .chunks(chunk_size), + ) + .map( + |validators: &[(&near_primitives::types::AccountId, &u128)]| async { + get_combine_validators(&json_rpc_client, validators).await + }, + ) + .buffer_unordered(concurrency) + .collect::>>(), + ) + .into_iter() + .try_fold(std::collections::HashMap::new(), |mut acc, x| { + acc.extend(x?); + Ok::<_, color_eyre::eyre::Error>(acc) + })?; + + let mut validator_list: Vec = combine_validators.into_values().collect(); + validator_list.sort_by(|a, b| b.stake.cmp(&a.stake)); + Ok(validator_list) +} + +async fn get_combine_validators( + json_rpc_client: &near_jsonrpc_client::JsonRpcClient, + validators: &[(&near_primitives::types::AccountId, &u128)], +) -> color_eyre::Result> +{ + let mut combine_validators: std::collections::HashMap< + near_primitives::types::AccountId, + ValidatorsTable, + > = std::collections::HashMap::new(); + for (validator_id, stake) in validators { + let validator_id = *validator_id; + let reward_fee_fraction = json_rpc_client + .call(near_jsonrpc_client::methods::query::RpcQueryRequest { + block_reference: near_primitives::types::Finality::Final.into(), + request: near_primitives::views::QueryRequest::CallFunction { + account_id: validator_id.clone(), + method_name: "get_reward_fee_fraction".to_string(), + args: near_primitives::types::FunctionArgs::from(vec![]), + }, + }) + .await + .wrap_err("Failed to fetch query for view method: 'get_reward_fee_fraction'"); + + if reward_fee_fraction.is_err() { + continue; + }; + let fee = reward_fee_fraction? + .call_result()? + .parse_result_from_json::() + .wrap_err( + "Failed to parse return value of view function call for RewardFeeFraction.", + )?; + + let number_of_accounts = json_rpc_client + .call(near_jsonrpc_client::methods::query::RpcQueryRequest { + block_reference: near_primitives::types::Finality::Final.into(), + request: near_primitives::views::QueryRequest::CallFunction { + account_id: validator_id.clone(), + method_name: "get_number_of_accounts".to_string(), + args: near_primitives::types::FunctionArgs::from(vec![]), + }, + }) + .await + .wrap_err("Failed to fetch query for view method: 'get_number_of_accounts'"); + if number_of_accounts.is_err() { + continue; + }; + let delegators = number_of_accounts? + .call_result()? + .parse_result_from_json::() + .wrap_err("Failed to parse return value of view function call for u64.")?; + + let validators_table = ValidatorsTable { + validator_id: validator_id.clone(), + fee, + delegators, + stake: **stake, + }; + combine_validators.insert(validator_id.clone(), validators_table); + } + Ok(combine_validators) +} From 17fd2666649e9969440f9b8c2d7c094ee1dce994 Mon Sep 17 00:00:00 2001 From: FroVolod Date: Fri, 28 Jul 2023 18:01:41 +0300 Subject: [PATCH 07/44] refactored --- src/commands/staking/validator_list/mod.rs | 180 +------------------- src/common.rs | 188 +++++++++++++++++++++ 2 files changed, 193 insertions(+), 175 deletions(-) diff --git a/src/commands/staking/validator_list/mod.rs b/src/commands/staking/validator_list/mod.rs index 524915210..9e4569d21 100644 --- a/src/commands/staking/validator_list/mod.rs +++ b/src/commands/staking/validator_list/mod.rs @@ -1,11 +1,5 @@ -use color_eyre::eyre::Context; -use futures::StreamExt; use prettytable::Table; -use near_jsonrpc_client::methods::validators::RpcValidatorRequest; - -use crate::common::{CallResultExt, JsonRpcClientExt, RpcQueryResponseExt}; - #[derive(Debug, Clone, interactive_clap::InteractiveClap)] #[interactive_clap(input_context = crate::GlobalContext)] #[interactive_clap(output_context = ValidatorListContext)] @@ -38,11 +32,14 @@ impl From for crate::network::NetworkContext { } } -pub fn display_validators_info(network_config: &crate::config::NetworkConfig) -> crate::CliResult { +fn display_validators_info(network_config: &crate::config::NetworkConfig) -> crate::CliResult { let mut table = Table::new(); table.set_titles(prettytable::row![Fg=>"#", "Validator Id", "Fee", "Delegators", "Stake"]); - for (index, validator) in get_validator_list(network_config)?.into_iter().enumerate() { + for (index, validator) in crate::common::get_validator_list(network_config)? + .into_iter() + .enumerate() + { table.add_row(prettytable::row![ Fg->index + 1, validator.validator_id, @@ -55,170 +52,3 @@ pub fn display_validators_info(network_config: &crate::config::NetworkConfig) -> table.printstd(); Ok(()) } - -#[derive(Debug, Clone, PartialEq, Eq)] -pub struct ValidatorsTable { - pub validator_id: near_primitives::types::AccountId, - pub fee: RewardFeeFraction, - pub delegators: u64, - pub stake: near_primitives::types::Balance, -} - -#[derive(Debug, Clone, PartialEq, Eq, serde::Deserialize)] -pub struct RewardFeeFraction { - pub numerator: u32, - pub denominator: u32, -} - -pub fn get_validator_list( - network_config: &crate::config::NetworkConfig, -) -> color_eyre::eyre::Result> { - let json_rpc_client = network_config.json_rpc_client(); - - let epoch_validator_info = json_rpc_client - .blocking_call(&RpcValidatorRequest { - epoch_reference: near_primitives::types::EpochReference::Latest, - }) - .wrap_err("Failed to get epoch validators information request.")?; - - let current_proposals = epoch_validator_info.current_proposals; - let current_proposals_stake: std::collections::HashMap< - near_primitives::types::AccountId, - near_primitives::types::Balance, - > = current_proposals - .into_iter() - .map(|validator_stake_view| { - let validator_stake = validator_stake_view.into_validator_stake(); - validator_stake.account_and_stake() - }) - .collect(); - - let current_validators = epoch_validator_info.current_validators; - let mut current_validators_stake: std::collections::HashMap< - near_primitives::types::AccountId, - near_primitives::types::Balance, - > = current_validators - .into_iter() - .map(|current_epoch_validator_info| { - ( - current_epoch_validator_info.account_id, - current_epoch_validator_info.stake, - ) - }) - .collect(); - - let next_validators = epoch_validator_info.next_validators; - let next_validators_stake: std::collections::HashMap< - near_primitives::types::AccountId, - near_primitives::types::Balance, - > = next_validators - .into_iter() - .map(|next_epoch_validator_info| { - ( - next_epoch_validator_info.account_id, - next_epoch_validator_info.stake, - ) - }) - .collect(); - - current_validators_stake.extend(next_validators_stake); - current_validators_stake.extend(current_proposals_stake); - - let runtime = tokio::runtime::Builder::new_multi_thread() - .enable_all() - .build()?; - let chunk_size = 15; - let concurrency = 10; - - let combine_validators: std::collections::HashMap< - near_primitives::types::AccountId, - ValidatorsTable, - > = runtime - .block_on( - futures::stream::iter( - current_validators_stake - .iter() - .collect::>() - .chunks(chunk_size), - ) - .map( - |validators: &[(&near_primitives::types::AccountId, &u128)]| async { - get_combine_validators(&json_rpc_client, validators).await - }, - ) - .buffer_unordered(concurrency) - .collect::>>(), - ) - .into_iter() - .try_fold(std::collections::HashMap::new(), |mut acc, x| { - acc.extend(x?); - Ok::<_, color_eyre::eyre::Error>(acc) - })?; - - let mut validator_list: Vec = combine_validators.into_values().collect(); - validator_list.sort_by(|a, b| b.stake.cmp(&a.stake)); - Ok(validator_list) -} - -async fn get_combine_validators( - json_rpc_client: &near_jsonrpc_client::JsonRpcClient, - validators: &[(&near_primitives::types::AccountId, &u128)], -) -> color_eyre::Result> -{ - let mut combine_validators: std::collections::HashMap< - near_primitives::types::AccountId, - ValidatorsTable, - > = std::collections::HashMap::new(); - for (validator_id, stake) in validators { - let validator_id = *validator_id; - let reward_fee_fraction = json_rpc_client - .call(near_jsonrpc_client::methods::query::RpcQueryRequest { - block_reference: near_primitives::types::Finality::Final.into(), - request: near_primitives::views::QueryRequest::CallFunction { - account_id: validator_id.clone(), - method_name: "get_reward_fee_fraction".to_string(), - args: near_primitives::types::FunctionArgs::from(vec![]), - }, - }) - .await - .wrap_err("Failed to fetch query for view method: 'get_reward_fee_fraction'"); - - if reward_fee_fraction.is_err() { - continue; - }; - let fee = reward_fee_fraction? - .call_result()? - .parse_result_from_json::() - .wrap_err( - "Failed to parse return value of view function call for RewardFeeFraction.", - )?; - - let number_of_accounts = json_rpc_client - .call(near_jsonrpc_client::methods::query::RpcQueryRequest { - block_reference: near_primitives::types::Finality::Final.into(), - request: near_primitives::views::QueryRequest::CallFunction { - account_id: validator_id.clone(), - method_name: "get_number_of_accounts".to_string(), - args: near_primitives::types::FunctionArgs::from(vec![]), - }, - }) - .await - .wrap_err("Failed to fetch query for view method: 'get_number_of_accounts'"); - if number_of_accounts.is_err() { - continue; - }; - let delegators = number_of_accounts? - .call_result()? - .parse_result_from_json::() - .wrap_err("Failed to parse return value of view function call for u64.")?; - - let validators_table = ValidatorsTable { - validator_id: validator_id.clone(), - fee, - delegators, - stake: **stake, - }; - combine_validators.insert(validator_id.clone(), validators_table); - } - Ok(combine_validators) -} diff --git a/src/common.rs b/src/common.rs index 58adf8aaa..2f244f236 100644 --- a/src/common.rs +++ b/src/common.rs @@ -4,6 +4,7 @@ use std::io::Write; use std::str::FromStr; use color_eyre::eyre::WrapErr; +use futures::StreamExt; use prettytable::Table; use near_primitives::{hash::CryptoHash, types::BlockReference, views::AccessKeyPermissionView}; @@ -1460,6 +1461,193 @@ fn path_directories() -> Vec { dirs } +pub fn display_validators_info(network_config: &crate::config::NetworkConfig) -> crate::CliResult { + let mut table = Table::new(); + table.set_titles(prettytable::row![Fg=>"#", "Validator Id", "Fee", "Delegators", "Stake"]); + + for (index, validator) in get_validator_list(network_config)?.into_iter().enumerate() { + table.add_row(prettytable::row![ + Fg->index + 1, + validator.validator_id, + format!("{:>6.2} %", validator.fee.numerator * 100 / validator.fee.denominator), + validator.delegators, + crate::common::NearBalance::from_yoctonear(validator.stake), + ]); + } + table.set_format(*prettytable::format::consts::FORMAT_NO_LINESEP_WITH_TITLE); + table.printstd(); + Ok(()) +} + +#[derive(Debug, Clone, PartialEq, Eq)] +pub struct ValidatorsTable { + pub validator_id: near_primitives::types::AccountId, + pub fee: RewardFeeFraction, + pub delegators: u64, + pub stake: near_primitives::types::Balance, +} + +#[derive(Debug, Clone, PartialEq, Eq, serde::Deserialize)] +pub struct RewardFeeFraction { + pub numerator: u32, + pub denominator: u32, +} + +pub fn get_validator_list( + network_config: &crate::config::NetworkConfig, +) -> color_eyre::eyre::Result> { + let json_rpc_client = network_config.json_rpc_client(); + + let epoch_validator_info = json_rpc_client + .blocking_call( + &near_jsonrpc_client::methods::validators::RpcValidatorRequest { + epoch_reference: near_primitives::types::EpochReference::Latest, + }, + ) + .wrap_err("Failed to get epoch validators information request.")?; + + let current_proposals = epoch_validator_info.current_proposals; + let current_proposals_stake: std::collections::HashMap< + near_primitives::types::AccountId, + near_primitives::types::Balance, + > = current_proposals + .into_iter() + .map(|validator_stake_view| { + let validator_stake = validator_stake_view.into_validator_stake(); + validator_stake.account_and_stake() + }) + .collect(); + + let current_validators = epoch_validator_info.current_validators; + let mut current_validators_stake: std::collections::HashMap< + near_primitives::types::AccountId, + near_primitives::types::Balance, + > = current_validators + .into_iter() + .map(|current_epoch_validator_info| { + ( + current_epoch_validator_info.account_id, + current_epoch_validator_info.stake, + ) + }) + .collect(); + + let next_validators = epoch_validator_info.next_validators; + let next_validators_stake: std::collections::HashMap< + near_primitives::types::AccountId, + near_primitives::types::Balance, + > = next_validators + .into_iter() + .map(|next_epoch_validator_info| { + ( + next_epoch_validator_info.account_id, + next_epoch_validator_info.stake, + ) + }) + .collect(); + + current_validators_stake.extend(next_validators_stake); + current_validators_stake.extend(current_proposals_stake); + + let runtime = tokio::runtime::Builder::new_multi_thread() + .enable_all() + .build()?; + let chunk_size = 15; + let concurrency = 10; + + let combine_validators: std::collections::HashMap< + near_primitives::types::AccountId, + ValidatorsTable, + > = runtime + .block_on( + futures::stream::iter( + current_validators_stake + .iter() + .collect::>() + .chunks(chunk_size), + ) + .map( + |validators: &[(&near_primitives::types::AccountId, &u128)]| async { + get_combine_validators(&json_rpc_client, validators).await + }, + ) + .buffer_unordered(concurrency) + .collect::>>(), + ) + .into_iter() + .try_fold(std::collections::HashMap::new(), |mut acc, x| { + acc.extend(x?); + Ok::<_, color_eyre::eyre::Error>(acc) + })?; + + let mut validator_list: Vec = combine_validators.into_values().collect(); + validator_list.sort_by(|a, b| b.stake.cmp(&a.stake)); + Ok(validator_list) +} + +async fn get_combine_validators( + json_rpc_client: &near_jsonrpc_client::JsonRpcClient, + validators: &[(&near_primitives::types::AccountId, &u128)], +) -> color_eyre::Result> +{ + let mut combine_validators: std::collections::HashMap< + near_primitives::types::AccountId, + ValidatorsTable, + > = std::collections::HashMap::new(); + for (validator_id, stake) in validators { + let validator_id = *validator_id; + let reward_fee_fraction = json_rpc_client + .call(near_jsonrpc_client::methods::query::RpcQueryRequest { + block_reference: near_primitives::types::Finality::Final.into(), + request: near_primitives::views::QueryRequest::CallFunction { + account_id: validator_id.clone(), + method_name: "get_reward_fee_fraction".to_string(), + args: near_primitives::types::FunctionArgs::from(vec![]), + }, + }) + .await + .wrap_err("Failed to fetch query for view method: 'get_reward_fee_fraction'"); + + if reward_fee_fraction.is_err() { + continue; + }; + let fee = reward_fee_fraction? + .call_result()? + .parse_result_from_json::() + .wrap_err( + "Failed to parse return value of view function call for RewardFeeFraction.", + )?; + + let number_of_accounts = json_rpc_client + .call(near_jsonrpc_client::methods::query::RpcQueryRequest { + block_reference: near_primitives::types::Finality::Final.into(), + request: near_primitives::views::QueryRequest::CallFunction { + account_id: validator_id.clone(), + method_name: "get_number_of_accounts".to_string(), + args: near_primitives::types::FunctionArgs::from(vec![]), + }, + }) + .await + .wrap_err("Failed to fetch query for view method: 'get_number_of_accounts'"); + if number_of_accounts.is_err() { + continue; + }; + let delegators = number_of_accounts? + .call_result()? + .parse_result_from_json::() + .wrap_err("Failed to parse return value of view function call for u64.")?; + + let validators_table = ValidatorsTable { + validator_id: validator_id.clone(), + fee, + delegators, + stake: **stake, + }; + combine_validators.insert(validator_id.clone(), validators_table); + } + Ok(combine_validators) +} + pub fn display_account_info( viewed_at_block_hash: &CryptoHash, viewed_at_block_height: &near_primitives::types::BlockHeight, From 5f5d1e295fd5288066257dbce3612f0ad3485a4e Mon Sep 17 00:00:00 2001 From: FroVolod Date: Fri, 28 Jul 2023 18:07:17 +0300 Subject: [PATCH 08/44] fixed --- src/common.rs | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/src/common.rs b/src/common.rs index 2f244f236..26f12a493 100644 --- a/src/common.rs +++ b/src/common.rs @@ -1461,24 +1461,6 @@ fn path_directories() -> Vec { dirs } -pub fn display_validators_info(network_config: &crate::config::NetworkConfig) -> crate::CliResult { - let mut table = Table::new(); - table.set_titles(prettytable::row![Fg=>"#", "Validator Id", "Fee", "Delegators", "Stake"]); - - for (index, validator) in get_validator_list(network_config)?.into_iter().enumerate() { - table.add_row(prettytable::row![ - Fg->index + 1, - validator.validator_id, - format!("{:>6.2} %", validator.fee.numerator * 100 / validator.fee.denominator), - validator.delegators, - crate::common::NearBalance::from_yoctonear(validator.stake), - ]); - } - table.set_format(*prettytable::format::consts::FORMAT_NO_LINESEP_WITH_TITLE); - table.printstd(); - Ok(()) -} - #[derive(Debug, Clone, PartialEq, Eq)] pub struct ValidatorsTable { pub validator_id: near_primitives::types::AccountId, From 39ccfb7b901bbac5aed94f990f0c03e31a05d73f Mon Sep 17 00:00:00 2001 From: FroVolod Date: Fri, 28 Jul 2023 21:54:38 +0300 Subject: [PATCH 09/44] refactored --- src/commands/staking/delegate/view_balance.rs | 133 ++++++++++-------- 1 file changed, 75 insertions(+), 58 deletions(-) diff --git a/src/commands/staking/delegate/view_balance.rs b/src/commands/staking/delegate/view_balance.rs index c41cd57e2..74224740f 100644 --- a/src/commands/staking/delegate/view_balance.rs +++ b/src/commands/staking/delegate/view_balance.rs @@ -27,64 +27,9 @@ impl ViewBalanceContext { let validator_id = previous_context.validator_account_id.clone(); move |network_config, block_reference| { - let json_rpc_client = network_config.json_rpc_client(); - let user_staked_balance: u128 = json_rpc_client - .blocking_call_view_function( - &previous_context.validator_account_id, - "get_account_staked_balance", - serde_json::json!({ - "account_id": account_id.to_string(), - }) - .to_string() - .into_bytes(), - block_reference.clone(), - ) - .wrap_err( - "Failed to fetch query for view method: 'get_account_staked_balance'" - )? - .parse_result_from_json::() - .wrap_err( - "Failed to parse return value of view function call for String." - )? - .parse()?; - let user_unstaked_balance: u128 = json_rpc_client - .blocking_call_view_function( - &previous_context.validator_account_id, - "get_account_unstaked_balance", - serde_json::json!({ - "account_id": account_id.to_string(), - }) - .to_string() - .into_bytes(), - block_reference.clone(), - ) - .wrap_err( - "Failed to fetch query for view method: 'get_account_unstaked_balance'" - )? - .parse_result_from_json::() - .wrap_err( - "Failed to parse return value of view function call for String." - )? - .parse()?; - let user_total_balance: u128 = json_rpc_client - .blocking_call_view_function( - &previous_context.validator_account_id, - "get_account_total_balance", - serde_json::json!({ - "account_id": account_id.to_string(), - }) - .to_string() - .into_bytes(), - block_reference.clone(), - ) - .wrap_err( - "Failed to fetch query for view method: 'get_account_total_balance'" - )? - .parse_result_from_json::() - .wrap_err( - "Failed to parse return value of view function call for String." - )? - .parse()?; + let user_staked_balance: u128 = get_user_staked_balance(network_config, block_reference, &previous_context.validator_account_id, &account_id)?; + let user_unstaked_balance: u128 = get_user_unstaked_balance(network_config, block_reference, &previous_context.validator_account_id, &account_id)?; + let user_total_balance: u128 = get_user_total_balance(network_config, block_reference, &previous_context.validator_account_id, &account_id)?; eprintln!("Balance on validator <{validator_id}> for <{account_id}>:"); eprintln!(" Staked balance: {:>38}", crate::common::NearBalance::from_yoctonear(user_staked_balance).to_string()); @@ -117,3 +62,75 @@ impl ViewBalance { ) } } + +pub fn get_user_staked_balance( + network_config: &crate::config::NetworkConfig, + block_reference: &near_primitives::types::BlockReference, + validator_account_id: &near_primitives::types::AccountId, + account_id: &near_primitives::types::AccountId, +) -> color_eyre::eyre::Result { + Ok(network_config + .json_rpc_client() + .blocking_call_view_function( + validator_account_id, + "get_account_staked_balance", + serde_json::json!({ + "account_id": account_id, + }) + .to_string() + .into_bytes(), + block_reference.clone(), + ) + .wrap_err("Failed to fetch query for view method: 'get_account_staked_balance'")? + .parse_result_from_json::() + .wrap_err("Failed to parse return value of view function call for String.")? + .parse::()?) +} + +pub fn get_user_unstaked_balance( + network_config: &crate::config::NetworkConfig, + block_reference: &near_primitives::types::BlockReference, + validator_account_id: &near_primitives::types::AccountId, + account_id: &near_primitives::types::AccountId, +) -> color_eyre::eyre::Result { + Ok(network_config + .json_rpc_client() + .blocking_call_view_function( + validator_account_id, + "get_account_unstaked_balance", + serde_json::json!({ + "account_id": account_id, + }) + .to_string() + .into_bytes(), + block_reference.clone(), + ) + .wrap_err("Failed to fetch query for view method: 'get_account_unstaked_balance'")? + .parse_result_from_json::() + .wrap_err("Failed to parse return value of view function call for String.")? + .parse::()?) +} + +pub fn get_user_total_balance( + network_config: &crate::config::NetworkConfig, + block_reference: &near_primitives::types::BlockReference, + validator_account_id: &near_primitives::types::AccountId, + account_id: &near_primitives::types::AccountId, +) -> color_eyre::eyre::Result { + Ok(network_config + .json_rpc_client() + .blocking_call_view_function( + validator_account_id, + "get_account_total_balance", + serde_json::json!({ + "account_id": account_id, + }) + .to_string() + .into_bytes(), + block_reference.clone(), + ) + .wrap_err("Failed to fetch query for view method: 'get_account_total_balance'")? + .parse_result_from_json::() + .wrap_err("Failed to parse return value of view function call for String.")? + .parse::()?) +} From bca4e17fe7906682cf9de114d0002267a14b0673 Mon Sep 17 00:00:00 2001 From: FroVolod Date: Fri, 28 Jul 2023 22:02:53 +0300 Subject: [PATCH 10/44] added delegated stake for view_account_summary --- .../account/view_account_summary/mod.rs | 21 +++++++++++++++++++ src/commands/staking/delegate/mod.rs | 2 +- src/commands/staking/mod.rs | 2 +- src/common.rs | 12 +++++++++++ 4 files changed, 35 insertions(+), 2 deletions(-) diff --git a/src/commands/account/view_account_summary/mod.rs b/src/commands/account/view_account_summary/mod.rs index c6b8b054e..7331f6064 100644 --- a/src/commands/account/view_account_summary/mod.rs +++ b/src/commands/account/view_account_summary/mod.rs @@ -3,6 +3,8 @@ use color_eyre::eyre::Context; use crate::common::JsonRpcClientExt; use crate::common::RpcQueryResponseExt; +use crate::commands::staking::delegate::view_balance; + #[derive(Debug, Clone, interactive_clap::InteractiveClap)] #[interactive_clap(input_context = crate::GlobalContext)] #[interactive_clap(output_context = ViewAccountSummaryContext)] @@ -52,10 +54,29 @@ impl ViewAccountSummaryContext { })? .access_key_list_view()?; + let validator_list = crate::common::get_validator_list(network_config)?; + let delegated_stake: std::collections::HashMap = validator_list + .into_iter() + .filter_map(|validator_table| { + let user_total_balance = match view_balance::get_user_staked_balance(network_config, block_reference, &validator_table.validator_id, &account_id) { + Ok(balance) => { + if balance == 0 { + return None; + } else { + crate::common::NearBalance::from_yoctonear(balance) + } + }, + Err(_) => return None, + }; + Some((validator_table.validator_id, user_total_balance)) + }) + .collect(); + crate::common::display_account_info( &rpc_query_response.block_hash, &rpc_query_response.block_height, &account_id, + delegated_stake, &account_view, &access_key_list.keys, ); diff --git a/src/commands/staking/delegate/mod.rs b/src/commands/staking/delegate/mod.rs index 4443070e5..eac158fbf 100644 --- a/src/commands/staking/delegate/mod.rs +++ b/src/commands/staking/delegate/mod.rs @@ -2,7 +2,7 @@ use strum::{EnumDiscriminants, EnumIter, EnumMessage}; mod unstake; mod unstake_all; -mod view_balance; +pub mod view_balance; mod withdraw; mod withdraw_all; diff --git a/src/commands/staking/mod.rs b/src/commands/staking/mod.rs index 855dc85ed..7d89d9257 100644 --- a/src/commands/staking/mod.rs +++ b/src/commands/staking/mod.rs @@ -1,6 +1,6 @@ use strum::{EnumDiscriminants, EnumIter, EnumMessage}; -mod delegate; +pub mod delegate; mod validator_list; #[derive(Debug, Clone, interactive_clap::InteractiveClap)] diff --git a/src/common.rs b/src/common.rs index 26f12a493..47cb96451 100644 --- a/src/common.rs +++ b/src/common.rs @@ -1634,6 +1634,10 @@ pub fn display_account_info( viewed_at_block_hash: &CryptoHash, viewed_at_block_height: &near_primitives::types::BlockHeight, account_id: &near_primitives::types::AccountId, + delegated_stake: std::collections::HashMap< + near_primitives::types::AccountId, + crate::common::NearBalance, + >, account_view: &near_primitives::views::AccountView, access_keys: &[near_primitives::views::AccessKeyInfoView], ) { @@ -1652,6 +1656,14 @@ pub fn display_account_info( Fg->"Validator stake", Fy->NearBalance::from_yoctonear(account_view.locked) ]); + + for (validator_id, stake) in delegated_stake.iter() { + table.add_row(prettytable::row![ + Fg->format!("Delegated stake for <{validator_id}>"), + Fy->stake + ]); + } + table.add_row(prettytable::row![ Fg->"Storage used by the account", Fy->bytesize::ByteSize(account_view.storage_usage), From 3f6b8ef0cc88544b9496db2e086832dcf5ff1248 Mon Sep 17 00:00:00 2001 From: FroVolod Date: Sat, 29 Jul 2023 19:46:33 +0300 Subject: [PATCH 11/44] refactored get_validator_list() --- src/common.rs | 77 +++++++++++++++++++++++++++------------------------ 1 file changed, 41 insertions(+), 36 deletions(-) diff --git a/src/common.rs b/src/common.rs index 47cb96451..dbac30c9a 100644 --- a/src/common.rs +++ b/src/common.rs @@ -1480,6 +1480,45 @@ pub fn get_validator_list( ) -> color_eyre::eyre::Result> { let json_rpc_client = network_config.json_rpc_client(); + let validators_stake = get_validators_stake(&json_rpc_client)?; + + let runtime = tokio::runtime::Builder::new_multi_thread() + .enable_all() + .build()?; + let chunk_size = 15; + let concurrency = 10; + + let validators_table: std::collections::HashMap< + near_primitives::types::AccountId, + ValidatorsTable, + > = runtime + .block_on( + futures::stream::iter( + validators_stake + .iter() + .collect::>() + .chunks(chunk_size), + ) + .map(|validators| async { get_validators_table(&json_rpc_client, validators).await }) + .buffer_unordered(concurrency) + .collect::>>(), + ) + .into_iter() + .try_fold(std::collections::HashMap::new(), |mut acc, x| { + acc.extend(x?); + Ok::<_, color_eyre::eyre::Error>(acc) + })?; + + let mut validator_list: Vec = validators_table.into_values().collect(); + validator_list.sort_by(|a, b| b.stake.cmp(&a.stake)); + Ok(validator_list) +} + +pub fn get_validators_stake( + json_rpc_client: &near_jsonrpc_client::JsonRpcClient, +) -> color_eyre::eyre::Result< + std::collections::HashMap, +> { let epoch_validator_info = json_rpc_client .blocking_call( &near_jsonrpc_client::methods::validators::RpcValidatorRequest { @@ -1530,44 +1569,10 @@ pub fn get_validator_list( current_validators_stake.extend(next_validators_stake); current_validators_stake.extend(current_proposals_stake); - - let runtime = tokio::runtime::Builder::new_multi_thread() - .enable_all() - .build()?; - let chunk_size = 15; - let concurrency = 10; - - let combine_validators: std::collections::HashMap< - near_primitives::types::AccountId, - ValidatorsTable, - > = runtime - .block_on( - futures::stream::iter( - current_validators_stake - .iter() - .collect::>() - .chunks(chunk_size), - ) - .map( - |validators: &[(&near_primitives::types::AccountId, &u128)]| async { - get_combine_validators(&json_rpc_client, validators).await - }, - ) - .buffer_unordered(concurrency) - .collect::>>(), - ) - .into_iter() - .try_fold(std::collections::HashMap::new(), |mut acc, x| { - acc.extend(x?); - Ok::<_, color_eyre::eyre::Error>(acc) - })?; - - let mut validator_list: Vec = combine_validators.into_values().collect(); - validator_list.sort_by(|a, b| b.stake.cmp(&a.stake)); - Ok(validator_list) + Ok(current_validators_stake) } -async fn get_combine_validators( +async fn get_validators_table( json_rpc_client: &near_jsonrpc_client::JsonRpcClient, validators: &[(&near_primitives::types::AccountId, &u128)], ) -> color_eyre::Result> From e8fd3416a559972dc7f99858a6741d12c013b488 Mon Sep 17 00:00:00 2001 From: FroVolod Date: Sat, 29 Jul 2023 19:55:31 +0300 Subject: [PATCH 12/44] refactored delegated_stake --- .../account/view_account_summary/mod.rs | 119 ++++++++++++++---- 1 file changed, 95 insertions(+), 24 deletions(-) diff --git a/src/commands/account/view_account_summary/mod.rs b/src/commands/account/view_account_summary/mod.rs index 7331f6064..06ee4c885 100644 --- a/src/commands/account/view_account_summary/mod.rs +++ b/src/commands/account/view_account_summary/mod.rs @@ -1,9 +1,7 @@ use color_eyre::eyre::Context; +use futures::StreamExt; -use crate::common::JsonRpcClientExt; -use crate::common::RpcQueryResponseExt; - -use crate::commands::staking::delegate::view_balance; +use crate::common::{CallResultExt, JsonRpcClientExt, RpcQueryResponseExt}; #[derive(Debug, Clone, interactive_clap::InteractiveClap)] #[interactive_clap(input_context = crate::GlobalContext)] @@ -29,8 +27,9 @@ impl ViewAccountSummaryContext { let on_after_getting_block_reference_callback: crate::network_view_at_block::OnAfterGettingBlockReferenceCallback = std::sync::Arc::new({ move |network_config, block_reference| { - let rpc_query_response = network_config - .json_rpc_client() + let json_rpc_client = network_config.json_rpc_client(); + + let rpc_query_response = json_rpc_client .blocking_call_view_account(&account_id.clone(), block_reference.clone()) .wrap_err_with(|| { format!( @@ -40,8 +39,7 @@ impl ViewAccountSummaryContext { })?; let account_view = rpc_query_response.account_view()?; - let access_key_list = network_config - .json_rpc_client() + let access_key_list = json_rpc_client .blocking_call_view_access_key_list( &account_id, block_reference.clone(), @@ -54,23 +52,32 @@ impl ViewAccountSummaryContext { })? .access_key_list_view()?; - let validator_list = crate::common::get_validator_list(network_config)?; - let delegated_stake: std::collections::HashMap = validator_list - .into_iter() - .filter_map(|validator_table| { - let user_total_balance = match view_balance::get_user_staked_balance(network_config, block_reference, &validator_table.validator_id, &account_id) { - Ok(balance) => { - if balance == 0 { - return None; - } else { - crate::common::NearBalance::from_yoctonear(balance) - } - }, - Err(_) => return None, - }; - Some((validator_table.validator_id, user_total_balance)) + let validators_stake = crate::common::get_validators_stake(&json_rpc_client)?; + + let runtime = tokio::runtime::Builder::new_multi_thread() + .enable_all() + .build()?; + let chunk_size = 15; + let concurrency = 10; + + let delegated_stake: std::collections::HashMap = runtime + .block_on( + futures::stream::iter(validators_stake + .iter() + .collect::>() + .chunks(chunk_size), + ) + .map(|validators| async { + get_delegated_stake(&json_rpc_client, block_reference, &account_id, validators).await }) - .collect(); + .buffer_unordered(concurrency) + .collect::>>(), + ) + .into_iter() + .try_fold(std::collections::HashMap::new(), |mut acc, x| { + acc.extend(x?); + Ok::<_, color_eyre::eyre::Error>(acc) + })?; crate::common::display_account_info( &rpc_query_response.block_hash, @@ -106,3 +113,67 @@ impl ViewAccountSummary { ) } } + +async fn get_delegated_stake( + json_rpc_client: &near_jsonrpc_client::JsonRpcClient, + block_reference: &near_primitives::types::BlockReference, + account_id: &near_primitives::types::AccountId, + validators: &[(&near_primitives::types::AccountId, &u128)], +) -> color_eyre::Result< + std::collections::HashMap, +> { + let mut validators_stake: std::collections::HashMap< + near_primitives::types::AccountId, + crate::common::NearBalance, + > = std::collections::HashMap::new(); + for (validator_id, _) in validators { + let validator_id = *validator_id; + let user_staked_balance = + get_user_staked_balance(json_rpc_client, block_reference, validator_id, account_id) + .await + .ok(); + let balance = if let Some(balance) = user_staked_balance { + if balance == 0 { + continue; + } else { + balance + } + } else { + continue; + }; + validators_stake.insert( + validator_id.clone(), + crate::common::NearBalance::from_yoctonear(balance), + ); + } + Ok(validators_stake) +} + +async fn get_user_staked_balance( + json_rpc_client: &near_jsonrpc_client::JsonRpcClient, + block_reference: &near_primitives::types::BlockReference, + validator_account_id: &near_primitives::types::AccountId, + account_id: &near_primitives::types::AccountId, +) -> color_eyre::eyre::Result { + Ok(json_rpc_client + .call(near_jsonrpc_client::methods::query::RpcQueryRequest { + block_reference: block_reference.clone(), + request: near_primitives::views::QueryRequest::CallFunction { + account_id: validator_account_id.clone(), + method_name: "get_account_staked_balance".to_string(), + args: near_primitives::types::FunctionArgs::from( + serde_json::json!({ + "account_id": account_id, + }) + .to_string() + .into_bytes(), + ), + }, + }) + .await + .wrap_err("Failed to fetch query for view method: 'get_account_staked_balance'")? + .call_result()? + .parse_result_from_json::() + .wrap_err("Failed to parse return value of view function call for String.")? + .parse::()?) +} From 9ddcb47784f99b65b503f8166f65bdab4c63ee89 Mon Sep 17 00:00:00 2001 From: FroVolod Date: Sat, 29 Jul 2023 20:37:21 +0300 Subject: [PATCH 13/44] fixed --- src/common.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/common.rs b/src/common.rs index dbac30c9a..9e4f713de 100644 --- a/src/common.rs +++ b/src/common.rs @@ -101,7 +101,7 @@ impl std::fmt::Display for NearBalance { f, "{}.{} NEAR", self.yoctonear_amount / ONE_NEAR, - format!("{:0>24}", (self.yoctonear_amount % ONE_NEAR)) //.trim_end_matches('0') XXX + format!("{:0>24}", (self.yoctonear_amount % ONE_NEAR)).trim_end_matches('0') ) } } From 13f1b7bd197be8909b097350bdfaec6a4a53e32f Mon Sep 17 00:00:00 2001 From: FroVolod Date: Wed, 2 Aug 2023 12:10:41 +0300 Subject: [PATCH 14/44] added Stake, StakeAll --- src/commands/staking/delegate/mod.rs | 9 ++- src/commands/staking/delegate/stake.rs | 92 ++++++++++++++++++++++ src/commands/staking/delegate/stake_all.rs | 84 ++++++++++++++++++++ 3 files changed, 184 insertions(+), 1 deletion(-) create mode 100644 src/commands/staking/delegate/stake.rs create mode 100644 src/commands/staking/delegate/stake_all.rs diff --git a/src/commands/staking/delegate/mod.rs b/src/commands/staking/delegate/mod.rs index eac158fbf..905c1cd4b 100644 --- a/src/commands/staking/delegate/mod.rs +++ b/src/commands/staking/delegate/mod.rs @@ -1,5 +1,7 @@ use strum::{EnumDiscriminants, EnumIter, EnumMessage}; +mod stake; +mod stake_all; mod unstake; mod unstake_all; pub mod view_balance; @@ -61,7 +63,12 @@ pub enum DelegateStakingCommand { message = "stake - Staking the given amount from the inner account of the predecessor" ))] /// Staking the given amount from the inner account of the predecessor - Stake, + Stake(self::stake::Stake), + #[strum_discriminants(strum( + message = "stake-all - Staking all available unstaked balance from the inner account of the predecessor" + ))] + /// Staking all available unstaked balance from the inner account of the predecessor + StakeAll(self::stake_all::StakeAll), #[strum_discriminants(strum( message = "unstake - Unstaking the given amount from the inner account of the predecessor" ))] diff --git a/src/commands/staking/delegate/stake.rs b/src/commands/staking/delegate/stake.rs new file mode 100644 index 000000000..be40529ae --- /dev/null +++ b/src/commands/staking/delegate/stake.rs @@ -0,0 +1,92 @@ +use std::str::FromStr; + +#[derive(Debug, Clone, interactive_clap::InteractiveClap)] +#[interactive_clap(input_context = super::DelegateStakeContext)] +#[interactive_clap(output_context = StakeContext)] +pub struct Stake { + /// Enter the amount to stake from the inner account of the predecessor (example: 10NEAR or 0.5near or 10000yoctonear): + amount: crate::common::NearBalance, + #[interactive_clap(skip_default_input_arg)] + /// What is the signer account ID? + signer_account_id: crate::types::account_id::AccountId, + #[interactive_clap(named_arg)] + /// Select network + network_config: crate::network_for_transaction::NetworkForTransactionArgs, +} + +#[derive(Clone)] +pub struct StakeContext(crate::commands::ActionContext); + +impl StakeContext { + pub fn from_previous_context( + previous_context: super::DelegateStakeContext, + scope: &::InteractiveClapContextScope, + ) -> color_eyre::eyre::Result { + let signer = scope.signer_account_id.clone(); + let signer_id: near_primitives::types::AccountId = scope.signer_account_id.clone().into(); + let validator_account_id = previous_context.validator_account_id.clone(); + let amount = scope.amount.clone(); + + let on_after_getting_network_callback: crate::commands::OnAfterGettingNetworkCallback = + std::sync::Arc::new(move |_network_config| { + Ok(crate::commands::PrepopulatedTransaction { + signer_id: signer_id.clone(), + receiver_id: previous_context.validator_account_id.clone(), + actions: vec![near_primitives::transaction::Action::FunctionCall( + near_primitives::transaction::FunctionCallAction { + method_name: "stake".to_string(), + args: serde_json::json!({ + "amount": amount.clone().to_yoctonear().to_string() + }) + .to_string() + .into_bytes(), + gas: crate::common::NearGas::from_str("300 TeraGas") + .unwrap() + .inner, + deposit: crate::common::NearBalance::from_yoctonear(0).to_yoctonear(), + }, + )], + }) + }); + + let amount = scope.amount.clone(); + let on_after_sending_transaction_callback: crate::transaction_signature_options::OnAfterSendingTransactionCallback = std::sync::Arc::new( + move |outcome_view, _network_config| { + if let near_primitives::views::FinalExecutionStatus::SuccessValue(_) = outcome_view.status { + eprintln!( + "<{signer}> has successfully stake {amount} on <{validator_account_id}>.", + ); + } + Ok(()) + }, + ); + Ok(Self(crate::commands::ActionContext { + global_context: previous_context.global_context, + on_after_getting_network_callback, + on_before_signing_callback: std::sync::Arc::new( + |_prepolulated_unsinged_transaction, _network_config| Ok(()), + ), + on_before_sending_transaction_callback: std::sync::Arc::new( + |_signed_transaction, _network_config, _message| Ok(()), + ), + on_after_sending_transaction_callback, + })) + } +} + +impl From for crate::commands::ActionContext { + fn from(item: StakeContext) -> Self { + item.0 + } +} + +impl Stake { + pub fn input_signer_account_id( + context: &super::DelegateStakeContext, + ) -> color_eyre::eyre::Result> { + crate::common::input_signer_account_id_from_used_account_list( + &context.global_context.config.credentials_home_dir, + "What is the signer account ID?", + ) + } +} diff --git a/src/commands/staking/delegate/stake_all.rs b/src/commands/staking/delegate/stake_all.rs new file mode 100644 index 000000000..f4575cc0e --- /dev/null +++ b/src/commands/staking/delegate/stake_all.rs @@ -0,0 +1,84 @@ +use std::str::FromStr; + +#[derive(Debug, Clone, interactive_clap::InteractiveClap)] +#[interactive_clap(input_context = super::DelegateStakeContext)] +#[interactive_clap(output_context = StakeAllContext)] +pub struct StakeAll { + #[interactive_clap(skip_default_input_arg)] + /// What is the signer account ID? + signer_account_id: crate::types::account_id::AccountId, + #[interactive_clap(named_arg)] + /// Select network + network_config: crate::network_for_transaction::NetworkForTransactionArgs, +} + +#[derive(Clone)] +pub struct StakeAllContext(crate::commands::ActionContext); + +impl StakeAllContext { + pub fn from_previous_context( + previous_context: super::DelegateStakeContext, + scope: &::InteractiveClapContextScope, + ) -> color_eyre::eyre::Result { + let signer = scope.signer_account_id.clone(); + let signer_id: near_primitives::types::AccountId = scope.signer_account_id.clone().into(); + let validator_account_id = previous_context.validator_account_id.clone(); + + let on_after_getting_network_callback: crate::commands::OnAfterGettingNetworkCallback = + std::sync::Arc::new(move |_network_config| { + Ok(crate::commands::PrepopulatedTransaction { + signer_id: signer_id.clone(), + receiver_id: previous_context.validator_account_id.clone(), + actions: vec![near_primitives::transaction::Action::FunctionCall( + near_primitives::transaction::FunctionCallAction { + method_name: "stake_all".to_string(), + args: vec![], + gas: crate::common::NearGas::from_str("300 TeraGas") + .unwrap() + .inner, + deposit: crate::common::NearBalance::from_yoctonear(0).to_yoctonear(), + }, + )], + }) + }); + + let on_after_sending_transaction_callback: crate::transaction_signature_options::OnAfterSendingTransactionCallback = std::sync::Arc::new( + move |outcome_view, _network_config| { + if let near_primitives::views::FinalExecutionStatus::SuccessValue(_) = outcome_view.status { + eprintln!( + "<{signer}> has successfully stake the entire amount on <{validator_account_id}>.", //XXX + ); + } + Ok(()) + }, + ); + Ok(Self(crate::commands::ActionContext { + global_context: previous_context.global_context, + on_after_getting_network_callback, + on_before_signing_callback: std::sync::Arc::new( + |_prepolulated_unsinged_transaction, _network_config| Ok(()), + ), + on_before_sending_transaction_callback: std::sync::Arc::new( + |_signed_transaction, _network_config, _message| Ok(()), + ), + on_after_sending_transaction_callback, + })) + } +} + +impl From for crate::commands::ActionContext { + fn from(item: StakeAllContext) -> Self { + item.0 + } +} + +impl StakeAll { + pub fn input_signer_account_id( + context: &super::DelegateStakeContext, + ) -> color_eyre::eyre::Result> { + crate::common::input_signer_account_id_from_used_account_list( + &context.global_context.config.credentials_home_dir, + "What is the signer account ID?", + ) + } +} From d94aade11227f3cb19141b49e909c8e858ff9ff3 Mon Sep 17 00:00:00 2001 From: FroVolod Date: Wed, 2 Aug 2023 19:57:03 +0300 Subject: [PATCH 15/44] added Deposit, DepositAndStake --- src/commands/staking/delegate/deposit.rs | 88 +++++++++++++++++++ .../staking/delegate/deposit_and_stake.rs | 88 +++++++++++++++++++ src/commands/staking/delegate/mod.rs | 26 ++++-- 3 files changed, 195 insertions(+), 7 deletions(-) create mode 100644 src/commands/staking/delegate/deposit.rs create mode 100644 src/commands/staking/delegate/deposit_and_stake.rs diff --git a/src/commands/staking/delegate/deposit.rs b/src/commands/staking/delegate/deposit.rs new file mode 100644 index 000000000..903d7a58f --- /dev/null +++ b/src/commands/staking/delegate/deposit.rs @@ -0,0 +1,88 @@ +use std::str::FromStr; + +#[derive(Debug, Clone, interactive_clap::InteractiveClap)] +#[interactive_clap(input_context = super::DelegateStakeContext)] +#[interactive_clap(output_context = DepositContext)] +pub struct Deposit { + /// Enter the attached amount to be deposited into the predecessor's internal account (example: 10NEAR or 0.5near or 10000yoctonear): + amount: crate::common::NearBalance, + #[interactive_clap(skip_default_input_arg)] + /// What is the signer account ID? + signer_account_id: crate::types::account_id::AccountId, + #[interactive_clap(named_arg)] + /// Select network + network_config: crate::network_for_transaction::NetworkForTransactionArgs, +} + +#[derive(Clone)] +pub struct DepositContext(crate::commands::ActionContext); + +impl DepositContext { + pub fn from_previous_context( + previous_context: super::DelegateStakeContext, + scope: &::InteractiveClapContextScope, + ) -> color_eyre::eyre::Result { + let signer = scope.signer_account_id.clone(); + let signer_id: near_primitives::types::AccountId = scope.signer_account_id.clone().into(); + let validator_account_id = previous_context.validator_account_id.clone(); + let amount = scope.amount.clone(); + + let on_after_getting_network_callback: crate::commands::OnAfterGettingNetworkCallback = + std::sync::Arc::new(move |_network_config| { + Ok(crate::commands::PrepopulatedTransaction { + signer_id: signer_id.clone(), + receiver_id: previous_context.validator_account_id.clone(), + actions: vec![near_primitives::transaction::Action::FunctionCall( + near_primitives::transaction::FunctionCallAction { + method_name: "deposit".to_string(), + args: serde_json::json!({}).to_string().into_bytes(), + gas: crate::common::NearGas::from_str("300 TeraGas") + .unwrap() + .inner, + deposit: amount.to_yoctonear(), + }, + )], + }) + }); + + let amount = scope.amount.clone(); + let on_after_sending_transaction_callback: crate::transaction_signature_options::OnAfterSendingTransactionCallback = std::sync::Arc::new( + move |outcome_view, _network_config| { + if let near_primitives::views::FinalExecutionStatus::SuccessValue(_) = outcome_view.status { + eprintln!( + "<{signer}> has successfully deposited {amount} on <{validator_account_id}>.", + ); + } + Ok(()) + }, + ); + Ok(Self(crate::commands::ActionContext { + global_context: previous_context.global_context, + on_after_getting_network_callback, + on_before_signing_callback: std::sync::Arc::new( + |_prepolulated_unsinged_transaction, _network_config| Ok(()), + ), + on_before_sending_transaction_callback: std::sync::Arc::new( + |_signed_transaction, _network_config, _message| Ok(()), + ), + on_after_sending_transaction_callback, + })) + } +} + +impl From for crate::commands::ActionContext { + fn from(item: DepositContext) -> Self { + item.0 + } +} + +impl Deposit { + pub fn input_signer_account_id( + context: &super::DelegateStakeContext, + ) -> color_eyre::eyre::Result> { + crate::common::input_signer_account_id_from_used_account_list( + &context.global_context.config.credentials_home_dir, + "What is the signer account ID?", + ) + } +} diff --git a/src/commands/staking/delegate/deposit_and_stake.rs b/src/commands/staking/delegate/deposit_and_stake.rs new file mode 100644 index 000000000..2384e362a --- /dev/null +++ b/src/commands/staking/delegate/deposit_and_stake.rs @@ -0,0 +1,88 @@ +use std::str::FromStr; + +#[derive(Debug, Clone, interactive_clap::InteractiveClap)] +#[interactive_clap(input_context = super::DelegateStakeContext)] +#[interactive_clap(output_context = DepositAndStakeContext)] +pub struct DepositAndStake { + /// Enter the attached amount to be deposited and then staked into the predecessor's internal account (example: 10NEAR or 0.5near or 10000yoctonear): + amount: crate::common::NearBalance, + #[interactive_clap(skip_default_input_arg)] + /// What is the signer account ID? + signer_account_id: crate::types::account_id::AccountId, + #[interactive_clap(named_arg)] + /// Select network + network_config: crate::network_for_transaction::NetworkForTransactionArgs, +} + +#[derive(Clone)] +pub struct DepositAndStakeContext(crate::commands::ActionContext); + +impl DepositAndStakeContext { + pub fn from_previous_context( + previous_context: super::DelegateStakeContext, + scope: &::InteractiveClapContextScope, + ) -> color_eyre::eyre::Result { + let signer = scope.signer_account_id.clone(); + let signer_id: near_primitives::types::AccountId = scope.signer_account_id.clone().into(); + let validator_account_id = previous_context.validator_account_id.clone(); + let amount = scope.amount.clone(); + + let on_after_getting_network_callback: crate::commands::OnAfterGettingNetworkCallback = + std::sync::Arc::new(move |_network_config| { + Ok(crate::commands::PrepopulatedTransaction { + signer_id: signer_id.clone(), + receiver_id: previous_context.validator_account_id.clone(), + actions: vec![near_primitives::transaction::Action::FunctionCall( + near_primitives::transaction::FunctionCallAction { + method_name: "deposit_and_stake".to_string(), + args: serde_json::json!({}).to_string().into_bytes(), + gas: crate::common::NearGas::from_str("300 TeraGas") + .unwrap() + .inner, + deposit: amount.to_yoctonear(), + }, + )], + }) + }); + + let amount = scope.amount.clone(); + let on_after_sending_transaction_callback: crate::transaction_signature_options::OnAfterSendingTransactionCallback = std::sync::Arc::new( + move |outcome_view, _network_config| { + if let near_primitives::views::FinalExecutionStatus::SuccessValue(_) = outcome_view.status { + eprintln!( + "<{signer}> has successfully deposited and staked {amount} on <{validator_account_id}>.", + ); + } + Ok(()) + }, + ); + Ok(Self(crate::commands::ActionContext { + global_context: previous_context.global_context, + on_after_getting_network_callback, + on_before_signing_callback: std::sync::Arc::new( + |_prepolulated_unsinged_transaction, _network_config| Ok(()), + ), + on_before_sending_transaction_callback: std::sync::Arc::new( + |_signed_transaction, _network_config, _message| Ok(()), + ), + on_after_sending_transaction_callback, + })) + } +} + +impl From for crate::commands::ActionContext { + fn from(item: DepositAndStakeContext) -> Self { + item.0 + } +} + +impl DepositAndStake { + pub fn input_signer_account_id( + context: &super::DelegateStakeContext, + ) -> color_eyre::eyre::Result> { + crate::common::input_signer_account_id_from_used_account_list( + &context.global_context.config.credentials_home_dir, + "What is the signer account ID?", + ) + } +} diff --git a/src/commands/staking/delegate/mod.rs b/src/commands/staking/delegate/mod.rs index 905c1cd4b..e926b619c 100644 --- a/src/commands/staking/delegate/mod.rs +++ b/src/commands/staking/delegate/mod.rs @@ -1,5 +1,7 @@ use strum::{EnumDiscriminants, EnumIter, EnumMessage}; +mod deposit; +mod deposit_and_stake; mod stake; mod stake_all; mod unstake; @@ -55,37 +57,47 @@ impl DelegateStake { /// Select actions with delegated staking: pub enum DelegateStakingCommand { #[strum_discriminants(strum( - message = "view-balance - View the total balance for a given account" + message = "view-balance - View the total balance for a given account" ))] /// View the total balance for a given account ViewBalance(self::view_balance::ViewBalance), #[strum_discriminants(strum( - message = "stake - Staking the given amount from the inner account of the predecessor" + message = "deposit - Deposits the attached amount into the inner account of the predecessor" + ))] + /// Deposits the attached amount into the inner account of the predecessor + Deposit(self::deposit::Deposit), + #[strum_discriminants(strum( + message = "deposit-and-stake - Deposits the attached amount into the inner account of the predecessor and stakes it" + ))] + /// Deposits the attached amount into the inner account of the predecessor and stakes it + DepositAndStake(self::deposit_and_stake::DepositAndStake), + #[strum_discriminants(strum( + message = "stake - Staking the given amount from the inner account of the predecessor" ))] /// Staking the given amount from the inner account of the predecessor Stake(self::stake::Stake), #[strum_discriminants(strum( - message = "stake-all - Staking all available unstaked balance from the inner account of the predecessor" + message = "stake-all - Staking all available unstaked balance from the inner account of the predecessor" ))] /// Staking all available unstaked balance from the inner account of the predecessor StakeAll(self::stake_all::StakeAll), #[strum_discriminants(strum( - message = "unstake - Unstaking the given amount from the inner account of the predecessor" + message = "unstake - Unstaking the given amount from the inner account of the predecessor" ))] /// Unstaking the given amount from the inner account of the predecessor Unstake(self::unstake::Unstake), #[strum_discriminants(strum( - message = "unstake-all - Unstaking all staked balance from the inner account of the predecessor" + message = "unstake-all - Unstaking all staked balance from the inner account of the predecessor" ))] /// Unstaking all staked balance from the inner account of the predecessor UnstakeAll(self::unstake_all::UnstakeAll), #[strum_discriminants(strum( - message = "withdraw - Withdrawing the non staked balance for given account" + message = "withdraw - Withdrawing the non staked balance for given account" ))] /// Withdrawing the non staked balance for given account Withdraw(self::withdraw::Withdraw), #[strum_discriminants(strum( - message = "withdraw-all - Withdrawing the entire unstaked balance from the predecessor account" + message = "withdraw-all - Withdrawing the entire unstaked balance from the predecessor account" ))] /// Withdrawing the entire unstaked balance from the predecessor account WithdrawAll(self::withdraw_all::WithdrawAll), From 9ad54aaad9d043ba958a302378e7ecaff32994a2 Mon Sep 17 00:00:00 2001 From: FroVolod Date: Wed, 2 Aug 2023 20:01:34 +0300 Subject: [PATCH 16/44] fixed --- src/commands/staking/delegate/stake_all.rs | 2 +- src/commands/staking/delegate/unstake_all.rs | 2 +- src/commands/staking/delegate/withdraw_all.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/commands/staking/delegate/stake_all.rs b/src/commands/staking/delegate/stake_all.rs index f4575cc0e..4e7cedbd6 100644 --- a/src/commands/staking/delegate/stake_all.rs +++ b/src/commands/staking/delegate/stake_all.rs @@ -32,7 +32,7 @@ impl StakeAllContext { actions: vec![near_primitives::transaction::Action::FunctionCall( near_primitives::transaction::FunctionCallAction { method_name: "stake_all".to_string(), - args: vec![], + args: serde_json::json!({}).to_string().into_bytes(), gas: crate::common::NearGas::from_str("300 TeraGas") .unwrap() .inner, diff --git a/src/commands/staking/delegate/unstake_all.rs b/src/commands/staking/delegate/unstake_all.rs index b8057bac6..66caec03f 100644 --- a/src/commands/staking/delegate/unstake_all.rs +++ b/src/commands/staking/delegate/unstake_all.rs @@ -32,7 +32,7 @@ impl UnstakeAllContext { actions: vec![near_primitives::transaction::Action::FunctionCall( near_primitives::transaction::FunctionCallAction { method_name: "unstake_all".to_string(), - args: vec![], + args: serde_json::json!({}).to_string().into_bytes(), gas: crate::common::NearGas::from_str("300 TeraGas") .unwrap() .inner, diff --git a/src/commands/staking/delegate/withdraw_all.rs b/src/commands/staking/delegate/withdraw_all.rs index ad5a736ac..76e828202 100644 --- a/src/commands/staking/delegate/withdraw_all.rs +++ b/src/commands/staking/delegate/withdraw_all.rs @@ -63,7 +63,7 @@ impl WithdrawAllContext { actions: vec![near_primitives::transaction::Action::FunctionCall( near_primitives::transaction::FunctionCallAction { method_name: "withdraw_all".to_string(), - args: vec![], + args: serde_json::json!({}).to_string().into_bytes(), gas: crate::common::NearGas::from_str("300 TeraGas") .unwrap() .inner, From b2646c8d91a9e07807e1357e333bf8aa0f3fdd70 Mon Sep 17 00:00:00 2001 From: FroVolod Date: Sun, 3 Sep 2023 11:06:44 +0300 Subject: [PATCH 17/44] updated to "order networks selection ..." #225 --- src/commands/account/view_account_summary/mod.rs | 10 ++++++---- src/commands/staking/delegate/deposit.rs | 8 ++++---- src/commands/staking/delegate/deposit_and_stake.rs | 8 ++++---- src/commands/staking/delegate/stake.rs | 8 ++++---- src/commands/staking/delegate/stake_all.rs | 8 ++++---- src/commands/staking/delegate/unstake.rs | 8 ++++---- src/commands/staking/delegate/unstake_all.rs | 8 ++++---- src/commands/staking/delegate/view_balance.rs | 7 +++++-- src/commands/staking/delegate/withdraw.rs | 8 ++++---- src/commands/staking/delegate/withdraw_all.rs | 8 ++++---- src/commands/staking/validator_list/mod.rs | 1 + 11 files changed, 44 insertions(+), 38 deletions(-) diff --git a/src/commands/account/view_account_summary/mod.rs b/src/commands/account/view_account_summary/mod.rs index e4a2b0e3b..6a6934059 100644 --- a/src/commands/account/view_account_summary/mod.rs +++ b/src/commands/account/view_account_summary/mod.rs @@ -27,9 +27,10 @@ impl ViewAccountSummaryContext { let account_id: near_primitives::types::AccountId = scope.account_id.clone().into(); move |network_config, block_reference| { - let rpc_query_response = network_config - .json_rpc_client() - .blocking_call_view_account(&account_id, block_reference.clone()) + let json_rpc_client = network_config.json_rpc_client(); + + let rpc_query_response = json_rpc_client + .blocking_call_view_account(&account_id.clone(), block_reference.clone()) .wrap_err_with(|| { format!( "Failed to fetch query ViewAccount for <{}>", @@ -38,7 +39,8 @@ impl ViewAccountSummaryContext { })?; let account_view = rpc_query_response.account_view()?; - let access_key_list = json_rpc_client + let access_key_list = network_config + .json_rpc_client() .blocking_call_view_access_key_list( &account_id, block_reference.clone(), diff --git a/src/commands/staking/delegate/deposit.rs b/src/commands/staking/delegate/deposit.rs index 903d7a58f..d77e15dab 100644 --- a/src/commands/staking/delegate/deposit.rs +++ b/src/commands/staking/delegate/deposit.rs @@ -25,6 +25,7 @@ impl DepositContext { let signer = scope.signer_account_id.clone(); let signer_id: near_primitives::types::AccountId = scope.signer_account_id.clone().into(); let validator_account_id = previous_context.validator_account_id.clone(); + let interacting_with_account_ids = vec![validator_account_id.clone()]; let amount = scope.amount.clone(); let on_after_getting_network_callback: crate::commands::OnAfterGettingNetworkCallback = @@ -49,15 +50,14 @@ impl DepositContext { let on_after_sending_transaction_callback: crate::transaction_signature_options::OnAfterSendingTransactionCallback = std::sync::Arc::new( move |outcome_view, _network_config| { if let near_primitives::views::FinalExecutionStatus::SuccessValue(_) = outcome_view.status { - eprintln!( - "<{signer}> has successfully deposited {amount} on <{validator_account_id}>.", - ); - } + eprintln!("<{signer}> has successfully deposited {amount} on <{validator_account_id}>.") + } Ok(()) }, ); Ok(Self(crate::commands::ActionContext { global_context: previous_context.global_context, + interacting_with_account_ids, on_after_getting_network_callback, on_before_signing_callback: std::sync::Arc::new( |_prepolulated_unsinged_transaction, _network_config| Ok(()), diff --git a/src/commands/staking/delegate/deposit_and_stake.rs b/src/commands/staking/delegate/deposit_and_stake.rs index 2384e362a..1fd74eaae 100644 --- a/src/commands/staking/delegate/deposit_and_stake.rs +++ b/src/commands/staking/delegate/deposit_and_stake.rs @@ -25,6 +25,7 @@ impl DepositAndStakeContext { let signer = scope.signer_account_id.clone(); let signer_id: near_primitives::types::AccountId = scope.signer_account_id.clone().into(); let validator_account_id = previous_context.validator_account_id.clone(); + let interacting_with_account_ids = vec![validator_account_id.clone()]; let amount = scope.amount.clone(); let on_after_getting_network_callback: crate::commands::OnAfterGettingNetworkCallback = @@ -49,15 +50,14 @@ impl DepositAndStakeContext { let on_after_sending_transaction_callback: crate::transaction_signature_options::OnAfterSendingTransactionCallback = std::sync::Arc::new( move |outcome_view, _network_config| { if let near_primitives::views::FinalExecutionStatus::SuccessValue(_) = outcome_view.status { - eprintln!( - "<{signer}> has successfully deposited and staked {amount} on <{validator_account_id}>.", - ); - } + eprintln!("<{signer}> has successfully deposited and staked {amount} on <{validator_account_id}>.") + } Ok(()) }, ); Ok(Self(crate::commands::ActionContext { global_context: previous_context.global_context, + interacting_with_account_ids, on_after_getting_network_callback, on_before_signing_callback: std::sync::Arc::new( |_prepolulated_unsinged_transaction, _network_config| Ok(()), diff --git a/src/commands/staking/delegate/stake.rs b/src/commands/staking/delegate/stake.rs index be40529ae..61b264a1e 100644 --- a/src/commands/staking/delegate/stake.rs +++ b/src/commands/staking/delegate/stake.rs @@ -25,6 +25,7 @@ impl StakeContext { let signer = scope.signer_account_id.clone(); let signer_id: near_primitives::types::AccountId = scope.signer_account_id.clone().into(); let validator_account_id = previous_context.validator_account_id.clone(); + let interacting_with_account_ids = vec![validator_account_id.clone()]; let amount = scope.amount.clone(); let on_after_getting_network_callback: crate::commands::OnAfterGettingNetworkCallback = @@ -53,15 +54,14 @@ impl StakeContext { let on_after_sending_transaction_callback: crate::transaction_signature_options::OnAfterSendingTransactionCallback = std::sync::Arc::new( move |outcome_view, _network_config| { if let near_primitives::views::FinalExecutionStatus::SuccessValue(_) = outcome_view.status { - eprintln!( - "<{signer}> has successfully stake {amount} on <{validator_account_id}>.", - ); - } + eprintln!("<{signer}> has successfully stake {amount} on <{validator_account_id}>.") + } Ok(()) }, ); Ok(Self(crate::commands::ActionContext { global_context: previous_context.global_context, + interacting_with_account_ids, on_after_getting_network_callback, on_before_signing_callback: std::sync::Arc::new( |_prepolulated_unsinged_transaction, _network_config| Ok(()), diff --git a/src/commands/staking/delegate/stake_all.rs b/src/commands/staking/delegate/stake_all.rs index 4e7cedbd6..aae876791 100644 --- a/src/commands/staking/delegate/stake_all.rs +++ b/src/commands/staking/delegate/stake_all.rs @@ -23,6 +23,7 @@ impl StakeAllContext { let signer = scope.signer_account_id.clone(); let signer_id: near_primitives::types::AccountId = scope.signer_account_id.clone().into(); let validator_account_id = previous_context.validator_account_id.clone(); + let interacting_with_account_ids = vec![validator_account_id.clone()]; let on_after_getting_network_callback: crate::commands::OnAfterGettingNetworkCallback = std::sync::Arc::new(move |_network_config| { @@ -45,15 +46,14 @@ impl StakeAllContext { let on_after_sending_transaction_callback: crate::transaction_signature_options::OnAfterSendingTransactionCallback = std::sync::Arc::new( move |outcome_view, _network_config| { if let near_primitives::views::FinalExecutionStatus::SuccessValue(_) = outcome_view.status { - eprintln!( - "<{signer}> has successfully stake the entire amount on <{validator_account_id}>.", //XXX - ); - } + eprintln!("<{signer}> has successfully stake the entire amount on <{validator_account_id}>.") + } Ok(()) }, ); Ok(Self(crate::commands::ActionContext { global_context: previous_context.global_context, + interacting_with_account_ids, on_after_getting_network_callback, on_before_signing_callback: std::sync::Arc::new( |_prepolulated_unsinged_transaction, _network_config| Ok(()), diff --git a/src/commands/staking/delegate/unstake.rs b/src/commands/staking/delegate/unstake.rs index 89889f8c8..baa904ed4 100644 --- a/src/commands/staking/delegate/unstake.rs +++ b/src/commands/staking/delegate/unstake.rs @@ -25,6 +25,7 @@ impl UnstakeContext { let signer = scope.signer_account_id.clone(); let signer_id: near_primitives::types::AccountId = scope.signer_account_id.clone().into(); let validator_account_id = previous_context.validator_account_id.clone(); + let interacting_with_account_ids = vec![validator_account_id.clone()]; let amount = scope.amount.clone(); let on_after_getting_network_callback: crate::commands::OnAfterGettingNetworkCallback = @@ -53,15 +54,14 @@ impl UnstakeContext { let on_after_sending_transaction_callback: crate::transaction_signature_options::OnAfterSendingTransactionCallback = std::sync::Arc::new( move |outcome_view, _network_config| { if let near_primitives::views::FinalExecutionStatus::SuccessValue(_) = outcome_view.status { - eprintln!( - "<{signer}> has successfully unstake {amount} from <{validator_account_id}>.", - ); - } + eprintln!("<{signer}> has successfully unstake {amount} from <{validator_account_id}>.") + } Ok(()) }, ); Ok(Self(crate::commands::ActionContext { global_context: previous_context.global_context, + interacting_with_account_ids, on_after_getting_network_callback, on_before_signing_callback: std::sync::Arc::new( |_prepolulated_unsinged_transaction, _network_config| Ok(()), diff --git a/src/commands/staking/delegate/unstake_all.rs b/src/commands/staking/delegate/unstake_all.rs index 66caec03f..1de48c02a 100644 --- a/src/commands/staking/delegate/unstake_all.rs +++ b/src/commands/staking/delegate/unstake_all.rs @@ -23,6 +23,7 @@ impl UnstakeAllContext { let signer = scope.signer_account_id.clone(); let signer_id: near_primitives::types::AccountId = scope.signer_account_id.clone().into(); let validator_account_id = previous_context.validator_account_id.clone(); + let interacting_with_account_ids = vec![validator_account_id.clone()]; let on_after_getting_network_callback: crate::commands::OnAfterGettingNetworkCallback = std::sync::Arc::new(move |_network_config| { @@ -45,15 +46,14 @@ impl UnstakeAllContext { let on_after_sending_transaction_callback: crate::transaction_signature_options::OnAfterSendingTransactionCallback = std::sync::Arc::new( move |outcome_view, _network_config| { if let near_primitives::views::FinalExecutionStatus::SuccessValue(_) = outcome_view.status { - eprintln!( - "<{signer}> has successfully unstake the entire amount from <{validator_account_id}>.", //XXX - ); - } + eprintln!("<{signer}> has successfully unstake the entire amount from <{validator_account_id}>.") + } Ok(()) }, ); Ok(Self(crate::commands::ActionContext { global_context: previous_context.global_context, + interacting_with_account_ids, on_after_getting_network_callback, on_before_signing_callback: std::sync::Arc::new( |_prepolulated_unsinged_transaction, _network_config| Ok(()), diff --git a/src/commands/staking/delegate/view_balance.rs b/src/commands/staking/delegate/view_balance.rs index 74224740f..c66704445 100644 --- a/src/commands/staking/delegate/view_balance.rs +++ b/src/commands/staking/delegate/view_balance.rs @@ -22,16 +22,18 @@ impl ViewBalanceContext { previous_context: super::DelegateStakeContext, scope: &::InteractiveClapContextScope, ) -> color_eyre::eyre::Result { + let validator_account_id = previous_context.validator_account_id.clone(); + let interacting_with_account_ids = vec![validator_account_id.clone()]; + let on_after_getting_block_reference_callback: crate::network_view_at_block::OnAfterGettingBlockReferenceCallback = std::sync::Arc::new({ let account_id: near_primitives::types::AccountId = scope.account_id.clone().into(); - let validator_id = previous_context.validator_account_id.clone(); move |network_config, block_reference| { let user_staked_balance: u128 = get_user_staked_balance(network_config, block_reference, &previous_context.validator_account_id, &account_id)?; let user_unstaked_balance: u128 = get_user_unstaked_balance(network_config, block_reference, &previous_context.validator_account_id, &account_id)?; let user_total_balance: u128 = get_user_total_balance(network_config, block_reference, &previous_context.validator_account_id, &account_id)?; - eprintln!("Balance on validator <{validator_id}> for <{account_id}>:"); + eprintln!("Balance on validator <{validator_account_id}> for <{account_id}>:"); eprintln!(" Staked balance: {:>38}", crate::common::NearBalance::from_yoctonear(user_staked_balance).to_string()); eprintln!(" Unstaked balance: {:>38}", crate::common::NearBalance::from_yoctonear(user_unstaked_balance).to_string()); eprintln!(" Total balance: {:>38}", crate::common::NearBalance::from_yoctonear(user_total_balance).to_string()); @@ -41,6 +43,7 @@ impl ViewBalanceContext { }); Ok(Self(crate::network_view_at_block::ArgsForViewContext { config: previous_context.global_context.config, + interacting_with_account_ids, on_after_getting_block_reference_callback, })) } diff --git a/src/commands/staking/delegate/withdraw.rs b/src/commands/staking/delegate/withdraw.rs index cf5eef48c..08fab9e2d 100644 --- a/src/commands/staking/delegate/withdraw.rs +++ b/src/commands/staking/delegate/withdraw.rs @@ -27,6 +27,7 @@ impl WithdrawContext { scope: &::InteractiveClapContextScope, ) -> color_eyre::eyre::Result { let validator_account_id = previous_context.validator_account_id.clone(); + let interacting_with_account_ids = vec![validator_account_id.clone()]; let on_after_getting_network_callback: crate::commands::OnAfterGettingNetworkCallback = std::sync::Arc::new({ @@ -87,15 +88,14 @@ impl WithdrawContext { move |outcome_view, _network_config| { if let near_primitives::views::FinalExecutionStatus::SuccessValue(_) = outcome_view.status { - eprintln!( - "<{signer}> has successfully withdrawn {amount} from <{validator_account_id}>.", - ); - } + eprintln!("<{signer}> has successfully withdrawn {amount} from <{validator_account_id}>.") + } Ok(()) } }); Ok(Self(crate::commands::ActionContext { global_context: previous_context.global_context, + interacting_with_account_ids, on_after_getting_network_callback, on_before_signing_callback: std::sync::Arc::new( |_prepolulated_unsinged_transaction, _network_config| Ok(()), diff --git a/src/commands/staking/delegate/withdraw_all.rs b/src/commands/staking/delegate/withdraw_all.rs index 76e828202..c5aee585c 100644 --- a/src/commands/staking/delegate/withdraw_all.rs +++ b/src/commands/staking/delegate/withdraw_all.rs @@ -25,6 +25,7 @@ impl WithdrawAllContext { scope: &::InteractiveClapContextScope, ) -> color_eyre::eyre::Result { let validator_account_id = previous_context.validator_account_id.clone(); + let interacting_with_account_ids = vec![validator_account_id.clone()]; let on_after_getting_network_callback: crate::commands::OnAfterGettingNetworkCallback = std::sync::Arc::new({ @@ -80,15 +81,14 @@ impl WithdrawAllContext { move |outcome_view, _network_config| { if let near_primitives::views::FinalExecutionStatus::SuccessValue(_) = outcome_view.status { - eprintln!( - "<{signer}> has successfully withdrawn the entire amount from <{validator_account_id}>.", //XXX - ); - } + eprintln!("<{signer}> has successfully withdrawn the entire amount from <{validator_account_id}>.") + } Ok(()) } }); Ok(Self(crate::commands::ActionContext { global_context: previous_context.global_context, + interacting_with_account_ids, on_after_getting_network_callback, on_before_signing_callback: std::sync::Arc::new( |_prepolulated_unsinged_transaction, _network_config| Ok(()), diff --git a/src/commands/staking/validator_list/mod.rs b/src/commands/staking/validator_list/mod.rs index 9e4569d21..6fdebc2b9 100644 --- a/src/commands/staking/validator_list/mod.rs +++ b/src/commands/staking/validator_list/mod.rs @@ -21,6 +21,7 @@ impl ValidatorListContext { std::sync::Arc::new(display_validators_info); Ok(Self(crate::network::NetworkContext { config: previous_context.config, + interacting_with_account_ids: vec![], on_after_getting_network_callback, })) } From cc04fe1cdc9c942cb93a35ee515bc08fdcc17f83 Mon Sep 17 00:00:00 2001 From: FroVolod Date: Sun, 3 Sep 2023 12:26:57 +0300 Subject: [PATCH 18/44] added validators url --- src/commands/staking/validator_list/mod.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/commands/staking/validator_list/mod.rs b/src/commands/staking/validator_list/mod.rs index 6fdebc2b9..f22868345 100644 --- a/src/commands/staking/validator_list/mod.rs +++ b/src/commands/staking/validator_list/mod.rs @@ -51,5 +51,10 @@ fn display_validators_info(network_config: &crate::config::NetworkConfig) -> cra } table.set_format(*prettytable::format::consts::FORMAT_NO_LINESEP_WITH_TITLE); table.printstd(); + let validators_url: url::Url = network_config.wallet_url.join("staking/validators")?; + eprintln!( + "This is not a complete list of validators. To see the full list of validators visit this URL:\n{}\n", + &validators_url.as_str() + ); Ok(()) } From d461b41b090890fe4c6d48006b7c59f2d01fbb34 Mon Sep 17 00:00:00 2001 From: FroVolod Date: Sun, 10 Sep 2023 18:33:08 +0300 Subject: [PATCH 19/44] fixed unstake message --- src/common.rs | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/common.rs b/src/common.rs index 617744c2a..4ad463ca4 100644 --- a/src/common.rs +++ b/src/common.rs @@ -870,11 +870,18 @@ fn print_value_successful_transaction( stake, public_key: _, } => { - eprintln!( - "Validator <{}> has successfully staked {}.", - transaction_info.transaction.signer_id, - crate::common::NearBalance::from_yoctonear(stake), - ); + if stake == 0 { + eprintln!( + "Validator <{}> successfully unstaked.", + transaction_info.transaction.signer_id, + ); + } else { + eprintln!( + "Validator <{}> has successfully staked {}.", + transaction_info.transaction.signer_id, + crate::common::NearBalance::from_yoctonear(stake), + ); + } } near_primitives::views::ActionView::AddKey { public_key, From d93fedfc87defefb341b8ee12b48fcafbc83ac1b Mon Sep 17 00:00:00 2001 From: FroVolod Date: Tue, 26 Sep 2023 10:36:32 +0300 Subject: [PATCH 20/44] updated to "near-gas" --- src/commands/staking/delegate/deposit.rs | 6 +----- src/commands/staking/delegate/deposit_and_stake.rs | 6 +----- src/commands/staking/delegate/stake.rs | 8 ++------ src/commands/staking/delegate/stake_all.rs | 8 ++------ src/commands/staking/delegate/unstake.rs | 8 ++------ src/commands/staking/delegate/unstake_all.rs | 8 ++------ src/commands/staking/delegate/withdraw.rs | 9 ++------- src/commands/staking/delegate/withdraw_all.rs | 9 ++------- 8 files changed, 14 insertions(+), 48 deletions(-) diff --git a/src/commands/staking/delegate/deposit.rs b/src/commands/staking/delegate/deposit.rs index d77e15dab..29adf2d2b 100644 --- a/src/commands/staking/delegate/deposit.rs +++ b/src/commands/staking/delegate/deposit.rs @@ -1,5 +1,3 @@ -use std::str::FromStr; - #[derive(Debug, Clone, interactive_clap::InteractiveClap)] #[interactive_clap(input_context = super::DelegateStakeContext)] #[interactive_clap(output_context = DepositContext)] @@ -37,9 +35,7 @@ impl DepositContext { near_primitives::transaction::FunctionCallAction { method_name: "deposit".to_string(), args: serde_json::json!({}).to_string().into_bytes(), - gas: crate::common::NearGas::from_str("300 TeraGas") - .unwrap() - .inner, + gas: crate::common::NearGas::from_tgas(300).as_gas(), deposit: amount.to_yoctonear(), }, )], diff --git a/src/commands/staking/delegate/deposit_and_stake.rs b/src/commands/staking/delegate/deposit_and_stake.rs index 1fd74eaae..f182a2e52 100644 --- a/src/commands/staking/delegate/deposit_and_stake.rs +++ b/src/commands/staking/delegate/deposit_and_stake.rs @@ -1,5 +1,3 @@ -use std::str::FromStr; - #[derive(Debug, Clone, interactive_clap::InteractiveClap)] #[interactive_clap(input_context = super::DelegateStakeContext)] #[interactive_clap(output_context = DepositAndStakeContext)] @@ -37,9 +35,7 @@ impl DepositAndStakeContext { near_primitives::transaction::FunctionCallAction { method_name: "deposit_and_stake".to_string(), args: serde_json::json!({}).to_string().into_bytes(), - gas: crate::common::NearGas::from_str("300 TeraGas") - .unwrap() - .inner, + gas: crate::common::NearGas::from_tgas(300).as_gas(), deposit: amount.to_yoctonear(), }, )], diff --git a/src/commands/staking/delegate/stake.rs b/src/commands/staking/delegate/stake.rs index 61b264a1e..a937eaabf 100644 --- a/src/commands/staking/delegate/stake.rs +++ b/src/commands/staking/delegate/stake.rs @@ -1,5 +1,3 @@ -use std::str::FromStr; - #[derive(Debug, Clone, interactive_clap::InteractiveClap)] #[interactive_clap(input_context = super::DelegateStakeContext)] #[interactive_clap(output_context = StakeContext)] @@ -41,10 +39,8 @@ impl StakeContext { }) .to_string() .into_bytes(), - gas: crate::common::NearGas::from_str("300 TeraGas") - .unwrap() - .inner, - deposit: crate::common::NearBalance::from_yoctonear(0).to_yoctonear(), + gas: crate::common::NearGas::from_tgas(300).as_gas(), + deposit: 0, }, )], }) diff --git a/src/commands/staking/delegate/stake_all.rs b/src/commands/staking/delegate/stake_all.rs index aae876791..13f7d8fc7 100644 --- a/src/commands/staking/delegate/stake_all.rs +++ b/src/commands/staking/delegate/stake_all.rs @@ -1,5 +1,3 @@ -use std::str::FromStr; - #[derive(Debug, Clone, interactive_clap::InteractiveClap)] #[interactive_clap(input_context = super::DelegateStakeContext)] #[interactive_clap(output_context = StakeAllContext)] @@ -34,10 +32,8 @@ impl StakeAllContext { near_primitives::transaction::FunctionCallAction { method_name: "stake_all".to_string(), args: serde_json::json!({}).to_string().into_bytes(), - gas: crate::common::NearGas::from_str("300 TeraGas") - .unwrap() - .inner, - deposit: crate::common::NearBalance::from_yoctonear(0).to_yoctonear(), + gas: crate::common::NearGas::from_tgas(300).as_gas(), + deposit: 0, }, )], }) diff --git a/src/commands/staking/delegate/unstake.rs b/src/commands/staking/delegate/unstake.rs index baa904ed4..88e5659e7 100644 --- a/src/commands/staking/delegate/unstake.rs +++ b/src/commands/staking/delegate/unstake.rs @@ -1,5 +1,3 @@ -use std::str::FromStr; - #[derive(Debug, Clone, interactive_clap::InteractiveClap)] #[interactive_clap(input_context = super::DelegateStakeContext)] #[interactive_clap(output_context = UnstakeContext)] @@ -41,10 +39,8 @@ impl UnstakeContext { }) .to_string() .into_bytes(), - gas: crate::common::NearGas::from_str("300 TeraGas") - .unwrap() - .inner, - deposit: crate::common::NearBalance::from_yoctonear(0).to_yoctonear(), + gas: crate::common::NearGas::from_tgas(300).as_gas(), + deposit: 0, }, )], }) diff --git a/src/commands/staking/delegate/unstake_all.rs b/src/commands/staking/delegate/unstake_all.rs index 1de48c02a..4b05ac84e 100644 --- a/src/commands/staking/delegate/unstake_all.rs +++ b/src/commands/staking/delegate/unstake_all.rs @@ -1,5 +1,3 @@ -use std::str::FromStr; - #[derive(Debug, Clone, interactive_clap::InteractiveClap)] #[interactive_clap(input_context = super::DelegateStakeContext)] #[interactive_clap(output_context = UnstakeAllContext)] @@ -34,10 +32,8 @@ impl UnstakeAllContext { near_primitives::transaction::FunctionCallAction { method_name: "unstake_all".to_string(), args: serde_json::json!({}).to_string().into_bytes(), - gas: crate::common::NearGas::from_str("300 TeraGas") - .unwrap() - .inner, - deposit: crate::common::NearBalance::from_yoctonear(0).to_yoctonear(), + gas: crate::common::NearGas::from_tgas(300).as_gas(), + deposit: 0, }, )], }) diff --git a/src/commands/staking/delegate/withdraw.rs b/src/commands/staking/delegate/withdraw.rs index 08fab9e2d..522620011 100644 --- a/src/commands/staking/delegate/withdraw.rs +++ b/src/commands/staking/delegate/withdraw.rs @@ -1,5 +1,3 @@ -use std::str::FromStr; - use color_eyre::eyre::WrapErr; use crate::common::{CallResultExt, JsonRpcClientExt}; @@ -71,11 +69,8 @@ impl WithdrawContext { }) .to_string() .into_bytes(), - gas: crate::common::NearGas::from_str("300 TeraGas") - .unwrap() - .inner, - deposit: crate::common::NearBalance::from_yoctonear(0) - .to_yoctonear(), + gas: crate::common::NearGas::from_tgas(300).as_gas(), + deposit: 0, }, )], }) diff --git a/src/commands/staking/delegate/withdraw_all.rs b/src/commands/staking/delegate/withdraw_all.rs index c5aee585c..f1c499e4c 100644 --- a/src/commands/staking/delegate/withdraw_all.rs +++ b/src/commands/staking/delegate/withdraw_all.rs @@ -1,5 +1,3 @@ -use std::str::FromStr; - use color_eyre::eyre::WrapErr; use crate::common::{CallResultExt, JsonRpcClientExt}; @@ -65,11 +63,8 @@ impl WithdrawAllContext { near_primitives::transaction::FunctionCallAction { method_name: "withdraw_all".to_string(), args: serde_json::json!({}).to_string().into_bytes(), - gas: crate::common::NearGas::from_str("300 TeraGas") - .unwrap() - .inner, - deposit: crate::common::NearBalance::from_yoctonear(0) - .to_yoctonear(), + gas: crate::common::NearGas::from_tgas(300).as_gas(), + deposit: 0, }, )], }) From e8fbce9691c026a220b1a280709ed8ff609af3ab Mon Sep 17 00:00:00 2001 From: FroVolod Date: Tue, 26 Sep 2023 10:39:02 +0300 Subject: [PATCH 21/44] clippy --- src/commands/contract/call_function/as_transaction/mod.rs | 2 +- .../contract/deploy/initialize_mode/call_function_type/mod.rs | 2 +- src/commands/tokens/send_ft/mod.rs | 2 +- src/commands/tokens/send_nft/mod.rs | 2 +- .../add_action_1/add_action/call_function/mod.rs | 2 +- .../add_action_2/add_action/call_function/mod.rs | 2 +- .../add_action_3/add_action/call_function/mod.rs | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/commands/contract/call_function/as_transaction/mod.rs b/src/commands/contract/call_function/as_transaction/mod.rs index 094d8d035..5a9e6db50 100644 --- a/src/commands/contract/call_function/as_transaction/mod.rs +++ b/src/commands/contract/call_function/as_transaction/mod.rs @@ -96,7 +96,7 @@ impl PrepaidGasContext { receiver_account_id: previous_context.receiver_account_id, function_name: previous_context.function_name, function_args: previous_context.function_args, - gas: scope.gas.clone(), + gas: scope.gas, }) } } diff --git a/src/commands/contract/deploy/initialize_mode/call_function_type/mod.rs b/src/commands/contract/deploy/initialize_mode/call_function_type/mod.rs index 9722e371a..494bf6fdc 100644 --- a/src/commands/contract/deploy/initialize_mode/call_function_type/mod.rs +++ b/src/commands/contract/deploy/initialize_mode/call_function_type/mod.rs @@ -96,7 +96,7 @@ impl PrepaidGasContext { code: previous_context.code, function_name: previous_context.function_name, function_args: previous_context.function_args, - gas: scope.gas.clone(), + gas: scope.gas, }) } } diff --git a/src/commands/tokens/send_ft/mod.rs b/src/commands/tokens/send_ft/mod.rs index d28aca196..10724e31b 100644 --- a/src/commands/tokens/send_ft/mod.rs +++ b/src/commands/tokens/send_ft/mod.rs @@ -50,7 +50,7 @@ impl SendFtCommandContext { ft_contract_account_id: scope.ft_contract_account_id.clone().into(), receiver_account_id: scope.receiver_account_id.clone().into(), amount: scope.amount, - gas: scope.gas.clone(), + gas: scope.gas, deposit: scope.deposit.clone(), }) } diff --git a/src/commands/tokens/send_nft/mod.rs b/src/commands/tokens/send_nft/mod.rs index 649359cfa..c53c85823 100644 --- a/src/commands/tokens/send_nft/mod.rs +++ b/src/commands/tokens/send_nft/mod.rs @@ -50,7 +50,7 @@ impl SendNftCommandContext { nft_contract_account_id: scope.nft_contract_account_id.clone().into(), receiver_account_id: scope.receiver_account_id.clone().into(), token_id: scope.token_id.clone(), - gas: scope.gas.clone(), + gas: scope.gas, deposit: scope.deposit.clone(), }) } diff --git a/src/commands/transaction/construct_transaction/add_action_1/add_action/call_function/mod.rs b/src/commands/transaction/construct_transaction/add_action_1/add_action/call_function/mod.rs index b82316552..ba5552f55 100644 --- a/src/commands/transaction/construct_transaction/add_action_1/add_action/call_function/mod.rs +++ b/src/commands/transaction/construct_transaction/add_action_1/add_action/call_function/mod.rs @@ -97,7 +97,7 @@ impl PrepaidGasContext { actions: previous_context.actions, function_name: previous_context.function_name, function_args: previous_context.function_args, - gas: scope.gas.clone(), + gas: scope.gas, }) } } diff --git a/src/commands/transaction/construct_transaction/add_action_2/add_action/call_function/mod.rs b/src/commands/transaction/construct_transaction/add_action_2/add_action/call_function/mod.rs index db1ffac52..43aa368bd 100644 --- a/src/commands/transaction/construct_transaction/add_action_2/add_action/call_function/mod.rs +++ b/src/commands/transaction/construct_transaction/add_action_2/add_action/call_function/mod.rs @@ -97,7 +97,7 @@ impl PrepaidGasContext { actions: previous_context.actions, function_name: previous_context.function_name, function_args: previous_context.function_args, - gas: scope.gas.clone(), + gas: scope.gas, }) } } diff --git a/src/commands/transaction/construct_transaction/add_action_3/add_action/call_function/mod.rs b/src/commands/transaction/construct_transaction/add_action_3/add_action/call_function/mod.rs index 14680e676..cf4fce49c 100644 --- a/src/commands/transaction/construct_transaction/add_action_3/add_action/call_function/mod.rs +++ b/src/commands/transaction/construct_transaction/add_action_3/add_action/call_function/mod.rs @@ -97,7 +97,7 @@ impl PrepaidGasContext { actions: previous_context.actions, function_name: previous_context.function_name, function_args: previous_context.function_args, - gas: scope.gas.clone(), + gas: scope.gas, }) } } From 4fef7c4cd9992a94f36670edea67c84343d3bf01 Mon Sep 17 00:00:00 2001 From: FroVolod Date: Sat, 30 Sep 2023 10:01:35 +0300 Subject: [PATCH 22/44] updated: interactive-clap = "0.2.5" --- Cargo.lock | 8 ++++---- Cargo.toml | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4d8d094f7..e4bd57a1c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1794,9 +1794,9 @@ dependencies = [ [[package]] name = "interactive-clap" -version = "0.2.4" +version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e9a4460797bc616e3256b1becad15e859c4f8d63a8a379c87fdcb1734206cf0a" +checksum = "cfa3bbd3c31d3f6765db87b260af5612dcaaeb58a48bda65b28fc939e1db3080" dependencies = [ "interactive-clap-derive", "strum", @@ -1805,9 +1805,9 @@ dependencies = [ [[package]] name = "interactive-clap-derive" -version = "0.2.4" +version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e4d0f6a898a8dc1bcea5b00552c5a3fa3f64a2634f84b854390269238abdc9ed" +checksum = "7d2e37af37a6ee00d336794e148a508f58daf3d0484278d1ca63224ba5c0a7e0" dependencies = [ "proc-macro-error", "proc-macro2", diff --git a/Cargo.toml b/Cargo.toml index b410497db..d294768b3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -75,8 +75,8 @@ near-gas = { version = "0.2.3", features = [ "interactive-clap", ] } -interactive-clap = "0.2.4" -interactive-clap-derive = "0.2.4" +interactive-clap = "0.2.5" +interactive-clap-derive = "0.2.5" keyring = "2.0.5" [features] From dbf79fc9bfabea20262f51c9337b84734582ee02 Mon Sep 17 00:00:00 2001 From: Vlad Frolov Date: Sun, 22 Oct 2023 10:26:10 +0200 Subject: [PATCH 23/44] refactor: optimized and simplified the delegated stake fetching --- .../account/view_account_summary/mod.rs | 118 +++++++----------- src/commands/staking/validator_list/mod.rs | 2 +- src/common.rs | 6 +- 3 files changed, 51 insertions(+), 75 deletions(-) diff --git a/src/commands/account/view_account_summary/mod.rs b/src/commands/account/view_account_summary/mod.rs index 90d380839..4e03e3e87 100644 --- a/src/commands/account/view_account_summary/mod.rs +++ b/src/commands/account/view_account_summary/mod.rs @@ -1,5 +1,5 @@ use color_eyre::eyre::Context; -use futures::StreamExt; +use futures::{StreamExt, TryStreamExt}; use crate::common::{CallResultExt, JsonRpcClientExt, RpcQueryResponseExt}; @@ -58,27 +58,27 @@ impl ViewAccountSummaryContext { let runtime = tokio::runtime::Builder::new_multi_thread() .enable_all() .build()?; - let chunk_size = 15; let concurrency = 10; - - let delegated_stake: std::collections::HashMap = runtime + let delegated_stake: std::collections::BTreeMap = runtime .block_on( - futures::stream::iter(validators_stake - .iter() - .collect::>() - .chunks(chunk_size), - ) - .map(|validators| async { - get_delegated_stake(&json_rpc_client, block_reference, &account_id, validators).await + futures::stream::iter(validators_stake.into_keys()) + .map(|validator_account_id| async { + let balance = get_delegated_staked_balance(&json_rpc_client, block_reference, &validator_account_id, &account_id).await?; + Ok::<_, color_eyre::eyre::Report>(( + validator_account_id, + balance, + )) }) .buffer_unordered(concurrency) - .collect::>>(), - ) - .into_iter() - .try_fold(std::collections::HashMap::new(), |mut acc, x| { - acc.extend(x?); - Ok::<_, color_eyre::eyre::Error>(acc) - })?; + .filter(|balance_result| futures::future::ready( + if let Ok((_, balance)) = balance_result { + !balance.is_zero() + } else { + true + } + )) + .try_collect(), + )?; let contract_account_id = network_config.get_near_social_account_id_from_network()?; @@ -104,7 +104,7 @@ impl ViewAccountSummaryContext { &rpc_query_response.block_hash, &rpc_query_response.block_height, &account_id, - delegated_stake, + &delegated_stake, &account_view, &access_key_list.keys, social_db.accounts.get(&account_id) @@ -138,66 +138,42 @@ impl ViewAccountSummary { } } -async fn get_delegated_stake( - json_rpc_client: &near_jsonrpc_client::JsonRpcClient, - block_reference: &near_primitives::types::BlockReference, - account_id: &near_primitives::types::AccountId, - validators: &[(&near_primitives::types::AccountId, &u128)], -) -> color_eyre::Result< - std::collections::HashMap, -> { - let mut validators_stake: std::collections::HashMap< - near_primitives::types::AccountId, - crate::common::NearBalance, - > = std::collections::HashMap::new(); - for (validator_id, _) in validators { - let validator_id = *validator_id; - let user_staked_balance = - get_user_staked_balance(json_rpc_client, block_reference, validator_id, account_id) - .await - .ok(); - let balance = if let Some(balance) = user_staked_balance { - if balance == 0 { - continue; - } else { - balance - } - } else { - continue; - }; - validators_stake.insert( - validator_id.clone(), - crate::common::NearBalance::from_yoctonear(balance), - ); - } - Ok(validators_stake) -} - -async fn get_user_staked_balance( +async fn get_delegated_staked_balance( json_rpc_client: &near_jsonrpc_client::JsonRpcClient, block_reference: &near_primitives::types::BlockReference, - validator_account_id: &near_primitives::types::AccountId, + staking_pool_account_id: &near_primitives::types::AccountId, account_id: &near_primitives::types::AccountId, -) -> color_eyre::eyre::Result { - Ok(json_rpc_client +) -> color_eyre::eyre::Result { + let account_staked_balance_response = json_rpc_client .call(near_jsonrpc_client::methods::query::RpcQueryRequest { block_reference: block_reference.clone(), request: near_primitives::views::QueryRequest::CallFunction { - account_id: validator_account_id.clone(), + account_id: staking_pool_account_id.clone(), method_name: "get_account_staked_balance".to_string(), - args: near_primitives::types::FunctionArgs::from( - serde_json::json!({ + args: near_primitives::types::FunctionArgs::from(serde_json::to_vec( + &serde_json::json!({ "account_id": account_id, - }) - .to_string() - .into_bytes(), - ), + }), + )?), }, }) - .await - .wrap_err("Failed to fetch query for view method: 'get_account_staked_balance'")? - .call_result()? - .parse_result_from_json::() - .wrap_err("Failed to parse return value of view function call for String.")? - .parse::()?) + .await; + match account_staked_balance_response { + Ok(response) => Ok(crate::common::NearBalance::from_yoctonear( + response + .call_result()? + .parse_result_from_json::() + .wrap_err("Failed to parse return value of view function call for String.")? + .parse::()?, + )), + Err(near_jsonrpc_client::errors::JsonRpcError::ServerError( + near_jsonrpc_client::errors::JsonRpcServerError::HandlerError( + near_jsonrpc_client::methods::query::RpcQueryError::NoContractCode { .. } + | near_jsonrpc_client::methods::query::RpcQueryError::ContractExecutionError { + .. + }, + ), + )) => Ok(crate::common::NearBalance::from_yoctonear(0)), + Err(err) => Err(err.into()), + } } diff --git a/src/commands/staking/validator_list/mod.rs b/src/commands/staking/validator_list/mod.rs index f22868345..f95896739 100644 --- a/src/commands/staking/validator_list/mod.rs +++ b/src/commands/staking/validator_list/mod.rs @@ -53,7 +53,7 @@ fn display_validators_info(network_config: &crate::config::NetworkConfig) -> cra table.printstd(); let validators_url: url::Url = network_config.wallet_url.join("staking/validators")?; eprintln!( - "This is not a complete list of validators. To see the full list of validators visit this URL:\n{}\n", + "This is not a complete list of validators. To see the full list of validators visit Explorer:\n{}\n", &validators_url.as_str() ); Ok(()) diff --git a/src/common.rs b/src/common.rs index f0e4d823e..4901f2553 100644 --- a/src/common.rs +++ b/src/common.rs @@ -1462,7 +1462,7 @@ pub fn display_account_info( viewed_at_block_hash: &CryptoHash, viewed_at_block_height: &near_primitives::types::BlockHeight, account_id: &near_primitives::types::AccountId, - delegated_stake: std::collections::HashMap< + delegated_stake: &std::collections::BTreeMap< near_primitives::types::AccountId, crate::common::NearBalance, >, @@ -1490,9 +1490,9 @@ pub fn display_account_info( Fy->NearBalance::from_yoctonear(account_view.locked) ]); - for (validator_id, stake) in delegated_stake.iter() { + for (validator_id, stake) in delegated_stake { table.add_row(prettytable::row![ - Fg->format!("Delegated stake for <{validator_id}>"), + Fg->format!("Delegated stake with <{validator_id}>"), Fy->stake ]); } From e6ba1fff33d2cd2ebef0dc48b04c741ed12605ae Mon Sep 17 00:00:00 2001 From: FroVolod Date: Sun, 22 Oct 2023 20:13:54 +0300 Subject: [PATCH 24/44] refactor: serde_json::to_vec() instead of .to_string().into_bytes() --- .../fund_myself_create_account/sign_as/mod.rs | 6 ++---- .../storage_management/storage_deposit.rs | 6 +++--- .../storage_management/storage_withdraw.rs | 6 ++---- .../storage_management/view_storage_balance.rs | 6 ++---- .../account/update_social_profile/sign_as.rs | 6 ++---- .../account/view_account_summary/mod.rs | 6 ++---- .../call_function_args_type/mod.rs | 2 +- src/commands/staking/delegate/deposit.rs | 2 +- .../staking/delegate/deposit_and_stake.rs | 2 +- src/commands/staking/delegate/stake.rs | 8 +++----- src/commands/staking/delegate/stake_all.rs | 2 +- src/commands/staking/delegate/unstake.rs | 6 ++---- src/commands/staking/delegate/unstake_all.rs | 2 +- src/commands/staking/delegate/view_balance.rs | 18 ++++++------------ src/commands/staking/delegate/withdraw.rs | 12 ++++-------- src/commands/staking/delegate/withdraw_all.rs | 8 +++----- src/commands/tokens/send_ft/mod.rs | 6 ++---- src/commands/tokens/send_nft/mod.rs | 6 ++---- src/commands/tokens/view_ft_balance/mod.rs | 6 ++---- src/commands/tokens/view_nft_assets/mod.rs | 6 ++---- 20 files changed, 44 insertions(+), 78 deletions(-) diff --git a/src/commands/account/create_account/fund_myself_create_account/sign_as/mod.rs b/src/commands/account/create_account/fund_myself_create_account/sign_as/mod.rs index 293236aee..16d45455d 100644 --- a/src/commands/account/create_account/fund_myself_create_account/sign_as/mod.rs +++ b/src/commands/account/create_account/fund_myself_create_account/sign_as/mod.rs @@ -81,12 +81,10 @@ impl From for crate::commands::ActionContext { ], new_account_id.clone()) } else { - let args = json!({ + let args = serde_json::to_vec(&json!({ "new_account_id": new_account_id.clone().to_string(), "new_public_key": item.account_properties.public_key.to_string() - }) - .to_string() - .into_bytes(); + }))?; if let Some(linkdrop_account_id) = &network_config.linkdrop_account_id { if new_account_id.is_sub_account_of(linkdrop_account_id) diff --git a/src/commands/account/storage_management/storage_deposit.rs b/src/commands/account/storage_management/storage_deposit.rs index 816ae34bb..928c9df91 100644 --- a/src/commands/account/storage_management/storage_deposit.rs +++ b/src/commands/account/storage_management/storage_deposit.rs @@ -117,9 +117,9 @@ impl SignerAccountIdContext { actions: vec![near_primitives::transaction::Action::FunctionCall( near_primitives::transaction::FunctionCallAction { method_name: "storage_deposit".to_string(), - args: serde_json::json!({ "account_id": &receiver_account_id }) - .to_string() - .into_bytes(), + args: serde_json::to_vec(&serde_json::json!({ + "account_id": &receiver_account_id + }))?, gas: crate::common::NearGas::from_tgas(50).as_gas(), deposit: deposit.to_yoctonear(), }, diff --git a/src/commands/account/storage_management/storage_withdraw.rs b/src/commands/account/storage_management/storage_withdraw.rs index 00d3d5f01..662d5ddc2 100644 --- a/src/commands/account/storage_management/storage_withdraw.rs +++ b/src/commands/account/storage_management/storage_withdraw.rs @@ -63,11 +63,9 @@ impl SignerAccountIdContext { actions: vec![near_primitives::transaction::Action::FunctionCall( near_primitives::transaction::FunctionCallAction { method_name: "storage_withdraw".to_string(), - args: serde_json::json!({ + args: serde_json::to_vec(&serde_json::json!({ "amount": amount.clone().to_yoctonear().to_string() - }) - .to_string() - .into_bytes(), + }))?, gas: crate::common::NearGas::from_tgas(50).as_gas(), deposit: crate::common::NearBalance::from_yoctonear(1) .to_yoctonear(), diff --git a/src/commands/account/storage_management/view_storage_balance.rs b/src/commands/account/storage_management/view_storage_balance.rs index 6bb36e1d1..eaf184aec 100644 --- a/src/commands/account/storage_management/view_storage_balance.rs +++ b/src/commands/account/storage_management/view_storage_balance.rs @@ -35,11 +35,9 @@ impl AccountContext { .blocking_call_view_function( &contract_account_id, "storage_balance_of", - serde_json::json!({ + serde_json::to_vec(&serde_json::json!({ "account_id": account_id.to_string(), - }) - .to_string() - .into_bytes(), + }))?, block_reference.clone(), ) .wrap_err_with(|| { diff --git a/src/commands/account/update_social_profile/sign_as.rs b/src/commands/account/update_social_profile/sign_as.rs index c89dce9d0..c633d5dde 100644 --- a/src/commands/account/update_social_profile/sign_as.rs +++ b/src/commands/account/update_social_profile/sign_as.rs @@ -64,11 +64,9 @@ impl From for crate::commands::ActionContext { .blocking_call_view_function( &contract_account_id, "get", - serde_json::json!({ + serde_json::to_vec(&serde_json::json!({ "keys": vec![format!("{account_id}/profile/**")], - }) - .to_string() - .into_bytes(), + }))?, near_primitives::types::Finality::Final.into(), ) .wrap_err_with(|| {format!("Failed to fetch query for view method: 'get {account_id}/profile/**'")})? diff --git a/src/commands/account/view_account_summary/mod.rs b/src/commands/account/view_account_summary/mod.rs index 4e03e3e87..5e4e3c091 100644 --- a/src/commands/account/view_account_summary/mod.rs +++ b/src/commands/account/view_account_summary/mod.rs @@ -87,11 +87,9 @@ impl ViewAccountSummaryContext { .blocking_call_view_function( &contract_account_id, "get", - serde_json::json!({ + serde_json::to_vec(&serde_json::json!({ "keys": vec![format!("{account_id}/profile/**")], - }) - .to_string() - .into_bytes(), + }))?, block_reference.clone(), ) .wrap_err_with(|| {format!("Failed to fetch query for view method: 'get {account_id}/profile/**'")})? diff --git a/src/commands/contract/call_function/call_function_args_type/mod.rs b/src/commands/contract/call_function/call_function_args_type/mod.rs index 4f8a706a3..c54e63e10 100644 --- a/src/commands/contract/call_function/call_function_args_type/mod.rs +++ b/src/commands/contract/call_function/call_function_args_type/mod.rs @@ -84,7 +84,7 @@ pub fn function_args( super::call_function_args_type::FunctionArgsType::JsonArgs => { let data_json = serde_json::Value::from_str(&args).wrap_err("Data not in JSON format!")?; - Ok(data_json.to_string().into_bytes()) + serde_json::to_vec(&data_json).wrap_err("Internal error!") } super::call_function_args_type::FunctionArgsType::TextArgs => Ok(args.into_bytes()), super::call_function_args_type::FunctionArgsType::Base64Args => { diff --git a/src/commands/staking/delegate/deposit.rs b/src/commands/staking/delegate/deposit.rs index 29adf2d2b..ee5faca19 100644 --- a/src/commands/staking/delegate/deposit.rs +++ b/src/commands/staking/delegate/deposit.rs @@ -34,7 +34,7 @@ impl DepositContext { actions: vec![near_primitives::transaction::Action::FunctionCall( near_primitives::transaction::FunctionCallAction { method_name: "deposit".to_string(), - args: serde_json::json!({}).to_string().into_bytes(), + args: serde_json::to_vec(&serde_json::json!({}))?, gas: crate::common::NearGas::from_tgas(300).as_gas(), deposit: amount.to_yoctonear(), }, diff --git a/src/commands/staking/delegate/deposit_and_stake.rs b/src/commands/staking/delegate/deposit_and_stake.rs index f182a2e52..aa4da76a7 100644 --- a/src/commands/staking/delegate/deposit_and_stake.rs +++ b/src/commands/staking/delegate/deposit_and_stake.rs @@ -34,7 +34,7 @@ impl DepositAndStakeContext { actions: vec![near_primitives::transaction::Action::FunctionCall( near_primitives::transaction::FunctionCallAction { method_name: "deposit_and_stake".to_string(), - args: serde_json::json!({}).to_string().into_bytes(), + args: serde_json::to_vec(&serde_json::json!({}))?, gas: crate::common::NearGas::from_tgas(300).as_gas(), deposit: amount.to_yoctonear(), }, diff --git a/src/commands/staking/delegate/stake.rs b/src/commands/staking/delegate/stake.rs index a937eaabf..2dec33a5f 100644 --- a/src/commands/staking/delegate/stake.rs +++ b/src/commands/staking/delegate/stake.rs @@ -34,11 +34,9 @@ impl StakeContext { actions: vec![near_primitives::transaction::Action::FunctionCall( near_primitives::transaction::FunctionCallAction { method_name: "stake".to_string(), - args: serde_json::json!({ - "amount": amount.clone().to_yoctonear().to_string() - }) - .to_string() - .into_bytes(), + args: serde_json::to_vec(&serde_json::json!({ + "amount": amount.clone().to_yoctonear().to_string() + }))?, gas: crate::common::NearGas::from_tgas(300).as_gas(), deposit: 0, }, diff --git a/src/commands/staking/delegate/stake_all.rs b/src/commands/staking/delegate/stake_all.rs index 13f7d8fc7..d6185fd3f 100644 --- a/src/commands/staking/delegate/stake_all.rs +++ b/src/commands/staking/delegate/stake_all.rs @@ -31,7 +31,7 @@ impl StakeAllContext { actions: vec![near_primitives::transaction::Action::FunctionCall( near_primitives::transaction::FunctionCallAction { method_name: "stake_all".to_string(), - args: serde_json::json!({}).to_string().into_bytes(), + args: serde_json::to_vec(&serde_json::json!({}))?, gas: crate::common::NearGas::from_tgas(300).as_gas(), deposit: 0, }, diff --git a/src/commands/staking/delegate/unstake.rs b/src/commands/staking/delegate/unstake.rs index 88e5659e7..0853bebc6 100644 --- a/src/commands/staking/delegate/unstake.rs +++ b/src/commands/staking/delegate/unstake.rs @@ -34,11 +34,9 @@ impl UnstakeContext { actions: vec![near_primitives::transaction::Action::FunctionCall( near_primitives::transaction::FunctionCallAction { method_name: "unstake".to_string(), - args: serde_json::json!({ + args: serde_json::to_vec(&serde_json::json!({ "amount": amount.clone().to_yoctonear().to_string() - }) - .to_string() - .into_bytes(), + }))?, gas: crate::common::NearGas::from_tgas(300).as_gas(), deposit: 0, }, diff --git a/src/commands/staking/delegate/unstake_all.rs b/src/commands/staking/delegate/unstake_all.rs index 4b05ac84e..29756bab0 100644 --- a/src/commands/staking/delegate/unstake_all.rs +++ b/src/commands/staking/delegate/unstake_all.rs @@ -31,7 +31,7 @@ impl UnstakeAllContext { actions: vec![near_primitives::transaction::Action::FunctionCall( near_primitives::transaction::FunctionCallAction { method_name: "unstake_all".to_string(), - args: serde_json::json!({}).to_string().into_bytes(), + args: serde_json::to_vec(&serde_json::json!({}))?, gas: crate::common::NearGas::from_tgas(300).as_gas(), deposit: 0, }, diff --git a/src/commands/staking/delegate/view_balance.rs b/src/commands/staking/delegate/view_balance.rs index c66704445..c4d50b36d 100644 --- a/src/commands/staking/delegate/view_balance.rs +++ b/src/commands/staking/delegate/view_balance.rs @@ -77,11 +77,9 @@ pub fn get_user_staked_balance( .blocking_call_view_function( validator_account_id, "get_account_staked_balance", - serde_json::json!({ + serde_json::to_vec(&serde_json::json!({ "account_id": account_id, - }) - .to_string() - .into_bytes(), + }))?, block_reference.clone(), ) .wrap_err("Failed to fetch query for view method: 'get_account_staked_balance'")? @@ -101,11 +99,9 @@ pub fn get_user_unstaked_balance( .blocking_call_view_function( validator_account_id, "get_account_unstaked_balance", - serde_json::json!({ + serde_json::to_vec(&serde_json::json!({ "account_id": account_id, - }) - .to_string() - .into_bytes(), + }))?, block_reference.clone(), ) .wrap_err("Failed to fetch query for view method: 'get_account_unstaked_balance'")? @@ -125,11 +121,9 @@ pub fn get_user_total_balance( .blocking_call_view_function( validator_account_id, "get_account_total_balance", - serde_json::json!({ + serde_json::to_vec(&serde_json::json!({ "account_id": account_id, - }) - .to_string() - .into_bytes(), + }))?, block_reference.clone(), ) .wrap_err("Failed to fetch query for view method: 'get_account_total_balance'")? diff --git a/src/commands/staking/delegate/withdraw.rs b/src/commands/staking/delegate/withdraw.rs index 522620011..caa9ef060 100644 --- a/src/commands/staking/delegate/withdraw.rs +++ b/src/commands/staking/delegate/withdraw.rs @@ -39,11 +39,9 @@ impl WithdrawContext { .blocking_call_view_function( &previous_context.validator_account_id, "is_account_unstaked_balance_available", - serde_json::json!({ + serde_json::to_vec(&serde_json::json!({ "account_id": signer_id.to_string(), - }) - .to_string() - .into_bytes(), + }))?, near_primitives::types::BlockReference::Finality(near_primitives::types::Finality::Final), ) .wrap_err( @@ -64,11 +62,9 @@ impl WithdrawContext { actions: vec![near_primitives::transaction::Action::FunctionCall( near_primitives::transaction::FunctionCallAction { method_name: "withdraw".to_string(), - args: serde_json::json!({ + args: serde_json::to_vec(&serde_json::json!({ "amount": amount.clone().to_yoctonear().to_string() - }) - .to_string() - .into_bytes(), + }))?, gas: crate::common::NearGas::from_tgas(300).as_gas(), deposit: 0, }, diff --git a/src/commands/staking/delegate/withdraw_all.rs b/src/commands/staking/delegate/withdraw_all.rs index f1c499e4c..81491f304 100644 --- a/src/commands/staking/delegate/withdraw_all.rs +++ b/src/commands/staking/delegate/withdraw_all.rs @@ -36,11 +36,9 @@ impl WithdrawAllContext { .blocking_call_view_function( &previous_context.validator_account_id, "is_account_unstaked_balance_available", - serde_json::json!({ + serde_json::to_vec(&serde_json::json!({ "account_id": signer_id.to_string(), - }) - .to_string() - .into_bytes(), + }))?, near_primitives::types::BlockReference::Finality(near_primitives::types::Finality::Final), ) .wrap_err( @@ -62,7 +60,7 @@ impl WithdrawAllContext { actions: vec![near_primitives::transaction::Action::FunctionCall( near_primitives::transaction::FunctionCallAction { method_name: "withdraw_all".to_string(), - args: serde_json::json!({}).to_string().into_bytes(), + args: serde_json::to_vec(&serde_json::json!({}))?, gas: crate::common::NearGas::from_tgas(300).as_gas(), deposit: 0, }, diff --git a/src/commands/tokens/send_ft/mod.rs b/src/commands/tokens/send_ft/mod.rs index 10724e31b..60a4c0364 100644 --- a/src/commands/tokens/send_ft/mod.rs +++ b/src/commands/tokens/send_ft/mod.rs @@ -71,12 +71,10 @@ impl From for crate::commands::ActionContext { actions: vec![near_primitives::transaction::Action::FunctionCall( near_primitives::transaction::FunctionCallAction { method_name: "ft_transfer".to_string(), - args: json!({ + args: serde_json::to_vec(&json!({ "receiver_id": receiver_account_id.to_string(), "amount": item.amount.to_string() - }) - .to_string() - .into_bytes(), + }))?, gas: item.gas.as_gas(), deposit: item.deposit.to_yoctonear(), }, diff --git a/src/commands/tokens/send_nft/mod.rs b/src/commands/tokens/send_nft/mod.rs index c53c85823..5bf428f0d 100644 --- a/src/commands/tokens/send_nft/mod.rs +++ b/src/commands/tokens/send_nft/mod.rs @@ -72,12 +72,10 @@ impl From for crate::commands::ActionContext { actions: vec![near_primitives::transaction::Action::FunctionCall( near_primitives::transaction::FunctionCallAction { method_name: "nft_transfer".to_string(), - args: json!({ + args: serde_json::to_vec(&json!({ "receiver_id": receiver_account_id.to_string(), "token_id": token_id - }) - .to_string() - .into_bytes(), + }))?, gas: item.gas.as_gas(), deposit: item.deposit.to_yoctonear(), }, diff --git a/src/commands/tokens/view_ft_balance/mod.rs b/src/commands/tokens/view_ft_balance/mod.rs index a02555e53..dd7d87de4 100644 --- a/src/commands/tokens/view_ft_balance/mod.rs +++ b/src/commands/tokens/view_ft_balance/mod.rs @@ -34,11 +34,9 @@ impl ViewFtBalanceContext { network_config, block_reference.clone(), )?; - let args = json!({ + let args = serde_json::to_vec(&json!({ "account_id": owner_account_id.to_string(), - }) - .to_string() - .into_bytes(); + }))?; let call_result = network_config .json_rpc_client() .blocking_call_view_function( diff --git a/src/commands/tokens/view_nft_assets/mod.rs b/src/commands/tokens/view_nft_assets/mod.rs index d73341211..f5425ae41 100644 --- a/src/commands/tokens/view_nft_assets/mod.rs +++ b/src/commands/tokens/view_nft_assets/mod.rs @@ -29,11 +29,9 @@ impl ViewNftAssetsContext { scope.nft_contract_account_id.clone().into(); move |network_config, block_reference| { - let args = json!({ + let args = serde_json::to_vec(&json!({ "account_id": owner_account_id.to_string(), - }) - .to_string() - .into_bytes(); + }))?; let call_result = network_config .json_rpc_client() .blocking_call_view_function( From cf8cfb62a02d8b03f92a01bae02ea40d9394a81b Mon Sep 17 00:00:00 2001 From: FroVolod <36816899+FroVolod@users.noreply.github.com> Date: Sun, 22 Oct 2023 20:16:53 +0300 Subject: [PATCH 25/44] Update src/commands/staking/delegate/unstake.rs Co-authored-by: Vlad Frolov --- src/commands/staking/delegate/unstake.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/commands/staking/delegate/unstake.rs b/src/commands/staking/delegate/unstake.rs index 0853bebc6..8aac4df29 100644 --- a/src/commands/staking/delegate/unstake.rs +++ b/src/commands/staking/delegate/unstake.rs @@ -44,15 +44,16 @@ impl UnstakeContext { }) }); - let amount = scope.amount.clone(); - let on_after_sending_transaction_callback: crate::transaction_signature_options::OnAfterSendingTransactionCallback = std::sync::Arc::new( + let on_after_sending_transaction_callback: crate::transaction_signature_options::OnAfterSendingTransactionCallback = std::sync::Arc::new({ + let amount = scope.amount.clone(); + move |outcome_view, _network_config| { if let near_primitives::views::FinalExecutionStatus::SuccessValue(_) = outcome_view.status { eprintln!("<{signer}> has successfully unstake {amount} from <{validator_account_id}>.") } Ok(()) - }, - ); + } + }); Ok(Self(crate::commands::ActionContext { global_context: previous_context.global_context, interacting_with_account_ids, From 4d92ff30fc3f88c8b640f45c174b00700451a03f Mon Sep 17 00:00:00 2001 From: FroVolod Date: Mon, 23 Oct 2023 16:58:58 +0300 Subject: [PATCH 26/44] refactored get_validator_list() --- src/common.rs | 144 ++++++++++++++++++++++---------------------------- 1 file changed, 63 insertions(+), 81 deletions(-) diff --git a/src/common.rs b/src/common.rs index 4901f2553..5b191f1ba 100644 --- a/src/common.rs +++ b/src/common.rs @@ -1308,31 +1308,29 @@ pub fn get_validator_list( let runtime = tokio::runtime::Builder::new_multi_thread() .enable_all() .build()?; - let chunk_size = 15; let concurrency = 10; - let validators_table: std::collections::HashMap< - near_primitives::types::AccountId, - ValidatorsTable, - > = runtime - .block_on( - futures::stream::iter( - validators_stake - .iter() - .collect::>() - .chunks(chunk_size), - ) - .map(|validators| async { get_validators_table(&json_rpc_client, validators).await }) + let mut validator_list = runtime.block_on( + futures::stream::iter(validators_stake.iter()) + .map(|(validator_account_id, stake)| async { + let validators_table = get_validators_table( + &json_rpc_client.clone(), + &validator_account_id.clone(), + *stake, + ) + .await?; + Ok::<_, color_eyre::eyre::Report>(validators_table) + }) .buffer_unordered(concurrency) - .collect::>>(), - ) - .into_iter() - .try_fold(std::collections::HashMap::new(), |mut acc, x| { - acc.extend(x?); - Ok::<_, color_eyre::eyre::Error>(acc) - })?; - - let mut validator_list: Vec = validators_table.into_values().collect(); + .filter_map(|validators_table_result| { + futures::future::ready(if let Ok(validators_table) = validators_table_result { + Some(validators_table) + } else { + None + }) + }) + .collect::>(), + ); validator_list.sort_by(|a, b| b.stake.cmp(&a.stake)); Ok(validator_list) } @@ -1397,65 +1395,49 @@ pub fn get_validators_stake( async fn get_validators_table( json_rpc_client: &near_jsonrpc_client::JsonRpcClient, - validators: &[(&near_primitives::types::AccountId, &u128)], -) -> color_eyre::Result> -{ - let mut combine_validators: std::collections::HashMap< - near_primitives::types::AccountId, - ValidatorsTable, - > = std::collections::HashMap::new(); - for (validator_id, stake) in validators { - let validator_id = *validator_id; - let reward_fee_fraction = json_rpc_client - .call(near_jsonrpc_client::methods::query::RpcQueryRequest { - block_reference: near_primitives::types::Finality::Final.into(), - request: near_primitives::views::QueryRequest::CallFunction { - account_id: validator_id.clone(), - method_name: "get_reward_fee_fraction".to_string(), - args: near_primitives::types::FunctionArgs::from(vec![]), - }, - }) - .await - .wrap_err("Failed to fetch query for view method: 'get_reward_fee_fraction'"); - - if reward_fee_fraction.is_err() { - continue; - }; - let fee = reward_fee_fraction? - .call_result()? - .parse_result_from_json::() - .wrap_err( - "Failed to parse return value of view function call for RewardFeeFraction.", - )?; - - let number_of_accounts = json_rpc_client - .call(near_jsonrpc_client::methods::query::RpcQueryRequest { - block_reference: near_primitives::types::Finality::Final.into(), - request: near_primitives::views::QueryRequest::CallFunction { - account_id: validator_id.clone(), - method_name: "get_number_of_accounts".to_string(), - args: near_primitives::types::FunctionArgs::from(vec![]), - }, - }) - .await - .wrap_err("Failed to fetch query for view method: 'get_number_of_accounts'"); - if number_of_accounts.is_err() { - continue; - }; - let delegators = number_of_accounts? - .call_result()? - .parse_result_from_json::() - .wrap_err("Failed to parse return value of view function call for u64.")?; - - let validators_table = ValidatorsTable { - validator_id: validator_id.clone(), - fee, - delegators, - stake: **stake, - }; - combine_validators.insert(validator_id.clone(), validators_table); - } - Ok(combine_validators) + validator_account_id: &near_primitives::types::AccountId, + stake: u128, +) -> color_eyre::Result { + let reward_fee_fraction = json_rpc_client + .call(near_jsonrpc_client::methods::query::RpcQueryRequest { + block_reference: near_primitives::types::Finality::Final.into(), + request: near_primitives::views::QueryRequest::CallFunction { + account_id: validator_account_id.clone(), + method_name: "get_reward_fee_fraction".to_string(), + args: near_primitives::types::FunctionArgs::from(vec![]), + }, + }) + .await + .wrap_err("Failed to fetch query for view method: 'get_reward_fee_fraction'")?; + + let fee = reward_fee_fraction + .call_result()? + .parse_result_from_json::() + .wrap_err("Failed to parse return value of view function call for RewardFeeFraction.")?; + + let number_of_accounts = json_rpc_client + .call(near_jsonrpc_client::methods::query::RpcQueryRequest { + block_reference: near_primitives::types::Finality::Final.into(), + request: near_primitives::views::QueryRequest::CallFunction { + account_id: validator_account_id.clone(), + method_name: "get_number_of_accounts".to_string(), + args: near_primitives::types::FunctionArgs::from(vec![]), + }, + }) + .await + .wrap_err("Failed to fetch query for view method: 'get_number_of_accounts'")?; + + let delegators = number_of_accounts + .call_result()? + .parse_result_from_json::() + .wrap_err("Failed to parse return value of view function call for u64.")?; + + Ok(ValidatorsTable { + validator_id: validator_account_id.clone(), + fee, + delegators, + stake, + }) } pub fn display_account_info( From 1ebba517276e72d6c5c3440b892ccfdf6d020088 Mon Sep 17 00:00:00 2001 From: FroVolod Date: Tue, 24 Oct 2023 13:35:32 +0300 Subject: [PATCH 27/44] refactored --- src/commands/staking/delegate/deposit.rs | 28 +++++++++-------- .../staking/delegate/deposit_and_stake.rs | 28 +++++++++-------- src/commands/staking/delegate/mod.rs | 12 ++++---- src/commands/staking/delegate/stake.rs | 28 +++++++++-------- src/commands/staking/delegate/stake_all.rs | 28 +++++++++-------- src/commands/staking/delegate/unstake.rs | 28 +++++++++-------- src/commands/staking/delegate/unstake_all.rs | 28 +++++++++-------- src/commands/staking/delegate/view_balance.rs | 21 ++++++------- src/commands/staking/delegate/withdraw.rs | 30 +++++++++++-------- src/commands/staking/delegate/withdraw_all.rs | 30 +++++++++++-------- 10 files changed, 147 insertions(+), 114 deletions(-) diff --git a/src/commands/staking/delegate/deposit.rs b/src/commands/staking/delegate/deposit.rs index ee5faca19..af1990f10 100644 --- a/src/commands/staking/delegate/deposit.rs +++ b/src/commands/staking/delegate/deposit.rs @@ -5,8 +5,8 @@ pub struct Deposit { /// Enter the attached amount to be deposited into the predecessor's internal account (example: 10NEAR or 0.5near or 10000yoctonear): amount: crate::common::NearBalance, #[interactive_clap(skip_default_input_arg)] - /// What is the signer account ID? - signer_account_id: crate::types::account_id::AccountId, + /// What is validator account ID? + validator_account_id: crate::types::account_id::AccountId, #[interactive_clap(named_arg)] /// Select network network_config: crate::network_for_transaction::NetworkForTransactionArgs, @@ -20,17 +20,21 @@ impl DepositContext { previous_context: super::DelegateStakeContext, scope: &::InteractiveClapContextScope, ) -> color_eyre::eyre::Result { - let signer = scope.signer_account_id.clone(); - let signer_id: near_primitives::types::AccountId = scope.signer_account_id.clone().into(); - let validator_account_id = previous_context.validator_account_id.clone(); - let interacting_with_account_ids = vec![validator_account_id.clone()]; + let signer = previous_context.account_id.clone(); + let validator_account_id: near_primitives::types::AccountId = + scope.validator_account_id.clone().into(); + let validator_id = validator_account_id.clone(); + let interacting_with_account_ids = vec![ + previous_context.account_id.clone(), + validator_account_id.clone(), + ]; let amount = scope.amount.clone(); let on_after_getting_network_callback: crate::commands::OnAfterGettingNetworkCallback = std::sync::Arc::new(move |_network_config| { Ok(crate::commands::PrepopulatedTransaction { - signer_id: signer_id.clone(), - receiver_id: previous_context.validator_account_id.clone(), + signer_id: previous_context.account_id.clone(), + receiver_id: validator_account_id.clone(), actions: vec![near_primitives::transaction::Action::FunctionCall( near_primitives::transaction::FunctionCallAction { method_name: "deposit".to_string(), @@ -46,7 +50,7 @@ impl DepositContext { let on_after_sending_transaction_callback: crate::transaction_signature_options::OnAfterSendingTransactionCallback = std::sync::Arc::new( move |outcome_view, _network_config| { if let near_primitives::views::FinalExecutionStatus::SuccessValue(_) = outcome_view.status { - eprintln!("<{signer}> has successfully deposited {amount} on <{validator_account_id}>.") + eprintln!("<{signer}> has successfully deposited {amount} on <{validator_id}>.") } Ok(()) }, @@ -73,12 +77,12 @@ impl From for crate::commands::ActionContext { } impl Deposit { - pub fn input_signer_account_id( + pub fn input_validator_account_id( context: &super::DelegateStakeContext, ) -> color_eyre::eyre::Result> { - crate::common::input_signer_account_id_from_used_account_list( + crate::common::input_non_signer_account_id_from_used_account_list( &context.global_context.config.credentials_home_dir, - "What is the signer account ID?", + "What is validator account ID?", ) } } diff --git a/src/commands/staking/delegate/deposit_and_stake.rs b/src/commands/staking/delegate/deposit_and_stake.rs index aa4da76a7..fe61914ae 100644 --- a/src/commands/staking/delegate/deposit_and_stake.rs +++ b/src/commands/staking/delegate/deposit_and_stake.rs @@ -5,8 +5,8 @@ pub struct DepositAndStake { /// Enter the attached amount to be deposited and then staked into the predecessor's internal account (example: 10NEAR or 0.5near or 10000yoctonear): amount: crate::common::NearBalance, #[interactive_clap(skip_default_input_arg)] - /// What is the signer account ID? - signer_account_id: crate::types::account_id::AccountId, + /// What is validator account ID? + validator_account_id: crate::types::account_id::AccountId, #[interactive_clap(named_arg)] /// Select network network_config: crate::network_for_transaction::NetworkForTransactionArgs, @@ -20,17 +20,21 @@ impl DepositAndStakeContext { previous_context: super::DelegateStakeContext, scope: &::InteractiveClapContextScope, ) -> color_eyre::eyre::Result { - let signer = scope.signer_account_id.clone(); - let signer_id: near_primitives::types::AccountId = scope.signer_account_id.clone().into(); - let validator_account_id = previous_context.validator_account_id.clone(); - let interacting_with_account_ids = vec![validator_account_id.clone()]; + let signer = previous_context.account_id.clone(); + let validator_account_id: near_primitives::types::AccountId = + scope.validator_account_id.clone().into(); + let validator_id = validator_account_id.clone(); + let interacting_with_account_ids = vec![ + previous_context.account_id.clone(), + validator_account_id.clone(), + ]; let amount = scope.amount.clone(); let on_after_getting_network_callback: crate::commands::OnAfterGettingNetworkCallback = std::sync::Arc::new(move |_network_config| { Ok(crate::commands::PrepopulatedTransaction { - signer_id: signer_id.clone(), - receiver_id: previous_context.validator_account_id.clone(), + signer_id: previous_context.account_id.clone(), + receiver_id: validator_account_id.clone(), actions: vec![near_primitives::transaction::Action::FunctionCall( near_primitives::transaction::FunctionCallAction { method_name: "deposit_and_stake".to_string(), @@ -46,7 +50,7 @@ impl DepositAndStakeContext { let on_after_sending_transaction_callback: crate::transaction_signature_options::OnAfterSendingTransactionCallback = std::sync::Arc::new( move |outcome_view, _network_config| { if let near_primitives::views::FinalExecutionStatus::SuccessValue(_) = outcome_view.status { - eprintln!("<{signer}> has successfully deposited and staked {amount} on <{validator_account_id}>.") + eprintln!("<{signer}> has successfully deposited and staked {amount} on <{validator_id}>.") } Ok(()) }, @@ -73,12 +77,12 @@ impl From for crate::commands::ActionContext { } impl DepositAndStake { - pub fn input_signer_account_id( + pub fn input_validator_account_id( context: &super::DelegateStakeContext, ) -> color_eyre::eyre::Result> { - crate::common::input_signer_account_id_from_used_account_list( + crate::common::input_non_signer_account_id_from_used_account_list( &context.global_context.config.credentials_home_dir, - "What is the signer account ID?", + "What is validator account ID?", ) } } diff --git a/src/commands/staking/delegate/mod.rs b/src/commands/staking/delegate/mod.rs index e926b619c..2e2775331 100644 --- a/src/commands/staking/delegate/mod.rs +++ b/src/commands/staking/delegate/mod.rs @@ -15,8 +15,8 @@ mod withdraw_all; #[interactive_clap(output_context = DelegateStakeContext)] pub struct DelegateStake { #[interactive_clap(skip_default_input_arg)] - /// What is validator account ID? - validator_account_id: crate::types::account_id::AccountId, + /// Enter account ID to stake: + account_id: crate::types::account_id::AccountId, #[interactive_clap(subcommand)] delegate_stake_command: DelegateStakingCommand, } @@ -24,7 +24,7 @@ pub struct DelegateStake { #[derive(Debug, Clone)] pub struct DelegateStakeContext { global_context: crate::GlobalContext, - validator_account_id: near_primitives::types::AccountId, + account_id: near_primitives::types::AccountId, } impl DelegateStakeContext { @@ -34,18 +34,18 @@ impl DelegateStakeContext { ) -> color_eyre::eyre::Result { Ok(Self { global_context: previous_context, - validator_account_id: scope.validator_account_id.clone().into(), + account_id: scope.account_id.clone().into(), }) } } impl DelegateStake { - pub fn input_validator_account_id( + pub fn input_account_id( context: &crate::GlobalContext, ) -> color_eyre::eyre::Result> { crate::common::input_non_signer_account_id_from_used_account_list( &context.config.credentials_home_dir, - "What is validator account ID?", + "Enter account ID to stake:", ) } } diff --git a/src/commands/staking/delegate/stake.rs b/src/commands/staking/delegate/stake.rs index 2dec33a5f..b3234ec6c 100644 --- a/src/commands/staking/delegate/stake.rs +++ b/src/commands/staking/delegate/stake.rs @@ -5,8 +5,8 @@ pub struct Stake { /// Enter the amount to stake from the inner account of the predecessor (example: 10NEAR or 0.5near or 10000yoctonear): amount: crate::common::NearBalance, #[interactive_clap(skip_default_input_arg)] - /// What is the signer account ID? - signer_account_id: crate::types::account_id::AccountId, + /// What is validator account ID? + validator_account_id: crate::types::account_id::AccountId, #[interactive_clap(named_arg)] /// Select network network_config: crate::network_for_transaction::NetworkForTransactionArgs, @@ -20,17 +20,21 @@ impl StakeContext { previous_context: super::DelegateStakeContext, scope: &::InteractiveClapContextScope, ) -> color_eyre::eyre::Result { - let signer = scope.signer_account_id.clone(); - let signer_id: near_primitives::types::AccountId = scope.signer_account_id.clone().into(); - let validator_account_id = previous_context.validator_account_id.clone(); - let interacting_with_account_ids = vec![validator_account_id.clone()]; + let signer = previous_context.account_id.clone(); + let validator_account_id: near_primitives::types::AccountId = + scope.validator_account_id.clone().into(); + let validator_id = validator_account_id.clone(); + let interacting_with_account_ids = vec![ + previous_context.account_id.clone(), + validator_account_id.clone(), + ]; let amount = scope.amount.clone(); let on_after_getting_network_callback: crate::commands::OnAfterGettingNetworkCallback = std::sync::Arc::new(move |_network_config| { Ok(crate::commands::PrepopulatedTransaction { - signer_id: signer_id.clone(), - receiver_id: previous_context.validator_account_id.clone(), + signer_id: previous_context.account_id.clone(), + receiver_id: validator_account_id.clone(), actions: vec![near_primitives::transaction::Action::FunctionCall( near_primitives::transaction::FunctionCallAction { method_name: "stake".to_string(), @@ -48,7 +52,7 @@ impl StakeContext { let on_after_sending_transaction_callback: crate::transaction_signature_options::OnAfterSendingTransactionCallback = std::sync::Arc::new( move |outcome_view, _network_config| { if let near_primitives::views::FinalExecutionStatus::SuccessValue(_) = outcome_view.status { - eprintln!("<{signer}> has successfully stake {amount} on <{validator_account_id}>.") + eprintln!("<{signer}> has successfully stake {amount} on <{validator_id}>.") } Ok(()) }, @@ -75,12 +79,12 @@ impl From for crate::commands::ActionContext { } impl Stake { - pub fn input_signer_account_id( + pub fn input_validator_account_id( context: &super::DelegateStakeContext, ) -> color_eyre::eyre::Result> { - crate::common::input_signer_account_id_from_used_account_list( + crate::common::input_non_signer_account_id_from_used_account_list( &context.global_context.config.credentials_home_dir, - "What is the signer account ID?", + "What is validator account ID?", ) } } diff --git a/src/commands/staking/delegate/stake_all.rs b/src/commands/staking/delegate/stake_all.rs index d6185fd3f..f8a82b95c 100644 --- a/src/commands/staking/delegate/stake_all.rs +++ b/src/commands/staking/delegate/stake_all.rs @@ -3,8 +3,8 @@ #[interactive_clap(output_context = StakeAllContext)] pub struct StakeAll { #[interactive_clap(skip_default_input_arg)] - /// What is the signer account ID? - signer_account_id: crate::types::account_id::AccountId, + /// What is validator account ID? + validator_account_id: crate::types::account_id::AccountId, #[interactive_clap(named_arg)] /// Select network network_config: crate::network_for_transaction::NetworkForTransactionArgs, @@ -18,16 +18,20 @@ impl StakeAllContext { previous_context: super::DelegateStakeContext, scope: &::InteractiveClapContextScope, ) -> color_eyre::eyre::Result { - let signer = scope.signer_account_id.clone(); - let signer_id: near_primitives::types::AccountId = scope.signer_account_id.clone().into(); - let validator_account_id = previous_context.validator_account_id.clone(); - let interacting_with_account_ids = vec![validator_account_id.clone()]; + let signer = previous_context.account_id.clone(); + let validator_account_id: near_primitives::types::AccountId = + scope.validator_account_id.clone().into(); + let validator_id = validator_account_id.clone(); + let interacting_with_account_ids = vec![ + previous_context.account_id.clone(), + validator_account_id.clone(), + ]; let on_after_getting_network_callback: crate::commands::OnAfterGettingNetworkCallback = std::sync::Arc::new(move |_network_config| { Ok(crate::commands::PrepopulatedTransaction { - signer_id: signer_id.clone(), - receiver_id: previous_context.validator_account_id.clone(), + signer_id: previous_context.account_id.clone(), + receiver_id: validator_account_id.clone(), actions: vec![near_primitives::transaction::Action::FunctionCall( near_primitives::transaction::FunctionCallAction { method_name: "stake_all".to_string(), @@ -42,7 +46,7 @@ impl StakeAllContext { let on_after_sending_transaction_callback: crate::transaction_signature_options::OnAfterSendingTransactionCallback = std::sync::Arc::new( move |outcome_view, _network_config| { if let near_primitives::views::FinalExecutionStatus::SuccessValue(_) = outcome_view.status { - eprintln!("<{signer}> has successfully stake the entire amount on <{validator_account_id}>.") + eprintln!("<{signer}> has successfully stake the entire amount on <{validator_id}>.") } Ok(()) }, @@ -69,12 +73,12 @@ impl From for crate::commands::ActionContext { } impl StakeAll { - pub fn input_signer_account_id( + pub fn input_validator_account_id( context: &super::DelegateStakeContext, ) -> color_eyre::eyre::Result> { - crate::common::input_signer_account_id_from_used_account_list( + crate::common::input_non_signer_account_id_from_used_account_list( &context.global_context.config.credentials_home_dir, - "What is the signer account ID?", + "What is validator account ID?", ) } } diff --git a/src/commands/staking/delegate/unstake.rs b/src/commands/staking/delegate/unstake.rs index 8aac4df29..2183f85ee 100644 --- a/src/commands/staking/delegate/unstake.rs +++ b/src/commands/staking/delegate/unstake.rs @@ -5,8 +5,8 @@ pub struct Unstake { /// Enter the amount to unstake from the inner account of the predecessor (example: 10NEAR or 0.5near or 10000yoctonear): amount: crate::common::NearBalance, #[interactive_clap(skip_default_input_arg)] - /// What is the signer account ID? - signer_account_id: crate::types::account_id::AccountId, + /// What is validator account ID? + validator_account_id: crate::types::account_id::AccountId, #[interactive_clap(named_arg)] /// Select network network_config: crate::network_for_transaction::NetworkForTransactionArgs, @@ -20,17 +20,21 @@ impl UnstakeContext { previous_context: super::DelegateStakeContext, scope: &::InteractiveClapContextScope, ) -> color_eyre::eyre::Result { - let signer = scope.signer_account_id.clone(); - let signer_id: near_primitives::types::AccountId = scope.signer_account_id.clone().into(); - let validator_account_id = previous_context.validator_account_id.clone(); - let interacting_with_account_ids = vec![validator_account_id.clone()]; + let signer = previous_context.account_id.clone(); + let validator_account_id: near_primitives::types::AccountId = + scope.validator_account_id.clone().into(); + let validator_id = validator_account_id.clone(); + let interacting_with_account_ids = vec![ + previous_context.account_id.clone(), + validator_account_id.clone(), + ]; let amount = scope.amount.clone(); let on_after_getting_network_callback: crate::commands::OnAfterGettingNetworkCallback = std::sync::Arc::new(move |_network_config| { Ok(crate::commands::PrepopulatedTransaction { - signer_id: signer_id.clone(), - receiver_id: previous_context.validator_account_id.clone(), + signer_id: previous_context.account_id.clone(), + receiver_id: validator_account_id.clone(), actions: vec![near_primitives::transaction::Action::FunctionCall( near_primitives::transaction::FunctionCallAction { method_name: "unstake".to_string(), @@ -49,7 +53,7 @@ impl UnstakeContext { move |outcome_view, _network_config| { if let near_primitives::views::FinalExecutionStatus::SuccessValue(_) = outcome_view.status { - eprintln!("<{signer}> has successfully unstake {amount} from <{validator_account_id}>.") + eprintln!("<{signer}> has successfully unstake {amount} from <{validator_id}>.") } Ok(()) } @@ -76,12 +80,12 @@ impl From for crate::commands::ActionContext { } impl Unstake { - pub fn input_signer_account_id( + pub fn input_validator_account_id( context: &super::DelegateStakeContext, ) -> color_eyre::eyre::Result> { - crate::common::input_signer_account_id_from_used_account_list( + crate::common::input_non_signer_account_id_from_used_account_list( &context.global_context.config.credentials_home_dir, - "What is the signer account ID?", + "What is validator account ID?", ) } } diff --git a/src/commands/staking/delegate/unstake_all.rs b/src/commands/staking/delegate/unstake_all.rs index 29756bab0..4479cb605 100644 --- a/src/commands/staking/delegate/unstake_all.rs +++ b/src/commands/staking/delegate/unstake_all.rs @@ -3,8 +3,8 @@ #[interactive_clap(output_context = UnstakeAllContext)] pub struct UnstakeAll { #[interactive_clap(skip_default_input_arg)] - /// What is the signer account ID? - signer_account_id: crate::types::account_id::AccountId, + /// What is validator account ID? + validator_account_id: crate::types::account_id::AccountId, #[interactive_clap(named_arg)] /// Select network network_config: crate::network_for_transaction::NetworkForTransactionArgs, @@ -18,16 +18,20 @@ impl UnstakeAllContext { previous_context: super::DelegateStakeContext, scope: &::InteractiveClapContextScope, ) -> color_eyre::eyre::Result { - let signer = scope.signer_account_id.clone(); - let signer_id: near_primitives::types::AccountId = scope.signer_account_id.clone().into(); - let validator_account_id = previous_context.validator_account_id.clone(); - let interacting_with_account_ids = vec![validator_account_id.clone()]; + let signer = previous_context.account_id.clone(); + let validator_account_id: near_primitives::types::AccountId = + scope.validator_account_id.clone().into(); + let validator_id = validator_account_id.clone(); + let interacting_with_account_ids = vec![ + previous_context.account_id.clone(), + validator_account_id.clone(), + ]; let on_after_getting_network_callback: crate::commands::OnAfterGettingNetworkCallback = std::sync::Arc::new(move |_network_config| { Ok(crate::commands::PrepopulatedTransaction { - signer_id: signer_id.clone(), - receiver_id: previous_context.validator_account_id.clone(), + signer_id: previous_context.account_id.clone(), + receiver_id: validator_account_id.clone(), actions: vec![near_primitives::transaction::Action::FunctionCall( near_primitives::transaction::FunctionCallAction { method_name: "unstake_all".to_string(), @@ -42,7 +46,7 @@ impl UnstakeAllContext { let on_after_sending_transaction_callback: crate::transaction_signature_options::OnAfterSendingTransactionCallback = std::sync::Arc::new( move |outcome_view, _network_config| { if let near_primitives::views::FinalExecutionStatus::SuccessValue(_) = outcome_view.status { - eprintln!("<{signer}> has successfully unstake the entire amount from <{validator_account_id}>.") + eprintln!("<{signer}> has successfully unstake the entire amount from <{validator_id}>.") } Ok(()) }, @@ -69,12 +73,12 @@ impl From for crate::commands::ActionContext { } impl UnstakeAll { - pub fn input_signer_account_id( + pub fn input_validator_account_id( context: &super::DelegateStakeContext, ) -> color_eyre::eyre::Result> { - crate::common::input_signer_account_id_from_used_account_list( + crate::common::input_non_signer_account_id_from_used_account_list( &context.global_context.config.credentials_home_dir, - "What is the signer account ID?", + "What is validator account ID?", ) } } diff --git a/src/commands/staking/delegate/view_balance.rs b/src/commands/staking/delegate/view_balance.rs index c4d50b36d..54ee1293b 100644 --- a/src/commands/staking/delegate/view_balance.rs +++ b/src/commands/staking/delegate/view_balance.rs @@ -7,8 +7,8 @@ use crate::common::{CallResultExt, JsonRpcClientExt}; #[interactive_clap(output_context = ViewBalanceContext)] pub struct ViewBalance { #[interactive_clap(skip_default_input_arg)] - /// On which account ID do you need to view the total balance? - account_id: crate::types::account_id::AccountId, + /// What is validator account ID? + validator_account_id: crate::types::account_id::AccountId, #[interactive_clap(named_arg)] /// Select network network_config: crate::network_view_at_block::NetworkViewAtBlockArgs, @@ -22,16 +22,17 @@ impl ViewBalanceContext { previous_context: super::DelegateStakeContext, scope: &::InteractiveClapContextScope, ) -> color_eyre::eyre::Result { - let validator_account_id = previous_context.validator_account_id.clone(); - let interacting_with_account_ids = vec![validator_account_id.clone()]; + let account_id = previous_context.account_id.clone(); + let validator_account_id: near_primitives::types::AccountId = + scope.validator_account_id.clone().into(); + let interacting_with_account_ids = vec![account_id.clone(), validator_account_id.clone()]; let on_after_getting_block_reference_callback: crate::network_view_at_block::OnAfterGettingBlockReferenceCallback = std::sync::Arc::new({ - let account_id: near_primitives::types::AccountId = scope.account_id.clone().into(); move |network_config, block_reference| { - let user_staked_balance: u128 = get_user_staked_balance(network_config, block_reference, &previous_context.validator_account_id, &account_id)?; - let user_unstaked_balance: u128 = get_user_unstaked_balance(network_config, block_reference, &previous_context.validator_account_id, &account_id)?; - let user_total_balance: u128 = get_user_total_balance(network_config, block_reference, &previous_context.validator_account_id, &account_id)?; + let user_staked_balance: u128 = get_user_staked_balance(network_config, block_reference, &validator_account_id, &account_id)?; + let user_unstaked_balance: u128 = get_user_unstaked_balance(network_config, block_reference, &validator_account_id, &account_id)?; + let user_total_balance: u128 = get_user_total_balance(network_config, block_reference, &validator_account_id, &account_id)?; eprintln!("Balance on validator <{validator_account_id}> for <{account_id}>:"); eprintln!(" Staked balance: {:>38}", crate::common::NearBalance::from_yoctonear(user_staked_balance).to_string()); @@ -56,12 +57,12 @@ impl From for crate::network_view_at_block::ArgsForViewConte } impl ViewBalance { - pub fn input_account_id( + pub fn input_validator_account_id( context: &super::DelegateStakeContext, ) -> color_eyre::eyre::Result> { crate::common::input_non_signer_account_id_from_used_account_list( &context.global_context.config.credentials_home_dir, - "On which account ID do you need to view the total balance?", + "What is validator account ID?", ) } } diff --git a/src/commands/staking/delegate/withdraw.rs b/src/commands/staking/delegate/withdraw.rs index caa9ef060..27f3da34a 100644 --- a/src/commands/staking/delegate/withdraw.rs +++ b/src/commands/staking/delegate/withdraw.rs @@ -9,8 +9,8 @@ pub struct Withdraw { /// Enter the amount to withdraw from the non staked balance (example: 10NEAR or 0.5near or 10000yoctonear): amount: crate::common::NearBalance, #[interactive_clap(skip_default_input_arg)] - /// What is the signer account ID? - signer_account_id: crate::types::account_id::AccountId, + /// What is validator account ID? + validator_account_id: crate::types::account_id::AccountId, #[interactive_clap(named_arg)] /// Select network network_config: crate::network_for_transaction::NetworkForTransactionArgs, @@ -24,20 +24,24 @@ impl WithdrawContext { previous_context: super::DelegateStakeContext, scope: &::InteractiveClapContextScope, ) -> color_eyre::eyre::Result { - let validator_account_id = previous_context.validator_account_id.clone(); - let interacting_with_account_ids = vec![validator_account_id.clone()]; + let validator_account_id: near_primitives::types::AccountId = + scope.validator_account_id.clone().into(); + let validator_id = validator_account_id.clone(); + let interacting_with_account_ids = vec![ + previous_context.account_id.clone(), + validator_account_id.clone(), + ]; let on_after_getting_network_callback: crate::commands::OnAfterGettingNetworkCallback = std::sync::Arc::new({ + let signer_id = previous_context.account_id.clone(); let amount = scope.amount.clone(); - let signer_id: near_primitives::types::AccountId = - scope.signer_account_id.clone().into(); move |network_config| { let is_account_unstaked_balance_available = network_config .json_rpc_client() .blocking_call_view_function( - &previous_context.validator_account_id, + &validator_account_id, "is_account_unstaked_balance_available", serde_json::to_vec(&serde_json::json!({ "account_id": signer_id.to_string(), @@ -58,7 +62,7 @@ impl WithdrawContext { } Ok(crate::commands::PrepopulatedTransaction { signer_id: signer_id.clone(), - receiver_id: previous_context.validator_account_id.clone(), + receiver_id: validator_account_id.clone(), actions: vec![near_primitives::transaction::Action::FunctionCall( near_primitives::transaction::FunctionCallAction { method_name: "withdraw".to_string(), @@ -75,11 +79,11 @@ impl WithdrawContext { let on_after_sending_transaction_callback: crate::transaction_signature_options::OnAfterSendingTransactionCallback = std::sync::Arc::new({ let amount = scope.amount.clone(); - let signer = scope.signer_account_id.clone(); + let signer_id = previous_context.account_id.clone(); move |outcome_view, _network_config| { if let near_primitives::views::FinalExecutionStatus::SuccessValue(_) = outcome_view.status { - eprintln!("<{signer}> has successfully withdrawn {amount} from <{validator_account_id}>.") + eprintln!("<{signer_id}> has successfully withdrawn {amount} from <{validator_id}>.") } Ok(()) } @@ -106,12 +110,12 @@ impl From for crate::commands::ActionContext { } impl Withdraw { - pub fn input_signer_account_id( + pub fn input_validator_account_id( context: &super::DelegateStakeContext, ) -> color_eyre::eyre::Result> { - crate::common::input_signer_account_id_from_used_account_list( + crate::common::input_non_signer_account_id_from_used_account_list( &context.global_context.config.credentials_home_dir, - "What is the signer account ID?", + "What is validator account ID?", ) } } diff --git a/src/commands/staking/delegate/withdraw_all.rs b/src/commands/staking/delegate/withdraw_all.rs index 81491f304..af030c93f 100644 --- a/src/commands/staking/delegate/withdraw_all.rs +++ b/src/commands/staking/delegate/withdraw_all.rs @@ -7,8 +7,8 @@ use crate::common::{CallResultExt, JsonRpcClientExt}; #[interactive_clap(output_context = WithdrawAllContext)] pub struct WithdrawAll { #[interactive_clap(skip_default_input_arg)] - /// What is the signer account ID? - signer_account_id: crate::types::account_id::AccountId, + /// What is validator account ID? + validator_account_id: crate::types::account_id::AccountId, #[interactive_clap(named_arg)] /// Select network network_config: crate::network_for_transaction::NetworkForTransactionArgs, @@ -22,19 +22,23 @@ impl WithdrawAllContext { previous_context: super::DelegateStakeContext, scope: &::InteractiveClapContextScope, ) -> color_eyre::eyre::Result { - let validator_account_id = previous_context.validator_account_id.clone(); - let interacting_with_account_ids = vec![validator_account_id.clone()]; + let validator_account_id: near_primitives::types::AccountId = + scope.validator_account_id.clone().into(); + let validator_id = validator_account_id.clone(); + let interacting_with_account_ids = vec![ + previous_context.account_id.clone(), + validator_account_id.clone(), + ]; let on_after_getting_network_callback: crate::commands::OnAfterGettingNetworkCallback = std::sync::Arc::new({ - let signer_id: near_primitives::types::AccountId = - scope.signer_account_id.clone().into(); + let signer_id = previous_context.account_id.clone(); move |network_config| { let is_account_unstaked_balance_available = network_config .json_rpc_client() .blocking_call_view_function( - &previous_context.validator_account_id, + &validator_account_id, "is_account_unstaked_balance_available", serde_json::to_vec(&serde_json::json!({ "account_id": signer_id.to_string(), @@ -56,7 +60,7 @@ impl WithdrawAllContext { Ok(crate::commands::PrepopulatedTransaction { signer_id: signer_id.clone(), - receiver_id: previous_context.validator_account_id.clone(), + receiver_id: validator_account_id.clone(), actions: vec![near_primitives::transaction::Action::FunctionCall( near_primitives::transaction::FunctionCallAction { method_name: "withdraw_all".to_string(), @@ -70,11 +74,11 @@ impl WithdrawAllContext { }); let on_after_sending_transaction_callback: crate::transaction_signature_options::OnAfterSendingTransactionCallback = std::sync::Arc::new({ - let signer = scope.signer_account_id.clone(); + let signer_id = previous_context.account_id.clone(); move |outcome_view, _network_config| { if let near_primitives::views::FinalExecutionStatus::SuccessValue(_) = outcome_view.status { - eprintln!("<{signer}> has successfully withdrawn the entire amount from <{validator_account_id}>.") + eprintln!("<{signer_id}> has successfully withdrawn the entire amount from <{validator_id}>.") } Ok(()) } @@ -101,12 +105,12 @@ impl From for crate::commands::ActionContext { } impl WithdrawAll { - pub fn input_signer_account_id( + pub fn input_validator_account_id( context: &super::DelegateStakeContext, ) -> color_eyre::eyre::Result> { - crate::common::input_signer_account_id_from_used_account_list( + crate::common::input_non_signer_account_id_from_used_account_list( &context.global_context.config.credentials_home_dir, - "What is the signer account ID?", + "What is validator account ID?", ) } } From 1645264e8a01de0579f9b45ebf5947f898ede659 Mon Sep 17 00:00:00 2001 From: FroVolod Date: Tue, 24 Oct 2023 14:29:34 +0300 Subject: [PATCH 28/44] updated input_account_id() --- src/commands/staking/delegate/mod.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/commands/staking/delegate/mod.rs b/src/commands/staking/delegate/mod.rs index 2e2775331..bc33f2819 100644 --- a/src/commands/staking/delegate/mod.rs +++ b/src/commands/staking/delegate/mod.rs @@ -15,7 +15,7 @@ mod withdraw_all; #[interactive_clap(output_context = DelegateStakeContext)] pub struct DelegateStake { #[interactive_clap(skip_default_input_arg)] - /// Enter account ID to stake: + /// Enter the account that you want to manage delegated stake for: account_id: crate::types::account_id::AccountId, #[interactive_clap(subcommand)] delegate_stake_command: DelegateStakingCommand, @@ -45,7 +45,7 @@ impl DelegateStake { ) -> color_eyre::eyre::Result> { crate::common::input_non_signer_account_id_from_used_account_list( &context.config.credentials_home_dir, - "Enter account ID to stake:", + "Enter the account that you want to manage delegated stake for:", ) } } From 205d93a7ac0c9b79a269308aa9cd9c719a4cfc3d Mon Sep 17 00:00:00 2001 From: FroVolod Date: Wed, 25 Oct 2023 12:04:28 +0300 Subject: [PATCH 29/44] refactored get_validator_list() --- src/commands/staking/validator_list/mod.rs | 14 +++- src/common.rs | 88 +++++++++++++--------- 2 files changed, 64 insertions(+), 38 deletions(-) diff --git a/src/commands/staking/validator_list/mod.rs b/src/commands/staking/validator_list/mod.rs index f95896739..399de06fb 100644 --- a/src/commands/staking/validator_list/mod.rs +++ b/src/commands/staking/validator_list/mod.rs @@ -41,11 +41,21 @@ fn display_validators_info(network_config: &crate::config::NetworkConfig) -> cra .into_iter() .enumerate() { + let fee = if let Some(fee) = validator.fee { + format!("{:>6.2} %", fee.numerator * 100 / fee.denominator) + } else { + format!("{:>6}", "N/A") + }; + let delegators = if let Some(num) = validator.delegators { + format!("{:>8}", num) + } else { + format!("{:>8}", "N/A") + }; table.add_row(prettytable::row![ Fg->index + 1, validator.validator_id, - format!("{:>6.2} %", validator.fee.numerator * 100 / validator.fee.denominator), - validator.delegators, + fee, + delegators, crate::common::NearBalance::from_yoctonear(validator.stake), ]); } diff --git a/src/common.rs b/src/common.rs index 5b191f1ba..9ccc6693a 100644 --- a/src/common.rs +++ b/src/common.rs @@ -4,7 +4,7 @@ use std::io::Write; use std::str::FromStr; use color_eyre::eyre::WrapErr; -use futures::StreamExt; +use futures::{StreamExt, TryStreamExt}; use prettytable::Table; use near_primitives::{hash::CryptoHash, types::BlockReference, views::AccessKeyPermissionView}; @@ -1285,10 +1285,10 @@ fn path_directories() -> Vec { } #[derive(Debug, Clone, PartialEq, Eq)] -pub struct ValidatorsTable { +pub struct StakingPoolInfo { pub validator_id: near_primitives::types::AccountId, - pub fee: RewardFeeFraction, - pub delegators: u64, + pub fee: Option, + pub delegators: Option, pub stake: near_primitives::types::Balance, } @@ -1300,7 +1300,7 @@ pub struct RewardFeeFraction { pub fn get_validator_list( network_config: &crate::config::NetworkConfig, -) -> color_eyre::eyre::Result> { +) -> color_eyre::eyre::Result> { let json_rpc_client = network_config.json_rpc_client(); let validators_stake = get_validators_stake(&json_rpc_client)?; @@ -1313,24 +1313,16 @@ pub fn get_validator_list( let mut validator_list = runtime.block_on( futures::stream::iter(validators_stake.iter()) .map(|(validator_account_id, stake)| async { - let validators_table = get_validators_table( + get_staking_pool_info( &json_rpc_client.clone(), - &validator_account_id.clone(), + validator_account_id.clone(), *stake, ) - .await?; - Ok::<_, color_eyre::eyre::Report>(validators_table) + .await }) .buffer_unordered(concurrency) - .filter_map(|validators_table_result| { - futures::future::ready(if let Ok(validators_table) = validators_table_result { - Some(validators_table) - } else { - None - }) - }) - .collect::>(), - ); + .try_collect::>(), + )?; validator_list.sort_by(|a, b| b.stake.cmp(&a.stake)); Ok(validator_list) } @@ -1393,12 +1385,12 @@ pub fn get_validators_stake( Ok(current_validators_stake) } -async fn get_validators_table( +async fn get_staking_pool_info( json_rpc_client: &near_jsonrpc_client::JsonRpcClient, - validator_account_id: &near_primitives::types::AccountId, + validator_account_id: near_primitives::types::AccountId, stake: u128, -) -> color_eyre::Result { - let reward_fee_fraction = json_rpc_client +) -> color_eyre::Result { + let fee = match json_rpc_client .call(near_jsonrpc_client::methods::query::RpcQueryRequest { block_reference: near_primitives::types::Finality::Final.into(), request: near_primitives::views::QueryRequest::CallFunction { @@ -1408,14 +1400,27 @@ async fn get_validators_table( }, }) .await - .wrap_err("Failed to fetch query for view method: 'get_reward_fee_fraction'")?; - - let fee = reward_fee_fraction - .call_result()? - .parse_result_from_json::() - .wrap_err("Failed to parse return value of view function call for RewardFeeFraction.")?; + { + Ok(response) => Some( + response + .call_result()? + .parse_result_from_json::() + .wrap_err( + "Failed to parse return value of view function call for RewardFeeFraction.", + )?, + ), + Err(near_jsonrpc_client::errors::JsonRpcError::ServerError( + near_jsonrpc_client::errors::JsonRpcServerError::HandlerError( + near_jsonrpc_client::methods::query::RpcQueryError::NoContractCode { .. } + | near_jsonrpc_client::methods::query::RpcQueryError::ContractExecutionError { + .. + }, + ), + )) => None, + Err(err) => return Err(err.into()), + }; - let number_of_accounts = json_rpc_client + let delegators = match json_rpc_client .call(near_jsonrpc_client::methods::query::RpcQueryRequest { block_reference: near_primitives::types::Finality::Final.into(), request: near_primitives::views::QueryRequest::CallFunction { @@ -1425,14 +1430,25 @@ async fn get_validators_table( }, }) .await - .wrap_err("Failed to fetch query for view method: 'get_number_of_accounts'")?; - - let delegators = number_of_accounts - .call_result()? - .parse_result_from_json::() - .wrap_err("Failed to parse return value of view function call for u64.")?; + { + Ok(response) => Some( + response + .call_result()? + .parse_result_from_json::() + .wrap_err("Failed to parse return value of view function call for u64.")?, + ), + Err(near_jsonrpc_client::errors::JsonRpcError::ServerError( + near_jsonrpc_client::errors::JsonRpcServerError::HandlerError( + near_jsonrpc_client::methods::query::RpcQueryError::NoContractCode { .. } + | near_jsonrpc_client::methods::query::RpcQueryError::ContractExecutionError { + .. + }, + ), + )) => None, + Err(err) => return Err(err.into()), + }; - Ok(ValidatorsTable { + Ok(StakingPoolInfo { validator_id: validator_account_id.clone(), fee, delegators, From 3038d6174867855156ead7916e215e3ab2c02098 Mon Sep 17 00:00:00 2001 From: FroVolod Date: Wed, 25 Oct 2023 17:17:50 +0300 Subject: [PATCH 30/44] added get_used_delegated_validator_list() --- src/commands/staking/delegate/deposit.rs | 3 +- .../staking/delegate/deposit_and_stake.rs | 3 +- src/commands/staking/delegate/mod.rs | 5 + src/commands/staking/delegate/stake.rs | 3 +- src/commands/staking/delegate/stake_all.rs | 3 +- src/commands/staking/delegate/unstake.rs | 3 +- src/commands/staking/delegate/unstake_all.rs | 3 +- src/commands/staking/delegate/view_balance.rs | 3 +- src/commands/staking/delegate/withdraw.rs | 3 +- src/commands/staking/delegate/withdraw_all.rs | 3 +- src/common.rs | 134 ++++++++++++++++++ 11 files changed, 148 insertions(+), 18 deletions(-) diff --git a/src/commands/staking/delegate/deposit.rs b/src/commands/staking/delegate/deposit.rs index af1990f10..fea65d2a6 100644 --- a/src/commands/staking/delegate/deposit.rs +++ b/src/commands/staking/delegate/deposit.rs @@ -80,9 +80,8 @@ impl Deposit { pub fn input_validator_account_id( context: &super::DelegateStakeContext, ) -> color_eyre::eyre::Result> { - crate::common::input_non_signer_account_id_from_used_account_list( + crate::common::input_delegated_validator_account_id_from_used_delegated_validator_list( &context.global_context.config.credentials_home_dir, - "What is validator account ID?", ) } } diff --git a/src/commands/staking/delegate/deposit_and_stake.rs b/src/commands/staking/delegate/deposit_and_stake.rs index fe61914ae..853803977 100644 --- a/src/commands/staking/delegate/deposit_and_stake.rs +++ b/src/commands/staking/delegate/deposit_and_stake.rs @@ -80,9 +80,8 @@ impl DepositAndStake { pub fn input_validator_account_id( context: &super::DelegateStakeContext, ) -> color_eyre::eyre::Result> { - crate::common::input_non_signer_account_id_from_used_account_list( + crate::common::input_delegated_validator_account_id_from_used_delegated_validator_list( &context.global_context.config.credentials_home_dir, - "What is validator account ID?", ) } } diff --git a/src/commands/staking/delegate/mod.rs b/src/commands/staking/delegate/mod.rs index bc33f2819..5b593bc71 100644 --- a/src/commands/staking/delegate/mod.rs +++ b/src/commands/staking/delegate/mod.rs @@ -32,6 +32,11 @@ impl DelegateStakeContext { previous_context: crate::GlobalContext, scope: &::InteractiveClapContextScope, ) -> color_eyre::eyre::Result { + if !crate::common::is_used_delegated_validator_list_exist( + &previous_context.config.credentials_home_dir, + ) { + crate::common::create_used_delegated_validator_list(&previous_context.config)?; + } Ok(Self { global_context: previous_context, account_id: scope.account_id.clone().into(), diff --git a/src/commands/staking/delegate/stake.rs b/src/commands/staking/delegate/stake.rs index b3234ec6c..933b9375f 100644 --- a/src/commands/staking/delegate/stake.rs +++ b/src/commands/staking/delegate/stake.rs @@ -82,9 +82,8 @@ impl Stake { pub fn input_validator_account_id( context: &super::DelegateStakeContext, ) -> color_eyre::eyre::Result> { - crate::common::input_non_signer_account_id_from_used_account_list( + crate::common::input_delegated_validator_account_id_from_used_delegated_validator_list( &context.global_context.config.credentials_home_dir, - "What is validator account ID?", ) } } diff --git a/src/commands/staking/delegate/stake_all.rs b/src/commands/staking/delegate/stake_all.rs index f8a82b95c..2c53269ba 100644 --- a/src/commands/staking/delegate/stake_all.rs +++ b/src/commands/staking/delegate/stake_all.rs @@ -76,9 +76,8 @@ impl StakeAll { pub fn input_validator_account_id( context: &super::DelegateStakeContext, ) -> color_eyre::eyre::Result> { - crate::common::input_non_signer_account_id_from_used_account_list( + crate::common::input_delegated_validator_account_id_from_used_delegated_validator_list( &context.global_context.config.credentials_home_dir, - "What is validator account ID?", ) } } diff --git a/src/commands/staking/delegate/unstake.rs b/src/commands/staking/delegate/unstake.rs index 2183f85ee..42fd8f89c 100644 --- a/src/commands/staking/delegate/unstake.rs +++ b/src/commands/staking/delegate/unstake.rs @@ -83,9 +83,8 @@ impl Unstake { pub fn input_validator_account_id( context: &super::DelegateStakeContext, ) -> color_eyre::eyre::Result> { - crate::common::input_non_signer_account_id_from_used_account_list( + crate::common::input_delegated_validator_account_id_from_used_delegated_validator_list( &context.global_context.config.credentials_home_dir, - "What is validator account ID?", ) } } diff --git a/src/commands/staking/delegate/unstake_all.rs b/src/commands/staking/delegate/unstake_all.rs index 4479cb605..9b218df47 100644 --- a/src/commands/staking/delegate/unstake_all.rs +++ b/src/commands/staking/delegate/unstake_all.rs @@ -76,9 +76,8 @@ impl UnstakeAll { pub fn input_validator_account_id( context: &super::DelegateStakeContext, ) -> color_eyre::eyre::Result> { - crate::common::input_non_signer_account_id_from_used_account_list( + crate::common::input_delegated_validator_account_id_from_used_delegated_validator_list( &context.global_context.config.credentials_home_dir, - "What is validator account ID?", ) } } diff --git a/src/commands/staking/delegate/view_balance.rs b/src/commands/staking/delegate/view_balance.rs index 54ee1293b..b1f18835a 100644 --- a/src/commands/staking/delegate/view_balance.rs +++ b/src/commands/staking/delegate/view_balance.rs @@ -60,9 +60,8 @@ impl ViewBalance { pub fn input_validator_account_id( context: &super::DelegateStakeContext, ) -> color_eyre::eyre::Result> { - crate::common::input_non_signer_account_id_from_used_account_list( + crate::common::input_delegated_validator_account_id_from_used_delegated_validator_list( &context.global_context.config.credentials_home_dir, - "What is validator account ID?", ) } } diff --git a/src/commands/staking/delegate/withdraw.rs b/src/commands/staking/delegate/withdraw.rs index 27f3da34a..70f07a8c2 100644 --- a/src/commands/staking/delegate/withdraw.rs +++ b/src/commands/staking/delegate/withdraw.rs @@ -113,9 +113,8 @@ impl Withdraw { pub fn input_validator_account_id( context: &super::DelegateStakeContext, ) -> color_eyre::eyre::Result> { - crate::common::input_non_signer_account_id_from_used_account_list( + crate::common::input_delegated_validator_account_id_from_used_delegated_validator_list( &context.global_context.config.credentials_home_dir, - "What is validator account ID?", ) } } diff --git a/src/commands/staking/delegate/withdraw_all.rs b/src/commands/staking/delegate/withdraw_all.rs index af030c93f..0acb7eef6 100644 --- a/src/commands/staking/delegate/withdraw_all.rs +++ b/src/commands/staking/delegate/withdraw_all.rs @@ -108,9 +108,8 @@ impl WithdrawAll { pub fn input_validator_account_id( context: &super::DelegateStakeContext, ) -> color_eyre::eyre::Result> { - crate::common::input_non_signer_account_id_from_used_account_list( + crate::common::input_delegated_validator_account_id_from_used_delegated_validator_list( &context.global_context.config.credentials_home_dir, - "What is validator account ID?", ) } } diff --git a/src/common.rs b/src/common.rs index 9ccc6693a..a7f769cb3 100644 --- a/src/common.rs +++ b/src/common.rs @@ -1284,6 +1284,140 @@ fn path_directories() -> Vec { dirs } +pub fn get_delegated_validator_list_from_network( + network_config: &crate::config::NetworkConfig, +) -> color_eyre::eyre::Result> { + Ok(get_validator_list(network_config)? + .into_iter() + .filter(|staking_pool_info| staking_pool_info.delegators.is_some()) + .map(|staking_pool_info| staking_pool_info.validator_id) + .collect::>()) +} + +fn get_used_delegated_validator_list_path( + credentials_home_dir: &std::path::Path, +) -> std::path::PathBuf { + credentials_home_dir.join("delegated_validators.json") +} + +pub fn create_used_delegated_validator_list(config: &crate::config::Config) -> CliResult { + let mut used_delegated_validator_list: std::collections::BTreeSet< + near_primitives::types::AccountId, + > = std::collections::BTreeSet::new(); + + for network_config in config.network_connection.values() { + let used_delegated_validators = get_delegated_validator_list_from_network(network_config)?; + for validator_account_id in used_delegated_validators { + used_delegated_validator_list.insert(validator_account_id); + } + } + + if !used_delegated_validator_list.is_empty() { + let used_delegated_validator_list_path = + get_used_delegated_validator_list_path(&config.credentials_home_dir); + let used_delegated_validator_list_buf = serde_json::to_string( + &used_delegated_validator_list + .into_iter() + .map(String::from) + .collect::>(), + )?; + std::fs::write( + &used_delegated_validator_list_path, + used_delegated_validator_list_buf, + ) + .wrap_err_with(|| { + format!( + "Failed to write to file: {}", + used_delegated_validator_list_path.display() + ) + })?; + } + Ok(()) +} + +pub fn get_used_delegated_validator_list( + credentials_home_dir: &std::path::Path, +) -> VecDeque { + serde_json::from_str( + std::fs::read_to_string(get_used_delegated_validator_list_path(credentials_home_dir)) + .as_deref() + .unwrap_or("[]"), + ) + .unwrap_or_default() +} + +pub fn update_used_delegated_validator_list( + credentials_home_dir: &std::path::Path, + validator_account_id: &near_primitives::types::AccountId, +) { + let mut used_delegated_validator_list = get_used_delegated_validator_list(credentials_home_dir); + + let used_validator_account_id = if let Some(used_validator_account_id) = + used_delegated_validator_list + .iter() + .position(|used_account| used_account == validator_account_id) + .and_then(|position| used_delegated_validator_list.remove(position)) + { + used_validator_account_id + } else { + validator_account_id.clone() + }; + used_delegated_validator_list.push_front(used_validator_account_id); + + let used_delegated_validator_list_path = + get_used_delegated_validator_list_path(credentials_home_dir); + if let Ok(used_delegated_validator_list_buf) = + serde_json::to_string(&used_delegated_validator_list) + { + let _ = std::fs::write( + used_delegated_validator_list_path, + used_delegated_validator_list_buf, + ); + } +} + +pub fn is_used_delegated_validator_list_exist(credentials_home_dir: &std::path::Path) -> bool { + get_used_delegated_validator_list_path(credentials_home_dir).exists() +} + +pub fn input_delegated_validator_account_id_from_used_delegated_validator_list( + credentials_home_dir: &std::path::Path, +) -> color_eyre::eyre::Result> { + let used_delegated_validator_list = get_used_delegated_validator_list(credentials_home_dir) + .into_iter() + .map(String::from) + .collect::>(); + let validator_account_id_str = match Text::new("What is delegated validator account ID?") + .with_autocomplete(move |val: &str| { + Ok(used_delegated_validator_list + .iter() + .filter(|s| s.contains(val)) + .cloned() + .collect()) + }) + .with_validator(|account_id_str: &str| { + match near_primitives::types::AccountId::validate(account_id_str) { + Ok(_) => Ok(inquire::validator::Validation::Valid), + Err(err) => Ok(inquire::validator::Validation::Invalid( + inquire::validator::ErrorMessage::Custom(format!("Invalid account ID: {err}")), + )), + } + }) + .prompt() + { + Ok(value) => value, + Err( + inquire::error::InquireError::OperationCanceled + | inquire::error::InquireError::OperationInterrupted, + ) => return Ok(None), + Err(err) => return Err(err.into()), + }; + let validator_account_id = + crate::types::account_id::AccountId::from_str(&validator_account_id_str)?; + update_used_delegated_validator_list(credentials_home_dir, validator_account_id.as_ref()); + Ok(Some(validator_account_id)) +} + #[derive(Debug, Clone, PartialEq, Eq)] pub struct StakingPoolInfo { pub validator_id: near_primitives::types::AccountId, From 2e7a484c5a593551b5ee4f4b264cd874a8f8f3ea Mon Sep 17 00:00:00 2001 From: FroVolod Date: Wed, 25 Oct 2023 21:57:19 +0300 Subject: [PATCH 31/44] updated GUIDE --- docs/GUIDE.en.md | 290 +++++++++++++++++++++++++++++++++++++++++++++++ docs/GUIDE.ru.md | 290 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 580 insertions(+) diff --git a/docs/GUIDE.en.md b/docs/GUIDE.en.md index 6299c78bc..82b00af5e 100644 --- a/docs/GUIDE.en.md +++ b/docs/GUIDE.en.md @@ -82,6 +82,7 @@ Before proceeding to the description of specific commands, it is necessary to co - [account - Manage accounts](#account---Manage-accounts) - [tokens - Manage token assets such as NEAR, FT, NFT](#tokens---Manage-token-assets-such-as-NEAR-FT-NFT) +- [staking - Manage staking: view, add and withdraw stake](#staking---Manage-staking-view-add-and-withdraw-stake) - [contract - Manage smart-contracts: deploy code, call functions](#contract---Manage-smart-contracts-deploy-code-call-functions) - [transaction - Operate transactions](#transaction---Operate-transactions) - [config - Manage connections in a configuration file](#config---Manage-connections-in-a-configuration-file) @@ -1327,6 +1328,295 @@ fro_volod.testnet account has NFT tokens: +### staking - Manage staking: view, add and withdraw stake + +- [validator-list](#validator-list---View-the-list-of-validators-to-delegate) +- [delegate](#delegate---Delegation-management) + +#### validator-list - View the list of validators to delegate + +To view a list of validators, enter at the terminal command line: +```txt +near staking \ + validator-list \ + network-config mainnet +``` + +
The result of this command will be as follows: + +```txt ++-----+----------------------------------------------+----------+------------+----------------------------------------+ +| # | Validator Id | Fee | Delegators | Stake | ++-----+----------------------------------------------+----------+------------+----------------------------------------+ +| 1 | staked.poolv1.near | 10 % | 3207 | 44135674.18356215181482959363448 NEAR | +| 2 | figment.poolv1.near | 10 % | 1911 | 43158696.364374348313201031661037 NEAR | +| 3 | astro-stakers.poolv1.near | 1 % | 11528 | 26760042.204197815051321354819805 NEAR | +| 4 | bzam6yjpnfnxsdmjf6pw.poolv1.near | 100 % | 772 | 23347900.996610021010359525969384 NEAR | +| 5 | zavodil.poolv1.near | 1 % | 7116 | 20700903.223980192761611953425855 NEAR | +| 6 | binancenode1.poolv1.near | 5 % | 1250 | 14209385.916611355199355410152982 NEAR | +| 7 | staking_yes_protocol1.poolv1.near | 100 % | 65 | 13590245.381034035922399111793022 NEAR | +| 8 | pinnacle1.poolv1.near | 100 % | 4 | 13509874.537453205747773186007329 NEAR | +| 9 | priory.poolv1.near | 100 % | 15 | 12727257.514716521676379711750814 NEAR | +| 10 | stake1.poolv1.near | 3 % | 754 | 12449700.095021989100340879377004 NEAR | +| 11 | mockingbird.poolv1.near | 100 % | 28 | 11501759.018634341466180769487983 NEAR | +| 12 | dqw9k3e4422cxt92masmy.poolv1.near | 100 % | 36 | 11122519.385245577197951932017032 NEAR | +| 13 | flipside.pool.near | 100 % | 9 | 11087540.718366137730589600283212 NEAR | +| 14 | sweat_validator.poolv1.near | 100 % | 112 | 10900424.272450229667472212076621 NEAR | +| 15 | epic.poolv1.near | 1 % | 5363 | 10769900.629411406438519703653828 NEAR | +| 16 | future_is_near.poolv1.near | 9 % | 355 | 10243082.132364573976720438585765 NEAR | +| 17 | cosmose.poolv1.near | 100 % | 10 | 10064982.806109296980776431396738 NEAR | +| 18 | aurora.pool.near | 99 % | 3301 | 9298278.181302142009939675438401 NEAR | +... +``` +
+ +
Demonstration of the command in interactive mode + + + +
+ +#### delegate - Delegation management + +- [view-balance](#View-the-total-balance-for-a-given-account) +- [deposit](#deposit---Deposits-the-attached-amount-into-the-inner-account-of-the-predecessor) +- [deposit-and-stake](#deposit-and-stake---Deposits-the-attached-amount-into-the-inner-account-of-the-predecessor-and-stakes-it) +- [stake](#stake---Staking-the-given-amount-from-the-inner-account-of-the-predecessor) +- [stake-all](#stake-all---Staking-all-available-unstaked-balance-from-the-inner-account-of-the-predecessor) +- [unstake](#unstake---Unstaking-the-given-amount-from-the-inner-account-of-the-predecessor) +- [unstake-all](#unstake-all---Unstaking-all-staked-balance-from-the-inner-account-of-the-predecessor) +- [withdraw](#withdraw---Withdrawing-the-non-staked-balance-for-given-account) +- [withdraw-all](#withdraw-all---Withdrawing-the-entire-unstaked-balance-from-the-predecessor-account) + +##### view-balance - View the total balance for a given account + +To view the account balance of a delegated validator, enter at the terminal command line: +```txt +near staking \ + delegate volodymyr.testnet \ + view-balance aurora.pool.f863973.m0 \ + network-config testnet \ + now +``` + +
The result of this command will be as follows: + +```txt +Balance on validator for : + Staked balance: 38.021465232511349340052266 NEAR + Unstaked balance: 0.000000000000000000000001 NEAR + Total balance: 38.021465232511349340052267 NEAR +``` +
+ +
Demonstration of the command in interactive mode + + + +
+ +##### deposit - Deposits the attached amount into the inner account of the predecessor + +To deposit your account with a delegated validator, you need to enter in the terminal command line: +```txt +near staking \ + delegate volodymyr.testnet \ + deposit '10 NEAR' aurora.pool.f863973.m0 \ + network-config testnet \ + sign-with-legacy-keychain \ + send +``` + +
The result of this command will be as follows: + +```txt + has successfully deposited 10 NEAR on . +``` +
+ +
Demonstration of the command in interactive mode + + + +
+ +##### deposit-and-stake - Deposits the attached amount into the inner account of the predecessor and stakes it + +To place a deposit and a delegated stake, you must enter the following in the terminal command line: +```txt +near staking \ + delegate volodymyr.testnet \ + deposit-and-stake '15 NEAR' aurora.pool.f863973.m0 \ + network-config testnet \ + sign-with-legacy-keychain \ + send +``` + +
The result of this command will be as follows: + +```txt + has successfully deposited and staked 15 NEAR on . +``` +
+ +
Demonstration of the command in interactive mode + + + +
+ +##### stake - Staking the given amount from the inner account of the predecessor + +To stake a certain amount from a previously made deposit with a delegated validator, you must enter in the terminal command line: +```txt +near staking \ + delegate volodymyr.testnet \ + stake '5 NEAR' aurora.pool.f863973.m0 \ + network-config testnet \ + sign-with-legacy-keychain \ + send +``` + +
The result of this command will be as follows: + +```txt + has successfully stake 5 NEAR on . +``` +
+ +
Demonstration of the command in interactive mode + + + +
+ +##### stake-all - Staking all available unstaked balance from the inner account of the predecessor + +To stake the entire deposit with a delegated validator, you must enter in the terminal command line: +```txt +near staking \ + delegate volodymyr.testnet \ + stake-all aurora.pool.f863973.m0 \ + network-config testnet \ + sign-with-legacy-keychain \ + send +``` + +
The result of this command will be as follows: + +```txt + has successfully stake the entire amount on . +``` +
+ +
Demonstration of the command in interactive mode + + + +
+ +##### unstake - Unstaking the given amount from the inner account of the predecessor + +To unstake of a certain amount from a delegated validator, you must enter in the terminal command line: +```txt +near staking \ + delegate volodymyr.testnet \ + unstake '7 NEAR' aurora.pool.f863973.m0 \ + network-config testnet \ + sign-with-legacy-keychain \ + send +``` + +
The result of this command will be as follows: + +```txt + has successfully unstake 7 NEAR from . +``` +
+ +
Demonstration of the command in interactive mode + + + +
+ +##### unstake-all - Unstaking all staked balance from the inner account of the predecessor + +To unstake the entire bet from a delegated validator, you must enter in the terminal command line: +```txt +near staking \ + delegate volodymyr.testnet \ + stake-all aurora.pool.f863973.m0 \ + network-config testnet \ + sign-with-legacy-keychain \ + send +``` + +
The result of this command will be as follows: + +```txt + has successfully stake the entire amount on . +``` +
+ +
Demonstration of the command in interactive mode + + + +
+ +##### withdraw - Withdrawing the non staked balance for given account + +To withdraw a certain amount from a delegated validator to your account, you need to enter in the terminal command line: +```txt +near staking \ + delegate volodymyr.testnet \ + withdraw '3 NEAR' aurora.pool.f863973.m0 \ + network-config testnet \ + sign-with-legacy-keychain \ + send +``` + +
The result of this command will be as follows: + +```txt +Error: + 0: can't withdraw tokens in the current epoch. +``` +
+ +
Demonstration of the command in interactive mode + + + +
+ +##### withdraw-all - Withdrawing the entire unstaked balance from the predecessor account + +To withdraw the entire amount from the delegated validator to your account, you need to enter in the terminal command line: +```txt +near staking \ + delegate volodymyr.testnet \ + withdraw-all aurora.pool.f863973.m0 \ + network-config testnet \ + sign-with-legacy-keychain \ + send +``` + +
The result of this command will be as follows: + +```txt +Error: + 0: can't withdraw tokens in the current epoch. +``` +
+ +
Demonstration of the command in interactive mode + + + +
+ ### contract - Manage smart-contracts: deploy code, call functions - [call-function](#call-function---Execute-function-contract-method) diff --git a/docs/GUIDE.ru.md b/docs/GUIDE.ru.md index 0016cc0a1..898a37660 100644 --- a/docs/GUIDE.ru.md +++ b/docs/GUIDE.ru.md @@ -80,6 +80,7 @@ near --offline tokens \ - [account - Manage accounts](#account---Manage-accounts) - [tokens - Manage token assets such as NEAR, FT, NFT](#tokens---Manage-token-assets-such-as-NEAR-FT-NFT) +- [staking - Manage staking: view, add and withdraw stake](#staking---Manage-staking-view-add-and-withdraw-stake) - [contract - Manage smart-contracts: deploy code, call functions](#contract---Manage-smart-contracts-deploy-code-call-functions) - [transaction - Operate transactions](#transaction---Operate-transactions) - [config - Manage connections in a configuration file](#config---Manage-connections-in-a-configuration-file) @@ -1329,6 +1330,295 @@ fro_volod.testnet account has NFT tokens: +### staking - Manage staking: view, add and withdraw stake + +- [validator-list](#validator-list---View-the-list-of-validators-to-delegate) +- [delegate](#delegate---Delegation-management) + +#### validator-list - View the list of validators to delegate + +Для просмотра списка Π²Π°Π»ΠΈΠ΄Π°Ρ‚ΠΎΡ€ΠΎΠ² Π½Π΅ΠΎΠ±Ρ…ΠΎΠ΄ΠΈΠΌΠΎ ввСсти Π² ΠΊΠΎΠΌΠ°Π½Π΄Π½ΠΎΠΉ строкС Ρ‚Π΅Ρ€ΠΌΠΈΠ½Π°Π»Π°: +```txt +near staking \ + validator-list \ + network-config mainnet +``` + +
Π Π΅Π·ΡƒΠ»ΡŒΡ‚Π°Ρ‚ выполнСния ΠΊΠΎΠΌΠ°Π½Π΄Ρ‹ + +```txt ++-----+----------------------------------------------+----------+------------+----------------------------------------+ +| # | Validator Id | Fee | Delegators | Stake | ++-----+----------------------------------------------+----------+------------+----------------------------------------+ +| 1 | staked.poolv1.near | 10 % | 3207 | 44135674.18356215181482959363448 NEAR | +| 2 | figment.poolv1.near | 10 % | 1911 | 43158696.364374348313201031661037 NEAR | +| 3 | astro-stakers.poolv1.near | 1 % | 11528 | 26760042.204197815051321354819805 NEAR | +| 4 | bzam6yjpnfnxsdmjf6pw.poolv1.near | 100 % | 772 | 23347900.996610021010359525969384 NEAR | +| 5 | zavodil.poolv1.near | 1 % | 7116 | 20700903.223980192761611953425855 NEAR | +| 6 | binancenode1.poolv1.near | 5 % | 1250 | 14209385.916611355199355410152982 NEAR | +| 7 | staking_yes_protocol1.poolv1.near | 100 % | 65 | 13590245.381034035922399111793022 NEAR | +| 8 | pinnacle1.poolv1.near | 100 % | 4 | 13509874.537453205747773186007329 NEAR | +| 9 | priory.poolv1.near | 100 % | 15 | 12727257.514716521676379711750814 NEAR | +| 10 | stake1.poolv1.near | 3 % | 754 | 12449700.095021989100340879377004 NEAR | +| 11 | mockingbird.poolv1.near | 100 % | 28 | 11501759.018634341466180769487983 NEAR | +| 12 | dqw9k3e4422cxt92masmy.poolv1.near | 100 % | 36 | 11122519.385245577197951932017032 NEAR | +| 13 | flipside.pool.near | 100 % | 9 | 11087540.718366137730589600283212 NEAR | +| 14 | sweat_validator.poolv1.near | 100 % | 112 | 10900424.272450229667472212076621 NEAR | +| 15 | epic.poolv1.near | 1 % | 5363 | 10769900.629411406438519703653828 NEAR | +| 16 | future_is_near.poolv1.near | 9 % | 355 | 10243082.132364573976720438585765 NEAR | +| 17 | cosmose.poolv1.near | 100 % | 10 | 10064982.806109296980776431396738 NEAR | +| 18 | aurora.pool.near | 99 % | 3301 | 9298278.181302142009939675438401 NEAR | +... +``` +
+ +
ДСмонстрация Ρ€Π°Π±ΠΎΡ‚Ρ‹ ΠΊΠΎΠΌΠ°Π½Π΄Ρ‹ Π² ΠΈΠ½Ρ‚Π΅Ρ€Π°ΠΊΡ‚ΠΈΠ²Π½ΠΎΠΌ Ρ€Π΅ΠΆΠΈΠΌΠ΅ + + + +
+ +#### delegate - Delegation management + +- [view-balance](#View-the-total-balance-for-a-given-account) +- [deposit](#deposit---Deposits-the-attached-amount-into-the-inner-account-of-the-predecessor) +- [deposit-and-stake](#deposit-and-stake---Deposits-the-attached-amount-into-the-inner-account-of-the-predecessor-and-stakes-it) +- [stake](#stake---Staking-the-given-amount-from-the-inner-account-of-the-predecessor) +- [stake-all](#stake-all---Staking-all-available-unstaked-balance-from-the-inner-account-of-the-predecessor) +- [unstake](#unstake---Unstaking-the-given-amount-from-the-inner-account-of-the-predecessor) +- [unstake-all](#unstake-all---Unstaking-all-staked-balance-from-the-inner-account-of-the-predecessor) +- [withdraw](#withdraw---Withdrawing-the-non-staked-balance-for-given-account) +- [withdraw-all](#withdraw-all---Withdrawing-the-entire-unstaked-balance-from-the-predecessor-account) + +##### view-balance - View the total balance for a given account + +Для просмотра баланса Π°ΠΊΠΊΠ°ΡƒΠ½Ρ‚Π° Ρƒ Π΄Π΅Π»Π΅Π³ΠΈΡ€ΠΎΠ°Π½Π½ΠΎΠ³ΠΎ Π²Π°Π»ΠΈΠ΄Π°Ρ‚ΠΎΡ€Π° Π½Π΅ΠΎΠ±Ρ…ΠΎΠ΄ΠΈΠΌΠΎ ввСсти Π² ΠΊΠΎΠΌΠ°Π½Π΄Π½ΠΎΠΉ строкС Ρ‚Π΅Ρ€ΠΌΠΈΠ½Π°Π»Π°: +```txt +near staking \ + delegate volodymyr.testnet \ + view-balance aurora.pool.f863973.m0 \ + network-config testnet \ + now +``` + +
Π Π΅Π·ΡƒΠ»ΡŒΡ‚Π°Ρ‚ выполнСния ΠΊΠΎΠΌΠ°Π½Π΄Ρ‹ + +```txt +Balance on validator for : + Staked balance: 38.021465232511349340052266 NEAR + Unstaked balance: 0.000000000000000000000001 NEAR + Total balance: 38.021465232511349340052267 NEAR +``` +
+ +
ДСмонстрация Ρ€Π°Π±ΠΎΡ‚Ρ‹ ΠΊΠΎΠΌΠ°Π½Π΄Ρ‹ Π² ΠΈΠ½Ρ‚Π΅Ρ€Π°ΠΊΡ‚ΠΈΠ²Π½ΠΎΠΌ Ρ€Π΅ΠΆΠΈΠΌΠ΅ + + + +
+ +##### deposit - Deposits the attached amount into the inner account of the predecessor + +Π§Ρ‚ΠΎΠ±Ρ‹ Ρ€Π°Π·ΠΌΠ΅ΡΡ‚ΠΈΡ‚ΡŒ Π΄Π΅ΠΏΠΎΠ·ΠΈΡ‚ Π’Π°ΡˆΠ΅Π³ΠΎ Π°ΠΊΠΊΠ°ΡƒΠ½Ρ‚Π° Ρƒ Π΄Π΅Π»Π΅Π³ΠΈΡ€ΠΎΠ°Π½Π½ΠΎΠ³ΠΎ Π²Π°Π»ΠΈΠ΄Π°Ρ‚ΠΎΡ€Π°, Π½Π΅ΠΎΠ±Ρ…ΠΎΠ΄ΠΈΠΌΠΎ ввСсти Π² ΠΊΠΎΠΌΠ°Π½Π΄Π½ΠΎΠΉ строкС Ρ‚Π΅Ρ€ΠΌΠΈΠ½Π°Π»Π°: +```txt +near staking \ + delegate volodymyr.testnet \ + deposit '10 NEAR' aurora.pool.f863973.m0 \ + network-config testnet \ + sign-with-legacy-keychain \ + send +``` + +
Π Π΅Π·ΡƒΠ»ΡŒΡ‚Π°Ρ‚ выполнСния ΠΊΠΎΠΌΠ°Π½Π΄Ρ‹ + +```txt + has successfully deposited 10 NEAR on . +``` +
+ +
ДСмонстрация Ρ€Π°Π±ΠΎΡ‚Ρ‹ ΠΊΠΎΠΌΠ°Π½Π΄Ρ‹ Π² ΠΈΠ½Ρ‚Π΅Ρ€Π°ΠΊΡ‚ΠΈΠ²Π½ΠΎΠΌ Ρ€Π΅ΠΆΠΈΠΌΠ΅ + + + +
+ +##### deposit-and-stake - Deposits the attached amount into the inner account of the predecessor and stakes it + +Π§Ρ‚ΠΎΠ±Ρ‹ Ρ€Π°Π·ΠΌΠ΅ΡΡ‚ΠΈΡ‚ΡŒ Π΄Π΅ΠΏΠΎΠ·ΠΈΡ‚ ΠΈ ΡΠ΄Π΅Π»Π°Ρ‚ΡŒ ставку Π’Π°ΡˆΠ΅Π³ΠΎ Π°ΠΊΠΊΠ°ΡƒΠ½Ρ‚Π° Ρƒ Π΄Π΅Π»Π΅Π³ΠΈΡ€ΠΎΠ°Π½Π½ΠΎΠ³ΠΎ Π²Π°Π»ΠΈΠ΄Π°Ρ‚ΠΎΡ€Π°, Π½Π΅ΠΎΠ±Ρ…ΠΎΠ΄ΠΈΠΌΠΎ ввСсти Π² ΠΊΠΎΠΌΠ°Π½Π΄Π½ΠΎΠΉ строкС Ρ‚Π΅Ρ€ΠΌΠΈΠ½Π°Π»Π°: +```txt +near staking \ + delegate volodymyr.testnet \ + deposit-and-stake '15 NEAR' aurora.pool.f863973.m0 \ + network-config testnet \ + sign-with-legacy-keychain \ + send +``` + +
Π Π΅Π·ΡƒΠ»ΡŒΡ‚Π°Ρ‚ выполнСния ΠΊΠΎΠΌΠ°Π½Π΄Ρ‹ + +```txt + has successfully deposited and staked 15 NEAR on . +``` +
+ +
ДСмонстрация Ρ€Π°Π±ΠΎΡ‚Ρ‹ ΠΊΠΎΠΌΠ°Π½Π΄Ρ‹ Π² ΠΈΠ½Ρ‚Π΅Ρ€Π°ΠΊΡ‚ΠΈΠ²Π½ΠΎΠΌ Ρ€Π΅ΠΆΠΈΠΌΠ΅ + + + +
+ +##### stake - Staking the given amount from the inner account of the predecessor + +Π§Ρ‚ΠΎΠ±Ρ‹ ΡΠ΄Π΅Π»Π°Ρ‚ΡŒ ставку ΠΎΠΏΡ€Π΅Π΄Π΅Π»Π΅Π½Π½ΠΎΠΉ суммы ΠΎΡ‚ внСсСнного Ρ€Π°Π½Π΅Π΅ Π΄Π΅ΠΏΠΎΠ·ΠΈΡ‚Π° Ρƒ Π΄Π΅Π»Π΅Π³ΠΈΡ€ΠΎΠ°Π½Π½ΠΎΠ³ΠΎ Π²Π°Π»ΠΈΠ΄Π°Ρ‚ΠΎΡ€Π°, Π½Π΅ΠΎΠ±Ρ…ΠΎΠ΄ΠΈΠΌΠΎ ввСсти Π² ΠΊΠΎΠΌΠ°Π½Π΄Π½ΠΎΠΉ строкС Ρ‚Π΅Ρ€ΠΌΠΈΠ½Π°Π»Π°: +```txt +near staking \ + delegate volodymyr.testnet \ + stake '5 NEAR' aurora.pool.f863973.m0 \ + network-config testnet \ + sign-with-legacy-keychain \ + send +``` + +
Π Π΅Π·ΡƒΠ»ΡŒΡ‚Π°Ρ‚ выполнСния ΠΊΠΎΠΌΠ°Π½Π΄Ρ‹ + +```txt + has successfully stake 5 NEAR on . +``` +
+ +
ДСмонстрация Ρ€Π°Π±ΠΎΡ‚Ρ‹ ΠΊΠΎΠΌΠ°Π½Π΄Ρ‹ Π² ΠΈΠ½Ρ‚Π΅Ρ€Π°ΠΊΡ‚ΠΈΠ²Π½ΠΎΠΌ Ρ€Π΅ΠΆΠΈΠΌΠ΅ + + + +
+ +##### stake-all - Staking all available unstaked balance from the inner account of the predecessor + +Π§Ρ‚ΠΎΠ±Ρ‹ ΡΠ΄Π΅Π»Π°Ρ‚ΡŒ ставку всСго Π΄Π΅ΠΏΠΎΠ·ΠΈΡ‚Π° Ρƒ Π΄Π΅Π»Π΅Π³ΠΈΡ€ΠΎΠ°Π½Π½ΠΎΠ³ΠΎ Π²Π°Π»ΠΈΠ΄Π°Ρ‚ΠΎΡ€Π°, Π½Π΅ΠΎΠ±Ρ…ΠΎΠ΄ΠΈΠΌΠΎ ввСсти Π² ΠΊΠΎΠΌΠ°Π½Π΄Π½ΠΎΠΉ строкС Ρ‚Π΅Ρ€ΠΌΠΈΠ½Π°Π»Π°: +```txt +near staking \ + delegate volodymyr.testnet \ + stake-all aurora.pool.f863973.m0 \ + network-config testnet \ + sign-with-legacy-keychain \ + send +``` + +
Π Π΅Π·ΡƒΠ»ΡŒΡ‚Π°Ρ‚ выполнСния ΠΊΠΎΠΌΠ°Π½Π΄Ρ‹ + +```txt + has successfully stake the entire amount on . +``` +
+ +
ДСмонстрация Ρ€Π°Π±ΠΎΡ‚Ρ‹ ΠΊΠΎΠΌΠ°Π½Π΄Ρ‹ Π² ΠΈΠ½Ρ‚Π΅Ρ€Π°ΠΊΡ‚ΠΈΠ²Π½ΠΎΠΌ Ρ€Π΅ΠΆΠΈΠΌΠ΅ + + + +
+ +##### unstake - Unstaking the given amount from the inner account of the predecessor + +Π§Ρ‚ΠΎΠ±Ρ‹ ΡΠ½ΡΡ‚ΡŒ ставку ΠΎΠΏΡ€Π΅Π΄Π΅Π»Π΅Π½Π½ΠΎΠΉ суммы Ρƒ Π΄Π΅Π»Π΅Π³ΠΈΡ€ΠΎΠ°Π½Π½ΠΎΠ³ΠΎ Π²Π°Π»ΠΈΠ΄Π°Ρ‚ΠΎΡ€Π°, Π½Π΅ΠΎΠ±Ρ…ΠΎΠ΄ΠΈΠΌΠΎ ввСсти Π² ΠΊΠΎΠΌΠ°Π½Π΄Π½ΠΎΠΉ строкС Ρ‚Π΅Ρ€ΠΌΠΈΠ½Π°Π»Π°: +```txt +near staking \ + delegate volodymyr.testnet \ + unstake '7 NEAR' aurora.pool.f863973.m0 \ + network-config testnet \ + sign-with-legacy-keychain \ + send +``` + +
Π Π΅Π·ΡƒΠ»ΡŒΡ‚Π°Ρ‚ выполнСния ΠΊΠΎΠΌΠ°Π½Π΄Ρ‹ + +```txt + has successfully unstake 7 NEAR from . +``` +
+ +
ДСмонстрация Ρ€Π°Π±ΠΎΡ‚Ρ‹ ΠΊΠΎΠΌΠ°Π½Π΄Ρ‹ Π² ΠΈΠ½Ρ‚Π΅Ρ€Π°ΠΊΡ‚ΠΈΠ²Π½ΠΎΠΌ Ρ€Π΅ΠΆΠΈΠΌΠ΅ + + + +
+ +##### unstake-all - Unstaking all staked balance from the inner account of the predecessor + +Π§Ρ‚ΠΎΠ±Ρ‹ ΡΠ½ΡΡ‚ΡŒ всю ставку Ρƒ Π΄Π΅Π»Π΅Π³ΠΈΡ€ΠΎΠ°Π½Π½ΠΎΠ³ΠΎ Π²Π°Π»ΠΈΠ΄Π°Ρ‚ΠΎΡ€Π°, Π½Π΅ΠΎΠ±Ρ…ΠΎΠ΄ΠΈΠΌΠΎ ввСсти Π² ΠΊΠΎΠΌΠ°Π½Π΄Π½ΠΎΠΉ строкС Ρ‚Π΅Ρ€ΠΌΠΈΠ½Π°Π»Π°: +```txt +near staking \ + delegate volodymyr.testnet \ + stake-all aurora.pool.f863973.m0 \ + network-config testnet \ + sign-with-legacy-keychain \ + send +``` + +
Π Π΅Π·ΡƒΠ»ΡŒΡ‚Π°Ρ‚ выполнСния ΠΊΠΎΠΌΠ°Π½Π΄Ρ‹ + +```txt + has successfully stake the entire amount on . +``` +
+ +
ДСмонстрация Ρ€Π°Π±ΠΎΡ‚Ρ‹ ΠΊΠΎΠΌΠ°Π½Π΄Ρ‹ Π² ΠΈΠ½Ρ‚Π΅Ρ€Π°ΠΊΡ‚ΠΈΠ²Π½ΠΎΠΌ Ρ€Π΅ΠΆΠΈΠΌΠ΅ + + + +
+ +##### withdraw - Withdrawing the non staked balance for given account + +Π§Ρ‚ΠΎΠ±Ρ‹ вывСсти ΠΎΠΏΡ€Π΅Π΄Π΅Π»Π΅Π½Π½ΡƒΡŽ сумму ΠΈΠ· Π΄Π΅Π»Π΅Π³ΠΈΡ€ΠΎΠ°Π½Π½ΠΎΠ³ΠΎ Π²Π°Π»ΠΈΠ΄Π°Ρ‚ΠΎΡ€Π° Π½Π° свой Π°ΠΊΠΊΠ°ΡƒΠ½Ρ‚, Π½Π΅ΠΎΠ±Ρ…ΠΎΠ΄ΠΈΠΌΠΎ ввСсти Π² ΠΊΠΎΠΌΠ°Π½Π΄Π½ΠΎΠΉ строкС Ρ‚Π΅Ρ€ΠΌΠΈΠ½Π°Π»Π°: +```txt +near staking \ + delegate volodymyr.testnet \ + withdraw '3 NEAR' aurora.pool.f863973.m0 \ + network-config testnet \ + sign-with-legacy-keychain \ + send +``` + +
Π Π΅Π·ΡƒΠ»ΡŒΡ‚Π°Ρ‚ выполнСния ΠΊΠΎΠΌΠ°Π½Π΄Ρ‹ + +```txt +Error: + 0: can't withdraw tokens in the current epoch. +``` +
+ +
ДСмонстрация Ρ€Π°Π±ΠΎΡ‚Ρ‹ ΠΊΠΎΠΌΠ°Π½Π΄Ρ‹ Π² ΠΈΠ½Ρ‚Π΅Ρ€Π°ΠΊΡ‚ΠΈΠ²Π½ΠΎΠΌ Ρ€Π΅ΠΆΠΈΠΌΠ΅ + + + +
+ +##### withdraw-all - Withdrawing the entire unstaked balance from the predecessor account + +Π§Ρ‚ΠΎΠ±Ρ‹ вывСсти всю сумму ΠΈΠ· Π΄Π΅Π»Π΅Π³ΠΈΡ€ΠΎΠ°Π½Π½ΠΎΠ³ΠΎ Π²Π°Π»ΠΈΠ΄Π°Ρ‚ΠΎΡ€Π° Π½Π° свой Π°ΠΊΠΊΠ°ΡƒΠ½Ρ‚, Π½Π΅ΠΎΠ±Ρ…ΠΎΠ΄ΠΈΠΌΠΎ ввСсти Π² ΠΊΠΎΠΌΠ°Π½Π΄Π½ΠΎΠΉ строкС Ρ‚Π΅Ρ€ΠΌΠΈΠ½Π°Π»Π°: +```txt +near staking \ + delegate volodymyr.testnet \ + withdraw-all aurora.pool.f863973.m0 \ + network-config testnet \ + sign-with-legacy-keychain \ + send +``` + +
Π Π΅Π·ΡƒΠ»ΡŒΡ‚Π°Ρ‚ выполнСния ΠΊΠΎΠΌΠ°Π½Π΄Ρ‹ + +```txt +Error: + 0: can't withdraw tokens in the current epoch. +``` +
+ +
ДСмонстрация Ρ€Π°Π±ΠΎΡ‚Ρ‹ ΠΊΠΎΠΌΠ°Π½Π΄Ρ‹ Π² ΠΈΠ½Ρ‚Π΅Ρ€Π°ΠΊΡ‚ΠΈΠ²Π½ΠΎΠΌ Ρ€Π΅ΠΆΠΈΠΌΠ΅ + + + +
+ ### contract - Manage smart-contracts: deploy code, call functions - [call-function](#call-function---Execute-function-contract-method) From 770796df5dad8a76d9c759afa902340b7acbb42c Mon Sep 17 00:00:00 2001 From: FroVolod <36816899+FroVolod@users.noreply.github.com> Date: Thu, 26 Oct 2023 09:23:41 +0300 Subject: [PATCH 32/44] Update src/commands/staking/delegate/mod.rs Co-authored-by: Vlad Frolov --- src/commands/staking/delegate/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/commands/staking/delegate/mod.rs b/src/commands/staking/delegate/mod.rs index 5b593bc71..15e5a9d33 100644 --- a/src/commands/staking/delegate/mod.rs +++ b/src/commands/staking/delegate/mod.rs @@ -13,7 +13,7 @@ mod withdraw_all; #[derive(Debug, Clone, interactive_clap::InteractiveClap)] #[interactive_clap(input_context = crate::GlobalContext)] #[interactive_clap(output_context = DelegateStakeContext)] -pub struct DelegateStake { +pub struct StakeDelegation { #[interactive_clap(skip_default_input_arg)] /// Enter the account that you want to manage delegated stake for: account_id: crate::types::account_id::AccountId, From 2998e10c61a280e9020e9fc4d3896f1e97d7fbc4 Mon Sep 17 00:00:00 2001 From: FroVolod Date: Thu, 26 Oct 2023 09:44:48 +0300 Subject: [PATCH 33/44] renamed Delegate to Delegation --- src/commands/staking/delegate/deposit.rs | 6 +++--- .../staking/delegate/deposit_and_stake.rs | 6 +++--- src/commands/staking/delegate/mod.rs | 16 ++++++++-------- src/commands/staking/delegate/stake.rs | 6 +++--- src/commands/staking/delegate/stake_all.rs | 6 +++--- src/commands/staking/delegate/unstake.rs | 6 +++--- src/commands/staking/delegate/unstake_all.rs | 6 +++--- src/commands/staking/delegate/view_balance.rs | 6 +++--- src/commands/staking/delegate/withdraw.rs | 6 +++--- src/commands/staking/delegate/withdraw_all.rs | 6 +++--- src/commands/staking/mod.rs | 4 ++-- 11 files changed, 37 insertions(+), 37 deletions(-) diff --git a/src/commands/staking/delegate/deposit.rs b/src/commands/staking/delegate/deposit.rs index fea65d2a6..882a66351 100644 --- a/src/commands/staking/delegate/deposit.rs +++ b/src/commands/staking/delegate/deposit.rs @@ -1,5 +1,5 @@ #[derive(Debug, Clone, interactive_clap::InteractiveClap)] -#[interactive_clap(input_context = super::DelegateStakeContext)] +#[interactive_clap(input_context = super::StakeDelegationContext)] #[interactive_clap(output_context = DepositContext)] pub struct Deposit { /// Enter the attached amount to be deposited into the predecessor's internal account (example: 10NEAR or 0.5near or 10000yoctonear): @@ -17,7 +17,7 @@ pub struct DepositContext(crate::commands::ActionContext); impl DepositContext { pub fn from_previous_context( - previous_context: super::DelegateStakeContext, + previous_context: super::StakeDelegationContext, scope: &::InteractiveClapContextScope, ) -> color_eyre::eyre::Result { let signer = previous_context.account_id.clone(); @@ -78,7 +78,7 @@ impl From for crate::commands::ActionContext { impl Deposit { pub fn input_validator_account_id( - context: &super::DelegateStakeContext, + context: &super::StakeDelegationContext, ) -> color_eyre::eyre::Result> { crate::common::input_delegated_validator_account_id_from_used_delegated_validator_list( &context.global_context.config.credentials_home_dir, diff --git a/src/commands/staking/delegate/deposit_and_stake.rs b/src/commands/staking/delegate/deposit_and_stake.rs index 853803977..af6e13740 100644 --- a/src/commands/staking/delegate/deposit_and_stake.rs +++ b/src/commands/staking/delegate/deposit_and_stake.rs @@ -1,5 +1,5 @@ #[derive(Debug, Clone, interactive_clap::InteractiveClap)] -#[interactive_clap(input_context = super::DelegateStakeContext)] +#[interactive_clap(input_context = super::StakeDelegationContext)] #[interactive_clap(output_context = DepositAndStakeContext)] pub struct DepositAndStake { /// Enter the attached amount to be deposited and then staked into the predecessor's internal account (example: 10NEAR or 0.5near or 10000yoctonear): @@ -17,7 +17,7 @@ pub struct DepositAndStakeContext(crate::commands::ActionContext); impl DepositAndStakeContext { pub fn from_previous_context( - previous_context: super::DelegateStakeContext, + previous_context: super::StakeDelegationContext, scope: &::InteractiveClapContextScope, ) -> color_eyre::eyre::Result { let signer = previous_context.account_id.clone(); @@ -78,7 +78,7 @@ impl From for crate::commands::ActionContext { impl DepositAndStake { pub fn input_validator_account_id( - context: &super::DelegateStakeContext, + context: &super::StakeDelegationContext, ) -> color_eyre::eyre::Result> { crate::common::input_delegated_validator_account_id_from_used_delegated_validator_list( &context.global_context.config.credentials_home_dir, diff --git a/src/commands/staking/delegate/mod.rs b/src/commands/staking/delegate/mod.rs index 15e5a9d33..12044cb31 100644 --- a/src/commands/staking/delegate/mod.rs +++ b/src/commands/staking/delegate/mod.rs @@ -12,25 +12,25 @@ mod withdraw_all; #[derive(Debug, Clone, interactive_clap::InteractiveClap)] #[interactive_clap(input_context = crate::GlobalContext)] -#[interactive_clap(output_context = DelegateStakeContext)] +#[interactive_clap(output_context = StakeDelegationContext)] pub struct StakeDelegation { #[interactive_clap(skip_default_input_arg)] /// Enter the account that you want to manage delegated stake for: account_id: crate::types::account_id::AccountId, #[interactive_clap(subcommand)] - delegate_stake_command: DelegateStakingCommand, + delegate_stake_command: StakeDelegationCommand, } #[derive(Debug, Clone)] -pub struct DelegateStakeContext { +pub struct StakeDelegationContext { global_context: crate::GlobalContext, account_id: near_primitives::types::AccountId, } -impl DelegateStakeContext { +impl StakeDelegationContext { pub fn from_previous_context( previous_context: crate::GlobalContext, - scope: &::InteractiveClapContextScope, + scope: &::InteractiveClapContextScope, ) -> color_eyre::eyre::Result { if !crate::common::is_used_delegated_validator_list_exist( &previous_context.config.credentials_home_dir, @@ -44,7 +44,7 @@ impl DelegateStakeContext { } } -impl DelegateStake { +impl StakeDelegation { pub fn input_account_id( context: &crate::GlobalContext, ) -> color_eyre::eyre::Result> { @@ -56,11 +56,11 @@ impl DelegateStake { } #[derive(Debug, EnumDiscriminants, Clone, interactive_clap::InteractiveClap)] -#[interactive_clap(context = DelegateStakeContext)] +#[interactive_clap(context = StakeDelegationContext)] #[strum_discriminants(derive(EnumMessage, EnumIter))] #[non_exhaustive] /// Select actions with delegated staking: -pub enum DelegateStakingCommand { +pub enum StakeDelegationCommand { #[strum_discriminants(strum( message = "view-balance - View the total balance for a given account" ))] diff --git a/src/commands/staking/delegate/stake.rs b/src/commands/staking/delegate/stake.rs index 933b9375f..5d3de28dc 100644 --- a/src/commands/staking/delegate/stake.rs +++ b/src/commands/staking/delegate/stake.rs @@ -1,5 +1,5 @@ #[derive(Debug, Clone, interactive_clap::InteractiveClap)] -#[interactive_clap(input_context = super::DelegateStakeContext)] +#[interactive_clap(input_context = super::StakeDelegationContext)] #[interactive_clap(output_context = StakeContext)] pub struct Stake { /// Enter the amount to stake from the inner account of the predecessor (example: 10NEAR or 0.5near or 10000yoctonear): @@ -17,7 +17,7 @@ pub struct StakeContext(crate::commands::ActionContext); impl StakeContext { pub fn from_previous_context( - previous_context: super::DelegateStakeContext, + previous_context: super::StakeDelegationContext, scope: &::InteractiveClapContextScope, ) -> color_eyre::eyre::Result { let signer = previous_context.account_id.clone(); @@ -80,7 +80,7 @@ impl From for crate::commands::ActionContext { impl Stake { pub fn input_validator_account_id( - context: &super::DelegateStakeContext, + context: &super::StakeDelegationContext, ) -> color_eyre::eyre::Result> { crate::common::input_delegated_validator_account_id_from_used_delegated_validator_list( &context.global_context.config.credentials_home_dir, diff --git a/src/commands/staking/delegate/stake_all.rs b/src/commands/staking/delegate/stake_all.rs index 2c53269ba..2ac7d7d64 100644 --- a/src/commands/staking/delegate/stake_all.rs +++ b/src/commands/staking/delegate/stake_all.rs @@ -1,5 +1,5 @@ #[derive(Debug, Clone, interactive_clap::InteractiveClap)] -#[interactive_clap(input_context = super::DelegateStakeContext)] +#[interactive_clap(input_context = super::StakeDelegationContext)] #[interactive_clap(output_context = StakeAllContext)] pub struct StakeAll { #[interactive_clap(skip_default_input_arg)] @@ -15,7 +15,7 @@ pub struct StakeAllContext(crate::commands::ActionContext); impl StakeAllContext { pub fn from_previous_context( - previous_context: super::DelegateStakeContext, + previous_context: super::StakeDelegationContext, scope: &::InteractiveClapContextScope, ) -> color_eyre::eyre::Result { let signer = previous_context.account_id.clone(); @@ -74,7 +74,7 @@ impl From for crate::commands::ActionContext { impl StakeAll { pub fn input_validator_account_id( - context: &super::DelegateStakeContext, + context: &super::StakeDelegationContext, ) -> color_eyre::eyre::Result> { crate::common::input_delegated_validator_account_id_from_used_delegated_validator_list( &context.global_context.config.credentials_home_dir, diff --git a/src/commands/staking/delegate/unstake.rs b/src/commands/staking/delegate/unstake.rs index 42fd8f89c..98ead47e9 100644 --- a/src/commands/staking/delegate/unstake.rs +++ b/src/commands/staking/delegate/unstake.rs @@ -1,5 +1,5 @@ #[derive(Debug, Clone, interactive_clap::InteractiveClap)] -#[interactive_clap(input_context = super::DelegateStakeContext)] +#[interactive_clap(input_context = super::StakeDelegationContext)] #[interactive_clap(output_context = UnstakeContext)] pub struct Unstake { /// Enter the amount to unstake from the inner account of the predecessor (example: 10NEAR or 0.5near or 10000yoctonear): @@ -17,7 +17,7 @@ pub struct UnstakeContext(crate::commands::ActionContext); impl UnstakeContext { pub fn from_previous_context( - previous_context: super::DelegateStakeContext, + previous_context: super::StakeDelegationContext, scope: &::InteractiveClapContextScope, ) -> color_eyre::eyre::Result { let signer = previous_context.account_id.clone(); @@ -81,7 +81,7 @@ impl From for crate::commands::ActionContext { impl Unstake { pub fn input_validator_account_id( - context: &super::DelegateStakeContext, + context: &super::StakeDelegationContext, ) -> color_eyre::eyre::Result> { crate::common::input_delegated_validator_account_id_from_used_delegated_validator_list( &context.global_context.config.credentials_home_dir, diff --git a/src/commands/staking/delegate/unstake_all.rs b/src/commands/staking/delegate/unstake_all.rs index 9b218df47..604dc04b6 100644 --- a/src/commands/staking/delegate/unstake_all.rs +++ b/src/commands/staking/delegate/unstake_all.rs @@ -1,5 +1,5 @@ #[derive(Debug, Clone, interactive_clap::InteractiveClap)] -#[interactive_clap(input_context = super::DelegateStakeContext)] +#[interactive_clap(input_context = super::StakeDelegationContext)] #[interactive_clap(output_context = UnstakeAllContext)] pub struct UnstakeAll { #[interactive_clap(skip_default_input_arg)] @@ -15,7 +15,7 @@ pub struct UnstakeAllContext(crate::commands::ActionContext); impl UnstakeAllContext { pub fn from_previous_context( - previous_context: super::DelegateStakeContext, + previous_context: super::StakeDelegationContext, scope: &::InteractiveClapContextScope, ) -> color_eyre::eyre::Result { let signer = previous_context.account_id.clone(); @@ -74,7 +74,7 @@ impl From for crate::commands::ActionContext { impl UnstakeAll { pub fn input_validator_account_id( - context: &super::DelegateStakeContext, + context: &super::StakeDelegationContext, ) -> color_eyre::eyre::Result> { crate::common::input_delegated_validator_account_id_from_used_delegated_validator_list( &context.global_context.config.credentials_home_dir, diff --git a/src/commands/staking/delegate/view_balance.rs b/src/commands/staking/delegate/view_balance.rs index b1f18835a..035fdb4de 100644 --- a/src/commands/staking/delegate/view_balance.rs +++ b/src/commands/staking/delegate/view_balance.rs @@ -3,7 +3,7 @@ use color_eyre::eyre::WrapErr; use crate::common::{CallResultExt, JsonRpcClientExt}; #[derive(Debug, Clone, interactive_clap::InteractiveClap)] -#[interactive_clap(input_context = super::DelegateStakeContext)] +#[interactive_clap(input_context = super::StakeDelegationContext)] #[interactive_clap(output_context = ViewBalanceContext)] pub struct ViewBalance { #[interactive_clap(skip_default_input_arg)] @@ -19,7 +19,7 @@ pub struct ViewBalanceContext(crate::network_view_at_block::ArgsForViewContext); impl ViewBalanceContext { pub fn from_previous_context( - previous_context: super::DelegateStakeContext, + previous_context: super::StakeDelegationContext, scope: &::InteractiveClapContextScope, ) -> color_eyre::eyre::Result { let account_id = previous_context.account_id.clone(); @@ -58,7 +58,7 @@ impl From for crate::network_view_at_block::ArgsForViewConte impl ViewBalance { pub fn input_validator_account_id( - context: &super::DelegateStakeContext, + context: &super::StakeDelegationContext, ) -> color_eyre::eyre::Result> { crate::common::input_delegated_validator_account_id_from_used_delegated_validator_list( &context.global_context.config.credentials_home_dir, diff --git a/src/commands/staking/delegate/withdraw.rs b/src/commands/staking/delegate/withdraw.rs index 70f07a8c2..533256f0b 100644 --- a/src/commands/staking/delegate/withdraw.rs +++ b/src/commands/staking/delegate/withdraw.rs @@ -3,7 +3,7 @@ use color_eyre::eyre::WrapErr; use crate::common::{CallResultExt, JsonRpcClientExt}; #[derive(Debug, Clone, interactive_clap::InteractiveClap)] -#[interactive_clap(input_context = super::DelegateStakeContext)] +#[interactive_clap(input_context = super::StakeDelegationContext)] #[interactive_clap(output_context = WithdrawContext)] pub struct Withdraw { /// Enter the amount to withdraw from the non staked balance (example: 10NEAR or 0.5near or 10000yoctonear): @@ -21,7 +21,7 @@ pub struct WithdrawContext(crate::commands::ActionContext); impl WithdrawContext { pub fn from_previous_context( - previous_context: super::DelegateStakeContext, + previous_context: super::StakeDelegationContext, scope: &::InteractiveClapContextScope, ) -> color_eyre::eyre::Result { let validator_account_id: near_primitives::types::AccountId = @@ -111,7 +111,7 @@ impl From for crate::commands::ActionContext { impl Withdraw { pub fn input_validator_account_id( - context: &super::DelegateStakeContext, + context: &super::StakeDelegationContext, ) -> color_eyre::eyre::Result> { crate::common::input_delegated_validator_account_id_from_used_delegated_validator_list( &context.global_context.config.credentials_home_dir, diff --git a/src/commands/staking/delegate/withdraw_all.rs b/src/commands/staking/delegate/withdraw_all.rs index 0acb7eef6..beb2b8858 100644 --- a/src/commands/staking/delegate/withdraw_all.rs +++ b/src/commands/staking/delegate/withdraw_all.rs @@ -3,7 +3,7 @@ use color_eyre::eyre::WrapErr; use crate::common::{CallResultExt, JsonRpcClientExt}; #[derive(Debug, Clone, interactive_clap::InteractiveClap)] -#[interactive_clap(input_context = super::DelegateStakeContext)] +#[interactive_clap(input_context = super::StakeDelegationContext)] #[interactive_clap(output_context = WithdrawAllContext)] pub struct WithdrawAll { #[interactive_clap(skip_default_input_arg)] @@ -19,7 +19,7 @@ pub struct WithdrawAllContext(crate::commands::ActionContext); impl WithdrawAllContext { pub fn from_previous_context( - previous_context: super::DelegateStakeContext, + previous_context: super::StakeDelegationContext, scope: &::InteractiveClapContextScope, ) -> color_eyre::eyre::Result { let validator_account_id: near_primitives::types::AccountId = @@ -106,7 +106,7 @@ impl From for crate::commands::ActionContext { impl WithdrawAll { pub fn input_validator_account_id( - context: &super::DelegateStakeContext, + context: &super::StakeDelegationContext, ) -> color_eyre::eyre::Result> { crate::common::input_delegated_validator_account_id_from_used_delegated_validator_list( &context.global_context.config.credentials_home_dir, diff --git a/src/commands/staking/mod.rs b/src/commands/staking/mod.rs index 7d89d9257..f46b97be4 100644 --- a/src/commands/staking/mod.rs +++ b/src/commands/staking/mod.rs @@ -21,7 +21,7 @@ pub enum StakingType { ))] /// View the list of validators to delegate ValidatorList(self::validator_list::ValidatorList), - #[strum_discriminants(strum(message = "delegate - Delegation management"))] + #[strum_discriminants(strum(message = "delegation - Delegation management"))] /// Delegation management - Delegate(self::delegate::DelegateStake), + Delegation(self::delegate::StakeDelegation), } From fa9a6531d77938e391d30d85c3364a5796e4e550 Mon Sep 17 00:00:00 2001 From: FroVolod Date: Thu, 26 Oct 2023 11:08:04 +0300 Subject: [PATCH 34/44] fixed GUIDE --- docs/GUIDE.en.md | 30 +++++++++++++++--------------- docs/GUIDE.ru.md | 30 +++++++++++++++--------------- 2 files changed, 30 insertions(+), 30 deletions(-) diff --git a/docs/GUIDE.en.md b/docs/GUIDE.en.md index 82b00af5e..bd9c85645 100644 --- a/docs/GUIDE.en.md +++ b/docs/GUIDE.en.md @@ -1331,7 +1331,7 @@ fro_volod.testnet account has NFT tokens: ### staking - Manage staking: view, add and withdraw stake - [validator-list](#validator-list---View-the-list-of-validators-to-delegate) -- [delegate](#delegate---Delegation-management) +- [delegation](#delegation---Delegation-management) #### validator-list - View the list of validators to delegate @@ -1376,7 +1376,7 @@ near staking \ -#### delegate - Delegation management +#### delegation - Delegation management - [view-balance](#View-the-total-balance-for-a-given-account) - [deposit](#deposit---Deposits-the-attached-amount-into-the-inner-account-of-the-predecessor) @@ -1393,7 +1393,7 @@ near staking \ To view the account balance of a delegated validator, enter at the terminal command line: ```txt near staking \ - delegate volodymyr.testnet \ + delegation volodymyr.testnet \ view-balance aurora.pool.f863973.m0 \ network-config testnet \ now @@ -1420,7 +1420,7 @@ Balance on validator for : To deposit your account with a delegated validator, you need to enter in the terminal command line: ```txt near staking \ - delegate volodymyr.testnet \ + delegation volodymyr.testnet \ deposit '10 NEAR' aurora.pool.f863973.m0 \ network-config testnet \ sign-with-legacy-keychain \ @@ -1445,7 +1445,7 @@ near staking \ To place a deposit and a delegated stake, you must enter the following in the terminal command line: ```txt near staking \ - delegate volodymyr.testnet \ + delegation volodymyr.testnet \ deposit-and-stake '15 NEAR' aurora.pool.f863973.m0 \ network-config testnet \ sign-with-legacy-keychain \ @@ -1470,7 +1470,7 @@ near staking \ To stake a certain amount from a previously made deposit with a delegated validator, you must enter in the terminal command line: ```txt near staking \ - delegate volodymyr.testnet \ + delegation volodymyr.testnet \ stake '5 NEAR' aurora.pool.f863973.m0 \ network-config testnet \ sign-with-legacy-keychain \ @@ -1495,7 +1495,7 @@ near staking \ To stake the entire deposit with a delegated validator, you must enter in the terminal command line: ```txt near staking \ - delegate volodymyr.testnet \ + delegation volodymyr.testnet \ stake-all aurora.pool.f863973.m0 \ network-config testnet \ sign-with-legacy-keychain \ @@ -1520,7 +1520,7 @@ near staking \ To unstake of a certain amount from a delegated validator, you must enter in the terminal command line: ```txt near staking \ - delegate volodymyr.testnet \ + delegation volodymyr.testnet \ unstake '7 NEAR' aurora.pool.f863973.m0 \ network-config testnet \ sign-with-legacy-keychain \ @@ -1545,8 +1545,8 @@ near staking \ To unstake the entire bet from a delegated validator, you must enter in the terminal command line: ```txt near staking \ - delegate volodymyr.testnet \ - stake-all aurora.pool.f863973.m0 \ + delegation volodymyr.testnet \ + unstake-all aurora.pool.f863973.m0 \ network-config testnet \ sign-with-legacy-keychain \ send @@ -1555,13 +1555,13 @@ near staking \
The result of this command will be as follows: ```txt - has successfully stake the entire amount on . + has successfully unstake the entire amount from . ```
Demonstration of the command in interactive mode - - + +
@@ -1570,7 +1570,7 @@ near staking \ To withdraw a certain amount from a delegated validator to your account, you need to enter in the terminal command line: ```txt near staking \ - delegate volodymyr.testnet \ + delegation volodymyr.testnet \ withdraw '3 NEAR' aurora.pool.f863973.m0 \ network-config testnet \ sign-with-legacy-keychain \ @@ -1596,7 +1596,7 @@ Error: To withdraw the entire amount from the delegated validator to your account, you need to enter in the terminal command line: ```txt near staking \ - delegate volodymyr.testnet \ + delegation volodymyr.testnet \ withdraw-all aurora.pool.f863973.m0 \ network-config testnet \ sign-with-legacy-keychain \ diff --git a/docs/GUIDE.ru.md b/docs/GUIDE.ru.md index 898a37660..f7fc82496 100644 --- a/docs/GUIDE.ru.md +++ b/docs/GUIDE.ru.md @@ -1333,7 +1333,7 @@ fro_volod.testnet account has NFT tokens: ### staking - Manage staking: view, add and withdraw stake - [validator-list](#validator-list---View-the-list-of-validators-to-delegate) -- [delegate](#delegate---Delegation-management) +- [delegation](#delegation---Delegation-management) #### validator-list - View the list of validators to delegate @@ -1378,7 +1378,7 @@ near staking \ -#### delegate - Delegation management +#### delegation - Delegation management - [view-balance](#View-the-total-balance-for-a-given-account) - [deposit](#deposit---Deposits-the-attached-amount-into-the-inner-account-of-the-predecessor) @@ -1395,7 +1395,7 @@ near staking \ Для просмотра баланса Π°ΠΊΠΊΠ°ΡƒΠ½Ρ‚Π° Ρƒ Π΄Π΅Π»Π΅Π³ΠΈΡ€ΠΎΠ°Π½Π½ΠΎΠ³ΠΎ Π²Π°Π»ΠΈΠ΄Π°Ρ‚ΠΎΡ€Π° Π½Π΅ΠΎΠ±Ρ…ΠΎΠ΄ΠΈΠΌΠΎ ввСсти Π² ΠΊΠΎΠΌΠ°Π½Π΄Π½ΠΎΠΉ строкС Ρ‚Π΅Ρ€ΠΌΠΈΠ½Π°Π»Π°: ```txt near staking \ - delegate volodymyr.testnet \ + delegation volodymyr.testnet \ view-balance aurora.pool.f863973.m0 \ network-config testnet \ now @@ -1422,7 +1422,7 @@ Balance on validator for : Π§Ρ‚ΠΎΠ±Ρ‹ Ρ€Π°Π·ΠΌΠ΅ΡΡ‚ΠΈΡ‚ΡŒ Π΄Π΅ΠΏΠΎΠ·ΠΈΡ‚ Π’Π°ΡˆΠ΅Π³ΠΎ Π°ΠΊΠΊΠ°ΡƒΠ½Ρ‚Π° Ρƒ Π΄Π΅Π»Π΅Π³ΠΈΡ€ΠΎΠ°Π½Π½ΠΎΠ³ΠΎ Π²Π°Π»ΠΈΠ΄Π°Ρ‚ΠΎΡ€Π°, Π½Π΅ΠΎΠ±Ρ…ΠΎΠ΄ΠΈΠΌΠΎ ввСсти Π² ΠΊΠΎΠΌΠ°Π½Π΄Π½ΠΎΠΉ строкС Ρ‚Π΅Ρ€ΠΌΠΈΠ½Π°Π»Π°: ```txt near staking \ - delegate volodymyr.testnet \ + delegation volodymyr.testnet \ deposit '10 NEAR' aurora.pool.f863973.m0 \ network-config testnet \ sign-with-legacy-keychain \ @@ -1447,7 +1447,7 @@ near staking \ Π§Ρ‚ΠΎΠ±Ρ‹ Ρ€Π°Π·ΠΌΠ΅ΡΡ‚ΠΈΡ‚ΡŒ Π΄Π΅ΠΏΠΎΠ·ΠΈΡ‚ ΠΈ ΡΠ΄Π΅Π»Π°Ρ‚ΡŒ ставку Π’Π°ΡˆΠ΅Π³ΠΎ Π°ΠΊΠΊΠ°ΡƒΠ½Ρ‚Π° Ρƒ Π΄Π΅Π»Π΅Π³ΠΈΡ€ΠΎΠ°Π½Π½ΠΎΠ³ΠΎ Π²Π°Π»ΠΈΠ΄Π°Ρ‚ΠΎΡ€Π°, Π½Π΅ΠΎΠ±Ρ…ΠΎΠ΄ΠΈΠΌΠΎ ввСсти Π² ΠΊΠΎΠΌΠ°Π½Π΄Π½ΠΎΠΉ строкС Ρ‚Π΅Ρ€ΠΌΠΈΠ½Π°Π»Π°: ```txt near staking \ - delegate volodymyr.testnet \ + delegation volodymyr.testnet \ deposit-and-stake '15 NEAR' aurora.pool.f863973.m0 \ network-config testnet \ sign-with-legacy-keychain \ @@ -1472,7 +1472,7 @@ near staking \ Π§Ρ‚ΠΎΠ±Ρ‹ ΡΠ΄Π΅Π»Π°Ρ‚ΡŒ ставку ΠΎΠΏΡ€Π΅Π΄Π΅Π»Π΅Π½Π½ΠΎΠΉ суммы ΠΎΡ‚ внСсСнного Ρ€Π°Π½Π΅Π΅ Π΄Π΅ΠΏΠΎΠ·ΠΈΡ‚Π° Ρƒ Π΄Π΅Π»Π΅Π³ΠΈΡ€ΠΎΠ°Π½Π½ΠΎΠ³ΠΎ Π²Π°Π»ΠΈΠ΄Π°Ρ‚ΠΎΡ€Π°, Π½Π΅ΠΎΠ±Ρ…ΠΎΠ΄ΠΈΠΌΠΎ ввСсти Π² ΠΊΠΎΠΌΠ°Π½Π΄Π½ΠΎΠΉ строкС Ρ‚Π΅Ρ€ΠΌΠΈΠ½Π°Π»Π°: ```txt near staking \ - delegate volodymyr.testnet \ + delegation volodymyr.testnet \ stake '5 NEAR' aurora.pool.f863973.m0 \ network-config testnet \ sign-with-legacy-keychain \ @@ -1497,7 +1497,7 @@ near staking \ Π§Ρ‚ΠΎΠ±Ρ‹ ΡΠ΄Π΅Π»Π°Ρ‚ΡŒ ставку всСго Π΄Π΅ΠΏΠΎΠ·ΠΈΡ‚Π° Ρƒ Π΄Π΅Π»Π΅Π³ΠΈΡ€ΠΎΠ°Π½Π½ΠΎΠ³ΠΎ Π²Π°Π»ΠΈΠ΄Π°Ρ‚ΠΎΡ€Π°, Π½Π΅ΠΎΠ±Ρ…ΠΎΠ΄ΠΈΠΌΠΎ ввСсти Π² ΠΊΠΎΠΌΠ°Π½Π΄Π½ΠΎΠΉ строкС Ρ‚Π΅Ρ€ΠΌΠΈΠ½Π°Π»Π°: ```txt near staking \ - delegate volodymyr.testnet \ + delegation volodymyr.testnet \ stake-all aurora.pool.f863973.m0 \ network-config testnet \ sign-with-legacy-keychain \ @@ -1522,7 +1522,7 @@ near staking \ Π§Ρ‚ΠΎΠ±Ρ‹ ΡΠ½ΡΡ‚ΡŒ ставку ΠΎΠΏΡ€Π΅Π΄Π΅Π»Π΅Π½Π½ΠΎΠΉ суммы Ρƒ Π΄Π΅Π»Π΅Π³ΠΈΡ€ΠΎΠ°Π½Π½ΠΎΠ³ΠΎ Π²Π°Π»ΠΈΠ΄Π°Ρ‚ΠΎΡ€Π°, Π½Π΅ΠΎΠ±Ρ…ΠΎΠ΄ΠΈΠΌΠΎ ввСсти Π² ΠΊΠΎΠΌΠ°Π½Π΄Π½ΠΎΠΉ строкС Ρ‚Π΅Ρ€ΠΌΠΈΠ½Π°Π»Π°: ```txt near staking \ - delegate volodymyr.testnet \ + delegation volodymyr.testnet \ unstake '7 NEAR' aurora.pool.f863973.m0 \ network-config testnet \ sign-with-legacy-keychain \ @@ -1547,8 +1547,8 @@ near staking \ Π§Ρ‚ΠΎΠ±Ρ‹ ΡΠ½ΡΡ‚ΡŒ всю ставку Ρƒ Π΄Π΅Π»Π΅Π³ΠΈΡ€ΠΎΠ°Π½Π½ΠΎΠ³ΠΎ Π²Π°Π»ΠΈΠ΄Π°Ρ‚ΠΎΡ€Π°, Π½Π΅ΠΎΠ±Ρ…ΠΎΠ΄ΠΈΠΌΠΎ ввСсти Π² ΠΊΠΎΠΌΠ°Π½Π΄Π½ΠΎΠΉ строкС Ρ‚Π΅Ρ€ΠΌΠΈΠ½Π°Π»Π°: ```txt near staking \ - delegate volodymyr.testnet \ - stake-all aurora.pool.f863973.m0 \ + delegation volodymyr.testnet \ + unstake-all aurora.pool.f863973.m0 \ network-config testnet \ sign-with-legacy-keychain \ send @@ -1557,13 +1557,13 @@ near staking \
Π Π΅Π·ΡƒΠ»ΡŒΡ‚Π°Ρ‚ выполнСния ΠΊΠΎΠΌΠ°Π½Π΄Ρ‹ ```txt - has successfully stake the entire amount on . + has successfully unstake the entire amount from . ```
ДСмонстрация Ρ€Π°Π±ΠΎΡ‚Ρ‹ ΠΊΠΎΠΌΠ°Π½Π΄Ρ‹ Π² ΠΈΠ½Ρ‚Π΅Ρ€Π°ΠΊΡ‚ΠΈΠ²Π½ΠΎΠΌ Ρ€Π΅ΠΆΠΈΠΌΠ΅ - - + +
@@ -1572,7 +1572,7 @@ near staking \ Π§Ρ‚ΠΎΠ±Ρ‹ вывСсти ΠΎΠΏΡ€Π΅Π΄Π΅Π»Π΅Π½Π½ΡƒΡŽ сумму ΠΈΠ· Π΄Π΅Π»Π΅Π³ΠΈΡ€ΠΎΠ°Π½Π½ΠΎΠ³ΠΎ Π²Π°Π»ΠΈΠ΄Π°Ρ‚ΠΎΡ€Π° Π½Π° свой Π°ΠΊΠΊΠ°ΡƒΠ½Ρ‚, Π½Π΅ΠΎΠ±Ρ…ΠΎΠ΄ΠΈΠΌΠΎ ввСсти Π² ΠΊΠΎΠΌΠ°Π½Π΄Π½ΠΎΠΉ строкС Ρ‚Π΅Ρ€ΠΌΠΈΠ½Π°Π»Π°: ```txt near staking \ - delegate volodymyr.testnet \ + delegation volodymyr.testnet \ withdraw '3 NEAR' aurora.pool.f863973.m0 \ network-config testnet \ sign-with-legacy-keychain \ @@ -1598,7 +1598,7 @@ Error: Π§Ρ‚ΠΎΠ±Ρ‹ вывСсти всю сумму ΠΈΠ· Π΄Π΅Π»Π΅Π³ΠΈΡ€ΠΎΠ°Π½Π½ΠΎΠ³ΠΎ Π²Π°Π»ΠΈΠ΄Π°Ρ‚ΠΎΡ€Π° Π½Π° свой Π°ΠΊΠΊΠ°ΡƒΠ½Ρ‚, Π½Π΅ΠΎΠ±Ρ…ΠΎΠ΄ΠΈΠΌΠΎ ввСсти Π² ΠΊΠΎΠΌΠ°Π½Π΄Π½ΠΎΠΉ строкС Ρ‚Π΅Ρ€ΠΌΠΈΠ½Π°Π»Π°: ```txt near staking \ - delegate volodymyr.testnet \ + delegation volodymyr.testnet \ withdraw-all aurora.pool.f863973.m0 \ network-config testnet \ sign-with-legacy-keychain \ From 33abbb25292d1aafbd2ac59297fae19a209ab2d6 Mon Sep 17 00:00:00 2001 From: FroVolod Date: Thu, 26 Oct 2023 14:10:54 +0300 Subject: [PATCH 35/44] fixed GUIDE --- docs/GUIDE.en.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/GUIDE.en.md b/docs/GUIDE.en.md index bd9c85645..4004a7929 100644 --- a/docs/GUIDE.en.md +++ b/docs/GUIDE.en.md @@ -1388,9 +1388,9 @@ near staking \ - [withdraw](#withdraw---Withdrawing-the-non-staked-balance-for-given-account) - [withdraw-all](#withdraw-all---Withdrawing-the-entire-unstaked-balance-from-the-predecessor-account) -##### view-balance - View the total balance for a given account +##### view-balance - View the delegated stake balance for a given account -To view the account balance of a delegated validator, enter at the terminal command line: +To view the delegated stake account balance on a validator staking pool, enter at the terminal command line: ```txt near staking \ delegation volodymyr.testnet \ @@ -1402,9 +1402,9 @@ near staking \
The result of this command will be as follows: ```txt -Balance on validator for : +Delegated stake balance on validator for : Staked balance: 38.021465232511349340052266 NEAR - Unstaked balance: 0.000000000000000000000001 NEAR + Unstaked balance: 0.000000000000000000000001 NEAR (available for withdrawal) (not available for withdrawal in the current epoch) Total balance: 38.021465232511349340052267 NEAR ```
From d40363fe4da8d58bd1d85e50e4e6dcec0189ac0e Mon Sep 17 00:00:00 2001 From: Vlad Frolov Date: Thu, 26 Oct 2023 14:47:54 +0200 Subject: [PATCH 36/44] docs: Updated the GUIDE --- docs/GUIDE.en.md | 115 +++++++++++++++++++---------------------------- 1 file changed, 45 insertions(+), 70 deletions(-) diff --git a/docs/GUIDE.en.md b/docs/GUIDE.en.md index 4004a7929..f59259cf4 100644 --- a/docs/GUIDE.en.md +++ b/docs/GUIDE.en.md @@ -5,10 +5,10 @@ overview of its capabilities. This guide assumes that _near CLI_ is [installed](README.md#installation) and that readers have passing familiarity with using command line tools. This also assumes a Unix-like system, although most commands are probably easily -translatable to any command line shell environment. +translatable to any command line shell environment. With _near CLI_ you can create, sign and send transactions in _online_ mode, which is enabled by default. -In _offline_ mode, you can create and sign a transaction. The base64 encoding transaction can be [signed](#sign-transaction---sign-previously-prepared-unsigned-transaction) or [sent](#send-signed-transaction---send-a-signed-transaction) later (even from another computer). To enter the _offline_ mode, you need to set the ```--offline``` flag in the command: +In _offline_ mode, you can create and sign a transaction. The base64 encoding transaction can be [signed](#sign-transaction---sign-previously-prepared-unsigned-transaction) or [sent](#send-signed-transaction---send-a-signed-transaction) later (even from another computer). To enter the _offline_ mode, you need to set the ```--offline``` flag in the command: ```txt near --offline tokens \ fro_volod.testnet \ @@ -30,9 +30,9 @@ Before proceeding to the description of specific commands, it is necessary to co - _sign-with-keychain - Sign the transaction with a key saved in legacy keychain (compatible with the old near CLI)_ - _near CLI_ will independently find access keys and sign the created transaction. + _near CLI_ will independently find access keys and sign the created transaction. Directory with access keys defined in [config](#config---manage-connections-in-a-configuration-file). - The access keys must be in the _public-key.json_ file located in _/Users/user/.near-credentials/network-name/user-name/_ + The access keys must be in the _public-key.json_ file located in _/Users/user/.near-credentials/network-name/user-name/_ For example, _/Users/frovolod/.near-credentials/testnet/volodymyr.testnet/ed25519_8h7kFK4quSUJRkUwo3LLiK83sraEm2jnQTECuZhWu8HC.json_
Demonstration of the command in interactive mode @@ -42,7 +42,7 @@ Before proceeding to the description of specific commands, it is necessary to co
- _sign-with-ledger - Sign the transaction with Ledger Nano device_ - + This option involves signing the created transaction using a ledger. - _sign-with-plaintext-private-key - Sign the transaction with a plaintext private key_ @@ -65,11 +65,11 @@ Before proceeding to the description of specific commands, it is necessary to co 2. Actions with a signed transaction - _near CLI_ support for meta transactions as specified in [NEP-366](https://near.github.io/nearcore/architecture/how/meta-tx.html#meta-transactions). To create it, you just need to specify a _network_ that supports meta transactions. You can find out about such support in [config](#show-connections---Show-a-list-of-network-connections). The *meta_transaction_relayer_url* field is responsible for the ability to support meta transactions. For example: + _near CLI_ support for meta transactions as specified in [NEP-366](https://near.github.io/nearcore/architecture/how/meta-tx.html#meta-transactions). To create it, you just need to specify a _network_ that supports meta transactions. You can find out about such support in [config](#show-connections---Show-a-list-of-network-connections). The *meta_transaction_relayer_url* field is responsible for the ability to support meta transactions. For example: ```txt meta_transaction_relayer_url = "https://near-testnet.api.pagoda.co/relay" ``` - + A signed transaction / meta transactions can be sent for immediate execution: - _send - Send the transaction to the network_ @@ -246,7 +246,7 @@ near account \ network-config testnet ``` -You will be redirected to the browser for authorization. +You will be redirected to the browser for authorization. Default wallet url is https://app.mynearwallet.com/ (for testnet - https://testnet.mynearwallet.com/). But if you want to change to a different wallet url, you can use `--wallet-url` option: ```txt near account \ @@ -334,7 +334,7 @@ near account \ network-config testnet ``` -You will be redirected to the browser for authorization. +You will be redirected to the browser for authorization. Default wallet url is https://app.mynearwallet.com/ (for testnet - https://testnet.mynearwallet.com/). But if you want to change to a different wallet url, you can use `--wallet-url` option: ```txt near account \ @@ -392,9 +392,9 @@ Here is the private key for account : ed25519:4TKr1c7p...y7p8 #### sponsor-by-faucet-service - I would like the faucet service sponsor to cover the cost of creating an account (testnet only for now) -testnet has a faucet (helper service) that can sponsor account creation. -When adding your own network in the [add-connection](#add-connection---Add-a-network-connection) configurator, you can specify your service in the *faucet_url* field. -Access keys to the created account can be added in several ways: +testnet has a faucet (helper service) that can sponsor account creation. +When adding your own network in the [add-connection](#add-connection---Add-a-network-connection) configurator, you can specify your service in the *faucet_url* field. +Access keys to the created account can be added in several ways: - [autogenerate-new-keypair](#autogenerate-new-keypair---Automatically-generate-a-key-pair) - [use-manually-provided-seed-prase](#use-manually-provided-seed-prase---Use-the-provided-seed-phrase-manually) - [use-manually-provided-public-key](#use-manually-provided-public-key---Use-the-provided-public-key-manually) @@ -517,8 +517,8 @@ https://explorer.testnet.near.org/transactions/BStBXVisyR5FUj3ZfCAeQ1ohfwTnx2vTb #### fund-myself - I would like fund myself to cover the cost of creating an account -With this command, you can create both a sub account and a "short name" account. -Access keys to the created account can be added in several ways: +With this command, you can create both a sub account and a "short name" account. +Access keys to the created account can be added in several ways: - [autogenerate-new-keypair](#autogenerate-new-keypair---Automatically-generate-a-key-pair) - [use-manually-provided-seed-prase](#use-manually-provided-seed-prase---Use-the-provided-seed-phrase-manually) - [use-manually-provided-public-key](#use-manually-provided-public-key---Use-the-provided-public-key-manually) @@ -547,7 +547,7 @@ Transaction ID: DRT3EpCK9iT5APyGgfcgSoLPCLCYYKtnrVgDhGLDEZFo To see the transaction in the transaction explorer, please open this url in your browser: https://explorer.testnet.near.org/transactions/DRT3EpCK9iT5APyGgfcgSoLPCLCYYKtnrVgDhGLDEZFo -The data for the access key is saved in a file /Users/frovolod/.near-credentials/testnet/new.fro_volod.testnet/ed25519_3ngtirechhepHKrzfkdgqqtwqSMtdbSLR6N1c4ivnzu6.json +The data for the access key is saved in a file /Users/frovolod/.near-credentials/testnet/new.fro_volod.testnet/ed25519_3ngtirechhepHKrzfkdgqqtwqSMtdbSLR6N1c4ivnzu6.json The data for the access key is saved in a file "/Users/frovolod/.near-credentials/testnet/new.fro_volod.testnet.json" ``` @@ -692,7 +692,7 @@ https://explorer.testnet.near.org/transactions/BKJp3QdaLtnXA8xwfqyk6JfrDsDxbxqAD ##### use-auto-generation - Use auto-generation to create an implicit account This command automatically generates access keys and saves them to a file named _implicit-account-id_. -In order to execute this command, in the terminal command line type: +In order to execute this command, in the terminal command line type: ```txt near account \ create-account \ @@ -892,7 +892,7 @@ https://explorer.testnet.near.org/transactions/EHvB47npN8Z46qhsrw5XpKmD3n3jDn4MG #### list-keys - View a list of access keys of an account -Viewing account access keys is possible at the current time (***now***) and at a certain point in the past by specifying a block (***at-block-height*** or ***at-block-hash***). +Viewing account access keys is possible at the current time (***now***) and at a certain point in the past by specifying a block (***at-block-height*** or ***at-block-hash***). Examples of the use of these parameters are discussed in the ([View properties for an account](#view-account-summary---view-properties-for-an-account)). To view the list of access keys, type the following in the terminal command line: @@ -1228,7 +1228,7 @@ https://explorer.testnet.near.org/transactions/9q2VbakZbj5ja6GAFXpFnbtbYHijEHyT7 #### view-near-balance - View the balance of Near tokens -Viewing the account balance is possible at the current time (***now***) and at a certain moment in the past by specifying the block (***at-block-height*** or ***at-block-hash***). +Viewing the account balance is possible at the current time (***now***) and at a certain moment in the past by specifying the block (***at-block-height*** or ***at-block-hash***). Examples of the use of these parameters are discussed in the ([View properties for an account](#view-account-summary---view-properties-for-an-account)). To view the amount in NEAR tokens on the account, type the following in the terminal command line: @@ -1255,7 +1255,7 @@ fro_volod.testnet account has 169.589001320890476999999994 NEAR available for tr #### view-ft-balance - View the balance of FT tokens -Viewing the account balance is possible at the current time (***now***) and at a certain moment in the past by specifying the block (***at-block-height*** or ***at-block-hash***). +Viewing the account balance is possible at the current time (***now***) and at a certain moment in the past by specifying the block (***at-block-height*** or ***at-block-hash***). Examples of the use of these parameters are discussed in the ([View properties for an account](#view-account-summary---view-properties-for-an-account)). To view funds in FT tokens on the account, type the following in the terminal command line: @@ -1282,7 +1282,7 @@ fro_volod.testnet account has "31942967677775774595" FT tokens (FT-contract: usd #### view-nft-assets - View the balance of NFT tokens -Viewing the account balance is possible at the current time (***now***) and at a certain moment in the past by specifying the block (***at-block-height*** or ***at-block-hash***). +Viewing the account balance is possible at the current time (***now***) and at a certain moment in the past by specifying the block (***at-block-height*** or ***at-block-hash***). Examples of the use of these parameters are discussed in the ([View properties for an account](#view-account-summary---view-properties-for-an-account)). To view funds in NFT tokens on the account, type the following in the terminal command line: @@ -1328,7 +1328,7 @@ fro_volod.testnet account has NFT tokens: -### staking - Manage staking: view, add and withdraw stake +### staking - Manage staking: view, deposit, and withdraw delegated stake - [validator-list](#validator-list---View-the-list-of-validators-to-delegate) - [delegation](#delegation---Delegation-management) @@ -1376,7 +1376,7 @@ near staking \ -#### delegation - Delegation management +#### delegation - Stake delegation management - [view-balance](#View-the-total-balance-for-a-given-account) - [deposit](#deposit---Deposits-the-attached-amount-into-the-inner-account-of-the-predecessor) @@ -1415,34 +1415,9 @@ Delegated stake balance on validator for -##### deposit - Deposits the attached amount into the inner account of the predecessor +##### deposit-and-stake - Delegate NEAR tokens to a validator's staking pool -To deposit your account with a delegated validator, you need to enter in the terminal command line: -```txt -near staking \ - delegation volodymyr.testnet \ - deposit '10 NEAR' aurora.pool.f863973.m0 \ - network-config testnet \ - sign-with-legacy-keychain \ - send -``` - -
The result of this command will be as follows: - -```txt - has successfully deposited 10 NEAR on . -``` -
- -
Demonstration of the command in interactive mode - - - -
- -##### deposit-and-stake - Deposits the attached amount into the inner account of the predecessor and stakes it - -To place a deposit and a delegated stake, you must enter the following in the terminal command line: +To delegate your NEAR tokens to a staking pool to support a validator and gain staking rewards, deposit NEAR tokens and stake with a selected staking pool, you may use the following command (note that you need to use your own account id, adjust the amount of NEAR tokens to deposit and stake, choose the staking pool account id, and use the appropriate network): ```txt near staking \ delegation volodymyr.testnet \ @@ -1455,7 +1430,7 @@ near staking \
The result of this command will be as follows: ```txt - has successfully deposited and staked 15 NEAR on . + has successfully delegated 15 NEAR to stake with . ```
@@ -1465,9 +1440,9 @@ near staking \ -##### stake - Staking the given amount from the inner account of the predecessor +##### stake - Delegate a certain amount of previously deposited or unstaked NEAR tokens to a validator's staking pool -To stake a certain amount from a previously made deposit with a delegated validator, you must enter in the terminal command line: +To delegate your NEAR tokens to a staking pool to support a validator and gain staking rewards, stake deposited NEAR tokens with a selected staking pool. You may use the following command (note that you need to use your own account id, adjust the amount of NEAR tokens to deposit and stake, choose the staking pool account id, and use the appropriate network): ```txt near staking \ delegation volodymyr.testnet \ @@ -1480,7 +1455,7 @@ near staking \
The result of this command will be as follows: ```txt - has successfully stake 5 NEAR on . + has successfully delegated 5 NEAR to stake with . ```
@@ -1490,9 +1465,9 @@ near staking \ -##### stake-all - Staking all available unstaked balance from the inner account of the predecessor +##### stake-all - Delegate all previously deposited or unstaked NEAR tokens to a validator's staking pool -To stake the entire deposit with a delegated validator, you must enter in the terminal command line: +To delegate your NEAR tokens to a staking pool to support a validator and gain staking rewards, stake all previosly deposited or unstaked NEAR tokens with a selected staking pool. You may use the following command (note that you need to use your own account id, adjust the amount of NEAR tokens to deposit and stake, choose the staking pool account id, and use the appropriate network): ```txt near staking \ delegation volodymyr.testnet \ @@ -1505,7 +1480,7 @@ near staking \
The result of this command will be as follows: ```txt - has successfully stake the entire amount on . + has successfully delegated all previously unstaked NEAR tokens to stake with . ```
@@ -1515,7 +1490,7 @@ near staking \ -##### unstake - Unstaking the given amount from the inner account of the predecessor +##### unstake - Unstake a certain amount of delegated NEAR tokens from a avalidator's staking pool To unstake of a certain amount from a delegated validator, you must enter in the terminal command line: ```txt @@ -1540,7 +1515,7 @@ near staking \ -##### unstake-all - Unstaking all staked balance from the inner account of the predecessor +##### unstake-all - Unstake all delegated NEAR tokens from a avalidator's staking pool To unstake the entire bet from a delegated validator, you must enter in the terminal command line: ```txt @@ -1565,7 +1540,7 @@ near staking \ -##### withdraw - Withdrawing the non staked balance for given account +##### withdraw - Withdraw a certain amount of unstaked NEAR tokens from a avalidator's staking pool To withdraw a certain amount from a delegated validator to your account, you need to enter in the terminal command line: ```txt @@ -1580,7 +1555,7 @@ near staking \
The result of this command will be as follows: ```txt -Error: +Error: 0: can't withdraw tokens in the current epoch. ```
@@ -1591,7 +1566,7 @@ Error: -##### withdraw-all - Withdrawing the entire unstaked balance from the predecessor account +##### withdraw-all - Withdraw all unstaked NEAR tokens from a avalidator's staking pool To withdraw the entire amount from the delegated validator to your account, you need to enter in the terminal command line: ```txt @@ -1606,7 +1581,7 @@ near staking \
The result of this command will be as follows: ```txt -Error: +Error: 0: can't withdraw tokens in the current epoch. ```
@@ -1631,7 +1606,7 @@ Error: ##### as-read-only - Calling a view method -Viewing data is possible at the current time (***now***) and at a certain point in the past by specifying a block (***at-block-height*** or ***at-block-hash***). +Viewing data is possible at the current time (***now***) and at a certain point in the past by specifying a block (***at-block-height*** or ***at-block-hash***). Examples of the use of these parameters are discussed in the ([View properties for an account](#view-account-summary---view-properties-for-an-account)). To run this command, type the following in the terminal command line: @@ -1748,7 +1723,7 @@ https://explorer.testnet.near.org/transactions/4YGGhF88aevNGpF5uaXNGHfQprHRqkia7 #### download-wasm - Download wasm -You can download the contract file for the current moment (***now***) and for a certain moment in the past by specifying the block (***at-block-height*** or ***at-block-hash***). +You can download the contract file for the current moment (***now***) and for a certain moment in the past by specifying the block (***at-block-height*** or ***at-block-hash***). Examples of the use of these parameters are discussed in the ([View properties for an account](#view-account-summary---view-properties-for-an-account)). In order to get the contract file, type the following in the terminal command line: @@ -1775,8 +1750,8 @@ The file "/Users/frovolod/Downloads/contract_262_volodymyr_testnet.wasm" was dow #### view-storage - View contract storage state -You can view the contract key values at the current moment in time (***now***) and at a certain point in the past by specifying a block (***at-block-height*** or ***at-block-hash***). -Examples of the use of these parameters are discussed in the ([View properties for an account](#view-account-summary---view-properties-for-an-account)). +You can view the contract key values at the current moment in time (***now***) and at a certain point in the past by specifying a block (***at-block-height*** or ***at-block-hash***). +Examples of the use of these parameters are discussed in the ([View properties for an account](#view-account-summary---view-properties-for-an-account)). The keys themselves can be viewed all (***all***) or filtered using ***keys-start-with-string*** or ***keys-start-with-bytes-as-base64***. To view contract keys, enter at the terminal command line: @@ -2002,7 +1977,7 @@ Transaction status: FinalExecutionOutcomeWithReceiptView { #### construct-transaction - Construct a new transaction - + Let's consider an example when it is necessary to perform several actions within one transaction: 1. Create an account 2. Add access keys to the created account @@ -2017,7 +1992,7 @@ To do this, we will use the transaction constructor: #### sign-transaction - Sign previously prepared unsigned transaction - + Consider an example of using the ability to create a transaction in _offline_: 1. Create a transaction. 2. When choosing how to sign a transaction, select the _sign later_ option and follow the instructions. @@ -2030,7 +2005,7 @@ Consider an example of using the ability to create a transaction in _offline_: #### send-signed-transaction - Send a signed transaction - + Let's look at the previous example, using the capabilities of sending a signed transaction: 1. Create a transaction. 2. Sign the transaction with your access keys. @@ -2044,7 +2019,7 @@ Let's look at the previous example, using the capabilities of sending a signed t #### send-meta-transaction - Act as a relayer to send a signed delegate action (meta-transaction) - + Consider an example of using metatransaction functions: 1. Create a transaction. 2. Specify a _network_ that supports meta-transactions. From 7461a4f1a87427faeb9153fb13018ba698b32219 Mon Sep 17 00:00:00 2001 From: FroVolod Date: Thu, 26 Oct 2023 16:40:53 +0300 Subject: [PATCH 37/44] updated StakeDelegationCommand --- src/commands/staking/delegate/deposit.rs | 87 ------------------------ src/commands/staking/delegate/mod.rs | 34 ++++----- 2 files changed, 14 insertions(+), 107 deletions(-) delete mode 100644 src/commands/staking/delegate/deposit.rs diff --git a/src/commands/staking/delegate/deposit.rs b/src/commands/staking/delegate/deposit.rs deleted file mode 100644 index 882a66351..000000000 --- a/src/commands/staking/delegate/deposit.rs +++ /dev/null @@ -1,87 +0,0 @@ -#[derive(Debug, Clone, interactive_clap::InteractiveClap)] -#[interactive_clap(input_context = super::StakeDelegationContext)] -#[interactive_clap(output_context = DepositContext)] -pub struct Deposit { - /// Enter the attached amount to be deposited into the predecessor's internal account (example: 10NEAR or 0.5near or 10000yoctonear): - amount: crate::common::NearBalance, - #[interactive_clap(skip_default_input_arg)] - /// What is validator account ID? - validator_account_id: crate::types::account_id::AccountId, - #[interactive_clap(named_arg)] - /// Select network - network_config: crate::network_for_transaction::NetworkForTransactionArgs, -} - -#[derive(Clone)] -pub struct DepositContext(crate::commands::ActionContext); - -impl DepositContext { - pub fn from_previous_context( - previous_context: super::StakeDelegationContext, - scope: &::InteractiveClapContextScope, - ) -> color_eyre::eyre::Result { - let signer = previous_context.account_id.clone(); - let validator_account_id: near_primitives::types::AccountId = - scope.validator_account_id.clone().into(); - let validator_id = validator_account_id.clone(); - let interacting_with_account_ids = vec![ - previous_context.account_id.clone(), - validator_account_id.clone(), - ]; - let amount = scope.amount.clone(); - - let on_after_getting_network_callback: crate::commands::OnAfterGettingNetworkCallback = - std::sync::Arc::new(move |_network_config| { - Ok(crate::commands::PrepopulatedTransaction { - signer_id: previous_context.account_id.clone(), - receiver_id: validator_account_id.clone(), - actions: vec![near_primitives::transaction::Action::FunctionCall( - near_primitives::transaction::FunctionCallAction { - method_name: "deposit".to_string(), - args: serde_json::to_vec(&serde_json::json!({}))?, - gas: crate::common::NearGas::from_tgas(300).as_gas(), - deposit: amount.to_yoctonear(), - }, - )], - }) - }); - - let amount = scope.amount.clone(); - let on_after_sending_transaction_callback: crate::transaction_signature_options::OnAfterSendingTransactionCallback = std::sync::Arc::new( - move |outcome_view, _network_config| { - if let near_primitives::views::FinalExecutionStatus::SuccessValue(_) = outcome_view.status { - eprintln!("<{signer}> has successfully deposited {amount} on <{validator_id}>.") - } - Ok(()) - }, - ); - Ok(Self(crate::commands::ActionContext { - global_context: previous_context.global_context, - interacting_with_account_ids, - on_after_getting_network_callback, - on_before_signing_callback: std::sync::Arc::new( - |_prepolulated_unsinged_transaction, _network_config| Ok(()), - ), - on_before_sending_transaction_callback: std::sync::Arc::new( - |_signed_transaction, _network_config, _message| Ok(()), - ), - on_after_sending_transaction_callback, - })) - } -} - -impl From for crate::commands::ActionContext { - fn from(item: DepositContext) -> Self { - item.0 - } -} - -impl Deposit { - pub fn input_validator_account_id( - context: &super::StakeDelegationContext, - ) -> color_eyre::eyre::Result> { - crate::common::input_delegated_validator_account_id_from_used_delegated_validator_list( - &context.global_context.config.credentials_home_dir, - ) - } -} diff --git a/src/commands/staking/delegate/mod.rs b/src/commands/staking/delegate/mod.rs index 12044cb31..cd2a7face 100644 --- a/src/commands/staking/delegate/mod.rs +++ b/src/commands/staking/delegate/mod.rs @@ -1,6 +1,5 @@ use strum::{EnumDiscriminants, EnumIter, EnumMessage}; -mod deposit; mod deposit_and_stake; mod stake; mod stake_all; @@ -62,19 +61,14 @@ impl StakeDelegation { /// Select actions with delegated staking: pub enum StakeDelegationCommand { #[strum_discriminants(strum( - message = "view-balance - View the total balance for a given account" + message = "view-balance - View the delegated stake balance for a given account" ))] - /// View the total balance for a given account + /// View the delegated stake balance for a given account ViewBalance(self::view_balance::ViewBalance), #[strum_discriminants(strum( - message = "deposit - Deposits the attached amount into the inner account of the predecessor" + message = "deposit-and-stake - Delegate NEAR tokens to a validator's staking pool" ))] - /// Deposits the attached amount into the inner account of the predecessor - Deposit(self::deposit::Deposit), - #[strum_discriminants(strum( - message = "deposit-and-stake - Deposits the attached amount into the inner account of the predecessor and stakes it" - ))] - /// Deposits the attached amount into the inner account of the predecessor and stakes it + /// Delegate NEAR tokens to a validator's staking pool DepositAndStake(self::deposit_and_stake::DepositAndStake), #[strum_discriminants(strum( message = "stake - Staking the given amount from the inner account of the predecessor" @@ -82,28 +76,28 @@ pub enum StakeDelegationCommand { /// Staking the given amount from the inner account of the predecessor Stake(self::stake::Stake), #[strum_discriminants(strum( - message = "stake-all - Staking all available unstaked balance from the inner account of the predecessor" + message = "stake-all - Delegate all previously deposited or unstaked NEAR tokens to a validator's staking pool" ))] - /// Staking all available unstaked balance from the inner account of the predecessor + /// Delegate all previously deposited or unstaked NEAR tokens to a validator's staking pool StakeAll(self::stake_all::StakeAll), #[strum_discriminants(strum( - message = "unstake - Unstaking the given amount from the inner account of the predecessor" + message = "unstake - Unstake a certain amount of delegated NEAR tokens from a avalidator's staking pool" ))] - /// Unstaking the given amount from the inner account of the predecessor + /// Unstake a certain amount of delegated NEAR tokens from a avalidator's staking pool Unstake(self::unstake::Unstake), #[strum_discriminants(strum( - message = "unstake-all - Unstaking all staked balance from the inner account of the predecessor" + message = "unstake-all - Unstake all delegated NEAR tokens from a avalidator's staking pool" ))] - /// Unstaking all staked balance from the inner account of the predecessor + /// Unstake all delegated NEAR tokens from a avalidator's staking pool UnstakeAll(self::unstake_all::UnstakeAll), #[strum_discriminants(strum( - message = "withdraw - Withdrawing the non staked balance for given account" + message = "withdraw - Withdraw a certain amount of unstaked NEAR tokens from a avalidator's staking pool" ))] - /// Withdrawing the non staked balance for given account + /// Withdraw a certain amount of unstaked NEAR tokens from a avalidator's staking pool Withdraw(self::withdraw::Withdraw), #[strum_discriminants(strum( - message = "withdraw-all - Withdrawing the entire unstaked balance from the predecessor account" + message = "withdraw-all - Withdraw all unstaked NEAR tokens from a avalidator's staking pool" ))] - /// Withdrawing the entire unstaked balance from the predecessor account + /// Withdraw all unstaked NEAR tokens from a avalidator's staking pool WithdrawAll(self::withdraw_all::WithdrawAll), } From 877098c44063c0c8147ce8d498ad54f4693d1e77 Mon Sep 17 00:00:00 2001 From: FroVolod Date: Thu, 26 Oct 2023 16:50:22 +0300 Subject: [PATCH 38/44] fixed GUIDE --- docs/GUIDE.en.md | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/docs/GUIDE.en.md b/docs/GUIDE.en.md index f59259cf4..acbb521d9 100644 --- a/docs/GUIDE.en.md +++ b/docs/GUIDE.en.md @@ -1378,15 +1378,14 @@ near staking \ #### delegation - Stake delegation management -- [view-balance](#View-the-total-balance-for-a-given-account) -- [deposit](#deposit---Deposits-the-attached-amount-into-the-inner-account-of-the-predecessor) -- [deposit-and-stake](#deposit-and-stake---Deposits-the-attached-amount-into-the-inner-account-of-the-predecessor-and-stakes-it) -- [stake](#stake---Staking-the-given-amount-from-the-inner-account-of-the-predecessor) -- [stake-all](#stake-all---Staking-all-available-unstaked-balance-from-the-inner-account-of-the-predecessor) -- [unstake](#unstake---Unstaking-the-given-amount-from-the-inner-account-of-the-predecessor) -- [unstake-all](#unstake-all---Unstaking-all-staked-balance-from-the-inner-account-of-the-predecessor) -- [withdraw](#withdraw---Withdrawing-the-non-staked-balance-for-given-account) -- [withdraw-all](#withdraw-all---Withdrawing-the-entire-unstaked-balance-from-the-predecessor-account) +- [view-balance](#view-balance---View-the-delegated-stake-balance-for-a-given-account) +- [deposit-and-stake](#deposit-and-stake---Delegate-NEAR-tokens-to-a-validator's-staking-pool) +- [stake](#stake---Delegate-a-certain-amount-of-previously-deposited-or-unstaked-NEAR-tokens-to-a-validator's-staking-pool) +- [stake-all](#stake-all---Delegate-all-previously-deposited-or-unstaked-NEAR-tokens-to-a-validator's-staking-pool) +- [unstake](#unstake---Unstake-a-certain-amount-of-delegated-NEAR-tokens-from-a-avalidator's-staking-pool) +- [unstake-all](#unstake-all---Unstake-all-delegated-NEAR-tokens-from-a-avalidator's-staking-pool) +- [withdraw](#withdraw---Withdraw-a-certain-amount-of-unstaked-NEAR-tokens-from-a-avalidator's-staking-pool) +- [withdraw-all](#withdraw-all---Withdraw-all-unstaked-NEAR-tokens-from-a-avalidator's-staking-pool) ##### view-balance - View the delegated stake balance for a given account From 8559cbc84c1808bca77ab258461dda02d895b9d7 Mon Sep 17 00:00:00 2001 From: FroVolod Date: Thu, 26 Oct 2023 17:55:45 +0300 Subject: [PATCH 39/44] updated view-balance --- docs/GUIDE.en.md | 2 +- src/commands/staking/delegate/view_balance.rs | 29 ++++++++++++++++++- src/commands/staking/delegate/withdraw.rs | 27 ++++------------- src/commands/staking/delegate/withdraw_all.rs | 27 ++++------------- 4 files changed, 39 insertions(+), 46 deletions(-) diff --git a/docs/GUIDE.en.md b/docs/GUIDE.en.md index acbb521d9..a9eefdb1c 100644 --- a/docs/GUIDE.en.md +++ b/docs/GUIDE.en.md @@ -1403,7 +1403,7 @@ near staking \ ```txt Delegated stake balance on validator for : Staked balance: 38.021465232511349340052266 NEAR - Unstaked balance: 0.000000000000000000000001 NEAR (available for withdrawal) (not available for withdrawal in the current epoch) + Unstaked balance: 0.000000000000000000000001 NEAR Total balance: 38.021465232511349340052267 NEAR ``` diff --git a/src/commands/staking/delegate/view_balance.rs b/src/commands/staking/delegate/view_balance.rs index 035fdb4de..12df77108 100644 --- a/src/commands/staking/delegate/view_balance.rs +++ b/src/commands/staking/delegate/view_balance.rs @@ -33,10 +33,15 @@ impl ViewBalanceContext { let user_staked_balance: u128 = get_user_staked_balance(network_config, block_reference, &validator_account_id, &account_id)?; let user_unstaked_balance: u128 = get_user_unstaked_balance(network_config, block_reference, &validator_account_id, &account_id)?; let user_total_balance: u128 = get_user_total_balance(network_config, block_reference, &validator_account_id, &account_id)?; + let withdrawal_availability_message = match is_account_unstaked_balance_available_for_withdrawal(network_config, &validator_account_id, &account_id)? { + true if user_unstaked_balance > 0 => "(available for withdrawal)", + false if user_unstaked_balance > 0 => "(not available for withdrawal in the current epoch)", + _ => "" + }; eprintln!("Balance on validator <{validator_account_id}> for <{account_id}>:"); eprintln!(" Staked balance: {:>38}", crate::common::NearBalance::from_yoctonear(user_staked_balance).to_string()); - eprintln!(" Unstaked balance: {:>38}", crate::common::NearBalance::from_yoctonear(user_unstaked_balance).to_string()); + eprintln!(" Unstaked balance: {:>38} {withdrawal_availability_message}", crate::common::NearBalance::from_yoctonear(user_unstaked_balance).to_string()); eprintln!(" Total balance: {:>38}", crate::common::NearBalance::from_yoctonear(user_total_balance).to_string()); Ok(()) @@ -131,3 +136,25 @@ pub fn get_user_total_balance( .wrap_err("Failed to parse return value of view function call for String.")? .parse::()?) } + +pub fn is_account_unstaked_balance_available_for_withdrawal( + network_config: &crate::config::NetworkConfig, + validator_account_id: &near_primitives::types::AccountId, + account_id: &near_primitives::types::AccountId, +) -> color_eyre::eyre::Result { + network_config + .json_rpc_client() + .blocking_call_view_function( + validator_account_id, + "is_account_unstaked_balance_available", + serde_json::to_vec(&serde_json::json!({ + "account_id": account_id.to_string(), + }))?, + near_primitives::types::BlockReference::Finality( + near_primitives::types::Finality::Final, + ), + ) + .wrap_err("Failed to fetch query for view method: 'is_account_unstaked_balance_available'")? + .parse_result_from_json::() + .wrap_err("Failed to parse return value of view function call for bool value.") +} diff --git a/src/commands/staking/delegate/withdraw.rs b/src/commands/staking/delegate/withdraw.rs index 533256f0b..1e35d2dea 100644 --- a/src/commands/staking/delegate/withdraw.rs +++ b/src/commands/staking/delegate/withdraw.rs @@ -1,7 +1,3 @@ -use color_eyre::eyre::WrapErr; - -use crate::common::{CallResultExt, JsonRpcClientExt}; - #[derive(Debug, Clone, interactive_clap::InteractiveClap)] #[interactive_clap(input_context = super::StakeDelegationContext)] #[interactive_clap(output_context = WithdrawContext)] @@ -38,24 +34,11 @@ impl WithdrawContext { let amount = scope.amount.clone(); move |network_config| { - let is_account_unstaked_balance_available = network_config - .json_rpc_client() - .blocking_call_view_function( - &validator_account_id, - "is_account_unstaked_balance_available", - serde_json::to_vec(&serde_json::json!({ - "account_id": signer_id.to_string(), - }))?, - near_primitives::types::BlockReference::Finality(near_primitives::types::Finality::Final), - ) - .wrap_err( - "Failed to fetch query for view method: 'is_account_unstaked_balance_available'" - )? - .parse_result_from_json::() - .wrap_err( - "Failed to parse return value of view function call for bool value." - )?; - if !is_account_unstaked_balance_available { + if !super::view_balance::is_account_unstaked_balance_available_for_withdrawal( + network_config, + &validator_account_id, + &signer_id, + )? { return Err(color_eyre::Report::msg(format!( "<{signer_id}> can't withdraw tokens in the current epoch." ))); diff --git a/src/commands/staking/delegate/withdraw_all.rs b/src/commands/staking/delegate/withdraw_all.rs index beb2b8858..3b64ad979 100644 --- a/src/commands/staking/delegate/withdraw_all.rs +++ b/src/commands/staking/delegate/withdraw_all.rs @@ -1,7 +1,3 @@ -use color_eyre::eyre::WrapErr; - -use crate::common::{CallResultExt, JsonRpcClientExt}; - #[derive(Debug, Clone, interactive_clap::InteractiveClap)] #[interactive_clap(input_context = super::StakeDelegationContext)] #[interactive_clap(output_context = WithdrawAllContext)] @@ -35,24 +31,11 @@ impl WithdrawAllContext { let signer_id = previous_context.account_id.clone(); move |network_config| { - let is_account_unstaked_balance_available = network_config - .json_rpc_client() - .blocking_call_view_function( - &validator_account_id, - "is_account_unstaked_balance_available", - serde_json::to_vec(&serde_json::json!({ - "account_id": signer_id.to_string(), - }))?, - near_primitives::types::BlockReference::Finality(near_primitives::types::Finality::Final), - ) - .wrap_err( - "Failed to fetch query for view method: 'is_account_unstaked_balance_available'" - )? - .parse_result_from_json::() - .wrap_err( - "Failed to parse return value of view function call for bool value." - )?; - if !is_account_unstaked_balance_available { + if !super::view_balance::is_account_unstaked_balance_available_for_withdrawal( + network_config, + &validator_account_id, + &signer_id, + )? { return Err(color_eyre::Report::msg(format!( "<{signer_id}> can't withdraw tokens in the current epoch." ))); From 829144af3319c081611257998ded0b307914f02e Mon Sep 17 00:00:00 2001 From: FroVolod Date: Fri, 27 Oct 2023 10:07:32 +0300 Subject: [PATCH 40/44] updated get_used_delegated_validator_list() --- .../staking/delegate/deposit_and_stake.rs | 2 +- src/commands/staking/delegate/mod.rs | 5 - src/commands/staking/delegate/stake.rs | 2 +- src/commands/staking/delegate/stake_all.rs | 2 +- src/commands/staking/delegate/unstake.rs | 2 +- src/commands/staking/delegate/unstake_all.rs | 2 +- src/commands/staking/delegate/view_balance.rs | 2 +- src/commands/staking/delegate/withdraw.rs | 2 +- src/commands/staking/delegate/withdraw_all.rs | 2 +- src/common.rs | 131 ++++++------------ 10 files changed, 53 insertions(+), 99 deletions(-) diff --git a/src/commands/staking/delegate/deposit_and_stake.rs b/src/commands/staking/delegate/deposit_and_stake.rs index af6e13740..8d92d27fb 100644 --- a/src/commands/staking/delegate/deposit_and_stake.rs +++ b/src/commands/staking/delegate/deposit_and_stake.rs @@ -81,7 +81,7 @@ impl DepositAndStake { context: &super::StakeDelegationContext, ) -> color_eyre::eyre::Result> { crate::common::input_delegated_validator_account_id_from_used_delegated_validator_list( - &context.global_context.config.credentials_home_dir, + &context.global_context.config, ) } } diff --git a/src/commands/staking/delegate/mod.rs b/src/commands/staking/delegate/mod.rs index cd2a7face..997a3d8ea 100644 --- a/src/commands/staking/delegate/mod.rs +++ b/src/commands/staking/delegate/mod.rs @@ -31,11 +31,6 @@ impl StakeDelegationContext { previous_context: crate::GlobalContext, scope: &::InteractiveClapContextScope, ) -> color_eyre::eyre::Result { - if !crate::common::is_used_delegated_validator_list_exist( - &previous_context.config.credentials_home_dir, - ) { - crate::common::create_used_delegated_validator_list(&previous_context.config)?; - } Ok(Self { global_context: previous_context, account_id: scope.account_id.clone().into(), diff --git a/src/commands/staking/delegate/stake.rs b/src/commands/staking/delegate/stake.rs index 5d3de28dc..fe5f26c11 100644 --- a/src/commands/staking/delegate/stake.rs +++ b/src/commands/staking/delegate/stake.rs @@ -83,7 +83,7 @@ impl Stake { context: &super::StakeDelegationContext, ) -> color_eyre::eyre::Result> { crate::common::input_delegated_validator_account_id_from_used_delegated_validator_list( - &context.global_context.config.credentials_home_dir, + &context.global_context.config, ) } } diff --git a/src/commands/staking/delegate/stake_all.rs b/src/commands/staking/delegate/stake_all.rs index 2ac7d7d64..7fd2ce209 100644 --- a/src/commands/staking/delegate/stake_all.rs +++ b/src/commands/staking/delegate/stake_all.rs @@ -77,7 +77,7 @@ impl StakeAll { context: &super::StakeDelegationContext, ) -> color_eyre::eyre::Result> { crate::common::input_delegated_validator_account_id_from_used_delegated_validator_list( - &context.global_context.config.credentials_home_dir, + &context.global_context.config, ) } } diff --git a/src/commands/staking/delegate/unstake.rs b/src/commands/staking/delegate/unstake.rs index 98ead47e9..dfc650179 100644 --- a/src/commands/staking/delegate/unstake.rs +++ b/src/commands/staking/delegate/unstake.rs @@ -84,7 +84,7 @@ impl Unstake { context: &super::StakeDelegationContext, ) -> color_eyre::eyre::Result> { crate::common::input_delegated_validator_account_id_from_used_delegated_validator_list( - &context.global_context.config.credentials_home_dir, + &context.global_context.config, ) } } diff --git a/src/commands/staking/delegate/unstake_all.rs b/src/commands/staking/delegate/unstake_all.rs index 604dc04b6..864c9d8a8 100644 --- a/src/commands/staking/delegate/unstake_all.rs +++ b/src/commands/staking/delegate/unstake_all.rs @@ -77,7 +77,7 @@ impl UnstakeAll { context: &super::StakeDelegationContext, ) -> color_eyre::eyre::Result> { crate::common::input_delegated_validator_account_id_from_used_delegated_validator_list( - &context.global_context.config.credentials_home_dir, + &context.global_context.config, ) } } diff --git a/src/commands/staking/delegate/view_balance.rs b/src/commands/staking/delegate/view_balance.rs index 12df77108..064ea9c1c 100644 --- a/src/commands/staking/delegate/view_balance.rs +++ b/src/commands/staking/delegate/view_balance.rs @@ -66,7 +66,7 @@ impl ViewBalance { context: &super::StakeDelegationContext, ) -> color_eyre::eyre::Result> { crate::common::input_delegated_validator_account_id_from_used_delegated_validator_list( - &context.global_context.config.credentials_home_dir, + &context.global_context.config, ) } } diff --git a/src/commands/staking/delegate/withdraw.rs b/src/commands/staking/delegate/withdraw.rs index 1e35d2dea..d8a17a834 100644 --- a/src/commands/staking/delegate/withdraw.rs +++ b/src/commands/staking/delegate/withdraw.rs @@ -97,7 +97,7 @@ impl Withdraw { context: &super::StakeDelegationContext, ) -> color_eyre::eyre::Result> { crate::common::input_delegated_validator_account_id_from_used_delegated_validator_list( - &context.global_context.config.credentials_home_dir, + &context.global_context.config, ) } } diff --git a/src/commands/staking/delegate/withdraw_all.rs b/src/commands/staking/delegate/withdraw_all.rs index 3b64ad979..974402a49 100644 --- a/src/commands/staking/delegate/withdraw_all.rs +++ b/src/commands/staking/delegate/withdraw_all.rs @@ -92,7 +92,7 @@ impl WithdrawAll { context: &super::StakeDelegationContext, ) -> color_eyre::eyre::Result> { crate::common::input_delegated_validator_account_id_from_used_delegated_validator_list( - &context.global_context.config.credentials_home_dir, + &context.global_context.config, ) } } diff --git a/src/common.rs b/src/common.rs index a7f769cb3..dfac1af87 100644 --- a/src/common.rs +++ b/src/common.rs @@ -1284,106 +1284,62 @@ fn path_directories() -> Vec { dirs } -pub fn get_delegated_validator_list_from_network( - network_config: &crate::config::NetworkConfig, -) -> color_eyre::eyre::Result> { - Ok(get_validator_list(network_config)? - .into_iter() - .filter(|staking_pool_info| staking_pool_info.delegators.is_some()) - .map(|staking_pool_info| staking_pool_info.validator_id) - .collect::>()) -} - -fn get_used_delegated_validator_list_path( - credentials_home_dir: &std::path::Path, -) -> std::path::PathBuf { - credentials_home_dir.join("delegated_validators.json") -} - -pub fn create_used_delegated_validator_list(config: &crate::config::Config) -> CliResult { - let mut used_delegated_validator_list: std::collections::BTreeSet< +pub fn get_delegated_validator_list_from_mainnet( + network_connection: &linked_hash_map::LinkedHashMap, +) -> color_eyre::eyre::Result> { + let mut delegated_validator_list: std::collections::BTreeSet< near_primitives::types::AccountId, > = std::collections::BTreeSet::new(); + let network_config = network_connection.get("mainnet").expect("Internal error!"); - for network_config in config.network_connection.values() { - let used_delegated_validators = get_delegated_validator_list_from_network(network_config)?; - for validator_account_id in used_delegated_validators { - used_delegated_validator_list.insert(validator_account_id); - } - } - - if !used_delegated_validator_list.is_empty() { - let used_delegated_validator_list_path = - get_used_delegated_validator_list_path(&config.credentials_home_dir); - let used_delegated_validator_list_buf = serde_json::to_string( - &used_delegated_validator_list - .into_iter() - .map(String::from) - .collect::>(), - )?; - std::fs::write( - &used_delegated_validator_list_path, - used_delegated_validator_list_buf, + let epoch_validator_info = network_config + .json_rpc_client() + .blocking_call( + &near_jsonrpc_client::methods::validators::RpcValidatorRequest { + epoch_reference: near_primitives::types::EpochReference::Latest, + }, ) - .wrap_err_with(|| { - format!( - "Failed to write to file: {}", - used_delegated_validator_list_path.display() - ) - })?; + .wrap_err("Failed to get epoch validators information request.")?; + + for current_proposal in epoch_validator_info.current_proposals { + delegated_validator_list.insert(current_proposal.take_account_id()); } - Ok(()) -} -pub fn get_used_delegated_validator_list( - credentials_home_dir: &std::path::Path, -) -> VecDeque { - serde_json::from_str( - std::fs::read_to_string(get_used_delegated_validator_list_path(credentials_home_dir)) - .as_deref() - .unwrap_or("[]"), - ) - .unwrap_or_default() -} + for current_validator in epoch_validator_info.current_validators { + delegated_validator_list.insert(current_validator.account_id); + } -pub fn update_used_delegated_validator_list( - credentials_home_dir: &std::path::Path, - validator_account_id: &near_primitives::types::AccountId, -) { - let mut used_delegated_validator_list = get_used_delegated_validator_list(credentials_home_dir); + for next_validator in epoch_validator_info.next_validators { + delegated_validator_list.insert(next_validator.account_id); + } - let used_validator_account_id = if let Some(used_validator_account_id) = - used_delegated_validator_list - .iter() - .position(|used_account| used_account == validator_account_id) - .and_then(|position| used_delegated_validator_list.remove(position)) - { - used_validator_account_id - } else { - validator_account_id.clone() - }; - used_delegated_validator_list.push_front(used_validator_account_id); + Ok(delegated_validator_list) +} - let used_delegated_validator_list_path = - get_used_delegated_validator_list_path(credentials_home_dir); - if let Ok(used_delegated_validator_list_buf) = - serde_json::to_string(&used_delegated_validator_list) - { - let _ = std::fs::write( - used_delegated_validator_list_path, - used_delegated_validator_list_buf, - ); +pub fn get_used_delegated_validator_list( + config: &crate::config::Config, +) -> color_eyre::eyre::Result> { + let used_account_list: VecDeque = + get_used_account_list(&config.credentials_home_dir); + let mut delegated_validator_list = + get_delegated_validator_list_from_mainnet(&config.network_connection)?; + let mut used_delegated_validator_list: VecDeque = + VecDeque::new(); + + for used_account in used_account_list { + if delegated_validator_list.remove(&used_account.account_id) { + used_delegated_validator_list.push_back(used_account.account_id); + } } -} -pub fn is_used_delegated_validator_list_exist(credentials_home_dir: &std::path::Path) -> bool { - get_used_delegated_validator_list_path(credentials_home_dir).exists() + used_delegated_validator_list.extend(delegated_validator_list.into_iter()); + Ok(used_delegated_validator_list) } pub fn input_delegated_validator_account_id_from_used_delegated_validator_list( - credentials_home_dir: &std::path::Path, + config: &crate::config::Config, ) -> color_eyre::eyre::Result> { - let used_delegated_validator_list = get_used_delegated_validator_list(credentials_home_dir) + let used_delegated_validator_list = get_used_delegated_validator_list(config)? .into_iter() .map(String::from) .collect::>(); @@ -1414,7 +1370,10 @@ pub fn input_delegated_validator_account_id_from_used_delegated_validator_list( }; let validator_account_id = crate::types::account_id::AccountId::from_str(&validator_account_id_str)?; - update_used_delegated_validator_list(credentials_home_dir, validator_account_id.as_ref()); + update_used_account_list_as_non_signer( + &config.credentials_home_dir, + validator_account_id.as_ref(), + ); Ok(Some(validator_account_id)) } From dde9cb869fbe857b55dd19eebc38b9e8cfc98516 Mon Sep 17 00:00:00 2001 From: FroVolod Date: Mon, 30 Oct 2023 12:19:35 +0200 Subject: [PATCH 41/44] updated cargo.lock --- Cargo.lock | 346 +++++++++++++++++++++++++++++------------------------ 1 file changed, 189 insertions(+), 157 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d22f4b815..cf8abeaff 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -24,7 +24,7 @@ dependencies = [ "pin-project-lite", "smallvec", "tokio", - "tokio-util 0.7.9", + "tokio-util 0.7.10", ] [[package]] @@ -87,24 +87,14 @@ dependencies = [ [[package]] name = "ahash" -version = "0.7.6" +version = "0.8.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fcb51a0695d8f838b1ee009b3fbf66bda078cd64590202a864a8f3e8c4315c47" -dependencies = [ - "getrandom 0.2.10", - "once_cell", - "version_check", -] - -[[package]] -name = "ahash" -version = "0.8.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c99f64d1e06488f620f932677e24bc6e2897582980441ae90a671415bd7ec2f" +checksum = "91429305e9f0a25f6205c5b8e0d2db09e0708a7a6df0f42212bb56c32c8ac97a" dependencies = [ "cfg-if", "once_cell", "version_check", + "zerocopy", ] [[package]] @@ -260,13 +250,33 @@ dependencies = [ "futures-lite", "log", "parking", - "polling", - "rustix 0.37.25", + "polling 2.8.0", + "rustix 0.37.27", "slab", "socket2", "waker-fn", ] +[[package]] +name = "async-io" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "10da8f3146014722c89e7859e1d7bb97873125d7346d10ca642ffab794355828" +dependencies = [ + "async-lock", + "cfg-if", + "concurrent-queue", + "futures-io", + "futures-lite", + "parking", + "polling 3.3.0", + "rustix 0.38.21", + "slab", + "tracing", + "waker-fn", + "windows-sys 0.48.0", +] + [[package]] name = "async-lock" version = "2.8.0" @@ -282,14 +292,14 @@ version = "1.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ea6438ba0a08d81529c69b36700fa2f95837bfe3e776ab39cde9c14d9149da88" dependencies = [ - "async-io", + "async-io 1.13.0", "async-lock", "async-signal", "blocking", "cfg-if", - "event-listener 3.0.0", + "event-listener 3.0.1", "futures-lite", - "rustix 0.38.19", + "rustix 0.38.21", "windows-sys 0.48.0", ] @@ -306,17 +316,17 @@ dependencies = [ [[package]] name = "async-signal" -version = "0.2.4" +version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d2a5415b7abcdc9cd7d63d6badba5288b2ca017e3fbd4173b8f405449f1a2399" +checksum = "9e47d90f65a225c4527103a8d747001fc56e375203592b25ad103e1ca13124c5" dependencies = [ - "async-io", + "async-io 2.1.0", "async-lock", "atomic-waker", "cfg-if", "futures-core", "futures-io", - "rustix 0.38.19", + "rustix 0.38.21", "signal-hook-registry", "slab", "windows-sys 0.48.0", @@ -407,9 +417,9 @@ checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" [[package]] name = "base64" -version = "0.21.4" +version = "0.21.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ba43ea6f343b788c8764558649e08df62f86c6ef251fdaeb1ffd010a9ae50a2" +checksum = "35636a1494ede3b646cc98f74f8e62c773a38a659ebc777a2cf26b9b74171df9" [[package]] name = "bip39" @@ -503,16 +513,6 @@ dependencies = [ "tracing", ] -[[package]] -name = "borsh" -version = "0.9.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "15bf3650200d8bffa99015595e10f1fbd17de07abbc25bb067da79e769939bfa" -dependencies = [ - "borsh-derive 0.9.3", - "hashbrown 0.11.2", -] - [[package]] name = "borsh" version = "0.10.3" @@ -524,16 +524,13 @@ dependencies = [ ] [[package]] -name = "borsh-derive" -version = "0.9.3" +name = "borsh" +version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6441c552f230375d18e3cc377677914d2ca2b0d36e52129fe15450a2dce46775" +checksum = "5e3f7359eeed8d454c38bbb25eb89d98b888b1060bbfeed2cda71cb013ff2dc2" dependencies = [ - "borsh-derive-internal 0.9.3", - "borsh-schema-derive-internal 0.9.3", - "proc-macro-crate 0.1.5", - "proc-macro2", - "syn 1.0.109", + "borsh-derive 1.1.1", + "cfg_aliases", ] [[package]] @@ -542,22 +539,25 @@ version = "0.10.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0754613691538d51f329cce9af41d7b7ca150bc973056f1156611489475f54f7" dependencies = [ - "borsh-derive-internal 0.10.3", - "borsh-schema-derive-internal 0.10.3", + "borsh-derive-internal", + "borsh-schema-derive-internal", "proc-macro-crate 0.1.5", "proc-macro2", "syn 1.0.109", ] [[package]] -name = "borsh-derive-internal" -version = "0.9.3" +name = "borsh-derive" +version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5449c28a7b352f2d1e592a8a28bf139bc71afb0764a14f3c02500935d8c44065" +checksum = "318d18ba283f9aa5bfef1405996ce66c584127f401be1403729ec88b10adc772" dependencies = [ + "once_cell", + "proc-macro-crate 1.3.1", "proc-macro2", "quote", - "syn 1.0.109", + "syn 2.0.38", + "syn_derive", ] [[package]] @@ -571,17 +571,6 @@ dependencies = [ "syn 1.0.109", ] -[[package]] -name = "borsh-schema-derive-internal" -version = "0.9.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cdbd5696d8bfa21d53d9fe39a714a18538bad11492a42d066dbbc395fb1951c0" -dependencies = [ - "proc-macro2", - "quote", - "syn 1.0.109", -] - [[package]] name = "borsh-schema-derive-internal" version = "0.10.3" @@ -682,6 +671,12 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "cfg_aliases" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd16c4719339c4530435d38e511904438d07cce7950afa3718a84ac36c10e89e" + [[package]] name = "chrono" version = "0.4.31" @@ -717,9 +712,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.4.6" +version = "4.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d04704f56c2cde07f43e8e2c154b43f216dc5c92fc98ada720177362f953b956" +checksum = "ac495e00dcec98c83465d5ad66c5c4fabd652fd6686e7c6269b117e729a6f17b" dependencies = [ "clap_builder", "clap_derive", @@ -727,9 +722,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.4.6" +version = "4.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0e231faeaca65ebd1ea3c737966bf858971cd38c3849107aa3ea7de90a804e45" +checksum = "c77ed9a32a62e6ca27175d00d29d05ca32e396ea1eb5fb01d8256b669cec7663" dependencies = [ "anstream", "anstyle", @@ -739,9 +734,9 @@ dependencies = [ [[package]] name = "clap_derive" -version = "4.4.2" +version = "4.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0862016ff20d69b84ef8247369fabf5c008a7417002411897d40ee1f4532b873" +checksum = "cf9804afaaf59a91e75b022a30fb7229a7901f60c755489cc61c9b423b836442" dependencies = [ "heck 0.4.1", "proc-macro2", @@ -751,9 +746,9 @@ dependencies = [ [[package]] name = "clap_lex" -version = "0.5.1" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cd7cc57abe963c6d3b9d8be5b06ba7c8957a930305ca90304f24ef040aa6f961" +checksum = "702fc72eb24e5a1e48ce58027a675bc24edd52096d5397d4aea7c6dd9eca0bd1" [[package]] name = "color-eyre" @@ -852,9 +847,9 @@ checksum = "e496a50fda8aacccc86d7529e2c1e0892dbd0f898a6b5645b5561b89c3210efa" [[package]] name = "cpufeatures" -version = "0.2.9" +version = "0.2.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a17b76ff3a4162b0b27f354a0c87015ddad39d35f9c0c36607a3bdd175dde1f1" +checksum = "ce420fe07aecd3e67c5f910618fe65e94158f6dcc0adf44e00d69ce2bdfe0fd0" dependencies = [ "libc", ] @@ -1212,9 +1207,9 @@ dependencies = [ [[package]] name = "enum-map" -version = "2.6.3" +version = "2.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c188012f8542dee7b3996e44dd89461d64aa471b0a7c71a1ae2f595d259e96e5" +checksum = "53337c2dbf26a3c31eccc73a37b10c1614e8d4ae99b6a50d553e8936423c1f16" dependencies = [ "enum-map-derive", ] @@ -1275,9 +1270,9 @@ checksum = "0206175f82b8d6bf6652ff7d71a1e27fd2e4efde587fd368662814d6ec1d9ce0" [[package]] name = "event-listener" -version = "3.0.0" +version = "3.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "29e56284f00d94c1bc7fd3c77027b4623c88c1f53d8d2394c6199f2921dea325" +checksum = "01cec0252c2afff729ee6f00e903d479fba81784c8e2bd77447673471fdfaea1" dependencies = [ "concurrent-queue", "parking", @@ -1388,9 +1383,9 @@ dependencies = [ [[package]] name = "futures" -version = "0.3.28" +version = "0.3.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23342abe12aba583913b2e62f22225ff9c950774065e4bfb61a19cd9770fec40" +checksum = "da0290714b38af9b4a7b094b8a37086d1b4e61f2df9122c3cad2577669145335" dependencies = [ "futures-channel", "futures-core", @@ -1403,9 +1398,9 @@ dependencies = [ [[package]] name = "futures-channel" -version = "0.3.28" +version = "0.3.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "955518d47e09b25bbebc7a18df10b81f0c766eaf4c4f1cccef2fca5f2a4fb5f2" +checksum = "ff4dd66668b557604244583e3e1e1eada8c5c2e96a6d0d6653ede395b78bbacb" dependencies = [ "futures-core", "futures-sink", @@ -1413,15 +1408,15 @@ dependencies = [ [[package]] name = "futures-core" -version = "0.3.28" +version = "0.3.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4bca583b7e26f571124fe5b7561d49cb2868d79116cfa0eefce955557c6fee8c" +checksum = "eb1d22c66e66d9d72e1758f0bd7d4fd0bee04cad842ee34587d68c07e45d088c" [[package]] name = "futures-executor" -version = "0.3.28" +version = "0.3.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ccecee823288125bd88b4d7f565c9e58e41858e47ab72e8ea2d64e93624386e0" +checksum = "0f4fb8693db0cf099eadcca0efe2a5a22e4550f98ed16aba6c48700da29597bc" dependencies = [ "futures-core", "futures-task", @@ -1430,9 +1425,9 @@ dependencies = [ [[package]] name = "futures-io" -version = "0.3.28" +version = "0.3.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fff74096e71ed47f8e023204cfd0aa1289cd54ae5430a9523be060cdb849964" +checksum = "8bf34a163b5c4c52d0478a4d757da8fb65cabef42ba90515efee0f6f9fa45aaa" [[package]] name = "futures-lite" @@ -1451,9 +1446,9 @@ dependencies = [ [[package]] name = "futures-macro" -version = "0.3.28" +version = "0.3.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89ca545a94061b6365f2c7355b4b32bd20df3ff95f02da9329b34ccc3bd6ee72" +checksum = "53b153fd91e4b0147f4aced87be237c98248656bb01050b96bf3ee89220a8ddb" dependencies = [ "proc-macro2", "quote", @@ -1462,21 +1457,21 @@ dependencies = [ [[package]] name = "futures-sink" -version = "0.3.28" +version = "0.3.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f43be4fe21a13b9781a69afa4985b0f6ee0e1afab2c6f454a8cf30e2b2237b6e" +checksum = "e36d3378ee38c2a36ad710c5d30c2911d752cb941c00c72dbabfb786a7970817" [[package]] name = "futures-task" -version = "0.3.28" +version = "0.3.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "76d3d132be6c0e6aa1534069c705a74a5997a356c0dc2f86a47765e5617c5b65" +checksum = "efd193069b0ddadc69c46389b740bbccdd97203899b48d09c5f7969591d6bae2" [[package]] name = "futures-util" -version = "0.3.28" +version = "0.3.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26b01e40b772d54cf6c6d721c1d1abd0647a0106a12ecaa1c186273392a69533" +checksum = "a19526d624e703a3179b3d322efec918b6246ea0fa51d41124525f00f1cc8104" dependencies = [ "futures-channel", "futures-core", @@ -1543,19 +1538,10 @@ dependencies = [ "indexmap 1.9.3", "slab", "tokio", - "tokio-util 0.7.9", + "tokio-util 0.7.10", "tracing", ] -[[package]] -name = "hashbrown" -version = "0.11.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e" -dependencies = [ - "ahash 0.7.6", -] - [[package]] name = "hashbrown" version = "0.12.3" @@ -1568,14 +1554,14 @@ version = "0.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "43a3c133739dddd0d2990f9a4bdf8eb4b21ef50e4851ca85ab661199821d510e" dependencies = [ - "ahash 0.8.3", + "ahash", ] [[package]] name = "hashbrown" -version = "0.14.1" +version = "0.14.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7dfda62a12f55daeae5015f81b0baea145391cb4520f86c248fc615d72640d12" +checksum = "f93e7192158dbcda357bdec5fb5788eebf8bbac027f3f33e719d29135ae84156" [[package]] name = "heck" @@ -1817,7 +1803,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8adf3ddd720272c6ea8bf59463c04e0f93d0bbf7c5439b691bca2987e0270897" dependencies = [ "equivalent", - "hashbrown 0.14.1", + "hashbrown 0.14.2", "serde", ] @@ -1895,9 +1881,9 @@ dependencies = [ [[package]] name = "ipnet" -version = "2.8.0" +version = "2.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28b29a3cd74f0f4598934efe3aeba42bae0eb4680554128851ebbecb02af14e6" +checksum = "8f518f335dce6725a761382244631d86cf0ccb2863413590b31338feb467f9c3" [[package]] name = "is-docker" @@ -1915,7 +1901,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cb0889898416213fab133e1d33a0e5858a48177452750691bde3666d0fdbaf8b" dependencies = [ "hermit-abi 0.3.3", - "rustix 0.38.19", + "rustix 0.38.21", "windows-sys 0.48.0", ] @@ -2119,9 +2105,9 @@ dependencies = [ [[package]] name = "mio" -version = "0.8.8" +version = "0.8.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "927a765cd3fc26206e66b296465fa9d3e5ab003e651c1b3c060e7956d96b19d2" +checksum = "3dce281c5e46beae905d4de1870d8b1509a9142b62eedf18b443b011ca8343d0" dependencies = [ "libc", "log", @@ -2292,11 +2278,11 @@ dependencies = [ [[package]] name = "near-gas" -version = "0.2.3" +version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0dac82d80f9dba5d879876ccee0fc8f4d91ca82552bad545e9f9714c5da49e4c" +checksum = "95b30860db1eceba9b445dc56558a0fdcdfe29fd612a088e697b32dfb681aaac" dependencies = [ - "borsh 0.9.3", + "borsh 1.1.1", "interactive-clap", "schemars", "serde", @@ -2420,7 +2406,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "775fec19ef51a341abdbf792a9dda5b4cb89f488f681b2fd689b9321d24db47b" dependencies = [ "arbitrary", - "base64 0.21.4", + "base64 0.21.5", "borsh 0.10.3", "bs58 0.4.0", "derive_more", @@ -2714,9 +2700,9 @@ checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" [[package]] name = "openssl-src" -version = "300.1.5+3.1.3" +version = "300.1.6+3.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "559068e4c12950d7dcaa1857a61725c0d38d4fc03ff8e070ab31a75d6e316491" +checksum = "439fac53e092cd7442a3660c85dde4643ab3b5bd39040912388dcdabf6b88085" dependencies = [ "cc", ] @@ -2926,11 +2912,25 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "polling" +version = "3.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e53b6af1f60f36f8c2ac2aad5459d75a5a9b4be1e8cdd40264f315d78193e531" +dependencies = [ + "cfg-if", + "concurrent-queue", + "pin-project-lite", + "rustix 0.38.21", + "tracing", + "windows-sys 0.48.0", +] + [[package]] name = "portable-atomic" -version = "1.4.3" +version = "1.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "31114a898e107c51bb1609ffaf55a0e011cf6a4d7f1170d0015a165082c0338b" +checksum = "3bccab0e7fd7cc19f820a1c8c91720af652d0c88dc9664dd72aef2614f04af3b" [[package]] name = "powerfmt" @@ -3280,7 +3280,7 @@ version = "0.11.22" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "046cd98826c46c2ac8ddecae268eb5c2e58628688a5fc7a2643704a73faba95b" dependencies = [ - "base64 0.21.4", + "base64 0.21.5", "bytes", "encoding_rs", "futures-core", @@ -3329,9 +3329,9 @@ dependencies = [ [[package]] name = "rustix" -version = "0.37.25" +version = "0.37.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d4eb579851244c2c03e7c24f501c3432bed80b8f720af1d6e5b0e0f01555a035" +checksum = "fea8ca367a3a01fe35e6943c400addf443c0f57670e6ec51196f71a4b8762dd2" dependencies = [ "bitflags 1.3.2", "errno", @@ -3343,9 +3343,9 @@ dependencies = [ [[package]] name = "rustix" -version = "0.38.19" +version = "0.38.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "745ecfa778e66b2b63c88a61cb36e0eea109e803b0b86bf9879fbc77c70e86ed" +checksum = "2b426b0506e5d50a7d8dafcf2e81471400deb602392c7dd110815afb4eaf02a3" dependencies = [ "bitflags 2.4.1", "errno", @@ -3504,18 +3504,18 @@ checksum = "836fa6a3e1e547f9a2c4040802ec865b5d85f4014efe00555d7090a3dcaa1090" [[package]] name = "serde" -version = "1.0.189" +version = "1.0.190" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e422a44e74ad4001bdc8eede9a4570ab52f71190e9c076d14369f38b9200537" +checksum = "91d3c334ca1ee894a2c6f6ad698fe8c435b76d504b13d436f0685d648d6d96f7" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.189" +version = "1.0.190" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e48d1f918009ce3145511378cf68d613e3b3d9137d67272562080d68a2b32d5" +checksum = "67c5609f394e5c2bd7fc51efda478004ea80ef42fee983d5c67a65e34f32c0e3" dependencies = [ "proc-macro2", "quote", @@ -3546,9 +3546,9 @@ dependencies = [ [[package]] name = "serde_repr" -version = "0.1.16" +version = "0.1.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8725e1dfadb3a50f7e5ce0b1a540466f6ed3fe7a0fca2ac2b8b831d31316bd00" +checksum = "3081f5ffbb02284dda55132aa26daecedd7372a42417bbbab6f14ab7d6bb9145" dependencies = [ "proc-macro2", "quote", @@ -3557,9 +3557,9 @@ dependencies = [ [[package]] name = "serde_spanned" -version = "0.6.3" +version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96426c9936fd7a0124915f9185ea1d20aa9445cc9821142f0a73bc9207a2e186" +checksum = "12022b835073e5b11e90a14f86838ceb1c8fb0325b72416845c487ac0fa95e80" dependencies = [ "serde", ] @@ -3582,7 +3582,7 @@ version = "3.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "64cd236ccc1b7a29e7e2739f27c0b2dd199804abc4290e32f59f3b68d6405c23" dependencies = [ - "base64 0.21.4", + "base64 0.21.5", "chrono", "hex 0.4.3", "indexmap 1.9.3", @@ -3607,9 +3607,9 @@ dependencies = [ [[package]] name = "serde_yaml" -version = "0.9.25" +version = "0.9.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a49e178e4452f45cb61d0cd8cebc1b0fafd3e41929e996cef79aa3aca91f574" +checksum = "3cc7a1570e38322cfe4154732e5110f887ea57e22b76f4bfd32b5bdd3368666c" dependencies = [ "indexmap 2.0.2", "itoa", @@ -3791,9 +3791,9 @@ dependencies = [ [[package]] name = "socket2" -version = "0.4.9" +version = "0.4.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "64a4a911eed85daf18834cfaa86a79b7d266ff93ff5ba14005426219480ed662" +checksum = "9f7916fc008ca5542385b89a3d3ce689953c143e9304a9bf8beec1de48994c0d" dependencies = [ "libc", "winapi", @@ -3861,6 +3861,18 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "syn_derive" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1329189c02ff984e9736652b1631330da25eaa6bc639089ed4915d25446cbe7b" +dependencies = [ + "proc-macro-error", + "proc-macro2", + "quote", + "syn 2.0.38", +] + [[package]] name = "system-configuration" version = "0.5.1" @@ -3895,14 +3907,14 @@ dependencies = [ [[package]] name = "tempfile" -version = "3.8.0" +version = "3.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb94d2f3cc536af71caac6b6fcebf65860b347e7ce0cc9ebe8f70d3e521054ef" +checksum = "7ef1adac450ad7f4b3c28589471ade84f25f731a7a0fe30d71dfa9f60fd808e5" dependencies = [ "cfg-if", "fastrand 2.0.1", - "redox_syscall 0.3.5", - "rustix 0.38.19", + "redox_syscall 0.4.1", + "rustix 0.38.21", "windows-sys 0.48.0", ] @@ -3919,18 +3931,18 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.49" +version = "1.0.50" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1177e8c6d7ede7afde3585fd2513e611227efd6481bd78d2e82ba1ce16557ed4" +checksum = "f9a7210f5c9a7156bb50aa36aed4c95afb51df0df00713949448cf9e97d382d2" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.49" +version = "1.0.50" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10712f02019e9288794769fba95cd6847df9874d49d871d062172f9dd41bc4cc" +checksum = "266b2e40bc00e5a6c09c3584011e08b06f123c00362c92b975ba9843aaaa14b8" dependencies = [ "proc-macro2", "quote", @@ -4068,9 +4080,9 @@ dependencies = [ [[package]] name = "tokio-util" -version = "0.7.9" +version = "0.7.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d68074620f57a0b21594d9735eb2e98ab38b17f80d3fcb189fca266771ca60d" +checksum = "5419f34732d9eb6ee4c3578b7989078579b7f039cbbb9ca2c4da015749371e15" dependencies = [ "bytes", "futures-core", @@ -4103,9 +4115,9 @@ dependencies = [ [[package]] name = "toml_datetime" -version = "0.6.3" +version = "0.6.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7cda73e2f1397b1262d6dfdcef8aafae14d1de7748d66822d3bfeeb6d03e5e4b" +checksum = "3550f4e9685620ac18a50ed434eb3aec30db8ba93b0287467bca5826ea25baf1" dependencies = [ "serde", ] @@ -4180,7 +4192,7 @@ dependencies = [ "rand 0.8.5", "slab", "tokio", - "tokio-util 0.7.9", + "tokio-util 0.7.10", "tower-layer", "tower-service", "tracing", @@ -4200,9 +4212,9 @@ checksum = "b6bc1c9ce2b5135ac7f93c72918fc37feb872bdc6a5533a8b85eb4b86bfdae52" [[package]] name = "tracing" -version = "0.1.39" +version = "0.1.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee2ef2af84856a50c1d430afce2fdded0a4ec7eda868db86409b4543df0797f9" +checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" dependencies = [ "log", "pin-project-lite", @@ -4264,12 +4276,12 @@ dependencies = [ [[package]] name = "tracing-log" -version = "0.1.3" +version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78ddad33d2d10b1ed7eb9d1f518a5674713876e97e5bb9b7345a7984fbb4f922" +checksum = "f751112709b4e791d8ce53e32c4ed2d353565a795ce84da2285393f41557bdf2" dependencies = [ - "lazy_static", "log", + "once_cell", "tracing-core", ] @@ -4542,7 +4554,7 @@ dependencies = [ "either", "home", "once_cell", - "rustix 0.38.19", + "rustix 0.38.21", ] [[package]] @@ -4764,7 +4776,7 @@ dependencies = [ "async-broadcast", "async-executor", "async-fs", - "async-io", + "async-io 1.13.0", "async-lock", "async-process", "async-recursion", @@ -4821,6 +4833,26 @@ dependencies = [ "zvariant", ] +[[package]] +name = "zerocopy" +version = "0.7.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd66a62464e3ffd4e37bd09950c2b9dd6c4f8767380fabba0d523f9a775bc85a" +dependencies = [ + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.7.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "255c4596d41e6916ced49cfafea18727b24d67878fa180ddfd69b9df34fd1726" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.38", +] + [[package]] name = "zeroize" version = "1.3.0" From 60f7e5c598258a2ba11aee01bfc01b8dc1920ed1 Mon Sep 17 00:00:00 2001 From: Vlad Frolov Date: Tue, 31 Oct 2023 01:04:47 +0100 Subject: [PATCH 42/44] fixed GUIDES --- docs/GUIDE.en.md | 14 ++-- docs/GUIDE.ru.md | 117 +++++++++++---------------- src/commands/staking/delegate/mod.rs | 4 +- 3 files changed, 58 insertions(+), 77 deletions(-) diff --git a/docs/GUIDE.en.md b/docs/GUIDE.en.md index a9eefdb1c..8c98d5b3b 100644 --- a/docs/GUIDE.en.md +++ b/docs/GUIDE.en.md @@ -1416,7 +1416,7 @@ Delegated stake balance on validator for ДСмонстрация Ρ€Π°Π±ΠΎΡ‚Ρ‹ ΠΊΠΎΠΌΠ°Π½Π΄Ρ‹ Π² ΠΈΠ½Ρ‚Π΅Ρ€Π°ΠΊΡ‚ΠΈΠ²Π½ΠΎΠΌ Ρ€Π΅ΠΆΠΈΠΌΠ΅ @@ -63,7 +63,7 @@ near --offline tokens \ 2. ДСйствия с подписанной Ρ‚Ρ€Π°Π½Π·Π°ΠΊΡ†ΠΈΠ΅ΠΉ - _near CLI_ ΠΏΠΎΠ΄Π΄Π΅Ρ€ΠΆΠΈΠ²Π°Π΅Ρ‚ ΠΌΠ΅Ρ‚Π°-Ρ‚Ρ€Π°Π½Π·Π°ΠΊΡ†ΠΈΠΈ, описанныС Π² спСцификации [NEP-366](https://near.github.io/nearcore/architecture/how/meta-tx.html#meta-transactions). Для Π΅Ρ‘ создания достаточно ΡƒΠΊΠ°Π·Π°Ρ‚ΡŒ _network_, ΠΏΠΎΠ΄Π΄Π΅Ρ€ΠΆΠΈΠ²Π°ΡŽΡ‰ΡƒΡŽ ΠΌΠ΅Ρ‚Π°-Ρ‚Ρ€Π°Π½Π·Π°ΠΊΡ†ΠΈΠΈ. Π£Π·Π½Π°Ρ‚ΡŒ ΠΎ Ρ‚Π°ΠΊΠΎΠΉ ΠΏΠΎΠ΄Π΄Π΅Ρ€ΠΆΠΊΠ΅ ΠΌΠΎΠΆΠ½ΠΎ Π² [ΠΊΠΎΠ½Ρ„ΠΈΠ³ΡƒΡ€Π°Ρ†ΠΈΠΎΠ½Π½ΠΎΠΌ Ρ„Π°ΠΉΠ»Π΅](#show-connections---Show-a-list-of-network-connections). Π—Π° Π²ΠΎΠ·ΠΌΠΎΠΆΠ½ΠΎΡΡ‚ΡŒ ΠΏΠΎΠ΄Π΄Π΅Ρ€ΠΆΠΊΠΈ ΠΌΠ΅Ρ‚Π°-Ρ‚Ρ€Π°Π½Π·Π°ΠΊΡ†ΠΈΠΈ ΠΎΡ‚Π²Π΅Ρ‡Π°Π΅Ρ‚ ΠΏΠΎΠ»Π΅ *meta_transaction_relayer_url*. НапримСр: + _near CLI_ ΠΏΠΎΠ΄Π΄Π΅Ρ€ΠΆΠΈΠ²Π°Π΅Ρ‚ ΠΌΠ΅Ρ‚Π°-Ρ‚Ρ€Π°Π½Π·Π°ΠΊΡ†ΠΈΠΈ, описанныС Π² спСцификации [NEP-366](https://near.github.io/nearcore/architecture/how/meta-tx.html#meta-transactions). Для Π΅Ρ‘ создания достаточно ΡƒΠΊΠ°Π·Π°Ρ‚ΡŒ _network_, ΠΏΠΎΠ΄Π΄Π΅Ρ€ΠΆΠΈΠ²Π°ΡŽΡ‰ΡƒΡŽ ΠΌΠ΅Ρ‚Π°-Ρ‚Ρ€Π°Π½Π·Π°ΠΊΡ†ΠΈΠΈ. Π£Π·Π½Π°Ρ‚ΡŒ ΠΎ Ρ‚Π°ΠΊΠΎΠΉ ΠΏΠΎΠ΄Π΄Π΅Ρ€ΠΆΠΊΠ΅ ΠΌΠΎΠΆΠ½ΠΎ Π² [ΠΊΠΎΠ½Ρ„ΠΈΠ³ΡƒΡ€Π°Ρ†ΠΈΠΎΠ½Π½ΠΎΠΌ Ρ„Π°ΠΉΠ»Π΅](#show-connections---Show-a-list-of-network-connections). Π—Π° Π²ΠΎΠ·ΠΌΠΎΠΆΠ½ΠΎΡΡ‚ΡŒ ΠΏΠΎΠ΄Π΄Π΅Ρ€ΠΆΠΊΠΈ ΠΌΠ΅Ρ‚Π°-Ρ‚Ρ€Π°Π½Π·Π°ΠΊΡ†ΠΈΠΈ ΠΎΡ‚Π²Π΅Ρ‡Π°Π΅Ρ‚ ΠΏΠΎΠ»Π΅ *meta_transaction_relayer_url*. НапримСр: ```txt meta_transaction_relayer_url = "https://near-testnet.api.pagoda.co/relay" ``` @@ -246,7 +246,7 @@ near account \ network-config testnet ``` -Π’Ρ‹ Π±ΡƒΠ΄Π΅Ρ‚Π΅ ΠΏΠ΅Ρ€Π΅Π½Π°ΠΏΡ€Π°Π²Π»Π΅Π½Ρ‹ Π±Ρ€Π°ΡƒΠ·Π΅Ρ€ для Π°Π²Ρ‚ΠΎΡ€ΠΈΠ·Π°Ρ†ΠΈΠΈ. +Π’Ρ‹ Π±ΡƒΠ΄Π΅Ρ‚Π΅ ΠΏΠ΅Ρ€Π΅Π½Π°ΠΏΡ€Π°Π²Π»Π΅Π½Ρ‹ Π±Ρ€Π°ΡƒΠ·Π΅Ρ€ для Π°Π²Ρ‚ΠΎΡ€ΠΈΠ·Π°Ρ†ΠΈΠΈ. По ΡƒΠΌΠΎΠ»Ρ‡Π°Π½ΠΈΡŽ - это https://app.mynearwallet.com/ (для testnet - https://testnet.mynearwallet.com/). Но Π²Ρ‹ ΠΌΠΎΠΆΠ΅Ρ‚Π΅ ΠΈΠ·ΠΌΠ΅Π½ΠΈΡ‚ΡŒ адрСс для Π°Π²Ρ‚ΠΎΡ€ΠΈΠ·Π°Ρ†ΠΈΠΈ с ΠΏΠΎΠΌΠΎΡ‰ΡŒΡŽ Ρ„Π»Π°Π³Π° `--wallet-url`: ```txt near account \ @@ -334,7 +334,7 @@ near account \ network-config testnet ``` -Π’Ρ‹ Π±ΡƒΠ΄Π΅Ρ‚Π΅ ΠΏΠ΅Ρ€Π΅Π½Π°ΠΏΡ€Π°Π²Π»Π΅Π½Ρ‹ Π±Ρ€Π°ΡƒΠ·Π΅Ρ€. +Π’Ρ‹ Π±ΡƒΠ΄Π΅Ρ‚Π΅ ΠΏΠ΅Ρ€Π΅Π½Π°ΠΏΡ€Π°Π²Π»Π΅Π½Ρ‹ Π±Ρ€Π°ΡƒΠ·Π΅Ρ€. По ΡƒΠΌΠΎΠ»Ρ‡Π°Π½ΠΈΡŽ - это https://app.mynearwallet.com/ (для testnet - https://testnet.mynearwallet.com/). Но Π²Ρ‹ ΠΌΠΎΠΆΠ΅Ρ‚Π΅ ΠΈΠ·ΠΌΠ΅Π½ΠΈΡ‚ΡŒ адрСс для Π°Π²Ρ‚ΠΎΡ€ΠΈΠ·Π°Ρ†ΠΈΠΈ с ΠΏΠΎΠΌΠΎΡ‰ΡŒΡŽ Ρ„Π»Π°Π³Π° `--wallet-url`: ```txt near account \ @@ -392,9 +392,9 @@ Here is the private key for account : ed25519:4TKr1c7p...y7p8 #### sponsor-by-faucet-service - I would like the faucet service sponsor to cover the cost of creating an account (testnet only for now) -Π‘ ΠΏΠΎΠΌΠΎΡ‰ΡŒΡŽ этой ΠΊΠΎΠΌΠ°Π½Π΄Ρ‹ ΠΌΠΎΠΆΠ½ΠΎ ΡΠΎΠ·Π΄Π°Ρ‚ΡŒ Π°ΠΊΠΊΠ°ΡƒΠ½Ρ‚ ΠΏΡ€ΠΈ ΠΏΠΎΠΌΠΎΡ‰ΠΈ Π²ΡΠΏΠΎΠΌΠΎΠ³Π°Ρ‚Π΅Π»ΡŒΠ½ΠΎΠ³ΠΎ сСрвиса, ΠΊΠΎΡ‚ΠΎΡ€Ρ‹ΠΉ ΠΌΠΎΠΆΠ΅Ρ‚ ΡΠΏΠΎΠ½ΡΠΈΡ€ΠΎΠ²Π°Ρ‚ΡŒ созданиС ΡƒΡ‡Π΅Ρ‚Π½ΠΎΠΉ записи (ΠΏΠΎΠΊΠ° Ρ‚ΠΎΠ»ΡŒΠΊΠΎ testnet). -ΠŸΡ€ΠΈ Π΄ΠΎΠ±Π°Π²Π»Π΅Π½ΠΈΠΈ собствСнной сСти Π² ΠΊΠΎΠ½Ρ„ΠΈΠ³ΡƒΡ€Π°Ρ‚ΠΎΡ€Π΅ [add-connection](#add-connection---Add-a-network-connection) ΠΌΠΎΠΆΠ΅Ρ‚Π΅ ΡƒΠΊΠ°Π·Π°Ρ‚ΡŒ свой сСрвис Π² ΠΏΠΎΠ»Π΅ *faucet_url*. -ΠšΠ»ΡŽΡ‡ΠΈ доступа ΠΊ создаваСмому Π°ΠΊΠΊΠ°ΡƒΠ½Ρ‚Ρƒ ΠΌΠΎΠΆΠ½ΠΎ Π΄ΠΎΠ±Π°Π²ΠΈΡ‚ΡŒ нСсколькими способами: +Π‘ ΠΏΠΎΠΌΠΎΡ‰ΡŒΡŽ этой ΠΊΠΎΠΌΠ°Π½Π΄Ρ‹ ΠΌΠΎΠΆΠ½ΠΎ ΡΠΎΠ·Π΄Π°Ρ‚ΡŒ Π°ΠΊΠΊΠ°ΡƒΠ½Ρ‚ ΠΏΡ€ΠΈ ΠΏΠΎΠΌΠΎΡ‰ΠΈ Π²ΡΠΏΠΎΠΌΠΎΠ³Π°Ρ‚Π΅Π»ΡŒΠ½ΠΎΠ³ΠΎ сСрвиса, ΠΊΠΎΡ‚ΠΎΡ€Ρ‹ΠΉ ΠΌΠΎΠΆΠ΅Ρ‚ ΡΠΏΠΎΠ½ΡΠΈΡ€ΠΎΠ²Π°Ρ‚ΡŒ созданиС ΡƒΡ‡Π΅Ρ‚Π½ΠΎΠΉ записи (ΠΏΠΎΠΊΠ° Ρ‚ΠΎΠ»ΡŒΠΊΠΎ testnet). +ΠŸΡ€ΠΈ Π΄ΠΎΠ±Π°Π²Π»Π΅Π½ΠΈΠΈ собствСнной сСти Π² ΠΊΠΎΠ½Ρ„ΠΈΠ³ΡƒΡ€Π°Ρ‚ΠΎΡ€Π΅ [add-connection](#add-connection---Add-a-network-connection) ΠΌΠΎΠΆΠ΅Ρ‚Π΅ ΡƒΠΊΠ°Π·Π°Ρ‚ΡŒ свой сСрвис Π² ΠΏΠΎΠ»Π΅ *faucet_url*. +ΠšΠ»ΡŽΡ‡ΠΈ доступа ΠΊ создаваСмому Π°ΠΊΠΊΠ°ΡƒΠ½Ρ‚Ρƒ ΠΌΠΎΠΆΠ½ΠΎ Π΄ΠΎΠ±Π°Π²ΠΈΡ‚ΡŒ нСсколькими способами: - [autogenerate-new-keypair](#autogenerate-new-keypair---Automatically-generate-a-key-pair) - [use-manually-provided-seed-prase](#use-manually-provided-seed-prase---Use-the-provided-seed-phrase-manually) - [use-manually-provided-public-key](#use-manually-provided-public-key---Use-the-provided-public-key-manually) @@ -517,8 +517,8 @@ https://explorer.testnet.near.org/transactions/BStBXVisyR5FUj3ZfCAeQ1ohfwTnx2vTb #### fund-myself - I would like fund myself to cover the cost of creating an account -Π‘ ΠΏΠΎΠΌΠΎΡ‰ΡŒΡŽ этой ΠΊΠΎΠΌΠ°Π½Π΄Ρ‹ ΠΌΠΎΠΆΠ½ΠΎ ΡΠΎΠ·Π΄Π°Ρ‚ΡŒ ΠΊΠ°ΠΊ суб-Π°ΠΊΠΊΠ°ΡƒΠ½Ρ‚, Ρ‚Π°ΠΊ ΠΈ Π°ΠΊΠΊΠ°ΡƒΠ½Ρ‚ с ΠΊΠΎΡ€ΠΎΡ‚ΠΊΠΈΠΌ ΠΈΠΌΠ΅Π½Π΅ΠΌ, Π½Π°ΠΏΡ€ΠΈΠΌΠ΅Ρ€, alice.near ΠΈΠ»ΠΈ alice.testnet (Π² сСти testnet). -ΠšΠ»ΡŽΡ‡ΠΈ доступа ΠΊ создаваСмому Π°ΠΊΠΊΠ°ΡƒΠ½Ρ‚Ρƒ ΠΌΠΎΠΆΠ½ΠΎ Π΄ΠΎΠ±Π°Π²ΠΈΡ‚ΡŒ нСсколькими способами: +Π‘ ΠΏΠΎΠΌΠΎΡ‰ΡŒΡŽ этой ΠΊΠΎΠΌΠ°Π½Π΄Ρ‹ ΠΌΠΎΠΆΠ½ΠΎ ΡΠΎΠ·Π΄Π°Ρ‚ΡŒ ΠΊΠ°ΠΊ суб-Π°ΠΊΠΊΠ°ΡƒΠ½Ρ‚, Ρ‚Π°ΠΊ ΠΈ Π°ΠΊΠΊΠ°ΡƒΠ½Ρ‚ с ΠΊΠΎΡ€ΠΎΡ‚ΠΊΠΈΠΌ ΠΈΠΌΠ΅Π½Π΅ΠΌ, Π½Π°ΠΏΡ€ΠΈΠΌΠ΅Ρ€, alice.near ΠΈΠ»ΠΈ alice.testnet (Π² сСти testnet). +ΠšΠ»ΡŽΡ‡ΠΈ доступа ΠΊ создаваСмому Π°ΠΊΠΊΠ°ΡƒΠ½Ρ‚Ρƒ ΠΌΠΎΠΆΠ½ΠΎ Π΄ΠΎΠ±Π°Π²ΠΈΡ‚ΡŒ нСсколькими способами: - [autogenerate-new-keypair](#autogenerate-new-keypair---Automatically-generate-a-key-pair) - [use-manually-provided-seed-prase](#use-manually-provided-seed-prase---Use-the-provided-seed-phrase-manually) - [use-manually-provided-public-key](#use-manually-provided-public-key---Use-the-provided-public-key-manually) @@ -547,7 +547,7 @@ Transaction ID: DRT3EpCK9iT5APyGgfcgSoLPCLCYYKtnrVgDhGLDEZFo To see the transaction in the transaction explorer, please open this url in your browser: https://explorer.testnet.near.org/transactions/DRT3EpCK9iT5APyGgfcgSoLPCLCYYKtnrVgDhGLDEZFo -The data for the access key is saved in a file /Users/frovolod/.near-credentials/testnet/new.fro_volod.testnet/ed25519_3ngtirechhepHKrzfkdgqqtwqSMtdbSLR6N1c4ivnzu6.json +The data for the access key is saved in a file /Users/frovolod/.near-credentials/testnet/new.fro_volod.testnet/ed25519_3ngtirechhepHKrzfkdgqqtwqSMtdbSLR6N1c4ivnzu6.json The data for the access key is saved in a file "/Users/frovolod/.near-credentials/testnet/new.fro_volod.testnet.json" ``` @@ -892,7 +892,7 @@ https://explorer.testnet.near.org/transactions/EHvB47npN8Z46qhsrw5XpKmD3n3jDn4MG #### list-keys - View a list of access keys of an account -ΠŸΡ€ΠΎΡΠΌΠΎΡ‚Ρ€ ΠΊΠ»ΡŽΡ‡Π΅ΠΉ доступа Π°ΠΊΠΊΠ°ΡƒΠ½Ρ‚Π° Π²ΠΎΠ·ΠΌΠΎΠΆΠ΅Π½ Π½Π° Ρ‚Π΅ΠΊΡƒΡ‰ΠΈΠΉ ΠΌΠΎΠΌΠ΅Π½Ρ‚ Π²Ρ€Π΅ΠΌΠ΅Π½ΠΈ (***now***) ΠΈ Π½Π° ΠΎΠΏΡ€Π΅Π΄Π΅Π»Π΅Π½Ρ‹ΠΉ ΠΌΠΎΠΌΠ΅Π½Ρ‚ Π² ΠΏΡ€ΠΎΡˆΠ»ΠΎΠΌ, ΡƒΠΊΠ°Π·Π°Π² Π±Π»ΠΎΠΊ (***at-block-height*** ΠΈΠ»ΠΈ ***at-block-hash***). +ΠŸΡ€ΠΎΡΠΌΠΎΡ‚Ρ€ ΠΊΠ»ΡŽΡ‡Π΅ΠΉ доступа Π°ΠΊΠΊΠ°ΡƒΠ½Ρ‚Π° Π²ΠΎΠ·ΠΌΠΎΠΆΠ΅Π½ Π½Π° Ρ‚Π΅ΠΊΡƒΡ‰ΠΈΠΉ ΠΌΠΎΠΌΠ΅Π½Ρ‚ Π²Ρ€Π΅ΠΌΠ΅Π½ΠΈ (***now***) ΠΈ Π½Π° ΠΎΠΏΡ€Π΅Π΄Π΅Π»Π΅Π½Ρ‹ΠΉ ΠΌΠΎΠΌΠ΅Π½Ρ‚ Π² ΠΏΡ€ΠΎΡˆΠ»ΠΎΠΌ, ΡƒΠΊΠ°Π·Π°Π² Π±Π»ΠΎΠΊ (***at-block-height*** ΠΈΠ»ΠΈ ***at-block-hash***). ΠŸΡ€ΠΈΠΌΠ΅Ρ€Ρ‹ использования этих ΠΏΠ°Ρ€Π°ΠΌΠ΅Ρ‚Ρ€ΠΎΠ² рассмотрСны Π² Ρ€Π°Π·Π΄Π΅Π»Π΅ [View properties for an account](#view-account-summary---view-properties-for-an-account). Для просмотра списка ΠΊΠ»ΡŽΡ‡Π΅ΠΉ доступа Π½Π΅ΠΎΠ±Ρ…ΠΎΠ΄ΠΈΠΌΠΎ ввСсти Π² ΠΊΠΎΠΌΠ°Π½Π΄Π½ΠΎΠΉ строкС Ρ‚Π΅Ρ€ΠΌΠΈΠ½Π°Π»Π°: @@ -1230,7 +1230,7 @@ https://explorer.testnet.near.org/transactions/9q2VbakZbj5ja6GAFXpFnbtbYHijEHyT7 #### view-near-balance - View the balance of Near tokens -ΠŸΡ€ΠΎΡΠΌΠΎΡ‚Ρ€ баланса Π°ΠΊΠΊΠ°ΡƒΠ½Ρ‚Π° Π²ΠΎΠ·ΠΌΠΎΠΆΠ΅Π½ Π½Π° Ρ‚Π΅ΠΊΡƒΡ‰ΠΈΠΉ ΠΌΠΎΠΌΠ΅Π½Ρ‚ Π²Ρ€Π΅ΠΌΠ΅Π½ΠΈ (***now***) ΠΈ Π½Π° ΠΎΠΏΡ€Π΅Π΄Π΅Π»Π΅Π½Ρ‹ΠΉ ΠΌΠΎΠΌΠ΅Π½Ρ‚ Π² ΠΏΡ€ΠΎΡˆΠ»ΠΎΠΌ, ΡƒΠΊΠ°Π·Π°Π² Π±Π»ΠΎΠΊ (***at-block-height*** ΠΈΠ»ΠΈ ***at-block-hash***). +ΠŸΡ€ΠΎΡΠΌΠΎΡ‚Ρ€ баланса Π°ΠΊΠΊΠ°ΡƒΠ½Ρ‚Π° Π²ΠΎΠ·ΠΌΠΎΠΆΠ΅Π½ Π½Π° Ρ‚Π΅ΠΊΡƒΡ‰ΠΈΠΉ ΠΌΠΎΠΌΠ΅Π½Ρ‚ Π²Ρ€Π΅ΠΌΠ΅Π½ΠΈ (***now***) ΠΈ Π½Π° ΠΎΠΏΡ€Π΅Π΄Π΅Π»Π΅Π½Ρ‹ΠΉ ΠΌΠΎΠΌΠ΅Π½Ρ‚ Π² ΠΏΡ€ΠΎΡˆΠ»ΠΎΠΌ, ΡƒΠΊΠ°Π·Π°Π² Π±Π»ΠΎΠΊ (***at-block-height*** ΠΈΠ»ΠΈ ***at-block-hash***). ΠŸΡ€ΠΈΠΌΠ΅Ρ€Ρ‹ использования этих ΠΏΠ°Ρ€Π°ΠΌΠ΅Ρ‚Ρ€ΠΎΠ² рассмотрСны Π² Ρ€Π°Π·Π΄Π΅Π»Π΅ [View properties for an account](#view-account-summary---view-properties-for-an-account). Для просмотра срСдств Π² NEAR Ρ‚ΠΎΠΊΠ΅Π½Π°Ρ… Π½Π° счСту Π°ΠΊΠΊΠ°ΡƒΠ½Ρ‚Π° Π½Π΅ΠΎΠ±Ρ…ΠΎΠ΄ΠΈΠΌΠΎ ввСсти Π² ΠΊΠΎΠΌΠ°Π½Π΄Π½ΠΎΠΉ строкС Ρ‚Π΅Ρ€ΠΌΠΈΠ½Π°Π»Π°: @@ -1257,7 +1257,7 @@ fro_volod.testnet account has 169.589001320890476999999994 NEAR available for tr #### view-ft-balance - View the balance of FT tokens -ΠŸΡ€ΠΎΡΠΌΠΎΡ‚Ρ€ баланса Π°ΠΊΠΊΠ°ΡƒΠ½Ρ‚Π° Π²ΠΎΠ·ΠΌΠΎΠΆΠ΅Π½ Π½Π° Ρ‚Π΅ΠΊΡƒΡ‰ΠΈΠΉ ΠΌΠΎΠΌΠ΅Π½Ρ‚ Π²Ρ€Π΅ΠΌΠ΅Π½ΠΈ (***now***) ΠΈ Π½Π° ΠΎΠΏΡ€Π΅Π΄Π΅Π»Π΅Π½Ρ‹ΠΉ ΠΌΠΎΠΌΠ΅Π½Ρ‚ Π² ΠΏΡ€ΠΎΡˆΠ»ΠΎΠΌ, ΡƒΠΊΠ°Π·Π°Π² Π±Π»ΠΎΠΊ (***at-block-height*** ΠΈΠ»ΠΈ ***at-block-hash***). +ΠŸΡ€ΠΎΡΠΌΠΎΡ‚Ρ€ баланса Π°ΠΊΠΊΠ°ΡƒΠ½Ρ‚Π° Π²ΠΎΠ·ΠΌΠΎΠΆΠ΅Π½ Π½Π° Ρ‚Π΅ΠΊΡƒΡ‰ΠΈΠΉ ΠΌΠΎΠΌΠ΅Π½Ρ‚ Π²Ρ€Π΅ΠΌΠ΅Π½ΠΈ (***now***) ΠΈ Π½Π° ΠΎΠΏΡ€Π΅Π΄Π΅Π»Π΅Π½Ρ‹ΠΉ ΠΌΠΎΠΌΠ΅Π½Ρ‚ Π² ΠΏΡ€ΠΎΡˆΠ»ΠΎΠΌ, ΡƒΠΊΠ°Π·Π°Π² Π±Π»ΠΎΠΊ (***at-block-height*** ΠΈΠ»ΠΈ ***at-block-hash***). ΠŸΡ€ΠΈΠΌΠ΅Ρ€Ρ‹ использования этих ΠΏΠ°Ρ€Π°ΠΌΠ΅Ρ‚Ρ€ΠΎΠ² рассмотрСны Π² Ρ€Π°Π·Π΄Π΅Π»Π΅ [View properties for an account](#view-account-summary---view-properties-for-an-account). Для просмотра срСдств Π² FT Ρ‚ΠΎΠΊΠ΅Π½Π°Ρ… Π½Π° счСту Π°ΠΊΠΊΠ°ΡƒΠ½Ρ‚Π° Π½Π΅ΠΎΠ±Ρ…ΠΎΠ΄ΠΈΠΌΠΎ ввСсти Π² ΠΊΠΎΠΌΠ°Π½Π΄Π½ΠΎΠΉ строкС Ρ‚Π΅Ρ€ΠΌΠΈΠ½Π°Π»Π°: @@ -1284,7 +1284,7 @@ fro_volod.testnet account has "31942967677775774595" FT tokens (FT-contract: usd #### view-nft-assets - View the balance of NFT tokens -ΠŸΡ€ΠΎΡΠΌΠΎΡ‚Ρ€ баланса Π°ΠΊΠΊΠ°ΡƒΠ½Ρ‚Π° Π²ΠΎΠ·ΠΌΠΎΠΆΠ΅Π½ Π½Π° Ρ‚Π΅ΠΊΡƒΡ‰ΠΈΠΉ ΠΌΠΎΠΌΠ΅Π½Ρ‚ Π²Ρ€Π΅ΠΌΠ΅Π½ΠΈ (***now***) ΠΈ Π½Π° ΠΎΠΏΡ€Π΅Π΄Π΅Π»Π΅Π½Ρ‹ΠΉ ΠΌΠΎΠΌΠ΅Π½Ρ‚ Π² ΠΏΡ€ΠΎΡˆΠ»ΠΎΠΌ, ΡƒΠΊΠ°Π·Π°Π² Π±Π»ΠΎΠΊ (***at-block-height*** ΠΈΠ»ΠΈ ***at-block-hash***). +ΠŸΡ€ΠΎΡΠΌΠΎΡ‚Ρ€ баланса Π°ΠΊΠΊΠ°ΡƒΠ½Ρ‚Π° Π²ΠΎΠ·ΠΌΠΎΠΆΠ΅Π½ Π½Π° Ρ‚Π΅ΠΊΡƒΡ‰ΠΈΠΉ ΠΌΠΎΠΌΠ΅Π½Ρ‚ Π²Ρ€Π΅ΠΌΠ΅Π½ΠΈ (***now***) ΠΈ Π½Π° ΠΎΠΏΡ€Π΅Π΄Π΅Π»Π΅Π½Ρ‹ΠΉ ΠΌΠΎΠΌΠ΅Π½Ρ‚ Π² ΠΏΡ€ΠΎΡˆΠ»ΠΎΠΌ, ΡƒΠΊΠ°Π·Π°Π² Π±Π»ΠΎΠΊ (***at-block-height*** ΠΈΠ»ΠΈ ***at-block-hash***). ΠŸΡ€ΠΈΠΌΠ΅Ρ€Ρ‹ использования этих ΠΏΠ°Ρ€Π°ΠΌΠ΅Ρ‚Ρ€ΠΎΠ² рассмотрСны Π² Ρ€Π°Π·Π΄Π΅Π»Π΅ [View properties for an account](#view-account-summary---view-properties-for-an-account). Для просмотра срСдств Π² NFT Ρ‚ΠΎΠΊΠ΅Π½Π°Ρ… Π½Π° счСту Π°ΠΊΠΊΠ°ΡƒΠ½Ρ‚Π° Π½Π΅ΠΎΠ±Ρ…ΠΎΠ΄ΠΈΠΌΠΎ ввСсти Π² ΠΊΠΎΠΌΠ°Π½Π΄Π½ΠΎΠΉ строкС Ρ‚Π΅Ρ€ΠΌΠΈΠ½Π°Π»Π°: @@ -1381,7 +1381,6 @@ near staking \ #### delegation - Delegation management - [view-balance](#View-the-total-balance-for-a-given-account) -- [deposit](#deposit---Deposits-the-attached-amount-into-the-inner-account-of-the-predecessor) - [deposit-and-stake](#deposit-and-stake---Deposits-the-attached-amount-into-the-inner-account-of-the-predecessor-and-stakes-it) - [stake](#stake---Staking-the-given-amount-from-the-inner-account-of-the-predecessor) - [stake-all](#stake-all---Staking-all-available-unstaked-balance-from-the-inner-account-of-the-predecessor) @@ -1390,9 +1389,10 @@ near staking \ - [withdraw](#withdraw---Withdrawing-the-non-staked-balance-for-given-account) - [withdraw-all](#withdraw-all---Withdrawing-the-entire-unstaked-balance-from-the-predecessor-account) -##### view-balance - View the total balance for a given account +##### view-balance - View the delegated stake balance for a given account + +Для просмотра ΠΏΠΎΡ€ΡƒΡ‡Π΅Π½Π½ΠΎΠ³ΠΎ баланса Π°ΠΊΠΊΠ°ΡƒΠ½Ρ‚Π° Π² ΠΎΠ±Ρ‰ΠΈΠΉ Ρ„ΠΎΠ½Π΄ Π²Π°Π»ΠΈΠ΄Π°Ρ‚ΠΎΡ€Π° Π½Π΅ΠΎΠ±Ρ…ΠΎΠ΄ΠΈΠΌΠΎ ввСсти Π² ΠΊΠΎΠΌΠ°Π½Π΄Π½ΠΎΠΉ строкС Ρ‚Π΅Ρ€ΠΌΠΈΠ½Π°Π»Π°: -Для просмотра баланса Π°ΠΊΠΊΠ°ΡƒΠ½Ρ‚Π° Ρƒ Π΄Π΅Π»Π΅Π³ΠΈΡ€ΠΎΠ°Π½Π½ΠΎΠ³ΠΎ Π²Π°Π»ΠΈΠ΄Π°Ρ‚ΠΎΡ€Π° Π½Π΅ΠΎΠ±Ρ…ΠΎΠ΄ΠΈΠΌΠΎ ввСсти Π² ΠΊΠΎΠΌΠ°Π½Π΄Π½ΠΎΠΉ строкС Ρ‚Π΅Ρ€ΠΌΠΈΠ½Π°Π»Π°: ```txt near staking \ delegation volodymyr.testnet \ @@ -1417,34 +1417,10 @@ Balance on validator for : -##### deposit - Deposits the attached amount into the inner account of the predecessor +##### deposit-and-stake - Delegate NEAR tokens to a validator's staking pool -Π§Ρ‚ΠΎΠ±Ρ‹ Ρ€Π°Π·ΠΌΠ΅ΡΡ‚ΠΈΡ‚ΡŒ Π΄Π΅ΠΏΠΎΠ·ΠΈΡ‚ Π’Π°ΡˆΠ΅Π³ΠΎ Π°ΠΊΠΊΠ°ΡƒΠ½Ρ‚Π° Ρƒ Π΄Π΅Π»Π΅Π³ΠΈΡ€ΠΎΠ°Π½Π½ΠΎΠ³ΠΎ Π²Π°Π»ΠΈΠ΄Π°Ρ‚ΠΎΡ€Π°, Π½Π΅ΠΎΠ±Ρ…ΠΎΠ΄ΠΈΠΌΠΎ ввСсти Π² ΠΊΠΎΠΌΠ°Π½Π΄Π½ΠΎΠΉ строкС Ρ‚Π΅Ρ€ΠΌΠΈΠ½Π°Π»Π°: -```txt -near staking \ - delegation volodymyr.testnet \ - deposit '10 NEAR' aurora.pool.f863973.m0 \ - network-config testnet \ - sign-with-legacy-keychain \ - send -``` - -
Π Π΅Π·ΡƒΠ»ΡŒΡ‚Π°Ρ‚ выполнСния ΠΊΠΎΠΌΠ°Π½Π΄Ρ‹ +Π§Ρ‚ΠΎΠ±Ρ‹ ΠΏΠΎΡ€ΡƒΡ‡ΠΈΡ‚ΡŒ ваши NEAR Ρ‚ΠΎΠΊΠ΅Π½Ρ‹ Π² ΠΎΠ±Ρ‰ΠΈΠΉ Ρ„ΠΎΠ½Π΄ ΠΎΠ΄Π½ΠΎΠ³ΠΎ ΠΈΠ· Π²Π°Π»ΠΈΠ΄Π°Ρ‚ΠΎΡ€ΠΎΠ² ΠΈ получСния Π½Π°Π³Ρ€Π°Π΄, ΠΏΠ΅Ρ€Π΅Π΄Π°ΠΉΡ‚Π΅ ваши NEAR Ρ‚ΠΎΠΊΠ΅Π½Ρ‹ ΠΈ ΠΏΠ΅Ρ€Π΅Π²Π΅Π΄ΠΈΡ‚Π΅ ΠΈΡ… Π² ставку Π²Π°Π»ΠΈΠ΄Π°Ρ‚ΠΎΡ€Π°, ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΡ ΡΠ»Π΅Π΄ΡƒΡŽΡ‰ΡƒΡŽ ΠΊΠΎΠΌΠ°Π½Π΄Π½Ρƒ Π² Ρ‚Π΅Ρ€ΠΌΠΈΠ½Π°Π»Π΅ (ΠΎΠ±Ρ€Π°Ρ‚ΠΈΡ‚Π΅ Π²Π½ΠΈΠΌΠ°Π½ΠΈΠ΅, Ρ‡Ρ‚ΠΎ Π²Π°ΠΌ Π½Π΅ΠΎΠ±Ρ…ΠΎΠ΄ΠΈΠΌΠΎ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚ΡŒ свой собствСнный ΠΈΠ΄Π΅Π½Ρ‚ΠΈΡ„ΠΈΠΊΠ°Ρ‚ΠΎΡ€ Π°ΠΊΠΊΠ°ΡƒΠ½Ρ‚Π°, ΡƒΠΊΠ°Π·Π°Ρ‚ΡŒ ΠΆΠ΅Π»Π°Π΅ΠΌΠΎΠ΅ количСство NEAR Ρ‚ΠΎΠΊΠ΅Π½ΠΎΠ², Π° Ρ‚Π°ΠΊΠΆΠ΅ Π²Ρ‹Π±Ρ€Π°Ρ‚ΡŒ ΠΈΠ΄Π΅Π½Ρ‚ΠΈΡ„ΠΈΠΊΠ°Ρ‚ΠΎΡ€ Π°ΠΊΠΊΠ°ΡƒΠ½Ρ‚Π° Π²Π°Π»ΠΈΠ΄Π°Ρ‚ΠΎΡ€Π°): -```txt - has successfully deposited 10 NEAR on . -``` -
- -
ДСмонстрация Ρ€Π°Π±ΠΎΡ‚Ρ‹ ΠΊΠΎΠΌΠ°Π½Π΄Ρ‹ Π² ΠΈΠ½Ρ‚Π΅Ρ€Π°ΠΊΡ‚ΠΈΠ²Π½ΠΎΠΌ Ρ€Π΅ΠΆΠΈΠΌΠ΅ - - - -
- -##### deposit-and-stake - Deposits the attached amount into the inner account of the predecessor and stakes it - -Π§Ρ‚ΠΎΠ±Ρ‹ Ρ€Π°Π·ΠΌΠ΅ΡΡ‚ΠΈΡ‚ΡŒ Π΄Π΅ΠΏΠΎΠ·ΠΈΡ‚ ΠΈ ΡΠ΄Π΅Π»Π°Ρ‚ΡŒ ставку Π’Π°ΡˆΠ΅Π³ΠΎ Π°ΠΊΠΊΠ°ΡƒΠ½Ρ‚Π° Ρƒ Π΄Π΅Π»Π΅Π³ΠΈΡ€ΠΎΠ°Π½Π½ΠΎΠ³ΠΎ Π²Π°Π»ΠΈΠ΄Π°Ρ‚ΠΎΡ€Π°, Π½Π΅ΠΎΠ±Ρ…ΠΎΠ΄ΠΈΠΌΠΎ ввСсти Π² ΠΊΠΎΠΌΠ°Π½Π΄Π½ΠΎΠΉ строкС Ρ‚Π΅Ρ€ΠΌΠΈΠ½Π°Π»Π°: ```txt near staking \ delegation volodymyr.testnet \ @@ -1467,9 +1443,10 @@ near staking \ -##### stake - Staking the given amount from the inner account of the predecessor +##### stake - Delegate a certain amount of previously deposited or unstaked NEAR tokens to a validator's staking pool + +Π§Ρ‚ΠΎΠ±Ρ‹ ΠΏΠΎΡ€ΡƒΡ‡ΠΈΡ‚ΡŒ ваши NEAR Ρ‚ΠΎΠΊΠ΅Π½Ρ‹ Π² ΠΎΠ±Ρ‰ΠΈΠΉ Ρ„ΠΎΠ½Π΄ ΠΎΠ΄Π½ΠΎΠ³ΠΎ ΠΈΠ· Π²Π°Π»ΠΈΠ΄Π°Ρ‚ΠΎΡ€ΠΎΠ² ΠΈ получСния Π½Π°Π³Ρ€Π°Π΄, ΠΏΠ΅Ρ€Π΅Π²Π΅Π΄ΠΈΡ‚Π΅ Ρ€Π°Π½Π½Π΅Π΅ ΠΏΠ΅Ρ€Π΅Π΄Π°Π½Π½Ρ‹Π΅ NEAR Ρ‚ΠΎΠΊΠ΅Π½Ρ‹ Π² ставку Π²Π°Π»ΠΈΠ΄Π°Ρ‚ΠΎΡ€Π°, ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΡ ΡΠ»Π΅Π΄ΡƒΡŽΡ‰ΡƒΡŽ ΠΊΠΎΠΌΠ°Π½Π΄Π½Ρƒ Π² Ρ‚Π΅Ρ€ΠΌΠΈΠ½Π°Π»Π΅ (ΠΎΠ±Ρ€Π°Ρ‚ΠΈΡ‚Π΅ Π²Π½ΠΈΠΌΠ°Π½ΠΈΠ΅, Ρ‡Ρ‚ΠΎ Π²Π°ΠΌ Π½Π΅ΠΎΠ±Ρ…ΠΎΠ΄ΠΈΠΌΠΎ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚ΡŒ свой собствСнный ΠΈΠ΄Π΅Π½Ρ‚ΠΈΡ„ΠΈΠΊΠ°Ρ‚ΠΎΡ€ Π°ΠΊΠΊΠ°ΡƒΠ½Ρ‚Π°, ΡƒΠΊΠ°Π·Π°Ρ‚ΡŒ ΠΆΠ΅Π»Π°Π΅ΠΌΠΎΠ΅ количСство NEAR Ρ‚ΠΎΠΊΠ΅Π½ΠΎΠ², Π° Ρ‚Π°ΠΊΠΆΠ΅ Π²Ρ‹Π±Ρ€Π°Ρ‚ΡŒ ΠΈΠ΄Π΅Π½Ρ‚ΠΈΡ„ΠΈΠΊΠ°Ρ‚ΠΎΡ€ Π°ΠΊΠΊΠ°ΡƒΠ½Ρ‚Π° Π²Π°Π»ΠΈΠ΄Π°Ρ‚ΠΎΡ€Π°): -Π§Ρ‚ΠΎΠ±Ρ‹ ΡΠ΄Π΅Π»Π°Ρ‚ΡŒ ставку ΠΎΠΏΡ€Π΅Π΄Π΅Π»Π΅Π½Π½ΠΎΠΉ суммы ΠΎΡ‚ внСсСнного Ρ€Π°Π½Π΅Π΅ Π΄Π΅ΠΏΠΎΠ·ΠΈΡ‚Π° Ρƒ Π΄Π΅Π»Π΅Π³ΠΈΡ€ΠΎΠ°Π½Π½ΠΎΠ³ΠΎ Π²Π°Π»ΠΈΠ΄Π°Ρ‚ΠΎΡ€Π°, Π½Π΅ΠΎΠ±Ρ…ΠΎΠ΄ΠΈΠΌΠΎ ввСсти Π² ΠΊΠΎΠΌΠ°Π½Π΄Π½ΠΎΠΉ строкС Ρ‚Π΅Ρ€ΠΌΠΈΠ½Π°Π»Π°: ```txt near staking \ delegation volodymyr.testnet \ @@ -1492,9 +1469,9 @@ near staking \ -##### stake-all - Staking all available unstaked balance from the inner account of the predecessor +##### stake-all - Delegate all previously deposited or unstaked NEAR tokens to a validator's staking pool -Π§Ρ‚ΠΎΠ±Ρ‹ ΡΠ΄Π΅Π»Π°Ρ‚ΡŒ ставку всСго Π΄Π΅ΠΏΠΎΠ·ΠΈΡ‚Π° Ρƒ Π΄Π΅Π»Π΅Π³ΠΈΡ€ΠΎΠ°Π½Π½ΠΎΠ³ΠΎ Π²Π°Π»ΠΈΠ΄Π°Ρ‚ΠΎΡ€Π°, Π½Π΅ΠΎΠ±Ρ…ΠΎΠ΄ΠΈΠΌΠΎ ввСсти Π² ΠΊΠΎΠΌΠ°Π½Π΄Π½ΠΎΠΉ строкС Ρ‚Π΅Ρ€ΠΌΠΈΠ½Π°Π»Π°: +Π§Ρ‚ΠΎΠ±Ρ‹ ΠΏΠΎΡ€ΡƒΡ‡ΠΈΡ‚ΡŒ ваши NEAR Ρ‚ΠΎΠΊΠ΅Π½Ρ‹ Π² ΠΎΠ±Ρ‰ΠΈΠΉ Ρ„ΠΎΠ½Π΄ ΠΎΠ΄Π½ΠΎΠ³ΠΎ ΠΈΠ· Π²Π°Π»ΠΈΠ΄Π°Ρ‚ΠΎΡ€ΠΎΠ² ΠΈ получСния Π½Π°Π³Ρ€Π°Π΄, ΠΏΠ΅Ρ€Π΅Π²Π΅Π΄ΠΈΡ‚Π΅ всС Ρ€Π°Π½Π½Π΅Π΅ ΠΏΠ΅Ρ€Π΅Π΄Π°Π½Π½Ρ‹Π΅ NEAR Ρ‚ΠΎΠΊΠ΅Π½Ρ‹ Π² ставку Π²Π°Π»ΠΈΠ΄Π°Ρ‚ΠΎΡ€Π°, ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΡ ΡΠ»Π΅Π΄ΡƒΡŽΡ‰ΡƒΡŽ ΠΊΠΎΠΌΠ°Π½Π΄Π½Ρƒ Π² Ρ‚Π΅Ρ€ΠΌΠΈΠ½Π°Π»Π΅ (ΠΎΠ±Ρ€Π°Ρ‚ΠΈΡ‚Π΅ Π²Π½ΠΈΠΌΠ°Π½ΠΈΠ΅, Ρ‡Ρ‚ΠΎ Π²Π°ΠΌ Π½Π΅ΠΎΠ±Ρ…ΠΎΠ΄ΠΈΠΌΠΎ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚ΡŒ свой собствСнный ΠΈΠ΄Π΅Π½Ρ‚ΠΈΡ„ΠΈΠΊΠ°Ρ‚ΠΎΡ€ Π°ΠΊΠΊΠ°ΡƒΠ½Ρ‚Π°, Π° Ρ‚Π°ΠΊΠΆΠ΅ Π²Ρ‹Π±Ρ€Π°Ρ‚ΡŒ ΠΈΠ΄Π΅Π½Ρ‚ΠΈΡ„ΠΈΠΊΠ°Ρ‚ΠΎΡ€ Π°ΠΊΠΊΠ°ΡƒΠ½Ρ‚Π° Π²Π°Π»ΠΈΠ΄Π°Ρ‚ΠΎΡ€Π°): ```txt near staking \ delegation volodymyr.testnet \ @@ -1517,9 +1494,10 @@ near staking \ -##### unstake - Unstaking the given amount from the inner account of the predecessor +##### unstake - Unstake a certain amount of delegated NEAR tokens from a avalidator's staking pool + +Π§Ρ‚ΠΎΠ±Ρ‹ ΠΎΡ‚ΠΌΠ΅Π½ΠΈΡ‚ΡŒ ΠΎΠΏΡ€Π΅Π΄Π΅Π»Ρ‘Π½Π½ΡƒΡŽ Ρ‡Π°ΡΡ‚ΡŒ ставки, ΡΠΎΠ²Π΅Ρ€ΡˆΡ‘Π½Π½ΡƒΡŽ Ρ‡Π΅Ρ€Π΅Π· ΠΎΠ±Ρ‰ΠΈΠΉ Ρ„ΠΎΠ½Π΄ Π²Π°Π»ΠΈΠ΄Π°Ρ‚ΠΎΡ€Π°, ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠΉΡ‚Π΅ ΡΠ»Π΅Π΄ΡƒΡŽΡ‰ΡƒΡŽ ΠΊΠΎΠΌΠ°Π½Π΄Π½Ρƒ Π² Ρ‚Π΅Ρ€ΠΌΠΈΠ½Π°Π»Π΅ (ΠΎΠ±Ρ€Π°Ρ‚ΠΈΡ‚Π΅ Π²Π½ΠΈΠΌΠ°Π½ΠΈΠ΅, Ρ‡Ρ‚ΠΎ Π²Π°ΠΌ Π½Π΅ΠΎΠ±Ρ…ΠΎΠ΄ΠΈΠΌΠΎ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚ΡŒ свой собствСнный ΠΈΠ΄Π΅Π½Ρ‚ΠΈΡ„ΠΈΠΊΠ°Ρ‚ΠΎΡ€ Π°ΠΊΠΊΠ°ΡƒΠ½Ρ‚Π°, ΡƒΠΊΠ°Π·Π°Ρ‚ΡŒ ΠΆΠ΅Π»Π°Π΅ΠΌΠΎΠ΅ количСство NEAR Ρ‚ΠΎΠΊΠ΅Π½ΠΎΠ², Π° Ρ‚Π°ΠΊΠΆΠ΅ Π²Ρ‹Π±Ρ€Π°Ρ‚ΡŒ ΠΈΠ΄Π΅Π½Ρ‚ΠΈΡ„ΠΈΠΊΠ°Ρ‚ΠΎΡ€ Π°ΠΊΠΊΠ°ΡƒΠ½Ρ‚Π° Π²Π°Π»ΠΈΠ΄Π°Ρ‚ΠΎΡ€Π°): -Π§Ρ‚ΠΎΠ±Ρ‹ ΡΠ½ΡΡ‚ΡŒ ставку ΠΎΠΏΡ€Π΅Π΄Π΅Π»Π΅Π½Π½ΠΎΠΉ суммы Ρƒ Π΄Π΅Π»Π΅Π³ΠΈΡ€ΠΎΠ°Π½Π½ΠΎΠ³ΠΎ Π²Π°Π»ΠΈΠ΄Π°Ρ‚ΠΎΡ€Π°, Π½Π΅ΠΎΠ±Ρ…ΠΎΠ΄ΠΈΠΌΠΎ ввСсти Π² ΠΊΠΎΠΌΠ°Π½Π΄Π½ΠΎΠΉ строкС Ρ‚Π΅Ρ€ΠΌΠΈΠ½Π°Π»Π°: ```txt near staking \ delegation volodymyr.testnet \ @@ -1542,9 +1520,10 @@ near staking \ -##### unstake-all - Unstaking all staked balance from the inner account of the predecessor +##### unstake-all - Unstake all delegated NEAR tokens from a avalidator's staking pool + +Π§Ρ‚ΠΎΠ±Ρ‹ ΠΎΡ‚ΠΌΠ΅Π½ΠΈΡ‚ΡŒ всю ставку, ΡΠΎΠ²Π΅Ρ€ΡˆΡ‘Π½Π½ΡƒΡŽ Ρ‡Π΅Ρ€Π΅Π· ΠΎΠ±Ρ‰ΠΈΠΉ Ρ„ΠΎΠ½Π΄ Π²Π°Π»ΠΈΠ΄Π°Ρ‚ΠΎΡ€Π°, ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠΉΡ‚Π΅ ΡΠ»Π΅Π΄ΡƒΡŽΡ‰ΡƒΡŽ ΠΊΠΎΠΌΠ°Π½Π΄Π½Ρƒ Π² Ρ‚Π΅Ρ€ΠΌΠΈΠ½Π°Π»Π΅ (ΠΎΠ±Ρ€Π°Ρ‚ΠΈΡ‚Π΅ Π²Π½ΠΈΠΌΠ°Π½ΠΈΠ΅, Ρ‡Ρ‚ΠΎ Π²Π°ΠΌ Π½Π΅ΠΎΠ±Ρ…ΠΎΠ΄ΠΈΠΌΠΎ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚ΡŒ свой собствСнный ΠΈΠ΄Π΅Π½Ρ‚ΠΈΡ„ΠΈΠΊΠ°Ρ‚ΠΎΡ€ Π°ΠΊΠΊΠ°ΡƒΠ½Ρ‚Π°, Π° Ρ‚Π°ΠΊΠΆΠ΅ Π²Ρ‹Π±Ρ€Π°Ρ‚ΡŒ ΠΈΠ΄Π΅Π½Ρ‚ΠΈΡ„ΠΈΠΊΠ°Ρ‚ΠΎΡ€ Π°ΠΊΠΊΠ°ΡƒΠ½Ρ‚Π° Π²Π°Π»ΠΈΠ΄Π°Ρ‚ΠΎΡ€Π°): -Π§Ρ‚ΠΎΠ±Ρ‹ ΡΠ½ΡΡ‚ΡŒ всю ставку Ρƒ Π΄Π΅Π»Π΅Π³ΠΈΡ€ΠΎΠ°Π½Π½ΠΎΠ³ΠΎ Π²Π°Π»ΠΈΠ΄Π°Ρ‚ΠΎΡ€Π°, Π½Π΅ΠΎΠ±Ρ…ΠΎΠ΄ΠΈΠΌΠΎ ввСсти Π² ΠΊΠΎΠΌΠ°Π½Π΄Π½ΠΎΠΉ строкС Ρ‚Π΅Ρ€ΠΌΠΈΠ½Π°Π»Π°: ```txt near staking \ delegation volodymyr.testnet \ @@ -1567,9 +1546,10 @@ near staking \ -##### withdraw - Withdrawing the non staked balance for given account +##### withdraw - Withdraw a certain amount of unstaked NEAR tokens from a avalidator's staking pool + +Π§Ρ‚ΠΎΠ±Ρ‹ ΠΏΠΎΠ»ΡƒΡ‡ΠΈΡ‚ΡŒ ваши Ρ€Π°Π½Π½Π΅Π΅ ΠΏΠΎΡ€ΡƒΡ‡Π΅Π½Π½Ρ‹Π΅ NEAR Ρ‚ΠΎΠΊΠ΅Π½Ρ‹ ΠΈ Π½Π°Π³Ρ€Π°Π΄Ρ‹ ΠΈΠ· ΠΎΠ±Ρ‰Π΅Π³ΠΎ Ρ„ΠΎΠ½Π΄Π° Π²Π°Π»ΠΈΠ΄Π°Ρ‚ΠΎΡ€Π° послС Ρ‚ΠΎΠ³ΠΎ ΠΊΠ°ΠΊ ставка Π±Ρ‹Π»Π° снята ΠΈ ΠΏΡ€ΠΎΡˆΠ»ΠΎ 4 эпохи, ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠΉΡ‚Π΅ ΡΠ»Π΅Π΄ΡƒΡŽΡ‰ΡƒΡŽ ΠΊΠΎΠΌΠ°Π½Π΄Π½Ρƒ Π² Ρ‚Π΅Ρ€ΠΌΠΈΠ½Π°Π»Π΅ (ΠΎΠ±Ρ€Π°Ρ‚ΠΈΡ‚Π΅ Π²Π½ΠΈΠΌΠ°Π½ΠΈΠ΅, Ρ‡Ρ‚ΠΎ Π²Π°ΠΌ Π½Π΅ΠΎΠ±Ρ…ΠΎΠ΄ΠΈΠΌΠΎ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚ΡŒ свой собствСнный ΠΈΠ΄Π΅Π½Ρ‚ΠΈΡ„ΠΈΠΊΠ°Ρ‚ΠΎΡ€ Π°ΠΊΠΊΠ°ΡƒΠ½Ρ‚Π°, ΡƒΠΊΠ°Π·Π°Ρ‚ΡŒ ΠΆΠ΅Π»Π°Π΅ΠΌΠΎΠ΅ количСство NEAR Ρ‚ΠΎΠΊΠ΅Π½ΠΎΠ², Π° Ρ‚Π°ΠΊΠΆΠ΅ Π²Ρ‹Π±Ρ€Π°Ρ‚ΡŒ ΠΈΠ΄Π΅Π½Ρ‚ΠΈΡ„ΠΈΠΊΠ°Ρ‚ΠΎΡ€ Π°ΠΊΠΊΠ°ΡƒΠ½Ρ‚Π° Π²Π°Π»ΠΈΠ΄Π°Ρ‚ΠΎΡ€Π°): -Π§Ρ‚ΠΎΠ±Ρ‹ вывСсти ΠΎΠΏΡ€Π΅Π΄Π΅Π»Π΅Π½Π½ΡƒΡŽ сумму ΠΈΠ· Π΄Π΅Π»Π΅Π³ΠΈΡ€ΠΎΠ°Π½Π½ΠΎΠ³ΠΎ Π²Π°Π»ΠΈΠ΄Π°Ρ‚ΠΎΡ€Π° Π½Π° свой Π°ΠΊΠΊΠ°ΡƒΠ½Ρ‚, Π½Π΅ΠΎΠ±Ρ…ΠΎΠ΄ΠΈΠΌΠΎ ввСсти Π² ΠΊΠΎΠΌΠ°Π½Π΄Π½ΠΎΠΉ строкС Ρ‚Π΅Ρ€ΠΌΠΈΠ½Π°Π»Π°: ```txt near staking \ delegation volodymyr.testnet \ @@ -1582,7 +1562,7 @@ near staking \
Π Π΅Π·ΡƒΠ»ΡŒΡ‚Π°Ρ‚ выполнСния ΠΊΠΎΠΌΠ°Π½Π΄Ρ‹ ```txt -Error: +Error: 0: can't withdraw tokens in the current epoch. ```
@@ -1593,9 +1573,10 @@ Error: -##### withdraw-all - Withdrawing the entire unstaked balance from the predecessor account +##### withdraw-all - Withdraw all unstaked NEAR tokens from a avalidator's staking pool + +Π§Ρ‚ΠΎΠ±Ρ‹ ΠΏΠΎΠ»ΡƒΡ‡ΠΈΡ‚ΡŒ всС ваши Ρ€Π°Π½Π½Π΅Π΅ ΠΏΠΎΡ€ΡƒΡ‡Π΅Π½Π½Ρ‹Π΅ NEAR Ρ‚ΠΎΠΊΠ΅Π½Ρ‹ ΠΈ Π½Π°Π³Ρ€Π°Π΄Ρ‹ ΠΈΠ· ΠΎΠ±Ρ‰Π΅Π³ΠΎ Ρ„ΠΎΠ½Π΄Π° Π²Π°Π»ΠΈΠ΄Π°Ρ‚ΠΎΡ€Π° послС Ρ‚ΠΎΠ³ΠΎ ΠΊΠ°ΠΊ ставка Π±Ρ‹Π»Π° снята ΠΈ ΠΏΡ€ΠΎΡˆΠ»ΠΎ 4 эпохи, ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠΉΡ‚Π΅ ΡΠ»Π΅Π΄ΡƒΡŽΡ‰ΡƒΡŽ ΠΊΠΎΠΌΠ°Π½Π΄Π½Ρƒ Π² Ρ‚Π΅Ρ€ΠΌΠΈΠ½Π°Π»Π΅ (ΠΎΠ±Ρ€Π°Ρ‚ΠΈΡ‚Π΅ Π²Π½ΠΈΠΌΠ°Π½ΠΈΠ΅, Ρ‡Ρ‚ΠΎ Π²Π°ΠΌ Π½Π΅ΠΎΠ±Ρ…ΠΎΠ΄ΠΈΠΌΠΎ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚ΡŒ свой собствСнный ΠΈΠ΄Π΅Π½Ρ‚ΠΈΡ„ΠΈΠΊΠ°Ρ‚ΠΎΡ€ Π°ΠΊΠΊΠ°ΡƒΠ½Ρ‚Π°, Π° Ρ‚Π°ΠΊΠΆΠ΅ Π²Ρ‹Π±Ρ€Π°Ρ‚ΡŒ ΠΈΠ΄Π΅Π½Ρ‚ΠΈΡ„ΠΈΠΊΠ°Ρ‚ΠΎΡ€ Π°ΠΊΠΊΠ°ΡƒΠ½Ρ‚Π° Π²Π°Π»ΠΈΠ΄Π°Ρ‚ΠΎΡ€Π°): -Π§Ρ‚ΠΎΠ±Ρ‹ вывСсти всю сумму ΠΈΠ· Π΄Π΅Π»Π΅Π³ΠΈΡ€ΠΎΠ°Π½Π½ΠΎΠ³ΠΎ Π²Π°Π»ΠΈΠ΄Π°Ρ‚ΠΎΡ€Π° Π½Π° свой Π°ΠΊΠΊΠ°ΡƒΠ½Ρ‚, Π½Π΅ΠΎΠ±Ρ…ΠΎΠ΄ΠΈΠΌΠΎ ввСсти Π² ΠΊΠΎΠΌΠ°Π½Π΄Π½ΠΎΠΉ строкС Ρ‚Π΅Ρ€ΠΌΠΈΠ½Π°Π»Π°: ```txt near staking \ delegation volodymyr.testnet \ @@ -1608,7 +1589,7 @@ near staking \
Π Π΅Π·ΡƒΠ»ΡŒΡ‚Π°Ρ‚ выполнСния ΠΊΠΎΠΌΠ°Π½Π΄Ρ‹ ```txt -Error: +Error: 0: can't withdraw tokens in the current epoch. ```
@@ -1633,7 +1614,7 @@ Error: ##### as-read-only - Calling a view method -ΠŸΡ€ΠΎΡΠΌΠΎΡ‚Ρ€ Π΄Π°Π½Π½Ρ‹Ρ… Π²ΠΎΠ·ΠΌΠΎΠΆΠ΅Π½ Π½Π° Ρ‚Π΅ΠΊΡƒΡ‰ΠΈΠΉ ΠΌΠΎΠΌΠ΅Π½Ρ‚ Π²Ρ€Π΅ΠΌΠ΅Π½ΠΈ (***now***) ΠΈ Π½Π° ΠΎΠΏΡ€Π΅Π΄Π΅Π»Π΅Π½Ρ‹ΠΉ ΠΌΠΎΠΌΠ΅Π½Ρ‚ Π² ΠΏΡ€ΠΎΡˆΠ»ΠΎΠΌ, ΡƒΠΊΠ°Π·Π°Π² Π±Π»ΠΎΠΊ (***at-block-height*** ΠΈΠ»ΠΈ ***at-block-hash***). +ΠŸΡ€ΠΎΡΠΌΠΎΡ‚Ρ€ Π΄Π°Π½Π½Ρ‹Ρ… Π²ΠΎΠ·ΠΌΠΎΠΆΠ΅Π½ Π½Π° Ρ‚Π΅ΠΊΡƒΡ‰ΠΈΠΉ ΠΌΠΎΠΌΠ΅Π½Ρ‚ Π²Ρ€Π΅ΠΌΠ΅Π½ΠΈ (***now***) ΠΈ Π½Π° ΠΎΠΏΡ€Π΅Π΄Π΅Π»Π΅Π½Ρ‹ΠΉ ΠΌΠΎΠΌΠ΅Π½Ρ‚ Π² ΠΏΡ€ΠΎΡˆΠ»ΠΎΠΌ, ΡƒΠΊΠ°Π·Π°Π² Π±Π»ΠΎΠΊ (***at-block-height*** ΠΈΠ»ΠΈ ***at-block-hash***). ΠŸΡ€ΠΈΠΌΠ΅Ρ€Ρ‹ использования этих ΠΏΠ°Ρ€Π°ΠΌΠ΅Ρ‚Ρ€ΠΎΠ² рассмотрСны Π² Ρ€Π°Π·Π΄Π΅Π»Π΅ [View properties for an account](#view-account-summary---view-properties-for-an-account). Для выполнСния этой ΠΊΠΎΠΌΠ°Π½Π΄Ρ‹ Π½Π΅ΠΎΠ±Ρ…ΠΎΠ΄ΠΈΠΌΠΎ ввСсти Π² ΠΊΠΎΠΌΠ°Π½Π΄Π½ΠΎΠΉ строкС Ρ‚Π΅Ρ€ΠΌΠΈΠ½Π°Π»Π°: @@ -1750,7 +1731,7 @@ https://explorer.testnet.near.org/transactions/4YGGhF88aevNGpF5uaXNGHfQprHRqkia7 #### download-wasm - Download wasm -Π‘ΠΊΠ°Ρ‡Π°Ρ‚ΡŒ Ρ„Π°ΠΉΠ» ΠΊΠΎΠ½Ρ‚Ρ€Π°ΠΊΡ‚Π° Π²ΠΎΠ·ΠΌΠΎΠΆΠ½ΠΎ Π½Π° Ρ‚Π΅ΠΊΡƒΡ‰ΠΈΠΉ ΠΌΠΎΠΌΠ΅Π½Ρ‚ Π²Ρ€Π΅ΠΌΠ΅Π½ΠΈ (***now***) ΠΈ Π½Π° ΠΎΠΏΡ€Π΅Π΄Π΅Π»Π΅Π½Ρ‹ΠΉ ΠΌΠΎΠΌΠ΅Π½Ρ‚ Π² ΠΏΡ€ΠΎΡˆΠ»ΠΎΠΌ, ΡƒΠΊΠ°Π·Π°Π² Π±Π»ΠΎΠΊ (***at-block-height*** ΠΈΠ»ΠΈ ***at-block-hash***). +Π‘ΠΊΠ°Ρ‡Π°Ρ‚ΡŒ Ρ„Π°ΠΉΠ» ΠΊΠΎΠ½Ρ‚Ρ€Π°ΠΊΡ‚Π° Π²ΠΎΠ·ΠΌΠΎΠΆΠ½ΠΎ Π½Π° Ρ‚Π΅ΠΊΡƒΡ‰ΠΈΠΉ ΠΌΠΎΠΌΠ΅Π½Ρ‚ Π²Ρ€Π΅ΠΌΠ΅Π½ΠΈ (***now***) ΠΈ Π½Π° ΠΎΠΏΡ€Π΅Π΄Π΅Π»Π΅Π½Ρ‹ΠΉ ΠΌΠΎΠΌΠ΅Π½Ρ‚ Π² ΠΏΡ€ΠΎΡˆΠ»ΠΎΠΌ, ΡƒΠΊΠ°Π·Π°Π² Π±Π»ΠΎΠΊ (***at-block-height*** ΠΈΠ»ΠΈ ***at-block-hash***). ΠŸΡ€ΠΈΠΌΠ΅Ρ€Ρ‹ использования этих ΠΏΠ°Ρ€Π°ΠΌΠ΅Ρ‚Ρ€ΠΎΠ² рассмотрСны Π² Ρ€Π°Π·Π΄Π΅Π»Π΅ [View properties for an account](#view-account-summary---view-properties-for-an-account). Для получСния Ρ„Π°ΠΉΠ»Π° ΠΊΠΎΠ½Ρ‚Ρ€Π°ΠΊΡ‚Π° Π½Π΅ΠΎΠ±Ρ…ΠΎΠ΄ΠΈΠΌΠΎ ввСсти Π² ΠΊΠΎΠΌΠ°Π½Π΄Π½ΠΎΠΉ строкС Ρ‚Π΅Ρ€ΠΌΠΈΠ½Π°Π»Π°: @@ -1777,8 +1758,8 @@ The file "/Users/frovolod/Downloads/contract_262_volodymyr_testnet.wasm" was dow #### view-storage - View contract storage state -ΠŸΡ€ΠΎΡΠΌΠΎΡ‚Ρ€Π΅Ρ‚ΡŒ значСния ΠΊΠ»ΡŽΡ‡Π΅ΠΉ ΠΊΠΎΠ½Ρ‚Ρ€Π°ΠΊΡ‚Π° Π²ΠΎΠ·ΠΌΠΎΠΆΠ½ΠΎ Π½Π° Ρ‚Π΅ΠΊΡƒΡ‰ΠΈΠΉ ΠΌΠΎΠΌΠ΅Π½Ρ‚ Π²Ρ€Π΅ΠΌΠ΅Π½ΠΈ (***now***) ΠΈ Π½Π° ΠΎΠΏΡ€Π΅Π΄Π΅Π»Π΅Π½Ρ‹ΠΉ ΠΌΠΎΠΌΠ΅Π½Ρ‚ Π² ΠΏΡ€ΠΎΡˆΠ»ΠΎΠΌ, ΡƒΠΊΠ°Π·Π°Π² Π±Π»ΠΎΠΊ (***at-block-height*** ΠΈΠ»ΠΈ ***at-block-hash***). -ΠŸΡ€ΠΈΠΌΠ΅Ρ€Ρ‹ использования этих ΠΏΠ°Ρ€Π°ΠΌΠ΅Ρ‚Ρ€ΠΎΠ² рассмотрСны Π² Ρ€Π°Π·Π΄Π΅Π»Π΅ [View properties for an account](#view-account-summary---view-properties-for-an-account). +ΠŸΡ€ΠΎΡΠΌΠΎΡ‚Ρ€Π΅Ρ‚ΡŒ значСния ΠΊΠ»ΡŽΡ‡Π΅ΠΉ ΠΊΠΎΠ½Ρ‚Ρ€Π°ΠΊΡ‚Π° Π²ΠΎΠ·ΠΌΠΎΠΆΠ½ΠΎ Π½Π° Ρ‚Π΅ΠΊΡƒΡ‰ΠΈΠΉ ΠΌΠΎΠΌΠ΅Π½Ρ‚ Π²Ρ€Π΅ΠΌΠ΅Π½ΠΈ (***now***) ΠΈ Π½Π° ΠΎΠΏΡ€Π΅Π΄Π΅Π»Π΅Π½Ρ‹ΠΉ ΠΌΠΎΠΌΠ΅Π½Ρ‚ Π² ΠΏΡ€ΠΎΡˆΠ»ΠΎΠΌ, ΡƒΠΊΠ°Π·Π°Π² Π±Π»ΠΎΠΊ (***at-block-height*** ΠΈΠ»ΠΈ ***at-block-hash***). +ΠŸΡ€ΠΈΠΌΠ΅Ρ€Ρ‹ использования этих ΠΏΠ°Ρ€Π°ΠΌΠ΅Ρ‚Ρ€ΠΎΠ² рассмотрСны Π² Ρ€Π°Π·Π΄Π΅Π»Π΅ [View properties for an account](#view-account-summary---view-properties-for-an-account). Π‘Π°ΠΌΠΈ ΠΆΠ΅ ΠΊΠ»ΡŽΡ‡ΠΈ ΠΌΠΎΠΆΠ½ΠΎ ΠΏΡ€ΠΎΡΠΌΠΎΡ‚Ρ€Π΅Ρ‚ΡŒ всС (***all***) ΠΈΠ»ΠΈ ΠΎΡ‚Ρ„ΠΈΠ»ΡŒΡ‚Ρ€ΠΎΠ²Π°Π½Π½Ρ‹Π΅ с ΠΏΠΎΠΌΠΎΡ‰ΡŒΡŽ ***keys-start-with-string*** ΠΈΠ»ΠΈ ***keys-start-with-bytes-as-base64***. Для просмотра ΠΊΠ»ΡŽΡ‡Π΅ΠΉ ΠΊΠΎΠ½Ρ‚Ρ€Π°ΠΊΡ‚Π° Π½Π΅ΠΎΠ±Ρ…ΠΎΠ΄ΠΈΠΌΠΎ ввСсти Π² ΠΊΠΎΠΌΠ°Π½Π΄Π½ΠΎΠΉ строкС Ρ‚Π΅Ρ€ΠΌΠΈΠ½Π°Π»Π°: @@ -2004,7 +1985,7 @@ Transaction status: FinalExecutionOutcomeWithReceiptView { #### construct-transaction - Construct a new transaction - + Рассмотрим ΠΏΡ€ΠΈΠΌΠ΅Ρ€, ΠΊΠΎΠ³Π΄Π° Π½Π΅ΠΎΠ±Ρ…ΠΎΠ΄ΠΈΠΌΠΎ Π²Ρ‹ΠΏΠΎΠ»Π½ΠΈΡ‚ΡŒ нСсколько дСйствий Π² Ρ€Π°ΠΌΠΊΠ°Ρ… ΠΎΠ΄Π½ΠΎΠΉ Ρ‚Ρ€Π°Π½Π·Π°ΠΊΡ†ΠΈΠΈ: 1. Π‘ΠΎΠ·Π΄Π°Ρ‚ΡŒ Π°ΠΊΠΊΠ°ΡƒΠ½Ρ‚ 2. Π”ΠΎΠ±Π°Π²ΠΈΡ‚ΡŒ созданному Π°ΠΊΠΊΠ°ΡƒΠ½Ρ‚Ρƒ ΠΊΠ»ΡŽΡ‡ΠΈ доступа @@ -2019,7 +2000,7 @@ Transaction status: FinalExecutionOutcomeWithReceiptView { #### sign-transaction - Sign previously prepared unsigned transaction - + Рассмотрим ΠΏΡ€ΠΈΠΌΠ΅Ρ€, ΠΏΡ€ΠΈΠΌΠ΅Π½ΠΈΠ² Π²ΠΎΠ·ΠΌΠΎΠΆΠ½ΠΎΡΡ‚ΡŒ создания Ρ‚Ρ€Π°Π½Π·Π°ΠΊΡ†ΠΈΠΈ Π² Ρ€Π΅ΠΆΠΈΠΌΠ΅ _offline_: 1. Π‘ΠΎΠ·Π΄Π°Ρ‚ΡŒ Ρ‚Ρ€Π°Π½Π·Π°ΠΊΡ†ΠΈΡŽ. 2. ΠŸΡ€ΠΈ Π²Ρ‹Π±ΠΎΡ€Π΅ срСдств подписи Ρ‚Ρ€Π°Π½Π·Π°ΠΊΡ†ΠΈΠΈ ΡƒΠΊΠ°Π·Π°Ρ‚ΡŒ ΠΏΡƒΠ½ΠΊΡ‚ _sign-later_ ΠΈ ΡΠ»Π΅Π΄ΠΎΠ²Π°Ρ‚ΡŒ дальнСйшим инструкциям. @@ -2032,7 +2013,7 @@ Transaction status: FinalExecutionOutcomeWithReceiptView { #### send-signed-transaction - Send a signed transaction - + Рассмотрим ΠΏΡ€Π΅Π΄Ρ‹Π΄ΡƒΡ‰ΠΈΠΉ ΠΏΡ€ΠΈΠΌΠ΅Ρ€, ΠΏΡ€ΠΈΠΌΠ΅Π½ΠΈΠ² возмоТности ΠΎΡ‚ΠΏΡ€Π°Π²ΠΊΠΈ подписанной Ρ‚Ρ€Π°Π½Π·Π°ΠΊΡ†ΠΈΠΈ Ρ‚Ρ€Π°Π½Π·Π°ΠΊΡ†ΠΈΠΈ: 1. Π‘ΠΎΠ·Π΄Π°Ρ‚ΡŒ Ρ‚Ρ€Π°Π½Π·Π°ΠΊΡ†ΠΈΡŽ. 2. ΠŸΠΎΠ΄ΠΏΠΈΡΠ°Ρ‚ΡŒ Ρ‚Ρ€Π°Π½Π·Π°ΠΊΡ†ΠΈΡŽ своими ΠΊΠ»ΡŽΡ‡Π°ΠΌΠΈ доступа. @@ -2046,7 +2027,7 @@ Transaction status: FinalExecutionOutcomeWithReceiptView { #### send-meta-transaction - Act as a relayer to send a signed delegate action (meta-transaction) - + Рассмотрим ΠΏΡ€ΠΈΠΌΠ΅Ρ€, ΠΏΡ€ΠΈΠΌΠ΅Π½ΠΈΠ² возмоТности ΠΌΠ΅Ρ‚Π°-Ρ‚Ρ€Π°Π½Π·Π°ΠΊΡ†ΠΈΠΈ: 1. Π‘ΠΎΠ·Π΄Π°Ρ‚ΡŒ Ρ‚Ρ€Π°Π½Π·Π°ΠΊΡ†ΠΈΡŽ. 2. Π£ΠΊΠ°Π·Π°Ρ‚ΡŒ _network_ с ΠΏΠΎΠ΄Π΄Π΅Ρ€ΠΆΠΊΠΎΠΉ ΠΌΠ΅Ρ‚Π°-Ρ‚Ρ€Π°Π½Π·Π°ΠΊΡ†ΠΈΠΈ. diff --git a/src/commands/staking/delegate/mod.rs b/src/commands/staking/delegate/mod.rs index 997a3d8ea..51e357c15 100644 --- a/src/commands/staking/delegate/mod.rs +++ b/src/commands/staking/delegate/mod.rs @@ -66,9 +66,9 @@ pub enum StakeDelegationCommand { /// Delegate NEAR tokens to a validator's staking pool DepositAndStake(self::deposit_and_stake::DepositAndStake), #[strum_discriminants(strum( - message = "stake - Staking the given amount from the inner account of the predecessor" + message = "stake - Delegate a certain amount of previously deposited or unstaked NEAR tokens to a validator's staking pool" ))] - /// Staking the given amount from the inner account of the predecessor + /// Delegate a certain amount of previously deposited or unstaked NEAR tokens to a validator's staking pool Stake(self::stake::Stake), #[strum_discriminants(strum( message = "stake-all - Delegate all previously deposited or unstaked NEAR tokens to a validator's staking pool" From 07960bb6db78d2d97bb07f3d209ff0d47a662793 Mon Sep 17 00:00:00 2001 From: Vlad Frolov Date: Tue, 31 Oct 2023 01:49:31 +0100 Subject: [PATCH 43/44] refactor: common.rs --- Cargo.lock | 68 +++--------- .../staking/delegate/deposit_and_stake.rs | 4 +- src/commands/staking/delegate/stake.rs | 4 +- src/commands/staking/delegate/stake_all.rs | 4 +- src/commands/staking/delegate/unstake.rs | 4 +- src/commands/staking/delegate/unstake_all.rs | 4 +- src/commands/staking/delegate/view_balance.rs | 4 +- src/commands/staking/delegate/withdraw.rs | 4 +- src/commands/staking/delegate/withdraw_all.rs | 4 +- src/common.rs | 101 ++++++++---------- 10 files changed, 68 insertions(+), 133 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f421c6500..0b53a39d6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -250,33 +250,13 @@ dependencies = [ "futures-lite", "log", "parking", - "polling 2.8.0", + "polling", "rustix 0.37.27", "slab", "socket2", "waker-fn", ] -[[package]] -name = "async-io" -version = "2.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10da8f3146014722c89e7859e1d7bb97873125d7346d10ca642ffab794355828" -dependencies = [ - "async-lock", - "cfg-if", - "concurrent-queue", - "futures-io", - "futures-lite", - "parking", - "polling 3.3.0", - "rustix 0.38.21", - "slab", - "tracing", - "waker-fn", - "windows-sys 0.48.0", -] - [[package]] name = "async-lock" version = "2.8.0" @@ -292,12 +272,12 @@ version = "1.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ea6438ba0a08d81529c69b36700fa2f95837bfe3e776ab39cde9c14d9149da88" dependencies = [ - "async-io 1.13.0", + "async-io", "async-lock", "async-signal", "blocking", "cfg-if", - "event-listener 3.0.1", + "event-listener 3.0.0", "futures-lite", "rustix 0.38.21", "windows-sys 0.48.0", @@ -316,11 +296,11 @@ dependencies = [ [[package]] name = "async-signal" -version = "0.2.5" +version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e47d90f65a225c4527103a8d747001fc56e375203592b25ad103e1ca13124c5" +checksum = "d2a5415b7abcdc9cd7d63d6badba5288b2ca017e3fbd4173b8f405449f1a2399" dependencies = [ - "async-io 2.1.0", + "async-io", "async-lock", "atomic-waker", "cfg-if", @@ -1270,9 +1250,9 @@ checksum = "0206175f82b8d6bf6652ff7d71a1e27fd2e4efde587fd368662814d6ec1d9ce0" [[package]] name = "event-listener" -version = "3.0.1" +version = "3.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01cec0252c2afff729ee6f00e903d479fba81784c8e2bd77447673471fdfaea1" +checksum = "29e56284f00d94c1bc7fd3c77027b4623c88c1f53d8d2394c6199f2921dea325" dependencies = [ "concurrent-queue", "parking", @@ -2923,25 +2903,11 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "polling" -version = "3.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e53b6af1f60f36f8c2ac2aad5459d75a5a9b4be1e8cdd40264f315d78193e531" -dependencies = [ - "cfg-if", - "concurrent-queue", - "pin-project-lite", - "rustix 0.38.21", - "tracing", - "windows-sys 0.48.0", -] - [[package]] name = "portable-atomic" -version = "1.5.1" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3bccab0e7fd7cc19f820a1c8c91720af652d0c88dc9664dd72aef2614f04af3b" +checksum = "b559898e0b4931ed2d3b959ab0c2da4d99cc644c4b0b1a35b4d344027f474023" [[package]] name = "powerfmt" @@ -3522,9 +3488,9 @@ dependencies = [ [[package]] name = "serde_repr" -version = "0.1.17" +version = "0.1.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3081f5ffbb02284dda55132aa26daecedd7372a42417bbbab6f14ab7d6bb9145" +checksum = "8725e1dfadb3a50f7e5ce0b1a540466f6ed3fe7a0fca2ac2b8b831d31316bd00" dependencies = [ "proc-macro2", "quote", @@ -4752,7 +4718,7 @@ dependencies = [ "async-broadcast", "async-executor", "async-fs", - "async-io 1.13.0", + "async-io", "async-lock", "async-process", "async-recursion", @@ -4811,18 +4777,18 @@ dependencies = [ [[package]] name = "zerocopy" -version = "0.7.20" +version = "0.7.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd66a62464e3ffd4e37bd09950c2b9dd6c4f8767380fabba0d523f9a775bc85a" +checksum = "c552e97c5a9b90bc8ddc545b5106e798807376356688ebaa3aee36f44f8c4b9e" dependencies = [ "zerocopy-derive", ] [[package]] name = "zerocopy-derive" -version = "0.7.20" +version = "0.7.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "255c4596d41e6916ced49cfafea18727b24d67878fa180ddfd69b9df34fd1726" +checksum = "964bc0588d7ac1c0243d0427ef08482618313702bbb014806cb7ab3da34d3d99" dependencies = [ "proc-macro2", "quote", diff --git a/src/commands/staking/delegate/deposit_and_stake.rs b/src/commands/staking/delegate/deposit_and_stake.rs index f9ca1d521..d9cfd241d 100644 --- a/src/commands/staking/delegate/deposit_and_stake.rs +++ b/src/commands/staking/delegate/deposit_and_stake.rs @@ -80,8 +80,6 @@ impl DepositAndStake { pub fn input_validator_account_id( context: &super::StakeDelegationContext, ) -> color_eyre::eyre::Result> { - crate::common::input_delegated_validator_account_id_from_used_delegated_validator_list( - &context.global_context.config, - ) + crate::common::input_staking_pool_validator_account_id(&context.global_context.config) } } diff --git a/src/commands/staking/delegate/stake.rs b/src/commands/staking/delegate/stake.rs index c909dd923..5681da2ca 100644 --- a/src/commands/staking/delegate/stake.rs +++ b/src/commands/staking/delegate/stake.rs @@ -82,8 +82,6 @@ impl Stake { pub fn input_validator_account_id( context: &super::StakeDelegationContext, ) -> color_eyre::eyre::Result> { - crate::common::input_delegated_validator_account_id_from_used_delegated_validator_list( - &context.global_context.config, - ) + crate::common::input_staking_pool_validator_account_id(&context.global_context.config) } } diff --git a/src/commands/staking/delegate/stake_all.rs b/src/commands/staking/delegate/stake_all.rs index 7fd2ce209..08d0d3373 100644 --- a/src/commands/staking/delegate/stake_all.rs +++ b/src/commands/staking/delegate/stake_all.rs @@ -76,8 +76,6 @@ impl StakeAll { pub fn input_validator_account_id( context: &super::StakeDelegationContext, ) -> color_eyre::eyre::Result> { - crate::common::input_delegated_validator_account_id_from_used_delegated_validator_list( - &context.global_context.config, - ) + crate::common::input_staking_pool_validator_account_id(&context.global_context.config) } } diff --git a/src/commands/staking/delegate/unstake.rs b/src/commands/staking/delegate/unstake.rs index e7851fc04..2468f6bdf 100644 --- a/src/commands/staking/delegate/unstake.rs +++ b/src/commands/staking/delegate/unstake.rs @@ -83,8 +83,6 @@ impl Unstake { pub fn input_validator_account_id( context: &super::StakeDelegationContext, ) -> color_eyre::eyre::Result> { - crate::common::input_delegated_validator_account_id_from_used_delegated_validator_list( - &context.global_context.config, - ) + crate::common::input_staking_pool_validator_account_id(&context.global_context.config) } } diff --git a/src/commands/staking/delegate/unstake_all.rs b/src/commands/staking/delegate/unstake_all.rs index 864c9d8a8..af57fa7f3 100644 --- a/src/commands/staking/delegate/unstake_all.rs +++ b/src/commands/staking/delegate/unstake_all.rs @@ -76,8 +76,6 @@ impl UnstakeAll { pub fn input_validator_account_id( context: &super::StakeDelegationContext, ) -> color_eyre::eyre::Result> { - crate::common::input_delegated_validator_account_id_from_used_delegated_validator_list( - &context.global_context.config, - ) + crate::common::input_staking_pool_validator_account_id(&context.global_context.config) } } diff --git a/src/commands/staking/delegate/view_balance.rs b/src/commands/staking/delegate/view_balance.rs index 2b85705de..e7a5adb11 100644 --- a/src/commands/staking/delegate/view_balance.rs +++ b/src/commands/staking/delegate/view_balance.rs @@ -65,9 +65,7 @@ impl ViewBalance { pub fn input_validator_account_id( context: &super::StakeDelegationContext, ) -> color_eyre::eyre::Result> { - crate::common::input_delegated_validator_account_id_from_used_delegated_validator_list( - &context.global_context.config, - ) + crate::common::input_staking_pool_validator_account_id(&context.global_context.config) } } diff --git a/src/commands/staking/delegate/withdraw.rs b/src/commands/staking/delegate/withdraw.rs index b578c710c..2f4e8c917 100644 --- a/src/commands/staking/delegate/withdraw.rs +++ b/src/commands/staking/delegate/withdraw.rs @@ -96,8 +96,6 @@ impl Withdraw { pub fn input_validator_account_id( context: &super::StakeDelegationContext, ) -> color_eyre::eyre::Result> { - crate::common::input_delegated_validator_account_id_from_used_delegated_validator_list( - &context.global_context.config, - ) + crate::common::input_staking_pool_validator_account_id(&context.global_context.config) } } diff --git a/src/commands/staking/delegate/withdraw_all.rs b/src/commands/staking/delegate/withdraw_all.rs index 974402a49..d25f3b8fc 100644 --- a/src/commands/staking/delegate/withdraw_all.rs +++ b/src/commands/staking/delegate/withdraw_all.rs @@ -91,8 +91,6 @@ impl WithdrawAll { pub fn input_validator_account_id( context: &super::StakeDelegationContext, ) -> color_eyre::eyre::Result> { - crate::common::input_delegated_validator_account_id_from_used_delegated_validator_list( - &context.global_context.config, - ) + crate::common::input_staking_pool_validator_account_id(&context.global_context.config) } } diff --git a/src/common.rs b/src/common.rs index de8a6b102..a8638f209 100644 --- a/src/common.rs +++ b/src/common.rs @@ -1270,19 +1270,16 @@ fn is_executable>(path: P) -> bool { } fn path_directories() -> Vec { - let mut dirs = vec![]; if let Some(val) = std::env::var_os("PATH") { - dirs.extend(std::env::split_paths(&val)); + std::env::split_paths(&val).collect() + } else { + Vec::new() } - dirs } pub fn get_delegated_validator_list_from_mainnet( network_connection: &linked_hash_map::LinkedHashMap, ) -> color_eyre::eyre::Result> { - let mut delegated_validator_list: std::collections::BTreeSet< - near_primitives::types::AccountId, - > = std::collections::BTreeSet::new(); let network_config = network_connection.get("mainnet").expect("Internal error!"); let epoch_validator_info = network_config @@ -1294,19 +1291,23 @@ pub fn get_delegated_validator_list_from_mainnet( ) .wrap_err("Failed to get epoch validators information request.")?; - for current_proposal in epoch_validator_info.current_proposals { - delegated_validator_list.insert(current_proposal.take_account_id()); - } - - for current_validator in epoch_validator_info.current_validators { - delegated_validator_list.insert(current_validator.account_id); - } - - for next_validator in epoch_validator_info.next_validators { - delegated_validator_list.insert(next_validator.account_id); - } - - Ok(delegated_validator_list) + Ok(epoch_validator_info + .current_proposals + .into_iter() + .map(|current_proposal| current_proposal.take_account_id()) + .chain( + epoch_validator_info + .current_validators + .into_iter() + .map(|current_validator| current_validator.account_id), + ) + .chain( + epoch_validator_info + .next_validators + .into_iter() + .map(|next_validator| next_validator.account_id), + ) + .collect()) } pub fn get_used_delegated_validator_list( @@ -1329,7 +1330,7 @@ pub fn get_used_delegated_validator_list( Ok(used_delegated_validator_list) } -pub fn input_delegated_validator_account_id_from_used_delegated_validator_list( +pub fn input_staking_pool_validator_account_id( config: &crate::config::Config, ) -> color_eyre::eyre::Result> { let used_delegated_validator_list = get_used_delegated_validator_list(config)? @@ -1426,49 +1427,33 @@ pub fn get_validators_stake( ) .wrap_err("Failed to get epoch validators information request.")?; - let current_proposals = epoch_validator_info.current_proposals; - let current_proposals_stake: std::collections::HashMap< - near_primitives::types::AccountId, - near_primitives::types::Balance, - > = current_proposals + Ok(epoch_validator_info + .current_proposals .into_iter() .map(|validator_stake_view| { let validator_stake = validator_stake_view.into_validator_stake(); validator_stake.account_and_stake() }) - .collect(); - - let current_validators = epoch_validator_info.current_validators; - let mut current_validators_stake: std::collections::HashMap< - near_primitives::types::AccountId, - near_primitives::types::Balance, - > = current_validators - .into_iter() - .map(|current_epoch_validator_info| { - ( - current_epoch_validator_info.account_id, - current_epoch_validator_info.stake, - ) - }) - .collect(); - - let next_validators = epoch_validator_info.next_validators; - let next_validators_stake: std::collections::HashMap< - near_primitives::types::AccountId, - near_primitives::types::Balance, - > = next_validators - .into_iter() - .map(|next_epoch_validator_info| { - ( - next_epoch_validator_info.account_id, - next_epoch_validator_info.stake, - ) - }) - .collect(); - - current_validators_stake.extend(next_validators_stake); - current_validators_stake.extend(current_proposals_stake); - Ok(current_validators_stake) + .chain(epoch_validator_info.current_validators.into_iter().map( + |current_epoch_validator_info| { + ( + current_epoch_validator_info.account_id, + current_epoch_validator_info.stake, + ) + }, + )) + .chain( + epoch_validator_info + .next_validators + .into_iter() + .map(|next_epoch_validator_info| { + ( + next_epoch_validator_info.account_id, + next_epoch_validator_info.stake, + ) + }), + ) + .collect()) } async fn get_staking_pool_info( From 45c34d115552cd2ec24fb8d8688884e39f88c575 Mon Sep 17 00:00:00 2001 From: Vlad Frolov Date: Tue, 31 Oct 2023 02:09:50 +0100 Subject: [PATCH 44/44] refactor: Refactored success messages and the `from_previous_context` --- docs/GUIDE.en.md | 12 ++- docs/GUIDE.ru.md | 2 +- .../staking/delegate/deposit_and_stake.rs | 70 +++++++++--------- src/commands/staking/delegate/stake.rs | 74 ++++++++++--------- src/commands/staking/delegate/stake_all.rs | 66 +++++++++-------- src/commands/staking/delegate/unstake.rs | 69 ++++++++--------- src/commands/staking/delegate/unstake_all.rs | 66 +++++++++-------- src/commands/staking/delegate/view_balance.rs | 2 +- src/commands/staking/delegate/withdraw.rs | 48 +++++------- src/commands/staking/delegate/withdraw_all.rs | 33 +++------ 10 files changed, 219 insertions(+), 223 deletions(-) diff --git a/docs/GUIDE.en.md b/docs/GUIDE.en.md index 8c98d5b3b..fa01a37c7 100644 --- a/docs/GUIDE.en.md +++ b/docs/GUIDE.en.md @@ -1401,7 +1401,7 @@ near staking \
The result of this command will be as follows: ```txt -Delegated stake balance on validator for : +Delegated stake balance with validator by : Staked balance: 38.021465232511349340052266 NEAR Unstaked balance: 0.000000000000000000000001 NEAR Total balance: 38.021465232511349340052267 NEAR @@ -1504,7 +1504,7 @@ near staking \
The result of this command will be as follows: ```txt - has successfully unstake 7 NEAR from . + has successfully unstaked 7 NEAR from . ```
@@ -1529,7 +1529,7 @@ near staking \
The result of this command will be as follows: ```txt - has successfully unstake the entire amount from . + has successfully unstaked the entire amount from . ```
@@ -1554,8 +1554,7 @@ near staking \
The result of this command will be as follows: ```txt -Error: - 0: can't withdraw tokens in the current epoch. + has successfully withdrawn 3 NEAR from . ```
@@ -1580,8 +1579,7 @@ near staking \
The result of this command will be as follows: ```txt -Error: - 0: can't withdraw tokens in the current epoch. + has successfully withdrawn the entire amount from . ```
diff --git a/docs/GUIDE.ru.md b/docs/GUIDE.ru.md index d8addcd30..1e19506ea 100644 --- a/docs/GUIDE.ru.md +++ b/docs/GUIDE.ru.md @@ -1404,7 +1404,7 @@ near staking \
Π Π΅Π·ΡƒΠ»ΡŒΡ‚Π°Ρ‚ выполнСния ΠΊΠΎΠΌΠ°Π½Π΄Ρ‹ ```txt -Balance on validator for : +Delegated stake balance with validator by : Staked balance: 38.021465232511349340052266 NEAR Unstaked balance: 0.000000000000000000000001 NEAR Total balance: 38.021465232511349340052267 NEAR diff --git a/src/commands/staking/delegate/deposit_and_stake.rs b/src/commands/staking/delegate/deposit_and_stake.rs index d9cfd241d..2f3a87c55 100644 --- a/src/commands/staking/delegate/deposit_and_stake.rs +++ b/src/commands/staking/delegate/deposit_and_stake.rs @@ -20,44 +20,48 @@ impl DepositAndStakeContext { previous_context: super::StakeDelegationContext, scope: &::InteractiveClapContextScope, ) -> color_eyre::eyre::Result { - let signer = previous_context.account_id.clone(); - let validator_account_id: near_primitives::types::AccountId = - scope.validator_account_id.clone().into(); - let validator_id = validator_account_id.clone(); - let interacting_with_account_ids = vec![ - previous_context.account_id.clone(), - validator_account_id.clone(), - ]; - let amount = scope.amount; - let on_after_getting_network_callback: crate::commands::OnAfterGettingNetworkCallback = - std::sync::Arc::new(move |_network_config| { - Ok(crate::commands::PrepopulatedTransaction { - signer_id: previous_context.account_id.clone(), - receiver_id: validator_account_id.clone(), - actions: vec![near_primitives::transaction::Action::FunctionCall( - near_primitives::transaction::FunctionCallAction { - method_name: "deposit_and_stake".to_string(), - args: serde_json::to_vec(&serde_json::json!({}))?, - gas: crate::common::NearGas::from_tgas(300).as_gas(), - deposit: amount.as_yoctonear(), - }, - )], - }) + std::sync::Arc::new({ + let signer_id = previous_context.account_id.clone(); + let validator_account_id: near_primitives::types::AccountId = + scope.validator_account_id.clone().into(); + let amount = scope.amount; + + move |_network_config| { + Ok(crate::commands::PrepopulatedTransaction { + signer_id: signer_id.clone(), + receiver_id: validator_account_id.clone(), + actions: vec![near_primitives::transaction::Action::FunctionCall( + near_primitives::transaction::FunctionCallAction { + method_name: "deposit_and_stake".to_string(), + args: serde_json::to_vec(&serde_json::json!({}))?, + gas: crate::common::NearGas::from_tgas(50).as_gas(), + deposit: amount.as_yoctonear(), + }, + )], + }) + } }); - let amount = scope.amount; - let on_after_sending_transaction_callback: crate::transaction_signature_options::OnAfterSendingTransactionCallback = std::sync::Arc::new( - move |outcome_view, _network_config| { - if let near_primitives::views::FinalExecutionStatus::SuccessValue(_) = outcome_view.status { - eprintln!("<{signer}> has successfully deposited and staked {amount} on <{validator_id}>.") - } - Ok(()) - }, - ); + let on_after_sending_transaction_callback: crate::transaction_signature_options::OnAfterSendingTransactionCallback = std::sync::Arc::new({ + let signer_id = previous_context.account_id.clone(); + let validator_id = scope.validator_account_id.clone(); + let amount = scope.amount; + + move |outcome_view, _network_config| { + if let near_primitives::views::FinalExecutionStatus::SuccessValue(_) = outcome_view.status { + eprintln!("<{signer_id}> has successfully delegated {amount} to stake with <{validator_id}>.") + } + Ok(()) + } + }); + Ok(Self(crate::commands::ActionContext { global_context: previous_context.global_context, - interacting_with_account_ids, + interacting_with_account_ids: vec![ + previous_context.account_id.clone(), + scope.validator_account_id.clone().into(), + ], on_after_getting_network_callback, on_before_signing_callback: std::sync::Arc::new( |_prepolulated_unsinged_transaction, _network_config| Ok(()), diff --git a/src/commands/staking/delegate/stake.rs b/src/commands/staking/delegate/stake.rs index 5681da2ca..bc854275e 100644 --- a/src/commands/staking/delegate/stake.rs +++ b/src/commands/staking/delegate/stake.rs @@ -20,46 +20,50 @@ impl StakeContext { previous_context: super::StakeDelegationContext, scope: &::InteractiveClapContextScope, ) -> color_eyre::eyre::Result { - let signer = previous_context.account_id.clone(); - let validator_account_id: near_primitives::types::AccountId = - scope.validator_account_id.clone().into(); - let validator_id = validator_account_id.clone(); - let interacting_with_account_ids = vec![ - previous_context.account_id.clone(), - validator_account_id.clone(), - ]; - let amount = scope.amount; - let on_after_getting_network_callback: crate::commands::OnAfterGettingNetworkCallback = - std::sync::Arc::new(move |_network_config| { - Ok(crate::commands::PrepopulatedTransaction { - signer_id: previous_context.account_id.clone(), - receiver_id: validator_account_id.clone(), - actions: vec![near_primitives::transaction::Action::FunctionCall( - near_primitives::transaction::FunctionCallAction { - method_name: "stake".to_string(), - args: serde_json::to_vec(&serde_json::json!({ - "amount": amount.clone().as_yoctonear().to_string() - }))?, - gas: crate::common::NearGas::from_tgas(300).as_gas(), - deposit: 0, - }, - )], - }) + std::sync::Arc::new({ + let signer_id = previous_context.account_id.clone(); + let validator_account_id: near_primitives::types::AccountId = + scope.validator_account_id.clone().into(); + let amount = scope.amount; + + move |_network_config| { + Ok(crate::commands::PrepopulatedTransaction { + signer_id: signer_id.clone(), + receiver_id: validator_account_id.clone(), + actions: vec![near_primitives::transaction::Action::FunctionCall( + near_primitives::transaction::FunctionCallAction { + method_name: "stake".to_string(), + args: serde_json::to_vec(&serde_json::json!({ + "amount": amount, + }))?, + gas: crate::common::NearGas::from_tgas(50).as_gas(), + deposit: 0, + }, + )], + }) + } }); - let amount = scope.amount; - let on_after_sending_transaction_callback: crate::transaction_signature_options::OnAfterSendingTransactionCallback = std::sync::Arc::new( - move |outcome_view, _network_config| { - if let near_primitives::views::FinalExecutionStatus::SuccessValue(_) = outcome_view.status { - eprintln!("<{signer}> has successfully stake {amount} on <{validator_id}>.") - } - Ok(()) - }, - ); + let on_after_sending_transaction_callback: crate::transaction_signature_options::OnAfterSendingTransactionCallback = std::sync::Arc::new({ + let signer_id = previous_context.account_id.clone(); + let validator_id = scope.validator_account_id.clone(); + let amount = scope.amount; + + move |outcome_view, _network_config| { + if let near_primitives::views::FinalExecutionStatus::SuccessValue(_) = outcome_view.status { + eprintln!("<{signer_id}> has successfully delegated {amount} to stake with <{validator_id}>.") + } + Ok(()) + } + }); + Ok(Self(crate::commands::ActionContext { global_context: previous_context.global_context, - interacting_with_account_ids, + interacting_with_account_ids: vec![ + previous_context.account_id.clone(), + scope.validator_account_id.clone().into(), + ], on_after_getting_network_callback, on_before_signing_callback: std::sync::Arc::new( |_prepolulated_unsinged_transaction, _network_config| Ok(()), diff --git a/src/commands/staking/delegate/stake_all.rs b/src/commands/staking/delegate/stake_all.rs index 08d0d3373..7b107a39a 100644 --- a/src/commands/staking/delegate/stake_all.rs +++ b/src/commands/staking/delegate/stake_all.rs @@ -18,42 +18,46 @@ impl StakeAllContext { previous_context: super::StakeDelegationContext, scope: &::InteractiveClapContextScope, ) -> color_eyre::eyre::Result { - let signer = previous_context.account_id.clone(); - let validator_account_id: near_primitives::types::AccountId = - scope.validator_account_id.clone().into(); - let validator_id = validator_account_id.clone(); - let interacting_with_account_ids = vec![ - previous_context.account_id.clone(), - validator_account_id.clone(), - ]; - let on_after_getting_network_callback: crate::commands::OnAfterGettingNetworkCallback = - std::sync::Arc::new(move |_network_config| { - Ok(crate::commands::PrepopulatedTransaction { - signer_id: previous_context.account_id.clone(), - receiver_id: validator_account_id.clone(), - actions: vec![near_primitives::transaction::Action::FunctionCall( - near_primitives::transaction::FunctionCallAction { - method_name: "stake_all".to_string(), - args: serde_json::to_vec(&serde_json::json!({}))?, - gas: crate::common::NearGas::from_tgas(300).as_gas(), - deposit: 0, - }, - )], - }) + std::sync::Arc::new({ + let signer_id = previous_context.account_id.clone(); + let validator_account_id: near_primitives::types::AccountId = + scope.validator_account_id.clone().into(); + + move |_network_config| { + Ok(crate::commands::PrepopulatedTransaction { + signer_id: signer_id.clone(), + receiver_id: validator_account_id.clone(), + actions: vec![near_primitives::transaction::Action::FunctionCall( + near_primitives::transaction::FunctionCallAction { + method_name: "stake_all".to_string(), + args: serde_json::to_vec(&serde_json::json!({}))?, + gas: crate::common::NearGas::from_tgas(50).as_gas(), + deposit: 0, + }, + )], + }) + } }); - let on_after_sending_transaction_callback: crate::transaction_signature_options::OnAfterSendingTransactionCallback = std::sync::Arc::new( - move |outcome_view, _network_config| { - if let near_primitives::views::FinalExecutionStatus::SuccessValue(_) = outcome_view.status { - eprintln!("<{signer}> has successfully stake the entire amount on <{validator_id}>.") - } - Ok(()) - }, - ); + let on_after_sending_transaction_callback: crate::transaction_signature_options::OnAfterSendingTransactionCallback = std::sync::Arc::new({ + let signer_id = previous_context.account_id.clone(); + let validator_id = scope.validator_account_id.clone(); + + move |outcome_view, _network_config| { + if let near_primitives::views::FinalExecutionStatus::SuccessValue(_) = outcome_view.status { + eprintln!("<{signer_id}> has successfully delegated to stake with <{validator_id}>.") + } + Ok(()) + } + }); + Ok(Self(crate::commands::ActionContext { global_context: previous_context.global_context, - interacting_with_account_ids, + interacting_with_account_ids: vec![ + previous_context.account_id.clone(), + scope.validator_account_id.clone().into(), + ], on_after_getting_network_callback, on_before_signing_callback: std::sync::Arc::new( |_prepolulated_unsinged_transaction, _network_config| Ok(()), diff --git a/src/commands/staking/delegate/unstake.rs b/src/commands/staking/delegate/unstake.rs index 2468f6bdf..8659acdaf 100644 --- a/src/commands/staking/delegate/unstake.rs +++ b/src/commands/staking/delegate/unstake.rs @@ -20,47 +20,50 @@ impl UnstakeContext { previous_context: super::StakeDelegationContext, scope: &::InteractiveClapContextScope, ) -> color_eyre::eyre::Result { - let signer = previous_context.account_id.clone(); - let validator_account_id: near_primitives::types::AccountId = - scope.validator_account_id.clone().into(); - let validator_id = validator_account_id.clone(); - let interacting_with_account_ids = vec![ - previous_context.account_id.clone(), - validator_account_id.clone(), - ]; - let amount = scope.amount; - let on_after_getting_network_callback: crate::commands::OnAfterGettingNetworkCallback = - std::sync::Arc::new(move |_network_config| { - Ok(crate::commands::PrepopulatedTransaction { - signer_id: previous_context.account_id.clone(), - receiver_id: validator_account_id.clone(), - actions: vec![near_primitives::transaction::Action::FunctionCall( - near_primitives::transaction::FunctionCallAction { - method_name: "unstake".to_string(), - args: serde_json::to_vec(&serde_json::json!({ - "amount": amount.clone().as_yoctonear().to_string() - }))?, - gas: crate::common::NearGas::from_tgas(300).as_gas(), - deposit: 0, - }, - )], - }) + std::sync::Arc::new({ + let signer_id = previous_context.account_id.clone(); + let validator_account_id: near_primitives::types::AccountId = + scope.validator_account_id.clone().into(); + let amount = scope.amount; + + move |_network_config| { + Ok(crate::commands::PrepopulatedTransaction { + signer_id: signer_id.clone(), + receiver_id: validator_account_id.clone(), + actions: vec![near_primitives::transaction::Action::FunctionCall( + near_primitives::transaction::FunctionCallAction { + method_name: "unstake".to_string(), + args: serde_json::to_vec(&serde_json::json!({ + "amount": amount, + }))?, + gas: crate::common::NearGas::from_tgas(50).as_gas(), + deposit: 0, + }, + )], + }) + } }); let on_after_sending_transaction_callback: crate::transaction_signature_options::OnAfterSendingTransactionCallback = std::sync::Arc::new({ - let amount = scope.amount; + let signer_id = previous_context.account_id.clone(); + let validator_id = scope.validator_account_id.clone(); + let amount = scope.amount; - move |outcome_view, _network_config| { - if let near_primitives::views::FinalExecutionStatus::SuccessValue(_) = outcome_view.status { - eprintln!("<{signer}> has successfully unstake {amount} from <{validator_id}>.") - } - Ok(()) + move |outcome_view, _network_config| { + if let near_primitives::views::FinalExecutionStatus::SuccessValue(_) = outcome_view.status { + eprintln!("<{signer_id}> has successfully unstaked {amount} from <{validator_id}>.") } - }); + Ok(()) + } + }); + Ok(Self(crate::commands::ActionContext { global_context: previous_context.global_context, - interacting_with_account_ids, + interacting_with_account_ids: vec![ + previous_context.account_id.clone(), + scope.validator_account_id.clone().into(), + ], on_after_getting_network_callback, on_before_signing_callback: std::sync::Arc::new( |_prepolulated_unsinged_transaction, _network_config| Ok(()), diff --git a/src/commands/staking/delegate/unstake_all.rs b/src/commands/staking/delegate/unstake_all.rs index af57fa7f3..1f1d278c4 100644 --- a/src/commands/staking/delegate/unstake_all.rs +++ b/src/commands/staking/delegate/unstake_all.rs @@ -18,42 +18,46 @@ impl UnstakeAllContext { previous_context: super::StakeDelegationContext, scope: &::InteractiveClapContextScope, ) -> color_eyre::eyre::Result { - let signer = previous_context.account_id.clone(); - let validator_account_id: near_primitives::types::AccountId = - scope.validator_account_id.clone().into(); - let validator_id = validator_account_id.clone(); - let interacting_with_account_ids = vec![ - previous_context.account_id.clone(), - validator_account_id.clone(), - ]; - let on_after_getting_network_callback: crate::commands::OnAfterGettingNetworkCallback = - std::sync::Arc::new(move |_network_config| { - Ok(crate::commands::PrepopulatedTransaction { - signer_id: previous_context.account_id.clone(), - receiver_id: validator_account_id.clone(), - actions: vec![near_primitives::transaction::Action::FunctionCall( - near_primitives::transaction::FunctionCallAction { - method_name: "unstake_all".to_string(), - args: serde_json::to_vec(&serde_json::json!({}))?, - gas: crate::common::NearGas::from_tgas(300).as_gas(), - deposit: 0, - }, - )], - }) + std::sync::Arc::new({ + let signer_id = previous_context.account_id.clone(); + let validator_account_id: near_primitives::types::AccountId = + scope.validator_account_id.clone().into(); + + move |_network_config| { + Ok(crate::commands::PrepopulatedTransaction { + signer_id: signer_id.clone(), + receiver_id: validator_account_id.clone(), + actions: vec![near_primitives::transaction::Action::FunctionCall( + near_primitives::transaction::FunctionCallAction { + method_name: "unstake_all".to_string(), + args: serde_json::to_vec(&serde_json::json!({}))?, + gas: crate::common::NearGas::from_tgas(50).as_gas(), + deposit: 0, + }, + )], + }) + } }); - let on_after_sending_transaction_callback: crate::transaction_signature_options::OnAfterSendingTransactionCallback = std::sync::Arc::new( - move |outcome_view, _network_config| { - if let near_primitives::views::FinalExecutionStatus::SuccessValue(_) = outcome_view.status { - eprintln!("<{signer}> has successfully unstake the entire amount from <{validator_id}>.") - } - Ok(()) - }, - ); + let on_after_sending_transaction_callback: crate::transaction_signature_options::OnAfterSendingTransactionCallback = std::sync::Arc::new({ + let signer_id = previous_context.account_id.clone(); + let validator_id = scope.validator_account_id.clone(); + + move |outcome_view, _network_config| { + if let near_primitives::views::FinalExecutionStatus::SuccessValue(_) = outcome_view.status { + eprintln!("<{signer_id}> has successfully unstaked the entire available amount from <{validator_id}>.") + } + Ok(()) + } + }); + Ok(Self(crate::commands::ActionContext { global_context: previous_context.global_context, - interacting_with_account_ids, + interacting_with_account_ids: vec![ + previous_context.account_id.clone(), + scope.validator_account_id.clone().into(), + ], on_after_getting_network_callback, on_before_signing_callback: std::sync::Arc::new( |_prepolulated_unsinged_transaction, _network_config| Ok(()), diff --git a/src/commands/staking/delegate/view_balance.rs b/src/commands/staking/delegate/view_balance.rs index e7a5adb11..f529ac98e 100644 --- a/src/commands/staking/delegate/view_balance.rs +++ b/src/commands/staking/delegate/view_balance.rs @@ -39,7 +39,7 @@ impl ViewBalanceContext { _ => "" }; - eprintln!("Balance on validator <{validator_account_id}> for <{account_id}>:"); + eprintln!("Delegated stake balance with validator <{validator_account_id}> by <{account_id}>:"); eprintln!(" Staked balance: {:>38}", near_token::NearToken::from_yoctonear(user_staked_balance).to_string()); eprintln!(" Unstaked balance: {:>38} {withdrawal_availability_message}", near_token::NearToken::from_yoctonear(user_unstaked_balance).to_string()); eprintln!(" Total balance: {:>38}", near_token::NearToken::from_yoctonear(user_total_balance).to_string()); diff --git a/src/commands/staking/delegate/withdraw.rs b/src/commands/staking/delegate/withdraw.rs index 2f4e8c917..b669f08ad 100644 --- a/src/commands/staking/delegate/withdraw.rs +++ b/src/commands/staking/delegate/withdraw.rs @@ -20,29 +20,14 @@ impl WithdrawContext { previous_context: super::StakeDelegationContext, scope: &::InteractiveClapContextScope, ) -> color_eyre::eyre::Result { - let validator_account_id: near_primitives::types::AccountId = - scope.validator_account_id.clone().into(); - let validator_id = validator_account_id.clone(); - let interacting_with_account_ids = vec![ - previous_context.account_id.clone(), - validator_account_id.clone(), - ]; - let on_after_getting_network_callback: crate::commands::OnAfterGettingNetworkCallback = std::sync::Arc::new({ let signer_id = previous_context.account_id.clone(); + let validator_account_id: near_primitives::types::AccountId = + scope.validator_account_id.clone().into(); let amount = scope.amount; - move |network_config| { - if !super::view_balance::is_account_unstaked_balance_available_for_withdrawal( - network_config, - &validator_account_id, - &signer_id, - )? { - return Err(color_eyre::Report::msg(format!( - "<{signer_id}> can't withdraw tokens in the current epoch." - ))); - } + move |_network_config| { Ok(crate::commands::PrepopulatedTransaction { signer_id: signer_id.clone(), receiver_id: validator_account_id.clone(), @@ -50,9 +35,9 @@ impl WithdrawContext { near_primitives::transaction::FunctionCallAction { method_name: "withdraw".to_string(), args: serde_json::to_vec(&serde_json::json!({ - "amount": amount.clone().as_yoctonear().to_string() + "amount": amount, }))?, - gas: crate::common::NearGas::from_tgas(300).as_gas(), + gas: crate::common::NearGas::from_tgas(50).as_gas(), deposit: 0, }, )], @@ -61,19 +46,24 @@ impl WithdrawContext { }); let on_after_sending_transaction_callback: crate::transaction_signature_options::OnAfterSendingTransactionCallback = std::sync::Arc::new({ - let amount = scope.amount; - let signer_id = previous_context.account_id.clone(); + let signer_id = previous_context.account_id.clone(); + let validator_id = scope.validator_account_id.clone(); + let amount = scope.amount; - move |outcome_view, _network_config| { - if let near_primitives::views::FinalExecutionStatus::SuccessValue(_) = outcome_view.status { - eprintln!("<{signer_id}> has successfully withdrawn {amount} from <{validator_id}>.") - } - Ok(()) + move |outcome_view, _network_config| { + if let near_primitives::views::FinalExecutionStatus::SuccessValue(_) = outcome_view.status { + eprintln!("<{signer_id}> has successfully withdrawn {amount} from <{validator_id}>.") } - }); + Ok(()) + } + }); + Ok(Self(crate::commands::ActionContext { global_context: previous_context.global_context, - interacting_with_account_ids, + interacting_with_account_ids: vec![ + previous_context.account_id.clone(), + scope.validator_account_id.clone().into(), + ], on_after_getting_network_callback, on_before_signing_callback: std::sync::Arc::new( |_prepolulated_unsinged_transaction, _network_config| Ok(()), diff --git a/src/commands/staking/delegate/withdraw_all.rs b/src/commands/staking/delegate/withdraw_all.rs index d25f3b8fc..be0ce58ec 100644 --- a/src/commands/staking/delegate/withdraw_all.rs +++ b/src/commands/staking/delegate/withdraw_all.rs @@ -18,29 +18,13 @@ impl WithdrawAllContext { previous_context: super::StakeDelegationContext, scope: &::InteractiveClapContextScope, ) -> color_eyre::eyre::Result { - let validator_account_id: near_primitives::types::AccountId = - scope.validator_account_id.clone().into(); - let validator_id = validator_account_id.clone(); - let interacting_with_account_ids = vec![ - previous_context.account_id.clone(), - validator_account_id.clone(), - ]; - let on_after_getting_network_callback: crate::commands::OnAfterGettingNetworkCallback = std::sync::Arc::new({ let signer_id = previous_context.account_id.clone(); + let validator_account_id: near_primitives::types::AccountId = + scope.validator_account_id.clone().into(); - move |network_config| { - if !super::view_balance::is_account_unstaked_balance_available_for_withdrawal( - network_config, - &validator_account_id, - &signer_id, - )? { - return Err(color_eyre::Report::msg(format!( - "<{signer_id}> can't withdraw tokens in the current epoch." - ))); - } - + move |_network_config| { Ok(crate::commands::PrepopulatedTransaction { signer_id: signer_id.clone(), receiver_id: validator_account_id.clone(), @@ -48,7 +32,7 @@ impl WithdrawAllContext { near_primitives::transaction::FunctionCallAction { method_name: "withdraw_all".to_string(), args: serde_json::to_vec(&serde_json::json!({}))?, - gas: crate::common::NearGas::from_tgas(300).as_gas(), + gas: crate::common::NearGas::from_tgas(50).as_gas(), deposit: 0, }, )], @@ -58,17 +42,22 @@ impl WithdrawAllContext { let on_after_sending_transaction_callback: crate::transaction_signature_options::OnAfterSendingTransactionCallback = std::sync::Arc::new({ let signer_id = previous_context.account_id.clone(); + let validator_id = scope.validator_account_id.clone(); move |outcome_view, _network_config| { if let near_primitives::views::FinalExecutionStatus::SuccessValue(_) = outcome_view.status { - eprintln!("<{signer_id}> has successfully withdrawn the entire amount from <{validator_id}>.") + eprintln!("<{signer_id}> has successfully withdrawn the entire available amount from <{validator_id}>.") } Ok(()) } }); + Ok(Self(crate::commands::ActionContext { global_context: previous_context.global_context, - interacting_with_account_ids, + interacting_with_account_ids: vec![ + previous_context.account_id.clone(), + scope.validator_account_id.clone().into(), + ], on_after_getting_network_callback, on_before_signing_callback: std::sync::Arc::new( |_prepolulated_unsinged_transaction, _network_config| Ok(()),