Document and clean RLP and some others

This commit is contained in:
nicksavers 2014-05-05 19:09:32 +02:00
parent 3a660658a2
commit d3cafc2731
9 changed files with 473 additions and 537 deletions

View File

@ -30,7 +30,7 @@ public enum Command {
private Command(int cmd) {
this.cmd = cmd;
}
public static Command fromInt(int i) {
Command type = intToTypeMap.get(Integer.valueOf(i));
if (type == null)

View File

@ -9,7 +9,7 @@ public class MessageDeserializer {
/**
* Get exactly one message payload
*/
public static void deserialize(byte [] msgData, int level, int startPos, int endPos){
private static void deserialize(byte [] msgData, int level, int startPos, int endPos){
if (msgData == null || msgData.length == 0) return ;
int pos = startPos;

View File

@ -31,7 +31,6 @@ public class ClientPeer {
EventLoopGroup workerGroup = new NioEventLoopGroup();
try {
Bootstrap b = new Bootstrap();
b.group(workerGroup);
b.channel(NioSocketChannel.class);
@ -58,18 +57,14 @@ public class ClientPeer {
// Start the client.
ChannelFuture f = b.connect(host, port).sync(); // (5)
// Wait until the connection is closed.
f.channel().closeFuture().sync();
} catch (InterruptedException ie){
System.out.println("-- ClientPeer: catch (InterruptedException ie) --");
ie.printStackTrace();
} finally {
workerGroup.shutdownGracefully();
}
}
}

View File

@ -122,7 +122,6 @@ public class EthereumProtocolHandler extends ChannelInboundHandlerAdapter {
timer.schedule(new TimerTask() {
public void run() {
System.out.println("[Send: TX]");
sendTx(ctx);
}

View File

@ -61,7 +61,6 @@ public class BlocksMessage extends Message {
sb.append("[").append(transactionData).append("]\n");
}
}
return "Blocks Message [\n" +
sb.toString()
+ " ]";

File diff suppressed because it is too large Load Diff

View File

@ -20,12 +20,10 @@ public class RLPList implements RLPElement{
}
public void addItem(RLPElement element){
list.add(element);
}
public RLPElement getElement(int index){
return list.get(index);
}
@ -52,17 +50,13 @@ public class RLPList implements RLPElement{
if (element instanceof RLPList) {
RLPList rlpList = (RLPList) element;
System.out.print("[");
System.out.print("[");
for (RLPElement singleElement : rlpList.getList()) {
recursivePrint(singleElement);
}
System.out.print("]");
} else {
String hex = Utils.toHexString(((RLPItem) element).getData());
System.out.print(hex + ", ");
}
}

View File

@ -79,13 +79,13 @@ public class PeerData {
@Override
public String toString() {
return "Peer: [ ip=" + getInetAddress()+ ", port=" + getPort() + ", peerId=" + Hex.toHexString( getPeerId() ) + "]";
return "Peer: [ip=" + getInetAddress() + ", port=" + getPort() + ", peerId=" + Hex.toHexString(getPeerId()) + "]";
}
@Override
public boolean equals(Object obj) {
PeerData peerData2 = (PeerData)obj;
return this.getInetAddress().equals(peerData2.getInetAddress());
PeerData peerData = (PeerData) obj;
return this.getInetAddress().equals(peerData.getInetAddress());
}
@Override

View File

@ -0,0 +1,159 @@
package org.ethereum.vm;
import java.util.HashMap;
import java.util.Map;
/**
* Instruction set for the Ethereum Virtual Machine
*/
public enum OpCode {
/**
* Stop and Arithmetic Operations
*/
STOP(0x00),
ADD(0x01),
MUL(0x02),
SUB(0x03),
DIV(0x04),
SDIV(0x05),
MOD(0x06),
SMOD(0x07),
EXP(0x08),
NEG(0x09),
LT(0x0a),
GT(0x0b),
EQ(0x0c),
NOT(0x0d),
/**
* Bitwise Logic Operations
*/
AND(0x10),
OR(0x11),
XOR(0x12),
BYTE(0x13),
/**
* SHA3
*/
SHA3(0x20),
/**
* Environmental Information
*/
ADDRESS(0x30),
BALANCE(0x31),
ORIGIN(0x32),
CALLER(0x33),
CALLVALUE(0x34),
CALLDATALOAD(0x35),
CALLDATASIZE(0x36),
CALLDATACOPY(0x37),
CODESIZE(0x38),
CODECOPY(0x39),
GASPRICE(0x3a),
/**
* Block Information
*/
PREVHASH(0x40),
COINBASE(0x41),
TIMESTAMP(0x42),
NUMBER(0x43),
DIFFICULTY(0x44),
GASLIMIT(0x45),
/**
* Memory, Storage and Flow Operations
*/
POP(0x50),
DUP(0x51),
SWAP(0x52),
MLOAD(0x53),
MSTORE(0x54),
MSTORE8(0x55),
SLOAD(0x56),
SSTORE(0x57),
JUMP(0x58),
JUMPI(0x59),
PC(0x5a),
MSIZE(0x5b),
GAS(0x5c),
/**
* Push Operations
*/
PUSH1(0x60),
PUSH2(0x61),
PUSH3(0x62),
PUSH4(0x63),
PUSH5(0x64),
PUSH6(0x65),
PUSH7(0x66),
PUSH8(0x67),
PUSH9(0x68),
PUSH10(0x69),
PUSH11(0x6a),
PUSH12(0x6b),
PUSH13(0x6c),
PUSH14(0x6d),
PUSH15(0x6e),
PUSH16(0x6f),
PUSH17(0x70),
PUSH18(0x71),
PUSH19(0x72),
PUSH20(0x73),
PUSH21(0x74),
PUSH22(0x75),
PUSH23(0x76),
PUSH24(0x77),
PUSH25(0x78),
PUSH26(0x79),
PUSH27(0x7a),
PUSH28(0x7b),
PUSH29(0x7c),
PUSH30(0x7d),
PUSH31(0x7e),
PUSH32(0x7f),
/**
* System operations
*/
CREATE(0xf0),
CALL(0xf1),
RETURN(0xf2),
SUICIDE(0xff);
private byte opcode;
private static final Map<Byte, OpCode> intToTypeMap = new HashMap<Byte, OpCode>();
static {
for (OpCode type : OpCode.values()) {
intToTypeMap.put(type.opcode, type);
}
}
private OpCode(int op) {
this.opcode = (byte) op;
}
public static OpCode fromInt(int i) {
OpCode type = intToTypeMap.get(i);
if (type == null)
return OpCode.STOP;
return type;
}
public int asInt() {
return opcode;
}
}