sendDocumentReceiptsList static method

Future<TransactionResult> sendDocumentReceiptsList(
  1. List<CommercioDocReceipt> commercioDocReceiptsList,
  2. Wallet wallet, {
  3. StdFee? fee,
  4. BroadcastingMode? mode,
  5. Client? client,
})

Creates a new transaction which sends a list of previously generated receipts commercioDocReceiptsList. Optionally fee and broadcasting mode parameters can be specified.

Implementation

static Future<TransactionResult> sendDocumentReceiptsList(
  List<CommercioDocReceipt> commercioDocReceiptsList,
  Wallet wallet, {
  StdFee? fee,
  BroadcastingMode? mode,
  http.Client? client,
}) async {
  List<StdMsg> msgs;

  final isLegacy21Chain = await wallet.networkInfo.isVersion(version: '2.1');

  if (isLegacy21Chain) {
    msgs = commercioDocReceiptsList.map((docReceipt) {
      // Convert the new CommercioDocReceipt entity to the old format
      final legacy21Receipt =
          legacy.CommercioDocReceiptMapper.toLegacy(docReceipt);

      // Replace the msg with the newer document with the legacy one
      return legacy.MsgSendDocumentReceipt(receipt: legacy21Receipt);
    }).toList();
  } else {
    msgs = commercioDocReceiptsList
        .map((commercioDocReceipt) =>
            MsgSendDocumentReceipt(receipt: commercioDocReceipt))
        .toList();
  }

  return TxHelper.createSignAndSendTx(
    msgs,
    wallet,
    fee: fee,
    mode: mode,
    client: client,
  );
}