feat: add native compact impl for alloy TxKind (#7686)

This commit is contained in:
Matthias Seitz
2024-04-16 22:45:01 +02:00
committed by GitHub
parent bb67c40d56
commit d39a8d7404
3 changed files with 34 additions and 0 deletions

View File

@ -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;

View File

@ -1,2 +1,3 @@
mod access_list;
mod log;
mod txkind;

View 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",)
}
}
}
}