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): small rpc cli improvements #3466

Merged
merged 1 commit into from
Jan 9, 2025
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
2 changes: 1 addition & 1 deletion lib/voyager-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ pub struct ClientInfo {
/// This is currently only used for threading the checksum for ibc-go
/// 08-wasm clients, and can likely be removed when support for that IBC
/// interface is dropped.
#[serde(default)]
#[serde(default, skip_serializing_if = "Value::is_null")]
pub metadata: Value,
}

Expand Down
24 changes: 19 additions & 5 deletions voyager/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,25 +187,39 @@ pub enum RpcCmd {
ClientState {
#[arg(value_parser(|s: &str| ok(ChainId::new(s.to_owned()))))]
on: ChainId,
// #[arg(value_parser(|s: &str| ok(RawClientId::new(s.parse::<Value>().unwrap_or_else(|_| Value::String(s.to_owned()))))))]
client_id: RawClientId,
#[arg(value_parser(|s: &str| ok(IbcSpecId::new(s.to_owned()))))]
ibc_spec_id: IbcSpecId,
client_id: RawClientId,
#[arg(long, default_value_t = QueryHeight::Latest)]
height: QueryHeight,
#[arg(long, short = 'd', default_value_t = false)]
decode: bool,
},
ConsensusState {
ClientMeta {
#[arg(value_parser(|s: &str| ok(ChainId::new(s.to_owned()))))]
on: ChainId,
// #[arg(value_parser(|s: &str| ok(RawClientId::new(s.parse::<Value>().unwrap_or_else(|_| Value::String(s.to_owned()))))))]
client_id: RawClientId,
#[arg(value_parser(|s: &str| ok(IbcSpecId::new(s.to_owned()))))]
ibc_spec_id: IbcSpecId,
client_id: RawClientId,
#[arg(long, default_value_t = QueryHeight::Latest)]
height: QueryHeight,
},
ClientInfo {
#[arg(value_parser(|s: &str| ok(ChainId::new(s.to_owned()))))]
on: ChainId,
client_id: RawClientId,
#[arg(value_parser(|s: &str| ok(IbcSpecId::new(s.to_owned()))))]
ibc_spec_id: IbcSpecId,
},
ConsensusState {
#[arg(value_parser(|s: &str| ok(ChainId::new(s.to_owned()))))]
on: ChainId,
#[arg(value_parser(|s: &str| ok(IbcSpecId::new(s.to_owned()))))]
ibc_spec_id: IbcSpecId,
client_id: RawClientId,
trusted_height: Height,
#[arg(long, default_value_t = QueryHeight::Latest)]
height: QueryHeight,
#[arg(long, short = 'd', default_value_t = false)]
decode: bool,
},
Expand Down
113 changes: 69 additions & 44 deletions voyager/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -500,22 +500,45 @@ async fn do_main(args: cli::AppArgs) -> anyhow::Result<()> {
get_voyager_config()?.voyager.rpc_laddr
))?;

let ibc_handlers = [
(IbcClassic::ID, IbcSpecHandler::new::<IbcClassic>()),
(IbcUnion::ID, IbcSpecHandler::new::<IbcUnion>()),
]
.into_iter()
.collect::<HashMap<_, _>>();

match rpc {
RpcCmd::Info => print_json(&voyager_client.info().await?),
RpcCmd::ClientMeta {
on,
client_id,
ibc_spec_id,
height,
} => {
let client_meta = voyager_client
.client_meta(on.clone(), ibc_spec_id.clone(), height, client_id.clone())
.await?;

print_json(&client_meta);
}
RpcCmd::ClientInfo {
on,
client_id,
ibc_spec_id,
} => {
let client_info = voyager_client
.client_info(on.clone(), ibc_spec_id.clone(), client_id.clone())
.await?;

print_json(&client_info);
}
RpcCmd::ClientState {
on,
client_id,
ibc_spec_id,
height,
decode,
} => {
let ibc_handlers = [
(IbcClassic::ID, IbcSpecHandler::new::<IbcClassic>()),
(IbcUnion::ID, IbcSpecHandler::new::<IbcUnion>())
]
.into_iter()
.collect::<HashMap<_, _>>();

let ibc_state = voyager_client
.query_ibc_state(
on.clone(),
Expand Down Expand Up @@ -550,45 +573,47 @@ async fn do_main(args: cli::AppArgs) -> anyhow::Result<()> {
}
}
RpcCmd::ConsensusState {
// on,
// client_id,
// ibc_spec_id,
// trusted_height,
// height,
// decode,
on,
client_id,
ibc_spec_id,
trusted_height,
height,
decode,
..
} => {
// let ibc_state = voyager_client
// .query_client_consensus_state(
// on.clone(),
// height,
// client_id.clone(),
// trusted_height,
// )
// .await?;

// if decode {
// let client_info = voyager_client
// .client_info(on, ibc_spec_id, client_id)
// .await?;

// let decoded = voyager_client
// .decode_consensus_state(
// client_info.client_type,
// client_info.ibc_interface,
// ibc_state.state,
// )
// .await?;

// print_json(&IbcState {
// height: ibc_state.height,
// state: decoded,
// });
// } else {
// print_json(&ibc_state);
// }

todo!()
let ibc_state = voyager_client
.query_ibc_state(
on.clone(),
ibc_spec_id.clone(),
height,
(ibc_handlers.get(&ibc_spec_id).unwrap().consensus_state_path)(
client_id.clone(),
trusted_height.to_string(),
)?,
)
.await?;

if decode {
let client_info = voyager_client
.client_info(on, ibc_spec_id.clone(), client_id)
.await?;

let decoded = voyager_client
.decode_consensus_state(
client_info.client_type,
client_info.ibc_interface,
ibc_spec_id,
serde_json::from_value(ibc_state.state).unwrap(),
)
.await?;

print_json(&IbcState {
height: ibc_state.height,
state: decoded,
});
} else {
print_json(&ibc_state);
}
}
}
}
Expand Down
Loading