diff --git a/lib/services/coins/coin_service.dart b/lib/services/coins/coin_service.dart index 7a43c71da..f0c154ba7 100644 --- a/lib/services/coins/coin_service.dart +++ b/lib/services/coins/coin_service.dart @@ -310,6 +310,8 @@ abstract class CoinServiceAPI { // 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) { + // Julian's code from https://github.com/cypherstack/stack_wallet/blob/35a8172d35f1b5cdbd22f0d56c4db02f795fd032/lib/services/coins/coin_paynym_extension.dart#L170 wins codegolf for this, I'd love to commit it now but need to retest this section ... should make unit tests for this case + // final String? address = output["scriptPubKey"]?["addresses"]?[0] as String? ?? output["scriptPubKey"]?["address"] as String?; String? address; if (output.containsKey('scriptPubKey') as bool) { // Make sure the key exists before using it @@ -330,6 +332,8 @@ abstract class CoinServiceAPI { // Firo wants an array/list of address strings like List List? getAddresses(dynamic output) { + // Inspired by Julian's code as referenced above, need to test before committing + // final List? addresses = output["scriptPubKey"]?["addresses"] as List? ?? [output["scriptPubKey"]?["address"]] as List?; List? addresses; if (output.containsKey('scriptPubKey') as bool) { if (output["scriptPubKey"].containsKey('addresses') as bool) {