Skip to content

Commit

Permalink
Merge pull request #2102 from kaloudis/sweepremoteclosed
Browse files Browse the repository at this point in the history
Embedded LND: chantools: sweepremoteclosed
  • Loading branch information
kaloudis authored Feb 7, 2025
2 parents f78d231 + e95b468 commit bd2c14b
Show file tree
Hide file tree
Showing 11 changed files with 656 additions and 10 deletions.
14 changes: 14 additions & 0 deletions App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,10 @@ import LSPS1Order from './views/LSPS1/Order';
import LSPS7 from './views/LSPS7/index';
import LSPS7Order from './views/LSPS7/Order';

// Chantools
import Chantools from './views/Settings/EmbeddedNode/Chantools';
import Sweepremoteclosed from './views/Settings/EmbeddedNode/Chantools/Sweepremoteclosed';

import RawTxHex from './views/RawTxHex';

import CustodialWalletWarning from './views/Settings/CustodialWalletWarning';
Expand Down Expand Up @@ -924,6 +928,16 @@ export default class App extends React.PureComponent {
DeveloperTools
}
/>
<Stack.Screen
name="Chantools" // @ts-ignore:next-line
component={Chantools}
/>
<Stack.Screen
name="Sweepremoteclosed" // @ts-ignore:next-line
component={
Sweepremoteclosed
}
/>
</Stack.Navigator>
</NavigationContainer>
</>
Expand Down
34 changes: 34 additions & 0 deletions android/app/src/main/java/com/zeus/lnc-rn/LncModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import java.net.InetSocketAddress
import java.net.ServerSocket
import java.net.Proxy;
import java.security.cert.X509Certificate
import kotlinx.coroutines.*

import app.zeusln.zeus.AndroidCallback

Expand Down Expand Up @@ -145,4 +146,37 @@ class LncModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaMod
gocb.setCallback(::sendEvent)
Lndmobile.invokeRPC(namespace, eventName, request, gocb)
}

// chantools

@ReactMethod
fun sweepRemoteClosed(
seedPhrase: String,
apiURL: String,
sweepAddr: String,
recoveryWindow: Int,
feeRate: Int,
sleepSeconds: Int,
publish: Boolean = false,
isTestnet: Boolean = false,
promise: Promise
) {
// Launch a coroutine in the background to avoid blocking the main thread
GlobalScope.launch(Dispatchers.IO) {
try {
// Perform the long-running task
val response = Lndmobile.sweepRemoteClosed(seedPhrase, apiURL, sweepAddr, recoveryWindow, feeRate, sleepSeconds, publish, isTestnet)

// When done, switch back to the main thread to resolve the promise
withContext(Dispatchers.Main) {
promise.resolve(response)
}
} catch (e: Throwable) {
// Handle errors, and make sure to switch back to the main thread to reject the promise
withContext(Dispatchers.Main) {
promise.reject("request Error", e)
}
}
}
}
}
6 changes: 3 additions & 3 deletions fetch-libraries.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
VERSION=v0.18.4-beta-zeus
VERSION=v0.18.4-beta-zeus.chantools-alpha1

ANDROID_FILE=Lndmobile.aar
IOS_FILE=Lndmobile.xcframework

ANDROID_SHA256='8f3f569fd603fb101d7de08a7f9e017cb7267fd24da549908b7733b40e54393f'
IOS_SHA256='159e63de8b4a14a402f885adb88c9b34a66c7f6c8a15cbb3c5cc2ba44a5c1bd6'
ANDROID_SHA256='db6a1953ed993ef13a843c22040560631c5870f294ec2256031fb5e73b113542'
IOS_SHA256='ceb9956853bad47391d068718364fd786767100e45d41b1660a0e421a19c4182'

FILE_PATH=https://github.com/ZeusLN/lnd/releases/download/$VERSION/

Expand Down
26 changes: 26 additions & 0 deletions ios/LncMobile/LncModule.mm
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,32 @@ -(void)stopObserving {}
];
}

// chantools

RCT_EXPORT_METHOD(sweepRemoteClosed:(NSString *)seedPhrase
apiURL:(NSString *)apiURL
sweepAddr:(NSString *)sweepAddr
recoveryWindow:(NSInteger)recoveryWindow
feeRate:(NSInteger)feeRate
sleepSeconds:(NSInteger)sleepSeconds
publish:(BOOL)publish
isTestnet:(BOOL)isTestnet
resolver:(RCTPromiseResolveBlock)resolve
rejecter:(RCTPromiseRejectBlock)reject)
{
NSError *error;
NSString *response = LndmobileSweepRemoteClosed(seedPhrase, apiURL, sweepAddr, recoveryWindow, feeRate, sleepSeconds, publish, isTestnet, &error);
if (error) {
// Create a string representation of the error
NSString *errorString = [NSString stringWithFormat:@"%@",
error.localizedDescription];

reject(@"sweepRemoteClosed_failure", errorString, error);
} else {
resolve(response);
}
}

