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

The following examples show how to use org.ethereum.util.RLPList#get() . 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: Transaction.java    From wkcwallet-java with Apache License 2.0 6 votes vote down vote up
public void rlpParse() {
    RLPList decodedTxList = RLP.decode2(this.rlpEncoded);
    RLPList transaction = (RLPList)decodedTxList.get(0);
    this.nonce = ((RLPElement)transaction.get(0)).getRLPData();
    this.gasPrice = ((RLPElement)transaction.get(1)).getRLPData();
    this.gasLimit = ((RLPElement)transaction.get(2)).getRLPData();
    this.receiveAddress = ((RLPElement)transaction.get(3)).getRLPData();
    this.value = ((RLPElement)transaction.get(4)).getRLPData();
    this.data = ((RLPElement)transaction.get(5)).getRLPData();
    if(((RLPElement)transaction.get(6)).getRLPData() != null) {
        byte v = ((RLPElement)transaction.get(6)).getRLPData()[0];
        byte[] r = ((RLPElement)transaction.get(7)).getRLPData();
        byte[] s = ((RLPElement)transaction.get(8)).getRLPData();
        this.signature = ECKey.ECDSASignature.fromComponents(r, s, v);
    } else {
    }

    this.parsed = true;
    this.hash = this.getHash();
}
 
Example 2
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 3
Source File: Transaction.java    From ethereumj with MIT License 6 votes vote down vote up
public void rlpParse() {

        RLPList decodedTxList = RLP.decode2(rlpEncoded);
        RLPList transaction =  (RLPList) decodedTxList.get(0);

        this.nonce =          ((RLPItem) transaction.get(0)).getRLPData();
        this.gasPrice =       ((RLPItem) transaction.get(1)).getRLPData();
        this.gasLimit =       ((RLPItem) transaction.get(2)).getRLPData();
        this.receiveAddress = ((RLPItem) transaction.get(3)).getRLPData();
        this.value =          ((RLPItem) transaction.get(4)).getRLPData();

        this.data =     ((RLPItem) transaction.get(5)).getRLPData();
        // only parse signature in case tx is signed
        if(((RLPItem) transaction.get(6)).getRLPData() != null) {
            byte v =		((RLPItem) transaction.get(6)).getRLPData()[0];
            byte[] r =		((RLPItem) transaction.get(7)).getRLPData();
            byte[] s =		((RLPItem) transaction.get(8)).getRLPData();
            this.signature = ECDSASignature.fromComponents(r, s, v);
        } else {
            logger.debug("RLP encoded tx is not signed!");
        }
        this.parsed = true;
        this.hash  = this.getHash();
    }
 
Example 4
Source File: Block.java    From ethereumj with MIT License 6 votes vote down vote up
private void parseRLP() {

        RLPList params = RLP.decode2(rlpEncoded);
        RLPList block = (RLPList) params.get(0);
        
        // Parse Header
        RLPList header = (RLPList) block.get(0);
        this.header = new BlockHeader(header);
        
        // Parse Transactions
        RLPList txReceipts = (RLPList) block.get(1);
        this.parseTxs(this.header.getTxTrieRoot(), txReceipts);

        // Parse Uncles
        RLPList uncleBlocks = (RLPList) block.get(2);
        for (RLPElement rawUncle : uncleBlocks) {

            RLPList uncleHeader = (RLPList) rawUncle;
            BlockHeader blockData = new BlockHeader(uncleHeader);
            this.uncleList.add(blockData);
        }
        this.parsed = true;
    }
 
Example 5
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 6
Source File: JournalSource.java    From nuls-v2 with MIT License 5 votes vote down vote up
private void parse(byte[] encoded) {
    RLPList l = (RLPList) RLP.decode2(encoded).get(0);
    updateHash = l.get(0).getRLPData();

    for (RLPElement aRInserted : (RLPList) l.get(1)) {
        insertedKeys.add(aRInserted.getRLPData());
    }
    for (RLPElement aRDeleted : (RLPList) l.get(2)) {
        deletedKeys.add(aRDeleted.getRLPData());
    }
}
 
Example 7
Source File: Block.java    From nuls-v2 with MIT License 5 votes vote down vote up
private synchronized void parseRLP() {
    if (parsed) {
        return;
    }

    RLPList params = RLP.decode2(rlpEncoded);
    RLPList block = (RLPList) params.get(0);

    // Parse Header
    RLPList header = (RLPList) block.get(0);
    this.header = new BlockHeader(header);
    this.parsed = true;
}
 
Example 8
Source File: JournalSource.java    From nuls with MIT License 5 votes vote down vote up
private void parse(byte[] encoded) {
    RLPList l = (RLPList) RLP.decode2(encoded).get(0);
    updateHash = l.get(0).getRLPData();

    for (RLPElement aRInserted : (RLPList) l.get(1)) {
        insertedKeys.add(aRInserted.getRLPData());
    }
    for (RLPElement aRDeleted : (RLPList) l.get(2)) {
        deletedKeys.add(aRDeleted.getRLPData());
    }
}
 
Example 9
Source File: Block.java    From nuls with MIT License 5 votes vote down vote up
private synchronized void parseRLP() {
    if (parsed) {
        return;
    }

    RLPList params = RLP.decode2(rlpEncoded);
    RLPList block = (RLPList) params.get(0);

    // Parse Header
    RLPList header = (RLPList) block.get(0);
    this.header = new BlockHeader(header);
    this.parsed = true;
}
 
Example 10
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 11
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 12
Source File: NewBlockMessage.java    From ethereumj with MIT License 5 votes vote down vote up
private void parse() {
	RLPList paramsList = (RLPList) RLP.decode2(encoded).get(0);

       RLPList blockRLP = ((RLPList) paramsList.get(1));
       block = new Block(blockRLP.getRLPData());
       difficulty =  paramsList.get(2).getRLPData();

       parsed = true;
}
 
Example 13
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;
  }