Java Code Examples for org.ethereum.util.RLPList#size()

The following examples show how to use org.ethereum.util.RLPList#size() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PeersMessage.java    From ethereumj with MIT License 6 votes vote down vote up
private void parse() {
	RLPList paramsList = (RLPList) RLP.decode2(encoded).get(0);

	peers = new LinkedHashSet<>();
	for (int i = 1; i < paramsList.size(); ++i) {
		RLPList peerParams = (RLPList) paramsList.get(i);
		byte[] ipBytes = peerParams.get(0).getRLPData();
		byte[] portBytes = peerParams.get(1).getRLPData();
		byte[] peerIdRaw = peerParams.get(2).getRLPData();

		try {
			int peerPort = ByteUtil.byteArrayToInt(portBytes);
			InetAddress address = InetAddress.getByAddress(ipBytes);

               String peerId = peerIdRaw == null ? "" :  Hex.toHexString(peerIdRaw);
               Peer peer = new Peer(address, peerPort, peerId);
			peers.add(peer);
		} catch (UnknownHostException e) {
			throw new RuntimeException("Malformed ip", e);
		}
	}
	this.parsed = true;
}
 
Example 2
Source File: Block.java    From ethereumj with MIT License 6 votes vote down vote up
private void parseTxs(byte[] expectedRoot, RLPList txReceipts) {

        this.txsState = new TrieImpl(null);
        for (int i = 0; i < txReceipts.size(); i++) {
        	RLPElement rlpTxReceipt = txReceipts.get(i);
            RLPElement txData = ((RLPList)rlpTxReceipt).get(0);
            
            // YP 4.3.1
            RLPElement pstTxState = ((RLPList)rlpTxReceipt).get(1);
            RLPElement cummGas    = ((RLPList)rlpTxReceipt).get(2);

            Transaction tx = new Transaction(txData.getRLPData());
            this.transactionsList.add(tx);
            TransactionReceipt txReceipt =
                new TransactionReceipt(tx, pstTxState.getRLPData(), cummGas.getRLPData());
            this.addTxReceipt(i, txReceipt);
        }
        String calculatedRoot = Hex.toHexString(txsState.getRootHash());
        if(!calculatedRoot.equals(Hex.toHexString(expectedRoot)))
			logger.error("Added tx receipts don't match the given txsStateRoot");
    }
 
Example 3
Source File: GetBlocksMessage.java    From ethereumj with MIT License 5 votes vote down vote up
private void parse() {
	RLPList paramsList = (RLPList) RLP.decode2(encoded).get(0);

	blockHashes = new ArrayList<>();
	for (int i = 1; i < paramsList.size(); ++i) {
		blockHashes.add(((RLPItem) paramsList.get(i)).getRLPData());
	}
	parsed = true;
}
 
Example 4
Source File: BlockHashesMessage.java    From ethereumj with MIT License 5 votes vote down vote up
private void parse() {
	RLPList paramsList = (RLPList) RLP.decode2(encoded).get(0);

	blockHashes = new ArrayList<>();
	for (int i = 1; i < paramsList.size(); ++i) {
		RLPItem rlpData = ((RLPItem) paramsList.get(i));
		blockHashes.add(rlpData.getRLPData());
	}
	parsed = true;
}
 
Example 5
Source File: BlocksMessage.java    From ethereumj with MIT License 5 votes vote down vote up
private void parse() {
	RLPList paramsList = (RLPList) RLP.decode2(encoded).get(0);

	blocks = new ArrayList<>();
	for (int i = 1; i < paramsList.size(); ++i) {
		RLPList rlpData = ((RLPList) paramsList.get(i));
		Block blockData = new Block(rlpData.getRLPData());
		blocks.add(blockData);
	}
	parsed = true;
}
 
Example 6
Source File: TransactionsMessage.java    From ethereumj with MIT License 5 votes vote down vote up
private void parse() {
RLPList paramsList = (RLPList) RLP.decode2(encoded).get(0);

transactions = new HashSet<>();
      for (int i = 1; i < paramsList.size(); ++i) {
          RLPList rlpTxData = (RLPList) paramsList.get(i);
          Transaction tx = new Transaction(rlpTxData.getRLPData());
          transactions.add(tx);
      }
      parsed = true;
  }