|
|
@ -1,4 +1,3 @@ |
|
|
|
import allchannels from './allchannels' |
|
|
|
import channelbalance from './channelbalance' |
|
|
|
import channels from './channels' |
|
|
|
import connectpeer from './connectpeer' |
|
|
@ -14,41 +13,44 @@ import peers from './peers' |
|
|
|
import pendingchannels from './pendingchannels' |
|
|
|
import walletbalance from './walletbalance' |
|
|
|
|
|
|
|
export default function(lnd, event, msg, data) { |
|
|
|
switch(msg) { |
|
|
|
export default function (lnd, event, msg, data) { |
|
|
|
switch (msg) { |
|
|
|
case 'info': |
|
|
|
info(lnd) |
|
|
|
.then(info =>event.sender.send('receiveInfo', info)) |
|
|
|
.then(infoData => event.sender.send('receiveInfo', infoData)) |
|
|
|
.catch(error => console.log('info error: ', error)) |
|
|
|
break |
|
|
|
case 'peers': |
|
|
|
// Data looks like { peers: [] }
|
|
|
|
peers(lnd) |
|
|
|
.then(peers => event.sender.send('receivePeers', peers)) |
|
|
|
.then(peersData => event.sender.send('receivePeers', peersData)) |
|
|
|
.catch(error => console.log('peers error: ', error)) |
|
|
|
break |
|
|
|
case 'channels': |
|
|
|
// Data looks like [ { channels: [channel, channel, channel] }, { total_limbo_balance: 0, pending_open_channels: [], pending_closing_channels: [], pending_force_closing_channels: [] } ]
|
|
|
|
// Data looks like
|
|
|
|
// [ { channels: [] }, { total_limbo_balance: 0, pending_open_channels: [], pending_closing_channels: [], pending_force_closing_channels: [] } ]
|
|
|
|
Promise.all([channels, pendingchannels].map(func => func(lnd))) |
|
|
|
.then(data => event.sender.send('receiveChannels', { channels: data[0].channels, pendingChannels: data[1] })) |
|
|
|
.then(channelsData => |
|
|
|
event.sender.send('receiveChannels', { channels: channelsData[0].channels, pendingChannels: channelsData[1] }) |
|
|
|
) |
|
|
|
.catch(error => console.log('channels error: ', error)) |
|
|
|
break |
|
|
|
case 'payments': |
|
|
|
// Data looks like { payments: [] }
|
|
|
|
payments(lnd) |
|
|
|
.then(payments => event.sender.send('receivePayments', payments)) |
|
|
|
.then(paymentsData => event.sender.send('receivePayments', paymentsData)) |
|
|
|
.catch(error => console.log('payments error: ', error)) |
|
|
|
break |
|
|
|
case 'invoices': |
|
|
|
// Data looks like { invoices: [] }
|
|
|
|
invoices(lnd) |
|
|
|
.then(invoices => event.sender.send('receiveInvoices', invoices)) |
|
|
|
.then(invoicesData => event.sender.send('receiveInvoices', invoicesData)) |
|
|
|
.catch(error => console.log('invoices error: ', error)) |
|
|
|
break |
|
|
|
case 'invoice': |
|
|
|
// Data looks like { invoices: [] }
|
|
|
|
invoice(data.payreq) |
|
|
|
.then(invoice => event.sender.send('receiveInvoice', invoice)) |
|
|
|
.then(invoiceData => event.sender.send('receiveInvoice', invoiceData)) |
|
|
|
.catch(error => console.log('invoice error: ', error)) |
|
|
|
break |
|
|
|
case 'balance': |
|
|
@ -61,7 +63,12 @@ export default function(lnd, event, msg, data) { |
|
|
|
// Invoice looks like { r_hash: Buffer, payment_request: '' }
|
|
|
|
// { memo, value } = data
|
|
|
|
createinvoice(lnd, data) |
|
|
|
.then(invoice => event.sender.send('createdInvoice', Object.assign(invoice, { memo: data.memo, value: data.value, r_hash: new Buffer(invoice.r_hash,'hex').toString('hex') }))) |
|
|
|
.then(newinvoice => |
|
|
|
event.sender.send( |
|
|
|
'createdInvoice', |
|
|
|
Object.assign(newinvoice, { memo: data.memo, value: data.value, r_hash: new Buffer(newinvoice.r_hash, 'hex').toString('hex') }) |
|
|
|
) |
|
|
|
) |
|
|
|
.catch(error => console.log('createInvoice error: ', error)) |
|
|
|
break |
|
|
|
case 'sendPayment': |
|
|
@ -75,7 +82,7 @@ export default function(lnd, event, msg, data) { |
|
|
|
// Response is empty. Streaming updates on channel status and updates
|
|
|
|
// { pubkey, localamt, pushamt } = data
|
|
|
|
openchannel(lnd, event, data) |
|
|
|
.then(channel => { |
|
|
|
.then((channel) => { |
|
|
|
console.log('CHANNEL: ', channel) |
|
|
|
event.sender.send('channelSuccessful', { channel }) |
|
|
|
}) |
|
|
@ -102,6 +109,5 @@ export default function(lnd, event, msg, data) { |
|
|
|
.catch(error => console.log('disconnectPeer error: ', error)) |
|
|
|
break |
|
|
|
default: |
|
|
|
return |
|
|
|
} |
|
|
|
} |