@corpus-core/colibri-stateless 0.3.0 → 0.3.2
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/c4w.js +1 -1
- package/index.js +19 -5
- package/package.json +1 -1
- package/subscriptionManager.js +0 -2
- package/types.d.ts +1 -1
- package/types.js +3 -3
package/index.js
CHANGED
|
@@ -111,13 +111,15 @@ const default_config = {
|
|
|
111
111
|
alias: ["mainnet", "eth", "0x1"],
|
|
112
112
|
beacon_apis: ["https://lodestar-mainnet.chainsafe.io"],
|
|
113
113
|
rpcs: ["https://rpc.ankr.com/eth"],
|
|
114
|
-
proofer: ["https://
|
|
114
|
+
proofer: ["https://mainnet1.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, {
|
|
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
|
|
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 {
|
|
@@ -308,7 +322,7 @@ export default class C4Client {
|
|
|
308
322
|
return result;
|
|
309
323
|
}
|
|
310
324
|
catch (error) {
|
|
311
|
-
const providerError = ProviderRpcError.createError(error);
|
|
325
|
+
const providerError = ProviderRpcError.createError(error, args);
|
|
312
326
|
this.connectionState.processFailedRequest(providerError);
|
|
313
327
|
throw providerError;
|
|
314
328
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@corpus-core/colibri-stateless",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.2",
|
|
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",
|
package/subscriptionManager.js
CHANGED
|
@@ -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 {
|
package/types.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ export declare class ProviderRpcError extends Error {
|
|
|
2
2
|
code: number;
|
|
3
3
|
data?: unknown;
|
|
4
4
|
constructor(code: number, message: string, data?: unknown);
|
|
5
|
-
static createError(error: any): ProviderRpcError;
|
|
5
|
+
static createError(error: any, args?: RequestArguments): ProviderRpcError;
|
|
6
6
|
}
|
|
7
7
|
export interface ColibriClient {
|
|
8
8
|
rpc(method: string, params: any[], method_type?: MethodType): Promise<any>;
|
package/types.js
CHANGED
|
@@ -12,14 +12,14 @@ export class ProviderRpcError extends Error {
|
|
|
12
12
|
}
|
|
13
13
|
Object.setPrototypeOf(this, ProviderRpcError.prototype);
|
|
14
14
|
}
|
|
15
|
-
static createError(error) {
|
|
15
|
+
static createError(error, args) {
|
|
16
16
|
let providerError;
|
|
17
17
|
if (error instanceof ProviderRpcError) {
|
|
18
18
|
providerError = error;
|
|
19
19
|
}
|
|
20
20
|
else {
|
|
21
21
|
let code;
|
|
22
|
-
let message = error?.message || 'An unknown error occurred';
|
|
22
|
+
let message = (error?.message || 'An unknown error occurred');
|
|
23
23
|
const originalData = error?.data;
|
|
24
24
|
if (typeof message === 'string' && message.startsWith('Method ') && message.endsWith(' is not supported')) {
|
|
25
25
|
code = 4200;
|
|
@@ -30,7 +30,7 @@ export class ProviderRpcError extends Error {
|
|
|
30
30
|
else {
|
|
31
31
|
code = (typeof error?.code === 'number') ? error.code : -32603;
|
|
32
32
|
}
|
|
33
|
-
providerError = new ProviderRpcError(code, message, originalData);
|
|
33
|
+
providerError = new ProviderRpcError(code, 'Error in rpc call ' + (args?.method || '') + JSON.stringify(args?.params || []) + ' : ' + message, originalData);
|
|
34
34
|
}
|
|
35
35
|
return providerError;
|
|
36
36
|
}
|