diff --git a/ethereumj-core/src/main/java/org/ethereum/core/Block.java b/ethereumj-core/src/main/java/org/ethereum/core/Block.java index f8ce6771..d1fd49f7 100644 --- a/ethereumj-core/src/main/java/org/ethereum/core/Block.java +++ b/ethereumj-core/src/main/java/org/ethereum/core/Block.java @@ -66,9 +66,6 @@ public class Block { this.parsed = true; } - // [parent_hash, uncles_hash, coinbase, state_root, tx_trie_root, - // difficulty, number, minGasPrice, gasLimit, gasUsed, timestamp, - // extradata, nonce] private void parseRLP() { RLPList params = (RLPList) RLP.decode2(rlpEncoded); @@ -294,15 +291,15 @@ public class Block { * likely next period. Conversely, if the period is too large, the difficulty, * and expected time to the next block, is reduced. */ - private boolean isValid() { - boolean isValid = false; + public boolean isValid() { + boolean isValid = true; // verify difficulty meets requirements - isValid = this.getDifficulty() == this.calcDifficulty(); + //isValid = this.getDifficulty() == this.calcDifficulty(); // verify gasLimit meets requirements - isValid = this.getGasLimit() == this.calcGasLimit(); + //isValid = this.getGasLimit() == this.calcGasLimit(); // verify timestamp meets requirements - isValid = this.getTimestamp() > this.getParent().getTimestamp(); +// isValid = this.getTimestamp() > this.getParent().getTimestamp(); return isValid; } diff --git a/ethereumj-core/src/main/java/org/ethereum/core/Blockchain.java b/ethereumj-core/src/main/java/org/ethereum/core/Blockchain.java index 2c08d939..b4ef3687 100644 --- a/ethereumj-core/src/main/java/org/ethereum/core/Blockchain.java +++ b/ethereumj-core/src/main/java/org/ethereum/core/Blockchain.java @@ -83,11 +83,13 @@ public class Blockchain extends ArrayList { } private void addBlock(Block block) { - this.wallet.processBlock(block); - this.gasPrice = block.getMinGasPrice(); - if(lastBlock == null || block.getNumber() > lastBlock.getNumber()) - this.lastBlock = block; - this.add(block); + if(block.isValid()) { + this.wallet.processBlock(block); + this.gasPrice = block.getMinGasPrice(); + if(lastBlock == null || block.getNumber() > lastBlock.getNumber()) + this.lastBlock = block; + this.add(block); + } } public long getGasPrice() { diff --git a/ethereumj-core/src/main/java/org/ethereum/core/Denomination.java b/ethereumj-core/src/main/java/org/ethereum/core/Denomination.java index 8e2b6b97..2d5fa7c3 100644 --- a/ethereumj-core/src/main/java/org/ethereum/core/Denomination.java +++ b/ethereumj-core/src/main/java/org/ethereum/core/Denomination.java @@ -10,15 +10,17 @@ public enum Denomination { SHANNON(newBigInt(9)), SZABO(newBigInt(12)), FINNY(newBigInt(15)), - ETHER(newBigInt(18)); - + ETHER(newBigInt(18)), + EINSTEIN(newBigInt(21)), + DOUGLAS(newBigInt(42)); + private BigInteger amount; private Denomination(BigInteger value) { this.amount = value; } - public BigInteger getDenomination() { + public BigInteger value() { return amount; } diff --git a/ethereumj-core/src/test/java/org/ethereum/core/BlockTest.java b/ethereumj-core/src/test/java/org/ethereum/core/BlockTest.java index 2210d050..773af8dc 100644 --- a/ethereumj-core/src/test/java/org/ethereum/core/BlockTest.java +++ b/ethereumj-core/src/test/java/org/ethereum/core/BlockTest.java @@ -86,4 +86,16 @@ public class BlockTest { BlocksMessage blockData = new BlocksMessage(rlpList); System.out.println(blockData.toString()); } + + @Test + public void testCalcDifficulty() { + // Block.calcDifficulty() + fail("Yet to be implemented."); + } + + @Test + public void testCalcGasLimit() { + // Block.calcGasLimit() + fail("Yet to be implemented."); + } } \ No newline at end of file