Skip to content

Commit cf173ff

Browse files
committed
fix(lightning): wait for channels ready when paying invoice
1 parent e31f100 commit cf173ff

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/utils/lightning/index.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1151,6 +1151,23 @@ export const waitForLdk = async (): Promise<void> => {
11511151
});
11521152
};
11531153

1154+
export const waitForLdkChannels = async (): Promise<void> => {
1155+
await tryNTimes({
1156+
toTry: async () => {
1157+
const channelsResult = await ldk.listUsableChannels();
1158+
if (channelsResult.isOk()) {
1159+
if (channelsResult.value.length > 0) {
1160+
return ok(channelsResult.value);
1161+
}
1162+
return err('no channels ready');
1163+
}
1164+
return err('error getting channels');
1165+
},
1166+
times: 5,
1167+
interval: 1000,
1168+
});
1169+
};
1170+
11541171
/**
11551172
* Returns the current LDK node id.
11561173
* @returns {Promise<Result<string>>}
@@ -1579,6 +1596,8 @@ export const payLightningInvoice = async ({
15791596
amount?: number;
15801597
}): Promise<Result<string>> => {
15811598
try {
1599+
await waitForLdkChannels();
1600+
15821601
const addPeersResponse = await addPeers();
15831602
if (addPeersResponse.isErr()) {
15841603
return err(addPeersResponse.error.message);

0 commit comments

Comments
 (0)