Commit 8703ef363b38c0652c4ef86ba883fef73c99b1d9
Merge pull request #47 from ewasm/system-contracts-api
Kernel: use new API for system contractswanderer authored on 8/31/2016, 2:14:30 PM
GitHub committed on 8/31/2016, 2:14:30 PM
Parent: 49dfa5e4a80eda9422f7a27a0d55fb30ffc77639
Parent: c4a7bb9447b7405533c5fd047199ec404f449bab
Files changed
index.js | changed |
precompile.js | changed |
index.js | ||
---|---|---|
@@ -97,8 +97,14 @@ | ||
97 | 97 | |
98 | 98 | // Transcompile code |
99 | 99 | // FIXME: decide if these are the right values here: from: 0, gasLimit: 0, value: 0 |
100 | 100 | code = this.callHandler({ from: Address.zero(), to: transcompilerContract, gasLimit: 0, value: new U256(0), data: code }).returnValue |
101 | + | |
102 | + if (code[0] === 0) { | |
103 | + code = code.slice(1) | |
104 | + } else { | |
105 | + throw new Error('Transcompilation failed: ' + Buffer.from(code).slice(1).toString()) | |
106 | + } | |
101 | 107 | } |
102 | 108 | |
103 | 109 | // creats a new Kernel |
104 | 110 | const environment = new Environment() |
@@ -148,8 +154,14 @@ | ||
148 | 154 | // Inject metering |
149 | 155 | if (Utils.isWASMCode(code)) { |
150 | 156 | // FIXME: decide if these are the right values here: from: 0, gasLimit: 0, value: 0 |
151 | 157 | code = this.callHandler({ from: Address.zero(), to: meteringContract, gasLimit: 0, value: new U256(0), data: code }).returnValue |
158 | + | |
159 | + if (code[0] === 0) { | |
160 | + code = code.slice(1) | |
161 | + } else { | |
162 | + throw new Error('Metering injection failed: ' + Buffer.from(code).slice(1).toString()) | |
163 | + } | |
152 | 164 | } |
153 | 165 | |
154 | 166 | let address = Utils.newAccountAddress(create.from, code) |
155 | 167 |
precompile.js | ||
---|---|---|
@@ -1,20 +1,25 @@ | ||
1 | 1 | // const evm2wasm = require('evm2wasm') |
2 | 2 | // const metering = require('wasm-metering') |
3 | 3 | |
4 | +function craftResponse (status, msg) { | |
5 | + // NOTE: why does this has to be so hard? | |
6 | + return Uint8Array.from(Buffer.concat([ new Buffer([ status ]), new Buffer(msg) ])) | |
7 | +} | |
8 | + | |
4 | 9 | module.exports.meteringInjector = function (call) { |
5 | 10 | console.log('Executing metering injector') |
6 | 11 | return { |
7 | 12 | // returnValue: metering.injectWAST(call.data, 2).slice(0) |
8 | - returnValue: call.data.slice(0) | |
13 | + returnValue: craftResponse(0, call.data) | |
9 | 14 | } |
10 | 15 | } |
11 | 16 | |
12 | 17 | module.exports.transcompiler = function (call) { |
13 | 18 | console.log('Executing transcompiler') |
14 | 19 | return { |
15 | 20 | // returnValue: evm2wasm.compileEVM(call.data).slice(0) |
16 | - returnValue: call.data.slice(0) | |
21 | + returnValue: craftResponse(1, 'Code not supported: ' + Buffer.from(call.data.slice(0, 8)).toString('hex') + '...') | |
17 | 22 | } |
18 | 23 | } |
19 | 24 | |
20 | 25 | module.exports.identity = function (call) { |
Built with git-ssb-web