Browse Source

feature(auth-macaroon): Add macaroon auth support

renovate/lint-staged-8.x
João Almeida 7 years ago
parent
commit
98e005938d
  1. 7
      app/lnd/config/index.js
  2. 11
      app/lnd/index.js
  3. 3
      app/lnd/lib/lightning.js
  4. 24
      app/lnd/methods/channelController.js
  5. 44
      app/lnd/methods/index.js
  6. 20
      app/lnd/methods/invoicesController.js
  7. 20
      app/lnd/methods/networkController.js
  8. 20
      app/lnd/methods/paymentsController.js
  9. 12
      app/lnd/methods/peersController.js
  10. 22
      app/lnd/methods/walletController.js
  11. 4
      app/lnd/push/closechannel.js
  12. 4
      app/lnd/push/openchannel.js
  13. 4
      app/lnd/push/subscribeinvoice.js
  14. 9
      app/lnd/subscribe/channelgraph.js
  15. 8
      app/lnd/subscribe/index.js
  16. 4
      app/lnd/subscribe/invoices.js
  17. 5
      app/lnd/subscribe/transactions.js

7
app/lnd/config/index.js

@ -6,15 +6,19 @@ import { userInfo, platform } from 'os'
import { join } from 'path' import { join } from 'path'
let loc let loc
let macaroonPath
switch (platform()) { switch (platform()) {
case 'darwin': case 'darwin':
loc = 'Library/Application Support/Lnd/tls.cert' loc = 'Library/Application Support/Lnd/tls.cert'
macaroonPath = 'Library/Application Support/Lnd/admin.macaroon'
break break
case 'linux': case 'linux':
loc = '.lnd/tls.cert' loc = '.lnd/tls.cert'
macaroonPath = '.lnd/admin.macaroon'
break break
case 'win32': case 'win32':
loc = join('Appdata', 'Local', 'Lnd', 'tls.cert') loc = join('Appdata', 'Local', 'Lnd', 'tls.cert')
macaroonPath = join('Appdata', 'Local', 'Lnd', 'admin.macaroon')
break break
default: default:
break break
@ -23,5 +27,6 @@ switch (platform()) {
export default { export default {
lightningRpc: `${__dirname}/rpc.proto`, lightningRpc: `${__dirname}/rpc.proto`,
lightningHost: 'localhost:10009', lightningHost: 'localhost:10009',
cert: join(userInfo().homedir, loc) cert: join(userInfo().homedir, loc),
macaroon: join(userInfo().homedir, macaroonPath)
} }

11
app/lnd/index.js

@ -1,13 +1,18 @@
import grpc from 'grpc'
import fs from 'fs'
import config from './config' import config from './config'
import lightning from './lib/lightning' import lightning from './lib/lightning'
import subscribe from './subscribe' import subscribe from './subscribe'
import methods from './methods' import methods from './methods'
export default (callback) => { 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 lnd = lightning(config.lightningRpc, config.lightningHost)
const lndMethods = (event, msg, data) => methods(lnd, event, msg, data)
const lndSubscribe = mainWindow => subscribe(mainWindow, lnd, meta)
const lndMethods = (event, msg, data) => methods(lnd, meta, event, msg, data)
callback(lndSubscribe, lndMethods) callback(lndSubscribe, lndMethods)
} }

3
app/lnd/lib/lightning.js

@ -6,8 +6,7 @@ import config from '../config'
module.exports = (rpcpath, host) => { module.exports = (rpcpath, host) => {
const lndCert = fs.readFileSync(config.cert) const lndCert = fs.readFileSync(config.cert)
const credentials = grpc.credentials.createSsl(lndCert) const credentials = grpc.credentials.createSsl(lndCert)
const rpc = grpc.load(path.join(__dirname, 'rpc.proto')) const rpc = grpc.load(path.join(__dirname, 'rpc.proto'))
return new rpc.lnrpc.Lightning(host, credentials) return new rpc.lnrpc.Lightning(host, credentials)
} }

24
app/lnd/methods/channelController.js

@ -11,7 +11,7 @@ const BufferUtil = bitcore.util.buffer
* @param {[type]} payload [description] * @param {[type]} payload [description]
* @return {[type]} [description] * @return {[type]} [description]
*/ */
export function openChannel(lnd, event, payload) { export function openChannel(lnd, meta, event, payload) {
const { pubkey, localamt, pushamt } = payload const { pubkey, localamt, pushamt } = payload
const res = { const res = {
node_pubkey: BufferUtil.hexToBuffer(pubkey), node_pubkey: BufferUtil.hexToBuffer(pubkey),
@ -20,7 +20,7 @@ export function openChannel(lnd, event, payload) {
} }
return new Promise((resolve, reject) => return new Promise((resolve, reject) =>
pushopenchannel(lnd, event, res) pushopenchannel(lnd, meta, event, res)
.then(data => resolve(data)) .then(data => resolve(data))
.catch(error => reject(error)) .catch(error => reject(error))
) )
@ -32,9 +32,9 @@ export function openChannel(lnd, event, payload) {
* @param {[type]} lnd [description] * @param {[type]} lnd [description]
* @return {[type]} [description] * @return {[type]} [description]
*/ */
export function channelBalance(lnd) { export function channelBalance(lnd, meta) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
lnd.channelBalance({}, (err, data) => { lnd.channelBalance({}, meta, (err, data) => {
if (err) { reject(err) } if (err) { reject(err) }
resolve(data) resolve(data)
@ -48,9 +48,9 @@ export function channelBalance(lnd) {
* @param {[type]} lnd [description] * @param {[type]} lnd [description]
* @return {[type]} [description] * @return {[type]} [description]
*/ */
export function listChannels(lnd) { export function listChannels(lnd, meta) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
lnd.listChannels({}, (err, data) => { lnd.listChannels({}, meta, (err, data) => {
if (err) { reject(err) } if (err) { reject(err) }
resolve(data) resolve(data)
@ -66,7 +66,7 @@ export function listChannels(lnd) {
* @param {[type]} payload [description] * @param {[type]} payload [description]
* @return {[type]} [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 tx = payload.channel_point.funding_txid.match(/.{2}/g).reverse().join('')
const res = { const res = {
channel_point: { channel_point: {
@ -77,7 +77,7 @@ export function closeChannel(lnd, event, payload) {
} }
return new Promise((resolve, reject) => return new Promise((resolve, reject) =>
pushclosechannel(lnd, event, res) pushclosechannel(lnd, meta, event, res)
.then(data => resolve(data)) .then(data => resolve(data))
.catch(error => reject(error)) .catch(error => reject(error))
) )
@ -89,9 +89,9 @@ export function closeChannel(lnd, event, payload) {
* @param {[type]} lnd [description] * @param {[type]} lnd [description]
* @return {[type]} [description] * @return {[type]} [description]
*/ */
export function pendingChannels(lnd) { export function pendingChannels(lnd, meta) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
lnd.pendingChannels({}, (err, data) => { lnd.pendingChannels({}, meta, (err, data) => {
if (err) { reject(err) } if (err) { reject(err) }
resolve(data) resolve(data)
@ -106,9 +106,9 @@ export function pendingChannels(lnd) {
* @param {[type]} channelId [description] * @param {[type]} channelId [description]
* @return {[type]} [description] * @return {[type]} [description]
*/ */
export function getChanInfo(lnd, { chanId }) { export function getChanInfo(lnd, meta, { chanId }) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
lnd.getChanInfo({ chan_id: chanId }, (err, data) => { lnd.getChanInfo({ chan_id: chanId }, meta, (err, data) => {
if (err) { reject(err) } if (err) { reject(err) }
resolve(data) resolve(data)

44
app/lnd/methods/index.js

@ -23,10 +23,10 @@ import * as networkController from './networkController'
// metadata.add('macaroon', macaroonHex) // metadata.add('macaroon', macaroonHex)
export default function (lnd, event, msg, data) { export default function (lnd, meta, event, msg, data) {
switch (msg) { switch (msg) {
case 'info': case 'info':
networkController.getInfo(lnd) networkController.getInfo(lnd, meta)
.then((infoData) => { .then((infoData) => {
event.sender.send('receiveInfo', infoData) event.sender.send('receiveInfo', infoData)
event.sender.send('receiveCryptocurrency', infoData.chains[0]) event.sender.send('receiveCryptocurrency', infoData.chains[0])
@ -34,21 +34,21 @@ export default function (lnd, event, msg, data) {
.catch(() => event.sender.send('infoFailed')) .catch(() => event.sender.send('infoFailed'))
break break
case 'describeNetwork': case 'describeNetwork':
networkController.describeGraph(lnd) networkController.describeGraph(lnd, meta)
.then(networkData => event.sender.send('receiveDescribeNetwork', networkData)) .then(networkData => event.sender.send('receiveDescribeNetwork', networkData))
.catch(error => console.log('describeGraph error: ', error)) .catch(error => console.log('describeGraph error: ', error))
break break
case 'queryRoutes': case 'queryRoutes':
// Data looks like { pubkey: String, amount: Number } // Data looks like { pubkey: String, amount: Number }
networkController.queryRoutes(lnd, data) networkController.queryRoutes(lnd, meta, data)
.then(routes => event.sender.send('receiveQueryRoutes', routes)) .then(routes => event.sender.send('receiveQueryRoutes', routes))
.catch(error => console.log('queryRoutes error: ', error)) .catch(error => console.log('queryRoutes error: ', error))
break break
case 'getInvoiceAndQueryRoutes': case 'getInvoiceAndQueryRoutes':
// Data looks like { pubkey: String, amount: Number } // Data looks like { pubkey: String, amount: Number }
invoicesController.getInvoice(lnd, { pay_req: data.payreq }) invoicesController.getInvoice(lnd, meta, { pay_req: data.payreq })
.then((invoiceData) => { .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) => { .then((routes) => {
event.sender.send('receiveInvoiceAndQueryRoutes', routes) event.sender.send('receiveInvoiceAndQueryRoutes', routes)
}) })
@ -58,26 +58,26 @@ export default function (lnd, event, msg, data) {
break break
case 'newaddress': case 'newaddress':
// Data looks like { address: '' } // Data looks like { address: '' }
walletController.newAddress(lnd, data.type) walletController.newAddress(lnd, meta, data.type)
.then(({ address }) => event.sender.send('receiveAddress', address)) .then(({ address }) => event.sender.send('receiveAddress', address))
.catch(error => console.log('newaddress error: ', error)) .catch(error => console.log('newaddress error: ', error))
break break
case 'setAlias': case 'setAlias':
// Data looks like { new_alias: '' } // Data looks like { new_alias: '' }
walletController.setAlias(lnd, data) walletController.setAlias(lnd, meta, data)
.then(() => event.sender.send('aliasSet')) .then(() => event.sender.send('aliasSet'))
.catch(error => console.log('setAlias error: ', error)) .catch(error => console.log('setAlias error: ', error))
break break
case 'peers': case 'peers':
// Data looks like { peers: [] } // Data looks like { peers: [] }
peersController.listPeers(lnd) peersController.listPeers(lnd, meta)
.then(peersData => event.sender.send('receivePeers', peersData)) .then(peersData => event.sender.send('receivePeers', peersData))
.catch(error => console.log('peers error: ', error)) .catch(error => console.log('peers error: ', error))
break break
case 'channels': case 'channels':
// Data looks like // Data looks like
// [ { channels: [] }, { total_limbo_balance: 0, pending_open_channels: [], pending_closing_channels: [], pending_force_closing_channels: [] } ] // [ { 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 => .then(channelsData =>
event.sender.send('receiveChannels', { channels: channelsData[0].channels, pendingChannels: channelsData[1] }) event.sender.send('receiveChannels', { channels: channelsData[0].channels, pendingChannels: channelsData[1] })
) )
@ -85,31 +85,31 @@ export default function (lnd, event, msg, data) {
break break
case 'transactions': case 'transactions':
// Data looks like { transactions: [] } // Data looks like { transactions: [] }
walletController.getTransactions(lnd) walletController.getTransactions(lnd, meta)
.then(transactionsData => event.sender.send('receiveTransactions', transactionsData)) .then(transactionsData => event.sender.send('receiveTransactions', transactionsData))
.catch(error => console.log('transactions error: ', error)) .catch(error => console.log('transactions error: ', error))
break break
case 'payments': case 'payments':
// Data looks like { payments: [] } // Data looks like { payments: [] }
paymentsController.listPayments(lnd) paymentsController.listPayments(lnd, meta)
.then(paymentsData => event.sender.send('receivePayments', paymentsData)) .then(paymentsData => event.sender.send('receivePayments', paymentsData))
.catch(error => console.log('payments error: ', error)) .catch(error => console.log('payments error: ', error))
break break
case 'invoices': case 'invoices':
// Data looks like { invoices: [] } // Data looks like { invoices: [] }
invoicesController.listInvoices(lnd) invoicesController.listInvoices(lnd, meta)
.then(invoicesData => event.sender.send('receiveInvoices', invoicesData)) .then(invoicesData => event.sender.send('receiveInvoices', invoicesData))
.catch(error => console.log('invoices error: ', error)) .catch(error => console.log('invoices error: ', error))
break break
case 'invoice': case 'invoice':
// Data looks like { invoices: [] } // 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)) .then(invoiceData => event.sender.send('receiveInvoice', invoiceData))
.catch(error => console.log('invoice error: ', error)) .catch(error => console.log('invoice error: ', error))
break break
case 'balance': case 'balance':
// Balance looks like [ { balance: '129477456' }, { balance: '243914' } ] // 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) => { .then((balance) => {
event.sender.send('receiveBalance', { walletBalance: balance[0].total_balance, channelBalance: balance[1].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': case 'createInvoice':
// Invoice looks like { r_hash: Buffer, payment_request: '' } // Invoice looks like { r_hash: Buffer, payment_request: '' }
// { memo, value } = data // { memo, value } = data
invoicesController.addInvoice(lnd, data) invoicesController.addInvoice(lnd, meta, data)
.then(newinvoice => .then(newinvoice =>
event.sender.send( event.sender.send(
'createdInvoice', 'createdInvoice',
@ -138,7 +138,7 @@ export default function (lnd, event, msg, data) {
case 'sendPayment': case 'sendPayment':
// Payment looks like { payment_preimage: Buffer, payment_route: Object } // Payment looks like { payment_preimage: Buffer, payment_route: Object }
// { paymentRequest } = data // { paymentRequest } = data
paymentsController.sendPaymentSync(lnd, data) paymentsController.sendPaymentSync(lnd, meta, data)
.then(({ payment_route }) => { .then(({ payment_route }) => {
console.log('payinvoice success: ', payment_route) console.log('payinvoice success: ', payment_route)
event.sender.send('paymentSuccessful', Object.assign(data, { payment_route })) event.sender.send('paymentSuccessful', Object.assign(data, { payment_route }))
@ -151,7 +151,7 @@ export default function (lnd, event, msg, data) {
case 'sendCoins': case 'sendCoins':
// Transaction looks like { txid: String } // Transaction looks like { txid: String }
// { amount, addr } = data // { 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 })) .then(({ txid }) => event.sender.send('transactionSuccessful', { amount: data.amount, addr: data.addr, txid }))
.catch((error) => { .catch((error) => {
console.log('error: ', error) console.log('error: ', error)
@ -161,7 +161,7 @@ export default function (lnd, event, msg, data) {
case 'openChannel': case 'openChannel':
// Response is empty. Streaming updates on channel status and updates // Response is empty. Streaming updates on channel status and updates
// { pubkey, localamt, pushamt } = data // { pubkey, localamt, pushamt } = data
channelController.openChannel(lnd, event, data) channelController.openChannel(lnd, meta, event, data)
.then((channel) => { .then((channel) => {
console.log('CHANNEL: ', channel) console.log('CHANNEL: ', channel)
event.sender.send('channelSuccessful', { channel }) event.sender.send('channelSuccessful', { channel })
@ -171,7 +171,7 @@ export default function (lnd, event, msg, data) {
case 'closeChannel': case 'closeChannel':
// Response is empty. Streaming updates on channel status and updates // Response is empty. Streaming updates on channel status and updates
// { channel_point, force } = data // { channel_point, force } = data
channelController.closeChannel(lnd, event, data) channelController.closeChannel(lnd, meta, event, data)
.then((result) => { .then((result) => {
console.log('CLOSE CHANNEL: ', result) console.log('CLOSE CHANNEL: ', result)
event.sender.send('closeChannelSuccessful') event.sender.send('closeChannelSuccessful')
@ -181,7 +181,7 @@ export default function (lnd, event, msg, data) {
case 'connectPeer': case 'connectPeer':
// Returns a peer_id. Pass the pubkey, host and peer_id so we can add a new peer to the list // Returns a peer_id. Pass the pubkey, host and peer_id so we can add a new peer to the list
// { pubkey, host } = data // { pubkey, host } = data
peersController.connectPeer(lnd, data) peersController.connectPeer(lnd, meta, data)
.then(({ peer_id }) => { .then(({ peer_id }) => {
console.log('peer_id: ', peer_id) console.log('peer_id: ', peer_id)
event.sender.send('connectSuccess', { pub_key: data.pubkey, address: data.host, 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': case 'disconnectPeer':
// Empty response. Pass back pubkey on success to remove it from the peers list // Empty response. Pass back pubkey on success to remove it from the peers list
// { pubkey } = data // { pubkey } = data
peersController.disconnectPeer(lnd, data) peersController.disconnectPeer(lnd, meta, data)
.then(() => { .then(() => {
console.log('pubkey: ', data.pubkey) console.log('pubkey: ', data.pubkey)
event.sender.send('disconnectSuccess', { pubkey: data.pubkey }) event.sender.send('disconnectSuccess', { pubkey: data.pubkey })

20
app/lnd/methods/invoicesController.js

@ -7,9 +7,9 @@ import pushinvoices from '../push/subscribeinvoice'
* @param value [description] * @param value [description]
* @return [description] * @return [description]
*/ */
export function addInvoice(lnd, { memo, value }) { export function addInvoice(lnd, meta, { memo, value }) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
lnd.addInvoice({ memo, value }, (err, data) => { lnd.addInvoice({ memo, value }, meta, (err, data) => {
if (err) { reject(err) } if (err) { reject(err) }
resolve(data) resolve(data)
@ -22,9 +22,9 @@ export function addInvoice(lnd, { memo, value }) {
* @param {[type]} lnd [description] * @param {[type]} lnd [description]
* @return {[type]} [description] * @return {[type]} [description]
*/ */
export function listInvoices(lnd) { export function listInvoices(lnd, meta) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
lnd.listInvoices({}, (err, data) => { lnd.listInvoices({}, meta, (err, data) => {
if (err) { reject(err) } if (err) { reject(err) }
resolve(data) resolve(data)
@ -36,9 +36,9 @@ export function listInvoices(lnd) {
* @param {[type]} payreq [description] * @param {[type]} payreq [description]
* @return {[type]} [description] * @return {[type]} [description]
*/ */
export function getInvoice(lnd, { pay_req }) { export function getInvoice(lnd, meta, { pay_req }) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
lnd.decodePayReq({ pay_req }, (err, data) => { lnd.decodePayReq({ pay_req }, meta, (err, data) => {
if (err) { reject(err) } if (err) { reject(err) }
resolve(data) resolve(data)
@ -53,9 +53,9 @@ export function getInvoice(lnd, { pay_req }) {
* @param {[type]} rhash [description] * @param {[type]} rhash [description]
* @return {[type]} [description] * @return {[type]} [description]
*/ */
export function lookupInvoice(lnd, { rhash }) { export function lookupInvoice(lnd, meta, { rhash }) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
lnd.lookupInvoice({ r_hash: rhash }, (err, data) => { lnd.lookupInvoice({ r_hash: rhash }, meta, (err, data) => {
if (err) { reject(err) } if (err) { reject(err) }
resolve(data) resolve(data)
@ -70,9 +70,9 @@ export function lookupInvoice(lnd, { rhash }) {
* @param {[type]} event [description] * @param {[type]} event [description]
* @return {[type]} [description] * @return {[type]} [description]
*/ */
export function subscribeInvoices(lnd, event) { export function subscribeInvoices(lnd, meta, event) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
pushinvoices(lnd, event) pushinvoices(lnd, meta, event)
.then(data => resolve(data)) .then(data => resolve(data))
.catch(error => reject(error)) .catch(error => reject(error))
}) })

20
app/lnd/methods/networkController.js

@ -3,9 +3,9 @@
* @param {[type]} lnd [description] * @param {[type]} lnd [description]
* @return {[type]} [description] * @return {[type]} [description]
*/ */
export function getInfo(lnd) { export function getInfo(lnd, meta) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
lnd.getInfo({}, (err, data) => { lnd.getInfo({}, meta, (err, data) => {
if (err) { reject(err) } if (err) { reject(err) }
resolve(data) resolve(data)
@ -20,9 +20,9 @@ export function getInfo(lnd) {
* @param {[type]} pubkey [description] * @param {[type]} pubkey [description]
* @return {[type]} [description] * @return {[type]} [description]
*/ */
export function getNodeInfo(lnd, { pubkey }) { export function getNodeInfo(lnd, meta, { pubkey }) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
lnd.getNodeInfo({ pub_key: pubkey }, (err, data) => { lnd.getNodeInfo({ pub_key: pubkey }, meta, (err, data) => {
if (err) { reject(err) } if (err) { reject(err) }
resolve(data) resolve(data)
@ -36,9 +36,9 @@ export function getNodeInfo(lnd, { pubkey }) {
* @param {[type]} lnd [description] * @param {[type]} lnd [description]
* @return {[type]} [description] * @return {[type]} [description]
*/ */
export function describeGraph(lnd) { export function describeGraph(lnd, meta) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
lnd.describeGraph({}, (err, data) => { lnd.describeGraph({}, meta, (err, data) => {
if (err) { reject(err) } if (err) { reject(err) }
resolve(data) resolve(data)
@ -54,9 +54,9 @@ export function describeGraph(lnd) {
* @param {[type]} amount [description] * @param {[type]} amount [description]
* @return {[type]} [description] * @return {[type]} [description]
*/ */
export function queryRoutes(lnd, { pubkey, amount }) { export function queryRoutes(lnd, meta, { pubkey, amount }) {
return new Promise((resolve, reject) => { 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) } if (err) { reject(err) }
resolve(data) resolve(data)
@ -70,9 +70,9 @@ export function queryRoutes(lnd, { pubkey, amount }) {
* @param {[type]} lnd [description] * @param {[type]} lnd [description]
* @return {[type]} [description] * @return {[type]} [description]
*/ */
export function getNetworkInfo(lnd) { export function getNetworkInfo(lnd, meta) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
lnd.getNetworkInfo({}, (err, data) => { lnd.getNetworkInfo({}, meta, (err, data) => {
if (err) { reject(err) } if (err) { reject(err) }
resolve(data) resolve(data)

20
app/lnd/methods/paymentsController.js

@ -4,9 +4,9 @@
* @param {[type]} paymentRequest [description] * @param {[type]} paymentRequest [description]
* @return {[type]} [description] * @return {[type]} [description]
*/ */
export function sendPaymentSync(lnd, { paymentRequest }) { export function sendPaymentSync(lnd, meta, { paymentRequest }) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
lnd.sendPaymentSync({ payment_request: paymentRequest }, (error, data) => { lnd.sendPaymentSync({ payment_request: paymentRequest }, meta, (error, data) => {
if (error) { if (error) {
reject({ error }) reject({ error })
return return
@ -26,9 +26,9 @@ export function sendPaymentSync(lnd, { paymentRequest }) {
* @param {[type]} paymentRequest [description] * @param {[type]} paymentRequest [description]
* @return {[type]} [description] * @return {[type]} [description]
*/ */
export function sendPayment(lnd, { paymentRequest }) { export function sendPayment(lnd, meta, { paymentRequest }) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
lnd.sendPayment({ payment_request: paymentRequest }, (err, data) => { lnd.sendPayment({ payment_request: paymentRequest }, meta, (err, data) => {
if (err) { reject(err) } if (err) { reject(err) }
resolve(data) resolve(data)
@ -42,9 +42,9 @@ export function sendPayment(lnd, { paymentRequest }) {
* @param {[type]} payReq [description] * @param {[type]} payReq [description]
* @return {[type]} [description] * @return {[type]} [description]
*/ */
export function decodePayReq(lnd, { payReq }) { export function decodePayReq(lnd, meta, { payReq }) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
lnd.decodePayReq({ pay_req: payReq }, (err, data) => { lnd.decodePayReq({ pay_req: payReq }, meta, (err, data) => {
if (err) { reject(err) } if (err) { reject(err) }
resolve(data) resolve(data)
@ -57,9 +57,9 @@ export function decodePayReq(lnd, { payReq }) {
* @param {[type]} lnd [description] * @param {[type]} lnd [description]
* @return {[type]} [description] * @return {[type]} [description]
*/ */
export function listPayments(lnd) { export function listPayments(lnd, meta) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
lnd.listPayments({}, (err, data) => { lnd.listPayments({}, meta, (err, data) => {
if (err) { reject(err) } if (err) { reject(err) }
resolve(data) resolve(data)
@ -72,9 +72,9 @@ export function listPayments(lnd) {
* @param {[type]} lnd [description] * @param {[type]} lnd [description]
* @return {[type]} [description] * @return {[type]} [description]
*/ */
export function deleteAllPayments(lnd) { export function deleteAllPayments(lnd, meta) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
lnd.deleteAllPayments({}, (err, data) => { lnd.deleteAllPayments({}, meta, (err, data) => {
if (err) { reject(err) } if (err) { reject(err) }
resolve(data) resolve(data)

12
app/lnd/methods/peersController.js

@ -5,9 +5,9 @@
* @param {[type]} host [description] * @param {[type]} host [description]
* @return {[type]} [description] * @return {[type]} [description]
*/ */
export function connectPeer(lnd, { pubkey, host }) { export function connectPeer(lnd, meta, { pubkey, host }) {
return new Promise((resolve, reject) => { 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) } if (err) { reject(err) }
resolve(data) resolve(data)
@ -22,9 +22,9 @@ export function connectPeer(lnd, { pubkey, host }) {
* @param {[type]} pubkey [description] * @param {[type]} pubkey [description]
* @return {[type]} [description] * @return {[type]} [description]
*/ */
export function disconnectPeer(lnd, { pubkey }) { export function disconnectPeer(lnd, meta, { pubkey }) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
lnd.disconnectPeer({ pub_key: pubkey }, (err, data) => { lnd.disconnectPeer({ pub_key: pubkey }, meta, (err, data) => {
if (err) { reject(err) } if (err) { reject(err) }
resolve(data) resolve(data)
@ -38,9 +38,9 @@ export function disconnectPeer(lnd, { pubkey }) {
* @param {[type]} lnd [description] * @param {[type]} lnd [description]
* @return {[type]} [description] * @return {[type]} [description]
*/ */
export function listPeers(lnd) { export function listPeers(lnd, meta) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
lnd.listPeers({}, (err, data) => { lnd.listPeers({}, meta, (err, data) => {
if (err) { reject(err) } if (err) { reject(err) }
resolve(data) resolve(data)

22
app/lnd/methods/walletController.js

@ -3,9 +3,9 @@
* @param {[type]} lnd [description] * @param {[type]} lnd [description]
* @return {[type]} [description] * @return {[type]} [description]
*/ */
export function walletBalance(lnd) { export function walletBalance(lnd, meta) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
lnd.walletBalance({}, (err, data) => { lnd.walletBalance({}, meta, (err, data) => {
if (err) { reject(err) } if (err) { reject(err) }
resolve(data) resolve(data)
@ -20,9 +20,9 @@ export function walletBalance(lnd) {
* @param {[type]} type [description] * @param {[type]} type [description]
* @return {[type]} [description] * @return {[type]} [description]
*/ */
export function newAddress(lnd, type) { export function newAddress(lnd, meta, type) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
lnd.newAddress({ type }, (err, data) => { lnd.newAddress({ type }, meta, (err, data) => {
if (err) { reject(err) } if (err) { reject(err) }
resolve(data) resolve(data)
@ -35,9 +35,9 @@ export function newAddress(lnd, type) {
* @param {[type]} lnd [description] * @param {[type]} lnd [description]
* @return {[type]} [description] * @return {[type]} [description]
*/ */
export function newWitnessAddress(lnd, { addr }) { export function newWitnessAddress(lnd, meta, { addr }) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
lnd.newWitnessAddress({ address: addr }, (err, data) => { lnd.newWitnessAddress({ address: addr }, meta, (err, data) => {
if (err) { reject(err) } if (err) { reject(err) }
resolve(data) resolve(data)
@ -51,9 +51,9 @@ export function newWitnessAddress(lnd, { addr }) {
* @param {[type]} lnd [description] * @param {[type]} lnd [description]
* @return {[type]} [description] * @return {[type]} [description]
*/ */
export function getTransactions(lnd) { export function getTransactions(lnd, meta) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
lnd.getTransactions({}, (err, data) => { lnd.getTransactions({}, meta, (err, data) => {
if (err) { reject(err) } if (err) { reject(err) }
resolve(data) resolve(data)
@ -69,9 +69,9 @@ export function getTransactions(lnd) {
* @param {[type]} amount [description] * @param {[type]} amount [description]
* @return {[type]} [description] * @return {[type]} [description]
*/ */
export function sendCoins(lnd, { addr, amount }) { export function sendCoins(lnd, meta, { addr, amount }) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
lnd.sendCoins({ addr, amount }, (err, data) => { lnd.sendCoins({ addr, amount }, meta, (err, data) => {
if (err) { reject(err) } if (err) { reject(err) }
resolve(data) resolve(data)
@ -83,7 +83,7 @@ export function sendCoins(lnd, { addr, amount }) {
* Executes a request to set the alias for the node * Executes a request to set the alias for the node
* @param {[type]} new_alias [description] * @param {[type]} new_alias [description]
*/ */
export function setAlias(lnd, { new_alias }) { export function setAlias(lnd, meta, { new_alias }) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
lnd.setAlias({ new_alias }, (err, data) => { lnd.setAlias({ new_alias }, (err, data) => {
if (err) { reject(err) } if (err) { reject(err) }

4
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) => { return new Promise((resolve, reject) => {
try { try {
const call = lnd.closeChannel(payload) const call = lnd.closeChannel(payload, meta)
call.on('data', data => event.sender.send('pushclosechannelupdated', { data })) call.on('data', data => event.sender.send('pushclosechannelupdated', { data }))
call.on('end', () => event.sender.send('pushclosechannelend')) call.on('end', () => event.sender.send('pushclosechannelend'))

4
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) => { return new Promise((resolve, reject) => {
try { try {
const call = lnd.openChannel(payload) const call = lnd.openChannel(payload, meta)
call.on('data', data => event.sender.send('pushchannelupdated', { data })) call.on('data', data => event.sender.send('pushchannelupdated', { data }))
call.on('end', () => event.sender.send('pushchannelend')) call.on('end', () => event.sender.send('pushchannelend'))

4
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) => { return new Promise((resolve, reject) => {
try { try {
const call = lnd.subscribeInvoices({}) const call = lnd.subscribeInvoices({}, meta)
call.on('data', data => event.sender.send('pushinvoicesupdated', { data })) call.on('data', data => event.sender.send('pushinvoicesupdated', { data }))
call.on('end', () => event.sender.send('pushinvoicesend')) call.on('end', () => event.sender.send('pushinvoicesend'))

9
app/lnd/subscribe/channelgraph.js

@ -1,9 +1,8 @@
/* eslint-disable */ export default function subscribeToChannelGraph(mainWindow, lnd, meta) {
export default function subscribeToChannelGraph(mainWindow, lnd) {
console.log('subscribeChannelGraph is happening') console.log('subscribeChannelGraph is happening')
const call = lnd.subscribeChannelGraph({})
const call = lnd.subscribeChannelGraph({}, meta)
call.on('data', channelGraphData => mainWindow.send('channelGraphData', { channelGraphData })) call.on('data', channelGraphData => mainWindow.send('channelGraphData', { channelGraphData }))
call.on('end', () => console.log('channel graph end')) call.on('end', () => console.log('channel graph end'))

8
app/lnd/subscribe/index.js

@ -2,8 +2,8 @@ import subscribeToTransactions from './transactions'
import subscribeToInvoices from './invoices' import subscribeToInvoices from './invoices'
import subscribeToChannelGraph from './channelgraph' import subscribeToChannelGraph from './channelgraph'
export default (mainWindow, lnd) => { export default (mainWindow, lnd, meta) => {
subscribeToTransactions(mainWindow, lnd) subscribeToTransactions(mainWindow, lnd, meta)
subscribeToInvoices(mainWindow, lnd) subscribeToInvoices(mainWindow, lnd, meta)
subscribeToChannelGraph(mainWindow, lnd) subscribeToChannelGraph(mainWindow, lnd, meta)
} }

4
app/lnd/subscribe/invoices.js

@ -1,7 +1,7 @@
/* eslint-disable */ /* eslint-disable */
export default function subscribeToInvoices(mainWindow, lnd) { export default function subscribeToInvoices(mainWindow, lnd, meta) {
const call = lnd.subscribeInvoices({}) const call = lnd.subscribeInvoices({}, meta)
call.on('data', invoice => mainWindow.send('invoiceUpdate', { invoice })) call.on('data', invoice => mainWindow.send('invoiceUpdate', { invoice }))
call.on('end', () => console.log('end')) call.on('end', () => console.log('end'))

5
app/lnd/subscribe/transactions.js

@ -1,8 +1,7 @@
/* eslint-disable */ /* eslint-disable */
export default function subscribeToTransactions(mainWindow, lnd) { export default function subscribeToTransactions(mainWindow, lnd, metadata) {
const call = lnd.subscribeTransactions({}) const call = lnd.subscribeTransactions({}, metadata)
call.on('data', transaction => { call.on('data', transaction => {
console.log('TRANSACTION: ', transaction) console.log('TRANSACTION: ', transaction)
mainWindow.send('newTransaction', { transaction }) mainWindow.send('newTransaction', { transaction })

Loading…
Cancel
Save