Skip to content

Commit 609f416

Browse files
committed
Fix openrpc docgen
Prevent multiple inputs for jsonrpc params.
1 parent 11d93cd commit 609f416

File tree

4 files changed

+38
-19
lines changed

4 files changed

+38
-19
lines changed

monad-rpc/monad-rpc-docs/monad-rpc-docs-derive/src/lib.rs

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ pub fn rpc(attr_args: TokenStream, decorated: TokenStream) -> TokenStream {
3636
let attr_args: AttributeArgs = parse_macro_input!(attr_args);
3737
let attr_args = extract_attrs(&attr_args);
3838
let method_name = attr_args.method_name.unwrap_or(fn_name.to_string());
39-
let input_infos = extract_input_info(inputs, &attr_args.ignore_inputs);
39+
let input_info = extract_input_info(inputs, &attr_args.ignore_inputs);
4040
let output = &input.sig.output;
4141
let output_info = extract_output_info(output.clone());
4242

@@ -51,11 +51,14 @@ pub fn rpc(attr_args: TokenStream, decorated: TokenStream) -> TokenStream {
5151
fn_name.span(),
5252
);
5353

54-
let input_types: Vec<Type> = input_infos.iter().map(|(_, typ, _)| typ.clone()).collect();
55-
let input_schemas: Vec<TokenStream2> = input_infos
56-
.iter()
54+
let input_type: Type = input_info
55+
.as_ref()
56+
.map(|(_, typ, _)| typ.clone())
57+
.unwrap_or(parse_quote!([u8; 0]));
58+
let input_schema: TokenStream2 = input_info
59+
.as_ref()
5760
.map(|(_, _, schema)| schema.clone())
58-
.collect();
61+
.unwrap_or(parse_quote!(None));
5962

6063
let output_type: Type = output_info
6164
.as_ref()
@@ -66,10 +69,6 @@ pub fn rpc(attr_args: TokenStream, decorated: TokenStream) -> TokenStream {
6669
.map(|(_, _, schema)| schema.clone())
6770
.unwrap_or(parse_quote!(None));
6871

69-
let default_input = parse_quote!([u8; 0]);
70-
let input_type = input_types.first().unwrap_or(&default_input);
71-
let default_schema = parse_quote!(None);
72-
let input_schema = input_schemas.first().unwrap_or(&default_schema);
7372
TokenStream::from(quote! {
7473
#input
7574

@@ -169,7 +168,10 @@ fn extract_attrs(attrs: &[NestedMeta]) -> Args {
169168

170169
if nv.path.is_ident("ignore") {
171170
if let Lit::Str(lit) = &nv.lit {
172-
args.ignore_inputs.push(lit.value());
171+
let value = lit.value();
172+
for item in value.split(',').map(|s| s.trim()).filter(|s| !s.is_empty()) {
173+
args.ignore_inputs.push(item.to_string());
174+
}
173175
}
174176
}
175177
}
@@ -181,8 +183,8 @@ fn extract_attrs(attrs: &[NestedMeta]) -> Args {
181183
fn extract_input_info(
182184
inputs: &syn::punctuated::Punctuated<FnArg, syn::token::Comma>,
183185
ignore_inputs: &[String],
184-
) -> Vec<(String, Type, TokenStream2)> {
185-
inputs
186+
) -> Option<(String, Type, TokenStream2)> {
187+
let collected: Vec<(String, Type, TokenStream2)> = inputs
186188
.iter()
187189
.filter_map(|arg| {
188190
if let FnArg::Typed(PatType { pat, ty, .. }) = arg {
@@ -202,7 +204,13 @@ fn extract_input_info(
202204
None
203205
}
204206
})
205-
.collect()
207+
.collect();
208+
209+
if collected.len() > 1 {
210+
panic!("Expected at most one input, got {}", collected.len());
211+
}
212+
213+
collected.into_iter().next()
206214
}
207215

208216
fn extract_output_info(output: ReturnType) -> Option<(String, Type, TokenStream2)> {

monad-rpc/src/handlers/eth/call.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -732,7 +732,10 @@ async fn prepare_eth_call<T: Triedb + TriedbPath>(
732732

733733
/// Executes a new message call immediately without creating a transaction on the block chain.
734734
#[tracing::instrument(level = "debug")]
735-
#[rpc(method = "eth_call", ignore = "chain_id", ignore = "eth_call_executor")]
735+
#[rpc(
736+
method = "eth_call",
737+
ignore = "eth_call_executor,chain_id,eth_call_provider_gas_limit"
738+
)]
736739
pub async fn monad_eth_call<T: Triedb + TriedbPath>(
737740
triedb_env: &T,
738741
eth_call_executor: Arc<EthCallExecutor>,
@@ -840,7 +843,10 @@ pub struct EthCallCapacityStats {
840843
/// Returns statistics about eth_call capacity including inactive executors and queued requests
841844
#[allow(non_snake_case)]
842845
#[tracing::instrument(level = "debug")]
843-
#[monad_rpc_docs::rpc(method = "admin_ethCallStatistics")]
846+
#[monad_rpc_docs::rpc(
847+
method = "admin_ethCallStatistics",
848+
ignore = "eth_call_executor_fibers,total_permits,available_permits"
849+
)]
844850
pub async fn monad_admin_ethCallStatistics(
845851
eth_call_executor_fibers: usize,
846852
total_permits: usize,

monad-rpc/src/handlers/eth/gas.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,8 +223,7 @@ pub struct MonadEthEstimateGasParams {
223223

224224
#[rpc(
225225
method = "eth_estimateGas",
226-
ignore = "chain_id",
227-
ignore = "eth_call_executor"
226+
ignore = "chain_id,provider_gas_limit,eth_call_executor"
228227
)]
229228
#[allow(non_snake_case)]
230229
/// Generates and returns an estimate of how much gas is necessary to allow the transaction to complete.

monad-rpc/src/handlers/eth/txn.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,10 @@ fn schema_for_filter(_: &mut schemars::gen::SchemaGenerator) -> schemars::schema
151151
.into()
152152
}
153153

154-
#[rpc(method = "eth_getLogs", ignore = "max_block_range")]
154+
#[rpc(
155+
method = "eth_getLogs",
156+
ignore = "max_block_range,use_eth_get_logs_index,dry_run_get_logs_index,max_finalized_block_cache_len"
157+
)]
155158
#[allow(non_snake_case)]
156159
/// Returns an array of all logs matching filter with given id.
157160
#[tracing::instrument(level = "debug", skip_all)]
@@ -187,7 +190,10 @@ pub struct MonadEthSendRawTransactionParams {
187190

188191
const MAX_CONCURRENT_SEND_RAW_TX: usize = 1_000;
189192
// TODO: need to support EIP-4844 transactions
190-
#[rpc(method = "eth_sendRawTransaction", ignore = "tx_pool", ignore = "ipc")]
193+
#[rpc(
194+
method = "eth_sendRawTransaction",
195+
ignore = "tx_pool,ipc,chain_id,allow_unprotected_txs"
196+
)]
191197
#[allow(non_snake_case)]
192198
#[tracing::instrument(level = "debug", skip_all)]
193199
/// Submits a raw transaction. For EIP-4844 transactions, the raw form must be the network form.

0 commit comments

Comments
 (0)