Commit 7ac30606a95e63244d5792a232ae3d353b000054
added block wrapper
wanderer authored on 8/22/2016, 4:47:20 PMAlex Beregszaszi committed on 8/23/2016, 12:13:16 AM
Parent: 730ac04e07656503bbe553e2c9bf298a7ee53170
Files changed
environment.js | changed |
interface.js | changed |
testEnvironment.js | changed |
transaction.js | changed |
block.js | added |
environment.js | ||
---|---|---|
@@ -1,9 +1,7 @@ | ||
1 | -const constants = require('./constants.js') | |
2 | 1 | const U256 = require('./u256.js') |
3 | 2 | const Address = require('./address.js') |
4 | -const ethUtils = require('ethereumjs-util') | |
5 | -const Block = require('ethereumjs-block') | |
3 | +const Block = require('./block.js') | |
6 | 4 | const blockChain = require('./fakeBlockChain.js') |
7 | 5 | |
8 | 6 | module.exports = class Environment { |
9 | 7 | constructor (data) { |
interface.js | ||
---|---|---|
@@ -232,9 +232,9 @@ | ||
232 | 232 | */ |
233 | 233 | getBlockHash (number, offset) { |
234 | 234 | this.takeGas(20) |
235 | 235 | |
236 | - const diff = this.environment.block.header.number - number | |
236 | + const diff = this.environment.block.number - number | |
237 | 237 | let hash |
238 | 238 | |
239 | 239 | if (diff > 256 || diff <= 0) { |
240 | 240 | hash = new U256(0) |
@@ -250,9 +250,9 @@ | ||
250 | 250 | */ |
251 | 251 | getBlockCoinbase (offset) { |
252 | 252 | this.takeGas(2) |
253 | 253 | |
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) | |
255 | 255 | } |
256 | 256 | |
257 | 257 | /** |
258 | 258 | * Get the block’s timestamp. |
@@ -260,9 +260,9 @@ | ||
260 | 260 | */ |
261 | 261 | getBlockTimestamp () { |
262 | 262 | this.takeGas(2) |
263 | 263 | |
264 | - return this.environment.block.header.timestamp | |
264 | + return this.environment.block.timestamp | |
265 | 265 | } |
266 | 266 | |
267 | 267 | /** |
268 | 268 | * Get the block’s number. |
@@ -270,9 +270,9 @@ | ||
270 | 270 | */ |
271 | 271 | getBlockNumber () { |
272 | 272 | this.takeGas(2) |
273 | 273 | |
274 | - return this.environment.block.header.number | |
274 | + return this.environment.block.number | |
275 | 275 | } |
276 | 276 | |
277 | 277 | /** |
278 | 278 | * Get the block’s difficulty. |
@@ -280,9 +280,9 @@ | ||
280 | 280 | */ |
281 | 281 | getBlockDifficulty () { |
282 | 282 | this.takeGas(2) |
283 | 283 | |
284 | - return this.environment.block.header.difficulty | |
284 | + return this.environment.block.difficulty | |
285 | 285 | } |
286 | 286 | |
287 | 287 | /** |
288 | 288 | * Get the block’s gas limit. |
@@ -290,9 +290,9 @@ | ||
290 | 290 | */ |
291 | 291 | getBlockGasLimit () { |
292 | 292 | this.takeGas(2) |
293 | 293 | |
294 | - return this.environment.block.header.gasLimit | |
294 | + return this.environment.block.gasLimit | |
295 | 295 | } |
296 | 296 | |
297 | 297 | /** |
298 | 298 | * Creates a new log in the current environment |
@@ -414,9 +414,9 @@ | ||
414 | 414 | const value = this.getMemory(valueOffset, 32).slice(0) |
415 | 415 | const oldValue = this.environment.state.get(path) |
416 | 416 | const valIsZero = value.every((i) => i === 0) |
417 | 417 | |
418 | - // FIXME: gas counting has more cases then the below | |
418 | + this.takeGas(5000) | |
419 | 419 | |
420 | 420 | // write |
421 | 421 | if (!valIsZero && !oldValue) { |
422 | 422 | this.takeGas(15000) |
testEnvironment.js | ||
---|---|---|
@@ -1,8 +1,7 @@ | ||
1 | 1 | const Environment = require('./environment.js') |
2 | 2 | const U256 = require('./u256.js') |
3 | 3 | const Address = require('./address.js') |
4 | -const BN = require('bn.js') | |
5 | 4 | |
6 | 5 | module.exports = class TestEnvironment extends Environment { |
7 | 6 | constructor (data) { |
8 | 7 | super() |
transaction.js | ||
---|---|---|
@@ -2,17 +2,15 @@ | ||
2 | 2 | // This class parses a serialised Ethereum transaction |
3 | 3 | // |
4 | 4 | // The input is a Buffer. |
5 | 5 | // |
6 | - | |
7 | 6 | const Address = require('./address.js') |
8 | 7 | const U256 = require('./u256.js') |
9 | -const ethUtils = require('ethereumjs-util') | |
10 | -const ethTx = require('ethereumjs-tx') | |
8 | +const OldTx = require('ethereumjs-tx') | |
11 | 9 | |
12 | 10 | module.exports = class Transaction { |
13 | 11 | constructor (tx) { |
14 | - this._tx = new ethTx(tx) | |
12 | + this._tx = new OldTx(tx) | |
15 | 13 | } |
16 | 14 | |
17 | 15 | get valid () { |
18 | 16 | return this._tx.verifySignature() |
block.js | ||
---|---|---|
@@ -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