git ssb

0+

wanderer🌟 / js-primea-hypervisor



Commit 67053274fc3dc39d5be81c4365673d94bd15a6bf

Merge pull request #41 from ewasm/create

Create: split out create machinism and support deploy/runtime bytecode
Alex Beregszaszi authored on 8/26/2016, 11:31:08 PM
GitHub committed on 8/26/2016, 11:31:08 PM
Parent: 35fc7a2516bd2641e4b9bb32ebdaed256fe57491
Parent: 254f1dd5867137c7707537afbcff63ec3aee6563

Files changed

index.jschanged
index.jsView
@@ -88,9 +88,10 @@
8888 if (!Utils.isWASMCode(code)) {
8989 // throw new Error('Not an eWASM contract')
9090
9191 // Transcompile code
92- code = this.callHandler({ to: transcompilerContract, data: code }).returnValue
92+ // FIXME: decide if these are the right values here: from: 0, gasLimit: 0, value: 0
93+ code = this.callHandler({ from: Address.zero(), to: transcompilerContract, gasLimit: 0, value: new U256(0), data: code }).returnValue
9394 }
9495
9596 // creats a new Kernel
9697 const environment = new Environment()
@@ -105,9 +106,10 @@
105106 environment.callData = call.data
106107 environment.callValue = call.value
107108 environment.gasLeft = call.gasLimit
108109
109- // environment.setCallHandler(callHandler)
110+ // environment.setCallHandler(this.callHandler)
111+ // environment.setCreateHandler(this.createHandler)
110112
111113 const kernel = new Kernel(this, environment)
112114 kernel.codeHandler(code, new Interface(environment))
113115
@@ -123,8 +125,35 @@
123125 logs: environment.logs
124126 }
125127 }
126128
129+ createHandler (create) {
130+ let code = create.data
131+
132+ // Inject metering
133+ if (Utils.isWASMCode(code)) {
134+ // FIXME: decide if these are the right values here: from: 0, gasLimit: 0, value: 0
135+ code = this.callHandler({ from: Address.zero(), to: meteringContract, gasLimit: 0, value: new U256(0), data: code }).returnValue
136+ }
137+
138+ let address = Utils.newAccountAddress(create.from, code)
139+
140+ this.environment.addAccount(address.toString(), {
141+ balance: create.value,
142+ code: code
143+ })
144+
145+ // Run code and take return value as contract code
146+ // FIXME: decide if these are the right values here: value: 0, data: ''
147+ code = this.callHandler({ from: create.from, to: address, gasLimit: create.gasLimit, value: new U256(0), data: new Uint8Array() }).returnValue
148+
149+ this.environment.state.get(address.toString()).set('code', code)
150+
151+ return {
152+ accountCreated: address
153+ }
154+ }
155+
127156 // run tx; the tx message handler
128157 runTx (tx, environment = new Environment()) {
129158 this.environment = environment
130159
@@ -151,23 +180,16 @@
151180 if (tx.to.isZero()) {
152181 if (tx.data.length !== 0) {
153182 console.log('This is a contract deployment transaction')
154183
155- // Inject metering
156- const code = this.callHandler({ to: meteringContract, data: tx.data }).returnValue
184+ // FIXME: deduct fees
157185
158- let address = Utils.newAccountAddress(tx.from, code)
159-
160- this.environment.addAccount(address.toString(), {
161- balance: tx.value,
162- code: code
186+ return this.createHandler({
187+ from: tx.from,
188+ gasLimit: tx.gasLimit,
189+ value: tx.value,
190+ data: tx.data
163191 })
164-
165- // FIXME: deduct fees
166-
167- return {
168- accountCreated: address
169- }
170192 }
171193 }
172194
173195 // deduct gasLimit * gasPrice from sender

Built with git-ssb-web