Skip to content

Commit 0db43ee

Browse files
pgherveouatheiordian
authored
Remove From [u8; n] impl for uint types (#859)
* update uint and deps * Fix uppercase * Apply suggestions from code review Co-authored-by: Alexander Theißen <alex.theissen@me.com> * Update changelogs * Apply suggestions from code review * Apply suggestions from code review --------- Co-authored-by: Alexander Theißen <alex.theissen@me.com> Co-authored-by: ordian <write@reusable.software>
1 parent 701148e commit 0db43ee

13 files changed

Lines changed: 72 additions & 80 deletions

File tree

ethereum-types/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ The format is based on [Keep a Changelog].
55
[Keep a Changelog]: http://keepachangelog.com/en/1.0.0/
66

77
## [Unreleased]
8+
### Breaking
9+
- Updated `uint` to 0.10. [#859](https://github.com/paritytech/parity-common/pull/859)
810

911
## [0.14.1] - 2022-11-29
1012
- Added `if_ethbloom` conditional macro. [#682](https://github.com/paritytech/parity-common/pull/682)

ethereum-types/src/hash.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,12 @@ macro_rules! impl_uint_conversions {
7474

7575
fn from_uint(value: &$uint) -> Self {
7676
let mut ret = $hash::zero();
77-
value.to_big_endian(ret.as_bytes_mut());
77+
value.write_as_big_endian(ret.as_bytes_mut());
7878
ret
7979
}
8080

8181
fn into_uint(&self) -> $uint {
82-
$uint::from(self.as_ref() as &[u8])
82+
$uint::from_big_endian(self.as_ref() as &[u8])
8383
}
8484
}
8585
};

ethereum-types/src/uint.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@ mod tests {
102102
#[test]
103103
fn fixed_arrays_roundtrip() {
104104
let raw: U256 = "7094875209347850239487502394881".into();
105-
let array: [u8; 32] = raw.into();
106-
let new_raw = array.into();
105+
let array: [u8; 32] = raw.to_big_endian();
106+
let new_raw = U256::from_big_endian(&array);
107107

108108
assert_eq!(raw, new_raw);
109109
}

primitive-types/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ The format is based on [Keep a Changelog].
55
[Keep a Changelog]: http://keepachangelog.com/en/1.0.0/
66

77
## [Unreleased]
8+
### Breaking
9+
- Updated `uint` to 0.10. [#859](https://github.com/paritytech/parity-common/pull/859)
810

911
## [0.12.2] - 2023-10-10
1012
- Added `schemars` support via `json-schema` feature. [#785](https://github.com/paritytech/parity-common/pull/785)

primitive-types/impls/codec/src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ macro_rules! impl_uint_codec {
1919
($name: ident, $len: expr) => {
2020
impl $crate::codec::Encode for $name {
2121
fn using_encoded<R, F: FnOnce(&[u8]) -> R>(&self, f: F) -> R {
22-
let mut bytes = [0u8; $len * 8];
23-
self.to_little_endian(&mut bytes);
22+
let bytes = self.to_little_endian();
2423
bytes.using_encoded(f)
2524
}
2625
}

primitive-types/impls/rlp/src/lib.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ macro_rules! impl_uint_rlp {
2323
impl $crate::rlp::Encodable for $name {
2424
fn rlp_append(&self, s: &mut $crate::rlp::RlpStream) {
2525
let leading_empty_bytes = $size * 8 - (self.bits() + 7) / 8;
26-
let mut buffer = [0u8; $size * 8];
27-
self.to_big_endian(&mut buffer);
26+
let buffer = self.to_big_endian();
2827
s.encoder().encode_value(&buffer[leading_empty_bytes..]);
2928
}
3029
}
@@ -35,7 +34,7 @@ macro_rules! impl_uint_rlp {
3534
if !bytes.is_empty() && bytes[0] == 0 {
3635
Err($crate::rlp::DecoderError::RlpInvalidIndirection)
3736
} else if bytes.len() <= $size * 8 {
38-
Ok($name::from(bytes))
37+
Ok($name::from_big_endian(bytes))
3938
} else {
4039
Err($crate::rlp::DecoderError::RlpIsTooBig)
4140
}

primitive-types/impls/serde/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ The format is based on [Keep a Changelog].
44

55
[Keep a Changelog]: http://keepachangelog.com/en/1.0.0/
66

7+
## [Unreleased]
8+
### Breaking
9+
- Updated `uint` to 0.10. [#859](https://github.com/paritytech/parity-common/pull/859)
10+
711
## [0.4.0] - 2022-09-02
812
- Support deserializing H256 et al from bytes or sequences of bytes, too. [#668](https://github.com/paritytech/parity-common/pull/668)
913
- Support deserializing H256 et al from newtype structs containing anything compatible, too. [#672](https://github.com/paritytech/parity-common/pull/672)

primitive-types/impls/serde/src/lib.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ macro_rules! impl_uint_serde {
3232
S: $crate::serde::Serializer,
3333
{
3434
let mut slice = [0u8; 2 + 2 * $len * 8];
35-
let mut bytes = [0u8; $len * 8];
36-
self.to_big_endian(&mut bytes);
35+
let bytes = self.to_big_endian();
3736
$crate::serialize::serialize_uint(&mut slice, &bytes, serializer)
3837
}
3938
}
@@ -48,7 +47,7 @@ macro_rules! impl_uint_serde {
4847
deserializer,
4948
$crate::serialize::ExpectedLen::Between(0, &mut bytes),
5049
)?;
51-
Ok(bytes[0..wrote].into())
50+
Ok(Self::from_big_endian(&bytes[0..wrote]))
5251
}
5352
}
5453
};

rlp/tests/tests.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ fn encode_u256() {
226226
ETestPair::from((U256::from(0x0100_0000_u64), hex!("8401000000"))),
227227
ETestPair::from((U256::from(0xffff_ffff_u64), hex!("84ffffffff"))),
228228
ETestPair::from((
229-
hex!(" 8090a0b0c0d0e0f00910203040506077000000000000000100000000000012f0").into(),
229+
U256::from_big_endian(&hex!(" 8090a0b0c0d0e0f00910203040506077000000000000000100000000000012f0")),
230230
hex!("a08090a0b0c0d0e0f00910203040506077000000000000000100000000000012f0"),
231231
)),
232232
];
@@ -482,7 +482,7 @@ fn decode_untrusted_u256() {
482482
DTestPair::from((U256::from(0x0100_0000_u64), hex!("8401000000"))),
483483
DTestPair::from((U256::from(0xffff_ffff_u64), hex!("84ffffffff"))),
484484
DTestPair::from((
485-
hex!(" 8090a0b0c0d0e0f00910203040506077000000000000000100000000000012f0").into(),
485+
U256::from_big_endian(&hex!(" 8090a0b0c0d0e0f00910203040506077000000000000000100000000000012f0")),
486486
hex!("a08090a0b0c0d0e0f00910203040506077000000000000000100000000000012f0"),
487487
)),
488488
];

uint/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ The format is based on [Keep a Changelog].
55
[Keep a Changelog]: http://keepachangelog.com/en/1.0.0/
66

77
## [Unreleased]
8+
### Breaking
9+
- Removed From<[u8; n]> conversions, renamed `to_big_endian` / `to_little_endian` to write_as_*, and made them return byte arrays. [#859](https://github.com/paritytech/parity-common/pull/859)
810

911
## [0.9.5] - 2022-11-29
1012
- Implemented bitwise assign traits. [#690](https://github.com/paritytech/parity-common/pull/690)

0 commit comments

Comments
 (0)