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