Commit 439177b212e72f0e65ae91c034b8d4d8c9c85d9a
converet interface to bigendian only
wanderer committed on 11/11/2016, 1:07:16 PMParent: 863cffe3f178010105fe06f1d375cb31e4579ea3
Files changed
EVMinterface.js | changed |
debugInterface.js | changed |
deps/u256.js | changed |
EVMinterface.js | ||
---|---|---|
@@ -120,15 +120,19 @@ | ||
120 | 120 | * offset. |
121 | 121 | * @param {integer} addressOffset the memory offset to laod the address |
122 | 122 | * @param {integer} resultOffset |
123 | 123 | */ |
124 | - getBalance (addressOffset, offset) { | |
124 | + getBalance (addressOffset, offset, cbIndex) { | |
125 | 125 | this.takeGas(20) |
126 | 126 | |
127 | - const address = Address.fromMemory(this.getMemory(addressOffset, ADDRESS_SIZE_BYTES)) | |
128 | - // call the parent contract and ask for the balance of one of its child contracts | |
129 | - const balance = this.kernel.environment.getBalance(address) | |
130 | - this.setMemory(offset, U128_SIZE_BYTES, balance.toMemory(U128_SIZE_BYTES)) | |
127 | + const path = [...this.getMemory(addressOffset, ADDRESS_SIZE_BYTES), 'balance'] | |
128 | + const opPromise = this.kernel.environment.state.get(path) | |
129 | + .then(vertex => new U256(vertex.value)) | |
130 | + .catch(() => new U256(0)) | |
131 | + | |
132 | + this.kernel.pushOpsQueue(opPromise, cbIndex, balance => { | |
133 | + this.setMemory(offset, U128_SIZE_BYTES, balance.toMemory(U128_SIZE_BYTES)) | |
134 | + }) | |
131 | 135 | } |
132 | 136 | |
133 | 137 | /** |
134 | 138 | * Gets the execution's origination address and loads it into memory at the |
@@ -234,11 +238,9 @@ | ||
234 | 238 | * @return {integer} |
235 | 239 | */ |
236 | 240 | getExternalCodeSize (addressOffset, cbOffset) { |
237 | 241 | this.takeGas(20) |
238 | - | |
239 | - const address = Address.fromMemory(this.getMemory(addressOffset, ADDRESS_SIZE_BYTES)).toArray() | |
240 | - address.push('code') | |
242 | + const address = [...this.getMemory(addressOffset, ADDRESS_SIZE_BYTES), 'code'] | |
241 | 243 | const opPromise = this.kernel.environment.state.root.get(address) |
242 | 244 | .then(vertex => vertex.value.length) |
243 | 245 | .catch(() => 0) |
244 | 246 |
debugInterface.js | ||
---|---|---|
@@ -34,15 +34,15 @@ | ||
34 | 34 | } |
35 | 35 | console.error(`op: ${opcode.name} gas: ${this.kernel.environment.gasLeft} sp: ${sp}`) |
36 | 36 | console.log('-------------stack--------------') |
37 | 37 | for (let i = sp; i >= 0; i -= 32) { |
38 | - console.log(`${(sp - i) / 32} ${this.getMemoryBuffer(i).reverse().toString('hex')}`) | |
38 | + console.log(`${(sp - i) / 32} ${this.getMemoryBuffer(i).toString('hex')}`) | |
39 | 39 | } |
40 | 40 | }.bind(this) |
41 | 41 | } |
42 | 42 | } |
43 | 43 | |
44 | 44 | getMemoryBuffer (offset, length = 32) { |
45 | 45 | const mem = this.kernel.memory.slice(offset, offset + length) |
46 | - return Buffer.from(mem) | |
46 | + return Buffer.from(mem).reverse() | |
47 | 47 | } |
48 | 48 | } |
deps/u256.js | ||
---|---|---|
@@ -27,15 +27,19 @@ | ||
27 | 27 | } |
28 | 28 | return this._value.toString(radix) |
29 | 29 | } |
30 | 30 | |
31 | - toBuffer (width) { | |
31 | + toBuffer (width = 32) { | |
32 | 32 | if (width <= 0 || width > 32) { |
33 | 33 | throw new Error('Invalid U256 width') |
34 | 34 | } |
35 | - return this._value.toBuffer('be', width || 32) | |
35 | + return this._value.toBuffer('be', width) | |
36 | 36 | } |
37 | 37 | |
38 | + toArray () { | |
39 | + return [...this.toBuffer()] | |
40 | + } | |
41 | + | |
38 | 42 | isZero () { |
39 | 43 | return this._value.isZero() |
40 | 44 | } |
41 | 45 |
Built with git-ssb-web