Search in sources :

Example 26 with RLPList

use of org.ethereum.util.RLPList in project rskj by rsksmart.

the class BlockGenerator method removeLastElement.

private static byte[] removeLastElement(byte[] rlpEncoded) {
    ArrayList<RLPElement> params = RLP.decode2(rlpEncoded);
    RLPList block = (RLPList) params.get(0);
    RLPList header = (RLPList) block.get(0);
    if (header.size() < 20) {
        return rlpEncoded;
    }
    // remove last element
    header.remove(header.size() - 1);
    // remove second last element
    header.remove(header.size() - 1);
    List<byte[]> newHeader = new ArrayList<>();
    for (int i = 0; i < header.size(); i++) {
        byte[] e = nullReplace(header.get(i).getRLPData());
        if (// fix bad feePaid
        (e.length > 32) && (i == 15))
            e = new byte[32];
        newHeader.add(RLP.encodeElement(e));
    }
    byte[][] newHeaderElements = newHeader.toArray(new byte[newHeader.size()][]);
    byte[] newEncodedHeader = RLP.encodeList(newHeaderElements);
    return RLP.encodeList(newEncodedHeader, // very weird.
    nullReplace(block.get(1).getRLPData()), nullReplace(block.get(2).getRLPData()));
}
Also used : RLPElement(org.ethereum.util.RLPElement) ArrayList(java.util.ArrayList) RLPList(org.ethereum.util.RLPList)

Example 27 with RLPList

use of org.ethereum.util.RLPList in project rskj by rsksmart.

the class FreeBlock method parseRLP.

private void parseRLP() {
    ArrayList<RLPElement> params = RLP.decode2(rlpEncoded);
    RLPList block = (RLPList) params.get(0);
    // Parse Header
    RLPList header = (RLPList) block.get(0);
    this.header = new FreeBlockHeader(header);
    // Parse Transactions
    RLPList txTransactions = (RLPList) block.get(1);
    this.transactionsList = parseTxs(txTransactions);
    byte[] calculatedRoot = getTxTrie(this.transactionsList).getHash().getBytes();
    // Parse Uncles
    RLPList uncleBlocks = (RLPList) block.get(2);
    for (RLPElement rawUncle : uncleBlocks) {
        RLPList uncleHeader = (RLPList) rawUncle;
        FreeBlockHeader blockData = new FreeBlockHeader(uncleHeader);
        this.uncleList.add(blockData);
    }
    this.parsed = true;
}
Also used : RLPElement(org.ethereum.util.RLPElement) RLPList(org.ethereum.util.RLPList)

Example 28 with RLPList

use of org.ethereum.util.RLPList in project rskj by rsksmart.

the class FindNodePeerMessage method parse.

@Override
public final void parse(byte[] data) {
    RLPList dataList = (RLPList) RLP.decode2OneItem(data, 0);
    RLPItem chk = (RLPItem) dataList.get(1);
    this.messageId = new String(chk.getRLPData(), Charset.forName("UTF-8"));
    RLPItem nodeRlp = (RLPItem) dataList.get(0);
    this.nodeId = nodeRlp.getRLPData();
}
Also used : RLPItem(org.ethereum.util.RLPItem) RLPList(org.ethereum.util.RLPList)

Example 29 with RLPList

use of org.ethereum.util.RLPList in project rskj by rsksmart.

the class PingPeerMessage method parse.

@Override
public final void parse(byte[] data) {
    RLPList dataList = (RLPList) RLP.decode2OneItem(data, 0);
    RLPList fromList = (RLPList) dataList.get(1);
    RLPItem chk = (RLPItem) dataList.get(2);
    byte[] ipB = fromList.get(0).getRLPData();
    this.host = new String(ipB, Charset.forName("UTF-8"));
    this.port = ByteUtil.byteArrayToInt(fromList.get(1).getRLPData());
    this.messageId = new String(chk.getRLPData(), Charset.forName("UTF-8"));
}
Also used : RLPItem(org.ethereum.util.RLPItem) RLPList(org.ethereum.util.RLPList)

Example 30 with RLPList

use of org.ethereum.util.RLPList in project rskj by rsksmart.

the class RskMessage method parse.

protected void parse() {
    RLPList paramsList = (RLPList) RLP.decode2(encoded).get(0);
    this.message = Message.create((RLPList) paramsList.get(0));
    this.parsed = true;
}
Also used : RLPList(org.ethereum.util.RLPList)

Aggregations

RLPList (org.ethereum.util.RLPList)60 RLPElement (org.ethereum.util.RLPElement)19 Test (org.junit.Test)13 Keccak256 (co.rsk.crypto.Keccak256)8 RskAddress (co.rsk.core.RskAddress)7 BigInteger (java.math.BigInteger)5 RLPItem (org.ethereum.util.RLPItem)5 LogInfo (org.ethereum.vm.LogInfo)5 Script (co.rsk.bitcoinj.script.Script)3 ScriptChunk (co.rsk.bitcoinj.script.ScriptChunk)3 Coin (co.rsk.core.Coin)3 RepositoryImpl (co.rsk.db.RepositoryImpl)3 BridgeEventLogger (co.rsk.peg.utils.BridgeEventLogger)3 BridgeEventLoggerImpl (co.rsk.peg.utils.BridgeEventLoggerImpl)3 ByteArrayInputStream (java.io.ByteArrayInputStream)3 InputStream (java.io.InputStream)3 ArrayList (java.util.ArrayList)3 co.rsk.bitcoinj.core (co.rsk.bitcoinj.core)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 IOException (java.io.IOException)2