Fix preimage undefined in wallet logs (#1337)
* Fix preimage undefined in NWC wallet logs * Return preimage as string
This commit is contained in:
parent
266e9a892d
commit
9f194c5d8e
@ -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).
|
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.
|
`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]
|
> [!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:
|
> 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:
|
||||||
|
@ -10,8 +10,7 @@ export async function testSendPayment ({ apiKey, currency }, { logger }) {
|
|||||||
|
|
||||||
export async function sendPayment (bolt11, { apiKey, currency }) {
|
export async function sendPayment (bolt11, { apiKey, currency }) {
|
||||||
const wallet = await getWallet(apiKey, currency)
|
const wallet = await getWallet(apiKey, currency)
|
||||||
const preImage = await payInvoice(apiKey, wallet, bolt11)
|
return await payInvoice(apiKey, wallet, bolt11)
|
||||||
return { preImage }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function payInvoice (authToken, wallet, invoice) {
|
async function payInvoice (authToken, wallet, invoice) {
|
||||||
|
@ -59,7 +59,7 @@ export function useWallet (name) {
|
|||||||
const hash = bolt11Tags(bolt11).payment_hash
|
const hash = bolt11Tags(bolt11).payment_hash
|
||||||
logger.info('sending payment:', `payment_hash=${hash}`)
|
logger.info('sending payment:', `payment_hash=${hash}`)
|
||||||
try {
|
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}`)
|
logger.ok('payment successful:', `payment_hash=${hash}`, `preimage=${preimage}`)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
const message = err.message || err.toString?.()
|
const message = err.message || err.toString?.()
|
||||||
|
@ -19,8 +19,7 @@ export async function sendPayment (bolt11, { url, adminKey }) {
|
|||||||
throw new Error('No preimage')
|
throw new Error('No preimage')
|
||||||
}
|
}
|
||||||
|
|
||||||
const preimage = checkResponse.preimage
|
return checkResponse.preimage
|
||||||
return { preimage }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getWallet ({ url, adminKey, invoiceKey }) {
|
async function getWallet ({ url, adminKey, invoiceKey }) {
|
||||||
|
@ -67,7 +67,7 @@ export async function sendPayment (bolt11, credentials, { logger }) {
|
|||||||
if (paymentError) throw new Error(paymentError)
|
if (paymentError) throw new Error(paymentError)
|
||||||
if (!preimage) throw new Error('No preimage in response')
|
if (!preimage) throw new Error('No preimage in response')
|
||||||
|
|
||||||
return { preimage }
|
return preimage
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
const msg = err.message || err.toString?.()
|
const msg = err.message || err.toString?.()
|
||||||
if (msg.includes('invoice expired')) {
|
if (msg.includes('invoice expired')) {
|
||||||
|
@ -35,5 +35,5 @@ export async function sendPayment (bolt11, { url, primaryPassword }) {
|
|||||||
throw new Error(payment.reason)
|
throw new Error(payment.reason)
|
||||||
}
|
}
|
||||||
|
|
||||||
return payment.paymentPreimage
|
return preimage
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user