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.201.28.117", 30303); new ClientPeer(thisConsole).connect("54.204.10.41", 30303);
new ClientPeer(thisConsole).connect("82.217.72.169", 30303); // new ClientPeer(thisConsole).connect("54.201.28.117", 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;

File diff suppressed because it is too large Load Diff

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,24 +1,22 @@
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
* Created on: 21/04/14 16:26 * Created on: 21/04/14 16:26
*/ */
public class RLPItem implements RLPElement{ public class RLPItem implements RLPElement {
byte[] data; byte[] data;
public RLPItem(byte[] data) { public RLPItem(byte[] data) {
this.data = data; this.data = data;
} }
public byte[] getData() { public byte[] getData() {
if (data.length == 0) return null;
return data;
}
if (data.length == 0)
return null;
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,32 +41,29 @@ 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 instanceof RLPList) {
if (element == null) throw new Error("RLPElement object can't be null"); RLPList rlpList = (RLPList) element;
if (element instanceof RLPList){
RLPList rlpList = (RLPList)element; System.out.print("[");
System.out.print("[");
for (RLPElement singleElement : rlpList.getList()){
recursivePrint(singleElement); for (RLPElement singleElement : rlpList.getList()) {
} recursivePrint(singleElement);
System.out.print("]"); }
} else { System.out.print("]");
} else {
String hex = Utils.toHexString(((RLPItem) element).getData()); String hex = Utils.toHexString(((RLPItem) element).getData());
System.out.print(hex + ", "); System.out.print(hex + ", ");
}
} }
}
} }

View File

@ -15,29 +15,27 @@ import java.io.FileReader;
* User: Roman Mandeleil * User: Roman Mandeleil
* Created on: 29/04/14 12:34 * Created on: 29/04/14 12:34
*/ */
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 templateFileName = userDir
+ "\\src\\main\\java\\org\\ethereum\\serpent\\Serpent2Asm.stg";
String userDir = System.getProperty("user.dir"); StringTemplateGroup template = new StringTemplateGroup(new FileReader(
String templateFileName = userDir + "\\src\\main\\java\\org\\ethereum\\serpent\\Serpent2Asm.stg"; templateFileName), AngleBracketTemplateLexer.class);
parser.setTemplateLib(template);
StringTemplateGroup template = new StringTemplateGroup(new FileReader(templateFileName), SerpentParser.program_return retVal = parser.program();
AngleBracketTemplateLexer.class);
parser.setTemplateLib(template);
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);
} }
} }