fetchUTXOTransactionsFromEpubKey function

Future<UTXOTxInfo> fetchUTXOTransactionsFromEpubKey({
  1. required Iterable<AddressType> addressTypes,
  2. required UTXONetworkType networkType,
  3. required String ePubKey,
  4. required HDWalletPurpose purpose,
  5. Set<UTXOTransaction> cachedTransactions = const {},
  6. List<NodeWithAddress> cachedNodes = const [],
  7. int minEndpoints = 2,
  8. Duration maxLatency = const Duration(milliseconds: 800),
})

Fetches UTXO Transactions for a given ePubKey if purpose is not provied the returned nodes cant be used to derive the master node (used in Proof of Payment)

Implementation

Future<UTXOTxInfo> fetchUTXOTransactionsFromEpubKey({
  required Iterable<AddressType> addressTypes,
  required UTXONetworkType networkType,
  required String ePubKey,
  required HDWalletPurpose purpose,
  Set<UTXOTransaction> cachedTransactions = const {},
  List<NodeWithAddress> cachedNodes = const [],
  int minEndpoints = 2,
  Duration maxLatency = const Duration(milliseconds: 800),
}) async {
  final watch = Stopwatch()..start();

  final endpoints = await getBestHealthEndpointsWithRetry(
    endpointPool: networkType.endpoints,
    token: networkType.coin,
    maxLatency: maxLatency,
    min: minEndpoints,
  );

  final isolateManager = IsolateManager();

  ///
  /// Search for Receive and Change Addresses
  ///

  final masterNode = await isolateManager.executeTask(
    IsolateTask(
      task: (arg) {
        return deriveMasterNodeFromExtendedKeyWithCheck(
          ePubKey: arg.$1,
          networkType: arg.$2,
          purpose: arg.$3,
        );
      },
      argument: (ePubKey, networkType, purpose),
    ),
  );

  final (allTxs, nodes) = await searchTransactionsForWalletType(
    masterNode: masterNode,
    purpose: purpose,
    addressTypes: addressTypes,
    networkType: networkType,
    endpoints: endpoints,
    cachedNodes: cachedNodes,
    isolateManager: isolateManager,
  );

  isolateManager.dispose();

  return fetchMissingUTXOTransactions(
    allTxs: allTxs,
    nodes: nodes,
    cachedNodes: cachedNodes,
    cachedTransactions: cachedTransactions,
    addressTypes: addressTypes,
    coin: networkType.coin,
    endpoints: endpoints,
    networkType: networkType,
    watch: watch,
  );
}