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

feat: enable trace logs for payments #276

Merged
merged 1 commit into from
Jan 30, 2025
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ PODS:
- React-jsinspector (0.72.4)
- React-logger (0.72.4):
- glog
- react-native-ldk (0.0.152):
- react-native-ldk (0.0.154):
- React
- react-native-randombytes (3.6.1):
- React-Core
Expand Down Expand Up @@ -621,7 +621,7 @@ SPEC CHECKSUMS:
React-jsiexecutor: c7f826e40fa9cab5d37cab6130b1af237332b594
React-jsinspector: aaed4cf551c4a1c98092436518c2d267b13a673f
React-logger: da1ebe05ae06eb6db4b162202faeafac4b435e77
react-native-ldk: 1d25080cfadac349eab355725da66de140fbc7a8
react-native-ldk: 6910154336e57be6702a33acad2191d39a3a214b
react-native-randombytes: 421f1c7d48c0af8dbcd471b0324393ebf8fe7846
react-native-tcp-socket: c1b7297619616b4c9caae6889bcb0aba78086989
React-NativeModulesApple: edb5ace14f73f4969df6e7b1f3e41bef0012740f
Expand Down
2 changes: 1 addition & 1 deletion lib/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@synonymdev/react-native-ldk",
"title": "React Native LDK",
"version": "0.0.152",
"version": "0.0.154",
"description": "React Native wrapper for LDK",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
Expand Down
70 changes: 41 additions & 29 deletions lib/src/lightning-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
TCreatePaymentReq,
TBackupServerDetails,
IAddress,
TLspLogPayload,

Check warning on line 58 in lib/src/lightning-manager.ts

View workflow job for this annotation

GitHub Actions / Run lint check

'TLspLogPayload' is defined but never used

Check warning on line 58 in lib/src/lightning-manager.ts

View workflow job for this annotation

GitHub Actions / Run lint check

'TLspLogPayload' is defined but never used

Check warning on line 58 in lib/src/lightning-manager.ts

View workflow job for this annotation

GitHub Actions / e2e-android

'TLspLogPayload' is defined but never used

Check warning on line 58 in lib/src/lightning-manager.ts

View workflow job for this annotation

GitHub Actions / e2e-ios

'TLspLogPayload' is defined but never used
TLspLogEvent,
TChannelMonitor,
TCreateChannelReq,
Expand Down Expand Up @@ -1324,43 +1324,55 @@
amountSats,
timeout = 20000,
}: TPaymentReq): Promise<Result<TChannelManagerPaymentSent>> => {
// Enable trace logging
await ldk.setLogLevel(ELdkLogLevels.trace, true);
await ldk.writeToLogFile('debug', `Trace logging enabled`);

return new Promise(async (resolve) => {
await ldk.writeToLogFile(
'debug',
`ldk.pay() called with hard timeout of ${timeout}ms`,
);
try {
await ldk.writeToLogFile(
'debug',
`ldk.pay() called with hard timeout of ${timeout}ms`,
);

if (timeout < 1000) {
return resolve(err('Timeout must be at least 1000ms.'));
}
if (timeout < 1000) {
return resolve(err('Timeout must be at least 1000ms.'));
}

this.subscribeToPaymentResponses(resolve);
this.subscribeToPaymentResponses(resolve);

let payResponse: Result<string> | undefined = await ldk.pay({
paymentRequest,
amountSats,
timeout,
});
let payResponse: Result<string> | undefined = await ldk.pay({
paymentRequest,
amountSats,
timeout,
});

await ldk.writeToLogFile(
'debug',
payResponse.isOk()
? `ldk.pay() success (pending callbacks) Payment ID: ${payResponse.value}`
: `ldk.pay() error ${payResponse.error.message}.`,
);
await ldk.writeToLogFile(
'debug',
payResponse.isOk()
? `ldk.pay() success (pending callbacks) Payment ID: ${payResponse.value}`
: `ldk.pay() error ${payResponse.error.message}.`,
);

if (!payResponse) {
this.unsubscribeFromPaymentSubscriptions();
return resolve(err('Unable to pay the provided lightning invoice.'));
}
if (!payResponse) {
this.unsubscribeFromPaymentSubscriptions();
return resolve(err('Unable to pay the provided lightning invoice.'));
}

if (payResponse.isErr()) {
this.unsubscribeFromPaymentSubscriptions();
return resolve(err(payResponse.error.message));
}
if (payResponse.isErr()) {
this.unsubscribeFromPaymentSubscriptions();
return resolve(err(payResponse.error.message));
}

//Save payment ids to file on payResponse success.
await this.appendLdkPaymentId(payResponse.value);
//Save payment ids to file on payResponse success.
await this.appendLdkPaymentId(payResponse.value);
} finally {
// Disable trace logging after 10 seconds
setTimeout(async () => {
await ldk.setLogLevel(ELdkLogLevels.trace, false);
await ldk.writeToLogFile('debug', `Trace logging disabled`);
}, 10000);
}
});
};

Expand Down Expand Up @@ -2184,7 +2196,7 @@
}

private onChannelManagerPendingHtlcsForwardable(
res: TChannelManagerPendingHtlcsForwardable,

Check warning on line 2199 in lib/src/lightning-manager.ts

View workflow job for this annotation

GitHub Actions / Run lint check

'res' is defined but never used. Allowed unused args must match /^_/u

Check warning on line 2199 in lib/src/lightning-manager.ts

View workflow job for this annotation

GitHub Actions / Run lint check

'res' is defined but never used. Allowed unused args must match /^_/u

Check warning on line 2199 in lib/src/lightning-manager.ts

View workflow job for this annotation

GitHub Actions / e2e-android

'res' is defined but never used. Allowed unused args must match /^_/u

Check warning on line 2199 in lib/src/lightning-manager.ts

View workflow job for this annotation

GitHub Actions / e2e-ios

'res' is defined but never used. Allowed unused args must match /^_/u
): void {
ldk.processPendingHtlcForwards().catch(console.error);
}
Expand Down Expand Up @@ -2447,7 +2459,7 @@
return err(res.error);
}

return new Promise((resolve, reject) => {

Check warning on line 2462 in lib/src/lightning-manager.ts

View workflow job for this annotation

GitHub Actions / Run lint check

'reject' is defined but never used. Allowed unused args must match /^_/u

Check warning on line 2462 in lib/src/lightning-manager.ts

View workflow job for this annotation

GitHub Actions / Run lint check

'reject' is defined but never used. Allowed unused args must match /^_/u

Check warning on line 2462 in lib/src/lightning-manager.ts

View workflow job for this annotation

GitHub Actions / e2e-android

'reject' is defined but never used. Allowed unused args must match /^_/u

Check warning on line 2462 in lib/src/lightning-manager.ts

View workflow job for this annotation

GitHub Actions / e2e-ios

'reject' is defined but never used. Allowed unused args must match /^_/u
// Channel funding ready event should be instant but if it fails and we don't get the event, we should reject.
const timeout = setTimeout(() => {
resolve(err(new Error('Event not triggered within 5 seconds')));
Expand Down
Loading