1
- import * as crypto from "crypto" ;
1
+ import crypto from "crypto" ; // eslint-disable-line unicorn/prefer-node-protocol
2
2
3
3
import { AnchorProvider , BN , Program } from "@coral-xyz/anchor" ;
4
4
import {
@@ -752,7 +752,7 @@ export class PythStakingClient {
752
752
publisherStakeAccountPositions : stakeAccount ,
753
753
publisherStakeAccountCustody : stakeAccount
754
754
? getStakeAccountCustodyAddress ( stakeAccount )
755
- : null ,
755
+ : null , // eslint-disable-line unicorn/no-null
756
756
stakeAccountPositions,
757
757
stakeAccountCustody : getStakeAccountCustodyAddress (
758
758
stakeAccountPositions ,
@@ -839,6 +839,7 @@ export class PythStakingClient {
839
839
. setPublisherStakeAccount ( )
840
840
. accounts ( {
841
841
currentStakeAccountPositionsOption : stakeAccountPositions ,
842
+ // eslint-disable-next-line unicorn/no-null
842
843
newStakeAccountPositionsOption : newStakeAccountPositions ?? null ,
843
844
publisher,
844
845
} )
@@ -1088,22 +1089,25 @@ export class PythStakingClient {
1088
1089
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
1089
1090
while ( true ) {
1090
1091
const res = await reader . read ( ) ;
1091
- if ( res . done ) break ;
1092
- if ( typeof res . value === "string" ) {
1092
+ if ( res . done ) {
1093
+ break ;
1094
+ } else if (
1095
+ typeof res . value === "string" ||
1096
+ res . value instanceof Uint8Array
1097
+ ) {
1093
1098
jsonparser . write ( res . value ) ;
1094
1099
}
1095
1100
}
1096
1101
} ;
1097
1102
1098
- parse ( ) . catch ( ( error : unknown ) => {
1099
- reject (
1100
- error instanceof Error
1101
- ? error
1102
- : new Error (
1103
- typeof error === "string" ? error : "Unknown Error" ,
1104
- ) ,
1105
- ) ;
1106
- } ) ;
1103
+ parse ( ) . then (
1104
+ ( ) => {
1105
+ reject ( new EndOfStreamError ( ) ) ;
1106
+ } ,
1107
+ ( error : unknown ) => {
1108
+ reject ( intoError ( error ) ) ;
1109
+ } ,
1110
+ ) ;
1107
1111
} ) ;
1108
1112
1109
1113
return accountSchema
@@ -1140,6 +1144,16 @@ const accountSchema = z.array(
1140
1144
} ) ,
1141
1145
) ;
1142
1146
1147
+ const intoError = ( error : unknown ) : Error => {
1148
+ if ( error instanceof Error ) {
1149
+ return error ;
1150
+ } else if ( typeof error === "string" ) {
1151
+ return new Error ( error ) ;
1152
+ } else {
1153
+ return new UnknownError ( ) ;
1154
+ }
1155
+ } ;
1156
+
1143
1157
class NotOKError extends Error {
1144
1158
constructor ( result : Response ) {
1145
1159
super ( `Received a ${ result . status . toString ( ) } response for ${ result . url } ` ) ;
@@ -1154,3 +1168,17 @@ class NoBodyError extends Error {
1154
1168
this . name = "NoBodyError" ;
1155
1169
}
1156
1170
}
1171
+
1172
+ class EndOfStreamError extends Error {
1173
+ constructor ( ) {
1174
+ super ( "Reached end of stream without finding accounts" ) ;
1175
+ this . name = "EndOfStreamError" ;
1176
+ }
1177
+ }
1178
+
1179
+ class UnknownError extends Error {
1180
+ constructor ( ) {
1181
+ super ( "Unknown error" ) ;
1182
+ this . name = "UnknownError" ;
1183
+ }
1184
+ }
0 commit comments