use of org.aion.db.impl.ByteArrayKeyValueStore 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.db.impl.ByteArrayKeyValueStore in project aion by aionnetwork.
the class InnerContractDetailsTest method testCommitToStored_withStorageOnAvm.
@Test
public void testCommitToStored_withStorageOnAvm() {
AionAddress address = mock(AionAddress.class);
ByteArrayKeyValueStore db = mock(XorDataSource.class);
AvmContractDetails parent = new AvmContractDetails(address, db, db);
InnerContractDetails child = new InnerContractDetails(null);
Map<ByteArrayWrapper, ByteArrayWrapper> storage = new HashMap<>();
for (int i = 0; i < 3; i++) {
ByteArrayWrapper key = ByteArrayWrapper.wrap(RandomUtils.nextBytes(32));
ByteArrayWrapper value = ByteArrayWrapper.wrap(RandomUtils.nextBytes(100));
child.put(key, value);
storage.put(key, value);
}
ByteArrayWrapper deletedKey = ByteArrayWrapper.wrap(RandomUtils.nextBytes(32));
child.delete(deletedKey);
storage.put(deletedKey, null);
assertThat(child.isDirty()).isTrue();
assertThat(parent.getVmType()).isEqualTo(InternalVmType.AVM);
child.commitTo(parent);
assertThat(parent.getVmType()).isEqualTo(InternalVmType.AVM);
for (ByteArrayWrapper key : storage.keySet()) {
assertThat(parent.get(key)).isEqualTo(storage.get(key));
}
assertThat(parent.isDirty()).isTrue();
}
Aggregations