git ssb

0+

wanderer🌟 / js-primea-hypervisor



Commit e0a962d924b51e646934cc30ae1c50df8f1ef31a

uses 'acccounts' key to store accounts

wanderer committed on 1/8/2017, 6:36:16 PM
Parent: 26787afda66ed5f43ebf8e40d4edefbbcc133e01

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
@@ -255,9 +255,9 @@
255255 * @return {integer}
256256 */
257257 getExternalCodeSize (addressOffset, cbOffset) {
258258 this.takeGas(20)
259- const address = [...this.getMemory(addressOffset, ADDRESS_SIZE_BYTES), 'code']
259+ const address = ['accounts', ...this.getMemory(addressOffset, ADDRESS_SIZE_BYTES), 'code']
260260 const opPromise = this.kernel.environment.state.root
261261 .get(address)
262262 .then(vertex => vertex.value.length)
263263 .catch(() => 0)
@@ -275,9 +275,9 @@
275275 */
276276 externalCodeCopy (addressOffset, resultOffset, codeOffset, length, cbIndex) {
277277 this.takeGas(20 + Math.ceil(length / 32) * 3)
278278
279- const address = [...this.getMemory(addressOffset, ADDRESS_SIZE_BYTES), 'code']
279+ const address = ['accounts', ...this.getMemory(addressOffset, ADDRESS_SIZE_BYTES), 'code']
280280 let opPromise
281281
282282 if (length) {
283283 opPromise = this.kernel.environment.state.root
@@ -464,9 +464,9 @@
464464 this.takeGas(40)
465465
466466 const gas = from64bit(gasHigh, gasLow)
467467 // Load the params from mem
468- const address = [...this.getMemory(addressOffset, ADDRESS_SIZE_BYTES)]
468+ const address = ['accounts', ...this.getMemory(addressOffset, ADDRESS_SIZE_BYTES)]
469469 const value = new U256(this.getMemory(valueOffset, U128_SIZE_BYTES))
470470
471471 // Special case for non-zero value; why does this exist?
472472 if (!value.isZero()) {
@@ -499,9 +499,9 @@
499499 */
500500 callCode (gas, addressOffset, valueOffset, dataOffset, dataLength, resultOffset, resultLength, cbIndex) {
501501 this.takeGas(40)
502502 // 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']
504504 const value = U256.fromMemory(this.getMemory(valueOffset, U128_SIZE_BYTES))
505505
506506 // Special case for non-zero value; why does this exist?
507507 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
@@ -48,14 +48,16 @@
4848 value: new Buffer(account.storage[key].slice(2), 'hex')
4949 }))
5050 }
5151
52- const path = [...new Buffer(address.slice(2), 'hex')]
52+ const path = ['accounts', ...new Buffer(address.slice(2), 'hex')]
5353 rootVertex.set(path, accountVertex)
5454 }
5555
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+ })
5860 const env = new Environment(envData)
5961
6062 try {
6163 await kernel.run(env)

Built with git-ssb-web