Skip to content

Commit

Permalink
feat(cli): bridge sudo change command (#1612)
Browse files Browse the repository at this point in the history
Summary
Adds bridge-sudo-change command for changing bridge privileges addresses

Background
Part of adding more actions to the cli

Changes
- adds `bridge-sudo-change` command setting bridge account privileges
addresses
- adds `bridge-account get` command querying bridge account information
Testing
Locally against a cluster

Related Issues
Part of #1474

closes #1547
  • Loading branch information
quasystaty1 authored Nov 6, 2024
1 parent 1ac8458 commit 1a69dc8
Show file tree
Hide file tree
Showing 3 changed files with 151 additions and 0 deletions.
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);
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),
}

0 comments on commit 1a69dc8

Please sign in to comment.