Skip to content

Commit

Permalink
fix: linting
Browse files Browse the repository at this point in the history
  • Loading branch information
Jasonvdb committed Aug 30, 2024
1 parent 3ea51d3 commit 39a6143
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 20 deletions.
2 changes: 1 addition & 1 deletion example/Dev.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,7 @@ const Dev = (): ReactElement => {
`bitcoin-cli createrawtransaction '[{"txid":"<tx-id>","vout":<index>}]' '{"${address}":${btc}}'`,
);
console.log(
`bitcoin-cli signrawtransactionwithwallet "<raw-transaction-hex>"`,
'bitcoin-cli signrawtransactionwithwallet "<raw-transaction-hex>"',
);
console.log('********');

Expand Down
2 changes: 1 addition & 1 deletion example/utils/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,4 +239,4 @@ export const ldkNetwork = (network: TAvailableNetworks): ENetworks => {
case 'bitcoinSignet':
return ENetworks.signet;
}
};
};
24 changes: 20 additions & 4 deletions lib/src/ldk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -490,9 +490,17 @@ class LDK {
* @param pushSats
* @returns {Promise<Err<unknown> | Ok<Ok<string> | Err<string>>>}
*/
async createChannel({counterPartyNodeId, channelValueSats, pushSats}: TCreateChannelReq): Promise<Result<string>> {
async createChannel({
counterPartyNodeId,
channelValueSats,
pushSats,
}: TCreateChannelReq): Promise<Result<string>> {
try {
const res = await NativeLDK.createChannel(counterPartyNodeId, channelValueSats, pushSats);
const res = await NativeLDK.createChannel(
counterPartyNodeId,
channelValueSats,
pushSats,
);
this.writeDebugToLog('createChannel');
return ok(res);
} catch (e) {
Expand All @@ -509,9 +517,17 @@ class LDK {
* @param fundingTransaction
* @returns {Promise<Err<unknown> | Ok<Ok<string> | Err<string>>>}
*/
async fundChannel({temporaryChannelId, counterPartyNodeId, fundingTransaction}: TFundChannelReq): Promise<Result<string>> {
async fundChannel({
temporaryChannelId,
counterPartyNodeId,
fundingTransaction,
}: TFundChannelReq): Promise<Result<string>> {
try {
const res = await NativeLDK.fundChannel(temporaryChannelId, counterPartyNodeId, fundingTransaction);
const res = await NativeLDK.fundChannel(
temporaryChannelId,
counterPartyNodeId,
fundingTransaction,
);
this.writeDebugToLog('fundChannel');
return ok(res);
} catch (e) {
Expand Down
36 changes: 22 additions & 14 deletions lib/src/lightning-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2438,30 +2438,38 @@ class LightningManager {
* Creates a new channel with the provided peer and then listens for the channel manager funding generation ready event.
* Once event is triggered, those details can be used to create the funding transaction.
*/
async createChannel(req: TCreateChannelReq): Promise<Result<TChannelManagerFundingGenerationReady>> {
async createChannel(
req: TCreateChannelReq,
): Promise<Result<TChannelManagerFundingGenerationReady>> {
const res = await ldk.createChannel(req);
if (res.isErr()) {
return err(res.error);
}

return new Promise((resolve, reject) => {
// Channel funding ready event should be instant but if it fails and we don't get the event, we should reject.
const timeout = setTimeout(() => {
reject(err(new Error("Event not triggered within 5 seconds")));
reject(err(new Error('Event not triggered within 5 seconds')));
}, 5000);

// Listen for the event for the channel funding details
ldk.onEvent(EEventTypes.channel_manager_funding_generation_ready, (eventRes: TChannelManagerFundingGenerationReady) => {
clearTimeout(timeout);
resolve(ok(eventRes));
});

ldk.onEvent(EEventTypes.channel_manager_channel_closed, (eventRes: TChannelManagerChannelClosed) => {
if (eventRes.channel_id === res.value) {
// Listen for the event for the channel funding details
ldk.onEvent(
EEventTypes.channel_manager_funding_generation_ready,
(eventRes: TChannelManagerFundingGenerationReady) => {
clearTimeout(timeout);
reject(err("Channel closed before funding"));
}
});
resolve(ok(eventRes));
},
);

ldk.onEvent(
EEventTypes.channel_manager_channel_closed,
(eventRes: TChannelManagerChannelClosed) => {
if (eventRes.channel_id === res.value) {
clearTimeout(timeout);
reject(err('Channel closed before funding'));
}
},
);
});
}
}
Expand Down

0 comments on commit 39a6143

Please sign in to comment.