Add global fee settings from config.js
This commit is contained in:
		
							parent
							
								
									d3df6aab05
								
							
						
					
					
						commit
						957d6c5951
					
				@ -12,9 +12,9 @@ export class Paym {
 | 
				
			|||||||
    this._isPaid = null;
 | 
					    this._isPaid = null;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  static get fee() {
 | 
					  // static get fee() {
 | 
				
			||||||
    return 0.003;
 | 
					  //   return 0.003;
 | 
				
			||||||
  }
 | 
					  // }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  setInvoice(bolt11) {
 | 
					  setInvoice(bolt11) {
 | 
				
			||||||
    this._bolt11 = bolt11;
 | 
					    this._bolt11 = bolt11;
 | 
				
			||||||
@ -39,7 +39,7 @@ export class Paym {
 | 
				
			|||||||
      pub_key: this._decoded.destination,
 | 
					      pub_key: this._decoded.destination,
 | 
				
			||||||
      amt: this._decoded.num_satoshis,
 | 
					      amt: this._decoded.num_satoshis,
 | 
				
			||||||
      final_cltv_delta: 144,
 | 
					      final_cltv_delta: 144,
 | 
				
			||||||
      fee_limit: { fixed: Math.floor(this._decoded.num_satoshis * 0.01) + 1 },
 | 
					      fee_limit: { fixed: Math.floor(this._decoded.num_satoshis * forwardFee) + 1 },
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
    let that = this;
 | 
					    let that = this;
 | 
				
			||||||
    return new Promise(function (resolve, reject) {
 | 
					    return new Promise(function (resolve, reject) {
 | 
				
			||||||
@ -74,7 +74,7 @@ export class Paym {
 | 
				
			|||||||
    if (payment && payment.payment_route && payment.payment_route.total_amt_msat) {
 | 
					    if (payment && payment.payment_route && payment.payment_route.total_amt_msat) {
 | 
				
			||||||
      // paid just now
 | 
					      // paid just now
 | 
				
			||||||
      this._isPaid = true;
 | 
					      this._isPaid = true;
 | 
				
			||||||
      payment.payment_route.total_fees = +payment.payment_route.total_fees + Math.floor(+payment.payment_route.total_amt * Paym.fee);
 | 
					      payment.payment_route.total_fees = +payment.payment_route.total_fees + Math.floor(+payment.payment_route.total_amt * internalFee);
 | 
				
			||||||
      if (this._bolt11) payment.pay_req = this._bolt11;
 | 
					      if (this._bolt11) payment.pay_req = this._bolt11;
 | 
				
			||||||
      if (this._decoded) payment.decoded = this._decoded;
 | 
					      if (this._decoded) payment.decoded = this._decoded;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
@ -87,7 +87,7 @@ export class Paym {
 | 
				
			|||||||
        if (this._bolt11) payment.pay_req = this._bolt11;
 | 
					        if (this._bolt11) payment.pay_req = this._bolt11;
 | 
				
			||||||
        // trying to guess the fee
 | 
					        // trying to guess the fee
 | 
				
			||||||
        payment.payment_route = payment.payment_route || {};
 | 
					        payment.payment_route = payment.payment_route || {};
 | 
				
			||||||
        payment.payment_route.total_fees = Math.floor(this._decoded.num_satoshis * 0.01); // we dont know the exact fee, so we use max (same as fee_limit)
 | 
					        payment.payment_route.total_fees = Math.floor(this._decoded.num_satoshis * forwardFee); // we dont know the exact fee, so we use max (same as fee_limit)
 | 
				
			||||||
        payment.payment_route.total_amt = this._decoded.num_satoshis;
 | 
					        payment.payment_route.total_amt = this._decoded.num_satoshis;
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
				
			|||||||
@ -175,7 +175,7 @@ export class User {
 | 
				
			|||||||
    let lockedPayments = await this.getLockedPayments();
 | 
					    let lockedPayments = await this.getLockedPayments();
 | 
				
			||||||
    for (let paym of lockedPayments) {
 | 
					    for (let paym of lockedPayments) {
 | 
				
			||||||
      // locked payments are processed in scripts/process-locked-payments.js
 | 
					      // locked payments are processed in scripts/process-locked-payments.js
 | 
				
			||||||
      calculatedBalance -= +paym.amount + /* feelimit */ Math.floor(paym.amount * 0.01);
 | 
					      calculatedBalance -= +paym.amount + /* feelimit */ Math.floor(paym.amount * forwardFee);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return calculatedBalance;
 | 
					    return calculatedBalance;
 | 
				
			||||||
@ -579,7 +579,7 @@ export class User {
 | 
				
			|||||||
      try {
 | 
					      try {
 | 
				
			||||||
        json = JSON.parse(paym);
 | 
					        json = JSON.parse(paym);
 | 
				
			||||||
        result.push(json);
 | 
					        result.push(json);
 | 
				
			||||||
      } catch (_) {}
 | 
					      } catch (_) { }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return result;
 | 
					    return result;
 | 
				
			||||||
 | 
				
			|||||||
@ -2,6 +2,8 @@ let config = {
 | 
				
			|||||||
  enableUpdateDescribeGraph: false,
 | 
					  enableUpdateDescribeGraph: false,
 | 
				
			||||||
  postRateLimit: 100,
 | 
					  postRateLimit: 100,
 | 
				
			||||||
  rateLimit: 200,
 | 
					  rateLimit: 200,
 | 
				
			||||||
 | 
					  defaultForwardReserveFee: 0.01,
 | 
				
			||||||
 | 
					  defaultIntraHubFee: 0.003,
 | 
				
			||||||
  bitcoind: {
 | 
					  bitcoind: {
 | 
				
			||||||
    rpc: 'http://login:password@1.1.1.1:8332/wallet/wallet.dat',
 | 
					    rpc: 'http://login:password@1.1.1.1:8332/wallet/wallet.dat',
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
 | 
				
			|||||||
@ -15,6 +15,12 @@ redis.monitor(function (err, monitor) {
 | 
				
			|||||||
  });
 | 
					  });
 | 
				
			||||||
});
 | 
					});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/****** START SET FEES FROM CONFIG AT STARTUP ******/
 | 
				
			||||||
 | 
					/** GLOBALS */
 | 
				
			||||||
 | 
					global.forwardFee = config.defaultForwardReserveFee;
 | 
				
			||||||
 | 
					global.internalFee = config.defaultIntraHubFee;
 | 
				
			||||||
 | 
					/****** END SET FEES FROM CONFIG AT STARTUP ******/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
let bitcoinclient = require('../bitcoin');
 | 
					let bitcoinclient = require('../bitcoin');
 | 
				
			||||||
let lightning = require('../lightning');
 | 
					let lightning = require('../lightning');
 | 
				
			||||||
let identity_pubkey = false;
 | 
					let identity_pubkey = false;
 | 
				
			||||||
@ -235,7 +241,7 @@ router.post('/payinvoice', async function (req, res) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    logger.log('/payinvoice', [req.id, 'userBalance: ' + userBalance, 'num_satoshis: ' + info.num_satoshis]);
 | 
					    logger.log('/payinvoice', [req.id, 'userBalance: ' + userBalance, 'num_satoshis: ' + info.num_satoshis]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (userBalance >= +info.num_satoshis + Math.floor(info.num_satoshis * 0.01)) {
 | 
					    if (userBalance >= +info.num_satoshis + Math.floor(info.num_satoshis * forwardFee)) {
 | 
				
			||||||
      // got enough balance, including 1% of payment amount - reserve for fees
 | 
					      // got enough balance, including 1% of payment amount - reserve for fees
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      if (identity_pubkey === info.destination) {
 | 
					      if (identity_pubkey === info.destination) {
 | 
				
			||||||
@ -262,8 +268,8 @@ router.post('/payinvoice', async function (req, res) {
 | 
				
			|||||||
        await u.savePaidLndInvoice({
 | 
					        await u.savePaidLndInvoice({
 | 
				
			||||||
          timestamp: parseInt(+new Date() / 1000),
 | 
					          timestamp: parseInt(+new Date() / 1000),
 | 
				
			||||||
          type: 'paid_invoice',
 | 
					          type: 'paid_invoice',
 | 
				
			||||||
          value: +info.num_satoshis + Math.floor(info.num_satoshis * Paym.fee),
 | 
					          value: +info.num_satoshis + Math.floor(info.num_satoshis * internalFee),
 | 
				
			||||||
          fee: Math.floor(info.num_satoshis * Paym.fee),
 | 
					          fee: Math.floor(info.num_satoshis * internalFee),
 | 
				
			||||||
          memo: decodeURIComponent(info.description),
 | 
					          memo: decodeURIComponent(info.description),
 | 
				
			||||||
          pay_req: req.body.invoice,
 | 
					          pay_req: req.body.invoice,
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
@ -316,7 +322,7 @@ router.post('/payinvoice', async function (req, res) {
 | 
				
			|||||||
      let inv = {
 | 
					      let inv = {
 | 
				
			||||||
        payment_request: req.body.invoice,
 | 
					        payment_request: req.body.invoice,
 | 
				
			||||||
        amt: info.num_satoshis, // amt is used only for 'tip' invoices
 | 
					        amt: info.num_satoshis, // amt is used only for 'tip' invoices
 | 
				
			||||||
        fee_limit: { fixed: Math.floor(info.num_satoshis * 0.005) + 1 },
 | 
					        fee_limit: { fixed: Math.floor(info.num_satoshis * internalFee) + 1 }, // fee setting was 0.005 now set as internalFee
 | 
				
			||||||
      };
 | 
					      };
 | 
				
			||||||
      try {
 | 
					      try {
 | 
				
			||||||
        await u.lockFunds(req.body.invoice, info);
 | 
					        await u.lockFunds(req.body.invoice, info);
 | 
				
			||||||
@ -419,8 +425,8 @@ router.get('/gettxs', async function (req, res) {
 | 
				
			|||||||
    for (let locked of lockedPayments) {
 | 
					    for (let locked of lockedPayments) {
 | 
				
			||||||
      txs.push({
 | 
					      txs.push({
 | 
				
			||||||
        type: 'paid_invoice',
 | 
					        type: 'paid_invoice',
 | 
				
			||||||
        fee: Math.floor(locked.amount * 0.01) /* feelimit */,
 | 
					        fee: Math.floor(locked.amount * forwardFee) /* feelimit */,
 | 
				
			||||||
        value: locked.amount + Math.floor(locked.amount * 0.01) /* feelimit */,
 | 
					        value: locked.amount + Math.floor(locked.amount * forwardFee) /* feelimit */,
 | 
				
			||||||
        timestamp: locked.timestamp,
 | 
					        timestamp: locked.timestamp,
 | 
				
			||||||
        memo: 'Payment in transition',
 | 
					        memo: 'Payment in transition',
 | 
				
			||||||
      });
 | 
					      });
 | 
				
			||||||
 | 
				
			|||||||
@ -50,7 +50,7 @@ let lightning = require('../lightning');
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  let locked = await U.getLockedPayments();
 | 
					  let locked = await U.getLockedPayments();
 | 
				
			||||||
  for (let loc of locked) {
 | 
					  for (let loc of locked) {
 | 
				
			||||||
    console.log('-', loc.amount + /* fee limit */ Math.floor(loc.amount * 0.01), new Date(loc.timestamp * 1000).toString(), '[locked]');
 | 
					    console.log('-', loc.amount + /* fee limit */ Math.floor(loc.amount * config.defaultForwardReserveFee), new Date(loc.timestamp * 1000).toString(), '[locked]');
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  console.log('\ncalculatedBalance\n================\n', calculatedBalance, await U.getCalculatedBalance());
 | 
					  console.log('\ncalculatedBalance\n================\n', calculatedBalance, await U.getCalculatedBalance());
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user