alexbosworth / lightning

Lightning client methods
MIT License
128 stars 33 forks source link

Implement EstimateRouteFee #167

Open huumn opened 6 months ago

huumn commented 6 months ago

It doesn't appear to be implemented. I'm pretty sure we can do this by probing using the library, but this would be nice to have.

The request/response are pretty simple so I imagine wrapping it is less of a lift than other things.

https://github.com/alexbosworth/lightning/blob/c75485887935835eb5e497bd7e5b457da8bd1bdf/grpc/protos/router.proto#L56-L60

alexbosworth commented 6 months ago

Yes there is probeForRoute

huumn commented 6 months ago

If anyone wants a shim for this, something like this should work (untested):

async function estimateRouteFee ({ lnd, dest, amt_sat, request, timeout }) {
  return await new Promise((resolve, reject) => {
    lnd.router.estimateRouteFee({ dest: Buffer.from(dest, 'hex'), amt_sat, payment_request: request, timeout }, (err, res) => {
      if (err) {
        reject(err)
      } else {
        if (res.failure_reason) {
          reject(new Error(`Unable to estimate route: ${res.failure_reason}`))
        }

        resolve({
          routingFeeMsat: res.routing_fee_msat,
          timeLockDelay: res.time_lock_delay
        })
      }
    })
  })
}