use getAddress with BTC, LTC, NMC, and PART

This commit is contained in:
sneurlax 2023-01-05 12:13:26 -06:00
parent fb7c58f60a
commit 2dbd81fd4c
5 changed files with 33 additions and 38 deletions

View file

@ -1297,7 +1297,8 @@ class BitcoinWallet extends CoinServiceAPI {
final priceData =
await _priceAPI.getPricesAnd24hChange(baseCurrency: _prefs.currency);
Decimal currentPrice = priceData[coin]?.item1 ?? Decimal.zero;
final locale = Platform.isWindows ? "en_US" : await Devicelocale.currentLocale;
final locale =
Platform.isWindows ? "en_US" : await Devicelocale.currentLocale;
final String worthNow = Format.localizedStringAsFixed(
value:
((currentPrice * Decimal.fromInt(txData["recipientAmt"] as int)) /
@ -2502,7 +2503,7 @@ class BitcoinWallet extends CoinServiceAPI {
for (final out in tx["vout"] as List) {
if (prevOut == out["n"]) {
final address = out["scriptPubKey"]["address"] as String?;
final address = getAddress(out) as String?;
if (address != null) {
sendersArray.add(address);
}
@ -2513,7 +2514,7 @@ class BitcoinWallet extends CoinServiceAPI {
Logging.instance.log("sendersArray: $sendersArray", level: LogLevel.Info);
for (final output in txObject["vout"] as List) {
final address = output["scriptPubKey"]["address"] as String?;
final address = getAddress(output);
if (address != null) {
recipientsArray.add(address);
}
@ -2553,7 +2554,7 @@ class BitcoinWallet extends CoinServiceAPI {
int totalOutput = 0;
for (final output in txObject["vout"] as List) {
final String address = output["scriptPubKey"]!["address"] as String;
final String address = getAddress(output) as String;
final value = output["value"]!;
final _value = (Decimal.parse(value.toString()) *
Decimal.fromInt(Constants.satsPerCoin(coin)))
@ -2578,7 +2579,7 @@ class BitcoinWallet extends CoinServiceAPI {
// add up received tx value
for (final output in txObject["vout"] as List) {
final address = output["scriptPubKey"]["address"];
final address = getAddress(output);
if (address != null) {
final value = (Decimal.parse(output["value"].toString()) *
Decimal.fromInt(Constants.satsPerCoin(coin)))
@ -3095,7 +3096,7 @@ class BitcoinWallet extends CoinServiceAPI {
for (final output in tx["vout"] as List) {
final n = output["n"];
if (n != null && n == utxosToUse[i].vout) {
final address = output["scriptPubKey"]["address"] as String;
final address = getAddress(output) as String;
if (!addressTxid.containsKey(address)) {
addressTxid[address] = <String>[];
}

View file

@ -1064,7 +1064,8 @@ class DogecoinWallet extends CoinServiceAPI {
final priceData =
await _priceAPI.getPricesAnd24hChange(baseCurrency: _prefs.currency);
Decimal currentPrice = priceData[coin]?.item1 ?? Decimal.zero;
final locale = Platform.isWindows ? "en_US" : await Devicelocale.currentLocale;
final locale =
Platform.isWindows ? "en_US" : await Devicelocale.currentLocale;
final String worthNow = Format.localizedStringAsFixed(
value:
((currentPrice * Decimal.fromInt(txData["recipientAmt"] as int)) /
@ -2113,7 +2114,7 @@ class DogecoinWallet extends CoinServiceAPI {
for (final out in tx["vout"] as List) {
if (prevOut == out["n"]) {
final address = out["scriptPubKey"]["addresses"][0] as String?;
final address = getAddress(out);
if (address != null) {
sendersArray.add(address);
}
@ -2124,7 +2125,7 @@ class DogecoinWallet extends CoinServiceAPI {
Logging.instance.log("sendersArray: $sendersArray", level: LogLevel.Info);
for (final output in txObject["vout"] as List) {
final address = output["scriptPubKey"]["addresses"][0] as String?;
final address = getAddress(output);
if (address != null) {
recipientsArray.add(address);
}
@ -2164,7 +2165,7 @@ class DogecoinWallet extends CoinServiceAPI {
int totalOutput = 0;
for (final output in txObject["vout"] as List) {
final address = output["scriptPubKey"]["addresses"][0];
final address = getAddress(output);
final value = output["value"];
final _value = (Decimal.parse(value.toString()) *
Decimal.fromInt(Constants.satsPerCoin(coin)))
@ -2189,7 +2190,7 @@ class DogecoinWallet extends CoinServiceAPI {
// add up received tx value
for (final output in txObject["vout"] as List) {
final address = output["scriptPubKey"]["addresses"][0];
final address = getAddress(output);
if (address != null) {
final value = (Decimal.parse(output["value"].toString()) *
Decimal.fromInt(Constants.satsPerCoin(coin)))
@ -2712,7 +2713,7 @@ class DogecoinWallet extends CoinServiceAPI {
for (final output in tx["vout"] as List) {
final n = output["n"];
if (n != null && n == utxosToUse[i].vout) {
final address = output["scriptPubKey"]["addresses"][0] as String;
final address = getAddress(output) as String;
if (!addressTxid.containsKey(address)) {
addressTxid[address] = <String>[];
}

View file

@ -1299,7 +1299,8 @@ class LitecoinWallet extends CoinServiceAPI {
final priceData =
await _priceAPI.getPricesAnd24hChange(baseCurrency: _prefs.currency);
Decimal currentPrice = priceData[coin]?.item1 ?? Decimal.zero;
final locale = Platform.isWindows ? "en_US" : await Devicelocale.currentLocale;
final locale =
Platform.isWindows ? "en_US" : await Devicelocale.currentLocale;
final String worthNow = Format.localizedStringAsFixed(
value:
((currentPrice * Decimal.fromInt(txData["recipientAmt"] as int)) /
@ -2513,7 +2514,7 @@ class LitecoinWallet extends CoinServiceAPI {
for (final out in tx["vout"] as List) {
if (prevOut == out["n"]) {
final address = out["scriptPubKey"]["addresses"][0] as String?;
final address = getAddress(out) as String?;
if (address != null) {
sendersArray.add(address);
}
@ -2524,7 +2525,7 @@ class LitecoinWallet extends CoinServiceAPI {
Logging.instance.log("sendersArray: $sendersArray", level: LogLevel.Info);
for (final output in txObject["vout"] as List) {
final address = output["scriptPubKey"]["addresses"][0] as String?;
final address = getAddress(output);
if (address != null) {
recipientsArray.add(address);
}
@ -2564,7 +2565,7 @@ class LitecoinWallet extends CoinServiceAPI {
int totalOutput = 0;
for (final output in txObject["vout"] as List) {
final String address =
final String address = getAddress(output) as String;
final value = output["value"] ?? 0;
final _value = (Decimal.parse(value.toString()) *
Decimal.fromInt(Constants.satsPerCoin(coin)))
@ -2589,7 +2590,7 @@ class LitecoinWallet extends CoinServiceAPI {
// add up received tx value
for (final output in txObject["vout"] as List) {
final address = output["scriptPubKey"]["addresses"][0];
final address = getAddress(output);
if (address != null) {
final value = (Decimal.parse((output["value"] ?? 0).toString()) *
Decimal.fromInt(Constants.satsPerCoin(coin)))
@ -3106,7 +3107,7 @@ class LitecoinWallet extends CoinServiceAPI {
for (final output in tx["vout"] as List) {
final n = output["n"];
if (n != null && n == utxosToUse[i].vout) {
final address = output["scriptPubKey"]["addresses"][0] as String;
final address = getAddress(output) as String;
if (!addressTxid.containsKey(address)) {
addressTxid[address] = <String>[];
}

View file

@ -1287,7 +1287,8 @@ class NamecoinWallet extends CoinServiceAPI {
final priceData =
await _priceAPI.getPricesAnd24hChange(baseCurrency: _prefs.currency);
Decimal currentPrice = priceData[coin]?.item1 ?? Decimal.zero;
final locale = Platform.isWindows ? "en_US" : await Devicelocale.currentLocale;
final locale =
Platform.isWindows ? "en_US" : await Devicelocale.currentLocale;
final String worthNow = Format.localizedStringAsFixed(
value:
((currentPrice * Decimal.fromInt(txData["recipientAmt"] as int)) /
@ -2494,11 +2495,7 @@ class NamecoinWallet extends CoinServiceAPI {
for (final out in tx["vout"] as List) {
if (prevOut == out["n"]) {
String? address = out["scriptPubKey"]["address"] as String?;
if (address == null && out["scriptPubKey"]["address"] != null) {
address = out["scriptPubKey"]["address"] as String?;
}
String? address = getAddress(out);
if (address != null) {
sendersArray.add(address);
}
@ -2509,10 +2506,7 @@ class NamecoinWallet extends CoinServiceAPI {
Logging.instance.log("sendersArray: $sendersArray", level: LogLevel.Info);
for (final output in txObject["vout"] as List) {
String? address = output["scriptPubKey"]["address"] as String?;
if (address == null && output["scriptPubKey"]["address"] != null) {
address = output["scriptPubKey"]["address"] as String?;
}
String? address = getAddress(output);
if (address != null) {
recipientsArray.add(address);
}
@ -2553,7 +2547,7 @@ class NamecoinWallet extends CoinServiceAPI {
for (final output in txObject["vout"] as List) {
Logging.instance.log(output, level: LogLevel.Info);
final address = output["scriptPubKey"]["address"];
final address = getAddress(output);
final value = output["value"] ?? 0;
final _value = (Decimal.parse(value.toString()) *
Decimal.fromInt(Constants.satsPerCoin(coin)))
@ -2578,10 +2572,7 @@ class NamecoinWallet extends CoinServiceAPI {
// add up received tx value
for (final output in txObject["vout"] as List) {
String? address = output["scriptPubKey"]["address"] as String?;
if (address == null && output["scriptPubKey"]["address"] != null) {
address = output["scriptPubKey"]["address"] as String?;
}
String? address = getAddress(output);
if (address != null) {
final value = (Decimal.parse((output["value"] ?? 0).toString()) *
Decimal.fromInt(Constants.satsPerCoin(coin)))
@ -3101,7 +3092,7 @@ class NamecoinWallet extends CoinServiceAPI {
for (final output in tx["vout"] as List) {
final n = output["n"];
if (n != null && n == utxosToUse[i].vout) {
final address = output["scriptPubKey"]["address"] as String;
final address = getAddress(output) as String;
if (!addressTxid.containsKey(address)) {
addressTxid[address] = <String>[];
}

View file

@ -1200,7 +1200,8 @@ class ParticlWallet extends CoinServiceAPI {
final priceData =
await _priceAPI.getPricesAnd24hChange(baseCurrency: _prefs.currency);
Decimal currentPrice = priceData[coin]?.item1 ?? Decimal.zero;
final locale = Platform.isWindows ? "en_US" : await Devicelocale.currentLocale;
final locale =
Platform.isWindows ? "en_US" : await Devicelocale.currentLocale;
final String worthNow = Format.localizedStringAsFixed(
value:
((currentPrice * Decimal.fromInt(txData["recipientAmt"] as int)) /
@ -2288,7 +2289,7 @@ class ParticlWallet extends CoinServiceAPI {
for (final out in tx["vout"] as List) {
if (prevOut == out["n"]) {
final address = out["scriptPubKey"]["addresses"][0] as String?;
final address = getAddress(out);
if (address != null) {
sendersArray.add(address);
}
@ -2302,7 +2303,7 @@ class ParticlWallet extends CoinServiceAPI {
// Particl has different tx types that need to be detected and handled here
if (output.containsKey('scriptPubKey') as bool) {
// Logging.instance.log("output is transparent", level: LogLevel.Info);
final address = output["scriptPubKey"]["addresses"][0] as String?;
final address = getAddress(output);
if (address != null) {
recipientsArray.add(address);
}
@ -2417,7 +2418,7 @@ class ParticlWallet extends CoinServiceAPI {
// add up received tx value
for (final output in txObject["vout"] as List) {
try {
final address = output["scriptPubKey"]["addresses"][0];
final address = getAddress(output);
if (address != null) {
final value = (Decimal.parse((output["value"] ?? 0).toString()) *
Decimal.fromInt(Constants.satsPerCoin(coin)))