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(voyager): clean up the cli arguments #788

Merged
merged 1 commit into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
42 changes: 6 additions & 36 deletions voyager/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,37 +36,27 @@ pub struct AppArgs {
#[allow(clippy::large_enum_variant)]
pub enum Command {
PrintConfig,
Relay(RelayCmd),
#[command(subcommand)]
SubmitPacket(SubmitPacketCmd),
#[command(subcommand)]
Query(QueryCmd),
Relay,
#[command(subcommand)]
Setup(SetupCmd),
#[command(subcommand)]
Ibc(IbcCmd),
}

#[derive(Debug, Subcommand)]
pub enum IbcCmd {
Query {
#[arg(long)]
on: String,
#[arg(long, default_value_t = QueryHeight::<Height>::Latest)]
at: QueryHeight<Height>,
#[command(subcommand)]
cmd: IbcQueryCmd,
cmd: QueryCmd,
},
}

#[derive(Debug, Subcommand)]
pub enum IbcQueryCmd {
pub enum QueryCmd {
#[command(subcommand)]
Path(IbcQueryPathCmd),
IbcPath(QueryIbcPathCmd),
}

#[derive(Debug, clap::Subcommand)]
pub enum IbcQueryPathCmd {
pub enum QueryIbcPathCmd {
ClientState(proof::ClientStatePath<String>),
ClientConsensusState(proof::ClientConsensusStatePath<String, Height>),
Connection(proof::ConnectionPath),
Expand All @@ -75,7 +65,7 @@ pub enum IbcQueryPathCmd {
Acknowledgement(proof::AcknowledgementPath),
}

impl IbcQueryPathCmd {
impl QueryIbcPathCmd {
pub async fn any_state_proof_to_json<
Counterparty: Chain,
This: IbcStateReadPaths<Counterparty>,
Expand Down Expand Up @@ -166,26 +156,6 @@ pub enum SubmitPacketCmd {
},
}

#[derive(Debug, Subcommand)]
pub enum QueryCmd {
Client {
#[arg(long)]
on: String,
#[arg(long)]
client_id: String,
},
Connection {},
Channel {},
Balances {
#[arg(long)]
on: String,
#[arg(long)]
who: Address,
#[arg(long)]
denom: String,
},
}

#[derive(Debug, Parser)]
pub struct RelayCmd {
#[arg(long)]
Expand Down
54 changes: 23 additions & 31 deletions voyager/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ use unionlabs::ethereum_consts_traits::Mainnet;

use crate::{
chain::AnyChain,
cli::{AppArgs, Command, IbcCmd, IbcQueryCmd},
cli::{AppArgs, Command, QueryCmd},
config::Config,
queue::{AnyQueue, InMemoryQueue, PgQueue, Voyager},
queue::{AnyQueue, Voyager},
};

pub const DELAY_PERIOD: u64 = 0;
Expand Down Expand Up @@ -51,7 +51,8 @@ async fn do_main(args: cli::AppArgs) -> Result<(), anyhow::Error> {
match args.command {
Command::PrintConfig => {
println!("{}", serde_json::to_string_pretty(&voyager_config).unwrap());

}
Command::Relay => {
let queue = Voyager::new(voyager_config.clone()).await;

queue.run().await;
Expand Down Expand Up @@ -100,39 +101,30 @@ async fn do_main(args: cli::AppArgs) -> Result<(), anyhow::Error> {
}
_ => panic!("not supported"),
},
Command::Ibc(IbcCmd::Query {
on,
at,
cmd: IbcQueryCmd::Path(path),
}) => {
Command::Query { on, at, cmd } => {
let on = voyager_config.get_chain(&on).await.unwrap();

let json = match on {
// AnyChain::Union(_) => todo!(),
AnyChain::EvmMainnet(evm) => {
path.any_state_proof_to_json::<Union, _>(evm, at).await
}
AnyChain::EvmMinimal(evm) => {
path.any_state_proof_to_json::<Union, _>(evm, at).await
}
AnyChain::Union(union) => {
// NOTE: ChainSpec is arbitrary
path.any_state_proof_to_json::<Evm<Mainnet>, _>(union, at)
.await
match cmd {
QueryCmd::IbcPath(path) => {
let json = match on {
AnyChain::EvmMainnet(evm) => {
path.any_state_proof_to_json::<Union, _>(evm, at).await
}
AnyChain::EvmMinimal(evm) => {
path.any_state_proof_to_json::<Union, _>(evm, at).await
}
AnyChain::Union(union) => {
// NOTE: ChainSpec is arbitrary
path.any_state_proof_to_json::<Evm<Mainnet>, _>(union, at)
.await
}
};

println!("{json}");
}
_ => panic!(),
};

println!("{json}");
}
}
_ => panic!(),
}

std::fs::write(
args.config_file_path,
serde_json::to_string_pretty(&voyager_config).unwrap(),
)
.unwrap();

Ok(())
}
Loading