git ssb

0+

wanderer🌟 / js-primea-hypervisor



Commit de87b9b68f0638e5deda64385e6c49c506325b8e

uses 'acccounts' key to store accounts

wanderer committed on 1/20/2017, 5:26:21 PM
Parent: c33f49958fc7e7e7c43b192b0c2b4361eda3c8a1

Files changed

EVMimports.jschanged
index.jschanged
tests/interfaceRunner.jschanged
EVMimports.jsView
@@ -122,9 +122,9 @@
122122 */
123123 getBalance (addressOffset, offset, cbIndex) {
124124 this.takeGas(20)
125125
126- const path = [...this.getMemory(addressOffset, ADDRESS_SIZE_BYTES), 'balance']
126+ const path = ['accounts', ...this.getMemory(addressOffset, ADDRESS_SIZE_BYTES), 'balance']
127127 const opPromise = this.kernel.environment.state.root.get(path)
128128 .then(vertex => new U256(vertex.value))
129129 .catch(() => new U256(0))
130130
@@ -256,9 +256,9 @@
256256 * @return {integer}
257257 */
258258 getExternalCodeSize (addressOffset, cbOffset) {
259259 this.takeGas(20)
260- const address = [...this.getMemory(addressOffset, ADDRESS_SIZE_BYTES), 'code']
260+ const address = ['accounts', ...this.getMemory(addressOffset, ADDRESS_SIZE_BYTES), 'code']
261261 const opPromise = this.kernel.environment.state.root
262262 .get(address)
263263 .then(vertex => vertex.value.length)
264264 .catch(() => 0)
@@ -276,9 +276,9 @@
276276 */
277277 externalCodeCopy (addressOffset, resultOffset, codeOffset, length, cbIndex) {
278278 this.takeGas(20 + Math.ceil(length / 32) * 3)
279279
280- const address = [...this.getMemory(addressOffset, ADDRESS_SIZE_BYTES), 'code']
280+ const address = ['accounts', ...this.getMemory(addressOffset, ADDRESS_SIZE_BYTES), 'code']
281281 let opPromise
282282
283283 if (length) {
284284 opPromise = this.kernel.environment.state.root
@@ -465,9 +465,9 @@
465465 this.takeGas(40)
466466
467467 const gas = from64bit(gasHigh, gasLow)
468468 // Load the params from mem
469- const address = [...this.getMemory(addressOffset, ADDRESS_SIZE_BYTES)]
469+ const address = ['accounts', ...this.getMemory(addressOffset, ADDRESS_SIZE_BYTES)]
470470 const value = new U256(this.getMemory(valueOffset, U128_SIZE_BYTES))
471471
472472 // Special case for non-zero value; why does this exist?
473473 if (!value.isZero()) {
@@ -500,9 +500,9 @@
500500 */
501501 callCode (gas, addressOffset, valueOffset, dataOffset, dataLength, resultOffset, resultLength, cbIndex) {
502502 this.takeGas(40)
503503 // 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']
505505 const value = U256.fromMemory(this.getMemory(valueOffset, U128_SIZE_BYTES))
506506
507507 // Special case for non-zero value; why does this exist?
508508 if (!value.isZero()) {
index.jsView
@@ -3,18 +3,16 @@
33 const Imports = require('./EVMimports.js')
44 const VM = require('./vm.js')
55 const Environment = require('./environment.js')
66
7-module.exports = class Kernel extends Vertex {
7+module.exports = class Kernel {
88 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
1111
1212 // 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)
1715
1816 /**
1917 * Builds a import map with an array of given interfaces
2018 */
@@ -36,20 +34,12 @@
3634 }
3735
3836 async messageReceiver (message) {
3937 // 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
5242 }
5343 }
5444
5545 copy () {
tests/interfaceRunner.jsView
@@ -49,14 +49,16 @@
4949 value: new Buffer(account.storage[key].slice(2), 'hex')
5050 }))
5151 }
5252
53- const path = [...new Buffer(address.slice(2), 'hex')]
53+ const path = ['accounts', ...new Buffer(address.slice(2), 'hex')]
5454 rootVertex.set(path, accountVertex)
5555 }
5656
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+ })
5961 const env = new Environment(envData)
6062
6163 try {
6264 await kernel.run(env)

Built with git-ssb-web