git ssb

0+

wanderer🌟 / js-primea-hypervisor



Commit 439177b212e72f0e65ae91c034b8d4d8c9c85d9a

converet interface to bigendian only

wanderer committed on 11/11/2016, 1:07:16 PM
Parent: 863cffe3f178010105fe06f1d375cb31e4579ea3

Files changed

EVMinterface.jschanged
debugInterface.jschanged
deps/u256.jschanged
EVMinterface.jsView
@@ -120,15 +120,19 @@
120120 * offset.
121121 * @param {integer} addressOffset the memory offset to laod the address
122122 * @param {integer} resultOffset
123123 */
124- getBalance (addressOffset, offset) {
124+ getBalance (addressOffset, offset, cbIndex) {
125125 this.takeGas(20)
126126
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+ })
131135 }
132136
133137 /**
134138 * Gets the execution's origination address and loads it into memory at the
@@ -234,11 +238,9 @@
234238 * @return {integer}
235239 */
236240 getExternalCodeSize (addressOffset, cbOffset) {
237241 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']
241243 const opPromise = this.kernel.environment.state.root.get(address)
242244 .then(vertex => vertex.value.length)
243245 .catch(() => 0)
244246
debugInterface.jsView
@@ -34,15 +34,15 @@
3434 }
3535 console.error(`op: ${opcode.name} gas: ${this.kernel.environment.gasLeft} sp: ${sp}`)
3636 console.log('-------------stack--------------')
3737 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')}`)
3939 }
4040 }.bind(this)
4141 }
4242 }
4343
4444 getMemoryBuffer (offset, length = 32) {
4545 const mem = this.kernel.memory.slice(offset, offset + length)
46- return Buffer.from(mem)
46+ return Buffer.from(mem).reverse()
4747 }
4848 }
deps/u256.jsView
@@ -27,15 +27,19 @@
2727 }
2828 return this._value.toString(radix)
2929 }
3030
31- toBuffer (width) {
31+ toBuffer (width = 32) {
3232 if (width <= 0 || width > 32) {
3333 throw new Error('Invalid U256 width')
3434 }
35- return this._value.toBuffer('be', width || 32)
35+ return this._value.toBuffer('be', width)
3636 }
3737
38+ toArray () {
39+ return [...this.toBuffer()]
40+ }
41+
3842 isZero () {
3943 return this._value.isZero()
4044 }
4145

Built with git-ssb-web