use of org.aion.util.types.ByteArrayWrapper in project aion by aionnetwork.
the class ContractInformation method deserializeInformation.
private static Information deserializeInformation(SharedRLPList list) {
// validity check
if (list.size() != 2)
return null;
Information info = new Information();
// validity check blocks
RLPElement code = list.get(0);
if (!(code.isList()))
return null;
for (RLPElement e : ((SharedRLPList) code)) {
// validity check pair
if (!(e.isList()))
return null;
SharedRLPList pair = (SharedRLPList) e;
// validity check hash
if (pair.size() != 2) {
return null;
}
byte[] key = pair.get(0).getRLPData();
if (key.length != HASH_SIZE) {
return null;
}
// validity check completeness status
byte[] flag = pair.get(1).getRLPData();
if (flag.length > 1 || (flag.length == 1 && flag[0] != 1))
return null;
ByteArrayWrapper keyWrap = ByteArrayWrapper.wrap(key);
// zero (i.e. false) decodes to empty byte array
info.blocks.put(keyWrap, flag.length == 1);
}
// validity check VM
byte[] array = list.get(1).getRLPData();
if (array.length != 1)
return null;
info.vm = InternalVmType.getInstance(array[0]);
// return correct instance
return info;
}
use of org.aion.util.types.ByteArrayWrapper in project aion by aionnetwork.
the class FvmContractDetails method getEncoded.
/**
* Returns an rlp encoding of this FvmContractDetails object.
*
* <p>The encoding is a list of 3 elements:<br>
* { 0:address, 1:storageRoot, 2:code }
*
* @return an rlp encoding of this.
*/
@Override
public byte[] getEncoded() {
byte[] rlpAddress = RLP.encodeElement(address.toByteArray());
byte[] rlpStorageRoot = RLP.encodeElement(storageTrie.getRootHash());
byte[][] codes = new byte[getCodes().size()][];
int i = 0;
for (ByteArrayWrapper bytes : this.getCodes().values()) {
codes[i++] = RLP.encodeElement(bytes.toBytes());
}
byte[] rlpCode = RLP.encodeList(codes);
return RLP.encodeList(rlpAddress, rlpStorageRoot, rlpCode);
}
use of org.aion.util.types.ByteArrayWrapper in project aion by aionnetwork.
the class AionRepositoryImpl method pruneBlocks.
private void pruneBlocks(long currentBlockNumber) {
if (currentBlockNumber > bestBlockNumber) {
// Prune only on increasing blocks
long pruneBlockNumber = currentBlockNumber - pruneBlockCount;
if (pruneBlockNumber >= 0) {
byte[] pruneBlockHash = blockStore.getBlockHashByNumber(pruneBlockNumber);
if (pruneBlockHash != null) {
ByteArrayWrapper hash = ByteArrayWrapper.wrap(pruneBlockHash);
stateDSPrune.prune(hash, pruneBlockNumber);
detailsDS.getStorageDSPrune().prune(hash, pruneBlockNumber);
}
}
}
bestBlockNumber = currentBlockNumber;
}
use of org.aion.util.types.ByteArrayWrapper in project aion by aionnetwork.
the class AionRepositoryImpl method getReferencedStorageNodes.
@VisibleForTesting
public List<byte[]> getReferencedStorageNodes(byte[] value, int limit, AionAddress contract) {
if (limit <= 0) {
return Collections.emptyList();
} else {
byte[] subKey = h256(("details-storage/" + contract.toString()).getBytes());
ByteArrayKeyValueStore db = new XorDataSource(selectDatabase(DatabaseType.STORAGE), subKey, false);
Trie trie = new SecureTrie(db);
Map<ByteArrayWrapper, byte[]> refs = trie.getReferencedTrieNodes(value, limit);
List<byte[]> converted = new ArrayList<>();
for (ByteArrayWrapper key : refs.keySet()) {
converted.add(ByteUtil.xorAlignRight(key.toBytes(), subKey));
}
return converted;
}
}
use of org.aion.util.types.ByteArrayWrapper in project aion by aionnetwork.
the class TrieTest method testGetMissingNodes_wCompleteTrie_wStartFromValue.
@Test
public void testGetMissingNodes_wCompleteTrie_wStartFromValue() {
MockDB mockDB = new MockDB("temp", log);
mockDB.open();
TrieImpl trie = new TrieImpl(mockDB);
for (Map.Entry<ByteArrayWrapper, byte[]> e : getSampleTrieUpdates().entrySet()) {
trie.update(e.getKey().toBytes(), e.getValue());
}
trie.getCache().commitForTest();
byte[] root = trie.getRootHash();
byte[] value = mockDB.get(root).get();
trie = new TrieImpl(mockDB);
assertThat(trie.getMissingNodes(value)).isEmpty();
}
Aggregations