-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cli): bridge sudo change command (#1612)
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
1 parent
1ac8458
commit 1a69dc8
Showing
3 changed files
with
151 additions
and
0 deletions.
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
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(()) | ||
} | ||
} |
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,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(()) | ||
} | ||
} |
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