From 98e005938df9ab97c639dccd4cef5c319f2204fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Almeida?= Date: Sun, 17 Dec 2017 14:21:23 -0500 Subject: [PATCH] feature(auth-macaroon): Add macaroon auth support --- app/lnd/config/index.js | 7 ++++- app/lnd/index.js | 11 +++++-- app/lnd/lib/lightning.js | 3 +- app/lnd/methods/channelController.js | 24 +++++++-------- app/lnd/methods/index.js | 44 +++++++++++++-------------- app/lnd/methods/invoicesController.js | 20 ++++++------ app/lnd/methods/networkController.js | 20 ++++++------ app/lnd/methods/paymentsController.js | 20 ++++++------ app/lnd/methods/peersController.js | 12 ++++---- app/lnd/methods/walletController.js | 22 +++++++------- app/lnd/push/closechannel.js | 4 +-- app/lnd/push/openchannel.js | 4 +-- app/lnd/push/subscribeinvoice.js | 4 +-- app/lnd/subscribe/channelgraph.js | 9 +++--- app/lnd/subscribe/index.js | 8 ++--- app/lnd/subscribe/invoices.js | 4 +-- app/lnd/subscribe/transactions.js | 5 ++- 17 files changed, 114 insertions(+), 107 deletions(-) diff --git a/app/lnd/config/index.js b/app/lnd/config/index.js index c0366490..523dd0d6 100644 --- a/app/lnd/config/index.js +++ b/app/lnd/config/index.js @@ -6,15 +6,19 @@ import { userInfo, platform } from 'os' import { join } from 'path' let loc +let macaroonPath switch (platform()) { case 'darwin': loc = 'Library/Application Support/Lnd/tls.cert' + macaroonPath = 'Library/Application Support/Lnd/admin.macaroon' break case 'linux': loc = '.lnd/tls.cert' + macaroonPath = '.lnd/admin.macaroon' break case 'win32': loc = join('Appdata', 'Local', 'Lnd', 'tls.cert') + macaroonPath = join('Appdata', 'Local', 'Lnd', 'admin.macaroon') break default: break @@ -23,5 +27,6 @@ switch (platform()) { export default { lightningRpc: `${__dirname}/rpc.proto`, lightningHost: 'localhost:10009', - cert: join(userInfo().homedir, loc) + cert: join(userInfo().homedir, loc), + macaroon: join(userInfo().homedir, macaroonPath) } diff --git a/app/lnd/index.js b/app/lnd/index.js index ef0d3623..40796b74 100644 --- a/app/lnd/index.js +++ b/app/lnd/index.js @@ -1,13 +1,18 @@ +import grpc from 'grpc' +import fs from 'fs' import config from './config' import lightning from './lib/lightning' import subscribe from './subscribe' import methods from './methods' export default (callback) => { - const lnd = lightning(config.lightningRpc, config.lightningHost) + const macaroonFile = fs.readFileSync(config.macaroon) + const meta = new grpc.Metadata() + meta.add('macaroon', macaroonFile.toString('hex')) - const lndSubscribe = mainWindow => subscribe(mainWindow, lnd) - const lndMethods = (event, msg, data) => methods(lnd, event, msg, data) + const lnd = lightning(config.lightningRpc, config.lightningHost) + const lndSubscribe = mainWindow => subscribe(mainWindow, lnd, meta) + const lndMethods = (event, msg, data) => methods(lnd, meta, event, msg, data) callback(lndSubscribe, lndMethods) } diff --git a/app/lnd/lib/lightning.js b/app/lnd/lib/lightning.js index f01c0ed1..bb1c1587 100644 --- a/app/lnd/lib/lightning.js +++ b/app/lnd/lib/lightning.js @@ -6,8 +6,7 @@ import config from '../config' module.exports = (rpcpath, host) => { const lndCert = fs.readFileSync(config.cert) const credentials = grpc.credentials.createSsl(lndCert) - const rpc = grpc.load(path.join(__dirname, 'rpc.proto')) - + return new rpc.lnrpc.Lightning(host, credentials) } diff --git a/app/lnd/methods/channelController.js b/app/lnd/methods/channelController.js index dd328ad0..e2117126 100644 --- a/app/lnd/methods/channelController.js +++ b/app/lnd/methods/channelController.js @@ -11,7 +11,7 @@ const BufferUtil = bitcore.util.buffer * @param {[type]} payload [description] * @return {[type]} [description] */ -export function openChannel(lnd, event, payload) { +export function openChannel(lnd, meta, event, payload) { const { pubkey, localamt, pushamt } = payload const res = { node_pubkey: BufferUtil.hexToBuffer(pubkey), @@ -20,7 +20,7 @@ export function openChannel(lnd, event, payload) { } return new Promise((resolve, reject) => - pushopenchannel(lnd, event, res) + pushopenchannel(lnd, meta, event, res) .then(data => resolve(data)) .catch(error => reject(error)) ) @@ -32,9 +32,9 @@ export function openChannel(lnd, event, payload) { * @param {[type]} lnd [description] * @return {[type]} [description] */ -export function channelBalance(lnd) { +export function channelBalance(lnd, meta) { return new Promise((resolve, reject) => { - lnd.channelBalance({}, (err, data) => { + lnd.channelBalance({}, meta, (err, data) => { if (err) { reject(err) } resolve(data) @@ -48,9 +48,9 @@ export function channelBalance(lnd) { * @param {[type]} lnd [description] * @return {[type]} [description] */ -export function listChannels(lnd) { +export function listChannels(lnd, meta) { return new Promise((resolve, reject) => { - lnd.listChannels({}, (err, data) => { + lnd.listChannels({}, meta, (err, data) => { if (err) { reject(err) } resolve(data) @@ -66,7 +66,7 @@ export function listChannels(lnd) { * @param {[type]} payload [description] * @return {[type]} [description] */ -export function closeChannel(lnd, event, payload) { +export function closeChannel(lnd, meta, event, payload) { const tx = payload.channel_point.funding_txid.match(/.{2}/g).reverse().join('') const res = { channel_point: { @@ -77,7 +77,7 @@ export function closeChannel(lnd, event, payload) { } return new Promise((resolve, reject) => - pushclosechannel(lnd, event, res) + pushclosechannel(lnd, meta, event, res) .then(data => resolve(data)) .catch(error => reject(error)) ) @@ -89,9 +89,9 @@ export function closeChannel(lnd, event, payload) { * @param {[type]} lnd [description] * @return {[type]} [description] */ -export function pendingChannels(lnd) { +export function pendingChannels(lnd, meta) { return new Promise((resolve, reject) => { - lnd.pendingChannels({}, (err, data) => { + lnd.pendingChannels({}, meta, (err, data) => { if (err) { reject(err) } resolve(data) @@ -106,9 +106,9 @@ export function pendingChannels(lnd) { * @param {[type]} channelId [description] * @return {[type]} [description] */ -export function getChanInfo(lnd, { chanId }) { +export function getChanInfo(lnd, meta, { chanId }) { return new Promise((resolve, reject) => { - lnd.getChanInfo({ chan_id: chanId }, (err, data) => { + lnd.getChanInfo({ chan_id: chanId }, meta, (err, data) => { if (err) { reject(err) } resolve(data) diff --git a/app/lnd/methods/index.js b/app/lnd/methods/index.js index 4495637f..87f5a76f 100644 --- a/app/lnd/methods/index.js +++ b/app/lnd/methods/index.js @@ -23,10 +23,10 @@ import * as networkController from './networkController' // metadata.add('macaroon', macaroonHex) -export default function (lnd, event, msg, data) { +export default function (lnd, meta, event, msg, data) { switch (msg) { case 'info': - networkController.getInfo(lnd) + networkController.getInfo(lnd, meta) .then((infoData) => { event.sender.send('receiveInfo', infoData) event.sender.send('receiveCryptocurrency', infoData.chains[0]) @@ -34,21 +34,21 @@ export default function (lnd, event, msg, data) { .catch(() => event.sender.send('infoFailed')) break case 'describeNetwork': - networkController.describeGraph(lnd) + networkController.describeGraph(lnd, meta) .then(networkData => event.sender.send('receiveDescribeNetwork', networkData)) .catch(error => console.log('describeGraph error: ', error)) break case 'queryRoutes': // Data looks like { pubkey: String, amount: Number } - networkController.queryRoutes(lnd, data) + networkController.queryRoutes(lnd, meta, data) .then(routes => event.sender.send('receiveQueryRoutes', routes)) .catch(error => console.log('queryRoutes error: ', error)) break case 'getInvoiceAndQueryRoutes': // Data looks like { pubkey: String, amount: Number } - invoicesController.getInvoice(lnd, { pay_req: data.payreq }) + invoicesController.getInvoice(lnd, meta, { pay_req: data.payreq }) .then((invoiceData) => { - networkController.queryRoutes(lnd, { pubkey: invoiceData.destination, amount: invoiceData.num_satoshis }) + networkController.queryRoutes(lnd, meta, { pubkey: invoiceData.destination, amount: invoiceData.num_satoshis }) .then((routes) => { event.sender.send('receiveInvoiceAndQueryRoutes', routes) }) @@ -58,26 +58,26 @@ export default function (lnd, event, msg, data) { break case 'newaddress': // Data looks like { address: '' } - walletController.newAddress(lnd, data.type) + walletController.newAddress(lnd, meta, data.type) .then(({ address }) => event.sender.send('receiveAddress', address)) .catch(error => console.log('newaddress error: ', error)) break case 'setAlias': // Data looks like { new_alias: '' } - walletController.setAlias(lnd, data) + walletController.setAlias(lnd, meta, data) .then(() => event.sender.send('aliasSet')) .catch(error => console.log('setAlias error: ', error)) break case 'peers': // Data looks like { peers: [] } - peersController.listPeers(lnd) + peersController.listPeers(lnd, meta) .then(peersData => event.sender.send('receivePeers', peersData)) .catch(error => console.log('peers error: ', error)) break case 'channels': // Data looks like // [ { channels: [] }, { total_limbo_balance: 0, pending_open_channels: [], pending_closing_channels: [], pending_force_closing_channels: [] } ] - Promise.all([channelController.listChannels, channelController.pendingChannels].map(func => func(lnd))) + Promise.all([channelController.listChannels, channelController.pendingChannels].map(func => func(lnd, meta))) .then(channelsData => event.sender.send('receiveChannels', { channels: channelsData[0].channels, pendingChannels: channelsData[1] }) ) @@ -85,31 +85,31 @@ export default function (lnd, event, msg, data) { break case 'transactions': // Data looks like { transactions: [] } - walletController.getTransactions(lnd) + walletController.getTransactions(lnd, meta) .then(transactionsData => event.sender.send('receiveTransactions', transactionsData)) .catch(error => console.log('transactions error: ', error)) break case 'payments': // Data looks like { payments: [] } - paymentsController.listPayments(lnd) + paymentsController.listPayments(lnd, meta) .then(paymentsData => event.sender.send('receivePayments', paymentsData)) .catch(error => console.log('payments error: ', error)) break case 'invoices': // Data looks like { invoices: [] } - invoicesController.listInvoices(lnd) + invoicesController.listInvoices(lnd, meta) .then(invoicesData => event.sender.send('receiveInvoices', invoicesData)) .catch(error => console.log('invoices error: ', error)) break case 'invoice': // Data looks like { invoices: [] } - invoicesController.getInvoice(lnd, { pay_req: data.payreq }) + invoicesController.getInvoice(lnd, meta, { pay_req: data.payreq }) .then(invoiceData => event.sender.send('receiveInvoice', invoiceData)) .catch(error => console.log('invoice error: ', error)) break case 'balance': // Balance looks like [ { balance: '129477456' }, { balance: '243914' } ] - Promise.all([walletController.walletBalance, channelController.channelBalance].map(func => func(lnd))) + Promise.all([walletController.walletBalance, channelController.channelBalance].map(func => func(lnd, meta))) .then((balance) => { event.sender.send('receiveBalance', { walletBalance: balance[0].total_balance, channelBalance: balance[1].balance }) }) @@ -118,7 +118,7 @@ export default function (lnd, event, msg, data) { case 'createInvoice': // Invoice looks like { r_hash: Buffer, payment_request: '' } // { memo, value } = data - invoicesController.addInvoice(lnd, data) + invoicesController.addInvoice(lnd, meta, data) .then(newinvoice => event.sender.send( 'createdInvoice', @@ -138,7 +138,7 @@ export default function (lnd, event, msg, data) { case 'sendPayment': // Payment looks like { payment_preimage: Buffer, payment_route: Object } // { paymentRequest } = data - paymentsController.sendPaymentSync(lnd, data) + paymentsController.sendPaymentSync(lnd, meta, data) .then(({ payment_route }) => { console.log('payinvoice success: ', payment_route) event.sender.send('paymentSuccessful', Object.assign(data, { payment_route })) @@ -151,7 +151,7 @@ export default function (lnd, event, msg, data) { case 'sendCoins': // Transaction looks like { txid: String } // { amount, addr } = data - walletController.sendCoins(lnd, data) + walletController.sendCoins(lnd, meta, data) .then(({ txid }) => event.sender.send('transactionSuccessful', { amount: data.amount, addr: data.addr, txid })) .catch((error) => { console.log('error: ', error) @@ -161,7 +161,7 @@ export default function (lnd, event, msg, data) { case 'openChannel': // Response is empty. Streaming updates on channel status and updates // { pubkey, localamt, pushamt } = data - channelController.openChannel(lnd, event, data) + channelController.openChannel(lnd, meta, event, data) .then((channel) => { console.log('CHANNEL: ', channel) event.sender.send('channelSuccessful', { channel }) @@ -171,7 +171,7 @@ export default function (lnd, event, msg, data) { case 'closeChannel': // Response is empty. Streaming updates on channel status and updates // { channel_point, force } = data - channelController.closeChannel(lnd, event, data) + channelController.closeChannel(lnd, meta, event, data) .then((result) => { console.log('CLOSE CHANNEL: ', result) event.sender.send('closeChannelSuccessful') @@ -181,7 +181,7 @@ export default function (lnd, event, msg, data) { case 'connectPeer': // Returns a peer_id. Pass the pubkey, host and peer_id so we can add a new peer to the list // { pubkey, host } = data - peersController.connectPeer(lnd, data) + peersController.connectPeer(lnd, meta, data) .then(({ peer_id }) => { console.log('peer_id: ', peer_id) event.sender.send('connectSuccess', { pub_key: data.pubkey, address: data.host, peer_id }) @@ -194,7 +194,7 @@ export default function (lnd, event, msg, data) { case 'disconnectPeer': // Empty response. Pass back pubkey on success to remove it from the peers list // { pubkey } = data - peersController.disconnectPeer(lnd, data) + peersController.disconnectPeer(lnd, meta, data) .then(() => { console.log('pubkey: ', data.pubkey) event.sender.send('disconnectSuccess', { pubkey: data.pubkey }) diff --git a/app/lnd/methods/invoicesController.js b/app/lnd/methods/invoicesController.js index 07266104..a888a24d 100644 --- a/app/lnd/methods/invoicesController.js +++ b/app/lnd/methods/invoicesController.js @@ -7,9 +7,9 @@ import pushinvoices from '../push/subscribeinvoice' * @param value [description] * @return [description] */ -export function addInvoice(lnd, { memo, value }) { +export function addInvoice(lnd, meta, { memo, value }) { return new Promise((resolve, reject) => { - lnd.addInvoice({ memo, value }, (err, data) => { + lnd.addInvoice({ memo, value }, meta, (err, data) => { if (err) { reject(err) } resolve(data) @@ -22,9 +22,9 @@ export function addInvoice(lnd, { memo, value }) { * @param {[type]} lnd [description] * @return {[type]} [description] */ -export function listInvoices(lnd) { +export function listInvoices(lnd, meta) { return new Promise((resolve, reject) => { - lnd.listInvoices({}, (err, data) => { + lnd.listInvoices({}, meta, (err, data) => { if (err) { reject(err) } resolve(data) @@ -36,9 +36,9 @@ export function listInvoices(lnd) { * @param {[type]} payreq [description] * @return {[type]} [description] */ -export function getInvoice(lnd, { pay_req }) { +export function getInvoice(lnd, meta, { pay_req }) { return new Promise((resolve, reject) => { - lnd.decodePayReq({ pay_req }, (err, data) => { + lnd.decodePayReq({ pay_req }, meta, (err, data) => { if (err) { reject(err) } resolve(data) @@ -53,9 +53,9 @@ export function getInvoice(lnd, { pay_req }) { * @param {[type]} rhash [description] * @return {[type]} [description] */ -export function lookupInvoice(lnd, { rhash }) { +export function lookupInvoice(lnd, meta, { rhash }) { return new Promise((resolve, reject) => { - lnd.lookupInvoice({ r_hash: rhash }, (err, data) => { + lnd.lookupInvoice({ r_hash: rhash }, meta, (err, data) => { if (err) { reject(err) } resolve(data) @@ -70,9 +70,9 @@ export function lookupInvoice(lnd, { rhash }) { * @param {[type]} event [description] * @return {[type]} [description] */ -export function subscribeInvoices(lnd, event) { +export function subscribeInvoices(lnd, meta, event) { return new Promise((resolve, reject) => { - pushinvoices(lnd, event) + pushinvoices(lnd, meta, event) .then(data => resolve(data)) .catch(error => reject(error)) }) diff --git a/app/lnd/methods/networkController.js b/app/lnd/methods/networkController.js index 8cdd4cbe..6179968a 100644 --- a/app/lnd/methods/networkController.js +++ b/app/lnd/methods/networkController.js @@ -3,9 +3,9 @@ * @param {[type]} lnd [description] * @return {[type]} [description] */ -export function getInfo(lnd) { +export function getInfo(lnd, meta) { return new Promise((resolve, reject) => { - lnd.getInfo({}, (err, data) => { + lnd.getInfo({}, meta, (err, data) => { if (err) { reject(err) } resolve(data) @@ -20,9 +20,9 @@ export function getInfo(lnd) { * @param {[type]} pubkey [description] * @return {[type]} [description] */ -export function getNodeInfo(lnd, { pubkey }) { +export function getNodeInfo(lnd, meta, { pubkey }) { return new Promise((resolve, reject) => { - lnd.getNodeInfo({ pub_key: pubkey }, (err, data) => { + lnd.getNodeInfo({ pub_key: pubkey }, meta, (err, data) => { if (err) { reject(err) } resolve(data) @@ -36,9 +36,9 @@ export function getNodeInfo(lnd, { pubkey }) { * @param {[type]} lnd [description] * @return {[type]} [description] */ -export function describeGraph(lnd) { +export function describeGraph(lnd, meta) { return new Promise((resolve, reject) => { - lnd.describeGraph({}, (err, data) => { + lnd.describeGraph({}, meta, (err, data) => { if (err) { reject(err) } resolve(data) @@ -54,9 +54,9 @@ export function describeGraph(lnd) { * @param {[type]} amount [description] * @return {[type]} [description] */ -export function queryRoutes(lnd, { pubkey, amount }) { +export function queryRoutes(lnd, meta, { pubkey, amount }) { return new Promise((resolve, reject) => { - lnd.queryRoutes({ pub_key: pubkey, amt: amount }, (err, data) => { + lnd.queryRoutes({ pub_key: pubkey, amt: amount }, meta, (err, data) => { if (err) { reject(err) } resolve(data) @@ -70,9 +70,9 @@ export function queryRoutes(lnd, { pubkey, amount }) { * @param {[type]} lnd [description] * @return {[type]} [description] */ -export function getNetworkInfo(lnd) { +export function getNetworkInfo(lnd, meta) { return new Promise((resolve, reject) => { - lnd.getNetworkInfo({}, (err, data) => { + lnd.getNetworkInfo({}, meta, (err, data) => { if (err) { reject(err) } resolve(data) diff --git a/app/lnd/methods/paymentsController.js b/app/lnd/methods/paymentsController.js index 6a5d5397..e9afd981 100644 --- a/app/lnd/methods/paymentsController.js +++ b/app/lnd/methods/paymentsController.js @@ -4,9 +4,9 @@ * @param {[type]} paymentRequest [description] * @return {[type]} [description] */ -export function sendPaymentSync(lnd, { paymentRequest }) { +export function sendPaymentSync(lnd, meta, { paymentRequest }) { return new Promise((resolve, reject) => { - lnd.sendPaymentSync({ payment_request: paymentRequest }, (error, data) => { + lnd.sendPaymentSync({ payment_request: paymentRequest }, meta, (error, data) => { if (error) { reject({ error }) return @@ -26,9 +26,9 @@ export function sendPaymentSync(lnd, { paymentRequest }) { * @param {[type]} paymentRequest [description] * @return {[type]} [description] */ -export function sendPayment(lnd, { paymentRequest }) { +export function sendPayment(lnd, meta, { paymentRequest }) { return new Promise((resolve, reject) => { - lnd.sendPayment({ payment_request: paymentRequest }, (err, data) => { + lnd.sendPayment({ payment_request: paymentRequest }, meta, (err, data) => { if (err) { reject(err) } resolve(data) @@ -42,9 +42,9 @@ export function sendPayment(lnd, { paymentRequest }) { * @param {[type]} payReq [description] * @return {[type]} [description] */ -export function decodePayReq(lnd, { payReq }) { +export function decodePayReq(lnd, meta, { payReq }) { return new Promise((resolve, reject) => { - lnd.decodePayReq({ pay_req: payReq }, (err, data) => { + lnd.decodePayReq({ pay_req: payReq }, meta, (err, data) => { if (err) { reject(err) } resolve(data) @@ -57,9 +57,9 @@ export function decodePayReq(lnd, { payReq }) { * @param {[type]} lnd [description] * @return {[type]} [description] */ -export function listPayments(lnd) { +export function listPayments(lnd, meta) { return new Promise((resolve, reject) => { - lnd.listPayments({}, (err, data) => { + lnd.listPayments({}, meta, (err, data) => { if (err) { reject(err) } resolve(data) @@ -72,9 +72,9 @@ export function listPayments(lnd) { * @param {[type]} lnd [description] * @return {[type]} [description] */ -export function deleteAllPayments(lnd) { +export function deleteAllPayments(lnd, meta) { return new Promise((resolve, reject) => { - lnd.deleteAllPayments({}, (err, data) => { + lnd.deleteAllPayments({}, meta, (err, data) => { if (err) { reject(err) } resolve(data) diff --git a/app/lnd/methods/peersController.js b/app/lnd/methods/peersController.js index 5e557eef..2562901e 100644 --- a/app/lnd/methods/peersController.js +++ b/app/lnd/methods/peersController.js @@ -5,9 +5,9 @@ * @param {[type]} host [description] * @return {[type]} [description] */ -export function connectPeer(lnd, { pubkey, host }) { +export function connectPeer(lnd, meta, { pubkey, host }) { return new Promise((resolve, reject) => { - lnd.connectPeer({ addr: { pubkey, host }, perm: true }, (err, data) => { + lnd.connectPeer({ addr: { pubkey, host }, perm: true }, meta, (err, data) => { if (err) { reject(err) } resolve(data) @@ -22,9 +22,9 @@ export function connectPeer(lnd, { pubkey, host }) { * @param {[type]} pubkey [description] * @return {[type]} [description] */ -export function disconnectPeer(lnd, { pubkey }) { +export function disconnectPeer(lnd, meta, { pubkey }) { return new Promise((resolve, reject) => { - lnd.disconnectPeer({ pub_key: pubkey }, (err, data) => { + lnd.disconnectPeer({ pub_key: pubkey }, meta, (err, data) => { if (err) { reject(err) } resolve(data) @@ -38,9 +38,9 @@ export function disconnectPeer(lnd, { pubkey }) { * @param {[type]} lnd [description] * @return {[type]} [description] */ -export function listPeers(lnd) { +export function listPeers(lnd, meta) { return new Promise((resolve, reject) => { - lnd.listPeers({}, (err, data) => { + lnd.listPeers({}, meta, (err, data) => { if (err) { reject(err) } resolve(data) diff --git a/app/lnd/methods/walletController.js b/app/lnd/methods/walletController.js index a0c47677..d50a674a 100644 --- a/app/lnd/methods/walletController.js +++ b/app/lnd/methods/walletController.js @@ -3,9 +3,9 @@ * @param {[type]} lnd [description] * @return {[type]} [description] */ -export function walletBalance(lnd) { +export function walletBalance(lnd, meta) { return new Promise((resolve, reject) => { - lnd.walletBalance({}, (err, data) => { + lnd.walletBalance({}, meta, (err, data) => { if (err) { reject(err) } resolve(data) @@ -20,9 +20,9 @@ export function walletBalance(lnd) { * @param {[type]} type [description] * @return {[type]} [description] */ -export function newAddress(lnd, type) { +export function newAddress(lnd, meta, type) { return new Promise((resolve, reject) => { - lnd.newAddress({ type }, (err, data) => { + lnd.newAddress({ type }, meta, (err, data) => { if (err) { reject(err) } resolve(data) @@ -35,9 +35,9 @@ export function newAddress(lnd, type) { * @param {[type]} lnd [description] * @return {[type]} [description] */ -export function newWitnessAddress(lnd, { addr }) { +export function newWitnessAddress(lnd, meta, { addr }) { return new Promise((resolve, reject) => { - lnd.newWitnessAddress({ address: addr }, (err, data) => { + lnd.newWitnessAddress({ address: addr }, meta, (err, data) => { if (err) { reject(err) } resolve(data) @@ -51,9 +51,9 @@ export function newWitnessAddress(lnd, { addr }) { * @param {[type]} lnd [description] * @return {[type]} [description] */ -export function getTransactions(lnd) { +export function getTransactions(lnd, meta) { return new Promise((resolve, reject) => { - lnd.getTransactions({}, (err, data) => { + lnd.getTransactions({}, meta, (err, data) => { if (err) { reject(err) } resolve(data) @@ -69,9 +69,9 @@ export function getTransactions(lnd) { * @param {[type]} amount [description] * @return {[type]} [description] */ -export function sendCoins(lnd, { addr, amount }) { +export function sendCoins(lnd, meta, { addr, amount }) { return new Promise((resolve, reject) => { - lnd.sendCoins({ addr, amount }, (err, data) => { + lnd.sendCoins({ addr, amount }, meta, (err, data) => { if (err) { reject(err) } resolve(data) @@ -83,7 +83,7 @@ export function sendCoins(lnd, { addr, amount }) { * Executes a request to set the alias for the node * @param {[type]} new_alias [description] */ -export function setAlias(lnd, { new_alias }) { +export function setAlias(lnd, meta, { new_alias }) { return new Promise((resolve, reject) => { lnd.setAlias({ new_alias }, (err, data) => { if (err) { reject(err) } diff --git a/app/lnd/push/closechannel.js b/app/lnd/push/closechannel.js index a522874f..b1f8e024 100644 --- a/app/lnd/push/closechannel.js +++ b/app/lnd/push/closechannel.js @@ -1,7 +1,7 @@ -export default function pushclosechannel(lnd, event, payload) { +export default function pushclosechannel(lnd, meta, event, payload) { return new Promise((resolve, reject) => { try { - const call = lnd.closeChannel(payload) + const call = lnd.closeChannel(payload, meta) call.on('data', data => event.sender.send('pushclosechannelupdated', { data })) call.on('end', () => event.sender.send('pushclosechannelend')) diff --git a/app/lnd/push/openchannel.js b/app/lnd/push/openchannel.js index 7bf8958a..cfc66d11 100644 --- a/app/lnd/push/openchannel.js +++ b/app/lnd/push/openchannel.js @@ -1,7 +1,7 @@ -export default function pushopenchannel(lnd, event, payload) { +export default function pushopenchannel(lnd, meta, event, payload) { return new Promise((resolve, reject) => { try { - const call = lnd.openChannel(payload) + const call = lnd.openChannel(payload, meta) call.on('data', data => event.sender.send('pushchannelupdated', { data })) call.on('end', () => event.sender.send('pushchannelend')) diff --git a/app/lnd/push/subscribeinvoice.js b/app/lnd/push/subscribeinvoice.js index 610e739d..ce47935e 100644 --- a/app/lnd/push/subscribeinvoice.js +++ b/app/lnd/push/subscribeinvoice.js @@ -1,7 +1,7 @@ -export default function pushinvoices(lnd, event) { +export default function pushinvoices(lnd, meta, event) { return new Promise((resolve, reject) => { try { - const call = lnd.subscribeInvoices({}) + const call = lnd.subscribeInvoices({}, meta) call.on('data', data => event.sender.send('pushinvoicesupdated', { data })) call.on('end', () => event.sender.send('pushinvoicesend')) diff --git a/app/lnd/subscribe/channelgraph.js b/app/lnd/subscribe/channelgraph.js index 666cd3cf..47b1aec7 100644 --- a/app/lnd/subscribe/channelgraph.js +++ b/app/lnd/subscribe/channelgraph.js @@ -1,9 +1,8 @@ -/* eslint-disable */ - -export default function subscribeToChannelGraph(mainWindow, lnd) { +export default function subscribeToChannelGraph(mainWindow, lnd, meta) { console.log('subscribeChannelGraph is happening') - - const call = lnd.subscribeChannelGraph({}) + + + const call = lnd.subscribeChannelGraph({}, meta) call.on('data', channelGraphData => mainWindow.send('channelGraphData', { channelGraphData })) call.on('end', () => console.log('channel graph end')) diff --git a/app/lnd/subscribe/index.js b/app/lnd/subscribe/index.js index 7ad6e1b8..bbf9cb38 100644 --- a/app/lnd/subscribe/index.js +++ b/app/lnd/subscribe/index.js @@ -2,8 +2,8 @@ import subscribeToTransactions from './transactions' import subscribeToInvoices from './invoices' import subscribeToChannelGraph from './channelgraph' -export default (mainWindow, lnd) => { - subscribeToTransactions(mainWindow, lnd) - subscribeToInvoices(mainWindow, lnd) - subscribeToChannelGraph(mainWindow, lnd) +export default (mainWindow, lnd, meta) => { + subscribeToTransactions(mainWindow, lnd, meta) + subscribeToInvoices(mainWindow, lnd, meta) + subscribeToChannelGraph(mainWindow, lnd, meta) } diff --git a/app/lnd/subscribe/invoices.js b/app/lnd/subscribe/invoices.js index 7a1dd101..63e238f8 100644 --- a/app/lnd/subscribe/invoices.js +++ b/app/lnd/subscribe/invoices.js @@ -1,7 +1,7 @@ /* eslint-disable */ -export default function subscribeToInvoices(mainWindow, lnd) { - const call = lnd.subscribeInvoices({}) +export default function subscribeToInvoices(mainWindow, lnd, meta) { + const call = lnd.subscribeInvoices({}, meta) call.on('data', invoice => mainWindow.send('invoiceUpdate', { invoice })) call.on('end', () => console.log('end')) diff --git a/app/lnd/subscribe/transactions.js b/app/lnd/subscribe/transactions.js index 5c3f0091..f1f8b9d7 100644 --- a/app/lnd/subscribe/transactions.js +++ b/app/lnd/subscribe/transactions.js @@ -1,8 +1,7 @@ /* eslint-disable */ -export default function subscribeToTransactions(mainWindow, lnd) { - const call = lnd.subscribeTransactions({}) - +export default function subscribeToTransactions(mainWindow, lnd, metadata) { + const call = lnd.subscribeTransactions({}, metadata) call.on('data', transaction => { console.log('TRANSACTION: ', transaction) mainWindow.send('newTransaction', { transaction })