Files: 0edfe5b10a3a58691d782ae18e443689a66cf95d / index.js
1760 bytesRaw
1 | /** |
2 | * This implements the Ethereum Kernel |
3 | * The kernal handles the following |
4 | * - Interprocess communications |
5 | * - Intializing the VM and exposes ROM to it (codeHandler) |
6 | * - Expose namespace which VM instance exists and Intializes the Environment (callHandler) |
7 | * - Provides some built in contract (runTx, runBlock) |
8 | * - Provides resource sharing and limiting via gas |
9 | * |
10 | * All State should be stored in the Environment. |
11 | */ |
12 | // const Environment = require('./environment.js') |
13 | const Interface = require('./interface.js') |
14 | const Environment = require('./environment.js') |
15 | |
16 | module.exports = class Kernal { |
17 | // runs some code in the VM |
18 | constructor (nameState) { |
19 | this.state = nameState |
20 | } |
21 | |
22 | // handles running code. |
23 | static codeHandler (code, environment = new Environment()) { |
24 | const ethInterface = new Interface(environment) |
25 | const instance = Wasm.instantiateModule(code, { |
26 | 'ethereum': ethInterface |
27 | }) |
28 | ethInterface.setModule(instance) |
29 | if (instance.exports.main) { |
30 | instance.exports.main() |
31 | } |
32 | return instance |
33 | } |
34 | |
35 | // loads code from the merkle trie and delegates the message |
36 | // Detects if code is EVM or WASM |
37 | // Detects if the code injection is needed |
38 | // Detects if transcompilation is needed |
39 | static callHandler (path, data, environment) { |
40 | // const instance = Wasm.instantiateModule(code, interface) |
41 | // interface.setModule(instance) |
42 | // return instance |
43 | } |
44 | |
45 | // run tx |
46 | runTx (tx, environment) { |
47 | // verify tx then send to call Handler |
48 | this.callHandler(tx, environment) |
49 | } |
50 | |
51 | // run block |
52 | runBlock (block, environment) { |
53 | // verify block then run each tx |
54 | block.tx.forEach((tx) => { |
55 | this.runTx(tx, environment) |
56 | }) |
57 | } |
58 | |
59 | // run blockchain |
60 | // runBlockchain () {} |
61 | } |
62 |
Built with git-ssb-web