git ssb

0+

wanderer🌟 / js-primea-hypervisor



Commit 05bf86af31b825ac9b412fbc4b18522d2b40e829

Kernel: split createHandler out of runTx

Alex Beregszaszi committed on 8/26/2016, 9:40:45 PM
Parent: 35fc7a2516bd2641e4b9bb32ebdaed256fe57491

Files changed

index.jschanged
index.jsView
@@ -105,9 +105,10 @@
105105 environment.callData = call.data
106106 environment.callValue = call.value
107107 environment.gasLeft = call.gasLimit
108108
109- // environment.setCallHandler(callHandler)
109+ // environment.setCallHandler(this.callHandler)
110+ // environment.setCreateHandler(this.createHandler)
110111
111112 const kernel = new Kernel(this, environment)
112113 kernel.codeHandler(code, new Interface(environment))
113114
@@ -123,8 +124,24 @@
123124 logs: environment.logs
124125 }
125126 }
126127
128+ createHandler (create) {
129+ // Inject metering
130+ const code = this.callHandler({ to: meteringContract, data: create.data }).returnValue
131+
132+ let address = Utils.newAccountAddress(create.from, code)
133+
134+ this.environment.addAccount(address.toString(), {
135+ balance: create.value,
136+ code: code
137+ })
138+
139+ return {
140+ accountCreated: address
141+ }
142+ }
143+
127144 // run tx; the tx message handler
128145 runTx (tx, environment = new Environment()) {
129146 this.environment = environment
130147
@@ -151,23 +168,16 @@
151168 if (tx.to.isZero()) {
152169 if (tx.data.length !== 0) {
153170 console.log('This is a contract deployment transaction')
154171
155- // Inject metering
156- const code = this.callHandler({ to: meteringContract, data: tx.data }).returnValue
172+ // FIXME: deduct fees
157173
158- let address = Utils.newAccountAddress(tx.from, code)
159-
160- this.environment.addAccount(address.toString(), {
161- balance: tx.value,
162- code: code
174+ return this.createHandler({
175+ from: tx.from,
176+ gasLimit: tx.gasLimit,
177+ value: tx.value,
178+ data: txdata
163179 })
164-
165- // FIXME: deduct fees
166-
167- return {
168- accountCreated: address
169- }
170180 }
171181 }
172182
173183 // deduct gasLimit * gasPrice from sender

Built with git-ssb-web