From 7286a85c42ba96d177d49942a57de8cbe572c443 Mon Sep 17 00:00:00 2001 From: hanabi1224 Date: Fri, 10 Nov 2023 22:38:05 +0800 Subject: [PATCH] fix: align forest-cli chain message output with lotus (#3709) --- src/cli/subcommands/chain_cmd.rs | 12 ++++++++++-- src/lotus_json/signed_message.rs | 7 +++++++ src/rpc_client/chain_ops.rs | 1 + 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/cli/subcommands/chain_cmd.rs b/src/cli/subcommands/chain_cmd.rs index 37de1c64463..5aa65df7512 100644 --- a/src/cli/subcommands/chain_cmd.rs +++ b/src/cli/subcommands/chain_cmd.rs @@ -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; @@ -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::(&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?)); diff --git a/src/lotus_json/signed_message.rs b/src/lotus_json/signed_message.rs index fac3b5a34b9..e0de1d633c0 100644 --- a/src/lotus_json/signed_message.rs +++ b/src/lotus_json/signed_message.rs @@ -16,6 +16,13 @@ pub struct SignedMessageLotusJson { cid: LotusJson>, } +impl SignedMessageLotusJson { + pub fn with_cid(mut self, cid: Cid) -> Self { + self.cid = LotusJson(Some(cid)); + self + } +} + impl HasLotusJson for SignedMessage { type LotusJson = SignedMessageLotusJson; diff --git a/src/rpc_client/chain_ops.rs b/src/rpc_client/chain_ops.rs index 3c9339773ad..ffc132fe801 100644 --- a/src/rpc_client/chain_ops.rs +++ b/src/rpc_client/chain_ops.rs @@ -84,6 +84,7 @@ impl ApiInfo { RpcRequest::new(CHAIN_EXPORT, params) } + #[allow(dead_code)] pub async fn chain_get_message(&self, cid: Cid) -> Result { self.call(Self::chain_get_message_req(cid)).await }