mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
feat: add native compact impl for alloy TxKind (#7686)
This commit is contained in:
@ -1,3 +1,5 @@
|
||||
//! Native Compact codec impl for primitive alloy log types.
|
||||
|
||||
use crate::Compact;
|
||||
use alloy_primitives::{Address, Bytes, Log, LogData};
|
||||
use bytes::BufMut;
|
||||
|
||||
@ -1,2 +1,3 @@
|
||||
mod access_list;
|
||||
mod log;
|
||||
mod txkind;
|
||||
|
||||
31
crates/storage/codecs/src/alloy/txkind.rs
Normal file
31
crates/storage/codecs/src/alloy/txkind.rs
Normal file
@ -0,0 +1,31 @@
|
||||
//! Native Compact codec impl for primitive alloy [TxKind].
|
||||
|
||||
use crate::Compact;
|
||||
use alloy_primitives::{Address, TxKind};
|
||||
|
||||
impl Compact for TxKind {
|
||||
fn to_compact<B>(self, buf: &mut B) -> usize
|
||||
where
|
||||
B: bytes::BufMut + AsMut<[u8]>,
|
||||
{
|
||||
match self {
|
||||
TxKind::Create => 0,
|
||||
TxKind::Call(address) => {
|
||||
address.to_compact(buf);
|
||||
1
|
||||
}
|
||||
}
|
||||
}
|
||||
fn from_compact(buf: &[u8], identifier: usize) -> (Self, &[u8]) {
|
||||
match identifier {
|
||||
0 => (TxKind::Create, buf),
|
||||
1 => {
|
||||
let (addr, buf) = Address::from_compact(buf, buf.len());
|
||||
(TxKind::Call(addr), buf)
|
||||
}
|
||||
_ => {
|
||||
unreachable!("Junk data in database: unknown TransactionKind variant",)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user