Skip to content

Commit

Permalink
add abandon channel to dev screen
Browse files Browse the repository at this point in the history
Signed-off-by: Nitesh Balusu <[email protected]>
  • Loading branch information
niteshbalusu11 authored and hsjoberg committed Jul 19, 2023
1 parent 705d00c commit fcedc71
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 52 deletions.
1 change: 1 addition & 0 deletions locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@
"alias": "Alias",
"node": "Node",
"channelId": "Channel ID",
"channelPoint": "Channel point",
"status": "Status",
"statusActive": "Active",
"statusInactive": "Inactive",
Expand Down
32 changes: 20 additions & 12 deletions src/components/ChannelCard.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import React from "react";
import { StyleSheet, Alert, Image, Linking } from "react-native";
import { Button, Card, CardItem, Body, Row, Right, Text, Left } from "native-base";
import { Svg, Line } from "react-native-svg";
import Long from "long";
import BigNumber from "bignumber.js";

import { useStoreActions, useStoreState } from "../state/store";
import { lnrpc } from "../../proto/lightning";
import * as nativeBaseTheme from "../native-base-theme/variables/commonColor";
import { valueBitcoin, getUnitNice, valueFiat } from "../utils/bitcoin-units";

import { Alert, Image, Linking, StyleSheet } from "react-native";
import { Body, Button, Card, CardItem, Left, Right, Row, Text } from "native-base";
import { Line, Svg } from "react-native-svg";
import { getUnitNice, valueBitcoin, valueFiat } from "../utils/bitcoin-units";
import { identifyService, lightningServices } from "../utils/lightning-services";
import { useStoreActions, useStoreState } from "../state/store";

import BigNumber from "bignumber.js";
import CopyText from "./CopyText";
import Long from "long";
import React from "react";
import { constructOnchainExplorerUrl } from "../utils/onchain-explorer";
import { lnrpc } from "../../proto/lightning";
import { namespaces } from "../i18n/i18n.constants";
import { toast } from "../utils";

import { useTranslation } from "react-i18next";
import { namespaces } from "../i18n/i18n.constants";

const blixtTheme = nativeBaseTheme.blixtTheme;

