From 728a0bf4b2880be745b544b0fc839b8bc2a2f82e Mon Sep 17 00:00:00 2001 From: fossephate <matt.cfosse@gmail.com> Date: Mon, 9 Sep 2024 13:24:50 -0700 Subject: [PATCH] more minor fixes --- cw_bitcoin/lib/litecoin_wallet.dart | 11 +++----- cw_bitcoin/lib/litecoin_wallet_addresses.dart | 25 +------------------ lib/bitcoin/cw_bitcoin.dart | 2 +- tool/configure.dart | 2 +- 4 files changed, 7 insertions(+), 33 deletions(-) diff --git a/cw_bitcoin/lib/litecoin_wallet.dart b/cw_bitcoin/lib/litecoin_wallet.dart index e3f68888e..e2010c520 100644 --- a/cw_bitcoin/lib/litecoin_wallet.dart +++ b/cw_bitcoin/lib/litecoin_wallet.dart @@ -776,6 +776,7 @@ abstract class LitecoinWalletBase extends ElectrumWallet with Store { script: outputs[0].toOutput.scriptPubKey, value: utxos.sumOfUtxosValue()) ]; } + // https://github.com/ltcmweb/mwebd?tab=readme-ov-file#fee-estimation final preOutputSum = outputs.fold<BigInt>(BigInt.zero, (acc, output) => acc + output.toOutput.amount); final fee = utxos.sumOfUtxosValue() - preOutputSum; @@ -891,19 +892,15 @@ abstract class LitecoinWalletBase extends ElectrumWallet with Store { _utxoStream?.cancel(); } - void setMwebEnabled(bool enabled) { + Future<void> setMwebEnabled(bool enabled) async { if (mwebEnabled == enabled) { return; } mwebEnabled = enabled; (walletAddresses as LitecoinWalletAddresses).mwebEnabled = enabled; - if (enabled) { - // generate inital mweb addresses: - (walletAddresses as LitecoinWalletAddresses).topUpMweb(0); - } - stopSync(); - startSync(); + await stopSync(); + await startSync(); } Future<RpcClient> getStub() async { diff --git a/cw_bitcoin/lib/litecoin_wallet_addresses.dart b/cw_bitcoin/lib/litecoin_wallet_addresses.dart index dcdf4ca1b..9f63f6662 100644 --- a/cw_bitcoin/lib/litecoin_wallet_addresses.dart +++ b/cw_bitcoin/lib/litecoin_wallet_addresses.dart @@ -2,20 +2,14 @@ import 'dart:typed_data'; import 'package:bech32/bech32.dart'; import 'package:bitcoin_base/bitcoin_base.dart'; -import 'package:blockchain_utils/bech32/bech32_base.dart'; import 'package:blockchain_utils/blockchain_utils.dart'; import 'package:cw_bitcoin/electrum_wallet.dart'; import 'package:cw_bitcoin/utils.dart'; import 'package:cw_bitcoin/electrum_wallet_addresses.dart'; import 'package:cw_core/wallet_info.dart'; import 'package:cw_mweb/cw_mweb.dart'; -import 'package:cw_mweb/mwebd.pb.dart'; import 'package:mobx/mobx.dart'; -// import 'dart:typed_data'; -// import 'package:bech32/bech32.dart'; -// import 'package:r_crypto/r_crypto.dart'; - part 'litecoin_wallet_addresses.g.dart'; String encodeMwebAddress(List<int> scriptPubKey) { @@ -36,12 +30,7 @@ abstract class LitecoinWalletAddressesBase extends ElectrumWalletAddresses with super.initialRegularAddressIndex, super.initialChangeAddressIndex, }) : super(walletInfo) { - if (mwebEnabled) { - // give the server a few seconds to start up before trying to get the addresses: - Future.delayed(const Duration(seconds: 5), () async { - await topUpMweb(0); - }); - } + topUpMweb(0); } final Bip32Slip10Secp256k1 mwebHd; @@ -79,18 +68,6 @@ abstract class LitecoinWalletAddressesBase extends ElectrumWalletAddresses with return generateP2WPKHAddress(hd: hd, index: index, network: network); } - @override - Future<String> getAddressAsync({ - required int index, - required Bip32Slip10Secp256k1 hd, - BitcoinAddressType? addressType, - }) async { - if (addressType == SegwitAddresType.mweb) { - await topUpMweb(index); - } - return getAddress(index: index, hd: hd, addressType: addressType); - } - @action @override Future<String> getChangeAddress({List<BitcoinOutput>? outputs, UtxoDetails? utxoDetails}) async { diff --git a/lib/bitcoin/cw_bitcoin.dart b/lib/bitcoin/cw_bitcoin.dart index 0c3e27930..074398263 100644 --- a/lib/bitcoin/cw_bitcoin.dart +++ b/lib/bitcoin/cw_bitcoin.dart @@ -557,7 +557,7 @@ class CWBitcoin extends Bitcoin { } @override - void setMwebEnabled(Object wallet, bool enabled) { + Future<void> setMwebEnabled(Object wallet, bool enabled) async { final litecoinWallet = wallet as LitecoinWallet; litecoinWallet.setMwebEnabled(enabled); } diff --git a/tool/configure.dart b/tool/configure.dart index 8ac6c7694..4605c99fc 100644 --- a/tool/configure.dart +++ b/tool/configure.dart @@ -224,7 +224,7 @@ abstract class Bitcoin { void setLedger(WalletBase wallet, Ledger ledger, LedgerDevice device); Future<List<HardwareAccountData>> getHardwareWalletAccounts(LedgerViewModel ledgerVM, {int index = 0, int limit = 5}); - void setMwebEnabled(Object wallet, bool enabled); + Future<void> setMwebEnabled(Object wallet, bool enabled); bool getMwebEnabled(Object wallet); } """;