@@ -118,19 +118,62 @@ const lightRPCProperties: Record<string, Omit<Parameters<CKBRPC['addMethod']>[0]
118118 } ,
119119}
120120
121+ class Method extends SdkRpcMethod {
122+ constructor ( node : CKBComponents . Node , options : CKBComponents . Method ) {
123+ super ( node , options , rpcConfig )
124+ }
125+ }
126+
121127export class FullCKBRPC extends CKBRPC {
128+ constructor ( url : string , rpcConfig : Partial < RPCConfig > ) {
129+ super ( url , rpcConfig )
130+ this . setNode ( { url } )
131+
132+ this . getSyncState = new Method ( this . node , {
133+ name : 'getSyncState' ,
134+ method : 'sync_state' ,
135+ paramsFormatters : [ ] ,
136+ resultFormatters : ( state : {
137+ assume_valid_target : string
138+ assume_valid_target_reached : boolean
139+ best_known_block_number : any
140+ best_known_block_timestamp : any
141+ fast_time : any
142+ ibd : any
143+ inflight_blocks_count : any
144+ low_time : any
145+ normal_time : any
146+ orphan_blocks_count : any
147+ } ) => {
148+ if ( ! state ) {
149+ return state
150+ }
151+ return {
152+ assumeValidTarget : state . assume_valid_target ,
153+ assumeValidTargetReached : state . assume_valid_target_reached ,
154+ bestKnownBlockNumber : state . best_known_block_number ,
155+ bestKnownBlockTimestamp : state . best_known_block_timestamp ,
156+ fastTime : state . fast_time ,
157+ ibd : state . ibd ,
158+ inflightBlocksCount : state . inflight_blocks_count ,
159+ lowTime : state . low_time ,
160+ normalTime : state . normal_time ,
161+ orphanBlocksCount : state . orphan_blocks_count ,
162+ }
163+ } ,
164+ } ) . call
165+ }
166+
122167 getGenesisBlockHash = async ( ) => {
123168 return this . getBlockHash ( '0x0' )
124169 }
125170
126171 getGenesisBlock = async ( ) : Promise < Block > => {
127172 return this . getBlockByNumber ( '0x0' )
128173 }
129- }
130174
131- class Method extends SdkRpcMethod {
132- constructor ( node : CKBComponents . Node , options : CKBComponents . Method ) {
133- super ( node , options , rpcConfig )
175+ getSyncState = async ( ) : Promise < CKBComponents . SyncState > => {
176+ return this . getSyncState ( )
134177 }
135178}
136179
@@ -233,6 +276,14 @@ export class LightRPC extends Base {
233276 return genesisBlock . header . hash
234277 }
235278
279+ getSyncState = async ( ) => {
280+ const headerTip = await this . getTipHeader ( )
281+ return {
282+ bestKnownBlockNumber : headerTip . number ,
283+ bestKnownBlockTimestamp : headerTip . timestamp ,
284+ } as CKBComponents . SyncState
285+ }
286+
236287 syncState = async ( ) => {
237288 const headerTip = await this . getTipHeader ( )
238289 return {
0 commit comments