Cleanup formatting and re-use Command enum
This commit is contained in:
parent
288e361043
commit
45bc55cf9e
9
README
9
README
|
@ -1,2 +1,7 @@
|
|||
-- First small steps in the big journey
|
||||
test
|
||||
Java implementation of Ethereum.
|
||||
|
||||
**Website:** http://www.ethereum.org
|
||||
|
||||
**Whitepaper:** https://github.com/ethereum/wiki/wiki/%5BEnglish%5D-White-Paper
|
||||
|
||||
**Yellow Paper:** http://gavwood.com/Paper.pdf
|
|
@ -1,14 +1,19 @@
|
|||
package org.ethereum.gui;
|
||||
|
||||
import org.ethereum.net.client.ClientPeer;
|
||||
import org.fife.ui.rsyntaxtextarea.*;
|
||||
import org.fife.ui.rtextarea.RTextScrollPane;
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Image;
|
||||
import java.awt.Toolkit;
|
||||
import java.awt.event.ComponentAdapter;
|
||||
import java.awt.event.ComponentEvent;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.io.IOException;
|
||||
import java.util.TimerTask;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.SwingUtilities;
|
||||
|
||||
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
|
||||
|
@ -27,9 +32,7 @@ public class ConnectionConsole extends JFrame implements PeerListener{
|
|||
|
||||
private RSyntaxTextArea textArea;
|
||||
|
||||
|
||||
public ConnectionConsole() {
|
||||
|
||||
final ConnectionConsole thisConsole = this;
|
||||
|
||||
java.net.URL url = ClassLoader.getSystemResource("ethereum-icon.png");
|
||||
|
@ -56,7 +59,6 @@ public class ConnectionConsole extends JFrame implements PeerListener{
|
|||
|
||||
@Override
|
||||
public void componentShown(ComponentEvent e) {
|
||||
|
||||
Thread t = new Thread() {
|
||||
public void run() {
|
||||
// new ClientPeer(thisConsole).connect("54.201.28.117", 30303);
|
||||
|
@ -66,40 +68,27 @@ public class ConnectionConsole extends JFrame implements PeerListener{
|
|||
}
|
||||
};
|
||||
t.start();
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void console(final String output) {
|
||||
|
||||
|
||||
SwingUtilities.invokeLater(new Runnable()
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
textArea.append(output);
|
||||
textArea.append("\n");
|
||||
textArea.setCaretPosition(textArea.getText().length());
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
// Start all Swing applications on the EDT.
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
new ConnectionConsole().setVisible(true);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
@Override
|
||||
public void console(final String output) {
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
textArea.append(output);
|
||||
textArea.append("\n");
|
||||
textArea.setCaretPosition(textArea.getText().length());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
// Start all Swing applications on the EDT.
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
new ConnectionConsole().setVisible(true);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,11 +1,20 @@
|
|||
package org.ethereum.gui;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Color;
|
||||
import java.awt.Font;
|
||||
import java.awt.Image;
|
||||
import java.awt.Toolkit;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JTable;
|
||||
import javax.swing.ListSelectionModel;
|
||||
import javax.swing.SwingConstants;
|
||||
import javax.swing.table.DefaultTableCellRenderer;
|
||||
import javax.swing.table.TableCellRenderer;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
/**
|
||||
* www.ethereumJ.com
|
||||
* User: Roman Mandeleil
|
||||
|
|
|
@ -1,11 +1,5 @@
|
|||
package org.ethereum.gui;
|
||||
|
||||
import com.maxmind.geoip.Location;
|
||||
import org.ethereum.geodb.IpGeoDB;
|
||||
import org.ethereum.util.Utils;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.table.AbstractTableModel;
|
||||
import java.net.InetAddress;
|
||||
import java.net.URL;
|
||||
import java.net.UnknownHostException;
|
||||
|
@ -13,22 +7,30 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import javax.swing.ImageIcon;
|
||||
import javax.swing.table.AbstractTableModel;
|
||||
|
||||
import org.ethereum.geodb.IpGeoDB;
|
||||
import org.ethereum.util.Utils;
|
||||
|
||||
import com.maxmind.geoip.Location;
|
||||
|
||||
/**
|
||||
* www.ethereumJ.com
|
||||
* User: Roman Mandeleil
|
||||
* Created on: 25/04/14 07:04
|
||||
*/
|
||||
public class PeersTableModel extends AbstractTableModel {
|
||||
public class PeersTableModel extends AbstractTableModel {
|
||||
|
||||
List<PeerInfo> peerInfoList = new ArrayList<PeerInfo>();
|
||||
private static final long serialVersionUID = -6984988938009834569L;
|
||||
|
||||
private List<PeerInfo> peerInfoList = new ArrayList<PeerInfo>();
|
||||
|
||||
public PeersTableModel() {
|
||||
|
||||
generateRandomData();
|
||||
}
|
||||
|
||||
public String getColumnName(int column) {
|
||||
|
||||
if (column == 0) return "Location";
|
||||
if (column == 1) return "IP";
|
||||
if (column == 2) return "Live";
|
||||
|
@ -39,7 +41,7 @@ public class PeersTableModel extends AbstractTableModel {
|
|||
return false;
|
||||
}
|
||||
|
||||
public Class getColumnClass(int column) {
|
||||
public Class<?> getColumnClass(int column) {
|
||||
if (column == 0) return ImageIcon.class;
|
||||
if (column == 1) return String.class;
|
||||
if (column == 2) return ImageIcon.class;
|
||||
|
@ -51,32 +53,23 @@ public class PeersTableModel extends AbstractTableModel {
|
|||
PeerInfo peerInfo = peerInfoList.get(row);
|
||||
|
||||
if (column == 0){
|
||||
|
||||
String countryCode = peerInfo.getLocation().countryCode;
|
||||
URL flagURL = ClassLoader.getSystemResource("flags/" + countryCode + ".png");
|
||||
ImageIcon flagIcon = new ImageIcon(flagURL);
|
||||
|
||||
return flagIcon;
|
||||
}
|
||||
|
||||
if (column == 1) return peerInfo.getIp().getHostAddress();
|
||||
if (column == 1)
|
||||
return peerInfo.getIp().getHostAddress();
|
||||
if (column == 2) {
|
||||
|
||||
Random random = new Random();
|
||||
boolean isConnected = random.nextBoolean();
|
||||
|
||||
ImageIcon flagIcon = null;
|
||||
if (peerInfo.connected){
|
||||
|
||||
flagIcon = Utils.getImageIcon("connected.png");
|
||||
} else {
|
||||
|
||||
flagIcon = Utils.getImageIcon("disconnected.png");
|
||||
}
|
||||
|
||||
return flagIcon;
|
||||
}
|
||||
|
||||
else return "";
|
||||
}
|
||||
|
||||
|
@ -88,8 +81,6 @@ public class PeersTableModel extends AbstractTableModel {
|
|||
return 3;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// todo: delete it when stabilized
|
||||
private void generateRandomData(){
|
||||
|
||||
|
@ -115,21 +106,18 @@ public class PeersTableModel extends AbstractTableModel {
|
|||
ips.add("82.240.16.5");
|
||||
ips.add("74.79.23.119");
|
||||
|
||||
|
||||
for (String peer : ips){
|
||||
|
||||
try {
|
||||
|
||||
InetAddress addr = InetAddress.getByName(peer);
|
||||
Location cr = IpGeoDB.getLocationForIp(addr);
|
||||
|
||||
peerInfoList.add(new PeerInfo(cr, addr));
|
||||
|
||||
} catch (UnknownHostException e) {e.printStackTrace(); }
|
||||
} catch (UnknownHostException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class PeerInfo{
|
||||
private class PeerInfo {
|
||||
|
||||
Location location;
|
||||
InetAddress ip;
|
||||
|
@ -147,7 +135,6 @@ public class PeersTableModel extends AbstractTableModel {
|
|||
return ip;
|
||||
}
|
||||
|
||||
|
||||
private Location getLocation() {
|
||||
return location;
|
||||
}
|
||||
|
|
|
@ -1,12 +1,27 @@
|
|||
package org.ethereum.gui;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Color;
|
||||
import java.awt.Font;
|
||||
import java.awt.Image;
|
||||
import java.awt.Toolkit;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.io.IOException;
|
||||
import javax.swing.*;
|
||||
|
||||
import org.fife.ui.rtextarea.*;
|
||||
import org.fife.ui.rsyntaxtextarea.*;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JMenu;
|
||||
import javax.swing.JMenuBar;
|
||||
import javax.swing.JMenuItem;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.SwingUtilities;
|
||||
|
||||
import org.fife.ui.rsyntaxtextarea.RSyntaxTextArea;
|
||||
import org.fife.ui.rsyntaxtextarea.SyntaxConstants;
|
||||
import org.fife.ui.rsyntaxtextarea.SyntaxScheme;
|
||||
import org.fife.ui.rsyntaxtextarea.Theme;
|
||||
import org.fife.ui.rsyntaxtextarea.Token;
|
||||
import org.fife.ui.rtextarea.RTextScrollPane;
|
||||
|
||||
/**
|
||||
* A simple example showing how to modify the fonts and colors used in an
|
||||
|
@ -76,7 +91,6 @@ public class SyntaxSchemeDemo extends JFrame implements ActionListener {
|
|||
setDefaultCloseOperation(EXIT_ON_CLOSE);
|
||||
pack();
|
||||
setLocationRelativeTo(null);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -109,7 +123,6 @@ public class SyntaxSchemeDemo extends JFrame implements ActionListener {
|
|||
Font.ITALIC, 12);
|
||||
|
||||
textArea.revalidate();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -154,5 +167,4 @@ public class SyntaxSchemeDemo extends JFrame implements ActionListener {
|
|||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,8 +1,11 @@
|
|||
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.PeerData;
|
||||
import org.ethereum.net.vo.TransactionData;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
|
@ -15,26 +18,18 @@ public class MainData {
|
|||
|
||||
private Set<PeerData> peers = Collections.synchronizedSet(new HashSet<PeerData>());
|
||||
|
||||
private List blocks = Collections.synchronizedList(new ArrayList());
|
||||
private List transactions = Collections.synchronizedList(new ArrayList());
|
||||
|
||||
public static MainData instance = new MainData();
|
||||
|
||||
public void addPeers(List newPeers){
|
||||
public void addPeers(List<PeerData> newPeers){
|
||||
this.peers.addAll(newPeers);
|
||||
|
||||
|
||||
for (PeerData peerData : this.peers){
|
||||
|
||||
Location location = IpGeoDB.getLocationForIp(peerData.getInetAddress());
|
||||
if (location != null)
|
||||
System.out.println("Hello: " + " [" + peerData.getInetAddress().toString()
|
||||
+ "] " + location.countryName);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void addBlocks(List blocks){}
|
||||
public void addTransactions(List transactions){}
|
||||
|
||||
public void addBlocks(List<BlockData> blocks) {}
|
||||
public void addTransactions(List<TransactionData> transactions) {}
|
||||
}
|
||||
|
|
|
@ -37,4 +37,8 @@ public enum Command {
|
|||
return Command.UNKNOWN;
|
||||
return type;
|
||||
}
|
||||
|
||||
public byte asByte() {
|
||||
return (byte) cmd;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,8 +6,6 @@ package org.ethereum.net;
|
|||
* Created on: 04/04/14 00:51
|
||||
*/
|
||||
public class MessageDeserializer {
|
||||
|
||||
|
||||
/**
|
||||
* Get exactly one message payload
|
||||
*/
|
||||
|
@ -21,43 +19,34 @@ public class MessageDeserializer {
|
|||
// 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){
|
||||
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--;
|
||||
}
|
||||
|
||||
// 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 ;
|
||||
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
|
||||
|
@ -67,18 +56,13 @@ public class MessageDeserializer {
|
|||
byte pow = (byte) (lenghtOfLenght - 1);
|
||||
|
||||
int length = 0;
|
||||
|
||||
for (int i = 1; i <= lenghtOfLenght; ++i){
|
||||
|
||||
length += msgData[pos + i] << (8 * pow);
|
||||
pow--;
|
||||
}
|
||||
|
||||
|
||||
// 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 ;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -88,10 +72,8 @@ public class MessageDeserializer {
|
|||
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;
|
||||
}
|
||||
|
||||
|
@ -108,14 +90,6 @@ public class MessageDeserializer {
|
|||
pos += 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -11,9 +11,6 @@ import java.util.Queue;
|
|||
import org.ethereum.net.rlp.RLPItem;
|
||||
import org.ethereum.net.rlp.RLPList;
|
||||
|
||||
/**
|
||||
|
||||
*/
|
||||
public class RLP {
|
||||
|
||||
public static byte decodeOneByteItem(byte[] data, int index) {
|
||||
|
|
|
@ -2,12 +2,8 @@ package org.ethereum.net.client;
|
|||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.ChannelOutboundBuffer;
|
||||
import io.netty.handler.codec.ByteToMessageDecoder;
|
||||
import io.netty.handler.codec.ReplayingDecoder;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
|
@ -17,7 +13,6 @@ import java.util.List;
|
|||
*/
|
||||
public class EthereumFrameDecoder extends ByteToMessageDecoder {
|
||||
|
||||
|
||||
@Override
|
||||
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
|
||||
|
||||
|
@ -36,10 +31,8 @@ public class EthereumFrameDecoder extends ByteToMessageDecoder {
|
|||
ctx.close();
|
||||
}
|
||||
|
||||
|
||||
// Don't have the full packet yet
|
||||
if (msgSize > in.readableBytes()) {
|
||||
|
||||
in.resetReaderIndex();
|
||||
return;
|
||||
}
|
||||
|
@ -52,4 +45,4 @@ public class EthereumFrameDecoder extends ByteToMessageDecoder {
|
|||
// Chop the achieved data.
|
||||
in.markReaderIndex();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,22 +1,43 @@
|
|||
package org.ethereum.net.client;
|
||||
|
||||
|
||||
import static org.ethereum.net.Command.BLOCKS;
|
||||
import static org.ethereum.net.Command.DISCONNECT;
|
||||
import static org.ethereum.net.Command.GET_CHAIN;
|
||||
import static org.ethereum.net.Command.GET_PEERS;
|
||||
import static org.ethereum.net.Command.GET_TRANSACTIONS;
|
||||
import static org.ethereum.net.Command.HELLO;
|
||||
import static org.ethereum.net.Command.NOT_IN_CHAIN;
|
||||
import static org.ethereum.net.Command.PEERS;
|
||||
import static org.ethereum.net.Command.PING;
|
||||
import static org.ethereum.net.Command.PONG;
|
||||
import static org.ethereum.net.Command.TRANSACTIONS;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.ChannelInboundHandlerAdapter;
|
||||
import io.netty.channel.ChannelOption;
|
||||
import io.netty.channel.FixedRecvByteBufAllocator;
|
||||
import org.spongycastle.util.encoders.Hex;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
|
||||
import org.ethereum.gui.PeerListener;
|
||||
import org.ethereum.manager.MainData;
|
||||
import org.ethereum.net.Command;
|
||||
import org.ethereum.net.RLP;
|
||||
import org.ethereum.net.message.*;
|
||||
import org.ethereum.net.message.BlocksMessage;
|
||||
import org.ethereum.net.message.DisconnectMessage;
|
||||
import org.ethereum.net.message.GetChainMessage;
|
||||
import org.ethereum.net.message.HelloMessage;
|
||||
import org.ethereum.net.message.Message;
|
||||
import org.ethereum.net.message.NotInChainMessage;
|
||||
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.util.Utils;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import org.spongycastle.util.encoders.Hex;
|
||||
|
||||
/**
|
||||
* www.ethereumJ.com
|
||||
|
@ -34,7 +55,6 @@ public class EthereumProtocolHandler extends ChannelInboundHandlerAdapter {
|
|||
private long lastPongTime = 0;
|
||||
private boolean tearDown = false;
|
||||
|
||||
|
||||
// hello data
|
||||
private boolean handShaked = false;
|
||||
private byte protocolVersion;
|
||||
|
@ -45,7 +65,7 @@ public class EthereumProtocolHandler extends ChannelInboundHandlerAdapter {
|
|||
private short peerPort;
|
||||
private byte[] peerId;
|
||||
|
||||
PeerListener peerListener;
|
||||
private PeerListener peerListener;
|
||||
|
||||
public EthereumProtocolHandler() { }
|
||||
|
||||
|
@ -58,10 +78,7 @@ public class EthereumProtocolHandler extends ChannelInboundHandlerAdapter {
|
|||
|
||||
// TODO: send hello
|
||||
// TODO: send ping schedule another ping
|
||||
|
||||
// TODO: ByteBuf vs Stream vs new byte ???
|
||||
|
||||
|
||||
final ByteBuf buffer = ctx.alloc().buffer(HELLO_MESSAGE.length + 8);
|
||||
|
||||
buffer.writeBytes(MAGIC_PREFIX);
|
||||
|
@ -69,7 +86,6 @@ public class EthereumProtocolHandler extends ChannelInboundHandlerAdapter {
|
|||
buffer.writeBytes(HELLO_MESSAGE);
|
||||
ctx.writeAndFlush(buffer);
|
||||
|
||||
|
||||
// sample for pinging in background
|
||||
timer.scheduleAtFixedRate(new TimerTask() {
|
||||
|
||||
|
@ -88,7 +104,6 @@ public class EthereumProtocolHandler extends ChannelInboundHandlerAdapter {
|
|||
|
||||
System.out.println("[Send: PING]");
|
||||
if (peerListener != null) peerListener.console("[Send: PING]");
|
||||
|
||||
sendPing(ctx);
|
||||
}
|
||||
}, 2000, 5000);
|
||||
|
@ -119,7 +134,6 @@ public class EthereumProtocolHandler extends ChannelInboundHandlerAdapter {
|
|||
sendGetChain(ctx);
|
||||
}
|
||||
}, 10000);
|
||||
|
||||
/*
|
||||
timer.schedule(new TimerTask() {
|
||||
|
||||
|
@ -130,29 +144,18 @@ public class EthereumProtocolHandler extends ChannelInboundHandlerAdapter {
|
|||
}
|
||||
}, 10000);
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* The message relieved here
|
||||
* @param ctx
|
||||
* @param msg
|
||||
* @throws Exception
|
||||
*/
|
||||
@Override
|
||||
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
|
||||
|
||||
|
||||
byte[] payload = (byte[]) msg;
|
||||
|
||||
System.out.print("msg: ");
|
||||
Utils.printHexStringForByteArray(payload);
|
||||
|
||||
byte command = RLP.getCommandCode(payload);
|
||||
|
||||
// got HELLO
|
||||
if ((int) (command & 0xFF) == 0x00) {
|
||||
if (Command.fromInt(command) == HELLO) {
|
||||
|
||||
System.out.println("[Recv: HELLO]" );
|
||||
RLPList rlpList = new RLPList();
|
||||
|
@ -168,12 +171,10 @@ public class EthereumProtocolHandler extends ChannelInboundHandlerAdapter {
|
|||
|
||||
System.out.println(helloMessage.toString());
|
||||
if (peerListener != null) peerListener.console(helloMessage.toString());
|
||||
|
||||
}
|
||||
|
||||
|
||||
// got DISCONNECT
|
||||
if ((int) (command & 0xFF) == 0x01) {
|
||||
if (Command.fromInt(command) == DISCONNECT) {
|
||||
|
||||
System.out.println("[Recv: DISCONNECT]");
|
||||
if (peerListener != null) peerListener.console("[Recv: DISCONNECT]");
|
||||
|
@ -184,35 +185,28 @@ public class EthereumProtocolHandler extends ChannelInboundHandlerAdapter {
|
|||
|
||||
System.out.println(disconnectMessage);
|
||||
if (peerListener != null) peerListener.console(disconnectMessage.toString());
|
||||
|
||||
}
|
||||
|
||||
// got PING send pong
|
||||
if ((int) (command & 0xFF) == 0x02) {
|
||||
|
||||
if (Command.fromInt(command) == PING) {
|
||||
System.out.println("[Recv: PING]");
|
||||
if (peerListener != null) peerListener.console("[Recv: PING]");
|
||||
|
||||
sendPong(ctx);
|
||||
}
|
||||
|
||||
// got PONG mark it
|
||||
if ((int) (command & 0xFF) == 0x03) {
|
||||
|
||||
if (Command.fromInt(command) == PONG) {
|
||||
System.out.println("[Recv: PONG]" );
|
||||
if (peerListener != null) peerListener.console("[Recv: PONG]");
|
||||
|
||||
this.lastPongTime = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
// got GETPEERS send peers
|
||||
if ((int) (command & 0xFF) == 0x10) {
|
||||
|
||||
if (Command.fromInt(command) == GET_PEERS) {
|
||||
System.out.println("[Recv: GETPEERS]" );
|
||||
if (peerListener != null) peerListener.console("[Recv: GETPEERS]");
|
||||
|
||||
String answer = "2240089100000134F9013111F84A8456084B1482765FB84072FD5DBC7F458FB0A52354E25234CEA90A51EA09858A21406056D9B9E0826BB153527E4C4CBEC53B46B0245E6E8503EEABDBF0F1789D7C5C78BBF2B1FDD9090CF84A8455417E2D82765FB840CE73F1F1F1F16C1B3FDA7B18EF7BA3CE17B6F1F1F1F141D3C6C654B7AE88B239407FF1F1F1F119025D785727ED017B6ADD21F1F1F1F1000001E321DBC31824BAF84A8436C91C7582765FB840D592C570B5082D357C30E61E3D8F26317BFD7A3A2A00A36CFB7254FEE80830F26DDFBD6A99712552F3D77314DB4AB58B9989F25699C4997A0F62489D4B86CB4DF84A8436CC0A2982765FB840E34C6E3EAC28CFD3DC930A5AEFD9552FEBCD72C33DFC74D8E4C7CF8A7BA71AE53316ADDBD241EB051ED0871C2B62825E66A45DC6A0E752A7F1C22ABEF9ABDE32";
|
||||
|
||||
byte[] answerBytes = Hex.decode(answer);
|
||||
|
||||
ByteBuf buffer = ctx.alloc().buffer(answerBytes.length);
|
||||
|
@ -223,16 +217,15 @@ public class EthereumProtocolHandler extends ChannelInboundHandlerAdapter {
|
|||
answer = "22 40 08 91 00 00 00 02 C1 10 ";
|
||||
answerBytes = Hex.decode(answer);
|
||||
buffer = ctx.alloc().buffer(answerBytes.length);
|
||||
|
||||
|
||||
answerBytes = Utils.hexStringToByteArr(answer);
|
||||
|
||||
buffer = ctx.alloc().buffer(answerBytes.length);
|
||||
buffer.writeBytes(answerBytes);
|
||||
ctx.writeAndFlush(buffer);
|
||||
}
|
||||
|
||||
// got PEERS
|
||||
if ((int) (command & 0xFF) == 0x11) {
|
||||
if (Command.fromInt(command) == PEERS) {
|
||||
|
||||
System.out.println("[Recv: PEERS]");
|
||||
if (peerListener != null) peerListener.console("[Recv: PEERS]");
|
||||
|
@ -248,7 +241,7 @@ public class EthereumProtocolHandler extends ChannelInboundHandlerAdapter {
|
|||
}
|
||||
|
||||
// got TRANSACTIONS
|
||||
if ((int) (command & 0xFF) == 0x12) {
|
||||
if (Command.fromInt(command) == TRANSACTIONS) {
|
||||
|
||||
System.out.println("Recv: TRANSACTIONS]");
|
||||
if (peerListener != null) peerListener.console("Recv: TRANSACTIONS]");
|
||||
|
@ -265,7 +258,7 @@ public class EthereumProtocolHandler extends ChannelInboundHandlerAdapter {
|
|||
}
|
||||
|
||||
// got BLOCKS
|
||||
if ((int) (command & 0xFF) == 0x13) {
|
||||
if (Command.fromInt(command) == BLOCKS) {
|
||||
System.out.println("[Recv: BLOCKS]");
|
||||
if (peerListener != null) peerListener.console("[Recv: BLOCKS]");
|
||||
|
||||
|
@ -273,15 +266,15 @@ public class EthereumProtocolHandler extends ChannelInboundHandlerAdapter {
|
|||
RLP.parseObjects(payload, rlpList);
|
||||
|
||||
BlocksMessage blocksMessage = new BlocksMessage(rlpList);
|
||||
List<BlockData> list = blocksMessage.getBlockDataList();
|
||||
List<BlockData> blockList = blocksMessage.getBlockDataList();
|
||||
|
||||
MainData.instance.addBlocks(list);
|
||||
MainData.instance.addBlocks(blockList);
|
||||
System.out.println(blocksMessage);
|
||||
if (peerListener != null) peerListener.console(blocksMessage.toString());
|
||||
}
|
||||
|
||||
// got GETCHAIN
|
||||
if ((int) (command & 0xFF) == 0x14) {
|
||||
if (Command.fromInt(command) == GET_CHAIN) {
|
||||
System.out.println("[Recv: GET_CHAIN]");
|
||||
if (peerListener != null) peerListener.console("[Recv: GET_CHAIN]");
|
||||
|
||||
|
@ -294,7 +287,7 @@ public class EthereumProtocolHandler extends ChannelInboundHandlerAdapter {
|
|||
}
|
||||
|
||||
// got NOTINCHAIN
|
||||
if ((int) (command & 0xFF) == 0x15) {
|
||||
if (Command.fromInt(command) == NOT_IN_CHAIN) {
|
||||
System.out.println("[Recv: NOT_IN_CHAIN]");
|
||||
if (peerListener != null) peerListener.console("[Recv: NOT_IN_CHAIN]");
|
||||
|
||||
|
@ -307,12 +300,11 @@ public class EthereumProtocolHandler extends ChannelInboundHandlerAdapter {
|
|||
}
|
||||
|
||||
// got GETTRANSACTIONS
|
||||
if ((int) (command & 0xFF) == 0x16) {
|
||||
if (Command.fromInt(command) == GET_TRANSACTIONS) {
|
||||
System.out.println("[Recv: GET_TRANSACTIONS]");
|
||||
if (peerListener != null) peerListener.console("[Recv: GET_TRANSACTIONS]");
|
||||
|
||||
// todo: send the queue of the transactions
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -324,10 +316,8 @@ public class EthereumProtocolHandler extends ChannelInboundHandlerAdapter {
|
|||
ctx.channel().config().setOption(ChannelOption.SO_RCVBUF, 32368);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
|
||||
|
||||
this.tearDown = true;
|
||||
System.out.println("Lost connection to the server");
|
||||
cause.printStackTrace();
|
||||
|
@ -349,15 +339,12 @@ public class EthereumProtocolHandler extends ChannelInboundHandlerAdapter {
|
|||
|
||||
|
||||
private void sendPing(ChannelHandlerContext ctx){
|
||||
|
||||
ByteBuf buffer = ctx.alloc().buffer(StaticMessages.PING.length);
|
||||
buffer.writeBytes(StaticMessages.PING);
|
||||
ctx.writeAndFlush(buffer);
|
||||
}
|
||||
|
||||
|
||||
private void sendPong(ChannelHandlerContext ctx){
|
||||
|
||||
System.out.println("[Send: PONG]");
|
||||
ByteBuf buffer = ctx.alloc().buffer(StaticMessages.PONG.length);
|
||||
buffer.writeBytes(StaticMessages.PONG);
|
||||
|
@ -365,28 +352,24 @@ public class EthereumProtocolHandler extends ChannelInboundHandlerAdapter {
|
|||
}
|
||||
|
||||
private void sendGetPeers(ChannelHandlerContext ctx){
|
||||
|
||||
ByteBuf buffer = ctx.alloc().buffer(StaticMessages.GET_PEERS.length);
|
||||
buffer.writeBytes(StaticMessages.GET_PEERS);
|
||||
ctx.writeAndFlush(buffer);
|
||||
}
|
||||
|
||||
private void sendGetTransactions(ChannelHandlerContext ctx){
|
||||
|
||||
ByteBuf buffer = ctx.alloc().buffer(StaticMessages.GET_TRANSACTIONS.length);
|
||||
buffer.writeBytes(StaticMessages.GET_TRANSACTIONS);
|
||||
ctx.writeAndFlush(buffer);
|
||||
}
|
||||
|
||||
private void sendGetChain(ChannelHandlerContext ctx){
|
||||
|
||||
ByteBuf buffer = ctx.alloc().buffer(StaticMessages.GET_CHAIN.length);
|
||||
buffer.writeBytes(StaticMessages.GET_CHAIN);
|
||||
ctx.writeAndFlush(buffer);
|
||||
}
|
||||
|
||||
private void sendTx(ChannelHandlerContext ctx){
|
||||
|
||||
byte[] TX_MSG =
|
||||
Hex.decode("2240089100000070F86E12F86B80881BC16D674EC8000094CD2A3D9F938E13CD947EC05ABC7FE734DF8DD8268609184E72A00064801BA0C52C114D4F5A3BA904A9B3036E5E118FE0DBB987FE3955DA20F2CD8F6C21AB9CA06BA4C2874299A55AD947DBC98A25EE895AABF6B625C26C435E84BFD70EDF2F69");
|
||||
|
||||
|
@ -395,7 +378,6 @@ public class EthereumProtocolHandler extends ChannelInboundHandlerAdapter {
|
|||
ctx.writeAndFlush(buffer);
|
||||
}
|
||||
|
||||
|
||||
private static byte[] calcPacketLength(byte[] msg){
|
||||
|
||||
int msgLen = msg.length;
|
||||
|
@ -405,9 +387,7 @@ public class EthereumProtocolHandler extends ChannelInboundHandlerAdapter {
|
|||
(byte)((msgLen >> 16) & 0xFF),
|
||||
(byte)((msgLen >> 8) & 0xFF),
|
||||
(byte)((msgLen ) & 0xFF)};
|
||||
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -3,6 +3,9 @@ package org.ethereum.net.message;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
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;
|
||||
|
@ -15,11 +18,8 @@ import org.ethereum.net.vo.TransactionData;
|
|||
*/
|
||||
public class BlocksMessage extends Message {
|
||||
|
||||
private final byte commandCode = 0x13;
|
||||
|
||||
private List<BlockData> blockDataList = new ArrayList<BlockData>();
|
||||
|
||||
|
||||
public BlocksMessage(RLPList rawData) {
|
||||
super(rawData);
|
||||
}
|
||||
|
@ -28,34 +28,29 @@ public class BlocksMessage extends Message {
|
|||
|
||||
RLPList paramsList = (RLPList) rawData.getElement(0);
|
||||
|
||||
if (((RLPItem)(paramsList).getElement(0)).getData()[0] != commandCode){
|
||||
|
||||
if ( Command.fromInt(((RLPItem)(paramsList).getElement(0)).getData()[0]) != BLOCKS){
|
||||
throw new Error("BlocksMessage: parsing for mal data");
|
||||
}
|
||||
|
||||
for (int i = 1; i < paramsList.size(); ++i){
|
||||
|
||||
RLPList rlpData = ((RLPList)paramsList.getElement(i));
|
||||
BlockData blockData = new BlockData(rlpData);
|
||||
this.blockDataList.add(blockData);
|
||||
}
|
||||
|
||||
parsed = true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public byte[] getPayload() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public List<BlockData> getBlockDataList() {
|
||||
if (!parsed) parseRLP();
|
||||
return blockDataList;
|
||||
}
|
||||
|
||||
public String toString(){
|
||||
public String toString() {
|
||||
|
||||
StringBuffer sb = new StringBuffer();
|
||||
for (BlockData blockData : this.getBlockDataList()){
|
||||
|
@ -63,7 +58,6 @@ public class BlocksMessage extends Message {
|
|||
|
||||
List<TransactionData> transactions = blockData.getTransactionsList();
|
||||
for (TransactionData transactionData : transactions){
|
||||
|
||||
sb.append("[").append(transactionData).append("]\n");
|
||||
}
|
||||
}
|
||||
|
@ -71,6 +65,5 @@ public class BlocksMessage extends Message {
|
|||
return "Blocks Message [\n" +
|
||||
sb.toString()
|
||||
+ " ]";
|
||||
|
||||
}
|
||||
}
|
|
@ -2,7 +2,8 @@ package org.ethereum.net.message;
|
|||
|
||||
import org.ethereum.net.rlp.RLPItem;
|
||||
import org.ethereum.net.rlp.RLPList;
|
||||
|
||||
import org.ethereum.net.Command;
|
||||
import static org.ethereum.net.Command.DISCONNECT;
|
||||
|
||||
/**
|
||||
* www.ethereumJ.com
|
||||
|
@ -11,7 +12,6 @@ import org.ethereum.net.rlp.RLPList;
|
|||
*/
|
||||
public class DisconnectMessage extends Message {
|
||||
|
||||
private final byte commandCode = 0x1;
|
||||
private byte reason;
|
||||
|
||||
public static byte REASON_DISCONNECT_REQUESTED = 0x00;
|
||||
|
@ -24,7 +24,6 @@ public class DisconnectMessage extends Message {
|
|||
public static byte REASON_INCOMPATIBLE_PROTOCOL = 0x07;
|
||||
public static byte REASON_PEER_QUITING = 0x08;
|
||||
|
||||
|
||||
public DisconnectMessage(RLPList rawData) {
|
||||
super(rawData);
|
||||
}
|
||||
|
@ -34,25 +33,20 @@ public class DisconnectMessage extends Message {
|
|||
|
||||
RLPList paramsList = (RLPList) rawData.getElement(0);
|
||||
|
||||
if (((RLPItem)(paramsList).getElement(0)).getData()[0] != commandCode){
|
||||
|
||||
if (Command.fromInt(((RLPItem)(paramsList).getElement(0)).getData()[0]) != DISCONNECT){
|
||||
throw new Error("Disconnect: parsing for mal data");
|
||||
}
|
||||
|
||||
byte[] reasonB = ((RLPItem)paramsList.getElement(1)).getData();
|
||||
if (reasonB == null){
|
||||
|
||||
this.reason = 0;
|
||||
} else {
|
||||
|
||||
this.reason = reasonB[0];
|
||||
}
|
||||
|
||||
this.parsed = true;
|
||||
// todo: what to do when mal data ?
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public byte[] getPayload() {
|
||||
return null;
|
||||
|
@ -64,9 +58,8 @@ public class DisconnectMessage extends Message {
|
|||
}
|
||||
|
||||
public String toString(){
|
||||
|
||||
if (!parsed) parseRLP();
|
||||
return "Disconnect Message [ reason=" + reason + " ]";
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -4,6 +4,8 @@ import java.math.BigInteger;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.ethereum.net.Command.GET_CHAIN;
|
||||
import org.ethereum.net.Command;
|
||||
import org.ethereum.net.rlp.RLPItem;
|
||||
import org.ethereum.net.rlp.RLPList;
|
||||
import org.ethereum.util.Utils;
|
||||
|
@ -15,7 +17,6 @@ import org.ethereum.util.Utils;
|
|||
*/
|
||||
public class GetChainMessage extends Message {
|
||||
|
||||
private final byte commandCode = 0x14;
|
||||
List<byte[]> blockHashList = new ArrayList<byte[]>();
|
||||
BigInteger blockNum;
|
||||
|
||||
|
@ -28,14 +29,12 @@ public class GetChainMessage extends Message {
|
|||
|
||||
RLPList paramsList = (RLPList) rawData.getElement(0);
|
||||
|
||||
if (((RLPItem)(paramsList).getElement(0)).getData()[0] != commandCode){
|
||||
|
||||
if (Command.fromInt(((RLPItem)(paramsList).getElement(0)).getData()[0]) != GET_CHAIN){
|
||||
throw new Error("GetChain: parsing for mal data");
|
||||
}
|
||||
|
||||
int size = paramsList.size();
|
||||
for (int i = 1; i < size - 1; ++i){
|
||||
|
||||
blockHashList.add(((RLPItem) paramsList.getElement(i)).getData());
|
||||
}
|
||||
|
||||
|
@ -62,20 +61,16 @@ public class GetChainMessage extends Message {
|
|||
return blockNum;
|
||||
}
|
||||
|
||||
|
||||
public String toString(){
|
||||
|
||||
if (!parsed) parseRLP();
|
||||
|
||||
StringBuffer sb = new StringBuffer();
|
||||
for (byte[] blockHash : blockHashList){
|
||||
|
||||
sb.append("").append(Utils.toHexString(blockHash)).append(", ");
|
||||
}
|
||||
|
||||
sb.append(" blockNum=").append(blockNum);
|
||||
|
||||
return "GetChain Message [" + sb.toString() + " ]";
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package org.ethereum.net.message;
|
||||
|
||||
import org.spongycastle.util.encoders.Hex;
|
||||
import static org.ethereum.net.Command.HELLO;
|
||||
import org.ethereum.net.RLP;
|
||||
import org.ethereum.net.rlp.RLPItem;
|
||||
import org.ethereum.net.rlp.RLPList;
|
||||
|
@ -14,8 +15,6 @@ import java.nio.ByteBuffer;
|
|||
*/
|
||||
public class HelloMessage extends Message {
|
||||
|
||||
private final byte commandCode = 0x00;
|
||||
|
||||
private byte protocolVersion;
|
||||
private byte networkId;
|
||||
private String clientId;
|
||||
|
@ -23,9 +22,7 @@ public class HelloMessage extends Message {
|
|||
private short peerPort;
|
||||
private byte[] peerId;
|
||||
|
||||
|
||||
public HelloMessage(RLPList rawData) {
|
||||
|
||||
super(rawData);
|
||||
}
|
||||
|
||||
|
@ -46,32 +43,27 @@ public class HelloMessage extends Message {
|
|||
// the message does no distinguish between the 0 and null so here I check command code for null
|
||||
// todo: find out if it can be 00
|
||||
if (((RLPItem)(paramsList).getElement(0)).getData() != null){
|
||||
|
||||
throw new Error("HelloMessage: parsing for mal data");
|
||||
}
|
||||
|
||||
|
||||
this.protocolVersion = ((RLPItem) paramsList.getElement(1)).getData()[0];
|
||||
|
||||
byte[] networkIdBytes = ((RLPItem) paramsList.getElement(2)).getData();
|
||||
this.networkId = networkIdBytes == null ? 0 : networkIdBytes[0] ;
|
||||
byte[] networkIdBytes = ((RLPItem) paramsList.getElement(2)).getData();
|
||||
this.networkId = networkIdBytes == null ? 0 : networkIdBytes[0] ;
|
||||
|
||||
this.clientId = new String(((RLPItem) paramsList.getElement(3)).getData());
|
||||
this.capabilities = ((RLPItem) paramsList.getElement(4)).getData()[0];
|
||||
|
||||
ByteBuffer bb = ByteBuffer.wrap(((RLPItem) paramsList.getElement(5)).getData());
|
||||
this.peerPort = bb.getShort();
|
||||
|
||||
this.peerPort = bb.getShort();
|
||||
this.peerId = ((RLPItem) paramsList.getElement(6)).getData();
|
||||
|
||||
this.parsed = true;
|
||||
// todo: what to do when mal data ?
|
||||
}
|
||||
|
||||
|
||||
public byte[] getPayload(){
|
||||
|
||||
byte[] command = RLP.encodeByte(this.commandCode);
|
||||
byte[] command = RLP.encodeByte(HELLO.asByte());
|
||||
byte[] protocolVersion = RLP.encodeByte(this.protocolVersion);
|
||||
byte[] networkId = RLP.encodeByte(this.networkId);
|
||||
byte[] clientId = RLP.encodeString(this.clientId);
|
||||
|
@ -85,52 +77,43 @@ public class HelloMessage extends Message {
|
|||
return data;
|
||||
}
|
||||
|
||||
|
||||
public byte getCommandCode() {
|
||||
|
||||
if (!parsed) parseRLP();
|
||||
return commandCode;
|
||||
return HELLO.asByte();
|
||||
}
|
||||
|
||||
public byte getProtocolVersion() {
|
||||
|
||||
if (!parsed) parseRLP();
|
||||
return protocolVersion;
|
||||
}
|
||||
|
||||
public byte getNetworkId() {
|
||||
|
||||
if (!parsed) parseRLP();
|
||||
return networkId;
|
||||
}
|
||||
|
||||
public String getClientId() {
|
||||
|
||||
if (!parsed) parseRLP();
|
||||
return clientId;
|
||||
}
|
||||
|
||||
public byte getCapabilities() {
|
||||
|
||||
if (!parsed) parseRLP();
|
||||
return capabilities;
|
||||
}
|
||||
|
||||
public short getPeerPort() {
|
||||
|
||||
if (!parsed) parseRLP();
|
||||
return peerPort;
|
||||
}
|
||||
|
||||
public byte[] getPeerId() {
|
||||
|
||||
if (!parsed) parseRLP();
|
||||
return peerId;
|
||||
}
|
||||
|
||||
public String toString(){
|
||||
|
||||
return "Hello Message [ command=" + this.commandCode + " " +
|
||||
return "Hello Message [ command=" + HELLO.asByte() + " " +
|
||||
" protocolVersion=" + this.protocolVersion + " " +
|
||||
" networkId=" + this.networkId + " " +
|
||||
" clientId= " + this.clientId + " " +
|
||||
|
@ -138,7 +121,6 @@ public class HelloMessage extends Message {
|
|||
" peerPort= " + this.peerPort + " " +
|
||||
" peerId= " + Hex.toHexString(this.peerId) + " " +
|
||||
"]";
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -12,8 +12,7 @@ public abstract class Message {
|
|||
RLPList rawData;
|
||||
boolean parsed = false;
|
||||
|
||||
|
||||
public Message(){}
|
||||
public Message() {}
|
||||
|
||||
public Message(RLPList rawData) {
|
||||
this.rawData = rawData;
|
||||
|
@ -21,7 +20,6 @@ public abstract class Message {
|
|||
}
|
||||
|
||||
public abstract void parseRLP();
|
||||
|
||||
public abstract byte[] getPayload();
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
package org.ethereum.net.message;
|
||||
|
||||
import static org.ethereum.net.Command.NOT_IN_CHAIN;
|
||||
|
||||
import org.ethereum.net.Command;
|
||||
import org.ethereum.net.message.Message;
|
||||
import org.ethereum.net.rlp.RLPItem;
|
||||
import org.ethereum.net.rlp.RLPList;
|
||||
|
@ -12,10 +15,8 @@ import org.ethereum.util.Utils;
|
|||
*/
|
||||
public class NotInChainMessage extends Message {
|
||||
|
||||
private final byte commandCode = 0x15;
|
||||
private byte[] hash;
|
||||
|
||||
|
||||
public NotInChainMessage(RLPList rawData) {
|
||||
super(rawData);
|
||||
}
|
||||
|
@ -24,11 +25,9 @@ public class NotInChainMessage extends Message {
|
|||
public void parseRLP() {
|
||||
RLPList paramsList = (RLPList) rawData.getElement(0);
|
||||
|
||||
if ((((RLPItem)(paramsList).getElement(0)).getData()[0] & 0xFF) != commandCode){
|
||||
|
||||
if (Command.fromInt(((RLPItem)(paramsList).getElement(0)).getData()[0] & 0xFF) != NOT_IN_CHAIN){
|
||||
throw new Error("NotInChain Message: parsing for mal data");
|
||||
}
|
||||
|
||||
hash = ((RLPItem)paramsList.getElement(1)).getData();
|
||||
}
|
||||
|
||||
|
@ -42,9 +41,8 @@ public class NotInChainMessage extends Message {
|
|||
}
|
||||
|
||||
public String toString(){
|
||||
|
||||
if (!parsed) parseRLP();
|
||||
|
||||
if (!parsed)
|
||||
parseRLP();
|
||||
return "NotInChain Message [" + Utils.toHexString(hash) + "]";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,6 +4,8 @@ import java.nio.ByteBuffer;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.ethereum.net.Command.PEERS;
|
||||
import org.ethereum.net.Command;
|
||||
import org.ethereum.net.rlp.RLPItem;
|
||||
import org.ethereum.net.rlp.RLPList;
|
||||
import org.ethereum.net.vo.PeerData;
|
||||
|
@ -15,16 +17,11 @@ import org.ethereum.net.vo.PeerData;
|
|||
*/
|
||||
public class PeersMessage extends Message {
|
||||
|
||||
private final byte commandCode = 0x11;
|
||||
|
||||
RLPList rawData;
|
||||
boolean parsed = false;
|
||||
|
||||
|
||||
List<PeerData> peers = new ArrayList<PeerData>();
|
||||
|
||||
public PeersMessage(){}
|
||||
|
||||
public PeersMessage(RLPList rawData) {
|
||||
this.rawData = rawData;
|
||||
parsed = false;
|
||||
|
@ -35,38 +32,28 @@ public class PeersMessage extends Message {
|
|||
|
||||
RLPList paramsList = (RLPList) rawData.getElement(0);
|
||||
|
||||
if ((((RLPItem)(paramsList).getElement(0)).getData()[0] & 0xFF) != commandCode){
|
||||
|
||||
if (Command.fromInt(((RLPItem)(paramsList).getElement(0)).getData()[0] & 0xFF) != PEERS){
|
||||
throw new Error("PeersMessage: parsing for mal data");
|
||||
}
|
||||
|
||||
for (int i = 1; i < paramsList.size(); ++i){
|
||||
|
||||
RLPList peerParams = (RLPList)paramsList.getElement(i);
|
||||
|
||||
byte[] ip = ((RLPItem) peerParams.getElement(0)).getData();
|
||||
|
||||
byte[] shortData = ((RLPItem) peerParams.getElement(1)).getData();
|
||||
|
||||
short peerPort = 0;
|
||||
if (shortData.length == 1)
|
||||
|
||||
peerPort = shortData[0];
|
||||
else{
|
||||
|
||||
else {
|
||||
ByteBuffer bb = ByteBuffer.wrap(shortData, 0, shortData.length);
|
||||
peerPort = bb.getShort();
|
||||
}
|
||||
|
||||
byte[] peerId = ((RLPItem) peerParams.getElement(2)).getData();
|
||||
|
||||
PeerData peer = new PeerData(ip, peerPort, peerId);
|
||||
peers.add(peer);
|
||||
}
|
||||
|
||||
this.parsed = true;
|
||||
// todo: what to do when mal data ?
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -75,27 +62,19 @@ public class PeersMessage extends Message {
|
|||
}
|
||||
|
||||
public List<PeerData> getPeers() {
|
||||
|
||||
if (!parsed){
|
||||
if (!parsed)
|
||||
parseRLP();
|
||||
}
|
||||
return peers;
|
||||
}
|
||||
|
||||
public String toString(){
|
||||
|
||||
if (!parsed){
|
||||
if (!parsed)
|
||||
parseRLP();
|
||||
}
|
||||
|
||||
|
||||
StringBuffer sb = new StringBuffer();
|
||||
|
||||
for (PeerData peerData : peers){
|
||||
|
||||
for (PeerData peerData : peers) {
|
||||
sb.append("[").append(peerData).append("] \n ");
|
||||
}
|
||||
|
||||
return "Peers Message [\n " + sb.toString() + "]";
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -72,7 +72,6 @@ public class StaticMessages {
|
|||
HELLO_MESSAGE = new HelloMessage((byte)0x0B, (byte)0x00, "EthereumJ [v0.0.1] pure java [by Roman Mandeleil]",
|
||||
(byte)0b00000111, (short)30303, peerIdBytes);
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
public static final HelloMessage HELLO_MESSAGE;
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package org.ethereum.net.message;
|
||||
|
||||
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;
|
||||
|
@ -14,7 +16,6 @@ import java.util.List;
|
|||
*/
|
||||
public class TransactionsMessage extends Message {
|
||||
|
||||
private final byte commandCode = 0x12;
|
||||
private List<TransactionData> transactions = new ArrayList<TransactionData>();
|
||||
|
||||
public TransactionsMessage() {
|
||||
|
@ -26,28 +27,23 @@ public class TransactionsMessage extends Message {
|
|||
|
||||
@Override
|
||||
public void parseRLP() {
|
||||
|
||||
RLPList paramsList = (RLPList) rawData.getElement(0);
|
||||
|
||||
if ((((RLPItem)(paramsList).getElement(0)).getData()[0] & 0xFF) != commandCode){
|
||||
|
||||
if ( Command.fromInt(((RLPItem)(paramsList).getElement(0)).getData()[0] & 0xFF) != TRANSACTIONS){
|
||||
throw new Error("TransactionMessage: parsing for mal data");
|
||||
}
|
||||
|
||||
transactions = new ArrayList<TransactionData>();
|
||||
int size = paramsList.getList().size();
|
||||
for (int i = 1; i < size; ++i){
|
||||
|
||||
RLPList rlpTxData = (RLPList) paramsList.getElement(i);
|
||||
TransactionData tx = new TransactionData(rlpTxData);
|
||||
transactions.add(tx);
|
||||
}
|
||||
|
||||
parsed = true;
|
||||
}
|
||||
|
||||
public List<TransactionData> getTransactions() {
|
||||
|
||||
if (!parsed) parseRLP();
|
||||
return transactions;
|
||||
}
|
||||
|
@ -58,16 +54,11 @@ public class TransactionsMessage extends Message {
|
|||
}
|
||||
|
||||
public String toString(){
|
||||
|
||||
if(!parsed)parseRLP();
|
||||
|
||||
if(!parsed) parseRLP();
|
||||
StringBuffer sb = new StringBuffer();
|
||||
|
||||
for (TransactionData transactionData : transactions){
|
||||
|
||||
sb.append(" ").append(transactionData).append("\n");
|
||||
}
|
||||
|
||||
return "Transactions Message [\n" + sb.toString() + " ]";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,18 +1,24 @@
|
|||
package org.ethereum.net;
|
||||
|
||||
import org.spongycastle.util.encoders.Hex;
|
||||
import org.ethereum.net.message.*;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.List;
|
||||
|
||||
import org.ethereum.net.message.BlocksMessage;
|
||||
import org.ethereum.net.message.DisconnectMessage;
|
||||
import org.ethereum.net.message.GetChainMessage;
|
||||
import org.ethereum.net.message.HelloMessage;
|
||||
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.PeerData;
|
||||
import org.ethereum.net.vo.TransactionData;
|
||||
import org.ethereum.util.Utils;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import org.spongycastle.util.encoders.Hex;
|
||||
|
||||
public class MessagesTest {
|
||||
|
||||
|
@ -157,7 +163,6 @@ public class MessagesTest {
|
|||
|
||||
}
|
||||
|
||||
|
||||
@Test /* Peers msg parsing performance*/
|
||||
public void test_7() throws UnknownHostException {
|
||||
|
||||
|
@ -179,7 +184,7 @@ public class MessagesTest {
|
|||
}
|
||||
|
||||
/* TRANSACTIONS */
|
||||
|
||||
|
||||
@Test /* Transactions message 1 */
|
||||
public void test_8(){
|
||||
|
||||
|
@ -229,7 +234,6 @@ public class MessagesTest {
|
|||
|
||||
assertEquals("0FF91628D04B215EBCCFD5F4FC34CC1B45DF32F6B4609FBB0DE42E8522264467",
|
||||
Utils.toHexString( tx.getSignatureS() ).toUpperCase());
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -284,8 +288,7 @@ public class MessagesTest {
|
|||
Utils.toHexString( tx.getSignatureS() ).toUpperCase());
|
||||
|
||||
|
||||
tx =
|
||||
transactionsMessage.getTransactions().get(2);
|
||||
tx = transactionsMessage.getTransactions().get(2);
|
||||
|
||||
assertEquals("B0251A1BB20B44459DB5B5444AB53EDD9E12C46D0BA07FA401A797BEB967D53C",
|
||||
Utils.toHexString( tx.getHash() ).toUpperCase());
|
||||
|
|
|
@ -4,7 +4,6 @@ import org.spongycastle.util.encoders.Hex;
|
|||
import org.ethereum.crypto.HashUtil;
|
||||
import org.ethereum.net.rlp.RLPList;
|
||||
import org.ethereum.util.Utils;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.math.BigInteger;
|
||||
|
@ -145,14 +144,13 @@ public class RLPTest {
|
|||
byte[] expected5 = {(byte)0x82, (byte)0x4E, (byte)0xEA};
|
||||
data = RLP.encodeShort((short)20202);
|
||||
assertArrayEquals(expected5, data);
|
||||
|
||||
}
|
||||
|
||||
@Test /** encode string */
|
||||
public void test6(){
|
||||
|
||||
byte[] data = RLP.encodeString("");
|
||||
Assert.assertArrayEquals(new byte[]{(byte)0x80}, data);
|
||||
assertArrayEquals(new byte[]{(byte)0x80}, data);
|
||||
|
||||
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,
|
||||
|
@ -161,7 +159,7 @@ public class RLPTest {
|
|||
String test = "EthereumJ Client";
|
||||
data = RLP.encodeString(test);
|
||||
|
||||
Assert.assertArrayEquals(expected, data);
|
||||
assertArrayEquals(expected, data);
|
||||
|
||||
String test2 = "Ethereum(++)/ZeroGox/v0.5.0/ncurses/Linux/g++";
|
||||
|
||||
|
@ -174,7 +172,7 @@ public class RLPTest {
|
|||
(byte)0x2F, (byte)0x67, (byte)0x2B, (byte)0x2B};
|
||||
|
||||
data = RLP.encodeString(test2);
|
||||
Assert.assertArrayEquals(expected2, data);
|
||||
assertArrayEquals(expected2, data);
|
||||
|
||||
String test3 = "Ethereum(++)/ZeroGox/v0.5.0/ncurses/Linux/g++Ethereum(++)/ZeroGox/v0.5.0/ncurses/Linux/g++";
|
||||
|
||||
|
@ -196,10 +194,9 @@ public class RLPTest {
|
|||
(byte)0x2F, (byte)0x67, (byte)0x2B, (byte)0x2B};
|
||||
|
||||
data = RLP.encodeString(test3);
|
||||
Assert.assertArrayEquals(expected3, data);
|
||||
assertArrayEquals(expected3, data);
|
||||
}
|
||||
|
||||
|
||||
@Test /** encode byte array */
|
||||
public void test7(){
|
||||
|
||||
|
@ -212,7 +209,7 @@ public class RLPTest {
|
|||
|
||||
String expected = "B8 40 " + byteArr;
|
||||
|
||||
Assert.assertArrayEquals(Utils.hexStringToByteArr(expected),
|
||||
assertArrayEquals(Utils.hexStringToByteArr(expected),
|
||||
RLP.encodeElement(byteArray));
|
||||
}
|
||||
|
||||
|
@ -242,12 +239,10 @@ public class RLPTest {
|
|||
byte[] header = RLP.encodeList(
|
||||
prevHash, uncleList, coinbase);
|
||||
|
||||
Assert.assertEquals("f856a000000000000000000000000000000000000000000000000000000000000000001dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347940000000000000000000000000000000000000000",
|
||||
assertEquals("f856a000000000000000000000000000000000000000000000000000000000000000001dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347940000000000000000000000000000000000000000",
|
||||
Hex.toHexString(header));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void test10(){
|
||||
// 2240089100000070
|
||||
|
@ -257,7 +252,6 @@ public class RLPTest {
|
|||
Queue<Integer> index = new LinkedList<Integer>();
|
||||
RLP.fullTraverse(payload, 0, 0, payload.length, 1, index);
|
||||
|
||||
|
||||
// TODO: assert lenght overflow while parsing list in RLP
|
||||
}
|
||||
|
||||
|
@ -274,7 +268,6 @@ public class RLPTest {
|
|||
// TODO: add some asserts in place of just printing the rlpList
|
||||
}
|
||||
|
||||
|
||||
@Test /* very long peers msg */
|
||||
public void test12(){
|
||||
|
||||
|
@ -313,7 +306,4 @@ public class RLPTest {
|
|||
RLPList.recursivePrint(rlpList);
|
||||
// TODO: add some asserts in place of just printing the rlpList
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -36,7 +36,6 @@ public class TestCompile {
|
|||
CommonTokenStream tokens = new CommonTokenStream(lex);
|
||||
SerpentParser parser = new SerpentParser(tokens);
|
||||
|
||||
|
||||
String userDir = System.getProperty("user.dir");
|
||||
String templateFileName = userDir + "\\src\\main\\java\\org\\ethereum\\serpent\\Serpent2Asm.stg";
|
||||
|
||||
|
@ -60,7 +59,6 @@ public class TestCompile {
|
|||
CommonTokenStream tokens = new CommonTokenStream(lex);
|
||||
SerpentParser parser = new SerpentParser(tokens);
|
||||
|
||||
|
||||
String userDir = System.getProperty("user.dir");
|
||||
String templateFileName = userDir + "\\src\\main\\java\\org\\ethereum\\serpent\\Serpent2Asm.stg";
|
||||
|
||||
|
@ -84,7 +82,6 @@ public class TestCompile {
|
|||
CommonTokenStream tokens = new CommonTokenStream(lex);
|
||||
SerpentParser parser = new SerpentParser(tokens);
|
||||
|
||||
|
||||
String userDir = System.getProperty("user.dir");
|
||||
String templateFileName = userDir + "\\src\\main\\java\\org\\ethereum\\serpent\\Serpent2Asm.stg";
|
||||
|
||||
|
@ -108,7 +105,6 @@ public class TestCompile {
|
|||
CommonTokenStream tokens = new CommonTokenStream(lex);
|
||||
SerpentParser parser = new SerpentParser(tokens);
|
||||
|
||||
|
||||
String userDir = System.getProperty("user.dir");
|
||||
String templateFileName = userDir + "\\src\\main\\java\\org\\ethereum\\serpent\\Serpent2Asm.stg";
|
||||
|
||||
|
@ -166,7 +162,6 @@ public class TestCompile {
|
|||
SerpentParser.bin_expr_return retVal = parser.bin_expr();
|
||||
|
||||
assertEquals("A B DIV", retVal.getTemplate().toString());
|
||||
|
||||
}
|
||||
|
||||
@Test /* Test EXP 1*/
|
||||
|
@ -180,7 +175,6 @@ public class TestCompile {
|
|||
CommonTokenStream tokens = new CommonTokenStream(lex);
|
||||
SerpentParser parser = new SerpentParser(tokens);
|
||||
|
||||
|
||||
String userDir = System.getProperty("user.dir");
|
||||
String templateFileName = userDir + "\\src\\main\\java\\org\\ethereum\\serpent\\Serpent2Asm.stg";
|
||||
|
||||
|
@ -191,7 +185,6 @@ public class TestCompile {
|
|||
SerpentParser.bin_expr_return retVal = parser.bin_expr();
|
||||
|
||||
assertEquals("A B EXP", retVal.getTemplate().toString());
|
||||
|
||||
}
|
||||
|
||||
@Test /* Test MOD 1*/
|
||||
|
@ -205,7 +198,6 @@ public class TestCompile {
|
|||
CommonTokenStream tokens = new CommonTokenStream(lex);
|
||||
SerpentParser parser = new SerpentParser(tokens);
|
||||
|
||||
|
||||
String userDir = System.getProperty("user.dir");
|
||||
String templateFileName = userDir + "\\src\\main\\java\\org\\ethereum\\serpent\\Serpent2Asm.stg";
|
||||
|
||||
|
@ -215,8 +207,6 @@ public class TestCompile {
|
|||
|
||||
SerpentParser.bin_expr_return retVal = parser.bin_expr();
|
||||
|
||||
|
||||
|
||||
assertEquals("A B MOD", retVal.getTemplate().toString());
|
||||
}
|
||||
|
||||
|
@ -231,7 +221,6 @@ public class TestCompile {
|
|||
CommonTokenStream tokens = new CommonTokenStream(lex);
|
||||
SerpentParser parser = new SerpentParser(tokens);
|
||||
|
||||
|
||||
String userDir = System.getProperty("user.dir");
|
||||
String templateFileName = userDir + "\\src\\main\\java\\org\\ethereum\\serpent\\Serpent2Asm.stg";
|
||||
|
||||
|
@ -242,7 +231,6 @@ public class TestCompile {
|
|||
SerpentParser.bin_expr_return retVal = parser.bin_expr();
|
||||
|
||||
assertEquals("A B SDIV", retVal.getTemplate().toString());
|
||||
|
||||
}
|
||||
|
||||
@Test /* Test SMOD 1*/
|
||||
|
@ -256,7 +244,6 @@ public class TestCompile {
|
|||
CommonTokenStream tokens = new CommonTokenStream(lex);
|
||||
SerpentParser parser = new SerpentParser(tokens);
|
||||
|
||||
|
||||
String userDir = System.getProperty("user.dir");
|
||||
String templateFileName = userDir + "\\src\\main\\java\\org\\ethereum\\serpent\\Serpent2Asm.stg";
|
||||
|
||||
|
@ -267,10 +254,8 @@ public class TestCompile {
|
|||
SerpentParser.bin_expr_return retVal = parser.bin_expr();
|
||||
|
||||
assertEquals("A B SMOD", retVal.getTemplate().toString());
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test /* Test multi binary operators 1*/
|
||||
public void test10() throws FileNotFoundException, RecognitionException {
|
||||
|
||||
|
@ -282,7 +267,6 @@ public class TestCompile {
|
|||
CommonTokenStream tokens = new CommonTokenStream(lex);
|
||||
SerpentParser parser = new SerpentParser(tokens);
|
||||
|
||||
|
||||
String userDir = System.getProperty("user.dir");
|
||||
String templateFileName = userDir + "\\src\\main\\java\\org\\ethereum\\serpent\\Serpent2Asm.stg";
|
||||
|
||||
|
@ -307,7 +291,6 @@ public class TestCompile {
|
|||
CommonTokenStream tokens = new CommonTokenStream(lex);
|
||||
SerpentParser parser = new SerpentParser(tokens);
|
||||
|
||||
|
||||
String userDir = System.getProperty("user.dir");
|
||||
String templateFileName = userDir + "\\src\\main\\java\\org\\ethereum\\serpent\\Serpent2Asm.stg";
|
||||
|
||||
|
@ -319,10 +302,8 @@ public class TestCompile {
|
|||
|
||||
assertEquals("A B DIV C SUB D ADD ET MUL ET2 MOD RO EXP RO2 ADD COOL SDIV HOT SMOD",
|
||||
retVal.getTemplate().toString());
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
['==', 2, 1, ['<1>', '<0>', 'EQ']], V
|
||||
['<', 2, 1, ['<1>', '<0>', 'LT']], V
|
||||
|
@ -343,7 +324,6 @@ public class TestCompile {
|
|||
CommonTokenStream tokens = new CommonTokenStream(lex);
|
||||
SerpentParser parser = new SerpentParser(tokens);
|
||||
|
||||
|
||||
String userDir = System.getProperty("user.dir");
|
||||
String templateFileName = userDir + "\\src\\main\\java\\org\\ethereum\\serpent\\Serpent2Asm.stg";
|
||||
|
||||
|
@ -355,7 +335,6 @@ public class TestCompile {
|
|||
|
||||
assertEquals("A B ADD B A ADD EQ",
|
||||
retVal.getTemplate().toString());
|
||||
|
||||
}
|
||||
|
||||
@Test /* Test '<' 1*/
|
||||
|
@ -369,7 +348,6 @@ public class TestCompile {
|
|||
CommonTokenStream tokens = new CommonTokenStream(lex);
|
||||
SerpentParser parser = new SerpentParser(tokens);
|
||||
|
||||
|
||||
String userDir = System.getProperty("user.dir");
|
||||
String templateFileName = userDir + "\\src\\main\\java\\org\\ethereum\\serpent\\Serpent2Asm.stg";
|
||||
|
||||
|
@ -381,7 +359,6 @@ public class TestCompile {
|
|||
|
||||
assertEquals("A C ADD C A ADD LT",
|
||||
retVal.getTemplate().toString());
|
||||
|
||||
}
|
||||
|
||||
@Test /* Test '<=' 1*/
|
||||
|
@ -395,7 +372,6 @@ public class TestCompile {
|
|||
CommonTokenStream tokens = new CommonTokenStream(lex);
|
||||
SerpentParser parser = new SerpentParser(tokens);
|
||||
|
||||
|
||||
String userDir = System.getProperty("user.dir");
|
||||
String templateFileName = userDir + "\\src\\main\\java\\org\\ethereum\\serpent\\Serpent2Asm.stg";
|
||||
|
||||
|
@ -407,10 +383,8 @@ public class TestCompile {
|
|||
|
||||
assertEquals("A C ADD C A ADD GT NOT",
|
||||
retVal.getTemplate().toString());
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test /* Test '>' 1*/
|
||||
public void test15() throws FileNotFoundException, RecognitionException {
|
||||
|
||||
|
@ -422,7 +396,6 @@ public class TestCompile {
|
|||
CommonTokenStream tokens = new CommonTokenStream(lex);
|
||||
SerpentParser parser = new SerpentParser(tokens);
|
||||
|
||||
|
||||
String userDir = System.getProperty("user.dir");
|
||||
String templateFileName = userDir + "\\src\\main\\java\\org\\ethereum\\serpent\\Serpent2Asm.stg";
|
||||
|
||||
|
@ -434,7 +407,6 @@ public class TestCompile {
|
|||
|
||||
assertEquals("A C ADD C A ADD GT",
|
||||
retVal.getTemplate().toString());
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -449,7 +421,6 @@ public class TestCompile {
|
|||
CommonTokenStream tokens = new CommonTokenStream(lex);
|
||||
SerpentParser parser = new SerpentParser(tokens);
|
||||
|
||||
|
||||
String userDir = System.getProperty("user.dir");
|
||||
String templateFileName = userDir + "\\src\\main\\java\\org\\ethereum\\serpent\\Serpent2Asm.stg";
|
||||
|
||||
|
@ -461,7 +432,6 @@ public class TestCompile {
|
|||
|
||||
assertEquals("A C ADD C A ADD LT NOT",
|
||||
retVal.getTemplate().toString());
|
||||
|
||||
}
|
||||
|
||||
@Test /* Test '!' 1 */
|
||||
|
@ -475,7 +445,6 @@ public class TestCompile {
|
|||
CommonTokenStream tokens = new CommonTokenStream(lex);
|
||||
SerpentParser parser = new SerpentParser(tokens);
|
||||
|
||||
|
||||
String userDir = System.getProperty("user.dir");
|
||||
String templateFileName = userDir + "\\src\\main\\java\\org\\ethereum\\serpent\\Serpent2Asm.stg";
|
||||
|
||||
|
@ -487,7 +456,6 @@ public class TestCompile {
|
|||
|
||||
assertEquals("A NOT",
|
||||
retVal.getTemplate().toString());
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -502,7 +470,6 @@ public class TestCompile {
|
|||
CommonTokenStream tokens = new CommonTokenStream(lex);
|
||||
SerpentParser parser = new SerpentParser(tokens);
|
||||
|
||||
|
||||
String userDir = System.getProperty("user.dir");
|
||||
String templateFileName = userDir + "\\src\\main\\java\\org\\ethereum\\serpent\\Serpent2Asm.stg";
|
||||
|
||||
|
@ -514,7 +481,6 @@ public class TestCompile {
|
|||
|
||||
assertEquals("A NOT NOT",
|
||||
retVal.getTemplate().toString());
|
||||
|
||||
}
|
||||
|
||||
@Test /* Test '!' 3 */
|
||||
|
@ -528,7 +494,6 @@ public class TestCompile {
|
|||
CommonTokenStream tokens = new CommonTokenStream(lex);
|
||||
SerpentParser parser = new SerpentParser(tokens);
|
||||
|
||||
|
||||
String userDir = System.getProperty("user.dir");
|
||||
String templateFileName = userDir + "\\src\\main\\java\\org\\ethereum\\serpent\\Serpent2Asm.stg";
|
||||
|
||||
|
@ -540,7 +505,6 @@ public class TestCompile {
|
|||
|
||||
assertEquals("A NOT NOT",
|
||||
retVal.getTemplate().toString());
|
||||
|
||||
}
|
||||
|
||||
@Test /* Test '!' 4 */
|
||||
|
@ -554,7 +518,6 @@ public class TestCompile {
|
|||
CommonTokenStream tokens = new CommonTokenStream(lex);
|
||||
SerpentParser parser = new SerpentParser(tokens);
|
||||
|
||||
|
||||
String userDir = System.getProperty("user.dir");
|
||||
String templateFileName = userDir + "\\src\\main\\java\\org\\ethereum\\serpent\\Serpent2Asm.stg";
|
||||
|
||||
|
@ -566,7 +529,6 @@ public class TestCompile {
|
|||
|
||||
assertEquals("A NOT",
|
||||
retVal.getTemplate().toString());
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -581,7 +543,6 @@ public class TestCompile {
|
|||
CommonTokenStream tokens = new CommonTokenStream(lex);
|
||||
SerpentParser parser = new SerpentParser(tokens);
|
||||
|
||||
|
||||
String userDir = System.getProperty("user.dir");
|
||||
String templateFileName = userDir + "\\src\\main\\java\\org\\ethereum\\serpent\\Serpent2Asm.stg";
|
||||
|
||||
|
@ -593,7 +554,6 @@ public class TestCompile {
|
|||
|
||||
assertEquals("10 0 MSTORE 20 32 MSTORE 30 64 MSTORE",
|
||||
retVal.getTemplate().toString().trim());
|
||||
|
||||
}
|
||||
|
||||
@Test /* Test set var '=' 2 */
|
||||
|
@ -607,7 +567,6 @@ public class TestCompile {
|
|||
CommonTokenStream tokens = new CommonTokenStream(lex);
|
||||
SerpentParser parser = new SerpentParser(tokens);
|
||||
|
||||
|
||||
String userDir = System.getProperty("user.dir");
|
||||
String templateFileName = userDir + "\\src\\main\\java\\org\\ethereum\\serpent\\Serpent2Asm.stg";
|
||||
|
||||
|
@ -633,7 +592,6 @@ public class TestCompile {
|
|||
CommonTokenStream tokens = new CommonTokenStream(lex);
|
||||
SerpentParser parser = new SerpentParser(tokens);
|
||||
|
||||
|
||||
String userDir = System.getProperty("user.dir");
|
||||
String templateFileName = userDir + "\\src\\main\\java\\org\\ethereum\\serpent\\Serpent2Asm.stg";
|
||||
|
||||
|
@ -645,7 +603,6 @@ public class TestCompile {
|
|||
|
||||
assertEquals("",
|
||||
retVal.getTemplate().toString().trim());
|
||||
|
||||
}
|
||||
|
||||
@Test /* Test contract.storage[x] 1 */
|
||||
|
@ -659,7 +616,6 @@ public class TestCompile {
|
|||
CommonTokenStream tokens = new CommonTokenStream(lex);
|
||||
SerpentParser parser = new SerpentParser(tokens);
|
||||
|
||||
|
||||
String userDir = System.getProperty("user.dir");
|
||||
String templateFileName = userDir + "\\src\\main\\java\\org\\ethereum\\serpent\\Serpent2Asm.stg";
|
||||
|
||||
|
@ -684,7 +640,6 @@ public class TestCompile {
|
|||
CommonTokenStream tokens = new CommonTokenStream(lex);
|
||||
SerpentParser parser = new SerpentParser(tokens);
|
||||
|
||||
|
||||
String userDir = System.getProperty("user.dir");
|
||||
String templateFileName = userDir + "\\src\\main\\java\\org\\ethereum\\serpent\\Serpent2Asm.stg";
|
||||
|
||||
|
@ -709,7 +664,6 @@ public class TestCompile {
|
|||
CommonTokenStream tokens = new CommonTokenStream(lex);
|
||||
SerpentParser parser = new SerpentParser(tokens);
|
||||
|
||||
|
||||
String userDir = System.getProperty("user.dir");
|
||||
String templateFileName = userDir + "\\src\\main\\java\\org\\ethereum\\serpent\\Serpent2Asm.stg";
|
||||
|
||||
|
@ -734,7 +688,6 @@ public class TestCompile {
|
|||
CommonTokenStream tokens = new CommonTokenStream(lex);
|
||||
SerpentParser parser = new SerpentParser(tokens);
|
||||
|
||||
|
||||
String userDir = System.getProperty("user.dir");
|
||||
String templateFileName = userDir + "\\src\\main\\java\\org\\ethereum\\serpent\\Serpent2Asm.stg";
|
||||
|
||||
|
@ -760,7 +713,6 @@ public class TestCompile {
|
|||
CommonTokenStream tokens = new CommonTokenStream(lex);
|
||||
SerpentParser parser = new SerpentParser(tokens);
|
||||
|
||||
|
||||
String userDir = System.getProperty("user.dir");
|
||||
String templateFileName = userDir + "\\src\\main\\java\\org\\ethereum\\serpent\\Serpent2Asm.stg";
|
||||
|
||||
|
@ -785,7 +737,6 @@ public class TestCompile {
|
|||
CommonTokenStream tokens = new CommonTokenStream(lex);
|
||||
SerpentParser parser = new SerpentParser(tokens);
|
||||
|
||||
|
||||
String userDir = System.getProperty("user.dir");
|
||||
String templateFileName = userDir + "\\src\\main\\java\\org\\ethereum\\serpent\\Serpent2Asm.stg";
|
||||
|
||||
|
@ -810,7 +761,6 @@ public class TestCompile {
|
|||
CommonTokenStream tokens = new CommonTokenStream(lex);
|
||||
SerpentParser parser = new SerpentParser(tokens);
|
||||
|
||||
|
||||
String userDir = System.getProperty("user.dir");
|
||||
String templateFileName = userDir + "\\src\\main\\java\\org\\ethereum\\serpent\\Serpent2Asm.stg";
|
||||
|
||||
|
@ -835,7 +785,6 @@ public class TestCompile {
|
|||
CommonTokenStream tokens = new CommonTokenStream(lex);
|
||||
SerpentParser parser = new SerpentParser(tokens);
|
||||
|
||||
|
||||
String userDir = System.getProperty("user.dir");
|
||||
String templateFileName = userDir + "\\src\\main\\java\\org\\ethereum\\serpent\\Serpent2Asm.stg";
|
||||
|
||||
|
@ -862,7 +811,6 @@ public class TestCompile {
|
|||
CommonTokenStream tokens = new CommonTokenStream(lex);
|
||||
SerpentParser parser = new SerpentParser(tokens);
|
||||
|
||||
|
||||
String userDir = System.getProperty("user.dir");
|
||||
String templateFileName = userDir + "\\src\\main\\java\\org\\ethereum\\serpent\\Serpent2Asm.stg";
|
||||
|
||||
|
@ -887,7 +835,6 @@ public class TestCompile {
|
|||
CommonTokenStream tokens = new CommonTokenStream(lex);
|
||||
SerpentParser parser = new SerpentParser(tokens);
|
||||
|
||||
|
||||
String userDir = System.getProperty("user.dir");
|
||||
String templateFileName = userDir + "\\src\\main\\java\\org\\ethereum\\serpent\\Serpent2Asm.stg";
|
||||
|
||||
|
@ -912,7 +859,6 @@ public class TestCompile {
|
|||
CommonTokenStream tokens = new CommonTokenStream(lex);
|
||||
SerpentParser parser = new SerpentParser(tokens);
|
||||
|
||||
|
||||
String userDir = System.getProperty("user.dir");
|
||||
String templateFileName = userDir + "\\src\\main\\java\\org\\ethereum\\serpent\\Serpent2Asm.stg";
|
||||
|
||||
|
@ -937,7 +883,6 @@ public class TestCompile {
|
|||
CommonTokenStream tokens = new CommonTokenStream(lex);
|
||||
SerpentParser parser = new SerpentParser(tokens);
|
||||
|
||||
|
||||
String userDir = System.getProperty("user.dir");
|
||||
String templateFileName = userDir + "\\src\\main\\java\\org\\ethereum\\serpent\\Serpent2Asm.stg";
|
||||
|
||||
|
@ -962,12 +907,10 @@ public class TestCompile {
|
|||
"else:\n" +
|
||||
" return(0)\n");
|
||||
|
||||
|
||||
SerpentLexer lex = new SerpentLexer(stream);
|
||||
CommonTokenStream tokens = new CommonTokenStream(lex);
|
||||
SerpentParser parser = new SerpentParser(tokens);
|
||||
|
||||
|
||||
String userDir = System.getProperty("user.dir");
|
||||
String templateFileName = userDir + "\\src\\main\\java\\org\\ethereum\\serpent\\Serpent2Asm.stg";
|
||||
|
||||
|
@ -981,11 +924,9 @@ public class TestCompile {
|
|||
retVal.getTemplate().toString().trim());
|
||||
}
|
||||
|
||||
|
||||
@Test /* Test complex contract with if_else_stmt inside else body */
|
||||
public void test36() throws FileNotFoundException, RecognitionException {
|
||||
|
||||
|
||||
CharStream stream =
|
||||
new ANTLRStringStream("" +
|
||||
" contract.storage[0xcd2a3d9f938e13cd947ec05abc7fe734df8dd826] = 1000000\n" +
|
||||
|
@ -1009,7 +950,6 @@ public class TestCompile {
|
|||
CommonTokenStream tokens = new CommonTokenStream(lex);
|
||||
SerpentParser parser = new SerpentParser(tokens);
|
||||
|
||||
|
||||
String userDir = System.getProperty("user.dir");
|
||||
String templateFileName = userDir + "\\src\\main\\java\\org\\ethereum\\serpent\\Serpent2Asm.stg";
|
||||
|
||||
|
@ -1036,7 +976,6 @@ public class TestCompile {
|
|||
CommonTokenStream tokens = new CommonTokenStream(lex);
|
||||
SerpentParser parser = new SerpentParser(tokens);
|
||||
|
||||
|
||||
String userDir = System.getProperty("user.dir");
|
||||
String templateFileName = userDir + "\\src\\main\\java\\org\\ethereum\\serpent\\Serpent2Asm.stg";
|
||||
|
||||
|
|
Loading…
Reference in New Issue