mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2025-03-26 00:58:50 +00:00
add getAddress helper func for transactions with odd outputs
OP_RETURN and some other output types can cause addresses to be placed in a list of strings or as a string under a different key; this handles that case
This commit is contained in:
parent
a62d94a60d
commit
a902c77057
1 changed files with 20 additions and 0 deletions
|
@ -307,4 +307,24 @@ abstract class CoinServiceAPI {
|
|||
|
||||
// used for electrumx coins
|
||||
Future<void> updateSentCachedTxData(Map<String, dynamic> txData);
|
||||
|
||||
// Certain outputs return address as an array/list of strings like List<String> ["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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue