diff --git a/src/blocks/tipset.rs b/src/blocks/tipset.rs index b7bd7cc876e5..e2afee00a12a 100644 --- a/src/blocks/tipset.rs +++ b/src/blocks/tipset.rs @@ -513,6 +513,7 @@ mod lotus_json { use super::TipsetKey; + #[derive(Clone)] pub struct TipsetLotusJson(Tipset); impl JsonSchema for TipsetLotusJson { diff --git a/src/cli/subcommands/attach_cmd.rs b/src/cli/subcommands/attach_cmd.rs index 0a6dd38c09a9..8087f059d3df 100644 --- a/src/cli/subcommands/attach_cmd.rs +++ b/src/cli/subcommands/attach_cmd.rs @@ -279,11 +279,7 @@ mod inner { Address::from_str(&to)?, humantoken::parse(&value)?, // Convert forest_shim::TokenAmount to TokenAmount3 ); - Ok( - MpoolPushMessage::call(&rpc::Client::from(api), (message.into(), None)) - .await? - .into_inner(), - ) + Ok(MpoolPushMessage::call(&rpc::Client::from(api), (message.into(), None)).await?) } type SleepParams = (u64,); @@ -300,14 +296,14 @@ mod inner { let mut epoch = None; loop { let state = SyncState::call(&client, ()).await?; - if state.active_syncs.as_ref().first().stage() == SyncStage::Complete { + if state.active_syncs.first().stage() == SyncStage::Complete { if let Some(prev) = epoch { - let curr = state.active_syncs.as_ref().first().epoch(); + let curr = state.active_syncs.first().epoch(); if (curr - prev) >= epochs { return Ok(()); } } else { - epoch = Some(state.active_syncs.as_ref().first().epoch()); + epoch = Some(state.active_syncs.first().epoch()); } } time::sleep(time::Duration::from_secs(1)).await; diff --git a/src/cli/subcommands/auth_cmd.rs b/src/cli/subcommands/auth_cmd.rs index c095ffd66206..3c8f12139f96 100644 --- a/src/cli/subcommands/auth_cmd.rs +++ b/src/cli/subcommands/auth_cmd.rs @@ -55,18 +55,14 @@ impl AuthCommands { let perm: String = perm.parse()?; let perms = process_perms(perm)?; let token_exp = Duration::from_std(expire_in.into())?; - let res = AuthNew::call(&client, (AuthNewParams { perms, token_exp },)) - .await? - .into_inner(); + let res = AuthNew::call(&client, (AuthNewParams { perms, token_exp },)).await?; print_rpc_res_bytes(res) } Self::ApiInfo { perm, expire_in } => { let perm: String = perm.parse()?; let perms = process_perms(perm)?; let token_exp = Duration::from_std(expire_in.into())?; - let token = AuthNew::call(&client, (AuthNewParams { perms, token_exp },)) - .await? - .into_inner(); + let token = AuthNew::call(&client, (AuthNewParams { perms, token_exp },)).await?; let new_api = api.set_token(Some(String::from_utf8(token)?)); println!("FULLNODE_API_INFO=\"{}\"", new_api); Ok(()) diff --git a/src/cli/subcommands/chain_cmd.rs b/src/cli/subcommands/chain_cmd.rs index e46bbd554994..7d46925af58f 100644 --- a/src/cli/subcommands/chain_cmd.rs +++ b/src/cli/subcommands/chain_cmd.rs @@ -62,12 +62,10 @@ impl ChainCommands { Self::Block { cid } => { print_pretty_json(ChainGetBlock::call(&client, (cid.into(),)).await?) } - Self::Genesis => print_pretty_json(ChainGetGenesis::call(&client, ()).await?), - Self::Head => print_rpc_res_cids(ChainHead::call(&client, ()).await?.into_inner()), + Self::Genesis => print_pretty_json(ChainGetGenesis::call_raw(&client, ()).await?), + Self::Head => print_rpc_res_cids(ChainHead::call(&client, ()).await?), Self::Message { cid } => { - let bytes = ChainReadObj::call(&client, (cid.into(),)) - .await? - .into_inner(); + let bytes = ChainReadObj::call(&client, (cid.into(),)).await?; match fvm_ipld_encoding::from_slice::(&bytes)? { ChainMessage::Unsigned(m) => print_pretty_json(LotusJson(m)), ChainMessage::Signed(m) => { @@ -77,9 +75,7 @@ impl ChainCommands { } } Self::ReadObj { cid } => { - let bytes = ChainReadObj::call(&client, (cid.into(),)) - .await? - .into_inner(); + let bytes = ChainReadObj::call(&client, (cid.into(),)).await?; println!("{}", hex::encode(bytes)); Ok(()) } @@ -122,18 +118,17 @@ async fn tipset_by_epoch_or_offset( client: &rpc::Client, epoch_or_offset: i64, ) -> Result { - let current_head = ChainHead::call(client, ()).await?.into_inner(); + let current_head = ChainHead::call(client, ()).await?; let target_epoch = match epoch_or_offset.is_negative() { true => current_head.epoch() + epoch_or_offset, // adding negative number false => epoch_or_offset, }; - Ok(ChainGetTipSetByHeight::call( + ChainGetTipSetByHeight::call( client, (target_epoch, LotusJson(current_head.key().clone().into())), ) - .await? - .into_inner()) + .await } const SET_HEAD_CONFIRMATION_MESSAGE: &str = diff --git a/src/cli/subcommands/info_cmd.rs b/src/cli/subcommands/info_cmd.rs index 39075429d5de..b8ce13f77d31 100644 --- a/src/cli/subcommands/info_cmd.rs +++ b/src/cli/subcommands/info_cmd.rs @@ -159,16 +159,13 @@ impl InfoCommand { StartTime::call(&client, ()), WalletDefaultAddress::call(&client, ()), )?; - let default_wallet_address = default_wallet_address.into_inner(); let cur_duration: Duration = SystemTime::now().duration_since(UNIX_EPOCH)?; let blocks_per_tipset_last_finality = node_status.chain_status.blocks_per_tipset_last_finality; let default_wallet_address_balance = if let Some(def_addr) = default_wallet_address { - let balance = WalletBalance::call(&client, (def_addr.into(),)) - .await? - .into_inner(); + let balance = WalletBalance::call(&client, (def_addr.into(),)).await?; Some(balance) } else { None @@ -177,7 +174,7 @@ impl InfoCommand { let node_status_info = NodeStatusInfo::new( cur_duration, blocks_per_tipset_last_finality, - &head.into_inner(), + &head, start_time, network, default_wallet_address, diff --git a/src/cli/subcommands/mpool_cmd.rs b/src/cli/subcommands/mpool_cmd.rs index efa5fd448531..2dcefcc766b6 100644 --- a/src/cli/subcommands/mpool_cmd.rs +++ b/src/cli/subcommands/mpool_cmd.rs @@ -214,12 +214,11 @@ impl MpoolCommands { to, from, } => { - let messages = MpoolPending::call(&client, (LotusJson(ApiTipsetKey(None)),)) - .await? - .into_inner(); + let messages = + MpoolPending::call(&client, (LotusJson(ApiTipsetKey(None)),)).await?; let local_addrs = if local { - let response = WalletList::call(&client, ()).await?.into_inner(); + let response = WalletList::call(&client, ()).await?; Some(HashSet::from_iter(response)) } else { None @@ -244,18 +243,17 @@ impl MpoolCommands { basefee_lookback, local, } => { - let tipset = ChainHead::call(&client, ()).await?.into_inner(); + let tipset = ChainHead::call(&client, ()).await?; let curr_base_fee = tipset.block_headers().first().parent_base_fee.to_owned(); let atto_str = ChainGetMinBaseFee::call(&client, (basefee_lookback,)).await?; let min_base_fee = TokenAmount::from_atto(atto_str.parse::()?); - let messages = MpoolPending::call(&client, (LotusJson(ApiTipsetKey(None)),)) - .await? - .into_inner(); + let messages = + MpoolPending::call(&client, (LotusJson(ApiTipsetKey(None)),)).await?; let local_addrs = if local { - let response = WalletList::call(&client, ()).await?.into_inner(); + let response = WalletList::call(&client, ()).await?; Some(HashSet::from_iter(response)) } else { None diff --git a/src/cli/subcommands/send_cmd.rs b/src/cli/subcommands/send_cmd.rs index 7347e6d35290..7804642feae8 100644 --- a/src/cli/subcommands/send_cmd.rs +++ b/src/cli/subcommands/send_cmd.rs @@ -42,7 +42,6 @@ impl SendCommand { } else { WalletDefaultAddress::call(&client, ()) .await? - .into_inner() .context("No default wallet address selected. Please set a default address.")? }; @@ -58,9 +57,7 @@ impl SendCommand { ..Default::default() }; - let signed_msg = MpoolPushMessage::call(&client, (message.into(), None)) - .await? - .into_inner(); + let signed_msg = MpoolPushMessage::call(&client, (message.into(), None)).await?; println!("{}", signed_msg.cid().unwrap()); diff --git a/src/cli/subcommands/snapshot_cmd.rs b/src/cli/subcommands/snapshot_cmd.rs index 55fbdb80f161..756874eb2125 100644 --- a/src/cli/subcommands/snapshot_cmd.rs +++ b/src/cli/subcommands/snapshot_cmd.rs @@ -49,16 +49,15 @@ impl SnapshotCommands { tipset, depth, } => { - let chain_head = ChainHead::call(&client, ()).await?.into_inner(); + let chain_head = ChainHead::call(&client, ()).await?; let epoch = tipset.unwrap_or(chain_head.epoch()); let raw_network_name = api.state_network_name().await?; let chain_name = crate::daemon::get_actual_chain_name(&raw_network_name); - let tipset = ChainGetTipSetByHeight::call(&client, (epoch, Default::default())) - .await? - .into_inner(); + let tipset = + ChainGetTipSetByHeight::call(&client, (epoch, Default::default())).await?; let output_path = match output_path.is_dir() { true => output_path.join(snapshot::filename( diff --git a/src/cli/subcommands/sync_cmd.rs b/src/cli/subcommands/sync_cmd.rs index d8f52e5fcc3c..9981a8733863 100644 --- a/src/cli/subcommands/sync_cmd.rs +++ b/src/cli/subcommands/sync_cmd.rs @@ -48,7 +48,7 @@ impl SyncCommands { for _ in ticker { let resp = SyncState::call(&client, ()).await?; - let active_syncs = resp.active_syncs.as_ref(); + let active_syncs = resp.active_syncs; let state = active_syncs .iter() .rev() @@ -99,7 +99,7 @@ impl SyncCommands { } Self::Status => { let resp = SyncState::call(&client, ()).await?; - let state = resp.active_syncs.as_ref().first(); + let state = resp.active_syncs.first(); let base = state.base(); let elapsed_time = state.get_elapsed_time(); diff --git a/src/lotus_json/beacon_entry.rs b/src/lotus_json/beacon_entry.rs index 113fc6d75e31..0aba231f53af 100644 --- a/src/lotus_json/beacon_entry.rs +++ b/src/lotus_json/beacon_entry.rs @@ -5,7 +5,7 @@ use crate::beacon::BeaconEntry; use super::*; -#[derive(Serialize, Deserialize, JsonSchema)] +#[derive(Clone, Serialize, Deserialize, JsonSchema)] #[serde(rename_all = "PascalCase")] pub struct BeaconEntryLotusJson { round: LotusJson, diff --git a/src/lotus_json/block_header.rs b/src/lotus_json/block_header.rs index fbaff998f8ee..64f068ac8fd9 100644 --- a/src/lotus_json/block_header.rs +++ b/src/lotus_json/block_header.rs @@ -16,7 +16,7 @@ use serde::{Deserialize, Serialize}; use crate::blocks::{CachingBlockHeader, RawBlockHeader}; -#[derive(Serialize, Deserialize, JsonSchema)] +#[derive(Clone, Serialize, Deserialize, JsonSchema)] #[serde(rename_all = "PascalCase")] pub struct BlockHeaderLotusJson { miner: LotusJson
, diff --git a/src/lotus_json/cid.rs b/src/lotus_json/cid.rs index 3acd2d908596..31e6aa241ada 100644 --- a/src/lotus_json/cid.rs +++ b/src/lotus_json/cid.rs @@ -3,7 +3,7 @@ use super::*; -#[derive(Serialize, Deserialize, JsonSchema)] +#[derive(Clone, Serialize, Deserialize, JsonSchema)] pub struct CidLotusJsonGeneric { #[serde(rename = "/")] slash: Stringify<::cid::CidGeneric>, diff --git a/src/lotus_json/key_info.rs b/src/lotus_json/key_info.rs index b9e193181a90..d343a0d3026d 100644 --- a/src/lotus_json/key_info.rs +++ b/src/lotus_json/key_info.rs @@ -4,7 +4,7 @@ use super::*; use crate::{key_management::KeyInfo, shim::crypto::SignatureType}; -#[derive(Serialize, Deserialize, JsonSchema)] +#[derive(Clone, Serialize, Deserialize, JsonSchema)] #[serde(rename_all = "PascalCase")] pub struct KeyInfoLotusJson { r#type: LotusJson, diff --git a/src/lotus_json/message.rs b/src/lotus_json/message.rs index f62e9ba040b1..c95e8488006e 100644 --- a/src/lotus_json/message.rs +++ b/src/lotus_json/message.rs @@ -7,7 +7,7 @@ use crate::shim::{address::Address, econ::TokenAmount, message::Message}; use ::cid::Cid; use fvm_ipld_encoding::RawBytes; -#[derive(Serialize, Deserialize, JsonSchema)] +#[derive(Clone, Serialize, Deserialize, JsonSchema)] #[serde(rename_all = "PascalCase")] pub struct MessageLotusJson { version: LotusJson, diff --git a/src/lotus_json/mod.rs b/src/lotus_json/mod.rs index 45bbe3876170..d277fcd6324c 100644 --- a/src/lotus_json/mod.rs +++ b/src/lotus_json/mod.rs @@ -132,6 +132,7 @@ use serde::{de::DeserializeOwned, Deserialize, Deserializer, Serialize, Serializ #[cfg(test)] use serde_json::json; use std::{fmt::Display, str::FromStr}; +use uuid::Uuid; #[cfg(test)] use {pretty_assertions::assert_eq, quickcheck::quickcheck}; @@ -416,9 +417,6 @@ impl LotusJson { pub fn into_inner(self) -> T { self.0 } - pub fn as_ref(&self) -> &T { - &self.0 - } } impl LotusJson> { @@ -449,6 +447,12 @@ impl JsonSchema for Stringify { } } +impl Clone for Stringify { + fn clone(&self) -> Self { + Self(self.0.clone()) + } +} + macro_rules! lotus_json_with_self { ($($domain_ty:ty),* $(,)?) => { $( @@ -482,6 +486,7 @@ lotus_json_with_self!( bool, DeadlineInfo, PaddedPieceSize, + Uuid, ); #[derive(Default, Debug, Serialize, Deserialize)] diff --git a/src/lotus_json/signature.rs b/src/lotus_json/signature.rs index bb70c874e4a8..137958dcf1c6 100644 --- a/src/lotus_json/signature.rs +++ b/src/lotus_json/signature.rs @@ -4,7 +4,7 @@ use super::*; use crate::shim::crypto::{Signature, SignatureType}; -#[derive(Serialize, Deserialize, JsonSchema)] +#[derive(Clone, Serialize, Deserialize, JsonSchema)] #[serde(rename_all = "PascalCase")] pub struct SignatureLotusJson { r#type: LotusJson, diff --git a/src/lotus_json/signed_message.rs b/src/lotus_json/signed_message.rs index a9261172893a..81722b0ee581 100644 --- a/src/lotus_json/signed_message.rs +++ b/src/lotus_json/signed_message.rs @@ -7,7 +7,7 @@ use ::cid::Cid; use super::*; -#[derive(Serialize, Deserialize, JsonSchema)] +#[derive(Clone, Serialize, Deserialize, JsonSchema)] #[serde(rename_all = "PascalCase")] pub struct SignedMessageLotusJson { message: LotusJson, diff --git a/src/lotus_json/token_amount.rs b/src/lotus_json/token_amount.rs index 91de4f7308f3..096e269d8e76 100644 --- a/src/lotus_json/token_amount.rs +++ b/src/lotus_json/token_amount.rs @@ -5,7 +5,7 @@ use super::*; use crate::shim::econ::TokenAmount; use num::BigInt; -#[derive(Serialize, Deserialize, JsonSchema)] +#[derive(Clone, Serialize, Deserialize, JsonSchema)] #[serde(transparent)] // name the field for clarity pub struct TokenAmountLotusJson { attos: LotusJson, diff --git a/src/lotus_json/vec.rs b/src/lotus_json/vec.rs index 30f7ef7fb40c..90762c4e9756 100644 --- a/src/lotus_json/vec.rs +++ b/src/lotus_json/vec.rs @@ -29,6 +29,12 @@ where } } +impl Clone for VecLotusJson { + fn clone(&self) -> Self { + Self(self.0.clone()) + } +} + #[test] fn shapshots() { assert_one_snapshot(json!([{"/": "baeaaaaa"}]), vec![::cid::Cid::default()]); diff --git a/src/lotus_json/vec_u8.rs b/src/lotus_json/vec_u8.rs index 2af7e68cc371..e18760997c78 100644 --- a/src/lotus_json/vec_u8.rs +++ b/src/lotus_json/vec_u8.rs @@ -6,10 +6,10 @@ use super::*; // This code looks odd so we can // - use #[serde(with = "...")] // - de/ser empty vecs as null -#[derive(Serialize, Deserialize, JsonSchema)] +#[derive(Clone, Serialize, Deserialize, JsonSchema)] pub struct VecU8LotusJson(Option); -#[derive(Serialize, Deserialize)] +#[derive(Clone, Serialize, Deserialize)] struct Inner(#[serde(with = "base64_standard")] Vec); impl JsonSchema for Inner { diff --git a/src/rpc/methods/auth.rs b/src/rpc/methods/auth.rs index 525b25c49572..6b51e3795103 100644 --- a/src/rpc/methods/auth.rs +++ b/src/rpc/methods/auth.rs @@ -2,7 +2,6 @@ // SPDX-License-Identifier: Apache-2.0, MIT use crate::auth::*; -use crate::lotus_json::LotusJson; use crate::rpc::{ApiVersion, Ctx, RpcMethod, ServerError}; use anyhow::Result; use chrono::Duration; @@ -26,7 +25,7 @@ impl RpcMethod<1> for AuthNew { const PARAM_NAMES: [&'static str; 1] = ["params"]; const API_VERSION: ApiVersion = ApiVersion::V0; type Params = (AuthNewParams,); - type Ok = LotusJson>; + type Ok = Vec; async fn handle( ctx: Ctx, (params,): Self::Params, @@ -34,7 +33,7 @@ impl RpcMethod<1> for AuthNew { let ks = ctx.keystore.read().await; let ki = ks.get(JWT_IDENTIFIER)?; let token = create_token(params.perms, ki.private_key(), params.token_exp)?; - Ok(LotusJson(token.as_bytes().to_vec())) + Ok(token.as_bytes().to_vec()) } } diff --git a/src/rpc/methods/beacon.rs b/src/rpc/methods/beacon.rs index fe3043d20aa3..ba099c166040 100644 --- a/src/rpc/methods/beacon.rs +++ b/src/rpc/methods/beacon.rs @@ -2,7 +2,7 @@ // SPDX-License-Identifier: Apache-2.0, MIT use crate::rpc::{ApiVersion, Ctx, RpcMethod, ServerError}; -use crate::{beacon::BeaconEntry, lotus_json::LotusJson, shim::clock::ChainEpoch}; +use crate::{beacon::BeaconEntry, shim::clock::ChainEpoch}; use anyhow::Result; use fvm_ipld_blockstore::Blockstore; @@ -23,7 +23,7 @@ impl RpcMethod<1> for BeaconGetEntry { const API_VERSION: ApiVersion = ApiVersion::V0; type Params = (ChainEpoch,); - type Ok = LotusJson; + type Ok = BeaconEntry; async fn handle( ctx: Ctx, @@ -33,6 +33,6 @@ impl RpcMethod<1> for BeaconGetEntry { let rr = beacon.max_beacon_round_for_epoch(ctx.state_manager.get_network_version(first), first); let e = beacon.entry(rr).await?; - Ok(e.into()) + Ok(e) } } diff --git a/src/rpc/methods/chain.rs b/src/rpc/methods/chain.rs index 23c81262e778..41a5916afe72 100644 --- a/src/rpc/methods/chain.rs +++ b/src/rpc/methods/chain.rs @@ -7,10 +7,9 @@ use crate::blocks::{CachingBlockHeader, Tipset, TipsetKey}; use crate::chain::index::ResolveNullTipset; use crate::chain::{ChainStore, HeadChange}; use crate::cid_collections::CidHashSet; -use crate::lotus_json::HasLotusJson; -use crate::lotus_json::LotusJson; #[cfg(test)] use crate::lotus_json::{assert_all_snapshots, assert_unchanged_via_json}; +use crate::lotus_json::{lotus_json_with_self, HasLotusJson, LotusJson}; use crate::message::{ChainMessage, SignedMessage}; use crate::rpc::types::ApiTipsetKey; use crate::rpc::{ApiVersion, Ctx, RpcMethod, ServerError}; @@ -69,7 +68,7 @@ impl RpcMethod<1> for ChainGetMessage { const API_VERSION: ApiVersion = ApiVersion::V0; type Params = (LotusJson,); - type Ok = LotusJson; + type Ok = Message; async fn handle( ctx: Ctx, @@ -80,10 +79,10 @@ impl RpcMethod<1> for ChainGetMessage { .blockstore() .get_cbor(&msg_cid)? .with_context(|| format!("can't find message with cid {msg_cid}"))?; - Ok(LotusJson(match chain_message { + Ok(match chain_message { ChainMessage::Signed(m) => m.into_message(), ChainMessage::Unsigned(m) => m, - })) + }) } } @@ -108,8 +107,7 @@ impl RpcMethod<1> for ChainGetParentMessages { Ok(vec![]) } else { let parent_tipset = Tipset::load_required(store, &block_header.parents)?; - let messages = load_api_messages_from_tipset(store, &parent_tipset)?; - Ok(messages) + load_api_messages_from_tipset(store, &parent_tipset) } } } @@ -205,8 +203,7 @@ impl RpcMethod<1> for ChainGetMessagesInTipset { ) -> Result { let store = ctx.chain_store.blockstore(); let tipset = Tipset::load_required(store, &tsk)?; - let messages = load_api_messages_from_tipset(store, &tipset)?; - Ok(messages) + load_api_messages_from_tipset(store, &tipset) } } @@ -289,7 +286,7 @@ impl RpcMethod<1> for ChainReadObj { const API_VERSION: ApiVersion = ApiVersion::V0; type Params = (LotusJson,); - type Ok = LotusJson>; + type Ok = Vec; async fn handle( ctx: Ctx, @@ -300,7 +297,7 @@ impl RpcMethod<1> for ChainReadObj { .blockstore() .get(&cid)? .with_context(|| format!("can't find object with cid={cid}"))?; - Ok(LotusJson(bytes)) + Ok(bytes) } } @@ -365,15 +362,13 @@ impl RpcMethod<2> for ChainGetPath { const API_VERSION: ApiVersion = ApiVersion::V0; type Params = (LotusJson, LotusJson); - type Ok = LotusJson>; + type Ok = Vec; async fn handle( ctx: Ctx, (LotusJson(from), LotusJson(to)): Self::Params, ) -> Result { - impl_chain_get_path(&ctx.chain_store, &from, &to) - .map(LotusJson) - .map_err(Into::into) + impl_chain_get_path(&ctx.chain_store, &from, &to).map_err(Into::into) } } @@ -443,7 +438,7 @@ impl RpcMethod<2> for ChainGetTipSetByHeight { const API_VERSION: ApiVersion = ApiVersion::V0; type Params = (ChainEpoch, LotusJson); - type Ok = LotusJson; + type Ok = Tipset; async fn handle( ctx: Ctx, @@ -458,7 +453,7 @@ impl RpcMethod<2> for ChainGetTipSetByHeight { .chain_store() .chain_index .tipset_by_height(height, ts, ResolveNullTipset::TakeOlder)?; - Ok((*tss).clone().into()) + Ok((*tss).clone()) } } @@ -469,7 +464,7 @@ impl RpcMethod<2> for ChainGetTipSetAfterHeight { const API_VERSION: ApiVersion = ApiVersion::V1; type Params = (ChainEpoch, LotusJson); - type Ok = LotusJson; + type Ok = Tipset; async fn handle( ctx: Ctx, @@ -484,7 +479,7 @@ impl RpcMethod<2> for ChainGetTipSetAfterHeight { .chain_store() .chain_index .tipset_by_height(height, ts, ResolveNullTipset::TakeNewer)?; - Ok((*tss).clone().into()) + Ok((*tss).clone()) } } @@ -495,11 +490,11 @@ impl RpcMethod<0> for ChainGetGenesis { const API_VERSION: ApiVersion = ApiVersion::V0; type Params = (); - type Ok = Option>; + type Ok = Option; async fn handle(ctx: Ctx, (): Self::Params) -> Result { let genesis = ctx.state_manager.chain_store().genesis_block_header(); - Ok(Some(Tipset::from(genesis).into())) + Ok(Some(Tipset::from(genesis))) } } @@ -510,11 +505,11 @@ impl RpcMethod<0> for ChainHead { const API_VERSION: ApiVersion = ApiVersion::V0; type Params = (); - type Ok = LotusJson; + type Ok = Tipset; async fn handle(ctx: Ctx, (): Self::Params) -> Result { let heaviest = ctx.state_manager.chain_store().heaviest_tipset(); - Ok((*heaviest).clone().into()) + Ok((*heaviest).clone()) } } @@ -525,7 +520,7 @@ impl RpcMethod<1> for ChainGetBlock { const API_VERSION: ApiVersion = ApiVersion::V0; type Params = (LotusJson,); - type Ok = LotusJson; + type Ok = CachingBlockHeader; async fn handle( ctx: Ctx, @@ -536,7 +531,7 @@ impl RpcMethod<1> for ChainGetBlock { .blockstore() .get_cbor(&cid)? .context("can't find BlockHeader with that cid")?; - Ok(blk.into()) + Ok(blk) } } @@ -547,7 +542,7 @@ impl RpcMethod<1> for ChainGetTipSet { const API_VERSION: ApiVersion = ApiVersion::V0; type Params = (LotusJson,); - type Ok = LotusJson; + type Ok = Tipset; async fn handle( ctx: Ctx, @@ -557,7 +552,7 @@ impl RpcMethod<1> for ChainGetTipSet { .state_manager .chain_store() .load_required_tipset_or_heaviest(&tsk)?; - Ok((*ts).clone().into()) + Ok((*ts).clone()) } } @@ -641,7 +636,7 @@ impl RpcMethod<1> for ChainTipSetWeight { const API_VERSION: ApiVersion = ApiVersion::V0; type Params = (LotusJson,); - type Ok = LotusJson; + type Ok = BigInt; async fn handle( ctx: Ctx, @@ -649,7 +644,7 @@ impl RpcMethod<1> for ChainTipSetWeight { ) -> Result { let tsk = ctx.chain_store.load_required_tipset_or_heaviest(&tsk)?; let weight = crate::fil_cns::weight(ctx.chain_store.blockstore(), &tsk)?; - Ok(LotusJson(weight)) + Ok(weight) } } @@ -733,6 +728,7 @@ pub struct BlockMessages { #[schemars(with = "LotusJson>")] pub cids: Vec, } +lotus_json_with_self!(BlockMessages); #[derive(Debug, Clone, Serialize, Deserialize, Eq, PartialEq, JsonSchema)] #[serde(rename_all = "PascalCase")] @@ -750,6 +746,8 @@ pub struct ApiReceipt { pub events_root: Option, } +lotus_json_with_self!(ApiReceipt); + #[derive(Serialize, Deserialize, JsonSchema, Clone, Debug, Eq, PartialEq)] #[serde(rename_all = "PascalCase")] pub struct ApiMessage { @@ -761,6 +759,8 @@ pub struct ApiMessage { pub message: Message, } +lotus_json_with_self!(ApiMessage); + #[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)] pub struct ChainExportParams { pub epoch: ChainEpoch, diff --git a/src/rpc/methods/common.rs b/src/rpc/methods/common.rs index 6bfd6f2cf176..c88ad1cb81b1 100644 --- a/src/rpc/methods/common.rs +++ b/src/rpc/methods/common.rs @@ -1,6 +1,7 @@ // Copyright 2019-2024 ChainSafe Systems // SPDX-License-Identifier: Apache-2.0, MIT +use crate::lotus_json::lotus_json_with_self; use crate::rpc::error::ServerError; use crate::rpc::{ApiVersion, Ctx, RpcMethod}; use fvm_ipld_blockstore::Blockstore; @@ -94,6 +95,7 @@ pub struct PublicVersion { pub api_version: ShiftingVersion, pub block_delay: u32, } +lotus_json_with_self!(PublicVersion); /// Integer based value on version information. Highest order bits for Major, /// Mid order for Minor and lowest for Patch. diff --git a/src/rpc/methods/eth.rs b/src/rpc/methods/eth.rs index 5356f45a567b..da597fea5b0e 100644 --- a/src/rpc/methods/eth.rs +++ b/src/rpc/methods/eth.rs @@ -325,7 +325,6 @@ pub async fn eth_syncing( let crate::rpc::sync::RPCSyncState { active_syncs } = crate::rpc::sync::SyncState::handle(data.clone(), ()).await?; match active_syncs - .into_inner() .into_iter() .rev() .find_or_first(|ss| ss.stage() != SyncStage::Idle) diff --git a/src/rpc/methods/mpool.rs b/src/rpc/methods/mpool.rs index 3a1cb4d726a7..5553074281ca 100644 --- a/src/rpc/methods/mpool.rs +++ b/src/rpc/methods/mpool.rs @@ -53,7 +53,7 @@ impl RpcMethod<1> for MpoolPending { const API_VERSION: ApiVersion = ApiVersion::V0; type Params = (LotusJson,); - type Ok = LotusJson>; + type Ok = Vec; async fn handle( ctx: Ctx, @@ -72,7 +72,7 @@ impl RpcMethod<1> for MpoolPending { } if mpts.epoch() > ts.epoch() { - return Ok(pending.into_iter().collect::>().into()); + return Ok(pending.into_iter().collect::>()); } loop { @@ -116,7 +116,7 @@ impl RpcMethod<1> for MpoolPending { .chain_index .load_required_tipset(ts.parents())?; } - Ok(pending.into_iter().collect::>().into()) + Ok(pending.into_iter().collect::>()) } } @@ -128,7 +128,7 @@ impl RpcMethod<2> for MpoolSelect { const API_VERSION: ApiVersion = ApiVersion::V0; type Params = (LotusJson, f64); - type Ok = LotusJson>; + type Ok = Vec; async fn handle( ctx: Ctx, @@ -139,7 +139,7 @@ impl RpcMethod<2> for MpoolSelect { .chain_store() .load_required_tipset_or_heaviest(&tsk)?; - Ok(LotusJson(ctx.mpool.select_messages(&ts, tq)?)) + Ok(ctx.mpool.select_messages(&ts, tq)?) } } @@ -151,14 +151,14 @@ impl RpcMethod<1> for MpoolPush { const API_VERSION: ApiVersion = ApiVersion::V0; type Params = (LotusJson,); - type Ok = LotusJson; + type Ok = Cid; async fn handle( ctx: Ctx, (LotusJson(msg),): Self::Params, ) -> Result { let cid = ctx.mpool.as_ref().push(msg).await?; - Ok(cid.into()) + Ok(cid) } } @@ -170,7 +170,7 @@ impl RpcMethod<2> for MpoolPushMessage { const API_VERSION: ApiVersion = ApiVersion::V0; type Params = (LotusJson, Option); - type Ok = LotusJson; + type Ok = SignedMessage; async fn handle( ctx: Ctx, @@ -218,6 +218,6 @@ impl RpcMethod<2> for MpoolPushMessage { ctx.mpool.as_ref().push(smsg.clone()).await?; - Ok(smsg.into()) + Ok(smsg) } } diff --git a/src/rpc/methods/net.rs b/src/rpc/methods/net.rs index 3ff01f05b803..35c0840049de 100644 --- a/src/rpc/methods/net.rs +++ b/src/rpc/methods/net.rs @@ -5,6 +5,7 @@ use std::any::Any; use std::str::FromStr; use crate::libp2p::{NetRPCMethods, NetworkMessage, PeerId}; +use crate::lotus_json::lotus_json_with_self; use crate::rpc::{ApiVersion, ServerError}; use crate::rpc::{Ctx, RpcMethod}; use anyhow::Result; @@ -251,6 +252,8 @@ pub struct AddrInfo { pub addrs: ahash::HashSet, } +lotus_json_with_self!(AddrInfo); + #[derive(Debug, Default, Serialize, Deserialize, Clone, JsonSchema)] pub struct NetInfoResult { pub num_peers: usize, @@ -260,6 +263,7 @@ pub struct NetInfoResult { pub num_pending_outgoing: u32, pub num_established: u32, } +lotus_json_with_self!(NetInfoResult); impl From for NetInfoResult { fn from(i: libp2p::swarm::NetworkInfo) -> Self { @@ -281,6 +285,7 @@ pub struct NatStatusResult { pub reachability: i32, pub public_addrs: Option>, } +lotus_json_with_self!(NatStatusResult); impl NatStatusResult { // See diff --git a/src/rpc/methods/node.rs b/src/rpc/methods/node.rs index 892559f30272..d7e2db92aa7f 100644 --- a/src/rpc/methods/node.rs +++ b/src/rpc/methods/node.rs @@ -3,7 +3,10 @@ use std::time::{Duration, SystemTime, UNIX_EPOCH}; -use crate::rpc::{ApiVersion, Ctx, RpcMethod, ServerError}; +use crate::{ + lotus_json::lotus_json_with_self, + rpc::{ApiVersion, Ctx, RpcMethod, ServerError}, +}; use fvm_ipld_blockstore::Blockstore; use schemars::JsonSchema; use serde::{Deserialize, Serialize}; @@ -77,18 +80,21 @@ pub struct NodeSyncStatus { pub epoch: u64, pub behind: u64, } +lotus_json_with_self!(NodeSyncStatus); #[derive(Debug, Serialize, Deserialize, Default, Clone, JsonSchema)] pub struct NodePeerStatus { pub peers_to_publish_msgs: u32, pub peers_to_publish_blocks: u32, } +lotus_json_with_self!(NodePeerStatus); #[derive(Debug, Serialize, Deserialize, Default, Clone, JsonSchema)] pub struct NodeChainStatus { pub blocks_per_tipset_last_100: f64, pub blocks_per_tipset_last_finality: f64, } +lotus_json_with_self!(NodeChainStatus); #[derive(Debug, Deserialize, Default, Serialize, Clone, JsonSchema)] pub struct NodeStatusResult { @@ -96,3 +102,4 @@ pub struct NodeStatusResult { pub peer_status: NodePeerStatus, pub chain_status: NodeChainStatus, } +lotus_json_with_self!(NodeStatusResult); diff --git a/src/rpc/methods/state.rs b/src/rpc/methods/state.rs index 60e26445c3fe..ed514a4176eb 100644 --- a/src/rpc/methods/state.rs +++ b/src/rpc/methods/state.rs @@ -1210,7 +1210,7 @@ impl RpcMethod<1> for StateGetBeaconEntry { const API_VERSION: ApiVersion = ApiVersion::V1; type Params = (LotusJson,); - type Ok = LotusJson; + type Ok = BeaconEntry; async fn handle( ctx: Ctx, @@ -1234,7 +1234,7 @@ impl RpcMethod<1> for StateGetBeaconEntry { let network_version = ctx.state_manager.get_network_version(epoch); let round = beacon.max_beacon_round_for_epoch(network_version, epoch); let entry = beacon.entry(round).await?; - Ok(LotusJson(entry)) + Ok(entry) } } diff --git a/src/rpc/methods/sync.rs b/src/rpc/methods/sync.rs index be2d24453dbe..ff792d6f517c 100644 --- a/src/rpc/methods/sync.rs +++ b/src/rpc/methods/sync.rs @@ -1,7 +1,7 @@ // Copyright 2019-2024 ChainSafe Systems // SPDX-License-Identifier: Apache-2.0, MIT -use crate::lotus_json::LotusJson; +use crate::lotus_json::{lotus_json_with_self, LotusJson}; use crate::rpc::{ApiVersion, Ctx, RpcMethod, ServerError}; use cid::Cid; use fvm_ipld_blockstore::Blockstore; @@ -64,7 +64,7 @@ impl RpcMethod<0> for SyncState { type Ok = RPCSyncState; async fn handle(ctx: Ctx, (): Self::Params) -> Result { - let active_syncs = LotusJson(nonempty![ctx.sync_state.as_ref().read().clone()]); + let active_syncs = nonempty![ctx.sync_state.as_ref().read().clone()]; Ok(RPCSyncState { active_syncs }) } } @@ -73,8 +73,10 @@ impl RpcMethod<0> for SyncState { #[serde(rename_all = "PascalCase")] pub struct RPCSyncState { #[schemars(with = "LotusJson>")] - pub active_syncs: LotusJson>, + #[serde(with = "crate::lotus_json")] + pub active_syncs: NonEmpty, } +lotus_json_with_self!(RPCSyncState); #[cfg(test)] mod tests { @@ -205,10 +207,7 @@ mod tests { let st_copy = ctx.sync_state.clone(); let ret = SyncState::handle(ctx.clone(), ()).await.unwrap(); - assert_eq!( - ret.active_syncs, - nonempty![st_copy.as_ref().read().clone()].into() - ); + assert_eq!(ret.active_syncs, nonempty![st_copy.as_ref().read().clone()]); // update cloned state st_copy.write().set_stage(SyncStage::Messages); @@ -216,9 +215,6 @@ mod tests { let ret = SyncState::handle(ctx.clone(), ()).await.unwrap(); - assert_eq!( - ret.active_syncs, - nonempty![st_copy.as_ref().read().clone()].into() - ); + assert_eq!(ret.active_syncs, nonempty![st_copy.as_ref().read().clone()]); } } diff --git a/src/rpc/methods/wallet.rs b/src/rpc/methods/wallet.rs index 09b103eb5f7d..cda1e2a137cf 100644 --- a/src/rpc/methods/wallet.rs +++ b/src/rpc/methods/wallet.rs @@ -40,7 +40,7 @@ impl RpcMethod<1> for WalletBalance { const API_VERSION: ApiVersion = ApiVersion::V0; type Params = (LotusJson
,); - type Ok = LotusJson; + type Ok = TokenAmount; async fn handle( ctx: Ctx, @@ -49,12 +49,12 @@ impl RpcMethod<1> for WalletBalance { let heaviest_ts = ctx.state_manager.chain_store().heaviest_tipset(); let cid = heaviest_ts.parent_state(); - Ok(LotusJson( + Ok( StateTree::new_from_root(ctx.state_manager.blockstore_owned(), cid)? .get_actor(&address)? .map(|it| it.balance.clone().into()) .unwrap_or_default(), - )) + ) } } @@ -65,11 +65,11 @@ impl RpcMethod<0> for WalletDefaultAddress { const API_VERSION: ApiVersion = ApiVersion::V0; type Params = (); - type Ok = LotusJson>; + type Ok = Option
; async fn handle(ctx: Ctx, (): Self::Params) -> Result { let keystore = ctx.keystore.read().await; - Ok(LotusJson(crate::key_management::get_default(&keystore)?)) + Ok(crate::key_management::get_default(&keystore)?) } } @@ -80,16 +80,15 @@ impl RpcMethod<1> for WalletExport { const API_VERSION: ApiVersion = ApiVersion::V0; type Params = (LotusJson
,); - type Ok = LotusJson; + type Ok = KeyInfo; async fn handle( ctx: Ctx, (LotusJson(address),): Self::Params, ) -> Result { let keystore = ctx.keystore.read().await; - let key_info = crate::key_management::export_key_info(&address, &keystore)?; - Ok(key_info.into()) + Ok(key_info) } } @@ -118,7 +117,7 @@ impl RpcMethod<1> for WalletImport { const API_VERSION: ApiVersion = ApiVersion::V0; type Params = (LotusJson,); - type Ok = LotusJson
; + type Ok = Address; async fn handle( ctx: Ctx, @@ -130,7 +129,7 @@ impl RpcMethod<1> for WalletImport { let mut keystore = ctx.keystore.write().await; keystore.put(&addr, key.key_info)?; - Ok(LotusJson(key.address)) + Ok(key.address) } } @@ -141,11 +140,11 @@ impl RpcMethod<0> for WalletList { const API_VERSION: ApiVersion = ApiVersion::V0; type Params = (); - type Ok = LotusJson>; + type Ok = Vec
; async fn handle(ctx: Ctx, (): Self::Params) -> Result { let keystore = ctx.keystore.read().await; - Ok(crate::key_management::list_addrs(&keystore)?.into()) + Ok(crate::key_management::list_addrs(&keystore)?) } } @@ -156,7 +155,7 @@ impl RpcMethod<1> for WalletNew { const API_VERSION: ApiVersion = ApiVersion::V0; type Params = (LotusJson,); - type Ok = LotusJson
; + type Ok = Address; async fn handle( ctx: Ctx, @@ -172,7 +171,7 @@ impl RpcMethod<1> for WalletNew { keystore.put("default", key.key_info)? } - Ok(key.address.into()) + Ok(key.address) } } @@ -205,7 +204,7 @@ impl RpcMethod<2> for WalletSign { const API_VERSION: ApiVersion = ApiVersion::V0; type Params = (LotusJson
, LotusJson>); - type Ok = LotusJson; + type Ok = Signature; async fn handle( ctx: Ctx, @@ -231,7 +230,7 @@ impl RpcMethod<2> for WalletSign { &BASE64_STANDARD.decode(message)?, )?; - Ok(sig.into()) + Ok(sig) } } @@ -242,10 +241,10 @@ impl RpcMethod<1> for WalletValidateAddress { const API_VERSION: ApiVersion = ApiVersion::V0; type Params = (String,); - type Ok = LotusJson
; + type Ok = Address; async fn handle(_: Ctx, (s,): Self::Params) -> Result { - Ok(LotusJson(s.parse()?)) + Ok(s.parse()?) } } diff --git a/src/rpc/reflect/mod.rs b/src/rpc/reflect/mod.rs index 40461c5b1a77..600b5b90d1a1 100644 --- a/src/rpc/reflect/mod.rs +++ b/src/rpc/reflect/mod.rs @@ -24,6 +24,8 @@ pub mod openrpc_types; mod parser; mod util; +use crate::lotus_json::HasLotusJson; + use self::{jsonrpc_types::RequestParameters, util::Optional as _}; use super::error::ServerError as Error; use fvm_ipld_blockstore::Blockstore; @@ -66,7 +68,7 @@ pub trait RpcMethod { /// Types of each argument. [`Option`]-al arguments MUST follow mandatory ones. type Params: Params; /// Return value of this method. - type Ok; + type Ok: HasLotusJson; /// Logic for this method. fn handle( ctx: Ctx, @@ -115,7 +117,7 @@ pub trait RpcMethodExt: RpcMethod { calling_convention: ParamStructure, ) -> Result where - Self::Ok: JsonSchema + Deserialize<'de>, + ::LotusJson: JsonSchema + Deserialize<'de>, { Ok(Method { name: String::from(Self::NAME), @@ -131,8 +133,8 @@ pub trait RpcMethodExt: RpcMethod { param_structure: calling_convention, result: Some(ContentDescriptor { name: format!("{}::Result", Self::NAME), - schema: Self::Ok::json_schema(gen), - required: !Self::Ok::optional(), + schema: ::LotusJson::json_schema(gen), + required: !::LotusJson::optional(), }), }) } @@ -142,7 +144,7 @@ pub trait RpcMethodExt: RpcMethod { calling_convention: ParamStructure, ) -> Result<&mut jsonrpsee::MethodCallback, jsonrpsee::core::RegisterMethodError> where - Self::Ok: Serialize + Clone + 'static, + ::LotusJson: Clone + 'static, { module.register_async_method(Self::NAME, move |params, ctx| async move { let raw = params @@ -152,7 +154,7 @@ pub trait RpcMethodExt: RpcMethod { .map_err(|e| Error::invalid_params(e, None))?; let params = Self::Params::parse(raw, Self::PARAM_NAMES, calling_convention)?; let ok = Self::handle(ctx, params).await?; - Result::<_, jsonrpsee::types::ErrorObjectOwned>::Ok(ok) + Result::<_, jsonrpsee::types::ErrorObjectOwned>::Ok(ok.into_lotus_json()) }) } /// Register this method and generate a schema entry for it in a [`SelfDescribingRpcModule`]. @@ -161,8 +163,7 @@ pub trait RpcMethodExt: RpcMethod { crate::rpc::RPCState, >, ) where - Self::Ok: Serialize + Clone + 'static, - Self::Ok: JsonSchema + Deserialize<'de>, + ::LotusJson: Clone + JsonSchema + Deserialize<'de> + 'static, { Self::register_raw(&mut module.inner, module.calling_convention).unwrap(); module @@ -209,13 +210,12 @@ pub trait RpcMethodExt: RpcMethod { timeout: crate::rpc_client::DEFAULT_TIMEOUT, }) } - fn call( + fn call_raw( client: &crate::rpc::client::Client, params: Self::Params, - ) -> impl Future> + ) -> impl Future::LotusJson, jsonrpsee::core::ClientError>> where Self::Params: Serialize, - Self::Ok: DeserializeOwned, { async { // TODO(aatifsyed): https://github.com/ChainSafe/forest/issues/4032 @@ -225,6 +225,19 @@ pub trait RpcMethodExt: RpcMethod { Ok(serde_json::from_value(json)?) } } + fn call( + client: &crate::rpc::client::Client, + params: Self::Params, + ) -> impl Future> + where + Self::Params: Serialize, + { + async { + Self::call_raw(client, params) + .await + .map(Self::Ok::from_lotus_json) + } + } } impl RpcMethodExt for T where T: RpcMethod {} diff --git a/src/tool/subcommands/api_cmd.rs b/src/tool/subcommands/api_cmd.rs index 52f8076e75b0..5d5585f9f752 100644 --- a/src/tool/subcommands/api_cmd.rs +++ b/src/tool/subcommands/api_cmd.rs @@ -338,10 +338,6 @@ impl RpcTest { fn identity(request: RpcRequest) -> RpcTest { Self::validate(request, |forest, lotus| forest == lotus) } - /// See [Self::identity], and note on this `impl` block. - fn identity_raw(request: RpcRequest) -> Self { - Self::validate_raw(request, |l, r| l == r) - } fn with_timeout(mut self, timeout: Duration) -> Self { self.request.set_timeout(timeout); @@ -424,9 +420,9 @@ impl RpcTest { fn common_tests() -> Vec { vec![ - RpcTest::basic_raw(Version::request(()).unwrap()), - RpcTest::basic_raw(StartTime::request(()).unwrap()), - RpcTest::basic_raw(Session::request(()).unwrap()), + RpcTest::basic(Version::request(()).unwrap()), + RpcTest::basic(StartTime::request(()).unwrap()), + RpcTest::basic(Session::request(()).unwrap()), ] } @@ -437,15 +433,15 @@ fn auth_tests() -> Vec { } fn beacon_tests() -> Vec { - vec![RpcTest::identity_raw( + vec![RpcTest::identity( BeaconGetEntry::request((10101,)).unwrap(), )] } fn chain_tests() -> Vec { vec![ - RpcTest::basic_raw(ChainHead::request(()).unwrap()), - RpcTest::identity_raw(ChainGetGenesis::request(()).unwrap()), + RpcTest::basic(ChainHead::request(()).unwrap()), + RpcTest::identity(ChainGetGenesis::request(()).unwrap()), ] } @@ -453,21 +449,21 @@ fn chain_tests_with_tipset(shared_tipset: &Tipset) -> Vec { let shared_block_cid = (*shared_tipset.min_ticket_block().cid()).into(); vec![ - RpcTest::identity_raw(ChainReadObj::request((shared_block_cid,)).unwrap()), - RpcTest::identity_raw(ChainHasObj::request((shared_block_cid,)).unwrap()), - RpcTest::identity_raw(ChainGetBlock::request((shared_block_cid,)).unwrap()), - RpcTest::identity_raw( + RpcTest::identity(ChainReadObj::request((shared_block_cid,)).unwrap()), + RpcTest::identity(ChainHasObj::request((shared_block_cid,)).unwrap()), + RpcTest::identity(ChainGetBlock::request((shared_block_cid,)).unwrap()), + RpcTest::identity( ChainGetTipSetAfterHeight::request((shared_tipset.epoch(), Default::default())) .unwrap(), ), - RpcTest::identity_raw( + RpcTest::identity( ChainGetTipSetAfterHeight::request((shared_tipset.epoch(), Default::default())) .unwrap(), ), - RpcTest::identity_raw( + RpcTest::identity( ChainGetTipSet::request((LotusJson(shared_tipset.key().clone().into()),)).unwrap(), ), - RpcTest::identity_raw( + RpcTest::identity( ChainGetPath::request(( shared_tipset.key().clone().into(), shared_tipset.parents().clone().into(), @@ -479,8 +475,8 @@ fn chain_tests_with_tipset(shared_tipset: &Tipset) -> Vec { fn mpool_tests() -> Vec { vec![ - RpcTest::basic_raw(MpoolPending::request((LotusJson(ApiTipsetKey(None)),)).unwrap()), - RpcTest::basic_raw(MpoolSelect::request((LotusJson(ApiTipsetKey(None)), 0.9_f64)).unwrap()), + RpcTest::basic(MpoolPending::request((LotusJson(ApiTipsetKey(None)),)).unwrap()), + RpcTest::basic(MpoolSelect::request((LotusJson(ApiTipsetKey(None)), 0.9_f64)).unwrap()), ] } @@ -498,14 +494,14 @@ fn net_tests() -> Vec { // More net commands should be tested. Tracking issue: // https://github.com/ChainSafe/forest/issues/3639 vec![ - RpcTest::basic_raw(NetAddrsListen::request(()).unwrap()), - RpcTest::basic_raw(NetPeers::request(()).unwrap()), - RpcTest::identity_raw(NetListening::request(()).unwrap()), - RpcTest::basic_raw(NetAgentVersion::request((peer_id,)).unwrap()), - RpcTest::basic_raw(NetInfo::request(()).unwrap()) + RpcTest::basic(NetAddrsListen::request(()).unwrap()), + RpcTest::basic(NetPeers::request(()).unwrap()), + RpcTest::identity(NetListening::request(()).unwrap()), + RpcTest::basic(NetAgentVersion::request((peer_id,)).unwrap()), + RpcTest::basic(NetInfo::request(()).unwrap()) .ignore("Not implemented in Lotus. Why do we even have this method?"), - RpcTest::basic_raw(NetAutoNatStatus::request(()).unwrap()), - RpcTest::identity_raw(NetVersion::request(()).unwrap()), + RpcTest::basic(NetAutoNatStatus::request(()).unwrap()), + RpcTest::identity(NetVersion::request(()).unwrap()), ] } @@ -519,8 +515,8 @@ fn node_tests() -> Vec { fn state_tests() -> Vec { vec![ - RpcTest::identity_raw(StateGetBeaconEntry::request((0.into(),)).unwrap()), - RpcTest::identity_raw(StateGetBeaconEntry::request((1.into(),)).unwrap()), + RpcTest::identity(StateGetBeaconEntry::request((0.into(),)).unwrap()), + RpcTest::identity(StateGetBeaconEntry::request((1.into(),)).unwrap()), ] } @@ -589,9 +585,7 @@ fn state_tests_with_tipset(shared_tipset: &Tipset) -> Vec { Address::new_id(18101), // msig address id shared_tipset.key().into(), )), - RpcTest::identity_raw( - StateGetBeaconEntry::request((shared_tipset.epoch().into(),)).unwrap(), - ), + RpcTest::identity(StateGetBeaconEntry::request((shared_tipset.epoch().into(),)).unwrap()), ] } @@ -610,9 +604,9 @@ fn wallet_tests() -> Vec { }; vec![ - RpcTest::identity_raw(WalletBalance::request((known_wallet.into(),)).unwrap()), - RpcTest::identity_raw(WalletValidateAddress::request((known_wallet.to_string(),)).unwrap()), - RpcTest::identity_raw( + RpcTest::identity(WalletBalance::request((known_wallet.into(),)).unwrap()), + RpcTest::identity(WalletValidateAddress::request((known_wallet.to_string(),)).unwrap()), + RpcTest::identity( WalletVerify::request((known_wallet.into(), text.into(), signature.into())).unwrap(), ), // These methods require write access in Lotus. Not sure why. @@ -672,7 +666,7 @@ fn gas_tests_with_tipset(shared_tipset: &Tipset) -> Vec { // is inherently non-deterministic but I'm fairly sure we're compensated for // everything. If not, this test will be flaky. Instead of disabling it, we // should relax the verification requirement. - vec![RpcTest::identity_raw( + vec![RpcTest::identity( GasEstimateGasLimit::request((message.into(), LotusJson(shared_tipset.key().into()))) .unwrap(), )] @@ -709,7 +703,7 @@ fn snapshot_tests(store: Arc, n_tipsets: usize) -> anyhow::Result, n_tipsets: usize) -> anyhow::Result, n_tipsets: usize) -> anyhow::Result, n_tipsets: usize) -> anyhow::Result, n_tipsets: usize) -> anyhow::Result, n_tipsets: usize) -> anyhow::Result { let client = rpc::Client::from(ApiInfo::from_env()?); - let head = ChainHead::call(&client, ()).await?.into_inner(); + let head = ChainHead::call(&client, ()).await?; let end_height = match height { Some(it) => it, None => head @@ -80,7 +80,7 @@ impl ShedCommands { LotusJson(ApiTipsetKey(Some(head.key().clone()))), ), ) - .map_ok(|LotusJson(tipset)| { + .map_ok(|tipset| { let cids = tipset.block_headers().iter().map(|it| *it.cid()); (tipset.epoch(), cids.collect::>()) }) diff --git a/src/wallet/subcommands/wallet_cmd.rs b/src/wallet/subcommands/wallet_cmd.rs index 501c5fcf2773..12b383969ca8 100644 --- a/src/wallet/subcommands/wallet_cmd.rs +++ b/src/wallet/subcommands/wallet_cmd.rs @@ -85,7 +85,7 @@ impl WalletBackend { if let Some(keystore) = &self.local { Ok(crate::key_management::list_addrs(keystore)?) } else { - Ok(WalletList::call(&self.remote, ()).await?.into_inner()) + Ok(WalletList::call(&self.remote, ()).await?) } } @@ -93,9 +93,7 @@ impl WalletBackend { if let Some(keystore) = &self.local { Ok(crate::key_management::export_key_info(&address, keystore)?) } else { - Ok(WalletExport::call(&self.remote, (address.into(),)) - .await? - .into_inner()) + Ok(WalletExport::call(&self.remote, (address.into(),)).await?) } } @@ -109,7 +107,6 @@ impl WalletBackend { } else { Ok(WalletImport::call(&self.remote, (key_info.into(),)) .await? - .into_inner() .to_string()) } } @@ -145,7 +142,6 @@ impl WalletBackend { } else { Ok(WalletNew::call(&self.remote, (signature_type.into(),)) .await? - .into_inner() .to_string()) } } @@ -156,7 +152,6 @@ impl WalletBackend { } else { Ok(WalletDefaultAddress::call(&self.remote, ()) .await? - .into_inner() .map(|it| it.to_string())) } } @@ -185,8 +180,7 @@ impl WalletBackend { } else { Ok( WalletSign::call(&self.remote, (address.into(), message.into_bytes().into())) - .await? - .into_inner(), + .await?, ) } } @@ -328,9 +322,7 @@ impl WalletCommands { Self::Balance { address } => { let StrictAddress(address) = StrictAddress::from_str(&address) .with_context(|| format!("Invalid address: {address}"))?; - let balance = WalletBalance::call(&backend.remote, (address.into(),)) - .await? - .into_inner(); + let balance = WalletBalance::call(&backend.remote, (address.into(),)).await?; println!("{balance}"); Ok(()) } @@ -417,9 +409,7 @@ impl WalletCommands { }; let balance_token_amount = - WalletBalance::call(&backend.remote, (address.into(),)) - .await? - .into_inner(); + WalletBalance::call(&backend.remote, (address.into(),)).await?; let balance_string = match (no_round, no_abbrev) { // no_round, absolute @@ -454,9 +444,7 @@ impl WalletCommands { Ok(()) } Self::ValidateAddress { address } => { - let response = WalletValidateAddress::call(&backend.remote, (address,)) - .await? - .into_inner(); + let response = WalletValidateAddress::call(&backend.remote, (address,)).await?; println!("{response}"); Ok(()) } @@ -535,9 +523,7 @@ impl WalletCommands { MpoolPush::call(&backend.remote, (LotusJson(smsg.clone()),)).await?; smsg } else { - MpoolPushMessage::call(&backend.remote, (LotusJson(message), None)) - .await? - .into_inner() + MpoolPushMessage::call(&backend.remote, (LotusJson(message), None)).await? }; println!("{}", signed_msg.cid().unwrap());