mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2025-03-12 09:27:01 +00:00
small tweaks mainly targeting firo transaction parsing
This commit is contained in:
parent
cae0bada66
commit
2469c3eb91
5 changed files with 26 additions and 18 deletions
|
@ -46,7 +46,7 @@ class OutputV2 {
|
|||
Map<String, dynamic> json, {
|
||||
required bool walletOwns,
|
||||
required int decimalPlaces,
|
||||
bool isECashFullAmountNotSats = false,
|
||||
bool isFullAmountNotSats = false,
|
||||
}) {
|
||||
try {
|
||||
List<String> addresses = [];
|
||||
|
@ -61,9 +61,11 @@ class OutputV2 {
|
|||
|
||||
return OutputV2.isarCantDoRequiredInDefaultConstructor(
|
||||
scriptPubKeyHex: json["scriptPubKey"]["hex"] as String,
|
||||
valueStringSats: parseOutputAmountString(json["value"].toString(),
|
||||
decimalPlaces: decimalPlaces,
|
||||
isECashFullAmountNotSats: isECashFullAmountNotSats),
|
||||
valueStringSats: parseOutputAmountString(
|
||||
json["value"].toString(),
|
||||
decimalPlaces: decimalPlaces,
|
||||
isFullAmountNotSats: isFullAmountNotSats,
|
||||
),
|
||||
addresses: addresses,
|
||||
walletOwns: walletOwns,
|
||||
);
|
||||
|
@ -75,7 +77,7 @@ class OutputV2 {
|
|||
static String parseOutputAmountString(
|
||||
String amount, {
|
||||
required int decimalPlaces,
|
||||
bool isECashFullAmountNotSats = false,
|
||||
bool isFullAmountNotSats = false,
|
||||
}) {
|
||||
final temp = Decimal.parse(amount);
|
||||
if (temp < Decimal.zero) {
|
||||
|
@ -83,7 +85,7 @@ class OutputV2 {
|
|||
}
|
||||
|
||||
final String valueStringSats;
|
||||
if (isECashFullAmountNotSats) {
|
||||
if (isFullAmountNotSats) {
|
||||
valueStringSats = temp.shift(decimalPlaces).toBigInt().toString();
|
||||
} else if (temp.isInteger) {
|
||||
valueStringSats = temp.toString();
|
||||
|
|
|
@ -169,7 +169,7 @@ class EcashWallet extends Bip39HDWallet
|
|||
final prevOut = OutputV2.fromElectrumXJson(
|
||||
prevOutJson,
|
||||
decimalPlaces: cryptoCurrency.fractionDigits,
|
||||
isECashFullAmountNotSats: true,
|
||||
isFullAmountNotSats: true,
|
||||
walletOwns: false, // doesn't matter here as this is not saved
|
||||
);
|
||||
|
||||
|
@ -208,7 +208,7 @@ class EcashWallet extends Bip39HDWallet
|
|||
OutputV2 output = OutputV2.fromElectrumXJson(
|
||||
Map<String, dynamic>.from(outputJson as Map),
|
||||
decimalPlaces: cryptoCurrency.fractionDigits,
|
||||
isECashFullAmountNotSats: true,
|
||||
isFullAmountNotSats: true,
|
||||
// don't know yet if wallet owns. Need addresses first
|
||||
walletOwns: false,
|
||||
);
|
||||
|
|
|
@ -193,6 +193,7 @@ class FiroWallet extends Bip39HDWallet
|
|||
OutputV2 output = OutputV2.fromElectrumXJson(
|
||||
outMap,
|
||||
decimalPlaces: cryptoCurrency.fractionDigits,
|
||||
isFullAmountNotSats: true,
|
||||
// don't know yet if wallet owns. Need addresses first
|
||||
walletOwns: false,
|
||||
);
|
||||
|
@ -294,6 +295,7 @@ class FiroWallet extends Bip39HDWallet
|
|||
final prevOut = OutputV2.fromElectrumXJson(
|
||||
prevOutJson,
|
||||
decimalPlaces: cryptoCurrency.fractionDigits,
|
||||
isFullAmountNotSats: true,
|
||||
walletOwns: false, // doesn't matter here as this is not saved
|
||||
);
|
||||
|
||||
|
@ -351,6 +353,9 @@ class FiroWallet extends Bip39HDWallet
|
|||
totalOut) {
|
||||
// definitely sent all to self
|
||||
type = TransactionType.sentToSelf;
|
||||
} else if (isSparkMint) {
|
||||
// probably sent to self
|
||||
type = TransactionType.sentToSelf;
|
||||
} else if (amountReceivedInThisWallet == BigInt.zero) {
|
||||
// most likely just a typical send
|
||||
// do nothing here yet
|
||||
|
|
|
@ -421,6 +421,10 @@ abstract class Wallet<T extends CryptoCurrency> {
|
|||
.checkChangeAddressForTransactions();
|
||||
}
|
||||
GlobalEventBus.instance.fire(RefreshPercentChangedEvent(0.3, walletId));
|
||||
if (this is SparkInterface) {
|
||||
// this should be called before updateTransactions()
|
||||
await (this as SparkInterface).refreshSparkData();
|
||||
}
|
||||
|
||||
GlobalEventBus.instance.fire(RefreshPercentChangedEvent(0.50, walletId));
|
||||
final fetchFuture = updateTransactions();
|
||||
|
@ -440,9 +444,6 @@ abstract class Wallet<T extends CryptoCurrency> {
|
|||
if (this is LelantusInterface) {
|
||||
await (this as LelantusInterface).refreshLelantusData();
|
||||
}
|
||||
if (this is SparkInterface) {
|
||||
await (this as SparkInterface).refreshSparkData();
|
||||
}
|
||||
GlobalEventBus.instance.fire(RefreshPercentChangedEvent(0.90, walletId));
|
||||
|
||||
await updateBalance();
|
||||
|
|
|
@ -504,6 +504,7 @@ mixin SparkInterface on Bip39HDWallet, ElectrumXInterface {
|
|||
});
|
||||
}
|
||||
|
||||
// update wallet spark coin height
|
||||
final coinsToCheck = await mainDB.isar.sparkCoins
|
||||
.where()
|
||||
.walletIdEqualToAnyLTagHash(walletId)
|
||||
|
@ -512,15 +513,14 @@ mixin SparkInterface on Bip39HDWallet, ElectrumXInterface {
|
|||
.findAll();
|
||||
final List<SparkCoin> updatedCoins = [];
|
||||
for (final coin in coinsToCheck) {
|
||||
final storedTx = await mainDB.getTransaction(walletId, coin.txHash);
|
||||
if (storedTx?.height != null) {
|
||||
updatedCoins.add(coin.copyWith(height: storedTx!.height!));
|
||||
} else {
|
||||
// TODO fetch tx from electrumx (and parse it to db?)
|
||||
final tx = await electrumXCachedClient.getTransaction(
|
||||
txHash: coin.txHash,
|
||||
coin: info.coin,
|
||||
);
|
||||
if (tx["height"] is int) {
|
||||
updatedCoins.add(coin.copyWith(height: tx["height"] as int));
|
||||
}
|
||||
}
|
||||
|
||||
// update wallet spark coins in isar
|
||||
if (updatedCoins.isNotEmpty) {
|
||||
await mainDB.isar.writeTxn(() async {
|
||||
await mainDB.isar.sparkCoins.putAll(updatedCoins);
|
||||
|
|
Loading…
Reference in a new issue