Skip to content

Commit ff53e53

Browse files
committed
Use u32/u64 as underlying type for unsigneds
1 parent 9c1d983 commit ff53e53

File tree

5 files changed

+36
-10
lines changed

5 files changed

+36
-10
lines changed

mina-p2p-messages/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ edition = "2021"
99
serde = { version = "1.0.142", features = ["derive"] }
1010
serde_json = { version = "1.0.83" }
1111
hex = "0.4.3"
12-
binprot = { git = "https://github.com/openmina/binprot-rs", rev = "dfbd3bbda8b2681d86ac73065523c658ee31d45d" }
13-
binprot_derive = { git = "https://github.com/openmina/binprot-rs", rev = "dfbd3bbda8b2681d86ac73065523c658ee31d45d" }
12+
binprot = { git = "https://github.com/openmina/binprot-rs", rev = "3f29b25" }
13+
binprot_derive = { git = "https://github.com/openmina/binprot-rs", rev = "3f29b25" }
1414
thiserror = "1.0.32"
1515
derive_more = "0.99.17"
1616
bs58 = { version = "0.4", features = ["check"] }

mina-p2p-messages/src/hash_input.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use o1_utils::FieldHelpers;
99
use crate::{
1010
b58::Base58CheckOfBinProt,
1111
bigint::BigInt,
12-
number::{Int32, Int64},
12+
number::{Int32, Int64, UInt32, UInt64},
1313
pseq::PaddedSeq,
1414
};
1515

@@ -41,6 +41,18 @@ impl ToInput for Int64 {
4141
}
4242
}
4343

44+
impl ToInput for UInt32 {
45+
fn to_input(&self, inputs: &mut Inputs) {
46+
inputs.append_u32(self.as_u32())
47+
}
48+
}
49+
50+
impl ToInput for UInt64 {
51+
fn to_input(&self, inputs: &mut Inputs) {
52+
inputs.append_u64(self.as_u64())
53+
}
54+
}
55+
4456
impl<T, D> ToInput for Vec<D>
4557
where
4658
D: Deref<Target = T>,

mina-p2p-messages/src/number.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ impl<T: std::fmt::Debug> std::fmt::Debug for Number<T> {
1616
}
1717

1818
pub type Int32 = Number<i32>;
19+
pub type UInt32 = Number<u32>;
1920
pub type Int64 = Number<i64>;
21+
pub type UInt64 = Number<u64>;
2022
pub type Float64 = Number<f64>;
2123

2224
impl Int32 {
@@ -31,6 +33,18 @@ impl Int64 {
3133
}
3234
}
3335

36+
impl UInt32 {
37+
pub fn as_u32(&self) -> u32 {
38+
self.0
39+
}
40+
}
41+
42+
impl UInt64 {
43+
pub fn as_u64(&self) -> u64 {
44+
self.0
45+
}
46+
}
47+
3448
impl From<u32> for Number<i32> {
3549
fn from(value: u32) -> Self {
3650
Self(value as i32)

mina-p2p-messages/src/v2/generated.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -792,7 +792,7 @@ pub struct NonZeroCurvePointUncompressedStableV1 {
792792
/// Gid: `125`
793793
/// Location: [src/int64.ml:6:6](https://github.com/MinaProtocol/mina/blob/14047c5551/src/int64.ml#L6)
794794
#[derive(Clone, PartialEq, Serialize, Deserialize, BinProtRead, BinProtWrite, Deref)]
795-
pub struct UnsignedExtendedUInt64Int64ForVersionTagsStableV1(pub crate::number::Int64);
795+
pub struct UnsignedExtendedUInt64Int64ForVersionTagsStableV1(pub crate::number::UInt64);
796796

797797
/// **OCaml name**: `Unsigned_extended.UInt32.Stable.V1`
798798
///
@@ -803,7 +803,7 @@ pub struct UnsignedExtendedUInt64Int64ForVersionTagsStableV1(pub crate::number::
803803
/// Gid: `119`
804804
/// Location: [src/int32.ml:6:6](https://github.com/MinaProtocol/mina/blob/14047c5551/src/int32.ml#L6)
805805
#[derive(Clone, PartialEq, Serialize, Deserialize, BinProtRead, BinProtWrite, Deref, Default)]
806-
pub struct UnsignedExtendedUInt32StableV1(pub crate::number::Int32);
806+
pub struct UnsignedExtendedUInt32StableV1(pub crate::number::UInt32);
807807

808808
/// **OCaml name**: `Mina_numbers__Nat.Make32.Stable.V1`
809809
///

mina-p2p-messages/src/v2/hashing.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -204,19 +204,19 @@ mod tests {
204204
amount: u64,
205205
fee: u64,
206206
nonce: u32,
207-
valid_until: i32,
207+
valid_until: u32,
208208
) -> String {
209209
use crate::number::Number;
210210
use crate::string::CharString;
211211

212212
let from = pub_key(from);
213213
let to = pub_key(to);
214214

215-
let v = Number(fee as i64);
215+
let v = Number(fee);
216216
let v = generated::UnsignedExtendedUInt64Int64ForVersionTagsStableV1(v);
217217
let fee = generated::CurrencyFeeStableV1(v);
218218

219-
let nonce = generated::UnsignedExtendedUInt32StableV1(Number(nonce as i32));
219+
let nonce = generated::UnsignedExtendedUInt32StableV1(Number(nonce));
220220

221221
let valid_until = generated::UnsignedExtendedUInt32StableV1(Number(valid_until));
222222

@@ -236,7 +236,7 @@ mod tests {
236236
memo,
237237
};
238238

239-
let v = Number(amount as i64);
239+
let v = Number(amount);
240240
let v = generated::UnsignedExtendedUInt64Int64ForVersionTagsStableV1(v);
241241
let amount = generated::CurrencyAmountStableV1(v);
242242

@@ -287,7 +287,7 @@ mod tests {
287287
1089541195,
288288
89541195,
289289
26100,
290-
-1
290+
u32::MAX,
291291
),
292292
expected_hash
293293
)

0 commit comments

Comments
 (0)