mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
Validation on decoding NewPooledTransactions68 (#6090)
This commit is contained in:
@ -283,10 +283,22 @@ pub struct NewPooledTransactionHashes68 {
|
||||
/// instead use the [`Encodable`](alloy_rlp::Encodable) and [`Decodable`](alloy_rlp::Decodable)
|
||||
/// implementations for `&[u8]` instead, which encodes into a RLP string, and expects an RLP
|
||||
/// string when decoding.
|
||||
#[cfg_attr(
|
||||
any(test, feature = "arbitrary"),
|
||||
proptest(strategy = "proptest::collection::vec(proptest::arbitrary::any::<u8>(), 100)")
|
||||
)]
|
||||
pub types: Vec<u8>,
|
||||
/// Transaction sizes for new transactions that have appeared on the network.
|
||||
#[cfg_attr(
|
||||
any(test, feature = "arbitrary"),
|
||||
proptest(strategy = "proptest::collection::vec(proptest::arbitrary::any::<usize>(), 100)")
|
||||
)]
|
||||
pub sizes: Vec<usize>,
|
||||
/// Transaction hashes for new transactions that have appeared on the network.
|
||||
#[cfg_attr(
|
||||
any(test, feature = "arbitrary"),
|
||||
proptest(strategy = "proptest::collection::vec(proptest::arbitrary::any::<B256>(), 100)")
|
||||
)]
|
||||
pub hashes: Vec<B256>,
|
||||
}
|
||||
|
||||
@ -342,7 +354,26 @@ impl Decodable for NewPooledTransactionHashes68 {
|
||||
}
|
||||
|
||||
let encodable = EncodableNewPooledTransactionHashes68::decode(buf)?;
|
||||
Ok(Self { types: encodable.types.into(), sizes: encodable.sizes, hashes: encodable.hashes })
|
||||
let msg = Self {
|
||||
types: encodable.types.into(),
|
||||
sizes: encodable.sizes,
|
||||
hashes: encodable.hashes,
|
||||
};
|
||||
|
||||
if msg.hashes.len() != msg.types.len() {
|
||||
return Err(alloy_rlp::Error::ListLengthMismatch {
|
||||
expected: msg.hashes.len(),
|
||||
got: msg.types.len(),
|
||||
})
|
||||
}
|
||||
if msg.hashes.len() != msg.sizes.len() {
|
||||
return Err(alloy_rlp::Error::ListLengthMismatch {
|
||||
expected: msg.hashes.len(),
|
||||
got: msg.sizes.len(),
|
||||
})
|
||||
}
|
||||
|
||||
Ok(msg)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user