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();
}
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;
}
}
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);
}
}
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();
}
Aggregations