Skip to content
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(cli): bridge sudo change command #1612

Merged
merged 5 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions crates/astria-cli/src/sequencer/bridge_account.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
use astria_core::primitive::v1::Address;
use astria_sequencer_client::{
HttpClient,
SequencerClientExt,
};
use color_eyre::eyre::{
self,
WrapErr as _,
};

#[derive(Debug, clap::Args)]
pub(super) struct Command {
#[command(subcommand)]
command: SubCommand,
}

impl Command {
pub(super) async fn run(self) -> eyre::Result<()> {
let SubCommand::Get(get) = self.command;
get.run().await
}
}

#[derive(Debug, clap::Subcommand)]
enum SubCommand {
/// Command for getting bridge account information
Get(Get),
}

#[derive(Debug, clap::Args)]
struct Get {
/// The url of the Sequencer node
#[arg(
long,
env = "SEQUENCER_URL",
default_value = crate::DEFAULT_SEQUENCER_RPC
)]
pub(crate) sequencer_url: String,
/// The bridge account address on the Sequencer
pub(crate) address: Address,
}

impl Get {
async fn run(self) -> eyre::Result<()> {
let sequencer_client = HttpClient::new(self.sequencer_url.as_str())
.wrap_err("failed constructing http sequencer client")?;

let res = sequencer_client
.get_bridge_account_info(self.address)
.await
.wrap_err("failed getting bridge account")?;
let Some(info) = res.info else {
return Err(eyre::eyre!("bridge account information not found"));
};
println!("Bridge Account Information for address: {}", self.address);
println!(" Rollup Id: {}", info.rollup_id);
println!(" Asset: {}", info.asset);
println!(" Sudo Address: {}", info.sudo_address);
println!(" Withdrawer Address {}", info.withdrawer_address);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
println!(" Withdrawer Address {}", info.withdrawer_address);
println!(" Withdrawer Address: {}", info.withdrawer_address);

Ok(())
}
}
81 changes: 81 additions & 0 deletions crates/astria-cli/src/sequencer/bridge_sudo_change.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
use astria_core::{
primitive::v1::{
asset,
Address,
},
protocol::transaction::v1::{
action::BridgeSudoChange,
Action,
},
};
use color_eyre::eyre::{
self,
WrapErr as _,
};

use crate::utils::submit_transaction;

#[derive(clap::Args, Debug)]
#[command(group(clap::ArgGroup::new("new_address")
.required(true)
.multiple(true)
.args(&["new_sudo_address", "new_withdrawer_address"])))]
pub(crate) struct Command {
/// The bridge account whose privileges will be modified.
pub(crate) bridge_address: Address,
/// The new address to receive sudo privileges.
#[arg(long, default_value = None)]
pub(crate) new_sudo_address: Option<Address>,
/// The new address to receive withdrawer privileges.
#[arg(long, default_value = None)]
pub(crate) new_withdrawer_address: Option<Address>,
/// The prefix to construct a bech32m address given the private key.
#[arg(long, default_value = "astria")]
pub(crate) prefix: String,
// TODO: https://github.com/astriaorg/astria/issues/594
// Don't use a plain text private, prefer wrapper like from
// the secrecy crate with specialized `Debug` and `Drop` implementations
// that overwrite the key on drop and don't reveal it when printing.
#[arg(long, env = "SEQUENCER_PRIVATE_KEY")]
pub(crate) private_key: String,
/// The url of the Sequencer node
#[arg(
long,
env = "SEQUENCER_URL",
default_value = crate::DEFAULT_SEQUENCER_RPC
)]
pub(crate) sequencer_url: String,
/// The chain id of the sequencing chain being used
#[arg(
long = "sequencer.chain-id",
env = "ROLLUP_SEQUENCER_CHAIN_ID",
default_value = crate::DEFAULT_SEQUENCER_CHAIN_ID
)]
pub(crate) sequencer_chain_id: String,
/// The asset to pay the transfer fees with.
#[arg(long, default_value = "nria")]
pub(crate) fee_asset: asset::Denom,
}

impl Command {
pub(super) async fn run(self) -> eyre::Result<()> {
let res = submit_transaction(
self.sequencer_url.as_str(),
self.sequencer_chain_id.clone(),
&self.prefix,
self.private_key.as_str(),
Action::BridgeSudoChange(BridgeSudoChange {
bridge_address: self.bridge_address,
new_sudo_address: self.new_sudo_address,
new_withdrawer_address: self.new_withdrawer_address,
fee_asset: self.fee_asset.clone(),
}),
)
.await
.wrap_err("failed to submit BridgeSudoChange transaction")?;

println!("BridgeSudoChange completed!");
println!("Included in block: {}", res.height);
Ok(())
}
}
8 changes: 8 additions & 0 deletions crates/astria-cli/src/sequencer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ mod account;
mod address;
mod balance;
mod block_height;
mod bridge_account;
mod bridge_lock;
mod bridge_sudo_change;
mod ics20_withdrawal;
mod init_bridge_account;
mod sign;
Expand Down Expand Up @@ -35,6 +37,8 @@ impl Command {
SubCommand::Ics20Withdrawal(ics20_withdrawal) => ics20_withdrawal.run().await,
SubCommand::Submit(submit) => submit.run().await,
SubCommand::Sign(sign) => sign.run(),
SubCommand::BridgeSudoChange(bridge_sudo_change) => bridge_sudo_change.run().await,
SubCommand::BridgeAccount(bridge_account) => bridge_account.run().await,
}
}
}
Expand Down Expand Up @@ -72,4 +76,8 @@ enum SubCommand {
backticks"
)]
Sign(sign::Command),
/// Command for changing sudo and withdrawer addresses
BridgeSudoChange(bridge_sudo_change::Command),
/// Commands for interacting with the bridge account
BridgeAccount(bridge_account::Command),
}
Loading