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 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;
}
use of org.aion.rlp.RLPElement in project aion by aionnetwork.
the class AionRepositoryImpl method loadImportableState.
@VisibleForTesting
public void loadImportableState(byte[] fullState, DatabaseType dbType) {
SharedRLPList data = RLP.decode2SharedList(fullState);
RLPElement elements = data.get(0);
if (elements.isList()) {
for (RLPElement element : (SharedRLPList) elements) {
if (element.isList()) {
byte[] data0;
if (data.get(0).isList()) {
data0 = SharedRLPList.getRLPDataCopy((SharedRLPList) data.get(0));
} else {
data0 = data.get(0).getRLPData();
}
byte[] data1;
if (data.get(1).isList()) {
data1 = SharedRLPList.getRLPDataCopy((SharedRLPList) data.get(1));
} else {
data1 = data.get(1).getRLPData();
}
importTrieNode(data0, data1, dbType);
} else {
throw new IllegalStateException();
}
}
} else {
throw new IllegalStateException();
}
}
use of org.aion.rlp.RLPElement in project aion by aionnetwork.
the class DetailsDataStore method fromEncoding.
/**
* Extracts an RLPContractDetails object from the RLP encoding.
*
* Accepted encodings:
* <ul>
* <li>{ 0:address, 1:isExternalStorage, 2:storageRoot, 3:storageTrie, 4:code }
* <li>{ 0:address, 1:storageRoot, 2:code }
* </ul>
*
* @param encoding The encoded ContractDetails to decode.
*/
public static RLPContractDetails fromEncoding(byte[] encoding) {
if (encoding == null) {
throw new NullPointerException("Cannot decode ContractDetails from null RLP encoding.");
}
if (encoding.length == 0) {
throw new IllegalArgumentException("Cannot decode ContractDetails from empty RLP encoding.");
}
SharedRLPList decoded = (SharedRLPList) (RLP.decode2SharedList(encoding)).get(0);
int elements = decoded.size();
if (elements == 3 || elements == 5) {
// extract 0:address from the encoding
AionAddress address;
RLPElement addressRLP = decoded.get(0);
if (addressRLP == null || addressRLP.getRLPData() == null || addressRLP.getRLPData().length != AionAddress.LENGTH) {
throw new IllegalArgumentException("Cannot decode ContractDetails with invalid contract address.");
} else {
address = new AionAddress(addressRLP.getRLPData());
}
if (elements == 3) {
return new RLPContractDetails(address, true, decoded.get(1), null, decoded.get(2));
} else {
boolean isExternalStorage = decoded.get(1).getRLPData().length > 0;
return new RLPContractDetails(address, isExternalStorage, decoded.get(2), decoded.get(3), decoded.get(4));
}
} else {
throw new IllegalStateException("Incompatible data storage. Please shutdown the kernel and perform database migration to version 1.0 (Denali) of the kernel as instructed in the release.");
}
}
Aggregations