fix some typos and do some cleanup

This commit is contained in:
ligi 2015-01-14 23:47:29 +01:00
parent e56dfacaae
commit 15971ed797
21 changed files with 83 additions and 116 deletions

View File

@ -60,7 +60,7 @@ import static org.ethereum.core.Denomination.SZABO;
@Component @Component
public class BlockchainImpl implements Blockchain { public class BlockchainImpl implements Blockchain {
/* A scalar value equal to the mininum limit of gas expenditure per block */ /* A scalar value equal to the minimum limit of gas expenditure per block */
private static long MIN_GAS_LIMIT = 125000L; private static long MIN_GAS_LIMIT = 125000L;
private static final Logger logger = LoggerFactory.getLogger("blockchain"); private static final Logger logger = LoggerFactory.getLogger("blockchain");

View File

@ -128,7 +128,7 @@ public class BlockStoreImpl implements BlockStore{
public BigInteger getTotalDifficultySince(long number) { public BigInteger getTotalDifficultySince(long number) {
BigInteger result = (BigInteger) sessionFactory.getCurrentSession(). BigInteger result = (BigInteger) sessionFactory.getCurrentSession().
createQuery("select sum(cummulativeDifficulty) from BlockVO where number > :number"). createQuery("select sum(cumulativeDifficulty) from BlockVO where number > :number").
setParameter("number", number). setParameter("number", number).
uniqueResult(); uniqueResult();
@ -141,7 +141,7 @@ public class BlockStoreImpl implements BlockStore{
public BigInteger getTotalDifficulty() { public BigInteger getTotalDifficulty() {
BigInteger result = (BigInteger) sessionFactory.getCurrentSession(). BigInteger result = (BigInteger) sessionFactory.getCurrentSession().
createQuery("select sum(cummulativeDifficulty) from BlockVO").uniqueResult(); createQuery("select sum(cumulativeDifficulty) from BlockVO").uniqueResult();
return result; return result;
} }

View File

@ -23,16 +23,16 @@ public class BlockVO {
@Lob @Lob
byte[] rlp; byte[] rlp;
BigInteger cummulativeDifficulty; BigInteger cumulativeDifficulty;
public BlockVO() { public BlockVO() {
} }
public BlockVO(Long number, byte[] hash, byte[] rlp, BigInteger cummulativeDifficulty) { public BlockVO(Long number, byte[] hash, byte[] rlp, BigInteger cumulativeDifficulty) {
this.number = number; this.number = number;
this.hash = hash; this.hash = hash;
this.rlp = rlp; this.rlp = rlp;
this.cummulativeDifficulty = cummulativeDifficulty; this.cumulativeDifficulty = cumulativeDifficulty;
} }
public byte[] getHash() { public byte[] getHash() {
@ -59,11 +59,11 @@ public class BlockVO {
this.rlp = rlp; this.rlp = rlp;
} }
public BigInteger getCummulativeDifficulty() { public BigInteger getCumulativeDifficulty() {
return cummulativeDifficulty; return cumulativeDifficulty;
} }
public void setCummulativeDifficulty(BigInteger cummulativeDifficulty) { public void setCumulativeDifficulty(BigInteger cumulativeDifficulty) {
this.cummulativeDifficulty = cummulativeDifficulty; this.cumulativeDifficulty = cumulativeDifficulty;
} }
} }

View File

@ -92,7 +92,7 @@ public interface Ethereum {
* @param gasPrice - gas price bid by miner , the user ask can be based on * @param gasPrice - gas price bid by miner , the user ask can be based on
* lastr submited block * lastr submited block
* @param gas - the quantity of gas requested for the transaction * @param gas - the quantity of gas requested for the transaction
* @param recieveAddress - the target address of the transaction * @param receiveAddress - the target address of the transaction
* @param value - the ether value of the transaction * @param value - the ether value of the transaction
* @param data - can be init procedure for creational transaction, * @param data - can be init procedure for creational transaction,
* also msg data for invoke transaction for only value * also msg data for invoke transaction for only value
@ -102,7 +102,7 @@ public interface Ethereum {
public Transaction createTransaction(BigInteger nonce, public Transaction createTransaction(BigInteger nonce,
BigInteger gasPrice, BigInteger gasPrice,
BigInteger gas, BigInteger gas,
byte[] recieveAddress, byte[] receiveAddress,
BigInteger value, byte[] data); BigInteger value, byte[] data);

View File

@ -201,7 +201,7 @@ public class EthereumImpl implements Ethereum {
public Transaction createTransaction(BigInteger nonce, public Transaction createTransaction(BigInteger nonce,
BigInteger gasPrice, BigInteger gasPrice,
BigInteger gas, BigInteger gas,
byte[] recieveAddress, byte[] receiveAddress,
BigInteger value, byte[] data) { BigInteger value, byte[] data) {
byte[] nonceBytes = ByteUtil.bigIntegerToBytes(nonce); byte[] nonceBytes = ByteUtil.bigIntegerToBytes(nonce);
@ -210,7 +210,7 @@ public class EthereumImpl implements Ethereum {
byte[] valueBytes = ByteUtil.bigIntegerToBytes(value); byte[] valueBytes = ByteUtil.bigIntegerToBytes(value);
Transaction tx = new Transaction(nonceBytes, gasPriceBytes, gasBytes, Transaction tx = new Transaction(nonceBytes, gasPriceBytes, gasBytes,
recieveAddress, valueBytes, data); receiveAddress, valueBytes, data);
return tx; return tx;
} }

View File

@ -99,24 +99,24 @@ public class AccountState {
BigInteger expectedBalance = new BigInteger(1, this.getBalance()); BigInteger expectedBalance = new BigInteger(1, this.getBalance());
if (!state.getBalance().equals(expectedBalance)) { if (!state.getBalance().equals(expectedBalance)) {
String formatedString = String.format("Account: %s: has unexpected balance, expected balance: %s found balance: %s", String formattedString = String.format("Account: %s: has unexpected balance, expected balance: %s found balance: %s",
Hex.toHexString(this.address), expectedBalance.toString(), state.getBalance().toString()); Hex.toHexString(this.address), expectedBalance.toString(), state.getBalance().toString());
results.add(formatedString); results.add(formattedString);
} }
BigInteger expectedNonce = new BigInteger(1, this.getNonce()); BigInteger expectedNonce = new BigInteger(1, this.getNonce());
if (!state.getNonce().equals(expectedNonce)) { if (!state.getNonce().equals(expectedNonce)) {
state.getNonce(); state.getNonce();
this.getNonce(); this.getNonce();
String formatedString = String.format("Account: %s: has unexpected nonce, expected nonce: %s found nonce: %s", String formattedString = String.format("Account: %s: has unexpected nonce, expected nonce: %s found nonce: %s",
Hex.toHexString(this.address), expectedNonce.toString(), state.getNonce().toString()); Hex.toHexString(this.address), expectedNonce.toString(), state.getNonce().toString());
results.add(formatedString); results.add(formattedString);
} }
if (!Arrays.equals(details.getCode(),this.getCode())) { if (!Arrays.equals(details.getCode(),this.getCode())) {
String formatedString = String.format("Account: %s: has unexpected nonce, expected nonce: %s found nonce: %s", String formattedString = String.format("Account: %s: has unexpected nonce, expected nonce: %s found nonce: %s",
Hex.toHexString(this.address), Hex.toHexString(this.getCode()), Hex.toHexString(details.getCode())); Hex.toHexString(this.address), Hex.toHexString(this.getCode()), Hex.toHexString(details.getCode()));
results.add(formatedString); results.add(formattedString);
} }
@ -131,22 +131,22 @@ public class AccountState {
DataWord expectedValue = this.getStorage().get(key); DataWord expectedValue = this.getStorage().get(key);
if (expectedValue == null) { if (expectedValue == null) {
String formatedString = String.format("Account: %s: has unexpected storage data: %s = %s", String formattedString = String.format("Account: %s: has unexpected storage data: %s = %s",
Hex.toHexString(this.address), Hex.toHexString(this.address),
key.toString(), key.toString(),
value.toString()); value.toString());
results.add(formatedString); results.add(formattedString);
continue; continue;
} }
if (!expectedValue.equals(value)) { if (!expectedValue.equals(value)) {
String formatedString = String.format("Account: %s: has unexpected value, for key: %s , expectedValue: %s real value: %s", String formattedString = String.format("Account: %s: has unexpected value, for key: %s , expectedValue: %s real value: %s",
Hex.toHexString(this.address), key.toString(), Hex.toHexString(this.address), key.toString(),
expectedValue.toString(), value.toString()); expectedValue.toString(), value.toString());
results.add(formatedString); results.add(formattedString);
continue; continue;
} }
@ -155,9 +155,9 @@ public class AccountState {
for (DataWord key : expectedKeys) { for (DataWord key : expectedKeys) {
if (!checked.contains(key)) { if (!checked.contains(key)) {
String formatedString = String.format("Account: %s: doesn't exist expected storage key: %s", String formattedString = String.format("Account: %s: doesn't exist expected storage key: %s",
Hex.toHexString(this.address), key.toString()); Hex.toHexString(this.address), key.toString());
results.add(formatedString); results.add(formattedString);
} }
} }

View File

@ -13,7 +13,7 @@ import java.math.BigInteger;
public class Env { public class Env {
private byte[] currentCoinbase; private byte[] currentCoinbase;
private byte[] currentDifficlty; private byte[] currentDifficulty;
private byte[] currentGasLimit; private byte[] currentGasLimit;
private byte[] currentNumber; private byte[] currentNumber;
private byte[] currentTimestamp; private byte[] currentTimestamp;
@ -39,7 +39,7 @@ public class Env {
String prevHash = env.get("previousHash").toString(); String prevHash = env.get("previousHash").toString();
this.currentCoinbase = Hex.decode(coinbase); this.currentCoinbase = Hex.decode(coinbase);
this.currentDifficlty = new BigInteger(difficulty).toByteArray(); this.currentDifficulty = new BigInteger(difficulty).toByteArray();
this.currentGasLimit = new BigInteger(gasLimit).toByteArray(); this.currentGasLimit = new BigInteger(gasLimit).toByteArray();
this.currentNumber = new BigInteger(number).toByteArray(); this.currentNumber = new BigInteger(number).toByteArray();
this.currentTimestamp = new BigInteger(timestamp).toByteArray(); this.currentTimestamp = new BigInteger(timestamp).toByteArray();
@ -51,8 +51,8 @@ public class Env {
return currentCoinbase; return currentCoinbase;
} }
public byte[] getCurrentDifficlty() { public byte[] getCurrentDifficulty() {
return currentDifficlty; return currentDifficulty;
} }
public byte[] getCurrentGasLimit() { public byte[] getCurrentGasLimit() {
@ -75,7 +75,7 @@ public class Env {
public String toString() { public String toString() {
return "Env{" + return "Env{" +
"currentCoinbase=" + Hex.toHexString(currentCoinbase) + "currentCoinbase=" + Hex.toHexString(currentCoinbase) +
", currentDifficlty=" + Hex.toHexString(currentDifficlty) + ", currentDifficulty=" + Hex.toHexString(currentDifficulty) +
", currentGasLimit=" + Hex.toHexString(currentGasLimit) + ", currentGasLimit=" + Hex.toHexString(currentGasLimit) +
", currentNumber=" + Hex.toHexString(currentNumber) + ", currentNumber=" + Hex.toHexString(currentNumber) +
", currentTimestamp=" + Hex.toHexString(currentTimestamp) + ", currentTimestamp=" + Hex.toHexString(currentTimestamp) +

View File

@ -56,9 +56,9 @@ public class Logs {
if (!postAddress.equals(realAddress)) { if (!postAddress.equals(realAddress)) {
String formatedString = String.format("Log: %s: has unexpected address, expected address: %s found address: %s", String formattedString = String.format("Log: %s: has unexpected address, expected address: %s found address: %s",
i, postAddress, realAddress); i, postAddress, realAddress);
results.add(formatedString); results.add(formattedString);
} }
String postData = Hex.toHexString(postLog.getData()); String postData = Hex.toHexString(postLog.getData());
@ -66,9 +66,9 @@ public class Logs {
if (!postData.equals(realData)) { if (!postData.equals(realData)) {
String formatedString = String.format("Log: %s: has unexpected data, expected data: %s found data: %s", String formattedString = String.format("Log: %s: has unexpected data, expected data: %s found data: %s",
i, postData, realData); i, postData, realData);
results.add(formatedString); results.add(formattedString);
} }
String postBloom = Hex.toHexString(postLog.getBloom().getData()); String postBloom = Hex.toHexString(postLog.getBloom().getData());
@ -76,9 +76,9 @@ public class Logs {
if (!postData.equals(realData)){ if (!postData.equals(realData)){
String formatedString = String.format("Log: %s: has unexpected bloom, expected bloom: %s found bloom: %s", String formattedString = String.format("Log: %s: has unexpected bloom, expected bloom: %s found bloom: %s",
i, postBloom, realBloom); i, postBloom, realBloom);
results.add(formatedString); results.add(formattedString);
} }
List<DataWord> postTopics = postLog.getTopics(); List<DataWord> postTopics = postLog.getTopics();
@ -91,9 +91,9 @@ public class Logs {
if (!postTopic.equals(realTopic)) { if (!postTopic.equals(realTopic)) {
String formatedString = String.format("Log: %s: has unexpected topic: %s, expected topic: %s found topic: %s", String formattedString = String.format("Log: %s: has unexpected topic: %s, expected topic: %s found topic: %s",
i, j, postTopic, realTopic); i, j, postTopic, realTopic);
results.add(formatedString); results.add(formattedString);
} }
++j; ++j;
} }

View File

@ -83,7 +83,7 @@ public class TestProgramInvokeFactory implements ProgramInvokeFactory {
long number = ByteUtil.byteArrayToLong(env.getCurrentNumber()); long number = ByteUtil.byteArrayToLong(env.getCurrentNumber());
/*** DIFFICULTY op ***/ /*** DIFFICULTY op ***/
byte[] difficulty = env.getCurrentDifficlty(); byte[] difficulty = env.getCurrentDifficulty();
/*** GASLIMIT op ***/ /*** GASLIMIT op ***/
long gaslimit = ByteUtil.byteArrayToLong(env.getCurrentGasLimit()); long gaslimit = ByteUtil.byteArrayToLong(env.getCurrentGasLimit());

View File

@ -173,7 +173,7 @@ public class TestRunner {
byte[] coinbase = env.getCurrentCoinbase(); byte[] coinbase = env.getCurrentCoinbase();
long timestamp = new BigInteger(env.getCurrentTimestamp()).longValue(); long timestamp = new BigInteger(env.getCurrentTimestamp()).longValue();
long number = new BigInteger(env.getCurrentNumber()).longValue(); long number = new BigInteger(env.getCurrentNumber()).longValue();
byte[] difficulty = env.getCurrentDifficlty(); byte[] difficulty = env.getCurrentDifficulty();
long gaslimit = new BigInteger(env.getCurrentGasLimit()).longValue(); long gaslimit = new BigInteger(env.getCurrentGasLimit()).longValue();
// Origin and caller need to exist in order to be able to execute // Origin and caller need to exist in order to be able to execute

View File

@ -76,7 +76,7 @@ public class PeerServer {
} catch (Exception e) { } catch (Exception e) {
logger.debug("Exception: {} ({})", e.getMessage(), e.getClass().getName()); logger.debug("Exception: {} ({})", e.getMessage(), e.getClass().getName());
throw new Error("Server Disconnnected"); throw new Error("Server Disconnected");
} finally { } finally {
workerGroup.shutdownGracefully(); workerGroup.shutdownGracefully();

View File

@ -733,7 +733,7 @@ public class SerpentToAssemblyCompiler extends SerpentBaseVisitor<String> {
} }
} }
private Integer getMsgOutputArraySize(String code) { private static Integer getMsgOutputArraySize(String code) {
String result = "0"; String result = "0";
Pattern pattern = Pattern.compile("<out_size ([0-9])* out_size>"); Pattern pattern = Pattern.compile("<out_size ([0-9])* out_size>");
@ -746,7 +746,7 @@ public class SerpentToAssemblyCompiler extends SerpentBaseVisitor<String> {
return Integer.parseInt(result); return Integer.parseInt(result);
} }
private Integer getMsgInputArraySize(String code) { private static Integer getMsgInputArraySize(String code) {
String result = "0"; String result = "0";
Pattern pattern = Pattern.compile("<in_size ([0-9])* in_size>"); Pattern pattern = Pattern.compile("<in_size ([0-9])* in_size>");
@ -759,14 +759,8 @@ public class SerpentToAssemblyCompiler extends SerpentBaseVisitor<String> {
return Integer.parseInt(result); return Integer.parseInt(result);
} }
private String cleanMsgString(String code) { private static String cleanMsgString(String code) {
return code.replaceAll("<(.*?)>", "");
String result = "";
Pattern pattern = Pattern.compile("<(.*?)>");
result = code.replaceAll("<(.*?)>", "");
return result;
} }
@ -774,7 +768,7 @@ public class SerpentToAssemblyCompiler extends SerpentBaseVisitor<String> {
* After the array deff code is set * After the array deff code is set
* extract the size out of code string * extract the size out of code string
*/ */
private Integer getArraySize(String code) { private static Integer getArraySize(String code) {
String result = "0"; String result = "0";
Pattern pattern = Pattern.compile(" [0-9]* SWAP MSTORE$"); Pattern pattern = Pattern.compile(" [0-9]* SWAP MSTORE$");

View File

@ -107,7 +107,7 @@ public class TrieImpl implements Trie {
byte[] k = binToNibbles(key); byte[] k = binToNibbles(key);
Value c = new Value(this.get(this.root, k)); Value c = new Value(this.get(this.root, k));
return (c == null) ? null : c.asBytes(); return c.asBytes();
} }
/** /**
@ -414,7 +414,7 @@ public class TrieImpl implements Trie {
*******************************/ *******************************/
// Created an array of empty elements of required length // Created an array of empty elements of required length
private Object[] emptyStringSlice(int l) { private static Object[] emptyStringSlice(int l) {
Object[] slice = new Object[l]; Object[] slice = new Object[l];
for (int i = 0; i < l; i++) { for (int i = 0; i < l; i++) {
slice[i] = ""; slice[i] = "";
@ -484,10 +484,10 @@ public class TrieImpl implements Trie {
public String getTrieDump() { public String getTrieDump() {
String root = "";
TraceAllNodes traceAction = new TraceAllNodes(); TraceAllNodes traceAction = new TraceAllNodes();
this.scanTree(this.getRootHash(), traceAction); this.scanTree(this.getRootHash(), traceAction);
final String root;
if (this.getRoot() instanceof Value) { if (this.getRoot() instanceof Value) {
root = "root: " + Hex.toHexString(getRootHash()) + " => " + this.getRoot() + "\n"; root = "root: " + Hex.toHexString(getRootHash()) + " => " + this.getRoot() + "\n";
} else { } else {
@ -501,10 +501,6 @@ public class TrieImpl implements Trie {
} }
public boolean validate() { public boolean validate() {
return cache.get(getRootHash()) != null;
if (cache.get(getRootHash()) != null)
return true;
else
return false;
} }
} }

View File

@ -29,7 +29,7 @@ public class TrieIterator {
if (currentNode.length() == 2) { if (currentNode.length() == 2) {
byte[] k = unpackToNibbles(currentNode.get(0).asBytes()); byte[] k = unpackToNibbles(currentNode.get(0).asBytes());
if (currentNode.get(1).asString() == "") { if (currentNode.get(1).asString().isEmpty()) {
this.workNode(currentNode.get(1)); this.workNode(currentNode.get(1));
} else { } else {
if (k[k.length - 1] == 16) { if (k[k.length - 1] == 16) {
@ -44,11 +44,11 @@ public class TrieIterator {
if (i == 16 && currentNode.get(i).length() != 0) { if (i == 16 && currentNode.get(i).length() != 0) {
this.values.add(currentNode.get(i).asString()); this.values.add(currentNode.get(i).asString());
} else { } else {
if (currentNode.get(i).asString() == "") { if (currentNode.get(i).asString().isEmpty()) {
this.workNode(currentNode.get(i)); this.workNode(currentNode.get(i));
} else { } else {
String val = currentNode.get(i).asString(); String val = currentNode.get(i).asString();
if (val != "") { if (!val.isEmpty()) {
this.shas.add(currentNode.get(1).asBytes()); this.shas.add(currentNode.get(1).asBytes());
this.getNode(val.getBytes()); this.getNode(val.getBytes());
} }

View File

@ -230,8 +230,7 @@ public class RLP {
public static BigInteger decodeBigInteger(byte[] data, int index) { public static BigInteger decodeBigInteger(byte[] data, int index) {
BigInteger value = null; final int length;
int length = 0;
if ((data[index] & 0xFF) >= OFFSET_LONG_ITEM if ((data[index] & 0xFF) >= OFFSET_LONG_ITEM
&& (data[index] & 0xFF) < OFFSET_SHORT_LIST) { && (data[index] & 0xFF) < OFFSET_SHORT_LIST) {
@ -249,14 +248,12 @@ public class RLP {
} }
byte[] valueBytes = new byte[length]; byte[] valueBytes = new byte[length];
System.arraycopy(data, index, valueBytes, 0, length); System.arraycopy(data, index, valueBytes, 0, length);
value = new BigInteger(1, valueBytes); return new BigInteger(1, valueBytes);
return value;
} }
private static byte[] decodeByteArray(byte[] data, int index) { private static byte[] decodeByteArray(byte[] data, int index) {
byte[] value = null; final int length;
int length = 0;
if ((data[index] & 0xFF) >= OFFSET_LONG_ITEM if ((data[index] & 0xFF) >= OFFSET_LONG_ITEM
&& (data[index] & 0xFF) < OFFSET_SHORT_LIST) { && (data[index] & 0xFF) < OFFSET_SHORT_LIST) {
@ -274,8 +271,7 @@ public class RLP {
} }
byte[] valueBytes = new byte[length]; byte[] valueBytes = new byte[length];
System.arraycopy(data, index, valueBytes, 0, length); System.arraycopy(data, index, valueBytes, 0, length);
value = valueBytes; return valueBytes;
return value;
} }
private static int nextItemLength(byte[] data, int index) { private static int nextItemLength(byte[] data, int index) {
@ -286,32 +282,25 @@ public class RLP {
if ((data[index] & 0xFF) >= OFFSET_LONG_LIST) { if ((data[index] & 0xFF) >= OFFSET_LONG_LIST) {
byte lengthOfLength = (byte) (data[index] - OFFSET_LONG_LIST); byte lengthOfLength = (byte) (data[index] - OFFSET_LONG_LIST);
int length = calcLength(lengthOfLength, data, index); return calcLength(lengthOfLength, data, index);
return length;
} }
if ((data[index] & 0xFF) >= OFFSET_SHORT_LIST if ((data[index] & 0xFF) >= OFFSET_SHORT_LIST
&& (data[index] & 0xFF) < OFFSET_LONG_LIST) { && (data[index] & 0xFF) < OFFSET_LONG_LIST) {
byte length = (byte) ((data[index] & 0xFF) - OFFSET_SHORT_LIST); return (byte) ((data[index] & 0xFF) - OFFSET_SHORT_LIST);
return length;
} }
if ((data[index] & 0xFF) > OFFSET_LONG_ITEM if ((data[index] & 0xFF) > OFFSET_LONG_ITEM
&& (data[index] & 0xFF) < OFFSET_SHORT_LIST) { && (data[index] & 0xFF) < OFFSET_SHORT_LIST) {
byte lengthOfLength = (byte) (data[index] - OFFSET_LONG_ITEM); byte lengthOfLength = (byte) (data[index] - OFFSET_LONG_ITEM);
int length = calcLength(lengthOfLength, data, index); return calcLength(lengthOfLength, data, index);
return length;
} }
if ((data[index] & 0xFF) > OFFSET_SHORT_ITEM if ((data[index] & 0xFF) > OFFSET_SHORT_ITEM
&& (data[index] & 0xFF) <= OFFSET_LONG_ITEM) { && (data[index] & 0xFF) <= OFFSET_LONG_ITEM) {
return (byte) ((data[index] & 0xFF) - OFFSET_SHORT_ITEM);
}
byte length = (byte) ((data[index] & 0xFF) - OFFSET_SHORT_ITEM); if ((data[index] & 0xFF) <= OFFSET_SHORT_ITEM) {
return length;
}
if ((data[index] & 0xFF) == OFFSET_SHORT_ITEM) {
return 1;
}
if ((data[index] & 0xFF) < OFFSET_SHORT_ITEM) {
return 1; return 1;
} }
return -1; return -1;
@ -409,7 +398,7 @@ public class RLP {
* Get exactly one message payload * Get exactly one message payload
*/ */
public static void fullTraverse(byte[] msgData, int level, int startPos, public static void fullTraverse(byte[] msgData, int level, int startPos,
int endPos, int levelToIndex, Queue<Integer> index) { int endPos, int levelToIndex, Queue<Integer> index) {
try { try {
@ -535,10 +524,9 @@ public class RLP {
/** /**
* Parse wire byte[] message into RLP elements * Parse wire byte[] message into RLP elements
* *
* @param msgData * @param msgData - raw RLP data
* - raw RLP data
* @return rlpList * @return rlpList
* - outcome of recursive RLP structure * - outcome of recursive RLP structure
*/ */
public static RLPList decode2(byte[] msgData) { public static RLPList decode2(byte[] msgData) {
RLPList rlpList = new RLPList(); RLPList rlpList = new RLPList();
@ -550,7 +538,7 @@ public class RLP {
* Get exactly one message payload * Get exactly one message payload
*/ */
private static void fullTraverse(byte[] msgData, int level, int startPos, private static void fullTraverse(byte[] msgData, int level, int startPos,
int endPos, int levelToIndex, RLPList rlpList) { int endPos, int levelToIndex, RLPList rlpList) {
try { try {
if (msgData == null || msgData.length == 0) if (msgData == null || msgData.length == 0)
@ -672,7 +660,7 @@ public class RLP {
* Reads any RLP encoded byte-array and returns all objects as byte-array or list of byte-arrays * Reads any RLP encoded byte-array and returns all objects as byte-array or list of byte-arrays
* *
* @param data RLP encoded byte-array * @param data RLP encoded byte-array
* @param pos position in the array to start reading * @param pos position in the array to start reading
* @return DecodeResult encapsulates the decoded items as a single Object and the final read position * @return DecodeResult encapsulates the decoded items as a single Object and the final read position
*/ */
public static DecodeResult decode(byte[] data, int pos) { public static DecodeResult decode(byte[] data, int pos) {
@ -871,8 +859,7 @@ public class RLP {
} }
int totalLength = 0; int totalLength = 0;
for (int i = 0; for (int i = 0; i < elements.length; ++i) {
elements != null && i < elements.length; ++i) {
totalLength += elements[i].length; totalLength += elements[i].length;
} }

View File

@ -29,7 +29,7 @@ public class Utils {
public static String hexStringToDecimalString(String hexNum) { public static String hexStringToDecimalString(String hexNum) {
boolean match = Pattern.matches("0[xX][0-9a-fA-F]+", hexNum); boolean match = Pattern.matches("0[xX][0-9a-fA-F]+", hexNum);
if (!match) throw new Error("The string doesn't conains hex num in form 0x.. : [" + hexNum + "]"); if (!match) throw new Error("The string doesn't contains hex num in form 0x.. : [" + hexNum + "]");
byte[] numberBytes = Hex.decode(hexNum.substring(2)); byte[] numberBytes = Hex.decode(hexNum.substring(2));
return (new BigInteger(1, numberBytes)).toString(); return (new BigInteger(1, numberBytes)).toString();
@ -73,7 +73,7 @@ public class Utils {
* @return - decode and validated address byte[] * @return - decode and validated address byte[]
*/ */
public static byte[] addressStringToBytes(String hex) { public static byte[] addressStringToBytes(String hex) {
byte[] addr = null; final byte[] addr;
try { try {
addr = Hex.decode(hex); addr = Hex.decode(hex);
} catch (DecoderException addressIsNotValid) { } catch (DecoderException addressIsNotValid) {

View File

@ -160,10 +160,7 @@ public class Value {
if (aData > 32 && aData < 126) ++readableChars; if (aData > 32 && aData < 126) ++readableChars;
} }
if ((double) readableChars / (double) data.length > 0.55) return (double) readableChars / (double) data.length > 0.55;
return true;
else
return false;
} }
// it's only if the isBytes() = true; // it's only if the isBytes() = true;
@ -179,10 +176,7 @@ public class Value {
++hexChars; ++hexChars;
} }
if ((double) hexChars / (double) data.length > 0.9) return (double) hexChars / (double) data.length > 0.9;
return true;
else
return false;
} }
public boolean isHashCode() { public boolean isHashCode() {

View File

@ -9,7 +9,7 @@ public class MessageCall {
public enum MsgType { public enum MsgType {
CALL, CALL,
STATELESS, STATELESS,
POST; POST
} }
/** /**

View File

@ -596,9 +596,8 @@ public class Program {
if (invokeData == null) return DataWord.ZERO_EMPTY_ARRAY; if (invokeData == null) return DataWord.ZERO_EMPTY_ARRAY;
BigInteger balance = result.getRepository().getBalance(address.getLast20Bytes()); BigInteger balance = result.getRepository().getBalance(address.getLast20Bytes());
DataWord balanceData = new DataWord(balance.toByteArray());
return balanceData; return new DataWord(balance.toByteArray());
} }
public DataWord getOriginAddress() { public DataWord getOriginAddress() {
@ -905,7 +904,7 @@ public class Program {
this.listener = listener; this.listener = listener;
} }
public void vallidateJumpDest(int nextPC) { public void validateJumpDest(int nextPC) {
if (!jumpdest.contains(nextPC)) throw new BadJumpDestinationException(); if (!jumpdest.contains(nextPC)) throw new BadJumpDestinationException();
} }

View File

@ -119,12 +119,9 @@ public class ProgramInvokeFactoryImpl implements ProgramInvokeFactory {
gaslimit); gaslimit);
} }
ProgramInvoke programInvoke = return new ProgramInvokeImpl(address, origin, caller, balance, gasPrice, gas, callValue, data,
new ProgramInvokeImpl(address, origin, caller, balance, gasPrice, gas, callValue, data, lastHash, coinbase, timestamp, number, difficulty, gaslimit,
lastHash, coinbase, timestamp, number, difficulty, gaslimit, repository, blockStore);
repository, blockStore);
return programInvoke;
} }
/** /**

View File

@ -504,7 +504,7 @@ public class VM {
case BYTE: { case BYTE: {
DataWord word1 = program.stackPop(); DataWord word1 = program.stackPop();
DataWord word2 = program.stackPop(); DataWord word2 = program.stackPop();
DataWord result = null; final DataWord result;
if (word1.value().compareTo(_32_) == -1) { if (word1.value().compareTo(_32_) == -1) {
byte tmp = word2.getData()[word1.intValue()]; byte tmp = word2.getData()[word1.intValue()];
word2.and(DataWord.ZERO); word2.and(DataWord.ZERO);
@ -896,7 +896,7 @@ public class VM {
case JUMP: { case JUMP: {
DataWord pos = program.stackPop(); DataWord pos = program.stackPop();
int nextPC = pos.intValue(); // possible overflow int nextPC = pos.intValue(); // possible overflow
program.vallidateJumpDest(nextPC); program.validateJumpDest(nextPC);
if (logger.isInfoEnabled()) if (logger.isInfoEnabled())
hint = "~> " + nextPC; hint = "~> " + nextPC;
@ -912,7 +912,7 @@ public class VM {
if (!cond.isZero()) { if (!cond.isZero()) {
int nextPC = pos.intValue(); // possible overflow int nextPC = pos.intValue(); // possible overflow
program.vallidateJumpDest(nextPC); program.validateJumpDest(nextPC);
if (logger.isInfoEnabled()) if (logger.isInfoEnabled())
hint = "~> " + nextPC; hint = "~> " + nextPC;