@feelyourprotocol/vm 8141.0.0
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 +373 -0
- package/README.md +583 -0
- package/dist/cjs/bloom/index.d.ts +29 -0
- package/dist/cjs/bloom/index.d.ts.map +1 -0
- package/dist/cjs/bloom/index.js +76 -0
- package/dist/cjs/bloom/index.js.map +1 -0
- package/dist/cjs/buildBlock.d.ts +118 -0
- package/dist/cjs/buildBlock.d.ts.map +1 -0
- package/dist/cjs/buildBlock.js +363 -0
- package/dist/cjs/buildBlock.js.map +1 -0
- package/dist/cjs/constructors.d.ts +9 -0
- package/dist/cjs/constructors.d.ts.map +1 -0
- package/dist/cjs/constructors.js +75 -0
- package/dist/cjs/constructors.js.map +1 -0
- package/dist/cjs/emitEVMProfile.d.ts +9 -0
- package/dist/cjs/emitEVMProfile.d.ts.map +1 -0
- package/dist/cjs/emitEVMProfile.js +130 -0
- package/dist/cjs/emitEVMProfile.js.map +1 -0
- package/dist/cjs/index.d.ts +11 -0
- package/dist/cjs/index.d.ts.map +1 -0
- package/dist/cjs/index.js +36 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/params.d.ts +3 -0
- package/dist/cjs/params.d.ts.map +1 -0
- package/dist/cjs/params.js +105 -0
- package/dist/cjs/params.js.map +1 -0
- package/dist/cjs/requests.d.ts +11 -0
- package/dist/cjs/requests.d.ts.map +1 -0
- package/dist/cjs/requests.js +208 -0
- package/dist/cjs/requests.js.map +1 -0
- package/dist/cjs/runBlock.d.ts +35 -0
- package/dist/cjs/runBlock.d.ts.map +1 -0
- package/dist/cjs/runBlock.js +797 -0
- package/dist/cjs/runBlock.js.map +1 -0
- package/dist/cjs/runFrameTx.d.ts +18 -0
- package/dist/cjs/runFrameTx.d.ts.map +1 -0
- package/dist/cjs/runFrameTx.js +313 -0
- package/dist/cjs/runFrameTx.js.map +1 -0
- package/dist/cjs/runTx.d.ts +18 -0
- package/dist/cjs/runTx.d.ts.map +1 -0
- package/dist/cjs/runTx.js +900 -0
- package/dist/cjs/runTx.js.map +1 -0
- package/dist/cjs/types.d.ts +452 -0
- package/dist/cjs/types.d.ts.map +1 -0
- package/dist/cjs/types.js +3 -0
- package/dist/cjs/types.js.map +1 -0
- package/dist/cjs/vm.d.ts +75 -0
- package/dist/cjs/vm.d.ts.map +1 -0
- package/dist/cjs/vm.js +111 -0
- package/dist/cjs/vm.js.map +1 -0
- package/dist/esm/bloom/index.d.ts +29 -0
- package/dist/esm/bloom/index.d.ts.map +1 -0
- package/dist/esm/bloom/index.js +72 -0
- package/dist/esm/bloom/index.js.map +1 -0
- package/dist/esm/buildBlock.d.ts +118 -0
- package/dist/esm/buildBlock.d.ts.map +1 -0
- package/dist/esm/buildBlock.js +358 -0
- package/dist/esm/buildBlock.js.map +1 -0
- package/dist/esm/constructors.d.ts +9 -0
- package/dist/esm/constructors.d.ts.map +1 -0
- package/dist/esm/constructors.js +72 -0
- package/dist/esm/constructors.js.map +1 -0
- package/dist/esm/emitEVMProfile.d.ts +9 -0
- package/dist/esm/emitEVMProfile.d.ts.map +1 -0
- package/dist/esm/emitEVMProfile.js +127 -0
- package/dist/esm/emitEVMProfile.js.map +1 -0
- package/dist/esm/index.d.ts +11 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +11 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/package.json +3 -0
- package/dist/esm/params.d.ts +3 -0
- package/dist/esm/params.d.ts.map +1 -0
- package/dist/esm/params.js +102 -0
- package/dist/esm/params.js.map +1 -0
- package/dist/esm/requests.d.ts +11 -0
- package/dist/esm/requests.d.ts.map +1 -0
- package/dist/esm/requests.js +204 -0
- package/dist/esm/requests.js.map +1 -0
- package/dist/esm/runBlock.d.ts +35 -0
- package/dist/esm/runBlock.d.ts.map +1 -0
- package/dist/esm/runBlock.js +790 -0
- package/dist/esm/runBlock.js.map +1 -0
- package/dist/esm/runFrameTx.d.ts +18 -0
- package/dist/esm/runFrameTx.d.ts.map +1 -0
- package/dist/esm/runFrameTx.js +310 -0
- package/dist/esm/runFrameTx.js.map +1 -0
- package/dist/esm/runTx.d.ts +18 -0
- package/dist/esm/runTx.d.ts.map +1 -0
- package/dist/esm/runTx.js +896 -0
- package/dist/esm/runTx.js.map +1 -0
- package/dist/esm/types.d.ts +452 -0
- package/dist/esm/types.d.ts.map +1 -0
- package/dist/esm/types.js +2 -0
- package/dist/esm/types.js.map +1 -0
- package/dist/esm/vm.d.ts +75 -0
- package/dist/esm/vm.d.ts.map +1 -0
- package/dist/esm/vm.js +107 -0
- package/dist/esm/vm.js.map +1 -0
- package/dist/tsconfig.prod.cjs.tsbuildinfo +1 -0
- package/dist/tsconfig.prod.esm.tsbuildinfo +1 -0
- package/package.json +117 -0
- package/src/bloom/index.ts +83 -0
- package/src/buildBlock.ts +470 -0
- package/src/constructors.ts +91 -0
- package/src/emitEVMProfile.ts +151 -0
- package/src/index.ts +10 -0
- package/src/params.ts +104 -0
- package/src/requests.ts +293 -0
- package/src/runBlock.ts +1022 -0
- package/src/runFrameTx.ts +411 -0
- package/src/runTx.ts +1203 -0
- package/src/types.ts +511 -0
- package/src/vm.ts +147 -0
package/dist/cjs/vm.js
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.VM = void 0;
|
|
4
|
+
const evm_1 = require("@feelyourprotocol/evm");
|
|
5
|
+
const eventemitter3_1 = require("eventemitter3");
|
|
6
|
+
const constructors_ts_1 = require("./constructors.js");
|
|
7
|
+
const params_ts_1 = require("./params.js");
|
|
8
|
+
const util_1 = require("@feelyourprotocol/util");
|
|
9
|
+
/**
|
|
10
|
+
* The VM is a state transition machine that executes EVM bytecode and updates the state.
|
|
11
|
+
* It can be used to execute transactions, blocks, individual transactions, or snippets of EVM bytecode.
|
|
12
|
+
*
|
|
13
|
+
* A VM can be created with the constructor method:
|
|
14
|
+
*
|
|
15
|
+
* - {@link createVM}
|
|
16
|
+
*/
|
|
17
|
+
class VM {
|
|
18
|
+
/**
|
|
19
|
+
* Instantiates a new {@link VM} Object.
|
|
20
|
+
*
|
|
21
|
+
* @deprecated The direct usage of this constructor is discouraged since
|
|
22
|
+
* non-finalized async initialization might lead to side effects. Please
|
|
23
|
+
* use the async {@link createVM} constructor instead (same API).
|
|
24
|
+
* @param opts
|
|
25
|
+
*/
|
|
26
|
+
constructor(opts = {}) {
|
|
27
|
+
this._isInitialized = false;
|
|
28
|
+
/**
|
|
29
|
+
* VM is run in DEBUG mode (default: false)
|
|
30
|
+
* Taken from DEBUG environment variable
|
|
31
|
+
*
|
|
32
|
+
* Safeguards on debug() calls are added for
|
|
33
|
+
* performance reasons to avoid string literal evaluation
|
|
34
|
+
* @hidden
|
|
35
|
+
*/
|
|
36
|
+
this.DEBUG = false;
|
|
37
|
+
this.common = opts.common;
|
|
38
|
+
this.common.updateParams(opts.params ?? params_ts_1.paramsVM);
|
|
39
|
+
this.stateManager = opts.stateManager;
|
|
40
|
+
this.blockchain = opts.blockchain;
|
|
41
|
+
this.evm = opts.evm;
|
|
42
|
+
this.events = new eventemitter3_1.EventEmitter();
|
|
43
|
+
this._emit = async (topic, data) => {
|
|
44
|
+
const listeners = this.events.listeners(topic);
|
|
45
|
+
for (const listener of listeners) {
|
|
46
|
+
if (listener.length === 2) {
|
|
47
|
+
await new Promise((resolve) => {
|
|
48
|
+
listener(data, resolve);
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
listener(data);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
this._opts = opts;
|
|
57
|
+
this._setHardfork = opts.setHardfork ?? false;
|
|
58
|
+
// Skip DEBUG calls unless 'ethjs' included in environmental DEBUG variables
|
|
59
|
+
this.DEBUG = (0, util_1.isDebugEnabled)('ethjs');
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Returns a copy of the {@link VM} instance.
|
|
63
|
+
*
|
|
64
|
+
* Note that the returned copy will share the same db as the original for the blockchain and the statemanager.
|
|
65
|
+
*
|
|
66
|
+
* Associated caches will be deleted and caches will be re-initialized for a more short-term focused
|
|
67
|
+
* usage, being less memory intense (the statemanager caches will switch to using an ORDERED_MAP cache
|
|
68
|
+
* data structure more suitable for short-term usage, the trie node LRU cache will not be activated at all).
|
|
69
|
+
* To fine-tune this behavior (if the shallow-copy-returned object has a longer life span e.g.) you can set
|
|
70
|
+
* the `downlevelCaches` option to `false`.
|
|
71
|
+
*
|
|
72
|
+
* @param downlevelCaches Downlevel (so: adopted for short-term usage) associated state caches (default: true)
|
|
73
|
+
*/
|
|
74
|
+
async shallowCopy(downlevelCaches = true) {
|
|
75
|
+
const common = this.common.copy();
|
|
76
|
+
common.setHardfork(this.common.hardfork());
|
|
77
|
+
const blockchain = this.blockchain.shallowCopy();
|
|
78
|
+
const stateManager = this.stateManager.shallowCopy(downlevelCaches);
|
|
79
|
+
const evmOpts = {
|
|
80
|
+
...this.evm._optsCached,
|
|
81
|
+
common: this._opts.evmOpts?.common?.copy() ?? common,
|
|
82
|
+
blockchain: this._opts.evmOpts?.blockchain?.shallowCopy() ?? blockchain,
|
|
83
|
+
stateManager: this._opts.evmOpts?.stateManager?.shallowCopy(downlevelCaches) ?? stateManager,
|
|
84
|
+
};
|
|
85
|
+
const evmCopy = await (0, evm_1.createEVM)(evmOpts); // TODO fixme (should copy the EVMInterface, not default EVM)
|
|
86
|
+
return (0, constructors_ts_1.createVM)({
|
|
87
|
+
stateManager,
|
|
88
|
+
blockchain: this.blockchain,
|
|
89
|
+
common,
|
|
90
|
+
evm: evmCopy,
|
|
91
|
+
setHardfork: this._setHardfork,
|
|
92
|
+
profilerOpts: this._opts.profilerOpts,
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Return a compact error string representation of the object
|
|
97
|
+
*/
|
|
98
|
+
errorStr() {
|
|
99
|
+
let hf = '';
|
|
100
|
+
try {
|
|
101
|
+
hf = this.common.hardfork();
|
|
102
|
+
}
|
|
103
|
+
catch {
|
|
104
|
+
hf = 'error';
|
|
105
|
+
}
|
|
106
|
+
const errorStr = `vm hf=${hf}`;
|
|
107
|
+
return errorStr;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
exports.VM = VM;
|
|
111
|
+
//# sourceMappingURL=vm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vm.js","sourceRoot":"","sources":["../../src/vm.ts"],"names":[],"mappings":";;;AAAA,yCAA2C;AAC3C,iDAA4C;AAE5C,uDAA4C;AAC5C,2CAAsC;AAItC,2CAAiD;AAIjD;;;;;;;GAOG;AACH,MAAa,EAAE;IAyCb;;;;;;;OAOG;IACH,YAAY,OAAe,EAAE;QA7BnB,mBAAc,GAAY,KAAK,CAAA;QAWzC;;;;;;;WAOG;QACM,UAAK,GAAY,KAAK,CAAA;QAW7B,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAO,CAAA;QAC1B,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,IAAI,CAAC,MAAM,IAAI,oBAAQ,CAAC,CAAA;QACjD,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,YAAa,CAAA;QACtC,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,UAAW,CAAA;QAClC,IAAI,CAAC,GAAG,GAAG,IAAI,CAAC,GAAI,CAAA;QAEpB,IAAI,CAAC,MAAM,GAAG,IAAI,4BAAY,EAAW,CAAA;QAEzC,IAAI,CAAC,KAAK,GAAG,KAAK,EAAE,KAAa,EAAE,IAAS,EAAiB,EAAE;YAC7D,MAAM,SAAS,GAAG,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,KAAsB,CAAC,CAAA;YAC/D,KAAK,MAAM,QAAQ,IAAI,SAAS,EAAE,CAAC;gBACjC,IAAI,QAAQ,CAAC,MAAM,KAAK,C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O,CAAC,CAAA,CAAC,6DAA6D;QACtG,OAAO,IAAA,0BAAQ,EAAC;YACd,YAAY;YACZ,UAAU,EAAE,IAAI,CAAC,UAAU;YAC3B,MAAM;YACN,GAAG,EAAE,OAAO;YACZ,WAAW,EAAE,IAAI,CAAC,YAAY;YAC9B,YAAY,EAAE,IAAI,CAAC,KAAK,CAAC,YAAY;SACtC,CAAC,CAAA;IACJ,CAAC;IAED;;OAEG;IACH,QAAQ;QACN,IAAI,EAAE,GAAG,EAAE,CAAA;QACX,IAAI,CAAC;YACH,EAAE,GAAG,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAA;QAC7B,CAAC;QAAC,MAAM,CAAC;YACP,EAAE,GAAG,OAAO,CAAA;QACd,CAAC;QACD,MAAM,QAAQ,GAAG,SAAS,EAAE,EAAE,CAAA;QAC9B,OAAO,QAAQ,CAAA;IACjB,CAAC;CACF;AA9HD,gBA8HC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { Common } from '@feelyourprotocol/common';
|
|
2
|
+
export declare class Bloom {
|
|
3
|
+
bitvector: Uint8Array;
|
|
4
|
+
keccakFunction: (msg: Uint8Array) => Uint8Array;
|
|
5
|
+
/**
|
|
6
|
+
* Represents a Bloom filter.
|
|
7
|
+
*/
|
|
8
|
+
constructor(bitvector?: Uint8Array, common?: Common);
|
|
9
|
+
/**
|
|
10
|
+
* Adds an element to a bit vector of a 64 byte bloom filter.
|
|
11
|
+
* @param e - The element to add
|
|
12
|
+
*/
|
|
13
|
+
add(e: Uint8Array): void;
|
|
14
|
+
/**
|
|
15
|
+
* Checks if an element is in the bloom.
|
|
16
|
+
* @param e - The element to check
|
|
17
|
+
*/
|
|
18
|
+
check(e: Uint8Array): boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Checks if multiple topics are in a bloom.
|
|
21
|
+
* @returns `true` if every topic is in the bloom
|
|
22
|
+
*/
|
|
23
|
+
multiCheck(topics: Uint8Array[]): boolean;
|
|
24
|
+
/**
|
|
25
|
+
* Bitwise or blooms together.
|
|
26
|
+
*/
|
|
27
|
+
or(bloom: Bloom): void;
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/bloom/index.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAA;AAIhD,qBAAa,KAAK;IAChB,SAAS,EAAE,UAAU,CAAA;IACrB,cAAc,EAAE,CAAC,GAAG,EAAE,UAAU,KAAK,UAAU,CAAA;IAE/C;;OAEG;gBACS,SAAS,CAAC,EAAE,UAAU,EAAE,MAAM,CAAC,EAAE,MAAM;IAenD;;;OAGG;IACH,GAAG,CAAC,CAAC,EAAE,UAAU;IAajB;;;OAGG;IACH,KAAK,CAAC,CAAC,EAAE,UAAU,GAAG,OAAO;IAgB7B;;;OAGG;IACH,UAAU,CAAC,MAAM,EAAE,UAAU,EAAE,GAAG,OAAO;IAIzC;;OAEG;IACH,EAAE,CAAC,KAAK,EAAE,KAAK;CAKhB"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { EthereumJSErrorWithoutCode } from '@feelyourprotocol/util';
|
|
2
|
+
import { keccak_256 } from '@noble/hashes/sha3.js';
|
|
3
|
+
const BYTE_SIZE = 256;
|
|
4
|
+
export class Bloom {
|
|
5
|
+
/**
|
|
6
|
+
* Represents a Bloom filter.
|
|
7
|
+
*/
|
|
8
|
+
constructor(bitvector, common) {
|
|
9
|
+
if (common?.customCrypto.keccak256 !== undefined) {
|
|
10
|
+
this.keccakFunction = common.customCrypto.keccak256;
|
|
11
|
+
}
|
|
12
|
+
else {
|
|
13
|
+
this.keccakFunction = keccak_256;
|
|
14
|
+
}
|
|
15
|
+
if (!bitvector) {
|
|
16
|
+
this.bitvector = new Uint8Array(BYTE_SIZE);
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
if (bitvector.length !== BYTE_SIZE)
|
|
20
|
+
throw EthereumJSErrorWithoutCode('bitvectors must be 2048 bits long');
|
|
21
|
+
this.bitvector = bitvector;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Adds an element to a bit vector of a 64 byte bloom filter.
|
|
26
|
+
* @param e - The element to add
|
|
27
|
+
*/
|
|
28
|
+
add(e) {
|
|
29
|
+
e = this.keccakFunction(e);
|
|
30
|
+
const mask = 2047; // binary 11111111111
|
|
31
|
+
for (let i = 0; i < 3; i++) {
|
|
32
|
+
const first2bytes = new DataView(e.buffer).getUint16(i * 2);
|
|
33
|
+
const loc = mask & first2bytes;
|
|
34
|
+
const byteLoc = loc >> 3;
|
|
35
|
+
const bitLoc = 1 << (loc % 8);
|
|
36
|
+
this.bitvector[BYTE_SIZE - byteLoc - 1] |= bitLoc;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Checks if an element is in the bloom.
|
|
41
|
+
* @param e - The element to check
|
|
42
|
+
*/
|
|
43
|
+
check(e) {
|
|
44
|
+
e = this.keccakFunction(e);
|
|
45
|
+
const mask = 2047; // binary 11111111111
|
|
46
|
+
let match = true;
|
|
47
|
+
for (let i = 0; i < 3 && match; i++) {
|
|
48
|
+
const first2bytes = new DataView(e.buffer).getUint16(i * 2);
|
|
49
|
+
const loc = mask & first2bytes;
|
|
50
|
+
const byteLoc = loc >> 3;
|
|
51
|
+
const bitLoc = 1 << (loc % 8);
|
|
52
|
+
match = (this.bitvector[BYTE_SIZE - byteLoc - 1] & bitLoc) !== 0;
|
|
53
|
+
}
|
|
54
|
+
return Boolean(match);
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Checks if multiple topics are in a bloom.
|
|
58
|
+
* @returns `true` if every topic is in the bloom
|
|
59
|
+
*/
|
|
60
|
+
multiCheck(topics) {
|
|
61
|
+
return topics.every((t) => this.check(t));
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Bitwise or blooms together.
|
|
65
|
+
*/
|
|
66
|
+
or(bloom) {
|
|
67
|
+
for (let i = 0; i <= BYTE_SIZE; i++) {
|
|
68
|
+
this.bitvector[i] = this.bitvector[i] | bloom.bitvector[i];
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/bloom/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,0BAA0B,EAAE,MAAM,kBAAkB,CAAA;AAC7D,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAA;AAIlD,MAAM,SAAS,GAAG,GAAG,CAAA;AAErB,MAAM,OAAO,KAAK;IAIhB;;OAEG;IACH,YAAY,SAAsB,EAAE,MAAe;QACjD,IAAI,MAAM,EAAE,YAAY,CAAC,SAAS,KAAK,SAAS,EAAE,CAAC;YACjD,IAAI,CAAC,cAAc,GAAG,MAAM,CAAC,YAAY,CAAC,SAAS,CAAA;QACrD,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,cAAc,GAAG,UAAU,CAAA;QAClC,CAAC;QACD,IAAI,CAAC,SAAS,EAAE,CAAC;YACf,IAAI,CAAC,SAAS,GAAG,IAAI,UAAU,CAAC,SAAS,CAAC,CAAA;QAC5C,CAAC;aAAM,CAAC;YACN,IAAI,SAAS,CAAC,MAAM,KAAK,SAAS;gBAChC,MAAM,0BAA0B,CAAC,mCAAmC,CAAC,CAAA;YACvE,IAAI,CAAC,SAAS,GAAG,SAAS,CAAA;QAC5B,CAAC;IACH,CAAC;IAED;;;OAGG;IACH,GAAG,CAAC,CAAa;QACf,CAAC,GAAG,IAAI,CAAC,cAAc,CAAC,CAAC,CAAC,CAAA;QAC1B,MAAM,IAAI,GAAG,IAAI,CAAA,CAAC,qBAAqB;QAEvC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,C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,MAAoB;QAC7B,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC,CAAa,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAA;IACvD,CAAC;IAED;;OAEG;IACH,EAAE,CAAC,KAAY;QACb,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,SAAS,EAAE,CAAC,EAAE,EAAE,CAAC;YACpC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,CAAA;QAC5D,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import type { Block } from '@feelyourprotocol/block';
|
|
2
|
+
import type { TypedTransaction } from '@feelyourprotocol/tx';
|
|
3
|
+
import type { BuildBlockOpts, RunTxResult, SealBlockOpts } from './types.ts';
|
|
4
|
+
import type { VM } from './vm.ts';
|
|
5
|
+
export type BuildStatus = (typeof BuildStatus)[keyof typeof BuildStatus];
|
|
6
|
+
export declare const BuildStatus: {
|
|
7
|
+
readonly Reverted: "reverted";
|
|
8
|
+
readonly Build: "build";
|
|
9
|
+
readonly Pending: "pending";
|
|
10
|
+
};
|
|
11
|
+
type BlockStatus = {
|
|
12
|
+
status: typeof BuildStatus.Pending | typeof BuildStatus.Reverted;
|
|
13
|
+
} | {
|
|
14
|
+
status: typeof BuildStatus.Build;
|
|
15
|
+
block: Block;
|
|
16
|
+
};
|
|
17
|
+
export declare class BlockBuilder {
|
|
18
|
+
/**
|
|
19
|
+
* The cumulative gas used by the transactions added to the block.
|
|
20
|
+
*/
|
|
21
|
+
gasUsed: bigint;
|
|
22
|
+
/**
|
|
23
|
+
* The cumulative blob gas used by the blobs in a block
|
|
24
|
+
*/
|
|
25
|
+
blobGasUsed: bigint;
|
|
26
|
+
/**
|
|
27
|
+
* Value of the block, represented by the final transaction fees
|
|
28
|
+
* accruing to the miner.
|
|
29
|
+
*/
|
|
30
|
+
private _minerValue;
|
|
31
|
+
private readonly vm;
|
|
32
|
+
private blockOpts;
|
|
33
|
+
private headerData;
|
|
34
|
+
private transactions;
|
|
35
|
+
private transactionResults;
|
|
36
|
+
private withdrawals?;
|
|
37
|
+
private checkpointed;
|
|
38
|
+
private blockStatus;
|
|
39
|
+
get transactionReceipts(): import("./types.ts").TxReceipt[];
|
|
40
|
+
get minerValue(): bigint;
|
|
41
|
+
constructor(vm: VM, opts: BuildBlockOpts);
|
|
42
|
+
/**
|
|
43
|
+
* Throws if the block has already been built or reverted.
|
|
44
|
+
*/
|
|
45
|
+
private checkStatus;
|
|
46
|
+
getStatus(): BlockStatus;
|
|
47
|
+
/**
|
|
48
|
+
* Calculates and returns the transactionsTrie for the block.
|
|
49
|
+
*/
|
|
50
|
+
transactionsTrie(): Promise<Uint8Array<ArrayBufferLike>>;
|
|
51
|
+
/**
|
|
52
|
+
* Calculates and returns the logs bloom for the block.
|
|
53
|
+
*/
|
|
54
|
+
logsBloom(): Uint8Array<ArrayBufferLike>;
|
|
55
|
+
/**
|
|
56
|
+
* Calculates and returns the receiptTrie for the block.
|
|
57
|
+
*/
|
|
58
|
+
receiptTrie(): Promise<Uint8Array<ArrayBufferLike>>;
|
|
59
|
+
/**
|
|
60
|
+
* Adds the block miner reward to the coinbase account.
|
|
61
|
+
*/
|
|
62
|
+
private rewardMiner;
|
|
63
|
+
/**
|
|
64
|
+
* Adds the withdrawal amount to the withdrawal address
|
|
65
|
+
*/
|
|
66
|
+
private processWithdrawals;
|
|
67
|
+
/**
|
|
68
|
+
* Run and add a transaction to the block being built.
|
|
69
|
+
* Please note that this modifies the state of the VM.
|
|
70
|
+
* Throws if the transaction's gasLimit is greater than
|
|
71
|
+
* the remaining gas in the block.
|
|
72
|
+
*/
|
|
73
|
+
addTransaction(tx: TypedTransaction, { skipHardForkValidation, allowNoBlobs, }?: {
|
|
74
|
+
skipHardForkValidation?: boolean;
|
|
75
|
+
allowNoBlobs?: boolean;
|
|
76
|
+
}): Promise<RunTxResult>;
|
|
77
|
+
/**
|
|
78
|
+
* Reverts the checkpoint on the StateManager to reset the state from any transactions that have been run.
|
|
79
|
+
*/
|
|
80
|
+
revert(): Promise<void>;
|
|
81
|
+
/**
|
|
82
|
+
* This method constructs the finalized block, including withdrawals and any CLRequests.
|
|
83
|
+
* It also:
|
|
84
|
+
* - Assigns the reward for miner (PoW)
|
|
85
|
+
* - Commits the checkpoint on the StateManager
|
|
86
|
+
* - Sets the tip of the VM's blockchain to this block
|
|
87
|
+
* For PoW, optionally seals the block with params `nonce` and `mixHash`,
|
|
88
|
+
* which is validated along with the block number and difficulty by ethash.
|
|
89
|
+
* For PoA, please pass `blockOption.cliqueSigner` into the buildBlock constructor,
|
|
90
|
+
* as the signer will be awarded the txs amount spent on gas as they are added.
|
|
91
|
+
*
|
|
92
|
+
* Note: we add CLRequests here because they can be generated at any time during the
|
|
93
|
+
* lifecycle of a pending block so need to be provided only when the block is finalized.
|
|
94
|
+
*/
|
|
95
|
+
build(sealOpts?: SealBlockOpts): Promise<{
|
|
96
|
+
block: Block;
|
|
97
|
+
requests: import("@feelyourprotocol/util").CLRequest<import("@feelyourprotocol/util").CLRequestType>[] | undefined;
|
|
98
|
+
}>;
|
|
99
|
+
initState(): Promise<void>;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Build a block on top of the current state
|
|
103
|
+
* by adding one transaction at a time.
|
|
104
|
+
*
|
|
105
|
+
* Creates a checkpoint on the StateManager and modifies the state
|
|
106
|
+
* as transactions are run. The checkpoint is committed on {@link BlockBuilder.build}
|
|
107
|
+
* or discarded with {@link BlockBuilder.revert}.
|
|
108
|
+
*
|
|
109
|
+
* @param {VM} vm
|
|
110
|
+
* @param {BuildBlockOpts} opts
|
|
111
|
+
* @returns An instance of {@link BlockBuilder} with methods:
|
|
112
|
+
* - {@link BlockBuilder.addTransaction}
|
|
113
|
+
* - {@link BlockBuilder.build}
|
|
114
|
+
* - {@link BlockBuilder.revert}
|
|
115
|
+
*/
|
|
116
|
+
export declare function buildBlock(vm: VM, opts: BuildBlockOpts): Promise<BlockBuilder>;
|
|
117
|
+
export {};
|
|
118
|
+
//# sourceMappingURL=buildBlock.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"buildBlock.d.ts","sourceRoot":"","sources":["../../src/buildBlock.ts"],"names":[],"mappings":"AA0CA,OAAO,KAAK,EAAE,KAAK,EAAc,MAAM,mBAAmB,CAAA;AAC1D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAA;AAEtD,OAAO,KAAK,EAAE,cAAc,EAAe,WAAW,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AACzF,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,SAAS,CAAA;AAEjC,MAAM,MAAM,WAAW,GAAG,CAAC,OAAO,WAAW,CAAC,CAAC,MAAM,OAAO,WAAW,CAAC,CAAA;AACxE,eAAO,MAAM,WAAW;;;;CAId,CAAA;AAEV,KAAK,WAAW,GACZ;IAAE,MAAM,EAAE,OAAO,WAAW,CAAC,OAAO,GAAG,OAAO,WAAW,CAAC,QAAQ,CAAA;CAAE,GACpE;IAAE,MAAM,EAAE,OAAO,WAAW,CAAC,KAAK,CAAC;IAAC,KAAK,EAAE,KAAK,CAAA;CAAE,CAAA;AAEtD,qBAAa,YAAY;IACvB;;OAEG;IACH,OAAO,SAAW;IAClB;;OAEG;IACH,WAAW,SAAW;IACtB;;;OAGG;IACH,OAAO,CAAC,WAAW,CAAW;IAE9B,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAI;IACvB,OAAO,CAAC,SAAS,CAAa;IAC9B,OAAO,CAAC,UAAU,CAAY;IAC9B,OAAO,CAAC,YAAY,CAAyB;IAC7C,OAAO,CAAC,kBAAkB,CAAoB;IAC9C,OAAO,CAAC,WAAW,CAAC,CAAc;IAClC,OAAO,CAAC,YAAY,CAAQ;IAC5B,OAA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