@@ -226,42 +226,13 @@ impl CkbRpcClient {
226226 self . post ( "get_block" , ( hash, Some ( Uint32 :: from ( 0u32 ) ) ) )
227227 }
228228
229- // turn block response into BlockView and cycle vec
230- fn transform_block_view_with_cycle (
231- opt_resp : Option < BlockResponse > ,
232- ) -> Result < Option < ( BlockView , Vec < Cycle > ) > , crate :: rpc:: RpcError > {
233- opt_resp
234- . map ( |resp| match resp {
235- BlockResponse :: Regular ( block_view) => Ok ( ( block_view. get_value ( ) ?, vec ! [ ] ) ) ,
236- BlockResponse :: WithCycles ( block_cycles) => {
237- let cycles = transform_cycles ( block_cycles. cycles ) ;
238- Ok ( ( block_cycles. block . get_value ( ) ?, cycles) )
239- }
240- } )
241- . transpose ( )
242- }
243229 /// Same as get_block except with parameter with_cycles and return BlockResponse
244230 pub fn get_block_with_cycles (
245231 & self ,
246232 hash : H256 ,
247233 ) -> Result < Option < ( BlockView , Vec < Cycle > ) > , crate :: rpc:: RpcError > {
248234 let res = self . post :: < _ , Option < BlockResponse > > ( "get_block" , ( hash, None :: < u32 > , true ) ) ?;
249- Self :: transform_block_view_with_cycle ( res)
250- }
251-
252- // turn BlockResponse to JsonBytes and Cycle tuple
253- fn blockresponse2bytes (
254- opt_resp : Option < BlockResponse > ,
255- ) -> Result < Option < ( JsonBytes , Vec < Cycle > ) > , crate :: rpc:: RpcError > {
256- opt_resp
257- . map ( |resp| match resp {
258- BlockResponse :: Regular ( block_view) => Ok ( ( block_view. get_json_bytes ( ) ?, vec ! [ ] ) ) ,
259- BlockResponse :: WithCycles ( block_cycles) => {
260- let cycles = transform_cycles ( block_cycles. cycles ) ;
261- Ok ( ( block_cycles. block . get_json_bytes ( ) ?, cycles) )
262- }
263- } )
264- . transpose ( )
235+ transform_block_view_with_cycle ( res)
265236 }
266237
267238 pub fn get_packed_block_with_cycles (
@@ -272,7 +243,7 @@ impl CkbRpcClient {
272243 "get_block" ,
273244 ( hash, Some ( Uint32 :: from ( 0u32 ) ) , true ) ,
274245 ) ?;
275- Self :: blockresponse2bytes ( res)
246+ blockresponse2bytes ( res)
276247 }
277248
278249 /// Same as get_block_by_number except with parameter with_cycles and return BlockResponse
@@ -289,7 +260,7 @@ impl CkbRpcClient {
289260 ) -> Result < Option < ( BlockView , Vec < Cycle > ) > , crate :: rpc:: RpcError > {
290261 let res = self
291262 . post :: < _ , Option < BlockResponse > > ( "get_block_by_number" , ( number, None :: < u32 > , true ) ) ?;
292- Self :: transform_block_view_with_cycle ( res)
263+ transform_block_view_with_cycle ( res)
293264 }
294265
295266 pub fn get_packed_block_by_number_with_cycles (
@@ -300,7 +271,7 @@ impl CkbRpcClient {
300271 "get_block_by_number" ,
301272 ( number, Some ( Uint32 :: from ( 0u32 ) ) , true ) ,
302273 ) ?;
303- Self :: blockresponse2bytes ( res)
274+ blockresponse2bytes ( res)
304275 }
305276
306277 pub fn get_packed_header ( & self , hash : H256 ) -> Result < Option < JsonBytes > , crate :: rpc:: RpcError > {
@@ -402,20 +373,6 @@ impl CkbRpcAsyncClient {
402373 . await
403374 }
404375
405- // turn block response into BlockView and cycle vec
406- fn transform_block_view_with_cycle (
407- opt_resp : Option < BlockResponse > ,
408- ) -> Result < Option < ( BlockView , Vec < Cycle > ) > , crate :: rpc:: RpcError > {
409- opt_resp
410- . map ( |resp| match resp {
411- BlockResponse :: Regular ( block_view) => Ok ( ( block_view. get_value ( ) ?, vec ! [ ] ) ) ,
412- BlockResponse :: WithCycles ( block_cycles) => {
413- let cycles = transform_cycles ( block_cycles. cycles ) ;
414- Ok ( ( block_cycles. block . get_value ( ) ?, cycles) )
415- }
416- } )
417- . transpose ( )
418- }
419376 /// Same as get_block except with parameter with_cycles and return BlockResponse
420377 pub async fn get_block_with_cycles (
421378 & self ,
@@ -424,22 +381,7 @@ impl CkbRpcAsyncClient {
424381 let res = self
425382 . post :: < _ , Option < BlockResponse > > ( "get_block" , ( hash, None :: < u32 > , true ) )
426383 . await ?;
427- Self :: transform_block_view_with_cycle ( res)
428- }
429-
430- // turn BlockResponse to JsonBytes and Cycle tuple
431- fn blockresponse2bytes (
432- opt_resp : Option < BlockResponse > ,
433- ) -> Result < Option < ( JsonBytes , Vec < Cycle > ) > , crate :: rpc:: RpcError > {
434- opt_resp
435- . map ( |resp| match resp {
436- BlockResponse :: Regular ( block_view) => Ok ( ( block_view. get_json_bytes ( ) ?, vec ! [ ] ) ) ,
437- BlockResponse :: WithCycles ( block_cycles) => {
438- let cycles = transform_cycles ( block_cycles. cycles ) ;
439- Ok ( ( block_cycles. block . get_json_bytes ( ) ?, cycles) )
440- }
441- } )
442- . transpose ( )
384+ transform_block_view_with_cycle ( res)
443385 }
444386
445387 pub async fn get_packed_block_with_cycles (
@@ -449,7 +391,7 @@ impl CkbRpcAsyncClient {
449391 let res = self
450392 . post :: < _ , Option < BlockResponse > > ( "get_block" , ( hash, Some ( Uint32 :: from ( 0u32 ) ) , true ) )
451393 . await ?;
452- Self :: blockresponse2bytes ( res)
394+ blockresponse2bytes ( res)
453395 }
454396
455397 /// Same as get_block_by_number except with parameter with_cycles and return BlockResponse
@@ -468,7 +410,7 @@ impl CkbRpcAsyncClient {
468410 let res = self
469411 . post :: < _ , Option < BlockResponse > > ( "get_block_by_number" , ( number, None :: < u32 > , true ) )
470412 . await ?;
471- Self :: transform_block_view_with_cycle ( res)
413+ transform_block_view_with_cycle ( res)
472414 }
473415
474416 pub async fn get_packed_block_by_number_with_cycles (
@@ -481,7 +423,7 @@ impl CkbRpcAsyncClient {
481423 ( number, Some ( Uint32 :: from ( 0u32 ) ) , true ) ,
482424 )
483425 . await ?;
484- Self :: blockresponse2bytes ( res)
426+ blockresponse2bytes ( res)
485427 }
486428
487429 pub async fn get_packed_header (
@@ -589,3 +531,33 @@ impl CkbRpcAsyncClient {
589531 . await
590532 }
591533}
534+
535+ // turn BlockResponse to JsonBytes and Cycle tuple
536+ fn blockresponse2bytes (
537+ opt_resp : Option < BlockResponse > ,
538+ ) -> Result < Option < ( JsonBytes , Vec < Cycle > ) > , crate :: rpc:: RpcError > {
539+ opt_resp
540+ . map ( |resp| match resp {
541+ BlockResponse :: Regular ( block_view) => Ok ( ( block_view. get_json_bytes ( ) ?, vec ! [ ] ) ) ,
542+ BlockResponse :: WithCycles ( block_cycles) => {
543+ let cycles = transform_cycles ( block_cycles. cycles ) ;
544+ Ok ( ( block_cycles. block . get_json_bytes ( ) ?, cycles) )
545+ }
546+ } )
547+ . transpose ( )
548+ }
549+
550+ // turn block response into BlockView and cycle vec
551+ fn transform_block_view_with_cycle (
552+ opt_resp : Option < BlockResponse > ,
553+ ) -> Result < Option < ( BlockView , Vec < Cycle > ) > , crate :: rpc:: RpcError > {
554+ opt_resp
555+ . map ( |resp| match resp {
556+ BlockResponse :: Regular ( block_view) => Ok ( ( block_view. get_value ( ) ?, vec ! [ ] ) ) ,
557+ BlockResponse :: WithCycles ( block_cycles) => {
558+ let cycles = transform_cycles ( block_cycles. cycles ) ;
559+ Ok ( ( block_cycles. block . get_value ( ) ?, cycles) )
560+ }
561+ } )
562+ . transpose ( )
563+ }
0 commit comments