Apply basic formatting

- Do not align assignments on equals signs
 - Use spaces before opening curly braces
 - Add spaces between parameters as necessary
 - Insert newlines between method declarations
 - Other minor changes

This formatting pass is not comprehensive. For the most part, it does
not deal with Javadoc formatting, line wrapping, parameter alignment
rules or a number of other items that can be addressed later.
This commit is contained in:
Chris Beams 2014-12-26 11:07:01 +01:00
parent e5fcf5b48e
commit 58874cfc7e
No known key found for this signature in database
GPG Key ID: 3D214F8F5BC5ED73
199 changed files with 4309 additions and 3331 deletions

View File

@ -1,4 +1,3 @@
<!--
Publish from local ${user.home}/.m2/repository
@ -25,7 +24,6 @@
-->
<project name="ethereumj-bintray" default="publish" basedir=".">
<tstamp/>
@ -78,8 +76,6 @@
</taskdef>
<target name="definePath">
<!--[groupId('.'->'/')]\[artifactId]\[version]-->
<!--[artifactId]-[version][suffix]-->
@ -116,7 +112,6 @@
</target>
<target name="publish" depends="dependency, definePath">
<parallel>
@ -169,6 +164,4 @@
</target>
</project>

View File

@ -369,7 +369,6 @@
</plugin>
-->
<plugin>
<groupId>org.antlr</groupId>
<artifactId>antlr4-maven-plugin</artifactId>
@ -400,7 +399,6 @@
</plugin>
</plugins>
<pluginManagement>
<plugins>

View File

