Browse Source

Merge pull request #32 from mayankchhabra/feature/sweep

Sweep (use all funds)
master
Mayank Chhabra 4 years ago
committed by GitHub
parent
commit
9c3e5adfb2
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      logic/lightning.js
  2. 5
      routes/v1/lnd/channel.js

4
logic/lightning.js

@ -103,9 +103,9 @@ function decodePaymentRequest(paymentRequest) {
// Estimate the cost of opening a channel. We do this by repurposing the existing estimateFee grpc route from lnd. We
// generate our own unused address and then feed that into the existing call. Then we add an extra 10 sats per
// feerateSatPerByte. This is because the actual cost is slightly more than the default one output estimate.
async function estimateChannelOpenFee(amt, confTarget) {
async function estimateChannelOpenFee(amt, confTarget, sweep) {
const address = (await generateAddress()).address;
const baseFeeEstimate = await estimateFee(address, amt, confTarget, false);
const baseFeeEstimate = await estimateFee(address, amt, confTarget, sweep);
if (confTarget === 0) {
const keys = Object.keys(baseFeeEstimate);

5
routes/v1/lnd/channel.js

@ -13,10 +13,11 @@ router.get('/', auth.jwt, safeHandler((req, res) =>
.then(channels => res.json(channels))
));
router.get('/estimateFee', auth.jwt, safeHandler(async(req, res, next) => {
router.get('/estimateFee', auth.jwt, safeHandler(async (req, res, next) => {
const amt = req.query.amt; // Denominated in Satoshi
const confTarget = req.query.confTarget;
const sweep = req.query.sweep === 'true';
try {
validator.isPositiveIntegerOrZero(confTarget);
@ -25,7 +26,7 @@ router.get('/estimateFee', auth.jwt, safeHandler(async(req, res, next) => {
return next(error);
}
return await lightningLogic.estimateChannelOpenFee(parseInt(amt, 10), parseInt(confTarget, 10))
return await lightningLogic.estimateChannelOpenFee(parseInt(amt, 10), parseInt(confTarget, 10), sweep)
.then(response => res.json(response));
}));

Loading…
Cancel
Save