Skip to content

Commit

Permalink
feat: add more config
Browse files Browse the repository at this point in the history
  • Loading branch information
iosh committed Nov 1, 2024
1 parent a374d64 commit 8b0f478
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 5 deletions.
9 changes: 9 additions & 0 deletions .changeset/slimy-donuts-hammer.md
Original file line number Diff line number Diff line change
@@ -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
16 changes: 11 additions & 5 deletions __test__/customConfig.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ beforeAll(async () => {
// devPackTxImmediately: true,
tcpPort: udpAndTcpPort,
udpPort: udpAndTcpPort,
pollLifetimeInSeconds: 180,
});

await server.start();
Expand All @@ -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}`),
});

Expand All @@ -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}`),
});

Expand All @@ -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(
Expand All @@ -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();
Expand All @@ -81,7 +78,6 @@ describe("customConfig", () => {

test("test genesis", async () => {
const client = createPublicClient({
chain: localChain,
transport: http(`http://127.0.0.1:${HTTP_PORT}`),
});

Expand All @@ -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();
});
});
9 changes: 9 additions & 0 deletions conflux.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

11 changes: 11 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u16>,
/// `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<u32>,
/// if `get_logs_filter_max_limit` is configured but the query would return more logs
pub get_logs_filter_max_limit: Option<u32>,
}

pub fn convert_config(js_config: ConfluxConfig, temp_dir_path: &Path) -> Configuration {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 8b0f478

Please sign in to comment.