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