Search in sources :

Example 6 with ByteArrayKeyValueStore

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;
    }
}
Also used : XorDataSource(org.aion.db.store.XorDataSource) ByteArrayWrapper(org.aion.util.types.ByteArrayWrapper) ArrayList(java.util.ArrayList) ByteArrayKeyValueStore(org.aion.db.impl.ByteArrayKeyValueStore) SecureTrie(org.aion.zero.impl.trie.SecureTrie) Trie(org.aion.zero.impl.trie.Trie) SecureTrie(org.aion.zero.impl.trie.SecureTrie) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 7 with ByteArrayKeyValueStore

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();
}
Also used : AionAddress(org.aion.types.AionAddress) ByteArrayWrapper(org.aion.util.types.ByteArrayWrapper) HashMap(java.util.HashMap) ByteArrayKeyValueStore(org.aion.db.impl.ByteArrayKeyValueStore) Test(org.junit.Test)

Aggregations

ByteArrayKeyValueStore (org.aion.db.impl.ByteArrayKeyValueStore)7 AionAddress (org.aion.types.AionAddress)5 Test (org.junit.Test)5 ByteArrayWrapper (org.aion.util.types.ByteArrayWrapper)3 HashMap (java.util.HashMap)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 ArrayList (java.util.ArrayList)1 XorDataSource (org.aion.db.store.XorDataSource)1 SecureTrie (org.aion.zero.impl.trie.SecureTrie)1 Trie (org.aion.zero.impl.trie.Trie)1