Commit de14490c984932fcb886b69855e66ae6d5ba7dac
convet codecopy to async
wanderer committed on 11/11/2016, 10:33:23 PMParent: 218378ee81f2cf20c03ed1333553072db9dd4205
Files changed
EVMinterface.js | changed |
EVMinterface.js | ||
---|---|---|
@@ -1,9 +1,8 @@ | ||
1 | 1 | /** |
2 | 2 | * This is the Ethereum interface that is exposed to the WASM instance which |
3 | 3 | * enables to interact with the Ethereum Environment |
4 | 4 | */ |
5 | - | |
6 | 5 | const Vertex = require('merkle-trie') |
7 | 6 | const Address = require('./deps/address.js') |
8 | 7 | const U256 = require('./deps/u256.js') |
9 | 8 | const fs = require('fs') |
@@ -222,15 +221,25 @@ | ||
222 | 221 | * @param {integer} offset the memory offset |
223 | 222 | * @param {integer} codeOffset the code offset |
224 | 223 | * @param {integer} length the length of code to copy |
225 | 224 | */ |
226 | - codeCopy (resultOffset, codeOffset, length) { | |
225 | + codeCopy (resultOffset, codeOffset, length, cbIndex) { | |
227 | 226 | this.takeGas(3 + Math.ceil(length / 32) * 3) |
228 | 227 | |
228 | + let opPromise | |
229 | + | |
229 | 230 | 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) | |
231 | 240 | this.setMemory(resultOffset, length, code) |
232 | - } | |
241 | + }) | |
233 | 242 | } |
234 | 243 | |
235 | 244 | /** |
236 | 245 | * Get size of an account’s code. |
Built with git-ssb-web