Skip to content

Commit

Permalink
feat: rpc::Client (#4140)
Browse files Browse the repository at this point in the history
  • Loading branch information
aatifsyed authored Apr 8, 2024
1 parent 8a2583e commit 8fd41b1
Show file tree
Hide file tree
Showing 18 changed files with 602 additions and 397 deletions.
38 changes: 37 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -82,18 +82,21 @@ git-version = "0.3"
group = "0.13"
hex = { version = "0.4", features = ["serde"] }
http = "1.0"
# TODO(forest): https://github.com/ChainSafe/forest/issues/3961
# bump hyper to 1.0 after https://github.com/paritytech/jsonrpsee/issues/1257
http02 = { version = "0.2", package = "http" }
human-repr = "1.0"
human_bytes = "0.4"
humantime = "2.1.0"
# TODO(forest): https://github.com/ChainSafe/forest/issues/3961
# bump hyper to 1.0 after https://github.com/paritytech/jsonrpsee/pull/1266
# bump hyper to 1.0 after https://github.com/paritytech/jsonrpsee/issues/1257
hyper = { version = "0.14", features = ["full"] }
indexmap = { version = "2.2", features = ["serde"] }
indicatif = { version = "0.17.6", features = ["tokio"] }
integer-encoding = "4.0"
is-terminal = "0.4"
itertools = "0.12.1"
jsonrpsee = { version = "0.22", features = ["server", "ws-client"] }
jsonrpsee = { version = "0.22.2", features = ["server", "ws-client", "http-client"] }
jsonwebtoken = "9"
kubert-prometheus-process = "0.1"
libc = "0.2"
Expand Down
15 changes: 9 additions & 6 deletions src/cli/subcommands/attach_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@ use std::{
str::FromStr,
};

use crate::chain::ChainEpochDelta;
use crate::chain_sync::SyncStage;
use crate::rpc_client::*;
use crate::shim::{address::Address, message::Message};
use crate::{
chain::ChainEpochDelta,
rpc::{self, mpool_api::MpoolPushMessage, RpcMethodExt as _},
};
use crate::{cli::humantoken, message::SignedMessage};
use boa_engine::{
object::{builtins::JsArray, FunctionObjectBuilder},
Expand Down Expand Up @@ -255,8 +258,11 @@ async fn send_message(params: SendMessageParams, api: ApiInfo) -> anyhow::Result
Address::from_str(&to)?,
humantoken::parse(&value)?, // Convert forest_shim::TokenAmount to TokenAmount3
);

Ok(api.mpool_push_message(message, None).await?)
Ok(
MpoolPushMessage::call(&rpc::Client::from(api), (message.into(), None))
.await?
.into_inner(),
)
}

