sendDocumentReceipt static method

Future<TransactionResult> sendDocumentReceipt({
  1. required String recipient,
  2. required String txHash,
  3. required String documentId,
  4. required Wallet wallet,
  5. String? proof,
  6. StdFee? fee,
  7. BroadcastingMode? mode,
  8. Client? client,
})

Creates a new transaction which tells the recipient that the document having the specified documentId and present inside the transaction with txHash has been properly seen; optionally proof of reading, fee and broadcasting mode.

Implementation

static Future<TransactionResult> sendDocumentReceipt({
  required String recipient,
  required String txHash,
  required String documentId,
  required Wallet wallet,
  String? proof,
  StdFee? fee,
  BroadcastingMode? mode,
  http.Client? client,
}) async {
  final commercioDocReceipt = CommercioDocReceiptHelper.fromWallet(
    wallet: wallet,
    recipient: recipient,
    txHash: txHash,
    documentId: documentId,
    proof: proof,
  );
  StdMsg msg = MsgSendDocumentReceipt(receipt: commercioDocReceipt);

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

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

    // Replace the msg with the newer document with the legacy one
    msg = legacy.MsgSendDocumentReceipt(receipt: legacy21Receipt);
  }

  return TxHelper.createSignAndSendTx(
    [msg],
    wallet,
    fee: fee,
    mode: mode,
    client: client,
  );
}