diff --git a/cw_bitcoin/lib/litecoin_wallet.dart b/cw_bitcoin/lib/litecoin_wallet.dart index d4adb1035..61f75d211 100644 --- a/cw_bitcoin/lib/litecoin_wallet.dart +++ b/cw_bitcoin/lib/litecoin_wallet.dart @@ -3,6 +3,8 @@ import 'dart:math'; import 'package:collection/collection.dart'; import 'package:convert/convert.dart'; import 'package:crypto/crypto.dart'; +import 'package:cw_core/cake_hive.dart'; +import 'package:cw_core/mweb_utxo.dart'; import 'package:fixnum/fixnum.dart'; import 'package:bitcoin_base/bitcoin_base.dart'; import 'package:cw_bitcoin/bitcoin_mnemonic.dart'; @@ -77,6 +79,7 @@ abstract class LitecoinWalletBase extends ElectrumWallet with Store { } final bitcoin.HDWallet mwebHd; + late final Box mwebUtxosBox; Timer? _syncTimer; static Future create( @@ -140,7 +143,9 @@ abstract class LitecoinWalletBase extends ElectrumWallet with Store { ); } + final Map mwebUtxos = {}; int mwebUtxosHeight = 0; + int lastMwebUtxosHeight = 2699272; @action @override @@ -187,8 +192,18 @@ abstract class LitecoinWalletBase extends ElectrumWallet with Store { processMwebUtxos(); } - final Map mwebUtxos = {}; - int lastMwebUtxosHeight = 0; + Future initMwebUtxosBox() async { + final boxName = "${walletInfo.name.replaceAll(" ", "_")}_${MwebUtxo.boxName}"; + + mwebUtxosBox = await CakeHive.openBox(boxName); + } + + // final Map mwebUtxo = MwebUtxo(); + + @override + Future init() async { + await initMwebUtxosBox(); + } Future processMwebUtxos() async { final stub = await CwMweb.stub(); @@ -487,4 +502,9 @@ abstract class LitecoinWalletBase extends ElectrumWallet with Store { await updateBalance(); }); } + + @override + Future save() async { + await super.save(); + } } diff --git a/cw_core/lib/hive_type_ids.dart b/cw_core/lib/hive_type_ids.dart index 4da616a79..6432c484b 100644 --- a/cw_core/lib/hive_type_ids.dart +++ b/cw_core/lib/hive_type_ids.dart @@ -18,3 +18,4 @@ const SPL_TOKEN_TYPE_ID = 16; const DERIVATION_INFO_TYPE_ID = 17; const TRON_TOKEN_TYPE_ID = 18; const HARDWARE_WALLET_TYPE_TYPE_ID = 19; +const MWEB_UTXO_TYPE_ID = 20; \ No newline at end of file diff --git a/cw_core/lib/mweb_utxo.dart b/cw_core/lib/mweb_utxo.dart new file mode 100644 index 000000000..02f162a37 --- /dev/null +++ b/cw_core/lib/mweb_utxo.dart @@ -0,0 +1,25 @@ +import 'package:cw_core/hive_type_ids.dart'; +import 'package:hive/hive.dart'; + +// part 'mweb_utxo.g.dart'; + +@HiveType(typeId: MWEB_UTXO_TYPE_ID) +class MwebUtxo extends HiveObject { + MwebUtxo({ + required this.address, + this.accountIndex, + required this.label, + }); + + static const typeId = MWEB_UTXO_TYPE_ID; + static const boxName = 'MwebUtxo'; + + @HiveField(0) + int? accountIndex; + + @HiveField(1, defaultValue: '') + String address; + + @HiveField(2, defaultValue: '') + String label; +} diff --git a/cw_mweb/android/src/main/kotlin/com/cakewallet/mweb/CwMwebPlugin.kt b/cw_mweb/android/src/main/kotlin/com/cakewallet/mweb/CwMwebPlugin.kt index d3d4140ef..fa4fc909f 100644 --- a/cw_mweb/android/src/main/kotlin/com/cakewallet/mweb/CwMwebPlugin.kt +++ b/cw_mweb/android/src/main/kotlin/com/cakewallet/mweb/CwMwebPlugin.kt @@ -40,5 +40,6 @@ class CwMwebPlugin: FlutterPlugin, MethodCallHandler { override fun onDetachedFromEngine(@NonNull binding: FlutterPlugin.FlutterPluginBinding) { channel.setMethodCallHandler(null) server?.stop() + server = null } } diff --git a/cw_mweb/ios/Classes/CwMwebPlugin.swift b/cw_mweb/ios/Classes/CwMwebPlugin.swift index a5fa63c5f..fa1ac39ad 100644 --- a/cw_mweb/ios/Classes/CwMwebPlugin.swift +++ b/cw_mweb/ios/Classes/CwMwebPlugin.swift @@ -49,4 +49,10 @@ public class CwMwebPlugin: NSObject, FlutterPlugin { result(FlutterMethodNotImplemented) } } + + deinit { + // Perform cleanup tasks + CwMwebPlugin.server?.stop() + CwMwebPlugin.server = nil + } } diff --git a/scripts/android/build_mwebd.sh b/scripts/android/build_mwebd.sh new file mode 100644 index 000000000..412bef973 --- /dev/null +++ b/scripts/android/build_mwebd.sh @@ -0,0 +1,7 @@ +git clone https://github.com/ltcmweb/mwebd +cd mwebd +go install github.com/ltcmweb/mwebd/cmd/mwebd@latest +gomobile bind -target=android -androidapi 19 github.com/ltcmweb/mwebd + +mkdir -p ../../../cw_mweb/android/libs/ +mv ./mwebd.aar $_ \ No newline at end of file