computeGroupId static method

Uint8List computeGroupId(
  1. List<RawTransaction> transactions
)

Compute the group id of the transactions.

Implementation

static Uint8List computeGroupId(List<RawTransaction> transactions) {
  if (transactions.isEmpty) {
    throw AlgorandException(message: 'Empty transaction list');
  }

  if (transactions.length > MAX_TRANSACTION_GROUP_SIZE) {
    throw AlgorandException(
        message: 'Max. group size is $MAX_TRANSACTION_GROUP_SIZE');
  }

  // Calculate the transaction ids for every transaction
  final transactionIds = <Uint8List>[];
  for (var transaction in transactions) {
    transactionIds.add(transaction.rawId);
  }

  // Encode the transaction
  final encodedTx = Encoder.encodeMessagePack({'txlist': transactionIds});

  // Prepend with group transaction prefix
  final tgBytes = utf8.encode(TG_PREFIX);

  // Merge the byte arrays & hash
  return Uint8List.fromList(
      sha512256.convert([...tgBytes, ...encodedTx]).bytes);
}