shareDocument static method

Future<TransactionResult> shareDocument({
  1. required String id,
  2. required CommercioDocMetadata metadata,
  3. required List<String> recipients,
  4. required Wallet wallet,
  5. String? contentUri,
  6. CommercioDoSign? doSign,
  7. CommercioDocChecksum? checksum,
  8. Uint8List? aesKey,
  9. Set<CommercioEncryptedData>? encryptedData,
  10. StdFee? fee,
  11. BroadcastingMode? mode,
  12. Client? client,
})

Creates a new transaction that allows to share the document associated with the given metadata and having the optional contentUri, doSign, checksum, fee and broadcasting mode. If encryptedData is specified then encrypts the proper data for the specified recipients and then sends the transaction to the blockchain.

If doSign is specified then the field checksum must be also provided.

Implementation

static Future<TransactionResult> shareDocument({
  required String id,
  required CommercioDocMetadata metadata,
  required List<String> recipients,
  required Wallet wallet,
  String? contentUri,
  CommercioDoSign? doSign,
  CommercioDocChecksum? checksum,
  Uint8List? aesKey,
  Set<CommercioEncryptedData>? encryptedData,
  StdFee? fee,
  BroadcastingMode? mode,
  http.Client? client,
}) async {
  // Build a generic document
  final commercioDoc = await CommercioDocHelper.fromWallet(
    wallet: wallet,
    recipients: recipients,
    id: id,
    metadata: metadata,
    checksum: checksum,
    contentUri: contentUri,
    doSign: doSign,
    encryptedData: encryptedData,
    aesKey: aesKey,
  );
  StdMsg msg = MsgShareDocument(document: commercioDoc);

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

  if (isLegacy21Chain) {
    // Convert the new CommercioDoc entity to the old format
    final legacy21Doc = legacy.CommercioDocMapper.toLegacy(commercioDoc);

    // Replace the msg with the newer document with the legacy one
    msg = legacy.MsgShareDocument(document: legacy21Doc);
  }

  // Build, sign and send the tx message
  return TxHelper.createSignAndSendTx(
    [msg],
    wallet,
    fee: fee,
    mode: mode,
    client: client,
  );
}