Cleanup code
This commit is contained in:
parent
f4ae933ab3
commit
96773417ff
|
@ -27,7 +27,6 @@ import java.util.Arrays;
|
|||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import org.ethereum.util.ByteUtil;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.spongycastle.asn1.sec.SECNamedCurves;
|
||||
|
@ -298,6 +297,12 @@ public class ECKey implements Serializable {
|
|||
return new ECDSASignature(new BigInteger(r), new BigInteger(s));
|
||||
}
|
||||
|
||||
public static ECDSASignature fromComponents(byte[] r, byte[] s, byte v) {
|
||||
ECDSASignature signature = new ECDSASignature(new BigInteger(r), new BigInteger(s));
|
||||
signature.v = v;
|
||||
return signature;
|
||||
}
|
||||
|
||||
/**
|
||||
* Will automatically adjust the S component to be less than or equal to half the curve order, if necessary.
|
||||
* This is required because for every signature (r,s) the signature (r, -s (mod N)) is a valid signature of
|
||||
|
|
|
@ -16,11 +16,9 @@ public class IpGeoDB { // change
|
|||
|
||||
static{
|
||||
try {
|
||||
|
||||
URL geiIpDBFile = ClassLoader.getSystemResource("GeoLiteCity.dat");
|
||||
File file = new File(geiIpDBFile.toURI());
|
||||
cl = new LookupService(file);
|
||||
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
@ -28,17 +26,14 @@ public class IpGeoDB { // change
|
|||
|
||||
private static LookupService cl;
|
||||
|
||||
|
||||
public static Location getLocationForIp(InetAddress ip){
|
||||
try {
|
||||
return cl.getLocation(ip);
|
||||
} catch (Throwable e) {
|
||||
|
||||
// todo: think about this exception, maybe you can do something more reasonable
|
||||
System.out.println(e.getMessage());
|
||||
// e.printStackTrace();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,9 +3,9 @@ package org.ethereum.manager;
|
|||
import com.maxmind.geoip.Location;
|
||||
|
||||
import org.ethereum.geodb.IpGeoDB;
|
||||
import org.ethereum.net.vo.BlockData;
|
||||
import org.ethereum.net.vo.Block;
|
||||
import org.ethereum.net.vo.PeerData;
|
||||
import org.ethereum.net.vo.TransactionData;
|
||||
import org.ethereum.net.vo.Transaction;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
|
@ -30,6 +30,6 @@ public class MainData {
|
|||
}
|
||||
}
|
||||
|
||||
public void addBlocks(List<BlockData> blocks) {}
|
||||
public void addTransactions(List<TransactionData> transactions) {}
|
||||
public void addBlocks(List<Block> blocks) {}
|
||||
public void addTransactions(List<Transaction> transactions) {}
|
||||
}
|
||||
|
|
|
@ -15,75 +15,51 @@ public class MessageDeserializer {
|
|||
int pos = startPos;
|
||||
|
||||
while(pos < endPos){
|
||||
|
||||
// It's a list with a payload more than 55 bytes
|
||||
// data[0] - 0xF7 = how many next bytes allocated
|
||||
// for the length of the list
|
||||
if ((msgData[pos] & 0xFF) >= 0xF7){
|
||||
|
||||
byte lenghtOfLenght = (byte) (msgData[pos] - 0xF7);
|
||||
byte pow = (byte) (lenghtOfLenght - 1);
|
||||
|
||||
int length = 0;
|
||||
for (int i = 1; i <= lenghtOfLenght; ++i){
|
||||
length += msgData[pos + i] << (8 * pow);
|
||||
pow--;
|
||||
}
|
||||
|
||||
byte lengthOfLength = (byte) (msgData[pos] - 0xF7);
|
||||
int length = calcLength(lengthOfLength, msgData, pos);
|
||||
// now we can parse an item for data[1]..data[length]
|
||||
System.out.println("-- level: [" + level + "] Found big list length: " + length);
|
||||
deserialize(msgData, level + 1, pos + lenghtOfLenght + 1, pos + lenghtOfLenght + length);
|
||||
pos += lenghtOfLenght + length + 1 ;
|
||||
deserialize(msgData, level + 1, pos + lengthOfLength + 1, pos + lengthOfLength + length);
|
||||
pos += lengthOfLength + length + 1 ;
|
||||
continue;
|
||||
}
|
||||
|
||||
// It's a list with a payload less than 55 bytes
|
||||
if ((msgData[pos] & 0xFF) >= 0xC0 && (msgData[pos] & 0xFF) < 0xF7){
|
||||
|
||||
byte length = (byte) (msgData[pos] - 0xC0);
|
||||
System.out.println("-- level: [" + level + "] Found small list length: " + length);
|
||||
deserialize(msgData, level + 1, pos + 1, pos + length + 1);
|
||||
pos += 1 + length;
|
||||
continue;
|
||||
}
|
||||
|
||||
// It's an item with a payload more than 55 bytes
|
||||
// data[0] - 0xB7 = how much next bytes allocated for
|
||||
// the length of the string
|
||||
if ((msgData[pos] & 0xFF) >= 0xB7 && (msgData[pos] & 0xFF) < 0xC0) {
|
||||
|
||||
byte lenghtOfLenght = (byte) (msgData[pos] - 0xB7);
|
||||
byte pow = (byte) (lenghtOfLenght - 1);
|
||||
|
||||
int length = 0;
|
||||
for (int i = 1; i <= lenghtOfLenght; ++i){
|
||||
length += msgData[pos + i] << (8 * pow);
|
||||
pow--;
|
||||
}
|
||||
byte lengthOfLength = (byte) (msgData[pos] - 0xB7);
|
||||
int length = calcLength(lengthOfLength, msgData, pos);
|
||||
// now we can parse an item for data[1]..data[length]
|
||||
System.out.println("-- level: [" + level + "] Found big item length: " + length);
|
||||
pos += lenghtOfLenght + length + 1 ;
|
||||
pos += lengthOfLength + length + 1 ;
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
// It's an item less than 55 bytes long,
|
||||
// data[0] - 0x80 == lenght of the item
|
||||
if ((msgData[pos] & 0xFF) > 0x80 && (msgData[pos] & 0xFF) < 0xB7) {
|
||||
|
||||
byte length = (byte) (msgData[pos] - 0x80);
|
||||
System.out.println("-- level: [" + level + "] Found small item length: " + length);
|
||||
pos += 1 + length;
|
||||
continue;
|
||||
}
|
||||
|
||||
// null item
|
||||
if ((msgData[pos] & 0xFF) == 0x80){
|
||||
System.out.println("-- level: [" + level + "] Found null item: ");
|
||||
pos += 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
// single byte item
|
||||
if ((msgData[pos] & 0xFF) < 0x80) {
|
||||
System.out.println("-- level: [" + level + "] Found single item: ");
|
||||
|
@ -92,4 +68,14 @@ public class MessageDeserializer {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static int calcLength(int lengthOfLength, byte[] msgData, int pos) {
|
||||
byte pow = (byte) (lengthOfLength - 1);
|
||||
int length = 0;
|
||||
for (int i = 1; i <= lengthOfLength; ++i){
|
||||
length += msgData[pos + i] << (8 * pow);
|
||||
pow--;
|
||||
}
|
||||
return length;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,7 +35,7 @@ import org.ethereum.net.message.PeersMessage;
|
|||
import org.ethereum.net.message.StaticMessages;
|
||||
import org.ethereum.net.message.TransactionsMessage;
|
||||
import org.ethereum.net.rlp.RLPList;
|
||||
import org.ethereum.net.vo.BlockData;
|
||||
import org.ethereum.net.vo.Block;
|
||||
import org.ethereum.util.Utils;
|
||||
import org.spongycastle.util.encoders.Hex;
|
||||
|
||||
|
@ -266,7 +266,7 @@ public class EthereumProtocolHandler extends ChannelInboundHandlerAdapter {
|
|||
RLP.parseObjects(payload, rlpList);
|
||||
|
||||
BlocksMessage blocksMessage = new BlocksMessage(rlpList);
|
||||
List<BlockData> blockList = blocksMessage.getBlockDataList();
|
||||
List<Block> blockList = blocksMessage.getBlockDataList();
|
||||
|
||||
MainData.instance.addBlocks(blockList);
|
||||
System.out.println(blocksMessage);
|
||||
|
|
|
@ -8,8 +8,8 @@ import static org.ethereum.net.Command.BLOCKS;
|
|||
import org.ethereum.net.Command;
|
||||
import org.ethereum.net.rlp.RLPItem;
|
||||
import org.ethereum.net.rlp.RLPList;
|
||||
import org.ethereum.net.vo.BlockData;
|
||||
import org.ethereum.net.vo.TransactionData;
|
||||
import org.ethereum.net.vo.Block;
|
||||
import org.ethereum.net.vo.Transaction;
|
||||
|
||||
/**
|
||||
* www.ethereumJ.com
|
||||
|
@ -18,7 +18,7 @@ import org.ethereum.net.vo.TransactionData;
|
|||
*/
|
||||
public class BlocksMessage extends Message {
|
||||
|
||||
private List<BlockData> blockDataList = new ArrayList<BlockData>();
|
||||
private List<Block> blockDataList = new ArrayList<Block>();
|
||||
|
||||
public BlocksMessage(RLPList rawData) {
|
||||
super(rawData);
|
||||
|
@ -34,7 +34,7 @@ public class BlocksMessage extends Message {
|
|||
|
||||
for (int i = 1; i < paramsList.size(); ++i){
|
||||
RLPList rlpData = ((RLPList)paramsList.getElement(i));
|
||||
BlockData blockData = new BlockData(rlpData);
|
||||
Block blockData = new Block(rlpData);
|
||||
this.blockDataList.add(blockData);
|
||||
}
|
||||
parsed = true;
|
||||
|
@ -45,7 +45,7 @@ public class BlocksMessage extends Message {
|
|||
return null;
|
||||
}
|
||||
|
||||
public List<BlockData> getBlockDataList() {
|
||||
public List<Block> getBlockDataList() {
|
||||
if (!parsed) parseRLP();
|
||||
return blockDataList;
|
||||
}
|
||||
|
@ -53,11 +53,11 @@ public class BlocksMessage extends Message {
|
|||
public String toString() {
|
||||
|
||||
StringBuffer sb = new StringBuffer();
|
||||
for (BlockData blockData : this.getBlockDataList()){
|
||||
for (Block blockData : this.getBlockDataList()){
|
||||
sb.append(" ").append( blockData.toString() ).append("\n");
|
||||
|
||||
List<TransactionData> transactions = blockData.getTransactionsList();
|
||||
for (TransactionData transactionData : transactions){
|
||||
List<Transaction> transactions = blockData.getTransactionsList();
|
||||
for (Transaction transactionData : transactions){
|
||||
sb.append("[").append(transactionData).append("]\n");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -46,9 +46,7 @@ public class StaticMessages {
|
|||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x03,
|
||||
(byte) 0xC2, (byte) 0x01, (byte) 0x08};
|
||||
|
||||
|
||||
public static final byte[] GET_CHAIN = {
|
||||
|
||||
(byte) 0x22, (byte) 0x40, (byte) 0x08, (byte) 0x91, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x27,
|
||||
(byte) 0xF8, (byte) 0x25, (byte) 0x14, (byte) 0xA0, (byte) 0xAB, (byte) 0x6B, (byte) 0x9A, (byte) 0x56, (byte) 0x13,
|
||||
(byte) 0x97, (byte) 0x0F, (byte) 0xAA, (byte) 0x77, (byte) 0x1B, (byte) 0x12, (byte) 0xD4, (byte) 0x49,
|
||||
|
|
|
@ -4,7 +4,7 @@ import static org.ethereum.net.Command.TRANSACTIONS;
|
|||
import org.ethereum.net.Command;
|
||||
import org.ethereum.net.rlp.RLPItem;
|
||||
import org.ethereum.net.rlp.RLPList;
|
||||
import org.ethereum.net.vo.TransactionData;
|
||||
import org.ethereum.net.vo.Transaction;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
@ -16,7 +16,7 @@ import java.util.List;
|
|||
*/
|
||||
public class TransactionsMessage extends Message {
|
||||
|
||||
private List<TransactionData> transactions = new ArrayList<TransactionData>();
|
||||
private List<Transaction> transactions = new ArrayList<Transaction>();
|
||||
|
||||
public TransactionsMessage() {
|
||||
}
|
||||
|
@ -33,17 +33,17 @@ public class TransactionsMessage extends Message {
|
|||
throw new Error("TransactionMessage: parsing for mal data");
|
||||
}
|
||||
|
||||
transactions = new ArrayList<TransactionData>();
|
||||
transactions = new ArrayList<Transaction>();
|
||||
int size = paramsList.getList().size();
|
||||
for (int i = 1; i < size; ++i){
|
||||
RLPList rlpTxData = (RLPList) paramsList.getElement(i);
|
||||
TransactionData tx = new TransactionData(rlpTxData);
|
||||
Transaction tx = new Transaction(rlpTxData);
|
||||
transactions.add(tx);
|
||||
}
|
||||
parsed = true;
|
||||
}
|
||||
|
||||
public List<TransactionData> getTransactions() {
|
||||
public List<Transaction> getTransactions() {
|
||||
if (!parsed) parseRLP();
|
||||
return transactions;
|
||||
}
|
||||
|
@ -56,7 +56,7 @@ public class TransactionsMessage extends Message {
|
|||
public String toString(){
|
||||
if(!parsed) parseRLP();
|
||||
StringBuffer sb = new StringBuffer();
|
||||
for (TransactionData transactionData : transactions){
|
||||
for (Transaction transactionData : transactions){
|
||||
sb.append(" ").append(transactionData).append("\n");
|
||||
}
|
||||
return "Transactions Message [\n" + sb.toString() + " ]";
|
||||
|
|
|
@ -7,7 +7,6 @@ import org.ethereum.net.rlp.RLPList;
|
|||
import org.ethereum.util.Utils;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -16,10 +15,10 @@ import java.util.List;
|
|||
* User: Roman Mandeleil
|
||||
* Created on: 13/04/14 19:34
|
||||
*/
|
||||
public class BlockData {
|
||||
public class Block {
|
||||
|
||||
RLPList rawData;
|
||||
boolean parsed = false;
|
||||
private RLPList rawData;
|
||||
private boolean parsed = false;
|
||||
|
||||
private byte[] hash;
|
||||
private byte[] parentHash;
|
||||
|
@ -33,15 +32,15 @@ public class BlockData {
|
|||
private byte[] extraData;
|
||||
private byte[] nonce;
|
||||
|
||||
List<TransactionData> transactionsList = new ArrayList<TransactionData>();
|
||||
List<BlockData> uncleList = new ArrayList<BlockData>();
|
||||
List<Transaction> transactionsList = new ArrayList<Transaction>();
|
||||
List<Block> uncleList = new ArrayList<Block>();
|
||||
|
||||
public BlockData(RLPList rawData) {
|
||||
public Block(RLPList rawData) {
|
||||
this.rawData = rawData;
|
||||
this.parsed = false;
|
||||
}
|
||||
|
||||
public BlockData(byte[] parentHash, byte[] unclesHash, byte[] coinbase, byte[] stateHash, byte[] txListHash, byte[] difficulty, long timestamp, byte[] extraData, byte[] nonce, List<TransactionData> transactionsList, List uncleList) {
|
||||
public Block(byte[] parentHash, byte[] unclesHash, byte[] coinbase, byte[] stateHash, byte[] txListHash, byte[] difficulty, long timestamp, byte[] extraData, byte[] nonce, List<Transaction> transactionsList, List<Block> uncleList) {
|
||||
this.parentHash = parentHash;
|
||||
this.unclesHash = unclesHash;
|
||||
this.coinbase = coinbase;
|
||||
|
@ -54,7 +53,6 @@ public class BlockData {
|
|||
this.transactionsList = transactionsList;
|
||||
this.uncleList = uncleList;
|
||||
this.parsed = true;
|
||||
|
||||
}
|
||||
|
||||
// [parent_hash, uncles_hash, coinbase, state_root, tx_list_hash, difficulty, timestamp, extradata, nonce]
|
||||
|
@ -76,24 +74,18 @@ public class BlockData {
|
|||
this.extraData = ((RLPItem) params.get(7)).getData();
|
||||
this.nonce = ((RLPItem) params.get(8)).getData();
|
||||
|
||||
|
||||
// parse transactions
|
||||
List<RLPElement> transactions = ((RLPList) rawData.getElement(1)).getList();
|
||||
|
||||
for (RLPElement rlpTx : transactions){
|
||||
|
||||
TransactionData tx = new TransactionData((RLPList)rlpTx);
|
||||
Transaction tx = new Transaction((RLPList)rlpTx);
|
||||
this.transactionsList.add(tx);
|
||||
}
|
||||
|
||||
// parse uncles
|
||||
List<RLPElement> uncleBlocks = ((RLPList) rawData.getElement(2)).getList();
|
||||
for (RLPElement rawUncle : uncleBlocks){
|
||||
|
||||
BlockData blockData = new BlockData((RLPList)rawUncle);
|
||||
Block blockData = new Block((RLPList)rawUncle);
|
||||
this.uncleList.add(blockData);
|
||||
}
|
||||
|
||||
this.parsed = true;
|
||||
}
|
||||
|
||||
|
@ -148,12 +140,12 @@ public class BlockData {
|
|||
return nonce;
|
||||
}
|
||||
|
||||
public List<TransactionData> getTransactionsList() {
|
||||
public List<Transaction> getTransactionsList() {
|
||||
if (!parsed) parseRLP();
|
||||
return transactionsList;
|
||||
}
|
||||
|
||||
public List<BlockData> getUncleList() {
|
||||
public List<Block> getUncleList() {
|
||||
if (!parsed) parseRLP();
|
||||
return uncleList;
|
||||
}
|
|
@ -1,7 +1,6 @@
|
|||
package org.ethereum.net.vo;
|
||||
|
||||
import org.spongycastle.util.encoders.Hex;
|
||||
import org.ethereum.net.rlp.RLPList;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
|
@ -13,39 +12,27 @@ import java.net.UnknownHostException;
|
|||
*/
|
||||
public class PeerData {
|
||||
|
||||
RLPList rawData;
|
||||
boolean parsed = false;
|
||||
private byte[] ip;
|
||||
private short port;
|
||||
private byte[] peerId;
|
||||
|
||||
byte[] ip;
|
||||
short port;
|
||||
byte[] peerId;
|
||||
|
||||
transient boolean isOnline = false;
|
||||
transient long lastCheckTime = 0;
|
||||
|
||||
public PeerData(RLPList rlpList){
|
||||
rawData = rlpList;
|
||||
parsed = false;
|
||||
}
|
||||
private transient boolean isOnline = false;
|
||||
private transient long lastCheckTime = 0;
|
||||
|
||||
public PeerData(byte[] ip, short port, byte[] peerId) {
|
||||
this.ip = ip;
|
||||
this.port = port;
|
||||
this.peerId = peerId;
|
||||
parsed = true;
|
||||
}
|
||||
|
||||
public InetAddress getInetAddress(){
|
||||
|
||||
InetAddress addr = null;
|
||||
|
||||
try {
|
||||
addr = InetAddress.getByAddress(ip);
|
||||
} catch (UnknownHostException e) {
|
||||
e.printStackTrace();
|
||||
throw new Error("malformed ip");
|
||||
}
|
||||
|
||||
return addr;
|
||||
}
|
||||
|
||||
|
@ -77,7 +64,6 @@ public class PeerData {
|
|||
this.lastCheckTime = lastCheckTime;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Peer: [ ip=" + getInetAddress()+ ", port=" + getPort() + ", peerId=" + Hex.toHexString( getPeerId() ) + "]";
|
||||
|
|
|
@ -10,44 +10,41 @@ import org.ethereum.util.Utils;
|
|||
* User: Roman Mandeleil
|
||||
* Created on: 21/04/14 09:19
|
||||
*/
|
||||
public class TransactionData {
|
||||
|
||||
RLPList rawData;
|
||||
boolean parsed = false;
|
||||
public class Transaction {
|
||||
|
||||
private RLPList rawData;
|
||||
private boolean parsed = false;
|
||||
|
||||
// creation contract tx or simple send tx
|
||||
// [ nonce, value, receiveAddress, gasPrice, gasDeposit, data, signatureV, signatureR, signatureS ]
|
||||
// or
|
||||
// [ nonce, endowment, 0, gasPrice, gasDeposit (for init), body, init, signatureV, signatureR, signatureS ]
|
||||
|
||||
byte[] hash;
|
||||
byte[] nonce;
|
||||
byte[] value;
|
||||
private byte[] hash;
|
||||
private byte[] nonce;
|
||||
private byte[] value;
|
||||
|
||||
// In creation transaction the receive address is - 0
|
||||
byte[] receiveAddress;
|
||||
byte[] gasPrice;
|
||||
byte[] gas;
|
||||
private byte[] receiveAddress;
|
||||
private byte[] gasPrice;
|
||||
private byte[] gas;
|
||||
|
||||
// Contract creation [data] will hold the contract
|
||||
// for other transaction [data] can hold data
|
||||
byte[] data;
|
||||
byte[] init;
|
||||
|
||||
private byte[] data;
|
||||
private byte[] init;
|
||||
|
||||
// Signature
|
||||
byte signatureV;
|
||||
byte[] signatureR;
|
||||
byte[] signatureS;
|
||||
private byte signatureV;
|
||||
private byte[] signatureR;
|
||||
private byte[] signatureS;
|
||||
|
||||
|
||||
public TransactionData(RLPList rawData) {
|
||||
public Transaction(RLPList rawData) {
|
||||
this.rawData = rawData;
|
||||
parsed = false;
|
||||
}
|
||||
|
||||
public TransactionData(byte[] nonce, byte[] value, byte[] recieveAddress, byte[] gasPrice, byte[] gas, byte[] data, byte signatureV, byte[] signatureR, byte[] signatureS) {
|
||||
public Transaction(byte[] nonce, byte[] value, byte[] recieveAddress, byte[] gasPrice, byte[] gas, byte[] data, byte signatureV, byte[] signatureR, byte[] signatureS) {
|
||||
this.nonce = nonce;
|
||||
this.value = value;
|
||||
this.receiveAddress = recieveAddress;
|
||||
|
@ -60,11 +57,8 @@ public class TransactionData {
|
|||
parsed = true;
|
||||
}
|
||||
|
||||
|
||||
public void rlpParse(){
|
||||
|
||||
if (rawData.size() == 9){ // Simple transaction
|
||||
|
||||
this.hash = HashUtil.sha3(rawData.getRLPData());
|
||||
this.nonce = ((RLPItem) rawData.getElement(0)).getData();
|
||||
this.value = ((RLPItem) rawData.getElement(1)).getData();
|
||||
|
@ -72,19 +66,13 @@ public class TransactionData {
|
|||
this.gasPrice = ((RLPItem) rawData.getElement(3)).getData();
|
||||
this.gas = ((RLPItem) rawData.getElement(4)).getData();
|
||||
this.data = ((RLPItem) rawData.getElement(5)).getData();
|
||||
|
||||
if (rawData.size() == 9){ // Simple transaction
|
||||
this.signatureV = ((RLPItem) rawData.getElement(6)).getData()[0];
|
||||
this.signatureR = ((RLPItem) rawData.getElement(7)).getData();
|
||||
this.signatureS = ((RLPItem) rawData.getElement(8)).getData();
|
||||
|
||||
} else if (rawData.size() == 10){ // Contract creation transaction
|
||||
|
||||
this.hash = HashUtil.sha3(rawData.getRLPData());
|
||||
this.nonce = ((RLPItem) rawData.getElement(0)).getData();
|
||||
this.value = ((RLPItem) rawData.getElement(1)).getData();
|
||||
this.receiveAddress = ((RLPItem) rawData.getElement(2)).getData();
|
||||
this.gasPrice = ((RLPItem) rawData.getElement(3)).getData();
|
||||
this.gas = ((RLPItem) rawData.getElement(4)).getData();
|
||||
this.data = ((RLPItem) rawData.getElement(5)).getData();
|
||||
this.init = ((RLPItem) rawData.getElement(6)).getData();
|
||||
this.signatureV = ((RLPItem) rawData.getElement(7)).getData()[0];
|
||||
this.signatureR = ((RLPItem) rawData.getElement(8)).getData();
|
||||
|
@ -95,7 +83,6 @@ public class TransactionData {
|
|||
this.parsed = true;
|
||||
}
|
||||
|
||||
|
||||
public RLPList getRawData() {
|
||||
return rawData;
|
||||
}
|
||||
|
@ -110,61 +97,51 @@ public class TransactionData {
|
|||
}
|
||||
|
||||
public byte[] getNonce() {
|
||||
|
||||
if (!parsed) rlpParse();
|
||||
return nonce;
|
||||
}
|
||||
|
||||
public byte[] getValue() {
|
||||
|
||||
if (!parsed) rlpParse();
|
||||
return value;
|
||||
}
|
||||
|
||||
public byte[] getReceiveAddress() {
|
||||
|
||||
if (!parsed) rlpParse();
|
||||
return receiveAddress;
|
||||
}
|
||||
|
||||
public byte[] getGasPrice() {
|
||||
|
||||
if (!parsed) rlpParse();
|
||||
return gasPrice;
|
||||
}
|
||||
|
||||
public byte[] getGas() {
|
||||
|
||||
if (!parsed) rlpParse();
|
||||
return gas;
|
||||
}
|
||||
|
||||
public byte[] getData() {
|
||||
|
||||
if (!parsed) rlpParse();
|
||||
return data;
|
||||
}
|
||||
|
||||
public byte[] getInit() {
|
||||
|
||||
if (!parsed) rlpParse();
|
||||
return init;
|
||||
}
|
||||
|
||||
public byte getSignatureV() {
|
||||
|
||||
if (!parsed) rlpParse();
|
||||
return signatureV;
|
||||
}
|
||||
|
||||
public byte[] getSignatureR() {
|
||||
|
||||
if (!parsed) rlpParse();
|
||||
return signatureR;
|
||||
}
|
||||
|
||||
public byte[] getSignatureS() {
|
||||
|
||||
if (!parsed) rlpParse();
|
||||
return signatureS;
|
||||
}
|
|
@ -49,9 +49,7 @@ public class Utils {
|
|||
}
|
||||
|
||||
public static void printHexStringForByte(byte data){
|
||||
|
||||
System.out.print("[");
|
||||
|
||||
String hexNum = Integer.toHexString ((int) data & 0xFF);
|
||||
if (((int) data & 0xFF) < 16) {
|
||||
hexNum = "0" + hexNum;
|
||||
|
@ -62,10 +60,8 @@ public class Utils {
|
|||
}
|
||||
|
||||
public static void printHexStringForByteArray(byte[] data){
|
||||
|
||||
System.out.print("[");
|
||||
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;
|
||||
|
@ -78,7 +74,6 @@ public class Utils {
|
|||
}
|
||||
|
||||
public static ImageIcon getImageIcon(String resource){
|
||||
|
||||
URL imageURL = ClassLoader.getSystemResource(resource);
|
||||
ImageIcon image = new ImageIcon(imageURL);
|
||||
return image;
|
||||
|
|
Before Width: | Height: | Size: 5.7 KiB After Width: | Height: | Size: 5.7 KiB |
Before Width: | Height: | Size: 4.5 KiB After Width: | Height: | Size: 4.5 KiB |
|
@ -4,7 +4,7 @@ import org.spongycastle.util.encoders.Hex;
|
|||
import org.ethereum.crypto.HashUtil;
|
||||
import org.ethereum.net.RLP;
|
||||
import org.ethereum.net.rlp.RLPList;
|
||||
import org.ethereum.net.vo.BlockData;
|
||||
import org.ethereum.net.vo.Block;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -131,7 +131,7 @@ public class BlockTest {
|
|||
RLPList rlpList = new RLPList();
|
||||
RLP.parseObjects(payload, rlpList);
|
||||
|
||||
BlockData blockData = new BlockData(rlpList);
|
||||
Block blockData = new Block(rlpList);
|
||||
RLPList.recursivePrint(rlpList);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,9 +13,9 @@ import org.ethereum.net.message.NotInChainMessage;
|
|||
import org.ethereum.net.message.PeersMessage;
|
||||
import org.ethereum.net.message.TransactionsMessage;
|
||||
import org.ethereum.net.rlp.RLPList;
|
||||
import org.ethereum.net.vo.BlockData;
|
||||
import org.ethereum.net.vo.Block;
|
||||
import org.ethereum.net.vo.PeerData;
|
||||
import org.ethereum.net.vo.TransactionData;
|
||||
import org.ethereum.net.vo.Transaction;
|
||||
import org.ethereum.util.Utils;
|
||||
import org.junit.Test;
|
||||
import org.spongycastle.util.encoders.Hex;
|
||||
|
@ -76,7 +76,6 @@ public class MessagesTest {
|
|||
Utils.toHexString(helloMessage.getPeerId()).toUpperCase() );
|
||||
}
|
||||
|
||||
|
||||
/* DISCONNECT_MESSAGE */
|
||||
|
||||
@Test /* DisconnectMessage 1 */
|
||||
|
@ -109,7 +108,6 @@ public class MessagesTest {
|
|||
DisconnectMessage.REASON_TCP_ERROR);
|
||||
}
|
||||
|
||||
|
||||
/* PEERS */
|
||||
|
||||
@Test /* PeersMessage 1*/
|
||||
|
@ -131,7 +129,6 @@ public class MessagesTest {
|
|||
assertEquals(30303, peerData.getPort());
|
||||
assertEquals("82A8A5831D3B4FB76CF130CDC8A2B162A85D005D82A1DCC9B73239035EADE6347EDE2FFC86571ABE348EA38699CE886AA3D425FE58182C433434AB4CFD7B5B88",
|
||||
Utils.toHexString( peerData.getPeerId() ).toUpperCase());
|
||||
|
||||
}
|
||||
|
||||
@Test /* PeersMessage 2 */
|
||||
|
@ -160,7 +157,6 @@ public class MessagesTest {
|
|||
assertEquals(30303, peerData.getPort());
|
||||
assertEquals("F6155F1A60143B7D9D5D1A440D7D52FE6809F69E0C6F1E0024457E0D71DD88ADE3B13AAA940C89AC0610952B48BD832C42E343A13E61FFDB06010CFFC345E053",
|
||||
Utils.toHexString( peerData.getPeerId() ).toUpperCase());
|
||||
|
||||
}
|
||||
|
||||
@Test /* Peers msg parsing performance*/
|
||||
|
@ -199,7 +195,7 @@ public class MessagesTest {
|
|||
|
||||
assertEquals(1, transactionsMessage.getTransactions().size());
|
||||
|
||||
TransactionData tx =
|
||||
Transaction tx =
|
||||
transactionsMessage.getTransactions().get(0);
|
||||
|
||||
assertEquals("558A3797E0DD3FBFAF761F1ADD6749C7D5DB313FDAC5CBA59F40E28AF7BBACD1",
|
||||
|
@ -236,7 +232,6 @@ public class MessagesTest {
|
|||
Utils.toHexString( tx.getSignatureS() ).toUpperCase());
|
||||
}
|
||||
|
||||
|
||||
@Test /* Transactions message 2 */
|
||||
public void test_9(){
|
||||
|
||||
|
@ -251,7 +246,7 @@ public class MessagesTest {
|
|||
|
||||
assertEquals(3, transactionsMessage.getTransactions().size());
|
||||
|
||||
TransactionData tx =
|
||||
Transaction tx =
|
||||
transactionsMessage.getTransactions().get(0);
|
||||
|
||||
assertEquals("4B7D9670A92BF120D5B43400543B69304A14D767CF836A7F6ABFF4EDDE092895",
|
||||
|
@ -287,7 +282,6 @@ public class MessagesTest {
|
|||
assertEquals("6D254E662BF7450DD8D835160CBB053463FED0B53F2CDD7F3EA8731919C8E8CC",
|
||||
Utils.toHexString( tx.getSignatureS() ).toUpperCase());
|
||||
|
||||
|
||||
tx = transactionsMessage.getTransactions().get(2);
|
||||
|
||||
assertEquals("B0251A1BB20B44459DB5B5444AB53EDD9E12C46D0BA07FA401A797BEB967D53C",
|
||||
|
@ -322,10 +316,8 @@ public class MessagesTest {
|
|||
|
||||
assertEquals("1E87172A861F6C37B5A9E3A5D0D7393152A7FBE41530E5BB8AC8F35433E5931B",
|
||||
Utils.toHexString(tx.getSignatureS()).toUpperCase());
|
||||
|
||||
}
|
||||
|
||||
|
||||
/* BLOCKS */
|
||||
|
||||
@Test /* BlocksMessage parsing 1*/
|
||||
|
@ -339,12 +331,12 @@ public class MessagesTest {
|
|||
RLP.parseObjects(payload, rlpList);
|
||||
|
||||
BlocksMessage blocksMessage = new BlocksMessage(rlpList);
|
||||
List<BlockData> list = blocksMessage.getBlockDataList();
|
||||
List<Block> list = blocksMessage.getBlockDataList();
|
||||
System.out.println(blocksMessage);
|
||||
|
||||
assertEquals(1, list.size());
|
||||
|
||||
BlockData block = list.get(0);
|
||||
Block block = list.get(0);
|
||||
|
||||
assertEquals("36A24B56C6104E5A5C0E70B0553F1A4D6109D065D718D7443A6A475EC8C83905",
|
||||
Utils.toHexString(block.getHash()).toUpperCase());
|
||||
|
@ -373,7 +365,6 @@ public class MessagesTest {
|
|||
Utils.toHexString(block.getNonce()).toUpperCase());
|
||||
}
|
||||
|
||||
|
||||
@Test /* BlocksMessage really big message parsing */
|
||||
public void test11(){
|
||||
|
||||
|
@ -384,13 +375,13 @@ public class MessagesTest {
|
|||
RLP.parseObjects(payload, rlpList);
|
||||
|
||||
BlocksMessage blocksMessage = new BlocksMessage(rlpList);
|
||||
List<BlockData> list = blocksMessage.getBlockDataList();
|
||||
List<Block> list = blocksMessage.getBlockDataList();
|
||||
System.out.println(blocksMessage);
|
||||
|
||||
|
||||
assertEquals(32, list.size());
|
||||
|
||||
BlockData block = list.get(31);
|
||||
Block block = list.get(31);
|
||||
|
||||
assertEquals("518916DFB79C390BD7BFF75712174512C2F96BEC42A3F573355507AD1588CE0C",
|
||||
Utils.toHexString(block.getHash()).toUpperCase());
|
||||
|
@ -419,11 +410,8 @@ public class MessagesTest {
|
|||
Utils.toHexString(block.getNonce()).toUpperCase());
|
||||
|
||||
System.out.println(blocksMessage);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* GET_CHAIN */
|
||||
|
||||
@Test /* GET_CHAIN message parsing*/
|
||||
|
@ -449,12 +437,8 @@ public class MessagesTest {
|
|||
|
||||
assertEquals("03AF21F3939C29C231200B1F790F16421A8923254CBF2A90455B9B8F28BE4562",
|
||||
Utils.toHexString( getChainMessage.getBlockHashList().get(25) ).toUpperCase());
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/* NOT_IN_CHAIN */
|
||||
|
||||
@Test /* NotInChainMessage parsing 1 */
|
||||
|
@ -472,7 +456,5 @@ public class MessagesTest {
|
|||
assertEquals("E5E441F0877116011CCDECE2501A50B40C40418377037E16D0282B2B5E347138",
|
||||
Utils.toHexString(notInChainMessage.getHash()).toUpperCase());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue