git ssb

0+

wanderer🌟 / js-primea-hypervisor



Tree: d48321af0dae8c0c5f6959e9c51e6ff1331b5a1b

Files: d48321af0dae8c0c5f6959e9c51e6ff1331b5a1b / index.js

2370 bytesRaw
1/**
2 * This implements the Ethereum Kernel
3 * Kernels must implement two methods `codeHandler` and `callHandler` (and `linkHandler` for sharding)
4 * The Kernel Contract handles the following
5 * - Interprocess communications
6 * - Intializing the VM and exposes ROM to it (codeHandler)
7 * - Expose namespace which VM instance exists and Intializes the Environment (callHandler)
8 * - Provides some built in contract (runTx, runBlock)
9 * - Provides resource sharing and limiting via gas
10 *
11 * All State should be stored in the Environment.
12 *
13 */
14
15// The Kernel Exposes this Interface to VM instances it makes
16const Interface = require('./interface.js')
17
18// The Kernel Stores all of its state in the Environment. The Interface is used
19// to by the VM to retrive infromation from the Environment.
20const Environment = require('./environment.js')
21
22const DebugInterface = require('./debugInterface.js')
23
24module.exports = class Kernal {
25 // runs some code in the VM
26 constructor (environment = new Environment()) {
27 this.environment = environment
28 }
29
30 // handles running code.
31 static codeHandler (code, ethInterface = new Interface(new Environment())) {
32 const debugInterface = new DebugInterface()
33
34 const instance = Wasm.instantiateModule(code, {
35 'ethereum': ethInterface.exportTable,
36 'debug': debugInterface.exportTable
37 })
38
39 ethInterface.setModule(instance)
40 debugInterface.setModule(instance)
41
42 if (instance.exports.main) {
43 instance.exports.main()
44 }
45 return instance
46 }
47
48 // loads code from the merkle trie and delegates the message
49 // Detects if code is EVM or WASM
50 // Detects if the code injection is needed
51 // Detects if transcompilation is needed
52 static callHandler (path, data) {
53 // creats a new Kernel
54 // const environment = new Environment(data)
55 // environment.parent = this
56 // const kernel = new Kernel(this, environment)
57 // kernel.codeHandler(code)
58 }
59
60 // run tx; the tx message handler
61 runTx (tx, environment = new Environment()) {
62 // verify tx then send to call Handler
63 this.callHandler(tx, environment)
64 }
65
66 // run block; the block message handler
67 runBlock (block, environment = new Environment()) {
68 // verify block then run each tx
69 block.tx.forEach((tx) => {
70 this.runTx(tx, environment)
71 })
72 }
73
74 // run blockchain
75 // runBlockchain () {}
76}
77

Built with git-ssb-web