Merge pull request #12 from nicksavers/master
Small fix Transaction.getSender() / update Log-version / removed imports
This commit is contained in:
commit
6e1862c317
|
@ -9,7 +9,6 @@
|
||||||
<url>http://www.ethereumj.org</url>
|
<url>http://www.ethereumj.org</url>
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
|
|
||||||
* To deploy all the classes and dependencies to one jar,
|
* To deploy all the classes and dependencies to one jar,
|
||||||
* that's one option to pack stand alone.
|
* that's one option to pack stand alone.
|
||||||
mvn clean package dependency:copy-dependencies -Dmaven.test.skip=true
|
mvn clean package dependency:copy-dependencies -Dmaven.test.skip=true
|
||||||
|
@ -100,7 +99,7 @@ mvn clean package -Dmaven.test.skip=true
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.slf4j</groupId>
|
<groupId>org.slf4j</groupId>
|
||||||
<artifactId>slf4j-api</artifactId>
|
<artifactId>slf4j-api</artifactId>
|
||||||
<version>1.7.7</version>
|
<version>${slf4j.version}</version>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
@ -109,7 +108,7 @@ mvn clean package -Dmaven.test.skip=true
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.slf4j</groupId>
|
<groupId>org.slf4j</groupId>
|
||||||
<artifactId>jcl-over-slf4j</artifactId>
|
<artifactId>jcl-over-slf4j</artifactId>
|
||||||
<version>1.5.6</version>
|
<version>${slf4j.version}</version>
|
||||||
<scope>runtime</scope>
|
<scope>runtime</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
@ -118,7 +117,7 @@ mvn clean package -Dmaven.test.skip=true
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.slf4j</groupId>
|
<groupId>org.slf4j</groupId>
|
||||||
<artifactId>slf4j-log4j12</artifactId>
|
<artifactId>slf4j-log4j12</artifactId>
|
||||||
<version>1.7.5</version>
|
<version>${slf4j.version}</version>
|
||||||
<scope>runtime</scope>
|
<scope>runtime</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
@ -153,14 +152,11 @@ mvn clean package -Dmaven.test.skip=true
|
||||||
<artifactId>maven-assembly-plugin</artifactId>
|
<artifactId>maven-assembly-plugin</artifactId>
|
||||||
<version>2.2.1</version>
|
<version>2.2.1</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
|
|
||||||
<archive>
|
<archive>
|
||||||
<manifest>
|
<manifest>
|
||||||
<mainClass>org.ethereum.gui.ToolBar</mainClass>
|
<mainClass>org.ethereum.gui.ToolBar</mainClass>
|
||||||
</manifest>
|
</manifest>
|
||||||
|
|
||||||
</archive>
|
</archive>
|
||||||
|
|
||||||
<descriptorRefs>
|
<descriptorRefs>
|
||||||
<descriptorRef>jar-with-dependencies</descriptorRef>
|
<descriptorRef>jar-with-dependencies</descriptorRef>
|
||||||
</descriptorRefs>
|
</descriptorRefs>
|
||||||
|
@ -189,8 +185,7 @@ mvn clean package -Dmaven.test.skip=true
|
||||||
</archive>
|
</archive>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
|
||||||
|
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
</project>
|
</project>
|
||||||
|
|
|
@ -5,100 +5,81 @@ import java.io.InputStream;
|
||||||
import java.util.Enumeration;
|
import java.util.Enumeration;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* www.ethereumJ.com
|
* www.ethereumJ.com
|
||||||
* User: Roman Mandeleil
|
* User: Roman Mandeleil
|
||||||
* Created on: 22/05/2014 19:22
|
* Created on: 22/05/2014 19:22
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class SystemProperties {
|
public class SystemProperties {
|
||||||
|
|
||||||
Properties prop = new Properties();
|
private static Logger logger = LoggerFactory.getLogger(SystemProperties.class);
|
||||||
InputStream input = null;
|
|
||||||
|
public static SystemProperties CONFIG = new SystemProperties();
|
||||||
public static SystemProperties config = new SystemProperties();
|
private Properties prop = new Properties();
|
||||||
|
private InputStream input = null;
|
||||||
|
|
||||||
public SystemProperties() {
|
public SystemProperties() {
|
||||||
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
String filename = "system.properties";
|
||||||
String filename = "system.properties";
|
input = SystemProperties.class.getClassLoader().getResourceAsStream(filename);
|
||||||
input = SystemProperties.class.getClassLoader().getResourceAsStream(filename);
|
if (input == null) {
|
||||||
if(input==null){
|
logger.warn("Sorry, unable to find " + filename);
|
||||||
System.out.println("Sorry, unable to find " + filename);
|
return;
|
||||||
return;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
//load a properties file from class path, inside static method
|
//load a properties file from class path, inside static method
|
||||||
prop.load(input);
|
prop.load(input);
|
||||||
|
|
||||||
|
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
ex.printStackTrace();
|
logger.error(ex.getMessage(), ex);
|
||||||
} finally{
|
} finally {
|
||||||
if(input!=null){
|
if (input != null) {
|
||||||
try {
|
try {
|
||||||
input.close();
|
input.close();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
logger.error(e.getMessage(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean peerDiscovery() {
|
||||||
public boolean peerDiscovery(){
|
if (prop.isEmpty())
|
||||||
|
return true;
|
||||||
if(prop.isEmpty()) return true;
|
return Boolean.parseBoolean(prop.getProperty("peer.discovery"));
|
||||||
|
}
|
||||||
boolean result =
|
|
||||||
Boolean.parseBoolean( prop.getProperty("peer.discovery") );
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int peerDiscoveryWorkers(){
|
public int peerDiscoveryWorkers(){
|
||||||
if(prop.isEmpty()) return 2;
|
if(prop.isEmpty()) return 2;
|
||||||
|
return Integer.parseInt( prop.getProperty("peer.discovery.workers") );
|
||||||
int result =
|
|
||||||
Integer.parseInt( prop.getProperty("peer.discovery.workers") );
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int peerDiscoveryTimeout(){
|
public int peerDiscoveryTimeout(){
|
||||||
if(prop.isEmpty()) return 10000;
|
if (prop.isEmpty())
|
||||||
|
return 10000;
|
||||||
int result =
|
return Integer.parseInt(prop.getProperty("peer.discovery.timeout")) * 1000;
|
||||||
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 "";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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[]){
|
public static void main(String args[]){
|
||||||
|
|
||||||
SystemProperties systemProperties = new SystemProperties();
|
SystemProperties systemProperties = new SystemProperties();
|
||||||
System.out.println(systemProperties.toString());
|
logger.info(systemProperties.toString());
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,10 +4,14 @@ import java.math.BigInteger;
|
||||||
|
|
||||||
import org.ethereum.crypto.HashUtil;
|
import org.ethereum.crypto.HashUtil;
|
||||||
import org.ethereum.util.RLP;
|
import org.ethereum.util.RLP;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
import org.spongycastle.util.encoders.Hex;
|
import org.spongycastle.util.encoders.Hex;
|
||||||
|
|
||||||
public class Genesis extends Block {
|
public class Genesis extends Block {
|
||||||
|
|
||||||
|
Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||||
|
|
||||||
private static byte[] zeroHash256 = new byte[32];
|
private static byte[] zeroHash256 = new byte[32];
|
||||||
private static byte[] zeroHash160 = new byte[20];
|
private static byte[] zeroHash160 = new byte[20];
|
||||||
private static byte[] sha3EmptyList = HashUtil.sha3(RLP.encodeList());
|
private static byte[] sha3EmptyList = HashUtil.sha3(RLP.encodeList());
|
||||||
|
@ -31,5 +35,6 @@ public class Genesis extends Block {
|
||||||
super(parentHash, unclesHash, coinbase, stateRoot,
|
super(parentHash, unclesHash, coinbase, stateRoot,
|
||||||
txTrieRoot, difficulty, number, minGasPrice, gasLimit, gasUsed,
|
txTrieRoot, difficulty, number, minGasPrice, gasLimit, gasUsed,
|
||||||
timestamp, extraData, nonce, null, null);
|
timestamp, extraData, nonce, null, null);
|
||||||
|
logger.info("Genesis-hash: " + Hex.toHexString(this.getHash()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,11 +2,14 @@ package org.ethereum.core;
|
||||||
|
|
||||||
import org.ethereum.crypto.ECKey.ECDSASignature;
|
import org.ethereum.crypto.ECKey.ECDSASignature;
|
||||||
import org.ethereum.crypto.ECKey;
|
import org.ethereum.crypto.ECKey;
|
||||||
|
import org.ethereum.crypto.ECKey.MissingPrivateKeyException;
|
||||||
import org.ethereum.crypto.HashUtil;
|
import org.ethereum.crypto.HashUtil;
|
||||||
import org.ethereum.util.ByteUtil;
|
import org.ethereum.util.ByteUtil;
|
||||||
import org.ethereum.util.RLP;
|
import org.ethereum.util.RLP;
|
||||||
import org.ethereum.util.RLPItem;
|
import org.ethereum.util.RLPItem;
|
||||||
import org.ethereum.util.RLPList;
|
import org.ethereum.util.RLPList;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
import org.spongycastle.util.BigIntegers;
|
import org.spongycastle.util.BigIntegers;
|
||||||
|
|
||||||
import java.security.SignatureException;
|
import java.security.SignatureException;
|
||||||
|
@ -22,6 +25,8 @@ import java.util.Arrays;
|
||||||
*/
|
*/
|
||||||
public class Transaction {
|
public class Transaction {
|
||||||
|
|
||||||
|
Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||||
|
|
||||||
private static final int CALL_SIZE = 9;
|
private static final int CALL_SIZE = 9;
|
||||||
private static final int CONTRACT_SIZE = 10;
|
private static final int CONTRACT_SIZE = 10;
|
||||||
|
|
||||||
|
@ -66,21 +71,21 @@ public class Transaction {
|
||||||
private ECDSASignature signature;
|
private ECDSASignature signature;
|
||||||
|
|
||||||
/* Tx in encoded form */
|
/* Tx in encoded form */
|
||||||
private byte[] rlpEncodedSigned;
|
|
||||||
private byte[] rlpEncoded;
|
private byte[] rlpEncoded;
|
||||||
|
private byte[] rlpRaw;
|
||||||
/* Indicates if this transaction has been parsed
|
/* Indicates if this transaction has been parsed
|
||||||
* from the rlp-encoded data */
|
* from the rlp-encoded data */
|
||||||
private boolean parsed = false;
|
private boolean parsed = false;
|
||||||
|
|
||||||
public Transaction(byte[] rawData) {
|
public Transaction(byte[] rawData) {
|
||||||
this.rlpEncodedSigned = rawData;
|
this.rlpEncoded = rawData;
|
||||||
parsed = false;
|
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.nonce = nonce;
|
||||||
this.gasPrice = gasPrice;
|
this.gasPrice = gasPrice;
|
||||||
this.gasLimit = gas;
|
this.gasLimit = gasLimit;
|
||||||
this.receiveAddress = recieveAddress;
|
this.receiveAddress = recieveAddress;
|
||||||
this.value = value;
|
this.value = value;
|
||||||
if(recieveAddress == null || receiveAddress.length == 0) {
|
if(recieveAddress == null || receiveAddress.length == 0) {
|
||||||
|
@ -93,7 +98,7 @@ public class Transaction {
|
||||||
|
|
||||||
public void rlpParse(){
|
public void rlpParse(){
|
||||||
|
|
||||||
RLPList decodedTxList = RLP.decode2(rlpEncodedSigned);
|
RLPList decodedTxList = RLP.decode2(rlpEncoded);
|
||||||
RLPList transaction = (RLPList) decodedTxList.get(0);
|
RLPList transaction = (RLPList) decodedTxList.get(0);
|
||||||
|
|
||||||
this.nonce = ((RLPItem) transaction.get(0)).getRLPData();
|
this.nonce = ((RLPItem) transaction.get(0)).getRLPData();
|
||||||
|
@ -104,16 +109,26 @@ public class Transaction {
|
||||||
this.data = ((RLPItem) transaction.get(5)).getRLPData();
|
this.data = ((RLPItem) transaction.get(5)).getRLPData();
|
||||||
|
|
||||||
if (transaction.size() == CALL_SIZE){ // Simple transaction
|
if (transaction.size() == CALL_SIZE){ // Simple transaction
|
||||||
byte v = ((RLPItem) transaction.get(6)).getRLPData()[0];
|
// only parse signature in case tx is signed
|
||||||
byte[] r = ((RLPItem) transaction.get(7)).getRLPData();
|
if(((RLPItem) transaction.get(6)).getRLPData() != null) {
|
||||||
byte[] s = ((RLPItem) transaction.get(8)).getRLPData();
|
byte v = ((RLPItem) transaction.get(6)).getRLPData()[0];
|
||||||
this.signature = ECDSASignature.fromComponents(r, s, v);
|
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
|
} else if (transaction.size() == CONTRACT_SIZE){ // Contract creation transaction
|
||||||
this.init = ((RLPItem) transaction.get(6)).getRLPData();
|
this.init = ((RLPItem) transaction.get(6)).getRLPData();
|
||||||
byte v = ((RLPItem) transaction.get(7)).getRLPData()[0];
|
// only parse signature in case tx is signed
|
||||||
byte[] r = ((RLPItem) transaction.get(8)).getRLPData();
|
if(((RLPItem) transaction.get(6)).getRLPData() != null) {
|
||||||
byte[] s = ((RLPItem) transaction.get(9)).getRLPData();
|
byte v = ((RLPItem) transaction.get(7)).getRLPData()[0];
|
||||||
this.signature = ECDSASignature.fromComponents(r, s, v);
|
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");
|
} else throw new RuntimeException("Wrong tx data element list size");
|
||||||
this.parsed = true;
|
this.parsed = true;
|
||||||
this.hash = this.getHash();
|
this.hash = this.getHash();
|
||||||
|
@ -126,7 +141,7 @@ public class Transaction {
|
||||||
public byte[] getHash() {
|
public byte[] getHash() {
|
||||||
|
|
||||||
if (!parsed) rlpParse();
|
if (!parsed) rlpParse();
|
||||||
byte[] plainMsg = this.getEncoded();
|
byte[] plainMsg = this.getEncodedRaw();
|
||||||
return HashUtil.sha3(plainMsg);
|
return HashUtil.sha3(plainMsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -183,22 +198,21 @@ public class Transaction {
|
||||||
return ECKey.recoverFromSignature(signature.v, signature, hash, true);
|
return ECKey.recoverFromSignature(signature.v, signature, hash, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public byte[] sender() {
|
public byte[] getSender() {
|
||||||
|
try {
|
||||||
ECKey key = null;
|
ECKey key = ECKey.signatureToKey(getHash(), getSignature().toBase64());
|
||||||
try {
|
return key.getAddress();
|
||||||
key = ECKey.signatureToKey(getHash(), getSignature().toBase64());
|
} catch (SignatureException e) {
|
||||||
} catch (SignatureException e) {
|
logger.error(e.getMessage(), e);
|
||||||
e.printStackTrace();
|
}
|
||||||
}
|
return null;
|
||||||
|
|
||||||
return key.getAddress();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sign(byte[] privKeyBytes) throws Exception {
|
public void sign(byte[] privKeyBytes) throws MissingPrivateKeyException {
|
||||||
byte[] hash = this.getHash();
|
byte[] hash = this.getHash();
|
||||||
ECKey key = ECKey.fromPrivate(privKeyBytes).decompress();
|
ECKey key = ECKey.fromPrivate(privKeyBytes).decompress();
|
||||||
this.signature = key.sign(hash);
|
this.signature = key.sign(hash);
|
||||||
|
this.rlpEncoded = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -206,15 +220,15 @@ public class Transaction {
|
||||||
if (!parsed) rlpParse();
|
if (!parsed) rlpParse();
|
||||||
return "TransactionData [" + " hash=" + ByteUtil.toHexString(hash) +
|
return "TransactionData [" + " hash=" + ByteUtil.toHexString(hash) +
|
||||||
" nonce=" + ByteUtil.toHexString(nonce) +
|
" nonce=" + ByteUtil.toHexString(nonce) +
|
||||||
", value=" + ByteUtil.toHexString(value) +
|
|
||||||
", receiveAddress=" + ByteUtil.toHexString(receiveAddress) +
|
|
||||||
", gasPrice=" + ByteUtil.toHexString(gasPrice) +
|
", gasPrice=" + ByteUtil.toHexString(gasPrice) +
|
||||||
", gas=" + ByteUtil.toHexString(gasLimit) +
|
", gas=" + ByteUtil.toHexString(gasLimit) +
|
||||||
|
", receiveAddress=" + ByteUtil.toHexString(receiveAddress) +
|
||||||
|
", value=" + ByteUtil.toHexString(value) +
|
||||||
", data=" + ByteUtil.toHexString(data) +
|
", data=" + ByteUtil.toHexString(data) +
|
||||||
", init=" + ByteUtil.toHexString(init) +
|
", init=" + ByteUtil.toHexString(init) +
|
||||||
", signatureV=" + signature.v +
|
", signatureV=" + signature.v +
|
||||||
", signatureR=" + ByteUtil.toHexString(signature.r.toByteArray()) +
|
", signatureR=" + ByteUtil.toHexString(BigIntegers.asUnsignedByteArray(signature.r)) +
|
||||||
", signatureS=" + ByteUtil.toHexString(signature.s.toByteArray()) +
|
", signatureS=" + ByteUtil.toHexString(BigIntegers.asUnsignedByteArray(signature.s)) +
|
||||||
']';
|
']';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -222,9 +236,9 @@ public class Transaction {
|
||||||
* For signature games you have to keep also
|
* For signature games you have to keep also
|
||||||
* rlp of the transaction without any signature data
|
* 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[] nonce = RLP.encodeElement(this.nonce);
|
||||||
byte[] gasPrice = RLP.encodeElement(this.gasPrice);
|
byte[] gasPrice = RLP.encodeElement(this.gasPrice);
|
||||||
|
@ -235,38 +249,46 @@ public class Transaction {
|
||||||
|
|
||||||
if(Arrays.equals(this.receiveAddress, new byte[0])) {
|
if(Arrays.equals(this.receiveAddress, new byte[0])) {
|
||||||
byte[] init = RLP.encodeElement(this.init);
|
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);
|
data, init);
|
||||||
} else {
|
} else {
|
||||||
this.rlpEncoded = RLP.encodeList(nonce, gasPrice, gasLimit, receiveAddress, value,
|
this.rlpRaw = RLP.encodeList(nonce, gasPrice, gasLimit, receiveAddress, value,
|
||||||
data);
|
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;
|
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -37,7 +37,7 @@ public class Wallet {
|
||||||
private HashMap<String, AddressState> rows = new HashMap<String, AddressState>();
|
private HashMap<String, AddressState> rows = new HashMap<String, AddressState>();
|
||||||
private long high;
|
private long high;
|
||||||
|
|
||||||
private List<WalletListener> listeners = new ArrayList();
|
private List<WalletListener> listeners = new ArrayList<WalletListener>();
|
||||||
|
|
||||||
public void addNewKey(){
|
public void addNewKey(){
|
||||||
|
|
||||||
|
@ -96,7 +96,7 @@ public class Wallet {
|
||||||
for (Transaction tx : transactions){
|
for (Transaction tx : transactions){
|
||||||
|
|
||||||
|
|
||||||
byte[] senderAddress = tx.sender();
|
byte[] senderAddress = tx.getSender();
|
||||||
AddressState senderState = rows.get(Hex.toHexString(senderAddress));
|
AddressState senderState = rows.get(Hex.toHexString(senderAddress));
|
||||||
if (senderState != null){
|
if (senderState != null){
|
||||||
BigInteger value = new BigInteger(tx.getValue());
|
BigInteger value = new BigInteger(tx.getValue());
|
||||||
|
@ -169,9 +169,6 @@ public class Wallet {
|
||||||
// this.importKey(privKey);
|
// this.importKey(privKey);
|
||||||
// this.setBalance(address, value);
|
// this.setBalance(address, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -257,7 +254,6 @@ public class Wallet {
|
||||||
public void valueChanged();
|
public void valueChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public long getHigh() {
|
public long getHigh() {
|
||||||
return high;
|
return high;
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,6 @@ package org.ethereum.crypto;
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
|
||||||
import static org.ethereum.util.ByteUtil.bigIntegerToBytes;
|
import static org.ethereum.util.ByteUtil.bigIntegerToBytes;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
@ -46,9 +45,7 @@ import org.spongycastle.math.ec.ECCurve;
|
||||||
import org.spongycastle.math.ec.ECPoint;
|
import org.spongycastle.math.ec.ECPoint;
|
||||||
import org.spongycastle.util.encoders.Base64;
|
import org.spongycastle.util.encoders.Base64;
|
||||||
import org.spongycastle.util.encoders.Hex;
|
import org.spongycastle.util.encoders.Hex;
|
||||||
|
|
||||||
import com.google.common.base.Preconditions;
|
|
||||||
|
|
||||||
public class ECKey implements Serializable {
|
public class ECKey implements Serializable {
|
||||||
private static final Logger log = LoggerFactory.getLogger(ECKey.class);
|
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.
|
* already. The compression state of the point will be preserved.
|
||||||
*/
|
*/
|
||||||
public static ECKey fromPrivateAndPrecalculatedPublic(byte[] priv, byte[] pub) {
|
public static ECKey fromPrivateAndPrecalculatedPublic(byte[] priv, byte[] pub) {
|
||||||
checkNotNull(priv);
|
check(priv != null, "Private key must not be null");
|
||||||
checkNotNull(pub);
|
check(pub != null, "Public key must not be null");
|
||||||
return new ECKey(new BigInteger(1, priv), CURVE.getCurve().decodePoint(pub));
|
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.
|
// No decryption of private key required.
|
||||||
if (priv == null)
|
if (priv == null)
|
||||||
throw new MissingPrivateKeyException();
|
throw new MissingPrivateKeyException();
|
||||||
checkNotNull(priv);
|
check(priv != null, "Private key must not be null");
|
||||||
ECDSASigner signer = new ECDSASigner(new HMacDSAKCalculator(new SHA256Digest()));
|
ECDSASigner signer = new ECDSASigner(new HMacDSAKCalculator(new SHA256Digest()));
|
||||||
ECPrivateKeyParameters privKey = new ECPrivateKeyParameters(priv, CURVE);
|
ECPrivateKeyParameters privKey = new ECPrivateKeyParameters(priv, CURVE);
|
||||||
signer.init(true, privKey);
|
signer.init(true, privKey);
|
||||||
|
@ -534,10 +531,10 @@ public class ECKey implements Serializable {
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
public static ECKey recoverFromSignature(int recId, ECDSASignature sig, byte[] messageHash, boolean compressed) {
|
public static ECKey recoverFromSignature(int recId, ECDSASignature sig, byte[] messageHash, boolean compressed) {
|
||||||
Preconditions.checkArgument(recId >= 0, "recId must be positive");
|
check(recId >= 0, "recId must be positive");
|
||||||
Preconditions.checkArgument(sig.r.signum() >= 0, "r must be positive");
|
check(sig.r.signum() >= 0, "r must be positive");
|
||||||
Preconditions.checkArgument(sig.s.signum() >= 0, "s must be positive");
|
check(sig.s.signum() >= 0, "s must be positive");
|
||||||
Preconditions.checkNotNull(messageHash);
|
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.0 For j from 0 to h (h == recId here and the loop is outside this function)
|
||||||
// 1.1 Let x = r + jn
|
// 1.1 Let x = r + jn
|
||||||
BigInteger n = CURVE.getN(); // Curve order.
|
BigInteger n = CURVE.getN(); // Curve order.
|
||||||
|
@ -624,4 +621,7 @@ public class ECKey implements Serializable {
|
||||||
public static class MissingPrivateKeyException extends RuntimeException {
|
public static class MissingPrivateKeyException extends RuntimeException {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void check(boolean test, String message) {
|
||||||
|
if(!test) throw new IllegalArgumentException(message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,6 @@ package org.ethereum.geodb;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.net.URISyntaxException;
|
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
|
||||||
import com.maxmind.geoip.Location;
|
import com.maxmind.geoip.Location;
|
||||||
|
@ -20,7 +19,7 @@ public class IpGeoDB { // change
|
||||||
File file = null;
|
File file = null;
|
||||||
try {
|
try {
|
||||||
|
|
||||||
URL geiIpDBFile = ClassLoader.getSystemResource("geolitecity.dat");
|
URL geiIpDBFile = ClassLoader.getSystemResource("GeoLiteCity.dat");
|
||||||
file = new File(geiIpDBFile.toURI());
|
file = new File(geiIpDBFile.toURI());
|
||||||
} catch (Throwable th) {
|
} catch (Throwable th) {
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package org.ethereum.gui;
|
package org.ethereum.gui;
|
||||||
|
|
||||||
import org.ethereum.manager.MainData;
|
import org.ethereum.manager.MainData;
|
||||||
import org.spongycastle.util.encoders.Hex;
|
|
||||||
|
|
||||||
import javax.swing.table.AbstractTableModel;
|
import javax.swing.table.AbstractTableModel;
|
||||||
|
|
||||||
|
@ -12,8 +11,6 @@ import javax.swing.table.AbstractTableModel;
|
||||||
*/
|
*/
|
||||||
public class BlockTableModel extends AbstractTableModel {
|
public class BlockTableModel extends AbstractTableModel {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getRowCount() {
|
public int getRowCount() {
|
||||||
|
|
||||||
|
|
|
@ -69,18 +69,23 @@ public class ConnectionConsoleWindow extends JFrame implements PeerListener{
|
||||||
Thread t = new Thread() {
|
Thread t = new Thread() {
|
||||||
public void run() {
|
public void run() {
|
||||||
|
|
||||||
// new ClientPeer(thisConsole).connect("54.201.28.117", 30303); // peer discovery
|
// Peer Server Zero: peer discovery
|
||||||
// new ClientPeer(thisConsole).connect("82.217.72.169", 30303); // Nick
|
// new ClientPeer(thisConsole).connect("54.201.28.117", 30303);
|
||||||
|
|
||||||
// new ClientPeer(thisConsole).connect("131.104.247.135", 30303); // Some dude in Canada
|
// Peer Server One: peer discovery
|
||||||
|
new ClientPeer(thisConsole).connect("54.204.10.41", 30303);
|
||||||
|
|
||||||
// new ClientPeer(thisConsole).connect("54.204.10.41", 30303);
|
// Some dude in Canada
|
||||||
|
// new ClientPeer(thisConsole).connect("131.104.247.135", 30303);
|
||||||
// new ClientPeer(thisConsole).connect("54.204.10.41", 30303); // CPP: ZeroGox Poc5
|
|
||||||
new ClientPeer(thisConsole).connect("54.211.14.10", 40404); // RomanJ
|
// Nick
|
||||||
|
// new ClientPeer(thisConsole).connect("82.217.72.169", 30303);
|
||||||
// new ClientPeer(thisConsole).connect("192.168.1.102", 30303);
|
|
||||||
|
// c++: ZeroGox
|
||||||
|
// new ClientPeer(thisConsole).connect("54.204.10.41", 30303);
|
||||||
|
|
||||||
|
// RomanJ
|
||||||
|
// new ClientPeer(thisConsole).connect("54.211.14.10", 40404);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
t.start();
|
t.start();
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package org.ethereum.gui;
|
package org.ethereum.gui;
|
||||||
|
|
||||||
import org.ethereum.core.Transaction;
|
import org.ethereum.core.Transaction;
|
||||||
import org.ethereum.crypto.HashUtil;
|
|
||||||
import org.ethereum.manager.MainData;
|
import org.ethereum.manager.MainData;
|
||||||
import org.ethereum.net.client.ClientPeer;
|
import org.ethereum.net.client.ClientPeer;
|
||||||
import org.ethereum.wallet.AddressState;
|
import org.ethereum.wallet.AddressState;
|
||||||
|
|
|
@ -2,7 +2,6 @@ package org.ethereum.gui;
|
||||||
|
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.UnknownHostException;
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
import javax.swing.ImageIcon;
|
import javax.swing.ImageIcon;
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package org.ethereum.gui;
|
package org.ethereum.gui;
|
||||||
|
|
||||||
import org.ethereum.config.SystemProperties;
|
|
||||||
import org.ethereum.manager.MainData;
|
import org.ethereum.manager.MainData;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
|
@ -16,7 +15,7 @@ import javax.swing.SwingConstants;
|
||||||
import javax.swing.table.DefaultTableCellRenderer;
|
import javax.swing.table.DefaultTableCellRenderer;
|
||||||
import javax.swing.table.TableCellRenderer;
|
import javax.swing.table.TableCellRenderer;
|
||||||
|
|
||||||
import static org.ethereum.config.SystemProperties.config;
|
import static org.ethereum.config.SystemProperties.CONFIG;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* www.ethereumJ.com
|
* www.ethereumJ.com
|
||||||
|
@ -93,7 +92,7 @@ public class PeersTableWindow extends JFrame{
|
||||||
}
|
}
|
||||||
}, 1000, 1000);
|
}, 1000, 1000);
|
||||||
|
|
||||||
if (config.peerDiscovery())
|
if (CONFIG.peerDiscovery())
|
||||||
MainData.instance.startPeerDiscovery();
|
MainData.instance.startPeerDiscovery();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,8 +8,6 @@ import org.slf4j.LoggerFactory;
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.awt.event.ActionEvent;
|
|
||||||
import java.awt.event.ActionListener;
|
|
||||||
import java.awt.event.ItemEvent;
|
import java.awt.event.ItemEvent;
|
||||||
import java.awt.event.ItemListener;
|
import java.awt.event.ItemListener;
|
||||||
|
|
||||||
|
@ -36,7 +34,7 @@ public class ToolBar extends JFrame {
|
||||||
introLogger.info("♢ EthereumJ [v0.5.1] ");
|
introLogger.info("♢ EthereumJ [v0.5.1] ");
|
||||||
introLogger.info("♢ Code by Roman Mandeleil, (c) 2014.");
|
introLogger.info("♢ Code by Roman Mandeleil, (c) 2014.");
|
||||||
introLogger.info("♢ Contribution: Nick Savers ");
|
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("");
|
||||||
introLogger.info("java.version: " + System.getProperty("java.version"));
|
introLogger.info("java.version: " + System.getProperty("java.version"));
|
||||||
introLogger.info("java.home: " + System.getProperty("java.home"));
|
introLogger.info("java.home: " + System.getProperty("java.home"));
|
||||||
|
@ -48,9 +46,6 @@ public class ToolBar extends JFrame {
|
||||||
System.exit(0);
|
System.exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
final JPanel cp = new JPanel(new FlowLayout());
|
final JPanel cp = new JPanel(new FlowLayout());
|
||||||
cp.setBackground(Color.WHITE);
|
cp.setBackground(Color.WHITE);
|
||||||
|
|
||||||
|
@ -161,7 +156,6 @@ public class ToolBar extends JFrame {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
JToggleButton chainToggle = new JToggleButton();
|
JToggleButton chainToggle = new JToggleButton();
|
||||||
chainToggle.setIcon(image_4);
|
chainToggle.setIcon(image_4);
|
||||||
chainToggle.setToolTipText("Block Chain");
|
chainToggle.setToolTipText("Block Chain");
|
||||||
|
@ -222,17 +216,14 @@ public class ToolBar extends JFrame {
|
||||||
cp.add(chainToggle);
|
cp.add(chainToggle);
|
||||||
cp.add(walletToggle);
|
cp.add(walletToggle);
|
||||||
|
|
||||||
|
|
||||||
MainData.instance.toString();
|
MainData.instance.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String args[]){
|
public static void main(String args[]){
|
||||||
|
|
||||||
SwingUtilities.invokeLater(new Runnable() {
|
SwingUtilities.invokeLater(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
new ToolBar().setVisible(true);
|
new ToolBar().setVisible(true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,6 @@ import javax.swing.border.EmptyBorder;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.awt.event.MouseAdapter;
|
import java.awt.event.MouseAdapter;
|
||||||
import java.awt.event.MouseEvent;
|
import java.awt.event.MouseEvent;
|
||||||
import java.math.BigInteger;
|
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -7,8 +7,6 @@ import javax.swing.border.Border;
|
||||||
import javax.swing.border.CompoundBorder;
|
import javax.swing.border.CompoundBorder;
|
||||||
import javax.swing.border.EmptyBorder;
|
import javax.swing.border.EmptyBorder;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.awt.event.ActionEvent;
|
|
||||||
import java.awt.event.ActionListener;
|
|
||||||
import java.awt.event.MouseAdapter;
|
import java.awt.event.MouseAdapter;
|
||||||
import java.awt.event.MouseEvent;
|
import java.awt.event.MouseEvent;
|
||||||
import java.math.BigInteger;
|
import java.math.BigInteger;
|
||||||
|
|
|
@ -18,7 +18,6 @@ import org.ethereum.net.client.ClientPeer;
|
||||||
import org.ethereum.net.client.PeerData;
|
import org.ethereum.net.client.PeerData;
|
||||||
import org.ethereum.net.message.StaticMessages;
|
import org.ethereum.net.message.StaticMessages;
|
||||||
import org.ethereum.net.peerdiscovery.PeerDiscovery;
|
import org.ethereum.net.peerdiscovery.PeerDiscovery;
|
||||||
import org.ethereum.net.peerdiscovery.WorkerThread;
|
|
||||||
import org.ethereum.wallet.AddressState;
|
import org.ethereum.wallet.AddressState;
|
||||||
import org.spongycastle.util.encoders.Hex;
|
import org.spongycastle.util.encoders.Hex;
|
||||||
|
|
||||||
|
@ -49,7 +48,7 @@ public class MainData {
|
||||||
|
|
||||||
wallet.importKey(cowAddr);
|
wallet.importKey(cowAddr);
|
||||||
AddressState state = wallet.getAddressState(key.getAddress());
|
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()));
|
wallet.importKey(HashUtil.sha3("cat".getBytes()));
|
||||||
|
|
||||||
peerDiscovery = new PeerDiscovery(peers);
|
peerDiscovery = new PeerDiscovery(peers);
|
||||||
|
@ -92,7 +91,7 @@ public class MainData {
|
||||||
|
|
||||||
public byte[] getLatestBlockHash(){
|
public byte[] getLatestBlockHash(){
|
||||||
if (blockChainDB.isEmpty())
|
if (blockChainDB.isEmpty())
|
||||||
return (new Genesis()).getHash();
|
return StaticMessages.GENESIS_HASH;
|
||||||
else
|
else
|
||||||
return blockChainDB.get(blockChainDB.size() - 1).getHash();
|
return blockChainDB.get(blockChainDB.size() - 1).getHash();
|
||||||
}
|
}
|
||||||
|
|
|
@ -89,7 +89,7 @@ public class ClientPeer {
|
||||||
*/
|
*/
|
||||||
public void sendTransaction(Transaction transaction){
|
public void sendTransaction(Transaction transaction){
|
||||||
|
|
||||||
transaction.getEncodedSigned();
|
transaction.getEncoded();
|
||||||
java.util.List<Transaction> txList = new ArrayList<Transaction>();
|
java.util.List<Transaction> txList = new ArrayList<Transaction>();
|
||||||
txList.add(transaction);
|
txList.add(transaction);
|
||||||
TransactionsMessage transactionsMessage = new TransactionsMessage(txList);
|
TransactionsMessage transactionsMessage = new TransactionsMessage(txList);
|
||||||
|
|
|
@ -6,7 +6,6 @@ import java.util.List;
|
||||||
import static org.ethereum.net.Command.BLOCKS;
|
import static org.ethereum.net.Command.BLOCKS;
|
||||||
|
|
||||||
import org.ethereum.core.Block;
|
import org.ethereum.core.Block;
|
||||||
import org.ethereum.core.Transaction;
|
|
||||||
import org.ethereum.net.Command;
|
import org.ethereum.net.Command;
|
||||||
import org.ethereum.util.RLPItem;
|
import org.ethereum.util.RLPItem;
|
||||||
import org.ethereum.util.RLPList;
|
import org.ethereum.util.RLPList;
|
||||||
|
|
|
@ -120,10 +120,10 @@ public class HelloMessage extends Message {
|
||||||
return "Hello Message [ command=" + HELLO.asByte() + " " +
|
return "Hello Message [ command=" + HELLO.asByte() + " " +
|
||||||
" protocolVersion=" + this.protocolVersion + " " +
|
" protocolVersion=" + this.protocolVersion + " " +
|
||||||
" networkId=" + this.networkId + " " +
|
" networkId=" + this.networkId + " " +
|
||||||
" clientId= " + this.clientId + " " +
|
" clientId=" + this.clientId + " " +
|
||||||
" capabilities= " + this.capabilities + " " +
|
" capabilities=" + this.capabilities + " " +
|
||||||
" peerPort= " + this.peerPort + " " +
|
" peerPort=" + this.peerPort + " " +
|
||||||
" peerId= " + Hex.toHexString(this.peerId) + " " +
|
" peerId=" + Hex.toHexString(this.peerId) + " " +
|
||||||
"]";
|
"]";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -78,4 +78,4 @@ public class PeersMessage extends Message {
|
||||||
}
|
}
|
||||||
return "Peers Message [\n " + sb.toString() + "]";
|
return "Peers Message [\n " + sb.toString() + "]";
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,8 +1,11 @@
|
||||||
package org.ethereum.net.message;
|
package org.ethereum.net.message;
|
||||||
|
|
||||||
|
import org.ethereum.core.Genesis;
|
||||||
import org.ethereum.crypto.HashUtil;
|
import org.ethereum.crypto.HashUtil;
|
||||||
import org.spongycastle.util.encoders.Hex;
|
import org.spongycastle.util.encoders.Hex;
|
||||||
|
|
||||||
|
import static org.ethereum.config.SystemProperties.CONFIG;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* www.ethereumJ.com
|
* www.ethereumJ.com
|
||||||
* User: Roman Mandeleil
|
* User: Roman Mandeleil
|
||||||
|
@ -16,16 +19,15 @@ public class StaticMessages {
|
||||||
public static final byte[] GET_TRANSACTIONS = Hex.decode("2240089100000002C116");
|
public static final byte[] GET_TRANSACTIONS = Hex.decode("2240089100000002C116");
|
||||||
|
|
||||||
public static final byte[] DISCONNECT_08 = Hex.decode("2240089100000003C20108");
|
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");
|
public static final byte[] MAGIC_PACKET = Hex.decode("22400891");
|
||||||
|
|
||||||
static {
|
static {
|
||||||
|
|
||||||
byte[] peerIdBytes = HashUtil.randomPeerId();
|
byte[] peerIdBytes = HashUtil.randomPeerId();
|
||||||
|
|
||||||
HELLO_MESSAGE = new HelloMessage((byte)0x11, (byte)0x00, "EthereumJ [v0.5.1] by RomanJ ",
|
HELLO_MESSAGE = new HelloMessage((byte) 0x11, (byte) 0x00,
|
||||||
(byte)0b00000111, (short)30303, peerIdBytes);
|
CONFIG.clientName(), (byte) 0b00000111,
|
||||||
|
(short) 30303, peerIdBytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final HelloMessage HELLO_MESSAGE;
|
public static final HelloMessage HELLO_MESSAGE;
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,7 +32,7 @@ public class TransactionsMessage extends Message {
|
||||||
|
|
||||||
for (Transaction tx : transactionList){
|
for (Transaction tx : transactionList){
|
||||||
|
|
||||||
byte[] txPayload = tx.getEncodedSigned();
|
byte[] txPayload = tx.getEncoded();
|
||||||
try {
|
try {
|
||||||
baos.write(txPayload);
|
baos.write(txPayload);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
@ -43,7 +43,7 @@ public class TransactionsMessage extends Message {
|
||||||
byte[][] elements = new byte[transactionList.size() + 1][];
|
byte[][] elements = new byte[transactionList.size() + 1][];
|
||||||
elements[0] = new byte[]{Command.TRANSACTIONS.asByte()};
|
elements[0] = new byte[]{Command.TRANSACTIONS.asByte()};
|
||||||
for (int i = 0; i < transactionList.size(); ++i){
|
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);
|
payload = RLP.encodeList(elements);
|
||||||
|
@ -84,8 +84,8 @@ public class TransactionsMessage extends Message {
|
||||||
public String toString() {
|
public String toString() {
|
||||||
if(!parsed) parseRLP();
|
if(!parsed) parseRLP();
|
||||||
StringBuffer sb = new StringBuffer();
|
StringBuffer sb = new StringBuffer();
|
||||||
for (Transaction transactionData : transactions){
|
for (Transaction transaction : transactions){
|
||||||
sb.append(" ").append(transactionData).append("\n");
|
sb.append(" ").append(transaction).append("\n");
|
||||||
}
|
}
|
||||||
return "Transactions Message [\n" + sb.toString() + " ]";
|
return "Transactions Message [\n" + sb.toString() + " ]";
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,13 +1,11 @@
|
||||||
package org.ethereum.net.peerdiscovery;
|
package org.ethereum.net.peerdiscovery;
|
||||||
|
|
||||||
|
|
||||||
import org.ethereum.config.SystemProperties;
|
|
||||||
import org.ethereum.net.client.PeerData;
|
import org.ethereum.net.client.PeerData;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.*;
|
import java.util.concurrent.*;
|
||||||
|
|
||||||
import static org.ethereum.config.SystemProperties.config;
|
import static org.ethereum.config.SystemProperties.CONFIG;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* www.ethereumJ.com
|
* www.ethereumJ.com
|
||||||
|
@ -39,7 +37,7 @@ public class PeerDiscovery {
|
||||||
|
|
||||||
//creating the ThreadPoolExecutor
|
//creating the ThreadPoolExecutor
|
||||||
executorPool = new ThreadPoolExecutor(1, 1000, 10, TimeUnit.SECONDS,
|
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
|
//start the monitoring thread
|
||||||
monitor = new PeerDiscoveryMonitorThread(executorPool, 3);
|
monitor = new PeerDiscoveryMonitorThread(executorPool, 3);
|
||||||
|
|
|
@ -5,18 +5,12 @@ import io.netty.channel.*;
|
||||||
import io.netty.channel.nio.NioEventLoopGroup;
|
import io.netty.channel.nio.NioEventLoopGroup;
|
||||||
import io.netty.channel.socket.nio.NioSocketChannel;
|
import io.netty.channel.socket.nio.NioSocketChannel;
|
||||||
import io.netty.handler.timeout.ReadTimeoutHandler;
|
import io.netty.handler.timeout.ReadTimeoutHandler;
|
||||||
import org.ethereum.config.SystemProperties;
|
|
||||||
import org.ethereum.gui.PeerListener;
|
import org.ethereum.gui.PeerListener;
|
||||||
import org.ethereum.manager.MainData;
|
|
||||||
import org.ethereum.net.client.EthereumFrameDecoder;
|
import org.ethereum.net.client.EthereumFrameDecoder;
|
||||||
import org.ethereum.net.client.PeerData;
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
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
|
* www.ethereumJ.com
|
||||||
|
@ -59,9 +53,8 @@ public class PeerTaster {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
// Start the client.
|
// 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)
|
ChannelFuture f = b.connect(host, port).sync(); // (5)
|
||||||
|
|
||||||
// Wait until the connection is closed.
|
// Wait until the connection is closed.
|
||||||
|
|
|
@ -1,18 +1,11 @@
|
||||||
package org.ethereum.serpent;
|
package org.ethereum.serpent;
|
||||||
|
|
||||||
import org.antlr.mojo.antlr4.Antlr4ErrorLog;
|
import java.io.File;
|
||||||
import org.antlr.mojo.antlr4.Antlr4Mojo;
|
|
||||||
import org.antlr.v4.Tool;
|
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.MojoExecutionException;
|
||||||
import org.apache.maven.plugin.MojoFailureException;
|
import org.apache.maven.plugin.MojoFailureException;
|
||||||
|
|
||||||
import java.io.*;
|
|
||||||
import java.net.URI;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* www.ethereumJ.com
|
* www.ethereumJ.com
|
||||||
* User: Roman Mandeleil
|
* User: Roman Mandeleil
|
||||||
|
@ -20,27 +13,19 @@ import java.util.Map;
|
||||||
*/
|
*/
|
||||||
public class ParserGenerator {
|
public class ParserGenerator {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public static void main(String args[]) throws MojoFailureException, MojoExecutionException {
|
public static void main(String args[]) throws MojoFailureException, MojoExecutionException {
|
||||||
|
|
||||||
String userDir = System.getProperty("user.dir");
|
String userDir = System.getProperty("user.dir");
|
||||||
|
|
||||||
|
|
||||||
String grammarName = userDir + "\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g4";
|
String grammarName = userDir + "\\src\\main\\java\\org\\ethereum\\serpent\\Serpent.g4";
|
||||||
|
|
||||||
|
|
||||||
File inputDir = new File(userDir + "\\src\\main\\java\\org\\ethereum\\serpent\\");
|
File inputDir = new File(userDir + "\\src\\main\\java\\org\\ethereum\\serpent\\");
|
||||||
|
|
||||||
|
|
||||||
String options[] = {grammarName, "-visitor", "-package", "org.ethereum.serpent"};
|
String options[] = {grammarName, "-visitor", "-package", "org.ethereum.serpent"};
|
||||||
Tool tool = new Tool(options);
|
Tool tool = new Tool(options);
|
||||||
tool.outputDirectory = userDir + "\\src\\main\\java\\org\\ethereum\\serpent\\";
|
tool.outputDirectory = userDir + "\\src\\main\\java\\org\\ethereum\\serpent\\";
|
||||||
tool.processGrammarsOnCommandLine();
|
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\\org\\ethereum\\serpent\\Serpent.g4"});
|
||||||
// org.antlr.Tool.main(new String[]{userDir + "\\src\\main\\java\\samples\\antlr\\PyEsque.g"});
|
// org.antlr.Tool.main(new String[]{userDir + "\\src\\main\\java\\samples\\antlr\\PyEsque.g"});
|
||||||
|
|
||||||
|
|
|
@ -3,17 +3,10 @@ package org.ethereum.util;
|
||||||
import java.math.BigInteger;
|
import java.math.BigInteger;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
import org.spongycastle.util.encoders.Hex;
|
import org.spongycastle.util.encoders.Hex;
|
||||||
|
|
||||||
import com.google.common.primitives.UnsignedInteger;
|
|
||||||
import com.google.common.primitives.UnsignedLongs;
|
|
||||||
|
|
||||||
public class ByteUtil {
|
public class ByteUtil {
|
||||||
|
|
||||||
private static Logger logger = LoggerFactory.getLogger("ByteUtil");
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a copy of bytes and appends b to the end of it
|
* Creates a copy of bytes and appends b to the end of it
|
||||||
*/
|
*/
|
||||||
|
@ -43,57 +36,11 @@ public class ByteUtil {
|
||||||
return bytes;
|
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){
|
public static String toHexString(byte[] data){
|
||||||
if (data == null) return "null";
|
if (data == null) return "null";
|
||||||
else return Hex.toHexString(data);
|
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
|
// The packet size should be 4 byte long
|
||||||
public static byte[] calcPacketSize(byte[] packet){
|
public static byte[] calcPacketSize(byte[] packet){
|
||||||
|
|
||||||
|
@ -135,38 +82,4 @@ public class ByteUtil {
|
||||||
return 0;
|
return 0;
|
||||||
return new BigInteger(1, b).intValue();
|
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));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,8 +2,6 @@ package org.ethereum.util;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import org.spongycastle.util.encoders.Hex;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* www.ethereumJ.com
|
* www.ethereumJ.com
|
||||||
* User: Roman Mandeleil
|
* User: Roman Mandeleil
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
#***
|
#***
|
||||||
# Starting to gather some properties the system going to support
|
# 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
|
# if the system will work as a server also
|
||||||
# accept for incoming connections [true/false]
|
# accept for incoming connections [true/false]
|
||||||
|
|
|
@ -9,8 +9,8 @@ import java.security.NoSuchAlgorithmException;
|
||||||
import java.security.NoSuchProviderException;
|
import java.security.NoSuchProviderException;
|
||||||
|
|
||||||
import org.ethereum.crypto.ECKey;
|
import org.ethereum.crypto.ECKey;
|
||||||
|
import org.ethereum.crypto.ECKey.MissingPrivateKeyException;
|
||||||
import org.ethereum.crypto.HashUtil;
|
import org.ethereum.crypto.HashUtil;
|
||||||
import org.ethereum.util.ByteUtil;
|
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.spongycastle.util.BigIntegers;
|
import org.spongycastle.util.BigIntegers;
|
||||||
|
@ -18,10 +18,6 @@ import org.spongycastle.util.encoders.Hex;
|
||||||
|
|
||||||
public class TransactionTest {
|
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 */
|
@Test /* sign transaction https://tools.ietf.org/html/rfc6979 */
|
||||||
public void test1() throws NoSuchProviderException, NoSuchAlgorithmException, InvalidKeyException, IOException {
|
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("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("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
|
// retrieve the signer/sender of the transaction
|
||||||
ECKey key = ECKey.signatureToKey(tx.getHash(), tx.getSignature().toBase64());
|
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 unsigned RLP\t\t: " + Hex.toHexString( tx.getEncodedRaw()));
|
||||||
System.out.println("Tx signed RLP\t\t: " + Hex.toHexString( tx.getEncodedSigned() ));
|
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("Signature public key\t: " + Hex.toHexString(key.getPubKey()));
|
||||||
System.out.println("Sender is\t\t: " + Hex.toHexString(key.getAddress()));
|
System.out.println("Sender is\t\t: " + Hex.toHexString(key.getAddress()));
|
||||||
|
@ -93,20 +89,16 @@ public class TransactionTest {
|
||||||
// cat --> 79b08ad8787060333663d19704909ee7b1903e58
|
// cat --> 79b08ad8787060333663d19704909ee7b1903e58
|
||||||
// cow --> cd2a3d9f938e13cd947ec05abc7fe734df8dd826
|
// 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");
|
BigInteger value = new BigInteger("1000000000000000000000000");
|
||||||
|
|
||||||
|
Transaction tx = new Transaction(nonce, gasPrice, gasLimit,
|
||||||
byte[] nonce = {01};
|
ecKey.getAddress(), value.toByteArray(), null);
|
||||||
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);
|
|
||||||
|
|
||||||
tx.sign(senderPrivKey);
|
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("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("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
|
// retrieve the signer/sender of the transaction
|
||||||
ECKey key = ECKey.signatureToKey(tx.getHash(), tx.getSignature().toBase64());
|
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 unsigned RLP\t\t: " + Hex.toHexString( tx.getEncodedRaw()));
|
||||||
System.out.println("Tx signed RLP\t\t: " + Hex.toHexString( tx.getEncodedSigned() ));
|
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("Signature public key\t: " + Hex.toHexString(key.getPubKey()));
|
||||||
System.out.println("Sender is\t\t: " + Hex.toHexString(key.getAddress()));
|
System.out.println("Sender is\t\t: " + Hex.toHexString(key.getAddress()));
|
||||||
|
@ -129,46 +121,89 @@ public class TransactionTest {
|
||||||
Hex.toHexString(key.getAddress()));
|
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
|
@Test
|
||||||
public void testTransactionFromRLP() {
|
public void testTransactionFromSignedRLP() throws Exception {
|
||||||
// from RLP encoding
|
Transaction txSigned = new Transaction(Hex.decode(RLP_ENCODED_SIGNED_TX));
|
||||||
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)));
|
|
||||||
|
|
||||||
assertEquals(HASH_RAW_TX, ByteUtil.toHexString(tx.getHash()));
|
assertEquals(HASH_TX, Hex.toHexString(txSigned.getHash()));
|
||||||
assertEquals(RLP_ENCODED_RAW_TX, ByteUtil.toHexString(tx.getEncoded()));
|
assertEquals(RLP_ENCODED_SIGNED_TX, Hex.toHexString(txSigned.getEncoded()));
|
||||||
assertEquals(RLP_ENCODED_SIGNED_TX, ByteUtil.toHexString(tx.getEncodedSigned()));
|
|
||||||
|
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
|
@Test
|
||||||
public void testTransactionFromRLP2() {
|
public void testTransactionFromNew2() throws MissingPrivateKeyException {
|
||||||
|
|
||||||
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 {
|
|
||||||
byte[] privKeyBytes = Hex.decode("c85ef7d79691fe79573b1a7064c19c1a9819ebdbd1faaab1a8ec92344438aaf4");
|
byte[] privKeyBytes = Hex.decode("c85ef7d79691fe79573b1a7064c19c1a9819ebdbd1faaab1a8ec92344438aaf4");
|
||||||
|
|
||||||
String RLP_TX_UNSIGNED = "e88085e8d4a510008227109413978aee95f38490e9769c39b2773ed763d9cd5f872386f26fc1000080";
|
String RLP_TX_UNSIGNED = "eb8085e8d4a510008227109413978aee95f38490e9769c39b2773ed763d9cd5f872386f26fc1000080808080";
|
||||||
String RLP_TX_SIGNED = "f86b8085e8d4a510008227109413978aee95f38490e9769c39b2773ed763d9cd5f872386f26fc10000801ba0eab47c1a49bf2fe5d40e01d313900e19ca485867d462fe06e139e3a536c6d4f4a014a569d327dcda4b29f74f93c0e9729d2f49ad726e703f9cd90dbb0fbf6649f1";
|
String RLP_TX_SIGNED = "f86b8085e8d4a510008227109413978aee95f38490e9769c39b2773ed763d9cd5f872386f26fc10000801ba0eab47c1a49bf2fe5d40e01d313900e19ca485867d462fe06e139e3a536c6d4f4a014a569d327dcda4b29f74f93c0e9729d2f49ad726e703f9cd90dbb0fbf6649f1";
|
||||||
String HASH_TX_UNSIGNED = "328ea6d24659dec48adea1aced9a136e5ebdf40258db30d1b1d97ed2b74be34e";
|
String HASH_TX_UNSIGNED = "328ea6d24659dec48adea1aced9a136e5ebdf40258db30d1b1d97ed2b74be34e";
|
||||||
|
|
||||||
|
@ -188,7 +223,7 @@ public class TransactionTest {
|
||||||
|
|
||||||
// Testing signed
|
// Testing signed
|
||||||
tx.sign(privKeyBytes);
|
tx.sign(privKeyBytes);
|
||||||
String encodedSigned = Hex.toHexString(tx.getEncodedSigned());
|
String encodedSigned = Hex.toHexString(tx.getEncoded());
|
||||||
assertEquals(RLP_TX_SIGNED, encodedSigned);
|
assertEquals(RLP_TX_SIGNED, encodedSigned);
|
||||||
assertEquals(HASH_TX_UNSIGNED, Hex.toHexString(tx.getHash()));
|
assertEquals(HASH_TX_UNSIGNED, Hex.toHexString(tx.getHash()));
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,7 +40,7 @@ public class ECKeyTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testHashCode() {
|
public void testHashCode() {
|
||||||
fail("Not yet implemented");
|
assertEquals(1866897155, ECKey.fromPrivate(privateKey).hashCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -48,7 +48,6 @@ public class MessagesTest {
|
||||||
helloMessage.parseRLP();
|
helloMessage.parseRLP();
|
||||||
System.out.println(helloMessage);
|
System.out.println(helloMessage);
|
||||||
|
|
||||||
|
|
||||||
assertEquals(12, helloMessage.getProtocolVersion());
|
assertEquals(12, helloMessage.getProtocolVersion());
|
||||||
assertEquals(0, helloMessage.getNetworkId());
|
assertEquals(0, helloMessage.getNetworkId());
|
||||||
assertEquals("Ethereum(++)/ZeroGox/v0.5.1/ncurses/Linux/g++", helloMessage.getClientId());
|
assertEquals("Ethereum(++)/ZeroGox/v0.5.1/ncurses/Linux/g++", helloMessage.getClientId());
|
||||||
|
@ -60,7 +59,7 @@ public class MessagesTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test /* HelloMessage 2 */
|
@Test /* HelloMessage 2 */
|
||||||
public void test_2(){
|
public void test_2() {
|
||||||
|
|
||||||
String helloMessageRaw = "F87F800B80B5457468657265756D282B2B292F76302E342E332F4554485F4255494C445F545950452F4554485F4255494C445F504C4154464F524D0782765FB840E02B18FBA6B887FB9258469C3AF8E445CC9AE2B5386CAC5F60C4170F822086224E3876555C745A7EC8AC181C7F9701776D94A779604EA12651DE5F4A748D29E1";
|
String helloMessageRaw = "F87F800B80B5457468657265756D282B2B292F76302E342E332F4554485F4255494C445F545950452F4554485F4255494C445F504C4154464F524D0782765FB840E02B18FBA6B887FB9258469C3AF8E445CC9AE2B5386CAC5F60C4170F822086224E3876555C745A7EC8AC181C7F9701776D94A779604EA12651DE5F4A748D29E1";
|
||||||
byte[] payload = Hex.decode(helloMessageRaw);
|
byte[] payload = Hex.decode(helloMessageRaw);
|
||||||
|
@ -179,11 +178,14 @@ public class MessagesTest {
|
||||||
/* TRANSACTIONS */
|
/* TRANSACTIONS */
|
||||||
|
|
||||||
@Test /* Transactions message 1 */
|
@Test /* Transactions message 1 */
|
||||||
public void test_8(){
|
public void test_8() {
|
||||||
|
|
||||||
String transactionsPacketRaw = "F86E12F86B04881BC16D674EC8000094CD2A3D9F938E13CD947EC05ABC7FE734DF8DD8268609184E72A00064801BA05E3868194605F1647593B842725818CCFA6A38651A728715133A8E97CDCFAC54A00FF91628D04B215EBCCFD5F4FC34CC1B45DF32F6B4609FBB0DE42E8522264467";
|
String txsPacketRaw = "f86e12f86b04648609184e72a00094cd2a3d9f938e13cd947ec05abc7fe734df8dd826"
|
||||||
|
+ "881bc16d674ec80000801ba05c89ebf2b77eeab88251e553f6f9d53badc1d800"
|
||||||
byte[] payload = Hex.decode(transactionsPacketRaw);
|
+ "bbac02d830801c2aa94a4c9fa00b7907532b1f29c79942b75fff98822293bf5f"
|
||||||
|
+ "daa3653a8d9f424c6a3265f06c";
|
||||||
|
|
||||||
|
byte[] payload = Hex.decode(txsPacketRaw);
|
||||||
RLPList rlpList = RLP.decode2(payload);
|
RLPList rlpList = RLP.decode2(payload);
|
||||||
|
|
||||||
TransactionsMessage transactionsMessage = new TransactionsMessage(rlpList);
|
TransactionsMessage transactionsMessage = new TransactionsMessage(rlpList);
|
||||||
|
@ -191,49 +193,45 @@ public class MessagesTest {
|
||||||
|
|
||||||
assertEquals(1, transactionsMessage.getTransactions().size());
|
assertEquals(1, transactionsMessage.getTransactions().size());
|
||||||
|
|
||||||
Transaction tx =
|
Transaction tx = transactionsMessage.getTransactions().get(0);
|
||||||
transactionsMessage.getTransactions().get(0);
|
|
||||||
|
|
||||||
assertEquals("558A3797E0DD3FBFAF761F1ADD6749C7D5DB313FDAC5CBA59F40E28AF7BBACD1",
|
assertEquals("5d2aee0490a9228024158433d650335116b4af5a30b8abb10e9b7f9f7e090fd8", Hex.toHexString(tx.getHash()));
|
||||||
Hex.toHexString( tx.getHash() ).toUpperCase());
|
assertEquals("04", Hex.toHexString(tx.getNonce()));
|
||||||
|
assertEquals("1bc16d674ec80000", Hex.toHexString(tx.getValue()));
|
||||||
assertEquals("04",
|
assertEquals("cd2a3d9f938e13cd947ec05abc7fe734df8dd826", Hex.toHexString(tx.getReceiveAddress()));
|
||||||
Hex.toHexString( tx.getNonce() ).toUpperCase());
|
assertEquals("64", Hex.toHexString(tx.getGasPrice()));
|
||||||
|
assertEquals("09184e72a000", Hex.toHexString(tx.getGasLimit()));
|
||||||
assertEquals("1BC16D674EC80000",
|
assertEquals("null", ByteUtil.toHexString(tx.getData()));
|
||||||
Hex.toHexString( tx.getValue() ).toUpperCase());
|
assertEquals("null", ByteUtil.toHexString(tx.getInit()));
|
||||||
|
assertEquals("1b", Hex.toHexString(new byte[] { tx.getSignature().v }));
|
||||||
assertEquals("CD2A3D9F938E13CD947EC05ABC7FE734DF8DD826",
|
assertEquals("5c89ebf2b77eeab88251e553f6f9d53badc1d800bbac02d830801c2aa94a4c9f", Hex.toHexString(tx.getSignature().r.toByteArray()));
|
||||||
Hex.toHexString( tx.getReceiveAddress() ).toUpperCase());
|
assertEquals("0b7907532b1f29c79942b75fff98822293bf5fdaa3653a8d9f424c6a3265f06c", Hex.toHexString(tx.getSignature().s.toByteArray()));
|
||||||
|
|
||||||
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());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test /* Transactions message 2 */
|
@Test /* Transactions message 2 */
|
||||||
public void test_9(){
|
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);
|
RLPList rlpList = RLP.decode2(payload);
|
||||||
|
|
||||||
TransactionsMessage transactionsMessage = new TransactionsMessage(rlpList);
|
TransactionsMessage transactionsMessage = new TransactionsMessage(rlpList);
|
||||||
|
@ -244,73 +242,73 @@ public class MessagesTest {
|
||||||
Transaction tx =
|
Transaction tx =
|
||||||
transactionsMessage.getTransactions().get(0);
|
transactionsMessage.getTransactions().get(0);
|
||||||
|
|
||||||
assertEquals("4B7D9670A92BF120D5B43400543B69304A14D767CF836A7F6ABFF4EDDE092895",
|
assertEquals("4b7d9670a92bf120d5b43400543b69304a14d767cf836a7f6abff4edde092895",
|
||||||
Hex.toHexString( tx.getHash() ).toUpperCase());
|
Hex.toHexString( tx.getHash() ));
|
||||||
|
|
||||||
|
assertEquals("null",
|
||||||
|
Hex.toHexString( tx.getNonce() ));
|
||||||
|
|
||||||
assertEquals("NULL",
|
assertEquals("NULL",
|
||||||
Hex.toHexString( tx.getNonce() ).toUpperCase());
|
Hex.toHexString( tx.getValue() ));
|
||||||
|
|
||||||
assertEquals("NULL",
|
|
||||||
Hex.toHexString( tx.getValue() ).toUpperCase());
|
|
||||||
|
|
||||||
assertEquals("0000000000000000000000000000000000000000",
|
assertEquals("0000000000000000000000000000000000000000",
|
||||||
Hex.toHexString( tx.getReceiveAddress() ).toUpperCase());
|
Hex.toHexString( tx.getReceiveAddress() ));
|
||||||
|
|
||||||
assertEquals("09184E72A000",
|
assertEquals("09184e72a000",
|
||||||
Hex.toHexString( tx.getGasPrice() ).toUpperCase());
|
Hex.toHexString( tx.getGasPrice() ));
|
||||||
|
|
||||||
assertEquals("2710",
|
assertEquals("2710",
|
||||||
Hex.toHexString( tx.getGasLimit() ).toUpperCase());
|
Hex.toHexString( tx.getGasLimit() ));
|
||||||
|
|
||||||
assertEquals("606956330C0D630000003359366000530A0D630000003359602060005301356000533557604060005301600054630000000C58",
|
assertEquals("606956330c0d630000003359366000530a0d630000003359602060005301356000533557604060005301600054630000000c58",
|
||||||
Hex.toHexString( tx.getData() ).toUpperCase());
|
Hex.toHexString( tx.getData() ));
|
||||||
|
|
||||||
assertEquals("33606957",
|
assertEquals("33606957",
|
||||||
Hex.toHexString( tx.getInit() ).toUpperCase());
|
Hex.toHexString( tx.getInit() ));
|
||||||
|
|
||||||
assertEquals("1C",
|
assertEquals("1c",
|
||||||
Hex.toHexString( new byte[] {tx.getSignature().v} ).toUpperCase());
|
Hex.toHexString( new byte[] {tx.getSignature().v} ));
|
||||||
|
|
||||||
assertEquals("7F6EB94576346488C6253197BDE6A7E59DDC36F2773672C849402AA9C402C3C4",
|
assertEquals("7f6eb94576346488c6253197bde6a7e59ddc36f2773672c849402aa9c402c3c4",
|
||||||
Hex.toHexString( tx.getSignature().r.toByteArray() ).toUpperCase());
|
Hex.toHexString( tx.getSignature().r.toByteArray() ));
|
||||||
|
|
||||||
assertEquals("6D254E662BF7450DD8D835160CBB053463FED0B53F2CDD7F3EA8731919C8E8CC",
|
assertEquals("6d254e662bf7450dd8d835160cbb053463fed0b53f2cdd7f3ea8731919c8e8cc",
|
||||||
Hex.toHexString( tx.getSignature().s.toByteArray() ).toUpperCase());
|
Hex.toHexString( tx.getSignature().s.toByteArray() ));
|
||||||
|
|
||||||
tx = transactionsMessage.getTransactions().get(2);
|
tx = transactionsMessage.getTransactions().get(2);
|
||||||
|
|
||||||
assertEquals("B0251A1BB20B44459DB5B5444AB53EDD9E12C46D0BA07FA401A797BEB967D53C",
|
assertEquals("b0251a1bb20b44459db5b5444ab53edd9e12c46d0ba07fa401a797beb967d53c",
|
||||||
Hex.toHexString( tx.getHash() ).toUpperCase());
|
Hex.toHexString( tx.getHash() ));
|
||||||
|
|
||||||
assertEquals("02",
|
assertEquals("02",
|
||||||
Hex.toHexString( tx.getNonce() ).toUpperCase());
|
Hex.toHexString( tx.getNonce() ));
|
||||||
|
|
||||||
assertEquals("NULL",
|
assertEquals("null",
|
||||||
Hex.toHexString( tx.getValue() ).toUpperCase());
|
Hex.toHexString( tx.getValue() ));
|
||||||
|
|
||||||
assertEquals("CCDEAC59D35627B7DE09332E819D5159E7BB7250",
|
assertEquals("ccdeac59d35627b7de09332e819d5159e7bb7250",
|
||||||
Hex.toHexString( tx.getReceiveAddress() ).toUpperCase());
|
Hex.toHexString( tx.getReceiveAddress() ));
|
||||||
|
|
||||||
assertEquals("09184E72A000",
|
assertEquals("09184e72a000",
|
||||||
Hex.toHexString( tx.getGasPrice() ).toUpperCase());
|
Hex.toHexString( tx.getGasPrice() ));
|
||||||
|
|
||||||
assertEquals("2710",
|
assertEquals("2710",
|
||||||
Hex.toHexString( tx.getGasLimit() ).toUpperCase());
|
Hex.toHexString( tx.getGasLimit() ));
|
||||||
|
|
||||||
assertEquals("00000000000000000000000000000000000000000000000000000000000000000000000000000000000000002D0ACEEE7E5AB874E22CCF8D1A649F59106D74E8",
|
assertEquals("00000000000000000000000000000000000000000000000000000000000000000000000000000000000000002d0aceee7e5ab874e22ccf8d1a649f59106d74e8",
|
||||||
Hex.toHexString( tx.getData() ).toUpperCase());
|
Hex.toHexString( tx.getData() ));
|
||||||
|
|
||||||
assertEquals("NULL",
|
assertEquals("null",
|
||||||
Hex.toHexString( tx.getInit() ).toUpperCase());
|
Hex.toHexString( tx.getInit() ));
|
||||||
|
|
||||||
assertEquals("1B",
|
assertEquals("1b",
|
||||||
Hex.toHexString( new byte[] {tx.getSignature().v} ).toUpperCase());
|
Hex.toHexString( new byte[] {tx.getSignature().v} ));
|
||||||
|
|
||||||
assertEquals("D05887574456C6DE8F7A0D172342C2CBDD4CF7AFE15D9DBB8B75B748BA6791C9",
|
assertEquals("d05887574456c6de8f7a0d172342c2cbdd4cf7afe15d9dbb8b75b748ba6791c9",
|
||||||
Hex.toHexString( tx.getSignature().r.toByteArray() ).toUpperCase());
|
Hex.toHexString( tx.getSignature().r.toByteArray() ));
|
||||||
|
|
||||||
assertEquals("1E87172A861F6C37B5A9E3A5D0D7393152A7FBE41530E5BB8AC8F35433E5931B",
|
assertEquals("1e87172a861f6c37b5a9e3a5d0d7393152a7fbe41530e5bb8ac8f35433e5931b",
|
||||||
Hex.toHexString(tx.getSignature().s.toByteArray()).toUpperCase());
|
Hex.toHexString(tx.getSignature().s.toByteArray()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* BLOCKS */
|
/* BLOCKS */
|
||||||
|
@ -534,7 +532,7 @@ public class MessagesTest {
|
||||||
ecKey.getAddress(), gasPrice, gas, null);
|
ecKey.getAddress(), gasPrice, gas, null);
|
||||||
|
|
||||||
tx.sign(privKey);
|
tx.sign(privKey);
|
||||||
tx.getEncodedSigned();
|
tx.getEncoded();
|
||||||
|
|
||||||
List<Transaction> txList = new ArrayList<Transaction>();
|
List<Transaction> txList = new ArrayList<Transaction>();
|
||||||
txList.add(tx);
|
txList.add(tx);
|
||||||
|
|
|
@ -737,7 +737,6 @@ public class SerpentCompileTest {
|
||||||
Assert.assertEquals(expected, result);
|
Assert.assertEquals(expected, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test // if elif else test 13
|
@Test // if elif else test 13
|
||||||
public void test28(){
|
public void test28(){
|
||||||
|
|
||||||
|
@ -775,7 +774,6 @@ public class SerpentCompileTest {
|
||||||
Assert.assertEquals(expected, result);
|
Assert.assertEquals(expected, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test // if elif else test 14
|
@Test // if elif else test 14
|
||||||
public void test29(){
|
public void test29(){
|
||||||
|
|
||||||
|
@ -913,7 +911,6 @@ public class SerpentCompileTest {
|
||||||
Assert.fail("Should be indent error thrown");
|
Assert.fail("Should be indent error thrown");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test // if elif else test 19
|
@Test // if elif else test 19
|
||||||
public void test34(){
|
public void test34(){
|
||||||
|
|
||||||
|
@ -957,8 +954,6 @@ public class SerpentCompileTest {
|
||||||
Assert.assertEquals(expected, result);
|
Assert.assertEquals(expected, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Test // if elif else test 20
|
@Test // if elif else test 20
|
||||||
public void test35(){
|
public void test35(){
|
||||||
|
|
||||||
|
@ -1003,7 +998,6 @@ public class SerpentCompileTest {
|
||||||
Assert.assertEquals(expected, result);
|
Assert.assertEquals(expected, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test // while test 1
|
@Test // while test 1
|
||||||
public void test36(){
|
public void test36(){
|
||||||
|
|
||||||
|
@ -1075,7 +1069,6 @@ public class SerpentCompileTest {
|
||||||
Assert.assertEquals(expected, result);
|
Assert.assertEquals(expected, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test // while test 3
|
@Test // while test 3
|
||||||
public void test38(){
|
public void test38(){
|
||||||
|
|
||||||
|
@ -1218,11 +1211,8 @@ public class SerpentCompileTest {
|
||||||
|
|
||||||
Assert.assertEquals(expected, result);
|
Assert.assertEquals(expected, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
*
|
||||||
a = msg.datasize
|
a = msg.datasize
|
||||||
b = msg.sender
|
b = msg.sender
|
||||||
c = msg.value
|
c = msg.value
|
||||||
|
|
|
@ -33,7 +33,7 @@ public class RLPTest {
|
||||||
"E0 DE 49 98 33 4F 3B CF 73 FA 11 7E F2 13 F8 74 " +
|
"E0 DE 49 98 33 4F 3B CF 73 FA 11 7E F2 13 F8 74 " +
|
||||||
"17 08 9F EA F8 4C 21 B0";
|
"17 08 9F EA F8 4C 21 B0";
|
||||||
|
|
||||||
byte[] payload = ByteUtil.hexStringToByteArr(peersPacket);
|
byte[] payload = Hex.decode(peersPacket);
|
||||||
|
|
||||||
byte[] ip = RLP.decodeIP4Bytes(payload, 5);
|
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 " +
|
"E0 DE 49 98 33 4F 3B CF 73 FA 11 7E F2 13 F8 74 " +
|
||||||
"17 08 9F EA F8 4C 21 B0";
|
"17 08 9F EA F8 4C 21 B0";
|
||||||
|
|
||||||
byte[] payload = ByteUtil.hexStringToByteArr(peersPacket);
|
byte[] payload = Hex.decode(peersPacket);
|
||||||
int oneInt = RLP.decodeInt(payload, 11);
|
int oneInt = RLP.decodeInt(payload, 11);
|
||||||
|
|
||||||
assertEquals(oneInt, 30303);
|
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 " +
|
"98 33 4F 3B CF 73 FA 11 7E F2 13 F8 74 17 08 9F " +
|
||||||
"EA F8 4C 21 B0 ";
|
"EA F8 4C 21 B0 ";
|
||||||
|
|
||||||
byte[] payload = ByteUtil.hexStringToByteArr(peersPacket);
|
byte[] payload = Hex.decode(peersPacket);
|
||||||
|
|
||||||
int nextIndex = 5;
|
int nextIndex = 5;
|
||||||
byte[] ip = RLP.decodeIP4Bytes(payload, nextIndex);
|
byte[] ip = RLP.decodeIP4Bytes(payload, nextIndex);
|
||||||
|
@ -212,17 +212,14 @@ public class RLPTest {
|
||||||
@Test /** encode byte array */
|
@Test /** encode byte array */
|
||||||
public void test8(){
|
public void test8(){
|
||||||
|
|
||||||
String byteArr = "CE 73 66 0A 06 62 6C 1B 3F DA 7B 18 EF 7B A3 CE " +
|
String byteArr = "ce73660a06626c1b3fda7b18ef7ba3ce17b6bf604f9541d3c6c654b7ae88b239"
|
||||||
"17 B6 BF 60 4F 95 41 D3 C6 C6 54 B7 AE 88 B2 39 " +
|
+ "407f659c78f419025d785727ed017b6add21952d7e12007373e321dbc31824ba";
|
||||||
"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 ";
|
|
||||||
|
|
||||||
byte[] byteArray = ByteUtil.hexStringToByteArr(byteArr);
|
byte[] byteArray = Hex.decode(byteArr);
|
||||||
|
|
||||||
String expected = "B8 40 " + byteArr;
|
String expected = "b840" + byteArr;
|
||||||
|
|
||||||
assertArrayEquals(ByteUtil.hexStringToByteArr(expected),
|
assertEquals(expected, Hex.toHexString(RLP.encodeElement(byteArray)));
|
||||||
RLP.encodeElement(byteArray));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test /** encode list */
|
@Test /** encode list */
|
||||||
|
@ -717,9 +714,4 @@ public class RLPTest {
|
||||||
oos.close();
|
oos.close();
|
||||||
return baos.size();
|
return baos.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,6 +1,5 @@
|
||||||
package org.ethereum.util;
|
package org.ethereum.util;
|
||||||
|
|
||||||
import junit.framework.Assert;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.spongycastle.util.encoders.Hex;
|
import org.spongycastle.util.encoders.Hex;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue