use of org.aion.rlp.RLPElement in project aion by aionnetwork.
the class AbstractBlockSummary method decodeMap.
protected static <K, V> Map<K, V> decodeMap(RLPList list, Functional.Function<byte[], K> keyDecoder, Functional.Function<byte[], V> valueDecoder) {
Map<K, V> result = new HashMap<>();
for (RLPElement entry : list) {
K key = keyDecoder.apply(((RLPList) entry).get(0).getRLPData());
V value = valueDecoder.apply(((RLPList) entry).get(1).getRLPData());
result.put(key, value);
}
return result;
}
use of org.aion.rlp.RLPElement in project aion by aionnetwork.
the class AionBlockHeaderWrapper method parse.
protected void parse(byte[] bytes) {
List<RLPElement> params = RLP.decode2(bytes);
List<RLPElement> wrapper = (RLPList) params.get(0);
byte[] headerBytes = wrapper.get(0).getRLPData();
this.header = new A0BlockHeader(headerBytes);
this.nodeId = wrapper.get(1).getRLPData();
}
use of org.aion.rlp.RLPElement in project aion by aionnetwork.
the class BroadcastTx method decode.
/* return the encodedData of the Transaction list, the caller function need to cast the return byte[] array
*/
public static List<byte[]> decode(final byte[] _msgBytes) {
RLPList paramsList = (RLPList) RLP.decode2(_msgBytes).get(0);
List<byte[]> txl = new ArrayList<>();
for (RLPElement aParamsList : paramsList) {
RLPList rlpData = ((RLPList) aParamsList);
txl.add(rlpData.getRLPData());
}
return txl;
}
use of org.aion.rlp.RLPElement in project aion by aionnetwork.
the class ResBlocksHeaders method decode.
public static ResBlocksHeaders decode(final byte[] _msgBytes) {
if (_msgBytes == null || _msgBytes.length == 0)
return null;
else {
try {
RLPList list = (RLPList) RLP.decode2(_msgBytes).get(0);
List<A0BlockHeader> blockHeaders = new ArrayList<>();
for (RLPElement aList : list) {
RLPList rlpData = ((RLPList) aList);
blockHeaders.add(A0BlockHeader.fromRLP(rlpData, true));
}
return new ResBlocksHeaders(blockHeaders);
} catch (Exception ex) {
return null;
}
}
}
use of org.aion.rlp.RLPElement in project aion by aionnetwork.
the class AionContractDetailsImpl method decode.
@Override
public void decode(byte[] rlpCode) {
RLPList data = RLP.decode2(rlpCode);
RLPList rlpList = (RLPList) data.get(0);
RLPItem address = (RLPItem) rlpList.get(0);
RLPItem isExternalStorage = (RLPItem) rlpList.get(1);
RLPItem storage = (RLPItem) rlpList.get(2);
RLPElement code = rlpList.get(3);
RLPList keys = (RLPList) rlpList.get(4);
RLPItem storageRoot = (RLPItem) rlpList.get(5);
if (address.getRLPData() == null) {
this.address = Address.EMPTY_ADDRESS();
} else {
this.address = Address.wrap(address.getRLPData());
}
this.externalStorage = !Arrays.equals(isExternalStorage.getRLPData(), EMPTY_BYTE_ARRAY);
this.storageTrie.deserialize(storage.getRLPData());
if (code instanceof RLPList) {
for (RLPElement e : ((RLPList) code)) {
setCode(e.getRLPData());
}
} else {
setCode(code.getRLPData());
}
for (RLPElement key : keys) {
addKey(key.getRLPData());
}
if (externalStorage) {
storageTrie.withPruningEnabled(prune >= 0);
storageTrie.setRoot(storageRoot.getRLPData());
storageTrie.getCache().setDB(getExternalStorageDataSource());
}
externalStorage = (storage.getRLPData().length > detailsInMemoryStorageLimit) || externalStorage;
this.rlpEncoded = rlpCode;
}
Aggregations