1313// See the License for the specific language governing permissions and
1414// limitations under the License.
1515
16- use parity_scale_codec:: { Decode , Encode } ;
16+ use parity_scale_codec:: { Decode , DecodeAll , Encode } ;
1717
18- use crate :: TokenId ;
18+ use crate :: { Destination , TokenId } ;
1919
2020pub type PscVec < T > = parity_scale_codec:: alloc:: vec:: Vec < T > ;
2121
@@ -32,6 +32,8 @@ pub struct Amount {
3232}
3333
3434impl Amount {
35+ pub const ZERO : Self = Self :: from_atoms ( 0 ) ;
36+
3537 pub const fn from_atoms ( v : AmountUIntType ) -> Self {
3638 Amount { atoms : v }
3739 }
@@ -89,3 +91,128 @@ pub type SecondsCountUIntType = u64;
8991
9092#[ derive( Debug , Clone , Copy , PartialOrd , Ord , PartialEq , Eq , Encode , Decode ) ]
9193pub struct SecondsCount ( #[ codec( compact) ] pub SecondsCountUIntType ) ;
94+
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+
204+ pub fn encode < T : Encode > ( t : & T ) -> PscVec < u8 > {
205+ t. encode ( )
206+ }
207+
208+ pub fn encode_to < T : Encode > ( t : & T , buf : & mut PscVec < u8 > ) {
209+ t. encode_to ( buf)
210+ }
211+
212+ pub fn decode_all < T : Decode > ( mut bytes : & [ u8 ] ) -> Option < T > {
213+ T :: decode_all ( & mut bytes) . ok ( )
214+ }
215+
216+ pub fn encode_as_compact ( num : u32 ) -> PscVec < u8 > {
217+ parity_scale_codec:: Compact :: < u32 > :: encode ( & num. into ( ) )
218+ }
0 commit comments