git ssb

0+

wanderer🌟 / js-primea-hypervisor



Tree: c137aba03aa9981099698af3a30df2969c42a73b

Files: c137aba03aa9981099698af3a30df2969c42a73b / index.js

2170 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// The Kernel Stores all of its state in the Environment. The Interface is used
18// to by the VM to retrive infromation from the Environment.
19const Environment = require('./environment.js')
20
21module.exports = class Kernal {
22 // runs some code in the VM
23 constructor (environment = new Environment()) {
24 this.environment = environment
25 }
26
27 // handles running code.
28 static codeHandler (code, ethInterface = new Interface(new Environment())) {
29 const instance = Wasm.instantiateModule(code, {
30 'ethereum': ethInterface
31 })
32
33 ethInterface.setModule(instance)
34 if (instance.exports.main) {
35 instance.exports.main()
36 }
37 return instance
38 }
39
40 // loads code from the merkle trie and delegates the message
41 // Detects if code is EVM or WASM
42 // Detects if the code injection is needed
43 // Detects if transcompilation is needed
44 static callHandler (path, data) {
45 // creats a new Kernel
46 // const environment = new Environment(data)
47 // environment.parent = this
48 // const kernel = new Kernel(this, environment)
49 // kernel.codeHandler(code)
50 }
51
52 // run tx; the tx message handler
53 runTx (tx, environment = new Environment()) {
54 // verify tx then send to call Handler
55 this.callHandler(tx, environment)
56 }
57
58 // run block; the block message handler
59 runBlock (block, environment = new Environment()) {
60 // verify block then run each tx
61 block.tx.forEach((tx) => {
62 this.runTx(tx, environment)
63 })
64 }
65
66 // run blockchain
67 // runBlockchain () {}
68}
69

Built with git-ssb-web