@ -18,10 +18,11 @@ import * as networkController from './networkController'
// TODO - SendPayment
// TODO - SendPayment
// TODO - DeleteAllPayments
// TODO - DeleteAllPayments
export default function ( lnd , meta , event , msg , data ) {
export default function ( lnd , event , msg , data ) {
switch ( msg ) {
switch ( msg ) {
case 'info' :
case 'info' :
networkController . getInfo ( lnd , meta )
networkController
. getInfo ( lnd )
. 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 ] )
@ -30,21 +31,24 @@ export default function (lnd, meta, event, msg, data) {
. catch ( ( ) => event . sender . send ( 'infoFailed' ) )
. catch ( ( ) => event . sender . send ( 'infoFailed' ) )
break
break
case 'describeNetwork' :
case 'describeNetwork' :
networkController . describeGraph ( lnd , meta )
networkController
. describeGraph ( lnd )
. 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 , meta , data )
networkController
. queryRoutes ( lnd , 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 , meta , { pay_req : data . payreq } )
invoicesController
. getInvoice ( lnd , { pay_req : data . payreq } )
. then ( invoiceData =>
. then ( invoiceData =>
networkController . queryRoutes ( lnd , meta , {
networkController . queryRoutes ( lnd , {
pubkey : invoiceData . destination ,
pubkey : invoiceData . destination ,
amount : invoiceData . num_satoshis
amount : invoiceData . num_satoshis
} ) )
} ) )
@ -53,57 +57,63 @@ export default function (lnd, meta, event, msg, data) {
break
break
case 'newaddress' :
case 'newaddress' :
// Data looks like { address: '' }
// Data looks like { address: '' }
walletController . newAddress ( lnd , meta , data . type )
walletController
. newAddress ( lnd , 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 , meta , data )
walletController
. setAlias ( lnd , 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 , meta )
peersController
. listPeers ( lnd )
. 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 , meta ) ) )
Promise . all ( [ channelController . listChannels , channelController . pendingChannels ] . map ( func => func ( lnd ) ) )
. 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 ] } ) )
. catch ( error => console . log ( 'channels error: ' , error ) )
. catch ( error => console . log ( 'channels error: ' , error ) )
break
break
case 'transactions' :
case 'transactions' :
// Data looks like { transactions: [] }
// Data looks like { transactions: [] }
walletController . getTransactions ( lnd , meta )
walletController
. getTransactions ( lnd )
. 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 , meta )
paymentsController
. listPayments ( lnd )
. 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 , meta )
invoicesController
. listInvoices ( lnd )
. 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 , meta , { pay_req : data . payreq } )
invoicesController
. getInvoice ( lnd , { 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 , meta ) ) )
Promise . all ( [ walletController . walletBalance , channelController . channelBalance ] . map ( func => func ( lnd ) ) )
. 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 } )
return balance
return balance
@ -113,7 +123,8 @@ export default function (lnd, meta, 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 , meta , data )
invoicesController
. addInvoice ( lnd , data )
. then ( newinvoice =>
. then ( newinvoice =>
event . sender . send (
event . sender . send (
'createdInvoice' ,
'createdInvoice' ,
@ -132,7 +143,8 @@ export default function (lnd, meta, 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 , meta , data )
paymentsController
. sendPaymentSync ( lnd , data )
. then ( ( payment ) => {
. then ( ( payment ) => {
const { payment_route } = payment
const { payment_route } = payment
console . log ( 'payinvoice success: ' , payment_route )
console . log ( 'payinvoice success: ' , payment_route )
@ -147,7 +159,8 @@ export default function (lnd, meta, 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 , meta , data )
walletController
. sendCoins ( lnd , 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 )
@ -157,7 +170,8 @@ export default function (lnd, meta, 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 , meta , event , data )
channelController
. openChannel ( lnd , event , data )
. then ( ( channel ) => {
. then ( ( channel ) => {
console . log ( 'CHANNEL: ' , channel )
console . log ( 'CHANNEL: ' , channel )
event . sender . send ( 'channelSuccessful' , { channel } )
event . sender . send ( 'channelSuccessful' , { channel } )
@ -168,7 +182,8 @@ export default function (lnd, meta, 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 , meta , event , data )
channelController
. closeChannel ( lnd , event , data )
. then ( ( result ) => {
. then ( ( result ) => {
console . log ( 'CLOSE CHANNEL: ' , result )
console . log ( 'CLOSE CHANNEL: ' , result )
event . sender . send ( 'closeChannelSuccessful' )
event . sender . send ( 'closeChannelSuccessful' )
@ -179,7 +194,8 @@ export default function (lnd, meta, 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 , meta , data )
peersController
. connectPeer ( lnd , data )
. then ( ( peer ) => {
. then ( ( peer ) => {
const { peer_id } = peer
const { peer_id } = peer
console . log ( 'peer_id: ' , peer_id )
console . log ( 'peer_id: ' , peer_id )
@ -194,7 +210,8 @@ export default function (lnd, meta, 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 , meta , data )
peersController
. disconnectPeer ( lnd , 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 } )
@ -205,7 +222,8 @@ export default function (lnd, meta, event, msg, data) {
case 'connectAndOpen' :
case 'connectAndOpen' :
// Connects to a peer if we aren't connected already and then attempt to open a channel
// Connects to a peer if we aren't connected already and then attempt to open a channel
// {} = data
// {} = data
channelController . connectAndOpen ( lnd , meta , event , data )
channelController
. connectAndOpen ( lnd , event , data )
. then ( ( channelData ) => {
. then ( ( channelData ) => {
console . log ( 'connectAndOpen data: ' , channelData )
console . log ( 'connectAndOpen data: ' , channelData )
// 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 })