git ssb

0+

wanderer🌟 / js-primea-hypervisor



Commit 448365b0d86410e9ec040c1956c8ad27e5b482d5

Interface: split out takeGas from useGas

Alex Beregszaszi committed on 8/18/2016, 10:39:48 PM
Parent: da7b20096a9e2da5c16128a768e529a9070114a8

Files changed

interface.jschanged
interface.jsView
@@ -64,13 +64,9 @@
6464 if (amount < 0) {
6565 throw new Error('Negative gas deduction requested')
6666 }
6767
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)
7369 }
7470
7571 /**
7672 * Returns the current amount of gas
@@ -419,8 +415,19 @@
419415 setMemory (offset, length, value) {
420416 const memory = new Uint8Array(this.module.exports.memory, offset, length)
421417 memory.set(value)
422418 }
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+ }
423430 }
424431
425432 //
426433 // Polyfill required unless this is sorted: https://bugs.chromium.org/p/chromium/issues/detail?id=633895

Built with git-ssb-web