getNetworkFees function

Future<UtxoNetworkFees> getNetworkFees({
  1. required UTXONetworkType network,
  2. double multiplier = 1.0,
})

Implementation

Future<UtxoNetworkFees> getNetworkFees({
  required UTXONetworkType network,
  double multiplier = 1.0,
}) async {
  final blockInOneHour = 3600 ~/ network.blockTime;
  final blocksTillTomorrow = 24 * 3600 ~/ network.blockTime;

  final client = await getBestHealthEndpointsWithRetry(
    endpointPool: network.endpoints,
    token: network.coin,
    max: 1,
    min: 1,
  )
      .then(
        (endpoints) => endpoints.first,
      )
      .then(
        (endpoint) => createElectrumXClient(
          endpoint: endpoint.$1,
          port: endpoint.$2,
          token: network.coin,
        ),
      );

  final next = await estimateFeeForPriority(
    blocks: 1,
    network: network,
    initalClient: client,
  );

  final second = await estimateFeeForPriority(
    blocks: 2,
    network: network,
    initalClient: client,
  );

  final hour = await estimateFeeForPriority(
    blocks: blockInOneHour,
    network: network,
    initalClient: client,
  );

  final day = await estimateFeeForPriority(
    blocks: blocksTillTomorrow,
    network: network,
    initalClient: client,
  );

  client?.disconnect();

  return UtxoNetworkFees(
    nextBlock: next.multiplyAndCeil(multiplier),
    secondBlock: second.multiplyAndCeil(multiplier),
    hour: hour.multiplyAndCeil(multiplier),
    day: day.multiplyAndCeil(multiplier),
  );
}