Commit be42af81974876ce832fa149178075c8fca67321
Merge branch 'shim' into testing
wanderer committed on 9/13/2016, 6:42:03 PMParent: faee2f5886f2e3201e3ae568539673700c84ecb3
Parent: 3b07461593e97b8ecb99d055a38948670485d41e
Files changed
index.js | changed |
interface.js | changed |
wasm/interface.wasm | changed |
wasm/interface.wast | changed |
index.js | ||
---|---|---|
@@ -58,8 +58,10 @@ | ||
58 | 58 | 'env': ethInterface.exportTable |
59 | 59 | } |
60 | 60 | // add shims |
61 | 61 | imports.ethereum.useGas = ethInterface.shims.exports.useGas |
62 | + imports.ethereum.getGasLeft = ethInterface.shims.exports.getGasLeft | |
63 | + | |
62 | 64 | const instance = WebAssembly.Instance(module, imports) |
63 | 65 | |
64 | 66 | ethInterface.setModule(instance) |
65 | 67 | debugInterface.setModule(instance) |
interface.js | ||
---|---|---|
@@ -18,17 +18,18 @@ | ||
18 | 18 | const shimBin = fs.readFileSync(path.join(__dirname, '/wasm/interface.wasm')) |
19 | 19 | const shimMod = WebAssembly.Module(shimBin) |
20 | 20 | this.shims = WebAssembly.Instance(shimMod, { |
21 | 21 | 'interface': { |
22 | - 'useGas': this._useGas.bind(this) | |
22 | + 'useGas': this._useGas.bind(this), | |
23 | + 'getGasLeftHigh': this._getGasLeftHigh.bind(this), | |
24 | + 'getGasLeftLow': this._getGasLeftLow.bind(this) | |
23 | 25 | } |
24 | 26 | }) |
25 | 27 | } |
26 | 28 | |
27 | 29 | get exportTable () { |
28 | 30 | let exportMethods = [ |
29 | 31 | // include all the public methods according to the Ethereum Environment Interface (EEI) r1 |
30 | - 'getGasLeft', | |
31 | 32 | 'getAddress', |
32 | 33 | 'getBalance', |
33 | 34 | 'getTxOrigin', |
34 | 35 | 'getCaller', |
@@ -91,10 +92,17 @@ | ||
91 | 92 | /** |
92 | 93 | * Returns the current amount of gas |
93 | 94 | * @return {integer} |
94 | 95 | */ |
95 | - getGasLeft () { | |
96 | - this.takeGas(2) | |
96 | + _getGasLeftHigh () { | |
97 | + return Math.floor(this.environment.gasLeft / 4294967296) | |
98 | + } | |
99 | + | |
100 | + /** | |
101 | + * Returns the current amount of gas | |
102 | + * @return {integer} | |
103 | + */ | |
104 | + _getGasLeftLow () { | |
97 | 105 | return this.environment.gasLeft |
98 | 106 | } |
99 | 107 | |
100 | 108 | /** |
wasm/interface.wasm | ||
---|---|---|
@@ -1,2 +1,2 @@ | ||
1 | - asm type | |
2 | -@ @ import interfaceuseGasfunctionexport useGascode f� � | |
1 | + asm type@ @ @ @ importF interfaceuseGas interfacegetGasLeftHigh interface getGasLeftLowfunctionexport useGas | |
2 | +getGasLeftcode& f� � � e �[ |
wasm/interface.wast | ||
---|---|---|
@@ -1,11 +1,25 @@ | ||
1 | 1 | (module |
2 | - (import $useGas "interface" "useGas" (param i32 i32)) | |
2 | + ;; useGas | |
3 | + (import $useGas "interface" "useGas" (param i32 i32)) | |
3 | 4 | (func $useGasShim |
4 | 5 | (param $amount i64) |
5 | 6 | (call_import $useGas |
6 | 7 | (i32.wrap/i64 |
7 | 8 | (i64.shr_u (get_local $amount) (i64.const 32))) |
8 | 9 | (i32.wrap/i64 (get_local $amount))) |
9 | 10 | ) |
10 | 11 | (export "useGas" $useGasShim) |
12 | + | |
13 | + ;; getGasLeft | |
14 | + (import $getGasLeftHigh "interface" "getGasLeftHigh" (result i32)) | |
15 | + (import $getGasLeftLow "interface" "getGasLeftLow" (result i32)) | |
16 | + (func $getGasLeft | |
17 | + (result i64) | |
18 | + (call_import $useGas (i32.const 0) (i32.const 2)) | |
19 | + (return | |
20 | + (i64.add | |
21 | + (i64.shl (i64.extend_u/i32 (call_import $getGasLeftHigh)) (i64.const 32)) | |
22 | + (i64.extend_u/i32 (call_import $getGasLeftLow)))) | |
23 | + ) | |
24 | + (export "getGasLeft" $getGasLeft) | |
11 | 25 | ) |
Built with git-ssb-web