Conflicts:
	src/main/java/org/ethereum/vm/Program.java
This commit is contained in:
romanman 2014-06-08 07:58:26 +01:00
commit 63a87f36a8
2 changed files with 122 additions and 35 deletions

View File

@ -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;
@ -29,6 +32,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();
@ -51,6 +56,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;
} }
@ -98,7 +104,7 @@ public class Block {
} }
public Block getParent() { public Block getParent() {
// TODO: Implement // TODO retrieve Parent from chain
return null; return null;
} }
@ -148,7 +154,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() {
@ -332,8 +338,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));
} }
} }

File diff suppressed because one or more lines are too long