Skip to content

Commit

Permalink
Merge pull request #276 from synonymdev/trace-for-pay
Browse files Browse the repository at this point in the history
feat: enable trace logs for payments
  • Loading branch information
Jasonvdb authored Jan 30, 2025
2 parents 7c5bad8 + 82c3189 commit 11e7624
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 32 deletions.
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 @@ -1324,43 +1324,55 @@ class LightningManager {
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

0 comments on commit 11e7624

Please sign in to comment.