Commit 08886ada2409d7516bf4a5654c170fa62fe5e439
move symbols to common
wanderer committed on 1/24/2017, 11:34:01 PMParent: 7a180f8331c532b243f6fda8a92ea00c741b4aaa
Files changed
EVMinterface.js | changed |
index.js | changed |
tests/interfaceRunner.js | changed |
common.js | added |
EVMinterface.js | ||
---|---|---|
@@ -7,8 +7,9 @@ | ||
7 | 7 | const ethUtil = require('ethereumjs-util') |
8 | 8 | const Vertex = require('merkle-trie') |
9 | 9 | const U256 = require('./deps/u256.js') |
10 | 10 | const Message = require('./message.js') |
11 | +const common = require('./common.js') | |
11 | 12 | |
12 | 13 | const U128_SIZE_BYTES = 16 |
13 | 14 | const ADDRESS_SIZE_BYTES = 20 |
14 | 15 | const U256_SIZE_BYTES = 32 |
@@ -33,16 +34,16 @@ | ||
33 | 34 | }) |
34 | 35 | } |
35 | 36 | |
36 | 37 | async initialize () { |
37 | - this.block = await this.kernel.send(this.kernel.ROOT, new Message({ | |
38 | + this.block = await this.kernel.send(common.ROOT, new Message({ | |
38 | 39 | data: { |
39 | 40 | getValue: 'block' |
40 | 41 | }, |
41 | 42 | sync: true |
42 | 43 | })) |
43 | 44 | |
44 | - this.blockchain = await this.kernel.send(this.kernel.ROOT, new Message({ | |
45 | + this.blockchain = await this.kernel.send(common.ROOT, new Message({ | |
45 | 46 | data: { |
46 | 47 | getValue: 'blockchain' |
47 | 48 | }, |
48 | 49 | sync: true |
@@ -149,10 +150,10 @@ | ||
149 | 150 | */ |
150 | 151 | getBalance (addressOffset, offset, cbIndex) { |
151 | 152 | this.takeGas(20) |
152 | 153 | |
153 | - const path = [this.kernel.PARENT, '0x' + new Buffer(this.getMemory(addressOffset, ADDRESS_SIZE_BYTES)).toString('hex')] | |
154 | - const opPromise = this.kernel.send(this.kernel.PARENT, new Message({ | |
154 | + const path = [common.PARENT, '0x' + new Buffer(this.getMemory(addressOffset, ADDRESS_SIZE_BYTES)).toString('hex')] | |
155 | + const opPromise = this.kernel.send(common.PARENT, new Message({ | |
155 | 156 | to: path, |
156 | 157 | data: { |
157 | 158 | getValue: 'balance' |
158 | 159 | }, |
@@ -497,9 +498,9 @@ | ||
497 | 498 | this.takeGas(40) |
498 | 499 | |
499 | 500 | const gas = from64bit(gasHigh, gasLow) |
500 | 501 | // Load the params from mem |
501 | - const address = [this.kernel.PARENT, ...this.getMemory(addressOffset, ADDRESS_SIZE_BYTES)] | |
502 | + const address = [common.PARENT, ...this.getMemory(addressOffset, ADDRESS_SIZE_BYTES)] | |
502 | 503 | const value = new U256(this.getMemory(valueOffset, U128_SIZE_BYTES)) |
503 | 504 | |
504 | 505 | // Special case for non-zero value; why does this exist? |
505 | 506 | if (!value.isZero()) { |
index.js | ||
---|---|---|
@@ -2,12 +2,10 @@ | ||
2 | 2 | const Cache = require('imperative-trie') |
3 | 3 | const imports = require('./EVMinterface.js') |
4 | 4 | const codeHandler = require('./codeHandler.js') |
5 | 5 | const MessageQueue = require('./messageQueue') |
6 | +const common = require('./common.js') | |
6 | 7 | |
7 | -const PARENT_SYMBOL = Symbol('parent') | |
8 | -const ROOT_SYMBOL = Symbol('root') | |
9 | - | |
10 | 8 | module.exports = class Kernel { |
11 | 9 | constructor (opts = {}) { |
12 | 10 | const state = this.state = opts.state || new Vertex() |
13 | 11 | state.value = opts.code || state.value |
@@ -17,24 +15,8 @@ | ||
17 | 15 | this._messageQueue = new MessageQueue(this) |
18 | 16 | this._instanceCache = new Cache() |
19 | 17 | } |
20 | 18 | |
21 | - static get PARENT () { | |
22 | - return PARENT_SYMBOL | |
23 | - } | |
24 | - | |
25 | - static get ROOT () { | |
26 | - return ROOT_SYMBOL | |
27 | - } | |
28 | - | |
29 | - get PARENT () { | |
30 | - return PARENT_SYMBOL | |
31 | - } | |
32 | - | |
33 | - get ROOT () { | |
34 | - return ROOT_SYMBOL | |
35 | - } | |
36 | - | |
37 | 19 | /** |
38 | 20 | * run the kernels code with a given enviroment |
39 | 21 | * The Kernel Stores all of its state in the Environment. The Interface is used |
40 | 22 | * to by the VM to retrive infromation from the Environment. |
@@ -61,17 +43,17 @@ | ||
61 | 43 | |
62 | 44 | async send (port, message) { |
63 | 45 | message.sending(this, this._messageQueue.currentMessage) |
64 | 46 | // replace root with parent path to root |
65 | - if (port === ROOT_SYMBOL) { | |
66 | - port = PARENT_SYMBOL | |
67 | - message.to = new Array(this.state.path.length - 1).fill(PARENT_SYMBOL).concat(message.to) | |
47 | + if (port === common.ROOT) { | |
48 | + port = common.PARENT | |
49 | + message.to = new Array(this.state.path.length - 1).fill(common.PARENT).concat(message.to) | |
68 | 50 | } |
69 | 51 | |
70 | - if (port === PARENT_SYMBOL) { | |
52 | + if (port === common.PARENT) { | |
71 | 53 | message.from.push(this.state.name) |
72 | 54 | } else { |
73 | - message.from.push(this.PARENT) | |
55 | + message.from.push(common.PARENT) | |
74 | 56 | } |
75 | 57 | |
76 | 58 | const dest = await this.getPort(port) |
77 | 59 | return dest.recieve(message) |
@@ -86,9 +68,9 @@ | ||
86 | 68 | } |
87 | 69 | |
88 | 70 | async getPort (name) { |
89 | 71 | let kernel |
90 | - if (name === this.PARENT) { | |
72 | + if (name === common.PARENT) { | |
91 | 73 | kernel = this.parent |
92 | 74 | } else { |
93 | 75 | kernel = this._instanceCache.get(name) |
94 | 76 | } |
@@ -96,9 +78,9 @@ | ||
96 | 78 | if (kernel) { |
97 | 79 | return kernel |
98 | 80 | } else { |
99 | 81 | const destState = await ( |
100 | - name === this.PARENT | |
82 | + name === common.PARENT | |
101 | 83 | ? this.state.getParent() |
102 | 84 | : this.state.get([name])) |
103 | 85 | |
104 | 86 | const kernel = new Kernel({ |
tests/interfaceRunner.js | ||
---|---|---|
@@ -8,8 +8,9 @@ | ||
8 | 8 | // TODO remove fakeblockchain |
9 | 9 | const fakeBlockChain = require('../fakeBlockChain.js') |
10 | 10 | const Kernel = require('../index.js') |
11 | 11 | const Message = require('../message.js') |
12 | +const common = require('../common.js') | |
12 | 13 | |
13 | 14 | const dir = path.join(__dirname, '/interface') |
14 | 15 | // get the test names |
15 | 16 | let tests = fs.readdirSync(dir).filter((file) => file.endsWith('.wast')) |
@@ -69,9 +70,9 @@ | ||
69 | 70 | |
70 | 71 | const callerState = await rootVertex.get(['accounts', envData.caller, 'code']) |
71 | 72 | const caller = new Kernel({state: callerState}) |
72 | 73 | try { |
73 | - await caller.send(Kernel.ROOT, message) | |
74 | + await caller.send(common.ROOT, message) | |
74 | 75 | } catch (e) { |
75 | 76 | t.fail('Exception: ' + e) |
76 | 77 | console.error('FAIL') |
77 | 78 | console.error(e) |
Built with git-ssb-web