generalize impl_error! macro so that used for other errors type
This commit is contained in:
		
							parent
							
								
									586b874a19
								
							
						
					
					
						commit
						81519555cf
					
				| @ -553,20 +553,10 @@ impl fmt::Display for CompactFiltersError { | |||||||
| 
 | 
 | ||||||
| impl std::error::Error for CompactFiltersError {} | impl std::error::Error for CompactFiltersError {} | ||||||
| 
 | 
 | ||||||
| macro_rules! impl_error { | impl_error!(rocksdb::Error, DB, CompactFiltersError); | ||||||
|     ( $from:ty, $to:ident ) => { | impl_error!(std::io::Error, IO, CompactFiltersError); | ||||||
|         impl std::convert::From<$from> for CompactFiltersError { | impl_error!(bitcoin::util::bip158::Error, BIP158, CompactFiltersError); | ||||||
|             fn from(err: $from) -> Self { | impl_error!(std::time::SystemTimeError, Time, CompactFiltersError); | ||||||
|                 CompactFiltersError::$to(err) |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|     }; |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| impl_error!(rocksdb::Error, DB); |  | ||||||
| impl_error!(std::io::Error, IO); |  | ||||||
| impl_error!(bitcoin::util::bip158::Error, BIP158); |  | ||||||
| impl_error!(std::time::SystemTimeError, Time); |  | ||||||
| 
 | 
 | ||||||
| impl From<crate::error::Error> for CompactFiltersError { | impl From<crate::error::Error> for CompactFiltersError { | ||||||
|     fn from(err: crate::error::Error) -> Self { |     fn from(err: crate::error::Error) -> Self { | ||||||
|  | |||||||
| @ -47,7 +47,7 @@ use serde::Deserialize; | |||||||
| 
 | 
 | ||||||
| use reqwest::{Client, StatusCode}; | use reqwest::{Client, StatusCode}; | ||||||
| 
 | 
 | ||||||
| use bitcoin::consensus::{deserialize, serialize}; | use bitcoin::consensus::{self, deserialize, serialize}; | ||||||
| use bitcoin::hashes::hex::{FromHex, ToHex}; | use bitcoin::hashes::hex::{FromHex, ToHex}; | ||||||
| use bitcoin::hashes::{sha256, Hash}; | use bitcoin::hashes::{sha256, Hash}; | ||||||
| use bitcoin::{BlockHash, BlockHeader, Script, Transaction, Txid}; | use bitcoin::{BlockHash, BlockHeader, Script, Transaction, Txid}; | ||||||
| @ -423,26 +423,7 @@ impl fmt::Display for EsploraError { | |||||||
| 
 | 
 | ||||||
| impl std::error::Error for EsploraError {} | impl std::error::Error for EsploraError {} | ||||||
| 
 | 
 | ||||||
| impl From<reqwest::Error> for EsploraError { | impl_error!(reqwest::Error, Reqwest, EsploraError); | ||||||
|     fn from(other: reqwest::Error) -> Self { | impl_error!(std::num::ParseIntError, Parsing, EsploraError); | ||||||
|         EsploraError::Reqwest(other) | impl_error!(consensus::encode::Error, BitcoinEncoding, EsploraError); | ||||||
|     } | impl_error!(bitcoin::hashes::hex::Error, Hex, EsploraError); | ||||||
| } |  | ||||||
| 
 |  | ||||||
| impl From<std::num::ParseIntError> for EsploraError { |  | ||||||
|     fn from(other: std::num::ParseIntError) -> Self { |  | ||||||
|         EsploraError::Parsing(other) |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| impl From<bitcoin::consensus::encode::Error> for EsploraError { |  | ||||||
|     fn from(other: bitcoin::consensus::encode::Error) -> Self { |  | ||||||
|         EsploraError::BitcoinEncoding(other) |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| impl From<bitcoin::hashes::hex::Error> for EsploraError { |  | ||||||
|     fn from(other: bitcoin::hashes::hex::Error) -> Self { |  | ||||||
|         EsploraError::Hex(other) |  | ||||||
|     } |  | ||||||
| } |  | ||||||
|  | |||||||
| @ -110,9 +110,12 @@ impl std::error::Error for Error {} | |||||||
| 
 | 
 | ||||||
| macro_rules! impl_error { | macro_rules! impl_error { | ||||||
|     ( $from:ty, $to:ident ) => { |     ( $from:ty, $to:ident ) => { | ||||||
|         impl std::convert::From<$from> for Error { |         impl_error!($from, $to, Error); | ||||||
|  |     }; | ||||||
|  |     ( $from:ty, $to:ident, $impl_for:ty ) => { | ||||||
|  |         impl std::convert::From<$from> for $impl_for { | ||||||
|             fn from(err: $from) -> Self { |             fn from(err: $from) -> Self { | ||||||
|                 Error::$to(err) |                 <$impl_for>::$to(err) | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|     }; |     }; | ||||||
|  | |||||||
| @ -679,17 +679,8 @@ pub enum KeyError { | |||||||
|     Miniscript(miniscript::Error), |     Miniscript(miniscript::Error), | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| impl From<miniscript::Error> for KeyError { | impl_error!(miniscript::Error, Miniscript, KeyError); | ||||||
|     fn from(inner: miniscript::Error) -> Self { | impl_error!(bitcoin::util::bip32::Error, BIP32, KeyError); | ||||||
|         KeyError::Miniscript(inner) |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| impl From<bitcoin::util::bip32::Error> for KeyError { |  | ||||||
|     fn from(inner: bitcoin::util::bip32::Error) -> Self { |  | ||||||
|         KeyError::BIP32(inner) |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| 
 | 
 | ||||||
| impl std::fmt::Display for KeyError { | impl std::fmt::Display for KeyError { | ||||||
|     fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |     fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user