Search in sources :

Example 16 with RLPElement

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

the class Block method parseTxs.

private List<Transaction> parseTxs(RLPList txTransactions) {
    List<Transaction> parsedTxs = new ArrayList<>();
    for (int i = 0; i < txTransactions.size(); i++) {
        RLPElement transactionRaw = txTransactions.get(i);
        Transaction tx = new ImmutableTransaction(transactionRaw.getRLPData());
        if (isRemascTransaction(tx, i, txTransactions.size())) {
            // It is the remasc transaction
            tx = new RemascTransaction(transactionRaw.getRLPData());
        }
        parsedTxs.add(tx);
    }
    return Collections.unmodifiableList(parsedTxs);
}
Also used : RemascTransaction(co.rsk.remasc.RemascTransaction) RemascTransaction(co.rsk.remasc.RemascTransaction) RLPElement(org.ethereum.util.RLPElement) ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList)

Example 17 with RLPElement

use of org.ethereum.util.RLPElement 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 18 with RLPElement

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

the class FreeBlock method parseTxs.

private static List<Transaction> parseTxs(RLPList txTransactions) {
    List<Transaction> parsedTxs = new ArrayList<>();
    for (int i = 0; i < txTransactions.size(); i++) {
        RLPElement transactionRaw = txTransactions.get(i);
        Transaction tx = new ImmutableTransaction(transactionRaw.getRLPData());
        parsedTxs.add(tx);
    }
    return Collections.unmodifiableList(parsedTxs);
}
Also used : ImmutableTransaction(org.ethereum.core.ImmutableTransaction) Transaction(org.ethereum.core.Transaction) RLPElement(org.ethereum.util.RLPElement) ImmutableTransaction(org.ethereum.core.ImmutableTransaction) ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList)

Example 19 with RLPElement

use of org.ethereum.util.RLPElement 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 20 with RLPElement

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

the class ProofOfWorkRule method validFallbackBlockSignature.

public static boolean validFallbackBlockSignature(Constants constants, BlockHeader header, byte[] signatureBytesRLP) {
    if (header.getBitcoinMergedMiningCoinbaseTransaction() != null) {
        return false;
    }
    if (header.getBitcoinMergedMiningMerkleProof() != null) {
        return false;
    }
    byte[] fallbackMiningPubKeyBytes;
    boolean isEvenBlockNumber = header.getNumber() % 2 == 0;
    if (isEvenBlockNumber) {
        fallbackMiningPubKeyBytes = constants.getFallbackMiningPubKey0();
    } else {
        fallbackMiningPubKeyBytes = constants.getFallbackMiningPubKey1();
    }
    ECKey fallbackMiningPubKey = ECKey.fromPublicOnly(fallbackMiningPubKeyBytes);
    List<RLPElement> signatureRLP = (RLPList) RLP.decode2(signatureBytesRLP).get(0);
    if (signatureRLP.size() != 3) {
        return false;
    }
    byte[] v = signatureRLP.get(0).getRLPData();
    byte[] r = signatureRLP.get(1).getRLPData();
    byte[] s = signatureRLP.get(2).getRLPData();
    ECKey.ECDSASignature signature = ECKey.ECDSASignature.fromComponents(r, s, v[0]);
    return fallbackMiningPubKey.verify(header.getHashForMergedMining(), signature);
}
Also used : RLPElement(org.ethereum.util.RLPElement) ECKey(org.ethereum.crypto.ECKey) RLPList(org.ethereum.util.RLPList)

Aggregations

RLPElement (org.ethereum.util.RLPElement)38 Test (org.junit.Test)29 RLPList (org.ethereum.util.RLPList)19 ArrayList (java.util.ArrayList)4 LogInfo (org.ethereum.vm.LogInfo)3 Coin (co.rsk.core.Coin)2 RskAddress (co.rsk.core.RskAddress)2 Keccak256 (co.rsk.crypto.Keccak256)2 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)2 Script (co.rsk.bitcoinj.script.Script)1 ScriptChunk (co.rsk.bitcoinj.script.ScriptChunk)1 BridgeConstants (co.rsk.config.BridgeConstants)1 RepositoryImpl (co.rsk.db.RepositoryImpl)1 Federation (co.rsk.peg.Federation)1 BridgeEventLogger (co.rsk.peg.utils.BridgeEventLogger)1 BridgeEventLoggerImpl (co.rsk.peg.utils.BridgeEventLoggerImpl)1 RemascTransaction (co.rsk.remasc.RemascTransaction)1 LinkedList (java.util.LinkedList)1 Block (org.ethereum.core.Block)1 ImmutableTransaction (org.ethereum.core.ImmutableTransaction)1