EVMinterface.jsView |
---|
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 | 5 | const fs = require('fs') |
6 | | -const path = require('path') |
7 | 6 | const ethUtil = require('ethereumjs-util') |
8 | 7 | const Vertex = require('merkle-trie') |
9 | 8 | const U256 = require('./deps/u256.js') |
10 | 9 | const Message = require('./message.js') |
21 | 20 | this.message = opts.message |
22 | 21 | this.kernel = opts.kernel |
23 | 22 | this.vm = opts.vm |
24 | 23 | this.results = opts.response |
25 | | - const shimBin = fs.readFileSync(path.join(__dirname, '/wasm/interface.wasm')) |
| 24 | + |
| 25 | + const shimBin = fs.readFileSync(`${__dirname}/wasm/interface.wasm`) |
26 | 26 | const shimMod = WebAssembly.Module(shimBin) |
| 27 | + |
27 | 28 | this.shims = WebAssembly.Instance(shimMod, { |
28 | 29 | 'interface': { |
29 | 30 | 'useGas': this._useGas.bind(this), |
30 | 31 | 'getGasLeftHigh': this._getGasLeftHigh.bind(this), |
31 | 32 | 'getGasLeftLow': this._getGasLeftLow.bind(this), |
32 | 33 | 'call': this._call.bind(this) |
33 | 34 | } |
34 | 35 | }) |
| 36 | + this.useGas = this.shims.exports.useGas |
| 37 | + this.getGasLeft = this.shims.exports.getGasLeft |
| 38 | + this.call = this.shims.exports.call |
35 | 39 | } |
36 | 40 | |
37 | 41 | static get name () { |
38 | 42 | return 'ethereum' |
39 | 43 | } |
40 | 44 | |
41 | | - get exports () { |
42 | | - let exportMethods = [ |
43 | | - |
44 | | - 'getAddress', |
45 | | - 'getBalance', |
46 | | - 'getTxOrigin', |
47 | | - 'getCaller', |
48 | | - 'getCallValue', |
49 | | - 'getCallDataSize', |
50 | | - 'callDataCopy', |
51 | | - 'callDataCopy256', |
52 | | - 'getCodeSize', |
53 | | - 'codeCopy', |
54 | | - 'getExternalCodeSize', |
55 | | - 'externalCodeCopy', |
56 | | - 'getTxGasPrice', |
57 | | - 'getBlockHash', |
58 | | - 'getBlockCoinbase', |
59 | | - 'getBlockTimestamp', |
60 | | - 'getBlockNumber', |
61 | | - 'getBlockDifficulty', |
62 | | - 'getBlockGasLimit', |
63 | | - 'log', |
64 | | - 'create', |
65 | | - 'callCode', |
66 | | - 'callDelegate', |
67 | | - 'storageStore', |
68 | | - 'storageLoad', |
69 | | - 'return', |
70 | | - 'selfDestruct' |
71 | | - ] |
72 | | - let ret = {} |
73 | | - exportMethods.forEach((method) => { |
74 | | - ret[method] = this[method].bind(this) |
75 | | - }) |
76 | | - |
77 | | - |
78 | | - ret.useGas = this.shims.exports.useGas |
79 | | - ret.getGasLeft = this.shims.exports.getGasLeft |
80 | | - ret.call = this.shims.exports.call |
81 | | - return ret |
| 45 | + static get hostContainer () { |
| 46 | + return 'wasm' |
82 | 47 | } |
83 | 48 | |
84 | 49 | setModule (mod) { |
85 | 50 | this.module = mod |
484 | 449 | |
485 | 450 | this.vm.pushOpsQueue(messagePromise, cbIndex, () => { |
486 | 451 | return 1 |
487 | 452 | }) |
| 453 | + return 1 |
488 | 454 | } |
489 | 455 | |
490 | 456 | |
491 | 457 | * Message-call into this account with an alternative account’s code. |
559 | 525 | const valIsZero = value.every((i) => i === 0) |
560 | 526 | const opPromise = this.kernel.state.get(key) |
561 | 527 | .then(vertex => vertex.value) |
562 | 528 | .catch(() => null) |
| 529 | + .then() |
563 | 530 | |
564 | 531 | this.vm.pushOpsQueue(opPromise, cbIndex, oldValue => { |
565 | 532 | if (valIsZero && oldValue) { |
566 | 533 | |