|
| 1 | +// Copyright (c) 2024-2025 RBB S.r.l |
| 2 | +// opensource@mintlayer.org |
| 3 | +// SPDX-License-Identifier: MIT |
| 4 | +// Licensed under the MIT License; |
| 5 | +// you may not use this file except in compliance with the License. |
| 6 | +// You may obtain a copy of the License at |
| 7 | +// |
| 8 | +// https://github.com/mintlayer/mintlayer-core-primitives/blob/master/LICENSE |
| 9 | +// |
| 10 | +// Unless required by applicable law or agreed to in writing, software |
| 11 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +// See the License for the specific language governing permissions and |
| 14 | +// limitations under the License. |
| 15 | + |
| 16 | +use crate::DestinationTag; |
| 17 | + |
| 18 | +#[derive(Clone, Copy, Debug, Eq, PartialEq)] |
| 19 | +pub enum CoinType { |
| 20 | + Mainnet, |
| 21 | + Testnet, |
| 22 | + Regtest, |
| 23 | + Signet, |
| 24 | +} |
| 25 | + |
| 26 | +impl CoinType { |
| 27 | + pub const fn coin_ticker(&self) -> &'static str { |
| 28 | + match self { |
| 29 | + Self::Mainnet => "ML", |
| 30 | + Self::Testnet => "TML", |
| 31 | + Self::Regtest => "RML", |
| 32 | + Self::Signet => "SML", |
| 33 | + } |
| 34 | + } |
| 35 | + |
| 36 | + pub const fn bip44_coin_type(&self) -> u32 { |
| 37 | + let hardened_bit = 1 << 31; |
| 38 | + match self { |
| 39 | + Self::Mainnet => 19788 + hardened_bit, |
| 40 | + Self::Testnet | Self::Regtest | Self::Signet => 1 + hardened_bit, |
| 41 | + } |
| 42 | + } |
| 43 | + |
| 44 | + pub const fn coin_decimals(&self) -> u8 { |
| 45 | + 11 |
| 46 | + } |
| 47 | + |
| 48 | + pub const fn address_prefix(&self, destination: DestinationTag) -> &'static str { |
| 49 | + match self { |
| 50 | + Self::Mainnet => match destination { |
| 51 | + DestinationTag::AnyoneCanSpend => "mxanyonecanspend", |
| 52 | + DestinationTag::PublicKeyHash => "mtc", |
| 53 | + DestinationTag::PublicKey => "mptc", |
| 54 | + DestinationTag::ScriptHash => "mstc", |
| 55 | + DestinationTag::ClassicMultisig => "mmtc", |
| 56 | + }, |
| 57 | + Self::Testnet => match destination { |
| 58 | + DestinationTag::AnyoneCanSpend => "txanyonecanspend", |
| 59 | + DestinationTag::PublicKeyHash => "tmt", |
| 60 | + DestinationTag::PublicKey => "tpmt", |
| 61 | + DestinationTag::ScriptHash => "tstc", |
| 62 | + DestinationTag::ClassicMultisig => "tmtc", |
| 63 | + }, |
| 64 | + Self::Regtest => match destination { |
| 65 | + DestinationTag::AnyoneCanSpend => "rxanyonecanspend", |
| 66 | + DestinationTag::PublicKeyHash => "rmt", |
| 67 | + DestinationTag::PublicKey => "rpmt", |
| 68 | + DestinationTag::ScriptHash => "rstc", |
| 69 | + DestinationTag::ClassicMultisig => "rmtc", |
| 70 | + }, |
| 71 | + Self::Signet => match destination { |
| 72 | + DestinationTag::AnyoneCanSpend => "sxanyonecanspend", |
| 73 | + DestinationTag::PublicKeyHash => "smt", |
| 74 | + DestinationTag::PublicKey => "spmt", |
| 75 | + DestinationTag::ScriptHash => "sstc", |
| 76 | + DestinationTag::ClassicMultisig => "smtc", |
| 77 | + }, |
| 78 | + } |
| 79 | + } |
| 80 | + |
| 81 | + pub const fn pool_id_address_prefix(&self) -> &'static str { |
| 82 | + match self { |
| 83 | + Self::Mainnet => "mpool", |
| 84 | + Self::Testnet => "tpool", |
| 85 | + Self::Regtest => "rpool", |
| 86 | + Self::Signet => "spool", |
| 87 | + } |
| 88 | + } |
| 89 | + |
| 90 | + pub const fn delegation_id_address_prefix(&self) -> &'static str { |
| 91 | + match self { |
| 92 | + Self::Mainnet => "mdelg", |
| 93 | + Self::Testnet => "tdelg", |
| 94 | + Self::Regtest => "rdelg", |
| 95 | + Self::Signet => "sdelg", |
| 96 | + } |
| 97 | + } |
| 98 | + |
| 99 | + pub const fn token_id_address_prefix(&self) -> &'static str { |
| 100 | + match self { |
| 101 | + Self::Mainnet => "mmltk", |
| 102 | + Self::Testnet => "tmltk", |
| 103 | + Self::Regtest => "rmltk", |
| 104 | + Self::Signet => "smltk", |
| 105 | + } |
| 106 | + } |
| 107 | + |
| 108 | + pub const fn order_id_address_prefix(&self) -> &'static str { |
| 109 | + match self { |
| 110 | + Self::Mainnet => "mordr", |
| 111 | + Self::Testnet => "tordr", |
| 112 | + Self::Regtest => "rordr", |
| 113 | + Self::Signet => "sordr", |
| 114 | + } |
| 115 | + } |
| 116 | + |
| 117 | + pub const fn vrf_public_key_address_prefix(&self) -> &'static str { |
| 118 | + match self { |
| 119 | + Self::Mainnet => "mvrfpk", |
| 120 | + Self::Testnet => "tvrfpk", |
| 121 | + Self::Regtest => "rvrfpk", |
| 122 | + Self::Signet => "svrfpk", |
| 123 | + } |
| 124 | + } |
| 125 | +} |
0 commit comments