use super::blockchain::*;
use molecule::prelude::*;
#[derive(Clone)]
pub struct PaymentHash(molecule::bytes::Bytes);
impl ::core::fmt::LowerHex for PaymentHash {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
use molecule::hex_string;
if f.alternate() {
write!(f, "0x")?;
}
write!(f, "{}", hex_string(self.as_slice()))
}
}
impl ::core::fmt::Debug for PaymentHash {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
write!(f, "{}({:#x})", Self::NAME, self)
}
}
impl ::core::fmt::Display for PaymentHash {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
use molecule::hex_string;
let raw_data = hex_string(&self.raw_data());
write!(f, "{}(0x{})", Self::NAME, raw_data)
}
}
impl ::core::default::Default for PaymentHash {
fn default() -> Self {
let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE);
PaymentHash::new_unchecked(v)
}
}
impl PaymentHash {
const DEFAULT_VALUE: [u8; 32] = [
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0,
];
pub const TOTAL_SIZE: usize = 32;
pub const ITEM_SIZE: usize = 1;
pub const ITEM_COUNT: usize = 32;
pub fn nth0(&self) -> Byte {
Byte::new_unchecked(self.0.slice(0..1))
}
pub fn nth1(&self) -> Byte {
Byte::new_unchecked(self.0.slice(1..2))
}
pub fn nth2(&self) -> Byte {
Byte::new_unchecked(self.0.slice(2..3))
}
pub fn nth3(&self) -> Byte {
Byte::new_unchecked(self.0.slice(3..4))
}
pub fn nth4(&self) -> Byte {
Byte::new_unchecked(self.0.slice(4..5))
}
pub fn nth5(&self) -> Byte {
Byte::new_unchecked(self.0.slice(5..6))
}
pub fn nth6(&self) -> Byte {
Byte::new_unchecked(self.0.slice(6..7))
}
pub fn nth7(&self) -> Byte {
Byte::new_unchecked(self.0.slice(7..8))
}
pub fn nth8(&self) -> Byte {
Byte::new_unchecked(self.0.slice(8..9))
}
pub fn nth9(&self) -> Byte {
Byte::new_unchecked(self.0.slice(9..10))
}
pub fn nth10(&self) -> Byte {
Byte::new_unchecked(self.0.slice(10..11))
}
pub fn nth11(&self) -> Byte {
Byte::new_unchecked(self.0.slice(11..12))
}
pub fn nth12(&self) -> Byte {
Byte::new_unchecked(self.0.slice(12..13))
}
pub fn nth13(&self) -> Byte {
Byte::new_unchecked(self.0.slice(13..14))
}
pub fn nth14(&self) -> Byte {
Byte::new_unchecked(self.0.slice(14..15))
}
pub fn nth15(&self) -> Byte {
Byte::new_unchecked(self.0.slice(15..16))
}
pub fn nth16(&self) -> Byte {
Byte::new_unchecked(self.0.slice(16..17))
}
pub fn nth17(&self) -> Byte {
Byte::new_unchecked(self.0.slice(17..18))
}
pub fn nth18(&self) -> Byte {
Byte::new_unchecked(self.0.slice(18..19))
}
pub fn nth19(&self) -> Byte {
Byte::new_unchecked(self.0.slice(19..20))
}
pub fn nth20(&self) -> Byte {
Byte::new_unchecked(self.0.slice(20..21))
}
pub fn nth21(&self) -> Byte {
Byte::new_unchecked(self.0.slice(21..22))
}
pub fn nth22(&self) -> Byte {
Byte::new_unchecked(self.0.slice(22..23))
}
pub fn nth23(&self) -> Byte {
Byte::new_unchecked(self.0.slice(23..24))
}
pub fn nth24(&self) -> Byte {
Byte::new_unchecked(self.0.slice(24..25))
}
pub fn nth25(&self) -> Byte {
Byte::new_unchecked(self.0.slice(25..26))
}
pub fn nth26(&self) -> Byte {
Byte::new_unchecked(self.0.slice(26..27))
}
pub fn nth27(&self) -> Byte {
Byte::new_unchecked(self.0.slice(27..28))
}
pub fn nth28(&self) -> Byte {
Byte::new_unchecked(self.0.slice(28..29))
}
pub fn nth29(&self) -> Byte {
Byte::new_unchecked(self.0.slice(29..30))
}
pub fn nth30(&self) -> Byte {
Byte::new_unchecked(self.0.slice(30..31))
}
pub fn nth31(&self) -> Byte {
Byte::new_unchecked(self.0.slice(31..32))
}
pub fn raw_data(&self) -> molecule::bytes::Bytes {
self.as_bytes()
}
pub fn as_reader<'r>(&'r self) -> PaymentHashReader<'r> {
PaymentHashReader::new_unchecked(self.as_slice())
}
}
impl molecule::prelude::Entity for PaymentHash {
type Builder = PaymentHashBuilder;
const NAME: &'static str = "PaymentHash";
fn new_unchecked(data: molecule::bytes::Bytes) -> Self {
PaymentHash(data)
}
fn as_bytes(&self) -> molecule::bytes::Bytes {
self.0.clone()
}
fn as_slice(&self) -> &[u8] {
&self.0[..]
}
fn from_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
PaymentHashReader::from_slice(slice).map(|reader| reader.to_entity())
}
fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
PaymentHashReader::from_compatible_slice(slice).map(|reader| reader.to_entity())
}
fn new_builder() -> Self::Builder {
::core::default::Default::default()
}
fn as_builder(self) -> Self::Builder {
Self::new_builder().set([
self.nth0(),
self.nth1(),
self.nth2(),
self.nth3(),
self.nth4(),
self.nth5(),
self.nth6(),
self.nth7(),
self.nth8(),
self.nth9(),
self.nth10(),
self.nth11(),
self.nth12(),
self.nth13(),
self.nth14(),
self.nth15(),
self.nth16(),
self.nth17(),
self.nth18(),
self.nth19(),
self.nth20(),
self.nth21(),
self.nth22(),
self.nth23(),
self.nth24(),
self.nth25(),
self.nth26(),
self.nth27(),
self.nth28(),
self.nth29(),
self.nth30(),
self.nth31(),
])
}
}
#[derive(Clone, Copy)]
pub struct PaymentHashReader<'r>(&'r [u8]);
impl<'r> ::core::fmt::LowerHex for PaymentHashReader<'r> {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
use molecule::hex_string;
if f.alternate() {
write!(f, "0x")?;
}
write!(f, "{}", hex_string(self.as_slice()))
}
}
impl<'r> ::core::fmt::Debug for PaymentHashReader<'r> {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
write!(f, "{}({:#x})", Self::NAME, self)
}
}
impl<'r> ::core::fmt::Display for PaymentHashReader<'r> {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
use molecule::hex_string;
let raw_data = hex_string(&self.raw_data());
write!(f, "{}(0x{})", Self::NAME, raw_data)
}
}
impl<'r> PaymentHashReader<'r> {
pub const TOTAL_SIZE: usize = 32;
pub const ITEM_SIZE: usize = 1;
pub const ITEM_COUNT: usize = 32;
pub fn nth0(&self) -> ByteReader<'r> {
ByteReader::new_unchecked(&self.as_slice()[0..1])
}
pub fn nth1(&self) -> ByteReader<'r> {
ByteReader::new_unchecked(&self.as_slice()[1..2])
}
pub fn nth2(&self) -> ByteReader<'r> {
ByteReader::new_unchecked(&self.as_slice()[2..3])
}
pub fn nth3(&self) -> ByteReader<'r> {
ByteReader::new_unchecked(&self.as_slice()[3..4])
}
pub fn nth4(&self) -> ByteReader<'r> {
ByteReader::new_unchecked(&self.as_slice()[4..5])
}
pub fn nth5(&self) -> ByteReader<'r> {
ByteReader::new_unchecked(&self.as_slice()[5..6])
}
pub fn nth6(&self) -> ByteReader<'r> {
ByteReader::new_unchecked(&self.as_slice()[6..7])
}
pub fn nth7(&self) -> ByteReader<'r> {
ByteReader::new_unchecked(&self.as_slice()[7..8])
}
pub fn nth8(&self) -> ByteReader<'r> {
ByteReader::new_unchecked(&self.as_slice()[8..9])
}
pub fn nth9(&self) -> ByteReader<'r> {
ByteReader::new_unchecked(&self.as_slice()[9..10])
}
pub fn nth10(&self) -> ByteReader<'r> {
ByteReader::new_unchecked(&self.as_slice()[10..11])
}
pub fn nth11(&self) -> ByteReader<'r> {
ByteReader::new_unchecked(&self.as_slice()[11..12])
}
pub fn nth12(&self) -> ByteReader<'r> {
ByteReader::new_unchecked(&self.as_slice()[12..13])
}
pub fn nth13(&self) -> ByteReader<'r> {
ByteReader::new_unchecked(&self.as_slice()[13..14])
}
pub fn nth14(&self) -> ByteReader<'r> {
ByteReader::new_unchecked(&self.as_slice()[14..15])
}
pub fn nth15(&self) -> ByteReader<'r> {
ByteReader::new_unchecked(&self.as_slice()[15..16])
}
pub fn nth16(&self) -> ByteReader<'r> {
ByteReader::new_unchecked(&self.as_slice()[16..17])
}
pub fn nth17(&self) -> ByteReader<'r> {
ByteReader::new_unchecked(&self.as_slice()[17..18])
}
pub fn nth18(&self) -> ByteReader<'r> {
ByteReader::new_unchecked(&self.as_slice()[18..19])
}
pub fn nth19(&self) -> ByteReader<'r> {
ByteReader::new_unchecked(&self.as_slice()[19..20])
}
pub fn nth20(&self) -> ByteReader<'r> {
ByteReader::new_unchecked(&self.as_slice()[20..21])
}
pub fn nth21(&self) -> ByteReader<'r> {
ByteReader::new_unchecked(&self.as_slice()[21..22])
}
pub fn nth22(&self) -> ByteReader<'r> {
ByteReader::new_unchecked(&self.as_slice()[22..23])
}
pub fn nth23(&self) -> ByteReader<'r> {
ByteReader::new_unchecked(&self.as_slice()[23..24])
}
pub fn nth24(&self) -> ByteReader<'r> {
ByteReader::new_unchecked(&self.as_slice()[24..25])
}
pub fn nth25(&self) -> ByteReader<'r> {
ByteReader::new_unchecked(&self.as_slice()[25..26])
}
pub fn nth26(&self) -> ByteReader<'r> {
ByteReader::new_unchecked(&self.as_slice()[26..27])
}
pub fn nth27(&self) -> ByteReader<'r> {
ByteReader::new_unchecked(&self.as_slice()[27..28])
}
pub fn nth28(&self) -> ByteReader<'r> {
ByteReader::new_unchecked(&self.as_slice()[28..29])
}
pub fn nth29(&self) -> ByteReader<'r> {
ByteReader::new_unchecked(&self.as_slice()[29..30])
}
pub fn nth30(&self) -> ByteReader<'r> {
ByteReader::new_unchecked(&self.as_slice()[30..31])
}
pub fn nth31(&self) -> ByteReader<'r> {
ByteReader::new_unchecked(&self.as_slice()[31..32])
}
pub fn raw_data(&self) -> &'r [u8] {
self.as_slice()
}
}
impl<'r> molecule::prelude::Reader<'r> for PaymentHashReader<'r> {
type Entity = PaymentHash;
const NAME: &'static str = "PaymentHashReader";
fn to_entity(&self) -> Self::Entity {
Self::Entity::new_unchecked(self.as_slice().to_owned().into())
}
fn new_unchecked(slice: &'r [u8]) -> Self {
PaymentHashReader(slice)
}
fn as_slice(&self) -> &'r [u8] {
self.0
}
fn verify(slice: &[u8], _compatible: bool) -> molecule::error::VerificationResult<()> {
use molecule::verification_error as ve;
let slice_len = slice.len();
if slice_len != Self::TOTAL_SIZE {
return ve!(Self, TotalSizeNotMatch, Self::TOTAL_SIZE, slice_len);
}
Ok(())
}
}
#[derive(Clone)]
pub struct PaymentHashBuilder(pub(crate) [Byte; 32]);
impl ::core::fmt::Debug for PaymentHashBuilder {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
write!(f, "{}({:?})", Self::NAME, &self.0[..])
}
}
impl ::core::default::Default for PaymentHashBuilder {
fn default() -> Self {
PaymentHashBuilder([
Byte::default(),
Byte::default(),
Byte::default(),
Byte::default(),
Byte::default(),
Byte::default(),
Byte::default(),
Byte::default(),
Byte::default(),
Byte::default(),
Byte::default(),
Byte::default(),
Byte::default(),
Byte::default(),
Byte::default(),
Byte::default(),
Byte::default(),
Byte::default(),
Byte::default(),
Byte::default(),
Byte::default(),
Byte::default(),
Byte::default(),
Byte::default(),
Byte::default(),
Byte::default(),
Byte::default(),
Byte::default(),
Byte::default(),
Byte::default(),
Byte::default(),
Byte::default(),
])
}
}
impl PaymentHashBuilder {
pub const TOTAL_SIZE: usize = 32;
pub const ITEM_SIZE: usize = 1;
pub const ITEM_COUNT: usize = 32;
pub fn set(mut self, v: [Byte; 32]) -> Self {
self.0 = v;
self
}
pub fn nth0(mut self, v: Byte) -> Self {
self.0[0] = v;
self
}
pub fn nth1(mut self, v: Byte) -> Self {
self.0[1] = v;
self
}
pub fn nth2(mut self, v: Byte) -> Self {
self.0[2] = v;
self
}
pub fn nth3(mut self, v: Byte) -> Self {
self.0[3] = v;
self
}
pub fn nth4(mut self, v: Byte) -> Self {
self.0[4] = v;
self
}
pub fn nth5(mut self, v: Byte) -> Self {
self.0[5] = v;
self
}
pub fn nth6(mut self, v: Byte) -> Self {
self.0[6] = v;
self
}
pub fn nth7(mut self, v: Byte) -> Self {
self.0[7] = v;
self
}
pub fn nth8(mut self, v: Byte) -> Self {
self.0[8] = v;
self
}
pub fn nth9(mut self, v: Byte) -> Self {
self.0[9] = v;
self
}
pub fn nth10(mut self, v: Byte) -> Self {
self.0[10] = v;
self
}
pub fn nth11(mut self, v: Byte) -> Self {
self.0[11] = v;
self
}
pub fn nth12(mut self, v: Byte) -> Self {
self.0[12] = v;
self
}
pub fn nth13(mut self, v: Byte) -> Self {
self.0[13] = v;
self
}
pub fn nth14(mut self, v: Byte) -> Self {
self.0[14] = v;
self
}
pub fn nth15(mut self, v: Byte) -> Self {
self.0[15] = v;
self
}
pub fn nth16(mut self, v: Byte) -> Self {
self.0[16] = v;
self
}
pub fn nth17(mut self, v: Byte) -> Self {
self.0[17] = v;
self
}
pub fn nth18(mut self, v: Byte) -> Self {
self.0[18] = v;
self
}
pub fn nth19(mut self, v: Byte) -> Self {
self.0[19] = v;
self
}
pub fn nth20(mut self, v: Byte) -> Self {
self.0[20] = v;
self
}
pub fn nth21(mut self, v: Byte) -> Self {
self.0[21] = v;
self
}
pub fn nth22(mut self, v: Byte) -> Self {
self.0[22] = v;
self
}
pub fn nth23(mut self, v: Byte) -> Self {
self.0[23] = v;
self
}
pub fn nth24(mut self, v: Byte) -> Self {
self.0[24] = v;
self
}
pub fn nth25(mut self, v: Byte) -> Self {
self.0[25] = v;
self
}
pub fn nth26(mut self, v: Byte) -> Self {
self.0[26] = v;
self
}
pub fn nth27(mut self, v: Byte) -> Self {
self.0[27] = v;
self
}
pub fn nth28(mut self, v: Byte) -> Self {
self.0[28] = v;
self
}
pub fn nth29(mut self, v: Byte) -> Self {
self.0[29] = v;
self
}
pub fn nth30(mut self, v: Byte) -> Self {
self.0[30] = v;
self
}
pub fn nth31(mut self, v: Byte) -> Self {
self.0[31] = v;
self
}
}
impl molecule::prelude::Builder for PaymentHashBuilder {
type Entity = PaymentHash;
const NAME: &'static str = "PaymentHashBuilder";
fn expected_length(&self) -> usize {
Self::TOTAL_SIZE
}
fn write<W: molecule::io::Write>(&self, writer: &mut W) -> molecule::io::Result<()> {
writer.write_all(self.0[0].as_slice())?;
writer.write_all(self.0[1].as_slice())?;
writer.write_all(self.0[2].as_slice())?;
writer.write_all(self.0[3].as_slice())?;
writer.write_all(self.0[4].as_slice())?;
writer.write_all(self.0[5].as_slice())?;
writer.write_all(self.0[6].as_slice())?;
writer.write_all(self.0[7].as_slice())?;
writer.write_all(self.0[8].as_slice())?;
writer.write_all(self.0[9].as_slice())?;
writer.write_all(self.0[10].as_slice())?;
writer.write_all(self.0[11].as_slice())?;
writer.write_all(self.0[12].as_slice())?;
writer.write_all(self.0[13].as_slice())?;
writer.write_all(self.0[14].as_slice())?;
writer.write_all(self.0[15].as_slice())?;
writer.write_all(self.0[16].as_slice())?;
writer.write_all(self.0[17].as_slice())?;
writer.write_all(self.0[18].as_slice())?;
writer.write_all(self.0[19].as_slice())?;
writer.write_all(self.0[20].as_slice())?;
writer.write_all(self.0[21].as_slice())?;
writer.write_all(self.0[22].as_slice())?;
writer.write_all(self.0[23].as_slice())?;
writer.write_all(self.0[24].as_slice())?;
writer.write_all(self.0[25].as_slice())?;
writer.write_all(self.0[26].as_slice())?;
writer.write_all(self.0[27].as_slice())?;
writer.write_all(self.0[28].as_slice())?;
writer.write_all(self.0[29].as_slice())?;
writer.write_all(self.0[30].as_slice())?;
writer.write_all(self.0[31].as_slice())?;
Ok(())
}
fn build(&self) -> Self::Entity {
let mut inner = Vec::with_capacity(self.expected_length());
self.write(&mut inner)
.unwrap_or_else(|_| panic!("{} build should be ok", Self::NAME));
PaymentHash::new_unchecked(inner.into())
}
}
impl From<[Byte; 32usize]> for PaymentHash {
fn from(value: [Byte; 32usize]) -> Self {
Self::new_builder().set(value).build()
}
}
impl ::core::convert::TryFrom<&[Byte]> for PaymentHash {
type Error = ::core::array::TryFromSliceError;
fn try_from(value: &[Byte]) -> Result<Self, ::core::array::TryFromSliceError> {
Ok(Self::new_builder()
.set(<&[Byte; 32usize]>::try_from(value)?.clone())
.build())
}
}
impl From<PaymentHash> for [Byte; 32usize] {
#[track_caller]
fn from(value: PaymentHash) -> Self {
[
value.nth0(),
value.nth1(),
value.nth2(),
value.nth3(),
value.nth4(),
value.nth5(),
value.nth6(),
value.nth7(),
value.nth8(),
value.nth9(),
value.nth10(),
value.nth11(),
value.nth12(),
value.nth13(),
value.nth14(),
value.nth15(),
value.nth16(),
value.nth17(),
value.nth18(),
value.nth19(),
value.nth20(),
value.nth21(),
value.nth22(),
value.nth23(),
value.nth24(),
value.nth25(),
value.nth26(),
value.nth27(),
value.nth28(),
value.nth29(),
value.nth30(),
value.nth31(),
]
}
}
impl From<[u8; 32usize]> for PaymentHash {
fn from(value: [u8; 32usize]) -> Self {
PaymentHashReader::new_unchecked(&value).to_entity()
}
}
impl ::core::convert::TryFrom<&[u8]> for PaymentHash {
type Error = ::core::array::TryFromSliceError;
fn try_from(value: &[u8]) -> Result<Self, ::core::array::TryFromSliceError> {
Ok(<[u8; 32usize]>::try_from(value)?.into())
}
}
impl From<PaymentHash> for [u8; 32usize] {
#[track_caller]
fn from(value: PaymentHash) -> Self {
::core::convert::TryFrom::try_from(value.as_slice()).unwrap()
}
}
impl<'a> From<PaymentHashReader<'a>> for &'a [u8; 32usize] {
#[track_caller]
fn from(value: PaymentHashReader<'a>) -> Self {
::core::convert::TryFrom::try_from(value.as_slice()).unwrap()
}
}
impl<'a> From<&'a PaymentHashReader<'a>> for &'a [u8; 32usize] {
#[track_caller]
fn from(value: &'a PaymentHashReader<'a>) -> Self {
::core::convert::TryFrom::try_from(value.as_slice()).unwrap()
}
}
#[derive(Clone)]
pub struct Signature(molecule::bytes::Bytes);
impl ::core::fmt::LowerHex for Signature {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
use molecule::hex_string;
if f.alternate() {
write!(f, "0x")?;
}
write!(f, "{}", hex_string(self.as_slice()))
}
}
impl ::core::fmt::Debug for Signature {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
write!(f, "{}({:#x})", Self::NAME, self)
}
}
impl ::core::fmt::Display for Signature {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
use molecule::hex_string;
let raw_data = hex_string(&self.raw_data());
write!(f, "{}(0x{})", Self::NAME, raw_data)
}
}
impl ::core::default::Default for Signature {
fn default() -> Self {
let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE);
Signature::new_unchecked(v)
}
}
impl Signature {
const DEFAULT_VALUE: [u8; 104] = [
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
];
pub const TOTAL_SIZE: usize = 104;
pub const ITEM_SIZE: usize = 1;
pub const ITEM_COUNT: usize = 104;
pub fn nth0(&self) -> Byte {
Byte::new_unchecked(self.0.slice(0..1))
}
pub fn nth1(&self) -> Byte {
Byte::new_unchecked(self.0.slice(1..2))
}
pub fn nth2(&self) -> Byte {
Byte::new_unchecked(self.0.slice(2..3))
}
pub fn nth3(&self) -> Byte {
Byte::new_unchecked(self.0.slice(3..4))
}
pub fn nth4(&self) -> Byte {
Byte::new_unchecked(self.0.slice(4..5))
}
pub fn nth5(&self) -> Byte {
Byte::new_unchecked(self.0.slice(5..6))
}
pub fn nth6(&self) -> Byte {
Byte::new_unchecked(self.0.slice(6..7))
}
pub fn nth7(&self) -> Byte {
Byte::new_unchecked(self.0.slice(7..8))
}
pub fn nth8(&self) -> Byte {
Byte::new_unchecked(self.0.slice(8..9))
}
pub fn nth9(&self) -> Byte {
Byte::new_unchecked(self.0.slice(9..10))
}
pub fn nth10(&self) -> Byte {
Byte::new_unchecked(self.0.slice(10..11))
}
pub fn nth11(&self) -> Byte {
Byte::new_unchecked(self.0.slice(11..12))
}
pub fn nth12(&self) -> Byte {
Byte::new_unchecked(self.0.slice(12..13))
}
pub fn nth13(&self) -> Byte {
Byte::new_unchecked(self.0.slice(13..14))
}
pub fn nth14(&self) -> Byte {
Byte::new_unchecked(self.0.slice(14..15))
}
pub fn nth15(&self) -> Byte {
Byte::new_unchecked(self.0.slice(15..16))
}
pub fn nth16(&self) -> Byte {
Byte::new_unchecked(self.0.slice(16..17))
}
pub fn nth17(&self) -> Byte {
Byte::new_unchecked(self.0.slice(17..18))
}
pub fn nth18(&self) -> Byte {
Byte::new_unchecked(self.0.slice(18..19))
}
pub fn nth19(&self) -> Byte {
Byte::new_unchecked(self.0.slice(19..20))
}
pub fn nth20(&self) -> Byte {
Byte::new_unchecked(self.0.slice(20..21))
}
pub fn nth21(&self) -> Byte {
Byte::new_unchecked(self.0.slice(21..22))
}
pub fn nth22(&self) -> Byte {
Byte::new_unchecked(self.0.slice(22..23))
}
pub fn nth23(&self) -> Byte {
Byte::new_unchecked(self.0.slice(23..24))
}
pub fn nth24(&self) -> Byte {
Byte::new_unchecked(self.0.slice(24..25))
}
pub fn nth25(&self) -> Byte {
Byte::new_unchecked(self.0.slice(25..26))
}
pub fn nth26(&self) -> Byte {
Byte::new_unchecked(self.0.slice(26..27))
}
pub fn nth27(&self) -> Byte {
Byte::new_unchecked(self.0.slice(27..28))
}
pub fn nth28(&self) -> Byte {
Byte::new_unchecked(self.0.slice(28..29))
}
pub fn nth29(&self) -> Byte {
Byte::new_unchecked(self.0.slice(29..30))
}
pub fn nth30(&self) -> Byte {
Byte::new_unchecked(self.0.slice(30..31))
}
pub fn nth31(&self) -> Byte {
Byte::new_unchecked(self.0.slice(31..32))
}
pub fn nth32(&self) -> Byte {
Byte::new_unchecked(self.0.slice(32..33))
}
pub fn nth33(&self) -> Byte {
Byte::new_unchecked(self.0.slice(33..34))
}
pub fn nth34(&self) -> Byte {
Byte::new_unchecked(self.0.slice(34..35))
}
pub fn nth35(&self) -> Byte {
Byte::new_unchecked(self.0.slice(35..36))
}
pub fn nth36(&self) -> Byte {
Byte::new_unchecked(self.0.slice(36..37))
}
pub fn nth37(&self) -> Byte {
Byte::new_unchecked(self.0.slice(37..38))
}
pub fn nth38(&self) -> Byte {
Byte::new_unchecked(self.0.slice(38..39))
}
pub fn nth39(&self) -> Byte {
Byte::new_unchecked(self.0.slice(39..40))
}
pub fn nth40(&self) -> Byte {
Byte::new_unchecked(self.0.slice(40..41))
}
pub fn nth41(&self) -> Byte {
Byte::new_unchecked(self.0.slice(41..42))
}
pub fn nth42(&self) -> Byte {
Byte::new_unchecked(self.0.slice(42..43))
}
pub fn nth43(&self) -> Byte {
Byte::new_unchecked(self.0.slice(43..44))
}
pub fn nth44(&self) -> Byte {
Byte::new_unchecked(self.0.slice(44..45))
}
pub fn nth45(&self) -> Byte {
Byte::new_unchecked(self.0.slice(45..46))
}
pub fn nth46(&self) -> Byte {
Byte::new_unchecked(self.0.slice(46..47))
}
pub fn nth47(&self) -> Byte {
Byte::new_unchecked(self.0.slice(47..48))
}
pub fn nth48(&self) -> Byte {
Byte::new_unchecked(self.0.slice(48..49))
}
pub fn nth49(&self) -> Byte {
Byte::new_unchecked(self.0.slice(49..50))
}
pub fn nth50(&self) -> Byte {
Byte::new_unchecked(self.0.slice(50..51))
}
pub fn nth51(&self) -> Byte {
Byte::new_unchecked(self.0.slice(51..52))
}
pub fn nth52(&self) -> Byte {
Byte::new_unchecked(self.0.slice(52..53))
}
pub fn nth53(&self) -> Byte {
Byte::new_unchecked(self.0.slice(53..54))
}
pub fn nth54(&self) -> Byte {
Byte::new_unchecked(self.0.slice(54..55))
}
pub fn nth55(&self) -> Byte {
Byte::new_unchecked(self.0.slice(55..56))
}
pub fn nth56(&self) -> Byte {
Byte::new_unchecked(self.0.slice(56..57))
}
pub fn nth57(&self) -> Byte {
Byte::new_unchecked(self.0.slice(57..58))
}
pub fn nth58(&self) -> Byte {
Byte::new_unchecked(self.0.slice(58..59))
}
pub fn nth59(&self) -> Byte {
Byte::new_unchecked(self.0.slice(59..60))
}
pub fn nth60(&self) -> Byte {
Byte::new_unchecked(self.0.slice(60..61))
}
pub fn nth61(&self) -> Byte {
Byte::new_unchecked(self.0.slice(61..62))
}
pub fn nth62(&self) -> Byte {
Byte::new_unchecked(self.0.slice(62..63))
}
pub fn nth63(&self) -> Byte {
Byte::new_unchecked(self.0.slice(63..64))
}
pub fn nth64(&self) -> Byte {
Byte::new_unchecked(self.0.slice(64..65))
}
pub fn nth65(&self) -> Byte {
Byte::new_unchecked(self.0.slice(65..66))
}
pub fn nth66(&self) -> Byte {
Byte::new_unchecked(self.0.slice(66..67))
}
pub fn nth67(&self) -> Byte {
Byte::new_unchecked(self.0.slice(67..68))
}
pub fn nth68(&self) -> Byte {
Byte::new_unchecked(self.0.slice(68..69))
}
pub fn nth69(&self) -> Byte {
Byte::new_unchecked(self.0.slice(69..70))
}
pub fn nth70(&self) -> Byte {
Byte::new_unchecked(self.0.slice(70..71))
}
pub fn nth71(&self) -> Byte {
Byte::new_unchecked(self.0.slice(71..72))
}
pub fn nth72(&self) -> Byte {
Byte::new_unchecked(self.0.slice(72..73))
}
pub fn nth73(&self) -> Byte {
Byte::new_unchecked(self.0.slice(73..74))
}
pub fn nth74(&self) -> Byte {
Byte::new_unchecked(self.0.slice(74..75))
}
pub fn nth75(&self) -> Byte {
Byte::new_unchecked(self.0.slice(75..76))
}
pub fn nth76(&self) -> Byte {
Byte::new_unchecked(self.0.slice(76..77))
}
pub fn nth77(&self) -> Byte {
Byte::new_unchecked(self.0.slice(77..78))
}
pub fn nth78(&self) -> Byte {
Byte::new_unchecked(self.0.slice(78..79))
}
pub fn nth79(&self) -> Byte {
Byte::new_unchecked(self.0.slice(79..80))
}
pub fn nth80(&self) -> Byte {
Byte::new_unchecked(self.0.slice(80..81))
}
pub fn nth81(&self) -> Byte {
Byte::new_unchecked(self.0.slice(81..82))
}
pub fn nth82(&self) -> Byte {
Byte::new_unchecked(self.0.slice(82..83))
}
pub fn nth83(&self) -> Byte {
Byte::new_unchecked(self.0.slice(83..84))
}
pub fn nth84(&self) -> Byte {
Byte::new_unchecked(self.0.slice(84..85))
}
pub fn nth85(&self) -> Byte {
Byte::new_unchecked(self.0.slice(85..86))
}
pub fn nth86(&self) -> Byte {
Byte::new_unchecked(self.0.slice(86..87))
}
pub fn nth87(&self) -> Byte {
Byte::new_unchecked(self.0.slice(87..88))
}
pub fn nth88(&self) -> Byte {
Byte::new_unchecked(self.0.slice(88..89))
}
pub fn nth89(&self) -> Byte {
Byte::new_unchecked(self.0.slice(89..90))
}
pub fn nth90(&self) -> Byte {
Byte::new_unchecked(self.0.slice(90..91))
}
pub fn nth91(&self) -> Byte {
Byte::new_unchecked(self.0.slice(91..92))
}
pub fn nth92(&self) -> Byte {
Byte::new_unchecked(self.0.slice(92..93))
}
pub fn nth93(&self) -> Byte {
Byte::new_unchecked(self.0.slice(93..94))
}
pub fn nth94(&self) -> Byte {
Byte::new_unchecked(self.0.slice(94..95))
}
pub fn nth95(&self) -> Byte {
Byte::new_unchecked(self.0.slice(95..96))
}
pub fn nth96(&self) -> Byte {
Byte::new_unchecked(self.0.slice(96..97))
}
pub fn nth97(&self) -> Byte {
Byte::new_unchecked(self.0.slice(97..98))
}
pub fn nth98(&self) -> Byte {
Byte::new_unchecked(self.0.slice(98..99))
}
pub fn nth99(&self) -> Byte {
Byte::new_unchecked(self.0.slice(99..100))
}
pub fn nth100(&self) -> Byte {
Byte::new_unchecked(self.0.slice(100..101))
}
pub fn nth101(&self) -> Byte {
Byte::new_unchecked(self.0.slice(101..102))
}
pub fn nth102(&self) -> Byte {
Byte::new_unchecked(self.0.slice(102..103))
}
pub fn nth103(&self) -> Byte {
Byte::new_unchecked(self.0.slice(103..104))
}
pub fn raw_data(&self) -> molecule::bytes::Bytes {
self.as_bytes()
}
pub fn as_reader<'r>(&'r self) -> SignatureReader<'r> {
SignatureReader::new_unchecked(self.as_slice())
}
}
impl molecule::prelude::Entity for Signature {
type Builder = SignatureBuilder;
const NAME: &'static str = "Signature";
fn new_unchecked(data: molecule::bytes::Bytes) -> Self {
Signature(data)
}
fn as_bytes(&self) -> molecule::bytes::Bytes {
self.0.clone()
}
fn as_slice(&self) -> &[u8] {
&self.0[..]
}
fn from_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
SignatureReader::from_slice(slice).map(|reader| reader.to_entity())
}
fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
SignatureReader::from_compatible_slice(slice).map(|reader| reader.to_entity())
}
fn new_builder() -> Self::Builder {
::core::default::Default::default()
}
fn as_builder(self) -> Self::Builder {
Self::new_builder().set([
self.nth0(),
self.nth1(),
self.nth2(),
self.nth3(),
self.nth4(),
self.nth5(),
self.nth6(),
self.nth7(),
self.nth8(),
self.nth9(),
self.nth10(),
self.nth11(),
self.nth12(),
self.nth13(),
self.nth14(),
self.nth15(),
self.nth16(),
self.nth17(),
self.nth18(),
self.nth19(),
self.nth20(),
self.nth21(),
self.nth22(),
self.nth23(),
self.nth24(),
self.nth25(),
self.nth26(),
self.nth27(),
self.nth28(),
self.nth29(),
self.nth30(),
self.nth31(),
self.nth32(),
self.nth33(),
self.nth34(),
self.nth35(),
self.nth36(),
self.nth37(),
self.nth38(),
self.nth39(),
self.nth40(),
self.nth41(),
self.nth42(),
self.nth43(),
self.nth44(),
self.nth45(),
self.nth46(),
self.nth47(),
self.nth48(),
self.nth49(),
self.nth50(),
self.nth51(),
self.nth52(),
self.nth53(),
self.nth54(),
self.nth55(),
self.nth56(),
self.nth57(),
self.nth58(),
self.nth59(),
self.nth60(),
self.nth61(),
self.nth62(),
self.nth63(),
self.nth64(),
self.nth65(),
self.nth66(),
self.nth67(),
self.nth68(),
self.nth69(),
self.nth70(),
self.nth71(),
self.nth72(),
self.nth73(),
self.nth74(),
self.nth75(),
self.nth76(),
self.nth77(),
self.nth78(),
self.nth79(),
self.nth80(),
self.nth81(),
self.nth82(),
self.nth83(),
self.nth84(),
self.nth85(),
self.nth86(),
self.nth87(),
self.nth88(),
self.nth89(),
self.nth90(),
self.nth91(),
self.nth92(),
self.nth93(),
self.nth94(),
self.nth95(),
self.nth96(),
self.nth97(),
self.nth98(),
self.nth99(),
self.nth100(),
self.nth101(),
self.nth102(),
self.nth103(),
])
}
}
#[derive(Clone, Copy)]
pub struct SignatureReader<'r>(&'r [u8]);
impl<'r> ::core::fmt::LowerHex for SignatureReader<'r> {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
use molecule::hex_string;
if f.alternate() {
write!(f, "0x")?;
}
write!(f, "{}", hex_string(self.as_slice()))
}
}
impl<'r> ::core::fmt::Debug for SignatureReader<'r> {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
write!(f, "{}({:#x})", Self::NAME, self)
}
}
impl<'r> ::core::fmt::Display for SignatureReader<'r> {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
use molecule::hex_string;
let raw_data = hex_string(&self.raw_data());
write!(f, "{}(0x{})", Self::NAME, raw_data)
}
}
impl<'r> SignatureReader<'r> {
pub const TOTAL_SIZE: usize = 104;
pub const ITEM_SIZE: usize = 1;
pub const ITEM_COUNT: usize = 104;
pub fn nth0(&self) -> ByteReader<'r> {
ByteReader::new_unchecked(&self.as_slice()[0..1])
}
pub fn nth1(&self) -> ByteReader<'r> {
ByteReader::new_unchecked(&self.as_slice()[1..2])
}
pub fn nth2(&self) -> ByteReader<'r> {
ByteReader::new_unchecked(&self.as_slice()[2..3])
}
pub fn nth3(&self) -> ByteReader<'r> {
ByteReader::new_unchecked(&self.as_slice()[3..4])
}
pub fn nth4(&self) -> ByteReader<'r> {
ByteReader::new_unchecked(&self.as_slice()[4..5])
}
pub fn nth5(&self) -> ByteReader<'r> {
ByteReader::new_unchecked(&self.as_slice()[5..6])
}
pub fn nth6(&self) -> ByteReader<'r> {
ByteReader::new_unchecked(&self.as_slice()[6..7])
}
pub fn nth7(&self) -> ByteReader<'r> {
ByteReader::new_unchecked(&self.as_slice()[7..8])
}
pub fn nth8(&self) -> ByteReader<'r> {
ByteReader::new_unchecked(&self.as_slice()[8..9])
}
pub fn nth9(&self) -> ByteReader<'r> {
ByteReader::new_unchecked(&self.as_slice()[9..10])
}
pub fn nth10(&self) -> ByteReader<'r> {
ByteReader::new_unchecked(&self.as_slice()[10..11])
}
pub fn nth11(&self) -> ByteReader<'r> {
ByteReader::new_unchecked(&self.as_slice()[11..12])
}
pub fn nth12(&self) -> ByteReader<'r> {
ByteReader::new_unchecked(&self.as_slice()[12..13])
}
pub fn nth13(&self) -> ByteReader<'r> {
ByteReader::new_unchecked(&self.as_slice()[13..14])
}
pub fn nth14(&self) -> ByteReader<'r> {
ByteReader::new_unchecked(&self.as_slice()[14..15])
}
pub fn nth15(&self) -> ByteReader<'r> {
ByteReader::new_unchecked(&self.as_slice()[15..16])
}
pub fn nth16(&self) -> ByteReader<'r> {
ByteReader::new_unchecked(&self.as_slice()[16..17])
}
pub fn nth17(&self) -> ByteReader<'r> {
ByteReader::new_unchecked(&self.as_slice()[17..18])
}
pub fn nth18(&self) -> ByteReader<'r> {
ByteReader::new_unchecked(&self.as_slice()[18..19])
}
pub fn nth19(&self) -> ByteReader<'r> {
ByteReader::new_unchecked(&self.as_slice()[19..20])
}
pub fn nth20(&self) -> ByteReader<'r> {
ByteReader::new_unchecked(&self.as_slice()[20..21])
}
pub fn nth21(&self) -> ByteReader<'r> {
ByteReader::new_unchecked(&self.as_slice()[21..22])
}
pub fn nth22(&self) -> ByteReader<'r> {
ByteReader::new_unchecked(&self.as_slice()[22..23])
}
pub fn nth23(&self) -> ByteReader<'r> {
ByteReader::new_unchecked(&self.as_slice()[23..24])
}
pub fn nth24(&self) -> ByteReader<'r> {
ByteReader::new_unchecked(&self.as_slice()[24..25])
}
pub fn nth25(&self) -> ByteReader<'r> {
ByteReader::new_unchecked(&self.as_slice()[25..26])
}
pub fn nth26(&self) -> ByteReader<'r> {
ByteReader::new_unchecked(&self.as_slice()[26..27])
}
pub fn nth27(&self) -> ByteReader<'r> {
ByteReader::new_unchecked(&self.as_slice()[27..28])
}
pub fn nth28(&self) -> ByteReader<'r> {
ByteReader::new_unchecked(&self.as_slice()[28..29])
}
pub fn nth29(&self) -> ByteReader<'r> {
ByteReader::new_unchecked(&self.as_slice()[29..30])
}
pub fn nth30(&self) -> ByteReader<'r> {
ByteReader::new_unchecked(&self.as_slice()[30..31])
}
pub fn nth31(&self) -> ByteReader<'r> {
ByteReader::new_unchecked(&self.as_slice()[31..32])
}
pub fn nth32(&self) -> ByteReader<'r> {
ByteReader::new_unchecked(&self.as_slice()[32..33])
}
pub fn nth33(&self) -> ByteReader<'r> {
ByteReader::new_unchecked(&self.as_slice()[33..34])
}
pub fn nth34(&self) -> ByteReader<'r> {
ByteReader::new_unchecked(&self.as_slice()[34..35])
}
pub fn nth35(&self) -> ByteReader<'r> {
ByteReader::new_unchecked(&self.as_slice()[35..36])
}
pub fn nth36(&self) -> ByteReader<'r> {
ByteReader::new_unchecked(&self.as_slice()[36..37])
}
pub fn nth37(&self) -> ByteReader<'r> {
ByteReader::new_unchecked(&self.as_slice()[37..38])
}
pub fn nth38(&self) -> ByteReader<'r> {
ByteReader::new_unchecked(&self.as_slice()[38..39])
}
pub fn nth39(&self) -> ByteReader<'r> {
ByteReader::new_unchecked(&self.as_slice()[39..40])
}
pub fn nth40(&self) -> ByteReader<'r> {
ByteReader::new_unchecked(&self.as_slice()[40..41])
}
pub fn nth41(&self) -> ByteReader<'r> {
ByteReader::new_unchecked(&self.as_slice()[41..42])
}
pub fn nth42(&self) -> ByteReader<'r> {
ByteReader::new_unchecked(&self.as_slice()[42..43])
}
pub fn nth43(&self) -> ByteReader<'r> {
ByteReader::new_unchecked(&self.as_slice()[43..44])
}
pub fn nth44(&self) -> ByteReader<'r> {
ByteReader::new_unchecked(&self.as_slice()[44..45])
}
pub fn nth45(&self) -> ByteReader<'r> {
ByteReader::new_unchecked(&self.as_slice()[45..46])
}
pub fn nth46(&self) -> ByteReader<'r> {
ByteReader::new_unchecked(&self.as_slice()[46..47])
}
pub fn nth47(&self) -> ByteReader<'r> {
ByteReader::new_unchecked(&self.as_slice()[47..48])
}
pub fn nth48(&self) -> ByteReader<'r> {
ByteReader::new_unchecked(&self.as_slice()[48..49])
}
pub fn nth49(&self) -> ByteReader<'r> {
ByteReader::new_unchecked(&self.as_slice()[49..50])
}
pub fn nth50(&self) -> ByteReader<'r> {
ByteReader::new_unchecked(&self.as_slice()[50..51])
}
pub fn nth51(&self) -> ByteReader<'r> {
ByteReader::new_unchecked(&self.as_slice()[51..52])
}
pub fn nth52(&self) -> ByteReader<'r> {
ByteReader::new_unchecked(&self.as_slice()[52..53])
}
pub fn nth53(&self) -> ByteReader<'r> {
ByteReader::new_unchecked(&self.as_slice()[53..54])
}
pub fn nth54(&self) -> ByteReader<'r> {
ByteReader::new_unchecked(&self.as_slice()[54..55])
}
pub fn nth55(&self) -> ByteReader<'r> {
ByteReader::new_unchecked(&self.as_slice()[55..56])
}
pub fn nth56(&self) -> ByteReader<'r> {
ByteReader::new_unchecked(&self.as_slice()[56..57])
}
pub fn nth57(&self) -> ByteReader<'r> {
ByteReader::new_unchecked(&self.as_slice()[57..58])
}
pub fn nth58(&self) -> ByteReader<'r> {
ByteReader::new_unchecked(&self.as_slice()[58..59])
}
pub fn nth59(&self) -> ByteReader<'r> {
ByteReader::new_unchecked(&self.as_slice()[59..60])
}
pub fn nth60(&self) -> ByteReader<'r> {
ByteReader::new_unchecked(&self.as_slice()[60..61])
}
pub fn nth61(&self) -> ByteReader<'r> {
ByteReader::new_unchecked(&self.as_slice()[61..62])
}
pub fn nth62(&self) -> ByteReader<'r> {
ByteReader::new_unchecked(&self.as_slice()[62..63])
}
pub fn nth63(&self) -> ByteReader<'r> {
ByteReader::new_unchecked(&self.as_slice()[63..64])
}
pub fn nth64(&self) -> ByteReader<'r> {
ByteReader::new_unchecked(&self.as_slice()[64..65])
}
pub fn nth65(&self) -> ByteReader<'r> {
ByteReader::new_unchecked(&self.as_slice()[65..66])
}
pub fn nth66(&self) -> ByteReader<'r> {
ByteReader::new_unchecked(&self.as_slice()[66..67])
}
pub fn nth67(&self) -> ByteReader<'r> {
ByteReader::new_unchecked(&self.as_slice()[67..68])
}
pub fn nth68(&self) -> ByteReader<'r> {
ByteReader::new_unchecked(&self.as_slice()[68..69])
}
pub fn nth69(&self) -> ByteReader<'r> {
ByteReader::new_unchecked(&self.as_slice()[69..70])
}
pub fn nth70(&self) -> ByteReader<'r> {
ByteReader::new_unchecked(&self.as_slice()[70..71])
}
pub fn nth71(&self) -> ByteReader<'r> {
ByteReader::new_unchecked(&self.as_slice()[71..72])
}
pub fn nth72(&self) -> ByteReader<'r> {
ByteReader::new_unchecked(&self.as_slice()[72..73])
}
pub fn nth73(&self) -> ByteReader<'r> {
ByteReader::new_unchecked(&self.as_slice()[73..74])
}
pub fn nth74(&self) -> ByteReader<'r> {
ByteReader::new_unchecked(&self.as_slice()[74..75])
}
pub fn nth75(&self) -> ByteReader<'r> {
ByteReader::new_unchecked(&self.as_slice()[75..76])
}
pub fn nth76(&self) -> ByteReader<'r> {
ByteReader::new_unchecked(&self.as_slice()[76..77])
}
pub fn nth77(&self) -> ByteReader<'r> {
ByteReader::new_unchecked(&self.as_slice()[77..78])
}
pub fn nth78(&self) -> ByteReader<'r> {
ByteReader::new_unchecked(&self.as_slice()[78..79])
}
pub fn nth79(&self) -> ByteReader<'r> {
ByteReader::new_unchecked(&self.as_slice()[79..80])
}
pub fn nth80(&self) -> ByteReader<'r> {
ByteReader::new_unchecked(&self.as_slice()[80..81])
}
pub fn nth81(&self) -> ByteReader<'r> {
ByteReader::new_unchecked(&self.as_slice()[81..82])
}
pub fn nth82(&self) -> ByteReader<'r> {
ByteReader::new_unchecked(&self.as_slice()[82..83])
}
pub fn nth83(&self) -> ByteReader<'r> {
ByteReader::new_unchecked(&self.as_slice()[83..84])
}
pub fn nth84(&self) -> ByteReader<'r> {
ByteReader::new_unchecked(&self.as_slice()[84..85])
}
pub fn nth85(&self) -> ByteReader<'r> {
ByteReader::new_unchecked(&self.as_slice()[85..86])
}
pub fn nth86(&self) -> ByteReader<'r> {
ByteReader::new_unchecked(&self.as_slice()[86..87])
}
pub fn nth87(&self) -> ByteReader<'r> {
ByteReader::new_unchecked(&self.as_slice()[87..88])
}
pub fn nth88(&self) -> ByteReader<'r> {
ByteReader::new_unchecked(&self.as_slice()[88..89])
}
pub fn nth89(&self) -> ByteReader<'r> {
ByteReader::new_unchecked(&self.as_slice()[89..90])
}
pub fn nth90(&self) -> ByteReader<'r> {
ByteReader::new_unchecked(&self.as_slice()[90..91])
}
pub fn nth91(&self) -> ByteReader<'r> {
ByteReader::new_unchecked(&self.as_slice()[91..92])
}
pub fn nth92(&self) -> ByteReader<'r> {
ByteReader::new_unchecked(&self.as_slice()[92..93])
}
pub fn nth93(&self) -> ByteReader<'r> {
ByteReader::new_unchecked(&self.as_slice()[93..94])
}
pub fn nth94(&self) -> ByteReader<'r> {
ByteReader::new_unchecked(&self.as_slice()[94..95])
}
pub fn nth95(&self) -> ByteReader<'r> {
ByteReader::new_unchecked(&self.as_slice()[95..96])
}
pub fn nth96(&self) -> ByteReader<'r> {
ByteReader::new_unchecked(&self.as_slice()[96..97])
}
pub fn nth97(&self) -> ByteReader<'r> {
ByteReader::new_unchecked(&self.as_slice()[97..98])
}
pub fn nth98(&self) -> ByteReader<'r> {
ByteReader::new_unchecked(&self.as_slice()[98..99])
}
pub fn nth99(&self) -> ByteReader<'r> {
ByteReader::new_unchecked(&self.as_slice()[99..100])
}
pub fn nth100(&self) -> ByteReader<'r> {
ByteReader::new_unchecked(&self.as_slice()[100..101])
}
pub fn nth101(&self) -> ByteReader<'r> {
ByteReader::new_unchecked(&self.as_slice()[101..102])
}
pub fn nth102(&self) -> ByteReader<'r> {
ByteReader::new_unchecked(&self.as_slice()[102..103])
}
pub fn nth103(&self) -> ByteReader<'r> {
ByteReader::new_unchecked(&self.as_slice()[103..104])
}
pub fn raw_data(&self) -> &'r [u8] {
self.as_slice()
}
}
impl<'r> molecule::prelude::Reader<'r> for SignatureReader<'r> {
type Entity = Signature;
const NAME: &'static str = "SignatureReader";
fn to_entity(&self) -> Self::Entity {
Self::Entity::new_unchecked(self.as_slice().to_owned().into())
}
fn new_unchecked(slice: &'r [u8]) -> Self {
SignatureReader(slice)
}
fn as_slice(&self) -> &'r [u8] {
self.0
}
fn verify(slice: &[u8], _compatible: bool) -> molecule::error::VerificationResult<()> {
use molecule::verification_error as ve;
let slice_len = slice.len();
if slice_len != Self::TOTAL_SIZE {
return ve!(Self, TotalSizeNotMatch, Self::TOTAL_SIZE, slice_len);
}
Ok(())
}
}
#[derive(Clone)]
pub struct SignatureBuilder(pub(crate) [Byte; 104]);
impl ::core::fmt::Debug for SignatureBuilder {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
write!(f, "{}({:?})", Self::NAME, &self.0[..])
}
}
impl ::core::default::Default for SignatureBuilder {
fn default() -> Self {
SignatureBuilder([
Byte::default(),
Byte::default(),
Byte::default(),
Byte::default(),
Byte::default(),
Byte::default(),
Byte::default(),
Byte::default(),
Byte::default(),
Byte::default(),
Byte::default(),
Byte::default(),
Byte::default(),
Byte::default(),
Byte::default(),
Byte::default(),
Byte::default(),
Byte::default(),
Byte::default(),
Byte::default(),
Byte::default(),
Byte::default(),
Byte::default(),
Byte::default(),
Byte::default(),
Byte::default(),
Byte::default(),
Byte::default(),
Byte::default(),
Byte::default(),
Byte::default(),
Byte::default(),
Byte::default(),
Byte::default(),
Byte::default(),
Byte::default(),
Byte::default(),
Byte::default(),
Byte::default(),
Byte::default(),
Byte::default(),
Byte::default(),
Byte::default(),
Byte::default(),
Byte::default(),
Byte::default(),
Byte::default(),
Byte::default(),
Byte::default(),
Byte::default(),
Byte::default(),
Byte::default(),
Byte::default(),
Byte::default(),
Byte::default(),
Byte::default(),
Byte::default(),
Byte::default(),
Byte::default(),
Byte::default(),
Byte::default(),
Byte::default(),
Byte::default(),
Byte::default(),
Byte::default(),
Byte::default(),
Byte::default(),
Byte::default(),
Byte::default(),
Byte::default(),
Byte::default(),
Byte::default(),
Byte::default(),
Byte::default(),
Byte::default(),
Byte::default(),
Byte::default(),
Byte::default(),
Byte::default(),
Byte::default(),
Byte::default(),
Byte::default(),
Byte::default(),
Byte::default(),
Byte::default(),
Byte::default(),
Byte::default(),
Byte::default(),
Byte::default(),
Byte::default(),
Byte::default(),
Byte::default(),
Byte::default(),
Byte::default(),
Byte::default(),
Byte::default(),
Byte::default(),
Byte::default(),
Byte::default(),
Byte::default(),
Byte::default(),
Byte::default(),
Byte::default(),
Byte::default(),
])
}
}
impl SignatureBuilder {
pub const TOTAL_SIZE: usize = 104;
pub const ITEM_SIZE: usize = 1;
pub const ITEM_COUNT: usize = 104;
pub fn set(mut self, v: [Byte; 104]) -> Self {
self.0 = v;
self
}
pub fn nth0(mut self, v: Byte) -> Self {
self.0[0] = v;
self
}
pub fn nth1(mut self, v: Byte) -> Self {
self.0[1] = v;
self
}
pub fn nth2(mut self, v: Byte) -> Self {
self.0[2] = v;
self
}
pub fn nth3(mut self, v: Byte) -> Self {
self.0[3] = v;
self
}
pub fn nth4(mut self, v: Byte) -> Self {
self.0[4] = v;
self
}
pub fn nth5(mut self, v: Byte) -> Self {
self.0[5] = v;
self
}
pub fn nth6(mut self, v: Byte) -> Self {
self.0[6] = v;
self
}
pub fn nth7(mut self, v: Byte) -> Self {
self.0[7] = v;
self
}
pub fn nth8(mut self, v: Byte) -> Self {
self.0[8] = v;
self
}
pub fn nth9(mut self, v: Byte) -> Self {
self.0[9] = v;
self
}
pub fn nth10(mut self, v: Byte) -> Self {
self.0[10] = v;
self
}
pub fn nth11(mut self, v: Byte) -> Self {
self.0[11] = v;
self
}
pub fn nth12(mut self, v: Byte) -> Self {
self.0[12] = v;
self
}
pub fn nth13(mut self, v: Byte) -> Self {
self.0[13] = v;
self
}
pub fn nth14(mut self, v: Byte) -> Self {
self.0[14] = v;
self
}
pub fn nth15(mut self, v: Byte) -> Self {
self.0[15] = v;
self
}
pub fn nth16(mut self, v: Byte) -> Self {
self.0[16] = v;
self
}
pub fn nth17(mut self, v: Byte) -> Self {
self.0[17] = v;
self
}
pub fn nth18(mut self, v: Byte) -> Self {
self.0[18] = v;
self
}
pub fn nth19(mut self, v: Byte) -> Self {
self.0[19] = v;
self
}
pub fn nth20(mut self, v: Byte) -> Self {
self.0[20] = v;
self
}
pub fn nth21(mut self, v: Byte) -> Self {
self.0[21] = v;
self
}
pub fn nth22(mut self, v: Byte) -> Self {
self.0[22] = v;
self
}
pub fn nth23(mut self, v: Byte) -> Self {
self.0[23] = v;
self
}
pub fn nth24(mut self, v: Byte) -> Self {
self.0[24] = v;
self
}
pub fn nth25(mut self, v: Byte) -> Self {
self.0[25] = v;
self
}
pub fn nth26(mut self, v: Byte) -> Self {
self.0[26] = v;
self
}
pub fn nth27(mut self, v: Byte) -> Self {
self.0[27] = v;
self
}
pub fn nth28(mut self, v: Byte) -> Self {
self.0[28] = v;
self
}
pub fn nth29(mut self, v: Byte) -> Self {
self.0[29] = v;
self
}
pub fn nth30(mut self, v: Byte) -> Self {
self.0[30] = v;
self
}
pub fn nth31(mut self, v: Byte) -> Self {
self.0[31] = v;
self
}
pub fn nth32(mut self, v: Byte) -> Self {
self.0[32] = v;
self
}
pub fn nth33(mut self, v: Byte) -> Self {
self.0[33] = v;
self
}
pub fn nth34(mut self, v: Byte) -> Self {
self.0[34] = v;
self
}
pub fn nth35(mut self, v: Byte) -> Self {
self.0[35] = v;
self
}
pub fn nth36(mut self, v: Byte) -> Self {
self.0[36] = v;
self
}
pub fn nth37(mut self, v: Byte) -> Self {
self.0[37] = v;
self
}
pub fn nth38(mut self, v: Byte) -> Self {
self.0[38] = v;
self
}
pub fn nth39(mut self, v: Byte) -> Self {
self.0[39] = v;
self
}
pub fn nth40(mut self, v: Byte) -> Self {
self.0[40] = v;
self
}
pub fn nth41(mut self, v: Byte) -> Self {
self.0[41] = v;
self
}
pub fn nth42(mut self, v: Byte) -> Self {
self.0[42] = v;
self
}
pub fn nth43(mut self, v: Byte) -> Self {
self.0[43] = v;
self
}
pub fn nth44(mut self, v: Byte) -> Self {
self.0[44] = v;
self
}
pub fn nth45(mut self, v: Byte) -> Self {
self.0[45] = v;
self
}
pub fn nth46(mut self, v: Byte) -> Self {
self.0[46] = v;
self
}
pub fn nth47(mut self, v: Byte) -> Self {
self.0[47] = v;
self
}
pub fn nth48(mut self, v: Byte) -> Self {
self.0[48] = v;
self
}
pub fn nth49(mut self, v: Byte) -> Self {
self.0[49] = v;
self
}
pub fn nth50(mut self, v: Byte) -> Self {
self.0[50] = v;
self
}
pub fn nth51(mut self, v: Byte) -> Self {
self.0[51] = v;
self
}
pub fn nth52(mut self, v: Byte) -> Self {
self.0[52] = v;
self
}
pub fn nth53(mut self, v: Byte) -> Self {
self.0[53] = v;
self
}
pub fn nth54(mut self, v: Byte) -> Self {
self.0[54] = v;
self
}
pub fn nth55(mut self, v: Byte) -> Self {
self.0[55] = v;
self
}
pub fn nth56(mut self, v: Byte) -> Self {
self.0[56] = v;
self
}
pub fn nth57(mut self, v: Byte) -> Self {
self.0[57] = v;
self
}
pub fn nth58(mut self, v: Byte) -> Self {
self.0[58] = v;
self
}
pub fn nth59(mut self, v: Byte) -> Self {
self.0[59] = v;
self
}
pub fn nth60(mut self, v: Byte) -> Self {
self.0[60] = v;
self
}
pub fn nth61(mut self, v: Byte) -> Self {
self.0[61] = v;
self
}
pub fn nth62(mut self, v: Byte) -> Self {
self.0[62] = v;
self
}
pub fn nth63(mut self, v: Byte) -> Self {
self.0[63] = v;
self
}
pub fn nth64(mut self, v: Byte) -> Self {
self.0[64] = v;
self
}
pub fn nth65(mut self, v: Byte) -> Self {
self.0[65] = v;
self
}
pub fn nth66(mut self, v: Byte) -> Self {
self.0[66] = v;
self
}
pub fn nth67(mut self, v: Byte) -> Self {
self.0[67] = v;
self
}
pub fn nth68(mut self, v: Byte) -> Self {
self.0[68] = v;
self
}
pub fn nth69(mut self, v: Byte) -> Self {
self.0[69] = v;
self
}
pub fn nth70(mut self, v: Byte) -> Self {
self.0[70] = v;
self
}
pub fn nth71(mut self, v: Byte) -> Self {
self.0[71] = v;
self
}
pub fn nth72(mut self, v: Byte) -> Self {
self.0[72] = v;
self
}
pub fn nth73(mut self, v: Byte) -> Self {
self.0[73] = v;
self
}
pub fn nth74(mut self, v: Byte) -> Self {
self.0[74] = v;
self
}
pub fn nth75(mut self, v: Byte) -> Self {
self.0[75] = v;
self
}
pub fn nth76(mut self, v: Byte) -> Self {
self.0[76] = v;
self
}
pub fn nth77(mut self, v: Byte) -> Self {
self.0[77] = v;
self
}
pub fn nth78(mut self, v: Byte) -> Self {
self.0[78] = v;
self
}
pub fn nth79(mut self, v: Byte) -> Self {
self.0[79] = v;
self
}
pub fn nth80(mut self, v: Byte) -> Self {
self.0[80] = v;
self
}
pub fn nth81(mut self, v: Byte) -> Self {
self.0[81] = v;
self
}
pub fn nth82(mut self, v: Byte) -> Self {
self.0[82] = v;
self
}
pub fn nth83(mut self, v: Byte) -> Self {
self.0[83] = v;
self
}
pub fn nth84(mut self, v: Byte) -> Self {
self.0[84] = v;
self
}
pub fn nth85(mut self, v: Byte) -> Self {
self.0[85] = v;
self
}
pub fn nth86(mut self, v: Byte) -> Self {
self.0[86] = v;
self
}
pub fn nth87(mut self, v: Byte) -> Self {
self.0[87] = v;
self
}
pub fn nth88(mut self, v: Byte) -> Self {
self.0[88] = v;
self
}
pub fn nth89(mut self, v: Byte) -> Self {
self.0[89] = v;
self
}
pub fn nth90(mut self, v: Byte) -> Self {
self.0[90] = v;
self
}
pub fn nth91(mut self, v: Byte) -> Self {
self.0[91] = v;
self
}
pub fn nth92(mut self, v: Byte) -> Self {
self.0[92] = v;
self
}
pub fn nth93(mut self, v: Byte) -> Self {
self.0[93] = v;
self
}
pub fn nth94(mut self, v: Byte) -> Self {
self.0[94] = v;
self
}
pub fn nth95(mut self, v: Byte) -> Self {
self.0[95] = v;
self
}
pub fn nth96(mut self, v: Byte) -> Self {
self.0[96] = v;
self
}
pub fn nth97(mut self, v: Byte) -> Self {
self.0[97] = v;
self
}
pub fn nth98(mut self, v: Byte) -> Self {
self.0[98] = v;
self
}
pub fn nth99(mut self, v: Byte) -> Self {
self.0[99] = v;
self
}
pub fn nth100(mut self, v: Byte) -> Self {
self.0[100] = v;
self
}
pub fn nth101(mut self, v: Byte) -> Self {
self.0[101] = v;
self
}
pub fn nth102(mut self, v: Byte) -> Self {
self.0[102] = v;
self
}
pub fn nth103(mut self, v: Byte) -> Self {
self.0[103] = v;
self
}
}
impl molecule::prelude::Builder for SignatureBuilder {
type Entity = Signature;
const NAME: &'static str = "SignatureBuilder";
fn expected_length(&self) -> usize {
Self::TOTAL_SIZE
}
fn write<W: molecule::io::Write>(&self, writer: &mut W) -> molecule::io::Result<()> {
writer.write_all(self.0[0].as_slice())?;
writer.write_all(self.0[1].as_slice())?;
writer.write_all(self.0[2].as_slice())?;
writer.write_all(self.0[3].as_slice())?;
writer.write_all(self.0[4].as_slice())?;
writer.write_all(self.0[5].as_slice())?;
writer.write_all(self.0[6].as_slice())?;
writer.write_all(self.0[7].as_slice())?;
writer.write_all(self.0[8].as_slice())?;
writer.write_all(self.0[9].as_slice())?;
writer.write_all(self.0[10].as_slice())?;
writer.write_all(self.0[11].as_slice())?;
writer.write_all(self.0[12].as_slice())?;
writer.write_all(self.0[13].as_slice())?;
writer.write_all(self.0[14].as_slice())?;
writer.write_all(self.0[15].as_slice())?;
writer.write_all(self.0[16].as_slice())?;
writer.write_all(self.0[17].as_slice())?;
writer.write_all(self.0[18].as_slice())?;
writer.write_all(self.0[19].as_slice())?;
writer.write_all(self.0[20].as_slice())?;
writer.write_all(self.0[21].as_slice())?;
writer.write_all(self.0[22].as_slice())?;
writer.write_all(self.0[23].as_slice())?;
writer.write_all(self.0[24].as_slice())?;
writer.write_all(self.0[25].as_slice())?;
writer.write_all(self.0[26].as_slice())?;
writer.write_all(self.0[27].as_slice())?;
writer.write_all(self.0[28].as_slice())?;
writer.write_all(self.0[29].as_slice())?;
writer.write_all(self.0[30].as_slice())?;
writer.write_all(self.0[31].as_slice())?;
writer.write_all(self.0[32].as_slice())?;
writer.write_all(self.0[33].as_slice())?;
writer.write_all(self.0[34].as_slice())?;
writer.write_all(self.0[35].as_slice())?;
writer.write_all(self.0[36].as_slice())?;
writer.write_all(self.0[37].as_slice())?;
writer.write_all(self.0[38].as_slice())?;
writer.write_all(self.0[39].as_slice())?;
writer.write_all(self.0[40].as_slice())?;
writer.write_all(self.0[41].as_slice())?;
writer.write_all(self.0[42].as_slice())?;
writer.write_all(self.0[43].as_slice())?;
writer.write_all(self.0[44].as_slice())?;
writer.write_all(self.0[45].as_slice())?;
writer.write_all(self.0[46].as_slice())?;
writer.write_all(self.0[47].as_slice())?;
writer.write_all(self.0[48].as_slice())?;
writer.write_all(self.0[49].as_slice())?;
writer.write_all(self.0[50].as_slice())?;
writer.write_all(self.0[51].as_slice())?;
writer.write_all(self.0[52].as_slice())?;
writer.write_all(self.0[53].as_slice())?;
writer.write_all(self.0[54].as_slice())?;
writer.write_all(self.0[55].as_slice())?;
writer.write_all(self.0[56].as_slice())?;
writer.write_all(self.0[57].as_slice())?;
writer.write_all(self.0[58].as_slice())?;
writer.write_all(self.0[59].as_slice())?;
writer.write_all(self.0[60].as_slice())?;
writer.write_all(self.0[61].as_slice())?;
writer.write_all(self.0[62].as_slice())?;
writer.write_all(self.0[63].as_slice())?;
writer.write_all(self.0[64].as_slice())?;
writer.write_all(self.0[65].as_slice())?;
writer.write_all(self.0[66].as_slice())?;
writer.write_all(self.0[67].as_slice())?;
writer.write_all(self.0[68].as_slice())?;
writer.write_all(self.0[69].as_slice())?;
writer.write_all(self.0[70].as_slice())?;
writer.write_all(self.0[71].as_slice())?;
writer.write_all(self.0[72].as_slice())?;
writer.write_all(self.0[73].as_slice())?;
writer.write_all(self.0[74].as_slice())?;
writer.write_all(self.0[75].as_slice())?;
writer.write_all(self.0[76].as_slice())?;
writer.write_all(self.0[77].as_slice())?;
writer.write_all(self.0[78].as_slice())?;
writer.write_all(self.0[79].as_slice())?;
writer.write_all(self.0[80].as_slice())?;
writer.write_all(self.0[81].as_slice())?;
writer.write_all(self.0[82].as_slice())?;
writer.write_all(self.0[83].as_slice())?;
writer.write_all(self.0[84].as_slice())?;
writer.write_all(self.0[85].as_slice())?;
writer.write_all(self.0[86].as_slice())?;
writer.write_all(self.0[87].as_slice())?;
writer.write_all(self.0[88].as_slice())?;
writer.write_all(self.0[89].as_slice())?;
writer.write_all(self.0[90].as_slice())?;
writer.write_all(self.0[91].as_slice())?;
writer.write_all(self.0[92].as_slice())?;
writer.write_all(self.0[93].as_slice())?;
writer.write_all(self.0[94].as_slice())?;
writer.write_all(self.0[95].as_slice())?;
writer.write_all(self.0[96].as_slice())?;
writer.write_all(self.0[97].as_slice())?;
writer.write_all(self.0[98].as_slice())?;
writer.write_all(self.0[99].as_slice())?;
writer.write_all(self.0[100].as_slice())?;
writer.write_all(self.0[101].as_slice())?;
writer.write_all(self.0[102].as_slice())?;
writer.write_all(self.0[103].as_slice())?;
Ok(())
}
fn build(&self) -> Self::Entity {
let mut inner = Vec::with_capacity(self.expected_length());
self.write(&mut inner)
.unwrap_or_else(|_| panic!("{} build should be ok", Self::NAME));
Signature::new_unchecked(inner.into())
}
}
impl From<[Byte; 104usize]> for Signature {
fn from(value: [Byte; 104usize]) -> Self {
Self::new_builder().set(value).build()
}
}
impl ::core::convert::TryFrom<&[Byte]> for Signature {
type Error = ::core::array::TryFromSliceError;
fn try_from(value: &[Byte]) -> Result<Self, ::core::array::TryFromSliceError> {
Ok(Self::new_builder()
.set(<&[Byte; 104usize]>::try_from(value)?.clone())
.build())
}
}
impl From<Signature> for [Byte; 104usize] {
#[track_caller]
fn from(value: Signature) -> Self {
[
value.nth0(),
value.nth1(),
value.nth2(),
value.nth3(),
value.nth4(),
value.nth5(),
value.nth6(),
value.nth7(),
value.nth8(),
value.nth9(),
value.nth10(),
value.nth11(),
value.nth12(),
value.nth13(),
value.nth14(),
value.nth15(),
value.nth16(),
value.nth17(),
value.nth18(),
value.nth19(),
value.nth20(),
value.nth21(),
value.nth22(),
value.nth23(),
value.nth24(),
value.nth25(),
value.nth26(),
value.nth27(),
value.nth28(),
value.nth29(),
value.nth30(),
value.nth31(),
value.nth32(),
value.nth33(),
value.nth34(),
value.nth35(),
value.nth36(),
value.nth37(),
value.nth38(),
value.nth39(),
value.nth40(),
value.nth41(),
value.nth42(),
value.nth43(),
value.nth44(),
value.nth45(),
value.nth46(),
value.nth47(),
value.nth48(),
value.nth49(),
value.nth50(),
value.nth51(),
value.nth52(),
value.nth53(),
value.nth54(),
value.nth55(),
value.nth56(),
value.nth57(),
value.nth58(),
value.nth59(),
value.nth60(),
value.nth61(),
value.nth62(),
value.nth63(),
value.nth64(),
value.nth65(),
value.nth66(),
value.nth67(),
value.nth68(),
value.nth69(),
value.nth70(),
value.nth71(),
value.nth72(),
value.nth73(),
value.nth74(),
value.nth75(),
value.nth76(),
value.nth77(),
value.nth78(),
value.nth79(),
value.nth80(),
value.nth81(),
value.nth82(),
value.nth83(),
value.nth84(),
value.nth85(),
value.nth86(),
value.nth87(),
value.nth88(),
value.nth89(),
value.nth90(),
value.nth91(),
value.nth92(),
value.nth93(),
value.nth94(),
value.nth95(),
value.nth96(),
value.nth97(),
value.nth98(),
value.nth99(),
value.nth100(),
value.nth101(),
value.nth102(),
value.nth103(),
]
}
}
impl From<[u8; 104usize]> for Signature {
fn from(value: [u8; 104usize]) -> Self {
SignatureReader::new_unchecked(&value).to_entity()
}
}
impl ::core::convert::TryFrom<&[u8]> for Signature {
type Error = ::core::array::TryFromSliceError;
fn try_from(value: &[u8]) -> Result<Self, ::core::array::TryFromSliceError> {
Ok(<[u8; 104usize]>::try_from(value)?.into())
}
}
impl From<Signature> for [u8; 104usize] {
#[track_caller]
fn from(value: Signature) -> Self {
::core::convert::TryFrom::try_from(value.as_slice()).unwrap()
}
}
impl<'a> From<SignatureReader<'a>> for &'a [u8; 104usize] {
#[track_caller]
fn from(value: SignatureReader<'a>) -> Self {
::core::convert::TryFrom::try_from(value.as_slice()).unwrap()
}
}
impl<'a> From<&'a SignatureReader<'a>> for &'a [u8; 104usize] {
#[track_caller]
fn from(value: &'a SignatureReader<'a>) -> Self {
::core::convert::TryFrom::try_from(value.as_slice()).unwrap()
}
}
#[derive(Clone)]
pub struct SignatureOpt(molecule::bytes::Bytes);
impl ::core::fmt::LowerHex for SignatureOpt {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
use molecule::hex_string;
if f.alternate() {
write!(f, "0x")?;
}
write!(f, "{}", hex_string(self.as_slice()))
}
}
impl ::core::fmt::Debug for SignatureOpt {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
write!(f, "{}({:#x})", Self::NAME, self)
}
}
impl ::core::fmt::Display for SignatureOpt {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
if let Some(v) = self.to_opt() {
write!(f, "{}(Some({}))", Self::NAME, v)
} else {
write!(f, "{}(None)", Self::NAME)
}
}
}
impl ::core::default::Default for SignatureOpt {
fn default() -> Self {
let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE);
SignatureOpt::new_unchecked(v)
}
}
impl SignatureOpt {
const DEFAULT_VALUE: [u8; 0] = [];
pub fn is_none(&self) -> bool {
self.0.is_empty()
}
pub fn is_some(&self) -> bool {
!self.0.is_empty()
}
pub fn to_opt(&self) -> Option<Signature> {
if self.is_none() {
None
} else {
Some(Signature::new_unchecked(self.0.clone()))
}
}
pub fn as_reader<'r>(&'r self) -> SignatureOptReader<'r> {
SignatureOptReader::new_unchecked(self.as_slice())
}
}
impl molecule::prelude::Entity for SignatureOpt {
type Builder = SignatureOptBuilder;
const NAME: &'static str = "SignatureOpt";
fn new_unchecked(data: molecule::bytes::Bytes) -> Self {
SignatureOpt(data)
}
fn as_bytes(&self) -> molecule::bytes::Bytes {
self.0.clone()
}
fn as_slice(&self) -> &[u8] {
&self.0[..]
}
fn from_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
SignatureOptReader::from_slice(slice).map(|reader| reader.to_entity())
}
fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
SignatureOptReader::from_compatible_slice(slice).map(|reader| reader.to_entity())
}
fn new_builder() -> Self::Builder {
::core::default::Default::default()
}
fn as_builder(self) -> Self::Builder {
Self::new_builder().set(self.to_opt())
}
}
#[derive(Clone, Copy)]
pub struct SignatureOptReader<'r>(&'r [u8]);
impl<'r> ::core::fmt::LowerHex for SignatureOptReader<'r> {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
use molecule::hex_string;
if f.alternate() {
write!(f, "0x")?;
}
write!(f, "{}", hex_string(self.as_slice()))
}
}
impl<'r> ::core::fmt::Debug for SignatureOptReader<'r> {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
write!(f, "{}({:#x})", Self::NAME, self)
}
}
impl<'r> ::core::fmt::Display for SignatureOptReader<'r> {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
if let Some(v) = self.to_opt() {
write!(f, "{}(Some({}))", Self::NAME, v)
} else {
write!(f, "{}(None)", Self::NAME)
}
}
}
impl<'r> SignatureOptReader<'r> {
pub fn is_none(&self) -> bool {
self.0.is_empty()
}
pub fn is_some(&self) -> bool {
!self.0.is_empty()
}
pub fn to_opt(&self) -> Option<SignatureReader<'r>> {
if self.is_none() {
None
} else {
Some(SignatureReader::new_unchecked(self.as_slice()))
}
}
}
impl<'r> molecule::prelude::Reader<'r> for SignatureOptReader<'r> {
type Entity = SignatureOpt;
const NAME: &'static str = "SignatureOptReader";
fn to_entity(&self) -> Self::Entity {
Self::Entity::new_unchecked(self.as_slice().to_owned().into())
}
fn new_unchecked(slice: &'r [u8]) -> Self {
SignatureOptReader(slice)
}
fn as_slice(&self) -> &'r [u8] {
self.0
}
fn verify(slice: &[u8], compatible: bool) -> molecule::error::VerificationResult<()> {
if !slice.is_empty() {
SignatureReader::verify(&slice[..], compatible)?;
}
Ok(())
}
}
#[derive(Clone, Debug, Default)]
pub struct SignatureOptBuilder(pub(crate) Option<Signature>);
impl SignatureOptBuilder {
pub fn set(mut self, v: Option<Signature>) -> Self {
self.0 = v;
self
}
}
impl molecule::prelude::Builder for SignatureOptBuilder {
type Entity = SignatureOpt;
const NAME: &'static str = "SignatureOptBuilder";
fn expected_length(&self) -> usize {
self.0
.as_ref()
.map(|ref inner| inner.as_slice().len())
.unwrap_or(0)
}
fn write<W: molecule::io::Write>(&self, writer: &mut W) -> molecule::io::Result<()> {
self.0
.as_ref()
.map(|ref inner| writer.write_all(inner.as_slice()))
.unwrap_or(Ok(()))
}
fn build(&self) -> Self::Entity {
let mut inner = Vec::with_capacity(self.expected_length());
self.write(&mut inner)
.unwrap_or_else(|_| panic!("{} build should be ok", Self::NAME));
SignatureOpt::new_unchecked(inner.into())
}
}
impl From<Signature> for SignatureOpt {
fn from(value: Signature) -> Self {
Self::new_builder().set(Some(value)).build()
}
}
#[derive(Clone)]
pub struct AmountOpt(molecule::bytes::Bytes);
impl ::core::fmt::LowerHex for AmountOpt {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
use molecule::hex_string;
if f.alternate() {
write!(f, "0x")?;
}
write!(f, "{}", hex_string(self.as_slice()))
}
}
impl ::core::fmt::Debug for AmountOpt {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
write!(f, "{}({:#x})", Self::NAME, self)
}
}
impl ::core::fmt::Display for AmountOpt {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
if let Some(v) = self.to_opt() {
write!(f, "{}(Some({}))", Self::NAME, v)
} else {
write!(f, "{}(None)", Self::NAME)
}
}
}
impl ::core::default::Default for AmountOpt {
fn default() -> Self {
let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE);
AmountOpt::new_unchecked(v)
}
}
impl AmountOpt {
const DEFAULT_VALUE: [u8; 0] = [];
pub fn is_none(&self) -> bool {
self.0.is_empty()
}
pub fn is_some(&self) -> bool {
!self.0.is_empty()
}
pub fn to_opt(&self) -> Option<Uint128> {
if self.is_none() {
None
} else {
Some(Uint128::new_unchecked(self.0.clone()))
}
}
pub fn as_reader<'r>(&'r self) -> AmountOptReader<'r> {
AmountOptReader::new_unchecked(self.as_slice())
}
}
impl molecule::prelude::Entity for AmountOpt {
type Builder = AmountOptBuilder;
const NAME: &'static str = "AmountOpt";
fn new_unchecked(data: molecule::bytes::Bytes) -> Self {
AmountOpt(data)
}
fn as_bytes(&self) -> molecule::bytes::Bytes {
self.0.clone()
}
fn as_slice(&self) -> &[u8] {
&self.0[..]
}
fn from_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
AmountOptReader::from_slice(slice).map(|reader| reader.to_entity())
}
fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
AmountOptReader::from_compatible_slice(slice).map(|reader| reader.to_entity())
}
fn new_builder() -> Self::Builder {
::core::default::Default::default()
}
fn as_builder(self) -> Self::Builder {
Self::new_builder().set(self.to_opt())
}
}
#[derive(Clone, Copy)]
pub struct AmountOptReader<'r>(&'r [u8]);
impl<'r> ::core::fmt::LowerHex for AmountOptReader<'r> {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
use molecule::hex_string;
if f.alternate() {
write!(f, "0x")?;
}
write!(f, "{}", hex_string(self.as_slice()))
}
}
impl<'r> ::core::fmt::Debug for AmountOptReader<'r> {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
write!(f, "{}({:#x})", Self::NAME, self)
}
}
impl<'r> ::core::fmt::Display for AmountOptReader<'r> {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
if let Some(v) = self.to_opt() {
write!(f, "{}(Some({}))", Self::NAME, v)
} else {
write!(f, "{}(None)", Self::NAME)
}
}
}
impl<'r> AmountOptReader<'r> {
pub fn is_none(&self) -> bool {
self.0.is_empty()
}
pub fn is_some(&self) -> bool {
!self.0.is_empty()
}
pub fn to_opt(&self) -> Option<Uint128Reader<'r>> {
if self.is_none() {
None
} else {
Some(Uint128Reader::new_unchecked(self.as_slice()))
}
}
}
impl<'r> molecule::prelude::Reader<'r> for AmountOptReader<'r> {
type Entity = AmountOpt;
const NAME: &'static str = "AmountOptReader";
fn to_entity(&self) -> Self::Entity {
Self::Entity::new_unchecked(self.as_slice().to_owned().into())
}
fn new_unchecked(slice: &'r [u8]) -> Self {
AmountOptReader(slice)
}
fn as_slice(&self) -> &'r [u8] {
self.0
}
fn verify(slice: &[u8], compatible: bool) -> molecule::error::VerificationResult<()> {
if !slice.is_empty() {
Uint128Reader::verify(&slice[..], compatible)?;
}
Ok(())
}
}
#[derive(Clone, Debug, Default)]
pub struct AmountOptBuilder(pub(crate) Option<Uint128>);
impl AmountOptBuilder {
pub fn set(mut self, v: Option<Uint128>) -> Self {
self.0 = v;
self
}
}
impl molecule::prelude::Builder for AmountOptBuilder {
type Entity = AmountOpt;
const NAME: &'static str = "AmountOptBuilder";
fn expected_length(&self) -> usize {
self.0
.as_ref()
.map(|ref inner| inner.as_slice().len())
.unwrap_or(0)
}
fn write<W: molecule::io::Write>(&self, writer: &mut W) -> molecule::io::Result<()> {
self.0
.as_ref()
.map(|ref inner| writer.write_all(inner.as_slice()))
.unwrap_or(Ok(()))
}
fn build(&self) -> Self::Entity {
let mut inner = Vec::with_capacity(self.expected_length());
self.write(&mut inner)
.unwrap_or_else(|_| panic!("{} build should be ok", Self::NAME));
AmountOpt::new_unchecked(inner.into())
}
}
impl From<Uint128> for AmountOpt {
fn from(value: Uint128) -> Self {
Self::new_builder().set(Some(value)).build()
}
}
#[derive(Clone)]
pub struct FinalHtlcTimeout(molecule::bytes::Bytes);
impl ::core::fmt::LowerHex for FinalHtlcTimeout {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
use molecule::hex_string;
if f.alternate() {
write!(f, "0x")?;
}
write!(f, "{}", hex_string(self.as_slice()))
}
}
impl ::core::fmt::Debug for FinalHtlcTimeout {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
write!(f, "{}({:#x})", Self::NAME, self)
}
}
impl ::core::fmt::Display for FinalHtlcTimeout {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
write!(f, "{} {{ ", Self::NAME)?;
write!(f, "{}: {}", "value", self.value())?;
write!(f, " }}")
}
}
impl ::core::default::Default for FinalHtlcTimeout {
fn default() -> Self {
let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE);
FinalHtlcTimeout::new_unchecked(v)
}
}
impl FinalHtlcTimeout {
const DEFAULT_VALUE: [u8; 8] = [0, 0, 0, 0, 0, 0, 0, 0];
pub const TOTAL_SIZE: usize = 8;
pub const FIELD_SIZES: [usize; 1] = [8];
pub const FIELD_COUNT: usize = 1;
pub fn value(&self) -> Uint64 {
Uint64::new_unchecked(self.0.slice(0..8))
}
pub fn as_reader<'r>(&'r self) -> FinalHtlcTimeoutReader<'r> {
FinalHtlcTimeoutReader::new_unchecked(self.as_slice())
}
}
impl molecule::prelude::Entity for FinalHtlcTimeout {
type Builder = FinalHtlcTimeoutBuilder;
const NAME: &'static str = "FinalHtlcTimeout";
fn new_unchecked(data: molecule::bytes::Bytes) -> Self {
FinalHtlcTimeout(data)
}
fn as_bytes(&self) -> molecule::bytes::Bytes {
self.0.clone()
}
fn as_slice(&self) -> &[u8] {
&self.0[..]
}
fn from_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
FinalHtlcTimeoutReader::from_slice(slice).map(|reader| reader.to_entity())
}
fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
FinalHtlcTimeoutReader::from_compatible_slice(slice).map(|reader| reader.to_entity())
}
fn new_builder() -> Self::Builder {
::core::default::Default::default()
}
fn as_builder(self) -> Self::Builder {
Self::new_builder().value(self.value())
}
}
#[derive(Clone, Copy)]
pub struct FinalHtlcTimeoutReader<'r>(&'r [u8]);
impl<'r> ::core::fmt::LowerHex for FinalHtlcTimeoutReader<'r> {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
use molecule::hex_string;
if f.alternate() {
write!(f, "0x")?;
}
write!(f, "{}", hex_string(self.as_slice()))
}
}
impl<'r> ::core::fmt::Debug for FinalHtlcTimeoutReader<'r> {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
write!(f, "{}({:#x})", Self::NAME, self)
}
}
impl<'r> ::core::fmt::Display for FinalHtlcTimeoutReader<'r> {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
write!(f, "{} {{ ", Self::NAME)?;
write!(f, "{}: {}", "value", self.value())?;
write!(f, " }}")
}
}
impl<'r> FinalHtlcTimeoutReader<'r> {
pub const TOTAL_SIZE: usize = 8;
pub const FIELD_SIZES: [usize; 1] = [8];
pub const FIELD_COUNT: usize = 1;
pub fn value(&self) -> Uint64Reader<'r> {
Uint64Reader::new_unchecked(&self.as_slice()[0..8])
}
}
impl<'r> molecule::prelude::Reader<'r> for FinalHtlcTimeoutReader<'r> {
type Entity = FinalHtlcTimeout;
const NAME: &'static str = "FinalHtlcTimeoutReader";
fn to_entity(&self) -> Self::Entity {
Self::Entity::new_unchecked(self.as_slice().to_owned().into())
}
fn new_unchecked(slice: &'r [u8]) -> Self {
FinalHtlcTimeoutReader(slice)
}
fn as_slice(&self) -> &'r [u8] {
self.0
}
fn verify(slice: &[u8], _compatible: bool) -> molecule::error::VerificationResult<()> {
use molecule::verification_error as ve;
let slice_len = slice.len();
if slice_len != Self::TOTAL_SIZE {
return ve!(Self, TotalSizeNotMatch, Self::TOTAL_SIZE, slice_len);
}
Ok(())
}
}
#[derive(Clone, Debug, Default)]
pub struct FinalHtlcTimeoutBuilder {
pub(crate) value: Uint64,
}
impl FinalHtlcTimeoutBuilder {
pub const TOTAL_SIZE: usize = 8;
pub const FIELD_SIZES: [usize; 1] = [8];
pub const FIELD_COUNT: usize = 1;
pub fn value(mut self, v: Uint64) -> Self {
self.value = v;
self
}
}
impl molecule::prelude::Builder for FinalHtlcTimeoutBuilder {
type Entity = FinalHtlcTimeout;
const NAME: &'static str = "FinalHtlcTimeoutBuilder";
fn expected_length(&self) -> usize {
Self::TOTAL_SIZE
}
fn write<W: molecule::io::Write>(&self, writer: &mut W) -> molecule::io::Result<()> {
writer.write_all(self.value.as_slice())?;
Ok(())
}
fn build(&self) -> Self::Entity {
let mut inner = Vec::with_capacity(self.expected_length());
self.write(&mut inner)
.unwrap_or_else(|_| panic!("{} build should be ok", Self::NAME));
FinalHtlcTimeout::new_unchecked(inner.into())
}
}
#[derive(Clone)]
pub struct FinalHtlcMinimumExpiryDelta(molecule::bytes::Bytes);
impl ::core::fmt::LowerHex for FinalHtlcMinimumExpiryDelta {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
use molecule::hex_string;
if f.alternate() {
write!(f, "0x")?;
}
write!(f, "{}", hex_string(self.as_slice()))
}
}
impl ::core::fmt::Debug for FinalHtlcMinimumExpiryDelta {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
write!(f, "{}({:#x})", Self::NAME, self)
}
}
impl ::core::fmt::Display for FinalHtlcMinimumExpiryDelta {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
write!(f, "{} {{ ", Self::NAME)?;
write!(f, "{}: {}", "value", self.value())?;
write!(f, " }}")
}
}
impl ::core::default::Default for FinalHtlcMinimumExpiryDelta {
fn default() -> Self {
let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE);
FinalHtlcMinimumExpiryDelta::new_unchecked(v)
}
}
impl FinalHtlcMinimumExpiryDelta {
const DEFAULT_VALUE: [u8; 8] = [0, 0, 0, 0, 0, 0, 0, 0];
pub const TOTAL_SIZE: usize = 8;
pub const FIELD_SIZES: [usize; 1] = [8];
pub const FIELD_COUNT: usize = 1;
pub fn value(&self) -> Uint64 {
Uint64::new_unchecked(self.0.slice(0..8))
}
pub fn as_reader<'r>(&'r self) -> FinalHtlcMinimumExpiryDeltaReader<'r> {
FinalHtlcMinimumExpiryDeltaReader::new_unchecked(self.as_slice())
}
}
impl molecule::prelude::Entity for FinalHtlcMinimumExpiryDelta {
type Builder = FinalHtlcMinimumExpiryDeltaBuilder;
const NAME: &'static str = "FinalHtlcMinimumExpiryDelta";
fn new_unchecked(data: molecule::bytes::Bytes) -> Self {
FinalHtlcMinimumExpiryDelta(data)
}
fn as_bytes(&self) -> molecule::bytes::Bytes {
self.0.clone()
}
fn as_slice(&self) -> &[u8] {
&self.0[..]
}
fn from_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
FinalHtlcMinimumExpiryDeltaReader::from_slice(slice).map(|reader| reader.to_entity())
}
fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
FinalHtlcMinimumExpiryDeltaReader::from_compatible_slice(slice)
.map(|reader| reader.to_entity())
}
fn new_builder() -> Self::Builder {
::core::default::Default::default()
}
fn as_builder(self) -> Self::Builder {
Self::new_builder().value(self.value())
}
}
#[derive(Clone, Copy)]
pub struct FinalHtlcMinimumExpiryDeltaReader<'r>(&'r [u8]);
impl<'r> ::core::fmt::LowerHex for FinalHtlcMinimumExpiryDeltaReader<'r> {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
use molecule::hex_string;
if f.alternate() {
write!(f, "0x")?;
}
write!(f, "{}", hex_string(self.as_slice()))
}
}
impl<'r> ::core::fmt::Debug for FinalHtlcMinimumExpiryDeltaReader<'r> {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
write!(f, "{}({:#x})", Self::NAME, self)
}
}
impl<'r> ::core::fmt::Display for FinalHtlcMinimumExpiryDeltaReader<'r> {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
write!(f, "{} {{ ", Self::NAME)?;
write!(f, "{}: {}", "value", self.value())?;
write!(f, " }}")
}
}
impl<'r> FinalHtlcMinimumExpiryDeltaReader<'r> {
pub const TOTAL_SIZE: usize = 8;
pub const FIELD_SIZES: [usize; 1] = [8];
pub const FIELD_COUNT: usize = 1;
pub fn value(&self) -> Uint64Reader<'r> {
Uint64Reader::new_unchecked(&self.as_slice()[0..8])
}
}
impl<'r> molecule::prelude::Reader<'r> for FinalHtlcMinimumExpiryDeltaReader<'r> {
type Entity = FinalHtlcMinimumExpiryDelta;
const NAME: &'static str = "FinalHtlcMinimumExpiryDeltaReader";
fn to_entity(&self) -> Self::Entity {
Self::Entity::new_unchecked(self.as_slice().to_owned().into())
}
fn new_unchecked(slice: &'r [u8]) -> Self {
FinalHtlcMinimumExpiryDeltaReader(slice)
}
fn as_slice(&self) -> &'r [u8] {
self.0
}
fn verify(slice: &[u8], _compatible: bool) -> molecule::error::VerificationResult<()> {
use molecule::verification_error as ve;
let slice_len = slice.len();
if slice_len != Self::TOTAL_SIZE {
return ve!(Self, TotalSizeNotMatch, Self::TOTAL_SIZE, slice_len);
}
Ok(())
}
}
#[derive(Clone, Debug, Default)]
pub struct FinalHtlcMinimumExpiryDeltaBuilder {
pub(crate) value: Uint64,
}
impl FinalHtlcMinimumExpiryDeltaBuilder {
pub const TOTAL_SIZE: usize = 8;
pub const FIELD_SIZES: [usize; 1] = [8];
pub const FIELD_COUNT: usize = 1;
pub fn value(mut self, v: Uint64) -> Self {
self.value = v;
self
}
}
impl molecule::prelude::Builder for FinalHtlcMinimumExpiryDeltaBuilder {
type Entity = FinalHtlcMinimumExpiryDelta;
const NAME: &'static str = "FinalHtlcMinimumExpiryDeltaBuilder";
fn expected_length(&self) -> usize {
Self::TOTAL_SIZE
}
fn write<W: molecule::io::Write>(&self, writer: &mut W) -> molecule::io::Result<()> {
writer.write_all(self.value.as_slice())?;
Ok(())
}
fn build(&self) -> Self::Entity {
let mut inner = Vec::with_capacity(self.expected_length());
self.write(&mut inner)
.unwrap_or_else(|_| panic!("{} build should be ok", Self::NAME));
FinalHtlcMinimumExpiryDelta::new_unchecked(inner.into())
}
}
#[derive(Clone)]
pub struct ExpiryTime(molecule::bytes::Bytes);
impl ::core::fmt::LowerHex for ExpiryTime {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
use molecule::hex_string;
if f.alternate() {
write!(f, "0x")?;
}
write!(f, "{}", hex_string(self.as_slice()))
}
}
impl ::core::fmt::Debug for ExpiryTime {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
write!(f, "{}({:#x})", Self::NAME, self)
}
}
impl ::core::fmt::Display for ExpiryTime {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
write!(f, "{} {{ ", Self::NAME)?;
write!(f, "{}: {}", "value", self.value())?;
write!(f, " }}")
}
}
impl ::core::default::Default for ExpiryTime {
fn default() -> Self {
let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE);
ExpiryTime::new_unchecked(v)
}
}
impl ExpiryTime {
const DEFAULT_VALUE: [u8; 8] = [0, 0, 0, 0, 0, 0, 0, 0];
pub const TOTAL_SIZE: usize = 8;
pub const FIELD_SIZES: [usize; 1] = [8];
pub const FIELD_COUNT: usize = 1;
pub fn value(&self) -> Uint64 {
Uint64::new_unchecked(self.0.slice(0..8))
}
pub fn as_reader<'r>(&'r self) -> ExpiryTimeReader<'r> {
ExpiryTimeReader::new_unchecked(self.as_slice())
}
}
impl molecule::prelude::Entity for ExpiryTime {
type Builder = ExpiryTimeBuilder;
const NAME: &'static str = "ExpiryTime";
fn new_unchecked(data: molecule::bytes::Bytes) -> Self {
ExpiryTime(data)
}
fn as_bytes(&self) -> molecule::bytes::Bytes {
self.0.clone()
}
fn as_slice(&self) -> &[u8] {
&self.0[..]
}
fn from_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
ExpiryTimeReader::from_slice(slice).map(|reader| reader.to_entity())
}
fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
ExpiryTimeReader::from_compatible_slice(slice).map(|reader| reader.to_entity())
}
fn new_builder() -> Self::Builder {
::core::default::Default::default()
}
fn as_builder(self) -> Self::Builder {
Self::new_builder().value(self.value())
}
}
#[derive(Clone, Copy)]
pub struct ExpiryTimeReader<'r>(&'r [u8]);
impl<'r> ::core::fmt::LowerHex for ExpiryTimeReader<'r> {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
use molecule::hex_string;
if f.alternate() {
write!(f, "0x")?;
}
write!(f, "{}", hex_string(self.as_slice()))
}
}
impl<'r> ::core::fmt::Debug for ExpiryTimeReader<'r> {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
write!(f, "{}({:#x})", Self::NAME, self)
}
}
impl<'r> ::core::fmt::Display for ExpiryTimeReader<'r> {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
write!(f, "{} {{ ", Self::NAME)?;
write!(f, "{}: {}", "value", self.value())?;
write!(f, " }}")
}
}
impl<'r> ExpiryTimeReader<'r> {
pub const TOTAL_SIZE: usize = 8;
pub const FIELD_SIZES: [usize; 1] = [8];
pub const FIELD_COUNT: usize = 1;
pub fn value(&self) -> Uint64Reader<'r> {
Uint64Reader::new_unchecked(&self.as_slice()[0..8])
}
}
impl<'r> molecule::prelude::Reader<'r> for ExpiryTimeReader<'r> {
type Entity = ExpiryTime;
const NAME: &'static str = "ExpiryTimeReader";
fn to_entity(&self) -> Self::Entity {
Self::Entity::new_unchecked(self.as_slice().to_owned().into())
}
fn new_unchecked(slice: &'r [u8]) -> Self {
ExpiryTimeReader(slice)
}
fn as_slice(&self) -> &'r [u8] {
self.0
}
fn verify(slice: &[u8], _compatible: bool) -> molecule::error::VerificationResult<()> {
use molecule::verification_error as ve;
let slice_len = slice.len();
if slice_len != Self::TOTAL_SIZE {
return ve!(Self, TotalSizeNotMatch, Self::TOTAL_SIZE, slice_len);
}
Ok(())
}
}
#[derive(Clone, Debug, Default)]
pub struct ExpiryTimeBuilder {
pub(crate) value: Uint64,
}
impl ExpiryTimeBuilder {
pub const TOTAL_SIZE: usize = 8;
pub const FIELD_SIZES: [usize; 1] = [8];
pub const FIELD_COUNT: usize = 1;
pub fn value(mut self, v: Uint64) -> Self {
self.value = v;
self
}
}
impl molecule::prelude::Builder for ExpiryTimeBuilder {
type Entity = ExpiryTime;
const NAME: &'static str = "ExpiryTimeBuilder";
fn expected_length(&self) -> usize {
Self::TOTAL_SIZE
}
fn write<W: molecule::io::Write>(&self, writer: &mut W) -> molecule::io::Result<()> {
writer.write_all(self.value.as_slice())?;
Ok(())
}
fn build(&self) -> Self::Entity {
let mut inner = Vec::with_capacity(self.expected_length());
self.write(&mut inner)
.unwrap_or_else(|_| panic!("{} build should be ok", Self::NAME));
ExpiryTime::new_unchecked(inner.into())
}
}
#[derive(Clone)]
pub struct Description(molecule::bytes::Bytes);
impl ::core::fmt::LowerHex for Description {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
use molecule::hex_string;
if f.alternate() {
write!(f, "0x")?;
}
write!(f, "{}", hex_string(self.as_slice()))
}
}
impl ::core::fmt::Debug for Description {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
write!(f, "{}({:#x})", Self::NAME, self)
}
}
impl ::core::fmt::Display for Description {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
write!(f, "{} {{ ", Self::NAME)?;
write!(f, "{}: {}", "value", self.value())?;
let extra_count = self.count_extra_fields();
if extra_count != 0 {
write!(f, ", .. ({} fields)", extra_count)?;
}
write!(f, " }}")
}
}
impl ::core::default::Default for Description {
fn default() -> Self {
let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE);
Description::new_unchecked(v)
}
}
impl Description {
const DEFAULT_VALUE: [u8; 12] = [12, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0];
pub const FIELD_COUNT: usize = 1;
pub fn total_size(&self) -> usize {
molecule::unpack_number(self.as_slice()) as usize
}
pub fn field_count(&self) -> usize {
if self.total_size() == molecule::NUMBER_SIZE {
0
} else {
(molecule::unpack_number(&self.as_slice()[molecule::NUMBER_SIZE..]) as usize / 4) - 1
}
}
pub fn count_extra_fields(&self) -> usize {
self.field_count() - Self::FIELD_COUNT
}
pub fn has_extra_fields(&self) -> bool {
Self::FIELD_COUNT != self.field_count()
}
pub fn value(&self) -> Bytes {
let slice = self.as_slice();
let start = molecule::unpack_number(&slice[4..]) as usize;
if self.has_extra_fields() {
let end = molecule::unpack_number(&slice[8..]) as usize;
Bytes::new_unchecked(self.0.slice(start..end))
} else {
Bytes::new_unchecked(self.0.slice(start..))
}
}
pub fn as_reader<'r>(&'r self) -> DescriptionReader<'r> {
DescriptionReader::new_unchecked(self.as_slice())
}
}
impl molecule::prelude::Entity for Description {
type Builder = DescriptionBuilder;
const NAME: &'static str = "Description";
fn new_unchecked(data: molecule::bytes::Bytes) -> Self {
Description(data)
}
fn as_bytes(&self) -> molecule::bytes::Bytes {
self.0.clone()
}
fn as_slice(&self) -> &[u8] {
&self.0[..]
}
fn from_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
DescriptionReader::from_slice(slice).map(|reader| reader.to_entity())
}
fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
DescriptionReader::from_compatible_slice(slice).map(|reader| reader.to_entity())
}
fn new_builder() -> Self::Builder {
::core::default::Default::default()
}
fn as_builder(self) -> Self::Builder {
Self::new_builder().value(self.value())
}
}
#[derive(Clone, Copy)]
pub struct DescriptionReader<'r>(&'r [u8]);
impl<'r> ::core::fmt::LowerHex for DescriptionReader<'r> {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
use molecule::hex_string;
if f.alternate() {
write!(f, "0x")?;
}
write!(f, "{}", hex_string(self.as_slice()))
}
}
impl<'r> ::core::fmt::Debug for DescriptionReader<'r> {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
write!(f, "{}({:#x})", Self::NAME, self)
}
}
impl<'r> ::core::fmt::Display for DescriptionReader<'r> {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
write!(f, "{} {{ ", Self::NAME)?;
write!(f, "{}: {}", "value", self.value())?;
let extra_count = self.count_extra_fields();
if extra_count != 0 {
write!(f, ", .. ({} fields)", extra_count)?;
}
write!(f, " }}")
}
}
impl<'r> DescriptionReader<'r> {
pub const FIELD_COUNT: usize = 1;
pub fn total_size(&self) -> usize {
molecule::unpack_number(self.as_slice()) as usize
}
pub fn field_count(&self) -> usize {
if self.total_size() == molecule::NUMBER_SIZE {
0
} else {
(molecule::unpack_number(&self.as_slice()[molecule::NUMBER_SIZE..]) as usize / 4) - 1
}
}
pub fn count_extra_fields(&self) -> usize {
self.field_count() - Self::FIELD_COUNT
}
pub fn has_extra_fields(&self) -> bool {
Self::FIELD_COUNT != self.field_count()
}
pub fn value(&self) -> BytesReader<'r> {
let slice = self.as_slice();
let start = molecule::unpack_number(&slice[4..]) as usize;
if self.has_extra_fields() {
let end = molecule::unpack_number(&slice[8..]) as usize;
BytesReader::new_unchecked(&self.as_slice()[start..end])
} else {
BytesReader::new_unchecked(&self.as_slice()[start..])
}
}
}
impl<'r> molecule::prelude::Reader<'r> for DescriptionReader<'r> {
type Entity = Description;
const NAME: &'static str = "DescriptionReader";
fn to_entity(&self) -> Self::Entity {
Self::Entity::new_unchecked(self.as_slice().to_owned().into())
}
fn new_unchecked(slice: &'r [u8]) -> Self {
DescriptionReader(slice)
}
fn as_slice(&self) -> &'r [u8] {
self.0
}
fn verify(slice: &[u8], compatible: bool) -> molecule::error::VerificationResult<()> {
use molecule::verification_error as ve;
let slice_len = slice.len();
if slice_len < molecule::NUMBER_SIZE {
return ve!(Self, HeaderIsBroken, molecule::NUMBER_SIZE, slice_len);
}
let total_size = molecule::unpack_number(slice) as usize;
if slice_len != total_size {
return ve!(Self, TotalSizeNotMatch, total_size, slice_len);
}
if slice_len < molecule::NUMBER_SIZE * 2 {
return ve!(Self, HeaderIsBroken, molecule::NUMBER_SIZE * 2, slice_len);
}
let offset_first = molecule::unpack_number(&slice[molecule::NUMBER_SIZE..]) as usize;
if offset_first % molecule::NUMBER_SIZE != 0 || offset_first < molecule::NUMBER_SIZE * 2 {
return ve!(Self, OffsetsNotMatch);
}
if slice_len < offset_first {
return ve!(Self, HeaderIsBroken, offset_first, slice_len);
}
let field_count = offset_first / molecule::NUMBER_SIZE - 1;
if field_count < Self::FIELD_COUNT {
return ve!(Self, FieldCountNotMatch, Self::FIELD_COUNT, field_count);
} else if !compatible && field_count > Self::FIELD_COUNT {
return ve!(Self, FieldCountNotMatch, Self::FIELD_COUNT, field_count);
};
let mut offsets: Vec<usize> = slice[molecule::NUMBER_SIZE..offset_first]
.chunks_exact(molecule::NUMBER_SIZE)
.map(|x| molecule::unpack_number(x) as usize)
.collect();
offsets.push(total_size);
if offsets.windows(2).any(|i| i[0] > i[1]) {
return ve!(Self, OffsetsNotMatch);
}
BytesReader::verify(&slice[offsets[0]..offsets[1]], compatible)?;
Ok(())
}
}
#[derive(Clone, Debug, Default)]
pub struct DescriptionBuilder {
pub(crate) value: Bytes,
}
impl DescriptionBuilder {
pub const FIELD_COUNT: usize = 1;
pub fn value(mut self, v: Bytes) -> Self {
self.value = v;
self
}
}
impl molecule::prelude::Builder for DescriptionBuilder {
type Entity = Description;
const NAME: &'static str = "DescriptionBuilder";
fn expected_length(&self) -> usize {
molecule::NUMBER_SIZE * (Self::FIELD_COUNT + 1) + self.value.as_slice().len()
}
fn write<W: molecule::io::Write>(&self, writer: &mut W) -> molecule::io::Result<()> {
let mut total_size = molecule::NUMBER_SIZE * (Self::FIELD_COUNT + 1);
let mut offsets = Vec::with_capacity(Self::FIELD_COUNT);
offsets.push(total_size);
total_size += self.value.as_slice().len();
writer.write_all(&molecule::pack_number(total_size as molecule::Number))?;
for offset in offsets.into_iter() {
writer.write_all(&molecule::pack_number(offset as molecule::Number))?;
}
writer.write_all(self.value.as_slice())?;
Ok(())
}
fn build(&self) -> Self::Entity {
let mut inner = Vec::with_capacity(self.expected_length());
self.write(&mut inner)
.unwrap_or_else(|_| panic!("{} build should be ok", Self::NAME));
Description::new_unchecked(inner.into())
}
}
#[derive(Clone)]
pub struct FallbackAddr(molecule::bytes::Bytes);
impl ::core::fmt::LowerHex for FallbackAddr {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
use molecule::hex_string;
if f.alternate() {
write!(f, "0x")?;
}
write!(f, "{}", hex_string(self.as_slice()))
}
}
impl ::core::fmt::Debug for FallbackAddr {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
write!(f, "{}({:#x})", Self::NAME, self)
}
}
impl ::core::fmt::Display for FallbackAddr {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
write!(f, "{} {{ ", Self::NAME)?;
write!(f, "{}: {}", "value", self.value())?;
let extra_count = self.count_extra_fields();
if extra_count != 0 {
write!(f, ", .. ({} fields)", extra_count)?;
}
write!(f, " }}")
}
}
impl ::core::default::Default for FallbackAddr {
fn default() -> Self {
let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE);
FallbackAddr::new_unchecked(v)
}
}
impl FallbackAddr {
const DEFAULT_VALUE: [u8; 12] = [12, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0];
pub const FIELD_COUNT: usize = 1;
pub fn total_size(&self) -> usize {
molecule::unpack_number(self.as_slice()) as usize
}
pub fn field_count(&self) -> usize {
if self.total_size() == molecule::NUMBER_SIZE {
0
} else {
(molecule::unpack_number(&self.as_slice()[molecule::NUMBER_SIZE..]) as usize / 4) - 1
}
}
pub fn count_extra_fields(&self) -> usize {
self.field_count() - Self::FIELD_COUNT
}
pub fn has_extra_fields(&self) -> bool {
Self::FIELD_COUNT != self.field_count()
}
pub fn value(&self) -> Bytes {
let slice = self.as_slice();
let start = molecule::unpack_number(&slice[4..]) as usize;
if self.has_extra_fields() {
let end = molecule::unpack_number(&slice[8..]) as usize;
Bytes::new_unchecked(self.0.slice(start..end))
} else {
Bytes::new_unchecked(self.0.slice(start..))
}
}
pub fn as_reader<'r>(&'r self) -> FallbackAddrReader<'r> {
FallbackAddrReader::new_unchecked(self.as_slice())
}
}
impl molecule::prelude::Entity for FallbackAddr {
type Builder = FallbackAddrBuilder;
const NAME: &'static str = "FallbackAddr";
fn new_unchecked(data: molecule::bytes::Bytes) -> Self {
FallbackAddr(data)
}
fn as_bytes(&self) -> molecule::bytes::Bytes {
self.0.clone()
}
fn as_slice(&self) -> &[u8] {
&self.0[..]
}
fn from_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
FallbackAddrReader::from_slice(slice).map(|reader| reader.to_entity())
}
fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
FallbackAddrReader::from_compatible_slice(slice).map(|reader| reader.to_entity())
}
fn new_builder() -> Self::Builder {
::core::default::Default::default()
}
fn as_builder(self) -> Self::Builder {
Self::new_builder().value(self.value())
}
}
#[derive(Clone, Copy)]
pub struct FallbackAddrReader<'r>(&'r [u8]);
impl<'r> ::core::fmt::LowerHex for FallbackAddrReader<'r> {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
use molecule::hex_string;
if f.alternate() {
write!(f, "0x")?;
}
write!(f, "{}", hex_string(self.as_slice()))
}
}
impl<'r> ::core::fmt::Debug for FallbackAddrReader<'r> {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
write!(f, "{}({:#x})", Self::NAME, self)
}
}
impl<'r> ::core::fmt::Display for FallbackAddrReader<'r> {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
write!(f, "{} {{ ", Self::NAME)?;
write!(f, "{}: {}", "value", self.value())?;
let extra_count = self.count_extra_fields();
if extra_count != 0 {
write!(f, ", .. ({} fields)", extra_count)?;
}
write!(f, " }}")
}
}
impl<'r> FallbackAddrReader<'r> {
pub const FIELD_COUNT: usize = 1;
pub fn total_size(&self) -> usize {
molecule::unpack_number(self.as_slice()) as usize
}
pub fn field_count(&self) -> usize {
if self.total_size() == molecule::NUMBER_SIZE {
0
} else {
(molecule::unpack_number(&self.as_slice()[molecule::NUMBER_SIZE..]) as usize / 4) - 1
}
}
pub fn count_extra_fields(&self) -> usize {
self.field_count() - Self::FIELD_COUNT
}
pub fn has_extra_fields(&self) -> bool {
Self::FIELD_COUNT != self.field_count()
}
pub fn value(&self) -> BytesReader<'r> {
let slice = self.as_slice();
let start = molecule::unpack_number(&slice[4..]) as usize;
if self.has_extra_fields() {
let end = molecule::unpack_number(&slice[8..]) as usize;
BytesReader::new_unchecked(&self.as_slice()[start..end])
} else {
BytesReader::new_unchecked(&self.as_slice()[start..])
}
}
}
impl<'r> molecule::prelude::Reader<'r> for FallbackAddrReader<'r> {
type Entity = FallbackAddr;
const NAME: &'static str = "FallbackAddrReader";
fn to_entity(&self) -> Self::Entity {
Self::Entity::new_unchecked(self.as_slice().to_owned().into())
}
fn new_unchecked(slice: &'r [u8]) -> Self {
FallbackAddrReader(slice)
}
fn as_slice(&self) -> &'r [u8] {
self.0
}
fn verify(slice: &[u8], compatible: bool) -> molecule::error::VerificationResult<()> {
use molecule::verification_error as ve;
let slice_len = slice.len();
if slice_len < molecule::NUMBER_SIZE {
return ve!(Self, HeaderIsBroken, molecule::NUMBER_SIZE, slice_len);
}
let total_size = molecule::unpack_number(slice) as usize;
if slice_len != total_size {
return ve!(Self, TotalSizeNotMatch, total_size, slice_len);
}
if slice_len < molecule::NUMBER_SIZE * 2 {
return ve!(Self, HeaderIsBroken, molecule::NUMBER_SIZE * 2, slice_len);
}
let offset_first = molecule::unpack_number(&slice[molecule::NUMBER_SIZE..]) as usize;
if offset_first % molecule::NUMBER_SIZE != 0 || offset_first < molecule::NUMBER_SIZE * 2 {
return ve!(Self, OffsetsNotMatch);
}
if slice_len < offset_first {
return ve!(Self, HeaderIsBroken, offset_first, slice_len);
}
let field_count = offset_first / molecule::NUMBER_SIZE - 1;
if field_count < Self::FIELD_COUNT {
return ve!(Self, FieldCountNotMatch, Self::FIELD_COUNT, field_count);
} else if !compatible && field_count > Self::FIELD_COUNT {
return ve!(Self, FieldCountNotMatch, Self::FIELD_COUNT, field_count);
};
let mut offsets: Vec<usize> = slice[molecule::NUMBER_SIZE..offset_first]
.chunks_exact(molecule::NUMBER_SIZE)
.map(|x| molecule::unpack_number(x) as usize)
.collect();
offsets.push(total_size);
if offsets.windows(2).any(|i| i[0] > i[1]) {
return ve!(Self, OffsetsNotMatch);
}
BytesReader::verify(&slice[offsets[0]..offsets[1]], compatible)?;
Ok(())
}
}
#[derive(Clone, Debug, Default)]
pub struct FallbackAddrBuilder {
pub(crate) value: Bytes,
}
impl FallbackAddrBuilder {
pub const FIELD_COUNT: usize = 1;
pub fn value(mut self, v: Bytes) -> Self {
self.value = v;
self
}
}
impl molecule::prelude::Builder for FallbackAddrBuilder {
type Entity = FallbackAddr;
const NAME: &'static str = "FallbackAddrBuilder";
fn expected_length(&self) -> usize {
molecule::NUMBER_SIZE * (Self::FIELD_COUNT + 1) + self.value.as_slice().len()
}
fn write<W: molecule::io::Write>(&self, writer: &mut W) -> molecule::io::Result<()> {
let mut total_size = molecule::NUMBER_SIZE * (Self::FIELD_COUNT + 1);
let mut offsets = Vec::with_capacity(Self::FIELD_COUNT);
offsets.push(total_size);
total_size += self.value.as_slice().len();
writer.write_all(&molecule::pack_number(total_size as molecule::Number))?;
for offset in offsets.into_iter() {
writer.write_all(&molecule::pack_number(offset as molecule::Number))?;
}
writer.write_all(self.value.as_slice())?;
Ok(())
}
fn build(&self) -> Self::Entity {
let mut inner = Vec::with_capacity(self.expected_length());
self.write(&mut inner)
.unwrap_or_else(|_| panic!("{} build should be ok", Self::NAME));
FallbackAddr::new_unchecked(inner.into())
}
}
#[derive(Clone)]
pub struct Feature(molecule::bytes::Bytes);
impl ::core::fmt::LowerHex for Feature {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
use molecule::hex_string;
if f.alternate() {
write!(f, "0x")?;
}
write!(f, "{}", hex_string(self.as_slice()))
}
}
impl ::core::fmt::Debug for Feature {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
write!(f, "{}({:#x})", Self::NAME, self)
}
}
impl ::core::fmt::Display for Feature {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
write!(f, "{} {{ ", Self::NAME)?;
write!(f, "{}: {}", "value", self.value())?;
let extra_count = self.count_extra_fields();
if extra_count != 0 {
write!(f, ", .. ({} fields)", extra_count)?;
}
write!(f, " }}")
}
}
impl ::core::default::Default for Feature {
fn default() -> Self {
let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE);
Feature::new_unchecked(v)
}
}
impl Feature {
const DEFAULT_VALUE: [u8; 12] = [12, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0];
pub const FIELD_COUNT: usize = 1;
pub fn total_size(&self) -> usize {
molecule::unpack_number(self.as_slice()) as usize
}
pub fn field_count(&self) -> usize {
if self.total_size() == molecule::NUMBER_SIZE {
0
} else {
(molecule::unpack_number(&self.as_slice()[molecule::NUMBER_SIZE..]) as usize / 4) - 1
}
}
pub fn count_extra_fields(&self) -> usize {
self.field_count() - Self::FIELD_COUNT
}
pub fn has_extra_fields(&self) -> bool {
Self::FIELD_COUNT != self.field_count()
}
pub fn value(&self) -> Bytes {
let slice = self.as_slice();
let start = molecule::unpack_number(&slice[4..]) as usize;
if self.has_extra_fields() {
let end = molecule::unpack_number(&slice[8..]) as usize;
Bytes::new_unchecked(self.0.slice(start..end))
} else {
Bytes::new_unchecked(self.0.slice(start..))
}
}
pub fn as_reader<'r>(&'r self) -> FeatureReader<'r> {
FeatureReader::new_unchecked(self.as_slice())
}
}
impl molecule::prelude::Entity for Feature {
type Builder = FeatureBuilder;
const NAME: &'static str = "Feature";
fn new_unchecked(data: molecule::bytes::Bytes) -> Self {
Feature(data)
}
fn as_bytes(&self) -> molecule::bytes::Bytes {
self.0.clone()
}
fn as_slice(&self) -> &[u8] {
&self.0[..]
}
fn from_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
FeatureReader::from_slice(slice).map(|reader| reader.to_entity())
}
fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
FeatureReader::from_compatible_slice(slice).map(|reader| reader.to_entity())
}
fn new_builder() -> Self::Builder {
::core::default::Default::default()
}
fn as_builder(self) -> Self::Builder {
Self::new_builder().value(self.value())
}
}
#[derive(Clone, Copy)]
pub struct FeatureReader<'r>(&'r [u8]);
impl<'r> ::core::fmt::LowerHex for FeatureReader<'r> {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
use molecule::hex_string;
if f.alternate() {
write!(f, "0x")?;
}
write!(f, "{}", hex_string(self.as_slice()))
}
}
impl<'r> ::core::fmt::Debug for FeatureReader<'r> {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
write!(f, "{}({:#x})", Self::NAME, self)
}
}
impl<'r> ::core::fmt::Display for FeatureReader<'r> {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
write!(f, "{} {{ ", Self::NAME)?;
write!(f, "{}: {}", "value", self.value())?;
let extra_count = self.count_extra_fields();
if extra_count != 0 {
write!(f, ", .. ({} fields)", extra_count)?;
}
write!(f, " }}")
}
}
impl<'r> FeatureReader<'r> {
pub const FIELD_COUNT: usize = 1;
pub fn total_size(&self) -> usize {
molecule::unpack_number(self.as_slice()) as usize
}
pub fn field_count(&self) -> usize {
if self.total_size() == molecule::NUMBER_SIZE {
0
} else {
(molecule::unpack_number(&self.as_slice()[molecule::NUMBER_SIZE..]) as usize / 4) - 1
}
}
pub fn count_extra_fields(&self) -> usize {
self.field_count() - Self::FIELD_COUNT
}
pub fn has_extra_fields(&self) -> bool {
Self::FIELD_COUNT != self.field_count()
}
pub fn value(&self) -> BytesReader<'r> {
let slice = self.as_slice();
let start = molecule::unpack_number(&slice[4..]) as usize;
if self.has_extra_fields() {
let end = molecule::unpack_number(&slice[8..]) as usize;
BytesReader::new_unchecked(&self.as_slice()[start..end])
} else {
BytesReader::new_unchecked(&self.as_slice()[start..])
}
}
}
impl<'r> molecule::prelude::Reader<'r> for FeatureReader<'r> {
type Entity = Feature;
const NAME: &'static str = "FeatureReader";
fn to_entity(&self) -> Self::Entity {
Self::Entity::new_unchecked(self.as_slice().to_owned().into())
}
fn new_unchecked(slice: &'r [u8]) -> Self {
FeatureReader(slice)
}
fn as_slice(&self) -> &'r [u8] {
self.0
}
fn verify(slice: &[u8], compatible: bool) -> molecule::error::VerificationResult<()> {
use molecule::verification_error as ve;
let slice_len = slice.len();
if slice_len < molecule::NUMBER_SIZE {
return ve!(Self, HeaderIsBroken, molecule::NUMBER_SIZE, slice_len);
}
let total_size = molecule::unpack_number(slice) as usize;
if slice_len != total_size {
return ve!(Self, TotalSizeNotMatch, total_size, slice_len);
}
if slice_len < molecule::NUMBER_SIZE * 2 {
return ve!(Self, HeaderIsBroken, molecule::NUMBER_SIZE * 2, slice_len);
}
let offset_first = molecule::unpack_number(&slice[molecule::NUMBER_SIZE..]) as usize;
if offset_first % molecule::NUMBER_SIZE != 0 || offset_first < molecule::NUMBER_SIZE * 2 {
return ve!(Self, OffsetsNotMatch);
}
if slice_len < offset_first {
return ve!(Self, HeaderIsBroken, offset_first, slice_len);
}
let field_count = offset_first / molecule::NUMBER_SIZE - 1;
if field_count < Self::FIELD_COUNT {
return ve!(Self, FieldCountNotMatch, Self::FIELD_COUNT, field_count);
} else if !compatible && field_count > Self::FIELD_COUNT {
return ve!(Self, FieldCountNotMatch, Self::FIELD_COUNT, field_count);
};
let mut offsets: Vec<usize> = slice[molecule::NUMBER_SIZE..offset_first]
.chunks_exact(molecule::NUMBER_SIZE)
.map(|x| molecule::unpack_number(x) as usize)
.collect();
offsets.push(total_size);
if offsets.windows(2).any(|i| i[0] > i[1]) {
return ve!(Self, OffsetsNotMatch);
}
BytesReader::verify(&slice[offsets[0]..offsets[1]], compatible)?;
Ok(())
}
}
#[derive(Clone, Debug, Default)]
pub struct FeatureBuilder {
pub(crate) value: Bytes,
}
impl FeatureBuilder {
pub const FIELD_COUNT: usize = 1;
pub fn value(mut self, v: Bytes) -> Self {
self.value = v;
self
}
}
impl molecule::prelude::Builder for FeatureBuilder {
type Entity = Feature;
const NAME: &'static str = "FeatureBuilder";
fn expected_length(&self) -> usize {
molecule::NUMBER_SIZE * (Self::FIELD_COUNT + 1) + self.value.as_slice().len()
}
fn write<W: molecule::io::Write>(&self, writer: &mut W) -> molecule::io::Result<()> {
let mut total_size = molecule::NUMBER_SIZE * (Self::FIELD_COUNT + 1);
let mut offsets = Vec::with_capacity(Self::FIELD_COUNT);
offsets.push(total_size);
total_size += self.value.as_slice().len();
writer.write_all(&molecule::pack_number(total_size as molecule::Number))?;
for offset in offsets.into_iter() {
writer.write_all(&molecule::pack_number(offset as molecule::Number))?;
}
writer.write_all(self.value.as_slice())?;
Ok(())
}
fn build(&self) -> Self::Entity {
let mut inner = Vec::with_capacity(self.expected_length());
self.write(&mut inner)
.unwrap_or_else(|_| panic!("{} build should be ok", Self::NAME));
Feature::new_unchecked(inner.into())
}
}
#[derive(Clone)]
pub struct UdtScript(molecule::bytes::Bytes);
impl ::core::fmt::LowerHex for UdtScript {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
use molecule::hex_string;
if f.alternate() {
write!(f, "0x")?;
}
write!(f, "{}", hex_string(self.as_slice()))
}
}
impl ::core::fmt::Debug for UdtScript {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
write!(f, "{}({:#x})", Self::NAME, self)
}
}
impl ::core::fmt::Display for UdtScript {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
write!(f, "{} {{ ", Self::NAME)?;
write!(f, "{}: {}", "value", self.value())?;
let extra_count = self.count_extra_fields();
if extra_count != 0 {
write!(f, ", .. ({} fields)", extra_count)?;
}
write!(f, " }}")
}
}
impl ::core::default::Default for UdtScript {
fn default() -> Self {
let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE);
UdtScript::new_unchecked(v)
}
}
impl UdtScript {
const DEFAULT_VALUE: [u8; 61] = [
61, 0, 0, 0, 8, 0, 0, 0, 53, 0, 0, 0, 16, 0, 0, 0, 48, 0, 0, 0, 49, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0,
];
pub const FIELD_COUNT: usize = 1;
pub fn total_size(&self) -> usize {
molecule::unpack_number(self.as_slice()) as usize
}
pub fn field_count(&self) -> usize {
if self.total_size() == molecule::NUMBER_SIZE {
0
} else {
(molecule::unpack_number(&self.as_slice()[molecule::NUMBER_SIZE..]) as usize / 4) - 1
}
}
pub fn count_extra_fields(&self) -> usize {
self.field_count() - Self::FIELD_COUNT
}
pub fn has_extra_fields(&self) -> bool {
Self::FIELD_COUNT != self.field_count()
}
pub fn value(&self) -> Script {
let slice = self.as_slice();
let start = molecule::unpack_number(&slice[4..]) as usize;
if self.has_extra_fields() {
let end = molecule::unpack_number(&slice[8..]) as usize;
Script::new_unchecked(self.0.slice(start..end))
} else {
Script::new_unchecked(self.0.slice(start..))
}
}
pub fn as_reader<'r>(&'r self) -> UdtScriptReader<'r> {
UdtScriptReader::new_unchecked(self.as_slice())
}
}
impl molecule::prelude::Entity for UdtScript {
type Builder = UdtScriptBuilder;
const NAME: &'static str = "UdtScript";
fn new_unchecked(data: molecule::bytes::Bytes) -> Self {
UdtScript(data)
}
fn as_bytes(&self) -> molecule::bytes::Bytes {
self.0.clone()
}
fn as_slice(&self) -> &[u8] {
&self.0[..]
}
fn from_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
UdtScriptReader::from_slice(slice).map(|reader| reader.to_entity())
}
fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
UdtScriptReader::from_compatible_slice(slice).map(|reader| reader.to_entity())
}
fn new_builder() -> Self::Builder {
::core::default::Default::default()
}
fn as_builder(self) -> Self::Builder {
Self::new_builder().value(self.value())
}
}
#[derive(Clone, Copy)]
pub struct UdtScriptReader<'r>(&'r [u8]);
impl<'r> ::core::fmt::LowerHex for UdtScriptReader<'r> {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
use molecule::hex_string;
if f.alternate() {
write!(f, "0x")?;
}
write!(f, "{}", hex_string(self.as_slice()))
}
}
impl<'r> ::core::fmt::Debug for UdtScriptReader<'r> {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
write!(f, "{}({:#x})", Self::NAME, self)
}
}
impl<'r> ::core::fmt::Display for UdtScriptReader<'r> {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
write!(f, "{} {{ ", Self::NAME)?;
write!(f, "{}: {}", "value", self.value())?;
let extra_count = self.count_extra_fields();
if extra_count != 0 {
write!(f, ", .. ({} fields)", extra_count)?;
}
write!(f, " }}")
}
}
impl<'r> UdtScriptReader<'r> {
pub const FIELD_COUNT: usize = 1;
pub fn total_size(&self) -> usize {
molecule::unpack_number(self.as_slice()) as usize
}
pub fn field_count(&self) -> usize {
if self.total_size() == molecule::NUMBER_SIZE {
0
} else {
(molecule::unpack_number(&self.as_slice()[molecule::NUMBER_SIZE..]) as usize / 4) - 1
}
}
pub fn count_extra_fields(&self) -> usize {
self.field_count() - Self::FIELD_COUNT
}
pub fn has_extra_fields(&self) -> bool {
Self::FIELD_COUNT != self.field_count()
}
pub fn value(&self) -> ScriptReader<'r> {
let slice = self.as_slice();
let start = molecule::unpack_number(&slice[4..]) as usize;
if self.has_extra_fields() {
let end = molecule::unpack_number(&slice[8..]) as usize;
ScriptReader::new_unchecked(&self.as_slice()[start..end])
} else {
ScriptReader::new_unchecked(&self.as_slice()[start..])
}
}
}
impl<'r> molecule::prelude::Reader<'r> for UdtScriptReader<'r> {
type Entity = UdtScript;
const NAME: &'static str = "UdtScriptReader";
fn to_entity(&self) -> Self::Entity {
Self::Entity::new_unchecked(self.as_slice().to_owned().into())
}
fn new_unchecked(slice: &'r [u8]) -> Self {
UdtScriptReader(slice)
}
fn as_slice(&self) -> &'r [u8] {
self.0
}
fn verify(slice: &[u8], compatible: bool) -> molecule::error::VerificationResult<()> {
use molecule::verification_error as ve;
let slice_len = slice.len();
if slice_len < molecule::NUMBER_SIZE {
return ve!(Self, HeaderIsBroken, molecule::NUMBER_SIZE, slice_len);
}
let total_size = molecule::unpack_number(slice) as usize;
if slice_len != total_size {
return ve!(Self, TotalSizeNotMatch, total_size, slice_len);
}
if slice_len < molecule::NUMBER_SIZE * 2 {
return ve!(Self, HeaderIsBroken, molecule::NUMBER_SIZE * 2, slice_len);
}
let offset_first = molecule::unpack_number(&slice[molecule::NUMBER_SIZE..]) as usize;
if offset_first % molecule::NUMBER_SIZE != 0 || offset_first < molecule::NUMBER_SIZE * 2 {
return ve!(Self, OffsetsNotMatch);
}
if slice_len < offset_first {
return ve!(Self, HeaderIsBroken, offset_first, slice_len);
}
let field_count = offset_first / molecule::NUMBER_SIZE - 1;
if field_count < Self::FIELD_COUNT {
return ve!(Self, FieldCountNotMatch, Self::FIELD_COUNT, field_count);
} else if !compatible && field_count > Self::FIELD_COUNT {
return ve!(Self, FieldCountNotMatch, Self::FIELD_COUNT, field_count);
};
let mut offsets: Vec<usize> = slice[molecule::NUMBER_SIZE..offset_first]
.chunks_exact(molecule::NUMBER_SIZE)
.map(|x| molecule::unpack_number(x) as usize)
.collect();
offsets.push(total_size);
if offsets.windows(2).any(|i| i[0] > i[1]) {
return ve!(Self, OffsetsNotMatch);
}
ScriptReader::verify(&slice[offsets[0]..offsets[1]], compatible)?;
Ok(())
}
}
#[derive(Clone, Debug, Default)]
pub struct UdtScriptBuilder {
pub(crate) value: Script,
}
impl UdtScriptBuilder {
pub const FIELD_COUNT: usize = 1;
pub fn value(mut self, v: Script) -> Self {
self.value = v;
self
}
}
impl molecule::prelude::Builder for UdtScriptBuilder {
type Entity = UdtScript;
const NAME: &'static str = "UdtScriptBuilder";
fn expected_length(&self) -> usize {
molecule::NUMBER_SIZE * (Self::FIELD_COUNT + 1) + self.value.as_slice().len()
}
fn write<W: molecule::io::Write>(&self, writer: &mut W) -> molecule::io::Result<()> {
let mut total_size = molecule::NUMBER_SIZE * (Self::FIELD_COUNT + 1);
let mut offsets = Vec::with_capacity(Self::FIELD_COUNT);
offsets.push(total_size);
total_size += self.value.as_slice().len();
writer.write_all(&molecule::pack_number(total_size as molecule::Number))?;
for offset in offsets.into_iter() {
writer.write_all(&molecule::pack_number(offset as molecule::Number))?;
}
writer.write_all(self.value.as_slice())?;
Ok(())
}
fn build(&self) -> Self::Entity {
let mut inner = Vec::with_capacity(self.expected_length());
self.write(&mut inner)
.unwrap_or_else(|_| panic!("{} build should be ok", Self::NAME));
UdtScript::new_unchecked(inner.into())
}
}
#[derive(Clone)]
pub struct PayeePublicKey(molecule::bytes::Bytes);
impl ::core::fmt::LowerHex for PayeePublicKey {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
use molecule::hex_string;
if f.alternate() {
write!(f, "0x")?;
}
write!(f, "{}", hex_string(self.as_slice()))
}
}
impl ::core::fmt::Debug for PayeePublicKey {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
write!(f, "{}({:#x})", Self::NAME, self)
}
}
impl ::core::fmt::Display for PayeePublicKey {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
write!(f, "{} {{ ", Self::NAME)?;
write!(f, "{}: {}", "value", self.value())?;
let extra_count = self.count_extra_fields();
if extra_count != 0 {
write!(f, ", .. ({} fields)", extra_count)?;
}
write!(f, " }}")
}
}
impl ::core::default::Default for PayeePublicKey {
fn default() -> Self {
let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE);
PayeePublicKey::new_unchecked(v)
}
}
impl PayeePublicKey {
const DEFAULT_VALUE: [u8; 12] = [12, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0];
pub const FIELD_COUNT: usize = 1;
pub fn total_size(&self) -> usize {
molecule::unpack_number(self.as_slice()) as usize
}
pub fn field_count(&self) -> usize {
if self.total_size() == molecule::NUMBER_SIZE {
0
} else {
(molecule::unpack_number(&self.as_slice()[molecule::NUMBER_SIZE..]) as usize / 4) - 1
}
}
pub fn count_extra_fields(&self) -> usize {
self.field_count() - Self::FIELD_COUNT
}
pub fn has_extra_fields(&self) -> bool {
Self::FIELD_COUNT != self.field_count()
}
pub fn value(&self) -> Bytes {
let slice = self.as_slice();
let start = molecule::unpack_number(&slice[4..]) as usize;
if self.has_extra_fields() {
let end = molecule::unpack_number(&slice[8..]) as usize;
Bytes::new_unchecked(self.0.slice(start..end))
} else {
Bytes::new_unchecked(self.0.slice(start..))
}
}
pub fn as_reader<'r>(&'r self) -> PayeePublicKeyReader<'r> {
PayeePublicKeyReader::new_unchecked(self.as_slice())
}
}
impl molecule::prelude::Entity for PayeePublicKey {
type Builder = PayeePublicKeyBuilder;
const NAME: &'static str = "PayeePublicKey";
fn new_unchecked(data: molecule::bytes::Bytes) -> Self {
PayeePublicKey(data)
}
fn as_bytes(&self) -> molecule::bytes::Bytes {
self.0.clone()
}
fn as_slice(&self) -> &[u8] {
&self.0[..]
}
fn from_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
PayeePublicKeyReader::from_slice(slice).map(|reader| reader.to_entity())
}
fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
PayeePublicKeyReader::from_compatible_slice(slice).map(|reader| reader.to_entity())
}
fn new_builder() -> Self::Builder {
::core::default::Default::default()
}
fn as_builder(self) -> Self::Builder {
Self::new_builder().value(self.value())
}
}
#[derive(Clone, Copy)]
pub struct PayeePublicKeyReader<'r>(&'r [u8]);
impl<'r> ::core::fmt::LowerHex for PayeePublicKeyReader<'r> {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
use molecule::hex_string;
if f.alternate() {
write!(f, "0x")?;
}
write!(f, "{}", hex_string(self.as_slice()))
}
}
impl<'r> ::core::fmt::Debug for PayeePublicKeyReader<'r> {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
write!(f, "{}({:#x})", Self::NAME, self)
}
}
impl<'r> ::core::fmt::Display for PayeePublicKeyReader<'r> {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
write!(f, "{} {{ ", Self::NAME)?;
write!(f, "{}: {}", "value", self.value())?;
let extra_count = self.count_extra_fields();
if extra_count != 0 {
write!(f, ", .. ({} fields)", extra_count)?;
}
write!(f, " }}")
}
}
impl<'r> PayeePublicKeyReader<'r> {
pub const FIELD_COUNT: usize = 1;
pub fn total_size(&self) -> usize {
molecule::unpack_number(self.as_slice()) as usize
}
pub fn field_count(&self) -> usize {
if self.total_size() == molecule::NUMBER_SIZE {
0
} else {
(molecule::unpack_number(&self.as_slice()[molecule::NUMBER_SIZE..]) as usize / 4) - 1
}
}
pub fn count_extra_fields(&self) -> usize {
self.field_count() - Self::FIELD_COUNT
}
pub fn has_extra_fields(&self) -> bool {
Self::FIELD_COUNT != self.field_count()
}
pub fn value(&self) -> BytesReader<'r> {
let slice = self.as_slice();
let start = molecule::unpack_number(&slice[4..]) as usize;
if self.has_extra_fields() {
let end = molecule::unpack_number(&slice[8..]) as usize;
BytesReader::new_unchecked(&self.as_slice()[start..end])
} else {
BytesReader::new_unchecked(&self.as_slice()[start..])
}
}
}
impl<'r> molecule::prelude::Reader<'r> for PayeePublicKeyReader<'r> {
type Entity = PayeePublicKey;
const NAME: &'static str = "PayeePublicKeyReader";
fn to_entity(&self) -> Self::Entity {
Self::Entity::new_unchecked(self.as_slice().to_owned().into())
}
fn new_unchecked(slice: &'r [u8]) -> Self {
PayeePublicKeyReader(slice)
}
fn as_slice(&self) -> &'r [u8] {
self.0
}
fn verify(slice: &[u8], compatible: bool) -> molecule::error::VerificationResult<()> {
use molecule::verification_error as ve;
let slice_len = slice.len();
if slice_len < molecule::NUMBER_SIZE {
return ve!(Self, HeaderIsBroken, molecule::NUMBER_SIZE, slice_len);
}
let total_size = molecule::unpack_number(slice) as usize;
if slice_len != total_size {
return ve!(Self, TotalSizeNotMatch, total_size, slice_len);
}
if slice_len < molecule::NUMBER_SIZE * 2 {
return ve!(Self, HeaderIsBroken, molecule::NUMBER_SIZE * 2, slice_len);
}
let offset_first = molecule::unpack_number(&slice[molecule::NUMBER_SIZE..]) as usize;
if offset_first % molecule::NUMBER_SIZE != 0 || offset_first < molecule::NUMBER_SIZE * 2 {
return ve!(Self, OffsetsNotMatch);
}
if slice_len < offset_first {
return ve!(Self, HeaderIsBroken, offset_first, slice_len);
}
let field_count = offset_first / molecule::NUMBER_SIZE - 1;
if field_count < Self::FIELD_COUNT {
return ve!(Self, FieldCountNotMatch, Self::FIELD_COUNT, field_count);
} else if !compatible && field_count > Self::FIELD_COUNT {
return ve!(Self, FieldCountNotMatch, Self::FIELD_COUNT, field_count);
};
let mut offsets: Vec<usize> = slice[molecule::NUMBER_SIZE..offset_first]
.chunks_exact(molecule::NUMBER_SIZE)
.map(|x| molecule::unpack_number(x) as usize)
.collect();
offsets.push(total_size);
if offsets.windows(2).any(|i| i[0] > i[1]) {
return ve!(Self, OffsetsNotMatch);
}
BytesReader::verify(&slice[offsets[0]..offsets[1]], compatible)?;
Ok(())
}
}
#[derive(Clone, Debug, Default)]
pub struct PayeePublicKeyBuilder {
pub(crate) value: Bytes,
}
impl PayeePublicKeyBuilder {
pub const FIELD_COUNT: usize = 1;
pub fn value(mut self, v: Bytes) -> Self {
self.value = v;
self
}
}
impl molecule::prelude::Builder for PayeePublicKeyBuilder {
type Entity = PayeePublicKey;
const NAME: &'static str = "PayeePublicKeyBuilder";
fn expected_length(&self) -> usize {
molecule::NUMBER_SIZE * (Self::FIELD_COUNT + 1) + self.value.as_slice().len()
}
fn write<W: molecule::io::Write>(&self, writer: &mut W) -> molecule::io::Result<()> {
let mut total_size = molecule::NUMBER_SIZE * (Self::FIELD_COUNT + 1);
let mut offsets = Vec::with_capacity(Self::FIELD_COUNT);
offsets.push(total_size);
total_size += self.value.as_slice().len();
writer.write_all(&molecule::pack_number(total_size as molecule::Number))?;
for offset in offsets.into_iter() {
writer.write_all(&molecule::pack_number(offset as molecule::Number))?;
}
writer.write_all(self.value.as_slice())?;
Ok(())
}
fn build(&self) -> Self::Entity {
let mut inner = Vec::with_capacity(self.expected_length());
self.write(&mut inner)
.unwrap_or_else(|_| panic!("{} build should be ok", Self::NAME));
PayeePublicKey::new_unchecked(inner.into())
}
}
#[derive(Clone)]
pub struct HashAlgorithm(molecule::bytes::Bytes);
impl ::core::fmt::LowerHex for HashAlgorithm {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
use molecule::hex_string;
if f.alternate() {
write!(f, "0x")?;
}
write!(f, "{}", hex_string(self.as_slice()))
}
}
impl ::core::fmt::Debug for HashAlgorithm {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
write!(f, "{}({:#x})", Self::NAME, self)
}
}
impl ::core::fmt::Display for HashAlgorithm {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
write!(f, "{} {{ ", Self::NAME)?;
write!(f, "{}: {}", "value", self.value())?;
write!(f, " }}")
}
}
impl ::core::default::Default for HashAlgorithm {
fn default() -> Self {
let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE);
HashAlgorithm::new_unchecked(v)
}
}
impl HashAlgorithm {
const DEFAULT_VALUE: [u8; 1] = [0];
pub const TOTAL_SIZE: usize = 1;
pub const FIELD_SIZES: [usize; 1] = [1];
pub const FIELD_COUNT: usize = 1;
pub fn value(&self) -> Byte {
Byte::new_unchecked(self.0.slice(0..1))
}
pub fn as_reader<'r>(&'r self) -> HashAlgorithmReader<'r> {
HashAlgorithmReader::new_unchecked(self.as_slice())
}
}
impl molecule::prelude::Entity for HashAlgorithm {
type Builder = HashAlgorithmBuilder;
const NAME: &'static str = "HashAlgorithm";
fn new_unchecked(data: molecule::bytes::Bytes) -> Self {
HashAlgorithm(data)
}
fn as_bytes(&self) -> molecule::bytes::Bytes {
self.0.clone()
}
fn as_slice(&self) -> &[u8] {
&self.0[..]
}
fn from_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
HashAlgorithmReader::from_slice(slice).map(|reader| reader.to_entity())
}
fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
HashAlgorithmReader::from_compatible_slice(slice).map(|reader| reader.to_entity())
}
fn new_builder() -> Self::Builder {
::core::default::Default::default()
}
fn as_builder(self) -> Self::Builder {
Self::new_builder().value(self.value())
}
}
#[derive(Clone, Copy)]
pub struct HashAlgorithmReader<'r>(&'r [u8]);
impl<'r> ::core::fmt::LowerHex for HashAlgorithmReader<'r> {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
use molecule::hex_string;
if f.alternate() {
write!(f, "0x")?;
}
write!(f, "{}", hex_string(self.as_slice()))
}
}
impl<'r> ::core::fmt::Debug for HashAlgorithmReader<'r> {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
write!(f, "{}({:#x})", Self::NAME, self)
}
}
impl<'r> ::core::fmt::Display for HashAlgorithmReader<'r> {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
write!(f, "{} {{ ", Self::NAME)?;
write!(f, "{}: {}", "value", self.value())?;
write!(f, " }}")
}
}
impl<'r> HashAlgorithmReader<'r> {
pub const TOTAL_SIZE: usize = 1;
pub const FIELD_SIZES: [usize; 1] = [1];
pub const FIELD_COUNT: usize = 1;
pub fn value(&self) -> ByteReader<'r> {
ByteReader::new_unchecked(&self.as_slice()[0..1])
}
}
impl<'r> molecule::prelude::Reader<'r> for HashAlgorithmReader<'r> {
type Entity = HashAlgorithm;
const NAME: &'static str = "HashAlgorithmReader";
fn to_entity(&self) -> Self::Entity {
Self::Entity::new_unchecked(self.as_slice().to_owned().into())
}
fn new_unchecked(slice: &'r [u8]) -> Self {
HashAlgorithmReader(slice)
}
fn as_slice(&self) -> &'r [u8] {
self.0
}
fn verify(slice: &[u8], _compatible: bool) -> molecule::error::VerificationResult<()> {
use molecule::verification_error as ve;
let slice_len = slice.len();
if slice_len != Self::TOTAL_SIZE {
return ve!(Self, TotalSizeNotMatch, Self::TOTAL_SIZE, slice_len);
}
Ok(())
}
}
#[derive(Clone, Debug, Default)]
pub struct HashAlgorithmBuilder {
pub(crate) value: Byte,
}
impl HashAlgorithmBuilder {
pub const TOTAL_SIZE: usize = 1;
pub const FIELD_SIZES: [usize; 1] = [1];
pub const FIELD_COUNT: usize = 1;
pub fn value(mut self, v: Byte) -> Self {
self.value = v;
self
}
}
impl molecule::prelude::Builder for HashAlgorithmBuilder {
type Entity = HashAlgorithm;
const NAME: &'static str = "HashAlgorithmBuilder";
fn expected_length(&self) -> usize {
Self::TOTAL_SIZE
}
fn write<W: molecule::io::Write>(&self, writer: &mut W) -> molecule::io::Result<()> {
writer.write_all(self.value.as_slice())?;
Ok(())
}
fn build(&self) -> Self::Entity {
let mut inner = Vec::with_capacity(self.expected_length());
self.write(&mut inner)
.unwrap_or_else(|_| panic!("{} build should be ok", Self::NAME));
HashAlgorithm::new_unchecked(inner.into())
}
}
#[derive(Clone)]
pub struct PaymentSecret(molecule::bytes::Bytes);
impl ::core::fmt::LowerHex for PaymentSecret {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
use molecule::hex_string;
if f.alternate() {
write!(f, "0x")?;
}
write!(f, "{}", hex_string(self.as_slice()))
}
}
impl ::core::fmt::Debug for PaymentSecret {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
write!(f, "{}({:#x})", Self::NAME, self)
}
}
impl ::core::fmt::Display for PaymentSecret {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
write!(f, "{} {{ ", Self::NAME)?;
write!(f, "{}: {}", "value", self.value())?;
write!(f, " }}")
}
}
impl ::core::default::Default for PaymentSecret {
fn default() -> Self {
let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE);
PaymentSecret::new_unchecked(v)
}
}
impl PaymentSecret {
const DEFAULT_VALUE: [u8; 32] = [
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0,
];
pub const TOTAL_SIZE: usize = 32;
pub const FIELD_SIZES: [usize; 1] = [32];
pub const FIELD_COUNT: usize = 1;
pub fn value(&self) -> Byte32 {
Byte32::new_unchecked(self.0.slice(0..32))
}
pub fn as_reader<'r>(&'r self) -> PaymentSecretReader<'r> {
PaymentSecretReader::new_unchecked(self.as_slice())
}
}
impl molecule::prelude::Entity for PaymentSecret {
type Builder = PaymentSecretBuilder;
const NAME: &'static str = "PaymentSecret";
fn new_unchecked(data: molecule::bytes::Bytes) -> Self {
PaymentSecret(data)
}
fn as_bytes(&self) -> molecule::bytes::Bytes {
self.0.clone()
}
fn as_slice(&self) -> &[u8] {
&self.0[..]
}
fn from_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
PaymentSecretReader::from_slice(slice).map(|reader| reader.to_entity())
}
fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
PaymentSecretReader::from_compatible_slice(slice).map(|reader| reader.to_entity())
}
fn new_builder() -> Self::Builder {
::core::default::Default::default()
}
fn as_builder(self) -> Self::Builder {
Self::new_builder().value(self.value())
}
}
#[derive(Clone, Copy)]
pub struct PaymentSecretReader<'r>(&'r [u8]);
impl<'r> ::core::fmt::LowerHex for PaymentSecretReader<'r> {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
use molecule::hex_string;
if f.alternate() {
write!(f, "0x")?;
}
write!(f, "{}", hex_string(self.as_slice()))
}
}
impl<'r> ::core::fmt::Debug for PaymentSecretReader<'r> {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
write!(f, "{}({:#x})", Self::NAME, self)
}
}
impl<'r> ::core::fmt::Display for PaymentSecretReader<'r> {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
write!(f, "{} {{ ", Self::NAME)?;
write!(f, "{}: {}", "value", self.value())?;
write!(f, " }}")
}
}
impl<'r> PaymentSecretReader<'r> {
pub const TOTAL_SIZE: usize = 32;
pub const FIELD_SIZES: [usize; 1] = [32];
pub const FIELD_COUNT: usize = 1;
pub fn value(&self) -> Byte32Reader<'r> {
Byte32Reader::new_unchecked(&self.as_slice()[0..32])
}
}
impl<'r> molecule::prelude::Reader<'r> for PaymentSecretReader<'r> {
type Entity = PaymentSecret;
const NAME: &'static str = "PaymentSecretReader";
fn to_entity(&self) -> Self::Entity {
Self::Entity::new_unchecked(self.as_slice().to_owned().into())
}
fn new_unchecked(slice: &'r [u8]) -> Self {
PaymentSecretReader(slice)
}
fn as_slice(&self) -> &'r [u8] {
self.0
}
fn verify(slice: &[u8], _compatible: bool) -> molecule::error::VerificationResult<()> {
use molecule::verification_error as ve;
let slice_len = slice.len();
if slice_len != Self::TOTAL_SIZE {
return ve!(Self, TotalSizeNotMatch, Self::TOTAL_SIZE, slice_len);
}
Ok(())
}
}
#[derive(Clone, Debug, Default)]
pub struct PaymentSecretBuilder {
pub(crate) value: Byte32,
}
impl PaymentSecretBuilder {
pub const TOTAL_SIZE: usize = 32;
pub const FIELD_SIZES: [usize; 1] = [32];
pub const FIELD_COUNT: usize = 1;
pub fn value(mut self, v: Byte32) -> Self {
self.value = v;
self
}
}
impl molecule::prelude::Builder for PaymentSecretBuilder {
type Entity = PaymentSecret;
const NAME: &'static str = "PaymentSecretBuilder";
fn expected_length(&self) -> usize {
Self::TOTAL_SIZE
}
fn write<W: molecule::io::Write>(&self, writer: &mut W) -> molecule::io::Result<()> {
writer.write_all(self.value.as_slice())?;
Ok(())
}
fn build(&self) -> Self::Entity {
let mut inner = Vec::with_capacity(self.expected_length());
self.write(&mut inner)
.unwrap_or_else(|_| panic!("{} build should be ok", Self::NAME));
PaymentSecret::new_unchecked(inner.into())
}
}
#[derive(Clone)]
pub struct InvoiceAttr(molecule::bytes::Bytes);
impl ::core::fmt::LowerHex for InvoiceAttr {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
use molecule::hex_string;
if f.alternate() {
write!(f, "0x")?;
}
write!(f, "{}", hex_string(self.as_slice()))
}
}
impl ::core::fmt::Debug for InvoiceAttr {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
write!(f, "{}({:#x})", Self::NAME, self)
}
}
impl ::core::fmt::Display for InvoiceAttr {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
write!(f, "{}(", Self::NAME)?;
self.to_enum().display_inner(f)?;
write!(f, ")")
}
}
impl ::core::default::Default for InvoiceAttr {
fn default() -> Self {
let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE);
InvoiceAttr::new_unchecked(v)
}
}
impl InvoiceAttr {
const DEFAULT_VALUE: [u8; 12] = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
pub const ITEMS_COUNT: usize = 10;
pub fn item_id(&self) -> molecule::Number {
molecule::unpack_number(self.as_slice())
}
pub fn to_enum(&self) -> InvoiceAttrUnion {
let inner = self.0.slice(molecule::NUMBER_SIZE..);
match self.item_id() {
0 => ExpiryTime::new_unchecked(inner).into(),
1 => Description::new_unchecked(inner).into(),
2 => FinalHtlcTimeout::new_unchecked(inner).into(),
3 => FinalHtlcMinimumExpiryDelta::new_unchecked(inner).into(),
4 => FallbackAddr::new_unchecked(inner).into(),
5 => Feature::new_unchecked(inner).into(),
6 => UdtScript::new_unchecked(inner).into(),
7 => PayeePublicKey::new_unchecked(inner).into(),
8 => HashAlgorithm::new_unchecked(inner).into(),
9 => PaymentSecret::new_unchecked(inner).into(),
_ => panic!("{}: invalid data", Self::NAME),
}
}
pub fn as_reader<'r>(&'r self) -> InvoiceAttrReader<'r> {
InvoiceAttrReader::new_unchecked(self.as_slice())
}
}
impl molecule::prelude::Entity for InvoiceAttr {
type Builder = InvoiceAttrBuilder;
const NAME: &'static str = "InvoiceAttr";
fn new_unchecked(data: molecule::bytes::Bytes) -> Self {
InvoiceAttr(data)
}
fn as_bytes(&self) -> molecule::bytes::Bytes {
self.0.clone()
}
fn as_slice(&self) -> &[u8] {
&self.0[..]
}
fn from_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
InvoiceAttrReader::from_slice(slice).map(|reader| reader.to_entity())
}
fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
InvoiceAttrReader::from_compatible_slice(slice).map(|reader| reader.to_entity())
}
fn new_builder() -> Self::Builder {
::core::default::Default::default()
}
fn as_builder(self) -> Self::Builder {
Self::new_builder().set(self.to_enum())
}
}
#[derive(Clone, Copy)]
pub struct InvoiceAttrReader<'r>(&'r [u8]);
impl<'r> ::core::fmt::LowerHex for InvoiceAttrReader<'r> {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
use molecule::hex_string;
if f.alternate() {
write!(f, "0x")?;
}
write!(f, "{}", hex_string(self.as_slice()))
}
}
impl<'r> ::core::fmt::Debug for InvoiceAttrReader<'r> {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
write!(f, "{}({:#x})", Self::NAME, self)
}
}
impl<'r> ::core::fmt::Display for InvoiceAttrReader<'r> {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
write!(f, "{}(", Self::NAME)?;
self.to_enum().display_inner(f)?;
write!(f, ")")
}
}
impl<'r> InvoiceAttrReader<'r> {
pub const ITEMS_COUNT: usize = 10;
pub fn item_id(&self) -> molecule::Number {
molecule::unpack_number(self.as_slice())
}
pub fn to_enum(&self) -> InvoiceAttrUnionReader<'r> {
let inner = &self.as_slice()[molecule::NUMBER_SIZE..];
match self.item_id() {
0 => ExpiryTimeReader::new_unchecked(inner).into(),
1 => DescriptionReader::new_unchecked(inner).into(),
2 => FinalHtlcTimeoutReader::new_unchecked(inner).into(),
3 => FinalHtlcMinimumExpiryDeltaReader::new_unchecked(inner).into(),
4 => FallbackAddrReader::new_unchecked(inner).into(),
5 => FeatureReader::new_unchecked(inner).into(),
6 => UdtScriptReader::new_unchecked(inner).into(),
7 => PayeePublicKeyReader::new_unchecked(inner).into(),
8 => HashAlgorithmReader::new_unchecked(inner).into(),
9 => PaymentSecretReader::new_unchecked(inner).into(),
_ => panic!("{}: invalid data", Self::NAME),
}
}
}
impl<'r> molecule::prelude::Reader<'r> for InvoiceAttrReader<'r> {
type Entity = InvoiceAttr;
const NAME: &'static str = "InvoiceAttrReader";
fn to_entity(&self) -> Self::Entity {
Self::Entity::new_unchecked(self.as_slice().to_owned().into())
}
fn new_unchecked(slice: &'r [u8]) -> Self {
InvoiceAttrReader(slice)
}
fn as_slice(&self) -> &'r [u8] {
self.0
}
fn verify(slice: &[u8], compatible: bool) -> molecule::error::VerificationResult<()> {
use molecule::verification_error as ve;
let slice_len = slice.len();
if slice_len < molecule::NUMBER_SIZE {
return ve!(Self, HeaderIsBroken, molecule::NUMBER_SIZE, slice_len);
}
let item_id = molecule::unpack_number(slice);
let inner_slice = &slice[molecule::NUMBER_SIZE..];
match item_id {
0 => ExpiryTimeReader::verify(inner_slice, compatible),
1 => DescriptionReader::verify(inner_slice, compatible),
2 => FinalHtlcTimeoutReader::verify(inner_slice, compatible),
3 => FinalHtlcMinimumExpiryDeltaReader::verify(inner_slice, compatible),
4 => FallbackAddrReader::verify(inner_slice, compatible),
5 => FeatureReader::verify(inner_slice, compatible),
6 => UdtScriptReader::verify(inner_slice, compatible),
7 => PayeePublicKeyReader::verify(inner_slice, compatible),
8 => HashAlgorithmReader::verify(inner_slice, compatible),
9 => PaymentSecretReader::verify(inner_slice, compatible),
_ => ve!(Self, UnknownItem, Self::ITEMS_COUNT, item_id),
}?;
Ok(())
}
}
#[derive(Clone, Debug, Default)]
pub struct InvoiceAttrBuilder(pub(crate) InvoiceAttrUnion);
impl InvoiceAttrBuilder {
pub const ITEMS_COUNT: usize = 10;
pub fn set<I>(mut self, v: I) -> Self
where
I: ::core::convert::Into<InvoiceAttrUnion>,
{
self.0 = v.into();
self
}
}
impl molecule::prelude::Builder for InvoiceAttrBuilder {
type Entity = InvoiceAttr;
const NAME: &'static str = "InvoiceAttrBuilder";
fn expected_length(&self) -> usize {
molecule::NUMBER_SIZE + self.0.as_slice().len()
}
fn write<W: molecule::io::Write>(&self, writer: &mut W) -> molecule::io::Result<()> {
writer.write_all(&molecule::pack_number(self.0.item_id()))?;
writer.write_all(self.0.as_slice())
}
fn build(&self) -> Self::Entity {
let mut inner = Vec::with_capacity(self.expected_length());
self.write(&mut inner)
.unwrap_or_else(|_| panic!("{} build should be ok", Self::NAME));
InvoiceAttr::new_unchecked(inner.into())
}
}
#[derive(Debug, Clone)]
pub enum InvoiceAttrUnion {
ExpiryTime(ExpiryTime),
Description(Description),
FinalHtlcTimeout(FinalHtlcTimeout),
FinalHtlcMinimumExpiryDelta(FinalHtlcMinimumExpiryDelta),
FallbackAddr(FallbackAddr),
Feature(Feature),
UdtScript(UdtScript),
PayeePublicKey(PayeePublicKey),
HashAlgorithm(HashAlgorithm),
PaymentSecret(PaymentSecret),
}
#[derive(Debug, Clone, Copy)]
pub enum InvoiceAttrUnionReader<'r> {
ExpiryTime(ExpiryTimeReader<'r>),
Description(DescriptionReader<'r>),
FinalHtlcTimeout(FinalHtlcTimeoutReader<'r>),
FinalHtlcMinimumExpiryDelta(FinalHtlcMinimumExpiryDeltaReader<'r>),
FallbackAddr(FallbackAddrReader<'r>),
Feature(FeatureReader<'r>),
UdtScript(UdtScriptReader<'r>),
PayeePublicKey(PayeePublicKeyReader<'r>),
HashAlgorithm(HashAlgorithmReader<'r>),
PaymentSecret(PaymentSecretReader<'r>),
}
impl ::core::default::Default for InvoiceAttrUnion {
fn default() -> Self {
InvoiceAttrUnion::ExpiryTime(::core::default::Default::default())
}
}
impl ::core::fmt::Display for InvoiceAttrUnion {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
InvoiceAttrUnion::ExpiryTime(ref item) => {
write!(f, "{}::{}({})", Self::NAME, ExpiryTime::NAME, item)
}
InvoiceAttrUnion::Description(ref item) => {
write!(f, "{}::{}({})", Self::NAME, Description::NAME, item)
}
InvoiceAttrUnion::FinalHtlcTimeout(ref item) => {
write!(f, "{}::{}({})", Self::NAME, FinalHtlcTimeout::NAME, item)
}
InvoiceAttrUnion::FinalHtlcMinimumExpiryDelta(ref item) => {
write!(
f,
"{}::{}({})",
Self::NAME,
FinalHtlcMinimumExpiryDelta::NAME,
item
)
}
InvoiceAttrUnion::FallbackAddr(ref item) => {
write!(f, "{}::{}({})", Self::NAME, FallbackAddr::NAME, item)
}
InvoiceAttrUnion::Feature(ref item) => {
write!(f, "{}::{}({})", Self::NAME, Feature::NAME, item)
}
InvoiceAttrUnion::UdtScript(ref item) => {
write!(f, "{}::{}({})", Self::NAME, UdtScript::NAME, item)
}
InvoiceAttrUnion::PayeePublicKey(ref item) => {
write!(f, "{}::{}({})", Self::NAME, PayeePublicKey::NAME, item)
}
InvoiceAttrUnion::HashAlgorithm(ref item) => {
write!(f, "{}::{}({})", Self::NAME, HashAlgorithm::NAME, item)
}
InvoiceAttrUnion::PaymentSecret(ref item) => {
write!(f, "{}::{}({})", Self::NAME, PaymentSecret::NAME, item)
}
}
}
}
impl<'r> ::core::fmt::Display for InvoiceAttrUnionReader<'r> {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
InvoiceAttrUnionReader::ExpiryTime(ref item) => {
write!(f, "{}::{}({})", Self::NAME, ExpiryTime::NAME, item)
}
InvoiceAttrUnionReader::Description(ref item) => {
write!(f, "{}::{}({})", Self::NAME, Description::NAME, item)
}
InvoiceAttrUnionReader::FinalHtlcTimeout(ref item) => {
write!(f, "{}::{}({})", Self::NAME, FinalHtlcTimeout::NAME, item)
}
InvoiceAttrUnionReader::FinalHtlcMinimumExpiryDelta(ref item) => {
write!(
f,
"{}::{}({})",
Self::NAME,
FinalHtlcMinimumExpiryDelta::NAME,
item
)
}
InvoiceAttrUnionReader::FallbackAddr(ref item) => {
write!(f, "{}::{}({})", Self::NAME, FallbackAddr::NAME, item)
}
InvoiceAttrUnionReader::Feature(ref item) => {
write!(f, "{}::{}({})", Self::NAME, Feature::NAME, item)
}
InvoiceAttrUnionReader::UdtScript(ref item) => {
write!(f, "{}::{}({})", Self::NAME, UdtScript::NAME, item)
}
InvoiceAttrUnionReader::PayeePublicKey(ref item) => {
write!(f, "{}::{}({})", Self::NAME, PayeePublicKey::NAME, item)
}
InvoiceAttrUnionReader::HashAlgorithm(ref item) => {
write!(f, "{}::{}({})", Self::NAME, HashAlgorithm::NAME, item)
}
InvoiceAttrUnionReader::PaymentSecret(ref item) => {
write!(f, "{}::{}({})", Self::NAME, PaymentSecret::NAME, item)
}
}
}
}
impl InvoiceAttrUnion {
pub(crate) fn display_inner(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
InvoiceAttrUnion::ExpiryTime(ref item) => write!(f, "{}", item),
InvoiceAttrUnion::Description(ref item) => write!(f, "{}", item),
InvoiceAttrUnion::FinalHtlcTimeout(ref item) => write!(f, "{}", item),
InvoiceAttrUnion::FinalHtlcMinimumExpiryDelta(ref item) => write!(f, "{}", item),
InvoiceAttrUnion::FallbackAddr(ref item) => write!(f, "{}", item),
InvoiceAttrUnion::Feature(ref item) => write!(f, "{}", item),
InvoiceAttrUnion::UdtScript(ref item) => write!(f, "{}", item),
InvoiceAttrUnion::PayeePublicKey(ref item) => write!(f, "{}", item),
InvoiceAttrUnion::HashAlgorithm(ref item) => write!(f, "{}", item),
InvoiceAttrUnion::PaymentSecret(ref item) => write!(f, "{}", item),
}
}
}
impl<'r> InvoiceAttrUnionReader<'r> {
pub(crate) fn display_inner(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
InvoiceAttrUnionReader::ExpiryTime(ref item) => write!(f, "{}", item),
InvoiceAttrUnionReader::Description(ref item) => write!(f, "{}", item),
InvoiceAttrUnionReader::FinalHtlcTimeout(ref item) => write!(f, "{}", item),
InvoiceAttrUnionReader::FinalHtlcMinimumExpiryDelta(ref item) => write!(f, "{}", item),
InvoiceAttrUnionReader::FallbackAddr(ref item) => write!(f, "{}", item),
InvoiceAttrUnionReader::Feature(ref item) => write!(f, "{}", item),
InvoiceAttrUnionReader::UdtScript(ref item) => write!(f, "{}", item),
InvoiceAttrUnionReader::PayeePublicKey(ref item) => write!(f, "{}", item),
InvoiceAttrUnionReader::HashAlgorithm(ref item) => write!(f, "{}", item),
InvoiceAttrUnionReader::PaymentSecret(ref item) => write!(f, "{}", item),
}
}
}
impl ::core::convert::From<ExpiryTime> for InvoiceAttrUnion {
fn from(item: ExpiryTime) -> Self {
InvoiceAttrUnion::ExpiryTime(item)
}
}
impl ::core::convert::From<Description> for InvoiceAttrUnion {
fn from(item: Description) -> Self {
InvoiceAttrUnion::Description(item)
}
}
impl ::core::convert::From<FinalHtlcTimeout> for InvoiceAttrUnion {
fn from(item: FinalHtlcTimeout) -> Self {
InvoiceAttrUnion::FinalHtlcTimeout(item)
}
}
impl ::core::convert::From<FinalHtlcMinimumExpiryDelta> for InvoiceAttrUnion {
fn from(item: FinalHtlcMinimumExpiryDelta) -> Self {
InvoiceAttrUnion::FinalHtlcMinimumExpiryDelta(item)
}
}
impl ::core::convert::From<FallbackAddr> for InvoiceAttrUnion {
fn from(item: FallbackAddr) -> Self {
InvoiceAttrUnion::FallbackAddr(item)
}
}
impl ::core::convert::From<Feature> for InvoiceAttrUnion {
fn from(item: Feature) -> Self {
InvoiceAttrUnion::Feature(item)
}
}
impl ::core::convert::From<UdtScript> for InvoiceAttrUnion {
fn from(item: UdtScript) -> Self {
InvoiceAttrUnion::UdtScript(item)
}
}
impl ::core::convert::From<PayeePublicKey> for InvoiceAttrUnion {
fn from(item: PayeePublicKey) -> Self {
InvoiceAttrUnion::PayeePublicKey(item)
}
}
impl ::core::convert::From<HashAlgorithm> for InvoiceAttrUnion {
fn from(item: HashAlgorithm) -> Self {
InvoiceAttrUnion::HashAlgorithm(item)
}
}
impl ::core::convert::From<PaymentSecret> for InvoiceAttrUnion {
fn from(item: PaymentSecret) -> Self {
InvoiceAttrUnion::PaymentSecret(item)
}
}
impl<'r> ::core::convert::From<ExpiryTimeReader<'r>> for InvoiceAttrUnionReader<'r> {
fn from(item: ExpiryTimeReader<'r>) -> Self {
InvoiceAttrUnionReader::ExpiryTime(item)
}
}
impl<'r> ::core::convert::From<DescriptionReader<'r>> for InvoiceAttrUnionReader<'r> {
fn from(item: DescriptionReader<'r>) -> Self {
InvoiceAttrUnionReader::Description(item)
}
}
impl<'r> ::core::convert::From<FinalHtlcTimeoutReader<'r>> for InvoiceAttrUnionReader<'r> {
fn from(item: FinalHtlcTimeoutReader<'r>) -> Self {
InvoiceAttrUnionReader::FinalHtlcTimeout(item)
}
}
impl<'r> ::core::convert::From<FinalHtlcMinimumExpiryDeltaReader<'r>>
for InvoiceAttrUnionReader<'r>
{
fn from(item: FinalHtlcMinimumExpiryDeltaReader<'r>) -> Self {
InvoiceAttrUnionReader::FinalHtlcMinimumExpiryDelta(item)
}
}
impl<'r> ::core::convert::From<FallbackAddrReader<'r>> for InvoiceAttrUnionReader<'r> {
fn from(item: FallbackAddrReader<'r>) -> Self {
InvoiceAttrUnionReader::FallbackAddr(item)
}
}
impl<'r> ::core::convert::From<FeatureReader<'r>> for InvoiceAttrUnionReader<'r> {
fn from(item: FeatureReader<'r>) -> Self {
InvoiceAttrUnionReader::Feature(item)
}
}
impl<'r> ::core::convert::From<UdtScriptReader<'r>> for InvoiceAttrUnionReader<'r> {
fn from(item: UdtScriptReader<'r>) -> Self {
InvoiceAttrUnionReader::UdtScript(item)
}
}
impl<'r> ::core::convert::From<PayeePublicKeyReader<'r>> for InvoiceAttrUnionReader<'r> {
fn from(item: PayeePublicKeyReader<'r>) -> Self {
InvoiceAttrUnionReader::PayeePublicKey(item)
}
}
impl<'r> ::core::convert::From<HashAlgorithmReader<'r>> for InvoiceAttrUnionReader<'r> {
fn from(item: HashAlgorithmReader<'r>) -> Self {
InvoiceAttrUnionReader::HashAlgorithm(item)
}
}
impl<'r> ::core::convert::From<PaymentSecretReader<'r>> for InvoiceAttrUnionReader<'r> {
fn from(item: PaymentSecretReader<'r>) -> Self {
InvoiceAttrUnionReader::PaymentSecret(item)
}
}
impl InvoiceAttrUnion {
pub const NAME: &'static str = "InvoiceAttrUnion";
pub fn as_bytes(&self) -> molecule::bytes::Bytes {
match self {
InvoiceAttrUnion::ExpiryTime(item) => item.as_bytes(),
InvoiceAttrUnion::Description(item) => item.as_bytes(),
InvoiceAttrUnion::FinalHtlcTimeout(item) => item.as_bytes(),
InvoiceAttrUnion::FinalHtlcMinimumExpiryDelta(item) => item.as_bytes(),
InvoiceAttrUnion::FallbackAddr(item) => item.as_bytes(),
InvoiceAttrUnion::Feature(item) => item.as_bytes(),
InvoiceAttrUnion::UdtScript(item) => item.as_bytes(),
InvoiceAttrUnion::PayeePublicKey(item) => item.as_bytes(),
InvoiceAttrUnion::HashAlgorithm(item) => item.as_bytes(),
InvoiceAttrUnion::PaymentSecret(item) => item.as_bytes(),
}
}
pub fn as_slice(&self) -> &[u8] {
match self {
InvoiceAttrUnion::ExpiryTime(item) => item.as_slice(),
InvoiceAttrUnion::Description(item) => item.as_slice(),
InvoiceAttrUnion::FinalHtlcTimeout(item) => item.as_slice(),
InvoiceAttrUnion::FinalHtlcMinimumExpiryDelta(item) => item.as_slice(),
InvoiceAttrUnion::FallbackAddr(item) => item.as_slice(),
InvoiceAttrUnion::Feature(item) => item.as_slice(),
InvoiceAttrUnion::UdtScript(item) => item.as_slice(),
InvoiceAttrUnion::PayeePublicKey(item) => item.as_slice(),
InvoiceAttrUnion::HashAlgorithm(item) => item.as_slice(),
InvoiceAttrUnion::PaymentSecret(item) => item.as_slice(),
}
}
pub fn item_id(&self) -> molecule::Number {
match self {
InvoiceAttrUnion::ExpiryTime(_) => 0,
InvoiceAttrUnion::Description(_) => 1,
InvoiceAttrUnion::FinalHtlcTimeout(_) => 2,
InvoiceAttrUnion::FinalHtlcMinimumExpiryDelta(_) => 3,
InvoiceAttrUnion::FallbackAddr(_) => 4,
InvoiceAttrUnion::Feature(_) => 5,
InvoiceAttrUnion::UdtScript(_) => 6,
InvoiceAttrUnion::PayeePublicKey(_) => 7,
InvoiceAttrUnion::HashAlgorithm(_) => 8,
InvoiceAttrUnion::PaymentSecret(_) => 9,
}
}
pub fn item_name(&self) -> &str {
match self {
InvoiceAttrUnion::ExpiryTime(_) => "ExpiryTime",
InvoiceAttrUnion::Description(_) => "Description",
InvoiceAttrUnion::FinalHtlcTimeout(_) => "FinalHtlcTimeout",
InvoiceAttrUnion::FinalHtlcMinimumExpiryDelta(_) => "FinalHtlcMinimumExpiryDelta",
InvoiceAttrUnion::FallbackAddr(_) => "FallbackAddr",
InvoiceAttrUnion::Feature(_) => "Feature",
InvoiceAttrUnion::UdtScript(_) => "UdtScript",
InvoiceAttrUnion::PayeePublicKey(_) => "PayeePublicKey",
InvoiceAttrUnion::HashAlgorithm(_) => "HashAlgorithm",
InvoiceAttrUnion::PaymentSecret(_) => "PaymentSecret",
}
}
pub fn as_reader<'r>(&'r self) -> InvoiceAttrUnionReader<'r> {
match self {
InvoiceAttrUnion::ExpiryTime(item) => item.as_reader().into(),
InvoiceAttrUnion::Description(item) => item.as_reader().into(),
InvoiceAttrUnion::FinalHtlcTimeout(item) => item.as_reader().into(),
InvoiceAttrUnion::FinalHtlcMinimumExpiryDelta(item) => item.as_reader().into(),
InvoiceAttrUnion::FallbackAddr(item) => item.as_reader().into(),
InvoiceAttrUnion::Feature(item) => item.as_reader().into(),
InvoiceAttrUnion::UdtScript(item) => item.as_reader().into(),
InvoiceAttrUnion::PayeePublicKey(item) => item.as_reader().into(),
InvoiceAttrUnion::HashAlgorithm(item) => item.as_reader().into(),
InvoiceAttrUnion::PaymentSecret(item) => item.as_reader().into(),
}
}
}
impl<'r> InvoiceAttrUnionReader<'r> {
pub const NAME: &'r str = "InvoiceAttrUnionReader";
pub fn as_slice(&self) -> &'r [u8] {
match self {
InvoiceAttrUnionReader::ExpiryTime(item) => item.as_slice(),
InvoiceAttrUnionReader::Description(item) => item.as_slice(),
InvoiceAttrUnionReader::FinalHtlcTimeout(item) => item.as_slice(),
InvoiceAttrUnionReader::FinalHtlcMinimumExpiryDelta(item) => item.as_slice(),
InvoiceAttrUnionReader::FallbackAddr(item) => item.as_slice(),
InvoiceAttrUnionReader::Feature(item) => item.as_slice(),
InvoiceAttrUnionReader::UdtScript(item) => item.as_slice(),
InvoiceAttrUnionReader::PayeePublicKey(item) => item.as_slice(),
InvoiceAttrUnionReader::HashAlgorithm(item) => item.as_slice(),
InvoiceAttrUnionReader::PaymentSecret(item) => item.as_slice(),
}
}
pub fn item_id(&self) -> molecule::Number {
match self {
InvoiceAttrUnionReader::ExpiryTime(_) => 0,
InvoiceAttrUnionReader::Description(_) => 1,
InvoiceAttrUnionReader::FinalHtlcTimeout(_) => 2,
InvoiceAttrUnionReader::FinalHtlcMinimumExpiryDelta(_) => 3,
InvoiceAttrUnionReader::FallbackAddr(_) => 4,
InvoiceAttrUnionReader::Feature(_) => 5,
InvoiceAttrUnionReader::UdtScript(_) => 6,
InvoiceAttrUnionReader::PayeePublicKey(_) => 7,
InvoiceAttrUnionReader::HashAlgorithm(_) => 8,
InvoiceAttrUnionReader::PaymentSecret(_) => 9,
}
}
pub fn item_name(&self) -> &str {
match self {
InvoiceAttrUnionReader::ExpiryTime(_) => "ExpiryTime",
InvoiceAttrUnionReader::Description(_) => "Description",
InvoiceAttrUnionReader::FinalHtlcTimeout(_) => "FinalHtlcTimeout",
InvoiceAttrUnionReader::FinalHtlcMinimumExpiryDelta(_) => "FinalHtlcMinimumExpiryDelta",
InvoiceAttrUnionReader::FallbackAddr(_) => "FallbackAddr",
InvoiceAttrUnionReader::Feature(_) => "Feature",
InvoiceAttrUnionReader::UdtScript(_) => "UdtScript",
InvoiceAttrUnionReader::PayeePublicKey(_) => "PayeePublicKey",
InvoiceAttrUnionReader::HashAlgorithm(_) => "HashAlgorithm",
InvoiceAttrUnionReader::PaymentSecret(_) => "PaymentSecret",
}
}
}
impl From<ExpiryTime> for InvoiceAttr {
fn from(value: ExpiryTime) -> Self {
Self::new_builder().set(value).build()
}
}
impl From<Description> for InvoiceAttr {
fn from(value: Description) -> Self {
Self::new_builder().set(value).build()
}
}
impl From<FinalHtlcTimeout> for InvoiceAttr {
fn from(value: FinalHtlcTimeout) -> Self {
Self::new_builder().set(value).build()
}
}
impl From<FinalHtlcMinimumExpiryDelta> for InvoiceAttr {
fn from(value: FinalHtlcMinimumExpiryDelta) -> Self {
Self::new_builder().set(value).build()
}
}
impl From<FallbackAddr> for InvoiceAttr {
fn from(value: FallbackAddr) -> Self {
Self::new_builder().set(value).build()
}
}
impl From<Feature> for InvoiceAttr {
fn from(value: Feature) -> Self {
Self::new_builder().set(value).build()
}
}
impl From<UdtScript> for InvoiceAttr {
fn from(value: UdtScript) -> Self {
Self::new_builder().set(value).build()
}
}
impl From<PayeePublicKey> for InvoiceAttr {
fn from(value: PayeePublicKey) -> Self {
Self::new_builder().set(value).build()
}
}
impl From<HashAlgorithm> for InvoiceAttr {
fn from(value: HashAlgorithm) -> Self {
Self::new_builder().set(value).build()
}
}
impl From<PaymentSecret> for InvoiceAttr {
fn from(value: PaymentSecret) -> Self {
Self::new_builder().set(value).build()
}
}
#[derive(Clone)]
pub struct InvoiceAttrsVec(molecule::bytes::Bytes);
impl ::core::fmt::LowerHex for InvoiceAttrsVec {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
use molecule::hex_string;
if f.alternate() {
write!(f, "0x")?;
}
write!(f, "{}", hex_string(self.as_slice()))
}
}
impl ::core::fmt::Debug for InvoiceAttrsVec {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
write!(f, "{}({:#x})", Self::NAME, self)
}
}
impl ::core::fmt::Display for InvoiceAttrsVec {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
write!(f, "{} [", Self::NAME)?;
for i in 0..self.len() {
if i == 0 {
write!(f, "{}", self.get_unchecked(i))?;
} else {
write!(f, ", {}", self.get_unchecked(i))?;
}
}
write!(f, "]")
}
}
impl ::core::default::Default for InvoiceAttrsVec {
fn default() -> Self {
let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE);
InvoiceAttrsVec::new_unchecked(v)
}
}
impl InvoiceAttrsVec {
const DEFAULT_VALUE: [u8; 4] = [4, 0, 0, 0];
pub fn total_size(&self) -> usize {
molecule::unpack_number(self.as_slice()) as usize
}
pub fn item_count(&self) -> usize {
if self.total_size() == molecule::NUMBER_SIZE {
0
} else {
(molecule::unpack_number(&self.as_slice()[molecule::NUMBER_SIZE..]) as usize / 4) - 1
}
}
pub fn len(&self) -> usize {
self.item_count()
}
pub fn is_empty(&self) -> bool {
self.len() == 0
}
pub fn get(&self, idx: usize) -> Option<InvoiceAttr> {
if idx >= self.len() {
None
} else {
Some(self.get_unchecked(idx))
}
}
pub fn get_unchecked(&self, idx: usize) -> InvoiceAttr {
let slice = self.as_slice();
let start_idx = molecule::NUMBER_SIZE * (1 + idx);
let start = molecule::unpack_number(&slice[start_idx..]) as usize;
if idx == self.len() - 1 {
InvoiceAttr::new_unchecked(self.0.slice(start..))
} else {
let end_idx = start_idx + molecule::NUMBER_SIZE;
let end = molecule::unpack_number(&slice[end_idx..]) as usize;
InvoiceAttr::new_unchecked(self.0.slice(start..end))
}
}
pub fn as_reader<'r>(&'r self) -> InvoiceAttrsVecReader<'r> {
InvoiceAttrsVecReader::new_unchecked(self.as_slice())
}
}
impl molecule::prelude::Entity for InvoiceAttrsVec {
type Builder = InvoiceAttrsVecBuilder;
const NAME: &'static str = "InvoiceAttrsVec";
fn new_unchecked(data: molecule::bytes::Bytes) -> Self {
InvoiceAttrsVec(data)
}
fn as_bytes(&self) -> molecule::bytes::Bytes {
self.0.clone()
}
fn as_slice(&self) -> &[u8] {
&self.0[..]
}
fn from_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
InvoiceAttrsVecReader::from_slice(slice).map(|reader| reader.to_entity())
}
fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
InvoiceAttrsVecReader::from_compatible_slice(slice).map(|reader| reader.to_entity())
}
fn new_builder() -> Self::Builder {
::core::default::Default::default()
}
fn as_builder(self) -> Self::Builder {
Self::new_builder().extend(self.into_iter())
}
}
#[derive(Clone, Copy)]
pub struct InvoiceAttrsVecReader<'r>(&'r [u8]);
impl<'r> ::core::fmt::LowerHex for InvoiceAttrsVecReader<'r> {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
use molecule::hex_string;
if f.alternate() {
write!(f, "0x")?;
}
write!(f, "{}", hex_string(self.as_slice()))
}
}
impl<'r> ::core::fmt::Debug for InvoiceAttrsVecReader<'r> {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
write!(f, "{}({:#x})", Self::NAME, self)
}
}
impl<'r> ::core::fmt::Display for InvoiceAttrsVecReader<'r> {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
write!(f, "{} [", Self::NAME)?;
for i in 0..self.len() {
if i == 0 {
write!(f, "{}", self.get_unchecked(i))?;
} else {
write!(f, ", {}", self.get_unchecked(i))?;
}
}
write!(f, "]")
}
}
impl<'r> InvoiceAttrsVecReader<'r> {
pub fn total_size(&self) -> usize {
molecule::unpack_number(self.as_slice()) as usize
}
pub fn item_count(&self) -> usize {
if self.total_size() == molecule::NUMBER_SIZE {
0
} else {
(molecule::unpack_number(&self.as_slice()[molecule::NUMBER_SIZE..]) as usize / 4) - 1
}
}
pub fn len(&self) -> usize {
self.item_count()
}
pub fn is_empty(&self) -> bool {
self.len() == 0
}
pub fn get(&self, idx: usize) -> Option<InvoiceAttrReader<'r>> {
if idx >= self.len() {
None
} else {
Some(self.get_unchecked(idx))
}
}
pub fn get_unchecked(&self, idx: usize) -> InvoiceAttrReader<'r> {
let slice = self.as_slice();
let start_idx = molecule::NUMBER_SIZE * (1 + idx);
let start = molecule::unpack_number(&slice[start_idx..]) as usize;
if idx == self.len() - 1 {
InvoiceAttrReader::new_unchecked(&self.as_slice()[start..])
} else {
let end_idx = start_idx + molecule::NUMBER_SIZE;
let end = molecule::unpack_number(&slice[end_idx..]) as usize;
InvoiceAttrReader::new_unchecked(&self.as_slice()[start..end])
}
}
}
impl<'r> molecule::prelude::Reader<'r> for InvoiceAttrsVecReader<'r> {
type Entity = InvoiceAttrsVec;
const NAME: &'static str = "InvoiceAttrsVecReader";
fn to_entity(&self) -> Self::Entity {
Self::Entity::new_unchecked(self.as_slice().to_owned().into())
}
fn new_unchecked(slice: &'r [u8]) -> Self {
InvoiceAttrsVecReader(slice)
}
fn as_slice(&self) -> &'r [u8] {
self.0
}
fn verify(slice: &[u8], compatible: bool) -> molecule::error::VerificationResult<()> {
use molecule::verification_error as ve;
let slice_len = slice.len();
if slice_len < molecule::NUMBER_SIZE {
return ve!(Self, HeaderIsBroken, molecule::NUMBER_SIZE, slice_len);
}
let total_size = molecule::unpack_number(slice) as usize;
if slice_len != total_size {
return ve!(Self, TotalSizeNotMatch, total_size, slice_len);
}
if slice_len == molecule::NUMBER_SIZE {
return Ok(());
}
if slice_len < molecule::NUMBER_SIZE * 2 {
return ve!(
Self,
TotalSizeNotMatch,
molecule::NUMBER_SIZE * 2,
slice_len
);
}
let offset_first = molecule::unpack_number(&slice[molecule::NUMBER_SIZE..]) as usize;
if offset_first % molecule::NUMBER_SIZE != 0 || offset_first < molecule::NUMBER_SIZE * 2 {
return ve!(Self, OffsetsNotMatch);
}
if slice_len < offset_first {
return ve!(Self, HeaderIsBroken, offset_first, slice_len);
}
let mut offsets: Vec<usize> = slice[molecule::NUMBER_SIZE..offset_first]
.chunks_exact(molecule::NUMBER_SIZE)
.map(|x| molecule::unpack_number(x) as usize)
.collect();
offsets.push(total_size);
if offsets.windows(2).any(|i| i[0] > i[1]) {
return ve!(Self, OffsetsNotMatch);
}
for pair in offsets.windows(2) {
let start = pair[0];
let end = pair[1];
InvoiceAttrReader::verify(&slice[start..end], compatible)?;
}
Ok(())
}
}
#[derive(Clone, Debug, Default)]
pub struct InvoiceAttrsVecBuilder(pub(crate) Vec<InvoiceAttr>);
impl InvoiceAttrsVecBuilder {
pub fn set(mut self, v: Vec<InvoiceAttr>) -> Self {
self.0 = v;
self
}
pub fn push(mut self, v: InvoiceAttr) -> Self {
self.0.push(v);
self
}
pub fn extend<T: ::core::iter::IntoIterator<Item = InvoiceAttr>>(mut self, iter: T) -> Self {
for elem in iter {
self.0.push(elem);
}
self
}
pub fn replace(&mut self, index: usize, v: InvoiceAttr) -> Option<InvoiceAttr> {
self.0
.get_mut(index)
.map(|item| ::core::mem::replace(item, v))
}
}
impl molecule::prelude::Builder for InvoiceAttrsVecBuilder {
type Entity = InvoiceAttrsVec;
const NAME: &'static str = "InvoiceAttrsVecBuilder";
fn expected_length(&self) -> usize {
molecule::NUMBER_SIZE * (self.0.len() + 1)
+ self
.0
.iter()
.map(|inner| inner.as_slice().len())
.sum::<usize>()
}
fn write<W: molecule::io::Write>(&self, writer: &mut W) -> molecule::io::Result<()> {
let item_count = self.0.len();
if item_count == 0 {
writer.write_all(&molecule::pack_number(
molecule::NUMBER_SIZE as molecule::Number,
))?;
} else {
let (total_size, offsets) = self.0.iter().fold(
(
molecule::NUMBER_SIZE * (item_count + 1),
Vec::with_capacity(item_count),
),
|(start, mut offsets), inner| {
offsets.push(start);
(start + inner.as_slice().len(), offsets)
},
);
writer.write_all(&molecule::pack_number(total_size as molecule::Number))?;
for offset in offsets.into_iter() {
writer.write_all(&molecule::pack_number(offset as molecule::Number))?;
}
for inner in self.0.iter() {
writer.write_all(inner.as_slice())?;
}
}
Ok(())
}
fn build(&self) -> Self::Entity {
let mut inner = Vec::with_capacity(self.expected_length());
self.write(&mut inner)
.unwrap_or_else(|_| panic!("{} build should be ok", Self::NAME));
InvoiceAttrsVec::new_unchecked(inner.into())
}
}
pub struct InvoiceAttrsVecIterator(InvoiceAttrsVec, usize, usize);
impl ::core::iter::Iterator for InvoiceAttrsVecIterator {
type Item = InvoiceAttr;
fn next(&mut self) -> Option<Self::Item> {
if self.1 >= self.2 {
None
} else {
let ret = self.0.get_unchecked(self.1);
self.1 += 1;
Some(ret)
}
}
}
impl ::core::iter::ExactSizeIterator for InvoiceAttrsVecIterator {
fn len(&self) -> usize {
self.2 - self.1
}
}
impl ::core::iter::IntoIterator for InvoiceAttrsVec {
type Item = InvoiceAttr;
type IntoIter = InvoiceAttrsVecIterator;
fn into_iter(self) -> Self::IntoIter {
let len = self.len();
InvoiceAttrsVecIterator(self, 0, len)
}
}
impl<'r> InvoiceAttrsVecReader<'r> {
pub fn iter<'t>(&'t self) -> InvoiceAttrsVecReaderIterator<'t, 'r> {
InvoiceAttrsVecReaderIterator(&self, 0, self.len())
}
}
pub struct InvoiceAttrsVecReaderIterator<'t, 'r>(&'t InvoiceAttrsVecReader<'r>, usize, usize);
impl<'t: 'r, 'r> ::core::iter::Iterator for InvoiceAttrsVecReaderIterator<'t, 'r> {
type Item = InvoiceAttrReader<'t>;
fn next(&mut self) -> Option<Self::Item> {
if self.1 >= self.2 {
None
} else {
let ret = self.0.get_unchecked(self.1);
self.1 += 1;
Some(ret)
}
}
}
impl<'t: 'r, 'r> ::core::iter::ExactSizeIterator for InvoiceAttrsVecReaderIterator<'t, 'r> {
fn len(&self) -> usize {
self.2 - self.1
}
}
impl ::core::iter::FromIterator<InvoiceAttr> for InvoiceAttrsVec {
fn from_iter<T: IntoIterator<Item = InvoiceAttr>>(iter: T) -> Self {
Self::new_builder().extend(iter).build()
}
}
#[derive(Clone)]
pub struct RawInvoiceData(molecule::bytes::Bytes);
impl ::core::fmt::LowerHex for RawInvoiceData {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
use molecule::hex_string;
if f.alternate() {
write!(f, "0x")?;
}
write!(f, "{}", hex_string(self.as_slice()))
}
}
impl ::core::fmt::Debug for RawInvoiceData {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
write!(f, "{}({:#x})", Self::NAME, self)
}
}
impl ::core::fmt::Display for RawInvoiceData {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
write!(f, "{} {{ ", Self::NAME)?;
write!(f, "{}: {}", "timestamp", self.timestamp())?;
write!(f, ", {}: {}", "payment_hash", self.payment_hash())?;
write!(f, ", {}: {}", "attrs", self.attrs())?;
let extra_count = self.count_extra_fields();
if extra_count != 0 {
write!(f, ", .. ({} fields)", extra_count)?;
}
write!(f, " }}")
}
}
impl ::core::default::Default for RawInvoiceData {
fn default() -> Self {
let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE);
RawInvoiceData::new_unchecked(v)
}
}
impl RawInvoiceData {
const DEFAULT_VALUE: [u8; 68] = [
68, 0, 0, 0, 16, 0, 0, 0, 32, 0, 0, 0, 64, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 4, 0, 0, 0,
];
pub const FIELD_COUNT: usize = 3;
pub fn total_size(&self) -> usize {
molecule::unpack_number(self.as_slice()) as usize
}
pub fn field_count(&self) -> usize {
if self.total_size() == molecule::NUMBER_SIZE {
0
} else {
(molecule::unpack_number(&self.as_slice()[molecule::NUMBER_SIZE..]) as usize / 4) - 1
}
}
pub fn count_extra_fields(&self) -> usize {
self.field_count() - Self::FIELD_COUNT
}
pub fn has_extra_fields(&self) -> bool {
Self::FIELD_COUNT != self.field_count()
}
pub fn timestamp(&self) -> Uint128 {
let slice = self.as_slice();
let start = molecule::unpack_number(&slice[4..]) as usize;
let end = molecule::unpack_number(&slice[8..]) as usize;
Uint128::new_unchecked(self.0.slice(start..end))
}
pub fn payment_hash(&self) -> PaymentHash {
let slice = self.as_slice();
let start = molecule::unpack_number(&slice[8..]) as usize;
let end = molecule::unpack_number(&slice[12..]) as usize;
PaymentHash::new_unchecked(self.0.slice(start..end))
}
pub fn attrs(&self) -> InvoiceAttrsVec {
let slice = self.as_slice();
let start = molecule::unpack_number(&slice[12..]) as usize;
if self.has_extra_fields() {
let end = molecule::unpack_number(&slice[16..]) as usize;
InvoiceAttrsVec::new_unchecked(self.0.slice(start..end))
} else {
InvoiceAttrsVec::new_unchecked(self.0.slice(start..))
}
}
pub fn as_reader<'r>(&'r self) -> RawInvoiceDataReader<'r> {
RawInvoiceDataReader::new_unchecked(self.as_slice())
}
}
impl molecule::prelude::Entity for RawInvoiceData {
type Builder = RawInvoiceDataBuilder;
const NAME: &'static str = "RawInvoiceData";
fn new_unchecked(data: molecule::bytes::Bytes) -> Self {
RawInvoiceData(data)
}
fn as_bytes(&self) -> molecule::bytes::Bytes {
self.0.clone()
}
fn as_slice(&self) -> &[u8] {
&self.0[..]
}
fn from_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
RawInvoiceDataReader::from_slice(slice).map(|reader| reader.to_entity())
}
fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
RawInvoiceDataReader::from_compatible_slice(slice).map(|reader| reader.to_entity())
}
fn new_builder() -> Self::Builder {
::core::default::Default::default()
}
fn as_builder(self) -> Self::Builder {
Self::new_builder()
.timestamp(self.timestamp())
.payment_hash(self.payment_hash())
.attrs(self.attrs())
}
}
#[derive(Clone, Copy)]
pub struct RawInvoiceDataReader<'r>(&'r [u8]);
impl<'r> ::core::fmt::LowerHex for RawInvoiceDataReader<'r> {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
use molecule::hex_string;
if f.alternate() {
write!(f, "0x")?;
}
write!(f, "{}", hex_string(self.as_slice()))
}
}
impl<'r> ::core::fmt::Debug for RawInvoiceDataReader<'r> {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
write!(f, "{}({:#x})", Self::NAME, self)
}
}
impl<'r> ::core::fmt::Display for RawInvoiceDataReader<'r> {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
write!(f, "{} {{ ", Self::NAME)?;
write!(f, "{}: {}", "timestamp", self.timestamp())?;
write!(f, ", {}: {}", "payment_hash", self.payment_hash())?;
write!(f, ", {}: {}", "attrs", self.attrs())?;
let extra_count = self.count_extra_fields();
if extra_count != 0 {
write!(f, ", .. ({} fields)", extra_count)?;
}
write!(f, " }}")
}
}
impl<'r> RawInvoiceDataReader<'r> {
pub const FIELD_COUNT: usize = 3;
pub fn total_size(&self) -> usize {
molecule::unpack_number(self.as_slice()) as usize
}
pub fn field_count(&self) -> usize {
if self.total_size() == molecule::NUMBER_SIZE {
0
} else {
(molecule::unpack_number(&self.as_slice()[molecule::NUMBER_SIZE..]) as usize / 4) - 1
}
}
pub fn count_extra_fields(&self) -> usize {
self.field_count() - Self::FIELD_COUNT
}
pub fn has_extra_fields(&self) -> bool {
Self::FIELD_COUNT != self.field_count()
}
pub fn timestamp(&self) -> Uint128Reader<'r> {
let slice = self.as_slice();
let start = molecule::unpack_number(&slice[4..]) as usize;
let end = molecule::unpack_number(&slice[8..]) as usize;
Uint128Reader::new_unchecked(&self.as_slice()[start..end])
}
pub fn payment_hash(&self) -> PaymentHashReader<'r> {
let slice = self.as_slice();
let start = molecule::unpack_number(&slice[8..]) as usize;
let end = molecule::unpack_number(&slice[12..]) as usize;
PaymentHashReader::new_unchecked(&self.as_slice()[start..end])
}
pub fn attrs(&self) -> InvoiceAttrsVecReader<'r> {
let slice = self.as_slice();
let start = molecule::unpack_number(&slice[12..]) as usize;
if self.has_extra_fields() {
let end = molecule::unpack_number(&slice[16..]) as usize;
InvoiceAttrsVecReader::new_unchecked(&self.as_slice()[start..end])
} else {
InvoiceAttrsVecReader::new_unchecked(&self.as_slice()[start..])
}
}
}
impl<'r> molecule::prelude::Reader<'r> for RawInvoiceDataReader<'r> {
type Entity = RawInvoiceData;
const NAME: &'static str = "RawInvoiceDataReader";
fn to_entity(&self) -> Self::Entity {
Self::Entity::new_unchecked(self.as_slice().to_owned().into())
}
fn new_unchecked(slice: &'r [u8]) -> Self {
RawInvoiceDataReader(slice)
}
fn as_slice(&self) -> &'r [u8] {
self.0
}
fn verify(slice: &[u8], compatible: bool) -> molecule::error::VerificationResult<()> {
use molecule::verification_error as ve;
let slice_len = slice.len();
if slice_len < molecule::NUMBER_SIZE {
return ve!(Self, HeaderIsBroken, molecule::NUMBER_SIZE, slice_len);
}
let total_size = molecule::unpack_number(slice) as usize;
if slice_len != total_size {
return ve!(Self, TotalSizeNotMatch, total_size, slice_len);
}
if slice_len < molecule::NUMBER_SIZE * 2 {
return ve!(Self, HeaderIsBroken, molecule::NUMBER_SIZE * 2, slice_len);
}
let offset_first = molecule::unpack_number(&slice[molecule::NUMBER_SIZE..]) as usize;
if offset_first % molecule::NUMBER_SIZE != 0 || offset_first < molecule::NUMBER_SIZE * 2 {
return ve!(Self, OffsetsNotMatch);
}
if slice_len < offset_first {
return ve!(Self, HeaderIsBroken, offset_first, slice_len);
}
let field_count = offset_first / molecule::NUMBER_SIZE - 1;
if field_count < Self::FIELD_COUNT {
return ve!(Self, FieldCountNotMatch, Self::FIELD_COUNT, field_count);
} else if !compatible && field_count > Self::FIELD_COUNT {
return ve!(Self, FieldCountNotMatch, Self::FIELD_COUNT, field_count);
};
let mut offsets: Vec<usize> = slice[molecule::NUMBER_SIZE..offset_first]
.chunks_exact(molecule::NUMBER_SIZE)
.map(|x| molecule::unpack_number(x) as usize)
.collect();
offsets.push(total_size);
if offsets.windows(2).any(|i| i[0] > i[1]) {
return ve!(Self, OffsetsNotMatch);
}
Uint128Reader::verify(&slice[offsets[0]..offsets[1]], compatible)?;
PaymentHashReader::verify(&slice[offsets[1]..offsets[2]], compatible)?;
InvoiceAttrsVecReader::verify(&slice[offsets[2]..offsets[3]], compatible)?;
Ok(())
}
}
#[derive(Clone, Debug, Default)]
pub struct RawInvoiceDataBuilder {
pub(crate) timestamp: Uint128,
pub(crate) payment_hash: PaymentHash,
pub(crate) attrs: InvoiceAttrsVec,
}
impl RawInvoiceDataBuilder {
pub const FIELD_COUNT: usize = 3;
pub fn timestamp(mut self, v: Uint128) -> Self {
self.timestamp = v;
self
}
pub fn payment_hash(mut self, v: PaymentHash) -> Self {
self.payment_hash = v;
self
}
pub fn attrs(mut self, v: InvoiceAttrsVec) -> Self {
self.attrs = v;
self
}
}
impl molecule::prelude::Builder for RawInvoiceDataBuilder {
type Entity = RawInvoiceData;
const NAME: &'static str = "RawInvoiceDataBuilder";
fn expected_length(&self) -> usize {
molecule::NUMBER_SIZE * (Self::FIELD_COUNT + 1)
+ self.timestamp.as_slice().len()
+ self.payment_hash.as_slice().len()
+ self.attrs.as_slice().len()
}
fn write<W: molecule::io::Write>(&self, writer: &mut W) -> molecule::io::Result<()> {
let mut total_size = molecule::NUMBER_SIZE * (Self::FIELD_COUNT + 1);
let mut offsets = Vec::with_capacity(Self::FIELD_COUNT);
offsets.push(total_size);
total_size += self.timestamp.as_slice().len();
offsets.push(total_size);
total_size += self.payment_hash.as_slice().len();
offsets.push(total_size);
total_size += self.attrs.as_slice().len();
writer.write_all(&molecule::pack_number(total_size as molecule::Number))?;
for offset in offsets.into_iter() {
writer.write_all(&molecule::pack_number(offset as molecule::Number))?;
}
writer.write_all(self.timestamp.as_slice())?;
writer.write_all(self.payment_hash.as_slice())?;
writer.write_all(self.attrs.as_slice())?;
Ok(())
}
fn build(&self) -> Self::Entity {
let mut inner = Vec::with_capacity(self.expected_length());
self.write(&mut inner)
.unwrap_or_else(|_| panic!("{} build should be ok", Self::NAME));
RawInvoiceData::new_unchecked(inner.into())
}
}
#[derive(Clone)]
pub struct RawCkbInvoice(molecule::bytes::Bytes);
impl ::core::fmt::LowerHex for RawCkbInvoice {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
use molecule::hex_string;
if f.alternate() {
write!(f, "0x")?;
}
write!(f, "{}", hex_string(self.as_slice()))
}
}
impl ::core::fmt::Debug for RawCkbInvoice {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
write!(f, "{}({:#x})", Self::NAME, self)
}
}
impl ::core::fmt::Display for RawCkbInvoice {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
write!(f, "{} {{ ", Self::NAME)?;
write!(f, "{}: {}", "currency", self.currency())?;
write!(f, ", {}: {}", "amount", self.amount())?;
write!(f, ", {}: {}", "signature", self.signature())?;
write!(f, ", {}: {}", "data", self.data())?;
let extra_count = self.count_extra_fields();
if extra_count != 0 {
write!(f, ", .. ({} fields)", extra_count)?;
}
write!(f, " }}")
}
}
impl ::core::default::Default for RawCkbInvoice {
fn default() -> Self {
let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE);
RawCkbInvoice::new_unchecked(v)
}
}
impl RawCkbInvoice {
const DEFAULT_VALUE: [u8; 89] = [
89, 0, 0, 0, 20, 0, 0, 0, 21, 0, 0, 0, 21, 0, 0, 0, 21, 0, 0, 0, 0, 68, 0, 0, 0, 16, 0, 0,
0, 32, 0, 0, 0, 64, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0,
0,
];
pub const FIELD_COUNT: usize = 4;
pub fn total_size(&self) -> usize {
molecule::unpack_number(self.as_slice()) as usize
}
pub fn field_count(&self) -> usize {
if self.total_size() == molecule::NUMBER_SIZE {
0
} else {
(molecule::unpack_number(&self.as_slice()[molecule::NUMBER_SIZE..]) as usize / 4) - 1
}
}
pub fn count_extra_fields(&self) -> usize {
self.field_count() - Self::FIELD_COUNT
}
pub fn has_extra_fields(&self) -> bool {
Self::FIELD_COUNT != self.field_count()
}
pub fn currency(&self) -> Byte {
let slice = self.as_slice();
let start = molecule::unpack_number(&slice[4..]) as usize;
let end = molecule::unpack_number(&slice[8..]) as usize;
Byte::new_unchecked(self.0.slice(start..end))
}
pub fn amount(&self) -> AmountOpt {
let slice = self.as_slice();
let start = molecule::unpack_number(&slice[8..]) as usize;
let end = molecule::unpack_number(&slice[12..]) as usize;
AmountOpt::new_unchecked(self.0.slice(start..end))
}
pub fn signature(&self) -> SignatureOpt {
let slice = self.as_slice();
let start = molecule::unpack_number(&slice[12..]) as usize;
let end = molecule::unpack_number(&slice[16..]) as usize;
SignatureOpt::new_unchecked(self.0.slice(start..end))
}
pub fn data(&self) -> RawInvoiceData {
let slice = self.as_slice();
let start = molecule::unpack_number(&slice[16..]) as usize;
if self.has_extra_fields() {
let end = molecule::unpack_number(&slice[20..]) as usize;
RawInvoiceData::new_unchecked(self.0.slice(start..end))
} else {
RawInvoiceData::new_unchecked(self.0.slice(start..))
}
}
pub fn as_reader<'r>(&'r self) -> RawCkbInvoiceReader<'r> {
RawCkbInvoiceReader::new_unchecked(self.as_slice())
}
}
impl molecule::prelude::Entity for RawCkbInvoice {
type Builder = RawCkbInvoiceBuilder;
const NAME: &'static str = "RawCkbInvoice";
fn new_unchecked(data: molecule::bytes::Bytes) -> Self {
RawCkbInvoice(data)
}
fn as_bytes(&self) -> molecule::bytes::Bytes {
self.0.clone()
}
fn as_slice(&self) -> &[u8] {
&self.0[..]
}
fn from_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
RawCkbInvoiceReader::from_slice(slice).map(|reader| reader.to_entity())
}
fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
RawCkbInvoiceReader::from_compatible_slice(slice).map(|reader| reader.to_entity())
}
fn new_builder() -> Self::Builder {
::core::default::Default::default()
}
fn as_builder(self) -> Self::Builder {
Self::new_builder()
.currency(self.currency())
.amount(self.amount())
.signature(self.signature())
.data(self.data())
}
}
#[derive(Clone, Copy)]
pub struct RawCkbInvoiceReader<'r>(&'r [u8]);
impl<'r> ::core::fmt::LowerHex for RawCkbInvoiceReader<'r> {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
use molecule::hex_string;
if f.alternate() {
write!(f, "0x")?;
}
write!(f, "{}", hex_string(self.as_slice()))
}
}
impl<'r> ::core::fmt::Debug for RawCkbInvoiceReader<'r> {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
write!(f, "{}({:#x})", Self::NAME, self)
}
}
impl<'r> ::core::fmt::Display for RawCkbInvoiceReader<'r> {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
write!(f, "{} {{ ", Self::NAME)?;
write!(f, "{}: {}", "currency", self.currency())?;
write!(f, ", {}: {}", "amount", self.amount())?;
write!(f, ", {}: {}", "signature", self.signature())?;
write!(f, ", {}: {}", "data", self.data())?;
let extra_count = self.count_extra_fields();
if extra_count != 0 {
write!(f, ", .. ({} fields)", extra_count)?;
}
write!(f, " }}")
}
}
impl<'r> RawCkbInvoiceReader<'r> {
pub const FIELD_COUNT: usize = 4;
pub fn total_size(&self) -> usize {
molecule::unpack_number(self.as_slice()) as usize
}
pub fn field_count(&self) -> usize {
if self.total_size() == molecule::NUMBER_SIZE {
0
} else {
(molecule::unpack_number(&self.as_slice()[molecule::NUMBER_SIZE..]) as usize / 4) - 1
}
}
pub fn count_extra_fields(&self) -> usize {
self.field_count() - Self::FIELD_COUNT
}
pub fn has_extra_fields(&self) -> bool {
Self::FIELD_COUNT != self.field_count()
}
pub fn currency(&self) -> ByteReader<'r> {
let slice = self.as_slice();
let start = molecule::unpack_number(&slice[4..]) as usize;
let end = molecule::unpack_number(&slice[8..]) as usize;
ByteReader::new_unchecked(&self.as_slice()[start..end])
}
pub fn amount(&self) -> AmountOptReader<'r> {
let slice = self.as_slice();
let start = molecule::unpack_number(&slice[8..]) as usize;
let end = molecule::unpack_number(&slice[12..]) as usize;
AmountOptReader::new_unchecked(&self.as_slice()[start..end])
}
pub fn signature(&self) -> SignatureOptReader<'r> {
let slice = self.as_slice();
let start = molecule::unpack_number(&slice[12..]) as usize;
let end = molecule::unpack_number(&slice[16..]) as usize;
SignatureOptReader::new_unchecked(&self.as_slice()[start..end])
}
pub fn data(&self) -> RawInvoiceDataReader<'r> {
let slice = self.as_slice();
let start = molecule::unpack_number(&slice[16..]) as usize;
if self.has_extra_fields() {
let end = molecule::unpack_number(&slice[20..]) as usize;
RawInvoiceDataReader::new_unchecked(&self.as_slice()[start..end])
} else {
RawInvoiceDataReader::new_unchecked(&self.as_slice()[start..])
}
}
}
impl<'r> molecule::prelude::Reader<'r> for RawCkbInvoiceReader<'r> {
type Entity = RawCkbInvoice;
const NAME: &'static str = "RawCkbInvoiceReader";
fn to_entity(&self) -> Self::Entity {
Self::Entity::new_unchecked(self.as_slice().to_owned().into())
}
fn new_unchecked(slice: &'r [u8]) -> Self {
RawCkbInvoiceReader(slice)
}
fn as_slice(&self) -> &'r [u8] {
self.0
}
fn verify(slice: &[u8], compatible: bool) -> molecule::error::VerificationResult<()> {
use molecule::verification_error as ve;
let slice_len = slice.len();
if slice_len < molecule::NUMBER_SIZE {
return ve!(Self, HeaderIsBroken, molecule::NUMBER_SIZE, slice_len);
}
let total_size = molecule::unpack_number(slice) as usize;
if slice_len != total_size {
return ve!(Self, TotalSizeNotMatch, total_size, slice_len);
}
if slice_len < molecule::NUMBER_SIZE * 2 {
return ve!(Self, HeaderIsBroken, molecule::NUMBER_SIZE * 2, slice_len);
}
let offset_first = molecule::unpack_number(&slice[molecule::NUMBER_SIZE..]) as usize;
if offset_first % molecule::NUMBER_SIZE != 0 || offset_first < molecule::NUMBER_SIZE * 2 {
return ve!(Self, OffsetsNotMatch);
}
if slice_len < offset_first {
return ve!(Self, HeaderIsBroken, offset_first, slice_len);
}
let field_count = offset_first / molecule::NUMBER_SIZE - 1;
if field_count < Self::FIELD_COUNT {
return ve!(Self, FieldCountNotMatch, Self::FIELD_COUNT, field_count);
} else if !compatible && field_count > Self::FIELD_COUNT {
return ve!(Self, FieldCountNotMatch, Self::FIELD_COUNT, field_count);
};
let mut offsets: Vec<usize> = slice[molecule::NUMBER_SIZE..offset_first]
.chunks_exact(molecule::NUMBER_SIZE)
.map(|x| molecule::unpack_number(x) as usize)
.collect();
offsets.push(total_size);
if offsets.windows(2).any(|i| i[0] > i[1]) {
return ve!(Self, OffsetsNotMatch);
}
ByteReader::verify(&slice[offsets[0]..offsets[1]], compatible)?;
AmountOptReader::verify(&slice[offsets[1]..offsets[2]], compatible)?;
SignatureOptReader::verify(&slice[offsets[2]..offsets[3]], compatible)?;
RawInvoiceDataReader::verify(&slice[offsets[3]..offsets[4]], compatible)?;
Ok(())
}
}
#[derive(Clone, Debug, Default)]
pub struct RawCkbInvoiceBuilder {
pub(crate) currency: Byte,
pub(crate) amount: AmountOpt,
pub(crate) signature: SignatureOpt,
pub(crate) data: RawInvoiceData,
}
impl RawCkbInvoiceBuilder {
pub const FIELD_COUNT: usize = 4;
pub fn currency(mut self, v: Byte) -> Self {
self.currency = v;
self
}
pub fn amount(mut self, v: AmountOpt) -> Self {
self.amount = v;
self
}
pub fn signature(mut self, v: SignatureOpt) -> Self {
self.signature = v;
self
}
pub fn data(mut self, v: RawInvoiceData) -> Self {
self.data = v;
self
}
}
impl molecule::prelude::Builder for RawCkbInvoiceBuilder {
type Entity = RawCkbInvoice;
const NAME: &'static str = "RawCkbInvoiceBuilder";
fn expected_length(&self) -> usize {
molecule::NUMBER_SIZE * (Self::FIELD_COUNT + 1)
+ self.currency.as_slice().len()
+ self.amount.as_slice().len()
+ self.signature.as_slice().len()
+ self.data.as_slice().len()
}
fn write<W: molecule::io::Write>(&self, writer: &mut W) -> molecule::io::Result<()> {
let mut total_size = molecule::NUMBER_SIZE * (Self::FIELD_COUNT + 1);
let mut offsets = Vec::with_capacity(Self::FIELD_COUNT);
offsets.push(total_size);
total_size += self.currency.as_slice().len();
offsets.push(total_size);
total_size += self.amount.as_slice().len();
offsets.push(total_size);
total_size += self.signature.as_slice().len();
offsets.push(total_size);
total_size += self.data.as_slice().len();
writer.write_all(&molecule::pack_number(total_size as molecule::Number))?;
for offset in offsets.into_iter() {
writer.write_all(&molecule::pack_number(offset as molecule::Number))?;
}
writer.write_all(self.currency.as_slice())?;
writer.write_all(self.amount.as_slice())?;
writer.write_all(self.signature.as_slice())?;
writer.write_all(self.data.as_slice())?;
Ok(())
}
fn build(&self) -> Self::Entity {
let mut inner = Vec::with_capacity(self.expected_length());
self.write(&mut inner)
.unwrap_or_else(|_| panic!("{} build should be ok", Self::NAME));
RawCkbInvoice::new_unchecked(inner.into())
}
}