@@ -9,13 +9,46 @@ use serde_hex::{SerHex, StrictPfx};
9
9
use crate :: big_num:: BigNum ;
10
10
use crate :: util:: serde:: ts_milliseconds_option;
11
11
use crate :: { AdUnit , EventSubmission , TargetingTag , ValidatorDesc , ValidatorId } ;
12
+ use hex:: { FromHex , FromHexError } ;
13
+ use std:: ops:: Deref ;
12
14
13
- pub type ChannelId = [ u8 ; 32 ] ;
15
+ #[ derive( Serialize , Deserialize , PartialEq , Eq , Debug , Copy , Clone ) ]
16
+ #[ serde( transparent) ]
17
+ pub struct ChannelId ( #[ serde( with = "SerHex::<StrictPfx>" ) ] [ u8 ; 32 ] ) ;
18
+
19
+ impl Deref for ChannelId {
20
+ type Target = [ u8 ] ;
21
+
22
+ fn deref ( & self ) -> & [ u8 ] {
23
+ & self . 0
24
+ }
25
+ }
26
+
27
+ impl From < [ u8 ; 32 ] > for ChannelId {
28
+ fn from ( array : [ u8 ; 32 ] ) -> Self {
29
+ Self ( array)
30
+ }
31
+ }
32
+
33
+ impl AsRef < [ u8 ] > for ChannelId {
34
+ fn as_ref ( & self ) -> & [ u8 ] {
35
+ & self . 0
36
+ }
37
+ }
38
+
39
+ impl FromHex for ChannelId {
40
+ type Error = FromHexError ;
41
+
42
+ fn from_hex < T : AsRef < [ u8 ] > > ( hex : T ) -> Result < Self , Self :: Error > {
43
+ let array = hex:: FromHex :: from_hex ( hex. as_ref ( ) ) ?;
44
+
45
+ Ok ( Self ( array) )
46
+ }
47
+ }
14
48
15
49
#[ derive( Serialize , Deserialize , Debug , Clone ) ]
16
50
#[ serde( rename_all = "camelCase" ) ]
17
51
pub struct Channel {
18
- #[ serde( with = "SerHex::<StrictPfx>" ) ]
19
52
pub id : ChannelId ,
20
53
pub creator : String ,
21
54
pub deposit_asset : String ,
0 commit comments