git ssb

0+

wanderer🌟 / js-primea-hypervisor



Commit de14490c984932fcb886b69855e66ae6d5ba7dac

convet codecopy to async

wanderer committed on 11/11/2016, 10:33:23 PM
Parent: 218378ee81f2cf20c03ed1333553072db9dd4205

Files changed

EVMinterface.jschanged
EVMinterface.jsView
@@ -1,9 +1,8 @@
11 /**
22 * This is the Ethereum interface that is exposed to the WASM instance which
33 * enables to interact with the Ethereum Environment
44 */
5-
65 const Vertex = require('merkle-trie')
76 const Address = require('./deps/address.js')
87 const U256 = require('./deps/u256.js')
98 const fs = require('fs')
@@ -222,15 +221,25 @@
222221 * @param {integer} offset the memory offset
223222 * @param {integer} codeOffset the code offset
224223 * @param {integer} length the length of code to copy
225224 */
226- codeCopy (resultOffset, codeOffset, length) {
225+ codeCopy (resultOffset, codeOffset, length, cbIndex) {
227226 this.takeGas(3 + Math.ceil(length / 32) * 3)
228227
228+ let opPromise
229+
229230 if (length) {
230- const code = this.kernel.environment.code.slice(codeOffset, codeOffset + length)
231+ opPromise = this.kernel.environment.state.get('code')
232+ .then(vertex => vertex.value)
233+ } else {
234+ opPromise = Promise.resolve([])
235+ }
236+
237+ // wait for all the prevouse async ops to finish before running the callback
238+ this.kernel.pushOpsQueue(opPromise, cbIndex, code => {
239+ code = code.slice(codeOffset, codeOffset + length)
231240 this.setMemory(resultOffset, length, code)
232- }
241+ })
233242 }
234243
235244 /**
236245 * Get size of an account’s code.

Built with git-ssb-web