// Don't compile this code when we build for the old architecture.
#ifdef RCT_NEW_ARCH_ENABLED
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:
Expand Down
16 changes: 16 additions & 0 deletions lndmobile/LndMobileInjection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ import {
} from './wallet';
import { status, modifyStatus, queryScores, setScores } from './autopilot';
import { checkScheduledSyncWorkStatus } from './scheduled-sync'; // TODO(hsjoberg): This could be its own injection "LndMobileScheduledSync"
import { sweepRemoteClosed } from './chantools';
import {
lnrpc,
signrpc,
Expand Down Expand Up @@ -473,6 +474,18 @@ export interface ILndMobileInjections {
scheduledSync: {
checkScheduledSyncWorkStatus: () => Promise<WorkInfo>;
};
chantools: {
sweepRemoteClosed: (
seed: string,
apiUrl: string,
sweepAddr: string,
recoveryWindow: number,
feeRate: number,
sleepSeconds: number,
publish: boolean,
isTestNet: boolean
) => Promise<string>;
};
}

// @ts-ignore:next-line
Expand Down Expand Up @@ -579,5 +592,8 @@ export default {
},
scheduledSync: {
checkScheduledSyncWorkStatus
},
chantools: {
sweepRemoteClosed
}
} as ILndMobileInjections;
24 changes: 24 additions & 0 deletions lndmobile/chantools.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { NativeModules } from 'react-native';
const { LncModule } = NativeModules;

export const sweepRemoteClosed = async (
seed: string,
apiUrl: string,
sweepAddr: string,
recoveryWindow: number,
feeRate: number,
sleepSeconds: number,
publish: boolean,
isTestNet: boolean
): Promise<string> => {
return await LncModule.sweepRemoteClosed(
seed,
apiUrl,
sweepAddr,
recoveryWindow,
feeRate,
sleepSeconds,
publish,
isTestNet
);
};
12 changes: 12 additions & 0 deletions locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1267,6 +1267,18 @@
"view.Settings.LSPServicesList.title": "LSP Services",
"view.Settings.LSPServicesList.flow2": "Just-in-time channels",
"view.Settings.LSPServicesList.lsps1": "Request channels in advance",
"views.Settings.EmbeddedNode.Chantools.Sweepremoteclosed.seedType": "Seed type",
"views.Settings.EmbeddedNode.Chantools.Sweepremoteclosed.currentWalletsSeed": "Current wallet's seed",
"views.Settings.EmbeddedNode.Chantools.Sweepremoteclosed.externalWalletSeed": "External wallet seed",
"views.Settings.EmbeddedNode.Chantools.Sweepremoteclosed.seed": "Seed phrase",
"views.Settings.EmbeddedNode.Chantools.Sweepremoteclosed.recoveryWindow": "Recovery window",
"views.Settings.EmbeddedNode.Chantools.Sweepremoteclosed.recoveryWindow.explainer": "The number of keys to scan per derivation path.",
"views.Settings.EmbeddedNode.Chantools.Sweepremoteclosed.sleepSeconds": "Seconds to wait between queries",
"views.Settings.EmbeddedNode.Chantools.Sweepremoteclosed.sleepSeconds.explainer": "Use this to add a pause between queries if you get rate limited by the API.",
"views.Settings.EmbeddedNode.Chantools.Sweepremoteclosed.sweepAddr": "Sweep address",
"views.Settings.EmbeddedNode.Chantools.Sweepremoteclosed.apiUrl": "API URL",
"views.Settings.EmbeddedNode.Chantools.Sweepremoteclosed.customApiUrl": "Custom API URL",
"views.Settings.EmbeddedNode.Chantools.Sweepremoteclosed.start": "Start sweep",
"views.LspExplanation.text1": "Zeus is a self-custodial lightning wallet. In order to send or receive a lightning payment, you must open a lightning payment channel, which has a setup fee.",
"views.LspExplanation.text2": "Once the channel is set up, you'll only have to pay normal network fees until your channel exhausts its capacity.",
"views.LspExplanation.buttonText": "Learn more about liquidity",
Expand Down
23 changes: 23 additions & 0 deletions views/Settings/EmbeddedNode/Advanced.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,29 @@ export default class EmbeddedNodeAdvancedSettings extends React.Component<
</Text>
</View>
</>
<>
<ListItem
containerStyle={{
backgroundColor: 'transparent'
}}
onPress={() => navigation.navigate('Chantools')}
>
<ListItem.Content>
<ListItem.Title
style={{
color: themeColor('text'),
fontFamily: 'PPNeueMontreal-Book'
}}
>
chantools
</ListItem.Title>
</ListItem.Content>
<Icon
name="keyboard-arrow-right"
color={themeColor('secondaryText')}
/>
</ListItem>
</>
<>
<View style={{ marginTop: 20 }}>
<Button
Expand Down
Loading

0 comments on commit bd2c14b

Please sign in to comment.