1+ import * as grpc from '@grpc/grpc-js' ;
12import fs from 'fs' ;
2- import grpc , { status } from 'grpc' ;
33import path from 'path' ;
44import { Arguments } from 'yargs' ;
55import Config from '../Config' ;
6- import { XudClient , XudInitClient } from '../proto/xudrpc_grpc_pb' ;
6+ import * as xudGrpc from '../proto/xudrpc_grpc_pb' ;
7+
8+ // @ts -ignore
9+ const XudClient = grpc . makeClientConstructor ( xudGrpc [ 'xudrpc.Xud' ] , 'XudService' ) ;
10+ // @ts -ignore
11+ const XudInitClient = grpc . makeClientConstructor ( xudGrpc [ 'xudrpc.XudInit' ] , 'XudInitService' ) ;
712
813/**
914 * Attempts to load the xud configuration file to dynamically determine the
@@ -55,24 +60,24 @@ const getTlsCert = (certPath: string) => {
5560 * A generic function to instantiate an XU client.
5661 * @param argv the command line arguments
5762 */
58- export const loadXudClient = async ( argv : Arguments < any > ) => {
63+ export const loadXudClient = async ( argv : Arguments < any > ) : Promise < xudGrpc . XudClient > => {
5964 await loadXudConfig ( argv ) ;
6065
6166 const certPath = argv . tlscertpath || path . join ( argv . xudir , 'tls.cert' ) ;
6267 const cert = getTlsCert ( certPath ) ;
6368 const credentials = grpc . credentials . createSsl ( cert ) ;
6469
65- return new XudClient ( `${ argv . rpchost } :${ argv . rpcport } ` , credentials ) ;
70+ return new XudClient ( `${ argv . rpchost } :${ argv . rpcport } ` , credentials ) as any ;
6671} ;
6772
68- export const loadXudInitClient = async ( argv : Arguments < any > ) => {
73+ export const loadXudInitClient = async ( argv : Arguments < any > ) : Promise < xudGrpc . XudInitClient > => {
6974 await loadXudConfig ( argv ) ;
7075
7176 const certPath = argv . tlscertpath || path . join ( argv . xudir , 'tls.cert' ) ;
7277 const cert = getTlsCert ( certPath ) ;
73- const credentials = grpc . credentials . createSsl ( cert ) ;
78+ const grpcCredentials = grpc . credentials . createSsl ( cert ) ;
7479
75- return new XudInitClient ( `${ argv . rpchost } :${ argv . rpcport } ` , credentials ) ;
80+ return new XudInitClient ( `${ argv . rpchost } :${ argv . rpcport } ` , grpcCredentials ) as any ;
7681} ;
7782
7883interface GrpcResponse {
@@ -83,23 +88,23 @@ export const callback = (argv: Arguments, formatOutput?: Function, displayJson?:
8388 return ( error : grpc . ServiceError | null , response : GrpcResponse ) => {
8489 if ( error ) {
8590 process . exitCode = 1 ;
86- if ( error . code === status . UNAVAILABLE && error . message . includes ( 'xud is starting' ) ) {
91+ if ( error . code === grpc . status . UNAVAILABLE && error . message . includes ( 'xud is starting' ) ) {
8792 console . error ( 'xud is starting... try again in a few seconds' ) ;
8893 } else if ( error . details === 'failed to connect to all addresses' ) {
8994 console . error ( `could not connect to xud at ${ argv . rpchost } :${ argv . rpcport } , is xud running?` ) ;
90- } else if ( error . code === status . UNIMPLEMENTED && error . message . includes ( 'xud is locked' ) ) {
95+ } else if ( error . code === grpc . status . UNIMPLEMENTED && error . message . includes ( 'xud is locked' ) ) {
9196 console . error ( "xud is locked, run 'xucli unlock', 'xucli create', or 'xucli restore' then try again" ) ;
9297 } else if (
93- error . code === status . UNIMPLEMENTED &&
98+ error . code === grpc . status . UNIMPLEMENTED &&
9499 error . message . includes ( 'xud node cannot be created because it already exists' )
95100 ) {
96101 console . error ( "an xud node already exists, try unlocking it with 'xucli unlock'" ) ;
97102 } else if (
98- error . code === status . UNIMPLEMENTED &&
103+ error . code === grpc . status . UNIMPLEMENTED &&
99104 error . message . includes ( 'xud node cannot be unlocked because it does not exist' )
100105 ) {
101106 console . error ( "no xud node exists to unlock, try creating one with 'xucli create' or 'xucli restore'" ) ;
102- } else if ( error . code === status . UNIMPLEMENTED && error . message . includes ( 'xud init service is disabled' ) ) {
107+ } else if ( error . code === grpc . status . UNIMPLEMENTED && error . message . includes ( 'xud init service is disabled' ) ) {
103108 console . error ( "xud is running and unlocked, try checking its status with 'xucli getinfo'" ) ;
104109 } else {
105110 console . error ( `${ error . name } : ${ error . message } ` ) ;
0 commit comments