Search in sources :

Example 41 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)

Example 42 with RLPList

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

the class GetBlockHeadersMessage method parse.

private void parse() {
    RLPList paramsList = (RLPList) RLP.decode2(encoded).get(0);
    byte[] blockBytes = paramsList.get(0).getRLPData();
    // it might be either a hash or number
    if (blockBytes == null) {
        this.blockNumber = 0;
    } else if (blockBytes.length == DEFAULT_SIZE_BYTES) {
        this.blockHash = blockBytes;
    } else {
        this.blockNumber = byteArrayToLong(blockBytes);
    }
    byte[] maxHeaders = paramsList.get(1).getRLPData();
    this.maxHeaders = byteArrayToInt(maxHeaders);
    byte[] skipBlocks = paramsList.get(2).getRLPData();
    this.skipBlocks = byteArrayToInt(skipBlocks);
    byte[] reverse = paramsList.get(3).getRLPData();
    this.reverse = byteArrayToInt(reverse) == 1;
    parsed = true;
}
Also used : RLPList(org.ethereum.util.RLPList)

Example 43 with RLPList

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

the class Message method create.

public static Message create(ArrayList<RLPElement> paramsList) {
    byte[] body = paramsList.get(1).getRLPData();
    if (body != null) {
        int type = paramsList.get(0).getRLPData()[0];
        MessageType messageType = MessageType.valueOfType(type);
        RLPList list = (RLPList) RLP.decode2(body).get(0);
        return messageType.createMessage(list);
    }
    return null;
}
Also used : RLPList(org.ethereum.util.RLPList)

Example 44 with RLPList

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

the class BridgeSerializationUtils method deserializeABICallSpec.

// For the serialization format, see BridgeSerializationUtils::serializeABICallSpec
private static ABICallSpec deserializeABICallSpec(byte[] data) {
    RLPList rlpList = (RLPList) RLP.decode2(data).get(0);
    if (rlpList.size() != 2) {
        throw new RuntimeException(String.format("Invalid serialized ABICallSpec. Expected 2 elements, but got %d", rlpList.size()));
    }
    String function = new String(rlpList.get(0).getRLPData(), StandardCharsets.UTF_8);
    byte[][] arguments = ((RLPList) rlpList.get(1)).stream().map(rlpElement -> rlpElement.getRLPData()).toArray(byte[][]::new);
    return new ABICallSpec(function, arguments);
}
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) RLPList(org.ethereum.util.RLPList)

Example 45 with RLPList

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

the class BridgeSerializationUtils method deserializeElection.

// For the serialization format, see BridgeSerializationUtils::serializeElection
public static ABICallElection deserializeElection(byte[] data, AddressBasedAuthorizer authorizer) {
    if (data == null || data.length == 0) {
        return new ABICallElection(authorizer);
    }
    RLPList rlpList = (RLPList) RLP.decode2(data).get(0);
    // List size must be even - key, value pairs expected in sequence
    if (rlpList.size() % 2 != 0) {
        throw new RuntimeException("deserializeElection: expected an even number of entries, but odd given");
    }
    int numEntries = rlpList.size() / 2;
    Map<ABICallSpec, List<RskAddress>> votes = new HashMap<>();
    for (int k = 0; k < numEntries; k++) {
        ABICallSpec spec = deserializeABICallSpec(rlpList.get(k * 2).getRLPData());
        List<RskAddress> specVotes = deserializeVoters(rlpList.get(k * 2 + 1).getRLPData());
        votes.put(spec, specVotes);
    }
    return new ABICallElection(authorizer, votes);
}
Also used : RskAddress(co.rsk.core.RskAddress) RLPList(org.ethereum.util.RLPList) 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