Commit de87b9b68f0638e5deda64385e6c49c506325b8e
uses 'acccounts' key to store accounts
wanderer committed on 1/20/2017, 5:26:21 PMParent: c33f49958fc7e7e7c43b192b0c2b4361eda3c8a1
Files changed
EVMimports.js | changed |
index.js | changed |
tests/interfaceRunner.js | changed |
EVMimports.js | ||
---|---|---|
@@ -122,9 +122,9 @@ | ||
122 | 122 | */ |
123 | 123 | getBalance (addressOffset, offset, cbIndex) { |
124 | 124 | this.takeGas(20) |
125 | 125 | |
126 | - const path = [...this.getMemory(addressOffset, ADDRESS_SIZE_BYTES), 'balance'] | |
126 | + const path = ['accounts', ...this.getMemory(addressOffset, ADDRESS_SIZE_BYTES), 'balance'] | |
127 | 127 | const opPromise = this.kernel.environment.state.root.get(path) |
128 | 128 | .then(vertex => new U256(vertex.value)) |
129 | 129 | .catch(() => new U256(0)) |
130 | 130 | |
@@ -256,9 +256,9 @@ | ||
256 | 256 | * @return {integer} |
257 | 257 | */ |
258 | 258 | getExternalCodeSize (addressOffset, cbOffset) { |
259 | 259 | this.takeGas(20) |
260 | - const address = [...this.getMemory(addressOffset, ADDRESS_SIZE_BYTES), 'code'] | |
260 | + const address = ['accounts', ...this.getMemory(addressOffset, ADDRESS_SIZE_BYTES), 'code'] | |
261 | 261 | const opPromise = this.kernel.environment.state.root |
262 | 262 | .get(address) |
263 | 263 | .then(vertex => vertex.value.length) |
264 | 264 | .catch(() => 0) |
@@ -276,9 +276,9 @@ | ||
276 | 276 | */ |
277 | 277 | externalCodeCopy (addressOffset, resultOffset, codeOffset, length, cbIndex) { |
278 | 278 | this.takeGas(20 + Math.ceil(length / 32) * 3) |
279 | 279 | |
280 | - const address = [...this.getMemory(addressOffset, ADDRESS_SIZE_BYTES), 'code'] | |
280 | + const address = ['accounts', ...this.getMemory(addressOffset, ADDRESS_SIZE_BYTES), 'code'] | |
281 | 281 | let opPromise |
282 | 282 | |
283 | 283 | if (length) { |
284 | 284 | opPromise = this.kernel.environment.state.root |
@@ -465,9 +465,9 @@ | ||
465 | 465 | this.takeGas(40) |
466 | 466 | |
467 | 467 | const gas = from64bit(gasHigh, gasLow) |
468 | 468 | // Load the params from mem |
469 | - const address = [...this.getMemory(addressOffset, ADDRESS_SIZE_BYTES)] | |
469 | + const address = ['accounts', ...this.getMemory(addressOffset, ADDRESS_SIZE_BYTES)] | |
470 | 470 | const value = new U256(this.getMemory(valueOffset, U128_SIZE_BYTES)) |
471 | 471 | |
472 | 472 | // Special case for non-zero value; why does this exist? |
473 | 473 | if (!value.isZero()) { |
@@ -500,9 +500,9 @@ | ||
500 | 500 | */ |
501 | 501 | callCode (gas, addressOffset, valueOffset, dataOffset, dataLength, resultOffset, resultLength, cbIndex) { |
502 | 502 | this.takeGas(40) |
503 | 503 | // Load the params from mem |
504 | - const path = [...this.getMemory(addressOffset, ADDRESS_SIZE_BYTES), 'code'] | |
504 | + const path = ['accounts', ...this.getMemory(addressOffset, ADDRESS_SIZE_BYTES), 'code'] | |
505 | 505 | const value = U256.fromMemory(this.getMemory(valueOffset, U128_SIZE_BYTES)) |
506 | 506 | |
507 | 507 | // Special case for non-zero value; why does this exist? |
508 | 508 | if (!value.isZero()) { |
index.js | ||
---|---|---|
@@ -3,18 +3,16 @@ | ||
3 | 3 | const Imports = require('./EVMimports.js') |
4 | 4 | const VM = require('./vm.js') |
5 | 5 | const Environment = require('./environment.js') |
6 | 6 | |
7 | -module.exports = class Kernel extends Vertex { | |
7 | +module.exports = class Kernel { | |
8 | 8 | constructor (opts = {}) { |
9 | - opts.code = opts.value || opts.code | |
10 | - super(opts) | |
9 | + opts.state = opts.state || new Vertex(opts.code) | |
10 | + opts.code = opts.state.value || opts.code | |
11 | 11 | |
12 | 12 | // if code is bound to this kernel then create the interfaceAPI and the imports |
13 | - if (opts.code) { | |
14 | - this._vm = new VM(opts.code) | |
15 | - this.imports = buildImports(this._vm, opts.interfaces) | |
16 | - } | |
13 | + this._vm = new VM(opts.code) | |
14 | + this.imports = buildImports(this._vm, opts.interfaces) | |
17 | 15 | |
18 | 16 | /** |
19 | 17 | * Builds a import map with an array of given interfaces |
20 | 18 | */ |
@@ -36,20 +34,12 @@ | ||
36 | 34 | } |
37 | 35 | |
38 | 36 | async messageReceiver (message) { |
39 | 37 | // let the code handle the message if there is code |
40 | - if (this.code) { | |
41 | - const environment = new Environment(message) | |
42 | - let result = await this.run(environment) | |
43 | - if (!result.execption) { | |
44 | - this.state = result.state | |
45 | - } | |
46 | - } else if (message.to.length) { | |
47 | - // else forward the message on to the destination contract | |
48 | - let [vertex, done] = await this.state.update(message.to) | |
49 | - message.to = [] | |
50 | - await vertex.kernel.messageReceiver(message) | |
51 | - done(vertex) | |
38 | + const environment = new Environment(message) | |
39 | + let result = await this.run(environment) | |
40 | + if (!result.execption) { | |
41 | + this.state = result.state | |
52 | 42 | } |
53 | 43 | } |
54 | 44 | |
55 | 45 | copy () { |
tests/interfaceRunner.js | ||
---|---|---|
@@ -49,14 +49,16 @@ | ||
49 | 49 | value: new Buffer(account.storage[key].slice(2), 'hex') |
50 | 50 | })) |
51 | 51 | } |
52 | 52 | |
53 | - const path = [...new Buffer(address.slice(2), 'hex')] | |
53 | + const path = ['accounts', ...new Buffer(address.slice(2), 'hex')] | |
54 | 54 | rootVertex.set(path, accountVertex) |
55 | 55 | } |
56 | 56 | |
57 | - envData.state = await rootVertex.get([...envData.address.toBuffer()]) | |
58 | - const kernel = new Kernel({code: code}) | |
57 | + envData.state = await rootVertex.get(['accounts', ...envData.address.toBuffer()]) | |
58 | + const kernel = new Kernel({ | |
59 | + code: code | |
60 | + }) | |
59 | 61 | const env = new Environment(envData) |
60 | 62 | |
61 | 63 | try { |
62 | 64 | await kernel.run(env) |
Built with git-ssb-web