Commit 448365b0d86410e9ec040c1956c8ad27e5b482d5
Interface: split out takeGas from useGas
Alex Beregszaszi committed on 8/18/2016, 10:39:48 PMParent: da7b20096a9e2da5c16128a768e529a9070114a8
Files changed
interface.js | changed |
interface.js | ||
---|---|---|
@@ -64,13 +64,9 @@ | ||
64 | 64 | if (amount < 0) { |
65 | 65 | throw new Error('Negative gas deduction requested') |
66 | 66 | } |
67 | 67 | |
68 | - if (this.environment.gasLimit < amount) { | |
69 | - throw new Error('Ran out of gas') | |
70 | - } | |
71 | - | |
72 | - this.environment.gasLimit -= amount | |
68 | + this.takeGas(amount) | |
73 | 69 | } |
74 | 70 | |
75 | 71 | /** |
76 | 72 | * Returns the current amount of gas |
@@ -419,8 +415,19 @@ | ||
419 | 415 | setMemory (offset, length, value) { |
420 | 416 | const memory = new Uint8Array(this.module.exports.memory, offset, length) |
421 | 417 | memory.set(value) |
422 | 418 | } |
419 | + | |
420 | + /* | |
421 | + * Takes gas from the tank. Only needs to check if there's gas left to be taken, | |
422 | + * because every caller of this method is trusted. | |
423 | + */ | |
424 | + takeGas (amount) { | |
425 | + if (this.environment.gasLimit < amount) { | |
426 | + throw new Error('Ran out of gas') | |
427 | + } | |
428 | + this.environment.gasLimit -= amount | |
429 | + } | |
423 | 430 | } |
424 | 431 | |
425 | 432 | // |
426 | 433 | // Polyfill required unless this is sorted: https://bugs.chromium.org/p/chromium/issues/detail?id=633895 |
Built with git-ssb-web