mirror of
https://github.com/status-im/ethereumj-personal.git
synced 2025-02-16 13:46:46 +00:00
Merge pull request #28 from nicksavers/master
Fix BlockTest and added asserts for Block#1 calculations
This commit is contained in:
commit
970f978734
@ -7,7 +7,10 @@ import org.ethereum.util.ByteUtil;
|
|||||||
import org.ethereum.util.RLP;
|
import org.ethereum.util.RLP;
|
||||||
import org.ethereum.util.RLPElement;
|
import org.ethereum.util.RLPElement;
|
||||||
import org.ethereum.util.RLPList;
|
import org.ethereum.util.RLPList;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
import org.spongycastle.util.BigIntegers;
|
import org.spongycastle.util.BigIntegers;
|
||||||
|
import org.spongycastle.util.encoders.Hex;
|
||||||
|
|
||||||
import java.math.BigInteger;
|
import java.math.BigInteger;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -22,6 +25,8 @@ import java.util.List;
|
|||||||
*/
|
*/
|
||||||
public class Block {
|
public class Block {
|
||||||
|
|
||||||
|
private static Logger logger = LoggerFactory.getLogger(Block.class);
|
||||||
|
|
||||||
/* A scalar value equal to the mininum limit of gas expenditure per block */
|
/* A scalar value equal to the mininum limit of gas expenditure per block */
|
||||||
private static long MIN_GAS_LIMIT = BigInteger.valueOf(10).pow(4).longValue();
|
private static long MIN_GAS_LIMIT = BigInteger.valueOf(10).pow(4).longValue();
|
||||||
|
|
||||||
@ -44,6 +49,7 @@ public class Block {
|
|||||||
/* Constructors */
|
/* Constructors */
|
||||||
|
|
||||||
public Block(byte[] rawData) {
|
public Block(byte[] rawData) {
|
||||||
|
logger.debug("RLP encoded [ " + Hex.toHexString(rawData) + " ]");
|
||||||
this.rlpEncoded = rawData;
|
this.rlpEncoded = rawData;
|
||||||
this.parsed = false;
|
this.parsed = false;
|
||||||
}
|
}
|
||||||
@ -91,7 +97,7 @@ public class Block {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Block getParent() {
|
public Block getParent() {
|
||||||
// TODO: Implement
|
// TODO retrieve Parent from chain
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -141,7 +147,7 @@ public class Block {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean isGenesis() {
|
public boolean isGenesis() {
|
||||||
return this.header.getNumber() == 0;
|
return this.getNumber() == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getGasLimit() {
|
public long getGasLimit() {
|
||||||
@ -325,8 +331,8 @@ public class Block {
|
|||||||
return Genesis.DIFFICULTY;
|
return Genesis.DIFFICULTY;
|
||||||
else {
|
else {
|
||||||
Block parent = this.getParent();
|
Block parent = this.getParent();
|
||||||
long parentDifficulty = new BigInteger(1, parent.header.getDifficulty()).longValue();
|
long parentDifficulty = new BigInteger(1, parent.getDifficulty()).longValue();
|
||||||
long newDifficulty = this.header.getTimestamp() >= parent.header.getTimestamp() + 42 ? parentDifficulty - (parentDifficulty >> 10) : (parentDifficulty + (parentDifficulty >> 10));
|
long newDifficulty = this.header.getTimestamp() >= parent.getTimestamp() + 42 ? parentDifficulty - (parentDifficulty >> 10) : (parentDifficulty + (parentDifficulty >> 10));
|
||||||
return BigIntegers.asUnsignedByteArray(BigInteger.valueOf(newDifficulty));
|
return BigIntegers.asUnsignedByteArray(BigInteger.valueOf(newDifficulty));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@ import java.util.*;
|
|||||||
|
|
||||||
public class Program {
|
public class Program {
|
||||||
|
|
||||||
Logger logger = LoggerFactory.getLogger("VM");
|
Logger logger = LoggerFactory.getLogger(Program.class);
|
||||||
ProgramListener listener;
|
ProgramListener listener;
|
||||||
|
|
||||||
Stack<DataWord> stack = new Stack<DataWord>();
|
Stack<DataWord> stack = new Stack<DataWord>();
|
||||||
|
File diff suppressed because one or more lines are too long
Loading…
x
Reference in New Issue
Block a user