git ssb

0+

wanderer🌟 / js-primea-hypervisor



Tree: d9ab14281e683bbcd8f54b5cb7874edbbdd088a7

Files: d9ab14281e683bbcd8f54b5cb7874edbbdd088a7 / hypervisor.js

1111 bytesRaw
1const Kernel = require('./index.js')
2const Vertex = require('merkle-trie')
3const Block = require('./deps/block.js')
4const blockchain = require('./fakeBlockChain.js')
5const codeHandlers = require('./codeHandler.js')
6
7module.exports = class Hypervisor {
8 constructor (state = new Vertex()) {
9 this.state = state
10 if (state.isEmpty) {
11 state.set('block', new Vertex({
12 value: new Block()
13 }))
14 state.set('blockchain', new Vertex({
15 value: blockchain
16 }))
17 }
18 this.root = new Kernel({
19 state: state
20 })
21 }
22
23 set (path, kernel) {
24 this.state.set(path, new Vertex({
25 value: kernel
26 }))
27 }
28
29 send (message) {
30 return this.root.send(message)
31 }
32
33 async get (path) {
34 let lastKernel = this.root
35 let state = this.state
36 while (path.length) {
37 const name = path.unshift()
38 state = await state.get(name)
39 const kernel = new Kernel({
40 state: state,
41 parent: lastKernel
42 })
43 lastKernel = kernel
44 }
45 return lastKernel
46 }
47
48 addVM (type, handler) {
49 codeHandlers.handlers.type = handler
50 }
51}
52

Built with git-ssb-web