mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2025-03-21 06:38:52 +00:00
add getAddresses helper func for Firo
don't assume keys exist without checking them
This commit is contained in:
parent
2dbd81fd4c
commit
2495673f79
2 changed files with 33 additions and 11 deletions
|
@ -327,4 +327,22 @@ abstract class CoinServiceAPI {
|
||||||
|
|
||||||
return address;
|
return address;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Firo wants an array/list of address strings like List<String>
|
||||||
|
List? getAddresses(dynamic output) {
|
||||||
|
List? addresses;
|
||||||
|
if (output.containsKey('scriptPubKey') as bool) {
|
||||||
|
if (output["scriptPubKey"].containsKey('addresses') as bool) {
|
||||||
|
addresses = output["scriptPubKey"]["addresses"] as List?;
|
||||||
|
} else if (output["scriptPubKey"].containsKey('address') as bool) {
|
||||||
|
addresses = [output["scriptPubKey"]["address"]];
|
||||||
|
}
|
||||||
|
} /*else {
|
||||||
|
// TODO detect cases in which no scriptPubKey exists
|
||||||
|
Logging.instance.log("output type not detected; output: ${output}",
|
||||||
|
level: LogLevel.Info);
|
||||||
|
}*/
|
||||||
|
|
||||||
|
return addresses;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -883,7 +883,8 @@ class FiroWallet extends CoinServiceAPI {
|
||||||
@override
|
@override
|
||||||
Future<void> updateSentCachedTxData(Map<String, dynamic> txData) async {
|
Future<void> updateSentCachedTxData(Map<String, dynamic> txData) async {
|
||||||
final currentPrice = await firoPrice;
|
final currentPrice = await firoPrice;
|
||||||
final locale = Platform.isWindows ? "en_US" : await Devicelocale.currentLocale;
|
final locale =
|
||||||
|
Platform.isWindows ? "en_US" : await Devicelocale.currentLocale;
|
||||||
final String worthNow = Format.localizedStringAsFixed(
|
final String worthNow = Format.localizedStringAsFixed(
|
||||||
value:
|
value:
|
||||||
((currentPrice * Decimal.fromInt(txData["recipientAmt"] as int)) /
|
((currentPrice * Decimal.fromInt(txData["recipientAmt"] as int)) /
|
||||||
|
@ -1691,7 +1692,7 @@ class FiroWallet extends CoinServiceAPI {
|
||||||
for (final output in tx["vout"] as List) {
|
for (final output in tx["vout"] as List) {
|
||||||
final n = output["n"];
|
final n = output["n"];
|
||||||
if (n != null && n == utxosToUse[i].vout) {
|
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)) {
|
if (!addressTxid.containsKey(address)) {
|
||||||
addressTxid[address] = <String>[];
|
addressTxid[address] = <String>[];
|
||||||
|
@ -2654,8 +2655,7 @@ class FiroWallet extends CoinServiceAPI {
|
||||||
|
|
||||||
final vouts = tx["vout"] as List?;
|
final vouts = tx["vout"] as List?;
|
||||||
if (vouts != null && outputIndex < vouts.length) {
|
if (vouts != null && outputIndex < vouts.length) {
|
||||||
final address =
|
final address = getAddress(vouts[outputIndex]);
|
||||||
vouts[outputIndex]["scriptPubKey"]["addresses"][0] as String?;
|
|
||||||
if (address != null) {
|
if (address != null) {
|
||||||
addressesToDerive.add(address);
|
addressesToDerive.add(address);
|
||||||
}
|
}
|
||||||
|
@ -2756,7 +2756,8 @@ class FiroWallet extends CoinServiceAPI {
|
||||||
var price = await firoPrice;
|
var price = await firoPrice;
|
||||||
var builtHex = txb.build();
|
var builtHex = txb.build();
|
||||||
// return builtHex;
|
// return builtHex;
|
||||||
final locale =Platform.isWindows ? "en_US" : await Devicelocale.currentLocale;
|
final locale =
|
||||||
|
Platform.isWindows ? "en_US" : await Devicelocale.currentLocale;
|
||||||
return {
|
return {
|
||||||
"transaction": builtHex,
|
"transaction": builtHex,
|
||||||
"txid": txId,
|
"txid": txId,
|
||||||
|
@ -2810,7 +2811,8 @@ class FiroWallet extends CoinServiceAPI {
|
||||||
final currentPrice = await firoPrice;
|
final currentPrice = await firoPrice;
|
||||||
// Grab the most recent information on all the joinsplits
|
// Grab the most recent information on all the joinsplits
|
||||||
|
|
||||||
final locale = Platform.isWindows ? "en_US" : await Devicelocale.currentLocale;
|
final locale =
|
||||||
|
Platform.isWindows ? "en_US" : await Devicelocale.currentLocale;
|
||||||
final updatedJSplit = await getJMintTransactions(cachedElectrumXClient,
|
final updatedJSplit = await getJMintTransactions(cachedElectrumXClient,
|
||||||
joinsplits, _prefs.currency, coin, currentPrice, locale!);
|
joinsplits, _prefs.currency, coin, currentPrice, locale!);
|
||||||
|
|
||||||
|
@ -3249,7 +3251,8 @@ class FiroWallet extends CoinServiceAPI {
|
||||||
final currentPrice = await firoPrice;
|
final currentPrice = await firoPrice;
|
||||||
final List<Map<String, dynamic>> midSortedArray = [];
|
final List<Map<String, dynamic>> midSortedArray = [];
|
||||||
|
|
||||||
final locale = Platform.isWindows ? "en_US" : await Devicelocale.currentLocale;
|
final locale =
|
||||||
|
Platform.isWindows ? "en_US" : await Devicelocale.currentLocale;
|
||||||
|
|
||||||
Logging.instance.log("refresh the txs", level: LogLevel.Info);
|
Logging.instance.log("refresh the txs", level: LogLevel.Info);
|
||||||
for (final txObject in allTransactions) {
|
for (final txObject in allTransactions) {
|
||||||
|
@ -3275,7 +3278,7 @@ class FiroWallet extends CoinServiceAPI {
|
||||||
// Logging.instance.log("sendersArray: $sendersArray");
|
// Logging.instance.log("sendersArray: $sendersArray");
|
||||||
|
|
||||||
for (final output in txObject["vout"] as List) {
|
for (final output in txObject["vout"] as List) {
|
||||||
final addresses = output["scriptPubKey"]["addresses"] as List?;
|
final addresses = getAddresses(output);
|
||||||
if (addresses != null && addresses.isNotEmpty) {
|
if (addresses != null && addresses.isNotEmpty) {
|
||||||
recipientsArray.add(addresses[0] as String);
|
recipientsArray.add(addresses[0] as String);
|
||||||
}
|
}
|
||||||
|
@ -3319,7 +3322,7 @@ class FiroWallet extends CoinServiceAPI {
|
||||||
}
|
}
|
||||||
|
|
||||||
for (final output in txObject["vout"] as List) {
|
for (final output in txObject["vout"] as List) {
|
||||||
final addresses = output["scriptPubKey"]["addresses"] as List?;
|
final addresses = getAddresses(output);
|
||||||
final value = output["value"] ?? 0;
|
final value = output["value"] ?? 0;
|
||||||
if (addresses != null && addresses.isNotEmpty) {
|
if (addresses != null && addresses.isNotEmpty) {
|
||||||
final address = addresses[0] as String;
|
final address = addresses[0] as String;
|
||||||
|
@ -4375,7 +4378,8 @@ class FiroWallet extends CoinServiceAPI {
|
||||||
final lelantusEntry = await _getLelantusEntry();
|
final lelantusEntry = await _getLelantusEntry();
|
||||||
final anonymitySets = await fetchAnonymitySets();
|
final anonymitySets = await fetchAnonymitySets();
|
||||||
final locktime = await getBlockHead(electrumXClient);
|
final locktime = await getBlockHead(electrumXClient);
|
||||||
final locale = Platform.isWindows ? "en_US" : await Devicelocale.currentLocale;
|
final locale =
|
||||||
|
Platform.isWindows ? "en_US" : await Devicelocale.currentLocale;
|
||||||
|
|
||||||
ReceivePort receivePort = await getIsolate({
|
ReceivePort receivePort = await getIsolate({
|
||||||
"function": "createJoinSplit",
|
"function": "createJoinSplit",
|
||||||
|
@ -4742,7 +4746,7 @@ class FiroWallet extends CoinServiceAPI {
|
||||||
}
|
}
|
||||||
tx["amount"] = tx["vout"][sendIndex]["value"];
|
tx["amount"] = tx["vout"][sendIndex]["value"];
|
||||||
|
|
||||||
tx["address"] = tx["vout"][sendIndex]["scriptPubKey"]["addresses"][0];
|
tx["address"] = getAddress(tx["vout"][sendIndex]) as String;
|
||||||
|
|
||||||
tx["fees"] = tx["vin"][0]["nFees"];
|
tx["fees"] = tx["vin"][0]["nFees"];
|
||||||
tx["inputSize"] = tx["vin"].length;
|
tx["inputSize"] = tx["vin"].length;
|
||||||
|
|
Loading…
Reference in a new issue