diff --git a/.changeset/slimy-donuts-hammer.md b/.changeset/slimy-donuts-hammer.md new file mode 100644 index 0000000..d700ec3 --- /dev/null +++ b/.changeset/slimy-donuts-hammer.md @@ -0,0 +1,9 @@ +--- +"@xcfx/node": patch +"@xcfx/node-darwin-arm64": patch +"@xcfx/node-darwin-x64": patch +"@xcfx/node-linux-x64-gnu": patch +"@xcfx/node-win32-x64-msvc": patch +--- + +Added pollLifetimeInSeconds and getLogsFilterMaxLimit to config diff --git a/__test__/customConfig.test.ts b/__test__/customConfig.test.ts index 2a11125..63c3002 100644 --- a/__test__/customConfig.test.ts +++ b/__test__/customConfig.test.ts @@ -30,6 +30,7 @@ beforeAll(async () => { // devPackTxImmediately: true, tcpPort: udpAndTcpPort, udpPort: udpAndTcpPort, + pollLifetimeInSeconds: 180, }); await server.start(); @@ -41,7 +42,6 @@ beforeAll(async () => { describe("customConfig", () => { test("test http port", async () => { const client = createPublicClient({ - chain: localChain, transport: http(`http://127.0.0.1:${HTTP_PORT}`), }); @@ -50,7 +50,6 @@ describe("customConfig", () => { test("test ws port", async () => { const client = createPublicClient({ - chain: localChain, transport: webSocket(`ws://127.0.0.1:${WS_PORT}`), }); @@ -59,7 +58,6 @@ describe("customConfig", () => { test("test mining address", async () => { const client = createPublicClient({ - chain: localChain, transport: http(`http://127.0.0.1:${HTTP_PORT}`), }); expect( @@ -71,7 +69,6 @@ describe("customConfig", () => { test("auto mining", async () => { const client = createPublicClient({ - chain: localChain, transport: http(`http://127.0.0.1:${HTTP_PORT}`), }); const block = await client.getBlock(); @@ -81,7 +78,6 @@ describe("customConfig", () => { test("test genesis", async () => { const client = createPublicClient({ - chain: localChain, transport: http(`http://127.0.0.1:${HTTP_PORT}`), }); @@ -95,4 +91,14 @@ describe("customConfig", () => { expect(balance).toBe(parseCFX("10000")); } }); + + test("pollLifetimeInSeconds enable filter rpc", async () => { + const client = createPublicClient({ + transport: http(`http://127.0.0.1:${HTTP_PORT}`), + }); + + const id = await client.createBlockFilter(); + + expect(id).toBeDefined(); + }); }); diff --git a/conflux.d.ts b/conflux.d.ts index a09a24c..bd3775d 100644 --- a/conflux.d.ts +++ b/conflux.d.ts @@ -169,5 +169,14 @@ export interface ConfluxConfig { * @default null */ jsonrpcLocalWsPort?: number + /** + * `poll_lifetime_in_seconds` is the lifetime of the poll in seconds. + * If set, the following RPC methods will be enabled: + * - `cfx_newFilter` `cfx_newBlockFilter` `cfx_newPendingTransactionFilter` `cfx_getFilterChanges` `cfx_getFilterLogs` `cfx_uninstallFilter`. + * - `eth_newFilter` `eth_newBlockFilter` `eth_newPendingTransactionFilter` eth_getFilterChanges eth_getFilterLogs eth_uninstallFilter + */ + pollLifetimeInSeconds?: number + /** if `get_logs_filter_max_limit` is configured but the query would return more logs */ + getLogsFilterMaxLimit?: number } diff --git a/src/config.rs b/src/config.rs index 4095a11..ab052eb 100644 --- a/src/config.rs +++ b/src/config.rs @@ -134,6 +134,13 @@ pub struct ConfluxConfig { /// if not set, the JSON-RPC server will not be started. /// @default null pub jsonrpc_local_ws_port: Option, + /// `poll_lifetime_in_seconds` is the lifetime of the poll in seconds. + /// If set, the following RPC methods will be enabled: + /// - `cfx_newFilter` `cfx_newBlockFilter` `cfx_newPendingTransactionFilter` `cfx_getFilterChanges` `cfx_getFilterLogs` `cfx_uninstallFilter`. + /// - `eth_newFilter` `eth_newBlockFilter` `eth_newPendingTransactionFilter` eth_getFilterChanges eth_getFilterLogs eth_uninstallFilter + pub poll_lifetime_in_seconds: Option, + /// if `get_logs_filter_max_limit` is configured but the query would return more logs + pub get_logs_filter_max_limit: Option, } pub fn convert_config(js_config: ConfluxConfig, temp_dir_path: &Path) -> Configuration { @@ -207,6 +214,10 @@ pub fn convert_config(js_config: ConfluxConfig, temp_dir_path: &Path) -> Configu conf.raw_conf.cip1559_transition_height = Some(js_config.cip1559_transition_height.unwrap_or(2) as u64); + conf.raw_conf.poll_lifetime_in_seconds = js_config.poll_lifetime_in_seconds; + + conf.raw_conf.get_logs_filter_max_limit = js_config.get_logs_filter_max_limit.map(|n| n as usize); + // confix data dir, default to temp dir conf.raw_conf.conflux_data_dir = js_config .conflux_data_dir