git ssb

0+

wanderer🌟 / js-primea-hypervisor



Tree: a1cbfac008b122511f7f6be08a5e1dc164c4a9ad

Files: a1cbfac008b122511f7f6be08a5e1dc164c4a9ad / index.js

1681 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')
13const Interface = require('./interface.js')
14const Environment = require('./environment.js')
15
16module.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, ethInterface = new Interface()) {
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 = new Environment()) {
40 // return instance
41 }
42
43 // run tx
44 runTx (tx, environment) {
45 // verify tx then send to call Handler
46 this.callHandler(tx, environment)
47 }
48
49 // run block
50 runBlock (block, environment) {
51 // verify block then run each tx
52 block.tx.forEach((tx) => {
53 this.runTx(tx, environment)
54 })
55 }
56
57 // run blockchain
58 // runBlockchain () {}
59}
60

Built with git-ssb-web