11import { XrpConfigLoader } from "../config/config"
2- import { IXrpBlock , IXrpBlockQueryResponse , IXrpInfoResponse } from "./interface"
2+ import { IXrpBlock , IXrpBlockQueryResponse , IXrpLedgerCurrentResponse , IXrpServerInfoResponse } from "./interface"
33
44export class XrpClient {
55
@@ -12,15 +12,27 @@ export class XrpClient {
1212 }
1313
1414 async blockHeight ( ) : Promise < number > {
15- const resp = await this . getLedgerCurrent ( )
16- this . ensureSuccess ( resp )
17- return resp . result . ledger_current_index
15+ let current_block = 0
16+ if ( this . config . xrpNodeIsAmendmentBlocked ) {
17+ const resp = await this . getServerInfo ( )
18+ this . ensureSuccess ( resp )
19+ current_block = resp . result . info . validated_ledger . seq
20+ } else {
21+ const resp = await this . getLedgerCurrent ( )
22+ this . ensureSuccess ( resp )
23+ current_block = resp . result . ledger_current_index
24+ }
25+ return current_block
1826 }
1927
20- private async getLedgerCurrent ( ) : Promise < IXrpInfoResponse > {
28+ private async getLedgerCurrent ( ) : Promise < IXrpLedgerCurrentResponse > {
2129 return this . request ( 'ledger_current' , [ ] )
2230 }
2331
32+ private async getServerInfo ( ) : Promise < IXrpServerInfoResponse > {
33+ return this . request ( 'server_info' , [ { } ] )
34+ }
35+
2436 private async getLedger ( n : number ) : Promise < IXrpBlockQueryResponse > {
2537 return this . request ( 'ledger' , [ {
2638 id : 1 ,
@@ -39,9 +51,9 @@ export class XrpClient {
3951 return resp . json ( )
4052 }
4153
42- private ensureSuccess ( resp : { result : { status : string } } ) : any {
54+ private ensureSuccess ( resp : { result : { status : string , error_message ?: string } } ) : any {
4355 if ( resp . result . status != 'success' ) {
44- throw new Error ( `rpc returned ${ resp } ` )
56+ throw new Error ( `rpc returned ${ JSON . stringify ( resp . result . error_message ) } ` )
4557 }
4658 }
4759}
0 commit comments