Getting rid of empty lines and unused imports

This commit is contained in:
nicksavers 2014-05-02 15:28:53 +02:00
parent 157cb63b6d
commit 2c96ec86c9
20 changed files with 824 additions and 980 deletions

View File

@ -92,6 +92,18 @@
<version>3.2.1</version> <version>3.2.1</version>
</dependency> </dependency>
</dependencies> </dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
</project> </project>

View File

@ -1,16 +1,11 @@
package org.ethereum.geodb; package org.ethereum.geodb;
import java.io.File;
import java.net.InetAddress;
import java.net.URL;
import com.maxmind.geoip.Location; import com.maxmind.geoip.Location;
import com.maxmind.geoip.LookupService; import com.maxmind.geoip.LookupService;
import com.maxmind.geoip2.DatabaseReader;
import com.maxmind.geoip2.exception.GeoIp2Exception;
import com.maxmind.geoip2.model.CityResponse;
import java.io.File;
import java.io.IOException;
import java.net.InetAddress;
import java.net.URISyntaxException;
import java.net.URL;
/** /**
* www.ethereumJ.com * www.ethereumJ.com

View File

@ -1,14 +1,19 @@
package org.ethereum.gui; package org.ethereum.gui;
import org.ethereum.net.client.ClientPeer; import java.awt.BorderLayout;
import org.fife.ui.rsyntaxtextarea.*; import java.awt.Image;
import org.fife.ui.rtextarea.RTextScrollPane; import java.awt.Toolkit;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import javax.swing.*; import javax.swing.JFrame;
import java.awt.*; import javax.swing.JPanel;
import java.awt.event.*; import javax.swing.SwingUtilities;
import java.io.IOException;
import java.util.TimerTask; import org.ethereum.net.client.ClientPeer;
import org.fife.ui.rsyntaxtextarea.RSyntaxTextArea;
import org.fife.ui.rsyntaxtextarea.SyntaxConstants;
import org.fife.ui.rtextarea.RTextScrollPane;
/** /**
* A simple example showing how to modify the fonts and colors used in an * A simple example showing how to modify the fonts and colors used in an
@ -27,7 +32,6 @@ public class ConnectionConsole extends JFrame implements PeerListener{
private RSyntaxTextArea textArea; private RSyntaxTextArea textArea;
public ConnectionConsole() { public ConnectionConsole() {
final ConnectionConsole thisConsole = this; final ConnectionConsole thisConsole = this;
@ -59,28 +63,21 @@ public class ConnectionConsole extends JFrame implements PeerListener{
Thread t = new Thread() { Thread t = new Thread() {
public void run() { public void run() {
new ClientPeer(thisConsole).connect("54.204.10.41", 30303);
// new ClientPeer(thisConsole).connect("54.201.28.117", 30303); // new ClientPeer(thisConsole).connect("54.201.28.117", 30303);
new ClientPeer(thisConsole).connect("82.217.72.169", 30303); // new ClientPeer(thisConsole).connect("82.217.72.169", 30303);
} }
}; };
t.start(); t.start();
} }
}); });
} }
@Override @Override
public void console(final String output) { public void console(final String output) {
SwingUtilities.invokeLater(new Runnable() {
SwingUtilities.invokeLater(new Runnable() public void run() {
{
public void run()
{
textArea.append(output); textArea.append(output);
textArea.append("\n"); textArea.append("\n");
textArea.setCaretPosition(textArea.getText().length()); textArea.setCaretPosition(textArea.getText().length());

View File

@ -1,7 +1,6 @@
package org.ethereum.gui; package org.ethereum.gui;
import com.maxmind.geoip.Location; import com.maxmind.geoip.Location;
import com.maxmind.geoip2.model.CityResponse;
import org.ethereum.geodb.IpGeoDB; import org.ethereum.geodb.IpGeoDB;
import org.ethereum.util.Utils; import org.ethereum.util.Utils;
@ -28,8 +27,6 @@ public class PeersTableModel extends AbstractTableModel {
generateRandomData(); generateRandomData();
} }
public String getColumnName(int column) { public String getColumnName(int column) {
if (column == 0) return "Location"; if (column == 0) return "Location";
@ -59,7 +56,6 @@ public class PeersTableModel extends AbstractTableModel {
URL flagURL = ClassLoader.getSystemResource("flags/" + countryCode + ".png"); URL flagURL = ClassLoader.getSystemResource("flags/" + countryCode + ".png");
ImageIcon flagIcon = new ImageIcon(flagURL); ImageIcon flagIcon = new ImageIcon(flagURL);
return flagIcon; return flagIcon;
} }
@ -78,7 +74,6 @@ public class PeersTableModel extends AbstractTableModel {
flagIcon = Utils.getImageIcon("disconnected.png"); flagIcon = Utils.getImageIcon("disconnected.png");
} }
return flagIcon; return flagIcon;
} }

View File

@ -11,7 +11,6 @@ import java.awt.*;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
/** /**
* www.ethereumJ.com * www.ethereumJ.com
* User: Roman Mandeleil * User: Roman Mandeleil

View File

@ -33,7 +33,6 @@ public class ToolBar extends JFrame {
this.setContentPane(cp); this.setContentPane(cp);
java.net.URL imageURL_1 = ClassLoader.getSystemResource("buttons/feedly.png"); java.net.URL imageURL_1 = ClassLoader.getSystemResource("buttons/feedly.png");
ImageIcon image_1 = new ImageIcon(imageURL_1); ImageIcon image_1 = new ImageIcon(imageURL_1);
@ -43,8 +42,6 @@ public class ToolBar extends JFrame {
java.net.URL imageURL_3 = ClassLoader.getSystemResource("buttons/browser.png"); java.net.URL imageURL_3 = ClassLoader.getSystemResource("buttons/browser.png");
ImageIcon image_3 = new ImageIcon(imageURL_3); ImageIcon image_3 = new ImageIcon(imageURL_3);
JToggleButton editorToggle = new JToggleButton(""); JToggleButton editorToggle = new JToggleButton("");
editorToggle.setIcon(image_1); editorToggle.setIcon(image_1);
editorToggle.setContentAreaFilled(true); editorToggle.setContentAreaFilled(true);
@ -97,20 +94,12 @@ public class ToolBar extends JFrame {
PeersTableMain mainFrame = new PeersTableMain(); PeersTableMain mainFrame = new PeersTableMain();
mainFrame.setVisible( true ); mainFrame.setVisible( true );
// mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
} }
}); });
cp.add(editorToggle); cp.add(editorToggle);
cp.add(logToggle); cp.add(logToggle);
cp.add(peersToggle); cp.add(peersToggle);
} }
public static void main(String args[]){ public static void main(String args[]){
@ -120,7 +109,6 @@ public class ToolBar extends JFrame {
new ToolBar().setVisible(true); new ToolBar().setVisible(true);
} }
}); });
} }
} }

View File

@ -1,8 +1,6 @@
package org.ethereum.manager; package org.ethereum.manager;
import com.maxmind.geoip.Location; import com.maxmind.geoip.Location;
import com.maxmind.geoip2.model.CityResponse;
import com.maxmind.geoip2.record.Country;
import org.ethereum.geodb.IpGeoDB; import org.ethereum.geodb.IpGeoDB;
import org.ethereum.net.vo.PeerData; import org.ethereum.net.vo.PeerData;

View File

@ -1,39 +1,35 @@
package org.ethereum.net; package org.ethereum.net;
import org.bouncycastle.util.encoders.Hex;
import org.ethereum.net.rlp.RLPItem;
import org.ethereum.net.rlp.RLPList;
import org.ethereum.util.Utils;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.math.BigInteger; import java.math.BigInteger;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.util.*; import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Queue;
import org.ethereum.net.rlp.RLPItem;
import org.ethereum.net.rlp.RLPList;
/** /**
*/ */
public class RLP { public class RLP {
public static byte decodeOneByteItem(byte[] data, int index) { public static byte decodeOneByteItem(byte[] data, int index) {
// null item // null item
if ((data[index] & 0xFF) == 0x80) { if ((data[index] & 0xFF) == 0x80) {
return (byte) (data[index] - 0x80); return (byte) (data[index] - 0x80);
} }
// single byte item // single byte item
if ((data[index] & 0xFF) < 0x80) { if ((data[index] & 0xFF) < 0x80) {
return (byte) (data[index]); return (byte) (data[index]);
} }
// single byte item // single byte item
if ((data[index] & 0xFF) == 0x81) { if ((data[index] & 0xFF) == 0x81) {
return (byte) (data[index + 1]); return (byte) (data[index + 1]);
} }
return 0; return 0;
} }
@ -69,7 +65,6 @@ public class RLP {
return value; return value;
} }
public static int decodeInt(byte[] data, int index) { public static int decodeInt(byte[] data, int index) {
int value = 0; int value = 0;
@ -79,18 +74,13 @@ public class RLP {
byte length = (byte) (data[index] - 0x80); byte length = (byte) (data[index] - 0x80);
byte pow = (byte) (length - 1); byte pow = (byte) (length - 1);
for (int i = 1; i <= length; ++i) { for (int i = 1; i <= length; ++i) {
value += data[index + i] << (8 * pow); value += data[index + i] << (8 * pow);
pow--; pow--;
} }
} else { } else {
throw new Error("wrong decode attempt"); throw new Error("wrong decode attempt");
} }
return value; return value;
} }
@ -99,16 +89,11 @@ public class RLP {
short value = 0; short value = 0;
if ((data[index] & 0xFF) > 0x80 && (data[index] & 0xFF) < 0xB7) { if ((data[index] & 0xFF) > 0x80 && (data[index] & 0xFF) < 0xB7) {
byte length = (byte) (data[index] - 0x80); byte length = (byte) (data[index] - 0x80);
value = ByteBuffer.wrap(data, index, length).getShort(); value = ByteBuffer.wrap(data, index, length).getShort();
} else { } else {
value = data[index]; value = data[index];
} }
return value; return value;
} }
@ -121,22 +106,18 @@ public class RLP {
byte length = (byte) (data[index] - 0x80); byte length = (byte) (data[index] - 0x80);
byte pow = (byte) (length - 1); byte pow = (byte) (length - 1);
for (int i = 1; i <= length; ++i) { for (int i = 1; i <= length; ++i) {
value += data[index + i] << (8 * pow); value += data[index + i] << (8 * pow);
pow--; pow--;
} }
} else { } else {
throw new Error("wrong decode attempt"); throw new Error("wrong decode attempt");
} }
return value; return value;
} }
public static byte[] decodeItemBytes(byte[] data, int index) { public static byte[] decodeItemBytes(byte[] data, int index) {
byte[] value = null; byte[] value = null;
@ -154,7 +135,6 @@ public class RLP {
pow--; pow--;
} }
byte[] valueBytes = new byte[length]; byte[] valueBytes = new byte[length];
System.arraycopy(data, index, valueBytes, 0, length); System.arraycopy(data, index, valueBytes, 0, length);
@ -195,7 +175,6 @@ public class RLP {
pow--; pow--;
} }
byte[] valueBytes = new byte[length]; byte[] valueBytes = new byte[length];
System.arraycopy(data, index, valueBytes, 0, length); System.arraycopy(data, index, valueBytes, 0, length);
@ -236,7 +215,6 @@ public class RLP {
pow--; pow--;
} }
byte[] valueBytes = new byte[length]; byte[] valueBytes = new byte[length];
System.arraycopy(data, index, valueBytes, 0, length); System.arraycopy(data, index, valueBytes, 0, length);
@ -260,11 +238,10 @@ public class RLP {
return value; return value;
} }
public static int nextItemLength(byte[] data, int index) { public static int nextItemLength(byte[] data, int index) {
if (index >= data.length)
if (index >= data.length) return -1; return -1;
if ((data[index] & 0xFF) >= 0xF7) { if ((data[index] & 0xFF) >= 0xF7) {
byte lenghtOfLenght = (byte) (data[index] - 0xF7); byte lenghtOfLenght = (byte) (data[index] - 0xF7);
@ -280,7 +257,6 @@ public class RLP {
return length; return length;
} }
if ((data[index] & 0xFF) >= 0xC0 && (data[index] & 0xFF) < 0xF7) { if ((data[index] & 0xFF) >= 0xC0 && (data[index] & 0xFF) < 0xF7) {
@ -289,7 +265,6 @@ public class RLP {
return length; return length;
} }
if ((data[index] & 0xFF) >= 0xB7 && (data[index] & 0xFF) < 0xC0) { if ((data[index] & 0xFF) >= 0xB7 && (data[index] & 0xFF) < 0xC0) {
byte lenghtOfLenght = (byte) (data[index] - 0xB7); byte lenghtOfLenght = (byte) (data[index] - 0xB7);
@ -305,7 +280,6 @@ public class RLP {
return length; return length;
} }
if ((data[index] & 0xFF) > 0x80 && (data[index] & 0xFF) < 0xB7) { if ((data[index] & 0xFF) > 0x80 && (data[index] & 0xFF) < 0xB7) {
@ -314,7 +288,6 @@ public class RLP {
return length; return length;
} }
if ((data[index] & 0xFF) == 0x80) { if ((data[index] & 0xFF) == 0x80) {
return 1; return 1;
@ -328,7 +301,6 @@ public class RLP {
return -1; return -1;
} }
public static byte[] decodeIP4Bytes(byte[] data, int index) { public static byte[] decodeIP4Bytes(byte[] data, int index) {
int length = (data[index] & 0xFF) - 0xC0; int length = (data[index] & 0xFF) - 0xC0;
@ -336,13 +308,22 @@ public class RLP {
byte aByte = decodeOneByteItem(data, index + offset); byte aByte = decodeOneByteItem(data, index + offset);
if ((data[index + offset] & 0xFF) > 0x80) offset = offset + 2; else offset = offset + 1; if ((data[index + offset] & 0xFF) > 0x80)
offset = offset + 2;
else
offset = offset + 1;
byte bByte = decodeOneByteItem(data, index + offset); byte bByte = decodeOneByteItem(data, index + offset);
if ((data[index + offset] & 0xFF) > 0x80) offset = offset + 2; else offset = offset + 1; if ((data[index + offset] & 0xFF) > 0x80)
offset = offset + 2;
else
offset = offset + 1;
byte cByte = decodeOneByteItem(data, index + offset); byte cByte = decodeOneByteItem(data, index + offset);
if ((data[index + offset] & 0xFF) > 0x80) offset = offset + 2; else offset = offset + 1; if ((data[index + offset] & 0xFF) > 0x80)
offset = offset + 2;
else
offset = offset + 1;
byte dByte = decodeOneByteItem(data, index + offset); byte dByte = decodeOneByteItem(data, index + offset);
byte[] ip = new byte[4]; byte[] ip = new byte[4];
@ -356,7 +337,8 @@ public class RLP {
public static int getFirstListElement(byte[] payload, int pos) { public static int getFirstListElement(byte[] payload, int pos) {
if (pos >= payload.length) return -1; if (pos >= payload.length)
return -1;
if ((payload[pos] & 0xFF) >= 0xF7) { if ((payload[pos] & 0xFF) >= 0xF7) {
@ -371,7 +353,6 @@ public class RLP {
return pos + 1; return pos + 1;
} }
if ((payload[pos] & 0xFF) >= 0xB7 && (payload[pos] & 0xFF) < 0xC0) { if ((payload[pos] & 0xFF) >= 0xB7 && (payload[pos] & 0xFF) < 0xC0) {
byte lenghtOfLenght = (byte) (payload[pos] - 0xB7); byte lenghtOfLenght = (byte) (payload[pos] - 0xB7);
@ -391,30 +372,24 @@ public class RLP {
return -1; return -1;
} }
public static int getNextElementIndex(byte[] payload, int pos) { public static int getNextElementIndex(byte[] payload, int pos) {
if (pos >= payload.length) return -1; if (pos >= payload.length)
return -1;
if ((payload[pos] & 0xFF) >= 0xF7) { if ((payload[pos] & 0xFF) >= 0xF7) {
byte lenghtOfLenght = (byte) (payload[pos] - 0xF7); byte lenghtOfLength = (byte) (payload[pos] - 0xF7);
byte pow = (byte) (lenghtOfLenght - 1); byte pow = (byte) (lenghtOfLength - 1);
int length = 0; int length = 0;
for (int i = 1; i <= lenghtOfLenght; ++i){ for (int i = 1; i <= lenghtOfLength; ++i) {
length += (payload[pos + i] & 0xFF) << (8 * pow); length += (payload[pos + i] & 0xFF) << (8 * pow);
pow--; pow--;
} }
return pos + lenghtOfLenght + length + 1 ; return pos + lenghtOfLength + length + 1;
} }
if ((payload[pos] & 0xFF) >= 0xC0 && (payload[pos] & 0xFF) < 0xF7) { if ((payload[pos] & 0xFF) >= 0xC0 && (payload[pos] & 0xFF) < 0xF7) {
@ -423,7 +398,6 @@ public class RLP {
return pos + 1 + length; return pos + 1 + length;
} }
if ((payload[pos] & 0xFF) >= 0xB7 && (payload[pos] & 0xFF) < 0xC0) { if ((payload[pos] & 0xFF) >= 0xB7 && (payload[pos] & 0xFF) < 0xC0) {
byte lenghtOfLenght = (byte) (payload[pos] - 0xB7); byte lenghtOfLenght = (byte) (payload[pos] - 0xB7);
@ -446,7 +420,6 @@ public class RLP {
return pos + 1 + length; return pos + 1 + length;
} }
if ((payload[pos] & 0xFF) == 0x80) { if ((payload[pos] & 0xFF) == 0x80) {
return pos + 1; return pos + 1;
@ -457,26 +430,25 @@ public class RLP {
return pos + 1; return pos + 1;
} }
return -1; return -1;
} }
/** /**
* Get exactly one message payload * Get exactly one message payload
*/ */
public static void fullTraverse(byte [] msgData, int level, int startPos, int endPos, public static void fullTraverse(byte[] msgData, int level, int startPos,
int levelToIndex, Queue<Integer> index) { int endPos, int levelToIndex, Queue<Integer> index) {
try { try {
if (msgData == null || msgData.length == 0) return ; if (msgData == null || msgData.length == 0)
return;
int pos = startPos; int pos = startPos;
while (pos < endPos) { while (pos < endPos) {
if (level == levelToIndex) index.add(new Integer(pos)); if (level == levelToIndex)
index.add(new Integer(pos));
// It's a list with a payload more than 55 bytes // It's a list with a payload more than 55 bytes
// data[0] - 0xF7 = how many next bytes allocated // data[0] - 0xF7 = how many next bytes allocated
@ -495,34 +467,37 @@ public class RLP {
} }
// now we can parse an item for data[1]..data[length] // now we can parse an item for data[1]..data[length]
System.out.println("-- level: [" + level + "] Found big list length: " + length); System.out.println("-- level: [" + level
+ "] Found big list length: " + length);
fullTraverse(msgData, level + 1, pos + lenghtOfLenght + 1, pos + lenghtOfLenght + length, fullTraverse(msgData, level + 1, pos + lenghtOfLenght + 1,
levelToIndex, index); pos + lenghtOfLenght + length, levelToIndex, index);
pos += lenghtOfLenght + length + 1; pos += lenghtOfLenght + length + 1;
continue; continue;
} }
// It's a list with a payload less than 55 bytes // It's a list with a payload less than 55 bytes
if ((msgData[pos] & 0xFF) >= 0xC0 && (msgData[pos] & 0xFF) < 0xF7){ if ((msgData[pos] & 0xFF) >= 0xC0
&& (msgData[pos] & 0xFF) < 0xF7) {
byte length = (byte) ((msgData[pos] & 0xFF) - 0xC0); byte length = (byte) ((msgData[pos] & 0xFF) - 0xC0);
System.out.println("-- level: [" + level + "] Found small list length: " + length); System.out.println("-- level: [" + level
+ "] Found small list length: " + length);
fullTraverse(msgData, level + 1, pos + 1, pos + length + 1, levelToIndex, index); fullTraverse(msgData, level + 1, pos + 1, pos + length + 1,
levelToIndex, index);
pos += 1 + length; pos += 1 + length;
continue; continue;
} }
// It's an item with a payload more than 55 bytes // It's an item with a payload more than 55 bytes
// data[0] - 0xB7 = how much next bytes allocated for // data[0] - 0xB7 = how much next bytes allocated for
// the length of the string // the length of the string
if ((msgData[pos] & 0xFF) >= 0xB7 && (msgData[pos] & 0xFF) < 0xC0) { if ((msgData[pos] & 0xFF) >= 0xB7
&& (msgData[pos] & 0xFF) < 0xC0) {
byte lenghtOfLenght = (byte) (msgData[pos] - 0xB7); byte lenghtOfLenght = (byte) (msgData[pos] - 0xB7);
byte pow = (byte) (lenghtOfLenght - 1); byte pow = (byte) (lenghtOfLenght - 1);
@ -535,22 +510,23 @@ public class RLP {
pow--; pow--;
} }
// now we can parse an item for data[1]..data[length] // now we can parse an item for data[1]..data[length]
System.out.println("-- level: [" + level + "] Found big item length: " + length); System.out.println("-- level: [" + level
+ "] Found big item length: " + length);
pos += lenghtOfLenght + length + 1; pos += lenghtOfLenght + length + 1;
continue; continue;
} }
// It's an item less than 55 bytes long, // It's an item less than 55 bytes long,
// data[0] - 0x80 == lenght of the item // data[0] - 0x80 == lenght of the item
if ((msgData[pos] & 0xFF) > 0x80 && (msgData[pos] & 0xFF) < 0xB7) { if ((msgData[pos] & 0xFF) > 0x80
&& (msgData[pos] & 0xFF) < 0xB7) {
byte length = (byte) ((msgData[pos] & 0xFF) - 0x80); byte length = (byte) ((msgData[pos] & 0xFF) - 0x80);
System.out.println("-- level: [" + level + "] Found small item length: " + length); System.out.println("-- level: [" + level
+ "] Found small item length: " + length);
pos += 1 + length; pos += 1 + length;
continue; continue;
@ -558,54 +534,48 @@ public class RLP {
// null item // null item
if ((msgData[pos] & 0xFF) == 0x80) { if ((msgData[pos] & 0xFF) == 0x80) {
System.out.println("-- level: [" + level + "] Found null item: "); System.out.println("-- level: [" + level
+ "] Found null item: ");
pos += 1; pos += 1;
continue; continue;
} }
// single byte item // single byte item
if ((msgData[pos] & 0xFF) < 0x80) { if ((msgData[pos] & 0xFF) < 0x80) {
System.out.println("-- level: [" + level + "] Found single item: "); System.out.println("-- level: [" + level
+ "] Found single item: ");
pos += 1; pos += 1;
continue; continue;
} }
} }
} catch (Throwable th) { } catch (Throwable th) {
throw new Error("wire packet not parsed correctly",
throw new Error("wire packet not parsed correctly", th.fillInStackTrace()); th.fillInStackTrace());
} }
} }
/** /**
* Parse wire byte[] message into RLP elements * Parse wire byte[] message into RLP elements
* *
* @param msgData - raw RLP data * @param msgData
* @param rlpList - outcome of recursive RLP structure * - raw RLP data
* @param rlpList
* - outcome of recursive RLP structure
*/ */
public static void parseObjects(byte[] msgData, RLPList rlpList) { public static void parseObjects(byte[] msgData, RLPList rlpList) {
RLP.fullTraverse2(msgData, 0, 0, msgData.length, 1, rlpList); RLP.fullTraverse2(msgData, 0, 0, msgData.length, 1, rlpList);
} }
/** /**
* Get exactly one message payload * Get exactly one message payload
*/ */
public static void fullTraverse2(byte [] msgData, int level, int startPos, int endPos, public static void fullTraverse2(byte[] msgData, int level, int startPos,
int levelToIndex, RLPList rlpList) { int endPos, int levelToIndex, RLPList rlpList) {
try { try {
if (msgData == null || msgData.length == 0) return ; if (msgData == null || msgData.length == 0)
return;
int pos = startPos; int pos = startPos;
while (pos < endPos) { while (pos < endPos) {
@ -626,30 +596,31 @@ public class RLP {
pow--; pow--;
} }
byte[] rlpData = new byte[lenghtOfLenght + length + 1]; byte[] rlpData = new byte[lenghtOfLenght + length + 1];
System.arraycopy(msgData, pos, rlpData, 0, lenghtOfLenght + length + 1); System.arraycopy(msgData, pos, rlpData, 0, lenghtOfLenght
+ length + 1);
RLPList newLevelList = new RLPList(); RLPList newLevelList = new RLPList();
newLevelList.setRLPData(rlpData); newLevelList.setRLPData(rlpData);
// todo: this done to get some data for testing should be
// todo: this done to get some data for testing should be delete // delete
// byte[] subList = Arrays.copyOfRange(msgData, pos, pos + lenghtOfLenght + length + 1); // byte[] subList = Arrays.copyOfRange(msgData, pos, pos +
// lenghtOfLenght + length + 1);
// System.out.println(Utils.toHexString(subList)); // System.out.println(Utils.toHexString(subList));
fullTraverse2(msgData, level + 1, pos + lenghtOfLenght + 1,
fullTraverse2(msgData, level + 1, pos + lenghtOfLenght + 1, pos + lenghtOfLenght + length + 1, pos + lenghtOfLenght + length + 1, levelToIndex,
levelToIndex, newLevelList); newLevelList);
rlpList.addItem(newLevelList); rlpList.addItem(newLevelList);
pos += lenghtOfLenght + length + 1; pos += lenghtOfLenght + length + 1;
continue; continue;
} }
// It's a list with a payload less than 55 bytes // It's a list with a payload less than 55 bytes
if ((msgData[pos] & 0xFF) >= 0xC0 && (msgData[pos] & 0xFF) < 0xF7){ if ((msgData[pos] & 0xFF) >= 0xC0
&& (msgData[pos] & 0xFF) < 0xF7) {
byte length = (byte) ((msgData[pos] & 0xFF) - 0xC0); byte length = (byte) ((msgData[pos] & 0xFF) - 0xC0);
@ -660,18 +631,19 @@ public class RLP {
newLevelList.setRLPData(rlpData); newLevelList.setRLPData(rlpData);
if (length > 0) if (length > 0)
fullTraverse2(msgData, level + 1, pos + 1, pos + length + 1, levelToIndex, newLevelList); fullTraverse2(msgData, level + 1, pos + 1, pos + length
+ 1, levelToIndex, newLevelList);
rlpList.addItem(newLevelList); rlpList.addItem(newLevelList);
pos += 1 + length; pos += 1 + length;
continue; continue;
} }
// It's an item with a payload more than 55 bytes // It's an item with a payload more than 55 bytes
// data[0] - 0xB7 = how much next bytes allocated for // data[0] - 0xB7 = how much next bytes allocated for
// the length of the string // the length of the string
if ((msgData[pos] & 0xFF) >= 0xB7 && (msgData[pos] & 0xFF) < 0xC0) { if ((msgData[pos] & 0xFF) >= 0xB7
&& (msgData[pos] & 0xFF) < 0xC0) {
byte lenghtOfLenght = (byte) (msgData[pos] - 0xB7); byte lenghtOfLenght = (byte) (msgData[pos] - 0xB7);
byte pow = (byte) (lenghtOfLenght - 1); byte pow = (byte) (lenghtOfLenght - 1);
@ -684,30 +656,29 @@ public class RLP {
pow--; pow--;
} }
// now we can parse an item for data[1]..data[length] // now we can parse an item for data[1]..data[length]
byte[] item = new byte[length]; byte[] item = new byte[length];
System.arraycopy(msgData, pos + lenghtOfLenght + 1, item, 0, length); System.arraycopy(msgData, pos + lenghtOfLenght + 1, item,
0, length);
byte[] rlpPrefix = new byte[lenghtOfLenght + 1]; byte[] rlpPrefix = new byte[lenghtOfLenght + 1];
System.arraycopy(msgData, pos, rlpPrefix, 0, lenghtOfLenght + 1); System.arraycopy(msgData, pos, rlpPrefix, 0,
lenghtOfLenght + 1);
RLPItem rlpItem = new RLPItem(item); RLPItem rlpItem = new RLPItem(item);
rlpList.addItem(rlpItem); rlpList.addItem(rlpItem);
pos += lenghtOfLenght + length + 1; pos += lenghtOfLenght + length + 1;
continue; continue;
} }
// It's an item less than 55 bytes long, // It's an item less than 55 bytes long,
// data[0] - 0x80 == length of the item // data[0] - 0x80 == length of the item
if ((msgData[pos] & 0xFF) > 0x80 && (msgData[pos] & 0xFF) < 0xB7) { if ((msgData[pos] & 0xFF) > 0x80
&& (msgData[pos] & 0xFF) < 0xB7) {
byte length = (byte) ((msgData[pos] & 0xFF) - 0x80); byte length = (byte) ((msgData[pos] & 0xFF) - 0x80);
byte[] item = new byte[length]; byte[] item = new byte[length];
System.arraycopy(msgData, pos + 1, item, 0, length); System.arraycopy(msgData, pos + 1, item, 0, length);
@ -742,83 +713,63 @@ public class RLP {
continue; continue;
} }
} }
} catch (Throwable th) { } catch (Throwable th) {
throw new Error("wire packet not parsed correctly",
throw new Error("wire packet not parsed correctly", th.fillInStackTrace()); th.fillInStackTrace());
} }
} }
/* /*
def rlp_encode(input): * def rlp_encode(input): if isinstance(input,str): if len(input) == 1 and
if isinstance(input,str): * chr(input) < 128: return input else: return encode_length(len(input),128)
if len(input) == 1 and chr(input) < 128: return input * + input elif isinstance(input,list): output = '' for item in input:
else: return encode_length(len(input),128) + input * output += rlp_encode(item) return encode_length(len(output),192) + output
elif isinstance(input,list): *
output = '' * def encode_length(L,offset): if L < 56: return chr(L + offset) elif L <
for item in input: output += rlp_encode(item) * 256**8: BL = to_binary(L) return chr(len(BL) + offset + 55) + BL else:
return encode_length(len(output),192) + output * raise Exception("input too long")
*
def encode_length(L,offset): * def to_binary(x): return '' if x == 0 else to_binary(int(x / 256)) +
if L < 56: * chr(x % 256)
return chr(L + offset)
elif L < 256**8:
BL = to_binary(L)
return chr(len(BL) + offset + 55) + BL
else:
raise Exception("input too long")
def to_binary(x):
return '' if x == 0 else to_binary(int(x / 256)) + chr(x % 256)
*/ */
private static void test1(Object... item){
}
private static String rlpEncode(Object item) { private static String rlpEncode(Object item) {
if (item instanceof String) { if (item instanceof String) {
String str = ((String) item); String str = ((String) item);
int length = str.length(); int length = str.length();
if (length == 1 && str.charAt(0) < 128 ) return str; if (length == 1 && str.charAt(0) < 128)
else return encodeLenght(str.length(), 128) + str; return str;
else
return encodeLenght(str.length(), 128) + str;
} else if (item instanceof List) { } else if (item instanceof List) {
List itemList = (List) item; List itemList = (List) item;
StringBuilder output = new StringBuilder(); StringBuilder output = new StringBuilder();
for (Object oneItem : itemList) output.append(rlpEncode(oneItem)); for (Object oneItem : itemList)
return encodeLenght(output.toString().length(), 192) + output.toString(); output.append(rlpEncode(oneItem));
return encodeLenght(output.toString().length(), 192)
+ output.toString();
} }
throw new Error("unsupported type" + item.getClass()); throw new Error("unsupported type" + item.getClass());
} }
private static String encodeLenght(int L, int offset) { private static String encodeLenght(int L, int offset) {
if (L < 56) if (L < 56)
return "" + (char) (L + offset); return "" + (char) (L + offset);
else if else if (L < (256 ^ 8)) {
(L < (256 ^ 8)) {
String BL = toBinary(L); String BL = toBinary(L);
return "" + (char) (BL.length() + offset + 55) + BL; return "" + (char) (BL.length() + offset + 55) + BL;
} } else
else
throw new Error("input too long"); throw new Error("input too long");
} }
public static byte getCommandCode(byte[] data) { public static byte getCommandCode(byte[] data) {
byte command = 0; byte command = 0;
@ -829,23 +780,20 @@ def encode_length(L,offset):
command = ((int) (command & 0xFF) == 0x80) ? 0 : command; command = ((int) (command & 0xFF) == 0x80) ? 0 : command;
return command; return command;
} }
public static Object decode(char[] data) { public static Object decode(char[] data) {
if (data == null || data.length == 0) return null; if (data == null || data.length == 0)
return null;
if (data[0] >= 0xF7){ /* 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 (data[0] >= 0xF7) { /*
* 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
*/
;
byte lenghtOfLenght = (byte) (data[0] - 0xF7); byte lenghtOfLenght = (byte) (data[0] - 0xF7);
byte pow = (byte) (lenghtOfLenght - 1); byte pow = (byte) (lenghtOfLenght - 1);
@ -860,17 +808,23 @@ def encode_length(L,offset):
System.out.println(length); System.out.println(length);
// now we can parse an item for data[1]..data[length] // now we can parse an item for data[1]..data[length]
} }
if (data[0] >= 0xC0 && data[0] < 0xF7) /* It's a list with a payload less than 55 bytes*/; if (data[0] >= 0xC0 && data[0] < 0xF7) /*
* It's a list with a payload
* less than 55 bytes
*/
;
if (data[0] >= 0xB7 && data[0] < 0xC0) {/*
* It's an item with a payload
if (data[0] >= 0xB7 && data[0] < 0xC0) {/* It's an item with a payload more than 55 bytes * more than 55 bytes data[0] -
data[0] - 0xB7 = how much next bytes allocated for * 0xB7 = how much next bytes
the length of the string */; * allocated for the length of
* the string
*/
;
byte lenghtOfLenght = (byte) (data[0] - 0xB7); byte lenghtOfLenght = (byte) (data[0] - 0xB7);
byte pow = (byte) (lenghtOfLenght - 1); byte pow = (byte) (lenghtOfLenght - 1);
@ -882,36 +836,34 @@ def encode_length(L,offset):
length += data[i] << (8 * pow); length += data[i] << (8 * pow);
pow--; pow--;
} }
// now we can parse an item for data[1]..data[length] // now we can parse an item for data[1]..data[length]
} }
if (data[0] >= 0x80 && data[0] < 0xB7) {/*
if (data[0] >= 0x80 && data[0] < 0xB7) {/* It's an item less than 55 bytes long, * It's an item less than 55
data[0] - 0x80 == lenght of the item */; * bytes long, data[0] - 0x80 ==
* lenght of the item
*/
;
} }
if (data[0] == 0x80) /* null item */; if (data[0] == 0x80) /* null item */
if (data[0] < 0x80) /* single byte item */; ;
if (data[0] < 0x80) /* single byte item */
;
return null; return null;
} }
private static String toBinary(int x) { private static String toBinary(int x) {
if (x == 0) return ""; if (x == 0)
else return toBinary(x >> 8) + ((char)(x & 0x00FF)); return "";
else
return toBinary(x >> 8) + ((char) (x & 0x00FF));
} }
public static byte[] encodeByte(byte singleByte) { public static byte[] encodeByte(byte singleByte) {
if ((singleByte & 0xFF) == 0) { if ((singleByte & 0xFF) == 0) {
@ -933,10 +885,8 @@ def encode_length(L,offset):
return encodeByte((byte) singleShort); return encodeByte((byte) singleShort);
else { else {
return new byte[]{(byte) 0x82, return new byte[] { (byte) 0x82, (byte) (singleShort >> 8 & 0xFF),
(byte) (singleShort >> 8 & 0xFF), (byte) (singleShort >> 0 & 0xFF) };
(byte) (singleShort >> 0 & 0xFF)
};
} }
} }
@ -989,10 +939,8 @@ def encode_length(L,offset):
return data; return data;
} }
} }
public static byte[] encodeList(byte[]... elements) { public static byte[] encodeList(byte[]... elements) {
int totalLength = 0; int totalLength = 0;
@ -1035,7 +983,6 @@ def encode_length(L,offset):
copyPos = lenBytes.length + 1; copyPos = lenBytes.length + 1;
} }
for (int i = 0; i < elements.length; ++i) { for (int i = 0; i < elements.length; ++i) {
System.arraycopy(elements[i], 0, data, copyPos, elements[i].length); System.arraycopy(elements[i], 0, data, copyPos, elements[i].length);
@ -1045,25 +992,15 @@ def encode_length(L,offset):
return data; return data;
} }
public static void main(String args[]) { public static void main(String args[]) {
char[] data = { 0xF9, 20, 100 }; char[] data = { 0xF9, 20, 100 };
decode(data); decode(data);
} }
public static void main2(String args[]) throws UnsupportedEncodingException { public static void main2(String args[]) throws UnsupportedEncodingException {
List<Object> moreInnerList = new ArrayList(); List<Object> moreInnerList = new ArrayList();
moreInnerList.add("aa"); moreInnerList.add("aa");
@ -1091,12 +1028,8 @@ def encode_length(L,offset):
System.out.println(result); System.out.println(result);
// System.out.println('\u0080'); // System.out.println('\u0080');
// System.out.println(toBinary(252)); // System.out.println(toBinary(252));
} }
} }

View File

@ -62,7 +62,6 @@ public class ClientPeer {
// Wait until the connection is closed. // Wait until the connection is closed.
f.channel().closeFuture().sync(); f.channel().closeFuture().sync();
} catch (InterruptedException ie){ } catch (InterruptedException ie){
System.out.println("-- ClientPeer: catch (InterruptedException ie) --"); System.out.println("-- ClientPeer: catch (InterruptedException ie) --");

View File

@ -1,14 +1,13 @@
package org.ethereum.net.message; package org.ethereum.net.message;
import org.ethereum.net.RLP; import java.util.ArrayList;
import java.util.List;
import org.ethereum.net.rlp.RLPItem; import org.ethereum.net.rlp.RLPItem;
import org.ethereum.net.rlp.RLPList; import org.ethereum.net.rlp.RLPList;
import org.ethereum.net.vo.BlockData; import org.ethereum.net.vo.BlockData;
import org.ethereum.net.vo.TransactionData; import org.ethereum.net.vo.TransactionData;
import java.util.ArrayList;
import java.util.List;
/** /**
* www.ethereumJ.com * www.ethereumJ.com
* User: Roman Mandeleil * User: Roman Mandeleil
@ -25,8 +24,6 @@ public class BlocksMessage extends Message {
super(rawData); super(rawData);
} }
public void parseRLP() { public void parseRLP() {
RLPList paramsList = (RLPList) rawData.getElement(0); RLPList paramsList = (RLPList) rawData.getElement(0);

View File

@ -1,15 +1,13 @@
package org.ethereum.net.message; package org.ethereum.net.message;
import org.ethereum.net.RLP; import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;
import org.ethereum.net.rlp.RLPItem; import org.ethereum.net.rlp.RLPItem;
import org.ethereum.net.rlp.RLPList; import org.ethereum.net.rlp.RLPList;
import org.ethereum.util.Utils; import org.ethereum.util.Utils;
import java.math.BigInteger;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.List;
/** /**
* www.ethereumJ.com * www.ethereumJ.com
* User: Roman Mandeleil * User: Roman Mandeleil
@ -21,7 +19,6 @@ public class GetChainMessage extends Message {
List<byte[]> blockHashList = new ArrayList<byte[]>(); List<byte[]> blockHashList = new ArrayList<byte[]>();
BigInteger blockNum; BigInteger blockNum;
public GetChainMessage(RLPList rawData) { public GetChainMessage(RLPList rawData) {
super(rawData); super(rawData);
} }
@ -36,7 +33,6 @@ public class GetChainMessage extends Message {
throw new Error("GetChain: parsing for mal data"); throw new Error("GetChain: parsing for mal data");
} }
int size = paramsList.size(); int size = paramsList.size();
for (int i = 1; i < size - 1; ++i){ for (int i = 1; i < size - 1; ++i){

View File

@ -29,7 +29,6 @@ public class HelloMessage extends Message {
super(rawData); super(rawData);
} }
public HelloMessage(byte protocolVersion, byte networkId, String clientId, byte capabilities, short peerPort, byte[] peerId) { public HelloMessage(byte protocolVersion, byte networkId, String clientId, byte capabilities, short peerPort, byte[] peerId) {
this.protocolVersion = protocolVersion; this.protocolVersion = protocolVersion;
this.networkId = networkId; this.networkId = networkId;
@ -39,7 +38,6 @@ public class HelloMessage extends Message {
this.peerId = peerId; this.peerId = peerId;
} }
@Override @Override
public void parseRLP() { public void parseRLP() {

View File

@ -1,19 +1,12 @@
package org.ethereum.net.message; package org.ethereum.net.message;
import org.ethereum.net.RLP;
import org.ethereum.net.message.Message;
import org.ethereum.net.rlp.RLPItem;
import org.ethereum.net.rlp.RLPList;
import org.ethereum.net.vo.PeerData;
import java.math.BigInteger;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import static org.junit.Assert.assertEquals; import org.ethereum.net.rlp.RLPItem;
import org.ethereum.net.rlp.RLPList;
import org.ethereum.net.vo.PeerData;
/** /**
* www.ethereumJ.com * www.ethereumJ.com
@ -37,7 +30,6 @@ public class PeersMessage extends Message {
parsed = false; parsed = false;
} }
@Override @Override
public void parseRLP() { public void parseRLP() {
@ -48,7 +40,6 @@ public class PeersMessage extends Message {
throw new Error("PeersMessage: parsing for mal data"); throw new Error("PeersMessage: parsing for mal data");
} }
for (int i = 1; i < paramsList.size(); ++i){ for (int i = 1; i < paramsList.size(); ++i){
RLPList peerParams = (RLPList)paramsList.getElement(i); RLPList peerParams = (RLPList)paramsList.getElement(i);
@ -92,7 +83,6 @@ public class PeersMessage extends Message {
return null; return null;
} }
public List<PeerData> getPeers() { public List<PeerData> getPeers() {
if (!parsed){ if (!parsed){

View File

@ -65,7 +65,6 @@ public class StaticMessages {
byte[] peerIdBytes = Utils.hexStringToByteArr(peerId); byte[] peerIdBytes = Utils.hexStringToByteArr(peerId);
HELLO_MESSAGE = new HelloMessage((byte)0x0C, (byte)0x00, "EthereumJ [v0.0.1] pure java [by Roman Mandeleil]", HELLO_MESSAGE = new HelloMessage((byte)0x0C, (byte)0x00, "EthereumJ [v0.0.1] pure java [by Roman Mandeleil]",
(byte)0b00000111, (short)30303, peerIdBytes); (byte)0b00000111, (short)30303, peerIdBytes);
@ -76,6 +75,5 @@ public class StaticMessages {
} }
public static final HelloMessage HELLO_MESSAGE; public static final HelloMessage HELLO_MESSAGE;
} }

View File

@ -1,7 +1,5 @@
package org.ethereum.net.rlp; package org.ethereum.net.rlp;
import org.bouncycastle.util.Arrays;
/** /**
* www.ethereumJ.com * www.ethereumJ.com
* User: Roman Mandeleil * User: Roman Mandeleil
@ -17,8 +15,8 @@ public class RLPItem implements RLPElement{
public byte[] getData() { public byte[] getData() {
if (data.length == 0) return null; if (data.length == 0)
return null;
return data; return data;
} }
} }

View File

@ -1,14 +1,10 @@
package org.ethereum.net.rlp; package org.ethereum.net.rlp;
import org.bouncycastle.util.Arrays;
import org.bouncycastle.util.encoders.Hex;
import org.ethereum.util.Utils;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.ethereum.util.Utils;
/** /**
* www.ethereumJ.com * www.ethereumJ.com
* User: Roman Mandeleil * User: Roman Mandeleil
@ -19,7 +15,6 @@ public class RLPList implements RLPElement{
byte[] rlpData; byte[] rlpData;
List<RLPElement> list; List<RLPElement> list;
public RLPList() { public RLPList() {
this.list = new ArrayList<RLPElement>(); this.list = new ArrayList<RLPElement>();
} }
@ -46,22 +41,21 @@ public class RLPList implements RLPElement{
this.rlpData = rlpData; this.rlpData = rlpData;
} }
public byte[] getRLPData(){ public byte[] getRLPData(){
return rlpData; return rlpData;
} }
public static void recursivePrint(RLPElement element) { public static void recursivePrint(RLPElement element) {
if (element == null) throw new Error("RLPElement object can't be null"); if (element == null)
throw new Error("RLPElement object can't be null");
if (element instanceof RLPList) { if (element instanceof RLPList) {
RLPList rlpList = (RLPList) element; RLPList rlpList = (RLPList) element;
System.out.print("[");
for (RLPElement singleElement : rlpList.getList()){
System.out.print("[");
for (RLPElement singleElement : rlpList.getList()) {
recursivePrint(singleElement); recursivePrint(singleElement);
} }
System.out.print("]"); System.out.print("]");
@ -70,8 +64,6 @@ public class RLPList implements RLPElement{
String hex = Utils.toHexString(((RLPItem) element).getData()); String hex = Utils.toHexString(((RLPItem) element).getData());
System.out.print(hex + ", "); System.out.print(hex + ", ");
}
}
} }
} }

View File

@ -17,27 +17,25 @@ import java.io.FileReader;
*/ */
public class SerpentCompiler { public class SerpentCompiler {
public static String compile(String code) throws FileNotFoundException, RecognitionException { public static String compile(String code) throws FileNotFoundException,
RecognitionException {
CharStream stream = CharStream stream = new ANTLRStringStream(code);
new ANTLRStringStream(code);
SerpentLexer lex = new SerpentLexer(stream); SerpentLexer lex = new SerpentLexer(stream);
CommonTokenStream tokens = new CommonTokenStream(lex); CommonTokenStream tokens = new CommonTokenStream(lex);
SerpentParser parser = new SerpentParser(tokens); SerpentParser parser = new SerpentParser(tokens);
String userDir = System.getProperty("user.dir"); String userDir = System.getProperty("user.dir");
String templateFileName = userDir + "\\src\\main\\java\\org\\ethereum\\serpent\\Serpent2Asm.stg"; String templateFileName = userDir
+ "\\src\\main\\java\\org\\ethereum\\serpent\\Serpent2Asm.stg";
StringTemplateGroup template = new StringTemplateGroup(new FileReader(templateFileName), StringTemplateGroup template = new StringTemplateGroup(new FileReader(
AngleBracketTemplateLexer.class); templateFileName), AngleBracketTemplateLexer.class);
parser.setTemplateLib(template); parser.setTemplateLib(template);
SerpentParser.program_return retVal = parser.program(); SerpentParser.program_return retVal = parser.program();
return retVal.getTemplate().toString().trim(); return retVal.getTemplate().toString().trim();
} }
} }

View File

@ -127,8 +127,6 @@ public class BlockTest {
System.out.println(Hex.toHexString(hash)); System.out.println(Hex.toHexString(hash));
System.out.println("ab6b9a5613970faa771b12d449b2e9bb925ab7a369f0a4b86b286e9d540099cf"); System.out.println("ab6b9a5613970faa771b12d449b2e9bb925ab7a369f0a4b86b286e9d540099cf");
} }
@Test /* got from go guy */ @Test /* got from go guy */
@ -136,7 +134,6 @@ public class BlockTest {
byte[] goGenesisBytes = Hex.decode("f8a4f8a0a00000000000000000000000000000000000000000000000000000000000000000a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d4934794000000000000000000000000000000000000000080a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347834000008080a004994f67dc55b09e814ab7ffc8df3686b4afb2bb53e60eae97ef043fe03fb829c0c0"); byte[] goGenesisBytes = Hex.decode("f8a4f8a0a00000000000000000000000000000000000000000000000000000000000000000a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d4934794000000000000000000000000000000000000000080a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347834000008080a004994f67dc55b09e814ab7ffc8df3686b4afb2bb53e60eae97ef043fe03fb829c0c0");
System.out.println( Hex.toHexString( Utils.sha3(goGenesisBytes) ) ); System.out.println( Hex.toHexString( Utils.sha3(goGenesisBytes) ) );
} }
@ -155,8 +152,6 @@ public class BlockTest {
RLPList.recursivePrint(rlpList); RLPList.recursivePrint(rlpList);
} }
} }

View File

@ -22,9 +22,6 @@ import static org.junit.Assert.assertEquals;
*/ */
public class RLPTest { public class RLPTest {
@Test @Test
public void test1() throws UnknownHostException { public void test1() throws UnknownHostException {
@ -35,16 +32,11 @@ 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 = Utils.hexStringToByteArr(peersPacket); byte[] payload = Utils.hexStringToByteArr(peersPacket);
byte[] ip = RLP.decodeIP4Bytes(payload, 5); byte[] ip = RLP.decodeIP4Bytes(payload, 5);
assertEquals(InetAddress.getByAddress(ip).toString(),("/54.204.10.41")); assertEquals(InetAddress.getByAddress(ip).toString(),("/54.204.10.41"));
} }
@Test @Test
@ -57,14 +49,10 @@ 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 = Utils.hexStringToByteArr(peersPacket); byte[] payload = Utils.hexStringToByteArr(peersPacket);
int oneInt = RLP.decodeInt(payload, 11); int oneInt = RLP.decodeInt(payload, 11);
assertEquals(oneInt, 30303); assertEquals(oneInt, 30303);
} }
@ -120,7 +108,6 @@ public class RLPTest {
nextIndex = RLP.getNextElementIndex(payload, nextIndex); nextIndex = RLP.getNextElementIndex(payload, nextIndex);
nextIndex = RLP.getFirstListElement(payload, nextIndex); nextIndex = RLP.getFirstListElement(payload, nextIndex);
assertEquals(-1, nextIndex); assertEquals(-1, nextIndex);
} }
@ -171,7 +158,6 @@ public class RLPTest {
byte[] data = RLP.encodeString(""); byte[] data = RLP.encodeString("");
Assert.assertArrayEquals(new byte[]{(byte)0x80}, data); Assert.assertArrayEquals(new byte[]{(byte)0x80}, data);
byte[] expected = { (byte)0x90, (byte)0x45, (byte)0x74, (byte)0x68, (byte)0x65, (byte)0x72, (byte)0x65, byte[] expected = { (byte)0x90, (byte)0x45, (byte)0x74, (byte)0x68, (byte)0x65, (byte)0x72, (byte)0x65,
(byte)0x75, (byte)0x6D, (byte)0x4A, (byte)0x20, (byte)0x43, (byte)0x6C, (byte)0x75, (byte)0x6D, (byte)0x4A, (byte)0x20, (byte)0x43, (byte)0x6C,
(byte)0x69, (byte)0x65, (byte)0x6E, (byte)0x74}; (byte)0x69, (byte)0x65, (byte)0x6E, (byte)0x74};
@ -221,7 +207,6 @@ public class RLPTest {
@Test /** encode byte array */ @Test /** encode byte array */
public void test7(){ public void test7(){
String byteArr = "CE 73 66 0A 06 62 6C 1B 3F DA 7B 18 EF 7B A3 CE " + String byteArr = "CE 73 66 0A 06 62 6C 1B 3F DA 7B 18 EF 7B A3 CE " +
"17 B6 BF 60 4F 95 41 D3 C6 C6 54 B7 AE 88 B2 39 " + "17 B6 BF 60 4F 95 41 D3 C6 C6 54 B7 AE 88 B2 39 " +
"40 7F 65 9C 78 F4 19 02 5D 78 57 27 ED 01 7B 6A " + "40 7F 65 9C 78 F4 19 02 5D 78 57 27 ED 01 7B 6A " +
@ -233,20 +218,16 @@ public class RLPTest {
Assert.assertArrayEquals(Utils.hexStringToByteArr(expected), Assert.assertArrayEquals(Utils.hexStringToByteArr(expected),
RLP.encodeElement(byteArray)); RLP.encodeElement(byteArray));
} }
@Test /** encode list */ @Test /** encode list */
public void test8(){ public void test8(){
} }
@Test /** found bug encode list affects element value, @Test /** found bug encode list affects element value,
hhh... not really at the end but keep the test */ hhh... not really at the end but keep the test */
public void test9(){ public void test9(){
/* 2 */ byte[] prevHash = /* 2 */ byte[] prevHash =
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
@ -265,10 +246,8 @@ public class RLPTest {
byte[] header = RLP.encodeList( byte[] header = RLP.encodeList(
prevHash, uncleList, coinbase); prevHash, uncleList, coinbase);
Assert.assertEquals("f856a000000000000000000000000000000000000000000000000000000000000000001dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347940000000000000000000000000000000000000000", Assert.assertEquals("f856a000000000000000000000000000000000000000000000000000000000000000001dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347940000000000000000000000000000000000000000",
Hex.toHexString(header)); Hex.toHexString(header));
} }

View File

@ -28,30 +28,25 @@ public class TransactionTest {
@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 {
//python taken exact data //python taken exact data
String txRLPRawData = "a9e880872386f26fc1000085e8d4a510008203e89413978aee95f38490e9769c39b2773ed763d9cd5f80"; String txRLPRawData = "a9e880872386f26fc1000085e8d4a510008203e89413978aee95f38490e9769c39b2773ed763d9cd5f80";
// String txRLPRawData = "f82804881bc16d674ec8000094cd2a3d9f938e13cd947ec05abc7fe734df8dd8268609184e72a0006480"; // String txRLPRawData = "f82804881bc16d674ec8000094cd2a3d9f938e13cd947ec05abc7fe734df8dd8268609184e72a0006480";
String cowPrivKey = "c85ef7d79691fe79573b1a7064c19c1a9819ebdbd1faaab1a8ec92344438aaf4"; String cowPrivKey = "c85ef7d79691fe79573b1a7064c19c1a9819ebdbd1faaab1a8ec92344438aaf4";
byte[] data = Hex.decode(txRLPRawData); byte[] data = Hex.decode(txRLPRawData);
byte[] privKey = Hex.decode(cowPrivKey); byte[] privKey = Hex.decode(cowPrivKey);
// step 1: serialize + RLP encode // step 1: serialize + RLP encode
// step 2: hash = sha3(step1) // step 2: hash = sha3(step1)
byte[] txHash = Utils.sha3(data); byte[] txHash = Utils.sha3(data);
X9ECParameters curvParams = SECNamedCurves.getByName("secp256k1"); X9ECParameters curvParams = SECNamedCurves.getByName("secp256k1");
// z = hash_to_int(msghash) // z = hash_to_int(msghash)
// k = deterministic_generate_k(msghash,priv) // k = deterministic_generate_k(msghash,priv)
BigInteger txHashInt = new BigInteger(1, txHash ); BigInteger txHashInt = new BigInteger(1, txHash );
/* /*
v = '\x01' * 32 v = '\x01' * 32
k = '\x00' * 32 k = '\x00' * 32
@ -84,7 +79,6 @@ public class TransactionTest {
hmac.init(secretKey); hmac.init(secretKey);
hmac.reset(); hmac.reset();
ByteArrayOutputStream baos = new ByteArrayOutputStream(v.length + 1 + privKey.length + txHash.length); ByteArrayOutputStream baos = new ByteArrayOutputStream(v.length + 1 + privKey.length + txHash.length);
baos.write(v); baos.write(v);
baos.write(new byte[]{00}); baos.write(new byte[]{00});
@ -101,8 +95,6 @@ public class TransactionTest {
} }
@Test /* achieve public key of the sender */ @Test /* achieve public key of the sender */
public void test2(){ public void test2(){
@ -118,11 +110,6 @@ public class TransactionTest {
String txHash = Hex.toHexString(Utils.sha3(rawTxBytes)); String txHash = Hex.toHexString(Utils.sha3(rawTxBytes));
System.out.println(txHash); System.out.println(txHash);
} }
} }