Merge pull request #12 from nicksavers/master

Small fix Transaction.getSender() / update Log-version / removed imports
This commit is contained in:
romanman 2014-05-25 08:43:03 +03:00
commit 6e1862c317
34 changed files with 386 additions and 500 deletions

View File

@ -9,7 +9,6 @@
<url>http://www.ethereumj.org</url>
<!--
* To deploy all the classes and dependencies to one jar,
* that's one option to pack stand alone.
mvn clean package dependency:copy-dependencies -Dmaven.test.skip=true
@ -100,7 +99,7 @@ mvn clean package -Dmaven.test.skip=true
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.7</version>
<version>${slf4j.version}</version>
<scope>compile</scope>
</dependency>
@ -109,7 +108,7 @@ mvn clean package -Dmaven.test.skip=true
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<version>1.5.6</version>
<version>${slf4j.version}</version>
<scope>runtime</scope>
</dependency>
@ -118,7 +117,7 @@ mvn clean package -Dmaven.test.skip=true
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.5</version>
<version>${slf4j.version}</version>
<scope>runtime</scope>
</dependency>
@ -153,14 +152,11 @@ mvn clean package -Dmaven.test.skip=true
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2.1</version>
<configuration>
<archive>
<manifest>
<mainClass>org.ethereum.gui.ToolBar</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
@ -189,8 +185,7 @@ mvn clean package -Dmaven.test.skip=true
</archive>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@ -5,100 +5,81 @@ import java.io.InputStream;
import java.util.Enumeration;
import java.util.Properties;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* www.ethereumJ.com
* User: Roman Mandeleil
* Created on: 22/05/2014 19:22
*/
public class SystemProperties {
Properties prop = new Properties();
InputStream input = null;
public static SystemProperties config = new SystemProperties();
private static Logger logger = LoggerFactory.getLogger(SystemProperties.class);
public static SystemProperties CONFIG = new SystemProperties();
private Properties prop = new Properties();
private InputStream input = null;
public SystemProperties() {
try {
String filename = "system.properties";
input = SystemProperties.class.getClassLoader().getResourceAsStream(filename);
if(input==null){
System.out.println("Sorry, unable to find " + filename);
return;
}
String filename = "system.properties";
input = SystemProperties.class.getClassLoader().getResourceAsStream(filename);
if (input == null) {
logger.warn("Sorry, unable to find " + filename);
return;
}
//load a properties file from class path, inside static method
prop.load(input);
} catch (IOException ex) {
ex.printStackTrace();
} finally{
if(input!=null){
try {
input.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
logger.error(ex.getMessage(), ex);
} finally {
if (input != null) {
try {
input.close();
} catch (IOException e) {
logger.error(e.getMessage(), e);
}
}
}
}
public boolean peerDiscovery(){
if(prop.isEmpty()) return true;
boolean result =
Boolean.parseBoolean( prop.getProperty("peer.discovery") );
return result;
}
public boolean peerDiscovery() {
if (prop.isEmpty())
return true;
return Boolean.parseBoolean(prop.getProperty("peer.discovery"));
}
public int peerDiscoveryWorkers(){
if(prop.isEmpty()) return 2;
int result =
Integer.parseInt( prop.getProperty("peer.discovery.workers") );
return result;
return Integer.parseInt( prop.getProperty("peer.discovery.workers") );
}
public int peerDiscoveryTimeout(){
if(prop.isEmpty()) return 10000;
int result =
Integer.parseInt( prop.getProperty("peer.discovery.timeout") );
return result * 1000;
}
public String toString(){
Enumeration<?> e = prop.propertyNames();
while (e.hasMoreElements()) {
String key = (String) e.nextElement();
String value = prop.getProperty(key);
if (!key.equals("null"))
System.out.println("Key : " + key + ", Value : " + value);
}
return "";
if (prop.isEmpty())
return 10000;
return Integer.parseInt(prop.getProperty("peer.discovery.timeout")) * 1000;
}
public String clientName() {
if(prop.isEmpty()) return "";
return prop.getProperty("client.name");
}
public String toString() {
Enumeration<?> e = prop.propertyNames();
while (e.hasMoreElements()) {
String key = (String) e.nextElement();
String value = prop.getProperty(key);
if (!key.equals("null"))
logger.info("Key: " + key + ", Value: " + value);
}
return "";
}
public static void main(String args[]){
SystemProperties systemProperties = new SystemProperties();
System.out.println(systemProperties.toString());
logger.info(systemProperties.toString());
}
}

View File

@ -4,10 +4,14 @@ import java.math.BigInteger;
import org.ethereum.crypto.HashUtil;
import org.ethereum.util.RLP;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.spongycastle.util.encoders.Hex;
public class Genesis extends Block {
Logger logger = LoggerFactory.getLogger(this.getClass());
private static byte[] zeroHash256 = new byte[32];
private static byte[] zeroHash160 = new byte[20];
private static byte[] sha3EmptyList = HashUtil.sha3(RLP.encodeList());
@ -31,5 +35,6 @@ public class Genesis extends Block {
super(parentHash, unclesHash, coinbase, stateRoot,
txTrieRoot, difficulty, number, minGasPrice, gasLimit, gasUsed,
timestamp, extraData, nonce, null, null);
logger.info("Genesis-hash: " + Hex.toHexString(this.getHash()));
}
}

View File

@ -2,11 +2,14 @@ package org.ethereum.core;
import org.ethereum.crypto.ECKey.ECDSASignature;
import org.ethereum.crypto.ECKey;
import org.ethereum.crypto.ECKey.MissingPrivateKeyException;
import org.ethereum.crypto.HashUtil;
import org.ethereum.util.ByteUtil;
import org.ethereum.util.RLP;
import org.ethereum.util.RLPItem;
import org.ethereum.util.RLPList;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.spongycastle.util.BigIntegers;
import java.security.SignatureException;
@ -22,6 +25,8 @@ import java.util.Arrays;
*/
public class Transaction {
Logger logger = LoggerFactory.getLogger(this.getClass());
private static final int CALL_SIZE = 9;
private static final int CONTRACT_SIZE = 10;
@ -66,21 +71,21 @@ public class Transaction {
private ECDSASignature signature;
/* Tx in encoded form */
private byte[] rlpEncodedSigned;
private byte[] rlpEncoded;
private byte[] rlpRaw;
/* Indicates if this transaction has been parsed
* from the rlp-encoded data */
private boolean parsed = false;
public Transaction(byte[] rawData) {
this.rlpEncodedSigned = rawData;
this.rlpEncoded = rawData;
parsed = false;
}
public Transaction(byte[] nonce, byte[] gasPrice, byte[] gas, byte[] recieveAddress, byte[] value, byte[] data) {
public Transaction(byte[] nonce, byte[] gasPrice, byte[] gasLimit, byte[] recieveAddress, byte[] value, byte[] data) {
this.nonce = nonce;
this.gasPrice = gasPrice;
this.gasLimit = gas;
this.gasLimit = gasLimit;
this.receiveAddress = recieveAddress;
this.value = value;
if(recieveAddress == null || receiveAddress.length == 0) {
@ -93,7 +98,7 @@ public class Transaction {
public void rlpParse(){
RLPList decodedTxList = RLP.decode2(rlpEncodedSigned);
RLPList decodedTxList = RLP.decode2(rlpEncoded);
RLPList transaction = (RLPList) decodedTxList.get(0);
this.nonce = ((RLPItem) transaction.get(0)).getRLPData();
@ -104,16 +109,26 @@ public class Transaction {
this.data = ((RLPItem) transaction.get(5)).getRLPData();
if (transaction.size() == CALL_SIZE){ // Simple transaction
byte v = ((RLPItem) transaction.get(6)).getRLPData()[0];
byte[] r = ((RLPItem) transaction.get(7)).getRLPData();
byte[] s = ((RLPItem) transaction.get(8)).getRLPData();
this.signature = ECDSASignature.fromComponents(r, s, v);
// only parse signature in case tx is signed
if(((RLPItem) transaction.get(6)).getRLPData() != null) {
byte v = ((RLPItem) transaction.get(6)).getRLPData()[0];
byte[] r = ((RLPItem) transaction.get(7)).getRLPData();
byte[] s = ((RLPItem) transaction.get(8)).getRLPData();
this.signature = ECDSASignature.fromComponents(r, s, v);
} else {
logger.debug("RLP encoded tx is not signed!");
}
} else if (transaction.size() == CONTRACT_SIZE){ // Contract creation transaction
this.init = ((RLPItem) transaction.get(6)).getRLPData();
byte v = ((RLPItem) transaction.get(7)).getRLPData()[0];
byte[] r = ((RLPItem) transaction.get(8)).getRLPData();
byte[] s = ((RLPItem) transaction.get(9)).getRLPData();
this.signature = ECDSASignature.fromComponents(r, s, v);
// only parse signature in case tx is signed
if(((RLPItem) transaction.get(6)).getRLPData() != null) {
byte v = ((RLPItem) transaction.get(7)).getRLPData()[0];
byte[] r = ((RLPItem) transaction.get(8)).getRLPData();
byte[] s = ((RLPItem) transaction.get(9)).getRLPData();
this.signature = ECDSASignature.fromComponents(r, s, v);
} else {
logger.debug("RLP encoded tx is not signed!");
}
} else throw new RuntimeException("Wrong tx data element list size");
this.parsed = true;
this.hash = this.getHash();
@ -126,7 +141,7 @@ public class Transaction {
public byte[] getHash() {
if (!parsed) rlpParse();
byte[] plainMsg = this.getEncoded();
byte[] plainMsg = this.getEncodedRaw();
return HashUtil.sha3(plainMsg);
}
@ -183,22 +198,21 @@ public class Transaction {
return ECKey.recoverFromSignature(signature.v, signature, hash, true);
}
public byte[] sender() {
ECKey key = null;
try {
key = ECKey.signatureToKey(getHash(), getSignature().toBase64());
} catch (SignatureException e) {
e.printStackTrace();
}
return key.getAddress();
public byte[] getSender() {
try {
ECKey key = ECKey.signatureToKey(getHash(), getSignature().toBase64());
return key.getAddress();
} catch (SignatureException e) {
logger.error(e.getMessage(), e);
}
return null;
}
public void sign(byte[] privKeyBytes) throws Exception {
public void sign(byte[] privKeyBytes) throws MissingPrivateKeyException {
byte[] hash = this.getHash();
ECKey key = ECKey.fromPrivate(privKeyBytes).decompress();
this.signature = key.sign(hash);
this.rlpEncoded = null;
}
@Override
@ -206,15 +220,15 @@ public class Transaction {
if (!parsed) rlpParse();
return "TransactionData [" + " hash=" + ByteUtil.toHexString(hash) +
" nonce=" + ByteUtil.toHexString(nonce) +
", value=" + ByteUtil.toHexString(value) +
", receiveAddress=" + ByteUtil.toHexString(receiveAddress) +
", gasPrice=" + ByteUtil.toHexString(gasPrice) +
", gas=" + ByteUtil.toHexString(gasLimit) +
", receiveAddress=" + ByteUtil.toHexString(receiveAddress) +
", value=" + ByteUtil.toHexString(value) +
", data=" + ByteUtil.toHexString(data) +
", init=" + ByteUtil.toHexString(init) +
", signatureV=" + signature.v +
", signatureR=" + ByteUtil.toHexString(signature.r.toByteArray()) +
", signatureS=" + ByteUtil.toHexString(signature.s.toByteArray()) +
", signatureR=" + ByteUtil.toHexString(BigIntegers.asUnsignedByteArray(signature.r)) +
", signatureS=" + ByteUtil.toHexString(BigIntegers.asUnsignedByteArray(signature.s)) +
']';
}
@ -222,9 +236,9 @@ public class Transaction {
* For signature games you have to keep also
* rlp of the transaction without any signature data
*/
public byte[] getEncoded(){
public byte[] getEncodedRaw(){
if (rlpEncoded != null) return rlpEncoded;
if (rlpRaw != null) return rlpRaw;
byte[] nonce = RLP.encodeElement(this.nonce);
byte[] gasPrice = RLP.encodeElement(this.gasPrice);
@ -235,38 +249,46 @@ public class Transaction {
if(Arrays.equals(this.receiveAddress, new byte[0])) {
byte[] init = RLP.encodeElement(this.init);
this.rlpEncoded = RLP.encodeList(nonce, gasPrice, gasLimit, receiveAddress, value,
this.rlpRaw = RLP.encodeList(nonce, gasPrice, gasLimit, receiveAddress, value,
data, init);
} else {
this.rlpEncoded = RLP.encodeList(nonce, gasPrice, gasLimit, receiveAddress, value,
this.rlpRaw = RLP.encodeList(nonce, gasPrice, gasLimit, receiveAddress, value,
data);
}
return rlpRaw;
}
public byte[] getEncoded() {
if(rlpEncoded != null) return rlpEncoded;
byte[] nonce = RLP.encodeElement(this.nonce);
byte[] gasPrice = RLP.encodeElement(this.gasPrice);
byte[] gasLimit = RLP.encodeElement(this.gasLimit);
byte[] receiveAddress = RLP.encodeElement(this.receiveAddress);
byte[] value = RLP.encodeElement(this.value);
byte[] data = RLP.encodeElement(this.data);
byte[] v, r, s;
if(signature != null) {
v = RLP.encodeByte( signature.v );
r = RLP.encodeElement(BigIntegers.asUnsignedByteArray(signature.r));
s = RLP.encodeElement(BigIntegers.asUnsignedByteArray(signature.s));
} else {
v = RLP.encodeElement(new byte[0]);
r = RLP.encodeElement(new byte[0]);
s = RLP.encodeElement(new byte[0]);
}
if(Arrays.equals(this.receiveAddress, new byte[0])) {
byte[] init = RLP.encodeElement(this.init);
this.rlpEncoded = RLP.encodeList(nonce, gasPrice, gasLimit, receiveAddress, value,
data, init, v, r, s);
} else {
this.rlpEncoded = RLP.encodeList(nonce, gasPrice, gasLimit, receiveAddress, value,
data, v, r, s);
}
return rlpEncoded;
}
public byte[] getEncodedSigned() {
if(rlpEncodedSigned != null) return rlpEncodedSigned;
byte[] nonce = RLP.encodeElement(this.nonce);
byte[] gasPrice = RLP.encodeElement(this.gasPrice);
byte[] gasLimit = RLP.encodeElement(this.gasLimit);
byte[] receiveAddress = RLP.encodeElement(this.receiveAddress);
byte[] value = RLP.encodeElement(this.value);
byte[] data = RLP.encodeElement(this.data);
byte[] v = RLP.encodeByte( signature.v );
byte[] r = RLP.encodeElement(BigIntegers.asUnsignedByteArray(signature.r));
byte[] s = RLP.encodeElement(BigIntegers.asUnsignedByteArray(signature.s));
if(Arrays.equals(this.receiveAddress, new byte[0])) {
byte[] init = RLP.encodeElement(this.init);
this.rlpEncodedSigned = RLP.encodeList(nonce, gasPrice, gasLimit, receiveAddress, value,
data, init, v, r, s);
} else {
this.rlpEncodedSigned = RLP.encodeList(nonce, gasPrice, gasLimit, receiveAddress, value,
data, v, r, s);
}
return rlpEncodedSigned;
}
}

View File

@ -37,7 +37,7 @@ public class Wallet {
private HashMap<String, AddressState> rows = new HashMap<String, AddressState>();
private long high;
private List<WalletListener> listeners = new ArrayList();
private List<WalletListener> listeners = new ArrayList<WalletListener>();
public void addNewKey(){
@ -96,7 +96,7 @@ public class Wallet {
for (Transaction tx : transactions){
byte[] senderAddress = tx.sender();
byte[] senderAddress = tx.getSender();
AddressState senderState = rows.get(Hex.toHexString(senderAddress));
if (senderState != null){
BigInteger value = new BigInteger(tx.getValue());
@ -169,9 +169,6 @@ public class Wallet {
// this.importKey(privKey);
// this.setBalance(address, value);
}
}
/**
@ -257,7 +254,6 @@ public class Wallet {
public void valueChanged();
}
public long getHigh() {
return high;
}

View File

@ -15,7 +15,6 @@ package org.ethereum.crypto;
* limitations under the License.
*/
import static com.google.common.base.Preconditions.checkNotNull;
import static org.ethereum.util.ByteUtil.bigIntegerToBytes;
import java.io.Serializable;
@ -46,9 +45,7 @@ import org.spongycastle.math.ec.ECCurve;
import org.spongycastle.math.ec.ECPoint;
import org.spongycastle.util.encoders.Base64;
import org.spongycastle.util.encoders.Hex;
import com.google.common.base.Preconditions;
public class ECKey implements Serializable {
private static final Logger log = LoggerFactory.getLogger(ECKey.class);
@ -158,8 +155,8 @@ public class ECKey implements Serializable {
* already. The compression state of the point will be preserved.
*/
public static ECKey fromPrivateAndPrecalculatedPublic(byte[] priv, byte[] pub) {
checkNotNull(priv);
checkNotNull(pub);
check(priv != null, "Private key must not be null");
check(pub != null, "Public key must not be null");
return new ECKey(new BigInteger(1, priv), CURVE.getCurve().decodePoint(pub));
}
@ -363,7 +360,7 @@ public class ECKey implements Serializable {
// No decryption of private key required.
if (priv == null)
throw new MissingPrivateKeyException();
checkNotNull(priv);
check(priv != null, "Private key must not be null");
ECDSASigner signer = new ECDSASigner(new HMacDSAKCalculator(new SHA256Digest()));
ECPrivateKeyParameters privKey = new ECPrivateKeyParameters(priv, CURVE);
signer.init(true, privKey);
@ -534,10 +531,10 @@ public class ECKey implements Serializable {
*/
@Nullable
public static ECKey recoverFromSignature(int recId, ECDSASignature sig, byte[] messageHash, boolean compressed) {
Preconditions.checkArgument(recId >= 0, "recId must be positive");
Preconditions.checkArgument(sig.r.signum() >= 0, "r must be positive");
Preconditions.checkArgument(sig.s.signum() >= 0, "s must be positive");
Preconditions.checkNotNull(messageHash);
check(recId >= 0, "recId must be positive");
check(sig.r.signum() >= 0, "r must be positive");
check(sig.s.signum() >= 0, "s must be positive");
check(messageHash != null, "messageHash must not be null");
// 1.0 For j from 0 to h (h == recId here and the loop is outside this function)
// 1.1 Let x = r + jn
BigInteger n = CURVE.getN(); // Curve order.
@ -624,4 +621,7 @@ public class ECKey implements Serializable {
public static class MissingPrivateKeyException extends RuntimeException {
}
private static void check(boolean test, String message) {
if(!test) throw new IllegalArgumentException(message);
}
}

View File

@ -2,7 +2,6 @@ package org.ethereum.geodb;
import java.io.File;
import java.net.InetAddress;
import java.net.URISyntaxException;
import java.net.URL;
import com.maxmind.geoip.Location;
@ -20,7 +19,7 @@ public class IpGeoDB { // change
File file = null;
try {
URL geiIpDBFile = ClassLoader.getSystemResource("geolitecity.dat");
URL geiIpDBFile = ClassLoader.getSystemResource("GeoLiteCity.dat");
file = new File(geiIpDBFile.toURI());
} catch (Throwable th) {

View File

@ -1,7 +1,6 @@
package org.ethereum.gui;
import org.ethereum.manager.MainData;
import org.spongycastle.util.encoders.Hex;
import javax.swing.table.AbstractTableModel;
@ -12,8 +11,6 @@ import javax.swing.table.AbstractTableModel;
*/
public class BlockTableModel extends AbstractTableModel {
@Override
public int getRowCount() {

View File

@ -69,18 +69,23 @@ public class ConnectionConsoleWindow extends JFrame implements PeerListener{
Thread t = new Thread() {
public void run() {
// new ClientPeer(thisConsole).connect("54.201.28.117", 30303); // peer discovery
// new ClientPeer(thisConsole).connect("82.217.72.169", 30303); // Nick
// new ClientPeer(thisConsole).connect("131.104.247.135", 30303); // Some dude in Canada
// new ClientPeer(thisConsole).connect("54.204.10.41", 30303);
// new ClientPeer(thisConsole).connect("54.204.10.41", 30303); // CPP: ZeroGox Poc5
new ClientPeer(thisConsole).connect("54.211.14.10", 40404); // RomanJ
// new ClientPeer(thisConsole).connect("192.168.1.102", 30303);
// Peer Server Zero: peer discovery
// new ClientPeer(thisConsole).connect("54.201.28.117", 30303);
// Peer Server One: peer discovery
new ClientPeer(thisConsole).connect("54.204.10.41", 30303);
// Some dude in Canada
// new ClientPeer(thisConsole).connect("131.104.247.135", 30303);
// Nick
// new ClientPeer(thisConsole).connect("82.217.72.169", 30303);
// c++: ZeroGox
// new ClientPeer(thisConsole).connect("54.204.10.41", 30303);
// RomanJ
// new ClientPeer(thisConsole).connect("54.211.14.10", 40404);
}
};
t.start();

View File

@ -1,7 +1,6 @@
package org.ethereum.gui;
import org.ethereum.core.Transaction;
import org.ethereum.crypto.HashUtil;
import org.ethereum.manager.MainData;
import org.ethereum.net.client.ClientPeer;
import org.ethereum.wallet.AddressState;

View File

@ -2,7 +2,6 @@ package org.ethereum.gui;
import java.net.InetAddress;
import java.net.URL;
import java.net.UnknownHostException;
import java.util.*;
import javax.swing.ImageIcon;

View File

@ -1,6 +1,5 @@
package org.ethereum.gui;
import org.ethereum.config.SystemProperties;
import org.ethereum.manager.MainData;
import java.awt.*;
@ -16,7 +15,7 @@ import javax.swing.SwingConstants;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.TableCellRenderer;
import static org.ethereum.config.SystemProperties.config;
import static org.ethereum.config.SystemProperties.CONFIG;
/**
* www.ethereumJ.com
@ -93,7 +92,7 @@ public class PeersTableWindow extends JFrame{
}
}, 1000, 1000);
if (config.peerDiscovery())
if (CONFIG.peerDiscovery())
MainData.instance.startPeerDiscovery();
}

View File

@ -8,8 +8,6 @@ import org.slf4j.LoggerFactory;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
@ -36,7 +34,7 @@ public class ToolBar extends JFrame {
introLogger.info("♢ EthereumJ [v0.5.1] ");
introLogger.info("♢ Code by Roman Mandeleil, (c) 2014.");
introLogger.info("♢ Contribution: Nick Savers ");
introLogger.info("♢ Based on a design by Vitaly Buterin.");
introLogger.info("♢ Based on a design by Vitalik Buterin.");
introLogger.info("");
introLogger.info("java.version: " + System.getProperty("java.version"));
introLogger.info("java.home: " + System.getProperty("java.home"));
@ -48,9 +46,6 @@ public class ToolBar extends JFrame {
System.exit(0);
}
final JPanel cp = new JPanel(new FlowLayout());
cp.setBackground(Color.WHITE);
@ -161,7 +156,6 @@ public class ToolBar extends JFrame {
}
});
JToggleButton chainToggle = new JToggleButton();
chainToggle.setIcon(image_4);
chainToggle.setToolTipText("Block Chain");
@ -222,17 +216,14 @@ public class ToolBar extends JFrame {
cp.add(chainToggle);
cp.add(walletToggle);
MainData.instance.toString();
}
public static void main(String args[]){
SwingUtilities.invokeLater(new Runnable() {
public void run() {
new ToolBar().setVisible(true);
}
});
}
}

View File

@ -11,7 +11,6 @@ import javax.swing.border.EmptyBorder;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.math.BigInteger;
import java.net.URL;
/**

View File

@ -7,8 +7,6 @@ import javax.swing.border.Border;
import javax.swing.border.CompoundBorder;
import javax.swing.border.EmptyBorder;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.math.BigInteger;

View File

@ -18,7 +18,6 @@ import org.ethereum.net.client.ClientPeer;
import org.ethereum.net.client.PeerData;
import org.ethereum.net.message.StaticMessages;
import org.ethereum.net.peerdiscovery.PeerDiscovery;
import org.ethereum.net.peerdiscovery.WorkerThread;
import org.ethereum.wallet.AddressState;
import org.spongycastle.util.encoders.Hex;
@ -49,7 +48,7 @@ public class MainData {
wallet.importKey(cowAddr);
AddressState state = wallet.getAddressState(key.getAddress());
state.addToBalance(new BigInteger("1606938044258990275541962092341162602522202993782792835301376"));
state.addToBalance(BigInteger.valueOf(2).pow(200)); // 1606938044258990275541962092341162602522202993782792835301376
wallet.importKey(HashUtil.sha3("cat".getBytes()));
peerDiscovery = new PeerDiscovery(peers);
@ -92,7 +91,7 @@ public class MainData {
public byte[] getLatestBlockHash(){
if (blockChainDB.isEmpty())
return (new Genesis()).getHash();
return StaticMessages.GENESIS_HASH;
else
return blockChainDB.get(blockChainDB.size() - 1).getHash();
}

View File

@ -89,7 +89,7 @@ public class ClientPeer {
*/
public void sendTransaction(Transaction transaction){
transaction.getEncodedSigned();
transaction.getEncoded();
java.util.List<Transaction> txList = new ArrayList<Transaction>();
txList.add(transaction);
TransactionsMessage transactionsMessage = new TransactionsMessage(txList);

View File

@ -6,7 +6,6 @@ import java.util.List;
import static org.ethereum.net.Command.BLOCKS;
import org.ethereum.core.Block;
import org.ethereum.core.Transaction;
import org.ethereum.net.Command;
import org.ethereum.util.RLPItem;
import org.ethereum.util.RLPList;

View File

@ -120,10 +120,10 @@ public class HelloMessage extends Message {
return "Hello Message [ command=" + HELLO.asByte() + " " +
" protocolVersion=" + this.protocolVersion + " " +
" networkId=" + this.networkId + " " +
" clientId= " + this.clientId + " " +
" capabilities= " + this.capabilities + " " +
" peerPort= " + this.peerPort + " " +
" peerId= " + Hex.toHexString(this.peerId) + " " +
" clientId=" + this.clientId + " " +
" capabilities=" + this.capabilities + " " +
" peerPort=" + this.peerPort + " " +
" peerId=" + Hex.toHexString(this.peerId) + " " +
"]";
}
}

View File

@ -78,4 +78,4 @@ public class PeersMessage extends Message {
}
return "Peers Message [\n " + sb.toString() + "]";
}
}
}

View File

@ -1,8 +1,11 @@
package org.ethereum.net.message;
import org.ethereum.core.Genesis;
import org.ethereum.crypto.HashUtil;
import org.spongycastle.util.encoders.Hex;
import static org.ethereum.config.SystemProperties.CONFIG;
/**
* www.ethereumJ.com
* User: Roman Mandeleil
@ -16,16 +19,15 @@ public class StaticMessages {
public static final byte[] GET_TRANSACTIONS = Hex.decode("2240089100000002C116");
public static final byte[] DISCONNECT_08 = Hex.decode("2240089100000003C20108");
public static final byte[] GENESIS_HASH = Hex.decode("c305511e7cb9b33767e50f5e94ecd7b1c51359a04f45183860ec6808d80b0d3f");
public static final byte[] GENESIS_HASH = (new Genesis()).getHash();
public static final byte[] MAGIC_PACKET = Hex.decode("22400891");
static {
byte[] peerIdBytes = HashUtil.randomPeerId();
HELLO_MESSAGE = new HelloMessage((byte)0x11, (byte)0x00, "EthereumJ [v0.5.1] by RomanJ ",
(byte)0b00000111, (short)30303, peerIdBytes);
HELLO_MESSAGE = new HelloMessage((byte) 0x11, (byte) 0x00,
CONFIG.clientName(), (byte) 0b00000111,
(short) 30303, peerIdBytes);
}
public static final HelloMessage HELLO_MESSAGE;
}

View File

@ -32,7 +32,7 @@ public class TransactionsMessage extends Message {
for (Transaction tx : transactionList){
byte[] txPayload = tx.getEncodedSigned();
byte[] txPayload = tx.getEncoded();
try {
baos.write(txPayload);
} catch (IOException e) {
@ -43,7 +43,7 @@ public class TransactionsMessage extends Message {
byte[][] elements = new byte[transactionList.size() + 1][];
elements[0] = new byte[]{Command.TRANSACTIONS.asByte()};
for (int i = 0; i < transactionList.size(); ++i){
elements[i + 1] = transactionList.get(i).getEncodedSigned();
elements[i + 1] = transactionList.get(i).getEncoded();
}
payload = RLP.encodeList(elements);
@ -84,8 +84,8 @@ public class TransactionsMessage extends Message {
public String toString() {
if(!parsed) parseRLP();
StringBuffer sb = new StringBuffer();
for (Transaction transactionData : transactions){
sb.append(" ").append(transactionData).append("\n");
for (Transaction transaction : transactions){
sb.append(" ").append(transaction).append("\n");
}
return "Transactions Message [\n" + sb.toString() + " ]";
}

View File

@ -1,13 +1,11 @@
package org.ethereum.net.peerdiscovery;
import org.ethereum.config.SystemProperties;
import org.ethereum.net.client.PeerData;
import java.util.List;
import java.util.concurrent.*;
import static org.ethereum.config.SystemProperties.config;
import static org.ethereum.config.SystemProperties.CONFIG;
/**
* www.ethereumJ.com
@ -39,7 +37,7 @@ public class PeerDiscovery {
//creating the ThreadPoolExecutor
executorPool = new ThreadPoolExecutor(1, 1000, 10, TimeUnit.SECONDS,
new ArrayBlockingQueue<Runnable>(config.peerDiscoveryWorkers()), threadFactory, rejectionHandler);
new ArrayBlockingQueue<Runnable>(CONFIG.peerDiscoveryWorkers()), threadFactory, rejectionHandler);
//start the monitoring thread
monitor = new PeerDiscoveryMonitorThread(executorPool, 3);

View File

@ -5,18 +5,12 @@ import io.netty.channel.*;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioSocketChannel;
import io.netty.handler.timeout.ReadTimeoutHandler;
import org.ethereum.config.SystemProperties;
import org.ethereum.gui.PeerListener;
import org.ethereum.manager.MainData;
import org.ethereum.net.client.EthereumFrameDecoder;
import org.ethereum.net.client.PeerData;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import static org.ethereum.config.SystemProperties.config;
import static org.ethereum.config.SystemProperties.CONFIG;
/**
* www.ethereumJ.com
@ -59,9 +53,8 @@ public class PeerTaster {
}
});
// Start the client.
b.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, config.peerDiscoveryTimeout());
b.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, CONFIG.peerDiscoveryTimeout());
ChannelFuture f = b.connect(host, port).sync(); // (5)
// Wait until the connection is closed.

View File

@ -1,18 +1,11 @@
package org.ethereum.serpent;
import org.antlr.mojo.antlr4.Antlr4ErrorLog;
import org.antlr.mojo.antlr4.Antlr4Mojo;
import java.io.File;
import org.antlr.v4.Tool;
import org.antlr.v4.codegen.CodeGenerator;
import org.antlr.v4.tool.Grammar;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import java.io.*;
import java.net.URI;
import java.util.HashMap;
import java.util.Map;
/**
* www.ethereumJ.com
* User: Roman Mandeleil
@ -20,27 +13,19 @@ import java.util.Map;
*/
public class ParserGenerator {
public static void main(String args[]) throws MojoFailureException, MojoExecutionException {
String userDir = System.getProperty("user.dir");
String grammarName = userDir + "\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g4";
File inputDir = new File(userDir + "\\src\\main\\java\\org\\ethereum\\serpent\\");
String options[] = {grammarName, "-visitor", "-package", "org.ethereum.serpent"};
Tool tool = new Tool(options);
tool.outputDirectory = userDir + "\\src\\main\\java\\org\\ethereum\\serpent\\";
tool.processGrammarsOnCommandLine();
// org.antlr.Tool.main(new String[]{userDir + "\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g4"});
// org.antlr.Tool.main(new String[]{userDir + "\\src\\main\\java\\samples\\antlr\\PyEsque.g"});

View File

@ -3,17 +3,10 @@ package org.ethereum.util;
import java.math.BigInteger;
import java.util.Arrays;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.spongycastle.util.encoders.Hex;
import com.google.common.primitives.UnsignedInteger;
import com.google.common.primitives.UnsignedLongs;
public class ByteUtil {
private static Logger logger = LoggerFactory.getLogger("ByteUtil");
/**
* Creates a copy of bytes and appends b to the end of it
*/
@ -43,57 +36,11 @@ public class ByteUtil {
return bytes;
}
public static byte[] hexStringToByteArr(String hexString){
String hexSymbols = "0123456789ABCDEF";
int arrSize = (int) (hexString.length() / 3);
byte[] result = new byte[arrSize];
for (int i = 0; i < arrSize; ++i){
int digit1 = hexSymbols.indexOf( hexString.charAt(i * 3) );
int digit2 = hexSymbols.indexOf( hexString.charAt(i * 3 + 1) );
result[i] = (byte) (digit1 * 16 + digit2);
}
return result;
}
public static String toHexString(byte[] data){
if (data == null) return "null";
else return Hex.toHexString(data);
}
public static void printHexStringForByte(byte data){
System.out.print("[");
String hexNum = Integer.toHexString ((int) data & 0xFF);
if (((int) data & 0xFF) < 16) {
hexNum = "0" + hexNum;
}
System.out.print( hexNum );
System.out.print("]");
System.out.println();
}
public static void printHexStringForByteArray(byte[] data){
if (logger.isInfoEnabled()) {
logger.info("[");
for (int i = 0; i < data.length; ++i) {
String hexNum = Integer.toHexString((int) data[i] & 0xFF);
if (((int) data[i] & 0xFF) < 16) {
hexNum = "0" + hexNum;
}
logger.info(hexNum);
logger.info(" ");
}
logger.info("]");
logger.info("");
}
}
// The packet size should be 4 byte long
public static byte[] calcPacketSize(byte[] packet){
@ -135,38 +82,4 @@ public class ByteUtil {
return 0;
return new BigInteger(1, b).intValue();
}
public static byte[] encodeInt(int value) {
if (isLessThanUnsigned(value, 253)) {
return new byte[]{(byte) value};
} else if (isLessThanUnsigned(value, 65536)) {
return new byte[]{(byte) 253, (byte) (value), (byte) (value >> 8)};
} else if (isLessThanUnsigned(value, UnsignedInteger.MAX_VALUE.longValue())) {
byte[] bytes = new byte[5];
bytes[0] = (byte) 254;
uint32ToByteArrayLE(value, bytes, 1);
return bytes;
} else {
byte[] bytes = new byte[9];
bytes[0] = (byte) 255;
uint32ToByteArrayLE(value, bytes, 1);
uint32ToByteArrayLE(value >>> 32, bytes, 5);
return bytes;
}
}
/**
* Work around lack of unsigned types in Java.
*/
public static boolean isLessThanUnsigned(long n1, long n2) {
return UnsignedLongs.compare(n1, n2) < 0;
}
public static void uint32ToByteArrayLE(long val, byte[] out, int offset) {
out[offset + 0] = (byte) (0xFF & (val >> 0));
out[offset + 1] = (byte) (0xFF & (val >> 8));
out[offset + 2] = (byte) (0xFF & (val >> 16));
out[offset + 3] = (byte) (0xFF & (val >> 24));
}
}

View File

@ -2,8 +2,6 @@ package org.ethereum.util;
import java.util.ArrayList;
import org.spongycastle.util.encoders.Hex;
/**
* www.ethereumJ.com
* User: Roman Mandeleil

View File

@ -2,7 +2,7 @@
#***
# Starting to gather some properties the system going to support
#***
client.name=EthereumJ [v0.5.1] by RomanJ
# if the system will work as a server also
# accept for incoming connections [true/false]

View File

@ -9,8 +9,8 @@ import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import org.ethereum.crypto.ECKey;
import org.ethereum.crypto.ECKey.MissingPrivateKeyException;
import org.ethereum.crypto.HashUtil;
import org.ethereum.util.ByteUtil;
import org.junit.Assert;
import org.junit.Test;
import org.spongycastle.util.BigIntegers;
@ -18,10 +18,6 @@ import org.spongycastle.util.encoders.Hex;
public class TransactionTest {
private static String RLP_ENCODED_RAW_TX = "ed808b00d3c21bcecceda10000009479b08ad8787060333663d19704909ee7b1903e588609184e72a00082425580";
private static String HASH_RAW_TX = "c957fce141839221403b51d26a5de186db2dabe0de4ac48f3f6718bfeb7c5f47";
private static String RLP_ENCODED_SIGNED_TX = "f870808b00d3c21bcecceda10000009479b08ad8787060333663d19704909ee7b1903e588609184e72a000824255801ca08e7dfa371b0acde61f894f1969f1f17696b86492a8572c60154e85d7801a4a08a0229807de94c4cfa63d978ff22f764cd9e6abd1bae1bcdba4aa4ae299ad0a8a9f";
@Test /* sign transaction https://tools.ietf.org/html/rfc6979 */
public void test1() throws NoSuchProviderException, NoSuchAlgorithmException, InvalidKeyException, IOException {
@ -69,13 +65,13 @@ public class TransactionTest {
System.out.println("r\t\t\t: " + Hex.toHexString(BigIntegers.asUnsignedByteArray(tx.getSignature().r)));
System.out.println("s\t\t\t: " + Hex.toHexString(BigIntegers.asUnsignedByteArray(tx.getSignature().s)));
System.out.println("RLP encoded tx\t\t: " + Hex.toHexString( tx.getEncodedSigned() ));
System.out.println("RLP encoded tx\t\t: " + Hex.toHexString( tx.getEncoded() ));
// retrieve the signer/sender of the transaction
ECKey key = ECKey.signatureToKey(tx.getHash(), tx.getSignature().toBase64());
System.out.println("Tx unsigned RLP\t\t: " + Hex.toHexString( tx.getEncoded()));
System.out.println("Tx signed RLP\t\t: " + Hex.toHexString( tx.getEncodedSigned() ));
System.out.println("Tx unsigned RLP\t\t: " + Hex.toHexString( tx.getEncodedRaw()));
System.out.println("Tx signed RLP\t\t: " + Hex.toHexString( tx.getEncoded() ));
System.out.println("Signature public key\t: " + Hex.toHexString(key.getPubKey()));
System.out.println("Sender is\t\t: " + Hex.toHexString(key.getAddress()));
@ -93,20 +89,16 @@ public class TransactionTest {
// cat --> 79b08ad8787060333663d19704909ee7b1903e58
// cow --> cd2a3d9f938e13cd947ec05abc7fe734df8dd826
ECKey ecKey = ECKey.fromPrivate(HashUtil.sha3("cat".getBytes()));
byte[] senderPrivKey = HashUtil.sha3("cow".getBytes());
byte[] nonce = { 0x01 };
byte[] gasPrice = Hex.decode("09184e72a000");
byte[] gasLimit = Hex.decode("4255");
BigInteger value = new BigInteger("1000000000000000000000000");
byte[] nonce = {01};
byte[] privKey = HashUtil.sha3("cat".getBytes());
ECKey ecKey = ECKey.fromPrivate(privKey);
byte[] senderPrivKey = HashUtil.sha3("cow".getBytes());
byte[] gasPrice= Hex.decode("09184e72a000");
byte[] gas = Hex.decode("4255");
Transaction tx = new Transaction(null, gasPrice, gas,
ecKey.getAddress(), value.toByteArray(), null);
Transaction tx = new Transaction(nonce, gasPrice, gasLimit,
ecKey.getAddress(), value.toByteArray(), null);
tx.sign(senderPrivKey);
@ -114,13 +106,13 @@ public class TransactionTest {
System.out.println("r\t\t\t: " + Hex.toHexString(BigIntegers.asUnsignedByteArray(tx.getSignature().r)));
System.out.println("s\t\t\t: " + Hex.toHexString(BigIntegers.asUnsignedByteArray(tx.getSignature().s)));
System.out.println("RLP encoded tx\t\t: " + Hex.toHexString( tx.getEncodedSigned() ));
System.out.println("RLP encoded tx\t\t: " + Hex.toHexString( tx.getEncoded() ));
// retrieve the signer/sender of the transaction
ECKey key = ECKey.signatureToKey(tx.getHash(), tx.getSignature().toBase64());
System.out.println("Tx unsigned RLP\t\t: " + Hex.toHexString( tx.getEncoded()));
System.out.println("Tx signed RLP\t\t: " + Hex.toHexString( tx.getEncodedSigned() ));
System.out.println("Tx unsigned RLP\t\t: " + Hex.toHexString( tx.getEncodedRaw()));
System.out.println("Tx signed RLP\t\t: " + Hex.toHexString( tx.getEncoded() ));
System.out.println("Signature public key\t: " + Hex.toHexString(key.getPubKey()));
System.out.println("Sender is\t\t: " + Hex.toHexString(key.getAddress()));
@ -129,46 +121,89 @@ public class TransactionTest {
Hex.toHexString(key.getAddress()));
}
// Testdata from: https://github.com/ethereum/tests/blob/master/txtest.json
String RLP_ENCODED_RAW_TX = "e88085e8d4a510008227109413978aee95f38490e9769c39b2773ed763d9cd5f872386f26fc1000080";
String RLP_ENCODED_UNSIGNED_TX = "eb8085e8d4a510008227109413978aee95f38490e9769c39b2773ed763d9cd5f872386f26fc1000080808080";
String HASH_TX = "328ea6d24659dec48adea1aced9a136e5ebdf40258db30d1b1d97ed2b74be34e";
String RLP_ENCODED_SIGNED_TX = "f86b8085e8d4a510008227109413978aee95f38490e9769c39b2773ed763d9cd5f872386f26fc10000801ba0eab47c1a49bf2fe5d40e01d313900e19ca485867d462fe06e139e3a536c6d4f4a014a569d327dcda4b29f74f93c0e9729d2f49ad726e703f9cd90dbb0fbf6649f1";
String KEY = "c85ef7d79691fe79573b1a7064c19c1a9819ebdbd1faaab1a8ec92344438aaf4";
byte[] testNonce = Hex.decode("");
byte[] testGasPrice = BigIntegers.asUnsignedByteArray(BigInteger.valueOf(1000000000000L));;
byte[] testGasLimit = BigIntegers.asUnsignedByteArray(BigInteger.valueOf(10000));;
byte[] testReceiveAddress = Hex.decode("13978aee95f38490e9769c39b2773ed763d9cd5f");
byte[] testValue = BigIntegers.asUnsignedByteArray(BigInteger.valueOf(10000000000000000L));
byte[] testData = Hex.decode("");
byte[] testInit = Hex.decode("");
@Test
public void testTransactionFromRLP() {
// from RLP encoding
fail("Double check the expected values, they don't seem to be parsed in the right order.");
byte[] encodedTxBytes = Hex.decode(RLP_ENCODED_SIGNED_TX);
Transaction tx = new Transaction(encodedTxBytes);
assertNull(tx.getNonce());
assertEquals(BigInteger.valueOf(16981), new BigInteger(tx.getValue()));
assertEquals("09184e72a000", ByteUtil.toHexString(tx.getReceiveAddress()));
assertEquals("00d3c21bcecceda1000000", ByteUtil.toHexString(tx.getGasPrice()));
assertEquals("79b08ad8787060333663d19704909ee7b1903e58", ByteUtil.toHexString(tx.getGasLimit()));
assertNull(tx.getData());
assertNull(tx.getInit());
assertEquals(28, tx.getSignature().v);
assertEquals("8e7dfa371b0acde61f894f1969f1f17696b86492a8572c60154e85d7801a4a08", Hex.toHexString(BigIntegers.asUnsignedByteArray(tx.getSignature().r)));
assertEquals("229807de94c4cfa63d978ff22f764cd9e6abd1bae1bcdba4aa4ae299ad0a8a9f", Hex.toHexString(BigIntegers.asUnsignedByteArray(tx.getSignature().s)));
public void testTransactionFromSignedRLP() throws Exception {
Transaction txSigned = new Transaction(Hex.decode(RLP_ENCODED_SIGNED_TX));
assertEquals(HASH_RAW_TX, ByteUtil.toHexString(tx.getHash()));
assertEquals(RLP_ENCODED_RAW_TX, ByteUtil.toHexString(tx.getEncoded()));
assertEquals(RLP_ENCODED_SIGNED_TX, ByteUtil.toHexString(tx.getEncodedSigned()));
assertEquals(HASH_TX, Hex.toHexString(txSigned.getHash()));
assertEquals(RLP_ENCODED_SIGNED_TX, Hex.toHexString(txSigned.getEncoded()));
assertNull(txSigned.getNonce());
assertEquals(new BigInteger(1, testGasPrice), new BigInteger(1, txSigned.getGasPrice()));
assertEquals(new BigInteger(1, testGasLimit), new BigInteger(1, txSigned.getGasLimit()));
assertEquals(Hex.toHexString(testReceiveAddress), Hex.toHexString(txSigned.getReceiveAddress()));
assertEquals(new BigInteger(1, testValue), new BigInteger(1, txSigned.getValue()));
assertNull(txSigned.getData());
assertNull(txSigned.getInit());
assertEquals(27, txSigned.getSignature().v);
assertEquals("eab47c1a49bf2fe5d40e01d313900e19ca485867d462fe06e139e3a536c6d4f4", Hex.toHexString(BigIntegers.asUnsignedByteArray(txSigned.getSignature().r)));
assertEquals("14a569d327dcda4b29f74f93c0e9729d2f49ad726e703f9cd90dbb0fbf6649f1", Hex.toHexString(BigIntegers.asUnsignedByteArray(txSigned.getSignature().s)));
}
@Test
public void testTransactionFromUnsignedRLP() throws Exception {
Transaction txUnsigned = new Transaction(Hex.decode(RLP_ENCODED_UNSIGNED_TX));
assertEquals(HASH_TX, Hex.toHexString(txUnsigned.getHash()));
assertEquals(RLP_ENCODED_UNSIGNED_TX, Hex.toHexString(txUnsigned.getEncoded()));
txUnsigned.sign(Hex.decode(KEY));
assertEquals(RLP_ENCODED_SIGNED_TX, Hex.toHexString(txUnsigned.getEncoded()));
assertNull(txUnsigned.getNonce());
assertEquals(new BigInteger(1, testGasPrice), new BigInteger(1, txUnsigned.getGasPrice()));
assertEquals(new BigInteger(1, testGasLimit), new BigInteger(1, txUnsigned.getGasLimit()));
assertEquals(Hex.toHexString(testReceiveAddress), Hex.toHexString(txUnsigned.getReceiveAddress()));
assertEquals(new BigInteger(1, testValue), new BigInteger(1, txUnsigned.getValue()));
assertNull(txUnsigned.getData());
assertNull(txUnsigned.getInit());
assertEquals(27, txUnsigned.getSignature().v);
assertEquals("eab47c1a49bf2fe5d40e01d313900e19ca485867d462fe06e139e3a536c6d4f4", Hex.toHexString(BigIntegers.asUnsignedByteArray(txUnsigned.getSignature().r)));
assertEquals("14a569d327dcda4b29f74f93c0e9729d2f49ad726e703f9cd90dbb0fbf6649f1", Hex.toHexString(BigIntegers.asUnsignedByteArray(txUnsigned.getSignature().s)));
}
@Test
public void testTransactionFromNew1() throws MissingPrivateKeyException {
Transaction txNew = new Transaction(testNonce, testGasPrice, testGasLimit, testReceiveAddress, testValue, testData);
assertEquals("", Hex.toHexString(txNew.getNonce()));
assertEquals(new BigInteger(1, testGasPrice), new BigInteger(1, txNew.getGasPrice()));
assertEquals(new BigInteger(1, testGasLimit), new BigInteger(1, txNew.getGasLimit()));
assertEquals(Hex.toHexString(testReceiveAddress), Hex.toHexString(txNew.getReceiveAddress()));
assertEquals(new BigInteger(1, testValue), new BigInteger(1, txNew.getValue()));
assertEquals("", Hex.toHexString(txNew.getData()));
assertNull(txNew.getInit());
assertNull(txNew.getSignature());
assertEquals(RLP_ENCODED_RAW_TX, Hex.toHexString(txNew.getEncodedRaw()));
assertEquals(HASH_TX, Hex.toHexString(txNew.getHash()));
assertEquals(RLP_ENCODED_UNSIGNED_TX, Hex.toHexString(txNew.getEncoded()));
txNew.sign(Hex.decode(KEY));
assertEquals(RLP_ENCODED_SIGNED_TX, Hex.toHexString(txNew.getEncoded()));
assertEquals(27, txNew.getSignature().v);
assertEquals("eab47c1a49bf2fe5d40e01d313900e19ca485867d462fe06e139e3a536c6d4f4", Hex.toHexString(BigIntegers.asUnsignedByteArray(txNew.getSignature().r)));
assertEquals("14a569d327dcda4b29f74f93c0e9729d2f49ad726e703f9cd90dbb0fbf6649f1", Hex.toHexString(BigIntegers.asUnsignedByteArray(txNew.getSignature().s)));
}
@Test
public void testTransactionFromRLP2() {
byte[] encodedTxBytes = Hex.decode("f86f81018609184e72a0008242559479b08ad8787060333663d19704909ee7b1903e58893635c9adc5dea00000801ba056f49cb76f7daadd0e7eb523a8c942a2b510f450185c93a3e2e51a749642f0efa03374f71fa8855212d8c369be6ced2801a8a7b6d7cea3a578623ad34feceef12f");
Transaction tx = new Transaction(encodedTxBytes);
System.out.println(Hex.toHexString( tx.sender() ));
System.out.println(Hex.toHexString( tx.getHash() ));
System.out.println(Hex.toHexString( tx.getEncoded() ));
}
@Test
public void testTransactionFromNew() throws Exception {
public void testTransactionFromNew2() throws MissingPrivateKeyException {
byte[] privKeyBytes = Hex.decode("c85ef7d79691fe79573b1a7064c19c1a9819ebdbd1faaab1a8ec92344438aaf4");
String RLP_TX_UNSIGNED = "e88085e8d4a510008227109413978aee95f38490e9769c39b2773ed763d9cd5f872386f26fc1000080";
String RLP_TX_UNSIGNED = "eb8085e8d4a510008227109413978aee95f38490e9769c39b2773ed763d9cd5f872386f26fc1000080808080";
String RLP_TX_SIGNED = "f86b8085e8d4a510008227109413978aee95f38490e9769c39b2773ed763d9cd5f872386f26fc10000801ba0eab47c1a49bf2fe5d40e01d313900e19ca485867d462fe06e139e3a536c6d4f4a014a569d327dcda4b29f74f93c0e9729d2f49ad726e703f9cd90dbb0fbf6649f1";
String HASH_TX_UNSIGNED = "328ea6d24659dec48adea1aced9a136e5ebdf40258db30d1b1d97ed2b74be34e";
@ -188,7 +223,7 @@ public class TransactionTest {
// Testing signed
tx.sign(privKeyBytes);
String encodedSigned = Hex.toHexString(tx.getEncodedSigned());
String encodedSigned = Hex.toHexString(tx.getEncoded());
assertEquals(RLP_TX_SIGNED, encodedSigned);
assertEquals(HASH_TX_UNSIGNED, Hex.toHexString(tx.getHash()));
}

View File

@ -40,7 +40,7 @@ public class ECKeyTest {
@Test
public void testHashCode() {
fail("Not yet implemented");
assertEquals(1866897155, ECKey.fromPrivate(privateKey).hashCode());
}
@Test

View File

@ -48,7 +48,6 @@ public class MessagesTest {
helloMessage.parseRLP();
System.out.println(helloMessage);
assertEquals(12, helloMessage.getProtocolVersion());
assertEquals(0, helloMessage.getNetworkId());
assertEquals("Ethereum(++)/ZeroGox/v0.5.1/ncurses/Linux/g++", helloMessage.getClientId());
@ -60,7 +59,7 @@ public class MessagesTest {
}
@Test /* HelloMessage 2 */
public void test_2(){
public void test_2() {
String helloMessageRaw = "F87F800B80B5457468657265756D282B2B292F76302E342E332F4554485F4255494C445F545950452F4554485F4255494C445F504C4154464F524D0782765FB840E02B18FBA6B887FB9258469C3AF8E445CC9AE2B5386CAC5F60C4170F822086224E3876555C745A7EC8AC181C7F9701776D94A779604EA12651DE5F4A748D29E1";
byte[] payload = Hex.decode(helloMessageRaw);
@ -179,11 +178,14 @@ public class MessagesTest {
/* TRANSACTIONS */
@Test /* Transactions message 1 */
public void test_8(){
public void test_8() {
String transactionsPacketRaw = "F86E12F86B04881BC16D674EC8000094CD2A3D9F938E13CD947EC05ABC7FE734DF8DD8268609184E72A00064801BA05E3868194605F1647593B842725818CCFA6A38651A728715133A8E97CDCFAC54A00FF91628D04B215EBCCFD5F4FC34CC1B45DF32F6B4609FBB0DE42E8522264467";
byte[] payload = Hex.decode(transactionsPacketRaw);
String txsPacketRaw = "f86e12f86b04648609184e72a00094cd2a3d9f938e13cd947ec05abc7fe734df8dd826"
+ "881bc16d674ec80000801ba05c89ebf2b77eeab88251e553f6f9d53badc1d800"
+ "bbac02d830801c2aa94a4c9fa00b7907532b1f29c79942b75fff98822293bf5f"
+ "daa3653a8d9f424c6a3265f06c";
byte[] payload = Hex.decode(txsPacketRaw);
RLPList rlpList = RLP.decode2(payload);
TransactionsMessage transactionsMessage = new TransactionsMessage(rlpList);
@ -191,49 +193,45 @@ public class MessagesTest {
assertEquals(1, transactionsMessage.getTransactions().size());
Transaction tx =
transactionsMessage.getTransactions().get(0);
Transaction tx = transactionsMessage.getTransactions().get(0);
assertEquals("558A3797E0DD3FBFAF761F1ADD6749C7D5DB313FDAC5CBA59F40E28AF7BBACD1",
Hex.toHexString( tx.getHash() ).toUpperCase());
assertEquals("04",
Hex.toHexString( tx.getNonce() ).toUpperCase());
assertEquals("1BC16D674EC80000",
Hex.toHexString( tx.getValue() ).toUpperCase());
assertEquals("CD2A3D9F938E13CD947EC05ABC7FE734DF8DD826",
Hex.toHexString( tx.getReceiveAddress() ).toUpperCase());
assertEquals("09184E72A000",
Hex.toHexString( tx.getGasPrice() ).toUpperCase());
assertEquals("64",
Hex.toHexString( tx.getGasLimit() ).toUpperCase());
assertEquals("NULL",
Hex.toHexString( tx.getData() ).toUpperCase());
assertEquals("NULL",
Hex.toHexString( tx.getInit() ).toUpperCase());
assertEquals("1B",
Hex.toHexString( new byte[] {tx.getSignature().v} ).toUpperCase());
assertEquals("5E3868194605F1647593B842725818CCFA6A38651A728715133A8E97CDCFAC54",
Hex.toHexString( tx.getSignature().r.toByteArray() ).toUpperCase());
assertEquals("0FF91628D04B215EBCCFD5F4FC34CC1B45DF32F6B4609FBB0DE42E8522264467",
Hex.toHexString( tx.getSignature().s.toByteArray() ).toUpperCase());
assertEquals("5d2aee0490a9228024158433d650335116b4af5a30b8abb10e9b7f9f7e090fd8", Hex.toHexString(tx.getHash()));
assertEquals("04", Hex.toHexString(tx.getNonce()));
assertEquals("1bc16d674ec80000", Hex.toHexString(tx.getValue()));
assertEquals("cd2a3d9f938e13cd947ec05abc7fe734df8dd826", Hex.toHexString(tx.getReceiveAddress()));
assertEquals("64", Hex.toHexString(tx.getGasPrice()));
assertEquals("09184e72a000", Hex.toHexString(tx.getGasLimit()));
assertEquals("null", ByteUtil.toHexString(tx.getData()));
assertEquals("null", ByteUtil.toHexString(tx.getInit()));
assertEquals("1b", Hex.toHexString(new byte[] { tx.getSignature().v }));
assertEquals("5c89ebf2b77eeab88251e553f6f9d53badc1d800bbac02d830801c2aa94a4c9f", Hex.toHexString(tx.getSignature().r.toByteArray()));
assertEquals("0b7907532b1f29c79942b75fff98822293bf5fdaa3653a8d9f424c6a3265f06c", Hex.toHexString(tx.getSignature().s.toByteArray()));
}
@Test /* Transactions message 2 */
public void test_9(){
String transactionsPacketRaw = "F9025012F89D80809400000000000000000000000000000000000000008609184E72A000822710B3606956330C0D630000003359366000530A0D630000003359602060005301356000533557604060005301600054630000000C5884336069571CA07F6EB94576346488C6253197BDE6A7E59DDC36F2773672C849402AA9C402C3C4A06D254E662BF7450DD8D835160CBB053463FED0B53F2CDD7F3EA8731919C8E8CCF9010501809400000000000000000000000000000000000000008609184E72A000822710B85336630000002E59606956330C0D63000000155933FF33560D63000000275960003356576000335700630000005358600035560D630000003A590033560D63000000485960003356573360003557600035335700B84A7F4E616D65526567000000000000000000000000000000000000000000000000003057307F4E616D655265670000000000000000000000000000000000000000000000000057336069571BA04AF15A0EC494AEAC5B243C8A2690833FAA74C0F73DB1F439D521C49C381513E9A05802E64939BE5A1F9D4D614038FBD5479538C48795614EF9C551477ECBDB49D2F8A6028094CCDEAC59D35627B7DE09332E819D5159E7BB72508609184E72A000822710B84000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002D0ACEEE7E5AB874E22CCF8D1A649F59106D74E81BA0D05887574456C6DE8F7A0D172342C2CBDD4CF7AFE15D9DBB8B75B748BA6791C9A01E87172A861F6C37B5A9E3A5D0D7393152A7FBE41530E5BB8AC8F35433E5931B";
String txsPacketRaw = "f9025012f89d8080940000000000000000000000000000000000000000860918"
+ "4e72a000822710b3606956330c0d630000003359366000530a0d630000003359"
+ "602060005301356000533557604060005301600054630000000c588433606957"
+ "1ca07f6eb94576346488c6253197bde6a7e59ddc36f2773672c849402aa9c402"
+ "c3c4a06d254e662bf7450dd8d835160cbb053463fed0b53f2cdd7f3ea8731919"
+ "c8e8ccf901050180940000000000000000000000000000000000000000860918"
+ "4e72a000822710b85336630000002e59606956330c0d63000000155933ff3356"
+ "0d63000000275960003356576000335700630000005358600035560d63000000"
+ "3a590033560d63000000485960003356573360003557600035335700b84a7f4e"
+ "616d655265670000000000000000000000000000000000000000000000000030"
+ "57307f4e616d6552656700000000000000000000000000000000000000000000"
+ "00000057336069571ba04af15a0ec494aeac5b243c8a2690833faa74c0f73db1"
+ "f439d521c49c381513e9a05802e64939be5a1f9d4d614038fbd5479538c48795"
+ "614ef9c551477ecbdb49d2f8a6028094ccdeac59d35627b7de09332e819d5159"
+ "e7bb72508609184e72a000822710b84000000000000000000000000000000000"
+ "000000000000000000000000000000000000000000000000000000002d0aceee"
+ "7e5ab874e22ccf8d1a649f59106d74e81ba0d05887574456c6de8f7a0d172342"
+ "c2cbdd4cf7afe15d9dbb8b75b748ba6791c9a01e87172a861f6c37b5a9e3a5d0"
+ "d7393152a7fbe41530e5bb8ac8f35433e5931b";
byte[] payload = Hex.decode(transactionsPacketRaw);
byte[] payload = Hex.decode(txsPacketRaw);
RLPList rlpList = RLP.decode2(payload);
TransactionsMessage transactionsMessage = new TransactionsMessage(rlpList);
@ -244,73 +242,73 @@ public class MessagesTest {
Transaction tx =
transactionsMessage.getTransactions().get(0);
assertEquals("4B7D9670A92BF120D5B43400543B69304A14D767CF836A7F6ABFF4EDDE092895",
Hex.toHexString( tx.getHash() ).toUpperCase());
assertEquals("4b7d9670a92bf120d5b43400543b69304a14d767cf836a7f6abff4edde092895",
Hex.toHexString( tx.getHash() ));
assertEquals("null",
Hex.toHexString( tx.getNonce() ));
assertEquals("NULL",
Hex.toHexString( tx.getNonce() ).toUpperCase());
assertEquals("NULL",
Hex.toHexString( tx.getValue() ).toUpperCase());
Hex.toHexString( tx.getValue() ));
assertEquals("0000000000000000000000000000000000000000",
Hex.toHexString( tx.getReceiveAddress() ).toUpperCase());
Hex.toHexString( tx.getReceiveAddress() ));
assertEquals("09184E72A000",
Hex.toHexString( tx.getGasPrice() ).toUpperCase());
assertEquals("09184e72a000",
Hex.toHexString( tx.getGasPrice() ));
assertEquals("2710",
Hex.toHexString( tx.getGasLimit() ).toUpperCase());
Hex.toHexString( tx.getGasLimit() ));
assertEquals("606956330C0D630000003359366000530A0D630000003359602060005301356000533557604060005301600054630000000C58",
Hex.toHexString( tx.getData() ).toUpperCase());
assertEquals("606956330c0d630000003359366000530a0d630000003359602060005301356000533557604060005301600054630000000c58",
Hex.toHexString( tx.getData() ));
assertEquals("33606957",
Hex.toHexString( tx.getInit() ).toUpperCase());
Hex.toHexString( tx.getInit() ));
assertEquals("1C",
Hex.toHexString( new byte[] {tx.getSignature().v} ).toUpperCase());
assertEquals("1c",
Hex.toHexString( new byte[] {tx.getSignature().v} ));
assertEquals("7F6EB94576346488C6253197BDE6A7E59DDC36F2773672C849402AA9C402C3C4",
Hex.toHexString( tx.getSignature().r.toByteArray() ).toUpperCase());
assertEquals("7f6eb94576346488c6253197bde6a7e59ddc36f2773672c849402aa9c402c3c4",
Hex.toHexString( tx.getSignature().r.toByteArray() ));
assertEquals("6D254E662BF7450DD8D835160CBB053463FED0B53F2CDD7F3EA8731919C8E8CC",
Hex.toHexString( tx.getSignature().s.toByteArray() ).toUpperCase());
assertEquals("6d254e662bf7450dd8d835160cbb053463fed0b53f2cdd7f3ea8731919c8e8cc",
Hex.toHexString( tx.getSignature().s.toByteArray() ));
tx = transactionsMessage.getTransactions().get(2);
assertEquals("B0251A1BB20B44459DB5B5444AB53EDD9E12C46D0BA07FA401A797BEB967D53C",
Hex.toHexString( tx.getHash() ).toUpperCase());
assertEquals("b0251a1bb20b44459db5b5444ab53edd9e12c46d0ba07fa401a797beb967d53c",
Hex.toHexString( tx.getHash() ));
assertEquals("02",
Hex.toHexString( tx.getNonce() ).toUpperCase());
Hex.toHexString( tx.getNonce() ));
assertEquals("NULL",
Hex.toHexString( tx.getValue() ).toUpperCase());
assertEquals("null",
Hex.toHexString( tx.getValue() ));
assertEquals("CCDEAC59D35627B7DE09332E819D5159E7BB7250",
Hex.toHexString( tx.getReceiveAddress() ).toUpperCase());
assertEquals("ccdeac59d35627b7de09332e819d5159e7bb7250",
Hex.toHexString( tx.getReceiveAddress() ));
assertEquals("09184E72A000",
Hex.toHexString( tx.getGasPrice() ).toUpperCase());
assertEquals("09184e72a000",
Hex.toHexString( tx.getGasPrice() ));
assertEquals("2710",
Hex.toHexString( tx.getGasLimit() ).toUpperCase());
Hex.toHexString( tx.getGasLimit() ));
assertEquals("00000000000000000000000000000000000000000000000000000000000000000000000000000000000000002D0ACEEE7E5AB874E22CCF8D1A649F59106D74E8",
Hex.toHexString( tx.getData() ).toUpperCase());
assertEquals("00000000000000000000000000000000000000000000000000000000000000000000000000000000000000002d0aceee7e5ab874e22ccf8d1a649f59106d74e8",
Hex.toHexString( tx.getData() ));
assertEquals("NULL",
Hex.toHexString( tx.getInit() ).toUpperCase());
assertEquals("null",
Hex.toHexString( tx.getInit() ));
assertEquals("1B",
Hex.toHexString( new byte[] {tx.getSignature().v} ).toUpperCase());
assertEquals("1b",
Hex.toHexString( new byte[] {tx.getSignature().v} ));
assertEquals("D05887574456C6DE8F7A0D172342C2CBDD4CF7AFE15D9DBB8B75B748BA6791C9",
Hex.toHexString( tx.getSignature().r.toByteArray() ).toUpperCase());
assertEquals("d05887574456c6de8f7a0d172342c2cbdd4cf7afe15d9dbb8b75b748ba6791c9",
Hex.toHexString( tx.getSignature().r.toByteArray() ));
assertEquals("1E87172A861F6C37B5A9E3A5D0D7393152A7FBE41530E5BB8AC8F35433E5931B",
Hex.toHexString(tx.getSignature().s.toByteArray()).toUpperCase());
assertEquals("1e87172a861f6c37b5a9e3a5d0d7393152a7fbe41530e5bb8ac8f35433e5931b",
Hex.toHexString(tx.getSignature().s.toByteArray()));
}
/* BLOCKS */
@ -534,7 +532,7 @@ public class MessagesTest {
ecKey.getAddress(), gasPrice, gas, null);
tx.sign(privKey);
tx.getEncodedSigned();
tx.getEncoded();
List<Transaction> txList = new ArrayList<Transaction>();
txList.add(tx);

View File

@ -737,7 +737,6 @@ public class SerpentCompileTest {
Assert.assertEquals(expected, result);
}
@Test // if elif else test 13
public void test28(){
@ -775,7 +774,6 @@ public class SerpentCompileTest {
Assert.assertEquals(expected, result);
}
@Test // if elif else test 14
public void test29(){
@ -913,7 +911,6 @@ public class SerpentCompileTest {
Assert.fail("Should be indent error thrown");
}
@Test // if elif else test 19
public void test34(){
@ -957,8 +954,6 @@ public class SerpentCompileTest {
Assert.assertEquals(expected, result);
}
@Test // if elif else test 20
public void test35(){
@ -1003,7 +998,6 @@ public class SerpentCompileTest {
Assert.assertEquals(expected, result);
}
@Test // while test 1
public void test36(){
@ -1075,7 +1069,6 @@ public class SerpentCompileTest {
Assert.assertEquals(expected, result);
}
@Test // while test 3
public void test38(){
@ -1218,11 +1211,8 @@ public class SerpentCompileTest {
Assert.assertEquals(expected, result);
}
/*
*
a = msg.datasize
b = msg.sender
c = msg.value

View File

@ -33,7 +33,7 @@ public class RLPTest {
"E0 DE 49 98 33 4F 3B CF 73 FA 11 7E F2 13 F8 74 " +
"17 08 9F EA F8 4C 21 B0";
byte[] payload = ByteUtil.hexStringToByteArr(peersPacket);
byte[] payload = Hex.decode(peersPacket);
byte[] ip = RLP.decodeIP4Bytes(payload, 5);
@ -50,7 +50,7 @@ public class RLPTest {
"E0 DE 49 98 33 4F 3B CF 73 FA 11 7E F2 13 F8 74 " +
"17 08 9F EA F8 4C 21 B0";
byte[] payload = ByteUtil.hexStringToByteArr(peersPacket);
byte[] payload = Hex.decode(peersPacket);
int oneInt = RLP.decodeInt(payload, 11);
assertEquals(oneInt, 30303);
@ -71,7 +71,7 @@ public class RLPTest {
"98 33 4F 3B CF 73 FA 11 7E F2 13 F8 74 17 08 9F " +
"EA F8 4C 21 B0 ";
byte[] payload = ByteUtil.hexStringToByteArr(peersPacket);
byte[] payload = Hex.decode(peersPacket);
int nextIndex = 5;
byte[] ip = RLP.decodeIP4Bytes(payload, nextIndex);
@ -212,17 +212,14 @@ public class RLPTest {
@Test /** encode byte array */
public void test8(){
String byteArr = "CE 73 66 0A 06 62 6C 1B 3F DA 7B 18 EF 7B A3 CE " +
"17 B6 BF 60 4F 95 41 D3 C6 C6 54 B7 AE 88 B2 39 " +
"40 7F 65 9C 78 F4 19 02 5D 78 57 27 ED 01 7B 6A " +
"DD 21 95 2D 7E 12 00 73 73 E3 21 DB C3 18 24 BA ";
String byteArr = "ce73660a06626c1b3fda7b18ef7ba3ce17b6bf604f9541d3c6c654b7ae88b239"
+ "407f659c78f419025d785727ed017b6add21952d7e12007373e321dbc31824ba";
byte[] byteArray = ByteUtil.hexStringToByteArr(byteArr);
byte[] byteArray = Hex.decode(byteArr);
String expected = "B8 40 " + byteArr;
String expected = "b840" + byteArr;
assertArrayEquals(ByteUtil.hexStringToByteArr(expected),
RLP.encodeElement(byteArray));
assertEquals(expected, Hex.toHexString(RLP.encodeElement(byteArray)));
}
@Test /** encode list */
@ -717,9 +714,4 @@ public class RLPTest {
oos.close();
return baos.size();
}
}

View File

@ -1,6 +1,5 @@
package org.ethereum.util;
import junit.framework.Assert;
import org.junit.Test;
import org.spongycastle.util.encoders.Hex;