diff --git a/ethereumj-core/src/main/java/org/ethereum/net/vo/Block.java b/ethereumj-core/src/main/java/org/ethereum/core/Block.java similarity index 98% rename from ethereumj-core/src/main/java/org/ethereum/net/vo/Block.java rename to ethereumj-core/src/main/java/org/ethereum/core/Block.java index 4f33269c..00b4a80b 100644 --- a/ethereumj-core/src/main/java/org/ethereum/net/vo/Block.java +++ b/ethereumj-core/src/main/java/org/ethereum/core/Block.java @@ -1,9 +1,9 @@ -package org.ethereum.net.vo; +package org.ethereum.core; import org.ethereum.crypto.HashUtil; -import org.ethereum.net.rlp.RLPElement; -import org.ethereum.net.rlp.RLPItem; -import org.ethereum.net.rlp.RLPList; +import org.ethereum.util.RLPElement; +import org.ethereum.util.RLPItem; +import org.ethereum.util.RLPList; import org.ethereum.util.Utils; import java.math.BigInteger; diff --git a/ethereumj-core/src/main/java/org/ethereum/net/vo/Transaction.java b/ethereumj-core/src/main/java/org/ethereum/core/Transaction.java similarity index 97% rename from ethereumj-core/src/main/java/org/ethereum/net/vo/Transaction.java rename to ethereumj-core/src/main/java/org/ethereum/core/Transaction.java index 7b3babfc..ccb1c897 100644 --- a/ethereumj-core/src/main/java/org/ethereum/net/vo/Transaction.java +++ b/ethereumj-core/src/main/java/org/ethereum/core/Transaction.java @@ -1,10 +1,10 @@ -package org.ethereum.net.vo; +package org.ethereum.core; import org.ethereum.crypto.ECKey.ECDSASignature; import org.ethereum.crypto.ECKey; import org.ethereum.crypto.HashUtil; -import org.ethereum.net.rlp.RLPItem; -import org.ethereum.net.rlp.RLPList; +import org.ethereum.util.RLPItem; +import org.ethereum.util.RLPList; import org.ethereum.util.Utils; /** @@ -89,7 +89,7 @@ public class Transaction { byte[] r = ((RLPItem) rawData.getElement(8)).getData(); byte[] s = ((RLPItem) rawData.getElement(9)).getData(); this.signature = ECDSASignature.fromComponents(r, s, v); - } else throw new Error("Wrong tx data element list size"); + } else throw new RuntimeException("Wrong tx data element list size"); this.parsed = true; } diff --git a/ethereumj-core/src/main/java/org/ethereum/crypto/vm/OpCode.java b/ethereumj-core/src/main/java/org/ethereum/crypto/vm/OpCode.java deleted file mode 100644 index 1cac5dd2..00000000 --- a/ethereumj-core/src/main/java/org/ethereum/crypto/vm/OpCode.java +++ /dev/null @@ -1,144 +0,0 @@ -package org.ethereum.crypto.vm; - -/** - * 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 int opcode; - - private OpCode(int opcode) { - this.opcode = opcode; - } - - public int getOpCode() { - return this.opcode; - } - - -} diff --git a/ethereumj-core/src/main/java/org/ethereum/manager/MainData.java b/ethereumj-core/src/main/java/org/ethereum/manager/MainData.java index fd573583..efc73f72 100644 --- a/ethereumj-core/src/main/java/org/ethereum/manager/MainData.java +++ b/ethereumj-core/src/main/java/org/ethereum/manager/MainData.java @@ -2,10 +2,10 @@ package org.ethereum.manager; import com.maxmind.geoip.Location; +import org.ethereum.core.Block; +import org.ethereum.core.Transaction; import org.ethereum.geodb.IpGeoDB; -import org.ethereum.net.vo.Block; -import org.ethereum.net.vo.PeerData; -import org.ethereum.net.vo.Transaction; +import org.ethereum.net.client.PeerData; import java.util.*; diff --git a/ethereumj-core/src/main/java/org/ethereum/net/client/EthereumProtocolHandler.java b/ethereumj-core/src/main/java/org/ethereum/net/client/EthereumProtocolHandler.java index 556258bb..ffb9ffb9 100644 --- a/ethereumj-core/src/main/java/org/ethereum/net/client/EthereumProtocolHandler.java +++ b/ethereumj-core/src/main/java/org/ethereum/net/client/EthereumProtocolHandler.java @@ -1,16 +1,6 @@ package org.ethereum.net.client; import static org.ethereum.net.Command.*; -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; @@ -21,6 +11,7 @@ import java.util.List; import java.util.Timer; import java.util.TimerTask; +import org.ethereum.core.Block; import org.ethereum.gui.PeerListener; import org.ethereum.manager.MainData; import org.ethereum.net.Command; @@ -33,9 +24,8 @@ 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.RLP; -import org.ethereum.net.rlp.RLPList; -import org.ethereum.net.vo.Block; +import org.ethereum.util.RLP; +import org.ethereum.util.RLPList; import org.ethereum.util.Utils; import org.spongycastle.util.encoders.Hex; @@ -140,9 +130,8 @@ public class EthereumProtocolHandler extends ChannelInboundHandlerAdapter { // got HELLO if (Command.fromInt(command) == HELLO) { System.out.println("[Recv: HELLO]" ); - RLPList rlpList = new RLPList(); - RLP.parseObjects(payload, rlpList); - + RLPList rlpList = RLP.decode2(payload); + HelloMessage helloMessage = new HelloMessage(rlpList); System.out.println(helloMessage.toString()); if (peerListener != null) peerListener.console(helloMessage.toString()); @@ -152,8 +141,7 @@ public class EthereumProtocolHandler extends ChannelInboundHandlerAdapter { System.out.println("[Recv: DISCONNECT]"); if (peerListener != null) peerListener.console("[Recv: DISCONNECT]"); - RLPList rlpList = new RLPList(); - RLP.parseObjects(payload, rlpList); + RLPList rlpList = RLP.decode2(payload); DisconnectMessage disconnectMessage = new DisconnectMessage(rlpList); System.out.println(disconnectMessage); @@ -198,8 +186,7 @@ public class EthereumProtocolHandler extends ChannelInboundHandlerAdapter { System.out.println("[Recv: PEERS]"); if (peerListener != null) peerListener.console("[Recv: PEERS]"); - RLPList rlpList = new RLPList(); - RLP.parseObjects(payload, rlpList); + RLPList rlpList = RLP.decode2(payload); PeersMessage peersMessage = new PeersMessage(rlpList); MainData.instance.addPeers(peersMessage.getPeers()); @@ -212,8 +199,7 @@ public class EthereumProtocolHandler extends ChannelInboundHandlerAdapter { System.out.println("Recv: TRANSACTIONS]"); if (peerListener != null) peerListener.console("Recv: TRANSACTIONS]"); - RLPList rlpList = new RLPList(); - RLP.parseObjects(payload, rlpList); + RLPList rlpList = RLP.decode2(payload); TransactionsMessage transactionsMessage = new TransactionsMessage(rlpList); MainData.instance.addTransactions(transactionsMessage.getTransactions()); @@ -226,8 +212,7 @@ public class EthereumProtocolHandler extends ChannelInboundHandlerAdapter { System.out.println("[Recv: BLOCKS]"); if (peerListener != null) peerListener.console("[Recv: BLOCKS]"); - RLPList rlpList = new RLPList(); - RLP.parseObjects(payload, rlpList); + RLPList rlpList = RLP.decode2(payload); BlocksMessage blocksMessage = new BlocksMessage(rlpList); List blockList = blocksMessage.getBlockDataList(); @@ -241,8 +226,7 @@ public class EthereumProtocolHandler extends ChannelInboundHandlerAdapter { System.out.println("[Recv: GET_CHAIN]"); if (peerListener != null) peerListener.console("[Recv: GET_CHAIN]"); - RLPList rlpList = new RLPList(); - RLP.parseObjects(payload, rlpList); + RLPList rlpList = RLP.decode2(payload); GetChainMessage getChainMessage = new GetChainMessage(rlpList); System.out.println(getChainMessage); @@ -253,8 +237,7 @@ public class EthereumProtocolHandler extends ChannelInboundHandlerAdapter { System.out.println("[Recv: NOT_IN_CHAIN]"); if (peerListener != null) peerListener.console("[Recv: NOT_IN_CHAIN]"); - RLPList rlpList = new RLPList(); - RLP.parseObjects(payload, rlpList); + RLPList rlpList = RLP.decode2(payload); NotInChainMessage notInChainMessage = new NotInChainMessage(rlpList); System.out.println(notInChainMessage); @@ -287,7 +270,6 @@ public class EthereumProtocolHandler extends ChannelInboundHandlerAdapter { private void sendMsg(Message msg, ChannelHandlerContext ctx){ byte[] data = msg.getPayload(); - final ByteBuf buffer = ctx.alloc().buffer(data.length + 8); byte[] packetLen = calcPacketLength(data); diff --git a/ethereumj-core/src/main/java/org/ethereum/net/vo/PeerData.java b/ethereumj-core/src/main/java/org/ethereum/net/client/PeerData.java similarity index 98% rename from ethereumj-core/src/main/java/org/ethereum/net/vo/PeerData.java rename to ethereumj-core/src/main/java/org/ethereum/net/client/PeerData.java index 6080fc88..fc3130bd 100644 --- a/ethereumj-core/src/main/java/org/ethereum/net/vo/PeerData.java +++ b/ethereumj-core/src/main/java/org/ethereum/net/client/PeerData.java @@ -1,4 +1,4 @@ -package org.ethereum.net.vo; +package org.ethereum.net.client; import org.spongycastle.util.encoders.Hex; diff --git a/ethereumj-core/src/main/java/org/ethereum/net/message/BlocksMessage.java b/ethereumj-core/src/main/java/org/ethereum/net/message/BlocksMessage.java index 35982ea8..40be8aad 100644 --- a/ethereumj-core/src/main/java/org/ethereum/net/message/BlocksMessage.java +++ b/ethereumj-core/src/main/java/org/ethereum/net/message/BlocksMessage.java @@ -5,11 +5,11 @@ import java.util.List; import static org.ethereum.net.Command.BLOCKS; +import org.ethereum.core.Block; +import org.ethereum.core.Transaction; import org.ethereum.net.Command; -import org.ethereum.net.rlp.RLPItem; -import org.ethereum.net.rlp.RLPList; -import org.ethereum.net.vo.Block; -import org.ethereum.net.vo.Transaction; +import org.ethereum.util.RLPItem; +import org.ethereum.util.RLPList; /** * www.ethereumJ.com @@ -18,51 +18,50 @@ import org.ethereum.net.vo.Transaction; */ public class BlocksMessage extends Message { - private List blockDataList = new ArrayList(); + private List blockDataList = new ArrayList(); - public BlocksMessage(RLPList rawData) { - super(rawData); - } + public BlocksMessage(RLPList rawData) { + super(rawData); + } - public void parseRLP() { + public void parseRLP() { - RLPList paramsList = (RLPList) rawData.getElement(0); + RLPList paramsList = (RLPList) rawData.getElement(0); + + if (Command.fromInt(((RLPItem) (paramsList).getElement(0)).getData()[0]) != BLOCKS) { + throw new Error("BlocksMessage: parsing for mal data"); + } - 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)); + Block blockData = new Block(rlpData); + this.blockDataList.add(blockData); + } + parsed = true; + } - for (int i = 1; i < paramsList.size(); ++i){ - RLPList rlpData = ((RLPList)paramsList.getElement(i)); - Block blockData = new Block(rlpData); - this.blockDataList.add(blockData); - } - parsed = true; - } + @Override + public byte[] getPayload() { + return null; + } - @Override - public byte[] getPayload() { - return null; - } - - public List getBlockDataList() { - if (!parsed) parseRLP(); - return blockDataList; - } + public List getBlockDataList() { + if (!parsed) + parseRLP(); + return blockDataList; + } public String toString() { - StringBuffer sb = new StringBuffer(); - for (Block blockData : this.getBlockDataList()){ - sb.append(" ").append( blockData.toString() ).append("\n"); + StringBuffer sb = new StringBuffer(); + for (Block blockData : this.getBlockDataList()) { + sb.append(" ").append(blockData.toString()).append("\n"); - List transactions = blockData.getTransactionsList(); - for (Transaction transactionData : transactions){ - sb.append("[").append(transactionData).append("]\n"); - } - } - return "Blocks Message [\n" + - sb.toString() - + " ]"; - } + List transactions = blockData.getTransactionsList(); + for (Transaction transactionData : transactions) { + sb.append("[").append(transactionData).append("]\n"); + } + } + return "Blocks Message [\n" + sb.toString() + " ]"; + } } \ No newline at end of file diff --git a/ethereumj-core/src/main/java/org/ethereum/net/message/DisconnectMessage.java b/ethereumj-core/src/main/java/org/ethereum/net/message/DisconnectMessage.java index 47769063..8950e53d 100644 --- a/ethereumj-core/src/main/java/org/ethereum/net/message/DisconnectMessage.java +++ b/ethereumj-core/src/main/java/org/ethereum/net/message/DisconnectMessage.java @@ -1,8 +1,9 @@ package org.ethereum.net.message; -import org.ethereum.net.rlp.RLPItem; -import org.ethereum.net.rlp.RLPList; import org.ethereum.net.Command; +import org.ethereum.util.RLPItem; +import org.ethereum.util.RLPList; + import static org.ethereum.net.Command.DISCONNECT; import static org.ethereum.net.message.ReasonCode.DISCONNECT_REQUESTED; diff --git a/ethereumj-core/src/main/java/org/ethereum/net/message/GetChainMessage.java b/ethereumj-core/src/main/java/org/ethereum/net/message/GetChainMessage.java index 79894395..1bf38220 100644 --- a/ethereumj-core/src/main/java/org/ethereum/net/message/GetChainMessage.java +++ b/ethereumj-core/src/main/java/org/ethereum/net/message/GetChainMessage.java @@ -5,9 +5,10 @@ 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.RLPItem; +import org.ethereum.util.RLPList; import org.ethereum.util.Utils; /** diff --git a/ethereumj-core/src/main/java/org/ethereum/net/message/HelloMessage.java b/ethereumj-core/src/main/java/org/ethereum/net/message/HelloMessage.java index 713dc72a..93e2e74e 100644 --- a/ethereumj-core/src/main/java/org/ethereum/net/message/HelloMessage.java +++ b/ethereumj-core/src/main/java/org/ethereum/net/message/HelloMessage.java @@ -4,9 +4,9 @@ import org.spongycastle.util.encoders.Hex; import static org.ethereum.net.Command.HELLO; -import org.ethereum.net.rlp.RLP; -import org.ethereum.net.rlp.RLPItem; -import org.ethereum.net.rlp.RLPList; +import org.ethereum.util.RLP; +import org.ethereum.util.RLPItem; +import org.ethereum.util.RLPList; import java.nio.ByteBuffer; diff --git a/ethereumj-core/src/main/java/org/ethereum/net/message/Message.java b/ethereumj-core/src/main/java/org/ethereum/net/message/Message.java index 04cf113e..42426165 100644 --- a/ethereumj-core/src/main/java/org/ethereum/net/message/Message.java +++ b/ethereumj-core/src/main/java/org/ethereum/net/message/Message.java @@ -1,6 +1,6 @@ package org.ethereum.net.message; -import org.ethereum.net.rlp.RLPList; +import org.ethereum.util.RLPList; /** * www.ethereumJ.com diff --git a/ethereumj-core/src/main/java/org/ethereum/net/message/NotInChainMessage.java b/ethereumj-core/src/main/java/org/ethereum/net/message/NotInChainMessage.java index a7328d90..7b26b932 100644 --- a/ethereumj-core/src/main/java/org/ethereum/net/message/NotInChainMessage.java +++ b/ethereumj-core/src/main/java/org/ethereum/net/message/NotInChainMessage.java @@ -4,8 +4,8 @@ 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; +import org.ethereum.util.RLPItem; +import org.ethereum.util.RLPList; import org.ethereum.util.Utils; /** diff --git a/ethereumj-core/src/main/java/org/ethereum/net/message/PeersMessage.java b/ethereumj-core/src/main/java/org/ethereum/net/message/PeersMessage.java index 8a21023d..362c0a9a 100644 --- a/ethereumj-core/src/main/java/org/ethereum/net/message/PeersMessage.java +++ b/ethereumj-core/src/main/java/org/ethereum/net/message/PeersMessage.java @@ -5,10 +5,11 @@ 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; +import org.ethereum.net.client.PeerData; +import org.ethereum.util.RLPItem; +import org.ethereum.util.RLPList; /** * www.ethereumJ.com diff --git a/ethereumj-core/src/main/java/org/ethereum/net/message/TransactionsMessage.java b/ethereumj-core/src/main/java/org/ethereum/net/message/TransactionsMessage.java index 2b1ef845..b3e11fcc 100644 --- a/ethereumj-core/src/main/java/org/ethereum/net/message/TransactionsMessage.java +++ b/ethereumj-core/src/main/java/org/ethereum/net/message/TransactionsMessage.java @@ -1,10 +1,11 @@ package org.ethereum.net.message; import static org.ethereum.net.Command.TRANSACTIONS; + +import org.ethereum.core.Transaction; import org.ethereum.net.Command; -import org.ethereum.net.rlp.RLPItem; -import org.ethereum.net.rlp.RLPList; -import org.ethereum.net.vo.Transaction; +import org.ethereum.util.RLPItem; +import org.ethereum.util.RLPList; import java.util.ArrayList; import java.util.List; diff --git a/ethereumj-core/src/main/java/org/ethereum/net/rlp/RLPElement.java b/ethereumj-core/src/main/java/org/ethereum/net/rlp/RLPElement.java deleted file mode 100644 index dfb2ec17..00000000 --- a/ethereumj-core/src/main/java/org/ethereum/net/rlp/RLPElement.java +++ /dev/null @@ -1,10 +0,0 @@ -package org.ethereum.net.rlp; - -/** - * www.ethereumJ.com - * User: Roman Mandeleil - * Created on: 21/04/14 16:28 - */ -public interface RLPElement { - -} diff --git a/ethereumj-core/src/main/java/org/ethereum/net/rlp/RLP.java b/ethereumj-core/src/main/java/org/ethereum/util/RLP.java similarity index 75% rename from ethereumj-core/src/main/java/org/ethereum/net/rlp/RLP.java rename to ethereumj-core/src/main/java/org/ethereum/util/RLP.java index ea2f66e5..c8ecba03 100644 --- a/ethereumj-core/src/main/java/org/ethereum/net/rlp/RLP.java +++ b/ethereumj-core/src/main/java/org/ethereum/util/RLP.java @@ -1,11 +1,20 @@ -package org.ethereum.net.rlp; +package org.ethereum.util; import java.math.BigInteger; import java.nio.ByteBuffer; +import java.util.ArrayList; import java.util.Arrays; -import java.util.List; import java.util.Queue; +import static java.util.Arrays.copyOfRange; +import static org.spongycastle.util.Arrays.concatenate; + +import java.util.List; + +import org.ethereum.util.RLP; +import org.ethereum.util.RLPItem; +import org.ethereum.util.RLPList; + /** * Recursive Length Prefix (RLP) encoding. * @@ -34,6 +43,9 @@ import java.util.Queue; */ public class RLP { + /** Allow for content up to size of 2^64 bytes **/ + private static double MAX_ITEM_LENGTH = Math.pow(256, 8); + /** * Reason for threshold according to Vitalik Buterin: * - 56 bytes maximizes the benefit of both options @@ -45,13 +57,30 @@ public class RLP { **/ private static int SIZE_THRESHOLD = 56; + /** RLP encoding rules are defined as follows: */ + + /* + * For a single byte whose value is in the [0x00, 0x7f] range, that byte is + * its own RLP encoding. + */ + /* * If a string is 0-55 bytes long, the RLP encoding consists of a single * byte with value 0x80 plus the length of the string followed by the * string. The range of the first byte is thus [0x80, 0xb7]. */ private static int OFFSET_SHORT_ITEM = 0x80; - + + /* + * If a string is more than 55 bytes long, the RLP encoding consists of a + * single byte with value 0xb7 plus the length of the length of the string + * in binary form, followed by the length of the string, followed by the + * string. For example, a length-1024 string would be encoded as + * \xb9\x04\x00 followed by the string. The range of the first byte is thus + * [0xb8, 0xbf]. + */ + private static int OFFSET_LONG_ITEM = 0xb8; + /* * If the total payload of a list (i.e. the combined length of all its * items) is 0-55 bytes long, the RLP encoding consists of a single byte @@ -60,9 +89,22 @@ public class RLP { * [0xc0, 0xf7]. */ private static int OFFSET_SHORT_LIST = 0xc0; + + /* + * If the total payload of a list is more than 55 bytes long, the RLP + * encoding consists of a single byte with value 0xf7 plus the length of the + * length of the list in binary form, followed by the length of the list, + * followed by the concatenation of the RLP encodings of the items. The + * range of the first byte is thus [0xf8, 0xff]. + */ + private static int OFFSET_LONG_LIST = 0xf8; + + + /* ****************************************************** + * DECODING * + * ******************************************************/ private static byte decodeOneByteItem(byte[] data, int index) { - // null item if ((data[index] & 0xFF) == OFFSET_SHORT_ITEM) { return (byte) (data[index] - OFFSET_SHORT_ITEM); @@ -91,7 +133,7 @@ public class RLP { pow--; } } else { - throw new Error("wrong decode attempt"); + throw new RuntimeException("wrong decode attempt"); } return value; } @@ -122,7 +164,7 @@ public class RLP { pow--; } } else { - throw new Error("wrong decode attempt"); + throw new RuntimeException("wrong decode attempt"); } return value; } @@ -143,7 +185,7 @@ public class RLP { value = new String(data, index + 1, length); } else { - throw new Error("wrong decode attempt"); + throw new RuntimeException("wrong decode attempt"); } return value; } @@ -163,7 +205,7 @@ public class RLP { length = (byte) (data[index] - OFFSET_SHORT_ITEM); } else { - throw new Error("wrong decode attempt"); + throw new RuntimeException("wrong decode attempt"); } byte[] valueBytes = new byte[length]; System.arraycopy(data, index, valueBytes, 0, length); @@ -186,7 +228,7 @@ public class RLP { length = (byte) (data[index] - OFFSET_SHORT_ITEM); } else { - throw new Error("wrong decode attempt"); + throw new RuntimeException("wrong decode attempt"); } byte[] valueBytes = new byte[length]; System.arraycopy(data, index, valueBytes, 0, length); @@ -209,14 +251,14 @@ public class RLP { length = (byte) (data[index] - OFFSET_SHORT_ITEM); } else { - throw new Error("wrong decode attempt"); + throw new RuntimeException("wrong decode attempt"); } byte[] valueBytes = new byte[length]; System.arraycopy(data, index, valueBytes, 0, length); value = valueBytes; return value; } - + private static int nextItemLength(byte[] data, int index) { if (index >= data.length) @@ -278,13 +320,8 @@ public class RLP { offset = offset + 1; byte dByte = decodeOneByteItem(data, index + offset); - byte[] ip = new byte[4]; - ip[0] = aByte; - ip[1] = bByte; - ip[2] = cByte; - ip[3] = dByte; - - return ip; + // return IP address + return new byte[] { aByte, bByte, cByte, dByte } ; } public static int getFirstListElement(byte[] payload, int pos) { @@ -293,22 +330,14 @@ public class RLP { return -1; if ((payload[pos] & 0xFF) >= 0xF7) { - byte lengthOfLength = (byte) (payload[pos] - 0xF7); - return pos + lengthOfLength + 1; } - if ((payload[pos] & 0xFF) >= OFFSET_SHORT_LIST && (payload[pos] & 0xFF) < 0xF7) { - - byte length = (byte) ((payload[pos] & 0xFF) - OFFSET_SHORT_LIST); return pos + 1; - } - + } if ((payload[pos] & 0xFF) >= 0xB7 && (payload[pos] & 0xFF) < OFFSET_SHORT_LIST) { - byte lengthOfLength = (byte) (payload[pos] - 0xB7); - int length = calcLength(lengthOfLength, payload, pos); return pos + lengthOfLength + 1; } @@ -353,11 +382,12 @@ public class RLP { /** * Get exactly one message payload */ - public static void fullTraverse(byte[] msgData, int level, int startPos, - int endPos, int levelToIndex, Queue index) { + public static void fullTraverse(byte[] msgData, int level, int startPos, + int endPos, int levelToIndex, Queue index) { + try { - if (msgData == null || msgData.length == 0) + if (msgData == null || msgData.length == 0) return; int pos = startPos; @@ -443,7 +473,7 @@ public class RLP { } } } catch (Throwable th) { - throw new Error("wire packet not parsed correctly", + throw new RuntimeException("wire packet not parsed correctly", th.fillInStackTrace()); } } @@ -467,6 +497,14 @@ public class RLP { } return length; } + + public static byte getCommandCode(byte[] data) { + byte command = 0; + int index = getFirstListElement(data, 0); + command = data[index]; + command = ((int) (command & 0xFF) == OFFSET_SHORT_ITEM) ? 0 : command; + return command; + } /** * Parse wire byte[] message into RLP elements @@ -476,15 +514,17 @@ public class RLP { * @param rlpList * - outcome of recursive RLP structure */ - public static void parseObjects(byte[] msgData, RLPList rlpList) { - RLP.fullTraverse(msgData, 0, 0, msgData.length, 1, rlpList); + public static RLPList decode2(byte[] msgData) { + RLPList rlpList = new RLPList(); + fullTraverse(msgData, 0, 0, msgData.length, 1, rlpList); + return rlpList; } /** * Get exactly one message payload */ - private static void fullTraverse(byte[] msgData, int level, int startPos, - int endPos, int levelToIndex, RLPList rlpList) { + private static void fullTraverse(byte[] msgData, int level, int startPos, + int endPos, int levelToIndex, RLPList rlpList) { try { if (msgData == null || msgData.length == 0) @@ -604,116 +644,128 @@ public class RLP { } } } catch (Throwable th) { - throw new Error("wire packet not parsed correctly", - th.fillInStackTrace()); + throw new RuntimeException("wire packet not parsed correctly", + th.fillInStackTrace()); } } - - private static String rlpEncode(Object item) { - if (item instanceof String) { - String str = ((String) item); - int length = str.length(); - if (length == 1 && str.charAt(0) < OFFSET_SHORT_ITEM) - return str; - else - return encodeLength(str.length(), OFFSET_SHORT_ITEM) + str; - } else if (item instanceof List) { - List itemList = (List) item; - StringBuilder output = new StringBuilder(); - - for (Object oneItem : itemList) - output.append(rlpEncode(oneItem)); - return encodeLength(output.toString().length(), OFFSET_SHORT_LIST) - + output.toString(); - } - throw new Error("unsupported type" + item.getClass()); - } - - /** Integer limitation goes up to 2^31-1 so length can never be bigger */ - private static String encodeLength(int L, int offset) { - if (L < SIZE_THRESHOLD) - return "" + (char) (L + offset); - else if (L < Math.pow(256, 8)) { - String BL = toBinary(L); - return "" + (char) (BL.length() + offset + SIZE_THRESHOLD - 1) + BL; - } else - throw new Error("input too long"); - } - - private static String toBinary(int x) { - if (x == 0) - return ""; - else - return toBinary(x >> 8) + ((char) (x & 0x00FF)); - } - - public static byte getCommandCode(byte[] data) { - byte command = 0; - int index = getFirstListElement(data, 0); - command = data[index]; - command = ((int) (command & 0xFF) == OFFSET_SHORT_ITEM) ? 0 : command; - return command; - } - - private static Object decode(char[] data) { - - if (data == null || data.length == 0) - return null; - - if (data[0] >= 0xF7) { - /* - * It's a list with a payload more than 55 bytes - * data[0] - 0xF7 = how many next bytes allocated for the length of the list - */ - byte lengthOfLength = (byte) (data[0] - 0xF7); - - byte pow = (byte) (lengthOfLength - 1); - long length = 0; - for (int i = 1; i <= lengthOfLength; ++i) { - length += data[i] << (8 * pow); - pow--; - } - System.out.println(length); - // now we can parse an item for data[1]..data[length] - } - if (data[0] >= OFFSET_SHORT_LIST && data[0] < 0xF7) - /* - * It's a list with a payload less than 55 bytes - */ - ; - if (data[0] >= 0xB7 && data[0] < OFFSET_SHORT_LIST) { - /* - * 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 - */ - ; - byte lengthOfLength = (byte) (data[0] - 0xB7); - - byte pow = (byte) (lengthOfLength - 1); - long length = 0; - for (int i = 1; i <= lengthOfLength; ++i) { - length += data[i] << (8 * pow); - pow--; - } - System.out.println(length); - // now we can parse an item for data[1]..data[length] - } - if (data[0] >= OFFSET_SHORT_ITEM && data[0] < 0xB7) { - /* - * It's an item less than 55 bytes long, - * data[0] - OFFSET_SHORT_ITEM == length of the item - */ - ; - } - if (data[0] == OFFSET_SHORT_ITEM) - /* null item */ - ; - if (data[0] < OFFSET_SHORT_ITEM) - /* single byte item */ - ; - return null; - } - + + /** + * Reads any RLP encoded byte-array and returns all objects as byte-array or list of byte-arrays + * + * @param data RLP encoded byte-array + * @param pos position in the array to start reading + * @return DecodeResult encapsulates the decoded items as a single Object and the final read position + */ + public static DecodeResult decode(byte[] data, int pos) { + if (data == null || data.length < 1) { + return null; + } + + int prefix = data[pos] & 0xFF; + if (prefix == OFFSET_SHORT_ITEM) { + return new DecodeResult(pos+1, new byte[0]); // means no length or 0 + } else if (prefix < OFFSET_SHORT_ITEM) { + return new DecodeResult(pos+1, new byte[] { data[pos] }); // byte is its own RLP encoding + } else if (prefix < OFFSET_LONG_ITEM){ + int len = prefix - OFFSET_SHORT_ITEM; // length of the encoded bytes + return new DecodeResult(pos+1+len, copyOfRange(data, pos+1, pos+1+len)); + } else if (prefix < OFFSET_SHORT_LIST) { + int lenlen = prefix - OFFSET_LONG_ITEM + 1; // length of length the encoded bytes + int lenbytes = toInt(copyOfRange(data, pos+1, pos+1+lenlen)); // length of encoded bytes + return new DecodeResult(pos+1+lenlen+lenbytes, copyOfRange(data, pos+1+lenlen, pos+1+lenlen+lenbytes)); + } else if (prefix < OFFSET_LONG_LIST) { + int len = prefix - OFFSET_SHORT_LIST; // length of the encoded list + int prevPos = pos; pos++; + return decodeList(data, pos, prevPos, len); + } else if (prefix < 0xFF) { + int lenlen = prefix - OFFSET_LONG_LIST + 1; // length of length the encoded list + int lenlist = toInt(copyOfRange(data, pos+1, pos+1+lenlen)); // length of encoded bytes + pos = pos + lenlen + 1; + int prevPos = lenlist; + return decodeList(data, pos, prevPos, lenlist); + } else { + throw new RuntimeException("Only byte values between 0x00 and 0xFF are supported, but got: " + prefix); + } + } + + private static DecodeResult decodeList(byte[] data, int pos, int prevPos, int len) { + List slice = new ArrayList(); + for (int i = 0; i < len;) { + // Get the next item in the data list and append it + DecodeResult result = decode(data, pos); + slice.add(result.getDecoded()); + // Increment pos by the amount bytes in the previous read + prevPos = result.getPos(); + i += (prevPos - pos); + pos = prevPos; + } + return new DecodeResult(pos, slice.toArray()); + } + + /** + * Cast hex encoded value from byte[] to int + * + * Limited to Integer.MAX_VALUE: 2^32-1 + * + * @param b array contains the hex values + * @return int value of all hex values together. + */ + public static int toInt(byte[] b) { + if (b == null || b.length == 0) { + return 0; + } + return new BigInteger(b).intValue(); + } + + /* ****************************************************** + * ENCODING * + * ******************************************************/ + + /** + * Turn Object into its RLP encoded equivalent of a byte-array + * Support for String, Integer, BigInteger and Lists of any of these types. + * + * @param item as object or List of objects + * @return byte[] RLP encoded + */ + public static byte[] encode(Object input) { + Value val = new Value(input); + if (val.isList()) { + List inputArray = val.asList(); + if (inputArray.size() == 0) { + return encodeLength(inputArray.size(), OFFSET_SHORT_LIST); + } + byte[] output = new byte[0]; + for (Object object : inputArray) { + output = concatenate(output, encode(object)); + } + byte[] prefix = encodeLength(output.length, OFFSET_SHORT_LIST); + return concatenate(prefix, output); + } else { + byte[] inputAsBytes = toBytes(input); + if(inputAsBytes.length == 1) { + return inputAsBytes; + } else { + byte[] firstByte = encodeLength(inputAsBytes.length, OFFSET_SHORT_ITEM); + return concatenate(firstByte, inputAsBytes); + } + } + } + + /** Integer limitation goes up to 2^31-1 so length can never be bigger than MAX_ITEM_LENGTH */ + public static byte[] encodeLength(int length, int offset) { + if (length < SIZE_THRESHOLD) { + byte firstByte = (byte) (length + offset); + return new byte[] { firstByte }; + } else if (length < MAX_ITEM_LENGTH) { + byte[] binaryLength = BigInteger.valueOf(length).toByteArray(); + byte firstByte = (byte) (binaryLength.length + offset + SIZE_THRESHOLD - 1 ); + return concatenate(new byte[] { firstByte }, binaryLength); + } else { + throw new RuntimeException("Input too long"); + } + } + public static byte[] encodeByte(byte singleByte) { if ((singleByte & 0xFF) == 0) { @@ -816,4 +868,26 @@ public class RLP { } return data; } -} \ No newline at end of file + + /* + * Utility function to convert Objects into byte arrays + */ + private static byte[] toBytes(Object input) { + if (input instanceof byte[]) { + return (byte[]) input; + } else if (input instanceof String) { + String inputString = (String) input; + return inputString.getBytes(); + } else if(input instanceof Integer) { + Integer inputInt = (Integer) input; + return (inputInt == 0) ? new byte[0] : BigInteger.valueOf(inputInt.longValue()).toByteArray(); + } else if(input instanceof BigInteger) { + BigInteger inputBigInt = (BigInteger) input; + return (inputBigInt == BigInteger.ZERO) ? new byte[0] : inputBigInt.toByteArray(); + } else if (input instanceof Value) { + Value val = (Value) input; + return toBytes(val.asObj()); + } + throw new RuntimeException("Unsupported type: Only accepting String, Integer and BigInteger for now"); + } +} diff --git a/ethereumj-core/src/main/java/org/ethereum/util/RLPElement.java b/ethereumj-core/src/main/java/org/ethereum/util/RLPElement.java new file mode 100644 index 00000000..98b339fa --- /dev/null +++ b/ethereumj-core/src/main/java/org/ethereum/util/RLPElement.java @@ -0,0 +1,8 @@ +package org.ethereum.util; + +/** + * Wrapper class for decoded elements from an RLP encoded byte array. + */ +public interface RLPElement { + +} diff --git a/ethereumj-core/src/main/java/org/ethereum/net/rlp/RLPItem.java b/ethereumj-core/src/main/java/org/ethereum/util/RLPItem.java similarity index 90% rename from ethereumj-core/src/main/java/org/ethereum/net/rlp/RLPItem.java rename to ethereumj-core/src/main/java/org/ethereum/util/RLPItem.java index a9d86418..cf097fa5 100644 --- a/ethereumj-core/src/main/java/org/ethereum/net/rlp/RLPItem.java +++ b/ethereumj-core/src/main/java/org/ethereum/util/RLPItem.java @@ -1,4 +1,4 @@ -package org.ethereum.net.rlp; +package org.ethereum.util; /** * www.ethereumJ.com diff --git a/ethereumj-core/src/main/java/org/ethereum/net/rlp/RLPList.java b/ethereumj-core/src/main/java/org/ethereum/util/RLPList.java similarity index 87% rename from ethereumj-core/src/main/java/org/ethereum/net/rlp/RLPList.java rename to ethereumj-core/src/main/java/org/ethereum/util/RLPList.java index 05c732ad..639252d6 100644 --- a/ethereumj-core/src/main/java/org/ethereum/net/rlp/RLPList.java +++ b/ethereumj-core/src/main/java/org/ethereum/util/RLPList.java @@ -1,16 +1,14 @@ -package org.ethereum.net.rlp; +package org.ethereum.util; import java.util.ArrayList; import java.util.List; -import org.ethereum.util.Utils; - /** * www.ethereumJ.com * User: Roman Mandeleil * Created on: 21/04/14 16:26 */ -public class RLPList implements RLPElement{ +public class RLPList implements RLPElement { byte[] rlpData; List list; @@ -46,7 +44,7 @@ public class RLPList implements RLPElement{ public static void recursivePrint(RLPElement element) { if (element == null) - throw new Error("RLPElement object can't be null"); + throw new RuntimeException("RLPElement object can't be null"); if (element instanceof RLPList) { RLPList rlpList = (RLPList) element; diff --git a/ethereumj-core/src/main/java/org/ethereum/util/RlpEncoder.java b/ethereumj-core/src/main/java/org/ethereum/util/RlpEncoder.java deleted file mode 100644 index c3cebafb..00000000 --- a/ethereumj-core/src/main/java/org/ethereum/util/RlpEncoder.java +++ /dev/null @@ -1,213 +0,0 @@ -package org.ethereum.util; - -import java.math.BigInteger; -import java.util.ArrayList; - -import static java.util.Arrays.copyOfRange; -import static org.spongycastle.util.Arrays.concatenate; - -import java.util.List; - -/** - * Recursive Length Prefix (RLP) encoding. - * - * The purpose of RLP is to encode arbitrarily nested arrays of binary data, and - * RLP is the main encoding method used to serialize objects in Ethereum. The - * only purpose of RLP is to encode structure; encoding specific atomic data - * types (eg. strings, ints, floats) is left up to higher-order protocols; in - * Ethereum the standard is that integers are represented in big endian binary - * form. If one wishes to use RLP to encode a dictionary, the two suggested - * canonical forms are to either use [[k1,v1],[k2,v2]...] with keys in - * lexicographic order or to use the higher-level Patricia Tree encoding as - * Ethereum does. - * - * The RLP encoding function takes in an item. An item is defined as follows: - * - * - A string (ie. byte array) is an item - A list of items is an item - * - * For example, an empty string is an item, as is the string containing the word - * "cat", a list containing any number of strings, as well as more complex data - * structures like ["cat",["puppy","cow"],"horse",[[]],"pig",[""],"sheep"]. Note - * that in the context of the rest of this article, "string" will be used as a - * synonym for "a certain number of bytes of binary data"; no special encodings - * are used and no knowledge about the content of the strings is implied. - * - * See: https://github.com/ethereum/wiki/wiki/%5BEnglish%5D-RLP - */ -public class RlpEncoder extends CompactEncoder { - - /** Allow for content up to size of 2^64 bytes **/ - private static double MAX_ITEM_LENGTH = Math.pow(256, 8); - - /** - [5:30:35 PM] Vitalik Buterin: 56 bytes maximizes the benefit of both options - [5:30:41 PM] Vitalik Buterin: if we went with 60 - [5:31:03 PM] Vitalik Buterin: then we would have only had 4 slots for long strings so RLP would not have been able to store objects above 4gb - [5:31:08 PM] Vitalik Buterin: if we went with 48 - [5:31:18 PM] Vitalik Buterin: then RLP would be fine for 2^128 space, but that's way too much - [5:31:32 PM] Vitalik Buterin: so 56 and 2^64 space seems like the right place to put the cutoff - [5:31:44 PM] Vitalik Buterin: also, that's where Bitcoin's varint does the cutof - **/ - private static int SIZE_THRESHOLD = 56; - - /** RLP encoding rules are defined as follows: */ - - /* - * For a single byte whose value is in the [0x00, 0x7f] range, that byte is - * its own RLP encoding. - */ - - /* - * If a string is 0-55 bytes long, the RLP encoding consists of a single - * byte with value 0x80 plus the length of the string followed by the - * string. The range of the first byte is thus [0x80, 0xb7]. - */ - private static int offsetShortItem = 0x80; - - /* - * If a string is more than 55 bytes long, the RLP encoding consists of a - * single byte with value 0xb7 plus the length of the length of the string - * in binary form, followed by the length of the string, followed by the - * string. For example, a length-1024 string would be encoded as - * \xb9\x04\x00 followed by the string. The range of the first byte is thus - * [0xb8, 0xbf]. - */ - private static int offsetLongItem = 0xb8; - - /* - * If the total payload of a list (i.e. the combined length of all its - * items) is 0-55 bytes long, the RLP encoding consists of a single byte - * with value 0xc0 plus the length of the list followed by the concatenation - * of the RLP encodings of the items. The range of the first byte is thus - * [0xc0, 0xf7]. - */ - private static int offsetShortList = 0xc0; - - /* - * If the total payload of a list is more than 55 bytes long, the RLP - * encoding consists of a single byte with value 0xf7 plus the length of the - * length of the list in binary form, followed by the length of the list, - * followed by the concatenation of the RLP encodings of the items. The - * range of the first byte is thus [0xf8, 0xff]. - */ - private static int offsetLongList = 0xf8; - private static int maxPrefix = 0xff; - - public static byte[] encode(Object input) { - Value val = new Value(input); - if (val.isList()) { - List inputArray = val.asList(); - if (inputArray.size() == 0) { - return encodeLength(inputArray.size(), offsetShortList); - } - byte[] output = new byte[0]; - for (Object object : inputArray) { - output = concatenate(output, encode(object)); - } - byte[] prefix = encodeLength(output.length, offsetShortList); - return concatenate(prefix, output); - } else { - byte[] inputAsHex = asHex(input); - if(inputAsHex.length == 1) { - return inputAsHex; - } else { - byte[] firstByte = encodeLength(inputAsHex.length, offsetShortItem); - return concatenate(firstByte, inputAsHex); - } - } - } - - public static DecodeResult decode(byte[] data, int pos) { - if (data == null || data.length < 1) { - return null; - } - - int prefix = data[pos] & maxPrefix; - if (prefix == offsetShortItem) { - return new DecodeResult(pos+1, new byte[0]); // means no length or 0 - } else if (prefix < offsetShortItem) { - return new DecodeResult(pos+1, new byte[] { data[pos] }); // byte is its own RLP encoding - } else if (prefix < offsetLongItem){ - int len = prefix - offsetShortItem; // length of the encoded bytes - return new DecodeResult(pos+1+len, copyOfRange(data, pos+1, pos+1+len)); - } else if (prefix < offsetShortList) { - int lenlen = prefix - offsetLongItem + 1; // length of length the encoded bytes - int lenbytes = toInt(copyOfRange(data, pos+1, pos+1+lenlen)); // length of encoded bytes - return new DecodeResult(pos+1+lenlen+lenbytes, copyOfRange(data, pos+1+lenlen, pos+1+lenlen+lenbytes)); - } else if (prefix < offsetLongList) { - int len = prefix - offsetShortList; // length of the encoded list - int prevPos = pos; pos++; - return decodeList(data, pos, prevPos, len); - } else if (prefix < maxPrefix) { - int lenlen = prefix - offsetLongList + 1; // length of length the encoded list - int lenlist = toInt(copyOfRange(data, pos+1, pos+1+lenlen)); // length of encoded bytes - pos = pos + lenlen + 1; - int prevPos = lenlist; - return decodeList(data, pos, prevPos, lenlist); - } else { - throw new RuntimeException("Only byte values between 0x00 and 0xFF are supported, but got: " + prefix); - } - } - - /** Integer limitation goes up to 2^31-1 so length can never be bigger than MAX_ITEM_LENGTH */ - public static byte[] encodeLength(int length, int offset) { - if (length < SIZE_THRESHOLD) { - byte firstByte = (byte) (length + offset); - return new byte[] { firstByte }; - } else if (length < MAX_ITEM_LENGTH) { - byte[] binaryLength = BigInteger.valueOf(length).toByteArray(); - byte firstByte = (byte) (binaryLength.length + offset + SIZE_THRESHOLD - 1 ); - return concatenate(new byte[] { firstByte }, binaryLength); - } else { - throw new RuntimeException("Input too long"); - } - } - - private static DecodeResult decodeList(byte[] data, int pos, int prevPos, int len) { - List slice = new ArrayList(); - for (int i = 0; i < len;) { - // Get the next item in the data list and append it - DecodeResult result = decode(data, pos); - slice.add(result.getDecoded()); - // Increment pos by the amount bytes in the previous read - prevPos = result.getPos(); - i += (prevPos - pos); - pos = prevPos; - } - return new DecodeResult(pos, slice.toArray()); - } - - public static byte[] asHex(Object input) { - if (input instanceof byte[]) { - return (byte[]) input; - } else if (input instanceof String) { - String inputString = (String) input; - return inputString.getBytes(); - } else if(input instanceof Integer) { - Integer inputInt = (Integer) input; - return (inputInt == 0) ? new byte[0] : BigInteger.valueOf(inputInt.longValue()).toByteArray(); - } else if(input instanceof BigInteger) { - BigInteger inputBigInt = (BigInteger) input; - return (inputBigInt == BigInteger.ZERO) ? new byte[0] : inputBigInt.toByteArray(); - } else if (input instanceof Value) { - Value val = (Value) input; - return asHex(val.asObj()); - } - throw new RuntimeException("Unsupported type: Only accepting String, Integer and BigInteger for now"); - } - - /** - * Cast hex encoded value from byte[] to int - * - * Limited to Integer.MAX_VALUE: 2^32-1 - * - * @param b array contains the hex values - * @return int value of all hex values together. - */ - public static int toInt(byte[] b) { - if (b == null || b.length == 0) { - return 0; - } - return new BigInteger(b).intValue(); - } -} diff --git a/ethereumj-core/src/main/java/org/ethereum/util/Value.java b/ethereumj-core/src/main/java/org/ethereum/util/Value.java index 49daeaa6..9cb30af5 100644 --- a/ethereumj-core/src/main/java/org/ethereum/util/Value.java +++ b/ethereumj-core/src/main/java/org/ethereum/util/Value.java @@ -15,7 +15,7 @@ public class Value { public void fromRlpEncoded(byte[] data) { if (data.length != 0) { - this.value = RlpEncoder.decode(data, 0).getDecoded(); + this.value = RLP.decode(data, 0).getDecoded(); } } @@ -104,7 +104,7 @@ public class Value { * *****************/ public byte[] encode() { - return RlpEncoder.encode(value); + return RLP.encode(value); } public boolean cmp(Value o) { diff --git a/ethereumj-core/src/test/java/org/ethereum/block/BlockTest.java b/ethereumj-core/src/test/java/org/ethereum/block/BlockTest.java index c5f9f603..be5a31e5 100644 --- a/ethereumj-core/src/test/java/org/ethereum/block/BlockTest.java +++ b/ethereumj-core/src/test/java/org/ethereum/block/BlockTest.java @@ -1,11 +1,10 @@ package org.ethereum.block; import org.spongycastle.util.encoders.Hex; +import org.ethereum.core.Block; import org.ethereum.crypto.HashUtil; -import org.ethereum.net.rlp.RLP; -import org.ethereum.net.rlp.RLPList; -import org.ethereum.net.vo.Block; -import org.ethereum.util.RlpEncoder; +import org.ethereum.util.RLP; +import org.ethereum.util.RLPList; import org.junit.Test; import static org.junit.Assert.*; @@ -129,7 +128,7 @@ public class BlockTest { public void testGenesisFromNew() { System.out.println(CPP_PoC5_GENESIS_HEX_RLP_ENCODED); - Object genesisItems = RlpEncoder.decode(CPP_PoC5_GENESIS_HEX_RLP_ENCODED.getBytes(), 0).getDecoded(); + Object genesisItems = RLP.decode(CPP_PoC5_GENESIS_HEX_RLP_ENCODED.getBytes(), 0).getDecoded(); // TODO: verify genesis items with expected values /* From: https://ethereum.etherpad.mozilla.org/11 @@ -183,8 +182,7 @@ public class BlockTest { byte[] payload = Hex.decode(blocksMsg); - RLPList rlpList = new RLPList(); - RLP.parseObjects(payload, rlpList); + RLPList rlpList = RLP.decode2(payload); Block blockData = new Block(rlpList); RLPList.recursivePrint(rlpList); diff --git a/ethereumj-core/src/test/java/org/ethereum/net/MessagesTest.java b/ethereumj-core/src/test/java/org/ethereum/net/MessagesTest.java index c13a5eda..93fe98fa 100644 --- a/ethereumj-core/src/test/java/org/ethereum/net/MessagesTest.java +++ b/ethereumj-core/src/test/java/org/ethereum/net/MessagesTest.java @@ -5,6 +5,9 @@ import static org.junit.Assert.*; import java.net.UnknownHostException; import java.util.List; +import org.ethereum.core.Block; +import org.ethereum.core.Transaction; +import org.ethereum.net.client.PeerData; import org.ethereum.net.message.BlocksMessage; import org.ethereum.net.message.DisconnectMessage; import org.ethereum.net.message.GetChainMessage; @@ -13,11 +16,8 @@ import org.ethereum.net.message.NotInChainMessage; import org.ethereum.net.message.PeersMessage; import org.ethereum.net.message.ReasonCode; import org.ethereum.net.message.TransactionsMessage; -import org.ethereum.net.rlp.RLP; -import org.ethereum.net.rlp.RLPList; -import org.ethereum.net.vo.Block; -import org.ethereum.net.vo.PeerData; -import org.ethereum.net.vo.Transaction; +import org.ethereum.util.RLP; +import org.ethereum.util.RLPList; import org.ethereum.util.Utils; import org.junit.Test; import org.spongycastle.util.encoders.Hex; @@ -38,8 +38,7 @@ public class MessagesTest { "C2 DE 3B 4B 25 52 FB 0D 75 95 A1 85 D5 58 F2 E6 " + "69 B5 95 67 4F 52 17 C9 96 EE 14 88 84 82 8B E0 FD"; byte[] payload = Hex.decode(helloMessageRaw); - RLPList rlpList = new RLPList(); - RLP.parseObjects(payload, rlpList); + RLPList rlpList = RLP.decode2(payload); HelloMessage helloMessage = new HelloMessage(rlpList); helloMessage.parseRLP(); @@ -61,8 +60,7 @@ public class MessagesTest { String helloMessageRaw = "F87F800B80B5457468657265756D282B2B292F76302E342E332F4554485F4255494C445F545950452F4554485F4255494C445F504C4154464F524D0782765FB840E02B18FBA6B887FB9258469C3AF8E445CC9AE2B5386CAC5F60C4170F822086224E3876555C745A7EC8AC181C7F9701776D94A779604EA12651DE5F4A748D29E1"; byte[] payload = Hex.decode(helloMessageRaw); - RLPList rlpList = new RLPList(); - RLP.parseObjects(payload, rlpList); + RLPList rlpList = RLP.decode2(payload); HelloMessage helloMessage = new HelloMessage(rlpList); helloMessage.parseRLP(); @@ -85,8 +83,7 @@ public class MessagesTest { String disconnectMessageRaw = "C20100"; byte[] payload = Hex.decode(disconnectMessageRaw); - RLPList rlpList = new RLPList(); - RLP.parseObjects(payload, rlpList); + RLPList rlpList = RLP.decode2(payload); DisconnectMessage disconnectMessage = new DisconnectMessage(rlpList); System.out.println(disconnectMessage); @@ -99,8 +96,7 @@ public class MessagesTest { String disconnectMessageRaw = "C20101"; byte[] payload = Hex.decode(disconnectMessageRaw); - RLPList rlpList = new RLPList(); - RLP.parseObjects(payload, rlpList); + RLPList rlpList = RLP.decode2(payload); DisconnectMessage disconnectMessage = new DisconnectMessage(rlpList); System.out.println(disconnectMessage); @@ -115,8 +111,7 @@ public class MessagesTest { String peersMessageRaw = "F902BC11F84CC65381AC81E24F82765FB84033F506917503D16ECA1574F73D427BB6BC8725BED28542151E966C71FF5E9EE2EB0B09A8A6D7F6BC9E3F58F407F3DEDF174C4B6D6426973FB874E18F9ACB2BB6F84DC781C87681AB81BE82765FB840370A33EE6716C22E8AB13FF666C2389BDF0947F2FD8C15F3ABA5D545A0B78F7A8ABB95FD575073BE596D237038149A3B71E3A8F30B55AE70ED0189803FD62F24F84CC66A81A80E81F982765FB84052C1D33B5635C25504AD3985A79BEE3FF26CA5A17D351B8775E7ACEBAB1365624C9EE3CDFF843AFD07B235D8569196C781115E8DCAEF93E0383B20CFA64766D0F84AC455417E2D82765FB84082A8A5831D3B4FB76CF130CDC8A2B162A85D005D82A1DCC9B73239035EADE6347EDE2FFC86571ABE348EA38699CE886AA3D425FE58182C433434AB4CFD7B5B88F84CC6443081AD81A3827A51B840A5FD77C0D432FBFA3317084914C2E8A8821E4BA1DCBA44961FF7480E6DB608789CAB6291416360EA8CDC26B0D2F0877C50E89A70C1BCF5D6DD8B182E0A9E37D3F84AC436481F3782765FB840CE73660A06626C1B3FDA7B18EF7BA3CE17B6BF604F9541D3C6C654B7AE88B239407F659C78F419025D785727ED017B6ADD21952D7E12007373E321DBC31824BAF84AC455417E2D82765FB840CE73F1F1F1F16C1B3FDA7B18EF7BA3CE17B6F1F1F1F141D3C6C654B7AE88B239407FF1F1F1F119025D785727ED017B6ADD21F1F1F1F1000001E321DBC31824BAF84CC66B81AA3981F782765FB840E02B18FBA6B887FB9258469C3AF8E445CC9AE2B5386CAC5F60C4170F822086224E3876555C745A7EC8AC181C7F9701776D94A779604EA12651DE5F4A748D29E1F84EC881BF81B181D1819F82765FB840EFDFAE4BC66C2FBAAA70FEC4E764552256D3E15B143FA8F9EF278A5E042221BA0D4E8688DD4BA9582ABAC97D81B9418E50391204E9335E8E37CD16B7D95193A7"; byte[] payload = Hex.decode(peersMessageRaw); - RLPList rlpList = new RLPList(); - RLP.parseObjects(payload, rlpList); + RLPList rlpList = RLP.decode2(payload); PeersMessage peersMessage= new PeersMessage(rlpList); System.out.println(peersMessage); @@ -136,8 +131,7 @@ public class MessagesTest { String peersMessageRaw = "F9175011F84CC681836881FC0482765FB840077E537A8B3673E8F1B625DBCC902EA7D4CED9402E4664E873679512CC2360698E53425652A04624FCF78CDBA1A3233087A919A34D11AEDACEEEB7D833FCBF26F84CC66381E75881AF82765FB8400AB2CDE83A098403DDC2EA5414740D8A0193E449C96E112419967ABC62EB17CDCED77AE0AB075E04F7DDDCD43FB9048BE53206A040620BDE26CB743FA312319FF84BC545818F165582765FB84015D678DBB6C9F241133DD2F5EAC96B1B8308C556037D83F63A3729DDE4C3F84ED8491C7C645827DC54CE32AB8A759EE04EA079F2703F352BBA24ED6249B47CA5F84EC881BF81B181D1819F82765FB84019549FBE60B8A8D8188C9F1741325C92A5CE2226F23B40053FB68D90ED4DD551C891952ABDB9A894713EE9A7B037D06822F8EBC68F53326D9559BFE8277BE4E9F84DC781CF81DB45819A82765FB84019C33DA7031CFF177EFA842FAA3D31BD83E1764EC610F236944A9F8A21C1C51A04F47F6B5FC3EFE65CAF369443635AFC58D8F5D4E2F12AF9EEEC3C6E30BF0A2BF84CC6443081AD81A382765FB8401E59C282081294808497AE7A7E976798C42B8BCCE13C9D8B0ECF8AFECDB5DFD4EFA8770FC0D1F7DE63C91640E7E8B4358C9E3ED0F3D6C98620AD7EA42418C9ECF84BC51F12819E4882765FB8401F68C075C1D87BC04765430FDFB1E5D00F1B784ED6BE721E4CAFF7BEB57B4B217B95DA19B5EC66045868B39AAC2E0876CF80F0B68D0FA20BDB9036BEAA7061EAF84CC681BF81EA393782765FB84021780C55B47DB4B11467B5F55B0B555E0887CE36FBD975E224B1C70EAC7AB8E8C2DB37F0A48B90FFDD5A379ADA99B6A0F6429C4A53C25558191A682636AEF4F2F84CC6443081AD81A382765FB8402315CB7CF49B8EAB212C5A45790B50797739738F5F733439B190119737EE8C09BC723794712AA82F2670BC581AB0757EF23137AC0FDF0F8C8965E7DD6BA79F8CF84AC455417E2D82765FB8402A38EA5D9A7EFD7FFFC0A81D8EA7ED28311C4012BBAB1407C8DAD2685129E042172734A328E8907F9054B8225FE77041D8A486A97976D2837242AB6C8C5905E4F84CC681836881FC0482765FB840324DD936384D8C0DDEFDE04BA7402998ABBD63D79C0BF8586B3DD2C7DBF6C91EB80A7B6DE8F16A50044F149C7B39AAFB9C3AD7F2CAA40355AAB09888186FCCA2F84CC65381AC81E24F82765FB84033F506917503D16ECA1574F73D427BB6BC8725BED28542151E966C71FF5E9EE2EB0B09A8A6D7F6BC9E3F58F407F3DEDF174C4B6D6426973FB874E18F9ACB2BB6F84DC781C87681AB81BE82765FB840370A33EE6716C22E8AB13FF666C2389BDF0947F2FD8C15F3ABA5D545A0B78F7A8ABB95FD575073BE596D237038149A3B71E3A8F30B55AE70ED0189803FD62F24F84CC6443081AD81A382765FB840394245C0991633ED060BAFB9646853D344188B804FE37E25A5BCAC44ED443A84A68B3AAF155EFE4861E84B4B515F9A5DECDBD7DAE98192D7A320A792C7D4DFAFF84DC75681B781E781CD82765FB840398650F67B2292939DE34C0EAEB9141F9484A0FB173FA33F81A1F7315D0EB77BDE3A76C38636FAE66FA14BF2AFDFD63E60ABD40E29B02A914E65DE5789983FD4F84CC64481B981EA4082765FB8403A15587A1C3ADABF0291B307F71B2C04D198AAE36B834995D3305DFF42F1AB86F483AE129E9203FBC6EF2187C8621EDD18F61D53EAA5B587FFDEA4D926489038F84DC781CF81DB45819A82765FB8403B1462040EA778E3F75E65CE2453418A662E6212C9F65B02EAB58D22B287E45053BDE5EBF060960CBFA0D9DC85BF51BA7AA1F2CAA2C13682D93277641D60DBEBF84CC66A81A80E81F982765FB8403ECC97AB15D22F7B9EDF19C04CE3B6095FA2504214002B35989C6F81EE4B961CC2A899C49415C914E313908340047D1D3B25D74F5B9C85A06AFA2659A539992EF84BC52E0481C10982765FB840407C22003F3BBAA6CBEB8E4B0AB7073073FEAB85182B405525F8BD283255043D713518F74748D92C43FBB99ECC7C3FBAB95D598006513AA8E59C48041C8B41C2F84BC5327E5681C282765FB840408C9324203BD8262FCE6506BA59DCDD567089B0EB9A5BB183477BABBF6163914ACDC7F495F8964D8AC12FE2401887B8CD8D97C0C9DCCFADDBB20A3C3147A789F84AC4266C4F6882765FB840423E4004DA2FA7500BC012C0674AA6571502C53AA4D91EFA6E2B5CB1E468C462CA3114A2E2EB0965B7044F9C9575965B47E47A41F13F1ADC03A2A4B342D7128DF84BC54081E7082D82765FB84042839375272C2F3DEADB28085D06055E353135C6C8D896097A1BC480C4884FD1604518CBDF731AC18F0984B7F02148E88290D13C224D82464314E2B5962E3F89F84BC581CB22640282765FB84043BFC2EBC291825D9EC00C636330235DCEDF3A623F4F08E49BCC1504D8E9B165F0A0FE976C1881455BB3051C7B604F64AC45C117C275C636F1A36ABFB11544FBF84DC73281AA81D881C882765FB84044CF19446CA465018E4DE6C60FC0DF529EBA250292EF7441E1DB59841C69F022F6092810C9A5A7F274F2F97C4BD6C76EADC064C7D6597CAEB17ED87CB257735FF84BC532819C5A5382765FB840461C9B54E91953C5BBC31C6712A917382BE67D60F75EB7F50651BEA3E594D0D19C2229D8F66ADB3F203F600038E7CC934DC92787FAC4392B9BFA7CBC786FD05BF84BC58186647D2982765FB84048353A0058E26448D94E59336CCA9D28A9374120DEF76C4BCCFEE18B0123E59192393A2EE3044D80E0EECBB09476BE62FDE1E874F93D05EA5C4A9A45C06E8FE1F84BC54E080581BB82765FB84048E8950949D4C00BCDBBE939C5BF078F2CBFF10884AF1660B1C322B9CAA3BA357BB4157FC6B0039AF9438DFE51EC278A47FCD3B726FA0A087D4C3C01A62F335EF84AC6584581C681C607B8404A0255FA4673FAA30FC5ABFD3C550BFDBC0D3C973D35F726463AF81C54A03281CFFF22C5F5965B38AC630152987757A31782478549C36F7C84CB4436BA79D6D9F84BC54081E7082D82765FB8404C7547AB4D541E10164CD3741F3476ED194B0AB9A136DFCAC3943F97358C9B0514142736CA2F170F125229057B473244A6230BF5471AD168188524B2B5CD8B7BF84CC6443081AD81A382765FB8404D5E4875D60EB4EEAFB6B2A7D3936ED3C9BC58ACAADE6A7F3C5F25598C20B364F12BEA2FB1DB3B2C2EF64785A47D6B6B5B103427CBAC0C88B18FE92A9F5393F8F84BC5520C81E35482765FB8404FD898627574D3E86B3F5A65C3EDC2E5DA84535926E4A28820B0038B19636E07DB5EB004D791F8041A006E33E108E4EC535499D128D8D9C5CAF6BBDC2204F76AF84CC66A81A80E81F982765FB84052C1D33B5635C25504AD3985A79BEE3FF26CA5A17D351B8775E7ACEBAB1365624C9EE3CDFF843AFD07B235D8569196C781115E8DCAEF93E0383B20CFA64766D0F84BC581B4202B0882765FB84053CCF25AB59409ECBB903D2EC3A9AA2EB39D7CC4C7DB7E6F68FD711A7CEBC606216DE737826DA42093E3E6521EE4770EB2D669DC4BF3546CC757C34012696EAEF84AC44C67374782765FB840600A77FB14E792C0C70DC4ADE382ED604362B978B19B94C4ED188338A1795D2DB45F7F223B66BAEBA391C59B5588B44EBAF71C7EB39755C27229C7FDE641BECEF84BC545818F165582765FB840634C1D314F4D0AE98A0A57D406091FC055E023F8A02800E93273BA34928D063877B7D5E7301ACBBEDA7BD4A7DFA3C3DBC840BB443E8863A6C514B82F2273A2DDF84BC56D2B819A4282765FB84069DD445F67C3BEF394F9549FDAE1623DBC20884A62FD5616DDBB49F84BA87E147CB8A50BA971D730C4621D0EB65133494E94FA5EA2E69C661F6B12E7ED2A8D4EF84BC518093D819B82765FB8406B5D4C35FFD1F5A198038A90834D29A1B88BE0D5EFCA08BC8A2D5881180B0B416BE00629AABE450A50828B8D1EE82D98F5528187EE67ED6E073BCEEFCDFB2BC9F84AC455417E2D82765FB8406CBB1ED536DC3858C1F063429BD3952A5D32EF8E11526CDFE72F41FEA1ACE960187C9975ABBC23783511C00F2698354747F905AAAC11DCD2B7478B3EAF327AC6F84BC54081E7082D82765FB8406EA28F64EA1CC3B6572544FD5BF743B0EAABE017F514730C897DA3C77F03C516F1E5F31D793B4BCE3CAA1DED56356D20B2EBB55A7066F41C25B7C3D56614E06BF84AC455417E2D82765FB84072532408E8BE6D5E2C9F650FB9C9F99650CC1FA062A4A4F2CFE4E6AE69CDD2E8B23ED14AFE66955C23FA048F3A976E3CE8169E505B6A89CC53D4FAC20C2A11BFF84DC77481FB81DD81FB82765FB84077B92DC86BC2599EEF46CAF2E84338165AE58971256A92CF0B802B6B510D9F690D1C0DA48A74C1A7C5FFFF46A267F5E3AB501D6F5E81E32EFCBB4EA4EC103CF3F84CC65281D94881A982765FB8407AEEA43360B9368B30E7F48286613FD1E3B0207FB71F0308D50412114463E77AB83027C0D40CADAAB8BBF612FC5B6967FA1C407329D47EC61FB0DC3DA1086832F84CC681A68193534F82765FB8407B3CDDE058D5B45D8DB2243660CFEA02E074EC213114C251D7C0C32D0403BB7AB47713D2492FF6C881CFC2AAC3F52CB269768C8968F3B6B18BAC9722D05331F6F84CC681B43881A23C82765FB840817219171552FE8DCF019EDDB90187FB0DE6A471456809698AB5251E6F498D8DF15C34CF1D86F4320689E458483657F04FA651407AFDBB2B2A91D5FBFCAD4FD6F84AC455417E2D82765FB84082A8A5831D3B4FB76CF130CDC8A2B162A85D005D82A1DCC9B73239035EADE6347EDE2FFC86571ABE348EA38699CE886AA3D425FE58182C433434AB4CFD7B5B88F84CC66A81A80E81F982765FB84087AB581BB97C212A2DA7EF0D6E105E41B55E4E42CBB6A1AF9A761A01CA8C65069AB4B5827E322CF2C5F59E7F592BE2A817C45AB641F5A9DD368963C73F9EE688F84CC65281D94881A982765FB8408C660DBC6D3DB0186AD10F05FD4F2F0643778EC514E8452A7550C630DA21171A29B1BB67C2E8E101EA1DB39743F3E78C4D2676A13D15515121515FC38B048F37F84CC66381E75881AF82765FB84094FE3D52A2894CEDC6B15424156EB8738A8441DD74BA9CED6664ED30A332A95B574D89262EA367FA900AE9706FB81A408287BDDEF3A9DD9FF44E3A41BC090FDCF84CC64D81B781903782765FB840951FAFCB6F521F0AA23BC58AF19CC40D6795124D89DC8E0CAF23369B67726A1BF6A7B4EF59CD983059B6A67C15F409903C96577CEDDACD89C7423A103C134E08F84DC781D5818181E60A82765FB840952114F110E8AC00DFEA5F050D955E764C7CBA8FB207C05A7AA5AE849168640A2B4E314391FC3A76795B3827055462639CFF4AE2D64AB80E95274428313E366AF84CC6584581C681C682765FB84096F347B096ED1630F474B97623E45E8D471B1D43C22F599607C8B2E3ED0D7B7905D8554AD399DBD739C76126404424D8DB0DC7D2B047C1A328AE27D40906C583F84CC681836881FC0482765FB8409A22C8FB1BD8BBD02F0E74ED9D3D55B0F5B09672BC43A2D47B1ED04238C1C32B6A657426525B15518236E9789B546A4A072A605E1373FE5B996BAEDC30359428F84BC5520C81E35482765FB8409B1A3A8D771B3D949CA394A88EB5DC29A953B02C81F017361FFC0AFE09ABCE3069171A87D474523687FCC9A9D32CC02CFAB4132256FEAABFE05F7AC747194E88F84BC54281D7781C82765FB8409FA7E55B2D98F1D744C76232E4FDA242FE9FD3D5743D16D3CAD2E548A07CB5AF06FE60EBAEB8C6095028179234DCDDD3CDCF1FCFE6EDAA2A53307FD103DA4AF0F84AC455417E2D82765FB840A01F834E9D1A613C3C747E561CAC19CB12D879C1A57420A49C23652B8F51288C8B111AA3888998B05E327F47A235C6A4A377F888E3005A2D4B03ECB7268608D3F84CC6443081AD81A3827A51B840A5FD77C0D432FBFA3317084914C2E8A8821E4BA1DCBA44961FF7480E6DB608789CAB6291416360EA8CDC26B0D2F0877C50E89A70C1BCF5D6DD8B182E0A9E37D3F84DC7818881A081983182765FB840AE31BD0254EE7D10B80FC90E74BA06BA761187DF3138A9799DE5828D0163524C44BAC7D2A9B5C41BE5BE8289A172361F0BA90410C94F579BF7EBD28F18AAA1CDF84AC455417E2D82765FB840BA3D216772CDC74558D2545624A2D62DCBCFD272305730C74643C7A7E819AFA6CDD82223E2B5501EB6D4EAE5DBF21E558C768ACAEC2C1CA10E74C4C87A574B53F84AC455417E2D82765FB840BDB49C01872D91BD1EA990BD2EDF16C48171A6067F9A6F7F48BFB194630B5AE9031B5DC263F59C66ADA444CB4E6F9DF62B3017CE612CAB7B53DA08D356F78D30F84CC66381E75881AF82765FB840C12BA91F95044D78EED1D3A9535EBD6471524418135EEB46AD5D5C6ECC2F5168B4AB3A062BB0742AEA65FFEA767FAB8DCC21783CB29BF32E2CD6222209FA71FDF84CC6443081AD81A3827A51B840C2E269E64AA8C9BE2D41812A48AFA2346BD41A1AB2E4646241AE3B8D0CCD41F2D682B15A025F759C0D955A6071D4E8EA7D4DE397D6E052230920113B6EB74C09F84AC44A4F177782765FB840C303B83F6A161F996736344480AE9D88FDC1D9C675BFACA888F70F24897265628209DA53741E03C0F65921F68F602DC9F334A3C45BCB92AF8544A6FB119BD887F84BC50C81FA611A82765FB840C76E7C157B7735511153D1F95081A144E088A989171F3D432CC5D8293ECE9CFAA483C032155D7B53656A6E33A3D75CD0624E09A2F949C156093DBAA83F1111F2F84BC5520C81E35482765FB840C7D5A3691A59599DE333489CBF8A47A7433E92C72706E13D94ED211296D35C97D8357D7E07B3858564D7268ED7AA097F37589C27770F90DD0B07635BE3F53364F84CC64E09819281B282765FB840C88197A82B0ACF0A872494D1DFAC9DE846DAA7DE08B240647A96BA72FBE08FD52B55C6C94514A47EC51BA49A975489EBC9383B48F5E240939068CE5836FF24F1F84BC581B4202B0882765FB840C9E039D8A8B9E435BEF2F45FC7CB7E788716E8C7AFC1BACC64E1246D2AB506D36073792AE696E41AD6BA0C8ABD2EC0D545B0757F94A9F3538280E56DB5F5D8ECF84BC54E6881A35182765FB840CA27683702A8E9BF3201656FF84A60D5B1DD814273993CF1A025B054454E40D53092F48518EE05BEAD4F18021F4F540C0B7C7D26EBA50EA4890B9E5E49A76C5FF84AC436481F3782765FB840CE73660A06626C1B3FDA7B18EF7BA3CE17B6BF604F9541D3C6C654B7AE88B239407F659C78F419025D785727ED017B6ADD21952D7E12007373E321DBC31824BAF84AC455417E2D82765FB840CE73F1F1F1F16C1B3FDA7B18EF7BA3CE17B6F1F1F1F141D3C6C654B7AE88B239407FF1F1F1F119025D785727ED017B6ADD21F1F1F1F1000001E321DBC31824BAF84BC549310781F382765FB840D553D2596461568CC7365D53F92F387FD39F10C4A9AC388EBFA1F59761F2DF215669B1C4A255DCC33E271573A01CBD1E12F0DF40C3DDC609C59F3E9A6E346EE1F84CC66B81AA3981F782765FB840E02B18FBA6B887FB9258469C3AF8E445CC9AE2B5386CAC5F60C4170F822086224E3876555C745A7EC8AC181C7F9701776D94A779604EA12651DE5F4A748D29E1F84CC64081E70A81D082765FB840E31115A76FA7FB2EFD3CFAF46AD00B05FC3498E1BAF1785DFFE6CA69913D256531D180564235FD3D3C10409CD11FC259CF7CFDA9B6BB253340412D82878F3BD3F84BC5415E31819782765FB840E5E8D8C2D762D21CA1E9BCEE8ADC53600F2D894097542666D6B5F41B23584B07F60901AB409DDF91E0CD2562DAFFF2CB0F221EB9F1156F781A5D9931A02A2E07F84CC65D818681C24982765FB840ECF3D13E7843E1B2537B742FA689912F7CFFB5D75E2CDD6732AAD1A3088F06066B435C0FA6D95C82A948AE0A1A0067D11A15668F70974299FD0F52CCD87D67DDF84EC881BF81B181D1819F82765FB840EFDFAE4BC66C2FBAAA70FEC4E764552256D3E15B143FA8F9EF278A5E042221BA0D4E8688DD4BA9582ABAC97D81B9418E50391204E9335E8E37CD16B7D95193A7F84BC5567C5281FE82765FB840F6155F1A60143B7D9D5D1A440D7D52FE6809F69E0C6F1E0024457E0D71DD88ADE3B13AAA940C89AC0610952B48BD832C42E343A13E61FFDB06010CFFC345E053F84CC66381E75881AF82765FB840FA568561B7D5288DF7A506C9BC1C9512AB396E68C46F0E62C21DC1AA584B844A8A7E944F6971303665FD37B138D9A5F637E672EDB98969664C4E7FD1C4126DEF"; byte[] payload = Hex.decode(peersMessageRaw); - RLPList rlpList = new RLPList(); - RLP.parseObjects(payload, rlpList); + RLPList rlpList = RLP.decode2(payload); PeersMessage peersMessage= new PeersMessage(rlpList); System.out.println(peersMessage); @@ -168,8 +162,7 @@ public class MessagesTest { String peersPacketRaw = "F9152E11F84CC681836881FC0482765FB840077E537A8B3673E8F1B625DBCC902EA7D4CED9402E4664E873679512CC2360698E53425652A04624FCF78CDBA1A3233087A919A34D11AEDACEEEB7D833FCBF26F84CC66381E75881AF82765FB8400AB2CDE83A098403DDC2EA5414740D8A0193E449C96E112419967ABC62EB17CDCED77AE0AB075E04F7DDDCD43FB9048BE53206A040620BDE26CB743FA312319FF84BC545818F165582765FB84015D678DBB6C9F241133DD2F5EAC96B1B8308C556037D83F63A3729DDE4C3F84ED8491C7C645827DC54CE32AB8A759EE04EA079F2703F352BBA24ED6249B47CA5F84DC781CF81DB45819A82765FB84019C33DA7031CFF177EFA842FAA3D31BD83E1764EC610F236944A9F8A21C1C51A04F47F6B5FC3EFE65CAF369443635AFC58D8F5D4E2F12AF9EEEC3C6E30BF0A2BF84CC6443081AD81A382765FB8401E59C282081294808497AE7A7E976798C42B8BCCE13C9D8B0ECF8AFECDB5DFD4EFA8770FC0D1F7DE63C91640E7E8B4358C9E3ED0F3D6C98620AD7EA42418C9ECF84BC51F12819E4882765FB8401F68C075C1D87BC04765430FDFB1E5D00F1B784ED6BE721E4CAFF7BEB57B4B217B95DA19B5EC66045868B39AAC2E0876CF80F0B68D0FA20BDB9036BEAA7061EAF84CC681BF81EA393782765FB84021780C55B47DB4B11467B5F55B0B555E0887CE36FBD975E224B1C70EAC7AB8E8C2DB37F0A48B90FFDD5A379ADA99B6A0F6429C4A53C25558191A682636AEF4F2F84CC6443081AD81A382765FB8402315CB7CF49B8EAB212C5A45790B50797739738F5F733439B190119737EE8C09BC723794712AA82F2670BC581AB0757EF23137AC0FDF0F8C8965E7DD6BA79F8CF84EC881BF81B181D1819F82765FB840249A3641E5A8D08E41A5CFC8DAE11F1761254F4FD47D9B13338DB8E6E3729E6F2AC9EC097A5C809684D62A41E6DFC2FFF72DC3DBD97EA26132BB97640565BB0CF84AC455417E2D82765FB8402A38EA5D9A7EFD7FFFC0A81D8EA7ED28311C4012BBAB1407C8DAD2685129E042172734A328E8907F9054B8225FE77041D8A486A97976D2837242AB6C8C5905E4F84CC66A81A80E81F982765FB8402CB30D5314ECE47E5B43DBD27A12CAD9A55CF57DD6EFB467151FEE95B9217B8BE2AB6214E07EFD9535660AE9C4FB932D2947ED6EDCD54F11081BA0FF7F30CE42F84CC681836881FC0482765FB840324DD936384D8C0DDEFDE04BA7402998ABBD63D79C0BF8586B3DD2C7DBF6C91EB80A7B6DE8F16A50044F149C7B39AAFB9C3AD7F2CAA40355AAB09888186FCCA2F84CC6443081AD81A382765FB840394245C0991633ED060BAFB9646853D344188B804FE37E25A5BCAC44ED443A84A68B3AAF155EFE4861E84B4B515F9A5DECDBD7DAE98192D7A320A792C7D4DFAFF84DC75681B781E781CD82765FB840398650F67B2292939DE34C0EAEB9141F9484A0FB173FA33F81A1F7315D0EB77BDE3A76C38636FAE66FA14BF2AFDFD63E60ABD40E29B02A914E65DE5789983FD4F84CC64481B981EA4082765FB8403A15587A1C3ADABF0291B307F71B2C04D198AAE36B834995D3305DFF42F1AB86F483AE129E9203FBC6EF2187C8621EDD18F61D53EAA5B587FFDEA4D926489038F84DC781CF81DB45819A82765FB8403B1462040EA778E3F75E65CE2453418A662E6212C9F65B02EAB58D22B287E45053BDE5EBF060960CBFA0D9DC85BF51BA7AA1F2CAA2C13682D93277641D60DBEBF84CC66A81A80E81F982765FB8403ECC97AB15D22F7B9EDF19C04CE3B6095FA2504214002B35989C6F81EE4B961CC2A899C49415C914E313908340047D1D3B25D74F5B9C85A06AFA2659A539992EF84BC52E0481C10982765FB840407C22003F3BBAA6CBEB8E4B0AB7073073FEAB85182B405525F8BD283255043D713518F74748D92C43FBB99ECC7C3FBAB95D598006513AA8E59C48041C8B41C2F84BC5327E5681C282765FB840408C9324203BD8262FCE6506BA59DCDD567089B0EB9A5BB183477BABBF6163914ACDC7F495F8964D8AC12FE2401887B8CD8D97C0C9DCCFADDBB20A3C3147A789F84AC4266C4F6882765FB840423E4004DA2FA7500BC012C0674AA6571502C53AA4D91EFA6E2B5CB1E468C462CA3114A2E2EB0965B7044F9C9575965B47E47A41F13F1ADC03A2A4B342D7128DF84BC54081E7082D82765FB84042839375272C2F3DEADB28085D06055E353135C6C8D896097A1BC480C4884FD1604518CBDF731AC18F0984B7F02148E88290D13C224D82464314E2B5962E3F89F84DC73281AA81D881C882765FB84044CF19446CA465018E4DE6C60FC0DF529EBA250292EF7441E1DB59841C69F022F6092810C9A5A7F274F2F97C4BD6C76EADC064C7D6597CAEB17ED87CB257735FF84BC532819C5A5382765FB840461C9B54E91953C5BBC31C6712A917382BE67D60F75EB7F50651BEA3E594D0D19C2229D8F66ADB3F203F600038E7CC934DC92787FAC4392B9BFA7CBC786FD05BF84BC58186647D2982765FB84048353A0058E26448D94E59336CCA9D28A9374120DEF76C4BCCFEE18B0123E59192393A2EE3044D80E0EECBB09476BE62FDE1E874F93D05EA5C4A9A45C06E8FE1F84BC54E080581BB82765FB84048E8950949D4C00BCDBBE939C5BF078F2CBFF10884AF1660B1C322B9CAA3BA357BB4157FC6B0039AF9438DFE51EC278A47FCD3B726FA0A087D4C3C01A62F335EF84AC6584581C681C607B8404A0255FA4673FAA30FC5ABFD3C550BFDBC0D3C973D35F726463AF81C54A03281CFFF22C5F5965B38AC630152987757A31782478549C36F7C84CB4436BA79D6D9F84BC54081E7082D82765FB8404C7547AB4D541E10164CD3741F3476ED194B0AB9A136DFCAC3943F97358C9B0514142736CA2F170F125229057B473244A6230BF5471AD168188524B2B5CD8B7BF84CC6443081AD81A382765FB8404D5E4875D60EB4EEAFB6B2A7D3936ED3C9BC58ACAADE6A7F3C5F25598C20B364F12BEA2FB1DB3B2C2EF64785A47D6B6B5B103427CBAC0C88B18FE92A9F5393F8F84BC5520C81E35482765FB8404FD898627574D3E86B3F5A65C3EDC2E5DA84535926E4A28820B0038B19636E07DB5EB004D791F8041A006E33E108E4EC535499D128D8D9C5CAF6BBDC2204F76AF84BC581B4202B0882765FB84053CCF25AB59409ECBB903D2EC3A9AA2EB39D7CC4C7DB7E6F68FD711A7CEBC606216DE737826DA42093E3E6521EE4770EB2D669DC4BF3546CC757C34012696EAEF84AC44C67374782765FB840600A77FB14E792C0C70DC4ADE382ED604362B978B19B94C4ED188338A1795D2DB45F7F223B66BAEBA391C59B5588B44EBAF71C7EB39755C27229C7FDE641BECEF84BC56D2B819A4282765FB84069DD445F67C3BEF394F9549FDAE1623DBC20884A62FD5616DDBB49F84BA87E147CB8A50BA971D730C4621D0EB65133494E94FA5EA2E69C661F6B12E7ED2A8D4EF84BC518093D819B82765FB8406B5D4C35FFD1F5A198038A90834D29A1B88BE0D5EFCA08BC8A2D5881180B0B416BE00629AABE450A50828B8D1EE82D98F5528187EE67ED6E073BCEEFCDFB2BC9F84AC455417E2D82765FB8406CBB1ED536DC3858C1F063429BD3952A5D32EF8E11526CDFE72F41FEA1ACE960187C9975ABBC23783511C00F2698354747F905AAAC11DCD2B7478B3EAF327AC6F84BC54081E7082D82765FB8406EA28F64EA1CC3B6572544FD5BF743B0EAABE017F514730C897DA3C77F03C516F1E5F31D793B4BCE3CAA1DED56356D20B2EBB55A7066F41C25B7C3D56614E06BF84AC455417E2D82765FB84072532408E8BE6D5E2C9F650FB9C9F99650CC1FA062A4A4F2CFE4E6AE69CDD2E8B23ED14AFE66955C23FA048F3A976E3CE8169E505B6A89CC53D4FAC20C2A11BFF84CC65281D94881A982765FB8407AEEA43360B9368B30E7F48286613FD1E3B0207FB71F0308D50412114463E77AB83027C0D40CADAAB8BBF612FC5B6967FA1C407329D47EC61FB0DC3DA1086832F84CC681A68193534F82765FB8407B3CDDE058D5B45D8DB2243660CFEA02E074EC213114C251D7C0C32D0403BB7AB47713D2492FF6C881CFC2AAC3F52CB269768C8968F3B6B18BAC9722D05331F6F84CC66A81A80E81F982765FB84087AB581BB97C212A2DA7EF0D6E105E41B55E4E42CBB6A1AF9A761A01CA8C65069AB4B5827E322CF2C5F59E7F592BE2A817C45AB641F5A9DD368963C73F9EE688F84CC65281D94881A982765FB8408C660DBC6D3DB0186AD10F05FD4F2F0643778EC514E8452A7550C630DA21171A29B1BB67C2E8E101EA1DB39743F3E78C4D2676A13D15515121515FC38B048F37F84CC66381E75881AF82765FB84094FE3D52A2894CEDC6B15424156EB8738A8441DD74BA9CED6664ED30A332A95B574D89262EA367FA900AE9706FB81A408287BDDEF3A9DD9FF44E3A41BC090FDCF84CC64D81B781903782765FB840951FAFCB6F521F0AA23BC58AF19CC40D6795124D89DC8E0CAF23369B67726A1BF6A7B4EF59CD983059B6A67C15F409903C96577CEDDACD89C7423A103C134E08F84DC781D5818181E60A82765FB840952114F110E8AC00DFEA5F050D955E764C7CBA8FB207C05A7AA5AE849168640A2B4E314391FC3A76795B3827055462639CFF4AE2D64AB80E95274428313E366AF84CC6584581C681C682765FB84096F347B096ED1630F474B97623E45E8D471B1D43C22F599607C8B2E3ED0D7B7905D8554AD399DBD739C76126404424D8DB0DC7D2B047C1A328AE27D40906C583F84CC681836881FC0482765FB8409A22C8FB1BD8BBD02F0E74ED9D3D55B0F5B09672BC43A2D47B1ED04238C1C32B6A657426525B15518236E9789B546A4A072A605E1373FE5B996BAEDC30359428F84BC5520C81E35482765FB8409B1A3A8D771B3D949CA394A88EB5DC29A953B02C81F017361FFC0AFE09ABCE3069171A87D474523687FCC9A9D32CC02CFAB4132256FEAABFE05F7AC747194E88F84BC54281D7781C82765FB8409FA7E55B2D98F1D744C76232E4FDA242FE9FD3D5743D16D3CAD2E548A07CB5AF06FE60EBAEB8C6095028179234DCDDD3CDCF1FCFE6EDAA2A53307FD103DA4AF0F84AC455417E2D82765FB840A01F834E9D1A613C3C747E561CAC19CB12D879C1A57420A49C23652B8F51288C8B111AA3888998B05E327F47A235C6A4A377F888E3005A2D4B03ECB7268608D3F84CC6443081AD81A3827A51B840A5FD77C0D432FBFA3317084914C2E8A8821E4BA1DCBA44961FF7480E6DB608789CAB6291416360EA8CDC26B0D2F0877C50E89A70C1BCF5D6DD8B182E0A9E37D3F84DC7818881A081983182765FB840AE31BD0254EE7D10B80FC90E74BA06BA761187DF3138A9799DE5828D0163524C44BAC7D2A9B5C41BE5BE8289A172361F0BA90410C94F579BF7EBD28F18AAA1CDF84CC681D95B81FC3D82765FB840B1D3B2BB241F3297CC1003E5907DD187B9FF3147F816B068D257222629F5AB9EF2AEAF7965F366AF72A299131D23F7A1ECD4A098D7D37D6F52F3A8C0037C52E0F84AC455417E2D82765FB840BA3D216772CDC74558D2545624A2D62DCBCFD272305730C74643C7A7E819AFA6CDD82223E2B5501EB6D4EAE5DBF21E558C768ACAEC2C1CA10E74C4C87A574B53F84AC455417E2D82765FB840BDB49C01872D91BD1EA990BD2EDF16C48171A6067F9A6F7F48BFB194630B5AE9031B5DC263F59C66ADA444CB4E6F9DF62B3017CE612CAB7B53DA08D356F78D30F84CC66381E75881AF82765FB840C12BA91F95044D78EED1D3A9535EBD6471524418135EEB46AD5D5C6ECC2F5168B4AB3A062BB0742AEA65FFEA767FAB8DCC21783CB29BF32E2CD6222209FA71FDF84CC6443081AD81A3827A51B840C2E269E64AA8C9BE2D41812A48AFA2346BD41A1AB2E4646241AE3B8D0CCD41F2D682B15A025F759C0D955A6071D4E8EA7D4DE397D6E052230920113B6EB74C09F84AC44A4F177782765FB840C303B83F6A161F996736344480AE9D88FDC1D9C675BFACA888F70F24897265628209DA53741E03C0F65921F68F602DC9F334A3C45BCB92AF8544A6FB119BD887F84BC50C81FA611A82765FB840C76E7C157B7735511153D1F95081A144E088A989171F3D432CC5D8293ECE9CFAA483C032155D7B53656A6E33A3D75CD0624E09A2F949C156093DBAA83F1111F2F84BC5520C81E35482765FB840C7D5A3691A59599DE333489CBF8A47A7433E92C72706E13D94ED211296D35C97D8357D7E07B3858564D7268ED7AA097F37589C27770F90DD0B07635BE3F53364F84CC64E09819281B282765FB840C88197A82B0ACF0A872494D1DFAC9DE846DAA7DE08B240647A96BA72FBE08FD52B55C6C94514A47EC51BA49A975489EBC9383B48F5E240939068CE5836FF24F1F84BC581B4202B0882765FB840C9E039D8A8B9E435BEF2F45FC7CB7E788716E8C7AFC1BACC64E1246D2AB506D36073792AE696E41AD6BA0C8ABD2EC0D545B0757F94A9F3538280E56DB5F5D8ECF84BC54E6881A35182765FB840CA27683702A8E9BF3201656FF84A60D5B1DD814273993CF1A025B054454E40D53092F48518EE05BEAD4F18021F4F540C0B7C7D26EBA50EA4890B9E5E49A76C5FF84CC681BF81EA393782765FB840CB78D224C1F5F1319EE9FD058050D24F40234570EAA5941046C7F967D8ADD06484776EB60C3BB11ED9E3562D259B9941585FDAD2D5F236564B8253A565483F89F84BC55C4B81D24C82765FB840CD9699760740E99DB8ED79311B80AFDACD6AA937AB1816B42BD3F465814152F3D9973DF578BE4D8C77FBB19416BDE414140AF3289356512F1BFEB54DD2679A94F84AC436481F3782765FB840CE73660A06626C1B3FDA7B18EF7BA3CE17B6BF604F9541D3C6C654B7AE88B239407F659C78F419025D785727ED017B6ADD21952D7E12007373E321DBC31824BAF84AC455417E2D82765FB840CE73F1F1F1F16C1B3FDA7B18EF7BA3CE17B6F1F1F1F141D3C6C654B7AE88B239407FF1F1F1F119025D785727ED017B6ADD21F1F1F1F1000001E321DBC31824BAF84CC66B81AA3981F782765FB840E02B18FBA6B887FB9258469C3AF8E445CC9AE2B5386CAC5F60C4170F822086224E3876555C745A7EC8AC181C7F9701776D94A779604EA12651DE5F4A748D29E1F84CC64081E70A81D082765FB840E31115A76FA7FB2EFD3CFAF46AD00B05FC3498E1BAF1785DFFE6CA69913D256531D180564235FD3D3C10409CD11FC259CF7CFDA9B6BB253340412D82878F3BD3F84BC5415E31819782765FB840E5E8D8C2D762D21CA1E9BCEE8ADC53600F2D894097542666D6B5F41B23584B07F60901AB409DDF91E0CD2562DAFFF2CB0F221EB9F1156F781A5D9931A02A2E07F84BC5567C5281FE82765FB840F6155F1A60143B7D9D5D1A440D7D52FE6809F69E0C6F1E0024457E0D71DD88ADE3B13AAA940C89AC0610952B48BD832C42E343A13E61FFDB06010CFFC345E053F84CC66381E75881AF82765FB840FA568561B7D5288DF7A506C9BC1C9512AB396E68C46F0E62C21DC1AA584B844A8A7E944F6971303665FD37B138D9A5F637E672EDB98969664C4E7FD1C4126DEF"; byte[] payload = Hex.decode(peersPacketRaw); - RLPList rlpList = new RLPList(); - RLP.parseObjects(payload, rlpList); + RLPList rlpList = RLP.decode2(payload); PeersMessage peersMessage = new PeersMessage(rlpList); peersMessage.parseRLP(); @@ -187,8 +180,7 @@ public class MessagesTest { String transactionsPacketRaw = "F86E12F86B04881BC16D674EC8000094CD2A3D9F938E13CD947EC05ABC7FE734DF8DD8268609184E72A00064801BA05E3868194605F1647593B842725818CCFA6A38651A728715133A8E97CDCFAC54A00FF91628D04B215EBCCFD5F4FC34CC1B45DF32F6B4609FBB0DE42E8522264467"; byte[] payload = Hex.decode(transactionsPacketRaw); - RLPList rlpList = new RLPList(); - RLP.parseObjects(payload, rlpList); + RLPList rlpList = RLP.decode2(payload); TransactionsMessage transactionsMessage = new TransactionsMessage(rlpList); System.out.println(transactionsMessage); @@ -238,8 +230,7 @@ public class MessagesTest { String transactionsPacketRaw = "F9025012F89D80809400000000000000000000000000000000000000008609184E72A000822710B3606956330C0D630000003359366000530A0D630000003359602060005301356000533557604060005301600054630000000C5884336069571CA07F6EB94576346488C6253197BDE6A7E59DDC36F2773672C849402AA9C402C3C4A06D254E662BF7450DD8D835160CBB053463FED0B53F2CDD7F3EA8731919C8E8CCF9010501809400000000000000000000000000000000000000008609184E72A000822710B85336630000002E59606956330C0D63000000155933FF33560D63000000275960003356576000335700630000005358600035560D630000003A590033560D63000000485960003356573360003557600035335700B84A7F4E616D65526567000000000000000000000000000000000000000000000000003057307F4E616D655265670000000000000000000000000000000000000000000000000057336069571BA04AF15A0EC494AEAC5B243C8A2690833FAA74C0F73DB1F439D521C49C381513E9A05802E64939BE5A1F9D4D614038FBD5479538C48795614EF9C551477ECBDB49D2F8A6028094CCDEAC59D35627B7DE09332E819D5159E7BB72508609184E72A000822710B84000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002D0ACEEE7E5AB874E22CCF8D1A649F59106D74E81BA0D05887574456C6DE8F7A0D172342C2CBDD4CF7AFE15D9DBB8B75B748BA6791C9A01E87172A861F6C37B5A9E3A5D0D7393152A7FBE41530E5BB8AC8F35433E5931B"; byte[] payload = Hex.decode(transactionsPacketRaw); - RLPList rlpList = new RLPList(); - RLP.parseObjects(payload, rlpList); + RLPList rlpList = RLP.decode2(payload); TransactionsMessage transactionsMessage = new TransactionsMessage(rlpList); System.out.println(transactionsMessage); @@ -327,8 +318,7 @@ public class MessagesTest { String blocksRaw = "F8CC13F8C9F8C5A0372D8E5C6E32335FB86FA7A6AE1B35165745346E1C786EACD42DF85F8DA12B3DA01DCC4DE8DEC75D7AAB85B567B6CCD41AD312451B948A7413F0A142FD40D49347941A4D98707BA8DD3D36D16E8C165C272645695CEAA05E2D2CC0B42B38B5B18C9D65734F9877C035DD390B9C12C48624F2243668A268A01DCC4DE8DEC75D7AAB85B567B6CCD41AD312451B948A7413F0A142FD40D493478402471A26845357C1FC80A00000000000000000000000000000000000000000000000006F4CD02DA011A235C0C0"; byte[] payload = Hex.decode(blocksRaw); - RLPList rlpList = new RLPList(); - RLP.parseObjects(payload, rlpList); + RLPList rlpList = RLP.decode2(payload); BlocksMessage blocksMessage = new BlocksMessage(rlpList); List list = blocksMessage.getBlockDataList(); @@ -371,8 +361,7 @@ public class MessagesTest { String blocksRaw = "F91C1C13F90150F8C4A07DF3D35D4DF0A56FCF1D6344D5315CB56B9BF83BB96AD17C7B96A9CD14133C5DA01DCC4DE8DEC75D7AAB85B567B6CCD41AD312451B948A7413F0A142FD40D49347943854AAF203BA5F8D49B1EC221329C7AEBCF050D3A064AFB6284FA35F26D7B2C5A26AFAA5483072FBCB575221B34CE002A991B7A223A04A8ABE6D802797DC80B497584F898C2D4FD561CC185828CFA1B92F6F38EE348E833FBFE484533F201C80A000000000000000000000000000000000000000000000000000CFCCB5CFD4667CF887F8850380942D0ACEEE7E5AB874E22CCF8D1A649F59106D74E88609184E72A000822710A047617600000000000000000000000000000000000000000000000000000000001CA08691AB40E258DE3C4F55C868C0C34E780E747158A1D96CA50186DFD3305ABD78A042269C981D048A7B791AAFC8F4E644232740C1A1CCEB5B6D05568827A64C0664C0F8C8F8C4A0637C8A6CDB907FAC6F752334AB79065BCC4E46CD4F4358DBC2A653544A20EB31A01DCC4DE8DEC75D7AAB85B567B6CCD41AD312451B948A7413F0A142FD40D49347943854AAF203BA5F8D49B1EC221329C7AEBCF050D3A022A36C1A1E807E6AFC22E6BB53A31111F56E7EE7DBB2EE571CEFB152B514DB4DA01DCC4DE8DEC75D7AAB85B567B6CCD41AD312451B948A7413F0A142FD40D49347833FCFD784533F1CF980A0000000000000000000000000000000000000000000000000E153D743FA040B18C0C0F8C8F8C4A07B2536237CBF114A043B0F9B27C76F84AC160EA5B87B53E42C7E76148964D450A01DCC4DE8DEC75D7AAB85B567B6CCD41AD312451B948A7413F0A142FD40D49347943854AAF203BA5F8D49B1EC221329C7AEBCF050D3A07A3BE0EE10ECE4B03097BF74AABAC628AA0FAE617377D30AB1B97376EE31F41AA01DCC4DE8DEC75D7AAB85B567B6CCD41AD312451B948A7413F0A142FD40D49347833FBFE884533F1CE880A0000000000000000000000000000000000000000000000000F3DEEA84969B6E95C0C0F8C8F8C4A0D2AE3F5DD931926DE428D99611980E7CDD7C1B838273E43FCAD1B94DA987CFB8A01DCC4DE8DEC75D7AAB85B567B6CCD41AD312451B948A7413F0A142FD40D49347943854AAF203BA5F8D49B1EC221329C7AEBCF050D3A00B5B11FCF4EE12C6812F9D01CF0DFF07C72CD7E02E48B35682F67C595407BE14A01DCC4DE8DEC75D7AAB85B567B6CCD41AD312451B948A7413F0A142FD40D49347833FAFFD84533F1CE280A00000000000000000000000000000000000000000000000005FCBC97B2EB8FFB3C0C0F8C8F8C4A094D615D3CB4B306D20985028C78F0C8413D509A75E8BB84EDA95F734DEBAD2A0A01DCC4DE8DEC75D7AAB85B567B6CCD41AD312451B948A7413F0A142FD40D49347943854AAF203BA5F8D49B1EC221329C7AEBCF050D3A04B8FD1B98CF5758BD303FF86393EB6D944C1058124BDDCE5D4E04B5395254D5EA01DCC4DE8DEC75D7AAB85B567B6CCD41AD312451B948A7413F0A142FD40D49347833FBFEC84533F1C7680A000000000000000000000000000000000000000000000000079FE3710116B32AAC0C0F8C8F8C4A09424A07A0E4C05BB872906C40844A75B76F6517467B79C12FA9CC6D79AE09934A01DCC4DE8DEC75D7AAB85B567B6CCD41AD312451B948A7413F0A142FD40D49347943854AAF203BA5F8D49B1EC221329C7AEBCF050D3A02DBE9FF9CBBC4C5A6FF26971F75B405891141F4E9BCE3C2DC4200A305138E584A01DCC4DE8DEC75D7AAB85B567B6CCD41AD312451B948A7413F0A142FD40D49347833FCFDF84533F1C3B80A0000000000000000000000000000000000000000000000000E0A6F8CF1D56031BC0C0F8C8F8C4A009AABEA60CF7EAA9DF4AFDF4E1B5F3E684DAB34FC9A9180A050085A4131CEEDFA01DCC4DE8DEC75D7AAB85B567B6CCD41AD312451B948A7413F0A142FD40D49347943854AAF203BA5F8D49B1EC221329C7AEBCF050D3A0436DA067F9683029E717EDF92DA46C3443E8C342974F47A563302A0678EFE702A01DCC4DE8DEC75D7AAB85B567B6CCD41AD312451B948A7413F0A142FD40D49347833FDFD684533F1BFC80A00000000000000000000000000000000000000000000000005BC88C041662FFDAC0C0F8C8F8C4A0F8B104093483B7C0182E1BBA2CE3340D14469D3A3EE7646821223A676C680AC1A01DCC4DE8DEC75D7AAB85B567B6CCD41AD312451B948A7413F0A142FD40D49347943854AAF203BA5F8D49B1EC221329C7AEBCF050D3A0D482E71CDE61190A33CA5AEB88B6B06276984E5A14253A98DF232E8767167221A01DCC4DE8DEC75D7AAB85B567B6CCD41AD312451B948A7413F0A142FD40D49347833FEFD184533F1BCE80A00000000000000000000000000000000000000000000000004AEB31823F6A1950C0C0F8C8F8C4A0DD1F0ABA02C2BB3B5A2B6CB1CC907EA70912BD46DC7A78577F2CAE6CDBCBE5F3A01DCC4DE8DEC75D7AAB85B567B6CCD41AD312451B948A7413F0A142FD40D49347943854AAF203BA5F8D49B1EC221329C7AEBCF050D3A058AB6DF33D7CBEB6A735A7E4CCF4F28143E6A1742E45DDA8F8CF48AF43CB66C0A01DCC4DE8DEC75D7AAB85B567B6CCD41AD312451B948A7413F0A142FD40D49347833FFFD084533F1B9F80A0000000000000000000000000000000000000000000000000577042B0858B510BC0C0F8C8F8C4A0A287BB7DA30F04344976ABE569BD719F69C1CBEA65533E5311CA5862E6EAA504A01DCC4DE8DEC75D7AAB85B567B6CCD41AD312451B948A7413F0A142FD40D49347943854AAF203BA5F8D49B1EC221329C7AEBCF050D3A07E0537009C23CB1152CAF84A52272431F74B6140866B15805622B7BCB607CD42A01DCC4DE8DEC75D7AAB85B567B6CCD41AD312451B948A7413F0A142FD40D4934783400FD384533F1B6180A000000000000000000000000000000000000000000000000083D31378A0993E1AC0C0F8C8F8C4A063483CFF8FBD489E6CE273326D8DC1D54A31C67F936CA84BF500E5419D3E9805A01DCC4DE8DEC75D7AAB85B567B6CCD41AD312451B948A7413F0A142FD40D49347943854AAF203BA5F8D49B1EC221329C7AEBCF050D3A07737D08564819D51F8F834A6EE4278C23A0C2F29A3F485B21002C1F24F04D8E4A01DCC4DE8DEC75D7AAB85B567B6CCD41AD312451B948A7413F0A142FD40D49347833FFFD484533F1B5780A0000000000000000000000000000000000000000000000000BB586FE6DE016E14C0C0F8C8F8C4A0975C8ED0C9197B7C018E02E1C95F315ACF82B25E4A812140F4515E8BC827650CA01DCC4DE8DEC75D7AAB85B567B6CCD41AD312451B948A7413F0A142FD40D49347943854AAF203BA5F8D49B1EC221329C7AEBCF050D3A0AD51229ABEAD59E93C80DB5BA160F0939BC49DCEE65D1C081F6EB040FF1F571FA01DCC4DE8DEC75D7AAB85B567B6CCD41AD312451B948A7413F0A142FD40D49347833FEFD984533F1B4E80A0000000000000000000000000000000000000000000000000548F02C6CEB26FD4C0C0F8C8F8C4A05844082E41F7C1F34485C7902AFA0AA0979A6A849100FC553CD946F4A663929CA01DCC4DE8DEC75D7AAB85B567B6CCD41AD312451B948A7413F0A142FD40D49347943854AAF203BA5F8D49B1EC221329C7AEBCF050D3A01BC726443437C4C062BE18D052278E4EF735B8FE84387C8A4FC85FB70D5078E0A01DCC4DE8DEC75D7AAB85B567B6CCD41AD312451B948A7413F0A142FD40D49347833FFFD884533F1B1080A0000000000000000000000000000000000000000000000000CC1E528F54F22BDAC0C0F8C8F8C4A0BA06BA81C93FAAF98EA2D83CBDC0788958D938B29A9EB2A92FFBD4A628B3D52EA01DCC4DE8DEC75D7AAB85B567B6CCD41AD312451B948A7413F0A142FD40D49347943854AAF203BA5F8D49B1EC221329C7AEBCF050D3A05053BFE1C0F1F0DD341C6DF35E5A659989BE041E8521027CC90F7605EB15FBB9A01DCC4DE8DEC75D7AAB85B567B6CCD41AD312451B948A7413F0A142FD40D49347833FEFDD84533F1B0380A0000000000000000000000000000000000000000000000000BCF9DF2FEC615ECAC0C0F8C8F8C4A083732D997DB15109E90464C24B7C959A78881D827C55A0D668A66A2736BE5D87A01DCC4DE8DEC75D7AAB85B567B6CCD41AD312451B948A7413F0A142FD40D49347943854AAF203BA5F8D49B1EC221329C7AEBCF050D3A054F4012CBA33A2B80B0DCA9DD52F56B2C588133BD71700863F8CB95127176634A01DCC4DE8DEC75D7AAB85B567B6CCD41AD312451B948A7413F0A142FD40D49347833FFFDC84533F1A4680A00000000000000000000000000000000000000000000000006920A1DC9D915D0EC0C0F8C8F8C4A052E2FBA761C2D0643170EF041C017391E781190FE715AE87CDAE8EEE1D45D95BA01DCC4DE8DEC75D7AAB85B567B6CCD41AD312451B948A7413F0A142FD40D49347943854AAF203BA5F8D49B1EC221329C7AEBCF050D3A0EE2C82F77D7AFD1F8DBE4F791DF8477496C23E5504B9D66814172077F65F81F2A01DCC4DE8DEC75D7AAB85B567B6CCD41AD312451B948A7413F0A142FD40D49347833FEFE184533F1A3880A0000000000000000000000000000000000000000000000000AE86DA9012398FC4C0C0F8C8F8C4A055703BA09544F386966B6D63BFC31033B761A4D1A6BB86B0CF49B4BB0526744EA01DCC4DE8DEC75D7AAB85B567B6CCD41AD312451B948A7413F0A142FD40D49347943854AAF203BA5F8D49B1EC221329C7AEBCF050D3A01684C03A675B53786F0077D1651C3D169A009B13A6EE2B5047BE6DBBE6D957FFA01DCC4DE8DEC75D7AAB85B567B6CCD41AD312451B948A7413F0A142FD40D49347833FDFEA84533F1A2F80A00000000000000000000000000000000000000000000000003247320D0EB639DFC0C0F8C8F8C4A05109A79B33D81F4EE4814B550FB0002F03368D67570F6D4E6105FCE2874D8B72A01DCC4DE8DEC75D7AAB85B567B6CCD41AD312451B948A7413F0A142FD40D49347943854AAF203BA5F8D49B1EC221329C7AEBCF050D3A0AE72E8C60A3DCFD53DEECDB2790D18F0CC710F77CF2C1ED76E7DA829BDE619DCA01DCC4DE8DEC75D7AAB85B567B6CCD41AD312451B948A7413F0A142FD40D49347833FCFF784533F1A1D80A000000000000000000000000000000000000000000000000040E0BC9BC9BCF295C0C0F8C8F8C4A03961E4BBBA5C95FAD3DB0CFFA3A16B9106F9EA3E8957993EAB576B683C22F416A01DCC4DE8DEC75D7AAB85B567B6CCD41AD312451B948A7413F0A142FD40D49347943854AAF203BA5F8D49B1EC221329C7AEBCF050D3A0E9C6CF457BBE64D6BDA67852A276CDBADB4F384A36D496E81801A496CFD9B7B5A01DCC4DE8DEC75D7AAB85B567B6CCD41AD312451B948A7413F0A142FD40D49347833FDFEE84533F19DF80A0000000000000000000000000000000000000000000000000DBB3FD6C816776D8C0C0F8C8F8C4A06B8265A357CB3AD744E19F04EB15377F660C10C900CC352D24F9B09073A363D6A01DCC4DE8DEC75D7AAB85B567B6CCD41AD312451B948A7413F0A142FD40D49347943854AAF203BA5F8D49B1EC221329C7AEBCF050D3A07BA07E1BC6A20FFA44AE6080D30982B9FAA148FAF6B1EC15E32D89AC853AC291A01DCC4DE8DEC75D7AAB85B567B6CCD41AD312451B948A7413F0A142FD40D49347833FEFE984533F198D80A00000000000000000000000000000000000000000000000005171325B6A2F17F1C0C0F8C8F8C4A0DCDC0347BB87CE72D49AC2E4E11F89069509B129A2536BF3D57C6BCA30894032A01DCC4DE8DEC75D7AAB85B567B6CCD41AD312451B948A7413F0A142FD40D49347943854AAF203BA5F8D49B1EC221329C7AEBCF050D3A0CA24447AA0CEDB4B561C7810461EEF19B16A827C27352E5E01F914E9D7C78247A01DCC4DE8DEC75D7AAB85B567B6CCD41AD312451B948A7413F0A142FD40D49347833FFFE884533F194680A0000000000000000000000000000000000000000000000000DA4714CFED9D8BBCC0C0F8C8F8C4A047F2DD6C15EA4082B3E11E5CF6B925B27E51D9DE68051A093E52EF465CFFBB8CA01DCC4DE8DEC75D7AAB85B567B6CCD41AD312451B948A7413F0A142FD40D49347943854AAF203BA5F8D49B1EC221329C7AEBCF050D3A05A7206EDDDF50FCFEEAA97348A7112FC6EDD0B5EACB44CF43D6A6C6B6609B459A01DCC4DE8DEC75D7AAB85B567B6CCD41AD312451B948A7413F0A142FD40D49347833FEFED84533F193E80A0000000000000000000000000000000000000000000000000FFAFBA4BF8DC944EC0C0F8C8F8C4A04D5AD6D860772145872F6660ECEFCB0B0B2056E0AA3509A48BF4C175459E5121A01DCC4DE8DEC75D7AAB85B567B6CCD41AD312451B948A7413F0A142FD40D49347943854AAF203BA5F8D49B1EC221329C7AEBCF050D3A00F4659D09BB2CED56E7FD9C4D3D90DACA8B4F471307B7C4385FD34A41016B0B2A01DCC4DE8DEC75D7AAB85B567B6CCD41AD312451B948A7413F0A142FD40D49347833FDFF684533F192580A000000000000000000000000000000000000000000000000090620E5E59A39FE5C0C0F8C8F8C4A0C1725C58D1BF023AF468E0088DB3CF642AE097CF2C58C2ECE2FC746980ACC7E6A01DCC4DE8DEC75D7AAB85B567B6CCD41AD312451B948A7413F0A142FD40D49347943854AAF203BA5F8D49B1EC221329C7AEBCF050D3A0BE19A182EA1584050DEB0A79ABDC11BE896CE8D00A282BCFAF9FFCD65FD64D6AA01DCC4DE8DEC75D7AAB85B567B6CCD41AD312451B948A7413F0A142FD40D49347833FEFF184533F189080A000000000000000000000000000000000000000000000000076F17F4199BCCD12C0C0F8C8F8C4A0BD521A20A18CA6CA7115065065A1AA20067EE580FB11E2963D1E3A681E8302AFA01DCC4DE8DEC75D7AAB85B567B6CCD41AD312451B948A7413F0A142FD40D49347943854AAF203BA5F8D49B1EC221329C7AEBCF050D3A011BE45633350E39475A1A07712BA72DE4602D9EEBF639CCD5422A389095CCAF1A01DCC4DE8DEC75D7AAB85B567B6CCD41AD312451B948A7413F0A142FD40D49347833FDFFA84533F187B80A00000000000000000000000000000000000000000000000000C71B81C4A4CB82CC0C0F8C8F8C4A07C6D2D56E9C87F1553E4D06705AF61A7C19A6046D2C39F8ED1417988783D3B1DA01DCC4DE8DEC75D7AAB85B567B6CCD41AD312451B948A7413F0A142FD40D49347943854AAF203BA5F8D49B1EC221329C7AEBCF050D3A012F5F0668063509E33A45A64EB6A072B2D84AA19F430F49F159BE5008A786B2EA01DCC4DE8DEC75D7AAB85B567B6CCD41AD312451B948A7413F0A142FD40D49347833FD00684533F186080A0000000000000000000000000000000000000000000000000B3F962892CFEC9E6C0C0F8C8F8C4A07154F0F8ECC7F791D22EEC06EC86D87A44B2704F015B3D2CFF3571A3D01AE0F6A01DCC4DE8DEC75D7AAB85B567B6CCD41AD312451B948A7413F0A142FD40D49347943854AAF203BA5F8D49B1EC221329C7AEBCF050D3A079536ABF8E163CF8AA97F0D52866D04363902D591FD7C36AA35FC983D45FEFD6A01DCC4DE8DEC75D7AAB85B567B6CCD41AD312451B948A7413F0A142FD40D49347833FDFFD84533F182F80A0000000000000000000000000000000000000000000000000736716E42499890FC0C0F8C8F8C4A0BF2FB1EE988AC4E17EAE221A24176649774333FAB25B6FC96C6081527FB6F121A01DCC4DE8DEC75D7AAB85B567B6CCD41AD312451B948A7413F0A142FD40D49347943854AAF203BA5F8D49B1EC221329C7AEBCF050D3A041578DAAE7BCCCD4976340AEB19E4132D2FE4193A0D92F87744C82BFE113502FA01DCC4DE8DEC75D7AAB85B567B6CCD41AD312451B948A7413F0A142FD40D49347833FD00984533F182B80A00000000000000000000000000000000000000000000000001C62FA76645942C6C0C0F8C8F8C4A07F84873E2679D40458B9DDA9900478A78871044E08F6B47DAD659B9B60FF8D48A01DCC4DE8DEC75D7AAB85B567B6CCD41AD312451B948A7413F0A142FD40D49347943854AAF203BA5F8D49B1EC221329C7AEBCF050D3A0597D3F4160770C0492333F90BAD739DC05117D0E478A91F09573742E432904E8A01DCC4DE8DEC75D7AAB85B567B6CCD41AD312451B948A7413F0A142FD40D49347833FE00184533F17F680A0000000000000000000000000000000000000000000000000E24D8B1140FB34D5C0C0F8C8F8C4A0FD77BD13A8CDE1766537FEBE751A27A2A31310A04638A1AFCD5E8AD3C5485453A01DCC4DE8DEC75D7AAB85B567B6CCD41AD312451B948A7413F0A142FD40D49347943854AAF203BA5F8D49B1EC221329C7AEBCF050D3A0473B2B248D91010BA9AEC2696FFC93C11C415ED132832BE0FD0578F184862E13A01DCC4DE8DEC75D7AAB85B567B6CCD41AD312451B948A7413F0A142FD40D49347833FEFFC84533F17CA80A0000000000000000000000000000000000000000000000000FB5B65BAC3F0D947C0C0F8C8F8C4A0518916DFB79C390BD7BFF75712174512C2F96BEC42A3F573355507AD1588CE0CA01DCC4DE8DEC75D7AAB85B567B6CCD41AD312451B948A7413F0A142FD40D49347943854AAF203BA5F8D49B1EC221329C7AEBCF050D3A08599D2EC9E95EC62F41A4975B655D8445D6767035F94EB235ED5EBEA976FB9EAA01DCC4DE8DEC75D7AAB85B567B6CCD41AD312451B948A7413F0A142FD40D49347833FE00484533F17B880A0000000000000000000000000000000000000000000000000BC27F4B8A201476BC0C0F90319F8C4A0AB6B9A5613970FAA771B12D449B2E9BB925AB7A369F0A4B86B286E9D540099CFA01DCC4DE8DEC75D7AAB85B567B6CCD41AD312451B948A7413F0A142FD40D49347943854AAF203BA5F8D49B1EC221329C7AEBCF050D3A0990DC3B5ACBEE04124361D958FE51ACB582593613FC290683940A0769549D3EDA09BFE4817D274EA3EB8672E9FE848C3885B53BBBD1D7C26E6039F90FB96B942B0833FF00084533F16B780A000000000000000000000000000000000000000000000000077377ADFF6C227DBF9024FF89D80809400000000000000000000000000000000000000008609184E72A000822710B3606956330C0D630000003359366000530A0D630000003359602060005301356000533557604060005301600054630000000C5884336069571CA07F6EB94576346488C6253197BDE6A7E59DDC36F2773672C849402AA9C402C3C4A06D254E662BF7450DD8D835160CBB053463FED0B53F2CDD7F3EA8731919C8E8CCF9010501809400000000000000000000000000000000000000008609184E72A000822710B85336630000002E59606956330C0D63000000155933FF33560D63000000275960003356576000335700630000005358600035560D630000003A590033560D63000000485960003356573360003557600035335700B84A7F4E616D65526567000000000000000000000000000000000000000000000000003057307F4E616D655265670000000000000000000000000000000000000000000000000057336069571BA04AF15A0EC494AEAC5B243C8A2690833FAA74C0F73DB1F439D521C49C381513E9A05802E64939BE5A1F9D4D614038FBD5479538C48795614EF9C551477ECBDB49D2F8A6028094CCDEAC59D35627B7DE09332E819D5159E7BB72508609184E72A000822710B84000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002D0ACEEE7E5AB874E22CCF8D1A649F59106D74E81BA0D05887574456C6DE8F7A0D172342C2CBDD4CF7AFE15D9DBB8B75B748BA6791C9A01E87172A861F6C37B5A9E3A5D0D7393152A7FBE41530E5BB8AC8F35433E5931BC0"; byte[] payload = Hex.decode(blocksRaw); - RLPList rlpList = new RLPList(); - RLP.parseObjects(payload, rlpList); + RLPList rlpList = RLP.decode2(payload); BlocksMessage blocksMessage = new BlocksMessage(rlpList); List list = blocksMessage.getBlockDataList(); @@ -419,8 +408,7 @@ public class MessagesTest { String getChainRaw = "F9042414A09F7A910147A6C99AB7EEEAC1ADC7B1B9B0D7D9DD83FD7FC125561016F19B624DA024B519ED5F71207330C1F450B7A4C7445C589B5F9AE73E9BBA09E0A8CB15D845A01EF7B03C7E58E65068D71F68E168C0CC0438808C32FB3E46E402D078B2020E0DA06A0F152620F606E134679D22A86156F9DDEB56FACD62C3106CC66AE030234483A001A3E918F9C2F74BD144505CF70650EF30BE806C533BA5AE3C983F55615EE98EA0E5E441F0877116011CCDECE2501A50B40C40418377037E16D0282B2B5E347138A0C55035BC5BDA25A8C6A2EFF4CCF5386CFFF3E7EE1DC9168B00AABF1074FEB1E2A060AC4D0C12C4CBF552440E659FE4E54C38EF7D05EF98965BA0E0248379CB78DFA0E1620BF60A735DDEA7CB434143E7EF663D043420F017360289FF78046948A77AA0DA8BC25F6571AB0EDE9C3DEF34FFF996575ADFCC1F8009A0388CE0A63AD9FC57A0E153CD998421E4F6BAC6A8329AE90BDA70D5D0F46A7EC02B88BDF5D3CAA8384FA0D3F00977D766A5CAF8F07EF8D15B1DADBBFD57B60BBE6CA54B2F9C2446F614EFA08687EC7AE1A541B13CDA57DCF387DEA3EA35A35AC3D5A9381376EAFBC7BA2CF5A08814AC8660E776A3FCA432D2E9A3533AFFEAEC783ECBB5DAD495B44E04EF1F98A07F2E67F508830BF18E8A432BAB9B957FA2BCDE57BE6C766C13871F833C27B9A5A021EE1E6602530EF711F6C8022799108E1AFB546E7B5FF3E3CBB4DA66C054868DA02940A17DD5C1D1911FFDA7DFAE3E5FAF8E1808CBD11F3248C18B8777B4A5D256A07E5D2F25D9750665ADBFF9C36820AD67CC55850D7D798DAB512343AB0C4E58B3A06674BD13B1051852413031BAA885448E50917D7F1D5EFB7DBA397ED4E5C36D72A06AA7A7D18B07BE0222DA47A8EE6923BAD522DBF5D0650D64CA0F2AD4C606D0CCA07F877735FCC29F804926AACEDBF7AD4896E330DCCE57F257A7D5C81F5CC03188A0FF6B7749526281A5E6A845B8ACC7DC03D2CAAEAFF0CEBF78659FDE1007AD9C05A054D6375CF54B0246FB45787206BA70115DED577354942A9219BC9E761A7E0CBCA0809384946576FB15A8F827B30045D18203A90BE662863D5F205B868DF882472AA05A6EA58D02A2823BA693AC11C21D3C4D66AFFFDB9F1475EA86A461912C2F3187A003AF21F3939C29C231200B1F790F16421A8923254CBF2A90455B9B8F28BE4562A036FDFB3E05936CAA1ABBDCFBBACD9000F86FBCAE2228E77346533CEF17073767A0D3CE8B71E129020F3356A09946F9BC4C18E61D9516E74F6F912461A438F1E006A01D8203A8E23F50D70188ED3099E50645B92959C2216EA7A74719C159B4978BDBA03812A8FC4A5BB6EF0832EBF5058FAF65A46187CEE568C94915AE1850069775F3A0687DDEF8750F606637B3F5F23D286053671081A1AD224B35A624DE7392193951A0E6A8E1D4417292E20F9698A3464CEEABC6476A57521FF79D994DE22C55DADEAD820100"; byte[] payload = Hex.decode(getChainRaw); - RLPList rlpList = new RLPList(); - RLP.parseObjects(payload, rlpList); + RLPList rlpList = RLP.decode2(payload); GetChainMessage getChainMessage = new GetChainMessage(rlpList); getChainMessage.parseRLP(); @@ -446,8 +434,7 @@ public class MessagesTest { String getChainRaw = "E015A0E5E441F0877116011CCDECE2501A50B40C40418377037E16D0282B2B5E347138"; byte[] payload = Hex.decode(getChainRaw); - RLPList rlpList = new RLPList(); - RLP.parseObjects(payload, rlpList); + RLPList rlpList = RLP.decode2(payload); NotInChainMessage notInChainMessage = new NotInChainMessage(rlpList); System.out.println(notInChainMessage); diff --git a/ethereumj-core/src/test/java/org/ethereum/util/RLPTest.java b/ethereumj-core/src/test/java/org/ethereum/util/RLPTest.java index 0ab7c5f0..71904750 100644 --- a/ethereumj-core/src/test/java/org/ethereum/util/RLPTest.java +++ b/ethereumj-core/src/test/java/org/ethereum/util/RLPTest.java @@ -2,19 +2,21 @@ package org.ethereum.util; import org.spongycastle.util.encoders.Hex; import org.ethereum.crypto.HashUtil; -import org.ethereum.net.rlp.RLP; -import org.ethereum.net.rlp.RLPList; import org.ethereum.util.Utils; import org.junit.Test; +import com.cedarsoftware.util.DeepEquals; + import java.math.BigInteger; import java.net.InetAddress; import java.net.UnknownHostException; +import java.util.Arrays; import java.util.LinkedList; import java.util.Queue; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; +import static org.ethereum.util.RLP.toInt; +import static org.ethereum.util.RlpTestData.*; +import static org.junit.Assert.*; public class RLPTest { @@ -51,7 +53,6 @@ public class RLPTest { assertEquals(oneInt, 30303); } - @Test public void test3() throws UnknownHostException { @@ -106,7 +107,6 @@ public class RLPTest { assertEquals(-1, nextIndex); } - @Test /** encode byte */ public void test4(){ @@ -262,8 +262,7 @@ public class RLPTest { String tx = "F86E12F86B80881BC16D674EC8000094CD2A3D9F938E13CD947EC05ABC7FE734DF8DD8268609184E72A00064801BA0C52C114D4F5A3BA904A9B3036E5E118FE0DBB987FE3955DA20F2CD8F6C21AB9CA06BA4C2874299A55AD947DBC98A25EE895AABF6B625C26C435E84BFD70EDF2F69"; byte[] payload = Hex.decode(tx); - RLPList rlpList = new RLPList(); - RLP.parseObjects(payload, rlpList); + RLPList rlpList = RLP.decode2(payload); RLPList.recursivePrint(rlpList); // TODO: add some asserts in place of just printing the rlpList @@ -275,8 +274,7 @@ public class RLPTest { String peers= "f9 14 90 11 f8 4c c6 81 83 68 81 fc 04 82 76 5f b8 40 07 7e 53 7a 8b 36 73 e8 f1 b6 25 db cc 90 2e a7 d4 ce d9 40 2e 46 64 e8 73 67 95 12 cc 23 60 69 8e 53 42 56 52 a0 46 24 fc f7 8c db a1 a3 23 30 87 a9 19 a3 4d 11 ae da ce ee b7 d8 33 fc bf 26 f8 4c c6 63 81 e7 58 81 af 82 76 5f b8 40 0a b2 cd e8 3a 09 84 03 dd c2 ea 54 14 74 0d 8a 01 93 e4 49 c9 6e 11 24 19 96 7a bc 62 eb 17 cd ce d7 7a e0 ab 07 5e 04 f7 dd dc d4 3f b9 04 8b e5 32 06 a0 40 62 0b de 26 cb 74 3f a3 12 31 9f f8 4d c7 81 cf 81 db 45 81 9a 82 76 5f b8 40 19 c3 3d a7 03 1c ff 17 7e fa 84 2f aa 3d 31 bd 83 e1 76 4e c6 10 f2 36 94 4a 9f 8a 21 c1 c5 1a 04 f4 7f 6b 5f c3 ef e6 5c af 36 94 43 63 5a fc 58 d8 f5 d4 e2 f1 2a f9 ee ec 3c 6e 30 bf 0a 2b f8 4c c6 44 30 81 ad 81 a3 82 76 5f b8 40 1e 59 c2 82 08 12 94 80 84 97 ae 7a 7e 97 67 98 c4 2b 8b cc e1 3c 9d 8b 0e cf 8a fe cd b5 df d4 ef a8 77 0f c0 d1 f7 de 63 c9 16 40 e7 e8 b4 35 8c 9e 3e d0 f3 d6 c9 86 20 ad 7e a4 24 18 c9 ec f8 4b c5 1f 12 81 9e 48 82 76 5f b8 40 1f 68 c0 75 c1 d8 7b c0 47 65 43 0f df b1 e5 d0 0f 1b 78 4e d6 be 72 1e 4c af f7 be b5 7b 4b 21 7b 95 da 19 b5 ec 66 04 58 68 b3 9a ac 2e 08 76 cf 80 f0 b6 8d 0f a2 0b db 90 36 be aa 70 61 ea f8 4c c6 81 bf 81 ea 39 37 82 76 5f b8 40 21 78 0c 55 b4 7d b4 b1 14 67 b5 f5 5b 0b 55 5e 08 87 ce 36 fb d9 75 e2 24 b1 c7 0e ac 7a b8 e8 c2 db 37 f0 a4 8b 90 ff dd 5a 37 9a da 99 b6 a0 f6 42 9c 4a 53 c2 55 58 19 1a 68 26 36 ae f4 f2 f8 4c c6 44 30 81 ad 81 a3 82 76 5f b8 40 23 15 cb 7c f4 9b 8e ab 21 2c 5a 45 79 0b 50 79 77 39 73 8f 5f 73 34 39 b1 90 11 97 37 ee 8c 09 bc 72 37 94 71 2a a8 2f 26 70 bc 58 1a b0 75 7e f2 31 37 ac 0f df 0f 8c 89 65 e7 dd 6b a7 9f 8c f8 4e c8 81 bf 81 b1 81 d1 81 9f 82 76 5f b8 40 24 9a 36 41 e5 a8 d0 8e 41 a5 cf c8 da e1 1f 17 61 25 4f 4f d4 7d 9b 13 33 8d b8 e6 e3 72 9e 6f 2a c9 ec 09 7a 5c 80 96 84 d6 2a 41 e6 df c2 ff f7 2d c3 db d9 7e a2 61 32 bb 97 64 05 65 bb 0c f8 4a c4 55 41 7e 2d 82 76 5f b8 40 2a 38 ea 5d 9a 7e fd 7f ff c0 a8 1d 8e a7 ed 28 31 1c 40 12 bb ab 14 07 c8 da d2 68 51 29 e0 42 17 27 34 a3 28 e8 90 7f 90 54 b8 22 5f e7 70 41 d8 a4 86 a9 79 76 d2 83 72 42 ab 6c 8c 59 05 e4 f8 4c c6 81 83 68 81 fc 04 82 76 5f b8 40 32 4d d9 36 38 4d 8c 0d de fd e0 4b a7 40 29 98 ab bd 63 d7 9c 0b f8 58 6b 3d d2 c7 db f6 c9 1e b8 0a 7b 6d e8 f1 6a 50 04 4f 14 9c 7b 39 aa fb 9c 3a d7 f2 ca a4 03 55 aa b0 98 88 18 6f cc a2 f8 4c c6 44 30 81 ad 81 a3 82 76 5f b8 40 39 42 45 c0 99 16 33 ed 06 0b af b9 64 68 53 d3 44 18 8b 80 4f e3 7e 25 a5 bc ac 44 ed 44 3a 84 a6 8b 3a af 15 5e fe 48 61 e8 4b 4b 51 5f 9a 5d ec db d7 da e9 81 92 d7 a3 20 a7 92 c7 d4 df af f8 4d c7 56 81 b7 81 e7 81 cd 82 76 5f b8 40 39 86 50 f6 7b 22 92 93 9d e3 4c 0e ae b9 14 1f 94 84 a0 fb 17 3f a3 3f 81 a1 f7 31 5d 0e b7 7b de 3a 76 c3 86 36 fa e6 6f a1 4b f2 af df d6 3e 60 ab d4 0e 29 b0 2a 91 4e 65 de 57 89 98 3f d4 f8 4c c6 44 81 b9 81 ea 40 82 76 5f b8 40 3a 15 58 7a 1c 3a da bf 02 91 b3 07 f7 1b 2c 04 d1 98 aa e3 6b 83 49 95 d3 30 5d ff 42 f1 ab 86 f4 83 ae 12 9e 92 03 fb c6 ef 21 87 c8 62 1e dd 18 f6 1d 53 ea a5 b5 87 ff de a4 d9 26 48 90 38 f8 4d c7 81 cf 81 db 45 81 9a 82 76 5f b8 40 3b 14 62 04 0e a7 78 e3 f7 5e 65 ce 24 53 41 8a 66 2e 62 12 c9 f6 5b 02 ea b5 8d 22 b2 87 e4 50 53 bd e5 eb f0 60 96 0c bf a0 d9 dc 85 bf 51 ba 7a a1 f2 ca a2 c1 36 82 d9 32 77 64 1d 60 db eb f8 4c c6 6a 81 a8 0e 81 f9 82 76 5f b8 40 3e cc 97 ab 15 d2 2f 7b 9e df 19 c0 4c e3 b6 09 5f a2 50 42 14 00 2b 35 98 9c 6f 81 ee 4b 96 1c c2 a8 99 c4 94 15 c9 14 e3 13 90 83 40 04 7d 1d 3b 25 d7 4f 5b 9c 85 a0 6a fa 26 59 a5 39 99 2e f8 4b c5 2e 04 81 c1 09 82 76 5f b8 40 40 7c 22 00 3f 3b ba a6 cb eb 8e 4b 0a b7 07 30 73 fe ab 85 18 2b 40 55 25 f8 bd 28 32 55 04 3d 71 35 18 f7 47 48 d9 2c 43 fb b9 9e cc 7c 3f ba b9 5d 59 80 06 51 3a a8 e5 9c 48 04 1c 8b 41 c2 f8 4b c5 32 7e 56 81 c2 82 76 5f b8 40 40 8c 93 24 20 3b d8 26 2f ce 65 06 ba 59 dc dd 56 70 89 b0 eb 9a 5b b1 83 47 7b ab bf 61 63 91 4a cd c7 f4 95 f8 96 4d 8a c1 2f e2 40 18 87 b8 cd 8d 97 c0 c9 dc cf ad db b2 0a 3c 31 47 a7 89 f8 4a c4 26 6c 4f 68 82 76 5f b8 40 42 3e 40 04 da 2f a7 50 0b c0 12 c0 67 4a a6 57 15 02 c5 3a a4 d9 1e fa 6e 2b 5c b1 e4 68 c4 62 ca 31 14 a2 e2 eb 09 65 b7 04 4f 9c 95 75 96 5b 47 e4 7a 41 f1 3f 1a dc 03 a2 a4 b3 42 d7 12 8d f8 4b c5 40 81 e7 08 2d 82 76 5f b8 40 42 83 93 75 27 2c 2f 3d ea db 28 08 5d 06 05 5e 35 31 35 c6 c8 d8 96 09 7a 1b c4 80 c4 88 4f d1 60 45 18 cb df 73 1a c1 8f 09 84 b7 f0 21 48 e8 82 90 d1 3c 22 4d 82 46 43 14 e2 b5 96 2e 3f 89 f8 4d c7 32 81 aa 81 d8 81 c8 82 76 5f b8 40 44 cf 19 44 6c a4 65 01 8e 4d e6 c6 0f c0 df 52 9e ba 25 02 92 ef 74 41 e1 db 59 84 1c 69 f0 22 f6 09 28 10 c9 a5 a7 f2 74 f2 f9 7c 4b d6 c7 6e ad c0 64 c7 d6 59 7c ae b1 7e d8 7c b2 57 73 5f f8 4b c5 32 81 9c 5a 53 82 76 5f b8 40 46 1c 9b 54 e9 19 53 c5 bb c3 1c 67 12 a9 17 38 2b e6 7d 60 f7 5e b7 f5 06 51 be a3 e5 94 d0 d1 9c 22 29 d8 f6 6a db 3f 20 3f 60 00 38 e7 cc 93 4d c9 27 87 fa c4 39 2b 9b fa 7c bc 78 6f d0 5b f8 4b c5 81 86 64 7d 29 82 76 5f b8 40 48 35 3a 00 58 e2 64 48 d9 4e 59 33 6c ca 9d 28 a9 37 41 20 de f7 6c 4b cc fe e1 8b 01 23 e5 91 92 39 3a 2e e3 04 4d 80 e0 ee cb b0 94 76 be 62 fd e1 e8 74 f9 3d 05 ea 5c 4a 9a 45 c0 6e 8f e1 f8 4b c5 4e 08 05 81 bb 82 76 5f b8 40 48 e8 95 09 49 d4 c0 0b cd bb e9 39 c5 bf 07 8f 2c bf f1 08 84 af 16 60 b1 c3 22 b9 ca a3 ba 35 7b b4 15 7f c6 b0 03 9a f9 43 8d fe 51 ec 27 8a 47 fc d3 b7 26 fa 0a 08 7d 4c 3c 01 a6 2f 33 5e f8 4a c6 58 45 81 c6 81 c6 07 b8 40 4a 02 55 fa 46 73 fa a3 0f c5 ab fd 3c 55 0b fd bc 0d 3c 97 3d 35 f7 26 46 3a f8 1c 54 a0 32 81 cf ff 22 c5 f5 96 5b 38 ac 63 01 52 98 77 57 a3 17 82 47 85 49 c3 6f 7c 84 cb 44 36 ba 79 d6 d9 f8 4b c5 40 81 e7 08 2d 82 76 5f b8 40 4c 75 47 ab 4d 54 1e 10 16 4c d3 74 1f 34 76 ed 19 4b 0a b9 a1 36 df ca c3 94 3f 97 35 8c 9b 05 14 14 27 36 ca 2f 17 0f 12 52 29 05 7b 47 32 44 a6 23 0b f5 47 1a d1 68 18 85 24 b2 b5 cd 8b 7b f8 4c c6 44 30 81 ad 81 a3 82 76 5f b8 40 4d 5e 48 75 d6 0e b4 ee af b6 b2 a7 d3 93 6e d3 c9 bc 58 ac aa de 6a 7f 3c 5f 25 59 8c 20 b3 64 f1 2b ea 2f b1 db 3b 2c 2e f6 47 85 a4 7d 6b 6b 5b 10 34 27 cb ac 0c 88 b1 8f e9 2a 9f 53 93 f8 f8 4b c5 52 0c 81 e3 54 82 76 5f b8 40 4f d8 98 62 75 74 d3 e8 6b 3f 5a 65 c3 ed c2 e5 da 84 53 59 26 e4 a2 88 20 b0 03 8b 19 63 6e 07 db 5e b0 04 d7 91 f8 04 1a 00 6e 33 e1 08 e4 ec 53 54 99 d1 28 d8 d9 c5 ca f6 bb dc 22 04 f7 6a f8 4b c5 81 b4 20 2b 08 82 76 5f b8 40 53 cc f2 5a b5 94 09 ec bb 90 3d 2e c3 a9 aa 2e b3 9d 7c c4 c7 db 7e 6f 68 fd 71 1a 7c eb c6 06 21 6d e7 37 82 6d a4 20 93 e3 e6 52 1e e4 77 0e b2 d6 69 dc 4b f3 54 6c c7 57 c3 40 12 69 6e ae f8 4c c6 6a 81 a8 0e 81 f9 82 76 5f b8 40 54 b3 93 15 69 91 39 87 80 50 2f a8 f4 14 13 79 bc e2 69 31 be 87 ba 8e 0b 74 9b a9 05 a9 e9 76 e5 de 6d 39 c9 8c f0 48 f2 5c 3c bb b8 c7 f3 02 c4 e6 04 ad 5b f7 2c db 06 10 0f 50 0d e3 a6 86 f8 4a c4 4c 67 37 47 82 76 5f b8 40 60 0a 77 fb 14 e7 92 c0 c7 0d c4 ad e3 82 ed 60 43 62 b9 78 b1 9b 94 c4 ed 18 83 38 a1 79 5d 2d b4 5f 7f 22 3b 66 ba eb a3 91 c5 9b 55 88 b4 4e ba f7 1c 7e b3 97 55 c2 72 29 c7 fd e6 41 be ce f8 4b c5 6d 2b 81 9a 42 82 76 5f b8 40 69 dd 44 5f 67 c3 be f3 94 f9 54 9f da e1 62 3d bc 20 88 4a 62 fd 56 16 dd bb 49 f8 4b a8 7e 14 7c b8 a5 0b a9 71 d7 30 c4 62 1d 0e b6 51 33 49 4e 94 fa 5e a2 e6 9c 66 1f 6b 12 e7 ed 2a 8d 4e f8 4b c5 18 09 3d 81 9b 82 76 5f b8 40 6b 5d 4c 35 ff d1 f5 a1 98 03 8a 90 83 4d 29 a1 b8 8b e0 d5 ef ca 08 bc 8a 2d 58 81 18 0b 0b 41 6b e0 06 29 aa be 45 0a 50 82 8b 8d 1e e8 2d 98 f5 52 81 87 ee 67 ed 6e 07 3b ce ef cd fb 2b c9 f8 4a c4 55 41 7e 2d 82 76 5f b8 40 6c bb 1e d5 36 dc 38 58 c1 f0 63 42 9b d3 95 2a 5d 32 ef 8e 11 52 6c df e7 2f 41 fe a1 ac e9 60 18 7c 99 75 ab bc 23 78 35 11 c0 0f 26 98 35 47 47 f9 05 aa ac 11 dc d2 b7 47 8b 3e af 32 7a c6 f8 4b c5 40 81 e7 08 2d 82 76 5f b8 40 6e a2 8f 64 ea 1c c3 b6 57 25 44 fd 5b f7 43 b0 ea ab e0 17 f5 14 73 0c 89 7d a3 c7 7f 03 c5 16 f1 e5 f3 1d 79 3b 4b ce 3c aa 1d ed 56 35 6d 20 b2 eb b5 5a 70 66 f4 1c 25 b7 c3 d5 66 14 e0 6b f8 4a c4 55 41 7e 2d 82 76 5f b8 40 72 53 24 08 e8 be 6d 5e 2c 9f 65 0f b9 c9 f9 96 50 cc 1f a0 62 a4 a4 f2 cf e4 e6 ae 69 cd d2 e8 b2 3e d1 4a fe 66 95 5c 23 fa 04 8f 3a 97 6e 3c e8 16 9e 50 5b 6a 89 cc 53 d4 fa c2 0c 2a 11 bf f8 4c c6 52 81 d9 48 81 a9 82 76 5f b8 40 7a ee a4 33 60 b9 36 8b 30 e7 f4 82 86 61 3f d1 e3 b0 20 7f b7 1f 03 08 d5 04 12 11 44 63 e7 7a b8 30 27 c0 d4 0c ad aa b8 bb f6 12 fc 5b 69 67 fa 1c 40 73 29 d4 7e c6 1f b0 dc 3d a1 08 68 32 f8 4c c6 81 a6 81 93 53 4f 82 76 5f b8 40 7b 3c dd e0 58 d5 b4 5d 8d b2 24 36 60 cf ea 02 e0 74 ec 21 31 14 c2 51 d7 c0 c3 2d 04 03 bb 7a b4 77 13 d2 49 2f f6 c8 81 cf c2 aa c3 f5 2c b2 69 76 8c 89 68 f3 b6 b1 8b ac 97 22 d0 53 31 f6 f8 4c c6 6a 81 a8 0e 81 f9 82 76 5f b8 40 87 ab 58 1b b9 7c 21 2a 2d a7 ef 0d 6e 10 5e 41 b5 5e 4e 42 cb b6 a1 af 9a 76 1a 01 ca 8c 65 06 9a b4 b5 82 7e 32 2c f2 c5 f5 9e 7f 59 2b e2 a8 17 c4 5a b6 41 f5 a9 dd 36 89 63 c7 3f 9e e6 88 f8 4c c6 52 81 d9 48 81 a9 82 76 5f b8 40 8c 66 0d bc 6d 3d b0 18 6a d1 0f 05 fd 4f 2f 06 43 77 8e c5 14 e8 45 2a 75 50 c6 30 da 21 17 1a 29 b1 bb 67 c2 e8 e1 01 ea 1d b3 97 43 f3 e7 8c 4d 26 76 a1 3d 15 51 51 21 51 5f c3 8b 04 8f 37 f8 4c c6 63 81 e7 58 81 af 82 76 5f b8 40 94 fe 3d 52 a2 89 4c ed c6 b1 54 24 15 6e b8 73 8a 84 41 dd 74 ba 9c ed 66 64 ed 30 a3 32 a9 5b 57 4d 89 26 2e a3 67 fa 90 0a e9 70 6f b8 1a 40 82 87 bd de f3 a9 dd 9f f4 4e 3a 41 bc 09 0f dc f8 4d c7 81 d5 81 81 81 e6 0a 82 76 5f b8 40 95 21 14 f1 10 e8 ac 00 df ea 5f 05 0d 95 5e 76 4c 7c ba 8f b2 07 c0 5a 7a a5 ae 84 91 68 64 0a 2b 4e 31 43 91 fc 3a 76 79 5b 38 27 05 54 62 63 9c ff 4a e2 d6 4a b8 0e 95 27 44 28 31 3e 36 6a f8 4c c6 58 45 81 c6 81 c6 82 76 5f b8 40 96 f3 47 b0 96 ed 16 30 f4 74 b9 76 23 e4 5e 8d 47 1b 1d 43 c2 2f 59 96 07 c8 b2 e3 ed 0d 7b 79 05 d8 55 4a d3 99 db d7 39 c7 61 26 40 44 24 d8 db 0d c7 d2 b0 47 c1 a3 28 ae 27 d4 09 06 c5 83 f8 4c c6 81 83 68 81 fc 04 82 76 5f b8 40 9a 22 c8 fb 1b d8 bb d0 2f 0e 74 ed 9d 3d 55 b0 f5 b0 96 72 bc 43 a2 d4 7b 1e d0 42 38 c1 c3 2b 6a 65 74 26 52 5b 15 51 82 36 e9 78 9b 54 6a 4a 07 2a 60 5e 13 73 fe 5b 99 6b ae dc 30 35 94 28 f8 4b c5 52 0c 81 e3 54 82 76 5f b8 40 9b 1a 3a 8d 77 1b 3d 94 9c a3 94 a8 8e b5 dc 29 a9 53 b0 2c 81 f0 17 36 1f fc 0a fe 09 ab ce 30 69 17 1a 87 d4 74 52 36 87 fc c9 a9 d3 2c c0 2c fa b4 13 22 56 fe aa bf e0 5f 7a c7 47 19 4e 88 f8 4b c5 42 81 d7 78 1c 82 76 5f b8 40 9f a7 e5 5b 2d 98 f1 d7 44 c7 62 32 e4 fd a2 42 fe 9f d3 d5 74 3d 16 d3 ca d2 e5 48 a0 7c b5 af 06 fe 60 eb ae b8 c6 09 50 28 17 92 34 dc dd d3 cd cf 1f cf e6 ed aa 2a 53 30 7f d1 03 da 4a f0 f8 4a c4 55 41 7e 2d 82 76 5f b8 40 a0 1f 83 4e 9d 1a 61 3c 3c 74 7e 56 1c ac 19 cb 12 d8 79 c1 a5 74 20 a4 9c 23 65 2b 8f 51 28 8c 8b 11 1a a3 88 89 98 b0 5e 32 7f 47 a2 35 c6 a4 a3 77 f8 88 e3 00 5a 2d 4b 03 ec b7 26 86 08 d3 f8 4c c6 44 30 81 ad 81 a3 82 7a 51 b8 40 a5 fd 77 c0 d4 32 fb fa 33 17 08 49 14 c2 e8 a8 82 1e 4b a1 dc ba 44 96 1f f7 48 0e 6d b6 08 78 9c ab 62 91 41 63 60 ea 8c dc 26 b0 d2 f0 87 7c 50 e8 9a 70 c1 bc f5 d6 dd 8b 18 2e 0a 9e 37 d3 f8 4d c7 81 88 81 a0 81 98 31 82 76 5f b8 40 ae 31 bd 02 54 ee 7d 10 b8 0f c9 0e 74 ba 06 ba 76 11 87 df 31 38 a9 79 9d e5 82 8d 01 63 52 4c 44 ba c7 d2 a9 b5 c4 1b e5 be 82 89 a1 72 36 1f 0b a9 04 10 c9 4f 57 9b f7 eb d2 8f 18 aa a1 cd f8 4a c4 55 41 7e 2d 82 76 5f b8 40 ba 3d 21 67 72 cd c7 45 58 d2 54 56 24 a2 d6 2d cb cf d2 72 30 57 30 c7 46 43 c7 a7 e8 19 af a6 cd d8 22 23 e2 b5 50 1e b6 d4 ea e5 db f2 1e 55 8c 76 8a ca ec 2c 1c a1 0e 74 c4 c8 7a 57 4b 53 f8 4a c4 55 41 7e 2d 82 76 5f b8 40 bd b4 9c 01 87 2d 91 bd 1e a9 90 bd 2e df 16 c4 81 71 a6 06 7f 9a 6f 7f 48 bf b1 94 63 0b 5a e9 03 1b 5d c2 63 f5 9c 66 ad a4 44 cb 4e 6f 9d f6 2b 30 17 ce 61 2c ab 7b 53 da 08 d3 56 f7 8d 30 f8 4c c6 63 81 e7 58 81 af 82 76 5f b8 40 c1 2b a9 1f 95 04 4d 78 ee d1 d3 a9 53 5e bd 64 71 52 44 18 13 5e eb 46 ad 5d 5c 6e cc 2f 51 68 b4 ab 3a 06 2b b0 74 2a ea 65 ff ea 76 7f ab 8d cc 21 78 3c b2 9b f3 2e 2c d6 22 22 09 fa 71 fd f8 4c c6 44 30 81 ad 81 a3 82 7a 51 b8 40 c2 e2 69 e6 4a a8 c9 be 2d 41 81 2a 48 af a2 34 6b d4 1a 1a b2 e4 64 62 41 ae 3b 8d 0c cd 41 f2 d6 82 b1 5a 02 5f 75 9c 0d 95 5a 60 71 d4 e8 ea 7d 4d e3 97 d6 e0 52 23 09 20 11 3b 6e b7 4c 09 f8 4a c4 4a 4f 17 77 82 76 5f b8 40 c3 03 b8 3f 6a 16 1f 99 67 36 34 44 80 ae 9d 88 fd c1 d9 c6 75 bf ac a8 88 f7 0f 24 89 72 65 62 82 09 da 53 74 1e 03 c0 f6 59 21 f6 8f 60 2d c9 f3 34 a3 c4 5b cb 92 af 85 44 a6 fb 11 9b d8 87 f8 4b c5 0c 81 fa 61 1a 82 76 5f b8 40 c7 6e 7c 15 7b 77 35 51 11 53 d1 f9 50 81 a1 44 e0 88 a9 89 17 1f 3d 43 2c c5 d8 29 3e ce 9c fa a4 83 c0 32 15 5d 7b 53 65 6a 6e 33 a3 d7 5c d0 62 4e 09 a2 f9 49 c1 56 09 3d ba a8 3f 11 11 f2 f8 4b c5 52 0c 81 e3 54 82 76 5f b8 40 c7 d5 a3 69 1a 59 59 9d e3 33 48 9c bf 8a 47 a7 43 3e 92 c7 27 06 e1 3d 94 ed 21 12 96 d3 5c 97 d8 35 7d 7e 07 b3 85 85 64 d7 26 8e d7 aa 09 7f 37 58 9c 27 77 0f 90 dd 0b 07 63 5b e3 f5 33 64 f8 4c c6 4e 09 81 92 81 b2 82 76 5f b8 40 c8 81 97 a8 2b 0a cf 0a 87 24 94 d1 df ac 9d e8 46 da a7 de 08 b2 40 64 7a 96 ba 72 fb e0 8f d5 2b 55 c6 c9 45 14 a4 7e c5 1b a4 9a 97 54 89 eb c9 38 3b 48 f5 e2 40 93 90 68 ce 58 36 ff 24 f1 f8 4b c5 81 b4 20 2b 08 82 76 5f b8 40 c9 e0 39 d8 a8 b9 e4 35 be f2 f4 5f c7 cb 7e 78 87 16 e8 c7 af c1 ba cc 64 e1 24 6d 2a b5 06 d3 60 73 79 2a e6 96 e4 1a d6 ba 0c 8a bd 2e c0 d5 45 b0 75 7f 94 a9 f3 53 82 80 e5 6d b5 f5 d8 ec f8 4b c5 4e 68 81 a3 51 82 76 5f b8 40 ca 27 68 37 02 a8 e9 bf 32 01 65 6f f8 4a 60 d5 b1 dd 81 42 73 99 3c f1 a0 25 b0 54 45 4e 40 d5 30 92 f4 85 18 ee 05 be ad 4f 18 02 1f 4f 54 0c 0b 7c 7d 26 eb a5 0e a4 89 0b 9e 5e 49 a7 6c 5f f8 4a c4 55 41 7e 2d 82 76 5f b8 40 cb 72 be 9e 2e 5d 4a 1f 25 72 96 c7 39 39 10 4e ce 80 31 32 15 26 5a f0 6b c7 ea f4 42 ab ff 4f 0b 48 fc fc 6f 43 f4 df 46 30 c7 12 b5 e7 ef db 75 4a 86 e4 0c f2 02 16 6e b6 9e ea a6 ad 3a 2d f8 4a c4 36 48 1f 37 82 76 5f b8 40 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 40 7f 65 9c 78 f4 19 02 5d 78 57 27 ed 01 7b 6a dd 21 95 2d 7e 12 00 73 73 e3 21 db c3 18 24 ba f8 4a c4 55 41 7e 2d 82 76 5f b8 40 ce 73 f1 f1 f1 f1 6c 1b 3f da 7b 18 ef 7b a3 ce 17 b6 f1 f1 f1 f1 41 d3 c6 c6 54 b7 ae 88 b2 39 40 7f f1 f1 f1 f1 19 02 5d 78 57 27 ed 01 7b 6a dd 21 f1 f1 f1 f1 00 00 01 e3 21 db c3 18 24 ba f8 4c c6 81 bf 81 ea 39 37 82 76 5f b8 40 d2 30 30 60 35 99 b7 6f 64 0b 8f 7c 11 99 12 bb 04 66 e7 ee f3 38 cd 9d e5 67 d2 b6 df ba 81 72 8d b2 e9 8f 29 38 25 bb 00 a9 a6 ac 93 66 83 fc 82 c8 bc 38 7a df 3a 4a 5f e1 cc ca dd 1a 74 59 f8 4c c6 6b 81 aa 39 81 f7 82 76 5f b8 40 e0 2b 18 fb a6 b8 87 fb 92 58 46 9c 3a f8 e4 45 cc 9a e2 b5 38 6c ac 5f 60 c4 17 0f 82 20 86 22 4e 38 76 55 5c 74 5a 7e c8 ac 18 1c 7f 97 01 77 6d 94 a7 79 60 4e a1 26 51 de 5f 4a 74 8d 29 e1 f8 4c c6 40 81 e7 0a 81 d0 82 76 5f b8 40 e3 11 15 a7 6f a7 fb 2e fd 3c fa f4 6a d0 0b 05 fc 34 98 e1 ba f1 78 5d ff e6 ca 69 91 3d 25 65 31 d1 80 56 42 35 fd 3d 3c 10 40 9c d1 1f c2 59 cf 7c fd a9 b6 bb 25 33 40 41 2d 82 87 8f 3b d3 f8 4b c5 41 5e 31 81 97 82 76 5f b8 40 e5 e8 d8 c2 d7 62 d2 1c a1 e9 bc ee 8a dc 53 60 0f 2d 89 40 97 54 26 66 d6 b5 f4 1b 23 58 4b 07 f6 09 01 ab 40 9d df 91 e0 cd 25 62 da ff f2 cb 0f 22 1e b9 f1 15 6f 78 1a 5d 99 31 a0 2a 2e 07 f8 4a c4 55 41 7e 2d 82 76 5f b8 40 ea 99 2c 13 68 7c 20 e7 90 a9 ff a6 df 8b 1a 16 86 88 e2 a8 87 36 5d 7a 50 21 86 fa 0d 62 20 e8 3e 11 3a 1f e7 7d c0 68 9d 55 ba 2e 8a 83 aa 8e 20 42 18 f4 d8 e7 32 82 5b d7 80 cf 94 ed 5c c3 f8 4b c5 56 7c 52 81 fe 82 76 5f b8 40 f6 15 5f 1a 60 14 3b 7d 9d 5d 1a 44 0d 7d 52 fe 68 09 f6 9e 0c 6f 1e 00 24 45 7e 0d 71 dd 88 ad e3 b1 3a aa 94 0c 89 ac 06 10 95 2b 48 bd 83 2c 42 e3 43 a1 3e 61 ff db 06 01 0c ff c3 45 e0 53 f8 4c c6 63 81 e7 58 81 af 82 76 5f b8 40 fa 56 85 61 b7 d5 28 8d f7 a5 06 c9 bc 1c 95 12 ab 39 6e 68 c4 6f 0e 62 c2 1d c1 aa 58 4b 84 4a 8a 7e 94 4f 69 71 30 36 65 fd 37 b1 38 d9 a5 f6 37 e6 72 ed b9 89 69 66 4c 4e 7f d1 c4 12 6d ef"; byte[] payload = Hex.decode(peers); - RLPList rlpList = new RLPList(); - RLP.parseObjects(payload, rlpList); + RLPList rlpList = RLP.decode2(payload); RLPList.recursivePrint(rlpList); // TODO: add some asserts in place of just printing the rlpList @@ -288,8 +286,7 @@ public class RLPTest { String blocksMsg= "f91c1c13f90150f8c4a07df3d35d4df0a56fcf1d6344d5315cb56b9bf83bb96ad17c7b96a9cd14133c5da01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347943854aaf203ba5f8d49b1ec221329c7aebcf050d3a064afb6284fa35f26d7b2c5a26afaa5483072fbcb575221b34ce002a991b7a223a04a8abe6d802797dc80b497584f898c2d4fd561cc185828cfa1b92f6f38ee348e833fbfe484533f201c80a000000000000000000000000000000000000000000000000000cfccb5cfd4667cf887f8850380942d0aceee7e5ab874e22ccf8d1a649f59106d74e88609184e72a000822710a047617600000000000000000000000000000000000000000000000000000000001ca08691ab40e258de3c4f55c868c0c34e780e747158a1d96ca50186dfd3305abd78a042269c981d048a7b791aafc8f4e644232740c1a1cceb5b6d05568827a64c0664c0f8c8f8c4a0637c8a6cdb907fac6f752334ab79065bcc4e46cd4f4358dbc2a653544a20eb31a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347943854aaf203ba5f8d49b1ec221329c7aebcf050d3a022a36c1a1e807e6afc22e6bb53a31111f56e7ee7dbb2ee571cefb152b514db4da01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347833fcfd784533f1cf980a0000000000000000000000000000000000000000000000000e153d743fa040b18c0c0f8c8f8c4a07b2536237cbf114a043b0f9b27c76f84ac160ea5b87b53e42c7e76148964d450a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347943854aaf203ba5f8d49b1ec221329c7aebcf050d3a07a3be0ee10ece4b03097bf74aabac628aa0fae617377d30ab1b97376ee31f41aa01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347833fbfe884533f1ce880a0000000000000000000000000000000000000000000000000f3deea84969b6e95c0c0f8c8f8c4a0d2ae3f5dd931926de428d99611980e7cdd7c1b838273e43fcad1b94da987cfb8a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347943854aaf203ba5f8d49b1ec221329c7aebcf050d3a00b5b11fcf4ee12c6812f9d01cf0dff07c72cd7e02e48b35682f67c595407be14a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347833faffd84533f1ce280a00000000000000000000000000000000000000000000000005fcbc97b2eb8ffb3c0c0f8c8f8c4a094d615d3cb4b306d20985028c78f0c8413d509a75e8bb84eda95f734debad2a0a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347943854aaf203ba5f8d49b1ec221329c7aebcf050d3a04b8fd1b98cf5758bd303ff86393eb6d944c1058124bddce5d4e04b5395254d5ea01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347833fbfec84533f1c7680a000000000000000000000000000000000000000000000000079fe3710116b32aac0c0f8c8f8c4a09424a07a0e4c05bb872906c40844a75b76f6517467b79c12fa9cc6d79ae09934a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347943854aaf203ba5f8d49b1ec221329c7aebcf050d3a02dbe9ff9cbbc4c5a6ff26971f75b405891141f4e9bce3c2dc4200a305138e584a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347833fcfdf84533f1c3b80a0000000000000000000000000000000000000000000000000e0a6f8cf1d56031bc0c0f8c8f8c4a009aabea60cf7eaa9df4afdf4e1b5f3e684dab34fc9a9180a050085a4131ceedfa01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347943854aaf203ba5f8d49b1ec221329c7aebcf050d3a0436da067f9683029e717edf92da46c3443e8c342974f47a563302a0678efe702a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347833fdfd684533f1bfc80a00000000000000000000000000000000000000000000000005bc88c041662ffdac0c0f8c8f8c4a0f8b104093483b7c0182e1bba2ce3340d14469d3a3ee7646821223a676c680ac1a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347943854aaf203ba5f8d49b1ec221329c7aebcf050d3a0d482e71cde61190a33ca5aeb88b6b06276984e5a14253a98df232e8767167221a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347833fefd184533f1bce80a00000000000000000000000000000000000000000000000004aeb31823f6a1950c0c0f8c8f8c4a0dd1f0aba02c2bb3b5a2b6cb1cc907ea70912bd46dc7a78577f2cae6cdbcbe5f3a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347943854aaf203ba5f8d49b1ec221329c7aebcf050d3a058ab6df33d7cbeb6a735a7e4ccf4f28143e6a1742e45dda8f8cf48af43cb66c0a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347833fffd084533f1b9f80a0000000000000000000000000000000000000000000000000577042b0858b510bc0c0f8c8f8c4a0a287bb7da30f04344976abe569bd719f69c1cbea65533e5311ca5862e6eaa504a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347943854aaf203ba5f8d49b1ec221329c7aebcf050d3a07e0537009c23cb1152caf84a52272431f74b6140866b15805622b7bcb607cd42a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d4934783400fd384533f1b6180a000000000000000000000000000000000000000000000000083d31378a0993e1ac0c0f8c8f8c4a063483cff8fbd489e6ce273326d8dc1d54a31c67f936ca84bf500e5419d3e9805a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347943854aaf203ba5f8d49b1ec221329c7aebcf050d3a07737d08564819d51f8f834a6ee4278c23a0c2f29a3f485b21002c1f24f04d8e4a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347833fffd484533f1b5780a0000000000000000000000000000000000000000000000000bb586fe6de016e14c0c0f8c8f8c4a0975c8ed0c9197b7c018e02e1c95f315acf82b25e4a812140f4515e8bc827650ca01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347943854aaf203ba5f8d49b1ec221329c7aebcf050d3a0ad51229abead59e93c80db5ba160f0939bc49dcee65d1c081f6eb040ff1f571fa01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347833fefd984533f1b4e80a0000000000000000000000000000000000000000000000000548f02c6ceb26fd4c0c0f8c8f8c4a05844082e41f7c1f34485c7902afa0aa0979a6a849100fc553cd946f4a663929ca01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347943854aaf203ba5f8d49b1ec221329c7aebcf050d3a01bc726443437c4c062be18d052278e4ef735b8fe84387c8a4fc85fb70d5078e0a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347833fffd884533f1b1080a0000000000000000000000000000000000000000000000000cc1e528f54f22bdac0c0f8c8f8c4a0ba06ba81c93faaf98ea2d83cbdc0788958d938b29a9eb2a92ffbd4a628b3d52ea01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347943854aaf203ba5f8d49b1ec221329c7aebcf050d3a05053bfe1c0f1f0dd341c6df35e5a659989be041e8521027cc90f7605eb15fbb9a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347833fefdd84533f1b0380a0000000000000000000000000000000000000000000000000bcf9df2fec615ecac0c0f8c8f8c4a083732d997db15109e90464c24b7c959a78881d827c55a0d668a66a2736be5d87a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347943854aaf203ba5f8d49b1ec221329c7aebcf050d3a054f4012cba33a2b80b0dca9dd52f56b2c588133bd71700863f8cb95127176634a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347833fffdc84533f1a4680a00000000000000000000000000000000000000000000000006920a1dc9d915d0ec0c0f8c8f8c4a052e2fba761c2d0643170ef041c017391e781190fe715ae87cdae8eee1d45d95ba01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347943854aaf203ba5f8d49b1ec221329c7aebcf050d3a0ee2c82f77d7afd1f8dbe4f791df8477496c23e5504b9d66814172077f65f81f2a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347833fefe184533f1a3880a0000000000000000000000000000000000000000000000000ae86da9012398fc4c0c0f8c8f8c4a055703ba09544f386966b6d63bfc31033b761a4d1a6bb86b0cf49b4bb0526744ea01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347943854aaf203ba5f8d49b1ec221329c7aebcf050d3a01684c03a675b53786f0077d1651c3d169a009b13a6ee2b5047be6dbbe6d957ffa01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347833fdfea84533f1a2f80a00000000000000000000000000000000000000000000000003247320d0eb639dfc0c0f8c8f8c4a05109a79b33d81f4ee4814b550fb0002f03368d67570f6d4e6105fce2874d8b72a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347943854aaf203ba5f8d49b1ec221329c7aebcf050d3a0ae72e8c60a3dcfd53deecdb2790d18f0cc710f77cf2c1ed76e7da829bde619dca01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347833fcff784533f1a1d80a000000000000000000000000000000000000000000000000040e0bc9bc9bcf295c0c0f8c8f8c4a03961e4bbba5c95fad3db0cffa3a16b9106f9ea3e8957993eab576b683c22f416a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347943854aaf203ba5f8d49b1ec221329c7aebcf050d3a0e9c6cf457bbe64d6bda67852a276cdbadb4f384a36d496e81801a496cfd9b7b5a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347833fdfee84533f19df80a0000000000000000000000000000000000000000000000000dbb3fd6c816776d8c0c0f8c8f8c4a06b8265a357cb3ad744e19f04eb15377f660c10c900cc352d24f9b09073a363d6a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347943854aaf203ba5f8d49b1ec221329c7aebcf050d3a07ba07e1bc6a20ffa44ae6080d30982b9faa148faf6b1ec15e32d89ac853ac291a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347833fefe984533f198d80a00000000000000000000000000000000000000000000000005171325b6a2f17f1c0c0f8c8f8c4a0dcdc0347bb87ce72d49ac2e4e11f89069509b129a2536bf3d57c6bca30894032a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347943854aaf203ba5f8d49b1ec221329c7aebcf050d3a0ca24447aa0cedb4b561c7810461eef19b16a827c27352e5e01f914e9d7c78247a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347833fffe884533f194680a0000000000000000000000000000000000000000000000000da4714cfed9d8bbcc0c0f8c8f8c4a047f2dd6c15ea4082b3e11e5cf6b925b27e51d9de68051a093e52ef465cffbb8ca01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347943854aaf203ba5f8d49b1ec221329c7aebcf050d3a05a7206edddf50fcfeeaa97348a7112fc6edd0b5eacb44cf43d6a6c6b6609b459a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347833fefed84533f193e80a0000000000000000000000000000000000000000000000000ffafba4bf8dc944ec0c0f8c8f8c4a04d5ad6d860772145872f6660ecefcb0b0b2056e0aa3509a48bf4c175459e5121a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347943854aaf203ba5f8d49b1ec221329c7aebcf050d3a00f4659d09bb2ced56e7fd9c4d3d90daca8b4f471307b7c4385fd34a41016b0b2a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347833fdff684533f192580a000000000000000000000000000000000000000000000000090620e5e59a39fe5c0c0f8c8f8c4a0c1725c58d1bf023af468e0088db3cf642ae097cf2c58c2ece2fc746980acc7e6a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347943854aaf203ba5f8d49b1ec221329c7aebcf050d3a0be19a182ea1584050deb0a79abdc11be896ce8d00a282bcfaf9ffcd65fd64d6aa01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347833feff184533f189080a000000000000000000000000000000000000000000000000076f17f4199bccd12c0c0f8c8f8c4a0bd521a20a18ca6ca7115065065a1aa20067ee580fb11e2963d1e3a681e8302afa01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347943854aaf203ba5f8d49b1ec221329c7aebcf050d3a011be45633350e39475a1a07712ba72de4602d9eebf639ccd5422a389095ccaf1a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347833fdffa84533f187b80a00000000000000000000000000000000000000000000000000c71b81c4a4cb82cc0c0f8c8f8c4a07c6d2d56e9c87f1553e4d06705af61a7c19a6046d2c39f8ed1417988783d3b1da01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347943854aaf203ba5f8d49b1ec221329c7aebcf050d3a012f5f0668063509e33a45a64eb6a072b2d84aa19f430f49f159be5008a786b2ea01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347833fd00684533f186080a0000000000000000000000000000000000000000000000000b3f962892cfec9e6c0c0f8c8f8c4a07154f0f8ecc7f791d22eec06ec86d87a44b2704f015b3d2cff3571a3d01ae0f6a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347943854aaf203ba5f8d49b1ec221329c7aebcf050d3a079536abf8e163cf8aa97f0d52866d04363902d591fd7c36aa35fc983d45fefd6a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347833fdffd84533f182f80a0000000000000000000000000000000000000000000000000736716e42499890fc0c0f8c8f8c4a0bf2fb1ee988ac4e17eae221a24176649774333fab25b6fc96c6081527fb6f121a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347943854aaf203ba5f8d49b1ec221329c7aebcf050d3a041578daae7bcccd4976340aeb19e4132d2fe4193a0d92f87744c82bfe113502fa01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347833fd00984533f182b80a00000000000000000000000000000000000000000000000001c62fa76645942c6c0c0f8c8f8c4a07f84873e2679d40458b9dda9900478a78871044e08f6b47dad659b9b60ff8d48a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347943854aaf203ba5f8d49b1ec221329c7aebcf050d3a0597d3f4160770c0492333f90bad739dc05117d0e478a91f09573742e432904e8a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347833fe00184533f17f680a0000000000000000000000000000000000000000000000000e24d8b1140fb34d5c0c0f8c8f8c4a0fd77bd13a8cde1766537febe751a27a2a31310a04638a1afcd5e8ad3c5485453a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347943854aaf203ba5f8d49b1ec221329c7aebcf050d3a0473b2b248d91010ba9aec2696ffc93c11c415ed132832be0fd0578f184862e13a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347833feffc84533f17ca80a0000000000000000000000000000000000000000000000000fb5b65bac3f0d947c0c0f8c8f8c4a0518916dfb79c390bd7bff75712174512c2f96bec42a3f573355507ad1588ce0ca01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347943854aaf203ba5f8d49b1ec221329c7aebcf050d3a08599d2ec9e95ec62f41a4975b655d8445d6767035f94eb235ed5ebea976fb9eaa01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347833fe00484533f17b880a0000000000000000000000000000000000000000000000000bc27f4b8a201476bc0c0f90319f8c4a0ab6b9a5613970faa771b12d449b2e9bb925ab7a369f0a4b86b286e9d540099cfa01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347943854aaf203ba5f8d49b1ec221329c7aebcf050d3a0990dc3b5acbee04124361d958fe51acb582593613fc290683940a0769549d3eda09bfe4817d274ea3eb8672e9fe848c3885b53bbbd1d7c26e6039f90fb96b942b0833ff00084533f16b780a000000000000000000000000000000000000000000000000077377adff6c227dbf9024ff89d80809400000000000000000000000000000000000000008609184e72a000822710b3606956330c0d630000003359366000530a0d630000003359602060005301356000533557604060005301600054630000000c5884336069571ca07f6eb94576346488c6253197bde6a7e59ddc36f2773672c849402aa9c402c3c4a06d254e662bf7450dd8d835160cbb053463fed0b53f2cdd7f3ea8731919c8e8ccf9010501809400000000000000000000000000000000000000008609184e72a000822710b85336630000002e59606956330c0d63000000155933ff33560d63000000275960003356576000335700630000005358600035560d630000003a590033560d63000000485960003356573360003557600035335700b84a7f4e616d65526567000000000000000000000000000000000000000000000000003057307f4e616d655265670000000000000000000000000000000000000000000000000057336069571ba04af15a0ec494aeac5b243c8a2690833faa74c0f73db1f439d521c49c381513e9a05802e64939be5a1f9d4d614038fbd5479538c48795614ef9c551477ecbdb49d2f8a6028094ccdeac59d35627b7de09332e819d5159e7bb72508609184e72a000822710b84000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002d0aceee7e5ab874e22ccf8d1a649f59106d74e81ba0d05887574456c6de8f7a0d172342c2cbdd4cf7afe15d9dbb8b75b748ba6791c9a01e87172a861f6c37b5a9e3a5d0d7393152a7fbe41530e5bb8ac8f35433e5931bc0"; byte[] payload = Hex.decode(blocksMsg); - RLPList rlpList = new RLPList(); - RLP.parseObjects(payload, rlpList); + RLPList rlpList = RLP.decode2(payload); RLPList.recursivePrint(rlpList); // TODO: add some asserts in place of just printing the rlpList @@ -301,10 +298,384 @@ public class RLPTest { String helloMsg= "f8 91 80 0b 80 b8 46 45 74 68 65 72 65 75 6d 28 2b 2b 29 2f 5a 65 72 6f 47 6f 78 2e 70 72 69 63 6b 6c 79 5f 6d 6f 72 73 65 2f 76 30 2e 34 2e 32 2f 52 65 6c 65 61 73 65 2d 57 69 6e 33 32 2f 57 69 6e 64 6f 77 73 2f 56 53 32 30 31 33 07 82 76 5f b8 40 ea 99 2c 13 68 7c 20 e7 90 a9 ff a6 df 8b 1a 16 86 88 e2 a8 87 36 5d 7a 50 21 86 fa 0d 62 20 e8 3e 11 3a 1f e7 7d c0 68 9d 55 ba 2e 8a 83 aa 8e 20 42 18 f4 d8 e7 32 82 5b d7 80 cf 94 ed 5c c3"; byte[] payload = Hex.decode(helloMsg); - RLPList rlpList = new RLPList(); - RLP.parseObjects(payload, rlpList); + RLPList rlpList = RLP.decode2(payload); RLPList.recursivePrint(rlpList); // TODO: add some asserts in place of just printing the rlpList } + + /************************************ + * Test data from: https://github.com/ethereum/wiki/wiki/%5BEnglish%5D-RLP + * + * Using assertEquals(String, String) instead of assertArrayEquals to see the actual content when the test fails. + */ + @Test(expected = RuntimeException.class) + public void testEncodeNull() { + RLP.encode(null); + } + + @Test + public void testEncodeEmptyString() { + String test = ""; + String expected = "80"; + byte[] encoderesult = RLP.encode(test); + assertEquals(expected, asHex(encoderesult)); + + byte[] decodeResult = (byte[]) RLP.decode(encoderesult, 0).getDecoded(); + assertEquals(test, bytesToAscii(decodeResult)); + } + + @Test + public void testEncodeShortString() { + String test = "dog"; + String expected = "83646f67"; + byte[] encoderesult = RLP.encode(test); + assertEquals(expected, asHex(encoderesult)); + + byte[] decodeResult = (byte[]) RLP.decode(encoderesult, 0).getDecoded(); + assertEquals(test, bytesToAscii(decodeResult)); + } + + @Test + public void testEncodeSingleCharacter() { + String test = "d"; + String expected = "64"; + byte[] encoderesult = RLP.encode(test); + assertEquals(expected, asHex(encoderesult)); + + byte[] decodeResult = (byte[]) RLP.decode(encoderesult, 0).getDecoded(); + assertEquals(test, bytesToAscii(decodeResult)); + } + + @Test + public void testEncodeLongString() { + String test = "Lorem ipsum dolor sit amet, consectetur adipisicing elit"; // length = 56 + String expected = "b8384c6f72656d20697073756d20646f6c6f722073697420616d65742c20636f6e7365637465747572206164697069736963696e6720656c6974"; + byte[] encoderesult = RLP.encode(test); + assertEquals(expected, asHex(encoderesult)); + + byte[] decodeResult = (byte[]) RLP.decode(encoderesult, 0).getDecoded(); + assertEquals(test, bytesToAscii(decodeResult)); + } + + @Test + public void testEncodeZero() { + Integer test = new Integer(0); + String expected = "80"; + byte[] encoderesult = RLP.encode(test); + assertEquals(expected, asHex(encoderesult)); + + byte[] decodeResult = (byte[]) RLP.decode(encoderesult, 0).getDecoded(); + int result = toInt(decodeResult); + assertEquals(test, Integer.valueOf(result)); + } + + @Test + public void testEncodeSmallInteger() { + Integer test = new Integer(15); + String expected = "0f"; + byte[] encoderesult = RLP.encode(test); + assertEquals(expected, asHex(encoderesult)); + + byte[] decodeResult = (byte[]) RLP.decode(encoderesult, 0).getDecoded(); + int result = toInt(decodeResult); + assertEquals(test, Integer.valueOf(result)); + } + + @Test + public void testEncodeMediumInteger() { + Integer test = new Integer(1000); + String expected = "8203e8"; + byte[] encoderesult = RLP.encode(test); + assertEquals(expected, asHex(encoderesult)); + + byte[] decodeResult = (byte[]) RLP.decode(encoderesult, 0).getDecoded(); + int result = toInt(decodeResult); + assertEquals(test, Integer.valueOf(result)); + + test = new Integer(1024); + expected = "820400"; + encoderesult = RLP.encode(test); + assertEquals(expected, asHex(encoderesult)); + + decodeResult = (byte[]) RLP.decode(encoderesult, 0).getDecoded(); + result = toInt(decodeResult); + assertEquals(test, Integer.valueOf(result)); + } + + @Test + public void testEncodeBigInteger() { + BigInteger test = new BigInteger("100102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", 16); + String expected = "a0100102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f"; + byte[] encoderesult = RLP.encode(test); + assertEquals(expected, asHex(encoderesult)); + + byte[] decodeResult = (byte[]) RLP.decode(encoderesult, 0).getDecoded(); + assertEquals(test, new BigInteger(decodeResult)); + } + + @Test + public void TestEncodeEmptyList() { + String[] test = new String[0]; + String expected = "c0"; + byte[] encoderesult = RLP.encode(test); + assertEquals(expected, asHex(encoderesult)); + + Object[] decodeResult = (Object[]) RLP.decode(encoderesult, 0).getDecoded(); + assertTrue(decodeResult.length == 0); + } + + @Test + public void testEncodeShortStringList() { + String[] test = new String[] { "cat", "dog" }; + String expected = "c88363617483646f67"; + byte[] encoderesult = RLP.encode(test); + assertEquals(expected, asHex(encoderesult)); + + Object[] decodeResult = (Object[]) RLP.decode(encoderesult, 0).getDecoded(); + assertEquals("cat", bytesToAscii((byte[]) decodeResult[0])); + assertEquals("dog", bytesToAscii((byte[]) decodeResult[1])); + + test = new String[] { "dog", "god", "cat" }; + expected = "cc83646f6783676f6483636174"; + encoderesult = RLP.encode(test); + assertEquals(expected, asHex(encoderesult)); + + decodeResult = (Object[]) RLP.decode(encoderesult, 0).getDecoded(); + assertEquals("dog", bytesToAscii((byte[]) decodeResult[0])); + assertEquals("god", bytesToAscii((byte[]) decodeResult[1])); + assertEquals("cat", bytesToAscii((byte[]) decodeResult[2])); + } + + @Test + public void testEncodeLongStringList() { + String element1 = "cat"; + String element2 = "Lorem ipsum dolor sit amet, consectetur adipisicing elit"; + String[] test = new String[] { element1, element2 }; + String expected = "f83e83636174b8384c6f72656d20697073756d20646f6c6f722073697420616d65742c20636f6e7365637465747572206164697069736963696e6720656c6974"; + byte[] encoderesult = (byte[]) RLP.encode(test); + assertEquals(expected, asHex(encoderesult)); + + Object[] decodeResult = (Object[]) RLP.decode(encoderesult, 0).getDecoded(); + assertEquals(element1, bytesToAscii((byte[]) decodeResult[0])); + assertEquals(element2, bytesToAscii((byte[]) decodeResult[1])); + } + + //multilist: + //in: [ 1, ["cat"], "dog", [ 2 ] ], + //out: "cc01c48363617483646f67c102" + //in: [ [ ["cat"], ["dog"] ], [ [1] [2] ], [] ], + //out: "cdc88363617483646f67c20102c0" + @Test + public void testEncodeMultiList() { + Object[] test = new Object[] { 1, new Object[] { "cat" }, "dog", new Object[] { 2 } }; + String expected = "cc01c48363617483646f67c102"; + byte[] encoderesult = RLP.encode(test); + assertEquals(expected, asHex(encoderesult)); + + Object[] decodeResult = (Object[]) RLP.decode(encoderesult, 0).getDecoded(); + assertEquals(1, toInt( (byte[]) decodeResult[0] )); + assertEquals("cat", bytesToAscii( ((byte[]) ((Object[]) decodeResult[1])[0] ))); + assertEquals("dog", bytesToAscii( (byte[]) decodeResult[2])); + assertEquals(2, toInt( ((byte[]) ((Object[]) decodeResult[3])[0] ))); + + test = new Object[] { new Object[] { "cat", "dog" }, new Object[] { 1, 2 }, new Object[] { } }; + expected = "cdc88363617483646f67c20102c0"; + encoderesult = RLP.encode(test); + assertEquals(expected, asHex(encoderesult)); + + decodeResult = (Object[]) RLP.decode(encoderesult, 0).getDecoded(); + assertEquals("cat", bytesToAscii( ((byte[]) ((Object[]) decodeResult[0])[0] ))); + assertEquals("dog", bytesToAscii( ((byte[]) ((Object[]) decodeResult[0])[1] ))); + assertEquals(1, toInt( ((byte[]) ((Object[]) decodeResult[1])[0] ))); + assertEquals(2, toInt( ((byte[]) ((Object[]) decodeResult[1])[1] ))); + assertTrue( ( ((Object[]) decodeResult[2]).length == 0 )); + } + + @Test + public void testEncodeEmptyListOfList() { + // list = [ [ [], [] ], [] ], + Object[] test = new Object[] { new Object[] { new Object[] {}, new Object[] {} }, new Object[] {} }; + String expected = "c4c2c0c0c0"; + byte[] encoderesult = RLP.encode(test); + assertEquals(expected, asHex(encoderesult)); + + Object[] decodeResult = (Object[]) RLP.decode(encoderesult, 0).getDecoded(); + assertTrue( decodeResult.length == 2 ); + assertTrue( ( (Object[]) (decodeResult[0] ) ).length == 2); + assertTrue( ( (Object[]) (decodeResult[1] ) ).length == 0); + assertTrue( ( (Object[]) ( (Object[]) ( decodeResult[0] ) )[0]).length == 0); + assertTrue( ( (Object[]) ( (Object[]) ( decodeResult[0] ) )[1]).length == 0); + } + + //The set theoretical representation of two + @Test + public void testEncodeRepOfTwoListOfList() { + //list: [ [], [[]], [ [], [[]] ] ] + Object[] test = new Object[] { new Object[] { }, new Object[] { new Object[] {} }, new Object[] { new Object[] {}, new Object[] { new Object[] { } } } }; + String expected = "c7c0c1c0c3c0c1c0"; + byte[] encoderesult = RLP.encode(test); + assertEquals(expected, asHex(encoderesult)); + + Object[] decodeResult = (Object[]) RLP.decode(encoderesult, 0).getDecoded(); + assertTrue( decodeResult.length == 3 ); + assertTrue( ( (Object[]) (decodeResult[0]) ).length == 0); + assertTrue( ( (Object[]) (decodeResult[1]) ).length == 1); + assertTrue( ( (Object[]) (decodeResult[2]) ).length == 2); + assertTrue( ( (Object[]) ( (Object[]) (decodeResult[1]) )[0]).length == 0); + assertTrue( ( (Object[]) ( (Object[]) (decodeResult[2]) )[0]).length == 0); + assertTrue( ( (Object[]) ( (Object[]) (decodeResult[2]) )[1]).length == 1); + assertTrue( ( (Object[]) ( (Object[]) ( (Object[]) (decodeResult[2]) )[1] )[0]).length == 0); + } + + @Test + public void testRlpEncode() { + + assertEquals(result01, asHex(RLP.encode(test01))); + assertEquals(result02, asHex(RLP.encode(test02))); + assertEquals(result03, asHex(RLP.encode(test03))); + assertEquals(result04, asHex(RLP.encode(test04))); + assertEquals(result05, asHex(RLP.encode(test05))); + assertEquals(result06, asHex(RLP.encode(test06))); + assertEquals(result07, asHex(RLP.encode(test07))); + assertEquals(result08, asHex(RLP.encode(test08))); + assertEquals(result09, asHex(RLP.encode(test09))); + assertEquals(result10, asHex(RLP.encode(test10))); + assertEquals(result11, asHex(RLP.encode(test11))); + assertEquals(result12, asHex(RLP.encode(test12))); + assertEquals(result13, asHex(RLP.encode(test13))); + assertEquals(result14, asHex(RLP.encode(test14))); + assertEquals(result15, asHex(RLP.encode(test15))); + assertEquals(result16, asHex(RLP.encode(test16))); + } + + @Test + public void testRlpDecode() { + int pos = 0; + byte[] decodedByte; + byte[] decodedData; + Object[] decodedList; + + decodedByte = (byte[]) RLP.decode(fromHex(result01), pos).getDecoded(); + assertEquals(test01, toInt(decodedByte)); + + decodedData = (byte[]) RLP.decode(fromHex(result02), pos).getDecoded(); + assertEquals(test02, bytesToAscii(decodedData)); + + decodedData = (byte[]) RLP.decode(fromHex(result03), pos).getDecoded(); + assertEquals(test03, bytesToAscii(decodedData)); + + decodedData = (byte[]) RLP.decode(fromHex(result04), pos).getDecoded(); + assertEquals(test04, bytesToAscii(decodedData)); + + decodedData = (byte[]) RLP.decode(fromHex(result05), pos).getDecoded(); + assertEquals(test05, bytesToAscii(decodedData)); + + decodedList = (Object[]) RLP.decode(fromHex(result06), pos).getDecoded(); + assertEquals(test06[0], bytesToAscii((byte[]) decodedList[0])); + assertEquals(test06[1], bytesToAscii((byte[]) decodedList[1])); + + decodedList = (Object[]) RLP.decode(fromHex(result07), pos).getDecoded(); + assertEquals(test07[0], bytesToAscii((byte[]) decodedList[0])); + assertEquals(test07[1], bytesToAscii((byte[]) decodedList[1])); + assertEquals(test07[2], bytesToAscii((byte[]) decodedList[2])); + + // 1 + decodedData = (byte[]) RLP.decode(fromHex(result08), pos).getDecoded(); + assertEquals(test08, toInt(decodedData)); + + // 10 + decodedData = (byte[]) RLP.decode(fromHex(result09), pos).getDecoded(); + assertEquals(test09, toInt(decodedData)); + + // 100 + decodedData = (byte[]) RLP.decode(fromHex(result10), pos).getDecoded(); + assertEquals(test10, toInt(decodedData)); + + // 1000 + decodedData = (byte[]) RLP.decode(fromHex(result11), pos).getDecoded(); + assertEquals(test11, toInt(decodedData)); + + decodedData = (byte[]) RLP.decode(fromHex(result12), pos).getDecoded(); + assertTrue(test12.compareTo(new BigInteger(decodedData)) == 0); + + decodedData = (byte[]) RLP.decode(fromHex(result13), pos).getDecoded(); + assertTrue(test13.compareTo(new BigInteger(decodedData)) == 0); + + // Need to test with different expected value, because decoding doesn't recognize types + Object testObject1 = RLP.decode(fromHex(result14), pos).getDecoded(); + assertTrue(DeepEquals.deepEquals(expected14, testObject1)); + + Object testObject2 = RLP.decode(fromHex(result15), pos).getDecoded(); + assertTrue(DeepEquals.deepEquals(test15, testObject2)); + + // Need to test with different expected value, because decoding doesn't recognize types + Object testObject3 = RLP.decode(fromHex(result16), pos).getDecoded(); + assertTrue(DeepEquals.deepEquals(expected16, testObject3)); + } + + @Test + public void testEncodeLength() { + int length; + int offset; + byte[] encodedLength; + String expected; + + // length < 56 + length = 1; offset = 128; + encodedLength = RLP.encodeLength(length, offset); + expected = "81"; + assertEquals(expected, asHex(encodedLength)); + + // 56 > length < 2^64 + length = 56; offset = 192; + encodedLength = RLP.encodeLength(length, offset); + expected = "f838"; + assertEquals(expected, asHex(encodedLength)); + + // length > 2^64 + // TODO: Fix this test - when casting double to int, information gets lost since 'int' is max (2^31)-1 + double maxLength = Math.pow(256, 8); offset = 192; + try { + encodedLength = RLP.encodeLength( (int) maxLength, offset); + System.out.println("length: " + length + ", offset: " + offset + ", encoded: " + Arrays.toString(encodedLength)); + fail("Expecting RuntimeException: 'Input too long'"); + } catch(RuntimeException e) { + // Success! + } + } + + // Code from: http://stackoverflow.com/a/9855338/459349 + protected final static char[] hexArray = "0123456789abcdef".toCharArray(); + private static String asHex(byte[] bytes) { + char[] hexChars = new char[bytes.length * 2]; + for ( int j = 0; j < bytes.length; j++ ) { + int v = bytes[j] & 0xFF; + hexChars[j * 2] = hexArray[v >>> 4]; + hexChars[j * 2 + 1] = hexArray[v & 0x0F]; + } + return new String(hexChars); + } + + // Code from: http://stackoverflow.com/a/4785776/459349 + private String bytesToAscii(byte[] b) { + String hex = asHex(b); + StringBuilder output = new StringBuilder(); + for (int i = 0; i < hex.length(); i+=2) { + String str = hex.substring(i, i+2); + output.append((char)Integer.parseInt(str, 16)); + } + return output.toString(); + } + + // Code from: http://stackoverflow.com/a/140861/459349 + public static byte[] fromHex(String s) { + int len = s.length(); + byte[] data = new byte[len / 2]; + for (int i = 0; i < len; i += 2) { + data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4) + + Character.digit(s.charAt(i+1), 16)); + } + return data; + } } \ No newline at end of file diff --git a/ethereumj-core/src/test/java/org/ethereum/util/RlpEncoderTest.java b/ethereumj-core/src/test/java/org/ethereum/util/RlpEncoderTest.java deleted file mode 100644 index 25ed44e7..00000000 --- a/ethereumj-core/src/test/java/org/ethereum/util/RlpEncoderTest.java +++ /dev/null @@ -1,425 +0,0 @@ -package org.ethereum.util; - -import static org.ethereum.util.RlpEncoder.toInt; -import static org.ethereum.util.RlpTestData.expected14; -import static org.ethereum.util.RlpTestData.expected16; -import static org.ethereum.util.RlpTestData.result01; -import static org.ethereum.util.RlpTestData.result02; -import static org.ethereum.util.RlpTestData.result03; -import static org.ethereum.util.RlpTestData.result04; -import static org.ethereum.util.RlpTestData.result05; -import static org.ethereum.util.RlpTestData.result06; -import static org.ethereum.util.RlpTestData.result07; -import static org.ethereum.util.RlpTestData.result08; -import static org.ethereum.util.RlpTestData.result09; -import static org.ethereum.util.RlpTestData.result10; -import static org.ethereum.util.RlpTestData.result11; -import static org.ethereum.util.RlpTestData.result12; -import static org.ethereum.util.RlpTestData.result13; -import static org.ethereum.util.RlpTestData.result14; -import static org.ethereum.util.RlpTestData.result15; -import static org.ethereum.util.RlpTestData.result16; -import static org.ethereum.util.RlpTestData.test01; -import static org.ethereum.util.RlpTestData.test02; -import static org.ethereum.util.RlpTestData.test03; -import static org.ethereum.util.RlpTestData.test04; -import static org.ethereum.util.RlpTestData.test05; -import static org.ethereum.util.RlpTestData.test06; -import static org.ethereum.util.RlpTestData.test07; -import static org.ethereum.util.RlpTestData.test08; -import static org.ethereum.util.RlpTestData.test09; -import static org.ethereum.util.RlpTestData.test10; -import static org.ethereum.util.RlpTestData.test11; -import static org.ethereum.util.RlpTestData.test12; -import static org.ethereum.util.RlpTestData.test13; -import static org.ethereum.util.RlpTestData.test14; -import static org.ethereum.util.RlpTestData.test15; -import static org.ethereum.util.RlpTestData.test16; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -import java.math.BigInteger; -import java.util.Arrays; - -import org.junit.Test; - -import com.cedarsoftware.util.DeepEquals; - -public class RlpEncoderTest { - - /************************************ - * Test data from: https://github.com/ethereum/wiki/wiki/%5BEnglish%5D-RLP - * - * Using assertEquals(String, String) instead of assertArrayEquals to see the actual content when the test fails. - */ - @Test(expected = RuntimeException.class) - public void testEncodeNull() { - RlpEncoder.encode(null); - } - - @Test - public void testEncodeEmptyString() { - String test = ""; - String expected = "80"; - byte[] encoderesult = RlpEncoder.encode(test); - assertEquals(expected, asHex(encoderesult)); - - byte[] decodeResult = (byte[]) RlpEncoder.decode(encoderesult, 0).getDecoded(); - assertEquals(test, bytesToAscii(decodeResult)); - } - - @Test - public void testEncodeShortString() { - String test = "dog"; - String expected = "83646f67"; - byte[] encoderesult = RlpEncoder.encode(test); - assertEquals(expected, asHex(encoderesult)); - - byte[] decodeResult = (byte[]) RlpEncoder.decode(encoderesult, 0).getDecoded(); - assertEquals(test, bytesToAscii(decodeResult)); - } - - @Test - public void testEncodeSingleCharacter() { - String test = "d"; - String expected = "64"; - byte[] encoderesult = RlpEncoder.encode(test); - assertEquals(expected, asHex(encoderesult)); - - byte[] decodeResult = (byte[]) RlpEncoder.decode(encoderesult, 0).getDecoded(); - assertEquals(test, bytesToAscii(decodeResult)); - } - - @Test - public void testEncodeLongString() { - String test = "Lorem ipsum dolor sit amet, consectetur adipisicing elit"; // length = 56 - String expected = "b8384c6f72656d20697073756d20646f6c6f722073697420616d65742c20636f6e7365637465747572206164697069736963696e6720656c6974"; - byte[] encoderesult = RlpEncoder.encode(test); - assertEquals(expected, asHex(encoderesult)); - - byte[] decodeResult = (byte[]) RlpEncoder.decode(encoderesult, 0).getDecoded(); - assertEquals(test, bytesToAscii(decodeResult)); - } - - @Test - public void testEncodeZero() { - Integer test = new Integer(0); - String expected = "80"; - byte[] encoderesult = RlpEncoder.encode(test); - assertEquals(expected, asHex(encoderesult)); - - byte[] decodeResult = (byte[]) RlpEncoder.decode(encoderesult, 0).getDecoded(); - int result = toInt(decodeResult); - assertEquals(test, Integer.valueOf(result)); - } - - @Test - public void testEncodeSmallInteger() { - Integer test = new Integer(15); - String expected = "0f"; - byte[] encoderesult = RlpEncoder.encode(test); - assertEquals(expected, asHex(encoderesult)); - - byte[] decodeResult = (byte[]) RlpEncoder.decode(encoderesult, 0).getDecoded(); - int result = toInt(decodeResult); - assertEquals(test, Integer.valueOf(result)); - } - - @Test - public void testEncodeMediumInteger() { - Integer test = new Integer(1000); - String expected = "8203e8"; - byte[] encoderesult = RlpEncoder.encode(test); - assertEquals(expected, asHex(encoderesult)); - - byte[] decodeResult = (byte[]) RlpEncoder.decode(encoderesult, 0).getDecoded(); - int result = toInt(decodeResult); - assertEquals(test, Integer.valueOf(result)); - - test = new Integer(1024); - expected = "820400"; - encoderesult = RlpEncoder.encode(test); - assertEquals(expected, asHex(encoderesult)); - - decodeResult = (byte[]) RlpEncoder.decode(encoderesult, 0).getDecoded(); - result = toInt(decodeResult); - assertEquals(test, Integer.valueOf(result)); - } - - @Test - public void testEncodeBigInteger() { - BigInteger test = new BigInteger("100102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", 16); - String expected = "a0100102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f"; - byte[] encoderesult = RlpEncoder.encode(test); - assertEquals(expected, asHex(encoderesult)); - - byte[] decodeResult = (byte[]) RlpEncoder.decode(encoderesult, 0).getDecoded(); - assertEquals(test, new BigInteger(decodeResult)); - } - - @Test - public void TestEncodeEmptyList() { - String[] test = new String[0]; - String expected = "c0"; - byte[] encoderesult = RlpEncoder.encode(test); - assertEquals(expected, asHex(encoderesult)); - - Object[] decodeResult = (Object[]) RlpEncoder.decode(encoderesult, 0).getDecoded(); - assertTrue(decodeResult.length == 0); - } - - @Test - public void testEncodeShortStringList() { - String[] test = new String[] { "cat", "dog" }; - String expected = "c88363617483646f67"; - byte[] encoderesult = RlpEncoder.encode(test); - assertEquals(expected, asHex(encoderesult)); - - Object[] decodeResult = (Object[]) RlpEncoder.decode(encoderesult, 0).getDecoded(); - assertEquals("cat", bytesToAscii((byte[]) decodeResult[0])); - assertEquals("dog", bytesToAscii((byte[]) decodeResult[1])); - - test = new String[] { "dog", "god", "cat" }; - expected = "cc83646f6783676f6483636174"; - encoderesult = RlpEncoder.encode(test); - assertEquals(expected, asHex(encoderesult)); - - decodeResult = (Object[]) RlpEncoder.decode(encoderesult, 0).getDecoded(); - assertEquals("dog", bytesToAscii((byte[]) decodeResult[0])); - assertEquals("god", bytesToAscii((byte[]) decodeResult[1])); - assertEquals("cat", bytesToAscii((byte[]) decodeResult[2])); - } - - @Test - public void testEncodeLongStringList() { - String element1 = "cat"; - String element2 = "Lorem ipsum dolor sit amet, consectetur adipisicing elit"; - String[] test = new String[] { element1, element2 }; - String expected = "f83e83636174b8384c6f72656d20697073756d20646f6c6f722073697420616d65742c20636f6e7365637465747572206164697069736963696e6720656c6974"; - byte[] encoderesult = (byte[]) RlpEncoder.encode(test); - assertEquals(expected, asHex(encoderesult)); - - Object[] decodeResult = (Object[]) RlpEncoder.decode(encoderesult, 0).getDecoded(); - assertEquals(element1, bytesToAscii((byte[]) decodeResult[0])); - assertEquals(element2, bytesToAscii((byte[]) decodeResult[1])); - } - - //multilist: - //in: [ 1, ["cat"], "dog", [ 2 ] ], - //out: "cc01c48363617483646f67c102" - //in: [ [ ["cat"], ["dog"] ], [ [1] [2] ], [] ], - //out: "cdc88363617483646f67c20102c0" - @Test - public void testEncodeMultiList() { - Object[] test = new Object[] { 1, new Object[] { "cat" }, "dog", new Object[] { 2 } }; - String expected = "cc01c48363617483646f67c102"; - byte[] encoderesult = RlpEncoder.encode(test); - assertEquals(expected, asHex(encoderesult)); - - Object[] decodeResult = (Object[]) RlpEncoder.decode(encoderesult, 0).getDecoded(); - assertEquals(1, toInt( (byte[]) decodeResult[0] )); - assertEquals("cat", bytesToAscii( ((byte[]) ((Object[]) decodeResult[1])[0] ))); - assertEquals("dog", bytesToAscii( (byte[]) decodeResult[2])); - assertEquals(2, toInt( ((byte[]) ((Object[]) decodeResult[3])[0] ))); - - test = new Object[] { new Object[] { "cat", "dog" }, new Object[] { 1, 2 }, new Object[] { } }; - expected = "cdc88363617483646f67c20102c0"; - encoderesult = RlpEncoder.encode(test); - assertEquals(expected, asHex(encoderesult)); - - decodeResult = (Object[]) RlpEncoder.decode(encoderesult, 0).getDecoded(); - assertEquals("cat", bytesToAscii( ((byte[]) ((Object[]) decodeResult[0])[0] ))); - assertEquals("dog", bytesToAscii( ((byte[]) ((Object[]) decodeResult[0])[1] ))); - assertEquals(1, toInt( ((byte[]) ((Object[]) decodeResult[1])[0] ))); - assertEquals(2, toInt( ((byte[]) ((Object[]) decodeResult[1])[1] ))); - assertTrue( ( ((Object[]) decodeResult[2]).length == 0 )); - } - - @Test - public void testEncodeEmptyListOfList() { - // list = [ [ [], [] ], [] ], - Object[] test = new Object[] { new Object[] { new Object[] {}, new Object[] {} }, new Object[] {} }; - String expected = "c4c2c0c0c0"; - byte[] encoderesult = RlpEncoder.encode(test); - assertEquals(expected, asHex(encoderesult)); - - Object[] decodeResult = (Object[]) RlpEncoder.decode(encoderesult, 0).getDecoded(); - assertTrue( decodeResult.length == 2 ); - assertTrue( ( (Object[]) (decodeResult[0] ) ).length == 2); - assertTrue( ( (Object[]) (decodeResult[1] ) ).length == 0); - assertTrue( ( (Object[]) ( (Object[]) ( decodeResult[0] ) )[0]).length == 0); - assertTrue( ( (Object[]) ( (Object[]) ( decodeResult[0] ) )[1]).length == 0); - } - - //The set theoretical representation of two - @Test - public void testEncodeRepOfTwoListOfList() { - //list: [ [], [[]], [ [], [[]] ] ] - Object[] test = new Object[] { new Object[] { }, new Object[] { new Object[] {} }, new Object[] { new Object[] {}, new Object[] { new Object[] { } } } }; - String expected = "c7c0c1c0c3c0c1c0"; - byte[] encoderesult = RlpEncoder.encode(test); - assertEquals(expected, asHex(encoderesult)); - - Object[] decodeResult = (Object[]) RlpEncoder.decode(encoderesult, 0).getDecoded(); - assertTrue( decodeResult.length == 3 ); - assertTrue( ( (Object[]) (decodeResult[0]) ).length == 0); - assertTrue( ( (Object[]) (decodeResult[1]) ).length == 1); - assertTrue( ( (Object[]) (decodeResult[2]) ).length == 2); - assertTrue( ( (Object[]) ( (Object[]) (decodeResult[1]) )[0]).length == 0); - assertTrue( ( (Object[]) ( (Object[]) (decodeResult[2]) )[0]).length == 0); - assertTrue( ( (Object[]) ( (Object[]) (decodeResult[2]) )[1]).length == 1); - assertTrue( ( (Object[]) ( (Object[]) ( (Object[]) (decodeResult[2]) )[1] )[0]).length == 0); - } - - @Test - public void testRlpEncode() { - - assertEquals(result01, asHex(RlpEncoder.encode(test01))); - assertEquals(result02, asHex(RlpEncoder.encode(test02))); - assertEquals(result03, asHex(RlpEncoder.encode(test03))); - assertEquals(result04, asHex(RlpEncoder.encode(test04))); - assertEquals(result05, asHex(RlpEncoder.encode(test05))); - assertEquals(result06, asHex(RlpEncoder.encode(test06))); - assertEquals(result07, asHex(RlpEncoder.encode(test07))); - assertEquals(result08, asHex(RlpEncoder.encode(test08))); - assertEquals(result09, asHex(RlpEncoder.encode(test09))); - assertEquals(result10, asHex(RlpEncoder.encode(test10))); - assertEquals(result11, asHex(RlpEncoder.encode(test11))); - assertEquals(result12, asHex(RlpEncoder.encode(test12))); - assertEquals(result13, asHex(RlpEncoder.encode(test13))); - assertEquals(result14, asHex(RlpEncoder.encode(test14))); - assertEquals(result15, asHex(RlpEncoder.encode(test15))); - assertEquals(result16, asHex(RlpEncoder.encode(test16))); - } - - @Test - public void testRlpDecode() { - int pos = 0; - byte[] decodedByte; - byte[] decodedData; - Object[] decodedList; - - decodedByte = (byte[]) RlpEncoder.decode(fromHex(result01), pos).getDecoded(); - assertEquals(test01, toInt(decodedByte)); - - decodedData = (byte[]) RlpEncoder.decode(fromHex(result02), pos).getDecoded(); - assertEquals(test02, bytesToAscii(decodedData)); - - decodedData = (byte[]) RlpEncoder.decode(fromHex(result03), pos).getDecoded(); - assertEquals(test03, bytesToAscii(decodedData)); - - decodedData = (byte[]) RlpEncoder.decode(fromHex(result04), pos).getDecoded(); - assertEquals(test04, bytesToAscii(decodedData)); - - decodedData = (byte[]) RlpEncoder.decode(fromHex(result05), pos).getDecoded(); - assertEquals(test05, bytesToAscii(decodedData)); - - decodedList = (Object[]) RlpEncoder.decode(fromHex(result06), pos).getDecoded(); - assertEquals(test06[0], bytesToAscii((byte[]) decodedList[0])); - assertEquals(test06[1], bytesToAscii((byte[]) decodedList[1])); - - decodedList = (Object[]) RlpEncoder.decode(fromHex(result07), pos).getDecoded(); - assertEquals(test07[0], bytesToAscii((byte[]) decodedList[0])); - assertEquals(test07[1], bytesToAscii((byte[]) decodedList[1])); - assertEquals(test07[2], bytesToAscii((byte[]) decodedList[2])); - - // 1 - decodedData = (byte[]) RlpEncoder.decode(fromHex(result08), pos).getDecoded(); - assertEquals(test08, toInt(decodedData)); - - // 10 - decodedData = (byte[]) RlpEncoder.decode(fromHex(result09), pos).getDecoded(); - assertEquals(test09, toInt(decodedData)); - - // 100 - decodedData = (byte[]) RlpEncoder.decode(fromHex(result10), pos).getDecoded(); - assertEquals(test10, toInt(decodedData)); - - // 1000 - decodedData = (byte[]) RlpEncoder.decode(fromHex(result11), pos).getDecoded(); - assertEquals(test11, toInt(decodedData)); - - decodedData = (byte[]) RlpEncoder.decode(fromHex(result12), pos).getDecoded(); - assertTrue(test12.compareTo(new BigInteger(decodedData)) == 0); - - decodedData = (byte[]) RlpEncoder.decode(fromHex(result13), pos).getDecoded(); - assertTrue(test13.compareTo(new BigInteger(decodedData)) == 0); - - // Need to test with different expected value, because decoding doesn't recognize types - Object testObject1 = RlpEncoder.decode(fromHex(result14), pos).getDecoded(); - assertTrue(DeepEquals.deepEquals(expected14, testObject1)); - - Object testObject2 = RlpEncoder.decode(fromHex(result15), pos).getDecoded(); - assertTrue(DeepEquals.deepEquals(test15, testObject2)); - - // Need to test with different expected value, because decoding doesn't recognize types - Object testObject3 = RlpEncoder.decode(fromHex(result16), pos).getDecoded(); - assertTrue(DeepEquals.deepEquals(expected16, testObject3)); - } - - @Test - public void testEncodeLength() { - int length; - int offset; - byte[] encodedLength; - String expected; - - // length < 56 - length = 1; offset = 128; - encodedLength = RlpEncoder.encodeLength(length, offset); - expected = "81"; - assertEquals(expected, asHex(encodedLength)); - - // 56 > length < 2^64 - length = 56; offset = 192; - encodedLength = RlpEncoder.encodeLength(length, offset); - expected = "f838"; - assertEquals(expected, asHex(encodedLength)); - - // length > 2^64 - // TODO: Fix this test - when casting double to int, information gets lost since 'int' is max (2^31)-1 - double maxLength = Math.pow(256, 8); offset = 192; - try { - encodedLength = RlpEncoder.encodeLength( (int) maxLength, offset); - System.out.println("length: " + length + ", offset: " + offset + ", encoded: " + Arrays.toString(encodedLength)); - fail("Expecting RuntimeException: 'Input too long'"); - } catch(RuntimeException e) { - // Success! - } - } - - // Code from: http://stackoverflow.com/a/9855338/459349 - protected final static char[] hexArray = "0123456789abcdef".toCharArray(); - private static String asHex(byte[] bytes) { - char[] hexChars = new char[bytes.length * 2]; - for ( int j = 0; j < bytes.length; j++ ) { - int v = bytes[j] & 0xFF; - hexChars[j * 2] = hexArray[v >>> 4]; - hexChars[j * 2 + 1] = hexArray[v & 0x0F]; - } - return new String(hexChars); - } - - // Code from: http://stackoverflow.com/a/4785776/459349 - private String bytesToAscii(byte[] b) { - String hex = asHex(b); - StringBuilder output = new StringBuilder(); - for (int i = 0; i < hex.length(); i+=2) { - String str = hex.substring(i, i+2); - output.append((char)Integer.parseInt(str, 16)); - } - return output.toString(); - } - - // Code from: http://stackoverflow.com/a/140861/459349 - public static byte[] fromHex(String s) { - int len = s.length(); - byte[] data = new byte[len / 2]; - for (int i = 0; i < len; i += 2) { - data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4) - + Character.digit(s.charAt(i+1), 16)); - } - return data; - } -}