Commit 5a752d9a115323e43483afd85c060ccd9876fd36
Kernel: merge call/create paths in runTx
Alex Beregszaszi committed on 8/28/2016, 9:18:55 PMParent: 0a07ab91671ed72fa98fdba917116ac2cbe4ab81
Files changed
index.js | changed |
index.js | ||
---|---|---|
@@ -182,26 +182,21 @@ | ||
182 | 182 | } |
183 | 183 | |
184 | 184 | fromAccount.set('nonce', fromAccount.get('nonce').add(new U256(1))) |
185 | 185 | |
186 | + let isCreation = false | |
187 | + | |
186 | 188 | // Special case: contract deployment |
187 | 189 | if (tx.to.isZero()) { |
188 | 190 | if (tx.data.length !== 0) { |
189 | 191 | console.log('This is a contract deployment transaction') |
190 | 192 | |
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 | |
199 | 194 | } |
200 | 195 | } |
201 | 196 | |
202 | 197 | // This cost will not be refunded |
203 | - let txCost = 21000 | |
198 | + let txCost = 21000 + (isCreation ? 32000 : 0) | |
204 | 199 | tx.data.forEach((item) => { |
205 | 200 | if (item === 0) { |
206 | 201 | txCost += 4 |
207 | 202 | } else { |
@@ -219,9 +214,10 @@ | ||
219 | 214 | |
220 | 215 | // deduct gasLimit * gasPrice from sender |
221 | 216 | fromAccount.set('balance', fromAccount.get('balance').sub(tx.gasLimit.mul(tx.gasPrice))) |
222 | 217 | |
223 | - let ret = this.callHandler({ | |
218 | + const handler = isCreation ? this.createHandler.bind(this) : this.callHandler.bind(this) | |
219 | + let ret = handler({ | |
224 | 220 | to: tx.to, |
225 | 221 | from: tx.from, |
226 | 222 | gasLimit: tx.gasLimit - txCost, |
227 | 223 | value: tx.value, |
@@ -235,9 +231,10 @@ | ||
235 | 231 | |
236 | 232 | // save new state? |
237 | 233 | |
238 | 234 | return { |
239 | - returnValue: ret.returnValue, | |
235 | + accountCreated: isCreation ? ret.accountCreated : undefined, | |
236 | + returnValue: isCreation ? undefined : ret.returnValue, | |
240 | 237 | gasLeft: ret.gasLeft, |
241 | 238 | logs: ret.logs |
242 | 239 | } |
243 | 240 | } |
Built with git-ssb-web