-
Notifications
You must be signed in to change notification settings - Fork 7
feat(dre): top up neuron request #752
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
b5f8777
adding balance command
NikolaMilosa 124dff6
getting account hex
NikolaMilosa 1069881
implementing topup request command
NikolaMilosa d33e589
Branch was auto-updated.
sa-github-api c0bb83b
Branch was auto-updated.
sa-github-api 1d20e69
implementing refresh
NikolaMilosa 5de65fc
adding refresh
NikolaMilosa 3e7715d
Branch was auto-updated.
sa-github-api 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 hidden or 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 hidden or 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,32 @@ | ||
use clap::Args; | ||
use ic_canisters::governance::GovernanceCanisterWrapper; | ||
|
||
use crate::commands::ExecutableCommand; | ||
|
||
#[derive(Args, Debug)] | ||
pub struct Balance { | ||
/// Neuron to query, by default will use the one from configured identity | ||
#[clap(long)] | ||
neuron: Option<u64>, | ||
} | ||
|
||
impl ExecutableCommand for Balance { | ||
fn require_ic_admin(&self) -> crate::commands::IcAdminRequirement { | ||
match &self.neuron { | ||
Some(_) => crate::commands::IcAdminRequirement::None, | ||
None => crate::commands::IcAdminRequirement::Detect, | ||
} | ||
} | ||
|
||
fn validate(&self, _cmd: &mut clap::Command) {} | ||
|
||
async fn execute(&self, ctx: crate::ctx::DreContext) -> anyhow::Result<()> { | ||
let governance = GovernanceCanisterWrapper::from(ctx.create_canister_client()?); | ||
let neuron_info = governance | ||
.get_neuron_info(self.neuron.unwrap_or_else(|| ctx.ic_admin().neuron.neuron_id)) | ||
.await?; | ||
|
||
println!("{}", neuron_info.stake_e8s / 10_u64.pow(8)); | ||
Ok(()) | ||
} | ||
} |
This file contains hidden or 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,32 @@ | ||
use clap::Args; | ||
|
||
use super::{impl_executable_command_for_enums, ExecutableCommand, IcAdminRequirement}; | ||
use crate::commands::neuron::balance::Balance; | ||
use crate::commands::neuron::refresh::Refresh; | ||
use crate::commands::neuron::top_up::TopUp; | ||
|
||
mod balance; | ||
mod refresh; | ||
mod top_up; | ||
|
||
#[derive(Args, Debug)] | ||
pub struct Neuron { | ||
#[clap(subcommand)] | ||
pub subcommand: Subcommands, | ||
} | ||
|
||
impl_executable_command_for_enums! { Balance, TopUp, Refresh } | ||
|
||
impl ExecutableCommand for Neuron { | ||
fn require_ic_admin(&self) -> IcAdminRequirement { | ||
self.subcommand.require_ic_admin() | ||
} | ||
|
||
fn validate(&self, cmd: &mut Command) { | ||
self.subcommand.validate(cmd) | ||
} | ||
|
||
async fn execute(&self, ctx: DreContext) -> anyhow::Result<()> { | ||
self.subcommand.execute(ctx).await | ||
} | ||
} |
This file contains hidden or 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,24 @@ | ||
use clap::Args; | ||
use ic_canisters::governance::GovernanceCanisterWrapper; | ||
|
||
use crate::commands::ExecutableCommand; | ||
|
||
#[derive(Args, Debug)] | ||
pub struct Refresh {} | ||
|
||
impl ExecutableCommand for Refresh { | ||
fn require_ic_admin(&self) -> crate::commands::IcAdminRequirement { | ||
crate::commands::IcAdminRequirement::Detect | ||
} | ||
|
||
fn validate(&self, _cmd: &mut clap::Command) {} | ||
|
||
async fn execute(&self, ctx: crate::ctx::DreContext) -> anyhow::Result<()> { | ||
let governance_canister = GovernanceCanisterWrapper::from(ctx.create_canister_client()?); | ||
|
||
let resp = governance_canister.refresh_neuron(ctx.ic_admin().neuron.neuron_id).await?; | ||
println!("{:?}", resp); | ||
|
||
Ok(()) | ||
} | ||
} |
This file contains hidden or 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,32 @@ | ||
use clap::Args; | ||
use ic_canisters::governance::GovernanceCanisterWrapper; | ||
use itertools::Itertools; | ||
|
||
use crate::commands::ExecutableCommand; | ||
|
||
#[derive(Args, Debug)] | ||
pub struct TopUp {} | ||
|
||
impl ExecutableCommand for TopUp { | ||
fn require_ic_admin(&self) -> crate::commands::IcAdminRequirement { | ||
crate::commands::IcAdminRequirement::Detect | ||
} | ||
|
||
fn validate(&self, _cmd: &mut clap::Command) {} | ||
|
||
async fn execute(&self, ctx: crate::ctx::DreContext) -> anyhow::Result<()> { | ||
let governance = GovernanceCanisterWrapper::from(ctx.create_canister_client()?); | ||
let full_neuron = governance.get_full_neuron(ctx.ic_admin().neuron.neuron_id).await?; | ||
let account_hex = full_neuron.account.iter().map(|byte| format!("{:02x}", byte)).join(""); | ||
|
||
println!("Please request ICP in the #icp-to-go slack channel:"); | ||
println!( | ||
"> Hi! Can I please get XX ICPs on the account address `{}` for neuron ID {} in order to be able to submit more NNS proposals. Thank you\n", | ||
account_hex, | ||
ctx.ic_admin().neuron.neuron_id | ||
); | ||
println!("You can check balance by running `dre neuron balance`"); | ||
|
||
Ok(()) | ||
} | ||
} |
This file contains hidden or 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
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.
Uh oh!
There was an error while loading. Please reload this page.