alexbosworth / lightning

Lightning client methods
MIT License
127 stars 33 forks source link

Tokens not being passed to subscribeToPayViaDetails via isDestinationPayable #139

Open eNzyOfficial opened 1 year ago

eNzyOfficial commented 1 year ago

https://github.com/alexbosworth/lightning/blob/37837f21aaeec005b16fbc549fc706384e5379e7/lnd_methods/offchain/is_destination_payable.js#L59

Can you confirm the above logic is correct?

If I pass in tokens it's always null and subscribeToPayViaDetails function fails with ExpectedTokenAmountToPayInPaymentDetails.

Example:

const { lnd } = authenticatedLndGrpc({
  cert,
  macaroon,
  socket
})

const request = 'lnbcrt50u...'

const { destination, tokens } = await decodePaymentRequest({
  request,
  lnd
})

const isPayable = await isDestinationPayable({
  destination,
  tokens,
  lnd
})
alexbosworth commented 1 year ago

nm i see the issue

alexbosworth commented 1 year ago

what happens if you use mtokens instead of tokens? it works ok?

eNzyOfficial commented 1 year ago

It doesn't, it throws the following:

Error: UnexpectedDifferingMtokensAndTokens
    at module.exports (/.../node_modules/lightning/bolt00/payment_amounts.js:71:13)
    at asyncAuto.params (/.../node_modules/lightning/lnd_methods/offchain/subscribe_to_pay.js:352:23)
    at runTask (/.../node_modules/async/auto.js:293:13)
    at /.../node_modules/async/auto.js:233:31
    at processQueue (/.../node_modules/async/auto.js:243:13)
    at taskComplete (/.../node_modules/async/auto.js:259:9)
    at /.../node_modules/async/auto.js:286:17
    at /.../node_modules/async/internal/onlyOnce.js:12:16
    at asyncAuto.maxCltvDelta (/.../node_modules/lightning/lnd_methods/offchain/subscribe_to_pay.js:331:16)
    at runTask (/.../node_modules/async/auto.js:293:13)
alexbosworth commented 1 year ago

I mean if you use the mtokens and tokens together like pass both that you get from decodePaymentRequest

eNzyOfficial commented 1 year ago

Same error:

const { lnd } = authenticatedLndGrpc({
  cert,
  macaroon,
  socket
})

const request = 'lnbcrt50u...'

const { destination, tokens } = await decodePaymentRequest({
  request,
  lnd
})

const isPayable = await isDestinationPayable({
  destination,
  tokens,
  mtokens: tokens,
  lnd
})

EDIT: Nevermind I'm an idiot, forgot to convert tokens to mtokens first

alexbosworth commented 1 year ago

sorry i mean decodePaymentRequest will return mtokens as well as tokens

so

const { destination, mtokens } = await decodePaymentRequest({
const isPayable = await isDestinationPayable({
  destination,
  mtokens,
  lnd
})
eNzyOfficial commented 1 year ago

If I use only mtokens

I'm still getting UnexpectedDifferingMtokensAndTokens

inside payment_amounts.js I add console.log(tokensAsMtokens, args.mtokens) which returns 1000 500000

if I include both mtokens and tokens in the initial call, it works fine.

const { destination, tokens, mtokens } = await decodePaymentRequest({
    request,
    lnd
})

const isPayable = await isDestinationPayable({
    destination,
    mtokens,
    tokens,
    lnd
})
alexbosworth commented 1 year ago

ok sounds like something is wrong there then, can take a look

it should work with tokens alone and mtokens alone

alexbosworth commented 1 year ago

should be corrected now