git ssb

0+

wanderer🌟 / js-primea-hypervisor



Commit 5a752d9a115323e43483afd85c060ccd9876fd36

Kernel: merge call/create paths in runTx

Alex Beregszaszi committed on 8/28/2016, 9:18:55 PM
Parent: 0a07ab91671ed72fa98fdba917116ac2cbe4ab81

Files changed

index.jschanged
index.jsView
@@ -182,26 +182,21 @@
182182 }
183183
184184 fromAccount.set('nonce', fromAccount.get('nonce').add(new U256(1)))
185185
186+ let isCreation = false
187+
186188 // Special case: contract deployment
187189 if (tx.to.isZero()) {
188190 if (tx.data.length !== 0) {
189191 console.log('This is a contract deployment transaction')
190192
191- // FIXME: deduct fees
192-
193- return this.createHandler({
194- from: tx.from,
195- gasLimit: tx.gasLimit,
196- value: tx.value,
197- data: tx.data
198- })
193+ isCreation = true
199194 }
200195 }
201196
202197 // This cost will not be refunded
203- let txCost = 21000
198+ let txCost = 21000 + (isCreation ? 32000 : 0)
204199 tx.data.forEach((item) => {
205200 if (item === 0) {
206201 txCost += 4
207202 } else {
@@ -219,9 +214,10 @@
219214
220215 // deduct gasLimit * gasPrice from sender
221216 fromAccount.set('balance', fromAccount.get('balance').sub(tx.gasLimit.mul(tx.gasPrice)))
222217
223- let ret = this.callHandler({
218+ const handler = isCreation ? this.createHandler.bind(this) : this.callHandler.bind(this)
219+ let ret = handler({
224220 to: tx.to,
225221 from: tx.from,
226222 gasLimit: tx.gasLimit - txCost,
227223 value: tx.value,
@@ -235,9 +231,10 @@
235231
236232 // save new state?
237233
238234 return {
239- returnValue: ret.returnValue,
235+ accountCreated: isCreation ? ret.accountCreated : undefined,
236+ returnValue: isCreation ? undefined : ret.returnValue,
240237 gasLeft: ret.gasLeft,
241238 logs: ret.logs
242239 }
243240 }

Built with git-ssb-web