@lodestar/prover 1.9.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/LICENSE +201 -0
- package/README.md +135 -0
- package/lib/cli/applyPreset.d.ts +2 -0
- package/lib/cli/applyPreset.js +72 -0
- package/lib/cli/applyPreset.js.map +1 -0
- package/lib/cli/cli.d.ts +8 -0
- package/lib/cli/cli.js +50 -0
- package/lib/cli/cli.js.map +1 -0
- package/lib/cli/cmds/index.d.ts +4 -0
- package/lib/cli/cmds/index.js +3 -0
- package/lib/cli/cmds/index.js.map +1 -0
- package/lib/cli/cmds/start/handler.d.ts +7 -0
- package/lib/cli/cmds/start/handler.js +30 -0
- package/lib/cli/cmds/start/handler.js.map +1 -0
- package/lib/cli/cmds/start/index.d.ts +5 -0
- package/lib/cli/cmds/start/index.js +15 -0
- package/lib/cli/cmds/start/index.js.map +1 -0
- package/lib/cli/cmds/start/options.d.ts +27 -0
- package/lib/cli/cmds/start/options.js +67 -0
- package/lib/cli/cmds/start/options.js.map +1 -0
- package/lib/cli/index.d.ts +4 -0
- package/lib/cli/index.js +25 -0
- package/lib/cli/index.js.map +1 -0
- package/lib/cli/options.d.ts +22 -0
- package/lib/cli/options.js +50 -0
- package/lib/cli/options.js.map +1 -0
- package/lib/constants.d.ts +6 -0
- package/lib/constants.js +7 -0
- package/lib/constants.js.map +1 -0
- package/lib/index.d.ts +4 -0
- package/lib/index.js +4 -0
- package/lib/index.js.map +1 -0
- package/lib/index.web.d.ts +3 -0
- package/lib/index.web.js +3 -0
- package/lib/index.web.js.map +1 -0
- package/lib/interfaces.d.ts +69 -0
- package/lib/interfaces.js +6 -0
- package/lib/interfaces.js.map +1 -0
- package/lib/proof_provider/ordered_map.d.ts +8 -0
- package/lib/proof_provider/ordered_map.js +24 -0
- package/lib/proof_provider/ordered_map.js.map +1 -0
- package/lib/proof_provider/payload_store.d.ts +25 -0
- package/lib/proof_provider/payload_store.js +154 -0
- package/lib/proof_provider/payload_store.js.map +1 -0
- package/lib/proof_provider/proof_provider.d.ts +36 -0
- package/lib/proof_provider/proof_provider.js +171 -0
- package/lib/proof_provider/proof_provider.js.map +1 -0
- package/lib/types.d.ts +136 -0
- package/lib/types.js +3 -0
- package/lib/types.js.map +1 -0
- package/lib/utils/assertion.d.ts +10 -0
- package/lib/utils/assertion.js +34 -0
- package/lib/utils/assertion.js.map +1 -0
- package/lib/utils/command.d.ts +22 -0
- package/lib/utils/command.js +27 -0
- package/lib/utils/command.js.map +1 -0
- package/lib/utils/consensus.d.ts +19 -0
- package/lib/utils/consensus.js +74 -0
- package/lib/utils/consensus.js.map +1 -0
- package/lib/utils/conversion.d.ts +47 -0
- package/lib/utils/conversion.js +94 -0
- package/lib/utils/conversion.js.map +1 -0
- package/lib/utils/errors.d.ts +6 -0
- package/lib/utils/errors.js +6 -0
- package/lib/utils/errors.js.map +1 -0
- package/lib/utils/evm.d.ts +44 -0
- package/lib/utils/evm.js +193 -0
- package/lib/utils/evm.js.map +1 -0
- package/lib/utils/execution.d.ts +12 -0
- package/lib/utils/execution.js +53 -0
- package/lib/utils/execution.js.map +1 -0
- package/lib/utils/file.d.ts +8 -0
- package/lib/utils/file.js +50 -0
- package/lib/utils/file.js.map +1 -0
- package/lib/utils/gitData/gitDataPath.d.ts +17 -0
- package/lib/utils/gitData/gitDataPath.js +37 -0
- package/lib/utils/gitData/gitDataPath.js.map +1 -0
- package/lib/utils/gitData/index.d.ts +6 -0
- package/lib/utils/gitData/index.js +68 -0
- package/lib/utils/gitData/index.js.map +1 -0
- package/lib/utils/gitData/writeGitData.d.ts +3 -0
- package/lib/utils/gitData/writeGitData.js +8 -0
- package/lib/utils/gitData/writeGitData.js.map +1 -0
- package/lib/utils/json_rpc.d.ts +17 -0
- package/lib/utils/json_rpc.js +115 -0
- package/lib/utils/json_rpc.js.map +1 -0
- package/lib/utils/logger.d.ts +4 -0
- package/lib/utils/logger.js +12 -0
- package/lib/utils/logger.js.map +1 -0
- package/lib/utils/process.d.ts +20 -0
- package/lib/utils/process.js +75 -0
- package/lib/utils/process.js.map +1 -0
- package/lib/utils/req_resp.d.ts +5 -0
- package/lib/utils/req_resp.js +33 -0
- package/lib/utils/req_resp.js.map +1 -0
- package/lib/utils/rpc.d.ts +26 -0
- package/lib/utils/rpc.js +55 -0
- package/lib/utils/rpc.js.map +1 -0
- package/lib/utils/validation.d.ts +30 -0
- package/lib/utils/validation.js +94 -0
- package/lib/utils/validation.js.map +1 -0
- package/lib/utils/verification.d.ts +34 -0
- package/lib/utils/verification.js +62 -0
- package/lib/utils/verification.js.map +1 -0
- package/lib/utils/version.d.ts +12 -0
- package/lib/utils/version.js +59 -0
- package/lib/utils/version.js.map +1 -0
- package/lib/verified_requests/eth_call.d.ts +4 -0
- package/lib/verified_requests/eth_call.js +33 -0
- package/lib/verified_requests/eth_call.js.map +1 -0
- package/lib/verified_requests/eth_estimateGas.d.ts +4 -0
- package/lib/verified_requests/eth_estimateGas.js +33 -0
- package/lib/verified_requests/eth_estimateGas.js.map +1 -0
- package/lib/verified_requests/eth_getBalance.d.ts +3 -0
- package/lib/verified_requests/eth_getBalance.js +13 -0
- package/lib/verified_requests/eth_getBalance.js.map +1 -0
- package/lib/verified_requests/eth_getBlockByHash.d.ts +4 -0
- package/lib/verified_requests/eth_getBlockByHash.js +12 -0
- package/lib/verified_requests/eth_getBlockByHash.js.map +1 -0
- package/lib/verified_requests/eth_getBlockByNumber.d.ts +7 -0
- package/lib/verified_requests/eth_getBlockByNumber.js +12 -0
- package/lib/verified_requests/eth_getBlockByNumber.js.map +1 -0
- package/lib/verified_requests/eth_getCode.d.ts +3 -0
- package/lib/verified_requests/eth_getCode.js +32 -0
- package/lib/verified_requests/eth_getCode.js.map +1 -0
- package/lib/verified_requests/eth_getTransactionCount.d.ts +6 -0
- package/lib/verified_requests/eth_getTransactionCount.js +13 -0
- package/lib/verified_requests/eth_getTransactionCount.js.map +1 -0
- package/lib/web3_provider.d.ts +14 -0
- package/lib/web3_provider.js +138 -0
- package/lib/web3_provider.js.map +1 -0
- package/lib/web3_proxy.d.ts +13 -0
- package/lib/web3_proxy.js +136 -0
- package/lib/web3_proxy.js.map +1 -0
- package/package.json +100 -0
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import { getClient } from "@lodestar/api/beacon";
|
|
2
|
+
import { createChainForkConfig } from "@lodestar/config";
|
|
3
|
+
import { networksChainConfig } from "@lodestar/config/networks";
|
|
4
|
+
import { Lightclient, LightclientEvent, RunStatusCode } from "@lodestar/light-client";
|
|
5
|
+
import { LightClientRestTransport } from "@lodestar/light-client/transport";
|
|
6
|
+
import { isForkWithdrawals } from "@lodestar/params";
|
|
7
|
+
import { LCTransport } from "../interfaces.js";
|
|
8
|
+
import { assertLightClient } from "../utils/assertion.js";
|
|
9
|
+
import { getExecutionPayloads, getGenesisData, getSyncCheckpoint, getUnFinalizedRangeForPayloads, } from "../utils/consensus.js";
|
|
10
|
+
import { bufferToHex } from "../utils/conversion.js";
|
|
11
|
+
import { PayloadStore } from "./payload_store.js";
|
|
12
|
+
export class ProofProvider {
|
|
13
|
+
constructor(opts) {
|
|
14
|
+
this.opts = opts;
|
|
15
|
+
this.store = new PayloadStore({ api: opts.api, logger: opts.logger });
|
|
16
|
+
this.logger = opts.logger;
|
|
17
|
+
this.config = opts.config;
|
|
18
|
+
this.api = opts.api;
|
|
19
|
+
this.network = opts.config.PRESET_BASE;
|
|
20
|
+
}
|
|
21
|
+
async waitToBeReady() {
|
|
22
|
+
return this.readyPromise;
|
|
23
|
+
}
|
|
24
|
+
static init(opts) {
|
|
25
|
+
if (opts.transport === LCTransport.P2P) {
|
|
26
|
+
throw new Error("P2P mode not supported yet");
|
|
27
|
+
}
|
|
28
|
+
opts.logger.info("Creating ProofProvider instance with REST APIs", {
|
|
29
|
+
network: opts.network,
|
|
30
|
+
urls: opts.urls.join(","),
|
|
31
|
+
});
|
|
32
|
+
const config = opts.network
|
|
33
|
+
? createChainForkConfig(networksChainConfig[opts.network])
|
|
34
|
+
: createChainForkConfig(opts.config);
|
|
35
|
+
const api = getClient({ urls: opts.urls }, { config });
|
|
36
|
+
const transport = new LightClientRestTransport(api);
|
|
37
|
+
const provider = new ProofProvider({
|
|
38
|
+
...opts,
|
|
39
|
+
config,
|
|
40
|
+
api,
|
|
41
|
+
transport,
|
|
42
|
+
});
|
|
43
|
+
provider.readyPromise = provider.sync(opts.wsCheckpoint).catch((e) => {
|
|
44
|
+
opts.logger.error("Error while syncing", e);
|
|
45
|
+
return Promise.reject(e);
|
|
46
|
+
});
|
|
47
|
+
return provider;
|
|
48
|
+
}
|
|
49
|
+
async sync(wsCheckpoint) {
|
|
50
|
+
if (this.lightClient !== undefined) {
|
|
51
|
+
throw Error("Light client already initialized and syncing.");
|
|
52
|
+
}
|
|
53
|
+
this.logger.info("Starting sync for proof provider");
|
|
54
|
+
const { api, config, transport } = this.opts;
|
|
55
|
+
const checkpointRoot = await getSyncCheckpoint(api, wsCheckpoint);
|
|
56
|
+
const genesisData = await getGenesisData(api);
|
|
57
|
+
this.logger.info("Initializing lightclient", { checkpointRoot: bufferToHex(checkpointRoot) });
|
|
58
|
+
this.lightClient = await Lightclient.initializeFromCheckpointRoot({
|
|
59
|
+
checkpointRoot,
|
|
60
|
+
config,
|
|
61
|
+
transport,
|
|
62
|
+
genesisData,
|
|
63
|
+
});
|
|
64
|
+
assertLightClient(this.lightClient);
|
|
65
|
+
// Wait for the lightclient to start
|
|
66
|
+
await new Promise((resolve) => {
|
|
67
|
+
var _a, _b;
|
|
68
|
+
const lightClientStarted = (status) => {
|
|
69
|
+
var _a;
|
|
70
|
+
if (status === RunStatusCode.started) {
|
|
71
|
+
(_a = this.lightClient) === null || _a === void 0 ? void 0 : _a.emitter.off(LightclientEvent.statusChange, lightClientStarted);
|
|
72
|
+
resolve();
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
(_a = this.lightClient) === null || _a === void 0 ? void 0 : _a.emitter.on(LightclientEvent.statusChange, lightClientStarted);
|
|
76
|
+
this.logger.info("Initiating lightclient");
|
|
77
|
+
(_b = this.lightClient) === null || _b === void 0 ? void 0 : _b.start();
|
|
78
|
+
});
|
|
79
|
+
this.logger.info("Lightclient synced", this.getStatus());
|
|
80
|
+
this.registerEvents();
|
|
81
|
+
// Load the payloads from the CL
|
|
82
|
+
this.logger.info("Building EL payload history");
|
|
83
|
+
const { start, end } = await getUnFinalizedRangeForPayloads(this.lightClient);
|
|
84
|
+
const payloads = await getExecutionPayloads({
|
|
85
|
+
api: this.opts.api,
|
|
86
|
+
startSlot: start,
|
|
87
|
+
endSlot: end,
|
|
88
|
+
logger: this.logger,
|
|
89
|
+
});
|
|
90
|
+
for (const payload of Object.values(payloads)) {
|
|
91
|
+
this.store.set(payload, false);
|
|
92
|
+
}
|
|
93
|
+
// Load the finalized payload from the CL
|
|
94
|
+
const finalizedSlot = this.lightClient.getFinalized().beacon.slot;
|
|
95
|
+
this.logger.debug("Getting finalized slot from lightclient", { finalizedSlot });
|
|
96
|
+
const finalizedPayload = await getExecutionPayloads({
|
|
97
|
+
api: this.opts.api,
|
|
98
|
+
startSlot: finalizedSlot,
|
|
99
|
+
endSlot: finalizedSlot,
|
|
100
|
+
logger: this.logger,
|
|
101
|
+
});
|
|
102
|
+
this.store.set(finalizedPayload[finalizedSlot], true);
|
|
103
|
+
this.logger.info("Proof provider ready");
|
|
104
|
+
}
|
|
105
|
+
getStatus() {
|
|
106
|
+
if (!this.lightClient) {
|
|
107
|
+
return {
|
|
108
|
+
latest: 0,
|
|
109
|
+
finalized: 0,
|
|
110
|
+
status: RunStatusCode.uninitialized,
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
return {
|
|
114
|
+
latest: this.lightClient.getHead().beacon.slot,
|
|
115
|
+
finalized: this.lightClient.getFinalized().beacon.slot,
|
|
116
|
+
status: this.lightClient.status,
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
async getExecutionPayload(blockNumber) {
|
|
120
|
+
assertLightClient(this.lightClient);
|
|
121
|
+
if (typeof blockNumber === "string" && blockNumber === "finalized") {
|
|
122
|
+
const payload = this.store.finalized;
|
|
123
|
+
if (!payload)
|
|
124
|
+
throw new Error("No finalized payload");
|
|
125
|
+
return payload;
|
|
126
|
+
}
|
|
127
|
+
if (typeof blockNumber === "string" && blockNumber === "latest") {
|
|
128
|
+
const payload = this.store.latest;
|
|
129
|
+
if (!payload)
|
|
130
|
+
throw new Error("No latest payload");
|
|
131
|
+
return payload;
|
|
132
|
+
}
|
|
133
|
+
if ((typeof blockNumber === "string" && blockNumber.startsWith("0x")) || typeof blockNumber === "number") {
|
|
134
|
+
const payload = await this.store.get(blockNumber);
|
|
135
|
+
if (!payload)
|
|
136
|
+
throw new Error(`No payload for blockNumber ${blockNumber}`);
|
|
137
|
+
return payload;
|
|
138
|
+
}
|
|
139
|
+
throw new Error(`Invalid blockNumber "${blockNumber}"`);
|
|
140
|
+
}
|
|
141
|
+
async processLCHeader(lcHeader, finalized = false) {
|
|
142
|
+
const fork = this.opts.config.getForkName(lcHeader.beacon.slot);
|
|
143
|
+
if (!isForkWithdrawals(fork)) {
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
const sszType = this.opts.config.getExecutionForkTypes(lcHeader.beacon.slot).ExecutionPayloadHeader;
|
|
147
|
+
if (isForkWithdrawals(fork) &&
|
|
148
|
+
(!("execution" in lcHeader) || sszType.equals(lcHeader.execution, sszType.defaultValue()))) {
|
|
149
|
+
throw new Error("Execution payload is required for execution fork");
|
|
150
|
+
}
|
|
151
|
+
await this.store.processLCHeader(lcHeader, finalized);
|
|
152
|
+
}
|
|
153
|
+
registerEvents() {
|
|
154
|
+
assertLightClient(this.lightClient);
|
|
155
|
+
this.opts.signal.addEventListener("abort", () => {
|
|
156
|
+
var _a;
|
|
157
|
+
(_a = this.lightClient) === null || _a === void 0 ? void 0 : _a.stop();
|
|
158
|
+
});
|
|
159
|
+
this.lightClient.emitter.on(LightclientEvent.lightClientFinalityHeader, async (data) => {
|
|
160
|
+
await this.processLCHeader(data, true).catch((e) => {
|
|
161
|
+
this.logger.error("Error processing finality update", null, e);
|
|
162
|
+
});
|
|
163
|
+
});
|
|
164
|
+
this.lightClient.emitter.on(LightclientEvent.lightClientOptimisticHeader, async (data) => {
|
|
165
|
+
await this.processLCHeader(data).catch((e) => {
|
|
166
|
+
this.logger.error("Error processing optimistic update", null, e);
|
|
167
|
+
});
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
//# sourceMappingURL=proof_provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"proof_provider.js","sourceRoot":"","sources":["../../src/proof_provider/proof_provider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAM,SAAS,EAAC,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAkB,qBAAqB,EAAC,MAAM,kBAAkB,CAAC;AACxE,OAAO,EAAc,mBAAmB,EAAC,MAAM,2BAA2B,CAAC;AAC3E,OAAO,EAAC,WAAW,EAAE,gBAAgB,EAAE,aAAa,EAAC,MAAM,wBAAwB,CAAC;AACpF,OAAO,EAAC,wBAAwB,EAAC,MAAM,kCAAkC,CAAC;AAC1E,OAAO,EAAC,iBAAiB,EAAC,MAAM,kBAAkB,CAAC;AAGnD,OAAO,EAAC,WAAW,EAA0B,MAAM,kBAAkB,CAAC;AACtE,OAAO,EAAC,iBAAiB,EAAC,MAAM,uBAAuB,CAAC;AACxD,OAAO,EACL,oBAAoB,EACpB,cAAc,EACd,iBAAiB,EACjB,8BAA8B,GAC/B,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAC,WAAW,EAAC,MAAM,wBAAwB,CAAC;AACnD,OAAO,EAAC,YAAY,EAAC,MAAM,oBAAoB,CAAC;AAQhD,MAAM,OAAO,aAAa;IAYxB,YAAqB,IAAyB;QAAzB,SAAI,GAAJ,IAAI,CAAqB;QAC5C,IAAI,CAAC,KAAK,GAAG,IAAI,YAAY,CAAC,EAAC,GAAG,EA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AEpC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,gBAAgB,CAAC,OAAO,EAAE,GAAG,EAAE;;YAC9C,MAAA,IAAI,CAAC,WAAW,0CAAE,IAAI,EAAE,CAAC;QAC3B,CAAC,CAAC,CAAC;QAEH,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,EAAE,CAAC,gBAAgB,CAAC,yBAAyB,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE;YACrF,MAAM,IAAI,CAAC,eAAe,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE;gBACjD,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,kCAAkC,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;YACjE,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;QAEH,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,EAAE,CAAC,gBAAgB,CAAC,2BAA2B,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE;YACvF,MAAM,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE;gBAC3C,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,oCAAoC,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;YACnE,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC;CACF"}
|
package/lib/types.d.ts
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
export type JsonRpcId = number | string;
|
|
3
|
+
export type JsonRpcVersion = string | ("2.0" | "1.0");
|
|
4
|
+
export interface JsonRpcRequestPayload<T = unknown[]> {
|
|
5
|
+
readonly jsonrpc: JsonRpcVersion;
|
|
6
|
+
readonly id: JsonRpcId;
|
|
7
|
+
readonly method: string;
|
|
8
|
+
readonly params: T;
|
|
9
|
+
readonly requestOptions?: unknown;
|
|
10
|
+
}
|
|
11
|
+
export interface JsonRpcNotificationPayload<T = unknown[]> {
|
|
12
|
+
readonly jsonrpc: JsonRpcVersion;
|
|
13
|
+
readonly method: string;
|
|
14
|
+
readonly params: T;
|
|
15
|
+
readonly requestOptions?: unknown;
|
|
16
|
+
}
|
|
17
|
+
export type JsonRpcRequest<T = unknown[]> = JsonRpcRequestPayload<T> | JsonRpcNotificationPayload<T>;
|
|
18
|
+
export type JsonRpcBatchRequest<T = unknown[]> = JsonRpcRequest<T>[];
|
|
19
|
+
export type JsonRpcRequestOrBatch<T = unknown[]> = JsonRpcRequest<T> | JsonRpcBatchRequest<T>;
|
|
20
|
+
export interface JsonRpcResponseWithResultPayload<T> {
|
|
21
|
+
readonly id: number | string;
|
|
22
|
+
jsonrpc: string;
|
|
23
|
+
result: T;
|
|
24
|
+
error?: never;
|
|
25
|
+
}
|
|
26
|
+
export interface JsonRpcErrorPayload<T> {
|
|
27
|
+
readonly code?: number;
|
|
28
|
+
readonly data?: T;
|
|
29
|
+
readonly message: string;
|
|
30
|
+
}
|
|
31
|
+
export interface JsonRpcResponseWithErrorPayload<T> {
|
|
32
|
+
readonly id: number | string;
|
|
33
|
+
jsonrpc: string;
|
|
34
|
+
result?: never;
|
|
35
|
+
error: JsonRpcErrorPayload<T>;
|
|
36
|
+
}
|
|
37
|
+
export type JsonRpcResponse<T = any, E = any> = JsonRpcResponseWithResultPayload<T> | JsonRpcResponseWithErrorPayload<E>;
|
|
38
|
+
export type JsonRpcBatchResponse<T = any, E = any> = JsonRpcResponse<T, E>[];
|
|
39
|
+
export type JsonRpcResponseOrBatch<T = any, E = any> = JsonRpcResponse<T, E> | JsonRpcBatchResponse<T, E>;
|
|
40
|
+
export type HexString = string;
|
|
41
|
+
export type ELBlockNumberOrTag = number | string | "latest" | "earliest" | "pending";
|
|
42
|
+
export interface ELProof {
|
|
43
|
+
readonly address: string;
|
|
44
|
+
readonly balance: string;
|
|
45
|
+
readonly codeHash: string;
|
|
46
|
+
readonly nonce: string;
|
|
47
|
+
readonly storageHash: string;
|
|
48
|
+
readonly accountProof: string[];
|
|
49
|
+
readonly storageProof: {
|
|
50
|
+
readonly key: string;
|
|
51
|
+
readonly value: string;
|
|
52
|
+
readonly proof: string[];
|
|
53
|
+
}[];
|
|
54
|
+
}
|
|
55
|
+
export interface ELTransaction {
|
|
56
|
+
readonly type: string;
|
|
57
|
+
readonly nonce: string;
|
|
58
|
+
readonly to: string | null;
|
|
59
|
+
readonly chainId?: string;
|
|
60
|
+
readonly input: string;
|
|
61
|
+
readonly value: string;
|
|
62
|
+
readonly gasPrice?: string;
|
|
63
|
+
readonly gas: string;
|
|
64
|
+
readonly maxFeePerGas?: string;
|
|
65
|
+
readonly maxPriorityFeePerGas?: string;
|
|
66
|
+
readonly blockHash: string;
|
|
67
|
+
readonly blockNumber: string;
|
|
68
|
+
readonly from: string;
|
|
69
|
+
readonly hash: string;
|
|
70
|
+
readonly r: string;
|
|
71
|
+
readonly s: string;
|
|
72
|
+
readonly v: string;
|
|
73
|
+
readonly transactionIndex: string;
|
|
74
|
+
readonly accessList?: {
|
|
75
|
+
address: string;
|
|
76
|
+
storageKeys: string[];
|
|
77
|
+
}[];
|
|
78
|
+
readonly data?: string;
|
|
79
|
+
}
|
|
80
|
+
export interface ELWithdrawal {
|
|
81
|
+
readonly index: string;
|
|
82
|
+
readonly validatorIndex: string;
|
|
83
|
+
readonly address: string;
|
|
84
|
+
readonly amount: string;
|
|
85
|
+
}
|
|
86
|
+
export interface ELBlock {
|
|
87
|
+
readonly parentHash: string;
|
|
88
|
+
readonly stateRoot: string;
|
|
89
|
+
readonly receiptsRoot: string;
|
|
90
|
+
readonly logsBloom: string;
|
|
91
|
+
readonly nonce: string;
|
|
92
|
+
readonly difficulty: string;
|
|
93
|
+
readonly totalDifficulty: string;
|
|
94
|
+
readonly number: string;
|
|
95
|
+
readonly gasLimit: string;
|
|
96
|
+
readonly gasUsed: string;
|
|
97
|
+
readonly timestamp: string;
|
|
98
|
+
readonly extraData?: Buffer | string;
|
|
99
|
+
readonly mixHash: string;
|
|
100
|
+
readonly hash: string;
|
|
101
|
+
readonly baseFeePerGas: string;
|
|
102
|
+
readonly miner: string;
|
|
103
|
+
readonly sha3Uncles: string;
|
|
104
|
+
readonly size: string;
|
|
105
|
+
readonly uncles: ELBlock[];
|
|
106
|
+
readonly transactions: ELTransaction[];
|
|
107
|
+
readonly transactionsRoot: string;
|
|
108
|
+
readonly withdrawals?: ELWithdrawal[];
|
|
109
|
+
readonly withdrawalsRoot?: string;
|
|
110
|
+
}
|
|
111
|
+
export interface ELAccessList {
|
|
112
|
+
readonly address: HexString;
|
|
113
|
+
readonly storageKeys: HexString[];
|
|
114
|
+
}
|
|
115
|
+
export interface ELAccessListResponse {
|
|
116
|
+
readonly error: string;
|
|
117
|
+
readonly gasUsed: HexString;
|
|
118
|
+
readonly accessList: ELAccessList[];
|
|
119
|
+
}
|
|
120
|
+
export type ELStorageProof = Pick<ELProof, "storageHash" | "storageProof">;
|
|
121
|
+
export type ELApi = {
|
|
122
|
+
eth_createAccessList: (transaction: ELTransaction, block?: ELBlockNumberOrTag) => ELAccessListResponse;
|
|
123
|
+
eth_call: (transaction: ELTransaction, block?: ELBlockNumberOrTag) => HexString;
|
|
124
|
+
eth_estimateGas: (transaction: ELTransaction, block?: ELBlockNumberOrTag) => HexString;
|
|
125
|
+
eth_getCode: (address: string, block?: ELBlockNumberOrTag) => HexString;
|
|
126
|
+
eth_getProof: (address: string, storageKeys: string[], block?: ELBlockNumberOrTag) => ELProof;
|
|
127
|
+
eth_getBlockByNumber: (block: ELBlockNumberOrTag, hydrated?: boolean) => ELBlock | undefined;
|
|
128
|
+
eth_getBlockByHash: (block: string, hydrated?: boolean) => ELBlock | undefined;
|
|
129
|
+
};
|
|
130
|
+
export type ELApiParams = {
|
|
131
|
+
[K in keyof ELApi]: Parameters<ELApi[K]>;
|
|
132
|
+
};
|
|
133
|
+
export type ELApiReturn = {
|
|
134
|
+
[K in keyof ELApi]: ReturnType<ELApi[K]>;
|
|
135
|
+
};
|
|
136
|
+
//# sourceMappingURL=types.d.ts.map
|
package/lib/types.js
ADDED
package/lib/types.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";AAmKA,wDAAwD"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Lightclient } from "@lodestar/light-client";
|
|
2
|
+
import { EIP1193Provider, EthersProvider, RequestProvider, SendAsyncProvider, SendProvider, Web3Provider } from "../interfaces.js";
|
|
3
|
+
export declare function assertLightClient(client?: Lightclient): asserts client is Lightclient;
|
|
4
|
+
export declare function isSendProvider(provider: Web3Provider): provider is SendProvider;
|
|
5
|
+
export declare function isEthersProvider(provider: Web3Provider): provider is EthersProvider;
|
|
6
|
+
export declare function isRequestProvider(provider: Web3Provider): provider is RequestProvider;
|
|
7
|
+
export declare function isSendAsyncProvider(provider: Web3Provider): provider is SendAsyncProvider;
|
|
8
|
+
export declare function isEIP1193Provider(provider: Web3Provider): provider is EIP1193Provider;
|
|
9
|
+
export declare function isTruthy<T = unknown>(value: T): value is Exclude<T, undefined | null>;
|
|
10
|
+
//# sourceMappingURL=assertion.d.ts.map
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export function assertLightClient(client) {
|
|
2
|
+
if (!client) {
|
|
3
|
+
throw new Error("Light client is not initialized yet.");
|
|
4
|
+
}
|
|
5
|
+
}
|
|
6
|
+
export function isSendProvider(provider) {
|
|
7
|
+
return ("send" in provider &&
|
|
8
|
+
typeof provider.send === "function" &&
|
|
9
|
+
provider.send.length > 1 &&
|
|
10
|
+
provider.send.constructor.name !== "AsyncFunction");
|
|
11
|
+
}
|
|
12
|
+
export function isEthersProvider(provider) {
|
|
13
|
+
return ("send" in provider &&
|
|
14
|
+
typeof provider.send === "function" &&
|
|
15
|
+
provider.send.length > 1 &&
|
|
16
|
+
provider.send.constructor.name === "AsyncFunction");
|
|
17
|
+
}
|
|
18
|
+
export function isRequestProvider(provider) {
|
|
19
|
+
return "request" in provider && typeof provider.request === "function" && provider.request.length > 1;
|
|
20
|
+
}
|
|
21
|
+
export function isSendAsyncProvider(provider) {
|
|
22
|
+
return ("sendAsync" in provider &&
|
|
23
|
+
typeof provider.sendAsync === "function" &&
|
|
24
|
+
provider.sendAsync.constructor.name === "AsyncFunction");
|
|
25
|
+
}
|
|
26
|
+
export function isEIP1193Provider(provider) {
|
|
27
|
+
return ("request" in provider &&
|
|
28
|
+
typeof provider.request === "function" &&
|
|
29
|
+
provider.request.constructor.name === "AsyncFunction");
|
|
30
|
+
}
|
|
31
|
+
export function isTruthy(value) {
|
|
32
|
+
return value !== undefined && value !== null && value !== false;
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=assertion.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assertion.js","sourceRoot":"","sources":["../../src/utils/assertion.ts"],"names":[],"mappings":"AAUA,MAAM,UAAU,iBAAiB,CAAC,MAAoB;IACpD,IAAI,CAAC,MAAM,EAAE;QACX,MAAM,IAAI,KAAK,CAAC,sCAAsC,CAAC,CAAC;KACzD;AACH,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,QAAsB;IACnD,OAAO,CACL,MAAM,IAAI,QAAQ;QAClB,OAAO,QAAQ,CAAC,IAAI,KAAK,UAAU;QACnC,QAAQ,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC;QACxB,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,KAAK,eAAe,CACnD,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,QAAsB;IACrD,OAAO,CACL,MAAM,IAAI,QAAQ;QAClB,OAAO,QAAQ,CAAC,IAAI,KAAK,UAAU;QACnC,QAAQ,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC;QACxB,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,KAAK,eAAe,CACnD,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,QAAsB;IACtD,OAAO,SAAS,IAAI,QAAQ,IAAI,OAAO,QAAQ,CAAC,OAAO,KAAK,UAAU,IAAI,QAAQ,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC;AACxG,CAAC;AAED,MAAM,UAAU,mBAAmB,CAAC,QAAsB;IACxD,OAAO,CACL,WAAW,IAAI,QAAQ;QACvB,OAAO,QAAQ,CAAC,SAAS,KAAK,UAAU;QACxC,QAAQ,CAAC,SAAS,CAAC,WAAW,CAAC,IAAI,KAAK,eAAe,CACxD,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,QAAsB;IACtD,OAAO,CACL,SAAS,IAAI,QAAQ;QACrB,OAAO,QAAQ,CAAC,OAAO,KAAK,UAAU;QACtC,QAAQ,CAAC,OAAO,CAAC,WAAW,CAAC,IAAI,KAAK,eAAe,CACtD,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,QAAQ,CAAc,KAAQ;IAC5C,OAAO,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,KAAK,CAAC;AAClE,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Options, Argv } from "yargs";
|
|
2
|
+
export type CliCommandOptions<OwnArgs> = Required<{
|
|
3
|
+
[key in keyof OwnArgs]: Options;
|
|
4
|
+
}>;
|
|
5
|
+
export interface CliCommand<OwnArgs = Record<never, never>, ParentArgs = Record<never, never>, R = any> {
|
|
6
|
+
command: string;
|
|
7
|
+
describe: string;
|
|
8
|
+
examples?: {
|
|
9
|
+
command: string;
|
|
10
|
+
description: string;
|
|
11
|
+
}[];
|
|
12
|
+
options?: CliCommandOptions<OwnArgs>;
|
|
13
|
+
subcommands?: CliCommand<any, OwnArgs & ParentArgs>[];
|
|
14
|
+
handler?: (args: OwnArgs & ParentArgs) => Promise<R>;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Register a CliCommand type to yargs. Recursively registers subcommands too.
|
|
18
|
+
* @param yargs
|
|
19
|
+
* @param cliCommand
|
|
20
|
+
*/
|
|
21
|
+
export declare function registerCommandToYargs(yargs: Argv, cliCommand: CliCommand<any, any>): void;
|
|
22
|
+
//# sourceMappingURL=command.d.ts.map
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Register a CliCommand type to yargs. Recursively registers subcommands too.
|
|
3
|
+
* @param yargs
|
|
4
|
+
* @param cliCommand
|
|
5
|
+
*/
|
|
6
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
7
|
+
export function registerCommandToYargs(yargs, cliCommand) {
|
|
8
|
+
yargs.command({
|
|
9
|
+
command: cliCommand.command,
|
|
10
|
+
describe: cliCommand.describe,
|
|
11
|
+
builder: (yargsBuilder) => {
|
|
12
|
+
yargsBuilder.options(cliCommand.options || {});
|
|
13
|
+
for (const subcommand of cliCommand.subcommands || []) {
|
|
14
|
+
registerCommandToYargs(yargsBuilder, subcommand);
|
|
15
|
+
}
|
|
16
|
+
if (cliCommand.examples) {
|
|
17
|
+
for (const example of cliCommand.examples) {
|
|
18
|
+
yargsBuilder.example(`$0 ${example.command}`, example.description);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return yargs;
|
|
22
|
+
},
|
|
23
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
24
|
+
handler: cliCommand.handler || function emptyHandler() { },
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=command.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"command.js","sourceRoot":"","sources":["../../src/utils/command.ts"],"names":[],"mappings":"AAiBA;;;;GAIG;AACH,8DAA8D;AAC9D,MAAM,UAAU,sBAAsB,CAAC,KAAW,EAAE,UAAgC;IAClF,KAAK,CAAC,OAAO,CAAC;QACZ,OAAO,EAAE,UAAU,CAAC,OAAO;QAC3B,QAAQ,EAAE,UAAU,CAAC,QAAQ;QAC7B,OAAO,EAAE,CAAC,YAAY,EAAE,EAAE;YACxB,YAAY,CAAC,OAAO,CAAC,UAAU,CAAC,OAAO,IAAI,EAAE,CAAC,CAAC;YAC/C,KAAK,MAAM,UAAU,IAAI,UAAU,CAAC,WAAW,IAAI,EAAE,EAAE;gBACrD,sBAAsB,CAAC,YAAY,EAAE,UAAU,CAAC,CAAC;aAClD;YACD,IAAI,UAAU,CAAC,QAAQ,EAAE;gBACvB,KAAK,MAAM,OAAO,IAAI,UAAU,CAAC,QAAQ,EAAE;oBACzC,YAAY,CAAC,OAAO,CAAC,MAAM,OAAO,CAAC,OAAO,EAAE,EAAE,OAAO,CAAC,WAAW,CAAC,CAAC;iBACpE;aACF;YACD,OAAO,KAAK,CAAC;QACf,CAAC;QACD,gEAAgE;QAChE,OAAO,EAAE,UAAU,CAAC,OAAO,IAAI,SAAS,YAAY,KAAU,CAAC;KAChE,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Api } from "@lodestar/api/beacon";
|
|
2
|
+
import { allForks, Bytes32, capella } from "@lodestar/types";
|
|
3
|
+
import { GenesisData, Lightclient } from "@lodestar/light-client";
|
|
4
|
+
import { Logger } from "@lodestar/utils";
|
|
5
|
+
export declare function fetchNearestBlock(api: Api, slot: number, direction?: "up" | "down"): Promise<capella.SignedBeaconBlock>;
|
|
6
|
+
export declare function getUnFinalizedRangeForPayloads(lightClient: Lightclient): Promise<{
|
|
7
|
+
start: number;
|
|
8
|
+
end: number;
|
|
9
|
+
}>;
|
|
10
|
+
export declare function getExecutionPayloads({ api, startSlot, endSlot, logger, }: {
|
|
11
|
+
api: Api;
|
|
12
|
+
startSlot: number;
|
|
13
|
+
endSlot: number;
|
|
14
|
+
logger: Logger;
|
|
15
|
+
}): Promise<Record<number, allForks.ExecutionPayload>>;
|
|
16
|
+
export declare function getExecutionPayloadForBlockNumber(api: Api, startSlot: number, blockNumber: number): Promise<Record<number, allForks.ExecutionPayload>>;
|
|
17
|
+
export declare function getGenesisData(api: Pick<Api, "beacon">): Promise<GenesisData>;
|
|
18
|
+
export declare function getSyncCheckpoint(api: Pick<Api, "beacon">, checkpoint?: string): Promise<Bytes32>;
|
|
19
|
+
//# sourceMappingURL=consensus.d.ts.map
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { ApiError } from "@lodestar/api";
|
|
2
|
+
import { MAX_PAYLOAD_HISTORY } from "../constants.js";
|
|
3
|
+
import { hexToBuffer } from "./conversion.js";
|
|
4
|
+
export async function fetchNearestBlock(api, slot, direction = "down") {
|
|
5
|
+
const res = await api.beacon.getBlockV2(slot);
|
|
6
|
+
if (res.ok)
|
|
7
|
+
return res.response.data;
|
|
8
|
+
if (!res.ok && res.error.code === 404) {
|
|
9
|
+
return fetchNearestBlock(api, direction === "down" ? slot - 1 : slot + 1);
|
|
10
|
+
}
|
|
11
|
+
throw new Error(`Can not fetch nearest block for slot=${slot}`);
|
|
12
|
+
}
|
|
13
|
+
export async function getUnFinalizedRangeForPayloads(lightClient) {
|
|
14
|
+
const headSlot = lightClient.getHead().beacon.slot;
|
|
15
|
+
const finalizeSlot = lightClient.getFinalized().beacon.slot;
|
|
16
|
+
const endSlot = headSlot - MAX_PAYLOAD_HISTORY;
|
|
17
|
+
return {
|
|
18
|
+
start: headSlot,
|
|
19
|
+
end: endSlot < finalizeSlot ? finalizeSlot : endSlot,
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
export async function getExecutionPayloads({ api, startSlot, endSlot, logger, }) {
|
|
23
|
+
[startSlot, endSlot] = [Math.min(startSlot, endSlot), Math.max(startSlot, endSlot)];
|
|
24
|
+
if (startSlot === endSlot) {
|
|
25
|
+
logger.debug("Fetching EL payload", { slot: startSlot });
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
logger.debug("Fetching EL payloads", { startSlot, endSlot });
|
|
29
|
+
}
|
|
30
|
+
const payloads = {};
|
|
31
|
+
let slot = endSlot;
|
|
32
|
+
let block = await fetchNearestBlock(api, slot, "down");
|
|
33
|
+
payloads[block.message.slot] = block.message.body.executionPayload;
|
|
34
|
+
while (slot >= startSlot) {
|
|
35
|
+
const previousBlock = await fetchNearestBlock(api, block.message.slot - 1, "down");
|
|
36
|
+
if (block.message.body.executionPayload.parentHash === previousBlock.message.body.executionPayload.blockHash) {
|
|
37
|
+
payloads[block.message.slot] = block.message.body.executionPayload;
|
|
38
|
+
}
|
|
39
|
+
slot = block.message.slot - 1;
|
|
40
|
+
block = previousBlock;
|
|
41
|
+
}
|
|
42
|
+
return payloads;
|
|
43
|
+
}
|
|
44
|
+
export async function getExecutionPayloadForBlockNumber(api, startSlot, blockNumber) {
|
|
45
|
+
const payloads = {};
|
|
46
|
+
let block = await fetchNearestBlock(api, startSlot, "down");
|
|
47
|
+
payloads[block.message.slot] = block.message.body.executionPayload;
|
|
48
|
+
while (payloads[block.message.slot].blockNumber !== blockNumber) {
|
|
49
|
+
const previousBlock = await fetchNearestBlock(api, block.message.slot - 1, "down");
|
|
50
|
+
block = previousBlock;
|
|
51
|
+
}
|
|
52
|
+
return payloads;
|
|
53
|
+
}
|
|
54
|
+
export async function getGenesisData(api) {
|
|
55
|
+
const res = await api.beacon.getGenesis();
|
|
56
|
+
ApiError.assert(res);
|
|
57
|
+
return {
|
|
58
|
+
genesisTime: Number(res.response.data.genesisTime),
|
|
59
|
+
genesisValidatorsRoot: res.response.data.genesisValidatorsRoot,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
export async function getSyncCheckpoint(api, checkpoint) {
|
|
63
|
+
let syncCheckpoint = checkpoint ? hexToBuffer(checkpoint) : undefined;
|
|
64
|
+
if (syncCheckpoint && syncCheckpoint.byteLength !== 32) {
|
|
65
|
+
throw Error(`Checkpoint root must be 32 bytes. length=${syncCheckpoint.byteLength}`);
|
|
66
|
+
}
|
|
67
|
+
if (!syncCheckpoint) {
|
|
68
|
+
const res = await api.beacon.getStateFinalityCheckpoints("head");
|
|
69
|
+
ApiError.assert(res);
|
|
70
|
+
syncCheckpoint = res.response.data.finalized.root;
|
|
71
|
+
}
|
|
72
|
+
return syncCheckpoint;
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=consensus.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"consensus.js","sourceRoot":"","sources":["../../src/utils/consensus.ts"],"names":[],"mappings":"AAGA,OAAO,EAAC,QAAQ,EAAC,MAAM,eAAe,CAAC;AAEvC,OAAO,EAAC,mBAAmB,EAAC,MAAM,iBAAiB,CAAC;AACpD,OAAO,EAAC,WAAW,EAAC,MAAM,iBAAiB,CAAC;AAE5C,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,GAAQ,EACR,IAAY,EACZ,YAA2B,MAAM;IAEjC,MAAM,GAAG,GAAG,MAAM,GAAG,CAAC,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;IAE9C,IAAI,GAAG,CAAC,EAAE;QAAE,OAAO,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC;IAErC,IAAI,CAAC,GAAG,CAAC,EAAE,IAAI,GAAG,CAAC,KAAK,CAAC,IAAI,KAAK,GAAG,EAAE;QACrC,OAAO,iBAAiB,CAAC,GAAG,EAAE,SAAS,KAAK,MAAM,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC;KAC3E;IAED,MAAM,IAAI,KAAK,CAAC,wCAAwC,IAAI,EAAE,CAAC,CAAC;AAClE,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,8BAA8B,CAAC,WAAwB;IAC3E,MAAM,QAAQ,GAAG,WAAW,CAAC,OAAO,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC;IACnD,MAAM,YAAY,GAAG,WAAW,CAAC,YAAY,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC;IAC5D,MAAM,OAAO,GAAG,QAAQ,GAAG,mBAAmB,CAAC;IAE/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E,UAAmB;IACnF,IAAI,cAAc,GAAwB,UAAU,CAAC,CAAC,CAAC,WAAW,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IAE3F,IAAI,cAAc,IAAI,cAAc,CAAC,UAAU,KAAK,EAAE,EAAE;QACtD,MAAM,KAAK,CAAC,4CAA4C,cAAc,CAAC,UAAU,EAAE,CAAC,CAAC;KACtF;IAED,IAAI,CAAC,cAAc,EAAE;QACnB,MAAM,GAAG,GAAG,MAAM,GAAG,CAAC,MAAM,CAAC,2BAA2B,CAAC,MAAM,CAAC,CAAC;QACjE,QAAQ,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QACrB,cAAc,GAAG,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC;KACnD;IAED,OAAO,cAAc,CAAC;AACxB,CAAC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { BlockData, HeaderData } from "@ethereumjs/block";
|
|
3
|
+
import { ELBlock, ELTransaction } from "../types.js";
|
|
4
|
+
export declare function numberToHex(num: number | bigint): string;
|
|
5
|
+
export declare function hexToNumber(num: string): number;
|
|
6
|
+
export declare function hexToBigInt(num: string): bigint;
|
|
7
|
+
export declare function bigIntToHex(num: bigint): string;
|
|
8
|
+
export declare function bufferToHex(buffer: Buffer | Uint8Array): string;
|
|
9
|
+
export declare function hexToBuffer(val: string): Buffer;
|
|
10
|
+
export declare function padLeft<T extends Buffer | Uint8Array>(v: T, length: number): T;
|
|
11
|
+
export declare function headerDataFromELBlock(blockInfo: ELBlock): HeaderData;
|
|
12
|
+
export declare function txDataFromELBlock(txInfo: ELTransaction): {
|
|
13
|
+
data: string;
|
|
14
|
+
gasPrice: bigint | null;
|
|
15
|
+
gasLimit: string;
|
|
16
|
+
to: Buffer | undefined;
|
|
17
|
+
value: bigint | undefined;
|
|
18
|
+
maxFeePerGas: bigint | undefined;
|
|
19
|
+
maxPriorityFeePerGas: bigint | undefined;
|
|
20
|
+
type: string;
|
|
21
|
+
nonce: string;
|
|
22
|
+
chainId?: string | undefined;
|
|
23
|
+
input: string;
|
|
24
|
+
gas: string;
|
|
25
|
+
blockHash: string;
|
|
26
|
+
blockNumber: string;
|
|
27
|
+
from: string;
|
|
28
|
+
hash: string;
|
|
29
|
+
r: string;
|
|
30
|
+
s: string;
|
|
31
|
+
v: string;
|
|
32
|
+
transactionIndex: string;
|
|
33
|
+
accessList?: {
|
|
34
|
+
address: string;
|
|
35
|
+
storageKeys: string[];
|
|
36
|
+
}[] | undefined;
|
|
37
|
+
};
|
|
38
|
+
export declare function blockDataFromELBlock(blockInfo: ELBlock): BlockData;
|
|
39
|
+
export declare function cleanObject<T extends Record<string, unknown> | unknown[]>(obj: T): T;
|
|
40
|
+
/**
|
|
41
|
+
* Convert an array to array of chunks
|
|
42
|
+
* @example
|
|
43
|
+
* chunkIntoN([1,2,3,4], 2)
|
|
44
|
+
* => [[1,2], [3,4]]
|
|
45
|
+
*/
|
|
46
|
+
export declare function chunkIntoN<T extends unknown[]>(arr: T, n: number): T[];
|
|
47
|
+
//# sourceMappingURL=conversion.d.ts.map
|