git ssb

0+

wanderer🌟 / js-primea-hypervisor



Commit 7ac30606a95e63244d5792a232ae3d353b000054

added block wrapper

wanderer authored on 8/22/2016, 4:47:20 PM
Alex Beregszaszi committed on 8/23/2016, 12:13:16 AM
Parent: 730ac04e07656503bbe553e2c9bf298a7ee53170

Files changed

environment.jschanged
interface.jschanged
testEnvironment.jschanged
transaction.jschanged
block.jsadded
environment.jsView
@@ -1,9 +1,7 @@
1-const constants = require('./constants.js')
21 const U256 = require('./u256.js')
32 const Address = require('./address.js')
4-const ethUtils = require('ethereumjs-util')
5-const Block = require('ethereumjs-block')
3+const Block = require('./block.js')
64 const blockChain = require('./fakeBlockChain.js')
75
86 module.exports = class Environment {
97 constructor (data) {
interface.jsView
@@ -232,9 +232,9 @@
232232 */
233233 getBlockHash (number, offset) {
234234 this.takeGas(20)
235235
236- const diff = this.environment.block.header.number - number
236+ const diff = this.environment.block.number - number
237237 let hash
238238
239239 if (diff > 256 || diff <= 0) {
240240 hash = new U256(0)
@@ -250,9 +250,9 @@
250250 */
251251 getBlockCoinbase (offset) {
252252 this.takeGas(2)
253253
254- this.setMemory(offset, constants.ADDRESS_SIZE_BYTES, this.environment.block.header.coinbase)
254+ this.setMemory(offset, constants.ADDRESS_SIZE_BYTES, this.environment.block.coinbase)
255255 }
256256
257257 /**
258258 * Get the block’s timestamp.
@@ -260,9 +260,9 @@
260260 */
261261 getBlockTimestamp () {
262262 this.takeGas(2)
263263
264- return this.environment.block.header.timestamp
264+ return this.environment.block.timestamp
265265 }
266266
267267 /**
268268 * Get the block’s number.
@@ -270,9 +270,9 @@
270270 */
271271 getBlockNumber () {
272272 this.takeGas(2)
273273
274- return this.environment.block.header.number
274+ return this.environment.block.number
275275 }
276276
277277 /**
278278 * Get the block’s difficulty.
@@ -280,9 +280,9 @@
280280 */
281281 getBlockDifficulty () {
282282 this.takeGas(2)
283283
284- return this.environment.block.header.difficulty
284+ return this.environment.block.difficulty
285285 }
286286
287287 /**
288288 * Get the block’s gas limit.
@@ -290,9 +290,9 @@
290290 */
291291 getBlockGasLimit () {
292292 this.takeGas(2)
293293
294- return this.environment.block.header.gasLimit
294+ return this.environment.block.gasLimit
295295 }
296296
297297 /**
298298 * Creates a new log in the current environment
@@ -414,9 +414,9 @@
414414 const value = this.getMemory(valueOffset, 32).slice(0)
415415 const oldValue = this.environment.state.get(path)
416416 const valIsZero = value.every((i) => i === 0)
417417
418- // FIXME: gas counting has more cases then the below
418+ this.takeGas(5000)
419419
420420 // write
421421 if (!valIsZero && !oldValue) {
422422 this.takeGas(15000)
testEnvironment.jsView
@@ -1,8 +1,7 @@
11 const Environment = require('./environment.js')
22 const U256 = require('./u256.js')
33 const Address = require('./address.js')
4-const BN = require('bn.js')
54
65 module.exports = class TestEnvironment extends Environment {
76 constructor (data) {
87 super()
transaction.jsView
@@ -2,17 +2,15 @@
22 // This class parses a serialised Ethereum transaction
33 //
44 // The input is a Buffer.
55 //
6-
76 const Address = require('./address.js')
87 const U256 = require('./u256.js')
9-const ethUtils = require('ethereumjs-util')
10-const ethTx = require('ethereumjs-tx')
8+const OldTx = require('ethereumjs-tx')
119
1210 module.exports = class Transaction {
1311 constructor (tx) {
14- this._tx = new ethTx(tx)
12+ this._tx = new OldTx(tx)
1513 }
1614
1715 get valid () {
1816 return this._tx.verifySignature()
block.jsView
@@ -1,0 +1,30 @@
1+//
2+// This class parses a serialised Ethereum Block
3+//
4+// The input is a Buffer.
5+//
6+const Address = require('./address.js')
7+const ethUtil = require('ethereumjs-util')
8+const OldBlock = require('ethereumjs-block')
9+
10+module.exports = class Block extends OldBlock {
11+ get number () {
12+ return ethUtil.bufferToInt(this.header.number)
13+ }
14+
15+ get gasLimit () {
16+ return ethUtil.bufferToInt(this.header.gasLimit)
17+ }
18+
19+ get difficulty () {
20+ return ethUtil.bufferToInt(this.header.difficulty)
21+ }
22+
23+ get timestamp () {
24+ return ethUtil.bufferToInt(this.header.timestamp)
25+ }
26+
27+ get coinbase () {
28+ return new Address(this.header.coinbase)
29+ }
30+}

Built with git-ssb-web