Search in sources :

Example 31 with RLPList

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

the class NewBlockHashesMessage method parse.

private void parse() {
    RLPList paramsList = (RLPList) RLP.decode2(encoded).get(0);
    blockIdentifiers = new ArrayList<>();
    for (int i = 0; i < paramsList.size(); ++i) {
        RLPList rlpData = ((RLPList) paramsList.get(i));
        blockIdentifiers.add(new BlockIdentifier(rlpData));
    }
    parsed = true;
}
Also used : BlockIdentifier(org.ethereum.core.BlockIdentifier) RLPList(org.ethereum.util.RLPList)

Example 32 with RLPList

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

the class BridgeSerializationUtils method deserializeMap.

public static SortedMap<Keccak256, BtcTransaction> deserializeMap(byte[] data, NetworkParameters networkParameters, boolean noInputsTxs) {
    SortedMap<Keccak256, BtcTransaction> map = new TreeMap<>();
    if (data == null || data.length == 0) {
        return map;
    }
    RLPList rlpList = (RLPList) RLP.decode2(data).get(0);
    int ntxs = rlpList.size() / 2;
    for (int k = 0; k < ntxs; k++) {
        Keccak256 hash = new Keccak256(rlpList.get(k * 2).getRLPData());
        byte[] payload = rlpList.get(k * 2 + 1).getRLPData();
        BtcTransaction tx;
        if (!noInputsTxs) {
            tx = new BtcTransaction(networkParameters, payload);
        } else {
            tx = new BtcTransaction(networkParameters);
            tx.parseNoInputs(payload);
        }
        map.put(hash, tx);
    }
    return map;
}
Also used : Keccak256(co.rsk.crypto.Keccak256) RLPList(org.ethereum.util.RLPList)

Example 33 with RLPList

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

the class BridgeSerializationUtils method deserializeReleaseRequestQueue.

// For the serialization format, see BridgeSerializationUtils::serializeReleaseRequestQueue
public static ReleaseRequestQueue deserializeReleaseRequestQueue(byte[] data, NetworkParameters networkParameters) {
    List<ReleaseRequestQueue.Entry> entries = new ArrayList<>();
    if (data == null || data.length == 0) {
        return new ReleaseRequestQueue(entries);
    }
    RLPList rlpList = (RLPList) RLP.decode2(data).get(0);
    // Must have an even number of items
    if (rlpList.size() % 2 != 0) {
        throw new RuntimeException(String.format("Invalid serialized ReleaseRequestQueue. Expected an even number of elements, but got %d", rlpList.size()));
    }
    int n = rlpList.size() / 2;
    for (int k = 0; k < n; k++) {
        byte[] addressBytes = rlpList.get(k * 2).getRLPData();
        Address address = new Address(networkParameters, addressBytes);
        Long amount = BigIntegers.fromUnsignedByteArray(rlpList.get(k * 2 + 1).getRLPData()).longValue();
        entries.add(new ReleaseRequestQueue.Entry(address, Coin.valueOf(amount)));
    }
    return new ReleaseRequestQueue(entries);
}
Also used : RskAddress(co.rsk.core.RskAddress) RLPList(org.ethereum.util.RLPList)

Example 34 with RLPList

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

the class BridgeSerializationUtils method deserializeUTXOList.

public static List<UTXO> deserializeUTXOList(byte[] data) throws IOException {
    List<UTXO> list = new ArrayList<>();
    if (data == null || data.length == 0) {
        return list;
    }
    RLPList rlpList = (RLPList) RLP.decode2(data).get(0);
    int nutxos = rlpList.size();
    for (int k = 0; k < nutxos; k++) {
        byte[] utxoBytes = rlpList.get(k).getRLPData();
        InputStream istream = new ByteArrayInputStream(utxoBytes);
        UTXO utxo = new UTXO(istream);
        list.add(utxo);
    }
    return list;
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) RLPList(org.ethereum.util.RLPList)

Example 35 with RLPList

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

the class BridgeSerializationUtils method deserializeReleaseTransactionSet.

// For the serialization format, see BridgeSerializationUtils::serializeReleaseTransactionSet
public static ReleaseTransactionSet deserializeReleaseTransactionSet(byte[] data, NetworkParameters networkParameters) {
    Set<ReleaseTransactionSet.Entry> entries = new HashSet<>();
    if (data == null || data.length == 0) {
        return new ReleaseTransactionSet(entries);
    }
    RLPList rlpList = (RLPList) RLP.decode2(data).get(0);
    // Must have an even number of items
    if (rlpList.size() % 2 != 0) {
        throw new RuntimeException(String.format("Invalid serialized ReleaseTransactionSet. Expected an even number of elements, but got %d", rlpList.size()));
    }
    int n = rlpList.size() / 2;
    for (int k = 0; k < n; k++) {
        byte[] txPayload = rlpList.get(k * 2).getRLPData();
        BtcTransaction tx = new BtcTransaction(networkParameters, txPayload);
        Long height = BigIntegers.fromUnsignedByteArray(rlpList.get(k * 2 + 1).getRLPData()).longValue();
        entries.add(new ReleaseTransactionSet.Entry(tx, height));
    }
    return new ReleaseTransactionSet(entries);
}
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