1- import * as crypto from "crypto" ;
1+ import crypto from "crypto" ; // eslint-disable-line unicorn/prefer-node-protocol
22
33import { AnchorProvider , BN , Program } from "@coral-xyz/anchor" ;
44import {
@@ -752,7 +752,7 @@ export class PythStakingClient {
752752 publisherStakeAccountPositions : stakeAccount ,
753753 publisherStakeAccountCustody : stakeAccount
754754 ? getStakeAccountCustodyAddress ( stakeAccount )
755- : null ,
755+ : null , // eslint-disable-line unicorn/no-null
756756 stakeAccountPositions,
757757 stakeAccountCustody : getStakeAccountCustodyAddress (
758758 stakeAccountPositions ,
@@ -839,6 +839,7 @@ export class PythStakingClient {
839839 . setPublisherStakeAccount ( )
840840 . accounts ( {
841841 currentStakeAccountPositionsOption : stakeAccountPositions ,
842+ // eslint-disable-next-line unicorn/no-null
842843 newStakeAccountPositionsOption : newStakeAccountPositions ?? null ,
843844 publisher,
844845 } )
@@ -1088,22 +1089,25 @@ export class PythStakingClient {
10881089 // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
10891090 while ( true ) {
10901091 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+ ) {
10931098 jsonparser . write ( res . value ) ;
10941099 }
10951100 }
10961101 } ;
10971102
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+ ) ;
11071111 } ) ;
11081112
11091113 return accountSchema
@@ -1140,6 +1144,16 @@ const accountSchema = z.array(
11401144 } ) ,
11411145) ;
11421146
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+
11431157class NotOKError extends Error {
11441158 constructor ( result : Response ) {
11451159 super ( `Received a ${ result . status . toString ( ) } response for ${ result . url } ` ) ;
@@ -1154,3 +1168,17 @@ class NoBodyError extends Error {
11541168 this . name = "NoBodyError" ;
11551169 }
11561170}
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