Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set remote chan reserve to 360 for blixt outbound opens #1411

Merged
merged 1 commit into from
Jan 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
172 changes: 129 additions & 43 deletions src/lndmobile/channel.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,30 @@
import { sendCommand, sendStreamCommand, decodeStreamResult, sendBidiStreamCommand, writeToStream } from "./utils";
import {
sendCommand,
sendStreamCommand,
decodeStreamResult,
sendBidiStreamCommand,
writeToStream,
} from "./utils";
import { lnrpc } from "../../proto/lightning";
import Long from "long";
import * as base64 from "base64-js";

/**
* @throws
*/
export const openChannel = async (pubkey: string, amount: number, privateChannel: boolean, feeRateSat?: number, type?: lnrpc.CommitmentType): Promise<lnrpc.ChannelPoint> => {
const response = await sendCommand<lnrpc.IOpenChannelRequest, lnrpc.OpenChannelRequest, lnrpc.ChannelPoint>({
export const openChannel = async (
pubkey: string,
amount: number,
privateChannel: boolean,
feeRateSat?: number,
type?: lnrpc.CommitmentType,
): Promise<lnrpc.ChannelPoint> => {
const remoteChanReserveSat = Long.fromValue(360);
const response = await sendCommand<
lnrpc.IOpenChannelRequest,
lnrpc.OpenChannelRequest,
lnrpc.ChannelPoint
>({
request: lnrpc.OpenChannelRequest,
response: lnrpc.ChannelPoint,
method: "OpenChannelSync",
Expand All @@ -19,6 +36,7 @@ export const openChannel = async (pubkey: string, amount: number, privateChannel
satPerByte: feeRateSat ? Long.fromValue(feeRateSat) : undefined,
scidAlias: true,
commitmentType: type,
remoteChanReserveSat,
},
});
return response;
Expand All @@ -27,8 +45,18 @@ export const openChannel = async (pubkey: string, amount: number, privateChannel
/**
* @throws
*/
export const openChannelAll = async (pubkey: string, privateChannel: boolean, feeRateSat?: number, type?: lnrpc.CommitmentType): Promise<lnrpc.ChannelPoint> => {
const response = await sendCommand<lnrpc.IOpenChannelRequest, lnrpc.OpenChannelRequest, lnrpc.ChannelPoint>({
export const openChannelAll = async (
pubkey: string,
privateChannel: boolean,
feeRateSat?: number,
type?: lnrpc.CommitmentType,
): Promise<lnrpc.ChannelPoint> => {
const remoteChanReserveSat = Long.fromValue(360);
const response = await sendCommand<
lnrpc.IOpenChannelRequest,
lnrpc.OpenChannelRequest,
lnrpc.ChannelPoint
>({
request: lnrpc.OpenChannelRequest,
response: lnrpc.ChannelPoint,
method: "OpenChannelSync",
Expand All @@ -40,6 +68,7 @@ export const openChannelAll = async (pubkey: string, privateChannel: boolean, fe
satPerByte: feeRateSat ? Long.fromValue(feeRateSat) : undefined,
scidAlias: true,
commitmentType: type,
remoteChanReserveSat,
},
});
return response;
Expand All @@ -49,35 +78,49 @@ export const openChannelAll = async (pubkey: string, privateChannel: boolean, fe
* @throws
* TODO implement
*/
export const closeChannel = async (fundingTxId: string, outputIndex: number, force: boolean): Promise<string> => {
const response = await sendStreamCommand<lnrpc.ICloseChannelRequest, lnrpc.CloseChannelRequest>({
request: lnrpc.CloseChannelRequest,
method: "CloseChannel",
options: {
channelPoint: {
fundingTxidStr: fundingTxId,
outputIndex,
export const closeChannel = async (
fundingTxId: string,
outputIndex: number,
force: boolean,
): Promise<string> => {
const response = await sendStreamCommand<lnrpc.ICloseChannelRequest, lnrpc.CloseChannelRequest>(
{
request: lnrpc.CloseChannelRequest,
method: "CloseChannel",
options: {
channelPoint: {
fundingTxidStr: fundingTxId,
outputIndex,
},
force,
},
force,
},
}, false);
false,
);
return response;
};

/**
* @throws
* TODO implement
*/
export const abandonChannel = async (fundingTxId: string, outputIndex: number): Promise<lnrpc.AbandonChannelResponse> => {
const response = await sendCommand<lnrpc.IAbandonChannelRequest, lnrpc.AbandonChannelRequest, lnrpc.AbandonChannelResponse>({
export const abandonChannel = async (
fundingTxId: string,
outputIndex: 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,
}
},
},
});
return response;
Expand All @@ -86,7 +129,11 @@ export const abandonChannel = async (fundingTxId: string, outputIndex: number):
* @throws
*/
export const pendingChannels = async (): Promise<lnrpc.PendingChannelsResponse> => {
const response = await sendCommand<lnrpc.IPendingChannelsRequest, lnrpc.PendingChannelsRequest, lnrpc.PendingChannelsResponse>({
const response = await sendCommand<
lnrpc.IPendingChannelsRequest,
lnrpc.PendingChannelsRequest,
lnrpc.PendingChannelsResponse
>({
request: lnrpc.PendingChannelsRequest,
response: lnrpc.PendingChannelsResponse,
method: "PendingChannels",
Expand All @@ -99,7 +146,11 @@ export const pendingChannels = async (): Promise<lnrpc.PendingChannelsResponse>
* @throws
*/
export const listChannels = async (): Promise<lnrpc.ListChannelsResponse> => {
const response = await sendCommand<lnrpc.IListChannelsRequest, lnrpc.ListChannelsRequest, lnrpc.ListChannelsResponse>({
const response = await sendCommand<
lnrpc.IListChannelsRequest,
lnrpc.ListChannelsRequest,
lnrpc.ListChannelsResponse
>({
request: lnrpc.ListChannelsRequest,
response: lnrpc.ListChannelsResponse,
method: "ListChannels",
Expand All @@ -114,7 +165,11 @@ export const listChannels = async (): Promise<lnrpc.ListChannelsResponse> => {
* @throws
*/
export const listPrivateChannels = async (): Promise<lnrpc.ListChannelsResponse> => {
const response = await sendCommand<lnrpc.IListChannelsRequest, lnrpc.ListChannelsRequest, lnrpc.ListChannelsResponse>({
const response = await sendCommand<
lnrpc.IListChannelsRequest,
lnrpc.ListChannelsRequest,
lnrpc.ListChannelsResponse
>({
request: lnrpc.ListChannelsRequest,
response: lnrpc.ListChannelsResponse,
method: "ListChannels",
Expand All @@ -129,7 +184,11 @@ export const listPrivateChannels = async (): Promise<lnrpc.ListChannelsResponse>
* @throws
*/
export const channelBalance = async (): Promise<lnrpc.ChannelBalanceResponse> => {
const response = await sendCommand<lnrpc.IChannelBalanceRequest, lnrpc.ChannelBalanceRequest, lnrpc.ChannelBalanceResponse>({
const response = await sendCommand<
lnrpc.IChannelBalanceRequest,
lnrpc.ChannelBalanceRequest,
lnrpc.ChannelBalanceResponse
>({
request: lnrpc.ChannelBalanceRequest,
response: lnrpc.ChannelBalanceResponse,
method: "ChannelBalance",
Expand All @@ -142,19 +201,29 @@ export const channelBalance = async (): Promise<lnrpc.ChannelBalanceResponse> =>
* @throws
*/
export const subscribeChannelEvents = async (): Promise<string> => {
const response = await sendStreamCommand<lnrpc.IChannelEventSubscription, lnrpc.ChannelEventSubscription>({
request: lnrpc.ChannelEventSubscription,
method: "SubscribeChannelEvents",
options: {},
}, false);
const response = await sendStreamCommand<
lnrpc.IChannelEventSubscription,
lnrpc.ChannelEventSubscription
>(
{
request: lnrpc.ChannelEventSubscription,
method: "SubscribeChannelEvents",
options: {},
},
false,
);
return response;
};

/**
* @throws
*/
export const exportAllChannelBackups = async (): Promise<lnrpc.ChanBackupSnapshot> => {
const response = await sendCommand<lnrpc.IChanBackupExportRequest, lnrpc.ChanBackupExportRequest, lnrpc.ChanBackupSnapshot>({
const response = await sendCommand<
lnrpc.IChanBackupExportRequest,
lnrpc.ChanBackupExportRequest,
lnrpc.ChanBackupSnapshot
>({
request: lnrpc.ChanBackupExportRequest,
response: lnrpc.ChanBackupSnapshot,
method: "ExportAllChannelBackups",
Expand All @@ -166,8 +235,14 @@ export const exportAllChannelBackups = async (): Promise<lnrpc.ChanBackupSnapsho
/**
* @throws
*/
export const verifyChanBackup = async (channelsBackupBase64: string): Promise<lnrpc.VerifyChanBackupResponse> => {
const response = await sendCommand<lnrpc.IChanBackupSnapshot, lnrpc.ChanBackupSnapshot, lnrpc.VerifyChanBackupResponse>({
export const verifyChanBackup = async (
channelsBackupBase64: string,
): Promise<lnrpc.VerifyChanBackupResponse> => {
const response = await sendCommand<
lnrpc.IChanBackupSnapshot,
lnrpc.ChanBackupSnapshot,
lnrpc.VerifyChanBackupResponse
>({
request: lnrpc.ChanBackupSnapshot,
response: lnrpc.VerifyChanBackupResponse,
method: "VerifyChanBackup",
Expand All @@ -184,7 +259,11 @@ export const verifyChanBackup = async (channelsBackupBase64: string): Promise<ln
* @throws
*/
export const getChanInfo = async (chanId: Long): Promise<lnrpc.ChannelEdge> => {
const response = await sendCommand<lnrpc.IChanInfoRequest, lnrpc.ChanInfoRequest, lnrpc.ChannelEdge>({
const response = await sendCommand<
lnrpc.IChanInfoRequest,
lnrpc.ChanInfoRequest,
lnrpc.ChannelEdge
>({
request: lnrpc.ChanInfoRequest,
response: lnrpc.ChannelEdge,
method: "GetChanInfo",
Expand All @@ -199,7 +278,11 @@ export const channelAcceptor = async () => {
return await sendBidiStreamCommand("ChannelAcceptor");
};

export const channelAcceptorResponse = async (pendingChanId: Uint8Array, accept: boolean, zeroConf: boolean = false) => {
export const channelAcceptorResponse = async (
pendingChanId: Uint8Array,
accept: boolean,
zeroConf: boolean = false,
) => {
return await writeToStream({
method: "ChannelAcceptor",
request: lnrpc.ChannelAcceptResponse,
Expand All @@ -212,20 +295,23 @@ export const channelAcceptorResponse = async (pendingChanId: Uint8Array, accept:
};

/*
* @throws
* FIXME: mock, fakelnd and injection
*/
* @throws
* FIXME: mock, fakelnd and injection
*/
export const closedChannels = async (chanId: Long): Promise<lnrpc.ClosedChannelsResponse> => {
const response = await sendCommand<lnrpc.IClosedChannelsRequest, lnrpc.ClosedChannelsRequest, lnrpc.ClosedChannelsResponse>({
request: lnrpc.ClosedChannelsRequest,
response: lnrpc.ClosedChannelsResponse,
method: "ClosedChannels",
options: {},
});
return response;
const response = await sendCommand<
lnrpc.IClosedChannelsRequest,
lnrpc.ClosedChannelsRequest,
lnrpc.ClosedChannelsResponse
>({
request: lnrpc.ClosedChannelsRequest,
response: lnrpc.ClosedChannelsResponse,
method: "ClosedChannels",
options: {},
});
return response;
};


export const decodeChannelAcceptRequest = (data: string): lnrpc.ChannelAcceptRequest => {
return decodeStreamResult<lnrpc.ChannelAcceptRequest>({
response: lnrpc.ChannelAcceptRequest,
Expand Down
Loading