mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
32 lines
850 B
Rust
32 lines
850 B
Rust
//! 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 {
|
|
Self::Create => 0,
|
|
Self::Call(address) => {
|
|
address.to_compact(buf);
|
|
1
|
|
}
|
|
}
|
|
}
|
|
fn from_compact(buf: &[u8], identifier: usize) -> (Self, &[u8]) {
|
|
match identifier {
|
|
0 => (Self::Create, buf),
|
|
1 => {
|
|
let (addr, buf) = Address::from_compact(buf, buf.len());
|
|
(addr.into(), buf)
|
|
}
|
|
_ => {
|
|
unreachable!("Junk data in database: unknown TransactionKind variant",)
|
|
}
|
|
}
|
|
}
|
|
}
|