|
|
@ -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 }) |
|
|
|