utxo method
Returns Utxo or a List
of Utxos for the address or addresses.
- If
addresses
isString
, it will return a list of Utxo - If
addresses
isList
of Strings andreturnAsMap
is true, it will returnMap
where key is the cashAddr and values are Lists of Utxo - If
addresses
isList
of Strings andreturnAsMap
is false, it will returnList
similar to https://developer.bitcoin.com/bitbox/docs/address#utxo except, that utxo entries are converted to Utxo objects - Otherwise it will throw
FormatException
Implementation
static Future<dynamic> utxo(addresses, [returnAsMap = false]) async {
// don't reuse _sendRequests's returnAsMap parameter here because we need to iterate through the list anyway
final result = await _sendRequest("utxo", addresses);
if (result is Map) {
return Utxo.convertMapListToUtxos(result["utxos"]);
} else if (result is List) {
final returnList = <Map>[];
final returnMap = <String, List>{};
result.forEach((addressUtxoMap) {
if (returnAsMap) {
returnMap[addressUtxoMap["cashAddress"]] = Utxo.convertMapListToUtxos(addressUtxoMap["utxos"]);
} else {
addressUtxoMap["utxos"] = Utxo.convertMapListToUtxos(addressUtxoMap["utxos"]);
returnList.add(addressUtxoMap);
}
});
return returnAsMap ? returnMap : returnList;
} else {
throw FormatException("Invalid format returned: $result");
}
}