Skip to content

Commit 8d8926a

Browse files
committed
fix comments
1 parent 6e3a9ca commit 8d8926a

4 files changed

Lines changed: 142 additions & 114 deletions

File tree

Cargo.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@ derive_more = { version = "2.0", default-features = false, features = [
1818
"debug",
1919
] }
2020
fixed-hash = { version = "0.8", default-features = false }
21+
22+
# Use the specific commit "5021525697edc0661591ebc71392c48d950a10b0",
23+
# which includes a fix for NanoX devices that do not support certain
24+
# atomic operations.
25+
#
26+
# Fix reference: https://github.com/paritytech/parity-scale-codec/pull/751
27+
# This fix should be included in releases after version 3.7.5.
2128
parity-scale-codec = { git = "https://github.com/paritytech/parity-scale-codec.git", rev = "5021525697edc0661591ebc71392c48d950a10b0", default-features = false, features = [
2229
"derive",
2330
] }

src/coin_type.rs

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
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::Destination;
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: &Destination) -> &'static str {
49+
match self {
50+
Self::Mainnet => match destination {
51+
Destination::AnyoneCanSpend => "mxanyonecanspend",
52+
Destination::PublicKeyHash(_) => "mtc",
53+
Destination::PublicKey(_) => "mptc",
54+
Destination::ScriptHash(_) => "mstc",
55+
Destination::ClassicMultisig(_) => "mmtc",
56+
},
57+
Self::Testnet => match destination {
58+
Destination::AnyoneCanSpend => "txanyonecanspend",
59+
Destination::PublicKeyHash(_) => "tmt",
60+
Destination::PublicKey(_) => "tpmt",
61+
Destination::ScriptHash(_) => "tstc",
62+
Destination::ClassicMultisig(_) => "tmtc",
63+
},
64+
Self::Regtest => match destination {
65+
Destination::AnyoneCanSpend => "rxanyonecanspend",
66+
Destination::PublicKeyHash(_) => "rmt",
67+
Destination::PublicKey(_) => "rpmt",
68+
Destination::ScriptHash(_) => "rstc",
69+
Destination::ClassicMultisig(_) => "rmtc",
70+
},
71+
Self::Signet => match destination {
72+
Destination::AnyoneCanSpend => "sxanyonecanspend",
73+
Destination::PublicKeyHash(_) => "smt",
74+
Destination::PublicKey(_) => "spmt",
75+
Destination::ScriptHash(_) => "sstc",
76+
Destination::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+
}

src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#![no_std]
1717

1818
mod accounts;
19+
mod coin_type;
1920
mod crypto;
2021
mod destination;
2122
mod id;
@@ -30,6 +31,7 @@ mod utxo_outpoint;
3031
mod tests;
3132

3233
pub use accounts::*;
34+
pub use coin_type::*;
3335
pub use crypto::*;
3436
pub use destination::*;
3537
pub use id::*;

src/misc.rs

Lines changed: 8 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
use parity_scale_codec::{Decode, DecodeAll, Encode};
1717

18-
use crate::{Destination, TokenId};
18+
use crate::TokenId;
1919

2020
pub 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)]
9393
pub 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-
20495
pub 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

Comments
 (0)