git ssb

0+

wanderer🌟 / js-primea-hypervisor



Tree: 2c04524fc8e9b757c060e0e2cf80d26d6d411e57

Files: 2c04524fc8e9b757c060e0e2cf80d26d6d411e57 / index.js

1549 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')
14
15module.exports = class Kernal {
16 // runs some code in the VM
17 constructor (nameState) {
18 this.state = nameState
19 }
20
21 // handles running code.
22 static codeHandler (code, environment) {
23 const ethInterface = new Interface(environment)
24 const instance = Wasm.instantiateModule(code, {
25 'ethereum': ethInterface
26 })
27 ethInterface.setModule(ethInterface)
28 return instance
29 }
30
31 // loads code from the merkle trie and delegates the message
32 // Detects if the code injection is needed
33 static callHandler (path, data, environment) {
34 // const instance = Wasm.instantiateModule(code, interface)
35 // interface.setModule(instance)
36 // return instance
37 }
38
39 // run tx
40 runTx (tx, environment) {
41 // verify tx then send to call Handler
42 this.callHandler(tx, environment)
43 }
44
45 // run block
46 runBlock (block, environment) {
47 // verify block then run each tx
48 block.tx.forEach((tx) => {
49 this.runTx(tx, environment)
50 })
51
52 }
53
54 // run blockchain
55 // runBlockchain () {}
56}
57

Built with git-ssb-web