Search in sources :

Example 1 with XorDataSource

use of org.aion.db.store.XorDataSource 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)

Aggregations

VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 ArrayList (java.util.ArrayList)1 ByteArrayKeyValueStore (org.aion.db.impl.ByteArrayKeyValueStore)1 XorDataSource (org.aion.db.store.XorDataSource)1 ByteArrayWrapper (org.aion.util.types.ByteArrayWrapper)1 SecureTrie (org.aion.zero.impl.trie.SecureTrie)1 Trie (org.aion.zero.impl.trie.Trie)1