Search in sources :

Example 1 with Trie

use of org.aion.zero.impl.trie.Trie in project aion by aionnetwork.

the class BlockUtil method calcTxTrieRoot.

public static byte[] calcTxTrieRoot(List<AionTransaction> transactions) {
    Objects.requireNonNull(transactions);
    if (transactions.isEmpty()) {
        return ConstantUtil.EMPTY_TRIE_HASH;
    }
    Trie txsState = new TrieImpl(null);
    for (int i = 0; i < transactions.size(); i++) {
        byte[] txEncoding = transactions.get(i).getEncoded();
        if (txEncoding != null) {
            txsState.update(RLP.encodeInt(i), txEncoding);
        } else {
            return ConstantUtil.EMPTY_TRIE_HASH;
        }
    }
    return txsState.getRootHash();
}
Also used : TrieImpl(org.aion.zero.impl.trie.TrieImpl) Trie(org.aion.zero.impl.trie.Trie)

Example 2 with Trie

use of org.aion.zero.impl.trie.Trie 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 3 with Trie

use of org.aion.zero.impl.trie.Trie in project aion by aionnetwork.

the class AionRepositoryImpl method getReferencedTrieNodes.

/**
 * Retrieves nodes referenced by a trie node value, where the size of the result is bounded by
 * the given limit.
 *
 * @param value a trie node value which may be referencing other nodes
 * @param limit the maximum number of key-value pairs to be retrieved by this method, which
 *     limits the search in the trie; zero and negative values for the limit will result in no
 *     search and an empty map will be returned
 * @param dbType the database where the value was stored and further keys should be searched for
 * @return an empty map when the value does not reference other trie nodes or the given limit is
 *     invalid, or a map containing all the referenced nodes reached while keeping within the
 *     limit on the result size
 */
public Map<ByteArrayWrapper, byte[]> getReferencedTrieNodes(byte[] value, int limit, DatabaseType dbType) {
    if (limit <= 0) {
        return Collections.emptyMap();
    } else {
        ByteArrayKeyValueDatabase db = selectDatabase(dbType);
        Trie trie = new TrieImpl(db);
        return trie.getReferencedTrieNodes(value, limit);
    }
}
Also used : TrieImpl(org.aion.zero.impl.trie.TrieImpl) ByteArrayKeyValueDatabase(org.aion.db.impl.ByteArrayKeyValueDatabase) SecureTrie(org.aion.zero.impl.trie.SecureTrie) Trie(org.aion.zero.impl.trie.Trie)

Example 4 with Trie

use of org.aion.zero.impl.trie.Trie in project aion by aionnetwork.

the class BlockUtil method calcReceiptsTrie.

public static byte[] calcReceiptsTrie(List<AionTxReceipt> receipts) {
    Objects.requireNonNull(receipts);
    if (receipts.isEmpty()) {
        return ConstantUtil.EMPTY_TRIE_HASH;
    }
    Trie receiptsTrie = new TrieImpl(null);
    for (int i = 0; i < receipts.size(); i++) {
        receiptsTrie.update(RLP.encodeInt(i), receipts.get(i).getReceiptTrieEncoded());
    }
    return receiptsTrie.getRootHash();
}
Also used : TrieImpl(org.aion.zero.impl.trie.TrieImpl) Trie(org.aion.zero.impl.trie.Trie)

Aggregations

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