Fix address has no matching Script error

This commit is contained in:
likho 2022-11-30 11:02:52 +02:00
parent be5e9189f4
commit 3d8ae35956

View file

@ -201,17 +201,15 @@ class ParticlWallet extends CoinServiceAPI {
@override @override
Future<Decimal> get pendingBalance async { Future<Decimal> get pendingBalance async {
final data = await utxoData; final data = await utxoData;
return Format.satoshisToAmount( return Format.satoshisToAmount(data.satoshiBalanceUnconfirmed, coin: coin);
data.satoshiBalanceUnconfirmed,
coin: coin);
} }
@override @override
Future<Decimal> get balanceMinusMaxFee async => Future<Decimal> get balanceMinusMaxFee async =>
(await availableBalance) - (await availableBalance) -
(Decimal.fromInt((await maxFee)) / (Decimal.fromInt((await maxFee)) /
Decimal.fromInt(Constants.satsPerCoin(coin))) Decimal.fromInt(Constants.satsPerCoin(coin)))
.toDecimal(); .toDecimal();
@override @override
Future<Decimal> get totalBalance async { Future<Decimal> get totalBalance async {
@ -220,19 +218,13 @@ class ParticlWallet extends CoinServiceAPI {
.get<dynamic>(boxName: walletId, key: 'totalBalance') as int?; .get<dynamic>(boxName: walletId, key: 'totalBalance') as int?;
if (totalBalance == null) { if (totalBalance == null) {
final data = await utxoData; final data = await utxoData;
return Format.satoshisToAmount( return Format.satoshisToAmount(data.satoshiBalance, coin: coin);
data.satoshiBalance,
coin: coin);
} else { } else {
return Format.satoshisToAmount( return Format.satoshisToAmount(totalBalance, coin: coin);
totalBalance,
coin: coin);
} }
} }
final data = await utxoData; final data = await utxoData;
return Format.satoshisToAmount( return Format.satoshisToAmount(data.satoshiBalance, coin: coin);
data.satoshiBalance,
coin: coin);
} }
@override @override
@ -320,7 +312,7 @@ class ParticlWallet extends CoinServiceAPI {
throw ArgumentError('Invalid version or Network mismatch'); throw ArgumentError('Invalid version or Network mismatch');
} else { } else {
try { try {
decodeBech32 = segwit.decode(address); decodeBech32 = segwit.decode(address, particl.bech32!);
} catch (err) { } catch (err) {
// Bech32 decode fail // Bech32 decode fail
} }
@ -1095,7 +1087,7 @@ class ParticlWallet extends CoinServiceAPI {
// check for send all // check for send all
bool isSendAll = false; bool isSendAll = false;
final balance = final balance =
Format.decimalAmountToSatoshis(await availableBalance, coin); Format.decimalAmountToSatoshis(await availableBalance, coin);
if (satoshiAmount == balance) { if (satoshiAmount == balance) {
isSendAll = true; isSendAll = true;
} }
@ -1294,14 +1286,14 @@ class ParticlWallet extends CoinServiceAPI {
@override @override
Future<void> updateSentCachedTxData(Map<String, dynamic> txData) async { Future<void> updateSentCachedTxData(Map<String, dynamic> txData) async {
final priceData = final priceData =
await _priceAPI.getPricesAnd24hChange(baseCurrency: _prefs.currency); await _priceAPI.getPricesAnd24hChange(baseCurrency: _prefs.currency);
Decimal currentPrice = priceData[coin]?.item1 ?? Decimal.zero; Decimal currentPrice = priceData[coin]?.item1 ?? Decimal.zero;
final locale = await Devicelocale.currentLocale; final locale = 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)) /
Decimal.fromInt(Constants.satsPerCoin(coin))) Decimal.fromInt(Constants.satsPerCoin(coin)))
.toDecimal(scaleOnInfinitePrecision: 2), .toDecimal(scaleOnInfinitePrecision: 2),
decimalPlaces: 2, decimalPlaces: 2,
locale: locale!); locale: locale!);
@ -1336,7 +1328,7 @@ class ParticlWallet extends CoinServiceAPI {
@override @override
bool validateAddress(String address) { bool validateAddress(String address) {
return Address.validateAddress(address, _network); return Address.validateAddress(address, _network, particl.bech32!);
} }
@override @override
@ -1424,7 +1416,8 @@ class ParticlWallet extends CoinServiceAPI {
} }
Future<ElectrumXNode> getCurrentNode() async { Future<ElectrumXNode> getCurrentNode() async {
final node = NodeService(secureStorageInterface: _secureStore).getPrimaryNodeFor(coin: coin) ?? final node = NodeService(secureStorageInterface: _secureStore)
.getPrimaryNodeFor(coin: coin) ??
DefaultNodes.getNodeFor(coin); DefaultNodes.getNodeFor(coin);
return ElectrumXNode( return ElectrumXNode(
@ -1965,7 +1958,7 @@ class ParticlWallet extends CoinServiceAPI {
utxo["status"]["block_time"] = txn["blocktime"]; utxo["status"]["block_time"] = txn["blocktime"];
final fiatValue = ((Decimal.fromInt(value) * currentPrice) / final fiatValue = ((Decimal.fromInt(value) * currentPrice) /
Decimal.fromInt(Constants.satsPerCoin(coin))) Decimal.fromInt(Constants.satsPerCoin(coin)))
.toDecimal(scaleOnInfinitePrecision: 2); .toDecimal(scaleOnInfinitePrecision: 2);
utxo["rawWorth"] = fiatValue; utxo["rawWorth"] = fiatValue;
utxo["fiatWorth"] = fiatValue.toString(); utxo["fiatWorth"] = fiatValue.toString();
@ -1974,17 +1967,17 @@ class ParticlWallet extends CoinServiceAPI {
} }
Decimal currencyBalanceRaw = Decimal currencyBalanceRaw =
((Decimal.fromInt(satoshiBalance) * currentPrice) / ((Decimal.fromInt(satoshiBalance) * currentPrice) /
Decimal.fromInt(Constants.satsPerCoin(coin))) Decimal.fromInt(Constants.satsPerCoin(coin)))
.toDecimal(scaleOnInfinitePrecision: 2); .toDecimal(scaleOnInfinitePrecision: 2);
final Map<String, dynamic> result = { final Map<String, dynamic> result = {
"total_user_currency": currencyBalanceRaw.toString(), "total_user_currency": currencyBalanceRaw.toString(),
"total_sats": satoshiBalance, "total_sats": satoshiBalance,
"total_btc": (Decimal.fromInt(satoshiBalance) / "total_btc": (Decimal.fromInt(satoshiBalance) /
Decimal.fromInt(Constants.satsPerCoin(coin))) Decimal.fromInt(Constants.satsPerCoin(coin)))
.toDecimal( .toDecimal(
scaleOnInfinitePrecision: Constants.decimalPlacesForCoin(coin)) scaleOnInfinitePrecision: Constants.decimalPlacesForCoin(coin))
.toString(), .toString(),
"outputArray": outputArray, "outputArray": outputArray,
"unconfirmed": satoshiBalancePending, "unconfirmed": satoshiBalancePending,
@ -2266,7 +2259,8 @@ class ParticlWallet extends CoinServiceAPI {
/// Returns the scripthash or throws an exception on invalid particl address /// Returns the scripthash or throws an exception on invalid particl address
String _convertToScriptHash(String particlAddress, NetworkType network) { String _convertToScriptHash(String particlAddress, NetworkType network) {
try { try {
final output = Address.addressToOutputScript(particlAddress, network); final output = Address.addressToOutputScript(
particlAddress, network, particl.bech32!);
final hash = sha256.convert(output.toList(growable: false)).toString(); final hash = sha256.convert(output.toList(growable: false)).toString();
final chars = hash.split(""); final chars = hash.split("");
@ -3319,7 +3313,7 @@ class ParticlWallet extends CoinServiceAPI {
// Add transaction output // Add transaction output
for (var i = 0; i < recipients.length; i++) { for (var i = 0; i < recipients.length; i++) {
txb.addOutput(recipients[i], satoshiAmounts[i]); txb.addOutput(recipients[i], satoshiAmounts[i], particl.bech32!);
} }
try { try {
@ -3750,7 +3744,8 @@ class ParticlWallet extends CoinServiceAPI {
@override @override
Future<int> estimateFeeFor(int satoshiAmount, int feeRate) async { Future<int> estimateFeeFor(int satoshiAmount, int feeRate) async {
final available = Format.decimalAmountToSatoshis(await availableBalance, coin); final available =
Format.decimalAmountToSatoshis(await availableBalance, coin);
if (available == satoshiAmount) { if (available == satoshiAmount) {
return satoshiAmount - sweepAllEstimate(feeRate); return satoshiAmount - sweepAllEstimate(feeRate);