fetchUTXOTransactions function

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

Implementation

Future<UTXOTxInfo> fetchUTXOTransactions({
  required Iterable<HDWalletPath> walletTypes,
  required Iterable<AddressType> addressTypes,
  required UTXONetworkType networkType,
  required Uint8List seed,
  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,
  );

  print(
    "Selected ${endpoints.map(
      (e) => "$e",
    )}",
  );

  final isolateManager = IsolateManager();

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

  final (allTxs, nodes) = await Future.wait([
    for (final walletType in walletTypes)
      () async {
        final masterNode = await isolateManager.executeTask(
          IsolateTask(
            task: (arg) {
              return deriveMasterNodeFromSeed(seed: arg.$1, walletPath: arg.$2);
            },
            argument: (seed, walletType),
          ),
        );
        return searchTransactionsForWalletType(
          masterNode: masterNode,
          purpose: walletType.purpose,
          addressTypes: addressTypes,
          networkType: networkType,
          endpoints: endpoints,
          cachedNodes: cachedNodes,
          isolateManager: isolateManager,
        );
      }.call()
  ]).then((value) => (
        value.expand((element) => element.$1).toSet(),
        value.expand((element) => element.$2).toSet()
      ));

  isolateManager.dispose();

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