use of io.nem.symbol.sdk.infrastructure.BinarySerializationImpl in project nem2-sdk-java by nemtech.
the class AggregateTransactionFactory method calculateTransactionsHash.
/**
* It generates the hash of the transactions that are going to be included in the {@link
* AggregateTransaction}
*
* @param transactions the inner transaction
* @return the added transaction hash.
*/
private static String calculateTransactionsHash(final List<Transaction> transactions) {
final MerkleHashBuilder transactionsHashBuilder = new MerkleHashBuilder();
final BinarySerializationImpl transactionSerialization = new BinarySerializationImpl();
Hasher hasher = Hashes::sha3_256;
for (final Transaction transaction : transactions) {
final byte[] bytes = transactionSerialization.serializeEmbedded(transaction);
byte[] transactionHash = hasher.hash(bytes);
transactionsHashBuilder.update(transactionHash);
}
final byte[] hash = transactionsHashBuilder.getRootHash();
return ConvertUtils.toHex(hash);
}
Aggregations