@corpus-core/colibri-stateless 0.2.6 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.js CHANGED
@@ -112,12 +112,14 @@ const default_config = {
112
112
  beacon_apis: ["https://lodestar-mainnet.chainsafe.io"],
113
113
  rpcs: ["https://rpc.ankr.com/eth"],
114
114
  proofer: ["https://mainnet.colibri-proof.tech"],
115
+ pollingInterval: 12000,
115
116
  },
116
117
  '100': {
117
118
  alias: ["gnosis", "xdai", "0x64"],
118
119
  beacon_apis: ["https://gnosis.colibri-proof.tech"],
119
120
  rpcs: ["https://rpc.ankr.com/gnosis"],
120
121
  proofer: ["https://gnosis.colibri-proof.tech"],
122
+ pollingInterval: 5000,
121
123
  },
122
124
  };
123
125
  function get_chain_id(chain_id) {
@@ -130,6 +132,15 @@ function get_chain_id(chain_id) {
130
132
  }
131
133
  throw new Error("Invalid chain id: " + chain_id);
132
134
  }
135
+ function chain_conf(config, chainId) {
136
+ const k = config?.chains?.[chainId];
137
+ if (k)
138
+ return k;
139
+ const k2 = default_config[chainId + ''];
140
+ if (k2)
141
+ return k2;
142
+ return undefined;
143
+ }
133
144
  export default class C4Client {
134
145
  config;
135
146
  eventEmitter;
@@ -139,8 +150,8 @@ export default class C4Client {
139
150
  const chainId = config?.chainId ? get_chain_id(config?.chainId + '') : 1;
140
151
  const chain_config = { ...default_config[chainId + ''] };
141
152
  this.config = {
153
+ chains: {},
142
154
  trusted_block_hashes: [],
143
- pollingInterval: 12000, // Default here, can be overridden by user config
144
155
  rpcs: chain_config.rpcs || [],
145
156
  beacon_apis: chain_config.beacon_apis || [],
146
157
  proofer: chain_config.proofer || [],
@@ -154,7 +165,10 @@ export default class C4Client {
154
165
  this.eventEmitter = new EventEmitter();
155
166
  this.connectionState = new ConnectionState({ chainId: parseInt(this.config.chainId + ''), debug: this.config.debug }, async () => this.rpc('eth_chainId', [], C4MethodType.LOCAL), // Use the specific callback
156
167
  this.eventEmitter);
157
- this.subscriptionManager = new SubscriptionManager(async (method, params) => this.rpc(method, params), this.eventEmitter, { debug: this.config.debug, pollingInterval: this.config.pollingInterval });
168
+ this.subscriptionManager = new SubscriptionManager(async (method, params) => this.rpc(method, params), this.eventEmitter, {
169
+ debug: this.config.debug,
170
+ pollingInterval: this.config.pollingInterval || chain_conf(this.config, this.config.chainId)?.pollingInterval || 12000
171
+ });
158
172
  }
159
173
  async getProoferConfig() {
160
174
  const c4w = await getC4w();
@@ -297,7 +311,7 @@ export default class C4Client {
297
311
  // If handleRequest returns a Promise, it means it's handling the request
298
312
  return subscriptionResult;
299
313
  }
300
- let conf = this.config.chains[this.config.chainId];
314
+ let conf = chain_conf(this.config, this.config.chainId);
301
315
  let strategy = conf?.proofStrategy || this.config.proofStrategy;
302
316
  // If not handled by SubscriptionManager, proceed with standard RPC call logic
303
317
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@corpus-core/colibri-stateless",
3
- "version": "0.2.6",
3
+ "version": "0.3.1",
4
4
  "description": "Colibri is a stateless and trustless ethereum client, which is optimized for the mobile apps or embedded devices, because it does not hols the state, but verifies on demand.",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -159,8 +159,6 @@ export class SubscriptionManager {
159
159
  sub.lastPolledBlockNumber = currentVerifiableBlockNumber;
160
160
  if (currentVerifiableBlockNumber <= sub.lastPolledBlockNumber)
161
161
  return []; // No new head yet for eth_subscribe('newHeads')
162
- // If new, target currentVerifiableBlockNumber for eth_getBlockByNumber
163
- fromBlock = currentVerifiableBlockNumber;
164
162
  }
165
163
  for (let blockNum = fromBlock; blockNum <= currentVerifiableBlockNumber; blockNum++) {
166
164
  try {