type SleepParams = (u64,);
Expand Down Expand Up @@ -344,9 +350,6 @@ impl AttachCommand {
"wallet_has" => ApiInfo::wallet_has_req,
"wallet_set_default" => ApiInfo::wallet_set_default_req,

// Message Pool API
"mpool_push_message" => |(message, specs)| ApiInfo::mpool_push_message_req(message, specs),

// Common API
"version" => |()| ApiInfo::version_req(),
"shutdown" => |()| ApiInfo::shutdown_req(),
Expand Down
5 changes: 1 addition & 4 deletions src/cli/subcommands/auth_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,7 @@ impl AuthCommands {
let perms = process_perms(perm)?;
let token_exp = Duration::from_std(expire_in.into())?;
let token = api.auth_new(perms, token_exp).await?;
let new_api = ApiInfo {
token: Some(String::from_utf8(token)?),
..api
};
let new_api = api.set_token(Some(String::from_utf8(token)?));
println!("FULLNODE_API_INFO=\"{}\"", new_api);
Ok(())
}
Expand Down
18 changes: 16 additions & 2 deletions src/cli/subcommands/mpool_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
use std::str::FromStr;

use crate::blocks::Tipset;
use crate::lotus_json::LotusJson;
use crate::message::SignedMessage;
use crate::rpc::mpool_api::MpoolPending;
use crate::rpc::types::ApiTipsetKey;
use crate::rpc::{self, RpcMethodExt as _};
use crate::rpc_client::ApiInfo;
use crate::shim::address::StrictAddress;
use crate::shim::message::Message;
Expand Down Expand Up @@ -211,7 +215,12 @@ impl MpoolCommands {
to,
from,
} => {
let messages = api.mpool_pending(vec![]).await?;
let messages = MpoolPending::call(
&rpc::Client::from(api.clone()),
(LotusJson(ApiTipsetKey(None)),),
)
.await?
.into_inner();

let local_addrs = if local {
let response = api.wallet_list().await?;
Expand Down Expand Up @@ -245,7 +254,12 @@ impl MpoolCommands {
let atto_str = api.chain_get_min_base_fee(basefee_lookback).await?;
let min_base_fee = TokenAmount::from_atto(atto_str.parse::<BigInt>()?);

let messages = api.mpool_pending(vec![]).await?;
let messages = MpoolPending::call(
&rpc::Client::from(api.clone()),
(LotusJson(ApiTipsetKey(None)),),
)
.await?
.into_inner();

let local_addrs = if local {
let response = api.wallet_list().await?;
Expand Down
6 changes: 5 additions & 1 deletion src/cli/subcommands/send_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

use std::str::FromStr as _;

use crate::rpc::mpool_api::MpoolPushMessage;
use crate::rpc::{self, RpcMethodExt as _};
use crate::rpc_client::ApiInfo;
use crate::shim::address::{Address, StrictAddress};
use crate::shim::econ::TokenAmount;
Expand Down Expand Up @@ -53,7 +55,9 @@ impl SendCommand {
..Default::default()
};

let signed_msg = api.mpool_push_message(message, None).await?;
let signed_msg = MpoolPushMessage::call(&rpc::Client::from(api), (message.into(), None))
.await?
.into_inner();

println!("{}", signed_msg.cid().unwrap());

Expand Down
5 changes: 2 additions & 3 deletions src/rpc/auth_layer.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
// Copyright 2019-2024 ChainSafe Systems
// SPDX-License-Identifier: Apache-2.0, MIT

use super::RpcMethod as _;
use crate::auth::{verify_token, JWT_IDENTIFIER};
use crate::key_management::KeyStore;
use crate::rpc::{
auth_api, beacon_api, chain_api, common_api, eth_api, gas_api, mpool_api, net_api, node_api,
state_api, sync_api, wallet_api, CANCEL_METHOD_NAME,
state_api, sync_api, wallet_api, RpcMethod as _, CANCEL_METHOD_NAME,
};
use ahash::{HashMap, HashMapExt as _};
use futures::future::BoxFuture;
Expand Down Expand Up @@ -46,7 +45,7 @@ static ACCESS_MAP: Lazy<HashMap<&str, Access>> = Lazy::new(|| {
access.insert(chain_api::CHAIN_GET_MESSAGE, Access::Read);
access.insert(chain_api::CHAIN_EXPORT, Access::Read);
access.insert(chain_api::CHAIN_READ_OBJ, Access::Read);
access.insert(chain_api::CHAIN_GET_PATH, Access::Read);
access.insert(chain_api::ChainGetPath::NAME, Access::Read);
access.insert(chain_api::CHAIN_HAS_OBJ, Access::Read);
access.insert(chain_api::CHAIN_GET_BLOCK_MESSAGES, Access::Read);
access.insert(chain_api::CHAIN_GET_TIPSET_BY_HEIGHT, Access::Read);
Expand Down
7 changes: 5 additions & 2 deletions src/rpc/chain_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ use crate::lotus_json::LotusJson;
use crate::lotus_json::{assert_all_snapshots, assert_unchanged_via_json};
use crate::message::ChainMessage;
use crate::rpc::types::{ApiHeadChange, ApiMessage, ApiReceipt, ApiTipsetKey, BlockMessages};
use crate::rpc::{error::JsonRpcError, Ctx, RpcMethod};
use crate::rpc::{
error::JsonRpcError,
reflect::{ApiVersion, Ctx, RpcMethod},
};
use crate::shim::clock::ChainEpoch;
use crate::shim::message::Message;
use crate::utils::io::VoidAsyncWriter;
Expand Down Expand Up @@ -64,7 +67,6 @@ pub const CHAIN_GET_GENESIS: &str = "Filecoin.ChainGetGenesis";
pub const CHAIN_HEAD: &str = "Filecoin.ChainHead";
pub const CHAIN_GET_BLOCK: &str = "Filecoin.ChainGetBlock";
pub const CHAIN_GET_TIPSET: &str = "Filecoin.ChainGetTipSet";
pub const CHAIN_GET_PATH: &str = "Filecoin.ChainGetPath";
pub const CHAIN_SET_HEAD: &str = "Filecoin.ChainSetHead";
pub const CHAIN_GET_MIN_BASE_FEE: &str = "Filecoin.ChainGetMinBaseFee";
pub const CHAIN_GET_MESSAGES_IN_TIPSET: &str = "Filecoin.ChainGetMessagesInTipset";
Expand Down Expand Up @@ -391,6 +393,7 @@ pub enum ChainGetPath {}
impl RpcMethod<2> for ChainGetPath {
const NAME: &'static str = "Filecoin.ChainGetPath";
const PARAM_NAMES: [&'static str; 2] = ["from", "to"];
const API_VERSION: ApiVersion = ApiVersion::V0;
type Params = (LotusJson<TipsetKey>, LotusJson<TipsetKey>);
type Ok = LotusJson<Vec<PathChange>>;

Expand Down
Loading

0 comments on commit 8fd41b1

Please sign in to comment.