From a66eee2922ec7ed864159e31c0bf511d7d4900ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hampus=20Sj=C3=B6berg?= Date: Tue, 3 Oct 2023 22:47:10 +0200 Subject: [PATCH] Add the ability to delete neutrino files --- .../java/com/blixtwallet/LndMobileTools.java | 13 +++++ ios/LndMobile/LndMobileTools.m | 5 ++ ios/LndMobile/LndMobileTools.swift | 26 ++++++++++ src/lndmobile/LndMobile.d.ts | 1 + src/windows/InitProcess/DEV_Commands.tsx | 7 ++- src/windows/Settings/Settings.tsx | 50 ++++++++++++++++++- 6 files changed, 100 insertions(+), 2 deletions(-) diff --git a/android/app/src/main/java/com/blixtwallet/LndMobileTools.java b/android/app/src/main/java/com/blixtwallet/LndMobileTools.java index 24aac5f93..6f7ab0f6a 100644 --- a/android/app/src/main/java/com/blixtwallet/LndMobileTools.java +++ b/android/app/src/main/java/com/blixtwallet/LndMobileTools.java @@ -657,6 +657,19 @@ public void DEBUG_deleteSpeedloaderDgraphDirectory(Promise promise) { promise.resolve(null); } + @ReactMethod + public void DEBUG_deleteNeutrinoFiles(Promise promise) { + String chainFolder = getReactApplicationContext().getFilesDir().toString() + "/data/chain/bitcoin/" + BuildConfig.CHAIN; + + String neutrinoDb = chainFolder + "/neutrino.db"; + String blockHeadersBin = chainFolder + "/block_headers.bin"; + String regHeadersBin = chainFolder + "/reg_filter_headers.bin"; + File neutrinoDbFile = new File(neutrinoDb); + File blockHeadersBinFile = new File(blockHeadersBin); + File regHeadersBinFiles = new File(regHeadersBin); + promise.resolve(neutrinoDbFile.delete() && blockHeadersBinFile.delete() && regHeadersBinFiles.delete()); + } + @ReactMethod public void DEBUG_listProcesses(Promise promise) { String processes = ""; diff --git a/ios/LndMobile/LndMobileTools.m b/ios/LndMobile/LndMobileTools.m index 3befaf666..68dd75853 100644 --- a/ios/LndMobile/LndMobileTools.m +++ b/ios/LndMobile/LndMobileTools.m @@ -67,6 +67,11 @@ @interface RCT_EXTERN_MODULE(LndMobileTools, RCTEventEmitter) rejecter: (RCTPromiseRejectBlock)reject ) +RCT_EXTERN_METHOD( + DEBUG_deleteNeutrinoFiles: (RCTPromiseResolveBlock)resolve + rejecter: (RCTPromiseRejectBlock)reject +) + RCT_EXTERN_METHOD( checkApplicationSupportExists: (RCTPromiseResolveBlock)resolve rejecter: (RCTPromiseRejectBlock)reject diff --git a/ios/LndMobile/LndMobileTools.swift b/ios/LndMobile/LndMobileTools.swift index 015858dc0..7ebf58506 100644 --- a/ios/LndMobile/LndMobileTools.swift +++ b/ios/LndMobile/LndMobileTools.swift @@ -372,6 +372,32 @@ autopilot.heuristic=preferential:0.05 resolve(nil) } + @objc(DEBUG_deleteNeutrinoFiles:rejecter:) + func DEBUG_deleteNeutrinoFiles(resolver resolve: RCTPromiseResolveBlock, rejecter reject: RCTPromiseRejectBlock) { + let chain = Bundle.main.object(forInfoDictionaryKey: "CHAIN") as? String + let applicationSupport = FileManager.default.urls(for: .applicationSupportDirectory, in: .userDomainMask)[0] + let chainPath = applicationSupport.appendingPathComponent("lnd", isDirectory: true) + .appendingPathComponent("data", isDirectory: true) + .appendingPathComponent("chain", isDirectory: true) + .appendingPathComponent("bitcoin", isDirectory: true) + .appendingPathComponent(chain ?? "mainnet", isDirectory: true) + + let neutrinoDbPath = chainPath.appendingPathComponent("neutrino.db") + let blockHeadersBinPath = chainPath.appendingPathComponent("block_headers.bin") + let regFiltersHeadersBinPath = chainPath.appendingPathComponent("reg_filter_headers.bin") + + do { + try FileManager.default.removeItem(at: neutrinoDbPath) + try FileManager.default.removeItem(at: blockHeadersBinPath) + try FileManager.default.removeItem(at: regFiltersHeadersBinPath) + } catch { + reject("error", error.localizedDescription, error) + return + } + + resolve(true) + } + @objc(checkApplicationSupportExists:rejecter:) func checkApplicationSupportExists(resolver resolve: RCTPromiseResolveBlock, rejecter reject: RCTPromiseRejectBlock) { let applicationSupport = FileManager.default.urls(for: .applicationSupportDirectory, in: .userDomainMask).first! diff --git a/src/lndmobile/LndMobile.d.ts b/src/lndmobile/LndMobile.d.ts index 72e17f75e..176750133 100644 --- a/src/lndmobile/LndMobile.d.ts +++ b/src/lndmobile/LndMobile.d.ts @@ -42,6 +42,7 @@ export interface ILndMobileTools { getTorEnabled(): Promise; DEBUG_deleteSpeedloaderLastrunFile(): boolean; DEBUG_deleteSpeedloaderDgraphDirectory(): null; + DEBUG_deleteNeutrinoFiles(): boolean; // Android-specific getIntentStringData(): Promise; diff --git a/src/windows/InitProcess/DEV_Commands.tsx b/src/windows/InitProcess/DEV_Commands.tsx index f4f57a36d..9fa0dd9f9 100644 --- a/src/windows/InitProcess/DEV_Commands.tsx +++ b/src/windows/InitProcess/DEV_Commands.tsx @@ -402,6 +402,9 @@ console.log(x); + Electron: - + Sqlite: