@@ -2,12 +2,12 @@ use std::marker::PhantomData;
22use std:: sync:: { Arc , Mutex } ;
33
44// Substrate
5- use scale_codec :: { Decode , Encode } ;
5+ use parity_scale_codec :: { Decode , Encode } ;
66use sp_core:: H256 ;
77use sp_database:: Database ;
88use sp_runtime:: traits:: Block as BlockT ;
99
10- use crate :: DbHash ;
10+ use crate :: { DbError , DbHash } ;
1111
1212/// The mapping to write in db
1313#[ derive( Debug ) ]
@@ -33,9 +33,9 @@ impl<B: BlockT> MappingDb<B> {
3333 }
3434
3535 /// Check if the given block hash has already been processed
36- pub fn is_synced ( & self , block_hash : & B :: Hash ) -> Result < bool , String > {
36+ pub fn is_synced ( & self , block_hash : & B :: Hash ) -> Result < bool , DbError > {
3737 match self . db . get ( crate :: columns:: SYNCED_MAPPING , & block_hash. encode ( ) ) {
38- Some ( raw) => Ok ( bool:: decode ( & mut & raw [ ..] ) . map_err ( |e| format ! ( "{:?}" , e ) ) ?) ,
38+ Some ( raw) => Ok ( bool:: decode ( & mut & raw [ ..] ) ?) ,
3939 None => Ok ( false ) ,
4040 }
4141 }
@@ -44,28 +44,28 @@ impl<B: BlockT> MappingDb<B> {
4444 ///
4545 /// Under some circumstances it can return multiples blocks hashes, meaning that the result has
4646 /// to be checked against the actual blockchain state in order to find the good one.
47- pub fn block_hash ( & self , starknet_block_hash : & H256 ) -> Result < Option < Vec < B :: Hash > > , String > {
47+ pub fn block_hash ( & self , starknet_block_hash : & H256 ) -> Result < Option < Vec < B :: Hash > > , DbError > {
4848 match self . db . get ( crate :: columns:: BLOCK_MAPPING , & starknet_block_hash. encode ( ) ) {
49- Some ( raw) => Ok ( Some ( Vec :: < B :: Hash > :: decode ( & mut & raw [ ..] ) . map_err ( |e| format ! ( "{:?}" , e ) ) ?) ) ,
49+ Some ( raw) => Ok ( Some ( Vec :: < B :: Hash > :: decode ( & mut & raw [ ..] ) ?) ) ,
5050 None => Ok ( None ) ,
5151 }
5252 }
5353
5454 /// Register that a Substrate block has been seen, without it containing a Starknet one
55- pub fn write_none ( & self , block_hash : B :: Hash ) -> Result < ( ) , String > {
55+ pub fn write_none ( & self , block_hash : B :: Hash ) -> Result < ( ) , DbError > {
5656 let _lock = self . write_lock . lock ( ) ;
5757
5858 let mut transaction = sp_database:: Transaction :: new ( ) ;
5959
6060 transaction. set ( crate :: columns:: SYNCED_MAPPING , & block_hash. encode ( ) , & true . encode ( ) ) ;
6161
62- self . db . commit ( transaction) . map_err ( |e| format ! ( "{:?}" , e ) ) ?;
62+ self . db . commit ( transaction) ?;
6363
6464 Ok ( ( ) )
6565 }
6666
6767 /// Register that a Substate block has been seen and map it to the Statknet block it contains
68- pub fn write_hashes ( & self , commitment : MappingCommitment < B > ) -> Result < ( ) , String > {
68+ pub fn write_hashes ( & self , commitment : MappingCommitment < B > ) -> Result < ( ) , DbError > {
6969 let _lock = self . write_lock . lock ( ) ;
7070
7171 let mut transaction = sp_database:: Transaction :: new ( ) ;
@@ -108,7 +108,7 @@ impl<B: BlockT> MappingDb<B> {
108108 ) ;
109109 }
110110
111- self . db . commit ( transaction) . map_err ( |e| format ! ( "{:?}" , e ) ) ?;
111+ self . db . commit ( transaction) ?;
112112
113113 Ok ( ( ) )
114114 }
@@ -121,9 +121,9 @@ impl<B: BlockT> MappingDb<B> {
121121 /// * `transaction_hash` - the transaction hash to search for. H256 is used here because it's a
122122 /// native type of substrate, and we are sure it's SCALE encoding is optimized and will not
123123 /// change.
124- pub fn block_hash_from_transaction_hash ( & self , transaction_hash : H256 ) -> Result < Option < B :: Hash > , String > {
124+ pub fn block_hash_from_transaction_hash ( & self , transaction_hash : H256 ) -> Result < Option < B :: Hash > , DbError > {
125125 match self . db . get ( crate :: columns:: TRANSACTION_MAPPING , & transaction_hash. encode ( ) ) {
126- Some ( raw) => Ok ( Some ( <B :: Hash >:: decode ( & mut & raw [ ..] ) . map_err ( |e| format ! ( "{:?}" , e ) ) ?) ) ,
126+ Some ( raw) => Ok ( Some ( <B :: Hash >:: decode ( & mut & raw [ ..] ) ?) ) ,
127127 None => Ok ( None ) ,
128128 }
129129 }
@@ -142,14 +142,14 @@ impl<B: BlockT> MappingDb<B> {
142142 ///
143143 /// - The cache is disabled.
144144 /// - The provided `starknet_hash` is not present in the cache.
145- pub fn cached_transaction_hashes_from_block_hash ( & self , starknet_hash : H256 ) -> Result < Option < Vec < H256 > > , String > {
145+ pub fn cached_transaction_hashes_from_block_hash ( & self , starknet_hash : H256 ) -> Result < Option < Vec < H256 > > , DbError > {
146146 if !self . cache_more_things {
147147 // The cache is not enabled, no need to even touch the database.
148148 return Ok ( None ) ;
149149 }
150150
151151 match self . db . get ( crate :: columns:: STARKNET_TRANSACTION_HASHES_CACHE , & starknet_hash. encode ( ) ) {
152- Some ( raw) => Ok ( Some ( Vec :: < H256 > :: decode ( & mut & raw [ ..] ) . map_err ( |e| format ! ( "{:?}" , e ) ) ?) ) ,
152+ Some ( raw) => Ok ( Some ( Vec :: < H256 > :: decode ( & mut & raw [ ..] ) ?) ) ,
153153 None => Ok ( None ) ,
154154 }
155155 }
0 commit comments