Skip to content

Commit

Permalink
Merge pull request #2135 from kaloudis/closechannel-delivery-address
Browse files Browse the repository at this point in the history
LND: CloseChannel: close to external address
  • Loading branch information
kaloudis committed Apr 23, 2024
2 parents 5c5e4cc + 1291ac5 commit 567ef8f
Show file tree
Hide file tree
Showing 9 changed files with 90 additions and 46 deletions.
10 changes: 9 additions & 1 deletion backends/EmbeddedLND.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,16 @@ export default class EmbeddedLND extends LND {
const force = urlParams && urlParams[2] ? true : false;
const sat_per_vbyte =
urlParams && urlParams[3] ? Number(urlParams[3]) : undefined;
const delivery_address =
urlParams && urlParams[4] ? urlParams[4] : undefined;

await closeChannel(fundingTxId, outputIndex, force, sat_per_vbyte);
return await closeChannel(
fundingTxId,
outputIndex,
force,
sat_per_vbyte,
delivery_address
);
};

getNodeInfo = async (urlParams?: Array<string>) =>
Expand Down
25 changes: 12 additions & 13 deletions backends/LND.ts
Original file line number Diff line number Diff line change
Expand Up @@ -420,20 +420,19 @@ export default class LND {
return result;
};
closeChannel = (urlParams?: Array<string>) => {
if (urlParams && urlParams.length === 4) {
return this.deleteRequest(
`/v1/channels/${urlParams && urlParams[0]}/${
urlParams && urlParams[1]
}?force=${urlParams && urlParams[2]}&sat_per_vbyte=${
urlParams && urlParams[3]
}`
);
let requestString = `/v1/channels/${urlParams && urlParams[0]}/${
urlParams && urlParams[1]
}?force=${urlParams && urlParams[2]}`;

if (urlParams && urlParams[3]) {
requestString += `&sat_per_vbyte=${urlParams && urlParams[3]}`;
}
return this.deleteRequest(
`/v1/channels/${urlParams && urlParams[0]}/${
urlParams && urlParams[1]
}?force=${urlParams && urlParams[2]}`
);

if (urlParams && urlParams[4]) {
requestString += `&delivery_address=${urlParams && urlParams[4]}`;
}

return this.deleteRequest(requestString);
};
getNodeInfo = (urlParams?: Array<string>) =>
this.getRequest(`/v1/graph/node/${urlParams && urlParams[0]}`);
Expand Down
22 changes: 9 additions & 13 deletions backends/LightningNodeConnect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,26 +272,22 @@ export default class LightningNodeConnect {
});
};
closeChannel = async (urlParams?: Array<string>) => {
let params;
if (urlParams && urlParams.length === 4) {
params = {
channel_point: {
funding_txid_str: urlParams && urlParams[0],
output_index:
urlParams && urlParams[1] && Number(urlParams[1])
},
force: urlParams && urlParams[2],
sat_per_vbyte: urlParams && urlParams[3] && Number(urlParams[3])
};
}
params = {
let params: any = {
channel_point: {
funding_txid_str: urlParams && urlParams[0],
output_index: urlParams && urlParams[1] && Number(urlParams[1])
},
force: urlParams && urlParams[2]
};

if (urlParams && urlParams[3]) {
params.sat_per_vbyte = Number(urlParams[3]);
}

if (urlParams && urlParams[4]) {
params.delivery_address = urlParams[4];
}

return this.lnc.lnd.lightning.closeChannel(params);
};
getNodeInfo = async (urlParams?: Array<string>) =>
Expand Down
3 changes: 2 additions & 1 deletion lndmobile/LndMobileInjection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,8 @@ export interface ILndMobileInjections {
fundingTxId: string,
outputIndex: number,
force?: boolean,
sat_per_vbyte?: number
sat_per_vbyte?: number,
delivery_address?: string
) => Promise<string>;
listChannels: () => Promise<lnrpc.ListChannelsResponse>;
openChannel: (
Expand Down
4 changes: 3 additions & 1 deletion lndmobile/channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,8 @@ export const closeChannel = async (
funding_txid: string,
output_index: number,
force?: boolean,
sat_per_vbyte?: number
sat_per_vbyte?: number,
delivery_address?: string
): Promise<string> => {
const response = await sendStreamCommand<
lnrpc.ICloseChannelRequest,
Expand All @@ -190,6 +191,7 @@ export const closeChannel = async (
sat_per_vbyte: sat_per_vbyte
? Long.fromValue(sat_per_vbyte)
: undefined,
delivery_address,
force
}
},
Expand Down
2 changes: 2 additions & 0 deletions locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,8 @@
"views.Channel.cancelClose": "Cancel Channel Close",
"views.Channel.close": "Close Channel",
"views.Channel.closingRate": "(Optional) Sat per vbyte closing fee",
"views.Channel.externalAddress": "(Optional) External address",
"views.Channel.externalAddress.info": "If specified, your channel funds will be sent to this external address, instead of an address in the internal wallet.",
"views.Channel.forceClose": "Force close",
"views.Channel.confirmClose": "Confirm Channel Close",
"views.Channel.aliasScid": "Alias SCID",
Expand Down
20 changes: 9 additions & 11 deletions stores/ChannelsStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,8 @@ export default class ChannelsStore {
channelPoint?: CloseChannelRequest | null,
channelId?: string | null,
satPerVbyte?: string | null,
forceClose?: boolean | string | null
forceClose?: boolean | string | null,
deliveryAddress?: string | null
) => {
this.closeChannelErr = null;
this.closingChannel = true;
Expand All @@ -463,16 +464,13 @@ export default class ChannelsStore {
// lnd
const { funding_txid_str, output_index } = channelPoint;

urlParams = [funding_txid_str, output_index, forceClose];

if (satPerVbyte) {
urlParams = [
funding_txid_str,
output_index,
forceClose,
satPerVbyte
];
}
urlParams = [
funding_txid_str,
output_index,
forceClose,
satPerVbyte,
deliveryAddress
];
}

if (this.settingsStore.implementation === 'lightning-node-connect') {
Expand Down
48 changes: 42 additions & 6 deletions views/Channels/Channel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
NativeEventEmitter,
ScrollView,
StyleSheet,
Text,
TouchableOpacity,
View
} from 'react-native';
Expand All @@ -24,6 +23,8 @@ import OnchainFeeInput from '../../components/OnchainFeeInput';
import Screen from '../../components/Screen';
import { ErrorMessage } from '../../components/SuccessErrorMessage';
import Switch from '../../components/Switch';
import Text from '../../components/Text';
import TextInput from '../../components/TextInput';

import PrivacyUtils from '../../utils/PrivacyUtils';
import BackendUtils from '../../utils/BackendUtils';
Expand All @@ -49,6 +50,7 @@ interface ChannelState {
confirmCloseChannel: boolean;
satPerByte: string;
forceCloseChannel: boolean;
deliveryAddress: string;
channel: Channel;
}

Expand All @@ -68,6 +70,7 @@ export default class ChannelView extends React.Component<
confirmCloseChannel: false,
satPerByte: '',
forceCloseChannel: false,
deliveryAddress: '',
channel
};

Expand All @@ -80,7 +83,8 @@ export default class ChannelView extends React.Component<
channelPoint?: string,
channelId?: string,
satPerVbyte?: string | null,
forceClose?: boolean | null
forceClose?: boolean | null,
deliveryAddress?: string | null
) => {
const { ChannelsStore, SettingsStore, navigation } = this.props;
const { implementation } = SettingsStore;
Expand All @@ -96,7 +100,8 @@ export default class ChannelView extends React.Component<
channelPoint ? { funding_txid_str, output_index } : null,
channelId ? channelId : null,
satPerVbyte ? satPerVbyte : null,
forceClose
forceClose,
deliveryAddress ? deliveryAddress : null
);

if (implementation === 'lightning-node-connect') {
Expand Down Expand Up @@ -150,8 +155,13 @@ export default class ChannelView extends React.Component<
render() {
const { navigation, SettingsStore, NodeInfoStore, ChannelsStore } =
this.props;
const { channel, confirmCloseChannel, satPerByte, forceCloseChannel } =
this.state;
const {
channel,
confirmCloseChannel,
satPerByte,
forceCloseChannel,
deliveryAddress
} = this.state;
const { settings } = SettingsStore;
const { privacy } = settings;
const lurkerMode = privacy && privacy.lurkerMode;
Expand Down Expand Up @@ -640,6 +650,31 @@ export default class ChannelView extends React.Component<
});
}}
/>
<>
<Text
style={{
...styles.text,
color: themeColor('text')
}}
infoText={localeString(
'views.Channel.externalAddress.info'
)}
>
{localeString(
'views.Channel.externalAddress'
)}
</Text>
<TextInput
placeholder={'bc1...'}
value={deliveryAddress}
onChangeText={(text: string) =>
this.setState({
deliveryAddress: text
})
}
locked={closingChannel}
/>
</>
<View style={{ marginBottom: 10 }}>
<Text
style={{
Expand Down Expand Up @@ -674,7 +709,8 @@ export default class ChannelView extends React.Component<
channel_point,
channelId,
satPerByte,
forceCloseChannel
forceCloseChannel,
deliveryAddress
)
}
quaternary
Expand Down
2 changes: 2 additions & 0 deletions views/Receive.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -997,6 +997,8 @@ export default class Receive extends React.Component<
const { lightningAddress } = LightningAddressStore;
const lightningAddressLoading = LightningAddressStore.loading;

console.log('address', address);

const error_msg = LSPStore.error_msg || InvoicesStore.error_msg;

const showCustomPreimageField =
Expand Down

0 comments on commit 567ef8f

Please sign in to comment.