Merge branch 'bluewallet-lndhub'
# Conflicts: # package.json
This commit is contained in:
		
						commit
						6074dc6c2c
					
				@ -243,7 +243,11 @@ export class User {
 | 
				
			|||||||
      invoice.description = '';
 | 
					      invoice.description = '';
 | 
				
			||||||
      for (let tag of decoded.tags) {
 | 
					      for (let tag of decoded.tags) {
 | 
				
			||||||
        if (tag.tagName === 'description') {
 | 
					        if (tag.tagName === 'description') {
 | 
				
			||||||
          invoice.description += decodeURIComponent(tag.data);
 | 
					          try {
 | 
				
			||||||
 | 
					            invoice.description += decodeURIComponent(tag.data);
 | 
				
			||||||
 | 
					          } catch (_) {
 | 
				
			||||||
 | 
					            invoice.description += tag.data;
 | 
				
			||||||
 | 
					          }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        if (tag.tagName === 'payment_hash') {
 | 
					        if (tag.tagName === 'payment_hash') {
 | 
				
			||||||
          invoice.payment_hash = tag.data;
 | 
					          invoice.payment_hash = tag.data;
 | 
				
			||||||
@ -267,7 +271,7 @@ export class User {
 | 
				
			|||||||
      }
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      invoice.amt = decoded.satoshis;
 | 
					      invoice.amt = decoded.satoshis;
 | 
				
			||||||
      invoice.expire_time = 3600;
 | 
					      invoice.expire_time = 3600 * 24;
 | 
				
			||||||
      // ^^^default; will keep for now. if we want to un-hardcode it - it should be among tags (`expire_time`)
 | 
					      // ^^^default; will keep for now. if we want to un-hardcode it - it should be among tags (`expire_time`)
 | 
				
			||||||
      invoice.timestamp = decoded.timestamp;
 | 
					      invoice.timestamp = decoded.timestamp;
 | 
				
			||||||
      invoice.type = 'user_invoice';
 | 
					      invoice.type = 'user_invoice';
 | 
				
			||||||
@ -313,6 +317,10 @@ export class User {
 | 
				
			|||||||
      if (invoice.payment_route) {
 | 
					      if (invoice.payment_route) {
 | 
				
			||||||
        invoice.fee = +invoice.payment_route.total_fees;
 | 
					        invoice.fee = +invoice.payment_route.total_fees;
 | 
				
			||||||
        invoice.value = +invoice.payment_route.total_fees + +invoice.payment_route.total_amt;
 | 
					        invoice.value = +invoice.payment_route.total_fees + +invoice.payment_route.total_amt;
 | 
				
			||||||
 | 
					        if (invoice.payment_route.total_amt_msat && invoice.payment_route.total_amt_msat / 1000 !== +invoice.payment_route.total_amt) {
 | 
				
			||||||
 | 
					          // okay, we have to account for MSAT
 | 
				
			||||||
 | 
					          invoice.value = +invoice.payment_route.total_fees + Math.max(parseInt(invoice.payment_route.total_amt_msat / 1000), +invoice.payment_route.total_amt) + 1; // extra sat to cover for msats, as external layer (clients) dont have that resolution
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
      } else {
 | 
					      } else {
 | 
				
			||||||
        invoice.fee = 0;
 | 
					        invoice.fee = 0;
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
 | 
				
			|||||||
@ -128,10 +128,17 @@ router.post('/payinvoice', async function(req, res) {
 | 
				
			|||||||
  // obtaining a lock
 | 
					  // obtaining a lock
 | 
				
			||||||
  let lock = new Lock(redis, 'invoice_paying_for_' + u.getUserId());
 | 
					  let lock = new Lock(redis, 'invoice_paying_for_' + u.getUserId());
 | 
				
			||||||
  if (!(await lock.obtainLock())) {
 | 
					  if (!(await lock.obtainLock())) {
 | 
				
			||||||
    return errorTryAgainLater(res);
 | 
					    return errorGeneralServerError(res);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  let userBalance = await u.getCalculatedBalance();
 | 
					  let userBalance;
 | 
				
			||||||
 | 
					  try {
 | 
				
			||||||
 | 
					    userBalance = await u.getCalculatedBalance();
 | 
				
			||||||
 | 
					  } catch (Error) {
 | 
				
			||||||
 | 
					    logger.log('', [req.id, 'error running getCalculatedBalance():', Error.message]);
 | 
				
			||||||
 | 
					    lock.releaseLock();
 | 
				
			||||||
 | 
					    return errorTryAgainLater(res);
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  lightning.decodePayReq({ pay_req: req.body.invoice }, async function(err, info) {
 | 
					  lightning.decodePayReq({ pay_req: req.body.invoice }, async function(err, info) {
 | 
				
			||||||
    if (err) {
 | 
					    if (err) {
 | 
				
			||||||
@ -206,7 +213,7 @@ router.post('/payinvoice', async function(req, res) {
 | 
				
			|||||||
          return errorPaymentFailed(res);
 | 
					          return errorPaymentFailed(res);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
      });
 | 
					      });
 | 
				
			||||||
      if (!info.num_satoshis && !info.num_satoshis) {
 | 
					      if (!info.num_satoshis) {
 | 
				
			||||||
        // tip invoice, but someone forgot to specify amount
 | 
					        // tip invoice, but someone forgot to specify amount
 | 
				
			||||||
        await lock.releaseLock();
 | 
					        await lock.releaseLock();
 | 
				
			||||||
        return errorBadArguments(res);
 | 
					        return errorBadArguments(res);
 | 
				
			||||||
@ -255,11 +262,16 @@ router.get('/balance', postLimiter, async function(req, res) {
 | 
				
			|||||||
    return errorBadAuth(res);
 | 
					    return errorBadAuth(res);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if (!(await u.getAddress())) await u.generateAddress(); // onchain address needed further
 | 
					  try {
 | 
				
			||||||
  await u.accountForPosibleTxids();
 | 
					    if (!(await u.getAddress())) await u.generateAddress(); // onchain address needed further
 | 
				
			||||||
  let balance = await u.getBalance();
 | 
					    await u.accountForPosibleTxids();
 | 
				
			||||||
  if (balance < 0) balance = 0;
 | 
					    let balance = await u.getBalance();
 | 
				
			||||||
  res.send({ BTC: { AvailableBalance: balance } });
 | 
					    if (balance < 0) balance = 0;
 | 
				
			||||||
 | 
					    res.send({ BTC: { AvailableBalance: balance } });
 | 
				
			||||||
 | 
					  } catch (Error) {
 | 
				
			||||||
 | 
					    logger.log('', [req.id, 'error getting balance:', Error.message, 'userid:', u.getUserId()]);
 | 
				
			||||||
 | 
					    return errorGeneralServerError(res);
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
});
 | 
					});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
router.get('/getinfo', postLimiter, async function(req, res) {
 | 
					router.get('/getinfo', postLimiter, async function(req, res) {
 | 
				
			||||||
@ -298,7 +310,7 @@ router.get('/gettxs', async function(req, res) {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
    res.send(txs);
 | 
					    res.send(txs);
 | 
				
			||||||
  } catch (Err) {
 | 
					  } catch (Err) {
 | 
				
			||||||
    logger.log('', [req.id, 'error:', Err]);
 | 
					    logger.log('', [req.id, 'error gettxs:', Err.message, 'userid:', u.getUserId()]);
 | 
				
			||||||
    res.send([]);
 | 
					    res.send([]);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
});
 | 
					});
 | 
				
			||||||
@ -318,7 +330,7 @@ router.get('/getuserinvoices', async function(req, res) {
 | 
				
			|||||||
      res.send(invoices);
 | 
					      res.send(invoices);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  } catch (Err) {
 | 
					  } catch (Err) {
 | 
				
			||||||
    logger.log('', [req.id, 'error:', Err]);
 | 
					    logger.log('', [req.id, 'error getting user invoices:', Err.message, 'userid:', u.getUserId()]);
 | 
				
			||||||
    res.send([]);
 | 
					    res.send([]);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
});
 | 
					});
 | 
				
			||||||
@ -408,7 +420,7 @@ function errorGeneralServerError(res) {
 | 
				
			|||||||
  return res.send({
 | 
					  return res.send({
 | 
				
			||||||
    error: true,
 | 
					    error: true,
 | 
				
			||||||
    code: 6,
 | 
					    code: 6,
 | 
				
			||||||
    message: 'Server fault',
 | 
					    message: 'Something went wrong. Please try again later',
 | 
				
			||||||
  });
 | 
					  });
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										18
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										18
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							@ -2050,9 +2050,9 @@
 | 
				
			|||||||
      }
 | 
					      }
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
    "eslint-plugin-prettier": {
 | 
					    "eslint-plugin-prettier": {
 | 
				
			||||||
      "version": "3.1.1",
 | 
					      "version": "3.1.2",
 | 
				
			||||||
      "resolved": "https://registry.npmjs.org/eslint-plugin-prettier/-/eslint-plugin-prettier-3.1.1.tgz",
 | 
					      "resolved": "https://registry.npmjs.org/eslint-plugin-prettier/-/eslint-plugin-prettier-3.1.2.tgz",
 | 
				
			||||||
      "integrity": "sha512-A+TZuHZ0KU0cnn56/9mfR7/KjUJ9QNVXUhwvRFSR7PGPe0zQR6PTkmyqg1AtUUEOzTqeRsUwyKFh0oVZKVCrtA==",
 | 
					      "integrity": "sha512-GlolCC9y3XZfv3RQfwGew7NnuFDKsfI4lbvRK+PIIo23SFH+LemGs4cKwzAaRa+Mdb+lQO/STaIayno8T5sJJA==",
 | 
				
			||||||
      "requires": {
 | 
					      "requires": {
 | 
				
			||||||
        "prettier-linter-helpers": "^1.0.0"
 | 
					        "prettier-linter-helpers": "^1.0.0"
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
@ -3641,9 +3641,9 @@
 | 
				
			|||||||
      "integrity": "sha1-EEqOSqym09jNFXqO+L+rLXo//bY="
 | 
					      "integrity": "sha1-EEqOSqym09jNFXqO+L+rLXo//bY="
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
    "ioredis": {
 | 
					    "ioredis": {
 | 
				
			||||||
      "version": "4.14.1",
 | 
					      "version": "4.15.1",
 | 
				
			||||||
      "resolved": "https://registry.npmjs.org/ioredis/-/ioredis-4.14.1.tgz",
 | 
					      "resolved": "https://registry.npmjs.org/ioredis/-/ioredis-4.15.1.tgz",
 | 
				
			||||||
      "integrity": "sha512-94W+X//GHM+1GJvDk6JPc+8qlM7Dul+9K+lg3/aHixPN7ZGkW6qlvX0DG6At9hWtH2v3B32myfZqWoANUJYGJA==",
 | 
					      "integrity": "sha512-vbSsIlmI2P31c+nxZvYjChAcgMK5Ssn9FLdhOXi0O+KVOp6JLXrkVFlq8Zrmc3ee5e5eoqB9nHFYIQzWKc/12Q==",
 | 
				
			||||||
      "requires": {
 | 
					      "requires": {
 | 
				
			||||||
        "cluster-key-slot": "^1.1.0",
 | 
					        "cluster-key-slot": "^1.1.0",
 | 
				
			||||||
        "debug": "^4.1.1",
 | 
					        "debug": "^4.1.1",
 | 
				
			||||||
@ -4211,9 +4211,9 @@
 | 
				
			|||||||
      "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g="
 | 
					      "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g="
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
    "mustache": {
 | 
					    "mustache": {
 | 
				
			||||||
      "version": "3.1.0",
 | 
					      "version": "3.2.1",
 | 
				
			||||||
      "resolved": "https://registry.npmjs.org/mustache/-/mustache-3.1.0.tgz",
 | 
					      "resolved": "https://registry.npmjs.org/mustache/-/mustache-3.2.1.tgz",
 | 
				
			||||||
      "integrity": "sha512-3Bxq1R5LBZp7fbFPZzFe5WN4s0q3+gxZaZuZVY+QctYJiCiVgXHOTIC0/HgZuOPFt/6BQcx5u0H2CUOxT/RoGQ=="
 | 
					      "integrity": "sha512-RERvMFdLpaFfSRIEe632yDm5nsd0SDKn8hGmcUwswnyiE5mtdZLDybtHAz6hjJhawokF0hXvGLtx9mrQfm6FkA=="
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
    "mute-stream": {
 | 
					    "mute-stream": {
 | 
				
			||||||
      "version": "0.0.8",
 | 
					      "version": "0.0.8",
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										10
									
								
								package.json
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								package.json
									
									
									
									
									
								
							@ -19,18 +19,18 @@
 | 
				
			|||||||
    "babel-preset-env": "^1.7.0",
 | 
					    "babel-preset-env": "^1.7.0",
 | 
				
			||||||
    "babel-preset-es2015": "^6.24.1",
 | 
					    "babel-preset-es2015": "^6.24.1",
 | 
				
			||||||
    "babel-register": "^6.26.0",
 | 
					    "babel-register": "^6.26.0",
 | 
				
			||||||
    "bignumber.js": "^9.0.0",
 | 
					    "bignumber.js": "^8.0.1",
 | 
				
			||||||
    "bolt11": "^1.2.6",
 | 
					    "bolt11": "^1.2.6",
 | 
				
			||||||
    "eslint": "^6.7.1",
 | 
					    "eslint": "^5.9.0",
 | 
				
			||||||
    "eslint-config-prettier": "^6.7.0",
 | 
					    "eslint-config-prettier": "^3.3.0",
 | 
				
			||||||
    "eslint-plugin-prettier": "^3.0.0",
 | 
					    "eslint-plugin-prettier": "^3.1.2",
 | 
				
			||||||
    "express": "^4.16.4",
 | 
					    "express": "^4.16.4",
 | 
				
			||||||
    "express-rate-limit": "^5.0.0",
 | 
					    "express-rate-limit": "^5.0.0",
 | 
				
			||||||
    "grpc": "^1.17.0-pre1",
 | 
					    "grpc": "^1.17.0-pre1",
 | 
				
			||||||
    "ioredis": "^4.2.0",
 | 
					    "ioredis": "^4.2.0",
 | 
				
			||||||
    "jayson": "^3.1.2",
 | 
					    "jayson": "^3.1.2",
 | 
				
			||||||
    "morgan": "^1.9.1",
 | 
					    "morgan": "^1.9.1",
 | 
				
			||||||
    "mustache": "^3.0.1",
 | 
					    "mustache": "^3.2.1",
 | 
				
			||||||
    "node-uuid": "^1.4.8",
 | 
					    "node-uuid": "^1.4.8",
 | 
				
			||||||
    "prettier": "^1.19.1",
 | 
					    "prettier": "^1.19.1",
 | 
				
			||||||
    "request": "^2.88.0",
 | 
					    "request": "^2.88.0",
 | 
				
			||||||
 | 
				
			|||||||
@ -37,10 +37,6 @@ if (!fs.existsSync('logs')) {
 | 
				
			|||||||
  fs.mkdirSync('logs');
 | 
					  fs.mkdirSync('logs');
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					 | 
				
			||||||
 * @param {string} label group label
 | 
					 | 
				
			||||||
 * @param {string} message log message
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
function log(label, message) {
 | 
					function log(label, message) {
 | 
				
			||||||
  logger.log({
 | 
					  logger.log({
 | 
				
			||||||
    level: 'info',
 | 
					    level: 'info',
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user