-
Notifications
You must be signed in to change notification settings - Fork 56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: New command - staking #227
Merged
Changes from 17 commits
Commits
Show all changes
54 commits
Select commit
Hold shift + click to select a range
54ef498
start
e2f3af7
added Withdraw, WithdrawAll
5d00339
added Unstake, UnstakeAll
7089c69
refactored Withdraw, WithdrawAll
538253c
added ViewBalance
2ac06dc
added ValidatorList
17fd266
refactored
5f5d1e2
fixed
39ccfb7
refactored
bca4e17
added delegated stake for view_account_summary
3f6b8ef
refactored get_validator_list()
e8fd341
refactored delegated_stake
9ddcb47
fixed
13f1b7b
added Stake, StakeAll
d94aade
added Deposit, DepositAndStake
9ad54aa
fixed <non-printable data (0 B)>
629d0d4
Merge branch 'master' into staking
FroVolod 6acc1cb
Merge branch 'master' into staking
FroVolod b2646c8
updated to "order networks selection ..." #225
cc04fe1
added validators url
66d3b40
Merge branch 'master' into staking
FroVolod 0d7e3b8
Merge branch 'master' into staking
FroVolod 3591c95
Merge branch 'master' into staking
FroVolod d461b41
fixed unstake message
4e9af99
Merge branch 'master' into staking
FroVolod d93fedf
updated to "near-gas"
e8fbce9
clippy
70b7eaf
Merge branch 'master' into staking
FroVolod 4fef7c4
updated: interactive-clap = "0.2.5"
3241e84
Merge branch 'master' into staking
FroVolod 49809df
Merge remote-tracking branch 'origin/master' into staking
dbf79fc
refactor: optimized and simplified the delegated stake fetching
frol e6ba1ff
refactor: serde_json::to_vec() instead of .to_string().into_bytes()
cf8cfb6
Update src/commands/staking/delegate/unstake.rs
FroVolod 4d92ff3
refactored get_validator_list()
1ebba51
refactored
1645264
updated input_account_id()
205d93a
refactored get_validator_list()
3038d61
added get_used_delegated_validator_list()
2e7a484
updated GUIDE
770796d
Update src/commands/staking/delegate/mod.rs
FroVolod 2998e10
renamed Delegate to Delegation
fa9a653
fixed GUIDE
33abbb2
fixed GUIDE
d40363f
docs: Updated the GUIDE
frol 7461a4f
updated StakeDelegationCommand
877098c
fixed GUIDE
8559cbc
updated view-balance
829144a
updated get_used_delegated_validator_list()
dde9cb8
updated cargo.lock
371bdf5
Merge remote-tracking branch 'origin/master' into staking
60f7e5c
fixed GUIDES
frol 07960bb
refactor: common.rs
frol 45c34d1
refactor: Refactored success messages and the `from_previous_context`
frol File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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: &<Deposit as interactive_clap::ToInteractiveClapContextScope>::InteractiveClapContextScope, | ||
) -> color_eyre::eyre::Result<Self> { | ||
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<DepositContext> 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<Option<crate::types::account_id::AccountId>> { | ||
crate::common::input_signer_account_id_from_used_account_list( | ||
&context.global_context.config.credentials_home_dir, | ||
"What is the signer account ID?", | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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: &<DepositAndStake as interactive_clap::ToInteractiveClapContextScope>::InteractiveClapContextScope, | ||
) -> color_eyre::eyre::Result<Self> { | ||
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<DepositAndStakeContext> 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<Option<crate::types::account_id::AccountId>> { | ||
crate::common::input_signer_account_id_from_used_account_list( | ||
&context.global_context.config.credentials_home_dir, | ||
"What is the signer account ID?", | ||
) | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently, the delegated stake for account_id can be viewed on validators and proposals. I need help to view the delegated stake in the validator whitelist.