11
11
//! These 20 bytes are the address.
12
12
//!
13
13
//! [Recommended Read](https://kobl.one/blog/create-full-ethereum-keypair-and-address/)
14
- #[ cfg( feature = "bech32" ) ]
14
+ #[ cfg( not ( feature = "mesalock_sgx" ) ) ]
15
15
use bech32:: { self , u5, FromBase32 , ToBase32 } ;
16
16
use parity_scale_codec:: { Decode , Encode } ;
17
17
use std:: ops;
18
18
use std:: prelude:: v1:: String ;
19
- #[ cfg( feature = "hex" ) ]
19
+ #[ cfg( not ( feature = "mesalock_sgx" ) ) ]
20
20
use std:: str:: FromStr ;
21
21
22
- #[ cfg( feature = "hex" ) ]
22
+ #[ cfg( not ( feature = "mesalock_sgx" ) ) ]
23
23
use hex;
24
24
use secp256k1:: key:: PublicKey ;
25
- #[ cfg( feature = "serde" ) ]
25
+ #[ cfg( not ( feature = "mesalock_sgx" ) ) ]
26
26
use serde:: de:: Error ;
27
- #[ cfg( feature = "serde" ) ]
27
+ #[ cfg( not ( feature = "mesalock_sgx" ) ) ]
28
28
use serde:: { Deserialize , Deserializer , Serialize , Serializer } ;
29
- #[ cfg( feature = "hex" ) ]
29
+ #[ cfg( not ( feature = "mesalock_sgx" ) ) ]
30
30
use std:: fmt;
31
31
use tiny_keccak:: { Hasher , Keccak } ;
32
32
33
33
use crate :: common:: { H256 , HASH_SIZE_256 } ;
34
- #[ cfg( feature = "bech32" ) ]
34
+ #[ cfg( not ( feature = "mesalock_sgx" ) ) ]
35
35
use crate :: init:: network:: { get_bech32_human_part_from_network, Network } ;
36
36
37
37
#[ derive( Debug , PartialEq ) ]
38
- #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
38
+ #[ cfg_attr( not ( feature = "mesalock_sgx" ) , derive( Serialize , Deserialize ) ) ]
39
39
pub enum CroAddressError {
40
40
// TODO: use directly bech32::Error or wrap it
41
41
Bech32Error ( String ) ,
42
42
InvalidNetwork ,
43
43
ConvertError ,
44
44
}
45
45
46
- #[ cfg( feature = "bech32" ) ]
46
+ #[ cfg( not ( feature = "mesalock_sgx" ) ) ]
47
47
impl :: std:: error:: Error for CroAddressError { }
48
48
49
49
// CRO: mainnet transfer
50
50
// TCRO: testnet transfer
51
51
// DCRO: devnet/regnet transfer
52
- #[ cfg( feature = "bech32" ) ]
52
+ #[ cfg( not ( feature = "mesalock_sgx" ) ) ]
53
53
pub trait CroAddress < T > {
54
54
fn to_cro ( & self , network : Network ) -> Result < String , CroAddressError > ;
55
55
fn from_cro ( encoded : & str , network : Network ) -> Result < T , CroAddressError > ;
85
85
86
86
/// Core domain logic errors
87
87
#[ derive( Debug ) ]
88
- #[ cfg( feature = "hex" ) ]
88
+ #[ cfg( not ( feature = "mesalock_sgx" ) ) ]
89
89
pub enum ErrorAddress {
90
90
/// An invalid length
91
91
InvalidLength ( usize ) ,
@@ -103,21 +103,21 @@ pub enum ErrorAddress {
103
103
InvalidCroAddress ,
104
104
}
105
105
106
- #[ cfg( feature = "hex" ) ]
106
+ #[ cfg( not ( feature = "mesalock_sgx" ) ) ]
107
107
impl From < hex:: FromHexError > for ErrorAddress {
108
108
fn from ( err : hex:: FromHexError ) -> Self {
109
109
ErrorAddress :: UnexpectedHexEncoding ( err)
110
110
}
111
111
}
112
112
113
- #[ cfg( feature = "hex" ) ]
113
+ #[ cfg( not ( feature = "mesalock_sgx" ) ) ]
114
114
impl From < secp256k1:: Error > for ErrorAddress {
115
115
fn from ( err : secp256k1:: Error ) -> Self {
116
116
ErrorAddress :: EcdsaCrypto ( err)
117
117
}
118
118
}
119
119
120
- #[ cfg( feature = "hex" ) ]
120
+ #[ cfg( not ( feature = "mesalock_sgx" ) ) ]
121
121
impl fmt:: Display for ErrorAddress {
122
122
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
123
123
match * self {
@@ -134,7 +134,7 @@ impl fmt::Display for ErrorAddress {
134
134
}
135
135
}
136
136
137
- #[ cfg( feature = "bech32" ) ]
137
+ #[ cfg( not ( feature = "mesalock_sgx" ) ) ]
138
138
impl fmt:: Display for CroAddressError {
139
139
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
140
140
match self {
@@ -145,7 +145,7 @@ impl fmt::Display for CroAddressError {
145
145
}
146
146
}
147
147
148
- #[ cfg( feature = "hex" ) ]
148
+ #[ cfg( not ( feature = "mesalock_sgx" ) ) ]
149
149
impl std:: error:: Error for ErrorAddress {
150
150
fn description ( & self ) -> & str {
151
151
"Core error"
@@ -167,10 +167,10 @@ pub type RedeemAddressRaw = [u8; REDEEM_ADDRESS_BYTES];
167
167
168
168
/// Eth-style Account address (20 bytes)
169
169
#[ derive( Clone , Copy , Default , Hash , PartialEq , Eq , PartialOrd , Ord , Encode , Decode ) ]
170
- #[ cfg_attr( not ( feature = "hex" ) , derive( Debug ) ) ]
170
+ #[ cfg_attr( feature = "mesalock_sgx" , derive( Debug ) ) ]
171
171
pub struct RedeemAddress ( pub RedeemAddressRaw ) ;
172
172
173
- #[ cfg( feature = "hex" ) ]
173
+ #[ cfg( not ( feature = "mesalock_sgx" ) ) ]
174
174
impl RedeemAddress {
175
175
/// Try to convert a byte vector to `RedeemAddress`.
176
176
///
@@ -187,7 +187,7 @@ impl RedeemAddress {
187
187
}
188
188
}
189
189
190
- #[ cfg( all ( feature = "bech32" , feature = "hex ") ) ]
190
+ #[ cfg( not ( feature = "mesalock_sgx " ) ) ]
191
191
impl CroAddress < RedeemAddress > for RedeemAddress {
192
192
fn to_cro ( & self , network : Network ) -> Result < String , CroAddressError > {
193
193
let checked_data: Vec < u5 > = self . 0 . to_vec ( ) . to_base32 ( ) ;
@@ -231,7 +231,7 @@ impl From<[u8; REDEEM_ADDRESS_BYTES]> for RedeemAddress {
231
231
}
232
232
}
233
233
234
- #[ cfg( feature = "hex" ) ]
234
+ #[ cfg( not ( feature = "mesalock_sgx" ) ) ]
235
235
impl FromStr for RedeemAddress {
236
236
type Err = ErrorAddress ;
237
237
@@ -250,21 +250,21 @@ impl FromStr for RedeemAddress {
250
250
}
251
251
}
252
252
253
- #[ cfg( feature = "hex" ) ]
253
+ #[ cfg( not ( feature = "mesalock_sgx" ) ) ]
254
254
impl fmt:: Display for RedeemAddress {
255
255
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
256
256
write ! ( f, "0x{}" , hex:: encode( self . 0 ) )
257
257
}
258
258
}
259
259
260
- #[ cfg( feature = "hex" ) ]
260
+ #[ cfg( not ( feature = "mesalock_sgx" ) ) ]
261
261
impl fmt:: Debug for RedeemAddress {
262
262
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
263
263
write ! ( f, "(0x{}" , hex:: encode( self . 0 ) )
264
264
}
265
265
}
266
266
267
- #[ cfg( all ( feature = "serde" , feature = "hex ") ) ]
267
+ #[ cfg( not ( feature = "mesalock_sgx " ) ) ]
268
268
impl Serialize for RedeemAddress {
269
269
fn serialize < S > ( & self , serializer : S ) -> Result < S :: Ok , S :: Error >
270
270
where
@@ -274,7 +274,7 @@ impl Serialize for RedeemAddress {
274
274
}
275
275
}
276
276
277
- #[ cfg( all ( feature = "serde" , feature = "hex ") ) ]
277
+ #[ cfg( not ( feature = "mesalock_sgx " ) ) ]
278
278
impl < ' de > Deserialize < ' de > for RedeemAddress {
279
279
fn deserialize < D > ( deserializer : D ) -> Result < Self , D :: Error >
280
280
where
0 commit comments