Open aatifsyed opened 8 months ago
Code snippets file for VSCode:
// This should live somewhere like `${workspaceDir}/.vscode/rpc.code-snippets`
{
"rpc method": {
"prefix": "impl RpcMethod",
"body": [
"pub enum ${1:MethodName} {}",
"impl RpcMethod<${2:ARITY}> for $1 {",
"const NAME: &'static str = \"Filecoin.$1\";",
"const PARAM_NAMES: [&'static str; $2] = [$3];",
"const API_VERSION: ApiVersion = ApiVersion::${7:V0};",
"",
"type Params = ($4);",
"type Ok = $6;",
"",
"async fn handle(ctx: Ctx<impl Blockstore $8>, ($5): Self::Params) -> Result<Self::Ok, ServerError> {",
"$0",
"}", // fn handle
"}", // impl RpcMethod
]
},
"imports": {
"prefix": "use",
"body": [
"use crate::rpc::{reflect::SelfDescribingRpcModule, ApiVersion, Ctx, RPCState, RpcMethod, RpcMethodExt as _, ServerError};",
"use schemars::JsonSchema;"
]
},
}
The motivating use-case is #4038. While we're in the area we can do a lot of cleanup.
4067
4081
4007
4134
4172
crate::rpc::Client
, removecrate::rpc_client::ApiInfo
.4140
4280
4231
4234
trait RpcMethod
.Ctx
rpc::types
are minimal - any structs used by only one e.ggas
API should live ingas.rs
, not intypes.rs
.types.rs
is only for types that are shared across APIsLotusJson
where possible.JsonSchema
where necessary.for_each_method
macro ingas.rs
.prelude
RpcTest
constructors should useRpcTest::basic_raw
, andRpcMethodExt::request
like this.forest-cli
calls shouldrpc::Client::from(api: ApiInfo)
and thenRpcMethodExt::call
on that. In the limit,ApiInfo
can be removed, and replaced by anrpc::Client::from_env
methodforest-cli attach
calls should be removed, and tracked under #41414139
4154
4155
4158
4168
4175
4187
4191
4200
4203
4204
4225
4244
4248
4141 / #4358
crate::rpc_client::RpcRequest::params
should beVec<Value>
orRequestParameters
, and should have better error handling.HasLotusJson
HasLotusJson
HasLotusJson
LotusJson
- it has separate CBOR and JSON representations.MessageSendSpec
, on the other hand, can just be deserialized normally. A misapplication of theHasLotusJson
API has lead to the proliferation oflotus_json_with_self!
callsLotusJson<Vec<T>>
should NOT recurse: users should useLotusJson<Vec<LotusJson<T>>
LotusJson<ApiTipsetKey>
is wrong4277
trait RpcMethod
OpenRPC
document nice.crate::rpc::types
4295