EVMinterface.jsView |
---|
128 | 128 | */ |
129 | 129 | getBalance (addressOffset, offset, cbIndex) { |
130 | 130 | this.takeGas(20) |
131 | 131 | |
132 | | - const path = [common.PARENT, '0x' + new Buffer(this.getMemory(addressOffset, ADDRESS_SIZE_BYTES)).toString('hex')] |
133 | | - const opPromise = this.kernel.send(common.PARENT, new Message({ |
| 132 | + const path = [common.PARENT, common.PARENT, '0x' + new Buffer(this.getMemory(addressOffset, ADDRESS_SIZE_BYTES)).toString('hex')] |
| 133 | + const opPromise = this.kernel.send(new Message({ |
134 | 134 | to: path, |
135 | 135 | data: { |
136 | 136 | getValue: 'balance' |
137 | 137 | }, |
138 | 138 | sync: true |
139 | 139 | })) |
140 | | - .catch(() => new U256(0)) |
| 140 | + .catch(() => new Buffer([])) |
141 | 141 | |
142 | 142 | this.api.pushOpsQueue(opPromise, cbIndex, balance => { |
143 | 143 | this.setMemory(offset, U128_SIZE_BYTES, new U256(balance).toMemory(U128_SIZE_BYTES)) |
144 | 144 | }) |
152 | 152 | */ |
153 | 153 | getTxOrigin (offset) { |
154 | 154 | this.takeGas(2) |
155 | 155 | |
156 | | - const origin = new Buffer(this.message.from[1].slice(2), 'hex') |
| 156 | + const origin = new Buffer(this.message.from[2].slice(2), 'hex') |
157 | 157 | this.setMemory(offset, ADDRESS_SIZE_BYTES, origin) |
158 | 158 | } |
159 | 159 | |
160 | 160 | |
311 | 311 | */ |
312 | 312 | getBlockHash (number, offset, cbOffset) { |
313 | 313 | this.takeGas(20) |
314 | 314 | |
315 | | - const diff = this.block.number - number |
| 315 | + const diff = this.message.block.number - number |
316 | 316 | let opPromise |
317 | 317 | |
318 | 318 | if (diff > 256 || diff <= 0) { |
319 | 319 | opPromise = Promise.resolve(new U256(0)) |
333 | 333 | */ |
334 | 334 | getBlockCoinbase (offset) { |
335 | 335 | this.takeGas(2) |
336 | 336 | |
337 | | - this.setMemory(offset, ADDRESS_SIZE_BYTES, this.block.header.coinbase) |
| 337 | + this.setMemory(offset, ADDRESS_SIZE_BYTES, this.message.block.header.coinbase) |
338 | 338 | } |
339 | 339 | |
340 | 340 | |
341 | 341 | * Get the block’s timestamp. |
343 | 343 | */ |
344 | 344 | getBlockTimestamp () { |
345 | 345 | this.takeGas(2) |
346 | 346 | |
347 | | - return this.block.timestamp |
| 347 | + return this.message.block.timestamp |
348 | 348 | } |
349 | 349 | |
350 | 350 | |
351 | 351 | * Get the block’s number. |
353 | 353 | */ |
354 | 354 | getBlockNumber () { |
355 | 355 | this.takeGas(2) |
356 | 356 | |
357 | | - return this.block.number |
| 357 | + return this.message.block.number |
358 | 358 | } |
359 | 359 | |
360 | 360 | |
361 | 361 | * Get the block’s difficulty. |
363 | 363 | */ |
364 | 364 | getBlockDifficulty (offset) { |
365 | 365 | this.takeGas(2) |
366 | 366 | |
367 | | - this.setMemory(offset, U256_SIZE_BYTES, this.block.difficulty.toMemory()) |
| 367 | + this.setMemory(offset, U256_SIZE_BYTES, this.message.block.difficulty.toMemory()) |
368 | 368 | } |
369 | 369 | |
370 | 370 | |
371 | 371 | * Get the block’s gas limit. |
552 | 552 | * @param {interger} valueOffset the memory offset to load the value from |
553 | 553 | */ |
554 | 554 | storageStore (pathOffset, valueOffset, cbIndex) { |
555 | 555 | this.takeGas(5000) |
556 | | - const path = [new Buffer(this.getMemory(pathOffset, U256_SIZE_BYTES)).toString('hex')] |
| 556 | + const key = new Buffer(this.getMemory(pathOffset, U256_SIZE_BYTES)).toString('hex') |
557 | 557 | |
558 | 558 | const value = this.getMemory(valueOffset, U256_SIZE_BYTES).slice(0) |
559 | 559 | const valIsZero = value.every((i) => i === 0) |
560 | | - const opPromise = this.kernel.getValue(path) |
| 560 | + const opPromise = this.kernel.stateInterface.get(key) |
561 | 561 | .then(vertex => vertex.value) |
562 | 562 | .catch(() => null) |
563 | 563 | |
564 | 564 | this.api.pushOpsQueue(opPromise, cbIndex, oldValue => { |
565 | 565 | if (valIsZero && oldValue) { |
566 | 566 | |
567 | 567 | this.results.gasRefund += 15000 |
568 | | - this.kernel.deleteValue(path) |
| 568 | + this.kernel.storageInterface.del(key) |
569 | 569 | } else { |
570 | 570 | if (!valIsZero && !oldValue) { |
571 | 571 | |
572 | 572 | this.takeGas(15000) |
573 | 573 | } |
574 | 574 | |
575 | | - this.kernel.setValue(path, new Vertex({ |
| 575 | + this.kernel.stateInterface.set(key, new Vertex({ |
576 | 576 | value: value |
577 | 577 | })) |
578 | 578 | } |
579 | 579 | }) |
587 | 587 | storageLoad (pathOffset, resultOffset, cbIndex) { |
588 | 588 | this.takeGas(50) |
589 | 589 | |
590 | 590 | |
591 | | - const path = [new Buffer(this.getMemory(pathOffset, U256_SIZE_BYTES)).toString('hex')] |
| 591 | + const key = new Buffer(this.getMemory(pathOffset, U256_SIZE_BYTES)).toString('hex') |
592 | 592 | |
593 | | - const opPromise = this.kernel.getValue(path) |
| 593 | + const opPromise = this.kernel.stateInterface.get(key) |
594 | 594 | .then(vertex => vertex.value) |
595 | 595 | .catch(() => new Uint8Array(32)) |
596 | 596 | |
597 | 597 | this.api.pushOpsQueue(opPromise, cbIndex, value => { |