Browse Source

chore(flow): add flowtype to Lightning class

renovate/lint-staged-8.x
Tom Kirkpatrick 6 years ago
parent
commit
0ecb169e5c
No known key found for this signature in database GPG Key ID: 72203A8EC5967EA8
  1. 21
      app/lib/lnd/lightning.js

21
app/lib/lnd/lightning.js

@ -1,5 +1,9 @@
// @flow
import grpc from 'grpc' import grpc from 'grpc'
import { loadSync } from '@grpc/proto-loader' import { loadSync } from '@grpc/proto-loader'
import { BrowserWindow } from 'electron'
import LndConfig from './config'
import { getDeadline, validateHost, createSslCreds, createMacaroonCreds } from './util' import { getDeadline, validateHost, createSslCreds, createMacaroonCreds } from './util'
import methods from './methods' import methods from './methods'
import { mainLog } from '../utils/log' import { mainLog } from '../utils/log'
@ -7,11 +11,22 @@ import subscribeToTransactions from './subscribe/transactions'
import subscribeToInvoices from './subscribe/invoices' import subscribeToInvoices from './subscribe/invoices'
import subscribeToChannelGraph from './subscribe/channelgraph' import subscribeToChannelGraph from './subscribe/channelgraph'
// Type definition for subscriptions property.
type LightningSubscriptionsType = {
channelGraph: any,
invoices: any,
transactions: any
}
/** /**
* Creates an LND grpc client lightning service. * Creates an LND grpc client lightning service.
* @returns {Lightning} * @returns {Lightning}
*/ */
class Lightning { class Lightning {
mainWindow: BrowserWindow
lnd: any
subscriptions: LightningSubscriptionsType
constructor() { constructor() {
this.mainWindow = null this.mainWindow = null
this.lnd = null this.lnd = null
@ -26,7 +41,7 @@ class Lightning {
* Connect to the gRPC interface and verify it is functional. * Connect to the gRPC interface and verify it is functional.
* @return {Promise<rpc.lnrpc.Lightning>} * @return {Promise<rpc.lnrpc.Lightning>}
*/ */
async connect(lndConfig) { async connect(lndConfig: LndConfig) {
const { rpcProtoPath, host, cert, macaroon } = lndConfig const { rpcProtoPath, host, cert, macaroon } = lndConfig
// Verify that the host is valid before creating a gRPC client that is connected to it. // Verify that the host is valid before creating a gRPC client that is connected to it.
@ -80,14 +95,14 @@ class Lightning {
/** /**
* Hook up lnd restful methods. * Hook up lnd restful methods.
*/ */
lndMethods(event, msg, data) { lndMethods(event: Event, msg: string, data: any) {
return methods(this.lnd, mainLog, event, msg, data) return methods(this.lnd, mainLog, event, msg, data)
} }
/** /**
* Subscribe to all bi-directional streams. * Subscribe to all bi-directional streams.
*/ */
subscribe(mainWindow) { subscribe(mainWindow: BrowserWindow) {
this.mainWindow = mainWindow this.mainWindow = mainWindow
this.subscriptions.channelGraph = subscribeToChannelGraph.call(this) this.subscriptions.channelGraph = subscribeToChannelGraph.call(this)

Loading…
Cancel
Save