hop-sdk 0.1.0

Client SDK for the Polkadot HOP protocol
Documentation
use crate::errors::HopError;
use crate::internal::ticket_internals::TICKET_BYTE_LEN;

pub struct HopTicket {
    bytes: [u8; TICKET_BYTE_LEN],
}

impl HopTicket {
    pub fn from_raw(bytes: [u8; TICKET_BYTE_LEN]) -> Self {
        Self { bytes }
    }

    pub fn encode(&self) -> Vec<u8> {
        self.bytes.to_vec()
    }

    pub fn decode(data: Vec<u8>) -> Result<Self, HopError> {
        let bytes: [u8; TICKET_BYTE_LEN] = data.try_into().map_err(|v: Vec<u8>| {
            HopError::InvalidTicket(format!(
                "Expected {} bytes, got {}",
                TICKET_BYTE_LEN,
                v.len()
            ))
        })?;
        Ok(Self { bytes })
    }

    pub fn raw(&self) -> &[u8; TICKET_BYTE_LEN] {
        &self.bytes
    }
}