Commit e40cb39472f8609adea6dbe71bd08f434fa64f5c
Environment: implement basic CALL support
Alex Beregszaszi committed on 8/28/2016, 1:15:40 AMParent: 9b0a23b3b60da5c801821cb2e1d65c73fa28d343
Files changed
environment.js | changed |
index.js | changed |
tests/interfaceRunner.js | changed |
environment.js | ||
---|---|---|
@@ -62,17 +62,32 @@ | ||
62 | 62 | getBlockHash (height) { |
63 | 63 | return this.blockchain.getBlock(height).hash() |
64 | 64 | } |
65 | 65 | |
66 | + set createHandler (value) { | |
67 | + this.createhandler = value | |
68 | + } | |
69 | + | |
70 | + set callHandler (value) { | |
71 | + this.callhandler = value | |
72 | + } | |
73 | + | |
66 | 74 | // kernal |
67 | 75 | create (code, value) { |
68 | 76 | // STUB |
69 | 77 | return [ 1, Address.zero() ] |
70 | 78 | } |
71 | 79 | |
72 | 80 | call (gas, address, value, data) { |
73 | - // STUB | |
74 | - return [ 1, new Uint8Array() ] | |
81 | + // FIXME: create a child environment here | |
82 | + const ret = this.callhandler({ | |
83 | + from: this.address, | |
84 | + to: address, | |
85 | + gasLimit: gas, | |
86 | + value: value, | |
87 | + data: data | |
88 | + }) | |
89 | + return [ !!ret.executionOutcome, ret.returnValue ] | |
75 | 90 | } |
76 | 91 | |
77 | 92 | callCode (gas, address, value, data) { |
78 | 93 | // STUB |
index.js | ||
---|---|---|
@@ -106,10 +106,10 @@ | ||
106 | 106 | environment.callData = call.data |
107 | 107 | environment.callValue = call.value |
108 | 108 | environment.gasLeft = call.gasLimit |
109 | 109 | |
110 | - // environment.setCallHandler(this.callHandler) | |
111 | - // environment.setCreateHandler(this.createHandler) | |
110 | + environment.callHandler = this.callHandler.bind(this) | |
111 | + environment.createHandler = this.createHandler.bind(this) | |
112 | 112 | |
113 | 113 | const kernel = new Kernel(this, environment) |
114 | 114 | kernel.codeHandler(code, new Interface(environment)) |
115 | 115 |
tests/interfaceRunner.js | ||
---|---|---|
@@ -28,8 +28,9 @@ | ||
28 | 28 | environment.parent = ethereum |
29 | 29 | const testContract = new Kernel(environment) |
30 | 30 | const ethInterface = new Interface(environment, testContract) |
31 | 31 | const debugInterface = new DebugInterface() |
32 | + environment.callHandler = testContract.callHandler.bind(testContract) | |
32 | 33 | |
33 | 34 | try { |
34 | 35 | const mod = Wasm.instantiateModule(buffer, { |
35 | 36 | 'ethereum': ethInterface.exportTable, |
Built with git-ssb-web