Search in sources :

Example 46 with RLPList

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

the class BridgeSerializationUtils method deserializeSet.

public static SortedSet<Sha256Hash> deserializeSet(byte[] data) {
    SortedSet<Sha256Hash> set = new TreeSet<>();
    if (data == null || data.length == 0) {
        return set;
    }
    RLPList rlpList = (RLPList) RLP.decode2(data).get(0);
    int nhashes = rlpList.size();
    for (int k = 0; k < nhashes; k++) {
        set.add(Sha256Hash.wrap(rlpList.get(k).getRLPData()));
    }
    return set;
}
Also used : RLPList(org.ethereum.util.RLPList)

Example 47 with RLPList

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

the class BridgeSerializationUtils method deserializeLockWhitelist.

public static LockWhitelist deserializeLockWhitelist(byte[] data, NetworkParameters parameters) {
    RLPList rlpList = (RLPList) RLP.decode2(data).get(0);
    int serializedAddressesSize = rlpList.size() - 1;
    // serialized addresses size must be even - key, value pairs expected in sequence
    if (serializedAddressesSize % 2 != 0) {
        throw new RuntimeException("deserializeLockWhitelist: expected an even number of addresses, but odd given");
    }
    Map<Address, Coin> whitelist = new HashMap<>(serializedAddressesSize / 2);
    for (int i = 0; i < serializedAddressesSize; i = i + 2) {
        byte[] hash160 = rlpList.get(i).getRLPData();
        byte[] maxValueData = rlpList.get(i + 1).getRLPData();
        whitelist.put(new Address(parameters, hash160), Coin.valueOf(safeToBigInteger(maxValueData).longValueExact()));
    }
    int disableBlockHeight = safeToBigInteger(rlpList.get(serializedAddressesSize).getRLPData()).intValueExact();
    return new LockWhitelist(whitelist, disableBlockHeight);
}
Also used : RskAddress(co.rsk.core.RskAddress) RLPList(org.ethereum.util.RLPList)

Example 48 with RLPList

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

the class BridgeSerializationUtils method deserializeFederation.

// For the serialization format, see BridgeSerializationUtils::serializeFederation
public static Federation deserializeFederation(byte[] data, Context btcContext) {
    RLPList rlpList = (RLPList) RLP.decode2(data).get(0);
    if (rlpList.size() != FEDERATION_RLP_LIST_SIZE) {
        throw new RuntimeException(String.format("Invalid serialized Federation. Expected %d elements but got %d", FEDERATION_RLP_LIST_SIZE, rlpList.size()));
    }
    byte[] creationTimeBytes = rlpList.get(FEDERATION_CREATION_TIME_INDEX).getRLPData();
    Instant creationTime = Instant.ofEpochMilli(BigIntegers.fromUnsignedByteArray(creationTimeBytes).longValue());
    List<BtcECKey> pubKeys = ((RLPList) rlpList.get(FEDERATION_PUB_KEYS_INDEX)).stream().map(pubKeyBytes -> BtcECKey.fromPublicOnly(pubKeyBytes.getRLPData())).collect(Collectors.toList());
    byte[] creationBlockNumberBytes = rlpList.get(FEDERATION_CREATION_BLOCK_NUMBER_INDEX).getRLPData();
    long creationBlockNumber = BigIntegers.fromUnsignedByteArray(creationBlockNumberBytes).longValue();
    return new Federation(pubKeys, creationTime, creationBlockNumber, btcContext.getParams());
}
Also used : java.util(java.util) ByteArrayOutputStream(java.io.ByteArrayOutputStream) RLP(org.ethereum.util.RLP) BigIntegers(org.spongycastle.util.BigIntegers) RskAddress(co.rsk.core.RskAddress) IOException(java.io.IOException) Instant(java.time.Instant) Keccak256(co.rsk.crypto.Keccak256) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) RLPList(org.ethereum.util.RLPList) ByteArrayInputStream(java.io.ByteArrayInputStream) co.rsk.bitcoinj.core(co.rsk.bitcoinj.core) BigInteger(java.math.BigInteger) Nullable(javax.annotation.Nullable) InputStream(java.io.InputStream) Instant(java.time.Instant) RLPList(org.ethereum.util.RLPList)

Example 49 with RLPList

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

the class BridgeState method create.

public static BridgeState create(BridgeConstants bridgeConstants, byte[] data) throws IOException {
    RLPList rlpList = (RLPList) RLP.decode2(data).get(0);
    byte[] btcBlockchainBestChainHeightBytes = rlpList.get(0).getRLPData();
    int btcBlockchainBestChainHeight = btcBlockchainBestChainHeightBytes == null ? 0 : (new BigInteger(1, btcBlockchainBestChainHeightBytes)).intValue();
    byte[] btcTxHashesAlreadyProcessedBytes = rlpList.get(1).getRLPData();
    Map<Sha256Hash, Long> btcTxHashesAlreadyProcessed = BridgeSerializationUtils.deserializeMapOfHashesToLong(btcTxHashesAlreadyProcessedBytes);
    byte[] btcUTXOsBytes = rlpList.get(2).getRLPData();
    List<UTXO> btcUTXOs = BridgeSerializationUtils.deserializeUTXOList(btcUTXOsBytes);
    byte[] rskTxsWaitingForSignaturesBytes = rlpList.get(3).getRLPData();
    SortedMap<Keccak256, BtcTransaction> rskTxsWaitingForSignatures = BridgeSerializationUtils.deserializeMap(rskTxsWaitingForSignaturesBytes, bridgeConstants.getBtcParams(), false);
    byte[] releaseRequestQueueBytes = rlpList.get(4).getRLPData();
    ReleaseRequestQueue releaseRequestQueue = BridgeSerializationUtils.deserializeReleaseRequestQueue(releaseRequestQueueBytes, bridgeConstants.getBtcParams());
    byte[] releaseTransactionSetBytes = rlpList.get(5).getRLPData();
    ReleaseTransactionSet releaseTransactionSet = BridgeSerializationUtils.deserializeReleaseTransactionSet(releaseTransactionSetBytes, bridgeConstants.getBtcParams());
    return new BridgeState(btcBlockchainBestChainHeight, btcTxHashesAlreadyProcessed, btcUTXOs, rskTxsWaitingForSignatures, releaseRequestQueue, releaseTransactionSet);
}
Also used : Sha256Hash(co.rsk.bitcoinj.core.Sha256Hash) BtcTransaction(co.rsk.bitcoinj.core.BtcTransaction) Keccak256(co.rsk.crypto.Keccak256) RLPList(org.ethereum.util.RLPList) UTXO(co.rsk.bitcoinj.core.UTXO) BigInteger(java.math.BigInteger)

Example 50 with RLPList

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

the class BlockHeadersMessage method parse.

private void parse() {
    RLPList paramsList = (RLPList) RLP.decode2(encoded).get(0);
    blockHeaders = new ArrayList<>();
    for (int i = 0; i < paramsList.size(); ++i) {
        RLPList rlpData = ((RLPList) paramsList.get(i));
        blockHeaders.add(new BlockHeader(rlpData, true));
    }
    parsed = true;
}
Also used : BlockHeader(org.ethereum.core.BlockHeader) 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