Expand Down Expand Up @@ -153,6 +153,14 @@ export function ChannelCard({ channel, alias }: IChannelCardProps) {
<CopyText style={{ fontSize: 14 }}>{channel.chanId?.toString()}</CopyText>
</Right>
</Row>
<Row style={{ width: "100%" }}>
<Left style={{ alignSelf: "flex-start" }}>
<Text style={style.channelDetailTitle}>{t("channel.channelPoint")}</Text>
</Left>
<Right>
<CopyText style={{ fontSize: 9.5 }}>{channel.channelPoint?.toString()}</CopyText>
</Right>
</Row>
<Row style={{ width: "100%" }}>
<Left style={{ alignSelf: "flex-start" }}>
<Text style={style.channelDetailTitle}>{t("channel.status")}</Text>
Expand Down
35 changes: 27 additions & 8 deletions src/lndmobile/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { NativeModules } from "react-native";
import { sendCommand, sendStreamCommand, decodeStreamResult } from "./utils";
import { lnrpc, routerrpc, invoicesrpc, devrpc } from "../../proto/lightning";
import Long from "long";
import sha from "sha.js";
import { stringToUint8Array, hexToUint8Array, unicodeStringToUint8Array } from "../utils";
import { TLV_KEYSEND, TLV_RECORD_NAME, TLV_WHATSAT_MESSAGE } from "../utils/constants";
import { checkLndStreamErrorResponse } from "../utils/lndmobile";
import { LndMobileEventEmitter } from "../utils/event-listener";
import { decodeStreamResult, sendCommand, sendStreamCommand } from "./utils";
import { devrpc, invoicesrpc, lnrpc, routerrpc } from "../../proto/lightning";
import { getChanInfo, listPrivateChannels } from "./channel";
import { hexToUint8Array, stringToUint8Array, unicodeStringToUint8Array } from "../utils";

import { LndMobileEventEmitter } from "../utils/event-listener";
import Long from "long";
import { NativeModules } from "react-native";
import { checkLndStreamErrorResponse } from "../utils/lndmobile";
import sha from "sha.js";
const { LndMobile, LndMobileTools } = NativeModules;

/**
Expand Down Expand Up @@ -694,3 +695,21 @@ export type IReadLndLogResponse = string[];
export const readLndLog = async (): Promise<IReadLndLogResponse> => {
return [""];
};


export const abandonChannel = async (fundingTxId: string, index: number): Promise<lnrpc.AbandonChannelResponse> => {
const response = await sendCommand<lnrpc.IAbandonChannelRequest, lnrpc.AbandonChannelRequest, lnrpc.AbandonChannelResponse>({
request: lnrpc.AbandonChannelRequest,
response: lnrpc.AbandonChannelResponse,
method: "AbandonChannel",
options: {
channelPoint: {
fundingTxidStr: fundingTxId,
outputIndex: index,
},
iKnowWhatIAmDoing: true,
}
})

return response;
}
97 changes: 65 additions & 32 deletions src/windows/InitProcess/DEV_Commands.tsx
Original file line number Diff line number Diff line change
@@ -1,43 +1,46 @@
import React, { useState } from "react";
import { StyleSheet, StatusBar, NativeModules, ScrollView, DeviceEventEmitter, EventEmitter, NativeEventEmitter, Linking } from "react-native";
import Clipboard from "@react-native-community/clipboard";
import { Text, Button, Toast, Input, View, Container } from "native-base";
import Long from "long";
import { StackNavigationProp } from "@react-navigation/stack";
import * as base64 from "base64-js";
import * as Keychain from 'react-native-keychain';
// import Sound from "react-native-sound";
import { JSHash, CONSTANTS } from "react-native-hash";
import { generateSecureRandom } from "react-native-securerandom";
// import RNLocalize from "react-native-localize";
import * as base64 from "base64-js";

import { Alert } from "../../utils/alert";
import { getTransactions, getTransaction, createTransaction, clearTransactions } from "../../storage/database/transaction";
import { useStoreState, useStoreActions } from "../../state/store";
import { ANDROID_PUSH_NOTIFICATION_PUSH_CHANNEL_ID, PLATFORM } from "../../utils/constants";
import { Button, Container, Input, Text, Toast, View } from "native-base";
// import Sound from "react-native-sound";
import { CONSTANTS, JSHash } from "react-native-hash";
import { DeviceEventEmitter, EventEmitter, Linking, NativeEventEmitter, NativeModules, ScrollView, StatusBar, StyleSheet } from "react-native";
import React, { useState } from "react";
import { StorageItem, getItem, setItem, setItemObject, storage } from "../../storage/app";
import { abandonChannel, checkStatus, connectPeer, decodePayReq, getInfo, getNetworkInfo, getNodeInfo, importGraph, listInvoices, listPeers, listUnspent, queryRoutes } from "../../lndmobile/index";
import { bytesToHexString, bytesToString, stringToUint8Array, toast } from "../../utils";
import { channelAcceptor, channelAcceptorResponse, closeChannel, decodeChannelAcceptRequest, decodeChannelEvent, listChannels, openChannel, pendingChannels } from "../../lndmobile/channel";
import { clearTransactions, createTransaction, getTransaction, getTransactions } from "../../storage/database/transaction";
import { deriveKey, derivePrivateKey, genSeed, initWallet, signMessage } from "../../lndmobile/wallet";
import { getItemObject, getPin, getWalletPassword, setWalletPassword } from "../../storage/keystore";
import { invoicesrpc, lnrpc } from "../../../proto/lightning";
import { sendCommand } from "../../lndmobile/utils";
import { getInfo, connectPeer, listPeers, decodePayReq, queryRoutes, checkStatus, getNodeInfo, listUnspent, getNetworkInfo, importGraph, listInvoices } from "../../lndmobile/index";
import { initWallet, genSeed, deriveKey, signMessage, derivePrivateKey } from "../../lndmobile/wallet";
import { pendingChannels, listChannels, openChannel, closeChannel, channelAcceptor, decodeChannelEvent, decodeChannelAcceptRequest, channelAcceptorResponse } from "../../lndmobile/channel";
import { modifyStatus, queryScores, status } from "../../lndmobile/autopilot";
import { newAddress, sendCoins } from "../../lndmobile/onchain";
import { storage, StorageItem, setItemObject, getItem, setItem } from "../../storage/app";
import { status, modifyStatus, queryScores } from "../../lndmobile/autopilot";
import { RootStackParamList } from "../../Main";
import { setWalletPassword, getWalletPassword, getItemObject, getPin } from "../../storage/keystore";
import { useStoreActions, useStoreState } from "../../state/store";

import { Alert } from "../../utils/alert";
import Clipboard from "@react-native-community/clipboard";
import Content from "../../components/Content";
import { blixtTheme } from "../../native-base-theme/variables/commonColor";
import { ICLOUD_BACKUP_KEY } from "../../state/ICloudBackup";
import { ILightningServices } from "../../utils/lightning-services";
import { LndMobileEventEmitter } from "../../utils/event-listener";
import { LoginMethods } from "../../state/Security";
import Long from "long";
import PushNotification from "react-native-push-notification";
import { RootStackParamList } from "../../Main";
import Spinner from "../../components/Spinner";

import secp256k1 from "secp256k1";
import { bytesToString, bytesToHexString, stringToUint8Array, toast } from "../../utils";
import { ILightningServices } from "../../utils/lightning-services";
import { StackNavigationProp } from "@react-navigation/stack";
import { blixtTheme } from "../../native-base-theme/variables/commonColor";
import { generateSecureRandom } from "react-native-securerandom";
import { localNotification } from "../../utils/push-notification";
import { ICLOUD_BACKUP_KEY } from "../../state/ICloudBackup";
import { notificationManager } from "../../state/NotificationManager";
import PushNotification from "react-native-push-notification";
import { ANDROID_PUSH_NOTIFICATION_PUSH_CHANNEL_ID, PLATFORM } from "../../utils/constants";
import { LndMobileEventEmitter } from "../../utils/event-listener";
import secp256k1 from "secp256k1";
import { sendCommand } from "../../lndmobile/utils";

// import RNLocalize from "react-native-localize";



let iCloudStorage: any;
console.log(PLATFORM);
Expand All @@ -50,6 +53,7 @@ interface IProps {
continueCallback?: () => void;
}
export default function DEV_Commands({ navigation, continueCallback }: IProps) {
const [channelPoint, setChannelPoint] = useState("");
const [connectPeerStr, setConnectPeer] = useState("");
const [sat, setSat] = useState("");
const [addr, setAddr] = useState("");
Expand Down Expand Up @@ -916,6 +920,35 @@ export default function DEV_Commands({ navigation, continueCallback }: IProps) {
</Button>
</View>
<View style={{ backgroundColor: blixtTheme.dark, padding: 15, marginTop: 10 }}>
<Input
onChangeText={(text: string) => setChannelPoint(text)}
placeholder="<funding_tx_id>:<index>"
value={channelPoint}
/>
<Button small danger onPress={async () => {
Alert.alert("Warning: Are you absolurely sure?", "Abdandoning a channel means you could potentially lose funds", [{
style: "cancel",
text: "No",
}, {
style: "default",
text: "Yes",
onPress: async () => {
try {
const [fundingTxId, index] = channelPoint.split(":");
const result = await abandonChannel(fundingTxId, Number(index));
console.log("abandon channel() ", result);
setCommandResult(result);
setError({});
} catch (e: any) {
setError(e);
setCommandResult({});
}
}
}]);
}}
>
<Text style={styles.buttonText}>AbandonChannel()</Text>
</Button>
<Input
onChangeText={(text: string) => {
setConnectPeer(text);
Expand All @@ -932,7 +965,7 @@ export default function DEV_Commands({ navigation, continueCallback }: IProps) {
setCommandResult(result);
setError({});
}
catch (e) {
catch (e: any) {
setError(e);
setCommandResult({});
}
Expand Down

0 comments on commit fcedc71

Please sign in to comment.