Commit e0a962d924b51e646934cc30ae1c50df8f1ef31a
uses 'acccounts' key to store accounts
wanderer committed on 1/8/2017, 6:36:16 PMParent: 26787afda66ed5f43ebf8e40d4edefbbcc133e01
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 | |
@@ -255,9 +255,9 @@ | ||
255 | 255 | * @return {integer} |
256 | 256 | */ |
257 | 257 | getExternalCodeSize (addressOffset, cbOffset) { |
258 | 258 | this.takeGas(20) |
259 | - const address = [...this.getMemory(addressOffset, ADDRESS_SIZE_BYTES), 'code'] | |
259 | + const address = ['accounts', ...this.getMemory(addressOffset, ADDRESS_SIZE_BYTES), 'code'] | |
260 | 260 | const opPromise = this.kernel.environment.state.root |
261 | 261 | .get(address) |
262 | 262 | .then(vertex => vertex.value.length) |
263 | 263 | .catch(() => 0) |
@@ -275,9 +275,9 @@ | ||
275 | 275 | */ |
276 | 276 | externalCodeCopy (addressOffset, resultOffset, codeOffset, length, cbIndex) { |
277 | 277 | this.takeGas(20 + Math.ceil(length / 32) * 3) |
278 | 278 | |
279 | - const address = [...this.getMemory(addressOffset, ADDRESS_SIZE_BYTES), 'code'] | |
279 | + const address = ['accounts', ...this.getMemory(addressOffset, ADDRESS_SIZE_BYTES), 'code'] | |
280 | 280 | let opPromise |
281 | 281 | |
282 | 282 | if (length) { |
283 | 283 | opPromise = this.kernel.environment.state.root |
@@ -464,9 +464,9 @@ | ||
464 | 464 | this.takeGas(40) |
465 | 465 | |
466 | 466 | const gas = from64bit(gasHigh, gasLow) |
467 | 467 | // Load the params from mem |
468 | - const address = [...this.getMemory(addressOffset, ADDRESS_SIZE_BYTES)] | |
468 | + const address = ['accounts', ...this.getMemory(addressOffset, ADDRESS_SIZE_BYTES)] | |
469 | 469 | const value = new U256(this.getMemory(valueOffset, U128_SIZE_BYTES)) |
470 | 470 | |
471 | 471 | // Special case for non-zero value; why does this exist? |
472 | 472 | if (!value.isZero()) { |
@@ -499,9 +499,9 @@ | ||
499 | 499 | */ |
500 | 500 | callCode (gas, addressOffset, valueOffset, dataOffset, dataLength, resultOffset, resultLength, cbIndex) { |
501 | 501 | this.takeGas(40) |
502 | 502 | // Load the params from mem |
503 | - const path = [...this.getMemory(addressOffset, ADDRESS_SIZE_BYTES), 'code'] | |
503 | + const path = ['accounts', ...this.getMemory(addressOffset, ADDRESS_SIZE_BYTES), 'code'] | |
504 | 504 | const value = U256.fromMemory(this.getMemory(valueOffset, U128_SIZE_BYTES)) |
505 | 505 | |
506 | 506 | // Special case for non-zero value; why does this exist? |
507 | 507 | 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 | ||
---|---|---|
@@ -48,14 +48,16 @@ | ||
48 | 48 | value: new Buffer(account.storage[key].slice(2), 'hex') |
49 | 49 | })) |
50 | 50 | } |
51 | 51 | |
52 | - const path = [...new Buffer(address.slice(2), 'hex')] | |
52 | + const path = ['accounts', ...new Buffer(address.slice(2), 'hex')] | |
53 | 53 | rootVertex.set(path, accountVertex) |
54 | 54 | } |
55 | 55 | |
56 | - envData.state = await rootVertex.get([...envData.address.toBuffer()]) | |
57 | - const kernel = new Kernel({code: code}) | |
56 | + envData.state = await rootVertex.get(['accounts', ...envData.address.toBuffer()]) | |
57 | + const kernel = new Kernel({ | |
58 | + code: code | |
59 | + }) | |
58 | 60 | const env = new Environment(envData) |
59 | 61 | |
60 | 62 | try { |
61 | 63 | await kernel.run(env) |
Built with git-ssb-web