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;
}
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;
}
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;
}
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);
}
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);
}
Aggregations