mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
chore: rearrange impl order (#1796)
This commit is contained in:
@ -259,22 +259,6 @@ pub struct NewPooledTransactionHashes68 {
|
||||
}
|
||||
|
||||
impl Encodable for NewPooledTransactionHashes68 {
|
||||
fn length(&self) -> usize {
|
||||
#[derive(RlpEncodable)]
|
||||
struct EncodableNewPooledTransactionHashes68<'a> {
|
||||
types: &'a [u8],
|
||||
sizes: &'a Vec<usize>,
|
||||
hashes: &'a Vec<H256>,
|
||||
}
|
||||
|
||||
let encodable = EncodableNewPooledTransactionHashes68 {
|
||||
types: &self.types[..],
|
||||
sizes: &self.sizes,
|
||||
hashes: &self.hashes,
|
||||
};
|
||||
|
||||
encodable.length()
|
||||
}
|
||||
fn encode(&self, out: &mut dyn bytes::BufMut) {
|
||||
#[derive(RlpEncodable)]
|
||||
struct EncodableNewPooledTransactionHashes68<'a> {
|
||||
@ -291,6 +275,22 @@ impl Encodable for NewPooledTransactionHashes68 {
|
||||
|
||||
encodable.encode(out);
|
||||
}
|
||||
fn length(&self) -> usize {
|
||||
#[derive(RlpEncodable)]
|
||||
struct EncodableNewPooledTransactionHashes68<'a> {
|
||||
types: &'a [u8],
|
||||
sizes: &'a Vec<usize>,
|
||||
hashes: &'a Vec<H256>,
|
||||
}
|
||||
|
||||
let encodable = EncodableNewPooledTransactionHashes68 {
|
||||
types: &self.types[..],
|
||||
sizes: &self.sizes,
|
||||
hashes: &self.hashes,
|
||||
};
|
||||
|
||||
encodable.length()
|
||||
}
|
||||
}
|
||||
|
||||
impl Decodable for NewPooledTransactionHashes68 {
|
||||
|
||||
@ -154,18 +154,18 @@ impl FromStr for Chain {
|
||||
}
|
||||
|
||||
impl Encodable for Chain {
|
||||
fn length(&self) -> usize {
|
||||
match self {
|
||||
Self::Named(chain) => u64::from(*chain).length(),
|
||||
Self::Id(id) => id.length(),
|
||||
}
|
||||
}
|
||||
fn encode(&self, out: &mut dyn reth_rlp::BufMut) {
|
||||
match self {
|
||||
Self::Named(chain) => u64::from(*chain).encode(out),
|
||||
Self::Id(id) => id.encode(out),
|
||||
}
|
||||
}
|
||||
fn length(&self) -> usize {
|
||||
match self {
|
||||
Self::Named(chain) => u64::from(*chain).length(),
|
||||
Self::Id(id) => id.length(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Decodable for Chain {
|
||||
|
||||
@ -146,12 +146,6 @@ impl GenesisAccount {
|
||||
}
|
||||
|
||||
impl Encodable for GenesisAccount {
|
||||
fn length(&self) -> usize {
|
||||
let len = self.payload_len();
|
||||
// RLP header length + payload length
|
||||
len + length_of_length(len)
|
||||
}
|
||||
|
||||
fn encode(&self, out: &mut dyn bytes::BufMut) {
|
||||
let header = RlpHeader { list: true, payload_length: self.payload_len() };
|
||||
header.encode(out);
|
||||
@ -174,6 +168,12 @@ impl Encodable for GenesisAccount {
|
||||
.encode(out);
|
||||
self.code.as_ref().map_or(KECCAK_EMPTY, keccak256).encode(out);
|
||||
}
|
||||
|
||||
fn length(&self) -> usize {
|
||||
let len = self.payload_len();
|
||||
// RLP header length + payload length
|
||||
len + length_of_length(len)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<EthersGenesisAccount> for GenesisAccount {
|
||||
|
||||
@ -106,6 +106,9 @@ impl Receipt {
|
||||
}
|
||||
|
||||
impl Encodable for Receipt {
|
||||
fn encode(&self, out: &mut dyn BufMut) {
|
||||
self.encode_inner(out, true)
|
||||
}
|
||||
fn length(&self) -> usize {
|
||||
let mut payload_len = self.receipt_length();
|
||||
// account for eip-2718 type prefix and set the list
|
||||
@ -117,9 +120,6 @@ impl Encodable for Receipt {
|
||||
|
||||
payload_len
|
||||
}
|
||||
fn encode(&self, out: &mut dyn BufMut) {
|
||||
self.encode_inner(out, true)
|
||||
}
|
||||
}
|
||||
|
||||
impl Decodable for Receipt {
|
||||
|
||||
@ -79,6 +79,13 @@ pub trait Encodable {
|
||||
}
|
||||
|
||||
impl<'a> Encodable for &'a [u8] {
|
||||
fn encode(&self, out: &mut dyn BufMut) {
|
||||
if self.len() != 1 || self[0] >= EMPTY_STRING_CODE {
|
||||
Header { list: false, payload_length: self.len() }.encode(out);
|
||||
}
|
||||
out.put_slice(self);
|
||||
}
|
||||
|
||||
fn length(&self) -> usize {
|
||||
let mut len = self.len();
|
||||
if self.len() != 1 || self[0] >= EMPTY_STRING_CODE {
|
||||
@ -86,23 +93,16 @@ impl<'a> Encodable for &'a [u8] {
|
||||
}
|
||||
len
|
||||
}
|
||||
|
||||
fn encode(&self, out: &mut dyn BufMut) {
|
||||
if self.len() != 1 || self[0] >= EMPTY_STRING_CODE {
|
||||
Header { list: false, payload_length: self.len() }.encode(out);
|
||||
}
|
||||
out.put_slice(self);
|
||||
}
|
||||
}
|
||||
|
||||
impl<const LEN: usize> Encodable for [u8; LEN] {
|
||||
fn length(&self) -> usize {
|
||||
(self as &[u8]).length()
|
||||
}
|
||||
|
||||
fn encode(&self, out: &mut dyn BufMut) {
|
||||
(self as &[u8]).encode(out)
|
||||
}
|
||||
|
||||
fn length(&self) -> usize {
|
||||
(self as &[u8]).length()
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl<const LEN: usize> MaxEncodedLenAssoc for [u8; LEN] {
|
||||
@ -164,13 +164,13 @@ encodable_uint!(u128);
|
||||
max_encoded_len_uint!(u128);
|
||||
|
||||
impl Encodable for bool {
|
||||
fn length(&self) -> usize {
|
||||
(*self as u8).length()
|
||||
}
|
||||
|
||||
fn encode(&self, out: &mut dyn BufMut) {
|
||||
(*self as u8).encode(out)
|
||||
}
|
||||
|
||||
fn length(&self) -> usize {
|
||||
(*self as u8).length()
|
||||
}
|
||||
}
|
||||
|
||||
impl_max_encoded_len!(bool, { <u8 as MaxEncodedLenAssoc>::LEN });
|
||||
@ -340,13 +340,13 @@ mod alloc_support {
|
||||
where
|
||||
T: Encodable,
|
||||
{
|
||||
fn length(&self) -> usize {
|
||||
list_length(self)
|
||||
}
|
||||
|
||||
fn encode(&self, out: &mut dyn BufMut) {
|
||||
encode_list(self, out)
|
||||
}
|
||||
|
||||
fn length(&self) -> usize {
|
||||
list_length(self)
|
||||
}
|
||||
}
|
||||
|
||||
impl Encodable for ::alloc::string::String {
|
||||
@ -583,7 +583,7 @@ mod tests {
|
||||
"0100020003000400050006000700080009000A0B4B000C000D000E010100020003000400050006000700080009000A0B4B000C000D000E01",
|
||||
16,
|
||||
)
|
||||
.unwrap(),
|
||||
.unwrap(),
|
||||
&hex!("b8380100020003000400050006000700080009000A0B4B000C000D000E010100020003000400050006000700080009000A0B4B000C000D000E01")[..],
|
||||
)])
|
||||
}
|
||||
|
||||
@ -83,18 +83,18 @@ impl TransactionKind {
|
||||
}
|
||||
|
||||
impl Encodable for TransactionKind {
|
||||
fn length(&self) -> usize {
|
||||
match self {
|
||||
TransactionKind::Call(to) => to.length(),
|
||||
TransactionKind::Create => ([]).length(),
|
||||
}
|
||||
}
|
||||
fn encode(&self, out: &mut dyn BufMut) {
|
||||
match self {
|
||||
TransactionKind::Call(to) => to.encode(out),
|
||||
TransactionKind::Create => ([]).encode(out),
|
||||
}
|
||||
}
|
||||
fn length(&self) -> usize {
|
||||
match self {
|
||||
TransactionKind::Call(to) => to.length(),
|
||||
TransactionKind::Create => ([]).length(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Decodable for TransactionKind {
|
||||
|
||||
Reference in New Issue
Block a user