11use crate :: { error, zgs_grpc_proto} ;
22use append_merkle:: ZERO_HASHES ;
3+ use ethereum_types:: H256 as EthH256 ;
34use jsonrpsee:: core:: RpcResult ;
45use merkle_light:: hash:: Algorithm ;
56use merkle_light:: merkle:: { log2_pow2, next_pow2, MerkleTree } ;
@@ -19,7 +20,6 @@ use storage::config::ShardConfig;
1920use storage:: log_store:: log_manager:: bytes_to_entries;
2021use storage:: H256 ;
2122use tonic:: Status as GrpcStatus ;
22- use ethereum_types:: H256 as EthH256 ;
2323
2424const ZERO_HASH : [ u8 ; 32 ] = [
2525 0xd3 , 0x97 , 0xb3 , 0xb0 , 0x43 , 0xd8 , 0x7f , 0xcd , 0x6f , 0xad , 0x12 , 0x91 , 0xff , 0xb , 0xfd , 0x16 ,
@@ -86,7 +86,10 @@ impl TryFrom<zgs_grpc_proto::DataRoot> for DataRoot {
8686 fn try_from ( value : zgs_grpc_proto:: DataRoot ) -> Result < Self , GrpcStatus > {
8787 let bytes = value. value ;
8888 if bytes. len ( ) != 32 {
89- return Err ( GrpcStatus :: invalid_argument ( format ! ( "Invalid hash length: got {}, want 32" , bytes. len( ) ) ) ) ;
89+ return Err ( GrpcStatus :: invalid_argument ( format ! (
90+ "Invalid hash length: got {}, want 32" ,
91+ bytes. len( )
92+ ) ) ) ;
9093 }
9194 // assume AppDataRoot is a newtype around H256:
9295 let mut arr = [ 0u8 ; 32 ] ;
@@ -104,7 +107,10 @@ impl TryFrom<zgs_grpc_proto::FileProof> for FileProof {
104107 let mut lemma = Vec :: with_capacity ( value. lemma . len ( ) ) ;
105108 for bin in value. lemma {
106109 if bin. len ( ) != 32 {
107- return Err ( GrpcStatus :: invalid_argument ( format ! ( "Invalid hash length: got {}, want 32" , bin. len( ) ) ) ) ;
110+ return Err ( GrpcStatus :: invalid_argument ( format ! (
111+ "Invalid hash length: got {}, want 32" ,
112+ bin. len( )
113+ ) ) ) ;
108114 }
109115 let mut arr = [ 0u8 ; 32 ] ;
110116 arr. copy_from_slice ( & bin) ;
@@ -123,24 +129,16 @@ impl TryFrom<zgs_grpc_proto::SegmentWithProof> for SegmentWithProof {
123129 type Error = GrpcStatus ;
124130
125131 fn try_from ( grpc_segment : zgs_grpc_proto:: SegmentWithProof ) -> Result < Self , GrpcStatus > {
126- let root = grpc_segment
127- . root
128- . unwrap ( )
129- . try_into ( )
130- . map_err ( |e| e) ?;
132+ let root = grpc_segment. root . unwrap ( ) . try_into ( ) . map_err ( |e| e) ?;
131133 let data = grpc_segment. data ;
132134 // index is u64 in proto, usize in app
133- let index = grpc_segment. index
134- . try_into ( )
135- . map_err ( |_| GrpcStatus :: invalid_argument ( format ! ( "Invalid segment index: {}" , grpc_segment. index) ) ) ?;
136- let proof = grpc_segment
137- . proof
138- . unwrap ( )
139- . try_into ( )
140- . map_err ( |e| e) ?;
141- let file_size = grpc_segment. file_size
142- . try_into ( )
143- . map_err ( |_| GrpcStatus :: invalid_argument ( format ! ( "Invalid file size: {}" , grpc_segment. file_size) ) ) ?;
135+ let index = grpc_segment. index . try_into ( ) . map_err ( |_| {
136+ GrpcStatus :: invalid_argument ( format ! ( "Invalid segment index: {}" , grpc_segment. index) )
137+ } ) ?;
138+ let proof = grpc_segment. proof . unwrap ( ) . try_into ( ) . map_err ( |e| e) ?;
139+ let file_size = grpc_segment. file_size . try_into ( ) . map_err ( |_| {
140+ GrpcStatus :: invalid_argument ( format ! ( "Invalid file size: {}" , grpc_segment. file_size) )
141+ } ) ?;
144142
145143 Ok ( SegmentWithProof {
146144 root,
0 commit comments