1515
1616use parity_scale_codec:: { Decode , DecodeAll , Encode } ;
1717
18- use crate :: { Destination , TokenId } ;
18+ use crate :: TokenId ;
1919
2020pub type PscVec < T > = parity_scale_codec:: alloc:: vec:: Vec < T > ;
2121
@@ -92,115 +92,6 @@ pub type SecondsCountUIntType = u64;
9292#[ derive( Debug , Clone , Copy , PartialOrd , Ord , PartialEq , Eq , Encode , Decode ) ]
9393pub struct SecondsCount ( #[ codec( compact) ] pub SecondsCountUIntType ) ;
9494
95- #[ derive( Clone , Copy , Debug , Eq , PartialEq ) ]
96- pub enum CoinType {
97- Mainnet ,
98- Testnet ,
99- Regtest ,
100- Signet ,
101- }
102-
103- impl CoinType {
104- pub const fn coin_ticker ( & self ) -> & ' static str {
105- match self {
106- Self :: Mainnet => "ML" ,
107- Self :: Testnet => "TML" ,
108- Self :: Regtest => "RML" ,
109- Self :: Signet => "SML" ,
110- }
111- }
112-
113- pub const fn bip44_coin_type ( & self ) -> u32 {
114- let hardened_bit = 1 << 31 ;
115- match self {
116- Self :: Mainnet => 19788 + hardened_bit,
117- Self :: Testnet | Self :: Regtest | Self :: Signet => 1 + hardened_bit,
118- }
119- }
120-
121- pub const fn coin_decimals ( & self ) -> u8 {
122- 11
123- }
124-
125- pub const fn address_prefix ( & self , destination : & Destination ) -> & ' static str {
126- match self {
127- Self :: Mainnet => match destination {
128- Destination :: AnyoneCanSpend => "mxanyonecanspend" ,
129- Destination :: PublicKeyHash ( _) => "mtc" ,
130- Destination :: PublicKey ( _) => "mptc" ,
131- Destination :: ScriptHash ( _) => "mstc" ,
132- Destination :: ClassicMultisig ( _) => "mmtc" ,
133- } ,
134- Self :: Testnet => match destination {
135- Destination :: AnyoneCanSpend => "txanyonecanspend" ,
136- Destination :: PublicKeyHash ( _) => "tmt" ,
137- Destination :: PublicKey ( _) => "tpmt" ,
138- Destination :: ScriptHash ( _) => "tstc" ,
139- Destination :: ClassicMultisig ( _) => "tmtc" ,
140- } ,
141- Self :: Regtest => match destination {
142- Destination :: AnyoneCanSpend => "rxanyonecanspend" ,
143- Destination :: PublicKeyHash ( _) => "rmt" ,
144- Destination :: PublicKey ( _) => "rpmt" ,
145- Destination :: ScriptHash ( _) => "rstc" ,
146- Destination :: ClassicMultisig ( _) => "rmtc" ,
147- } ,
148- Self :: Signet => match destination {
149- Destination :: AnyoneCanSpend => "sxanyonecanspend" ,
150- Destination :: PublicKeyHash ( _) => "smt" ,
151- Destination :: PublicKey ( _) => "spmt" ,
152- Destination :: ScriptHash ( _) => "sstc" ,
153- Destination :: ClassicMultisig ( _) => "smtc" ,
154- } ,
155- }
156- }
157-
158- pub const fn pool_id_address_prefix ( & self ) -> & ' static str {
159- match self {
160- Self :: Mainnet => "mpool" ,
161- Self :: Testnet => "tpool" ,
162- Self :: Regtest => "rpool" ,
163- Self :: Signet => "spool" ,
164- }
165- }
166-
167- pub const fn delegation_id_address_prefix ( & self ) -> & ' static str {
168- match self {
169- Self :: Mainnet => "mdelg" ,
170- Self :: Testnet => "tdelg" ,
171- Self :: Regtest => "rdelg" ,
172- Self :: Signet => "sdelg" ,
173- }
174- }
175-
176- pub const fn token_id_address_prefix ( & self ) -> & ' static str {
177- match self {
178- Self :: Mainnet => "mmltk" ,
179- Self :: Testnet => "tmltk" ,
180- Self :: Regtest => "rmltk" ,
181- Self :: Signet => "smltk" ,
182- }
183- }
184-
185- pub const fn order_id_address_prefix ( & self ) -> & ' static str {
186- match self {
187- Self :: Mainnet => "mordr" ,
188- Self :: Testnet => "tordr" ,
189- Self :: Regtest => "rordr" ,
190- Self :: Signet => "sordr" ,
191- }
192- }
193-
194- pub const fn vrf_public_key_address_prefix ( & self ) -> & ' static str {
195- match self {
196- Self :: Mainnet => "mvrfpk" ,
197- Self :: Testnet => "tvrfpk" ,
198- Self :: Regtest => "rvrfpk" ,
199- Self :: Signet => "svrfpk" ,
200- }
201- }
202- }
203-
20495pub fn encode < T : Encode > ( t : & T ) -> PscVec < u8 > {
20596 t. encode ( )
20697}
@@ -209,10 +100,13 @@ pub fn encode_to<T: Encode>(t: &T, buf: &mut PscVec<u8>) {
209100 t. encode_to ( buf)
210101}
211102
212- pub fn decode_all < T : Decode > ( mut bytes : & [ u8 ] ) -> Option < T > {
213- T :: decode_all ( & mut bytes) . ok ( )
103+ pub fn decode_all < T : Decode > ( mut bytes : & [ u8 ] ) -> Result < T , parity_scale_codec :: Error > {
104+ T :: decode_all ( & mut bytes)
214105}
215106
216- pub fn encode_as_compact ( num : u32 ) -> PscVec < u8 > {
217- parity_scale_codec:: Compact :: < u32 > :: encode ( & num. into ( ) )
107+ pub fn encode_as_compact < T > ( num : T ) -> PscVec < u8 >
108+ where
109+ for < ' a > parity_scale_codec:: CompactRef < ' a , T > : Encode + From < & ' a T > ,
110+ {
111+ parity_scale_codec:: Compact :: < T > :: encode ( & num. into ( ) )
218112}
0 commit comments