getUnconfirmed method

Future getUnconfirmed (dynamic addresses, [ dynamic returnAsMap = false ])

Returns list of unconfirmed transactions

  • If addresses is String, it will return Map with unconfirmed transaction details.
  • If addresses is List of Strings and returnAsMap is true, it will return Map with cashAddress used as keys and Map objects with address details in values.
  • If addresses is List of Strings and returnAsMap is false, it will return List with details sorted in the same order as the input list of addresses.
  • Otherwise it will throw FormatException

See https://developer.bitcoin.com/bitbox/docs/address#unconfirmed for details about the returned format. However note, that processing from array to map is done on the library side

Implementation

static Future<dynamic> getUnconfirmed(addresses,
    [returnAsMap = false]) async {
  final result = await _sendRequest("unconfirmed", addresses);

  if (result is Map) {
    return Utxo.convertMapListToUtxos(result["utxos"]);
  } else if (result is List<Map>) {
    final returnList = <Map>[];
    final returnMap = <String, List>{};

    result.forEach((addressUtxoMap) {
      if (returnAsMap) {
        returnMap[addressUtxoMap["cashAddr"]] =
            Utxo.convertMapListToUtxos(addressUtxoMap["utxos"]);
      } else {
        addressUtxoMap["utxos"] =
            Utxo.convertMapListToUtxos(addressUtxoMap["utxos"]);
        returnList.add(addressUtxoMap);
      }
    });

    return returnAsMap ? returnMap : returnList;
  }
}