From 65a9541673144581e2523833399c17705c66993f Mon Sep 17 00:00:00 2001 From: Mike Fluff Date: Wed, 6 Mar 2019 11:01:59 +0700 Subject: [PATCH 1/4] TLS config fix --- bitcoin.js | 8 +++++++- config.js | 10 +++++----- controllers/api.js | 9 +++++---- package-lock.json | 44 +++++++++++++++++++------------------------- 4 files changed, 36 insertions(+), 35 deletions(-) diff --git a/bitcoin.js b/bitcoin.js index 142044e..837bcdb 100644 --- a/bitcoin.js +++ b/bitcoin.js @@ -1,7 +1,13 @@ +const fs = require('fs') +const path = require('path') // setup bitcoind rpc const config = require('./config'); let jayson = require('jayson/promise'); let url = require('url'); let rpc = url.parse(config.bitcoind.rpc); rpc.timeout = 5000; -module.exports = jayson.client.http(rpc); +rpc.rejectUnauthorized = false +rpc.ecdhCurve = 'auto' +const client = jayson.client.https(rpc) +module.exports = client; + diff --git a/config.js b/config.js index 22585cb..441a603 100644 --- a/config.js +++ b/config.js @@ -1,16 +1,16 @@ let config = { bitcoind: { - rpc: 'http://login:password@1.1.1.1:8332', + rpc: 'https://kek:kek@127.0.0.1:18334', }, redis: { - port: 12914, - host: '1.1.1.1', + port: 6379, + host: '127.0.0.1', family: 4, - password: 'password', + password: '', db: 0, }, lnd: { - url: '1.1.1.1:10009', + url: '127.0.0.1:10009', }, }; diff --git a/controllers/api.js b/controllers/api.js index 70f5215..3d850e2 100644 --- a/controllers/api.js +++ b/controllers/api.js @@ -18,7 +18,8 @@ let lightning = require('../lightning'); let identity_pubkey = false; // ###################### SMOKE TESTS ######################## -bitcoinclient.request('getblockchaininfo', false, function(err, info) { +bitcoinclient.request('getinfo', false, function(err, info) { + console.log(err) if (info && info.result && info.result.blocks) { if (info.result.blocks < 550000) { console.error('bitcoind is not caught up'); @@ -240,7 +241,7 @@ router.get('/balance', async function(req, res) { } if (!(await u.getAddress())) await u.generateAddress(); // onchain address needed further - await u.accountForPosibleTxids(); + u.accountForPosibleTxids(); let balance = await u.getBalance(); res.send({ BTC: { AvailableBalance: balance } }); }); @@ -267,7 +268,7 @@ router.get('/gettxs', async function(req, res) { if (!(await u.getAddress())) await u.generateAddress(); // onchain addr needed further try { - await u.accountForPosibleTxids(); + u.accountForPosibleTxids(); let txs = await u.getTxs(); res.send(txs); } catch (Err) { @@ -304,7 +305,7 @@ router.get('/getpending', async function(req, res) { } if (!(await u.getAddress())) await u.generateAddress(); // onchain address needed further - await u.accountForPosibleTxids(); + u.accountForPosibleTxids(); let txs = await u.getPendingTxs(); res.send(txs); }); diff --git a/package-lock.json b/package-lock.json index f98aba5..c43a89b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "LndHub", - "version": "1.0.0", + "version": "1.1.1", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -1196,6 +1196,7 @@ "bech32": "^1.1.2", "bitcoinjs-lib": "^3.3.1", "bn.js": "^4.11.8", + "coininfo": "git+https://github.com/cryptocoinjs/coininfo.git#c7e003b2fc0db165b89e6f98f6d6360ad22616b2", "lodash": "^4.17.4", "safe-buffer": "^5.1.1", "secp256k1": "^3.4.0" @@ -1486,6 +1487,13 @@ "resolved": "https://registry.npmjs.org/code-point-at/-/code-point-at-1.1.0.tgz", "integrity": "sha1-DQcLTQQ6W+ozovGkDi7bPZpMz3c=" }, + "coininfo": { + "version": "git+https://github.com/cryptocoinjs/coininfo.git#c7e003b2fc0db165b89e6f98f6d6360ad22616b2", + "from": "git+https://github.com/cryptocoinjs/coininfo.git#c7e003b2fc0db165b89e6f98f6d6360ad22616b2", + "requires": { + "safe-buffer": "^5.1.1" + } + }, "collection-visit": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/collection-visit/-/collection-visit-1.0.0.tgz", @@ -2368,13 +2376,11 @@ }, "balanced-match": { "version": "1.0.0", - "bundled": true, - "optional": true + "bundled": true }, "brace-expansion": { "version": "1.1.11", "bundled": true, - "optional": true, "requires": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" @@ -2387,18 +2393,15 @@ }, "code-point-at": { "version": "1.1.0", - "bundled": true, - "optional": true + "bundled": true }, "concat-map": { "version": "0.0.1", - "bundled": true, - "optional": true + "bundled": true }, "console-control-strings": { "version": "1.1.0", - "bundled": true, - "optional": true + "bundled": true }, "core-util-is": { "version": "1.0.2", @@ -2501,8 +2504,7 @@ }, "inherits": { "version": "2.0.3", - "bundled": true, - "optional": true + "bundled": true }, "ini": { "version": "1.3.5", @@ -2512,7 +2514,6 @@ "is-fullwidth-code-point": { "version": "1.0.0", "bundled": true, - "optional": true, "requires": { "number-is-nan": "^1.0.0" } @@ -2525,20 +2526,17 @@ "minimatch": { "version": "3.0.4", "bundled": true, - "optional": true, "requires": { "brace-expansion": "^1.1.7" } }, "minimist": { "version": "0.0.8", - "bundled": true, - "optional": true + "bundled": true }, "minipass": { "version": "2.2.4", "bundled": true, - "optional": true, "requires": { "safe-buffer": "^5.1.1", "yallist": "^3.0.0" @@ -2555,7 +2553,6 @@ "mkdirp": { "version": "0.5.1", "bundled": true, - "optional": true, "requires": { "minimist": "0.0.8" } @@ -2628,8 +2625,7 @@ }, "number-is-nan": { "version": "1.0.1", - "bundled": true, - "optional": true + "bundled": true }, "object-assign": { "version": "4.1.1", @@ -2639,7 +2635,6 @@ "once": { "version": "1.4.0", "bundled": true, - "optional": true, "requires": { "wrappy": "1" } @@ -2745,7 +2740,6 @@ "string-width": { "version": "1.0.2", "bundled": true, - "optional": true, "requires": { "code-point-at": "^1.0.0", "is-fullwidth-code-point": "^1.0.0", @@ -2874,9 +2868,9 @@ "integrity": "sha512-6uHUhOPEBgQ24HM+r6b/QwWfZq+yiFcipKFrOFiBEnWdy5sdzYoi+pJeQaPI5qOLRFqWmAXUPQNsielzdLoecA==" }, "grpc": { - "version": "1.17.0-pre1", - "resolved": "https://registry.npmjs.org/grpc/-/grpc-1.17.0-pre1.tgz", - "integrity": "sha512-LWoGYW+ylOo2Ldvq/1i/SEwDsIxmDEJK9KoHPHEQkkwdG5zC+9D3/wJsgf/JFvpUoHrPdzLfBUqxfzRVCR90jw==", + "version": "1.19.0", + "resolved": "https://registry.npmjs.org/grpc/-/grpc-1.19.0.tgz", + "integrity": "sha512-xX+jZ1M3YXjngsRj/gTxB4EwM0WoWUr54DmyNq9xTeg1oSuVaTPD/PK9wnZKOJWTt1pkeFspXqwJPhddZNxHOA==", "requires": { "lodash.camelcase": "^4.3.0", "lodash.clone": "^4.5.0", From f624ced5ce324afbd8fcfefb359862d7e00f80a9 Mon Sep 17 00:00:00 2001 From: Mike Fluff Date: Wed, 6 Mar 2019 11:27:40 +0700 Subject: [PATCH 2/4] Fix with null result TXs fetcher --- class/User.js | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/class/User.js b/class/User.js index a2b62e0..5720ff4 100644 --- a/class/User.js +++ b/class/User.js @@ -282,13 +282,14 @@ export class User { let txs = await this._bitcoindrpc.request('listtransactions', [addr, 100500, 0, true]); txs = txs.result; let result = []; - for (let tx of txs) { - if (tx.confirmations >= 3) { - tx.type = 'bitcoind_tx'; - result.push(tx); + if(!txs===null) { + for (let tx of txs) { + if (tx.confirmations >= 3) { + tx.type = 'bitcoind_tx'; + result.push(tx); + } } } - let range = await this._redis.lrange('txs_for_' + this._userid, 0, -1); for (let invoice of range) { invoice = JSON.parse(invoice); @@ -311,9 +312,7 @@ export class User { delete invoice.payment_route; delete invoice.pay_req; delete invoice.decoded; - result.push(invoice); } - return result; } @@ -332,9 +331,11 @@ export class User { let txs = await this._bitcoindrpc.request('listtransactions', [addr, 100500, 0, true]); txs = txs.result; let result = []; - for (let tx of txs) { - if (tx.confirmations < 3) { - result.push(tx); + if(!txs === null) { + for (let tx of txs) { + if (tx.confirmations < 3) { + result.push(tx); + } } } return result; From cb722e160881e68c81dd4c693b17eb60356da5d4 Mon Sep 17 00:00:00 2001 From: Mike Fluff Date: Wed, 6 Mar 2019 11:34:17 +0700 Subject: [PATCH 3/4] Fix after merge --- class/User.js | 1 + controllers/api.js | 9 ++++----- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/class/User.js b/class/User.js index 5720ff4..5f6f741 100644 --- a/class/User.js +++ b/class/User.js @@ -312,6 +312,7 @@ export class User { delete invoice.payment_route; delete invoice.pay_req; delete invoice.decoded; + result.push(invoice); } return result; } diff --git a/controllers/api.js b/controllers/api.js index eca3346..fe95d6f 100644 --- a/controllers/api.js +++ b/controllers/api.js @@ -18,8 +18,7 @@ let lightning = require('../lightning'); let identity_pubkey = false; // ###################### SMOKE TESTS ######################## -bitcoinclient.request('getinfo', false, function(err, info) { - console.log(err) +bitcoinclient.request('getblockchaininfo', false, function(err, info) { if (info && info.result && info.result.blocks) { if (info.result.blocks < 550000) { console.error('bitcoind is not caught up'); @@ -252,7 +251,7 @@ router.get('/balance', async function(req, res) { } if (!(await u.getAddress())) await u.generateAddress(); // onchain address needed further - u.accountForPosibleTxids(); + await u.accountForPosibleTxids(); let balance = await u.getBalance(); if (balance < 0) balance = 0; res.send({ BTC: { AvailableBalance: balance } }); @@ -280,7 +279,7 @@ router.get('/gettxs', async function(req, res) { if (!(await u.getAddress())) await u.generateAddress(); // onchain addr needed further try { - u.accountForPosibleTxids(); + await u.accountForPosibleTxids(); let txs = await u.getTxs(); res.send(txs); } catch (Err) { @@ -317,7 +316,7 @@ router.get('/getpending', async function(req, res) { } if (!(await u.getAddress())) await u.generateAddress(); // onchain address needed further - u.accountForPosibleTxids(); + await u.accountForPosibleTxids(); let txs = await u.getPendingTxs(); res.send(txs); }); From 3317e620dd60300d5f751f84e84394707ad2b074 Mon Sep 17 00:00:00 2001 From: Mike Fluff Date: Wed, 6 Mar 2019 11:36:19 +0700 Subject: [PATCH 4/4] Linter fixes --- class/User.js | 2 +- controllers/api.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/class/User.js b/class/User.js index 5f6f741..7f0dec5 100644 --- a/class/User.js +++ b/class/User.js @@ -312,7 +312,7 @@ export class User { delete invoice.payment_route; delete invoice.pay_req; delete invoice.decoded; - result.push(invoice); + result.push(invoice); } return result; } diff --git a/controllers/api.js b/controllers/api.js index fe95d6f..ab2760b 100644 --- a/controllers/api.js +++ b/controllers/api.js @@ -279,7 +279,7 @@ router.get('/gettxs', async function(req, res) { if (!(await u.getAddress())) await u.generateAddress(); // onchain addr needed further try { - await u.accountForPosibleTxids(); + await u.accountForPosibleTxids(); let txs = await u.getTxs(); res.send(txs); } catch (Err) {