Skip to content

Commit

Permalink
Add the ability to delete neutrino files
Browse files Browse the repository at this point in the history
  • Loading branch information
hsjoberg committed Oct 3, 2023
1 parent 7fff22f commit a66eee2
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 2 deletions.
13 changes: 13 additions & 0 deletions android/app/src/main/java/com/blixtwallet/LndMobileTools.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "";
Expand Down
5 changes: 5 additions & 0 deletions ios/LndMobile/LndMobileTools.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 26 additions & 0 deletions ios/LndMobile/LndMobileTools.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand Down
1 change: 1 addition & 0 deletions src/lndmobile/LndMobile.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export interface ILndMobileTools {
getTorEnabled(): Promise<boolean>;
DEBUG_deleteSpeedloaderLastrunFile(): boolean;
DEBUG_deleteSpeedloaderDgraphDirectory(): null;
DEBUG_deleteNeutrinoFiles(): boolean;

// Android-specific
getIntentStringData(): Promise<string | null>;
Expand Down
7 changes: 6 additions & 1 deletion src/windows/InitProcess/DEV_Commands.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,9 @@ console.log(x);
<Button small onPress={async () => {
console.log(await NativeModules.LndMobileTools.tailLog(10));
}}><Text style={styles.buttonText}>LndMobileTools.tailLog</Text></Button>
<Button small onPress={async () => {
console.log(await NativeModules.LndMobile.DEBUG_crash());
}}><Text style={styles.buttonText}>NativeModules.LndMobile.DEBUG_crash (Android)</Text></Button>

<Text style={{ width: "100%"}}>Electron:</Text>
<Button small onPress={async () => {
Expand Down Expand Up @@ -634,7 +637,9 @@ console.log(x);
}}>
<Text style={styles.buttonText}>connect to Bitrefill node</Text>
</Button>

<Button small onPress={async () => {
console.log(await NativeModules.LndMobileTools.DEBUG_deleteNeutrinoFiles());
}}><Text style={styles.buttonText}>NativeModules.LndMobileTools.DEBUG_deleteNeutrinoFiles()</Text></Button>

<Text style={{ width: "100%" }}>Sqlite:</Text>
<Button small onPress={async () => console.log(await createTransaction(db!, {
Expand Down
50 changes: 49 additions & 1 deletion src/windows/Settings/Settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
import { Linking, NativeModules, PermissionsAndroid, Platform, StyleSheet } from "react-native";
import { LndLogLevel, OnchainExplorer } from "../../state/Settings";
import React, { useLayoutEffect } from "react";
import { camelCaseToSpace, formatISO, hexToUint8Array, toast } from "../../utils";
import { camelCaseToSpace, formatISO, hexToUint8Array, timeout, toast } from "../../utils";
import { getChanInfo, verifyChanBackup } from "../../lndmobile/channel";
import { getNodeInfo, resetMissionControl, xImportMissionControl } from "../../lndmobile";
import { languages, namespaces } from "../../i18n/i18n.constants";
Expand Down Expand Up @@ -2469,6 +2469,54 @@ ${t("experimental.tor.disabled.msg2")}`;
<Text>Dunder MissionControl import</Text>
</Body>
</ListItem>
<ListItem
style={style.listItem}
icon={true}
onPress={async () => {
try {
await NativeModules.LndMobile.stopLnd();
await timeout(5000); // Let lnd close down
} catch (e: any) {
// If lnd was closed down already
if (e?.message?.includes?.("closed")) {
console.log("yes closed");
} else {
toast("Error: " + e.message, 10000, "danger");
return;
}
}

console.log(await NativeModules.LndMobileTools.DEBUG_deleteNeutrinoFiles());
toast("Done. Restart is required");
restartNeeded();
}}
>
<Left>
<Icon style={style.icon} type="Foundation" name="page-delete" />
</Left>
<Body>
<Text>Stop lnd and delete neutrino files</Text>
</Body>
</ListItem>
<ListItem
style={style.listItem}
icon={true}
onPress={async () => {
try {
await NativeModules.LndMobile.stopLnd();
} catch (e: any) {
toast("Error: " + e.message, 10000, "danger");
return;
}
}}
>
<Left>
<Icon style={style.icon} type="FontAwesome" name="stop" />
</Left>
<Body>
<Text>Stop lnd</Text>
</Body>
</ListItem>
</List>
</Content>
</Container>
Expand Down

1 comment on commit a66eee2

@vercel
Copy link

@vercel vercel bot commented on a66eee2 Oct 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

blixt-wallet – ./

blixt-wallet-git-master-hsjoberg.vercel.app
blixt-wallet-hsjoberg.vercel.app

Please sign in to comment.