weird ecash electrumx server edgecase

This commit is contained in:
julian 2023-11-14 17:33:08 -06:00
parent d78a3e5104
commit 268dd9dd76
2 changed files with 10 additions and 5 deletions

View file

@ -46,6 +46,7 @@ class OutputV2 {
Map<String, dynamic> json, { Map<String, dynamic> json, {
required bool walletOwns, required bool walletOwns,
required int decimalPlaces, required int decimalPlaces,
bool isECashFullAmountNotSats = false,
}) { }) {
try { try {
List<String> addresses = []; List<String> addresses = [];
@ -60,10 +61,9 @@ class OutputV2 {
return OutputV2.isarCantDoRequiredInDefaultConstructor( return OutputV2.isarCantDoRequiredInDefaultConstructor(
scriptPubKeyHex: json["scriptPubKey"]["hex"] as String, scriptPubKeyHex: json["scriptPubKey"]["hex"] as String,
valueStringSats: parseOutputAmountString( valueStringSats: parseOutputAmountString(json["value"].toString(),
json["value"].toString(), decimalPlaces: decimalPlaces,
decimalPlaces: decimalPlaces, isECashFullAmountNotSats: isECashFullAmountNotSats),
),
addresses: addresses, addresses: addresses,
walletOwns: walletOwns, walletOwns: walletOwns,
); );
@ -75,6 +75,7 @@ class OutputV2 {
static String parseOutputAmountString( static String parseOutputAmountString(
String amount, { String amount, {
required int decimalPlaces, required int decimalPlaces,
bool isECashFullAmountNotSats = false,
}) { }) {
final temp = Decimal.parse(amount); final temp = Decimal.parse(amount);
if (temp < Decimal.zero) { if (temp < Decimal.zero) {
@ -82,7 +83,9 @@ class OutputV2 {
} }
final String valueStringSats; final String valueStringSats;
if (temp.isInteger) { if (isECashFullAmountNotSats) {
valueStringSats = temp.shift(decimalPlaces).toBigInt().toString();
} else if (temp.isInteger) {
valueStringSats = temp.toString(); valueStringSats = temp.toString();
} else { } else {
valueStringSats = temp.shift(decimalPlaces).toBigInt().toString(); valueStringSats = temp.shift(decimalPlaces).toBigInt().toString();

View file

@ -168,6 +168,7 @@ class EcashWallet extends Bip39HDWallet
final prevOut = OutputV2.fromElectrumXJson( final prevOut = OutputV2.fromElectrumXJson(
prevOutJson, prevOutJson,
decimalPlaces: cryptoCurrency.fractionDigits, decimalPlaces: cryptoCurrency.fractionDigits,
isECashFullAmountNotSats: true,
walletOwns: false, // doesn't matter here as this is not saved walletOwns: false, // doesn't matter here as this is not saved
); );
@ -206,6 +207,7 @@ class EcashWallet extends Bip39HDWallet
OutputV2 output = OutputV2.fromElectrumXJson( OutputV2 output = OutputV2.fromElectrumXJson(
Map<String, dynamic>.from(outputJson as Map), Map<String, dynamic>.from(outputJson as Map),
decimalPlaces: cryptoCurrency.fractionDigits, decimalPlaces: cryptoCurrency.fractionDigits,
isECashFullAmountNotSats: true,
// don't know yet if wallet owns. Need addresses first // don't know yet if wallet owns. Need addresses first
walletOwns: false, walletOwns: false,
); );