Commit 8ff4e4d6eb9c888cbb0c757e872b6da49d98c1e8
Kernel: assume that every number is an instance of U256
Alex Beregszaszi committed on 8/23/2016, 12:27:46 AMParent: c6e879cecacacc8ce87b4741f02493827fd992c8
Files changed
index.js | changed |
index.js | ||
---|---|---|
@@ -21,8 +21,9 @@ | ||
21 | 21 | |
22 | 22 | const DebugInterface = require('./debugInterface.js') |
23 | 23 | |
24 | 24 | const Address = require('./address.js') |
25 | +const U256 = require('./u256.js') | |
25 | 26 | const Utils = require('./utils.js') |
26 | 27 | |
27 | 28 | module.exports = class Kernel { |
28 | 29 | // runs some code in the VM |
@@ -101,10 +102,10 @@ | ||
101 | 102 | //this.environment.state.set(address, { stateRoot: stateRoot }) |
102 | 103 | |
103 | 104 | return { |
104 | 105 | executionOutcome: 1, // success |
105 | - gasLeft: environment.gasLimit, // this starts as the limit and results as the gas left | |
106 | - gasRefund: environment.gasRefund, | |
106 | + gasLeft: new U256(environment.gasLimit), // this starts as the limit and results as the gas left | |
107 | + gasRefund: new U256(environment.gasRefund), | |
107 | 108 | returnValue: environment.returnValue, |
108 | 109 | selfDestructAddress: environment.selfDestructAddress, |
109 | 110 | logs: environment.logs |
110 | 111 | } |
@@ -135,19 +136,19 @@ | ||
135 | 136 | throw new Error('Sender account not found') |
136 | 137 | } |
137 | 138 | |
138 | 139 | // deduct gasLimit * gasPrice from sender |
139 | - if (fromAccount.balance < (tx.gasLimit * tx.gasPrice)) { | |
140 | + if (fromAccount.balance.lt(tx.gasLimit.mul(tx.gasPrice))) { | |
140 | 141 | throw new Error('Insufficient account balance') |
141 | 142 | } |
142 | 143 | |
143 | - fromAccount.balance -= ts.gasLimit * tx.gasPrice | |
144 | + fromAccount.balance = fromAccount.balance.sub(ts.gasLimit.mul(tx.gasPrice)) | |
144 | 145 | |
145 | 146 | let ret = this.callHandler(tx.to, tx.gasLimit, tx.gasPrice, tx.value, tx.data) |
146 | 147 | |
147 | 148 | // refund gas |
148 | 149 | if (ret.executionOutcome === 1) { |
149 | - fromAccount.balance += (ret.gasLeft + ret.gasRefund) * tx.gasPrice | |
150 | + fromAccount.balance = fromAccount.balance.add(tx.gasPrice.mul(ret.gasLeft.add(ret.gasRefund))) | |
150 | 151 | } |
151 | 152 | |
152 | 153 | // save new state? |
153 | 154 |
Built with git-ssb-web