git ssb

0+

wanderer🌟 / js-primea-hypervisor



Commit e40cb39472f8609adea6dbe71bd08f434fa64f5c

Environment: implement basic CALL support

Alex Beregszaszi committed on 8/28/2016, 1:15:40 AM
Parent: 9b0a23b3b60da5c801821cb2e1d65c73fa28d343

Files changed

environment.jschanged
index.jschanged
tests/interfaceRunner.jschanged
environment.jsView
@@ -62,17 +62,32 @@
6262 getBlockHash (height) {
6363 return this.blockchain.getBlock(height).hash()
6464 }
6565
66+ set createHandler (value) {
67+ this.createhandler = value
68+ }
69+
70+ set callHandler (value) {
71+ this.callhandler = value
72+ }
73+
6674 // kernal
6775 create (code, value) {
6876 // STUB
6977 return [ 1, Address.zero() ]
7078 }
7179
7280 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 ]
7590 }
7691
7792 callCode (gas, address, value, data) {
7893 // STUB
index.jsView
@@ -106,10 +106,10 @@
106106 environment.callData = call.data
107107 environment.callValue = call.value
108108 environment.gasLeft = call.gasLimit
109109
110- // environment.setCallHandler(this.callHandler)
111- // environment.setCreateHandler(this.createHandler)
110+ environment.callHandler = this.callHandler.bind(this)
111+ environment.createHandler = this.createHandler.bind(this)
112112
113113 const kernel = new Kernel(this, environment)
114114 kernel.codeHandler(code, new Interface(environment))
115115
tests/interfaceRunner.jsView
@@ -28,8 +28,9 @@
2828 environment.parent = ethereum
2929 const testContract = new Kernel(environment)
3030 const ethInterface = new Interface(environment, testContract)
3131 const debugInterface = new DebugInterface()
32+ environment.callHandler = testContract.callHandler.bind(testContract)
3233
3334 try {
3435 const mod = Wasm.instantiateModule(buffer, {
3536 'ethereum': ethInterface.exportTable,

Built with git-ssb-web