File tree Expand file tree Collapse file tree 1 file changed +16
-3
lines changed Expand file tree Collapse file tree 1 file changed +16
-3
lines changed Original file line number Diff line number Diff line change 1
- import { IronfishSdk , RpcClient } from "@ironfish/sdk" ;
1
+ import { IronfishSdk , RpcClient , isRpcResponseError } from "@ironfish/sdk" ;
2
2
import { logger } from "./logger" ;
3
3
4
4
type ClientParams = {
@@ -28,8 +28,7 @@ class IronFishClient {
28
28
) {
29
29
const clientAddress = `${ host } :${ port } ` ;
30
30
const storedClient = this . clientRegistry . get ( clientAddress ) ;
31
-
32
- if ( storedClient ) {
31
+ if ( storedClient && ( await this . connected ( storedClient ) ) ) {
33
32
return storedClient ;
34
33
}
35
34
@@ -62,6 +61,20 @@ class IronFishClient {
62
61
63
62
return client ;
64
63
}
64
+
65
+ async connected ( client : RpcClient | undefined ) : Promise < boolean > {
66
+ try {
67
+ const response = await client ?. node . getStatus ( ) ;
68
+ if ( response && ! isRpcResponseError ( response ) ) {
69
+ return true ;
70
+ }
71
+ } catch ( error ) {
72
+ logger . error (
73
+ `Error while getting status from IronFish RPC. Reconnecting...` ,
74
+ ) ;
75
+ }
76
+ return false ;
77
+ }
65
78
}
66
79
67
80
export const ifClient = new IronFishClient ( ) ;
You can’t perform that action at this time.
0 commit comments