Fix preimage undefined in wallet logs (#1337)

* Fix preimage undefined in NWC wallet logs

* Return preimage as string
This commit is contained in:
ekzyis 2024-08-27 11:13:52 -05:00 committed by GitHub
parent 266e9a892d
commit 9f194c5d8e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 7 additions and 9 deletions

View File

@ -163,11 +163,11 @@ This function must throw an error if the configuration was found to be invalid.
The `context` argument is an object. It makes the wallet logger for this wallet as returned by `useWalletLogger` available under `context.logger`. See [components/wallet-logger.js](../components/wallet-logger.js).
- `sendPayment: async (bolt11: string, config, context) => Promise<{ preimage: string }>`
- `sendPayment: async (bolt11: string, config, context) => Promise<string>`
`sendPayment` will be called if a payment is required. Therefore, this function should implement the code to pay invoices from this wallet.
The first argument is the [BOLT11 payment request](https://github.com/lightning/bolts/blob/master/11-payment-encoding.md). The `config` argument is the current configuration of this wallet (that was validated before). The `context` argument is the same as for `testSendPayment`.
The first argument is the [BOLT11 payment request](https://github.com/lightning/bolts/blob/master/11-payment-encoding.md). The `config` argument is the current configuration of this wallet (that was validated before). The `context` argument is the same as for `testSendPayment`. The function should return the preimage on payment success.
> [!IMPORTANT]
> As mentioned above, this file must exist for every wallet and at least reexport everything in index.js so make sure that the following line is included:

View File

@ -10,8 +10,7 @@ export async function testSendPayment ({ apiKey, currency }, { logger }) {
export async function sendPayment (bolt11, { apiKey, currency }) {
const wallet = await getWallet(apiKey, currency)
const preImage = await payInvoice(apiKey, wallet, bolt11)
return { preImage }
return await payInvoice(apiKey, wallet, bolt11)
}
async function payInvoice (authToken, wallet, invoice) {

View File

@ -59,7 +59,7 @@ export function useWallet (name) {
const hash = bolt11Tags(bolt11).payment_hash
logger.info('sending payment:', `payment_hash=${hash}`)
try {
const { preimage } = await wallet.sendPayment(bolt11, config, { me, logger, status, showModal })
const preimage = await wallet.sendPayment(bolt11, config, { me, logger, status, showModal })
logger.ok('payment successful:', `payment_hash=${hash}`, `preimage=${preimage}`)
} catch (err) {
const message = err.message || err.toString?.()

View File

@ -19,8 +19,7 @@ export async function sendPayment (bolt11, { url, adminKey }) {
throw new Error('No preimage')
}
const preimage = checkResponse.preimage
return { preimage }
return checkResponse.preimage
}
async function getWallet ({ url, adminKey, invoiceKey }) {

View File

@ -67,7 +67,7 @@ export async function sendPayment (bolt11, credentials, { logger }) {
if (paymentError) throw new Error(paymentError)
if (!preimage) throw new Error('No preimage in response')
return { preimage }
return preimage
} catch (err) {
const msg = err.message || err.toString?.()
if (msg.includes('invoice expired')) {

View File

@ -35,5 +35,5 @@ export async function sendPayment (bolt11, { url, primaryPassword }) {
throw new Error(payment.reason)
}
return payment.paymentPreimage
return preimage
}