Skip to content

Commit

Permalink
fix: align forest-cli chain message output with lotus (#3709)
Browse files Browse the repository at this point in the history
  • Loading branch information
hanabi1224 authored Nov 10, 2023
1 parent 19d1312 commit 7286a85
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/cli/subcommands/chain_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
// SPDX-License-Identifier: Apache-2.0, MIT

use crate::blocks::{Tipset, TipsetKeys};
use crate::lotus_json::LotusJson;
use crate::lotus_json::{HasLotusJson, LotusJson};
use crate::message::ChainMessage;
use crate::rpc_client::{ApiInfo, JsonRpcError};
use anyhow::bail;
use cid::Cid;
Expand Down Expand Up @@ -61,7 +62,14 @@ impl ChainCommands {
Self::Genesis => print_pretty_json(LotusJson(api.chain_get_genesis().await?)),
Self::Head => print_rpc_res_cids(api.chain_head().await?),
Self::Message { cid } => {
print_pretty_json(LotusJson(api.chain_get_message(cid).await?))
let bytes = api.chain_read_obj(cid).await?;
match fvm_ipld_encoding::from_slice::<ChainMessage>(&bytes)? {
ChainMessage::Unsigned(m) => print_pretty_json(LotusJson(m)),
ChainMessage::Signed(m) => {
let cid = m.cid()?;
print_pretty_json(m.into_lotus_json().with_cid(cid))
}
}
}
Self::ReadObj { cid } => {
println!("{}", hex::encode(api.chain_read_obj(cid).await?));
Expand Down
7 changes: 7 additions & 0 deletions src/lotus_json/signed_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ pub struct SignedMessageLotusJson {
cid: LotusJson<Option<Cid>>,
}

impl SignedMessageLotusJson {
pub fn with_cid(mut self, cid: Cid) -> Self {
self.cid = LotusJson(Some(cid));
self
}
}

impl HasLotusJson for SignedMessage {
type LotusJson = SignedMessageLotusJson;

Expand Down
1 change: 1 addition & 0 deletions src/rpc_client/chain_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ impl ApiInfo {
RpcRequest::new(CHAIN_EXPORT, params)
}

#[allow(dead_code)]
pub async fn chain_get_message(&self, cid: Cid) -> Result<Message, JsonRpcError> {
self.call(Self::chain_get_message_req(cid)).await
}
Expand Down

0 comments on commit 7286a85

Please sign in to comment.