remove typos / add missing modifiers / code cleanup
This commit is contained in:
parent
d097a56644
commit
0c96950e0e
|
@ -61,10 +61,10 @@ public class Account {
|
|||
if (accountState != null)
|
||||
balance = accountState.getBalance();
|
||||
|
||||
synchronized (getPendingTransactins()) {
|
||||
if (!getPendingTransactins().isEmpty()) {
|
||||
synchronized (getPendingTransactions()) {
|
||||
if (!getPendingTransactions().isEmpty()) {
|
||||
|
||||
for (Transaction tx : getPendingTransactins()) {
|
||||
for (Transaction tx : getPendingTransactions()) {
|
||||
if (Arrays.equals(getAddress(), tx.getSender())) {
|
||||
balance = balance.subtract(new BigInteger(1, tx.getValue()));
|
||||
}
|
||||
|
@ -94,7 +94,7 @@ public class Account {
|
|||
this.address = address;
|
||||
}
|
||||
|
||||
public Set<Transaction> getPendingTransactins() {
|
||||
public Set<Transaction> getPendingTransactions() {
|
||||
return this.pendingTransactions;
|
||||
}
|
||||
|
||||
|
|
|
@ -37,10 +37,10 @@ public class Block {
|
|||
|
||||
private static final Logger logger = LoggerFactory.getLogger("block");
|
||||
|
||||
public static BigInteger BLOCK_REWARD = BigInteger.valueOf(1500000000000000000L);
|
||||
public static BigInteger UNCLE_REWARD = BLOCK_REWARD.multiply(
|
||||
public static final BigInteger BLOCK_REWARD = BigInteger.valueOf(1500000000000000000L);
|
||||
public static final BigInteger UNCLE_REWARD = BLOCK_REWARD.multiply(
|
||||
BigInteger.valueOf(15)).divide(BigInteger.valueOf(16));
|
||||
public static BigInteger INCLUSION_REWARD = Block.BLOCK_REWARD
|
||||
public static final BigInteger INCLUSION_REWARD = BLOCK_REWARD
|
||||
.divide(BigInteger.valueOf(32));
|
||||
|
||||
private BlockHeader header;
|
||||
|
@ -67,9 +67,9 @@ public class Block {
|
|||
}
|
||||
|
||||
public Block(byte[] parentHash, byte[] unclesHash, byte[] coinbase, byte[] logsBloom,
|
||||
byte[] difficulty, long number, long gasLimit,
|
||||
long gasUsed, long timestamp, byte[] extraData, byte[] nonce,
|
||||
List<Transaction> transactionsList, List<BlockHeader> uncleList) {
|
||||
byte[] difficulty, long number, long gasLimit,
|
||||
long gasUsed, long timestamp, byte[] extraData, byte[] nonce,
|
||||
List<Transaction> transactionsList, List<BlockHeader> uncleList) {
|
||||
this.header = new BlockHeader(parentHash, unclesHash, coinbase, logsBloom,
|
||||
difficulty, number, gasLimit, gasUsed,
|
||||
timestamp, extraData, nonce);
|
||||
|
@ -264,7 +264,7 @@ public class Block {
|
|||
|
||||
toStringBuff.setLength(0);
|
||||
toStringBuff.append("BlockData [");
|
||||
toStringBuff.append("hash=" + ByteUtil.toHexString(this.getHash())).append("");
|
||||
toStringBuff.append("hash=").append(ByteUtil.toHexString(this.getHash()));
|
||||
toStringBuff.append(header.toFlatString());
|
||||
|
||||
for (Transaction tx : getTransactionsList()) {
|
||||
|
@ -338,8 +338,7 @@ public class Block {
|
|||
|
||||
public byte[] getEncodedWithoutNonce() {
|
||||
if (!parsed) parseRLP();
|
||||
byte[] header = this.header.getEncodedWithoutNonce();
|
||||
return header;
|
||||
return this.header.getEncodedWithoutNonce();
|
||||
}
|
||||
|
||||
public String getShortHash() {
|
||||
|
|
|
@ -29,14 +29,14 @@ public class BlockHeader {
|
|||
private byte[] stateRoot;
|
||||
/* The SHA3 256-bit hash of the root node of the trie structure
|
||||
* populated with each transaction in the transaction
|
||||
* list portion, the trie is populate by [key, val] --> [rlp(index), rlp(tx_reciepe)]
|
||||
* list portion, the trie is populate by [key, val] --> [rlp(index), rlp(tx_recipe)]
|
||||
* of the block */
|
||||
private byte[] txTrieRoot;
|
||||
/* The SHA3 256-bit hash of the root node of the trie structure
|
||||
* populated with each transaction recipe in the transaction recipes
|
||||
* list portion, the trie is populate by [key, val] --> [rlp(index), rlp(tx_reciepe)]
|
||||
* list portion, the trie is populate by [key, val] --> [rlp(index), rlp(tx_recipe)]
|
||||
* of the block */
|
||||
private byte[] recieptTrieRoot;
|
||||
private byte[] receiptTrieRoot;
|
||||
|
||||
/*todo: comment it when you know what the fuck it is*/
|
||||
private byte[] logsBloom;
|
||||
|
@ -72,9 +72,9 @@ public class BlockHeader {
|
|||
if (this.txTrieRoot == null)
|
||||
this.txTrieRoot = EMPTY_TRIE_HASH;
|
||||
|
||||
this.recieptTrieRoot = rlpHeader.get(5).getRLPData();
|
||||
if (this.recieptTrieRoot == null)
|
||||
this.recieptTrieRoot = EMPTY_TRIE_HASH;
|
||||
this.receiptTrieRoot = rlpHeader.get(5).getRLPData();
|
||||
if (this.receiptTrieRoot == null)
|
||||
this.receiptTrieRoot = EMPTY_TRIE_HASH;
|
||||
|
||||
this.logsBloom = rlpHeader.get(6).getRLPData();
|
||||
this.difficulty = rlpHeader.get(7).getRLPData();
|
||||
|
@ -177,16 +177,16 @@ public class BlockHeader {
|
|||
this.txTrieRoot = txTrieRoot;
|
||||
}
|
||||
|
||||
public byte[] getRecieptTrieRoot() {
|
||||
return recieptTrieRoot;
|
||||
public byte[] getReceiptTrieRoot() {
|
||||
return receiptTrieRoot;
|
||||
}
|
||||
|
||||
public byte[] getLogsBloom() {
|
||||
return logsBloom;
|
||||
}
|
||||
|
||||
public void setRecieptTrieRoot(byte[] recieptTrieRoot) {
|
||||
this.recieptTrieRoot = recieptTrieRoot;
|
||||
public void setReceiptTrieRoot(byte[] receiptTrieRoot) {
|
||||
this.receiptTrieRoot = receiptTrieRoot;
|
||||
}
|
||||
|
||||
public byte[] getDifficulty() {
|
||||
|
@ -264,8 +264,8 @@ public class BlockHeader {
|
|||
if (txTrieRoot == null) this.txTrieRoot = EMPTY_TRIE_HASH;
|
||||
byte[] txTrieRoot = RLP.encodeElement(this.txTrieRoot);
|
||||
|
||||
if (recieptTrieRoot == null) this.recieptTrieRoot = EMPTY_TRIE_HASH;
|
||||
byte[] recieptTrieRoot = RLP.encodeElement(this.recieptTrieRoot);
|
||||
if (receiptTrieRoot == null) this.receiptTrieRoot = EMPTY_TRIE_HASH;
|
||||
byte[] receiptTrieRoot = RLP.encodeElement(this.receiptTrieRoot);
|
||||
|
||||
byte[] logsBloom = RLP.encodeElement(this.logsBloom);
|
||||
byte[] difficulty = RLP.encodeElement(this.difficulty);
|
||||
|
@ -277,51 +277,39 @@ public class BlockHeader {
|
|||
if (withNonce) {
|
||||
byte[] nonce = RLP.encodeElement(this.nonce);
|
||||
return RLP.encodeList(parentHash, unclesHash, coinbase,
|
||||
stateRoot, txTrieRoot, recieptTrieRoot, logsBloom, difficulty, number,
|
||||
stateRoot, txTrieRoot, receiptTrieRoot, logsBloom, difficulty, number,
|
||||
gasLimit, gasUsed, timestamp, extraData, nonce);
|
||||
} else {
|
||||
return RLP.encodeList(parentHash, unclesHash, coinbase,
|
||||
stateRoot, txTrieRoot, recieptTrieRoot, logsBloom, difficulty, number,
|
||||
stateRoot, txTrieRoot, receiptTrieRoot, logsBloom, difficulty, number,
|
||||
gasLimit, gasUsed, timestamp, extraData);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private StringBuffer toStringBuff = new StringBuffer();
|
||||
|
||||
public String toString() {
|
||||
return toStringWithSuffix("\n");
|
||||
}
|
||||
|
||||
toStringBuff.setLength(0);
|
||||
toStringBuff.append(" parentHash=" + toHexString(parentHash)).append("\n");
|
||||
toStringBuff.append(" unclesHash=" + toHexString(unclesHash)).append("\n");
|
||||
toStringBuff.append(" coinbase=" + toHexString(coinbase)).append("\n");
|
||||
toStringBuff.append(" stateRoot=" + toHexString(stateRoot)).append("\n");
|
||||
toStringBuff.append(" txTrieHash=" + toHexString(txTrieRoot)).append("\n");
|
||||
toStringBuff.append(" reciptsTrieHash=" + toHexString(recieptTrieRoot)).append("\n");
|
||||
toStringBuff.append(" difficulty=" + toHexString(difficulty)).append("\n");
|
||||
toStringBuff.append(" number=" + number).append("\n");
|
||||
toStringBuff.append(" gasLimit=" + gasLimit).append("\n");
|
||||
toStringBuff.append(" gasUsed=" + gasUsed).append("\n");
|
||||
toStringBuff.append(" timestamp=" + timestamp + " (" + Utils.longToDateTime(timestamp) + ")").append("\n");
|
||||
toStringBuff.append(" extraData=" + toHexString(extraData)).append("\n");
|
||||
toStringBuff.append(" nonce=" + toHexString(nonce)).append("\n");
|
||||
private String toStringWithSuffix(final String suffix) {
|
||||
StringBuilder toStringBuff = new StringBuilder();
|
||||
toStringBuff.append(" parentHash=").append(toHexString(parentHash)).append(suffix);
|
||||
toStringBuff.append(" unclesHash=").append(toHexString(unclesHash)).append(suffix);
|
||||
toStringBuff.append(" coinbase=").append(toHexString(coinbase)).append(suffix);
|
||||
toStringBuff.append(" stateRoot=").append(toHexString(stateRoot)).append(suffix);
|
||||
toStringBuff.append(" txTrieHash=").append(toHexString(txTrieRoot)).append(suffix);
|
||||
toStringBuff.append(" receiptsTrieHash=").append(toHexString(receiptTrieRoot)).append(suffix);
|
||||
toStringBuff.append(" difficulty=").append(toHexString(difficulty)).append(suffix);
|
||||
toStringBuff.append(" number=").append(number).append(suffix);
|
||||
toStringBuff.append(" gasLimit=").append(gasLimit).append(suffix);
|
||||
toStringBuff.append(" gasUsed=").append(gasUsed).append(suffix);
|
||||
toStringBuff.append(" timestamp=").append(timestamp).append(" (").append(Utils.longToDateTime(timestamp)).append(")").append(suffix);
|
||||
toStringBuff.append(" extraData=").append(toHexString(extraData)).append(suffix);
|
||||
toStringBuff.append(" nonce=").append(toHexString(nonce)).append(suffix);
|
||||
return toStringBuff.toString();
|
||||
}
|
||||
|
||||
public String toFlatString() {
|
||||
toStringBuff.append(" parentHash=" + toHexString(parentHash)).append("");
|
||||
toStringBuff.append(" unclesHash=" + toHexString(unclesHash)).append("");
|
||||
toStringBuff.append(" coinbase=" + toHexString(coinbase)).append("");
|
||||
toStringBuff.append(" stateRoot=" + toHexString(stateRoot)).append("");
|
||||
toStringBuff.append(" txTrieHash=" + toHexString(txTrieRoot)).append("");
|
||||
toStringBuff.append(" difficulty=" + toHexString(difficulty)).append("");
|
||||
toStringBuff.append(" number=" + number).append("");
|
||||
toStringBuff.append(" gasLimit=" + gasLimit).append("");
|
||||
toStringBuff.append(" gasUsed=" + gasUsed).append("");
|
||||
toStringBuff.append(" timestamp=" + timestamp).append("");
|
||||
toStringBuff.append(" extraData=" + toHexString(extraData)).append("");
|
||||
toStringBuff.append(" nonce=" + toHexString(nonce)).append("");
|
||||
return toStringBuff.toString();
|
||||
return toStringWithSuffix("");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -61,9 +61,8 @@ public class Bloom {
|
|||
|
||||
Bloom bloom = (Bloom) o;
|
||||
|
||||
if (!Arrays.equals(data, bloom.data)) return false;
|
||||
return Arrays.equals(data, bloom.data);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -91,8 +91,8 @@ public class TransactionExecutor {
|
|||
|
||||
|
||||
// FIND OUT THE TRANSACTION TYPE
|
||||
byte[] receiverAddress = null;
|
||||
byte[] code = EMPTY_BYTE_ARRAY;
|
||||
final byte[] receiverAddress;
|
||||
final byte[] code;
|
||||
boolean isContractCreation = tx.isContractCreation();
|
||||
if (isContractCreation) {
|
||||
receiverAddress = tx.getContractAddress();
|
||||
|
@ -224,8 +224,6 @@ public class TransactionExecutor {
|
|||
|
||||
receipt.setCumulativeGas(gasUsed);
|
||||
this.receipt = receipt;
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -99,7 +99,7 @@ public class TransactionReceipt {
|
|||
byte[] cumulativeGasRLP = RLP.encodeElement(this.cumulativeGas);
|
||||
byte[] bloomRLP = RLP.encodeElement(this.bloomFilter.data);
|
||||
|
||||
byte[] logInfoListRLP = null;
|
||||
final byte[] logInfoListRLP;
|
||||
if (logInfoList != null) {
|
||||
byte[][] logInfoListE = new byte[logInfoList.size()][];
|
||||
|
||||
|
|
|
@ -397,7 +397,6 @@ public class ECKey implements Serializable {
|
|||
// No decryption of private key required.
|
||||
if (priv == null)
|
||||
throw new MissingPrivateKeyException();
|
||||
check(priv != null, "Private key must not be null");
|
||||
ECDSASigner signer = new ECDSASigner(new HMacDSAKCalculator(new SHA256Digest()));
|
||||
ECPrivateKeyParameters privKey = new ECPrivateKeyParameters(priv, CURVE);
|
||||
signer.init(true, privKey);
|
||||
|
|
|
@ -80,9 +80,8 @@ public class HashUtil {
|
|||
|
||||
byte[] encSender = RLP.encodeElement(addr);
|
||||
byte[] encNonce = RLP.encodeBigInteger(new BigInteger(1, nonce));
|
||||
byte[] newAddress = sha3omit12(RLP.encodeList(encSender, encNonce));
|
||||
|
||||
return newAddress;
|
||||
return sha3omit12(RLP.encodeList(encSender, encNonce));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -112,7 +111,7 @@ public class HashUtil {
|
|||
|
||||
byte[] peerIdBytes = new BigInteger(512, Utils.getRandom()).toByteArray();
|
||||
|
||||
String peerId = null;
|
||||
final String peerId;
|
||||
if (peerIdBytes.length > 64)
|
||||
peerId = Hex.toHexString(peerIdBytes, 1, 64);
|
||||
else
|
||||
|
|
|
@ -127,12 +127,10 @@ public class BlockStoreImpl implements BlockStore{
|
|||
@Transactional(readOnly = true)
|
||||
public BigInteger getTotalDifficultySince(long number) {
|
||||
|
||||
BigInteger result = (BigInteger) sessionFactory.getCurrentSession().
|
||||
return (BigInteger) sessionFactory.getCurrentSession().
|
||||
createQuery("select sum(cumulativeDifficulty) from BlockVO where number > :number").
|
||||
setParameter("number", number).
|
||||
uniqueResult();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
@ -140,10 +138,8 @@ public class BlockStoreImpl implements BlockStore{
|
|||
@Transactional(readOnly = true)
|
||||
public BigInteger getTotalDifficulty() {
|
||||
|
||||
BigInteger result = (BigInteger) sessionFactory.getCurrentSession().
|
||||
return (BigInteger) sessionFactory.getCurrentSession().
|
||||
createQuery("select sum(cumulativeDifficulty) from BlockVO").uniqueResult();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -101,14 +101,11 @@ public class EthereumImpl implements Ethereum {
|
|||
worldManager.startPeerDiscovery();
|
||||
|
||||
final Set<PeerInfo> peers = worldManager.getPeerDiscovery().getPeers();
|
||||
synchronized (peers) {
|
||||
for (PeerInfo peer : peers) { // it blocks until a peer is available.
|
||||
if (peer.isOnline() && !excludePeers.contains(peer)) {
|
||||
logger.info("Found peer: {}", peer.toString());
|
||||
if (listener != null)
|
||||
listener.trace(String.format("Found online peer: [ %s ]", peer.toString()));
|
||||
return peer;
|
||||
}
|
||||
for (PeerInfo peer : peers) { // it blocks until a peer is available.
|
||||
if (peer.isOnline() && !excludePeers.contains(peer)) {
|
||||
logger.info("Found peer: {}", peer.toString());
|
||||
listener.trace(String.format("Found online peer: [ %s ]", peer.toString()));
|
||||
return peer;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
@ -209,10 +206,8 @@ public class EthereumImpl implements Ethereum {
|
|||
byte[] gasBytes = ByteUtil.bigIntegerToBytes(gas);
|
||||
byte[] valueBytes = ByteUtil.bigIntegerToBytes(value);
|
||||
|
||||
Transaction tx = new Transaction(nonceBytes, gasPriceBytes, gasBytes,
|
||||
return new Transaction(nonceBytes, gasPriceBytes, gasBytes,
|
||||
receiveAddress, valueBytes, data);
|
||||
|
||||
return tx;
|
||||
}
|
||||
|
||||
|
||||
|
@ -220,9 +215,8 @@ public class EthereumImpl implements Ethereum {
|
|||
public Future<Transaction> submitTransaction(Transaction transaction) {
|
||||
|
||||
TransactionTask transactionTask = new TransactionTask(transaction, worldManager);
|
||||
Future<Transaction> future = TransactionExecutor.instance.submitTransaction(transactionTask);
|
||||
|
||||
return future;
|
||||
return TransactionExecutor.instance.submitTransaction(transactionTask);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -84,7 +84,7 @@ public class JSONHelper {
|
|||
byte[] keyBytes = key.getData();
|
||||
AccountState accountState = repository.getAccountState(keyBytes);
|
||||
ContractDetails details = repository.getContractDetails(keyBytes);
|
||||
JSONHelper.dumpState(statesNode, Hex.toHexString(keyBytes), accountState, details);
|
||||
dumpState(statesNode, Hex.toHexString(keyBytes), accountState, details);
|
||||
}
|
||||
blockNode.put("state", statesNode);
|
||||
|
||||
|
|
|
@ -14,10 +14,10 @@ import java.math.BigInteger;
|
|||
*/
|
||||
public class CallCreate {
|
||||
|
||||
byte[] data;
|
||||
byte[] destination;
|
||||
byte[] gasLimit;
|
||||
byte[] value;
|
||||
private final byte[] data;
|
||||
private final byte[] destination;
|
||||
private final byte[] gasLimit;
|
||||
private final byte[] value;
|
||||
|
||||
/* e.g.
|
||||
"data" : [
|
||||
|
|
|
@ -12,12 +12,12 @@ import java.math.BigInteger;
|
|||
*/
|
||||
public class Env {
|
||||
|
||||
private byte[] currentCoinbase;
|
||||
private byte[] currentDifficulty;
|
||||
private byte[] currentGasLimit;
|
||||
private byte[] currentNumber;
|
||||
private byte[] currentTimestamp;
|
||||
private byte[] previousHash;
|
||||
private final byte[] currentCoinbase;
|
||||
private final byte[] currentDifficulty;
|
||||
private final byte[] currentGasLimit;
|
||||
private final byte[] currentNumber;
|
||||
private final byte[] currentTimestamp;
|
||||
private final byte[] previousHash;
|
||||
|
||||
|
||||
/*
|
||||
|
|
|
@ -14,16 +14,16 @@ import java.math.BigInteger;
|
|||
*/
|
||||
public class Exec {
|
||||
|
||||
private byte[] address;
|
||||
private byte[] caller;
|
||||
private byte[] data;
|
||||
private byte[] code;
|
||||
private final byte[] address;
|
||||
private final byte[] caller;
|
||||
private final byte[] data;
|
||||
private final byte[] code;
|
||||
|
||||
private byte[] gas;
|
||||
private byte[] gasPrice;
|
||||
private final byte[] gas;
|
||||
private final byte[] gasPrice;
|
||||
|
||||
private byte[] origin;
|
||||
private byte[] value;
|
||||
private final byte[] origin;
|
||||
private final byte[] value;
|
||||
|
||||
/*
|
||||
e.g:
|
||||
|
|
|
@ -19,7 +19,7 @@ public class JSONReader {
|
|||
String json = "";
|
||||
if (!SystemProperties.CONFIG.vmTestLoadLocal())
|
||||
json = getFromUrl("https://raw.githubusercontent.com/ethereum/tests/develop/" + filename);
|
||||
return json == "" ? json = getFromLocal(filename) : json;
|
||||
return json.isEmpty() ? getFromLocal(filename) : json;
|
||||
}
|
||||
|
||||
public static String getFromLocal(String filename) {
|
||||
|
@ -58,8 +58,6 @@ public class JSONReader {
|
|||
result += line;
|
||||
}
|
||||
rd.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ import java.math.BigInteger;
|
|||
*/
|
||||
public class TestProgramInvokeFactory implements ProgramInvokeFactory {
|
||||
|
||||
Env env;
|
||||
private final Env env;
|
||||
|
||||
TestProgramInvokeFactory(Env env) {
|
||||
this.env = env;
|
||||
|
|
|
@ -61,11 +61,10 @@ public class TestRunner {
|
|||
|
||||
public List<String> runTestCase(StateTestCase testCase) {
|
||||
|
||||
List<String> results = null;
|
||||
List<String> results = new ArrayList<>();;
|
||||
logger.info("\n***");
|
||||
logger.info(" Running test case: [" + testCase.getName() + "]");
|
||||
logger.info("***\n");
|
||||
results = new ArrayList<>();
|
||||
|
||||
logger.info("--------- PRE ---------");
|
||||
RepositoryDummy repository = loadRepository(testCase.getPre());
|
||||
|
@ -119,8 +118,8 @@ public class TestRunner {
|
|||
|
||||
AccountState expectedAccountState = testCase.getPost().get(wrap(addr));
|
||||
if (expectedAccountState == null) {
|
||||
String formatedString = String.format("Unexpected account state: address: %s", Hex.toHexString(addr));
|
||||
results.add(formatedString);
|
||||
String formattedString = String.format("Unexpected account state: address: %s", Hex.toHexString(addr));
|
||||
results.add(formattedString);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
|
@ -110,9 +110,9 @@ public class WorldManager {
|
|||
pendingTransactions.addAll(transactions);
|
||||
}
|
||||
|
||||
public void clearPendingTransactions(List<Transaction> recivedTransactions) {
|
||||
public void clearPendingTransactions(List<Transaction> receivedTransactions) {
|
||||
|
||||
for (Transaction tx : recivedTransactions) {
|
||||
for (Transaction tx : receivedTransactions) {
|
||||
logger.info("Clear transaction, hash: [{}]", Hex.toHexString(tx.getHash()));
|
||||
pendingTransactions.remove(tx);
|
||||
}
|
||||
|
|
|
@ -63,16 +63,15 @@ public class MessageQueue {
|
|||
}
|
||||
|
||||
public void sendMessage(Message msg) {
|
||||
|
||||
if (msg instanceof PingMessage && hasPing)
|
||||
return;
|
||||
if (msg instanceof PingMessage && !hasPing)
|
||||
if (msg instanceof PingMessage) {
|
||||
if (hasPing) return;
|
||||
hasPing = true;
|
||||
}
|
||||
|
||||
messageQueue.add(new MessageRoundtrip(msg));
|
||||
}
|
||||
|
||||
public void disconnect(){
|
||||
public void disconnect() {
|
||||
ctx.writeAndFlush(DISCONNECT_MESSAGE);
|
||||
ctx.close();
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ import org.ethereum.net.message.Message;
|
|||
*/
|
||||
public class MessageRoundtrip {
|
||||
|
||||
private Message msg = null;
|
||||
private final Message msg;
|
||||
long lastTimestamp = 0;
|
||||
long retryTimes = 0;
|
||||
boolean answered = false;
|
||||
|
|
|
@ -77,7 +77,7 @@ public class BlockHashesMessage extends EthMessage {
|
|||
public String toString() {
|
||||
if (!parsed) parse();
|
||||
|
||||
StringBuffer sb = Utils.getHashlistShort(this.blockHashes);
|
||||
return "[" + this.getCommand().name() + sb.toString() + "] (" + this.blockHashes.size() + ")";
|
||||
final String hashListShort = Utils.getHashListShort(blockHashes);
|
||||
return "[" + this.getCommand().name() + hashListShort + "] (" + blockHashes.size() + ")";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -79,7 +79,7 @@ public class BlocksMessage extends EthMessage {
|
|||
public String toString() {
|
||||
if (!parsed) parse();
|
||||
|
||||
StringBuffer sb = new StringBuffer();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (Block blockData : this.getBlocks()) {
|
||||
sb.append("\n ").append(blockData.toFlatString());
|
||||
}
|
||||
|
|
|
@ -157,7 +157,7 @@ public class EthHandler extends SimpleChannelInboundHandler<EthMessage> {
|
|||
break;
|
||||
case NEW_BLOCK:
|
||||
msgQueue.receivedMessage(msg);
|
||||
procesNewBlock((NewBlockMessage) msg);
|
||||
processNewBlock((NewBlockMessage) msg);
|
||||
case PACKET_COUNT:
|
||||
break;
|
||||
default:
|
||||
|
@ -212,11 +212,11 @@ public class EthHandler extends SimpleChannelInboundHandler<EthMessage> {
|
|||
}
|
||||
|
||||
if (!Arrays.equals(msg.getGenesisHash(), Blockchain.GENESIS_HASH)
|
||||
|| msg.getProtocolVersion() != EthHandler.VERSION) {
|
||||
|| msg.getProtocolVersion() != VERSION) {
|
||||
logger.info("Removing EthHandler for {} due to protocol incompatibility", ctx.channel().remoteAddress());
|
||||
// msgQueue.sendMessage(new DisconnectMessage(ReasonCode.INCOMPATIBLE_NETWORK));
|
||||
ctx.pipeline().remove(this); // Peer is not compatible for the 'eth' sub-protocol
|
||||
} else if (msg.getNetworkId() != EthHandler.NETWORK_ID)
|
||||
} else if (msg.getNetworkId() != NETWORK_ID)
|
||||
msgQueue.sendMessage(new DisconnectMessage(ReasonCode.INCOMPATIBLE_NETWORK));
|
||||
else {
|
||||
BlockQueue chainQueue = blockchain.getQueue();
|
||||
|
@ -282,9 +282,9 @@ public class EthHandler extends SimpleChannelInboundHandler<EthMessage> {
|
|||
List<Block> blockList = blocksMessage.getBlocks();
|
||||
|
||||
if (!blockList.isEmpty()) {
|
||||
Block block = blockList.get(blockList.size()-1);
|
||||
Block block = blockList.get(blockList.size() - 1);
|
||||
if (block.getNumber() > lastBlock.getNumber())
|
||||
lastBlock = blockList.get(blockList.size()-1);
|
||||
lastBlock = blockList.get(blockList.size() - 1);
|
||||
}
|
||||
|
||||
// check if you got less blocks than you asked
|
||||
|
@ -320,7 +320,7 @@ public class EthHandler extends SimpleChannelInboundHandler<EthMessage> {
|
|||
*
|
||||
* @param newBlockMessage - new block message
|
||||
*/
|
||||
public void procesNewBlock(NewBlockMessage newBlockMessage) {
|
||||
public void processNewBlock(NewBlockMessage newBlockMessage) {
|
||||
|
||||
Block newBlock = newBlockMessage.getBlock();
|
||||
|
||||
|
|
|
@ -97,8 +97,7 @@ public enum EthMessageCodes {
|
|||
}
|
||||
|
||||
public static EthMessageCodes fromByte(byte i) {
|
||||
EthMessageCodes type = intToTypeMap.get(i - OFFSET);
|
||||
return type;
|
||||
return intToTypeMap.get(i - OFFSET);
|
||||
}
|
||||
|
||||
public static boolean inRange(byte code) {
|
||||
|
|
|
@ -72,9 +72,7 @@ public class GetBlocksMessage extends EthMessage {
|
|||
}
|
||||
|
||||
public String toString() {
|
||||
if (!parsed) parse();
|
||||
|
||||
StringBuffer sb = Utils.getHashlistShort(this.blockHashes);
|
||||
return "[" + this.getCommand().name() + sb.toString() + "] (" + this.blockHashes.size() + ")";
|
||||
final String hashListShort = Utils.getHashListShort(getBlockHashes());
|
||||
return "[" + this.getCommand().name() + hashListShort+ "] (" + blockHashes.size() + ")";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -81,10 +81,10 @@ public class TransactionsMessage extends EthMessage {
|
|||
|
||||
public String toString() {
|
||||
if (!parsed) parse();
|
||||
StringBuffer sb = new StringBuffer();
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
for (Transaction transaction : transactions)
|
||||
sb.append("\n ").append(transaction);
|
||||
return "[" + this.getCommand().name() + " num:"
|
||||
return "[" + getCommand().name() + " num:"
|
||||
+ transactions.size() + " " + sb.toString() + "]";
|
||||
}
|
||||
}
|
|
@ -207,7 +207,7 @@ public class P2pHandler extends SimpleChannelInboundHandler<P2pMessage> {
|
|||
private void setHandshake(HelloMessage msg, ChannelHandlerContext ctx) {
|
||||
|
||||
this.handshakeHelloMessage = msg;
|
||||
if (msg.getP2PVersion() != P2pHandler.VERSION) {
|
||||
if (msg.getP2PVersion() != VERSION) {
|
||||
msgQueue.sendMessage(new DisconnectMessage(ReasonCode.INCOMPATIBLE_PROTOCOL));
|
||||
}
|
||||
else {
|
||||
|
|
|
@ -64,7 +64,7 @@ public enum P2pMessageCodes {
|
|||
USER(0x0F);
|
||||
|
||||
|
||||
private int cmd;
|
||||
private final int cmd;
|
||||
|
||||
private static final Map<Integer, P2pMessageCodes> intToTypeMap = new HashMap<>();
|
||||
|
||||
|
@ -79,16 +79,11 @@ public enum P2pMessageCodes {
|
|||
}
|
||||
|
||||
public static P2pMessageCodes fromByte(byte i) {
|
||||
P2pMessageCodes type = intToTypeMap.get((int) i);
|
||||
return type;
|
||||
return intToTypeMap.get((int) i);
|
||||
}
|
||||
|
||||
public static boolean inRange(byte code) {
|
||||
|
||||
if (code >= HELLO.asByte() && code <= USER.asByte())
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
return code >= HELLO.asByte() && code <= USER.asByte();
|
||||
}
|
||||
|
||||
public byte asByte() {
|
||||
|
|
|
@ -15,11 +15,10 @@ import java.util.List;
|
|||
*/
|
||||
public class Peer {
|
||||
|
||||
private InetAddress address;
|
||||
private int port;
|
||||
private String peerId;
|
||||
|
||||
private List<Capability> capabilities;
|
||||
private final InetAddress address;
|
||||
private final int port;
|
||||
private final String peerId;
|
||||
private final List<Capability> capabilities;
|
||||
|
||||
public Peer(InetAddress ip, int port, String peerId) {
|
||||
this.address = ip;
|
||||
|
|
|
@ -92,7 +92,7 @@ public class PeersMessage extends P2pMessage {
|
|||
public String toString() {
|
||||
if (!parsed) this.parse();
|
||||
|
||||
StringBuffer sb = new StringBuffer();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (Peer peerData : peers) {
|
||||
sb.append("\n ").append(peerData);
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ public class PingMessage extends P2pMessage {
|
|||
/**
|
||||
* Ping message is always a the same single command payload
|
||||
*/
|
||||
private static byte[] FIXED_PAYLOAD = Hex.decode("C102");
|
||||
private final static byte[] FIXED_PAYLOAD = Hex.decode("C102");
|
||||
|
||||
public byte[] getEncoded() {
|
||||
return FIXED_PAYLOAD;
|
||||
|
|
|
@ -12,7 +12,7 @@ public class PongMessage extends P2pMessage {
|
|||
/**
|
||||
* Pong message is always a the same single command payload
|
||||
*/
|
||||
private static byte[] FIXED_PAYLOAD = Hex.decode("C103");
|
||||
private final static byte[] FIXED_PAYLOAD = Hex.decode("C103");
|
||||
|
||||
@Override
|
||||
public byte[] getEncoded() {
|
||||
|
|
|
@ -22,7 +22,6 @@ public class WorkerThread implements Runnable {
|
|||
|
||||
private PeerInfo peerInfo;
|
||||
private ThreadPoolExecutor poolExecutor;
|
||||
private boolean running = true;
|
||||
|
||||
@Autowired
|
||||
ApplicationContext ctx;
|
||||
|
|
|
@ -41,7 +41,7 @@ public enum ShhMessageCodes {
|
|||
PACKET_COUNT(0x04);
|
||||
|
||||
static byte OFFSET = 0;
|
||||
private int cmd;
|
||||
private final int cmd;
|
||||
|
||||
private static final Map<Integer, ShhMessageCodes> intToTypeMap = new HashMap<>();
|
||||
|
||||
|
@ -56,8 +56,7 @@ public enum ShhMessageCodes {
|
|||
}
|
||||
|
||||
public static ShhMessageCodes fromByte(byte i) {
|
||||
ShhMessageCodes type = intToTypeMap.get(i - OFFSET);
|
||||
return type;
|
||||
return intToTypeMap.get(i - OFFSET);
|
||||
}
|
||||
|
||||
public static void setOffset(byte offset) {
|
||||
|
@ -65,11 +64,7 @@ public enum ShhMessageCodes {
|
|||
}
|
||||
|
||||
public static boolean inRange(byte code) {
|
||||
|
||||
if (code >= STATUS.asByte() && code <= PACKET_COUNT.asByte())
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
return code >= STATUS.asByte() && code <= PACKET_COUNT.asByte();
|
||||
}
|
||||
|
||||
public byte asByte() {
|
||||
|
|
|
@ -20,8 +20,8 @@ public class TransactionTask implements Callable<Transaction> {
|
|||
|
||||
private static final Logger logger = LoggerFactory.getLogger(TransactionTask.class);
|
||||
|
||||
private Transaction tx;
|
||||
private WorldManager worldManager;
|
||||
private final Transaction tx;
|
||||
private final WorldManager worldManager;
|
||||
|
||||
public TransactionTask(Transaction tx, WorldManager worldManager) {
|
||||
this.tx = tx;
|
||||
|
|
|
@ -8,15 +8,15 @@ import org.ethereum.core.Transaction;
|
|||
*/
|
||||
public class WalletTransaction {
|
||||
|
||||
private Transaction tx;
|
||||
int approved = 0; // each time the tx got from the wire this value increased
|
||||
private final Transaction tx;
|
||||
private int approved = 0; // each time the tx got from the wire this value increased
|
||||
|
||||
public WalletTransaction(Transaction tx) {
|
||||
this.tx = tx;
|
||||
}
|
||||
|
||||
public void incApproved() {
|
||||
++this.approved;
|
||||
approved++;
|
||||
}
|
||||
|
||||
public int getApproved() {
|
||||
|
|
|
@ -85,25 +85,25 @@ public class SerpentCompiler {
|
|||
Collections.addAll(lexaList, lexaArr);
|
||||
|
||||
// Encode push_n numbers
|
||||
boolean skiping = false;
|
||||
boolean skipping = false;
|
||||
for (int i = 0; i < lexaList.size(); ++i) {
|
||||
|
||||
String lexa = lexaList.get(i);
|
||||
|
||||
{ // skiping the [asm asm] block
|
||||
{ // skipping the [asm asm] block
|
||||
if (lexa.equals("asm]")) {
|
||||
skiping = false;
|
||||
skipping = false;
|
||||
lexaList.remove(i);
|
||||
--i;
|
||||
continue;
|
||||
}
|
||||
if (lexa.equals("[asm")) {
|
||||
skiping = true;
|
||||
skipping = true;
|
||||
lexaList.remove(i);
|
||||
--i;
|
||||
continue;
|
||||
}
|
||||
if (skiping)
|
||||
if (skipping)
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -206,7 +206,7 @@ public class SerpentCompiler {
|
|||
int numBytes = ByteUtil.numBytes(code.length + "");
|
||||
byte[] lenBytes = BigIntegers.asUnsignedByteArray(BigInteger.valueOf(code.length));
|
||||
|
||||
StringBuffer sb = new StringBuffer();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (byte lenByte : lenBytes) {
|
||||
sb.append(lenByte).append(" ");
|
||||
}
|
||||
|
@ -221,9 +221,7 @@ public class SerpentCompiler {
|
|||
|
||||
byte[] headerMachine = compileAssemblyToMachine(header);
|
||||
|
||||
byte[] result = init != null ? Arrays.concatenate(init, headerMachine, code) :
|
||||
return init != null ? Arrays.concatenate(init, headerMachine, code) :
|
||||
Arrays.concatenate(headerMachine, code);
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -81,7 +81,7 @@ public class SerpentToAssemblyCompiler extends SerpentBaseVisitor<String> {
|
|||
@Override
|
||||
public String visitIf_elif_else_stmt(@NotNull SerpentParser.If_elif_else_stmtContext ctx) {
|
||||
|
||||
StringBuffer retCode = new StringBuffer();
|
||||
StringBuilder retCode = new StringBuilder();
|
||||
|
||||
int endOfStmtLabel = labelIndex++;
|
||||
|
||||
|
@ -155,19 +155,15 @@ public class SerpentToAssemblyCompiler extends SerpentBaseVisitor<String> {
|
|||
SerpentParser.BlockContext whileBlock = (SerpentParser.BlockContext)
|
||||
ctx.getChild(4);
|
||||
|
||||
String retCode =
|
||||
String.format(" LABEL_%d %s NOT REF_%d JUMPI %s REF_%d JUMP LABEL_%d ",
|
||||
whileStartRef, visitCondition(whileCondition), whileEndRef, visitBlock(whileBlock),
|
||||
whileStartRef, whileEndRef);
|
||||
return retCode;
|
||||
return String.format(" LABEL_%d %s NOT REF_%d JUMPI %s REF_%d JUMP LABEL_%d ",
|
||||
whileStartRef, visitCondition(whileCondition), whileEndRef, visitBlock(whileBlock),
|
||||
whileStartRef, whileEndRef);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String visitBlock(@NotNull SerpentParser.BlockContext ctx) {
|
||||
|
||||
String blockStmt = super.visitBlock(ctx);
|
||||
|
||||
return blockStmt;
|
||||
return super.visitBlock(ctx);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -192,13 +188,11 @@ public class SerpentToAssemblyCompiler extends SerpentBaseVisitor<String> {
|
|||
public String visitAssign(@NotNull SerpentParser.AssignContext ctx) {
|
||||
|
||||
String varName = ctx.VAR().toString();
|
||||
int addr = 0;
|
||||
|
||||
// msg assigned has two arrays to calc
|
||||
if (ctx.msg_func() != null) {
|
||||
|
||||
String msgCode = visitMsg_func(ctx.msg_func(), varName);
|
||||
return msgCode;
|
||||
return visitMsg_func(ctx.msg_func(), varName);
|
||||
} else if (ctx.arr_def() != null) {
|
||||
// if it's an array the all management is different
|
||||
String arrayCode = visitArr_def(ctx.arr_def());
|
||||
|
@ -211,7 +205,7 @@ public class SerpentToAssemblyCompiler extends SerpentBaseVisitor<String> {
|
|||
return arrayCode;
|
||||
} else {
|
||||
String expression = visitExpression(ctx.expression());
|
||||
addr = vars.indexOf(varName);
|
||||
int addr = vars.indexOf(varName);
|
||||
if (addr == -1) {
|
||||
addr = vars.size();
|
||||
vars.add(varName);
|
||||
|
@ -668,7 +662,7 @@ public class SerpentToAssemblyCompiler extends SerpentBaseVisitor<String> {
|
|||
public String visitAsm(@NotNull SerpentParser.AsmContext ctx) {
|
||||
|
||||
int size = ctx.asm_symbol().getChildCount();
|
||||
StringBuffer sb = new StringBuffer();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
for (int i = 0; i < size; ++i) {
|
||||
|
||||
|
|
|
@ -17,8 +17,8 @@ import java.util.concurrent.ConcurrentHashMap;
|
|||
*/
|
||||
public class Cache {
|
||||
|
||||
private final DB db;
|
||||
private Map<ByteArrayWrapper, Node> nodes = new ConcurrentHashMap<>();
|
||||
private DB db;
|
||||
private boolean isDirty;
|
||||
|
||||
public Cache(DB db) {
|
||||
|
|
|
@ -45,7 +45,7 @@ import org.ethereum.util.Value;
|
|||
public class Node {
|
||||
|
||||
/* RLP encoded value of the Trie-node */
|
||||
private Value value;
|
||||
private final Value value;
|
||||
private boolean dirty;
|
||||
|
||||
public Node(Value val) {
|
||||
|
@ -65,8 +65,8 @@ public class Node {
|
|||
return dirty;
|
||||
}
|
||||
|
||||
public void setDirty(boolean ditry) {
|
||||
this.dirty = ditry;
|
||||
public void setDirty(boolean dirty) {
|
||||
this.dirty = dirty;
|
||||
}
|
||||
|
||||
public Value getValue() {
|
||||
|
|
|
@ -365,7 +365,7 @@ public class TrieImpl implements Trie {
|
|||
|
||||
private boolean isEmptyNode(Object node) {
|
||||
Value n = new Value(node);
|
||||
return (node == null || (n.isString() && (n.asString() == "" || n.get(0).isNull())) || n.length() == 0);
|
||||
return (node == null || (n.isString() && (n.asString().isEmpty() || n.get(0).isNull())) || n.length() == 0);
|
||||
}
|
||||
|
||||
private Object[] copyNode(Value currentNode) {
|
||||
|
@ -382,9 +382,7 @@ public class TrieImpl implements Trie {
|
|||
@Override
|
||||
public boolean equals(Object trie) {
|
||||
if (this == trie) return true;
|
||||
if (trie instanceof Trie)
|
||||
return Arrays.equals(this.getRootHash(), ((Trie) trie).getRootHash());
|
||||
return false;
|
||||
return trie instanceof Trie && Arrays.equals(this.getRootHash(), ((Trie) trie).getRootHash());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -168,12 +168,12 @@ public class ByteUtil {
|
|||
* @return pretty string of nibbles
|
||||
*/
|
||||
public static String nibblesToPrettyString(byte[] nibbles) {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
StringBuilder builder = new StringBuilder();
|
||||
for (byte nibble : nibbles) {
|
||||
String nibleString = oneByteToHexString(nibble);
|
||||
buffer.append("\\x" + nibleString);
|
||||
final String nibbleString = oneByteToHexString(nibble);
|
||||
builder.append("\\x").append(nibbleString);
|
||||
}
|
||||
return buffer.toString();
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
public static String oneByteToHexString(byte value) {
|
||||
|
|
|
@ -139,12 +139,10 @@ public abstract class FastByteComparisons {
|
|||
Field f = Unsafe.class.getDeclaredField("theUnsafe");
|
||||
f.setAccessible(true);
|
||||
return f.get(null);
|
||||
} catch (NoSuchFieldException e) {
|
||||
} catch (NoSuchFieldException | IllegalAccessException e) {
|
||||
// It doesn't matter what we throw;
|
||||
// it's swallowed in getBestComparer().
|
||||
throw new Error();
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new Error();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
@ -148,17 +148,13 @@ public class RLP {
|
|||
}
|
||||
|
||||
private static short decodeShort(byte[] data, int index) {
|
||||
|
||||
short value = 0;
|
||||
|
||||
if ((data[index] & 0xFF) > OFFSET_SHORT_ITEM
|
||||
&& (data[index] & 0xFF) < OFFSET_LONG_ITEM) {
|
||||
byte length = (byte) (data[index] - OFFSET_SHORT_ITEM);
|
||||
value = ByteBuffer.wrap(data, index, length).getShort();
|
||||
return ByteBuffer.wrap(data, index, length).getShort();
|
||||
} else {
|
||||
value = data[index];
|
||||
return data[index];
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
private static long decodeLong(byte[] data, int index) {
|
||||
|
@ -182,7 +178,7 @@ public class RLP {
|
|||
|
||||
private static String decodeStringItem(byte[] data, int index) {
|
||||
|
||||
String value = null;
|
||||
final String value;
|
||||
|
||||
if ((data[index] & 0xFF) >= OFFSET_LONG_ITEM
|
||||
&& (data[index] & 0xFF) < OFFSET_SHORT_LIST) {
|
||||
|
@ -205,8 +201,7 @@ public class RLP {
|
|||
|
||||
private static byte[] decodeItemBytes(byte[] data, int index) {
|
||||
|
||||
byte[] value = null;
|
||||
int length = 0;
|
||||
final int length;
|
||||
|
||||
if ((data[index] & 0xFF) >= OFFSET_LONG_ITEM
|
||||
&& (data[index] & 0xFF) < OFFSET_SHORT_LIST) {
|
||||
|
@ -224,8 +219,7 @@ public class RLP {
|
|||
}
|
||||
byte[] valueBytes = new byte[length];
|
||||
System.arraycopy(data, index, valueBytes, 0, length);
|
||||
value = valueBytes;
|
||||
return value;
|
||||
return valueBytes;
|
||||
}
|
||||
|
||||
public static BigInteger decodeBigInteger(byte[] data, int index) {
|
||||
|
@ -514,11 +508,9 @@ public class RLP {
|
|||
}
|
||||
|
||||
public static byte getCommandCode(byte[] data) {
|
||||
byte command = 0;
|
||||
int index = getFirstListElement(data, 0);
|
||||
command = data[index];
|
||||
command = ((command & 0xFF) == OFFSET_SHORT_ITEM) ? 0 : command;
|
||||
return command;
|
||||
final byte command = data[index];
|
||||
return ((command & 0xFF) == OFFSET_SHORT_ITEM) ? 0 : command;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -809,7 +801,7 @@ public class RLP {
|
|||
}
|
||||
|
||||
public static byte[] encodeBigInteger(BigInteger srcBigInteger) {
|
||||
if (srcBigInteger == BigInteger.ZERO)
|
||||
if (srcBigInteger.equals(BigInteger.ZERO))
|
||||
return encodeByte((byte) 0);
|
||||
else
|
||||
return encodeElement(asUnsignedByteArray(srcBigInteger));
|
||||
|
@ -859,12 +851,12 @@ public class RLP {
|
|||
}
|
||||
|
||||
int totalLength = 0;
|
||||
for (int i = 0; i < elements.length; ++i) {
|
||||
totalLength += elements[i].length;
|
||||
for (byte[] element1 : elements) {
|
||||
totalLength += element1.length;
|
||||
}
|
||||
|
||||
byte[] data;
|
||||
int copyPos = 0;
|
||||
int copyPos;
|
||||
if (totalLength < SIZE_THRESHOLD) {
|
||||
|
||||
data = new byte[1 + totalLength];
|
||||
|
@ -915,7 +907,7 @@ public class RLP {
|
|||
return (inputInt == 0) ? ByteUtil.EMPTY_BYTE_ARRAY : asUnsignedByteArray(BigInteger.valueOf(inputInt));
|
||||
} else if (input instanceof BigInteger) {
|
||||
BigInteger inputBigInt = (BigInteger) input;
|
||||
return (inputBigInt == BigInteger.ZERO) ? ByteUtil.EMPTY_BYTE_ARRAY : asUnsignedByteArray(inputBigInt);
|
||||
return (inputBigInt.equals(BigInteger.ZERO)) ? ByteUtil.EMPTY_BYTE_ARRAY : asUnsignedByteArray(inputBigInt);
|
||||
} else if (input instanceof Value) {
|
||||
Value val = (Value) input;
|
||||
return toBytes(val.asObj());
|
||||
|
|
|
@ -6,7 +6,7 @@ package org.ethereum.util;
|
|||
*/
|
||||
public class RLPItem implements RLPElement {
|
||||
|
||||
byte[] rlpData;
|
||||
private final byte[] rlpData;
|
||||
|
||||
public RLPItem(byte[] rlpData) {
|
||||
this.rlpData = rlpData;
|
||||
|
|
|
@ -125,15 +125,13 @@ public class Utils {
|
|||
return Double.parseDouble(version.substring(0, pos - 1));
|
||||
}
|
||||
|
||||
public static StringBuffer getHashlistShort(List<byte[]> blockHashes) {
|
||||
|
||||
StringBuffer sb = new StringBuffer();
|
||||
|
||||
if (blockHashes.isEmpty()) return sb.append("[]");
|
||||
public static String getHashListShort(List<byte[]> blockHashes) {
|
||||
if (blockHashes.isEmpty()) return "[]";
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
String firstHash = Hex.toHexString(blockHashes.get(0));
|
||||
String lastHash = Hex.toHexString(blockHashes.get(blockHashes.size() - 1));
|
||||
return sb.append(" ").append(firstHash).append("...").append(lastHash);
|
||||
return sb.append(" ").append(firstHash).append("...").append(lastHash).toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -147,7 +147,7 @@ public class Value {
|
|||
}
|
||||
|
||||
// it's only if the isBytes() = true;
|
||||
public boolean isReadbleString() {
|
||||
public boolean isReadableString() {
|
||||
|
||||
int readableChars = 0;
|
||||
byte[] data = (byte[]) value;
|
||||
|
@ -209,7 +209,7 @@ public class Value {
|
|||
|
||||
public String toString() {
|
||||
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
|
||||
if (isList()) {
|
||||
|
||||
|
@ -218,45 +218,45 @@ public class Value {
|
|||
// special case - key/value node
|
||||
if (list.length == 2) {
|
||||
|
||||
buffer.append("[ ");
|
||||
stringBuilder.append("[ ");
|
||||
|
||||
Value key = new Value(list[0]);
|
||||
|
||||
byte[] keyNibbles = CompactEncoder.binToNibblesNoTerminator(key.asBytes());
|
||||
String keyString = ByteUtil.nibblesToPrettyString(keyNibbles);
|
||||
buffer.append(keyString);
|
||||
stringBuilder.append(keyString);
|
||||
|
||||
buffer.append(",");
|
||||
stringBuilder.append(",");
|
||||
|
||||
Value val = new Value(list[1]);
|
||||
buffer.append(val.toString());
|
||||
stringBuilder.append(val.toString());
|
||||
|
||||
buffer.append(" ]");
|
||||
return buffer.toString();
|
||||
stringBuilder.append(" ]");
|
||||
return stringBuilder.toString();
|
||||
}
|
||||
buffer.append(" [");
|
||||
stringBuilder.append(" [");
|
||||
|
||||
for (int i = 0; i < list.length; ++i) {
|
||||
Value val = new Value(list[i]);
|
||||
if (val.isString() || val.isEmpty()) {
|
||||
buffer.append("'").append(val.toString()).append("'");
|
||||
stringBuilder.append("'").append(val.toString()).append("'");
|
||||
} else {
|
||||
buffer.append(val.toString());
|
||||
stringBuilder.append(val.toString());
|
||||
}
|
||||
if (i < list.length - 1)
|
||||
buffer.append(", ");
|
||||
stringBuilder.append(", ");
|
||||
}
|
||||
buffer.append("] ");
|
||||
stringBuilder.append("] ");
|
||||
|
||||
return buffer.toString();
|
||||
return stringBuilder.toString();
|
||||
} else if (isEmpty()) {
|
||||
return "";
|
||||
} else if (isBytes()) {
|
||||
|
||||
StringBuffer output = new StringBuffer();
|
||||
StringBuilder output = new StringBuilder();
|
||||
if (isHashCode()) {
|
||||
output.append(Hex.toHexString(asBytes()));
|
||||
} else if (isReadbleString()) {
|
||||
} else if (isReadableString()) {
|
||||
output.append("'");
|
||||
for (byte oneByte : asBytes()) {
|
||||
if (oneByte < 16) {
|
||||
|
|
|
@ -6,10 +6,10 @@ package org.ethereum.vm;
|
|||
*/
|
||||
public class CallCreate {
|
||||
|
||||
byte[] data;
|
||||
byte[] destination;
|
||||
byte[] gasLimit;
|
||||
byte[] value;
|
||||
final byte[] data;
|
||||
final byte[] destination;
|
||||
final byte[] gasLimit;
|
||||
final byte[] value;
|
||||
|
||||
|
||||
public CallCreate(byte[] data, byte[] destination, byte[] gasLimit, byte[] value) {
|
||||
|
|
|
@ -11,71 +11,71 @@ public class GasCost {
|
|||
/**
|
||||
* Cost 1 gas
|
||||
*/
|
||||
public static int STEP = 1;
|
||||
public final static int STEP = 1;
|
||||
/**
|
||||
* Cost 20 gas
|
||||
*/
|
||||
public static int BALANCE = 20;
|
||||
public final static int BALANCE = 20;
|
||||
/**
|
||||
* Cost 10 gas
|
||||
*/
|
||||
public static int SHA3 = 10;
|
||||
public final static int SHA3 = 10;
|
||||
/**
|
||||
* Cost 10 gas
|
||||
*/
|
||||
public static int SHA3_WORD = 10;
|
||||
public final static int SHA3_WORD = 10;
|
||||
/**
|
||||
* Cost 20 gas
|
||||
*/
|
||||
public static int SLOAD = 20;
|
||||
public final static int SLOAD = 20;
|
||||
/**
|
||||
* Cost 0 gas
|
||||
*/
|
||||
public static int STOP = 0;
|
||||
public final static int STOP = 0;
|
||||
/**
|
||||
* Cost 0 gas
|
||||
*/
|
||||
public static int SUICIDE = 0;
|
||||
public final static int SUICIDE = 0;
|
||||
/**
|
||||
* Cost 300 gas
|
||||
*/
|
||||
public static int SSTORE = 300;
|
||||
public final static int SSTORE = 300;
|
||||
/**
|
||||
* Cost 100 gas
|
||||
*/
|
||||
public static int RESET_SSTORE = 100;
|
||||
public final static int RESET_SSTORE = 100;
|
||||
/**
|
||||
* Cost 100 gas
|
||||
*/
|
||||
public static int REFUND_SSTORE = 100;
|
||||
public final static int REFUND_SSTORE = 100;
|
||||
/**
|
||||
* Cost 100 gas
|
||||
*/
|
||||
public static int CREATE = 100;
|
||||
public final static int CREATE = 100;
|
||||
/**
|
||||
* Cost 1 gas
|
||||
*/
|
||||
public static int CREATE_DATA_BYTE = 5;
|
||||
public final static int CREATE_DATA_BYTE = 5;
|
||||
/**
|
||||
* Cost 20 gas
|
||||
*/
|
||||
public static int CALL = 20;
|
||||
public final static int CALL = 20;
|
||||
/**
|
||||
* Cost 1 gas
|
||||
*/
|
||||
public static int MEMORY = 1;
|
||||
public final static int MEMORY = 1;
|
||||
/**
|
||||
* Cost 5 gas
|
||||
*/
|
||||
public static int TX_NO_ZERO_DATA = 5;
|
||||
public final static int TX_NO_ZERO_DATA = 5;
|
||||
/**
|
||||
* Cost 1 gas
|
||||
*/
|
||||
public static int TX_ZERO_DATA = 1;
|
||||
public final static int TX_ZERO_DATA = 1;
|
||||
/**
|
||||
* Cost 500 gas
|
||||
*/
|
||||
public static int TRANSACTION = 500;
|
||||
public final static int TRANSACTION = 500;
|
||||
/**
|
||||
* Cost 32 gas
|
||||
*/
|
||||
|
@ -83,23 +83,23 @@ public class GasCost {
|
|||
/**
|
||||
* Cost 1 gas
|
||||
*/
|
||||
public static int LOG_DATA_GAS = 1;
|
||||
public final static int LOG_DATA_GAS = 1;
|
||||
/**
|
||||
* Cost 32 gas
|
||||
*/
|
||||
public static int LOG_TOPIC_GAS = 32;
|
||||
public final static int LOG_TOPIC_GAS = 32;
|
||||
/**
|
||||
* Cost 1 gas
|
||||
*/
|
||||
public static int COPY_GAS = 1;
|
||||
public final static int COPY_GAS = 1;
|
||||
/**
|
||||
* Cost 1 gas
|
||||
*/
|
||||
public static int EXP_GAS = 1;
|
||||
public final static int EXP_GAS = 1;
|
||||
/**
|
||||
* Cost 1 gas
|
||||
*/
|
||||
public static int EXP_BYTE_GAS = 1;
|
||||
public final static int EXP_BYTE_GAS = 1;
|
||||
|
||||
|
||||
}
|
|
@ -95,7 +95,7 @@ public class LogInfo {
|
|||
@Override
|
||||
public String toString() {
|
||||
|
||||
StringBuffer topicsStr = new StringBuffer();
|
||||
StringBuilder topicsStr = new StringBuilder();
|
||||
topicsStr.append("[");
|
||||
|
||||
for (DataWord topic : topics) {
|
||||
|
|
|
@ -15,28 +15,28 @@ public class MessageCall {
|
|||
/**
|
||||
* Type of internal call. Either CALL, STATELESS or POST
|
||||
*/
|
||||
private MsgType type;
|
||||
private final MsgType type;
|
||||
|
||||
/**
|
||||
* gas to pay for the call, remaining gas will be refunded to the caller
|
||||
*/
|
||||
private DataWord gas;
|
||||
private final DataWord gas;
|
||||
/**
|
||||
* address of account which code to call
|
||||
*/
|
||||
private DataWord codeAddress;
|
||||
private final DataWord codeAddress;
|
||||
/**
|
||||
* the value that can be transfer along with the code execution
|
||||
*/
|
||||
private DataWord endowment;
|
||||
private final DataWord endowment;
|
||||
/**
|
||||
* start of memory to be input data to the call
|
||||
*/
|
||||
private DataWord inDataOffs;
|
||||
private final DataWord inDataOffs;
|
||||
/**
|
||||
* size of memory to be input data to the call
|
||||
*/
|
||||
private DataWord inDataSize;
|
||||
private final DataWord inDataSize;
|
||||
/**
|
||||
* start of memory to be output of the call
|
||||
*/
|
||||
|
|
|
@ -565,8 +565,8 @@ public enum OpCode {
|
|||
*/
|
||||
SUICIDE(0xff, 1);
|
||||
|
||||
private byte opcode;
|
||||
private int require;
|
||||
private final byte opcode;
|
||||
private final int require;
|
||||
|
||||
private static final Map<Byte, OpCode> intToTypeMap = new HashMap<>();
|
||||
private static final Map<String, Byte> stringToByteMap = new HashMap<>();
|
||||
|
|
|
@ -363,7 +363,7 @@ public class Program {
|
|||
|
||||
ProgramResult result = null;
|
||||
|
||||
if (programCode != null && programCode.length != 0) {
|
||||
if (programCode.length != 0) {
|
||||
VM vm = new VM();
|
||||
Program program = new Program(programCode, programInvoke);
|
||||
vm.play(program);
|
||||
|
@ -876,7 +876,7 @@ public class Program {
|
|||
return result;
|
||||
|
||||
OpCode op = OpCode.code(code[index]);
|
||||
byte[] continuedCode = null;
|
||||
final byte[] continuedCode;
|
||||
|
||||
switch(op) {
|
||||
case PUSH1: case PUSH2: case PUSH3: case PUSH4: case PUSH5: case PUSH6: case PUSH7: case PUSH8:
|
||||
|
|
|
@ -18,8 +18,8 @@ public class ProgramInvokeImpl implements ProgramInvoke {
|
|||
/**
|
||||
* TRANSACTION env **
|
||||
*/
|
||||
private DataWord address;
|
||||
private DataWord origin, caller,
|
||||
private final DataWord address;
|
||||
private final DataWord origin, caller,
|
||||
balance, gas, gasPrice, callValue;
|
||||
|
||||
byte[] msgData;
|
||||
|
@ -27,12 +27,12 @@ public class ProgramInvokeImpl implements ProgramInvoke {
|
|||
/**
|
||||
* BLOCK env **
|
||||
*/
|
||||
private DataWord prevHash, coinbase, timestamp,
|
||||
private final DataWord prevHash, coinbase, timestamp,
|
||||
number, difficulty, gaslimit;
|
||||
|
||||
Map<DataWord, DataWord> storage;
|
||||
private Map<DataWord, DataWord> storage;
|
||||
|
||||
private Repository repository;
|
||||
private final Repository repository;
|
||||
private boolean byTransaction = true;
|
||||
private boolean byTestingSuite = false;
|
||||
private int callDeep = 0;
|
||||
|
|
|
@ -17,10 +17,9 @@ public class ProgramInvokeMockImpl implements ProgramInvoke {
|
|||
|
||||
private byte[] msgData;
|
||||
|
||||
|
||||
private Repository repository = null;
|
||||
private Repository repository;
|
||||
private byte[] ownerAddress = Hex.decode("cd2a3d9f938e13cd947ec05abc7fe734df8dd826");
|
||||
private byte[] contractAddress = Hex.decode("471fd3ad3e9eeadeec4608b92d16ce6b500704cc");
|
||||
private final byte[] contractAddress = Hex.decode("471fd3ad3e9eeadeec4608b92d16ce6b500704cc");
|
||||
|
||||
// default for most tests. This can be overwritten by the test
|
||||
private long gasLimit = 1000000;
|
||||
|
@ -100,9 +99,11 @@ public class ProgramInvokeMockImpl implements ProgramInvoke {
|
|||
return new DataWord(balance);
|
||||
}
|
||||
|
||||
/*****************/
|
||||
/*** msg data ***/
|
||||
/*****************/
|
||||
/*** msg data ***/
|
||||
/**
|
||||
* *************
|
||||
*/
|
||||
|
||||
/* CALLDATALOAD op */
|
||||
public DataWord getDataValue(DataWord indexData) {
|
||||
|
|
|
@ -37,12 +37,12 @@ import java.util.Stack;
|
|||
|
||||
public class Op {
|
||||
|
||||
byte op;
|
||||
int pc;
|
||||
DataWord gas;
|
||||
Map<String, String> storage;
|
||||
byte[] memory;
|
||||
List<String> stack;
|
||||
private byte op;
|
||||
private int pc;
|
||||
private DataWord gas;
|
||||
private Map<String, String> storage;
|
||||
private byte[] memory;
|
||||
private List<String> stack;
|
||||
|
||||
public void setOp(byte op) {
|
||||
this.op = op;
|
||||
|
|
|
@ -11,8 +11,8 @@ import java.util.List;
|
|||
*/
|
||||
public class ProgramTrace {
|
||||
|
||||
byte[] txHash;
|
||||
List<Op> ops = new ArrayList<>();
|
||||
private byte[] txHash;
|
||||
private List<Op> ops = new ArrayList<>();
|
||||
|
||||
public void setTxHash(byte[] txHash) {
|
||||
this.txHash = txHash;
|
||||
|
|
Loading…
Reference in New Issue