pub struct PaymentSphinxCodec;Expand description
Codec for payment onion packets (used by the outer payment onion layer).
Implementations§
Source§impl PaymentSphinxCodec
impl PaymentSphinxCodec
Sourcepub fn pack_hop_data(version: u8, hop_data: &PaymentHopData) -> Vec<u8> ⓘ
pub fn pack_hop_data(version: u8, hop_data: &PaymentHopData) -> Vec<u8> ⓘ
Packs hop data according to the specified onion packet version.
- Version 0: Prepends u64 BE length header before molecule data.
- Version 1: Returns molecule-serialized data directly (uses molecule’s native u32 LE length).
Sourcepub fn unpack_hop_data(version: u8, buf: &[u8]) -> Option<PaymentHopData>
pub fn unpack_hop_data(version: u8, buf: &[u8]) -> Option<PaymentHopData>
Unpacks hop data according to the specified onion packet version.
- Version 0: Skips u64 BE length header, deserializes molecule data.
- Version 1: Deserializes molecule data directly (using molecule’s u32 LE length).
- Unknown versions: Returns None to fail fast and avoid silent misparsing.
Trait Implementations§
Source§impl SphinxOnionCodec for PaymentSphinxCodec
impl SphinxOnionCodec for PaymentSphinxCodec
const PACKET_DATA_LEN: usize = PACKET_DATA_LEN
Source§const CURRENT_VERSION: u8 = ONION_PACKET_VERSION_V1
const CURRENT_VERSION: u8 = ONION_PACKET_VERSION_V1
The onion packet version used when creating new packets.
type Decoded = PaymentHopData
type Current = CurrentPaymentHopData
Source§fn pack(decoded: &Self::Decoded) -> Vec<u8> ⓘ
fn pack(decoded: &Self::Decoded) -> Vec<u8> ⓘ
Packs the decoded data for transmission. Must use
CURRENT_VERSION format.Source§fn unpack(version: u8, buf: &[u8]) -> Option<Self::Decoded>
fn unpack(version: u8, buf: &[u8]) -> Option<Self::Decoded>
Unpacks data received from the network. Must handle all versions allowed by
is_version_allowed.fn to_current(decoded: Self::Decoded) -> Self::Current
Source§fn is_version_allowed(version: u8) -> bool
fn is_version_allowed(version: u8) -> bool
Returns true if the given version is allowed for this codec.
Auto Trait Implementations§
impl Freeze for PaymentSphinxCodec
impl RefUnwindSafe for PaymentSphinxCodec
impl Send for PaymentSphinxCodec
impl Sync for PaymentSphinxCodec
impl Unpin for PaymentSphinxCodec
impl UnsafeUnpin for PaymentSphinxCodec
impl UnwindSafe for PaymentSphinxCodec
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more