|
|
@ -4,7 +4,7 @@ import grpc from 'grpc' |
|
|
|
import { loadSync } from '@grpc/proto-loader' |
|
|
|
import StateMachine from 'javascript-state-machine' |
|
|
|
import LndConfig from './config' |
|
|
|
import { getDeadline, validateHost, createSslCreds, createMacaroonCreds } from './util' |
|
|
|
import { getDeadline, validateHost, createSslCreds } from './util' |
|
|
|
import methods from './walletUnlockerMethods' |
|
|
|
import { mainLog } from '../utils/log' |
|
|
|
|
|
|
@ -43,7 +43,7 @@ class WalletUnlocker { |
|
|
|
*/ |
|
|
|
async onBeforeConnect() { |
|
|
|
mainLog.info('Connecting to WalletUnlocker gRPC service') |
|
|
|
const { rpcProtoPath, host, cert, macaroon } = this.lndConfig |
|
|
|
const { rpcProtoPath, host, cert } = this.lndConfig |
|
|
|
|
|
|
|
// Verify that the host is valid before creating a gRPC client that is connected to it.
|
|
|
|
return await validateHost(host).then(async () => { |
|
|
@ -62,19 +62,15 @@ class WalletUnlocker { |
|
|
|
// Load gRPC package definition as a gRPC object hierarchy.
|
|
|
|
const rpc = grpc.loadPackageDefinition(packageDefinition) |
|
|
|
|
|
|
|
// Create ssl and macaroon credentials to use with the gRPC client.
|
|
|
|
const [sslCreds, macaroonCreds] = await Promise.all([ |
|
|
|
createSslCreds(cert), |
|
|
|
createMacaroonCreds(macaroon) |
|
|
|
]) |
|
|
|
const credentials = grpc.credentials.combineChannelCredentials(sslCreds, macaroonCreds) |
|
|
|
// Create ssl credentials to use with the gRPC client.
|
|
|
|
const sslCreds = await createSslCreds(cert) |
|
|
|
|
|
|
|
// Create a new gRPC client instance.
|
|
|
|
this.service = new rpc.lnrpc.WalletUnlocker(host, credentials) |
|
|
|
this.service = new rpc.lnrpc.WalletUnlocker(host, sslCreds) |
|
|
|
|
|
|
|
// Wait for the gRPC connection to be established.
|
|
|
|
return new Promise((resolve, reject) => { |
|
|
|
this.service.waitForReady(getDeadline(5), err => { |
|
|
|
this.service.waitForReady(getDeadline(10), err => { |
|
|
|
if (err) { |
|
|
|
this.service.close() |
|
|
|
return reject(err) |
|
|
|