This commit is contained in:
Matthew Fosse 2024-07-17 09:27:31 -07:00
parent 80d56bc400
commit ef458d1dae
6 changed files with 45 additions and 16 deletions

View file

@ -87,7 +87,6 @@ abstract class LitecoinWalletBase extends ElectrumWallet with Store {
final bitcoin.HDWallet mwebHd;
late final Box<MwebUtxo> mwebUtxosBox;
Timer? _syncTimer;
// late int lastMwebUtxosHeight;
int mwebUtxosHeight = 0;
late RpcClient _stub;
@ -156,6 +155,7 @@ abstract class LitecoinWalletBase extends ElectrumWallet with Store {
@override
Future<void> startSync() async {
await super.startSync();
_stub = await CwMweb.stub();
_syncTimer?.cancel();
_syncTimer = Timer.periodic(const Duration(milliseconds: 1500), (timer) async {
if (syncStatus is FailedSyncStatus) return;
@ -197,6 +197,13 @@ abstract class LitecoinWalletBase extends ElectrumWallet with Store {
processMwebUtxos();
}
@action
@override
Future<void> stopSync() async {
_syncTimer?.cancel();
await CwMweb.stop();
}
Future<void> initMwebUtxosBox() async {
final boxName = "${walletInfo.name.replaceAll(" ", "_")}_${MwebUtxo.boxName}";

View file

@ -65,11 +65,12 @@ abstract class WalletBase<BalanceType extends Balance, HistoryType extends Trans
Future<void> startSync();
Future<void> stopSync() async {}
Future<PendingTransaction> createTransaction(Object credentials);
int calculateEstimatedFee(TransactionPriority priority, int? amount);
// void fetchTransactionsAsync(
// void Function(TransactionType transaction) onTransactionLoaded,
// {void Function() onFinished});
@ -90,7 +91,8 @@ abstract class WalletBase<BalanceType extends Balance, HistoryType extends Trans
Future<void> renameWalletFiles(String newWalletName);
Future<String> signMessage(String message, {String? address = null}) => throw UnimplementedError();
Future<String> signMessage(String message, {String? address = null}) =>
throw UnimplementedError();
bool? isTestnet;
}

View file

@ -21,13 +21,21 @@ public class CwMwebPlugin: NSObject, FlutterPlugin {
// print("args: \(args)")
let dataDir = args?["dataDir"]
var error: NSError?
if dataDir == "stop" && CwMwebPlugin.server != nil {
print("Stopping server")
CwMwebPlugin.server?.stop()
CwMwebPlugin.server = nil
result(0)
return
}
if CwMwebPlugin.server == nil {
CwMwebPlugin.server = MwebdNewServer("", dataDir, "", &error)
if let server = CwMwebPlugin.server {
do {
print("starting server2 \(CwMwebPlugin.port)")
print("starting server \(CwMwebPlugin.port)")
try server.start(0, ret0_: &CwMwebPlugin.port)
result(CwMwebPlugin.port)
} catch let startError as NSError {

View file

@ -6,9 +6,21 @@ import 'mwebd.pbgrpc.dart';
class CwMweb {
static Future<RpcClient> stub() async {
final appDir = await getApplicationSupportDirectory();
return RpcClient(ClientChannel('127.0.0.1',
port: await CwMwebPlatform.instance.start(appDir.path) ?? 0,
options: const ChannelOptions(
credentials: ChannelCredentials.insecure())));
int port = await CwMwebPlatform.instance.start(appDir.path) ?? 0;
return RpcClient(
ClientChannel('127.0.0.1',
port: port,
options: const ChannelOptions(
credentials: ChannelCredentials.insecure(),
keepAlive: ClientKeepAliveOptions(permitWithoutCalls: true),
), channelShutdownHandler: () {
print("CHANNEL IS BEING SHUT DOWN");
// CwMwebPlatform.instance.stop();
}),
);
}
static Future<void> stop() async {
await CwMwebPlatform.instance.start("stop");
}
}

View file

@ -143,12 +143,4 @@ import workmanager
}
}
override func applicationDidBecomeActive(_ application: UIApplication) {
signal(SIGPIPE, SIG_IGN);
}
override func applicationWillEnterForeground(_ application: UIApplication) {
signal(SIGPIPE, SIG_IGN);
}
}

View file

@ -4,6 +4,7 @@ import 'package:cake_wallet/core/totp_request_details.dart';
import 'package:cake_wallet/utils/device_info.dart';
import 'package:cake_wallet/view_model/link_view_model.dart';
import 'package:cw_core/wallet_base.dart';
import 'package:cw_core/wallet_type.dart';
import 'package:flutter/material.dart';
import 'package:cake_wallet/routes.dart';
import 'package:cake_wallet/src/screens/auth/auth_page.dart';
@ -133,6 +134,10 @@ class RootState extends State<Root> with WidgetsBindingObserver {
setState(() => _setInactive(true));
}
if (widget.appStore.wallet?.type == WalletType.litecoin) {
widget.appStore.wallet?.stopSync();
}
break;
case AppLifecycleState.resumed:
widget.authService.requireAuth().then((value) {
@ -142,6 +147,9 @@ class RootState extends State<Root> with WidgetsBindingObserver {
});
}
});
if (widget.appStore.wallet?.type == WalletType.litecoin) {
widget.appStore.wallet?.startSync();
}
break;
default:
break;