@ -23,6 +23,7 @@ import java.util.concurrent.CopyOnWriteArrayList;
* (such blocks are known as uncles).
*
* www.ethereumJ.com
*
* @author Roman Mandeleil,
* Nick Savers
* Created on: 20/05/2014 10:44
@ -287,6 +288,7 @@ public class Block {
/**
* check if param block is son of this block
*
* @param block - possible a son of this
* @return - true if this block is parent of param block
*/

View File

@ -117,6 +117,7 @@ public class BlockHeader {
/**
* Calculate Difficulty
* See Yellow Paper: http://www.gavwood.com/Paper.pdf - page 5, 4.3.4 (24)
*
* @return byte array value of the difficulty
*/
public byte[] calcDifficulty() {
@ -132,8 +133,6 @@ public class BlockHeader {
}
public boolean isGenesis() {
return this.getNumber() == Genesis.NUMBER;
}
@ -141,79 +140,107 @@ public class BlockHeader {
public byte[] getParentHash() {
return parentHash;
}
public void setParentHash(byte[] parentHash) {
this.parentHash = parentHash;
}
public byte[] getUnclesHash() {
return unclesHash;
}
public void setUnclesHash(byte[] unclesHash) {
this.unclesHash = unclesHash;
}
public byte[] getCoinbase() {
return coinbase;
}
public void setCoinbase(byte[] coinbase) {
this.coinbase = coinbase;
}
public byte[] getStateRoot() {
return stateRoot;
}
public void setStateRoot(byte[] stateRoot) {
this.stateRoot = stateRoot;
}
public byte[] getTxTrieRoot() {
return txTrieRoot;
}
public void setTxTrieRoot(byte[] txTrieRoot) {
this.txTrieRoot = txTrieRoot;
}
public byte[] getRecieptTrieRoot() {
return recieptTrieRoot;
}
public byte[] getLogsBloom() {return logsBloom;}
public byte[] getLogsBloom() {
return logsBloom;
}
public void setRecieptTrieRoot(byte[] recieptTrieRoot) {
this.recieptTrieRoot = recieptTrieRoot;
}
public byte[] getDifficulty() {
return difficulty;
}
public void setDifficulty(byte[] difficulty) {
this.difficulty = difficulty;
}
public long getTimestamp() {
return timestamp;
}
public void setTimestamp(long timestamp) {
this.timestamp = timestamp;
}
public long getNumber() {
return number;
}
public void setNumber(long number) {
this.number = number;
}
public long getGasLimit() {
return gasLimit;
}
public void setGasLimit(long gasLimit) {
this.gasLimit = gasLimit;
}
public long getGasUsed() {
return gasUsed;
}
public void setGasUsed(long gasUsed) {
this.gasUsed = gasUsed;
}
public byte[] getExtraData() {
return extraData;
}
public void setExtraData(byte[] extraData) {
this.extraData = extraData;
}
public byte[] getNonce() {
return nonce;
}
public void setNonce(byte[] nonce) {
this.nonce = nonce;
}
@ -260,7 +287,6 @@ public class BlockHeader {
}
private StringBuffer toStringBuff = new StringBuffer();
public String toString() {

View File

@ -54,6 +54,7 @@ import static org.ethereum.core.Denomination.SZABO;
* See <a href="https://github.com/ethereum/wiki/wiki/White-Paper#blockchain-and-mining">Ethereum Whitepaper</a>
*
* www.etherJ.com
*
* @author Roman Mandeleil,
* Nick Savers
* Created on: 20/05/2014 10:44
@ -239,6 +240,7 @@ public class BlockchainImpl implements Blockchain {
/**
* Calculate GasLimit
* See Yellow Paper: http://www.gavwood.com/Paper.pdf - page 5, 4.3.4 (25)
*
* @return long value of the gasLimit
*/
public long calcGasLimit(BlockHeader header) {
@ -473,7 +475,10 @@ public class BlockchainImpl implements Blockchain {
if (!CONFIG.recordBlocks()) return;
if (bestBlock.isGenesis()) {
try {FileUtils.deleteDirectory(CONFIG.dumpDir());} catch (IOException e) {}
try {
FileUtils.deleteDirectory(CONFIG.dumpDir());
} catch (IOException e) {
}
}
String dir = CONFIG.dumpDir() + "/";

View File

@ -10,6 +10,7 @@ import org.ethereum.util.RLPList;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.spongycastle.util.BigIntegers;
import java.security.SignatureException;
import static org.ethereum.util.ByteUtil.EMPTY_BYTE_ARRAY;

View File

@ -284,7 +284,8 @@ public class TransactionExecutor {
Hex.toHexString(contractAddress),
Hex.toHexString(bodyCode));
BigInteger storageCost = gasPrice.multiply( BigInteger.valueOf( bodyCode.length * GasCost.CREATE_DATA_BYTE) );
BigInteger storageCost = gasPrice.multiply(BigInteger.valueOf(bodyCode.length * GasCost
.CREATE_DATA_BYTE));
BigInteger balance = repository.getBalance(senderAddress);
// check if can be charged for the contract data save

View File

@ -17,8 +17,6 @@ import static org.ethereum.util.ByteUtil.EMPTY_BYTE_ARRAY;
* comprising the transaction, together with the post-transaction state,
* and the cumulative gas used in the block containing the transaction receipt
* as of immediately after the transaction has happened,
*
*
*/
public class TransactionReceipt {

View File

@ -14,6 +14,7 @@ package org.ethereum.crypto;
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import static org.ethereum.util.ByteUtil.bigIntegerToBytes;
import java.io.Serializable;
@ -66,12 +67,15 @@ import org.spongycastle.util.encoders.Hex;
* can usually ignore the compressed/uncompressed distinction.</p>
*
* This code is borrowed from the bitcoinj project and altered to fit Ethereum.<br>
* See <a href="https://github.com/bitcoinj/bitcoinj/blob/master/core/src/main/java/com/google/bitcoin/core/ECKey.java">bitcoinj on GitHub</a>
* See <a href="https://github.com/bitcoinj/bitcoinj/blob/master/core/src/main/java/com/google/bitcoin/core/ECKey
* .java">bitcoinj on GitHub</a>
*/
public class ECKey implements Serializable {
private static final Logger logger = LoggerFactory.getLogger(ECKey.class);
/** The parameters of the secp256k1 curve that Ethereum uses. */
/**
* The parameters of the secp256k1 curve that Ethereum uses.
*/
public static final ECDomainParameters CURVE;
/**
@ -234,7 +238,9 @@ public class ECKey implements Serializable {
return point.getEncoded(compressed);
}
/** Gets the hash160 form of the public key (as seen in addresses). */
/**
* Gets the hash160 form of the public key (as seen in addresses).
*/
public byte[] getAddress() {
if (pubKeyHash == null) {
byte[] pubBytes = this.pub.getEncoded(false);
@ -251,7 +257,9 @@ public class ECKey implements Serializable {
return pub.getEncoded();
}
/** Gets the public key in the form of an elliptic curve point object from Bouncy Castle. */
/**
* Gets the public key in the form of an elliptic curve point object from Bouncy Castle.
*/
public ECPoint getPubKeyPoint() {
return pub;
}
@ -300,7 +308,9 @@ public class ECKey implements Serializable {
* components can be useful for doing further EC maths on them.
*/
public static class ECDSASignature {
/** The two components of the signature. */
/**
* The two components of the signature.
*/
public final BigInteger r, s;
public byte v;
@ -601,7 +611,9 @@ public class ECKey implements Serializable {
return ECKey.fromPublicOnly(q.getEncoded(compressed));
}
/** Decompress a compressed public key (x co-ord and low-bit of y-coord). */
/**
* Decompress a compressed public key (x co-ord and low-bit of y-coord).
*/
private static ECPoint decompressKey(BigInteger xBN, boolean yBit) {
X9IntegerConverter x9 = new X9IntegerConverter();
byte[] compEnc = x9.integerToBytes(xBN, 1 + x9.getByteLength(CURVE.getCurve()));

View File

@ -75,8 +75,7 @@ public class ContractDetails {
if (foundIndex != -1) {
DataWord value = storageValues.get(foundIndex);
return value.clone();
}
else
} else
return null;
}
@ -208,7 +207,6 @@ public class ContractDetails {
}
public ContractDetails clone() {
ContractDetails contractDetails = new ContractDetails();

View File

@ -164,7 +164,9 @@ public class RepositoryImpl implements Repository {
if (block.getNumber() == 0 && txNumber == 0)
if (CONFIG.dumpCleanOnRestart()) {
try {
FileUtils.deleteDirectory(CONFIG.dumpDir());} catch (IOException e) {}
FileUtils.deleteDirectory(CONFIG.dumpDir());
} catch (IOException e) {
}
}
String dir = CONFIG.dumpDir() + "/";
@ -241,7 +243,9 @@ public class RepositoryImpl implements Repository {
try {
if (bw != null) bw.close();
if (fw != null) fw.close();
} catch (IOException e) {e.printStackTrace();}
} catch (IOException e) {
e.printStackTrace();
}
}
}
@ -365,8 +369,6 @@ public class RepositoryImpl implements Repository {
}
@Override
public void delete(byte[] addr) {
worldState.delete(addr);

View File

@ -65,7 +65,9 @@ public class TrackDatabase implements Database {
return db.get(key);
}
/** Delete object (key) from db **/
/**
* Delete object (key) from db *
*/
public void delete(byte[] key) {
if (trackingChanges) {
ByteArrayWrapper wKey = new ByteArrayWrapper(key);

View File

@ -16,25 +16,42 @@ public interface Blockchain {
public static final byte[] GENESIS_HASH = Genesis.getInstance().getHash();
public long getSize();
public void add(Block block);
public void tryToConnect(Block block);
public void storeBlock(Block block, List<TransactionReceipt> receipts);
public Block getBlockByNumber(long blockNr);
public void setBestBlock(Block block);
public Block getBestBlock();
public BlockQueue getQueue();
public boolean hasParentOnTheChain(Block block);
public void reset();
public void close();
public void updateTotalDifficulty(Block block);
public BigInteger getTotalDifficulty();
public void setTotalDifficulty(BigInteger totalDifficulty);
public byte[] getBestBlockHash();
public List<byte[]> getListOfHashesStartFrom(byte[] hash, int qty);
TransactionReceipt getTransactionReceiptByHash(byte[] hash);
public Block getBlockByHash(byte[] hash);
public List<Chain> getAltChains();
public List<Block> getGarbage();
}

View File

@ -24,6 +24,7 @@ public interface Ethereum {
/**
* Find a peer but not this one
*
* @param excludePeer - peer to exclude
* @return online peer if available otherwise null
*/
@ -64,9 +65,11 @@ public interface Ethereum {
public Set<PeerInfo> getPeers();
public void startPeerDiscovery();
public void stopPeerDiscovery();
public void connect(InetAddress addr, int port);
public void connect(String ip, int port);
public Blockchain getBlockchain();

View File

@ -64,15 +64,18 @@ public class EthereumImpl implements Ethereum {
worldManager.loadBlockchain();
if (CONFIG.listenPort() > 0) {
Executors.newSingleThreadExecutor().submit(
new Runnable() { public void run() {
new Runnable() {
public void run() {
peerServer.start(CONFIG.listenPort());
}}
}
}
);
}
}
/**
* Find a peer but not this one
*
* @param peer - peer to exclude
* @return online peer
*/

View File

@ -172,12 +172,14 @@ public interface Repository {
/**
* Return to one of the previous snapshots
* by moving the root.
*
* @param root - new root
*/
public void syncToRoot(byte[] root);
/**
* Check to see if the current repository has an open connection to the database
*
* @return <tt>true</tt> if connection to database is open
*/
public boolean isClosed();

View File

@ -15,7 +15,6 @@ import com.fasterxml.jackson.databind.ObjectMapper;
* customize ethereum state dumps.
*
* @author Alon Muroch
*
*/
public class EtherObjectMapper extends ObjectMapper {
@ -44,7 +43,6 @@ public class EtherObjectMapper extends ObjectMapper {
* an ethereum {@link com.fasterxml.jackson.core.PrettyPrinter Pretty Printer} Generator
*
* @author Alon Muroch
*
*/
public class EtherPrettyPrinter extends DefaultPrettyPrinter {

View File

@ -86,6 +86,7 @@ public class Exec {
public byte[] getData() {
return data;
}
public byte[] getCode() {
return code;
}

View File

@ -40,7 +40,11 @@ public class Helper {
String number = ((String) val).substring(2);
if (number.length() % 2 == 1) number = "0" + number;
byte[] data = Hex.decode(number);
try {bos.write(data);} catch (IOException e) { logger.error("should not happen", e);}
try {
bos.write(data);
} catch (IOException e) {
logger.error("should not happen", e);
}
} else {
// BigInt num
@ -48,15 +52,22 @@ public class Helper {
if (!isNumeric) throw new Error("Wrong test case JSON format");
else {
BigInteger value = new BigInteger(val.toString());
try {bos.write(value.toByteArray());} catch (IOException e)
{ logger.error("should not happen", e);}
try {
bos.write(value.toByteArray());
} catch (IOException e) {
logger.error("should not happen", e);
}
}
}
} else if (val instanceof Long) {
// Simple long
byte[] data = ByteUtil.bigIntegerToBytes(BigInteger.valueOf((Long) val));
try {bos.write(data);} catch (IOException e) {logger.error("should not happen", e);}
try {
bos.write(data);
} catch (IOException e) {
logger.error("should not happen", e);
}
} else {
throw new Error("Wrong test case JSON format");
}

View File

@ -25,7 +25,8 @@ public class JSONReader {
System.out.println("Loading local file: " + filename);
try {
if (System.getProperty("ETHEREUM_TEST_PATH") == null) {
System.out.println("ETHEREUM_TEST_PATH is not passed as a VM argument, please make sure you pass it with the correct path");
System.out.println("ETHEREUM_TEST_PATH is not passed as a VM argument, please make sure you pass it " +
"with the correct path");
return "";
}
System.out.println("From: " + System.getProperty("ETHEREUM_TEST_PATH"));

View File

@ -44,6 +44,4 @@ public class StateTestSuite {
}
}

View File

@ -59,7 +59,8 @@ public class TestCase {
JSONObject execJSON = (JSONObject) testCaseJSONObj.get("exec");
JSONObject preJSON = (JSONObject) testCaseJSONObj.get("pre");
JSONObject postJSON = new JSONObject();
if(testCaseJSONObj.containsKey("post")) // in cases where there is no post dictionary (when testing for exceptions for example)
if (testCaseJSONObj.containsKey("post")) // in cases where there is no post dictionary (when testing for
// exceptions for example)
postJSON = (JSONObject) testCaseJSONObj.get("post");
JSONArray callCreates = new JSONArray();
if (testCaseJSONObj.containsKey("callcreates"))

View File

@ -179,8 +179,7 @@ public class TestRunner {
try {
while (!program.isStopped())
vm.step(program);
}
catch (RuntimeException ex) {
} catch (RuntimeException ex) {
vmDidThrowAnEception = true;
e = ex;
}
@ -192,11 +191,9 @@ public class TestRunner {
String.format("VM was expected to throw an exception");
logger.info(output);
results.add(output);
}
else
} else
logger.info("VM did throw an exception: " + e.toString());
}
else {
} else {
if (vmDidThrowAnEception) {
String output =
String.format("VM threw an unexpected exception: " + e.toString());
@ -317,8 +314,7 @@ public class TestRunner {
String.format("Expected log [ %s ]", expectedLogInfo.toString());
logger.info(output);
results.add(output);
}
else {
} else {
if (!Arrays.equals(expectedLogInfo.getAddress(), foundLogInfo.getAddress())) {
String output =
String.format("Expected address [ %s ], found [ %s ]", Hex.toHexString(expectedLogInfo.getAddress()), Hex.toHexString(foundLogInfo.getAddress()));
@ -344,11 +340,11 @@ public class TestRunner {
if (expectedLogInfo.getTopics().size() != foundLogInfo.getTopics().size()) {
String output =
String.format("Expected number of topics [ %d ], found [ %d ]", expectedLogInfo.getTopics().size(), foundLogInfo.getTopics().size());
String.format("Expected number of topics [ %d ], found [ %d ]",
expectedLogInfo.getTopics().size(), foundLogInfo.getTopics().size());
logger.info(output);
results.add(output);
}
else {
} else {
int j = 0;
for (DataWord topic : expectedLogInfo.getTopics()) {
byte[] foundTopic = foundLogInfo.getTopics().get(j).getData();

View File

@ -16,11 +16,18 @@ import java.util.Set;
public interface EthereumListener {
public void trace(String output);
public void onBlock(Block block);
public void onRecvMessage(Message message);
public void onSendMessage(Message message);
public void onPeerDisconnect(String host, long port);
public void onPendingTransactionsReceived(Set<Transaction> transactions);
public void onSyncDone();
public void onNoConnections();
}

View File

@ -27,17 +27,25 @@ public class BlockQueue {
private static final Logger logger = LoggerFactory.getLogger("blockqueue");
/** The list of hashes of the heaviest chain on the network,
* for which this client doesn't have the blocks yet */
/**
* The list of hashes of the heaviest chain on the network,
* for which this client doesn't have the blocks yet
*/
private Deque<byte[]> blockHashQueue = new ArrayDeque<>();
/** Queue with blocks to be validated and added to the blockchain */
/**
* Queue with blocks to be validated and added to the blockchain
*/
private Queue<Block> blockReceivedQueue = new ConcurrentLinkedQueue<>();
/** Highest known total difficulty, representing the heaviest chain on the network */
/**
* Highest known total difficulty, representing the heaviest chain on the network
*/
private BigInteger highestTotalDifficulty;
/** Last block in the queue to be processed */
/**
* Last block in the queue to be processed
*/
private Block lastBlock;
private Timer timer = new Timer("BlockQueueTimer");
@ -93,6 +101,7 @@ public class BlockQueue {
/**
* adding single block to the queue usually
* a result of a NEW_BLOCK message announce.
*
* @param block - new block
*/
public void addBlock(Block block) {

View File

@ -44,7 +44,8 @@ public class MessageQueue {
WorldManager worldManager;
boolean hasPing = false;
public MessageQueue(){}
public MessageQueue() {
}
public void activate(ChannelHandlerContext ctx) {
this.ctx = ctx;

View File

@ -22,6 +22,7 @@ import static org.ethereum.config.SystemProperties.CONFIG;
/**
* This class creates the connection to an remote address using the Netty framework
*
* @see <a href="http://netty.io">http://netty.io</a>
*/
@Component

View File

@ -18,7 +18,9 @@ import org.ethereum.util.Utils;
*/
public class BlockHashesMessage extends EthMessage {
/** List of block hashes from the peer ordered from child to parent */
/**
* List of block hashes from the peer ordered from child to parent
*/
private List<byte[]> blockHashes;
public BlockHashesMessage(byte[] payload) {

View File

@ -251,8 +251,7 @@ public class EthHandler extends SimpleChannelInboundHandler<EthMessage> {
foundHash = hashIterator.next();
if (FastByteComparisons.compareTo(foundHash, 0, 32, latestHash, 0, 32) != 0) {
chainQueue.addHash(foundHash); // store unknown hashes in queue until known hash is found
}
else {
} else {
logger.trace("Catch up with the hashes until: {[]}", foundHash);
// if known hash is found, ignore the rest
@ -302,6 +301,7 @@ public class EthHandler extends SimpleChannelInboundHandler<EthMessage> {
/**
* Processing NEW_BLOCK announce message
*
* @param newBlockMessage - new block message
*/
public void procesNewBlock(NewBlockMessage newBlockMessage) {

View File

@ -5,7 +5,8 @@ import org.ethereum.net.message.Message;
public abstract class EthMessage extends Message {
public EthMessage() {}
public EthMessage() {
}
public EthMessage(byte[] encoded) {
super(encoded);

View File

@ -15,50 +15,65 @@ public enum EthMessageCodes {
/* Ethereum protocol */
/** [0x00, [PROTOCOL_VERSION, NETWORK_ID, TD, BEST_HASH, GENESIS_HASH] <br>
/**
* [0x00, [PROTOCOL_VERSION, NETWORK_ID, TD, BEST_HASH, GENESIS_HASH] <br>
* Inform a peer of it's current ethereum state. This message should be
* send after the initial handshake and prior to any ethereum related messages. */
* send after the initial handshake and prior to any ethereum related messages.
*/
STATUS(0x00),
/** [+0x01] Request the peer to send all transactions
* currently in the queue. */
/**
* [+0x01] Request the peer to send all transactions
* currently in the queue.
*/
GET_TRANSACTIONS(0x01),
/** [+0x02, [nonce, receiving_address, value, ...], ...] <br>
/**
* [+0x02, [nonce, receiving_address, value, ...], ...] <br>
* Specify (a) transaction(s) that the peer should make sure is included
* on its transaction queue. The items in the list (following the first item 0x12)
* are transactions in the format described in the main Ethereum specification. */
* are transactions in the format described in the main Ethereum specification.
*/
TRANSACTIONS(0x02),
/** [+0x03, [hash : B_32, maxBlocks: P]: <br>
/**
* [+0x03, [hash : B_32, maxBlocks: P]: <br>
* Requests a BlockHashes message of at most maxBlocks entries,
* of block hashes from the blockchain, starting at the parent of block hash.
* Does not require the peer to give maxBlocks hashes -
* they could give somewhat fewer. */
* they could give somewhat fewer.
*/
GET_BLOCK_HASHES(0x03),
/** [+0x04, [hash_0: B_32, hash_1: B_32, ....]: <br>Gives a series of hashes
/**
* [+0x04, [hash_0: B_32, hash_1: B_32, ....]: <br>Gives a series of hashes
* of blocks (each the child of the next). This implies that the blocks
* are ordered from youngest to oldest. */
* are ordered from youngest to oldest.
*/
BLOCK_HASHES(0x04),
/** [+0x05, [hash_0: B_32, hash_1: B_32, ....]: <br>Requests a Blocks message
/**
* [+0x05, [hash_0: B_32, hash_1: B_32, ....]: <br>Requests a Blocks message
* detailing a number of blocks to be sent, each referred to by a hash. <br>
* <b>Note:</b> Don't expect that the peer necessarily give you all these blocks
* in a single message - you might have to re-request them. */
* in a single message - you might have to re-request them.
*/
GET_BLOCKS(0x05),
/** [+0x06, [block_header, transaction_list, uncle_list], ...] <br>
/**
* [+0x06, [block_header, transaction_list, uncle_list], ...] <br>
* Specify (a) block(s) that the peer should know about.
* The items in the list (following the first item, 0x13)
* are blocks in the format described in the main Ethereum specification. */
* are blocks in the format described in the main Ethereum specification.
*/
BLOCKS(0x06),
/**
* [+0x07 [blockHeader, transactionList, uncleList], totalDifficulty] <br>
* Specify a single block that the peer should know about. The composite item
* in the list (following the message ID) is a block in the format described
* in the main Ethereum specification. */
* in the main Ethereum specification.
*/
NEW_BLOCK(0x07),
/**
@ -70,6 +85,7 @@ public enum EthMessageCodes {
private int cmd;
private static final Map<Integer, EthMessageCodes> intToTypeMap = new HashMap<>();
static {
for (EthMessageCodes type : EthMessageCodes.values()) {
intToTypeMap.put(type.cmd, type);
@ -92,6 +108,7 @@ public enum EthMessageCodes {
public static void setOffset(byte offset) {
EthMessageCodes.OFFSET = offset;
}
public byte asByte() {
return (byte) (cmd + OFFSET);
}

View File

@ -14,11 +14,15 @@ import org.spongycastle.util.encoders.Hex;
*/
public class GetBlockHashesMessage extends EthMessage {
/** The newest block hash from which to start sending older hashes */
/**
* The newest block hash from which to start sending older hashes
*/
private byte[] bestHash;
/** The maximum number of blocks to return.
* <b>Note:</b> the peer could return fewer. */
/**
* The maximum number of blocks to return.
* <b>Note:</b> the peer could return fewer.
*/
private int maxBlocks;
public GetBlockHashesMessage(byte[] encoded) {

View File

@ -17,7 +17,9 @@ import static org.ethereum.net.eth.EthMessageCodes.GET_BLOCKS;
*/
public class GetBlocksMessage extends EthMessage {
/** List of block hashes for which to retrieve the blocks */
/**
* List of block hashes for which to retrieve the blocks
*/
private List<byte[]> blockHashes;
public GetBlocksMessage(byte[] encoded) {

View File

@ -11,7 +11,9 @@ import org.spongycastle.util.encoders.Hex;
*/
public class GetTransactionsMessage extends EthMessage {
/** GetTransactions message is always a the same single command payload */
/**
* GetTransactions message is always a the same single command payload
*/
private final static byte[] FIXED_PAYLOAD = Hex.decode("C116");
public byte[] getEncoded() {

View File

@ -5,7 +5,6 @@ import org.ethereum.util.RLP;
/**
* Wrapper around an Ethereum Ping message on the network
*
*/
public class PacketCountMessage extends EthMessage {

View File

@ -18,11 +18,17 @@ public class StatusMessage extends EthMessage {
private byte protocolVersion;
private byte networkId;
/** Total difficulty of the best chain as found in block header. */
/**
* Total difficulty of the best chain as found in block header.
*/
private byte[] totalDifficulty;
/** The hash of the best (i.e. highest TD) known block. */
/**
* The hash of the best (i.e. highest TD) known block.
*/
private byte[] bestHash;
/** The hash of the Genesis block */
/**
* The hash of the Genesis block
*/
private byte[] genesisHash;
public StatusMessage(byte[] encoded) {

View File

@ -12,7 +12,8 @@ public abstract class Message {
protected byte[] encoded;
protected byte code;
public Message() {}
public Message() {
}
public Message(byte[] encoded) {
this.encoded = encoded;

View File

@ -9,39 +9,60 @@ import java.util.Map;
*/
public enum ReasonCode {
/** [0x00] Disconnect request by other peer */
/**
* [0x00] Disconnect request by other peer
*/
REQUESTED(0x00),
/** [0x01] */
/**
* [0x01]
*/
TCP_ERROR(0x01),
/** [0x02] Packets can not be parsed */
/**
* [0x02] Packets can not be parsed
*/
BAD_PROTOCOL(0x02),
/** [0x03] This peer is too slow or delivers unreliable data */
/**
* [0x03] This peer is too slow or delivers unreliable data
*/
USELESS_PEER(0x03),
/** [0x04] Already too many connections with other peers */
/**
* [0x04] Already too many connections with other peers
*/
TOO_MANY_PEERS(0x04),
/** [0x05] Already have a running connection with this peer */
/**
* [0x05] Already have a running connection with this peer
*/
ALREADY_CONNECTED(0x05),
/** [0x06] Version of the p2p protocol is not the same as ours */
/**
* [0x06] Version of the p2p protocol is not the same as ours
*/
INCOMPATIBLE_PROTOCOL(0x06),
/** [0x07] Peer identifies itself with the wrong networkId */
/**
* [0x07] Peer identifies itself with the wrong networkId
*/
INCOMPATIBLE_NETWORK(0x07),
/** [0x08] Peer quit voluntarily */
/**
* [0x08] Peer quit voluntarily
*/
PEER_QUITING(0x08),
/** [0xFF] Reason not specified */
/**
* [0xFF] Reason not specified
*/
UNKNOWN(0xFF);
private int reason;
private static final Map<Integer, ReasonCode> intToTypeMap = new HashMap<>();
static {
for (ReasonCode type : ReasonCode.values()) {
intToTypeMap.put(type.reason, type);

View File

@ -2,7 +2,8 @@ package org.ethereum.net.message;
public abstract class ShhMessage extends Message {
public ShhMessage() {}
public ShhMessage() {
}
public ShhMessage(byte[] encoded) {
super(encoded);

View File

@ -9,7 +9,9 @@ import org.spongycastle.util.encoders.Hex;
*/
public class GetPeersMessage extends P2pMessage {
/** GetPeers message is always a the same single command payload */
/**
* GetPeers message is always a the same single command payload
*/
private final static byte[] FIXED_PAYLOAD = Hex.decode("C104");
@Override

View File

@ -20,16 +20,26 @@ import java.util.List;
*/
public class HelloMessage extends P2pMessage {
/** The implemented version of the P2P protocol. */
/**
* The implemented version of the P2P protocol.
*/
private byte p2pVersion;
/** The underlying client. A user-readable string. */
/**
* The underlying client. A user-readable string.
*/
private String clientId;
/** A peer-network capability code, readable ASCII and 3 letters.
* Currently only "eth", "shh" and "bzz" are known. */
/**
* A peer-network capability code, readable ASCII and 3 letters.
* Currently only "eth", "shh" and "bzz" are known.
*/
private List<Capability> capabilities;
/** The port on which the peer is listening for an incoming connection */
/**
* The port on which the peer is listening for an incoming connection
*/
private int listenPort;
/** The identity and public key of the peer */
/**
* The identity and public key of the peer
*/
private String peerId;
public HelloMessage(byte[] encoded) {

View File

@ -213,8 +213,7 @@ public class P2pHandler extends SimpleChannelInboundHandler<P2pMessage> {
ethHandler.setPeerId(msg.getPeerId());
ethHandler.activate();
}
else if (capability.getName().equals(Capability.SHH)){
} else if (capability.getName().equals(Capability.SHH)) {
// Activate ShhHandler for this peer
ShhHandler shhHandler =
@ -239,6 +238,7 @@ public class P2pHandler extends SimpleChannelInboundHandler<P2pMessage> {
/**
* submit transaction to the network
*
* @param tx - fresh transaction object
*/
public void sendTransaction(Transaction tx) {

View File

@ -5,7 +5,8 @@ import org.ethereum.net.p2p.P2pMessageCodes;
public abstract class P2pMessage extends Message {
public P2pMessage() {}
public P2pMessage() {
}
public P2pMessage(byte[] encoded) {
super(encoded);

View File

@ -8,6 +8,7 @@ import java.util.Map;
* <br>
* The codes for these commands are the first byte in every packet.
* ÐΞV
*
* @see <a href="https://github.com/ethereum/wiki/wiki/%C3%90%CE%9EVp2p-Wire-Protocol">
* https://github.com/ethereum/wiki/wiki/ÐΞVp2p-Wire-Protocol</a>
*/
@ -15,33 +16,45 @@ public enum P2pMessageCodes {
/* P2P protocol */
/** [0x00, P2P_VERSION, CLIEND_ID, CAPS, LISTEN_PORT, CLIENT_ID] <br>
/**
* [0x00, P2P_VERSION, CLIEND_ID, CAPS, LISTEN_PORT, CLIENT_ID] <br>
* First packet sent over the connection, and sent once by both sides.
* No other messages may be sent until a Hello is received. */
* No other messages may be sent until a Hello is received.
*/
HELLO(0x00),
/** [0x01, REASON] <br>Inform the peer that a disconnection is imminent;
/**
* [0x01, REASON] <br>Inform the peer that a disconnection is imminent;
* if received, a peer should disconnect immediately. When sending,
* well-behaved hosts give their peers a fighting chance (read: wait 2 seconds)
* to disconnect to before disconnecting themselves. */
* to disconnect to before disconnecting themselves.
*/
DISCONNECT(0x01),
/** [0x02] <br>Requests an immediate reply of Pong from the peer. */
/**
* [0x02] <br>Requests an immediate reply of Pong from the peer.
*/
PING(0x02),
/** [0x03] <br>Reply to peer's Ping packet. */
/**
* [0x03] <br>Reply to peer's Ping packet.
*/
PONG(0x03),
/** [0x04] <br>Request the peer to enumerate some known peers
* for us to connect to. This should include the peer itself. */
/**
* [0x04] <br>Request the peer to enumerate some known peers
* for us to connect to. This should include the peer itself.
*/
GET_PEERS(0x04),
/** [0x05, [IP1, Port1, Id1], [IP2, Port2, Id2], ... ] <br>
/**
* [0x05, [IP1, Port1, Id1], [IP2, Port2, Id2], ... ] <br>
* Specifies a number of known peers. IP is a 4-byte array 'ABCD'
* that should be interpreted as the IP address A.B.C.D.
* Port is a 2-byte array that should be interpreted as a
* 16-bit big-endian integer. Id is the 512-bit hash that acts
* as the unique identifier of the node. */
* as the unique identifier of the node.
*/
PEERS(0x05),
@ -54,6 +67,7 @@ public enum P2pMessageCodes {
private int cmd;
private static final Map<Integer, P2pMessageCodes> intToTypeMap = new HashMap<>();
static {
for (P2pMessageCodes type : P2pMessageCodes.values()) {
intToTypeMap.put(type.cmd, type);

View File

@ -9,7 +9,9 @@ import org.spongycastle.util.encoders.Hex;
*/
public class PingMessage extends P2pMessage {
/** Ping message is always a the same single command payload */
/**
* Ping message is always a the same single command payload
*/
private static byte[] FIXED_PAYLOAD = Hex.decode("C102");
public byte[] getEncoded() {

View File

@ -10,7 +10,9 @@ import org.spongycastle.util.encoders.Hex;
*/
public class PongMessage extends P2pMessage {
/** Pong message is always a the same single command payload */
/**
* Pong message is always a the same single command payload
*/
private static byte[] FIXED_PAYLOAD = Hex.decode("C103");
@Override

View File

@ -30,6 +30,7 @@ import static org.ethereum.config.SystemProperties.CONFIG;
/**
* This class creates the connection to an remote address using the Netty framework
*
* @see <a href="http://netty.io">http://netty.io</a>
*/
@Component
@ -140,8 +141,7 @@ public class DiscoveryChannel {
return p2pHandler.getHandshakeHelloMessage();
}
public StatusMessage getStatusHandshake()
{
public StatusMessage getStatusHandshake() {
return ethHandler.getHandshakeStatusMessage();
}
}

View File

@ -14,8 +14,6 @@ import org.springframework.stereotype.Component;
* Process the messages between peers with 'shh' capability on the network.
*
* Peers with 'shh' capability can send/receive:
*
*
*/
@Component
@Scope("prototype")

View File

@ -4,7 +4,8 @@ import org.ethereum.net.message.Message;
public abstract class ShhMessage extends Message {
public ShhMessage() {}
public ShhMessage() {
}
public ShhMessage(byte[] encoded) {
super(encoded);

View File

@ -15,25 +15,36 @@ public enum ShhMessageCodes {
/* Whisper Protocol */
/** [+0x00] */
/**
* [+0x00]
*/
STATUS(0x00),
/** [+0x01] */
/**
* [+0x01]
*/
MESSAGE(0x01),
/** [+0x02] */
/**
* [+0x02]
*/
ADD_FILTER(0x02),
/** [+0x03] */
/**
* [+0x03]
*/
REMOVE_FILTER(0x03),
/** [+0x04] */
/**
* [+0x04]
*/
PACKET_COUNT(0x04);
static byte OFFSET = 0;
private int cmd;
private static final Map<Integer, ShhMessageCodes> intToTypeMap = new HashMap<>();
static {
for (ShhMessageCodes type : ShhMessageCodes.values()) {
intToTypeMap.put(type.cmd, type);

View File

@ -15,6 +15,7 @@ public class TransactionExecutor {
static {
instance = new TransactionExecutor();
}
public static TransactionExecutor instance;
private ExecutorService executor = Executors.newFixedThreadPool(1);

View File

@ -6,6 +6,7 @@ import org.apache.maven.plugin.MojoFailureException;
/**
* www.ethereumJ.com
*
* @author: Roman Mandeleil
* Created on: 25/04/14 17:06
*/

View File

@ -5,7 +5,8 @@ import org.antlr.v4.runtime.atn.PredictionMode;
import org.antlr.v4.runtime.misc.Nullable;
public class ParserUtils {
private ParserUtils() {}
private ParserUtils() {
}
public static <L extends Lexer> L getLexer(Class<L> lexerClass, String source) {
CharStream input = new ANTLRInputStream(source);
@ -19,7 +20,8 @@ public class ParserUtils {
return lexer;
}
public static <P extends Parser> P getParser(Class<? extends Lexer> lexerClass, Class<P> parserClass, String source) {
public static <P extends Parser> P getParser(Class<? extends Lexer> lexerClass, Class<P> parserClass, String
source) {
Lexer lexer = getLexer(lexerClass, source);
TokenStream tokens = new CommonTokenStream(lexer);

View File

@ -18,6 +18,7 @@ import java.util.regex.Pattern;
/**
* www.ethereumJ.com
*
* @author Roman Mandeleil
* Created on: 13/05/14 19:37
*/
@ -194,7 +195,6 @@ public class SerpentCompiler {
}
/**
*
* @param code
* @param init
* @return encoded bytes

View File

@ -14,6 +14,7 @@ import java.util.regex.Pattern;
/**
* www.ethereumJ.com
*
* @author: Roman Mandeleil
* Created on: 05/05/14 13:41
*/
@ -155,7 +156,8 @@ public class SerpentToAssemblyCompiler extends SerpentBaseVisitor<String> {
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);
whileStartRef, visitCondition(whileCondition), whileEndRef, visitBlock(whileBlock),
whileStartRef, whileEndRef);
return retCode;
}
@ -332,13 +334,20 @@ public class SerpentToAssemblyCompiler extends SerpentBaseVisitor<String> {
String operand1 = visit(ctx.mul_expr());
switch (ctx.OP_MUL().getText().toLowerCase()) {
case "*": return operand0 + " " + operand1 + " MUL";
case "/": return operand0 + " " + operand1 + " DIV";
case "^": return operand0 + " " + operand1 + " EXP";
case "%": return operand0 + " " + operand1 + " MOD";
case "#/": return operand0 + " " + operand1 + " SDIV";
case "#%": return operand0 + " " + operand1 + " SMOD";
default: throw new UnknownOperandException(ctx.OP_MUL().getText());
case "*":
return operand0 + " " + operand1 + " MUL";
case "/":
return operand0 + " " + operand1 + " DIV";
case "^":
return operand0 + " " + operand1 + " EXP";
case "%":
return operand0 + " " + operand1 + " MOD";
case "#/":
return operand0 + " " + operand1 + " SDIV";
case "#%":
return operand0 + " " + operand1 + " SMOD";
default:
throw new UnknownOperandException(ctx.OP_MUL().getText());
}
}
@ -351,9 +360,12 @@ public class SerpentToAssemblyCompiler extends SerpentBaseVisitor<String> {
String operand1 = visit(ctx.add_expr());
switch (ctx.OP_ADD().getText().toLowerCase()) {
case "+": return operand0 + " " + operand1 + " ADD";
case "-": return operand0 + " " + operand1 + " SUB";
default: throw new UnknownOperandException(ctx.OP_ADD().getText());
case "+":
return operand0 + " " + operand1 + " ADD";
case "-":
return operand0 + " " + operand1 + " SUB";
default:
throw new UnknownOperandException(ctx.OP_ADD().getText());
}
}
@ -366,11 +378,16 @@ public class SerpentToAssemblyCompiler extends SerpentBaseVisitor<String> {
String operand1 = visit(ctx.add_expr());
switch (ctx.OP_REL().getText().toLowerCase()) {
case "<": return operand1 + " " + operand0 + " LT";
case ">": return operand1 + " " + operand0 + " GT";
case ">=": return operand1 + " " + operand0 + " LT NOT";
case "<=": return operand1 + " " + operand0 + " GT NOT";
default: throw new UnknownOperandException(ctx.OP_REL().getText());
case "<":
return operand1 + " " + operand0 + " LT";
case ">":
return operand1 + " " + operand0 + " GT";
case ">=":
return operand1 + " " + operand0 + " LT NOT";
case "<=":
return operand1 + " " + operand0 + " GT NOT";
default:
throw new UnknownOperandException(ctx.OP_REL().getText());
}
}
@ -383,9 +400,12 @@ public class SerpentToAssemblyCompiler extends SerpentBaseVisitor<String> {
String operand1 = visit(ctx.eq_exp());
switch (ctx.OP_EQ().getText().toLowerCase()) {
case "==": return operand0 + " " + operand1 + " EQ";
case "!=": return operand0 + " " + operand1 + " EQ NOT";
default: throw new UnknownOperandException(ctx.OP_EQ().getText());
case "==":
return operand0 + " " + operand1 + " EQ";
case "!=":
return operand0 + " " + operand1 + " EQ NOT";
default:
throw new UnknownOperandException(ctx.OP_EQ().getText());
}
}
@ -398,8 +418,10 @@ public class SerpentToAssemblyCompiler extends SerpentBaseVisitor<String> {
String operand1 = visit(ctx.and_exp());
switch (ctx.OP_AND().getText().toLowerCase()) {
case "&": return operand0 + " " + operand1 + " AND";
default: throw new UnknownOperandException(ctx.OP_AND().getText());
case "&":
return operand0 + " " + operand1 + " AND";
default:
throw new UnknownOperandException(ctx.OP_AND().getText());
}
}
@ -412,8 +434,10 @@ public class SerpentToAssemblyCompiler extends SerpentBaseVisitor<String> {
String operand1 = visit(ctx.ex_or_exp());
switch (ctx.OP_EX_OR().getText().toLowerCase()) {
case "xor": return operand0 + " " + operand1 + " XOR";
default: throw new UnknownOperandException(ctx.OP_EX_OR().getText());
case "xor":
return operand0 + " " + operand1 + " XOR";
default:
throw new UnknownOperandException(ctx.OP_EX_OR().getText());
}
}
@ -426,8 +450,10 @@ public class SerpentToAssemblyCompiler extends SerpentBaseVisitor<String> {
String operand1 = visit(ctx.in_or_exp());
switch (ctx.OP_IN_OR().getText().toLowerCase()) {
case "|": return operand0 + " " + operand1 + " OR";
default: throw new UnknownOperandException(ctx.OP_IN_OR().getText());
case "|":
return operand0 + " " + operand1 + " OR";
default:
throw new UnknownOperandException(ctx.OP_IN_OR().getText());
}
}
@ -440,9 +466,12 @@ public class SerpentToAssemblyCompiler extends SerpentBaseVisitor<String> {
String operand1 = visit(ctx.log_and_exp());
switch (ctx.OP_LOG_AND().getText().toLowerCase()) {
case "and": return operand0 + " " + operand1 + " NOT NOT MUL";
case "&&": return operand0 + " " + operand1 + " NOT NOT MUL";
default: throw new UnknownOperandException(ctx.OP_LOG_AND().getText());
case "and":
return operand0 + " " + operand1 + " NOT NOT MUL";
case "&&":
return operand0 + " " + operand1 + " NOT NOT MUL";
default:
throw new UnknownOperandException(ctx.OP_LOG_AND().getText());
}
}
@ -455,9 +484,12 @@ public class SerpentToAssemblyCompiler extends SerpentBaseVisitor<String> {
String operand1 = visit(ctx.log_or_exp());
switch (ctx.OP_LOG_OR().getText().toLowerCase()) {
case "||": return operand0 + " " + operand1 + " DUP 4 PC ADD JUMPI POP SWAP POP";
case "or": return operand0 + " " + operand1 + " DUP 4 PC ADD JUMPI POP SWAP POP";
default: throw new UnknownOperandException(ctx.OP_LOG_OR().getText());
case "||":
return operand0 + " " + operand1 + " DUP 4 PC ADD JUMPI POP SWAP POP";
case "or":
return operand0 + " " + operand1 + " DUP 4 PC ADD JUMPI POP SWAP POP";
default:
throw new UnknownOperandException(ctx.OP_LOG_OR().getText());
}
}
@ -649,14 +681,16 @@ public class SerpentToAssemblyCompiler extends SerpentBaseVisitor<String> {
if (match) {
int byteVal = Integer.parseInt(symbol);
if (byteVal > 255 || byteVal < 0) throw new Error("In the [asm asm] block should be placed only byte range numbers");
if (byteVal > 255 || byteVal < 0)
throw new Error("In the [asm asm] block should be placed only byte range numbers");
}
match = Pattern.matches("0[xX][0-9a-fA-F]+", symbol);
if (match) {
int byteVal = Integer.parseInt(symbol.substring(2), 16);
if (byteVal > 255 || byteVal < 0) throw new Error("In the [asm asm] block should be placed only byte range numbers");
if (byteVal > 255 || byteVal < 0)
throw new Error("In the [asm asm] block should be placed only byte range numbers");
symbol = byteVal + "";
}

View File

@ -11,6 +11,7 @@ import org.iq80.leveldb.WriteBatch;
/**
* www.ethereumJ.com
*
* @author: Nick Savers
* Created on: 20/05/2014 10:44
*/

View File

@ -18,5 +18,7 @@ public class CountAllNodes implements TrieImpl.ScanAction {
++counted;
}
public int getCounted(){return counted;}
public int getCounted() {
return counted;
}
}

View File

@ -40,6 +40,7 @@ import org.ethereum.util.Value;
* when length &lt; 32 for the obvious reason that the function f(x) = x is reversible.
*
* www.ethereumJ.com
*
* @author Nick Savers
* Created on: 20/05/2014 10:44
*/

View File

@ -36,6 +36,7 @@ import org.spongycastle.util.encoders.Hex;
* <b>Note:</b> the data isn't persisted unless `sync` is explicitly called.
*
* www.ethereumJ.com
*
* @author: Nick Savers
* Created on: 20/05/2014 10:44
*/

View File

@ -3,6 +3,7 @@ package org.ethereum.trie;
import java.util.List;
import org.ethereum.util.Value;
import static org.ethereum.util.CompactEncoder.unpackToNibbles;
/*

View File

@ -112,6 +112,7 @@ public class ByteUtil {
/**
* Calculate packet length
*
* @param msg byte[]
* @return byte-array with 4 elements
*/
@ -231,6 +232,7 @@ public class ByteUtil {
/**
* encode the values and concatenate together
*
* @param args Object
* @return byte[]
*/
@ -287,7 +289,6 @@ public class ByteUtil {
* increment byte array as a number until max is reached
*
* @param bytes byte[]
*
* @return boolean
*/
public static boolean increment(byte[] bytes) {

View File

@ -44,12 +44,12 @@ import java.util.Map;
* '\x20\x0f\x1c\xb8'
* &gt; [ 15, 1, 12, 11, 8, T ]
* '\x3f\x1c\xb8'
*
*/
public class CompactEncoder {
private final static byte TERMINATOR = 16;
private final static Map<Character, Byte> hexMap = new HashMap<>();
static {
hexMap.put('0', (byte) 0x0);
hexMap.put('1', (byte) 0x1);

View File

@ -18,6 +18,7 @@ public class DecodeResult implements Serializable {
public int getPos() {
return pos;
}
public Object getDecoded() {
return decoded;
}

View File

@ -44,7 +44,6 @@ public abstract class FastByteComparisons {
* @param b2 buffer2
* @param s2 offset2
* @param l2 length2
*
* @return int
*/
public static int compareTo(byte[] b1, int s1, int l1, byte[] b2, int s2, int l2) {
@ -74,6 +73,7 @@ public abstract class FastByteComparisons {
LexicographicalComparerHolder.class.getName() + "$UnsafeComparer";
static final Comparer<byte[]> BEST_COMPARER = getBestComparer();
/**
* Returns the Unsafe-using Comparer, or falls back to the pure-Java
* implementation if unable to do so.
@ -123,7 +123,9 @@ public abstract class FastByteComparisons {
static final Unsafe theUnsafe;
/** The offset to the first element in a byte array. */
/**
* The offset to the first element in a byte array.
*/
static final int BYTE_ARRAY_BASE_OFFSET;
static {

View File

@ -45,13 +45,15 @@ import org.spongycastle.util.encoders.Hex;
* See: https://github.com/ethereum/wiki/wiki/%5BEnglish%5D-RLP
*
* www.ethereumJ.com
*
* @author: Roman Mandeleil
* Created on: 01/04/2014 10:45
*
*/
public class RLP {
/** Allow for content up to size of 2^64 bytes **/
/**
* Allow for content up to size of 2^64 bytes *
*/
private static double MAX_ITEM_LENGTH = Math.pow(256, 8);
/**
@ -62,7 +64,7 @@ public class RLP {
* - if we went with 48 then RLP would be fine for 2^128 space, but that's way too much
* - so 56 and 2^64 space seems like the right place to put the cutoff
* - also, that's where Bitcoin's varint does the cutof
**/
*/
private static int SIZE_THRESHOLD = 56;
/** RLP encoding rules are defined as follows: */
@ -694,10 +696,12 @@ public class RLP {
} else if (prefix < OFFSET_SHORT_LIST) {
int lenlen = prefix - OFFSET_LONG_ITEM; // length of length the encoded bytes
int lenbytes = byteArrayToInt(copyOfRange(data, pos + 1, pos + 1 + lenlen)); // length of encoded bytes
return new DecodeResult(pos+1+lenlen+lenbytes, copyOfRange(data, pos+1+lenlen, pos+1+lenlen+lenbytes));
return new DecodeResult(pos + 1 + lenlen + lenbytes, copyOfRange(data, pos + 1 + lenlen, pos + 1 + lenlen
+ lenbytes));
} else if (prefix <= OFFSET_LONG_LIST) {
int len = prefix - OFFSET_SHORT_LIST; // length of the encoded list
int prevPos = pos; pos++;
int prevPos = pos;
pos++;
return decodeList(data, pos, prevPos, len);
} else if (prefix < 0xFF) {
int lenlen = prefix - OFFSET_LONG_LIST; // length of length the encoded list
@ -759,7 +763,9 @@ public class RLP {
}
}
/** Integer limitation goes up to 2^31-1 so length can never be bigger than MAX_ITEM_LENGTH */
/**
* Integer limitation goes up to 2^31-1 so length can never be bigger than MAX_ITEM_LENGTH
*/
public static byte[] encodeLength(int length, int offset) {
if (length < SIZE_THRESHOLD) {
byte firstByte = (byte) (length + offset);

View File

@ -6,9 +6,9 @@ import java.io.Serializable;
* Wrapper class for decoded elements from an RLP encoded byte array.
*
* www.ethereumJ.com
*
* @author: Roman Mandeleil
* Created on: 01/04/2014 10:45
*
*/
public interface RLPElement extends Serializable {

View File

@ -3,6 +3,7 @@ package org.ethereum.util;
/**
* www.ethereumJ.com
*
* @author: Roman Mandeleil
* Created on: 21/04/14 16:26
*/

View File

@ -4,6 +4,7 @@ import java.util.ArrayList;
/**
* www.ethereumJ.com
*
* @author: Roman Mandeleil
* Created on: 21/04/14 16:26
*/

View File

@ -50,6 +50,7 @@ public class Utils {
}
static BigInteger _1000_ = new BigInteger("1000");
public static String getValueShortString(BigInteger number) {
BigInteger result = number;
int pow = 0;
@ -68,8 +69,11 @@ public class Utils {
*/
public static byte[] addressStringToBytes(String hex) {
byte[] addr = null;
try { addr = Hex.decode(hex); }
catch(DecoderException addressIsNotValid) { return null; }
try {
addr = Hex.decode(hex);
} catch (DecoderException addressIsNotValid) {
return null;
}
if (isValidAddress(addr))
return addr;
@ -102,6 +106,7 @@ public class Utils {
}
public static double JAVA_VERSION = getJavaVersion();
static double getJavaVersion() {
String version = System.getProperty("java.version");

View File

@ -17,7 +17,8 @@ public class Value {
public static Value fromRlpEncoded(byte[] data) {
if (data != null && data.length != 0) {
return new Value(RLP.decode(data, 0).getDecoded());
} return null;
}
return null;
}
public Value(Object obj) {

View File

@ -14,6 +14,7 @@ import java.nio.ByteBuffer;
* Calculations can be done on this word with other DataWords
*
* www.ethereumJ.com
*
* @author: Roman Mandeleil
* Created on: 01/06/2014 10:45
*/
@ -60,6 +61,7 @@ public class DataWord implements Comparable<DataWord> {
public byte[] getNoLeadZeroesData() {
return ByteUtil.stripLeadingZeroes(data);
}
public byte[] getLast20Bytes() {
return Arrays.copyOfRange(data, 12, data.length);
}

View File

@ -8,51 +8,97 @@ package org.ethereum.vm;
*/
public class GasCost {
/** Cost 1 gas */
/**
* Cost 1 gas
*/
public static int STEP = 1;
/** Cost 20 gas */
/**
* Cost 20 gas
*/
public static int BALANCE = 20;
/** Cost 10 gas */
/**
* Cost 10 gas
*/
public static int SHA3 = 10;
/** Cost 10 gas */
/**
* Cost 10 gas
*/
public static int SHA3_WORD = 10;
/** Cost 20 gas */
/**
* Cost 20 gas
*/
public static int SLOAD = 20;
/** Cost 0 gas */
/**
* Cost 0 gas
*/
public static int STOP = 0;
/** Cost 0 gas */
/**
* Cost 0 gas
*/
public static int SUICIDE = 0;
/** Cost 300 gas */
/**
* Cost 300 gas
*/
public static int SSTORE = 300;
/** Cost 100 gas */
/**
* Cost 100 gas
*/
public static int RESET_SSTORE = 100;
/** Cost 100 gas */
/**
* Cost 100 gas
*/
public static int REFUND_SSTORE = 100;
/** Cost 100 gas */
/**
* Cost 100 gas
*/
public static int CREATE = 100;
/** Cost 1 gas */
/**
* Cost 1 gas
*/
public static int CREATE_DATA_BYTE = 5;
/** Cost 20 gas */
/**
* Cost 20 gas
*/
public static int CALL = 20;
/** Cost 1 gas */
/**
* Cost 1 gas
*/
public static int MEMORY = 1;
/** Cost 5 gas */
/**
* Cost 5 gas
*/
public static int TX_NO_ZERO_DATA = 5;
/** Cost 1 gas */
/**
* Cost 1 gas
*/
public static int TX_ZERO_DATA = 1;
/** Cost 500 gas */
/**
* Cost 500 gas
*/
public static int TRANSACTION = 500;
/** Cost 32 gas */
/**
* Cost 32 gas
*/
public static int LOG_GAS = 32;
/** Cost 1 gas */
/**
* Cost 1 gas
*/
public static int LOG_DATA_GAS = 1;
/** Cost 32 gas */
/**
* Cost 32 gas
*/
public static int LOG_TOPIC_GAS = 32;
/** Cost 1 gas */
/**
* Cost 1 gas
*/
public static int COPY_GAS = 1;
/** Cost 1 gas */
/**
* Cost 1 gas
*/
public static int EXP_GAS = 1;
/** Cost 1 gas */
/**
* Cost 1 gas
*/
public static int EXP_BYTE_GAS = 1;

View File

@ -12,22 +12,38 @@ public class MessageCall {
POST;
}
/** Type of internal call. Either CALL, STATELESS or POST */
/**
* Type of internal call. Either CALL, STATELESS or POST
*/
private MsgType type;
/** gas to pay for the call, remaining gas will be refunded to the caller */
/**
* gas to pay for the call, remaining gas will be refunded to the caller
*/
private DataWord gas;
/** address of account which code to call */
/**
* address of account which code to call
*/
private DataWord codeAddress;
/** the value that can be transfer along with the code execution */
/**
* the value that can be transfer along with the code execution
*/
private DataWord endowment;
/** start of memory to be input data to the call */
/**
* start of memory to be input data to the call
*/
private DataWord inDataOffs;
/** size of memory to be input data to the call */
/**
* size of memory to be input data to the call
*/
private DataWord inDataSize;
/** start of memory to be output of the call */
/**
* start of memory to be output of the call
*/
private DataWord outDataOffs;
/** size of memory to be output data to the call */
/**
* size of memory to be output data to the call
*/
private DataWord outDataSize;
public MessageCall(MsgType type, DataWord gas, DataWord codeAddress,

View File

@ -10,289 +10,529 @@ import java.util.Map;
*/
public enum OpCode {
/** Halts execution (0x00) */
/**
* Halts execution (0x00)
*/
STOP(0x00, 0),
/* Arithmetic Operations */
/** (0x01) Addition operation */
/**
* (0x01) Addition operation
*/
ADD(0x01, 2),
/** (0x02) Multiplication operation */
/**
* (0x02) Multiplication operation
*/
MUL(0x02, 2),
/** (0x03) Subtraction operations */
/**
* (0x03) Subtraction operations
*/
SUB(0x03, 2),
/** (0x04) Integer division operation */
/**
* (0x04) Integer division operation
*/
DIV(0x04, 2),
/** (0x05) Signed integer division operation*/
/**
* (0x05) Signed integer division operation
*/
SDIV(0x05, 2),
/** (0x06) Modulo remainder operation */
/**
* (0x06) Modulo remainder operation
*/
MOD(0x06, 2),
/** (0x07) Signed modulo remainder operation*/
/**
* (0x07) Signed modulo remainder operation
*/
SMOD(0x07, 2),
/** (0x08) Addition combined with modulo
* remainder operation */
/**
* (0x08) Addition combined with modulo
* remainder operation
*/
ADDMOD(0x08, 3),
/** (0x09) Multiplication combined with modulo
* remainder operation */
/**
* (0x09) Multiplication combined with modulo
* remainder operation
*/
MULMOD(0x09, 3),
/** (0x0a) Exponential operation */
/**
* (0x0a) Exponential operation
*/
EXP(0x0a, 2),
/** (0x0b) Extend length of signed integer */
/**
* (0x0b) Extend length of signed integer
*/
SIGNEXTEND(0x0b, 2),
/* Bitwise Logic & Comparison Operations */
/** (0x10) Less-than comparison */
/**
* (0x10) Less-than comparison
*/
LT(0X10, 2),
/** (0x11) Greater-than comparison */
/**
* (0x11) Greater-than comparison
*/
GT(0X11, 2),
/** (0x12) Signed less-than comparison */
/**
* (0x12) Signed less-than comparison
*/
SLT(0X12, 2),
/** (0x13) Signed greater-than comparison */
/**
* (0x13) Signed greater-than comparison
*/
SGT(0X13, 2),
/** (0x14) Equality comparison */
/**
* (0x14) Equality comparison
*/
EQ(0X14, 2),
/** (0x15) Negation operation */
/**
* (0x15) Negation operation
*/
ISZERO(0x15, 1),
/** (0x16) Bitwise AND operation */
/**
* (0x16) Bitwise AND operation
*/
AND(0x16, 2),
/** (0x17) Bitwise OR operation */
/**
* (0x17) Bitwise OR operation
*/
OR(0x17, 2),
/** (0x18) Bitwise XOR operation */
/**
* (0x18) Bitwise XOR operation
*/
XOR(0x18, 2),
/** (0x19) Bitwise NOT operationr */
/**
* (0x19) Bitwise NOT operationr
*/
NOT(0x19, 1),
/** (0x1a) Retrieve single byte from word */
/**
* (0x1a) Retrieve single byte from word
*/
BYTE(0x1a, 2),
/* Cryptographic Operations */
/** (0x20) Compute SHA3-256 hash */
/**
* (0x20) Compute SHA3-256 hash
*/
SHA3(0x20, 2),
/* Environmental Information */
/** (0x30) Get address of currently
* executing account */
/**
* (0x30) Get address of currently
* executing account
*/
ADDRESS(0x30, 0),
/** (0x31) Get balance of the given account */
/**
* (0x31) Get balance of the given account
*/
BALANCE(0x31, 1),
/** (0x32) Get execution origination address*/
/**
* (0x32) Get execution origination address
*/
ORIGIN(0x32, 0),
/** (0x33) Get caller address */
/**
* (0x33) Get caller address
*/
CALLER(0x33, 0),
/** (0x34) Get deposited value by the
/**
* (0x34) Get deposited value by the
* instruction/transaction responsible
* for this execution */
* for this execution
*/
CALLVALUE(0x34, 0),
/** (0x35) Get input data of current
* environment */
/**
* (0x35) Get input data of current
* environment
*/
CALLDATALOAD(0x35, 1),
/** (0x36) Get size of input data in current
* environment */
/**
* (0x36) Get size of input data in current
* environment
*/
CALLDATASIZE(0x36, 0),
/** (0x37) Copy input data in current
* environment to memory */
/**
* (0x37) Copy input data in current
* environment to memory
*/
CALLDATACOPY(0x37, 3),
/** (0x38) Get size of code running in
* current environment */
/**
* (0x38) Get size of code running in
* current environment
*/
CODESIZE(0x38, 0),
/** (0x39) Copy code running in current
* environment to memory */
/**
* (0x39) Copy code running in current
* environment to memory
*/
CODECOPY(0x39, 3), // [len code_start mem_start CODECOPY]
/** (0x3a) Get price of gas in current
* environment */
/**
* (0x3a) Get price of gas in current
* environment
*/
GASPRICE(0x3a, 0),
/** (0x3b) Get size of code running in
* current environment with given offset */
/**
* (0x3b) Get size of code running in
* current environment with given offset
*/
EXTCODESIZE(0x3b, 1),
/** (0x3c) Copy code running in current
* environment to memory with given offset */
/**
* (0x3c) Copy code running in current
* environment to memory with given offset
*/
EXTCODECOPY(0x3c, 4),
/* Block Information */
/** (0x40) Get hash of most recent
* complete block */
/**
* (0x40) Get hash of most recent
* complete block
*/
PREVHASH(0x40, 0),
/** (0x41) Get the blocks coinbase address */
/**
* (0x41) Get the blocks coinbase address
*/
COINBASE(0x41, 0),
/** (x042) Get the blocks timestamp */
/**
* (x042) Get the blocks timestamp
*/
TIMESTAMP(0x42, 0),
/** (0x43) Get the blocks number */
/**
* (0x43) Get the blocks number
*/
NUMBER(0x43, 0),
/** (0x44) Get the blocks difficulty */
/**
* (0x44) Get the blocks difficulty
*/
DIFFICULTY(0x44, 0),
/** (0x45) Get the blocks gas limit */
/**
* (0x45) Get the blocks gas limit
*/
GASLIMIT(0x45, 0),
/* Memory, Storage and Flow Operations */
/** (0x50) Remove item from stack */
/**
* (0x50) Remove item from stack
*/
POP(0x50, 1),
/** (0x51) Load word from memory */
/**
* (0x51) Load word from memory
*/
MLOAD(0x51, 1),
/** (0x52) Save word to memory */
/**
* (0x52) Save word to memory
*/
MSTORE(0x52, 2),
/** (0x53) Save byte to memory */
/**
* (0x53) Save byte to memory
*/
MSTORE8(0x53, 2),
/** (0x54) Load word from storage */
/**
* (0x54) Load word from storage
*/
SLOAD(0x54, 1),
/** (0x55) Save word to storage */
/**
* (0x55) Save word to storage
*/
SSTORE(0x55, 2),
/** (0x56) Alter the program counter */
/**
* (0x56) Alter the program counter
*/
JUMP(0x56, 1),
/** (0x57) Conditionally alter the program
* counter */
/**
* (0x57) Conditionally alter the program
* counter
*/
JUMPI(0x57, 2),
/** (0x58) Get the program counter */
/**
* (0x58) Get the program counter
*/
PC(0x58, 0),
/** (0x59) Get the size of active memory */
/**
* (0x59) Get the size of active memory
*/
MSIZE(0x59, 0),
/** (0x5a) Get the amount of available gas */
/**
* (0x5a) Get the amount of available gas
*/
GAS(0x5a, 0),
/** (0x5b) */
/**
* (0x5b)
*/
JUMPDEST(0x5b, 0),
/* Push Operations */
/** (0x60) Place 1-byte item on stack */
/**
* (0x60) Place 1-byte item on stack
*/
PUSH1(0x60, 0),
/** (0x61) Place 2-byte item on stack */
/**
* (0x61) Place 2-byte item on stack
*/
PUSH2(0x61, 0),
/** (0x62) Place 3-byte item on stack */
/**
* (0x62) Place 3-byte item on stack
*/
PUSH3(0x62, 0),
/** (0x63) Place 4-byte item on stack */
/**
* (0x63) Place 4-byte item on stack
*/
PUSH4(0x63, 0),
/** (0x64) Place 5-byte item on stack */
/**
* (0x64) Place 5-byte item on stack
*/
PUSH5(0x64, 0),
/** (0x65) Place 6-byte item on stack */
/**
* (0x65) Place 6-byte item on stack
*/
PUSH6(0x65, 0),
/** (0x66) Place 7-byte item on stack */
/**
* (0x66) Place 7-byte item on stack
*/
PUSH7(0x66, 0),
/** (0x67) Place 8-byte item on stack */
/**
* (0x67) Place 8-byte item on stack
*/
PUSH8(0x67, 0),
/** (0x68) Place 9-byte item on stack */
/**
* (0x68) Place 9-byte item on stack
*/
PUSH9(0x68, 0),
/** (0x69) Place 10-byte item on stack */
/**
* (0x69) Place 10-byte item on stack
*/
PUSH10(0x69, 0),
/** (0x6a) Place 11-byte item on stack */
/**
* (0x6a) Place 11-byte item on stack
*/
PUSH11(0x6a, 0),
/** (0x6b) Place 12-byte item on stack */
/**
* (0x6b) Place 12-byte item on stack
*/
PUSH12(0x6b, 0),
/** (0x6c) Place 13-byte item on stack */
/**
* (0x6c) Place 13-byte item on stack
*/
PUSH13(0x6c, 0),
/** (0x6d) Place 14-byte item on stack */
/**
* (0x6d) Place 14-byte item on stack
*/
PUSH14(0x6d, 0),
/** (0x6e) Place 15-byte item on stack */
/**
* (0x6e) Place 15-byte item on stack
*/
PUSH15(0x6e, 0),
/** (0x6f) Place 16-byte item on stack */
/**
* (0x6f) Place 16-byte item on stack
*/
PUSH16(0x6f, 0),
/** (0x70) Place 17-byte item on stack */
/**
* (0x70) Place 17-byte item on stack
*/
PUSH17(0x70, 0),
/** (0x71) Place 18-byte item on stack */
/**
* (0x71) Place 18-byte item on stack
*/
PUSH18(0x71, 0),
/** (0x72) Place 19-byte item on stack */
/**
* (0x72) Place 19-byte item on stack
*/
PUSH19(0x72, 0),
/** (0x73) Place 20-byte item on stack */
/**
* (0x73) Place 20-byte item on stack
*/
PUSH20(0x73, 0),
/** (0x74) Place 21-byte item on stack */
/**
* (0x74) Place 21-byte item on stack
*/
PUSH21(0x74, 0),
/** (0x75) Place 22-byte item on stack */
/**
* (0x75) Place 22-byte item on stack
*/
PUSH22(0x75, 0),
/** (0x76) Place 23-byte item on stack */
/**
* (0x76) Place 23-byte item on stack
*/
PUSH23(0x76, 0),
/** (0x77) Place 24-byte item on stack */
/**
* (0x77) Place 24-byte item on stack
*/
PUSH24(0x77, 0),
/** (0x78) Place 25-byte item on stack */
/**
* (0x78) Place 25-byte item on stack
*/
PUSH25(0x78, 0),
/** (0x79) Place 26-byte item on stack */
/**
* (0x79) Place 26-byte item on stack
*/
PUSH26(0x79, 0),
/** (0x7a) Place 27-byte item on stack */
/**
* (0x7a) Place 27-byte item on stack
*/
PUSH27(0x7a, 0),
/** (0x7b) Place 28-byte item on stack */
/**
* (0x7b) Place 28-byte item on stack
*/
PUSH28(0x7b, 0),
/** (0x7c) Place 29-byte item on stack */
/**
* (0x7c) Place 29-byte item on stack
*/
PUSH29(0x7c, 0),
/** (0x7d) Place 30-byte item on stack */
/**
* (0x7d) Place 30-byte item on stack
*/
PUSH30(0x7d, 0),
/** (0x7e) Place 31-byte item on stack */
/**
* (0x7e) Place 31-byte item on stack
*/
PUSH31(0x7e, 0),
/** (0x7f) Place 32-byte (full word)
* item on stack */
/**
* (0x7f) Place 32-byte (full word)
* item on stack
*/
PUSH32(0x7f, 0),
/* Duplicate Nth item from the stack */
/** (0x80) Duplicate 1st item on stack */
/**
* (0x80) Duplicate 1st item on stack
*/
DUP1(0x80, 1),
/** (0x81) Duplicate 2nd item on stack */
/**
* (0x81) Duplicate 2nd item on stack
*/
DUP2(0x81, 2),
/** (0x82) Duplicate 3rd item on stack */
/**
* (0x82) Duplicate 3rd item on stack
*/
DUP3(0x82, 3),
/** (0x83) Duplicate 4th item on stack */
/**
* (0x83) Duplicate 4th item on stack
*/
DUP4(0x83, 4),
/** (0x84) Duplicate 5th item on stack */
/**
* (0x84) Duplicate 5th item on stack
*/
DUP5(0x84, 5),
/** (0x85) Duplicate 6th item on stack */
/**
* (0x85) Duplicate 6th item on stack
*/
DUP6(0x85, 6),
/** (0x86) Duplicate 7th item on stack */
/**
* (0x86) Duplicate 7th item on stack
*/
DUP7(0x86, 7),
/** (0x87) Duplicate 8th item on stack */
/**
* (0x87) Duplicate 8th item on stack
*/
DUP8(0x87, 8),
/** (0x88) Duplicate 9th item on stack */
/**
* (0x88) Duplicate 9th item on stack
*/
DUP9(0x88, 9),
/** (0x89) Duplicate 10th item on stack */
/**
* (0x89) Duplicate 10th item on stack
*/
DUP10(0x89, 10),
/** (0x8a) Duplicate 11th item on stack */
/**
* (0x8a) Duplicate 11th item on stack
*/
DUP11(0x8a, 11),
/** (0x8b) Duplicate 12th item on stack */
/**
* (0x8b) Duplicate 12th item on stack
*/
DUP12(0x8b, 12),
/** (0x8c) Duplicate 13th item on stack */
/**
* (0x8c) Duplicate 13th item on stack
*/
DUP13(0x8c, 13),
/** (0x8d) Duplicate 14th item on stack */
/**
* (0x8d) Duplicate 14th item on stack
*/
DUP14(0x8d, 14),
/** (0x8e) Duplicate 15th item on stack */
/**
* (0x8e) Duplicate 15th item on stack
*/
DUP15(0x8e, 15),
/** (0x8f) Duplicate 16th item on stack */
/**
* (0x8f) Duplicate 16th item on stack
*/
DUP16(0x8f, 16),
/* Swap the Nth item from the stack with the top */
/** (0x90) Exchange 2nd item from stack with the top */
/**
* (0x90) Exchange 2nd item from stack with the top
*/
SWAP1(0x90, 2),
/** (0x91) Exchange 3rd item from stack with the top */
/**
* (0x91) Exchange 3rd item from stack with the top
*/
SWAP2(0x91, 3),
/** (0x92) Exchange 4th item from stack with the top */
/**
* (0x92) Exchange 4th item from stack with the top
*/
SWAP3(0x92, 4),
/** (0x93) Exchange 5th item from stack with the top */
/**
* (0x93) Exchange 5th item from stack with the top
*/
SWAP4(0x93, 5),
/** (0x94) Exchange 6th item from stack with the top */
/**
* (0x94) Exchange 6th item from stack with the top
*/
SWAP5(0x94, 6),
/** (0x95) Exchange 7th item from stack with the top */
/**
* (0x95) Exchange 7th item from stack with the top
*/
SWAP6(0x95, 7),
/** (0x96) Exchange 8th item from stack with the top */
/**
* (0x96) Exchange 8th item from stack with the top
*/
SWAP7(0x96, 8),
/** (0x97) Exchange 9th item from stack with the top */
/**
* (0x97) Exchange 9th item from stack with the top
*/
SWAP8(0x97, 9),
/** (0x98) Exchange 10th item from stack with the top */
/**
* (0x98) Exchange 10th item from stack with the top
*/
SWAP9(0x98, 10),
/** (0x99) Exchange 11th item from stack with the top */
/**
* (0x99) Exchange 11th item from stack with the top
*/
SWAP10(0x99, 11),
/** (0x9a) Exchange 12th item from stack with the top */
/**
* (0x9a) Exchange 12th item from stack with the top
*/
SWAP11(0x9a, 12),
/** (0x9b) Exchange 13th item from stack with the top */
/**
* (0x9b) Exchange 13th item from stack with the top
*/
SWAP12(0x9b, 13),
/** (0x9c) Exchange 14th item from stack with the top */
/**
* (0x9c) Exchange 14th item from stack with the top
*/
SWAP13(0x9c, 14),
/** (0x9d) Exchange 15th item from stack with the top */
/**
* (0x9d) Exchange 15th item from stack with the top
*/
SWAP14(0x9d, 15),
/** (0x9e) Exchange 16th item from stack with the top */
/**
* (0x9e) Exchange 16th item from stack with the top
*/
SWAP15(0x9e, 16),
/** (0x9f) Exchange 17th item from stack with the top */
/**
* (0x9f) Exchange 17th item from stack with the top
*/
SWAP16(0x9f, 17),
/** (0xa[n]) log some data for some addres with 0..n tags [addr [tag0..tagn] data] */
/**
* (0xa[n]) log some data for some addres with 0..n tags [addr [tag0..tagn] data]
*/
LOG0(0xa0, 2),
LOG1(0xa1, 3),
LOG2(0xa2, 4),
@ -301,17 +541,28 @@ public enum OpCode {
/* System operations */
/** (0xf0) Create a new account with associated code */
/**
* (0xf0) Create a new account with associated code
*/
CREATE(0xf0, 3), // [in_size] [in_offs] [gas_val] CREATE
/** (cxf1) Message-call into an account */
CALL(0xf1, 7), // [out_data_size] [out_data_start] [in_data_size] [in_data_start] [value] [to_addr] [gas] CALL
/** (0xf2) Calls self, but grabbing the code from the
* TO argument instead of from one's own address */
/**
* (cxf1) Message-call into an account
*/
CALL(0xf1, 7), // [out_data_size] [out_data_start] [in_data_size] [in_data_start] [value] [to_addr]
// [gas] CALL
/**
* (0xf2) Calls self, but grabbing the code from the
* TO argument instead of from one's own address
*/
CALLCODE(0xf2, 7),
/** (0xf3) Halt execution returning output data */
/**
* (0xf3) Halt execution returning output data
*/
RETURN(0xf3, 2),
/** (0xff) Halt execution and register account for
* later deletion */
/**
* (0xff) Halt execution and register account for
* later deletion
*/
SUICIDE(0xff, 1);
private byte opcode;

View File

@ -28,6 +28,7 @@ import static org.ethereum.util.ByteUtil.EMPTY_BYTE_ARRAY;
/**
* www.ethereumJ.com
*
* @author: Roman Mandeleil
* Created on: 01/06/2014 10:45
*/
@ -83,6 +84,7 @@ public class Program {
/**
* Last Op can only be set publicly (no getLastOp method), is used for logging
*
* @param op
*/
public void setLastOp(byte op) {
@ -91,6 +93,7 @@ public class Program {
/**
* Should be set only after the OP is fully executed
*
* @param op
*/
public void setPreviouslyExecutedOp(byte op) {
@ -99,6 +102,7 @@ public class Program {
/**
* returns the last fully executed OP
*
* @return
*/
public byte getPreviouslyExecutedOp() {
@ -178,6 +182,7 @@ public class Program {
/**
* Verifies that the stack is at least <code>stackSize</code>
*
* @param stackSize int
* @throws StackTooSmallException If the stack is
* smaller than <code>stackSize</code>
@ -855,13 +860,16 @@ public class Program {
}
@SuppressWarnings("serial")
public class OutOfGasException extends RuntimeException {}
public class OutOfGasException extends RuntimeException {
}
@SuppressWarnings("serial")
public class IllegalOperationException extends RuntimeException {}
public class IllegalOperationException extends RuntimeException {
}
@SuppressWarnings("serial")
public class BadJumpDestinationException extends RuntimeException {}
public class BadJumpDestinationException extends RuntimeException {
}
@SuppressWarnings("serial")
public class StackTooSmallException extends RuntimeException {
@ -885,5 +893,4 @@ public class Program {
}
}

View File

@ -4,33 +4,50 @@ import org.ethereum.facade.Repository;
/**
* www.ethereumJ.com
*
* @author: Roman Mandeleil
* Created on: 03/06/2014 14:59
*/
public interface ProgramInvoke {
public DataWord getOwnerAddress();
public DataWord getBalance();
public DataWord getOriginAddress();
public DataWord getCallerAddress();
public DataWord getMinGasPrice();
public DataWord getGas();
public DataWord getCallValue();
public DataWord getDataSize();
public DataWord getDataValue(DataWord indexData);
public byte[] getDataCopy(DataWord offsetData, DataWord lengthData);
public int countNonZeroData();
public DataWord getPrevHash();
public DataWord getCoinbase();
public DataWord getTimestamp();
public DataWord getNumber();
public DataWord getDifficulty();
public DataWord getGaslimit();
public Repository getRepository();
public boolean byTransaction();
boolean byTestingSuite();
public int getCallDeep();

View File

@ -16,6 +16,7 @@ import java.math.BigInteger;
public interface ProgramInvokeFactory {
public ProgramInvoke createProgramInvoke(Transaction tx, Block block, Repository repository);
public ProgramInvoke createProgramInvoke(Program program, DataWord toAddress,
DataWord inValue, DataWord inGas,
BigInteger balanceInt, byte[] dataIn,

View File

@ -8,19 +8,24 @@ import java.util.Map;
/**
* www.ethereumJ.com
*
* @author: Roman Mandeleil
* Created on: 03/06/2014 15:00
*/
public class ProgramInvokeImpl implements ProgramInvoke {
/*** TRANSACTION env ***/
/**
* TRANSACTION env **
*/
private DataWord address;
private DataWord origin, caller,
balance, gas, gasPrice, callValue;
byte[] msgData;
/*** BLOCK env ***/
/**
* BLOCK env **
*/
private DataWord prevHash, coinbase, timestamp,
number, difficulty, gaslimit;
@ -33,7 +38,8 @@ public class ProgramInvokeImpl implements ProgramInvoke {
public ProgramInvokeImpl(DataWord address, DataWord origin, DataWord caller, DataWord balance,
DataWord gasPrice, DataWord gas, DataWord callValue, byte[] msgData,
DataWord lastHash, DataWord coinbase, DataWord timestamp, DataWord number, DataWord difficulty,
DataWord lastHash, DataWord coinbase, DataWord timestamp, DataWord number, DataWord
difficulty,
DataWord gaslimit, Repository repository, int callDeep) {
// Transaction env
@ -139,6 +145,7 @@ public class ProgramInvokeImpl implements ProgramInvoke {
* However msgData here is a byte[] and this can't hold more than 2^32-1
*/
private static BigInteger MAX_MSG_DATA = BigInteger.valueOf(Integer.MAX_VALUE);
/* CALLDATALOAD op */
public DataWord getDataValue(DataWord indexData) {
@ -225,7 +232,9 @@ public class ProgramInvokeImpl implements ProgramInvoke {
}
/* Storage */
public Map<DataWord, DataWord> getStorage() { return storage; }
public Map<DataWord, DataWord> getStorage() {
return storage;
}
public Repository getRepository() {
return repository;

View File

@ -8,6 +8,7 @@ import org.spongycastle.util.encoders.Hex;
/**
* www.ethereumJ.com
*
* @author: Roman Mandeleil
* Created on: 03/06/2014 15:00
*/

View File

@ -8,6 +8,7 @@ import java.util.List;
/**
* www.ethereumJ.com
*
* @author: Roman Mandeleil
* Created on: 07/06/2014 17:45
*/
@ -32,6 +33,7 @@ public class ProgramResult {
public void spendGas(long gas) {
gasUsed += gas;
}
public void refundGas(long gas) {
gasUsed -= gas;
}

View File

@ -58,6 +58,7 @@ import static org.ethereum.vm.OpCode.PUSH1;
* the spawning execution environment) and which will deal with it separately.
*
* www.ethereumJ.com
*
* @author: Roman Mandeleil
* Created on: 01/06/2014 10:44
*/
@ -99,7 +100,8 @@ public class VM {
// Calculate fees and spend gas
switch (op) {
case STOP: case SUICIDE:
case STOP:
case SUICIDE:
// The ops that don't charge by step
gasCost = GasCost.STOP;
break;
@ -156,7 +158,8 @@ public class VM {
copySize = stack.get(stack.size() - 4).longValue();
newMemSize = memNeeded(stack.get(stack.size() - 2), stack.get(stack.size() - 4));
break;
case CALL: case CALLCODE:
case CALL:
case CALLCODE:
gasCost = GasCost.CALL;
DataWord callGasWord = stack.get(stack.size() - 1);
if (callGasWord.compareTo(program.getGas()) == 1) {
@ -171,7 +174,11 @@ public class VM {
gasCost = GasCost.CREATE;
newMemSize = memNeeded(stack.get(stack.size() - 2), stack.get(stack.size() - 3));
break;
case LOG0: case LOG1: case LOG2: case LOG3: case LOG4:
case LOG0:
case LOG1:
case LOG2:
case LOG3:
case LOG4:
int nTopics = op.val() - OpCode.LOG0.val();
newMemSize = memNeeded(stack.peek(), stack.get(stack.size() - 2));
@ -228,7 +235,8 @@ public class VM {
case STOP: {
program.setHReturn(ByteBuffer.allocate(0));
program.stop();
} break;
}
break;
case ADD: {
DataWord word1 = program.stackPop();
DataWord word2 = program.stackPop();
@ -240,7 +248,8 @@ public class VM {
program.stackPush(word1);
program.step();
} break;
}
break;
case MUL: {
DataWord word1 = program.stackPop();
DataWord word2 = program.stackPop();
@ -251,7 +260,8 @@ public class VM {
word1.mul(word2);
program.stackPush(word1);
program.step();
} break;
}
break;
case SUB: {
DataWord word1 = program.stackPop();
DataWord word2 = program.stackPop();
@ -262,7 +272,8 @@ public class VM {
word1.sub(word2);
program.stackPush(word1);
program.step();
} break;
}
break;
case DIV: {
DataWord word1 = program.stackPop();
DataWord word2 = program.stackPop();
@ -273,7 +284,8 @@ public class VM {
word1.div(word2);
program.stackPush(word1);
program.step();
} break;
}
break;
case SDIV: {
DataWord word1 = program.stackPop();
DataWord word2 = program.stackPop();
@ -284,7 +296,8 @@ public class VM {
word1.sDiv(word2);
program.stackPush(word1);
program.step();
} break;
}
break;
case MOD: {
DataWord word1 = program.stackPop();
DataWord word2 = program.stackPop();
@ -295,7 +308,8 @@ public class VM {
word1.mod(word2);
program.stackPush(word1);
program.step();
} break;
}
break;
case SMOD: {
DataWord word1 = program.stackPop();
DataWord word2 = program.stackPop();
@ -306,7 +320,8 @@ public class VM {
word1.sMod(word2);
program.stackPush(word1);
program.step();
} break;
}
break;
case EXP: {
DataWord word1 = program.stackPop();
DataWord word2 = program.stackPop();
@ -317,7 +332,8 @@ public class VM {
word1.exp(word2);
program.stackPush(word1);
program.step();
} break;
}
break;
case SIGNEXTEND: {
DataWord word1 = program.stackPop();
BigInteger k = word1.value();
@ -330,7 +346,8 @@ public class VM {
program.stackPush(word2);
}
program.step();
} break;
}
break;
case NOT: {
DataWord word1 = program.stackPop();
word1.bnot();
@ -340,7 +357,8 @@ public class VM {
program.stackPush(word1);
program.step();
} break;
}
break;
case LT: {
// TODO: can be improved by not using BigInteger
DataWord word1 = program.stackPop();
@ -357,7 +375,8 @@ public class VM {
}
program.stackPush(word1);
program.step();
} break;
}
break;
case SLT: {
// TODO: can be improved by not using BigInteger
DataWord word1 = program.stackPop();
@ -374,7 +393,8 @@ public class VM {
}
program.stackPush(word1);
program.step();
} break;
}
break;
case SGT: {
// TODO: can be improved by not using BigInteger
DataWord word1 = program.stackPop();
@ -391,7 +411,8 @@ public class VM {
}
program.stackPush(word1);
program.step();
} break;
}
break;
case GT: {
// TODO: can be improved by not using BigInteger
DataWord word1 = program.stackPop();
@ -408,7 +429,8 @@ public class VM {
}
program.stackPush(word1);
program.step();
} break;
}
break;
case EQ: {
DataWord word1 = program.stackPop();
DataWord word2 = program.stackPop();
@ -424,7 +446,8 @@ public class VM {
}
program.stackPush(word1);
program.step();
} break;
}
break;
case ISZERO: {
DataWord word1 = program.stackPop();
if (word1.isZero()) {
@ -438,7 +461,8 @@ public class VM {
program.stackPush(word1);
program.step();
} break;
}
break;
/**
* Bitwise Logic Operations
@ -453,7 +477,8 @@ public class VM {
word1.and(word2);
program.stackPush(word1);
program.step();
} break;
}
break;
case OR: {
DataWord word1 = program.stackPop();
DataWord word2 = program.stackPop();
@ -464,7 +489,8 @@ public class VM {
word1.or(word2);
program.stackPush(word1);
program.step();
} break;
}
break;
case XOR: {
DataWord word1 = program.stackPop();
DataWord word2 = program.stackPop();
@ -475,7 +501,8 @@ public class VM {
word1.xor(word2);
program.stackPush(word1);
program.step();
} break;
}
break;
case BYTE: {
DataWord word1 = program.stackPop();
DataWord word2 = program.stackPop();
@ -494,7 +521,8 @@ public class VM {
program.stackPush(result);
program.step();
} break;
}
break;
case ADDMOD: {
DataWord word1 = program.stackPop();
DataWord word2 = program.stackPop();
@ -502,7 +530,8 @@ public class VM {
word1.addmod(word2, word3);
program.stackPush(word1);
program.step();
} break;
}
break;
case MULMOD: {
DataWord word1 = program.stackPop();
DataWord word2 = program.stackPop();
@ -510,7 +539,8 @@ public class VM {
word1.mulmod(word2, word3);
program.stackPush(word1);
program.step();
} break;
}
break;
/**
* SHA3
@ -528,7 +558,8 @@ public class VM {
program.stackPush(word);
program.step();
} break;
}
break;
/**
* Environmental Information
@ -541,7 +572,8 @@ public class VM {
program.stackPush(address);
program.step();
} break;
}
break;
case BALANCE: {
DataWord address = program.stackPop();
DataWord balance = program.getBalance(address);
@ -553,7 +585,8 @@ public class VM {
program.stackPush(balance);
program.step();
} break;
}
break;
case ORIGIN: {
DataWord originAddress = program.getOriginAddress();
@ -562,7 +595,8 @@ public class VM {
program.stackPush(originAddress);
program.step();
} break;
}
break;
case CALLER: {
DataWord callerAddress = program.getCallerAddress();
@ -571,7 +605,8 @@ public class VM {
program.stackPush(callerAddress);
program.step();
} break;
}
break;
case CALLVALUE: {
DataWord callValue = program.getCallValue();
@ -580,7 +615,8 @@ public class VM {
program.stackPush(callValue);
program.step();
} break;
}
break;
case CALLDATALOAD: {
DataWord dataOffs = program.stackPop();
DataWord value = program.getDataValue(dataOffs);
@ -590,7 +626,8 @@ public class VM {
program.stackPush(value);
program.step();
} break;
}
break;
case CALLDATASIZE: {
DataWord dataSize = program.getDataSize();
@ -599,7 +636,8 @@ public class VM {
program.stackPush(dataSize);
program.step();
} break;
}
break;
case CALLDATACOPY: {
DataWord memOffsetData = program.stackPop();
DataWord dataOffsetData = program.stackPop();
@ -612,8 +650,10 @@ public class VM {
program.memorySave(memOffsetData.intValue(), msgData);
program.step();
} break;
case CODESIZE: case EXTCODESIZE: {
}
break;
case CODESIZE:
case EXTCODESIZE: {
int length;
if (op == OpCode.CODESIZE)
@ -629,8 +669,10 @@ public class VM {
program.stackPush(codeLength);
program.step();
} break;
case CODECOPY: case EXTCODECOPY: {
}
break;
case CODECOPY:
case EXTCODECOPY: {
byte[] fullCode = ByteUtil.EMPTY_BYTE_ARRAY;
if (op == OpCode.CODECOPY)
@ -660,7 +702,8 @@ public class VM {
program.memorySave(memOffset, codeCopy);
program.step();
} break;
}
break;
case GASPRICE: {
DataWord gasPrice = program.getGasPrice();
@ -669,7 +712,8 @@ public class VM {
program.stackPush(gasPrice);
program.step();
} break;
}
break;
/**
* Block Information
@ -682,7 +726,8 @@ public class VM {
program.stackPush(prevHash);
program.step();
} break;
}
break;
case COINBASE: {
DataWord coinbase = program.getCoinbase();
@ -691,7 +736,8 @@ public class VM {
program.stackPush(coinbase);
program.step();
} break;
}
break;
case TIMESTAMP: {
DataWord timestamp = program.getTimestamp();
@ -700,7 +746,8 @@ public class VM {
program.stackPush(timestamp);
program.step();
} break;
}
break;
case NUMBER: {
DataWord number = program.getNumber();
@ -709,7 +756,8 @@ public class VM {
program.stackPush(number);
program.step();
} break;
}
break;
case DIFFICULTY: {
DataWord difficulty = program.getDifficulty();
@ -718,7 +766,8 @@ public class VM {
program.stackPush(difficulty);
program.step();
} break;
}
break;
case GASLIMIT: {
DataWord gaslimit = program.getGaslimit();
@ -727,7 +776,8 @@ public class VM {
program.stackPush(gaslimit);
program.step();
} break;
}
break;
case POP: {
program.stackPop();
program.step();
@ -754,8 +804,13 @@ public class VM {
stack.set(stack.size() - n, word_1);
program.step();
} break;
case LOG0: case LOG1: case LOG2: case LOG3: case LOG4:{
}
break;
case LOG0:
case LOG1:
case LOG2:
case LOG3:
case LOG4: {
DataWord address = program.programAddress;
@ -780,7 +835,8 @@ public class VM {
program.getResult().addLogInfo(logInfo);
program.step();
} break;
}
break;
case MLOAD: {
DataWord addr = program.stackPop();
DataWord data = program.memoryLoad(addr);
@ -790,7 +846,8 @@ public class VM {
program.stackPush(data);
program.step();
} break;
}
break;
case MSTORE: {
DataWord addr = program.stackPop();
DataWord value = program.stackPop();
@ -800,14 +857,16 @@ public class VM {
program.memorySave(addr, value);
program.step();
} break;
}
break;
case MSTORE8: {
DataWord addr = program.stackPop();
DataWord value = program.stackPop();
byte[] byteVal = {value.getData()[31]};
program.memorySave(addr.intValue(), byteVal);
program.step();
} break;
}
break;
case SLOAD: {
DataWord key = program.stackPop();
DataWord val = program.storageLoad(key);
@ -820,7 +879,8 @@ public class VM {
program.stackPush(val);
program.step();
} break;
}
break;
case SSTORE: {
DataWord addr = program.stackPop();
DataWord value = program.stackPop();
@ -830,11 +890,13 @@ public class VM {
program.storageSave(addr, value);
program.step();
} break;
}
break;
case JUMP: {
DataWord pos = program.stackPop();
int nextPC = pos.intValue(); // possible overflow
if(program.getPreviouslyExecutedOp() < OpCode.PUSH1.val() || program.getPreviouslyExecutedOp() > OpCode.PUSH32.val()) {
if (program.getPreviouslyExecutedOp() < OpCode.PUSH1.val() || program.getPreviouslyExecutedOp() >
OpCode.PUSH32.val()) {
if (nextPC != 0 && program.getOp(nextPC) != OpCode.JUMPDEST.val())
throw program.new BadJumpDestinationException();
}
@ -844,14 +906,16 @@ public class VM {
program.setPC(nextPC);
} break;
}
break;
case JUMPI: {
DataWord pos = program.stackPop();
DataWord cond = program.stackPop();
if (!cond.isZero()) {
int nextPC = pos.intValue(); // possible overflow
if(program.getPreviouslyExecutedOp() < OpCode.PUSH1.val() || program.getPreviouslyExecutedOp() > OpCode.PUSH32.val()) {
if (program.getPreviouslyExecutedOp() < OpCode.PUSH1.val() || program.getPreviouslyExecutedOp
() > OpCode.PUSH32.val()) {
if (nextPC != 0 && program.getOp(nextPC) != OpCode.JUMPDEST.val())
throw program.new BadJumpDestinationException();
}
@ -867,7 +931,8 @@ public class VM {
program.step();
}
} break;
}
break;
case PC: {
int pc = program.getPC();
DataWord pcWord = new DataWord(pc);
@ -877,7 +942,8 @@ public class VM {
program.stackPush(pcWord);
program.step();
} break;
}
break;
case MSIZE: {
int memSize = program.getMemSize();
DataWord wordMemSize = new DataWord(memSize);
@ -887,7 +953,8 @@ public class VM {
program.stackPush(wordMemSize);
program.step();
} break;
}
break;
case GAS: {
DataWord gas = program.getGas();
@ -896,12 +963,41 @@ public class VM {
program.stackPush(gas);
program.step();
} break;
}
break;
case PUSH1: case PUSH2: case PUSH3: case PUSH4: case PUSH5: case PUSH6: case PUSH7: case PUSH8:
case PUSH9: case PUSH10: case PUSH11: case PUSH12: case PUSH13: case PUSH14: case PUSH15: case PUSH16:
case PUSH17: case PUSH18: case PUSH19: case PUSH20: case PUSH21: case PUSH22: case PUSH23: case PUSH24:
case PUSH25: case PUSH26: case PUSH27: case PUSH28: case PUSH29: case PUSH30: case PUSH31: case PUSH32:{
case PUSH1:
case PUSH2:
case PUSH3:
case PUSH4:
case PUSH5:
case PUSH6:
case PUSH7:
case PUSH8:
case PUSH9:
case PUSH10:
case PUSH11:
case PUSH12:
case PUSH13:
case PUSH14:
case PUSH15:
case PUSH16:
case PUSH17:
case PUSH18:
case PUSH19:
case PUSH20:
case PUSH21:
case PUSH22:
case PUSH23:
case PUSH24:
case PUSH25:
case PUSH26:
case PUSH27:
case PUSH28:
case PUSH29:
case PUSH30:
case PUSH31:
case PUSH32: {
program.step();
int nPush = op.val() - PUSH1.val() + 1;
@ -911,10 +1007,12 @@ public class VM {
hint = "" + Hex.toHexString(data);
program.stackPush(data);
} break;
}
break;
case JUMPDEST: {
program.step();
} break;
}
break;
case CREATE: {
DataWord value = program.stackPop();
DataWord inOffset = program.stackPop();
@ -929,8 +1027,10 @@ public class VM {
program.createContract(value, inOffset, inSize);
program.step();
} break;
case CALL: case CALLCODE: {
}
break;
case CALL:
case CALLCODE: {
DataWord gas = program.stackPop();
DataWord codeAddress = program.stackPop();
DataWord value = program.stackPop();
@ -959,7 +1059,8 @@ public class VM {
program.callToAddress(msg);
program.step();
} break;
}
break;
case RETURN: {
DataWord offset = program.stackPop();
DataWord size = program.stackPop();
@ -974,7 +1075,8 @@ public class VM {
program.step();
program.stop();
} break;
}
break;
case SUICIDE: {
DataWord address = program.stackPop();
program.suicide(address);
@ -983,7 +1085,8 @@ public class VM {
hint = "address: " + Hex.toHexString(program.getOwnerAddress().getLast20Bytes());
program.stop();
} break;
}
break;
default:
break;
}
@ -1056,7 +1159,9 @@ public class VM {
private void dumpLine(OpCode op, long gasBefore, long gasCost, long memWords, Program program) {
if (CONFIG.dumpStyle().equals("standard+")) {
switch (op) {
case STOP: case RETURN: case SUICIDE:
case STOP:
case RETURN:
case SUICIDE:
ContractDetails details = program.getResult().getRepository()
.getContractDetails(program.getOwnerAddress().getLast20Bytes());

View File

@ -10,7 +10,6 @@ import java.util.LinkedHashMap;
import java.util.List;
/**
*
* www.etherj.com
*
* @author: Roman Mandeleil

View File

@ -51,7 +51,8 @@ public class EtherSaleWalletDecoder {
return result;
}
protected byte[] decryptSeed(byte[] pbkdf2PasswordHash, byte[] encseedBytesWithIV) throws InvalidCipherTextException {
protected byte[] decryptSeed(byte[] pbkdf2PasswordHash, byte[] encseedBytesWithIV) throws
InvalidCipherTextException {
// first 16 bytes are the IV (0-15)
byte[] ivBytes = Arrays.copyOf(encseedBytesWithIV, IV_LENGTH);

View File

@ -232,8 +232,6 @@ public class BlockTest {
}
@Test
@Ignore
public void testUncleValidGenerationGap() {

View File

@ -125,5 +125,4 @@ public class ForkTest {
}
}

View File

@ -49,5 +49,4 @@ public class LogInfoTest {
}
}

View File

@ -246,7 +246,8 @@ public class TransactionTest {
@Test
public void testTransactionCreateContract() {
// String rlp = "f89f808609184e72a0008203e8808203e8b84b4560005444602054600f60056002600a02010b0d630000001d596002602054630000003b5860066000530860056006600202010a0d6300000036596004604054630000003b5860056060541ca0ddc901d83110ea50bc40803f42083afea1bbd420548f6392a679af8e24b21345a06620b3b512bea5f0a272703e8d6933177c23afc79516fd0ca4a204aa6e34c7e9";
// String rlp =
// "f89f808609184e72a0008203e8808203e8b84b4560005444602054600f60056002600a02010b0d630000001d596002602054630000003b5860066000530860056006600202010a0d6300000036596004604054630000003b5860056060541ca0ddc901d83110ea50bc40803f42083afea1bbd420548f6392a679af8e24b21345a06620b3b512bea5f0a272703e8d6933177c23afc79516fd0ca4a204aa6e34c7e9";
byte[] senderPrivKey = HashUtil.sha3("cow".getBytes());
@ -255,7 +256,8 @@ public class TransactionTest {
byte[] gas = Hex.decode("03e8"); // 1000
byte[] recieveAddress = null;
byte[] endowment = Hex.decode("03e8"); //10000000000000000"
byte[] init = Hex.decode("4560005444602054600f60056002600a02010b0d630000001d596002602054630000003b5860066000530860056006600202010a0d6300000036596004604054630000003b586005606054");
byte[] init = Hex.decode
("4560005444602054600f60056002600a02010b0d630000001d596002602054630000003b5860066000530860056006600202010a0d6300000036596004604054630000003b586005606054");
Transaction tx1 = new Transaction(nonce, gasPrice, gas,

View File

@ -30,6 +30,7 @@ import java.math.BigInteger;
/**
* www.ethereumJ.com
*
* @author: Roman Mandeleil
* Created on: 17/05/14 17:06
*/

View File

@ -196,26 +196,32 @@ public class ECKeyTest {
@Test
public void testIsPubKeyCanonicalCorect() {
// Test correct prefix 4, right length 65
byte[] canonicalPubkey1 = new byte[65]; canonicalPubkey1[0] = 0x04;
byte[] canonicalPubkey1 = new byte[65];
canonicalPubkey1[0] = 0x04;
assertTrue(ECKey.isPubKeyCanonical(canonicalPubkey1));
// Test correct prefix 2, right length 33
byte[] canonicalPubkey2 = new byte[33]; canonicalPubkey2[0] = 0x02;
byte[] canonicalPubkey2 = new byte[33];
canonicalPubkey2[0] = 0x02;
assertTrue(ECKey.isPubKeyCanonical(canonicalPubkey2));
// Test correct prefix 3, right length 33
byte[] canonicalPubkey3 = new byte[33]; canonicalPubkey3[0] = 0x03;
byte[] canonicalPubkey3 = new byte[33];
canonicalPubkey3[0] = 0x03;
assertTrue(ECKey.isPubKeyCanonical(canonicalPubkey3));
}
@Test
public void testIsPubKeyCanonicalWrongLength() {
// Test correct prefix 4, but wrong length !65
byte[] nonCanonicalPubkey1 = new byte[64]; nonCanonicalPubkey1[0] = 0x04;
byte[] nonCanonicalPubkey1 = new byte[64];
nonCanonicalPubkey1[0] = 0x04;
assertFalse(ECKey.isPubKeyCanonical(nonCanonicalPubkey1));
// Test correct prefix 2, but wrong length !33
byte[] nonCanonicalPubkey2 = new byte[32]; nonCanonicalPubkey2[0] = 0x02;
byte[] nonCanonicalPubkey2 = new byte[32];
nonCanonicalPubkey2[0] = 0x02;
assertFalse(ECKey.isPubKeyCanonical(nonCanonicalPubkey2));
// Test correct prefix 3, but wrong length !33
byte[] nonCanonicalPubkey3 = new byte[32]; nonCanonicalPubkey3[0] = 0x03;
byte[] nonCanonicalPubkey3 = new byte[32];
nonCanonicalPubkey3[0] = 0x03;
assertFalse(ECKey.isPubKeyCanonical(nonCanonicalPubkey3));
}

View File

@ -123,9 +123,15 @@ public class RepositoryTest {
byte[] cow = Hex.decode("CD2A3D9F938E13CD947EC05ABC7FE734DF8DD826");
byte[] horse = Hex.decode("13978AEE95F38490E9769C39B2773ED763D9CD5F");
track.increaseNonce(cow); track.increaseNonce(cow); track.increaseNonce(cow);
track.increaseNonce(cow); track.increaseNonce(cow); track.increaseNonce(cow);
track.increaseNonce(cow); track.increaseNonce(cow); track.increaseNonce(cow);
track.increaseNonce(cow);
track.increaseNonce(cow);
track.increaseNonce(cow);
track.increaseNonce(cow);
track.increaseNonce(cow);
track.increaseNonce(cow);
track.increaseNonce(cow);
track.increaseNonce(cow);
track.increaseNonce(cow);
track.increaseNonce(cow);
track.increaseNonce(horse);
@ -148,9 +154,15 @@ public class RepositoryTest {
byte[] cow = Hex.decode("CD2A3D9F938E13CD947EC05ABC7FE734DF8DD826");
byte[] horse = Hex.decode("13978AEE95F38490E9769C39B2773ED763D9CD5F");
track.increaseNonce(cow); track.increaseNonce(cow); track.increaseNonce(cow);
track.increaseNonce(cow); track.increaseNonce(cow); track.increaseNonce(cow);
track.increaseNonce(cow); track.increaseNonce(cow); track.increaseNonce(cow);
track.increaseNonce(cow);
track.increaseNonce(cow);
track.increaseNonce(cow);
track.increaseNonce(cow);
track.increaseNonce(cow);
track.increaseNonce(cow);
track.increaseNonce(cow);
track.increaseNonce(cow);
track.increaseNonce(cow);
track.increaseNonce(cow);
track.increaseNonce(horse);

View File

@ -96,7 +96,5 @@ public class GitHubStateTest {
}
}

View File

@ -55,7 +55,11 @@ public class MineSwarm {
workers.add(mt3);
while (!mt1.isDone() || !mt2.isDone() || !mt3.isDone()) {
try {Thread.sleep(1000);} catch (InterruptedException e) {e.printStackTrace();}
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
while (!blockAppearQueue.isEmpty()) {

View File

@ -100,7 +100,8 @@ public class TransactionsMessageTest {
assertEquals(3, transactionsMessage.getTransactions().size());
Iterator<Transaction> txIter = transactionsMessage.getTransactions().iterator();
Transaction tx1 = txIter.next(); txIter.next(); // skip one
Transaction tx1 = txIter.next();
txIter.next(); // skip one
Transaction tx3 = txIter.next();
assertEquals("1b9d9456293cbcbc2f28a0fdc67028128ea571b033fb0e21d0ee00bcd6167e5d",
@ -151,7 +152,8 @@ public class TransactionsMessageTest {
assertEquals("ccdeac59d35627b7de09332e819d5159e7bb7250",
Hex.toHexString(tx1.getGasLimit()));
assertEquals("00000000000000000000000000000000000000000000000000000000000000000000000000000000000000002d0aceee7e5ab874e22ccf8d1a649f59106d74e8",
assertEquals
("00000000000000000000000000000000000000000000000000000000000000000000000000000000000000002d0aceee7e5ab874e22ccf8d1a649f59106d74e8",
Hex.toHexString(tx1.getData()));
assertEquals("1b",
@ -167,7 +169,8 @@ public class TransactionsMessageTest {
@Test /* Transactions msg encode */
public void test_3() throws Exception {
String expected = "f87302f870808b00d3c21bcecceda10000009479b08ad8787060333663d19704909ee7b1903e588609184e72a000824255801ca00f410a70e42b2c9854a8421d32c87c370a2b9fff0a27f9f031bb4443681d73b5a018a7dc4c4f9dee9f3dc35cb96ca15859aa27e219a8e4a8547be6bd3206979858";
String expected =
"f87302f870808b00d3c21bcecceda10000009479b08ad8787060333663d19704909ee7b1903e588609184e72a000824255801ca00f410a70e42b2c9854a8421d32c87c370a2b9fff0a27f9f031bb4443681d73b5a018a7dc4c4f9dee9f3dc35cb96ca15859aa27e219a8e4a8547be6bd3206979858";
BigInteger value = new BigInteger("1000000000000000000000000");

View File

@ -15,7 +15,6 @@ import java.util.Arrays;
import java.util.List;
/**
*
* @author: Roman Mandeleil
* Created on: 15/10/2014 12:34
*/

View File

@ -8,6 +8,7 @@ import org.spongycastle.util.encoders.Hex;
/**
* www.ethereumJ.com
*
* @author: Roman Mandeleil
* Created on: 28/05/2014 20:05
*/

View File

@ -1,6 +1,7 @@
package test.ethereum.serpent;
import org.antlr.v4.runtime.tree.ParseTree;
import static org.junit.Assert.*;
import org.ethereum.serpent.*;
@ -8,6 +9,7 @@ import org.junit.Test;
/**
* www.ethereumJ.com
*
* @author: Roman Mandeleil
* Created on: 13/05/14 10:07
*/

View File

@ -840,7 +840,6 @@ public class TrieTest {
}
@Test // update the trie with blog key/val
// each time dump the entire trie
public void testSample_1() {

View File

@ -111,6 +111,7 @@ public class ByteUtilTest {
int result = ByteUtil.matchingNibbleLength(a, b);
assertEquals(1, result);
}
@Test
public void testMatchingNibbleLength2() {
// b larger than a

File diff suppressed because one or more lines are too long

View File

@ -11,6 +11,7 @@ import static org.junit.Assert.assertEquals;
/**
* www.ethereumJ.com
*
* @author: Roman Mandeleil
* Created on: 17/05/14 15:38
*/

Some files were not shown because too many files have changed in this diff Show More