diff --git a/lib/services/coins/coin_service.dart b/lib/services/coins/coin_service.dart index a690157ee..90a25a057 100644 --- a/lib/services/coins/coin_service.dart +++ b/lib/services/coins/coin_service.dart @@ -307,4 +307,24 @@ abstract class CoinServiceAPI { // used for electrumx coins Future updateSentCachedTxData(Map txData); + + // Certain outputs return address as an array/list of strings like List ["addresses"][0], some return it as a string like String ["address"] + String? getAddress(dynamic output) { + String? address; + if (output.containsKey('scriptPubKey') as bool) { + // Make sure the key exists before using it + if (output["scriptPubKey"].containsKey('address') as bool) { + address = output["scriptPubKey"]["address"] as String?; + } else if (output["scriptPubKey"].containsKey('addresses') as bool) { + address = output["scriptPubKey"]["addresses"][0] as String?; + // TODO determine cases in which there are multiple addresses in the array + } + } /*else { + // TODO detect cases in which no scriptPubKey exists + Logging.instance.log("output type not detected; output: ${output}", + level: LogLevel.Info); + }*/ + + return address; + } }