Skip to main content

fiber_types/gen/
fiber.rs

1// Generated by Molecule 0.8.0
2
3use super::blockchain::*;
4use molecule::prelude::*;
5#[derive(Clone)]
6pub struct Uint16(molecule::bytes::Bytes);
7impl ::core::fmt::LowerHex for Uint16 {
8    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
9        use molecule::hex_string;
10        if f.alternate() {
11            write!(f, "0x")?;
12        }
13        write!(f, "{}", hex_string(self.as_slice()))
14    }
15}
16impl ::core::fmt::Debug for Uint16 {
17    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
18        write!(f, "{}({:#x})", Self::NAME, self)
19    }
20}
21impl ::core::fmt::Display for Uint16 {
22    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
23        use molecule::hex_string;
24        let raw_data = hex_string(&self.raw_data());
25        write!(f, "{}(0x{})", Self::NAME, raw_data)
26    }
27}
28impl ::core::default::Default for Uint16 {
29    fn default() -> Self {
30        let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE);
31        Uint16::new_unchecked(v)
32    }
33}
34impl Uint16 {
35    const DEFAULT_VALUE: [u8; 2] = [0, 0];
36    pub const TOTAL_SIZE: usize = 2;
37    pub const ITEM_SIZE: usize = 1;
38    pub const ITEM_COUNT: usize = 2;
39    pub fn nth0(&self) -> Byte {
40        Byte::new_unchecked(self.0.slice(0..1))
41    }
42    pub fn nth1(&self) -> Byte {
43        Byte::new_unchecked(self.0.slice(1..2))
44    }
45    pub fn raw_data(&self) -> molecule::bytes::Bytes {
46        self.as_bytes()
47    }
48    pub fn as_reader<'r>(&'r self) -> Uint16Reader<'r> {
49        Uint16Reader::new_unchecked(self.as_slice())
50    }
51}
52impl molecule::prelude::Entity for Uint16 {
53    type Builder = Uint16Builder;
54    const NAME: &'static str = "Uint16";
55    fn new_unchecked(data: molecule::bytes::Bytes) -> Self {
56        Uint16(data)
57    }
58    fn as_bytes(&self) -> molecule::bytes::Bytes {
59        self.0.clone()
60    }
61    fn as_slice(&self) -> &[u8] {
62        &self.0[..]
63    }
64    fn from_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
65        Uint16Reader::from_slice(slice).map(|reader| reader.to_entity())
66    }
67    fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
68        Uint16Reader::from_compatible_slice(slice).map(|reader| reader.to_entity())
69    }
70    fn new_builder() -> Self::Builder {
71        ::core::default::Default::default()
72    }
73    fn as_builder(self) -> Self::Builder {
74        Self::new_builder().set([self.nth0(), self.nth1()])
75    }
76}
77#[derive(Clone, Copy)]
78pub struct Uint16Reader<'r>(&'r [u8]);
79impl<'r> ::core::fmt::LowerHex for Uint16Reader<'r> {
80    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
81        use molecule::hex_string;
82        if f.alternate() {
83            write!(f, "0x")?;
84        }
85        write!(f, "{}", hex_string(self.as_slice()))
86    }
87}
88impl<'r> ::core::fmt::Debug for Uint16Reader<'r> {
89    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
90        write!(f, "{}({:#x})", Self::NAME, self)
91    }
92}
93impl<'r> ::core::fmt::Display for Uint16Reader<'r> {
94    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
95        use molecule::hex_string;
96        let raw_data = hex_string(&self.raw_data());
97        write!(f, "{}(0x{})", Self::NAME, raw_data)
98    }
99}
100impl<'r> Uint16Reader<'r> {
101    pub const TOTAL_SIZE: usize = 2;
102    pub const ITEM_SIZE: usize = 1;
103    pub const ITEM_COUNT: usize = 2;
104    pub fn nth0(&self) -> ByteReader<'r> {
105        ByteReader::new_unchecked(&self.as_slice()[0..1])
106    }
107    pub fn nth1(&self) -> ByteReader<'r> {
108        ByteReader::new_unchecked(&self.as_slice()[1..2])
109    }
110    pub fn raw_data(&self) -> &'r [u8] {
111        self.as_slice()
112    }
113}
114impl<'r> molecule::prelude::Reader<'r> for Uint16Reader<'r> {
115    type Entity = Uint16;
116    const NAME: &'static str = "Uint16Reader";
117    fn to_entity(&self) -> Self::Entity {
118        Self::Entity::new_unchecked(self.as_slice().to_owned().into())
119    }
120    fn new_unchecked(slice: &'r [u8]) -> Self {
121        Uint16Reader(slice)
122    }
123    fn as_slice(&self) -> &'r [u8] {
124        self.0
125    }
126    fn verify(slice: &[u8], _compatible: bool) -> molecule::error::VerificationResult<()> {
127        use molecule::verification_error as ve;
128        let slice_len = slice.len();
129        if slice_len != Self::TOTAL_SIZE {
130            return ve!(Self, TotalSizeNotMatch, Self::TOTAL_SIZE, slice_len);
131        }
132        Ok(())
133    }
134}
135#[derive(Clone)]
136pub struct Uint16Builder(pub(crate) [Byte; 2]);
137impl ::core::fmt::Debug for Uint16Builder {
138    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
139        write!(f, "{}({:?})", Self::NAME, &self.0[..])
140    }
141}
142impl ::core::default::Default for Uint16Builder {
143    fn default() -> Self {
144        Uint16Builder([Byte::default(), Byte::default()])
145    }
146}
147impl Uint16Builder {
148    pub const TOTAL_SIZE: usize = 2;
149    pub const ITEM_SIZE: usize = 1;
150    pub const ITEM_COUNT: usize = 2;
151    pub fn set(mut self, v: [Byte; 2]) -> Self {
152        self.0 = v;
153        self
154    }
155    pub fn nth0(mut self, v: Byte) -> Self {
156        self.0[0] = v;
157        self
158    }
159    pub fn nth1(mut self, v: Byte) -> Self {
160        self.0[1] = v;
161        self
162    }
163}
164impl molecule::prelude::Builder for Uint16Builder {
165    type Entity = Uint16;
166    const NAME: &'static str = "Uint16Builder";
167    fn expected_length(&self) -> usize {
168        Self::TOTAL_SIZE
169    }
170    fn write<W: molecule::io::Write>(&self, writer: &mut W) -> molecule::io::Result<()> {
171        writer.write_all(self.0[0].as_slice())?;
172        writer.write_all(self.0[1].as_slice())?;
173        Ok(())
174    }
175    fn build(&self) -> Self::Entity {
176        let mut inner = Vec::with_capacity(self.expected_length());
177        self.write(&mut inner)
178            .unwrap_or_else(|_| panic!("{} build should be ok", Self::NAME));
179        Uint16::new_unchecked(inner.into())
180    }
181}
182impl From<[Byte; 2usize]> for Uint16 {
183    fn from(value: [Byte; 2usize]) -> Self {
184        Self::new_builder().set(value).build()
185    }
186}
187impl ::core::convert::TryFrom<&[Byte]> for Uint16 {
188    type Error = ::core::array::TryFromSliceError;
189    fn try_from(value: &[Byte]) -> Result<Self, ::core::array::TryFromSliceError> {
190        Ok(Self::new_builder()
191            .set(<&[Byte; 2usize]>::try_from(value)?.clone())
192            .build())
193    }
194}
195impl From<Uint16> for [Byte; 2usize] {
196    #[track_caller]
197    fn from(value: Uint16) -> Self {
198        [value.nth0(), value.nth1()]
199    }
200}
201impl From<[u8; 2usize]> for Uint16 {
202    fn from(value: [u8; 2usize]) -> Self {
203        Uint16Reader::new_unchecked(&value).to_entity()
204    }
205}
206impl ::core::convert::TryFrom<&[u8]> for Uint16 {
207    type Error = ::core::array::TryFromSliceError;
208    fn try_from(value: &[u8]) -> Result<Self, ::core::array::TryFromSliceError> {
209        Ok(<[u8; 2usize]>::try_from(value)?.into())
210    }
211}
212impl From<Uint16> for [u8; 2usize] {
213    #[track_caller]
214    fn from(value: Uint16) -> Self {
215        ::core::convert::TryFrom::try_from(value.as_slice()).unwrap()
216    }
217}
218impl<'a> From<Uint16Reader<'a>> for &'a [u8; 2usize] {
219    #[track_caller]
220    fn from(value: Uint16Reader<'a>) -> Self {
221        ::core::convert::TryFrom::try_from(value.as_slice()).unwrap()
222    }
223}
224impl<'a> From<&'a Uint16Reader<'a>> for &'a [u8; 2usize] {
225    #[track_caller]
226    fn from(value: &'a Uint16Reader<'a>) -> Self {
227        ::core::convert::TryFrom::try_from(value.as_slice()).unwrap()
228    }
229}
230#[derive(Clone)]
231pub struct EcdsaSignature(molecule::bytes::Bytes);
232impl ::core::fmt::LowerHex for EcdsaSignature {
233    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
234        use molecule::hex_string;
235        if f.alternate() {
236            write!(f, "0x")?;
237        }
238        write!(f, "{}", hex_string(self.as_slice()))
239    }
240}
241impl ::core::fmt::Debug for EcdsaSignature {
242    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
243        write!(f, "{}({:#x})", Self::NAME, self)
244    }
245}
246impl ::core::fmt::Display for EcdsaSignature {
247    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
248        use molecule::hex_string;
249        let raw_data = hex_string(&self.raw_data());
250        write!(f, "{}(0x{})", Self::NAME, raw_data)
251    }
252}
253impl ::core::default::Default for EcdsaSignature {
254    fn default() -> Self {
255        let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE);
256        EcdsaSignature::new_unchecked(v)
257    }
258}
259impl EcdsaSignature {
260    const DEFAULT_VALUE: [u8; 64] = [
261        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,
262        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,
263        0, 0, 0, 0,
264    ];
265    pub const TOTAL_SIZE: usize = 64;
266    pub const ITEM_SIZE: usize = 1;
267    pub const ITEM_COUNT: usize = 64;
268    pub fn nth0(&self) -> Byte {
269        Byte::new_unchecked(self.0.slice(0..1))
270    }
271    pub fn nth1(&self) -> Byte {
272        Byte::new_unchecked(self.0.slice(1..2))
273    }
274    pub fn nth2(&self) -> Byte {
275        Byte::new_unchecked(self.0.slice(2..3))
276    }
277    pub fn nth3(&self) -> Byte {
278        Byte::new_unchecked(self.0.slice(3..4))
279    }
280    pub fn nth4(&self) -> Byte {
281        Byte::new_unchecked(self.0.slice(4..5))
282    }
283    pub fn nth5(&self) -> Byte {
284        Byte::new_unchecked(self.0.slice(5..6))
285    }
286    pub fn nth6(&self) -> Byte {
287        Byte::new_unchecked(self.0.slice(6..7))
288    }
289    pub fn nth7(&self) -> Byte {
290        Byte::new_unchecked(self.0.slice(7..8))
291    }
292    pub fn nth8(&self) -> Byte {
293        Byte::new_unchecked(self.0.slice(8..9))
294    }
295    pub fn nth9(&self) -> Byte {
296        Byte::new_unchecked(self.0.slice(9..10))
297    }
298    pub fn nth10(&self) -> Byte {
299        Byte::new_unchecked(self.0.slice(10..11))
300    }
301    pub fn nth11(&self) -> Byte {
302        Byte::new_unchecked(self.0.slice(11..12))
303    }
304    pub fn nth12(&self) -> Byte {
305        Byte::new_unchecked(self.0.slice(12..13))
306    }
307    pub fn nth13(&self) -> Byte {
308        Byte::new_unchecked(self.0.slice(13..14))
309    }
310    pub fn nth14(&self) -> Byte {
311        Byte::new_unchecked(self.0.slice(14..15))
312    }
313    pub fn nth15(&self) -> Byte {
314        Byte::new_unchecked(self.0.slice(15..16))
315    }
316    pub fn nth16(&self) -> Byte {
317        Byte::new_unchecked(self.0.slice(16..17))
318    }
319    pub fn nth17(&self) -> Byte {
320        Byte::new_unchecked(self.0.slice(17..18))
321    }
322    pub fn nth18(&self) -> Byte {
323        Byte::new_unchecked(self.0.slice(18..19))
324    }
325    pub fn nth19(&self) -> Byte {
326        Byte::new_unchecked(self.0.slice(19..20))
327    }
328    pub fn nth20(&self) -> Byte {
329        Byte::new_unchecked(self.0.slice(20..21))
330    }
331    pub fn nth21(&self) -> Byte {
332        Byte::new_unchecked(self.0.slice(21..22))
333    }
334    pub fn nth22(&self) -> Byte {
335        Byte::new_unchecked(self.0.slice(22..23))
336    }
337    pub fn nth23(&self) -> Byte {
338        Byte::new_unchecked(self.0.slice(23..24))
339    }
340    pub fn nth24(&self) -> Byte {
341        Byte::new_unchecked(self.0.slice(24..25))
342    }
343    pub fn nth25(&self) -> Byte {
344        Byte::new_unchecked(self.0.slice(25..26))
345    }
346    pub fn nth26(&self) -> Byte {
347        Byte::new_unchecked(self.0.slice(26..27))
348    }
349    pub fn nth27(&self) -> Byte {
350        Byte::new_unchecked(self.0.slice(27..28))
351    }
352    pub fn nth28(&self) -> Byte {
353        Byte::new_unchecked(self.0.slice(28..29))
354    }
355    pub fn nth29(&self) -> Byte {
356        Byte::new_unchecked(self.0.slice(29..30))
357    }
358    pub fn nth30(&self) -> Byte {
359        Byte::new_unchecked(self.0.slice(30..31))
360    }
361    pub fn nth31(&self) -> Byte {
362        Byte::new_unchecked(self.0.slice(31..32))
363    }
364    pub fn nth32(&self) -> Byte {
365        Byte::new_unchecked(self.0.slice(32..33))
366    }
367    pub fn nth33(&self) -> Byte {
368        Byte::new_unchecked(self.0.slice(33..34))
369    }
370    pub fn nth34(&self) -> Byte {
371        Byte::new_unchecked(self.0.slice(34..35))
372    }
373    pub fn nth35(&self) -> Byte {
374        Byte::new_unchecked(self.0.slice(35..36))
375    }
376    pub fn nth36(&self) -> Byte {
377        Byte::new_unchecked(self.0.slice(36..37))
378    }
379    pub fn nth37(&self) -> Byte {
380        Byte::new_unchecked(self.0.slice(37..38))
381    }
382    pub fn nth38(&self) -> Byte {
383        Byte::new_unchecked(self.0.slice(38..39))
384    }
385    pub fn nth39(&self) -> Byte {
386        Byte::new_unchecked(self.0.slice(39..40))
387    }
388    pub fn nth40(&self) -> Byte {
389        Byte::new_unchecked(self.0.slice(40..41))
390    }
391    pub fn nth41(&self) -> Byte {
392        Byte::new_unchecked(self.0.slice(41..42))
393    }
394    pub fn nth42(&self) -> Byte {
395        Byte::new_unchecked(self.0.slice(42..43))
396    }
397    pub fn nth43(&self) -> Byte {
398        Byte::new_unchecked(self.0.slice(43..44))
399    }
400    pub fn nth44(&self) -> Byte {
401        Byte::new_unchecked(self.0.slice(44..45))
402    }
403    pub fn nth45(&self) -> Byte {
404        Byte::new_unchecked(self.0.slice(45..46))
405    }
406    pub fn nth46(&self) -> Byte {
407        Byte::new_unchecked(self.0.slice(46..47))
408    }
409    pub fn nth47(&self) -> Byte {
410        Byte::new_unchecked(self.0.slice(47..48))
411    }
412    pub fn nth48(&self) -> Byte {
413        Byte::new_unchecked(self.0.slice(48..49))
414    }
415    pub fn nth49(&self) -> Byte {
416        Byte::new_unchecked(self.0.slice(49..50))
417    }
418    pub fn nth50(&self) -> Byte {
419        Byte::new_unchecked(self.0.slice(50..51))
420    }
421    pub fn nth51(&self) -> Byte {
422        Byte::new_unchecked(self.0.slice(51..52))
423    }
424    pub fn nth52(&self) -> Byte {
425        Byte::new_unchecked(self.0.slice(52..53))
426    }
427    pub fn nth53(&self) -> Byte {
428        Byte::new_unchecked(self.0.slice(53..54))
429    }
430    pub fn nth54(&self) -> Byte {
431        Byte::new_unchecked(self.0.slice(54..55))
432    }
433    pub fn nth55(&self) -> Byte {
434        Byte::new_unchecked(self.0.slice(55..56))
435    }
436    pub fn nth56(&self) -> Byte {
437        Byte::new_unchecked(self.0.slice(56..57))
438    }
439    pub fn nth57(&self) -> Byte {
440        Byte::new_unchecked(self.0.slice(57..58))
441    }
442    pub fn nth58(&self) -> Byte {
443        Byte::new_unchecked(self.0.slice(58..59))
444    }
445    pub fn nth59(&self) -> Byte {
446        Byte::new_unchecked(self.0.slice(59..60))
447    }
448    pub fn nth60(&self) -> Byte {
449        Byte::new_unchecked(self.0.slice(60..61))
450    }
451    pub fn nth61(&self) -> Byte {
452        Byte::new_unchecked(self.0.slice(61..62))
453    }
454    pub fn nth62(&self) -> Byte {
455        Byte::new_unchecked(self.0.slice(62..63))
456    }
457    pub fn nth63(&self) -> Byte {
458        Byte::new_unchecked(self.0.slice(63..64))
459    }
460    pub fn raw_data(&self) -> molecule::bytes::Bytes {
461        self.as_bytes()
462    }
463    pub fn as_reader<'r>(&'r self) -> EcdsaSignatureReader<'r> {
464        EcdsaSignatureReader::new_unchecked(self.as_slice())
465    }
466}
467impl molecule::prelude::Entity for EcdsaSignature {
468    type Builder = EcdsaSignatureBuilder;
469    const NAME: &'static str = "EcdsaSignature";
470    fn new_unchecked(data: molecule::bytes::Bytes) -> Self {
471        EcdsaSignature(data)
472    }
473    fn as_bytes(&self) -> molecule::bytes::Bytes {
474        self.0.clone()
475    }
476    fn as_slice(&self) -> &[u8] {
477        &self.0[..]
478    }
479    fn from_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
480        EcdsaSignatureReader::from_slice(slice).map(|reader| reader.to_entity())
481    }
482    fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
483        EcdsaSignatureReader::from_compatible_slice(slice).map(|reader| reader.to_entity())
484    }
485    fn new_builder() -> Self::Builder {
486        ::core::default::Default::default()
487    }
488    fn as_builder(self) -> Self::Builder {
489        Self::new_builder().set([
490            self.nth0(),
491            self.nth1(),
492            self.nth2(),
493            self.nth3(),
494            self.nth4(),
495            self.nth5(),
496            self.nth6(),
497            self.nth7(),
498            self.nth8(),
499            self.nth9(),
500            self.nth10(),
501            self.nth11(),
502            self.nth12(),
503            self.nth13(),
504            self.nth14(),
505            self.nth15(),
506            self.nth16(),
507            self.nth17(),
508            self.nth18(),
509            self.nth19(),
510            self.nth20(),
511            self.nth21(),
512            self.nth22(),
513            self.nth23(),
514            self.nth24(),
515            self.nth25(),
516            self.nth26(),
517            self.nth27(),
518            self.nth28(),
519            self.nth29(),
520            self.nth30(),
521            self.nth31(),
522            self.nth32(),
523            self.nth33(),
524            self.nth34(),
525            self.nth35(),
526            self.nth36(),
527            self.nth37(),
528            self.nth38(),
529            self.nth39(),
530            self.nth40(),
531            self.nth41(),
532            self.nth42(),
533            self.nth43(),
534            self.nth44(),
535            self.nth45(),
536            self.nth46(),
537            self.nth47(),
538            self.nth48(),
539            self.nth49(),
540            self.nth50(),
541            self.nth51(),
542            self.nth52(),
543            self.nth53(),
544            self.nth54(),
545            self.nth55(),
546            self.nth56(),
547            self.nth57(),
548            self.nth58(),
549            self.nth59(),
550            self.nth60(),
551            self.nth61(),
552            self.nth62(),
553            self.nth63(),
554        ])
555    }
556}
557#[derive(Clone, Copy)]
558pub struct EcdsaSignatureReader<'r>(&'r [u8]);
559impl<'r> ::core::fmt::LowerHex for EcdsaSignatureReader<'r> {
560    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
561        use molecule::hex_string;
562        if f.alternate() {
563            write!(f, "0x")?;
564        }
565        write!(f, "{}", hex_string(self.as_slice()))
566    }
567}
568impl<'r> ::core::fmt::Debug for EcdsaSignatureReader<'r> {
569    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
570        write!(f, "{}({:#x})", Self::NAME, self)
571    }
572}
573impl<'r> ::core::fmt::Display for EcdsaSignatureReader<'r> {
574    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
575        use molecule::hex_string;
576        let raw_data = hex_string(&self.raw_data());
577        write!(f, "{}(0x{})", Self::NAME, raw_data)
578    }
579}
580impl<'r> EcdsaSignatureReader<'r> {
581    pub const TOTAL_SIZE: usize = 64;
582    pub const ITEM_SIZE: usize = 1;
583    pub const ITEM_COUNT: usize = 64;
584    pub fn nth0(&self) -> ByteReader<'r> {
585        ByteReader::new_unchecked(&self.as_slice()[0..1])
586    }
587    pub fn nth1(&self) -> ByteReader<'r> {
588        ByteReader::new_unchecked(&self.as_slice()[1..2])
589    }
590    pub fn nth2(&self) -> ByteReader<'r> {
591        ByteReader::new_unchecked(&self.as_slice()[2..3])
592    }
593    pub fn nth3(&self) -> ByteReader<'r> {
594        ByteReader::new_unchecked(&self.as_slice()[3..4])
595    }
596    pub fn nth4(&self) -> ByteReader<'r> {
597        ByteReader::new_unchecked(&self.as_slice()[4..5])
598    }
599    pub fn nth5(&self) -> ByteReader<'r> {
600        ByteReader::new_unchecked(&self.as_slice()[5..6])
601    }
602    pub fn nth6(&self) -> ByteReader<'r> {
603        ByteReader::new_unchecked(&self.as_slice()[6..7])
604    }
605    pub fn nth7(&self) -> ByteReader<'r> {
606        ByteReader::new_unchecked(&self.as_slice()[7..8])
607    }
608    pub fn nth8(&self) -> ByteReader<'r> {
609        ByteReader::new_unchecked(&self.as_slice()[8..9])
610    }
611    pub fn nth9(&self) -> ByteReader<'r> {
612        ByteReader::new_unchecked(&self.as_slice()[9..10])
613    }
614    pub fn nth10(&self) -> ByteReader<'r> {
615        ByteReader::new_unchecked(&self.as_slice()[10..11])
616    }
617    pub fn nth11(&self) -> ByteReader<'r> {
618        ByteReader::new_unchecked(&self.as_slice()[11..12])
619    }
620    pub fn nth12(&self) -> ByteReader<'r> {
621        ByteReader::new_unchecked(&self.as_slice()[12..13])
622    }
623    pub fn nth13(&self) -> ByteReader<'r> {
624        ByteReader::new_unchecked(&self.as_slice()[13..14])
625    }
626    pub fn nth14(&self) -> ByteReader<'r> {
627        ByteReader::new_unchecked(&self.as_slice()[14..15])
628    }
629    pub fn nth15(&self) -> ByteReader<'r> {
630        ByteReader::new_unchecked(&self.as_slice()[15..16])
631    }
632    pub fn nth16(&self) -> ByteReader<'r> {
633        ByteReader::new_unchecked(&self.as_slice()[16..17])
634    }
635    pub fn nth17(&self) -> ByteReader<'r> {
636        ByteReader::new_unchecked(&self.as_slice()[17..18])
637    }
638    pub fn nth18(&self) -> ByteReader<'r> {
639        ByteReader::new_unchecked(&self.as_slice()[18..19])
640    }
641    pub fn nth19(&self) -> ByteReader<'r> {
642        ByteReader::new_unchecked(&self.as_slice()[19..20])
643    }
644    pub fn nth20(&self) -> ByteReader<'r> {
645        ByteReader::new_unchecked(&self.as_slice()[20..21])
646    }
647    pub fn nth21(&self) -> ByteReader<'r> {
648        ByteReader::new_unchecked(&self.as_slice()[21..22])
649    }
650    pub fn nth22(&self) -> ByteReader<'r> {
651        ByteReader::new_unchecked(&self.as_slice()[22..23])
652    }
653    pub fn nth23(&self) -> ByteReader<'r> {
654        ByteReader::new_unchecked(&self.as_slice()[23..24])
655    }
656    pub fn nth24(&self) -> ByteReader<'r> {
657        ByteReader::new_unchecked(&self.as_slice()[24..25])
658    }
659    pub fn nth25(&self) -> ByteReader<'r> {
660        ByteReader::new_unchecked(&self.as_slice()[25..26])
661    }
662    pub fn nth26(&self) -> ByteReader<'r> {
663        ByteReader::new_unchecked(&self.as_slice()[26..27])
664    }
665    pub fn nth27(&self) -> ByteReader<'r> {
666        ByteReader::new_unchecked(&self.as_slice()[27..28])
667    }
668    pub fn nth28(&self) -> ByteReader<'r> {
669        ByteReader::new_unchecked(&self.as_slice()[28..29])
670    }
671    pub fn nth29(&self) -> ByteReader<'r> {
672        ByteReader::new_unchecked(&self.as_slice()[29..30])
673    }
674    pub fn nth30(&self) -> ByteReader<'r> {
675        ByteReader::new_unchecked(&self.as_slice()[30..31])
676    }
677    pub fn nth31(&self) -> ByteReader<'r> {
678        ByteReader::new_unchecked(&self.as_slice()[31..32])
679    }
680    pub fn nth32(&self) -> ByteReader<'r> {
681        ByteReader::new_unchecked(&self.as_slice()[32..33])
682    }
683    pub fn nth33(&self) -> ByteReader<'r> {
684        ByteReader::new_unchecked(&self.as_slice()[33..34])
685    }
686    pub fn nth34(&self) -> ByteReader<'r> {
687        ByteReader::new_unchecked(&self.as_slice()[34..35])
688    }
689    pub fn nth35(&self) -> ByteReader<'r> {
690        ByteReader::new_unchecked(&self.as_slice()[35..36])
691    }
692    pub fn nth36(&self) -> ByteReader<'r> {
693        ByteReader::new_unchecked(&self.as_slice()[36..37])
694    }
695    pub fn nth37(&self) -> ByteReader<'r> {
696        ByteReader::new_unchecked(&self.as_slice()[37..38])
697    }
698    pub fn nth38(&self) -> ByteReader<'r> {
699        ByteReader::new_unchecked(&self.as_slice()[38..39])
700    }
701    pub fn nth39(&self) -> ByteReader<'r> {
702        ByteReader::new_unchecked(&self.as_slice()[39..40])
703    }
704    pub fn nth40(&self) -> ByteReader<'r> {
705        ByteReader::new_unchecked(&self.as_slice()[40..41])
706    }
707    pub fn nth41(&self) -> ByteReader<'r> {
708        ByteReader::new_unchecked(&self.as_slice()[41..42])
709    }
710    pub fn nth42(&self) -> ByteReader<'r> {
711        ByteReader::new_unchecked(&self.as_slice()[42..43])
712    }
713    pub fn nth43(&self) -> ByteReader<'r> {
714        ByteReader::new_unchecked(&self.as_slice()[43..44])
715    }
716    pub fn nth44(&self) -> ByteReader<'r> {
717        ByteReader::new_unchecked(&self.as_slice()[44..45])
718    }
719    pub fn nth45(&self) -> ByteReader<'r> {
720        ByteReader::new_unchecked(&self.as_slice()[45..46])
721    }
722    pub fn nth46(&self) -> ByteReader<'r> {
723        ByteReader::new_unchecked(&self.as_slice()[46..47])
724    }
725    pub fn nth47(&self) -> ByteReader<'r> {
726        ByteReader::new_unchecked(&self.as_slice()[47..48])
727    }
728    pub fn nth48(&self) -> ByteReader<'r> {
729        ByteReader::new_unchecked(&self.as_slice()[48..49])
730    }
731    pub fn nth49(&self) -> ByteReader<'r> {
732        ByteReader::new_unchecked(&self.as_slice()[49..50])
733    }
734    pub fn nth50(&self) -> ByteReader<'r> {
735        ByteReader::new_unchecked(&self.as_slice()[50..51])
736    }
737    pub fn nth51(&self) -> ByteReader<'r> {
738        ByteReader::new_unchecked(&self.as_slice()[51..52])
739    }
740    pub fn nth52(&self) -> ByteReader<'r> {
741        ByteReader::new_unchecked(&self.as_slice()[52..53])
742    }
743    pub fn nth53(&self) -> ByteReader<'r> {
744        ByteReader::new_unchecked(&self.as_slice()[53..54])
745    }
746    pub fn nth54(&self) -> ByteReader<'r> {
747        ByteReader::new_unchecked(&self.as_slice()[54..55])
748    }
749    pub fn nth55(&self) -> ByteReader<'r> {
750        ByteReader::new_unchecked(&self.as_slice()[55..56])
751    }
752    pub fn nth56(&self) -> ByteReader<'r> {
753        ByteReader::new_unchecked(&self.as_slice()[56..57])
754    }
755    pub fn nth57(&self) -> ByteReader<'r> {
756        ByteReader::new_unchecked(&self.as_slice()[57..58])
757    }
758    pub fn nth58(&self) -> ByteReader<'r> {
759        ByteReader::new_unchecked(&self.as_slice()[58..59])
760    }
761    pub fn nth59(&self) -> ByteReader<'r> {
762        ByteReader::new_unchecked(&self.as_slice()[59..60])
763    }
764    pub fn nth60(&self) -> ByteReader<'r> {
765        ByteReader::new_unchecked(&self.as_slice()[60..61])
766    }
767    pub fn nth61(&self) -> ByteReader<'r> {
768        ByteReader::new_unchecked(&self.as_slice()[61..62])
769    }
770    pub fn nth62(&self) -> ByteReader<'r> {
771        ByteReader::new_unchecked(&self.as_slice()[62..63])
772    }
773    pub fn nth63(&self) -> ByteReader<'r> {
774        ByteReader::new_unchecked(&self.as_slice()[63..64])
775    }
776    pub fn raw_data(&self) -> &'r [u8] {
777        self.as_slice()
778    }
779}
780impl<'r> molecule::prelude::Reader<'r> for EcdsaSignatureReader<'r> {
781    type Entity = EcdsaSignature;
782    const NAME: &'static str = "EcdsaSignatureReader";
783    fn to_entity(&self) -> Self::Entity {
784        Self::Entity::new_unchecked(self.as_slice().to_owned().into())
785    }
786    fn new_unchecked(slice: &'r [u8]) -> Self {
787        EcdsaSignatureReader(slice)
788    }
789    fn as_slice(&self) -> &'r [u8] {
790        self.0
791    }
792    fn verify(slice: &[u8], _compatible: bool) -> molecule::error::VerificationResult<()> {
793        use molecule::verification_error as ve;
794        let slice_len = slice.len();
795        if slice_len != Self::TOTAL_SIZE {
796            return ve!(Self, TotalSizeNotMatch, Self::TOTAL_SIZE, slice_len);
797        }
798        Ok(())
799    }
800}
801#[derive(Clone)]
802pub struct EcdsaSignatureBuilder(pub(crate) [Byte; 64]);
803impl ::core::fmt::Debug for EcdsaSignatureBuilder {
804    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
805        write!(f, "{}({:?})", Self::NAME, &self.0[..])
806    }
807}
808impl ::core::default::Default for EcdsaSignatureBuilder {
809    fn default() -> Self {
810        EcdsaSignatureBuilder([
811            Byte::default(),
812            Byte::default(),
813            Byte::default(),
814            Byte::default(),
815            Byte::default(),
816            Byte::default(),
817            Byte::default(),
818            Byte::default(),
819            Byte::default(),
820            Byte::default(),
821            Byte::default(),
822            Byte::default(),
823            Byte::default(),
824            Byte::default(),
825            Byte::default(),
826            Byte::default(),
827            Byte::default(),
828            Byte::default(),
829            Byte::default(),
830            Byte::default(),
831            Byte::default(),
832            Byte::default(),
833            Byte::default(),
834            Byte::default(),
835            Byte::default(),
836            Byte::default(),
837            Byte::default(),
838            Byte::default(),
839            Byte::default(),
840            Byte::default(),
841            Byte::default(),
842            Byte::default(),
843            Byte::default(),
844            Byte::default(),
845            Byte::default(),
846            Byte::default(),
847            Byte::default(),
848            Byte::default(),
849            Byte::default(),
850            Byte::default(),
851            Byte::default(),
852            Byte::default(),
853            Byte::default(),
854            Byte::default(),
855            Byte::default(),
856            Byte::default(),
857            Byte::default(),
858            Byte::default(),
859            Byte::default(),
860            Byte::default(),
861            Byte::default(),
862            Byte::default(),
863            Byte::default(),
864            Byte::default(),
865            Byte::default(),
866            Byte::default(),
867            Byte::default(),
868            Byte::default(),
869            Byte::default(),
870            Byte::default(),
871            Byte::default(),
872            Byte::default(),
873            Byte::default(),
874            Byte::default(),
875        ])
876    }
877}
878impl EcdsaSignatureBuilder {
879    pub const TOTAL_SIZE: usize = 64;
880    pub const ITEM_SIZE: usize = 1;
881    pub const ITEM_COUNT: usize = 64;
882    pub fn set(mut self, v: [Byte; 64]) -> Self {
883        self.0 = v;
884        self
885    }
886    pub fn nth0(mut self, v: Byte) -> Self {
887        self.0[0] = v;
888        self
889    }
890    pub fn nth1(mut self, v: Byte) -> Self {
891        self.0[1] = v;
892        self
893    }
894    pub fn nth2(mut self, v: Byte) -> Self {
895        self.0[2] = v;
896        self
897    }
898    pub fn nth3(mut self, v: Byte) -> Self {
899        self.0[3] = v;
900        self
901    }
902    pub fn nth4(mut self, v: Byte) -> Self {
903        self.0[4] = v;
904        self
905    }
906    pub fn nth5(mut self, v: Byte) -> Self {
907        self.0[5] = v;
908        self
909    }
910    pub fn nth6(mut self, v: Byte) -> Self {
911        self.0[6] = v;
912        self
913    }
914    pub fn nth7(mut self, v: Byte) -> Self {
915        self.0[7] = v;
916        self
917    }
918    pub fn nth8(mut self, v: Byte) -> Self {
919        self.0[8] = v;
920        self
921    }
922    pub fn nth9(mut self, v: Byte) -> Self {
923        self.0[9] = v;
924        self
925    }
926    pub fn nth10(mut self, v: Byte) -> Self {
927        self.0[10] = v;
928        self
929    }
930    pub fn nth11(mut self, v: Byte) -> Self {
931        self.0[11] = v;
932        self
933    }
934    pub fn nth12(mut self, v: Byte) -> Self {
935        self.0[12] = v;
936        self
937    }
938    pub fn nth13(mut self, v: Byte) -> Self {
939        self.0[13] = v;
940        self
941    }
942    pub fn nth14(mut self, v: Byte) -> Self {
943        self.0[14] = v;
944        self
945    }
946    pub fn nth15(mut self, v: Byte) -> Self {
947        self.0[15] = v;
948        self
949    }
950    pub fn nth16(mut self, v: Byte) -> Self {
951        self.0[16] = v;
952        self
953    }
954    pub fn nth17(mut self, v: Byte) -> Self {
955        self.0[17] = v;
956        self
957    }
958    pub fn nth18(mut self, v: Byte) -> Self {
959        self.0[18] = v;
960        self
961    }
962    pub fn nth19(mut self, v: Byte) -> Self {
963        self.0[19] = v;
964        self
965    }
966    pub fn nth20(mut self, v: Byte) -> Self {
967        self.0[20] = v;
968        self
969    }
970    pub fn nth21(mut self, v: Byte) -> Self {
971        self.0[21] = v;
972        self
973    }
974    pub fn nth22(mut self, v: Byte) -> Self {
975        self.0[22] = v;
976        self
977    }
978    pub fn nth23(mut self, v: Byte) -> Self {
979        self.0[23] = v;
980        self
981    }
982    pub fn nth24(mut self, v: Byte) -> Self {
983        self.0[24] = v;
984        self
985    }
986    pub fn nth25(mut self, v: Byte) -> Self {
987        self.0[25] = v;
988        self
989    }
990    pub fn nth26(mut self, v: Byte) -> Self {
991        self.0[26] = v;
992        self
993    }
994    pub fn nth27(mut self, v: Byte) -> Self {
995        self.0[27] = v;
996        self
997    }
998    pub fn nth28(mut self, v: Byte) -> Self {
999        self.0[28] = v;
1000        self
1001    }
1002    pub fn nth29(mut self, v: Byte) -> Self {
1003        self.0[29] = v;
1004        self
1005    }
1006    pub fn nth30(mut self, v: Byte) -> Self {
1007        self.0[30] = v;
1008        self
1009    }
1010    pub fn nth31(mut self, v: Byte) -> Self {
1011        self.0[31] = v;
1012        self
1013    }
1014    pub fn nth32(mut self, v: Byte) -> Self {
1015        self.0[32] = v;
1016        self
1017    }
1018    pub fn nth33(mut self, v: Byte) -> Self {
1019        self.0[33] = v;
1020        self
1021    }
1022    pub fn nth34(mut self, v: Byte) -> Self {
1023        self.0[34] = v;
1024        self
1025    }
1026    pub fn nth35(mut self, v: Byte) -> Self {
1027        self.0[35] = v;
1028        self
1029    }
1030    pub fn nth36(mut self, v: Byte) -> Self {
1031        self.0[36] = v;
1032        self
1033    }
1034    pub fn nth37(mut self, v: Byte) -> Self {
1035        self.0[37] = v;
1036        self
1037    }
1038    pub fn nth38(mut self, v: Byte) -> Self {
1039        self.0[38] = v;
1040        self
1041    }
1042    pub fn nth39(mut self, v: Byte) -> Self {
1043        self.0[39] = v;
1044        self
1045    }
1046    pub fn nth40(mut self, v: Byte) -> Self {
1047        self.0[40] = v;
1048        self
1049    }
1050    pub fn nth41(mut self, v: Byte) -> Self {
1051        self.0[41] = v;
1052        self
1053    }
1054    pub fn nth42(mut self, v: Byte) -> Self {
1055        self.0[42] = v;
1056        self
1057    }
1058    pub fn nth43(mut self, v: Byte) -> Self {
1059        self.0[43] = v;
1060        self
1061    }
1062    pub fn nth44(mut self, v: Byte) -> Self {
1063        self.0[44] = v;
1064        self
1065    }
1066    pub fn nth45(mut self, v: Byte) -> Self {
1067        self.0[45] = v;
1068        self
1069    }
1070    pub fn nth46(mut self, v: Byte) -> Self {
1071        self.0[46] = v;
1072        self
1073    }
1074    pub fn nth47(mut self, v: Byte) -> Self {
1075        self.0[47] = v;
1076        self
1077    }
1078    pub fn nth48(mut self, v: Byte) -> Self {
1079        self.0[48] = v;
1080        self
1081    }
1082    pub fn nth49(mut self, v: Byte) -> Self {
1083        self.0[49] = v;
1084        self
1085    }
1086    pub fn nth50(mut self, v: Byte) -> Self {
1087        self.0[50] = v;
1088        self
1089    }
1090    pub fn nth51(mut self, v: Byte) -> Self {
1091        self.0[51] = v;
1092        self
1093    }
1094    pub fn nth52(mut self, v: Byte) -> Self {
1095        self.0[52] = v;
1096        self
1097    }
1098    pub fn nth53(mut self, v: Byte) -> Self {
1099        self.0[53] = v;
1100        self
1101    }
1102    pub fn nth54(mut self, v: Byte) -> Self {
1103        self.0[54] = v;
1104        self
1105    }
1106    pub fn nth55(mut self, v: Byte) -> Self {
1107        self.0[55] = v;
1108        self
1109    }
1110    pub fn nth56(mut self, v: Byte) -> Self {
1111        self.0[56] = v;
1112        self
1113    }
1114    pub fn nth57(mut self, v: Byte) -> Self {
1115        self.0[57] = v;
1116        self
1117    }
1118    pub fn nth58(mut self, v: Byte) -> Self {
1119        self.0[58] = v;
1120        self
1121    }
1122    pub fn nth59(mut self, v: Byte) -> Self {
1123        self.0[59] = v;
1124        self
1125    }
1126    pub fn nth60(mut self, v: Byte) -> Self {
1127        self.0[60] = v;
1128        self
1129    }
1130    pub fn nth61(mut self, v: Byte) -> Self {
1131        self.0[61] = v;
1132        self
1133    }
1134    pub fn nth62(mut self, v: Byte) -> Self {
1135        self.0[62] = v;
1136        self
1137    }
1138    pub fn nth63(mut self, v: Byte) -> Self {
1139        self.0[63] = v;
1140        self
1141    }
1142}
1143impl molecule::prelude::Builder for EcdsaSignatureBuilder {
1144    type Entity = EcdsaSignature;
1145    const NAME: &'static str = "EcdsaSignatureBuilder";
1146    fn expected_length(&self) -> usize {
1147        Self::TOTAL_SIZE
1148    }
1149    fn write<W: molecule::io::Write>(&self, writer: &mut W) -> molecule::io::Result<()> {
1150        writer.write_all(self.0[0].as_slice())?;
1151        writer.write_all(self.0[1].as_slice())?;
1152        writer.write_all(self.0[2].as_slice())?;
1153        writer.write_all(self.0[3].as_slice())?;
1154        writer.write_all(self.0[4].as_slice())?;
1155        writer.write_all(self.0[5].as_slice())?;
1156        writer.write_all(self.0[6].as_slice())?;
1157        writer.write_all(self.0[7].as_slice())?;
1158        writer.write_all(self.0[8].as_slice())?;
1159        writer.write_all(self.0[9].as_slice())?;
1160        writer.write_all(self.0[10].as_slice())?;
1161        writer.write_all(self.0[11].as_slice())?;
1162        writer.write_all(self.0[12].as_slice())?;
1163        writer.write_all(self.0[13].as_slice())?;
1164        writer.write_all(self.0[14].as_slice())?;
1165        writer.write_all(self.0[15].as_slice())?;
1166        writer.write_all(self.0[16].as_slice())?;
1167        writer.write_all(self.0[17].as_slice())?;
1168        writer.write_all(self.0[18].as_slice())?;
1169        writer.write_all(self.0[19].as_slice())?;
1170        writer.write_all(self.0[20].as_slice())?;
1171        writer.write_all(self.0[21].as_slice())?;
1172        writer.write_all(self.0[22].as_slice())?;
1173        writer.write_all(self.0[23].as_slice())?;
1174        writer.write_all(self.0[24].as_slice())?;
1175        writer.write_all(self.0[25].as_slice())?;
1176        writer.write_all(self.0[26].as_slice())?;
1177        writer.write_all(self.0[27].as_slice())?;
1178        writer.write_all(self.0[28].as_slice())?;
1179        writer.write_all(self.0[29].as_slice())?;
1180        writer.write_all(self.0[30].as_slice())?;
1181        writer.write_all(self.0[31].as_slice())?;
1182        writer.write_all(self.0[32].as_slice())?;
1183        writer.write_all(self.0[33].as_slice())?;
1184        writer.write_all(self.0[34].as_slice())?;
1185        writer.write_all(self.0[35].as_slice())?;
1186        writer.write_all(self.0[36].as_slice())?;
1187        writer.write_all(self.0[37].as_slice())?;
1188        writer.write_all(self.0[38].as_slice())?;
1189        writer.write_all(self.0[39].as_slice())?;
1190        writer.write_all(self.0[40].as_slice())?;
1191        writer.write_all(self.0[41].as_slice())?;
1192        writer.write_all(self.0[42].as_slice())?;
1193        writer.write_all(self.0[43].as_slice())?;
1194        writer.write_all(self.0[44].as_slice())?;
1195        writer.write_all(self.0[45].as_slice())?;
1196        writer.write_all(self.0[46].as_slice())?;
1197        writer.write_all(self.0[47].as_slice())?;
1198        writer.write_all(self.0[48].as_slice())?;
1199        writer.write_all(self.0[49].as_slice())?;
1200        writer.write_all(self.0[50].as_slice())?;
1201        writer.write_all(self.0[51].as_slice())?;
1202        writer.write_all(self.0[52].as_slice())?;
1203        writer.write_all(self.0[53].as_slice())?;
1204        writer.write_all(self.0[54].as_slice())?;
1205        writer.write_all(self.0[55].as_slice())?;
1206        writer.write_all(self.0[56].as_slice())?;
1207        writer.write_all(self.0[57].as_slice())?;
1208        writer.write_all(self.0[58].as_slice())?;
1209        writer.write_all(self.0[59].as_slice())?;
1210        writer.write_all(self.0[60].as_slice())?;
1211        writer.write_all(self.0[61].as_slice())?;
1212        writer.write_all(self.0[62].as_slice())?;
1213        writer.write_all(self.0[63].as_slice())?;
1214        Ok(())
1215    }
1216    fn build(&self) -> Self::Entity {
1217        let mut inner = Vec::with_capacity(self.expected_length());
1218        self.write(&mut inner)
1219            .unwrap_or_else(|_| panic!("{} build should be ok", Self::NAME));
1220        EcdsaSignature::new_unchecked(inner.into())
1221    }
1222}
1223impl From<[Byte; 64usize]> for EcdsaSignature {
1224    fn from(value: [Byte; 64usize]) -> Self {
1225        Self::new_builder().set(value).build()
1226    }
1227}
1228impl ::core::convert::TryFrom<&[Byte]> for EcdsaSignature {
1229    type Error = ::core::array::TryFromSliceError;
1230    fn try_from(value: &[Byte]) -> Result<Self, ::core::array::TryFromSliceError> {
1231        Ok(Self::new_builder()
1232            .set(<&[Byte; 64usize]>::try_from(value)?.clone())
1233            .build())
1234    }
1235}
1236impl From<EcdsaSignature> for [Byte; 64usize] {
1237    #[track_caller]
1238    fn from(value: EcdsaSignature) -> Self {
1239        [
1240            value.nth0(),
1241            value.nth1(),
1242            value.nth2(),
1243            value.nth3(),
1244            value.nth4(),
1245            value.nth5(),
1246            value.nth6(),
1247            value.nth7(),
1248            value.nth8(),
1249            value.nth9(),
1250            value.nth10(),
1251            value.nth11(),
1252            value.nth12(),
1253            value.nth13(),
1254            value.nth14(),
1255            value.nth15(),
1256            value.nth16(),
1257            value.nth17(),
1258            value.nth18(),
1259            value.nth19(),
1260            value.nth20(),
1261            value.nth21(),
1262            value.nth22(),
1263            value.nth23(),
1264            value.nth24(),
1265            value.nth25(),
1266            value.nth26(),
1267            value.nth27(),
1268            value.nth28(),
1269            value.nth29(),
1270            value.nth30(),
1271            value.nth31(),
1272            value.nth32(),
1273            value.nth33(),
1274            value.nth34(),
1275            value.nth35(),
1276            value.nth36(),
1277            value.nth37(),
1278            value.nth38(),
1279            value.nth39(),
1280            value.nth40(),
1281            value.nth41(),
1282            value.nth42(),
1283            value.nth43(),
1284            value.nth44(),
1285            value.nth45(),
1286            value.nth46(),
1287            value.nth47(),
1288            value.nth48(),
1289            value.nth49(),
1290            value.nth50(),
1291            value.nth51(),
1292            value.nth52(),
1293            value.nth53(),
1294            value.nth54(),
1295            value.nth55(),
1296            value.nth56(),
1297            value.nth57(),
1298            value.nth58(),
1299            value.nth59(),
1300            value.nth60(),
1301            value.nth61(),
1302            value.nth62(),
1303            value.nth63(),
1304        ]
1305    }
1306}
1307impl From<[u8; 64usize]> for EcdsaSignature {
1308    fn from(value: [u8; 64usize]) -> Self {
1309        EcdsaSignatureReader::new_unchecked(&value).to_entity()
1310    }
1311}
1312impl ::core::convert::TryFrom<&[u8]> for EcdsaSignature {
1313    type Error = ::core::array::TryFromSliceError;
1314    fn try_from(value: &[u8]) -> Result<Self, ::core::array::TryFromSliceError> {
1315        Ok(<[u8; 64usize]>::try_from(value)?.into())
1316    }
1317}
1318impl From<EcdsaSignature> for [u8; 64usize] {
1319    #[track_caller]
1320    fn from(value: EcdsaSignature) -> Self {
1321        ::core::convert::TryFrom::try_from(value.as_slice()).unwrap()
1322    }
1323}
1324impl<'a> From<EcdsaSignatureReader<'a>> for &'a [u8; 64usize] {
1325    #[track_caller]
1326    fn from(value: EcdsaSignatureReader<'a>) -> Self {
1327        ::core::convert::TryFrom::try_from(value.as_slice()).unwrap()
1328    }
1329}
1330impl<'a> From<&'a EcdsaSignatureReader<'a>> for &'a [u8; 64usize] {
1331    #[track_caller]
1332    fn from(value: &'a EcdsaSignatureReader<'a>) -> Self {
1333        ::core::convert::TryFrom::try_from(value.as_slice()).unwrap()
1334    }
1335}
1336#[derive(Clone)]
1337pub struct PubNonce(molecule::bytes::Bytes);
1338impl ::core::fmt::LowerHex for PubNonce {
1339    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
1340        use molecule::hex_string;
1341        if f.alternate() {
1342            write!(f, "0x")?;
1343        }
1344        write!(f, "{}", hex_string(self.as_slice()))
1345    }
1346}
1347impl ::core::fmt::Debug for PubNonce {
1348    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
1349        write!(f, "{}({:#x})", Self::NAME, self)
1350    }
1351}
1352impl ::core::fmt::Display for PubNonce {
1353    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
1354        use molecule::hex_string;
1355        let raw_data = hex_string(&self.raw_data());
1356        write!(f, "{}(0x{})", Self::NAME, raw_data)
1357    }
1358}
1359impl ::core::default::Default for PubNonce {
1360    fn default() -> Self {
1361        let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE);
1362        PubNonce::new_unchecked(v)
1363    }
1364}
1365impl PubNonce {
1366    const DEFAULT_VALUE: [u8; 66] = [
1367        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,
1368        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,
1369        0, 0, 0, 0, 0, 0,
1370    ];
1371    pub const TOTAL_SIZE: usize = 66;
1372    pub const ITEM_SIZE: usize = 1;
1373    pub const ITEM_COUNT: usize = 66;
1374    pub fn nth0(&self) -> Byte {
1375        Byte::new_unchecked(self.0.slice(0..1))
1376    }
1377    pub fn nth1(&self) -> Byte {
1378        Byte::new_unchecked(self.0.slice(1..2))
1379    }
1380    pub fn nth2(&self) -> Byte {
1381        Byte::new_unchecked(self.0.slice(2..3))
1382    }
1383    pub fn nth3(&self) -> Byte {
1384        Byte::new_unchecked(self.0.slice(3..4))
1385    }
1386    pub fn nth4(&self) -> Byte {
1387        Byte::new_unchecked(self.0.slice(4..5))
1388    }
1389    pub fn nth5(&self) -> Byte {
1390        Byte::new_unchecked(self.0.slice(5..6))
1391    }
1392    pub fn nth6(&self) -> Byte {
1393        Byte::new_unchecked(self.0.slice(6..7))
1394    }
1395    pub fn nth7(&self) -> Byte {
1396        Byte::new_unchecked(self.0.slice(7..8))
1397    }
1398    pub fn nth8(&self) -> Byte {
1399        Byte::new_unchecked(self.0.slice(8..9))
1400    }
1401    pub fn nth9(&self) -> Byte {
1402        Byte::new_unchecked(self.0.slice(9..10))
1403    }
1404    pub fn nth10(&self) -> Byte {
1405        Byte::new_unchecked(self.0.slice(10..11))
1406    }
1407    pub fn nth11(&self) -> Byte {
1408        Byte::new_unchecked(self.0.slice(11..12))
1409    }
1410    pub fn nth12(&self) -> Byte {
1411        Byte::new_unchecked(self.0.slice(12..13))
1412    }
1413    pub fn nth13(&self) -> Byte {
1414        Byte::new_unchecked(self.0.slice(13..14))
1415    }
1416    pub fn nth14(&self) -> Byte {
1417        Byte::new_unchecked(self.0.slice(14..15))
1418    }
1419    pub fn nth15(&self) -> Byte {
1420        Byte::new_unchecked(self.0.slice(15..16))
1421    }
1422    pub fn nth16(&self) -> Byte {
1423        Byte::new_unchecked(self.0.slice(16..17))
1424    }
1425    pub fn nth17(&self) -> Byte {
1426        Byte::new_unchecked(self.0.slice(17..18))
1427    }
1428    pub fn nth18(&self) -> Byte {
1429        Byte::new_unchecked(self.0.slice(18..19))
1430    }
1431    pub fn nth19(&self) -> Byte {
1432        Byte::new_unchecked(self.0.slice(19..20))
1433    }
1434    pub fn nth20(&self) -> Byte {
1435        Byte::new_unchecked(self.0.slice(20..21))
1436    }
1437    pub fn nth21(&self) -> Byte {
1438        Byte::new_unchecked(self.0.slice(21..22))
1439    }
1440    pub fn nth22(&self) -> Byte {
1441        Byte::new_unchecked(self.0.slice(22..23))
1442    }
1443    pub fn nth23(&self) -> Byte {
1444        Byte::new_unchecked(self.0.slice(23..24))
1445    }
1446    pub fn nth24(&self) -> Byte {
1447        Byte::new_unchecked(self.0.slice(24..25))
1448    }
1449    pub fn nth25(&self) -> Byte {
1450        Byte::new_unchecked(self.0.slice(25..26))
1451    }
1452    pub fn nth26(&self) -> Byte {
1453        Byte::new_unchecked(self.0.slice(26..27))
1454    }
1455    pub fn nth27(&self) -> Byte {
1456        Byte::new_unchecked(self.0.slice(27..28))
1457    }
1458    pub fn nth28(&self) -> Byte {
1459        Byte::new_unchecked(self.0.slice(28..29))
1460    }
1461    pub fn nth29(&self) -> Byte {
1462        Byte::new_unchecked(self.0.slice(29..30))
1463    }
1464    pub fn nth30(&self) -> Byte {
1465        Byte::new_unchecked(self.0.slice(30..31))
1466    }
1467    pub fn nth31(&self) -> Byte {
1468        Byte::new_unchecked(self.0.slice(31..32))
1469    }
1470    pub fn nth32(&self) -> Byte {
1471        Byte::new_unchecked(self.0.slice(32..33))
1472    }
1473    pub fn nth33(&self) -> Byte {
1474        Byte::new_unchecked(self.0.slice(33..34))
1475    }
1476    pub fn nth34(&self) -> Byte {
1477        Byte::new_unchecked(self.0.slice(34..35))
1478    }
1479    pub fn nth35(&self) -> Byte {
1480        Byte::new_unchecked(self.0.slice(35..36))
1481    }
1482    pub fn nth36(&self) -> Byte {
1483        Byte::new_unchecked(self.0.slice(36..37))
1484    }
1485    pub fn nth37(&self) -> Byte {
1486        Byte::new_unchecked(self.0.slice(37..38))
1487    }
1488    pub fn nth38(&self) -> Byte {
1489        Byte::new_unchecked(self.0.slice(38..39))
1490    }
1491    pub fn nth39(&self) -> Byte {
1492        Byte::new_unchecked(self.0.slice(39..40))
1493    }
1494    pub fn nth40(&self) -> Byte {
1495        Byte::new_unchecked(self.0.slice(40..41))
1496    }
1497    pub fn nth41(&self) -> Byte {
1498        Byte::new_unchecked(self.0.slice(41..42))
1499    }
1500    pub fn nth42(&self) -> Byte {
1501        Byte::new_unchecked(self.0.slice(42..43))
1502    }
1503    pub fn nth43(&self) -> Byte {
1504        Byte::new_unchecked(self.0.slice(43..44))
1505    }
1506    pub fn nth44(&self) -> Byte {
1507        Byte::new_unchecked(self.0.slice(44..45))
1508    }
1509    pub fn nth45(&self) -> Byte {
1510        Byte::new_unchecked(self.0.slice(45..46))
1511    }
1512    pub fn nth46(&self) -> Byte {
1513        Byte::new_unchecked(self.0.slice(46..47))
1514    }
1515    pub fn nth47(&self) -> Byte {
1516        Byte::new_unchecked(self.0.slice(47..48))
1517    }
1518    pub fn nth48(&self) -> Byte {
1519        Byte::new_unchecked(self.0.slice(48..49))
1520    }
1521    pub fn nth49(&self) -> Byte {
1522        Byte::new_unchecked(self.0.slice(49..50))
1523    }
1524    pub fn nth50(&self) -> Byte {
1525        Byte::new_unchecked(self.0.slice(50..51))
1526    }
1527    pub fn nth51(&self) -> Byte {
1528        Byte::new_unchecked(self.0.slice(51..52))
1529    }
1530    pub fn nth52(&self) -> Byte {
1531        Byte::new_unchecked(self.0.slice(52..53))
1532    }
1533    pub fn nth53(&self) -> Byte {
1534        Byte::new_unchecked(self.0.slice(53..54))
1535    }
1536    pub fn nth54(&self) -> Byte {
1537        Byte::new_unchecked(self.0.slice(54..55))
1538    }
1539    pub fn nth55(&self) -> Byte {
1540        Byte::new_unchecked(self.0.slice(55..56))
1541    }
1542    pub fn nth56(&self) -> Byte {
1543        Byte::new_unchecked(self.0.slice(56..57))
1544    }
1545    pub fn nth57(&self) -> Byte {
1546        Byte::new_unchecked(self.0.slice(57..58))
1547    }
1548    pub fn nth58(&self) -> Byte {
1549        Byte::new_unchecked(self.0.slice(58..59))
1550    }
1551    pub fn nth59(&self) -> Byte {
1552        Byte::new_unchecked(self.0.slice(59..60))
1553    }
1554    pub fn nth60(&self) -> Byte {
1555        Byte::new_unchecked(self.0.slice(60..61))
1556    }
1557    pub fn nth61(&self) -> Byte {
1558        Byte::new_unchecked(self.0.slice(61..62))
1559    }
1560    pub fn nth62(&self) -> Byte {
1561        Byte::new_unchecked(self.0.slice(62..63))
1562    }
1563    pub fn nth63(&self) -> Byte {
1564        Byte::new_unchecked(self.0.slice(63..64))
1565    }
1566    pub fn nth64(&self) -> Byte {
1567        Byte::new_unchecked(self.0.slice(64..65))
1568    }
1569    pub fn nth65(&self) -> Byte {
1570        Byte::new_unchecked(self.0.slice(65..66))
1571    }
1572    pub fn raw_data(&self) -> molecule::bytes::Bytes {
1573        self.as_bytes()
1574    }
1575    pub fn as_reader<'r>(&'r self) -> PubNonceReader<'r> {
1576        PubNonceReader::new_unchecked(self.as_slice())
1577    }
1578}
1579impl molecule::prelude::Entity for PubNonce {
1580    type Builder = PubNonceBuilder;
1581    const NAME: &'static str = "PubNonce";
1582    fn new_unchecked(data: molecule::bytes::Bytes) -> Self {
1583        PubNonce(data)
1584    }
1585    fn as_bytes(&self) -> molecule::bytes::Bytes {
1586        self.0.clone()
1587    }
1588    fn as_slice(&self) -> &[u8] {
1589        &self.0[..]
1590    }
1591    fn from_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
1592        PubNonceReader::from_slice(slice).map(|reader| reader.to_entity())
1593    }
1594    fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
1595        PubNonceReader::from_compatible_slice(slice).map(|reader| reader.to_entity())
1596    }
1597    fn new_builder() -> Self::Builder {
1598        ::core::default::Default::default()
1599    }
1600    fn as_builder(self) -> Self::Builder {
1601        Self::new_builder().set([
1602            self.nth0(),
1603            self.nth1(),
1604            self.nth2(),
1605            self.nth3(),
1606            self.nth4(),
1607            self.nth5(),
1608            self.nth6(),
1609            self.nth7(),
1610            self.nth8(),
1611            self.nth9(),
1612            self.nth10(),
1613            self.nth11(),
1614            self.nth12(),
1615            self.nth13(),
1616            self.nth14(),
1617            self.nth15(),
1618            self.nth16(),
1619            self.nth17(),
1620            self.nth18(),
1621            self.nth19(),
1622            self.nth20(),
1623            self.nth21(),
1624            self.nth22(),
1625            self.nth23(),
1626            self.nth24(),
1627            self.nth25(),
1628            self.nth26(),
1629            self.nth27(),
1630            self.nth28(),
1631            self.nth29(),
1632            self.nth30(),
1633            self.nth31(),
1634            self.nth32(),
1635            self.nth33(),
1636            self.nth34(),
1637            self.nth35(),
1638            self.nth36(),
1639            self.nth37(),
1640            self.nth38(),
1641            self.nth39(),
1642            self.nth40(),
1643            self.nth41(),
1644            self.nth42(),
1645            self.nth43(),
1646            self.nth44(),
1647            self.nth45(),
1648            self.nth46(),
1649            self.nth47(),
1650            self.nth48(),
1651            self.nth49(),
1652            self.nth50(),
1653            self.nth51(),
1654            self.nth52(),
1655            self.nth53(),
1656            self.nth54(),
1657            self.nth55(),
1658            self.nth56(),
1659            self.nth57(),
1660            self.nth58(),
1661            self.nth59(),
1662            self.nth60(),
1663            self.nth61(),
1664            self.nth62(),
1665            self.nth63(),
1666            self.nth64(),
1667            self.nth65(),
1668        ])
1669    }
1670}
1671#[derive(Clone, Copy)]
1672pub struct PubNonceReader<'r>(&'r [u8]);
1673impl<'r> ::core::fmt::LowerHex for PubNonceReader<'r> {
1674    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
1675        use molecule::hex_string;
1676        if f.alternate() {
1677            write!(f, "0x")?;
1678        }
1679        write!(f, "{}", hex_string(self.as_slice()))
1680    }
1681}
1682impl<'r> ::core::fmt::Debug for PubNonceReader<'r> {
1683    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
1684        write!(f, "{}({:#x})", Self::NAME, self)
1685    }
1686}
1687impl<'r> ::core::fmt::Display for PubNonceReader<'r> {
1688    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
1689        use molecule::hex_string;
1690        let raw_data = hex_string(&self.raw_data());
1691        write!(f, "{}(0x{})", Self::NAME, raw_data)
1692    }
1693}
1694impl<'r> PubNonceReader<'r> {
1695    pub const TOTAL_SIZE: usize = 66;
1696    pub const ITEM_SIZE: usize = 1;
1697    pub const ITEM_COUNT: usize = 66;
1698    pub fn nth0(&self) -> ByteReader<'r> {
1699        ByteReader::new_unchecked(&self.as_slice()[0..1])
1700    }
1701    pub fn nth1(&self) -> ByteReader<'r> {
1702        ByteReader::new_unchecked(&self.as_slice()[1..2])
1703    }
1704    pub fn nth2(&self) -> ByteReader<'r> {
1705        ByteReader::new_unchecked(&self.as_slice()[2..3])
1706    }
1707    pub fn nth3(&self) -> ByteReader<'r> {
1708        ByteReader::new_unchecked(&self.as_slice()[3..4])
1709    }
1710    pub fn nth4(&self) -> ByteReader<'r> {
1711        ByteReader::new_unchecked(&self.as_slice()[4..5])
1712    }
1713    pub fn nth5(&self) -> ByteReader<'r> {
1714        ByteReader::new_unchecked(&self.as_slice()[5..6])
1715    }
1716    pub fn nth6(&self) -> ByteReader<'r> {
1717        ByteReader::new_unchecked(&self.as_slice()[6..7])
1718    }
1719    pub fn nth7(&self) -> ByteReader<'r> {
1720        ByteReader::new_unchecked(&self.as_slice()[7..8])
1721    }
1722    pub fn nth8(&self) -> ByteReader<'r> {
1723        ByteReader::new_unchecked(&self.as_slice()[8..9])
1724    }
1725    pub fn nth9(&self) -> ByteReader<'r> {
1726        ByteReader::new_unchecked(&self.as_slice()[9..10])
1727    }
1728    pub fn nth10(&self) -> ByteReader<'r> {
1729        ByteReader::new_unchecked(&self.as_slice()[10..11])
1730    }
1731    pub fn nth11(&self) -> ByteReader<'r> {
1732        ByteReader::new_unchecked(&self.as_slice()[11..12])
1733    }
1734    pub fn nth12(&self) -> ByteReader<'r> {
1735        ByteReader::new_unchecked(&self.as_slice()[12..13])
1736    }
1737    pub fn nth13(&self) -> ByteReader<'r> {
1738        ByteReader::new_unchecked(&self.as_slice()[13..14])
1739    }
1740    pub fn nth14(&self) -> ByteReader<'r> {
1741        ByteReader::new_unchecked(&self.as_slice()[14..15])
1742    }
1743    pub fn nth15(&self) -> ByteReader<'r> {
1744        ByteReader::new_unchecked(&self.as_slice()[15..16])
1745    }
1746    pub fn nth16(&self) -> ByteReader<'r> {
1747        ByteReader::new_unchecked(&self.as_slice()[16..17])
1748    }
1749    pub fn nth17(&self) -> ByteReader<'r> {
1750        ByteReader::new_unchecked(&self.as_slice()[17..18])
1751    }
1752    pub fn nth18(&self) -> ByteReader<'r> {
1753        ByteReader::new_unchecked(&self.as_slice()[18..19])
1754    }
1755    pub fn nth19(&self) -> ByteReader<'r> {
1756        ByteReader::new_unchecked(&self.as_slice()[19..20])
1757    }
1758    pub fn nth20(&self) -> ByteReader<'r> {
1759        ByteReader::new_unchecked(&self.as_slice()[20..21])
1760    }
1761    pub fn nth21(&self) -> ByteReader<'r> {
1762        ByteReader::new_unchecked(&self.as_slice()[21..22])
1763    }
1764    pub fn nth22(&self) -> ByteReader<'r> {
1765        ByteReader::new_unchecked(&self.as_slice()[22..23])
1766    }
1767    pub fn nth23(&self) -> ByteReader<'r> {
1768        ByteReader::new_unchecked(&self.as_slice()[23..24])
1769    }
1770    pub fn nth24(&self) -> ByteReader<'r> {
1771        ByteReader::new_unchecked(&self.as_slice()[24..25])
1772    }
1773    pub fn nth25(&self) -> ByteReader<'r> {
1774        ByteReader::new_unchecked(&self.as_slice()[25..26])
1775    }
1776    pub fn nth26(&self) -> ByteReader<'r> {
1777        ByteReader::new_unchecked(&self.as_slice()[26..27])
1778    }
1779    pub fn nth27(&self) -> ByteReader<'r> {
1780        ByteReader::new_unchecked(&self.as_slice()[27..28])
1781    }
1782    pub fn nth28(&self) -> ByteReader<'r> {
1783        ByteReader::new_unchecked(&self.as_slice()[28..29])
1784    }
1785    pub fn nth29(&self) -> ByteReader<'r> {
1786        ByteReader::new_unchecked(&self.as_slice()[29..30])
1787    }
1788    pub fn nth30(&self) -> ByteReader<'r> {
1789        ByteReader::new_unchecked(&self.as_slice()[30..31])
1790    }
1791    pub fn nth31(&self) -> ByteReader<'r> {
1792        ByteReader::new_unchecked(&self.as_slice()[31..32])
1793    }
1794    pub fn nth32(&self) -> ByteReader<'r> {
1795        ByteReader::new_unchecked(&self.as_slice()[32..33])
1796    }
1797    pub fn nth33(&self) -> ByteReader<'r> {
1798        ByteReader::new_unchecked(&self.as_slice()[33..34])
1799    }
1800    pub fn nth34(&self) -> ByteReader<'r> {
1801        ByteReader::new_unchecked(&self.as_slice()[34..35])
1802    }
1803    pub fn nth35(&self) -> ByteReader<'r> {
1804        ByteReader::new_unchecked(&self.as_slice()[35..36])
1805    }
1806    pub fn nth36(&self) -> ByteReader<'r> {
1807        ByteReader::new_unchecked(&self.as_slice()[36..37])
1808    }
1809    pub fn nth37(&self) -> ByteReader<'r> {
1810        ByteReader::new_unchecked(&self.as_slice()[37..38])
1811    }
1812    pub fn nth38(&self) -> ByteReader<'r> {
1813        ByteReader::new_unchecked(&self.as_slice()[38..39])
1814    }
1815    pub fn nth39(&self) -> ByteReader<'r> {
1816        ByteReader::new_unchecked(&self.as_slice()[39..40])
1817    }
1818    pub fn nth40(&self) -> ByteReader<'r> {
1819        ByteReader::new_unchecked(&self.as_slice()[40..41])
1820    }
1821    pub fn nth41(&self) -> ByteReader<'r> {
1822        ByteReader::new_unchecked(&self.as_slice()[41..42])
1823    }
1824    pub fn nth42(&self) -> ByteReader<'r> {
1825        ByteReader::new_unchecked(&self.as_slice()[42..43])
1826    }
1827    pub fn nth43(&self) -> ByteReader<'r> {
1828        ByteReader::new_unchecked(&self.as_slice()[43..44])
1829    }
1830    pub fn nth44(&self) -> ByteReader<'r> {
1831        ByteReader::new_unchecked(&self.as_slice()[44..45])
1832    }
1833    pub fn nth45(&self) -> ByteReader<'r> {
1834        ByteReader::new_unchecked(&self.as_slice()[45..46])
1835    }
1836    pub fn nth46(&self) -> ByteReader<'r> {
1837        ByteReader::new_unchecked(&self.as_slice()[46..47])
1838    }
1839    pub fn nth47(&self) -> ByteReader<'r> {
1840        ByteReader::new_unchecked(&self.as_slice()[47..48])
1841    }
1842    pub fn nth48(&self) -> ByteReader<'r> {
1843        ByteReader::new_unchecked(&self.as_slice()[48..49])
1844    }
1845    pub fn nth49(&self) -> ByteReader<'r> {
1846        ByteReader::new_unchecked(&self.as_slice()[49..50])
1847    }
1848    pub fn nth50(&self) -> ByteReader<'r> {
1849        ByteReader::new_unchecked(&self.as_slice()[50..51])
1850    }
1851    pub fn nth51(&self) -> ByteReader<'r> {
1852        ByteReader::new_unchecked(&self.as_slice()[51..52])
1853    }
1854    pub fn nth52(&self) -> ByteReader<'r> {
1855        ByteReader::new_unchecked(&self.as_slice()[52..53])
1856    }
1857    pub fn nth53(&self) -> ByteReader<'r> {
1858        ByteReader::new_unchecked(&self.as_slice()[53..54])
1859    }
1860    pub fn nth54(&self) -> ByteReader<'r> {
1861        ByteReader::new_unchecked(&self.as_slice()[54..55])
1862    }
1863    pub fn nth55(&self) -> ByteReader<'r> {
1864        ByteReader::new_unchecked(&self.as_slice()[55..56])
1865    }
1866    pub fn nth56(&self) -> ByteReader<'r> {
1867        ByteReader::new_unchecked(&self.as_slice()[56..57])
1868    }
1869    pub fn nth57(&self) -> ByteReader<'r> {
1870        ByteReader::new_unchecked(&self.as_slice()[57..58])
1871    }
1872    pub fn nth58(&self) -> ByteReader<'r> {
1873        ByteReader::new_unchecked(&self.as_slice()[58..59])
1874    }
1875    pub fn nth59(&self) -> ByteReader<'r> {
1876        ByteReader::new_unchecked(&self.as_slice()[59..60])
1877    }
1878    pub fn nth60(&self) -> ByteReader<'r> {
1879        ByteReader::new_unchecked(&self.as_slice()[60..61])
1880    }
1881    pub fn nth61(&self) -> ByteReader<'r> {
1882        ByteReader::new_unchecked(&self.as_slice()[61..62])
1883    }
1884    pub fn nth62(&self) -> ByteReader<'r> {
1885        ByteReader::new_unchecked(&self.as_slice()[62..63])
1886    }
1887    pub fn nth63(&self) -> ByteReader<'r> {
1888        ByteReader::new_unchecked(&self.as_slice()[63..64])
1889    }
1890    pub fn nth64(&self) -> ByteReader<'r> {
1891        ByteReader::new_unchecked(&self.as_slice()[64..65])
1892    }
1893    pub fn nth65(&self) -> ByteReader<'r> {
1894        ByteReader::new_unchecked(&self.as_slice()[65..66])
1895    }
1896    pub fn raw_data(&self) -> &'r [u8] {
1897        self.as_slice()
1898    }
1899}
1900impl<'r> molecule::prelude::Reader<'r> for PubNonceReader<'r> {
1901    type Entity = PubNonce;
1902    const NAME: &'static str = "PubNonceReader";
1903    fn to_entity(&self) -> Self::Entity {
1904        Self::Entity::new_unchecked(self.as_slice().to_owned().into())
1905    }
1906    fn new_unchecked(slice: &'r [u8]) -> Self {
1907        PubNonceReader(slice)
1908    }
1909    fn as_slice(&self) -> &'r [u8] {
1910        self.0
1911    }
1912    fn verify(slice: &[u8], _compatible: bool) -> molecule::error::VerificationResult<()> {
1913        use molecule::verification_error as ve;
1914        let slice_len = slice.len();
1915        if slice_len != Self::TOTAL_SIZE {
1916            return ve!(Self, TotalSizeNotMatch, Self::TOTAL_SIZE, slice_len);
1917        }
1918        Ok(())
1919    }
1920}
1921#[derive(Clone)]
1922pub struct PubNonceBuilder(pub(crate) [Byte; 66]);
1923impl ::core::fmt::Debug for PubNonceBuilder {
1924    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
1925        write!(f, "{}({:?})", Self::NAME, &self.0[..])
1926    }
1927}
1928impl ::core::default::Default for PubNonceBuilder {
1929    fn default() -> Self {
1930        PubNonceBuilder([
1931            Byte::default(),
1932            Byte::default(),
1933            Byte::default(),
1934            Byte::default(),
1935            Byte::default(),
1936            Byte::default(),
1937            Byte::default(),
1938            Byte::default(),
1939            Byte::default(),
1940            Byte::default(),
1941            Byte::default(),
1942            Byte::default(),
1943            Byte::default(),
1944            Byte::default(),
1945            Byte::default(),
1946            Byte::default(),
1947            Byte::default(),
1948            Byte::default(),
1949            Byte::default(),
1950            Byte::default(),
1951            Byte::default(),
1952            Byte::default(),
1953            Byte::default(),
1954            Byte::default(),
1955            Byte::default(),
1956            Byte::default(),
1957            Byte::default(),
1958            Byte::default(),
1959            Byte::default(),
1960            Byte::default(),
1961            Byte::default(),
1962            Byte::default(),
1963            Byte::default(),
1964            Byte::default(),
1965            Byte::default(),
1966            Byte::default(),
1967            Byte::default(),
1968            Byte::default(),
1969            Byte::default(),
1970            Byte::default(),
1971            Byte::default(),
1972            Byte::default(),
1973            Byte::default(),
1974            Byte::default(),
1975            Byte::default(),
1976            Byte::default(),
1977            Byte::default(),
1978            Byte::default(),
1979            Byte::default(),
1980            Byte::default(),
1981            Byte::default(),
1982            Byte::default(),
1983            Byte::default(),
1984            Byte::default(),
1985            Byte::default(),
1986            Byte::default(),
1987            Byte::default(),
1988            Byte::default(),
1989            Byte::default(),
1990            Byte::default(),
1991            Byte::default(),
1992            Byte::default(),
1993            Byte::default(),
1994            Byte::default(),
1995            Byte::default(),
1996            Byte::default(),
1997        ])
1998    }
1999}
2000impl PubNonceBuilder {
2001    pub const TOTAL_SIZE: usize = 66;
2002    pub const ITEM_SIZE: usize = 1;
2003    pub const ITEM_COUNT: usize = 66;
2004    pub fn set(mut self, v: [Byte; 66]) -> Self {
2005        self.0 = v;
2006        self
2007    }
2008    pub fn nth0(mut self, v: Byte) -> Self {
2009        self.0[0] = v;
2010        self
2011    }
2012    pub fn nth1(mut self, v: Byte) -> Self {
2013        self.0[1] = v;
2014        self
2015    }
2016    pub fn nth2(mut self, v: Byte) -> Self {
2017        self.0[2] = v;
2018        self
2019    }
2020    pub fn nth3(mut self, v: Byte) -> Self {
2021        self.0[3] = v;
2022        self
2023    }
2024    pub fn nth4(mut self, v: Byte) -> Self {
2025        self.0[4] = v;
2026        self
2027    }
2028    pub fn nth5(mut self, v: Byte) -> Self {
2029        self.0[5] = v;
2030        self
2031    }
2032    pub fn nth6(mut self, v: Byte) -> Self {
2033        self.0[6] = v;
2034        self
2035    }
2036    pub fn nth7(mut self, v: Byte) -> Self {
2037        self.0[7] = v;
2038        self
2039    }
2040    pub fn nth8(mut self, v: Byte) -> Self {
2041        self.0[8] = v;
2042        self
2043    }
2044    pub fn nth9(mut self, v: Byte) -> Self {
2045        self.0[9] = v;
2046        self
2047    }
2048    pub fn nth10(mut self, v: Byte) -> Self {
2049        self.0[10] = v;
2050        self
2051    }
2052    pub fn nth11(mut self, v: Byte) -> Self {
2053        self.0[11] = v;
2054        self
2055    }
2056    pub fn nth12(mut self, v: Byte) -> Self {
2057        self.0[12] = v;
2058        self
2059    }
2060    pub fn nth13(mut self, v: Byte) -> Self {
2061        self.0[13] = v;
2062        self
2063    }
2064    pub fn nth14(mut self, v: Byte) -> Self {
2065        self.0[14] = v;
2066        self
2067    }
2068    pub fn nth15(mut self, v: Byte) -> Self {
2069        self.0[15] = v;
2070        self
2071    }
2072    pub fn nth16(mut self, v: Byte) -> Self {
2073        self.0[16] = v;
2074        self
2075    }
2076    pub fn nth17(mut self, v: Byte) -> Self {
2077        self.0[17] = v;
2078        self
2079    }
2080    pub fn nth18(mut self, v: Byte) -> Self {
2081        self.0[18] = v;
2082        self
2083    }
2084    pub fn nth19(mut self, v: Byte) -> Self {
2085        self.0[19] = v;
2086        self
2087    }
2088    pub fn nth20(mut self, v: Byte) -> Self {
2089        self.0[20] = v;
2090        self
2091    }
2092    pub fn nth21(mut self, v: Byte) -> Self {
2093        self.0[21] = v;
2094        self
2095    }
2096    pub fn nth22(mut self, v: Byte) -> Self {
2097        self.0[22] = v;
2098        self
2099    }
2100    pub fn nth23(mut self, v: Byte) -> Self {
2101        self.0[23] = v;
2102        self
2103    }
2104    pub fn nth24(mut self, v: Byte) -> Self {
2105        self.0[24] = v;
2106        self
2107    }
2108    pub fn nth25(mut self, v: Byte) -> Self {
2109        self.0[25] = v;
2110        self
2111    }
2112    pub fn nth26(mut self, v: Byte) -> Self {
2113        self.0[26] = v;
2114        self
2115    }
2116    pub fn nth27(mut self, v: Byte) -> Self {
2117        self.0[27] = v;
2118        self
2119    }
2120    pub fn nth28(mut self, v: Byte) -> Self {
2121        self.0[28] = v;
2122        self
2123    }
2124    pub fn nth29(mut self, v: Byte) -> Self {
2125        self.0[29] = v;
2126        self
2127    }
2128    pub fn nth30(mut self, v: Byte) -> Self {
2129        self.0[30] = v;
2130        self
2131    }
2132    pub fn nth31(mut self, v: Byte) -> Self {
2133        self.0[31] = v;
2134        self
2135    }
2136    pub fn nth32(mut self, v: Byte) -> Self {
2137        self.0[32] = v;
2138        self
2139    }
2140    pub fn nth33(mut self, v: Byte) -> Self {
2141        self.0[33] = v;
2142        self
2143    }
2144    pub fn nth34(mut self, v: Byte) -> Self {
2145        self.0[34] = v;
2146        self
2147    }
2148    pub fn nth35(mut self, v: Byte) -> Self {
2149        self.0[35] = v;
2150        self
2151    }
2152    pub fn nth36(mut self, v: Byte) -> Self {
2153        self.0[36] = v;
2154        self
2155    }
2156    pub fn nth37(mut self, v: Byte) -> Self {
2157        self.0[37] = v;
2158        self
2159    }
2160    pub fn nth38(mut self, v: Byte) -> Self {
2161        self.0[38] = v;
2162        self
2163    }
2164    pub fn nth39(mut self, v: Byte) -> Self {
2165        self.0[39] = v;
2166        self
2167    }
2168    pub fn nth40(mut self, v: Byte) -> Self {
2169        self.0[40] = v;
2170        self
2171    }
2172    pub fn nth41(mut self, v: Byte) -> Self {
2173        self.0[41] = v;
2174        self
2175    }
2176    pub fn nth42(mut self, v: Byte) -> Self {
2177        self.0[42] = v;
2178        self
2179    }
2180    pub fn nth43(mut self, v: Byte) -> Self {
2181        self.0[43] = v;
2182        self
2183    }
2184    pub fn nth44(mut self, v: Byte) -> Self {
2185        self.0[44] = v;
2186        self
2187    }
2188    pub fn nth45(mut self, v: Byte) -> Self {
2189        self.0[45] = v;
2190        self
2191    }
2192    pub fn nth46(mut self, v: Byte) -> Self {
2193        self.0[46] = v;
2194        self
2195    }
2196    pub fn nth47(mut self, v: Byte) -> Self {
2197        self.0[47] = v;
2198        self
2199    }
2200    pub fn nth48(mut self, v: Byte) -> Self {
2201        self.0[48] = v;
2202        self
2203    }
2204    pub fn nth49(mut self, v: Byte) -> Self {
2205        self.0[49] = v;
2206        self
2207    }
2208    pub fn nth50(mut self, v: Byte) -> Self {
2209        self.0[50] = v;
2210        self
2211    }
2212    pub fn nth51(mut self, v: Byte) -> Self {
2213        self.0[51] = v;
2214        self
2215    }
2216    pub fn nth52(mut self, v: Byte) -> Self {
2217        self.0[52] = v;
2218        self
2219    }
2220    pub fn nth53(mut self, v: Byte) -> Self {
2221        self.0[53] = v;
2222        self
2223    }
2224    pub fn nth54(mut self, v: Byte) -> Self {
2225        self.0[54] = v;
2226        self
2227    }
2228    pub fn nth55(mut self, v: Byte) -> Self {
2229        self.0[55] = v;
2230        self
2231    }
2232    pub fn nth56(mut self, v: Byte) -> Self {
2233        self.0[56] = v;
2234        self
2235    }
2236    pub fn nth57(mut self, v: Byte) -> Self {
2237        self.0[57] = v;
2238        self
2239    }
2240    pub fn nth58(mut self, v: Byte) -> Self {
2241        self.0[58] = v;
2242        self
2243    }
2244    pub fn nth59(mut self, v: Byte) -> Self {
2245        self.0[59] = v;
2246        self
2247    }
2248    pub fn nth60(mut self, v: Byte) -> Self {
2249        self.0[60] = v;
2250        self
2251    }
2252    pub fn nth61(mut self, v: Byte) -> Self {
2253        self.0[61] = v;
2254        self
2255    }
2256    pub fn nth62(mut self, v: Byte) -> Self {
2257        self.0[62] = v;
2258        self
2259    }
2260    pub fn nth63(mut self, v: Byte) -> Self {
2261        self.0[63] = v;
2262        self
2263    }
2264    pub fn nth64(mut self, v: Byte) -> Self {
2265        self.0[64] = v;
2266        self
2267    }
2268    pub fn nth65(mut self, v: Byte) -> Self {
2269        self.0[65] = v;
2270        self
2271    }
2272}
2273impl molecule::prelude::Builder for PubNonceBuilder {
2274    type Entity = PubNonce;
2275    const NAME: &'static str = "PubNonceBuilder";
2276    fn expected_length(&self) -> usize {
2277        Self::TOTAL_SIZE
2278    }
2279    fn write<W: molecule::io::Write>(&self, writer: &mut W) -> molecule::io::Result<()> {
2280        writer.write_all(self.0[0].as_slice())?;
2281        writer.write_all(self.0[1].as_slice())?;
2282        writer.write_all(self.0[2].as_slice())?;
2283        writer.write_all(self.0[3].as_slice())?;
2284        writer.write_all(self.0[4].as_slice())?;
2285        writer.write_all(self.0[5].as_slice())?;
2286        writer.write_all(self.0[6].as_slice())?;
2287        writer.write_all(self.0[7].as_slice())?;
2288        writer.write_all(self.0[8].as_slice())?;
2289        writer.write_all(self.0[9].as_slice())?;
2290        writer.write_all(self.0[10].as_slice())?;
2291        writer.write_all(self.0[11].as_slice())?;
2292        writer.write_all(self.0[12].as_slice())?;
2293        writer.write_all(self.0[13].as_slice())?;
2294        writer.write_all(self.0[14].as_slice())?;
2295        writer.write_all(self.0[15].as_slice())?;
2296        writer.write_all(self.0[16].as_slice())?;
2297        writer.write_all(self.0[17].as_slice())?;
2298        writer.write_all(self.0[18].as_slice())?;
2299        writer.write_all(self.0[19].as_slice())?;
2300        writer.write_all(self.0[20].as_slice())?;
2301        writer.write_all(self.0[21].as_slice())?;
2302        writer.write_all(self.0[22].as_slice())?;
2303        writer.write_all(self.0[23].as_slice())?;
2304        writer.write_all(self.0[24].as_slice())?;
2305        writer.write_all(self.0[25].as_slice())?;
2306        writer.write_all(self.0[26].as_slice())?;
2307        writer.write_all(self.0[27].as_slice())?;
2308        writer.write_all(self.0[28].as_slice())?;
2309        writer.write_all(self.0[29].as_slice())?;
2310        writer.write_all(self.0[30].as_slice())?;
2311        writer.write_all(self.0[31].as_slice())?;
2312        writer.write_all(self.0[32].as_slice())?;
2313        writer.write_all(self.0[33].as_slice())?;
2314        writer.write_all(self.0[34].as_slice())?;
2315        writer.write_all(self.0[35].as_slice())?;
2316        writer.write_all(self.0[36].as_slice())?;
2317        writer.write_all(self.0[37].as_slice())?;
2318        writer.write_all(self.0[38].as_slice())?;
2319        writer.write_all(self.0[39].as_slice())?;
2320        writer.write_all(self.0[40].as_slice())?;
2321        writer.write_all(self.0[41].as_slice())?;
2322        writer.write_all(self.0[42].as_slice())?;
2323        writer.write_all(self.0[43].as_slice())?;
2324        writer.write_all(self.0[44].as_slice())?;
2325        writer.write_all(self.0[45].as_slice())?;
2326        writer.write_all(self.0[46].as_slice())?;
2327        writer.write_all(self.0[47].as_slice())?;
2328        writer.write_all(self.0[48].as_slice())?;
2329        writer.write_all(self.0[49].as_slice())?;
2330        writer.write_all(self.0[50].as_slice())?;
2331        writer.write_all(self.0[51].as_slice())?;
2332        writer.write_all(self.0[52].as_slice())?;
2333        writer.write_all(self.0[53].as_slice())?;
2334        writer.write_all(self.0[54].as_slice())?;
2335        writer.write_all(self.0[55].as_slice())?;
2336        writer.write_all(self.0[56].as_slice())?;
2337        writer.write_all(self.0[57].as_slice())?;
2338        writer.write_all(self.0[58].as_slice())?;
2339        writer.write_all(self.0[59].as_slice())?;
2340        writer.write_all(self.0[60].as_slice())?;
2341        writer.write_all(self.0[61].as_slice())?;
2342        writer.write_all(self.0[62].as_slice())?;
2343        writer.write_all(self.0[63].as_slice())?;
2344        writer.write_all(self.0[64].as_slice())?;
2345        writer.write_all(self.0[65].as_slice())?;
2346        Ok(())
2347    }
2348    fn build(&self) -> Self::Entity {
2349        let mut inner = Vec::with_capacity(self.expected_length());
2350        self.write(&mut inner)
2351            .unwrap_or_else(|_| panic!("{} build should be ok", Self::NAME));
2352        PubNonce::new_unchecked(inner.into())
2353    }
2354}
2355impl From<[Byte; 66usize]> for PubNonce {
2356    fn from(value: [Byte; 66usize]) -> Self {
2357        Self::new_builder().set(value).build()
2358    }
2359}
2360impl ::core::convert::TryFrom<&[Byte]> for PubNonce {
2361    type Error = ::core::array::TryFromSliceError;
2362    fn try_from(value: &[Byte]) -> Result<Self, ::core::array::TryFromSliceError> {
2363        Ok(Self::new_builder()
2364            .set(<&[Byte; 66usize]>::try_from(value)?.clone())
2365            .build())
2366    }
2367}
2368impl From<PubNonce> for [Byte; 66usize] {
2369    #[track_caller]
2370    fn from(value: PubNonce) -> Self {
2371        [
2372            value.nth0(),
2373            value.nth1(),
2374            value.nth2(),
2375            value.nth3(),
2376            value.nth4(),
2377            value.nth5(),
2378            value.nth6(),
2379            value.nth7(),
2380            value.nth8(),
2381            value.nth9(),
2382            value.nth10(),
2383            value.nth11(),
2384            value.nth12(),
2385            value.nth13(),
2386            value.nth14(),
2387            value.nth15(),
2388            value.nth16(),
2389            value.nth17(),
2390            value.nth18(),
2391            value.nth19(),
2392            value.nth20(),
2393            value.nth21(),
2394            value.nth22(),
2395            value.nth23(),
2396            value.nth24(),
2397            value.nth25(),
2398            value.nth26(),
2399            value.nth27(),
2400            value.nth28(),
2401            value.nth29(),
2402            value.nth30(),
2403            value.nth31(),
2404            value.nth32(),
2405            value.nth33(),
2406            value.nth34(),
2407            value.nth35(),
2408            value.nth36(),
2409            value.nth37(),
2410            value.nth38(),
2411            value.nth39(),
2412            value.nth40(),
2413            value.nth41(),
2414            value.nth42(),
2415            value.nth43(),
2416            value.nth44(),
2417            value.nth45(),
2418            value.nth46(),
2419            value.nth47(),
2420            value.nth48(),
2421            value.nth49(),
2422            value.nth50(),
2423            value.nth51(),
2424            value.nth52(),
2425            value.nth53(),
2426            value.nth54(),
2427            value.nth55(),
2428            value.nth56(),
2429            value.nth57(),
2430            value.nth58(),
2431            value.nth59(),
2432            value.nth60(),
2433            value.nth61(),
2434            value.nth62(),
2435            value.nth63(),
2436            value.nth64(),
2437            value.nth65(),
2438        ]
2439    }
2440}
2441impl From<[u8; 66usize]> for PubNonce {
2442    fn from(value: [u8; 66usize]) -> Self {
2443        PubNonceReader::new_unchecked(&value).to_entity()
2444    }
2445}
2446impl ::core::convert::TryFrom<&[u8]> for PubNonce {
2447    type Error = ::core::array::TryFromSliceError;
2448    fn try_from(value: &[u8]) -> Result<Self, ::core::array::TryFromSliceError> {
2449        Ok(<[u8; 66usize]>::try_from(value)?.into())
2450    }
2451}
2452impl From<PubNonce> for [u8; 66usize] {
2453    #[track_caller]
2454    fn from(value: PubNonce) -> Self {
2455        ::core::convert::TryFrom::try_from(value.as_slice()).unwrap()
2456    }
2457}
2458impl<'a> From<PubNonceReader<'a>> for &'a [u8; 66usize] {
2459    #[track_caller]
2460    fn from(value: PubNonceReader<'a>) -> Self {
2461        ::core::convert::TryFrom::try_from(value.as_slice()).unwrap()
2462    }
2463}
2464impl<'a> From<&'a PubNonceReader<'a>> for &'a [u8; 66usize] {
2465    #[track_caller]
2466    fn from(value: &'a PubNonceReader<'a>) -> Self {
2467        ::core::convert::TryFrom::try_from(value.as_slice()).unwrap()
2468    }
2469}
2470#[derive(Clone)]
2471pub struct PubNonceOpt(molecule::bytes::Bytes);
2472impl ::core::fmt::LowerHex for PubNonceOpt {
2473    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
2474        use molecule::hex_string;
2475        if f.alternate() {
2476            write!(f, "0x")?;
2477        }
2478        write!(f, "{}", hex_string(self.as_slice()))
2479    }
2480}
2481impl ::core::fmt::Debug for PubNonceOpt {
2482    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
2483        write!(f, "{}({:#x})", Self::NAME, self)
2484    }
2485}
2486impl ::core::fmt::Display for PubNonceOpt {
2487    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
2488        if let Some(v) = self.to_opt() {
2489            write!(f, "{}(Some({}))", Self::NAME, v)
2490        } else {
2491            write!(f, "{}(None)", Self::NAME)
2492        }
2493    }
2494}
2495impl ::core::default::Default for PubNonceOpt {
2496    fn default() -> Self {
2497        let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE);
2498        PubNonceOpt::new_unchecked(v)
2499    }
2500}
2501impl PubNonceOpt {
2502    const DEFAULT_VALUE: [u8; 0] = [];
2503    pub fn is_none(&self) -> bool {
2504        self.0.is_empty()
2505    }
2506    pub fn is_some(&self) -> bool {
2507        !self.0.is_empty()
2508    }
2509    pub fn to_opt(&self) -> Option<PubNonce> {
2510        if self.is_none() {
2511            None
2512        } else {
2513            Some(PubNonce::new_unchecked(self.0.clone()))
2514        }
2515    }
2516    pub fn as_reader<'r>(&'r self) -> PubNonceOptReader<'r> {
2517        PubNonceOptReader::new_unchecked(self.as_slice())
2518    }
2519}
2520impl molecule::prelude::Entity for PubNonceOpt {
2521    type Builder = PubNonceOptBuilder;
2522    const NAME: &'static str = "PubNonceOpt";
2523    fn new_unchecked(data: molecule::bytes::Bytes) -> Self {
2524        PubNonceOpt(data)
2525    }
2526    fn as_bytes(&self) -> molecule::bytes::Bytes {
2527        self.0.clone()
2528    }
2529    fn as_slice(&self) -> &[u8] {
2530        &self.0[..]
2531    }
2532    fn from_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
2533        PubNonceOptReader::from_slice(slice).map(|reader| reader.to_entity())
2534    }
2535    fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
2536        PubNonceOptReader::from_compatible_slice(slice).map(|reader| reader.to_entity())
2537    }
2538    fn new_builder() -> Self::Builder {
2539        ::core::default::Default::default()
2540    }
2541    fn as_builder(self) -> Self::Builder {
2542        Self::new_builder().set(self.to_opt())
2543    }
2544}
2545#[derive(Clone, Copy)]
2546pub struct PubNonceOptReader<'r>(&'r [u8]);
2547impl<'r> ::core::fmt::LowerHex for PubNonceOptReader<'r> {
2548    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
2549        use molecule::hex_string;
2550        if f.alternate() {
2551            write!(f, "0x")?;
2552        }
2553        write!(f, "{}", hex_string(self.as_slice()))
2554    }
2555}
2556impl<'r> ::core::fmt::Debug for PubNonceOptReader<'r> {
2557    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
2558        write!(f, "{}({:#x})", Self::NAME, self)
2559    }
2560}
2561impl<'r> ::core::fmt::Display for PubNonceOptReader<'r> {
2562    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
2563        if let Some(v) = self.to_opt() {
2564            write!(f, "{}(Some({}))", Self::NAME, v)
2565        } else {
2566            write!(f, "{}(None)", Self::NAME)
2567        }
2568    }
2569}
2570impl<'r> PubNonceOptReader<'r> {
2571    pub fn is_none(&self) -> bool {
2572        self.0.is_empty()
2573    }
2574    pub fn is_some(&self) -> bool {
2575        !self.0.is_empty()
2576    }
2577    pub fn to_opt(&self) -> Option<PubNonceReader<'r>> {
2578        if self.is_none() {
2579            None
2580        } else {
2581            Some(PubNonceReader::new_unchecked(self.as_slice()))
2582        }
2583    }
2584}
2585impl<'r> molecule::prelude::Reader<'r> for PubNonceOptReader<'r> {
2586    type Entity = PubNonceOpt;
2587    const NAME: &'static str = "PubNonceOptReader";
2588    fn to_entity(&self) -> Self::Entity {
2589        Self::Entity::new_unchecked(self.as_slice().to_owned().into())
2590    }
2591    fn new_unchecked(slice: &'r [u8]) -> Self {
2592        PubNonceOptReader(slice)
2593    }
2594    fn as_slice(&self) -> &'r [u8] {
2595        self.0
2596    }
2597    fn verify(slice: &[u8], compatible: bool) -> molecule::error::VerificationResult<()> {
2598        if !slice.is_empty() {
2599            PubNonceReader::verify(&slice[..], compatible)?;
2600        }
2601        Ok(())
2602    }
2603}
2604#[derive(Clone, Debug, Default)]
2605pub struct PubNonceOptBuilder(pub(crate) Option<PubNonce>);
2606impl PubNonceOptBuilder {
2607    pub fn set(mut self, v: Option<PubNonce>) -> Self {
2608        self.0 = v;
2609        self
2610    }
2611}
2612impl molecule::prelude::Builder for PubNonceOptBuilder {
2613    type Entity = PubNonceOpt;
2614    const NAME: &'static str = "PubNonceOptBuilder";
2615    fn expected_length(&self) -> usize {
2616        self.0
2617            .as_ref()
2618            .map(|ref inner| inner.as_slice().len())
2619            .unwrap_or(0)
2620    }
2621    fn write<W: molecule::io::Write>(&self, writer: &mut W) -> molecule::io::Result<()> {
2622        self.0
2623            .as_ref()
2624            .map(|ref inner| writer.write_all(inner.as_slice()))
2625            .unwrap_or(Ok(()))
2626    }
2627    fn build(&self) -> Self::Entity {
2628        let mut inner = Vec::with_capacity(self.expected_length());
2629        self.write(&mut inner)
2630            .unwrap_or_else(|_| panic!("{} build should be ok", Self::NAME));
2631        PubNonceOpt::new_unchecked(inner.into())
2632    }
2633}
2634impl From<PubNonce> for PubNonceOpt {
2635    fn from(value: PubNonce) -> Self {
2636        Self::new_builder().set(Some(value)).build()
2637    }
2638}
2639#[derive(Clone)]
2640pub struct Pubkey(molecule::bytes::Bytes);
2641impl ::core::fmt::LowerHex for Pubkey {
2642    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
2643        use molecule::hex_string;
2644        if f.alternate() {
2645            write!(f, "0x")?;
2646        }
2647        write!(f, "{}", hex_string(self.as_slice()))
2648    }
2649}
2650impl ::core::fmt::Debug for Pubkey {
2651    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
2652        write!(f, "{}({:#x})", Self::NAME, self)
2653    }
2654}
2655impl ::core::fmt::Display for Pubkey {
2656    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
2657        use molecule::hex_string;
2658        let raw_data = hex_string(&self.raw_data());
2659        write!(f, "{}(0x{})", Self::NAME, raw_data)
2660    }
2661}
2662impl ::core::default::Default for Pubkey {
2663    fn default() -> Self {
2664        let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE);
2665        Pubkey::new_unchecked(v)
2666    }
2667}
2668impl Pubkey {
2669    const DEFAULT_VALUE: [u8; 33] = [
2670        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,
2671        0, 0, 0,
2672    ];
2673    pub const TOTAL_SIZE: usize = 33;
2674    pub const ITEM_SIZE: usize = 1;
2675    pub const ITEM_COUNT: usize = 33;
2676    pub fn nth0(&self) -> Byte {
2677        Byte::new_unchecked(self.0.slice(0..1))
2678    }
2679    pub fn nth1(&self) -> Byte {
2680        Byte::new_unchecked(self.0.slice(1..2))
2681    }
2682    pub fn nth2(&self) -> Byte {
2683        Byte::new_unchecked(self.0.slice(2..3))
2684    }
2685    pub fn nth3(&self) -> Byte {
2686        Byte::new_unchecked(self.0.slice(3..4))
2687    }
2688    pub fn nth4(&self) -> Byte {
2689        Byte::new_unchecked(self.0.slice(4..5))
2690    }
2691    pub fn nth5(&self) -> Byte {
2692        Byte::new_unchecked(self.0.slice(5..6))
2693    }
2694    pub fn nth6(&self) -> Byte {
2695        Byte::new_unchecked(self.0.slice(6..7))
2696    }
2697    pub fn nth7(&self) -> Byte {
2698        Byte::new_unchecked(self.0.slice(7..8))
2699    }
2700    pub fn nth8(&self) -> Byte {
2701        Byte::new_unchecked(self.0.slice(8..9))
2702    }
2703    pub fn nth9(&self) -> Byte {
2704        Byte::new_unchecked(self.0.slice(9..10))
2705    }
2706    pub fn nth10(&self) -> Byte {
2707        Byte::new_unchecked(self.0.slice(10..11))
2708    }
2709    pub fn nth11(&self) -> Byte {
2710        Byte::new_unchecked(self.0.slice(11..12))
2711    }
2712    pub fn nth12(&self) -> Byte {
2713        Byte::new_unchecked(self.0.slice(12..13))
2714    }
2715    pub fn nth13(&self) -> Byte {
2716        Byte::new_unchecked(self.0.slice(13..14))
2717    }
2718    pub fn nth14(&self) -> Byte {
2719        Byte::new_unchecked(self.0.slice(14..15))
2720    }
2721    pub fn nth15(&self) -> Byte {
2722        Byte::new_unchecked(self.0.slice(15..16))
2723    }
2724    pub fn nth16(&self) -> Byte {
2725        Byte::new_unchecked(self.0.slice(16..17))
2726    }
2727    pub fn nth17(&self) -> Byte {
2728        Byte::new_unchecked(self.0.slice(17..18))
2729    }
2730    pub fn nth18(&self) -> Byte {
2731        Byte::new_unchecked(self.0.slice(18..19))
2732    }
2733    pub fn nth19(&self) -> Byte {
2734        Byte::new_unchecked(self.0.slice(19..20))
2735    }
2736    pub fn nth20(&self) -> Byte {
2737        Byte::new_unchecked(self.0.slice(20..21))
2738    }
2739    pub fn nth21(&self) -> Byte {
2740        Byte::new_unchecked(self.0.slice(21..22))
2741    }
2742    pub fn nth22(&self) -> Byte {
2743        Byte::new_unchecked(self.0.slice(22..23))
2744    }
2745    pub fn nth23(&self) -> Byte {
2746        Byte::new_unchecked(self.0.slice(23..24))
2747    }
2748    pub fn nth24(&self) -> Byte {
2749        Byte::new_unchecked(self.0.slice(24..25))
2750    }
2751    pub fn nth25(&self) -> Byte {
2752        Byte::new_unchecked(self.0.slice(25..26))
2753    }
2754    pub fn nth26(&self) -> Byte {
2755        Byte::new_unchecked(self.0.slice(26..27))
2756    }
2757    pub fn nth27(&self) -> Byte {
2758        Byte::new_unchecked(self.0.slice(27..28))
2759    }
2760    pub fn nth28(&self) -> Byte {
2761        Byte::new_unchecked(self.0.slice(28..29))
2762    }
2763    pub fn nth29(&self) -> Byte {
2764        Byte::new_unchecked(self.0.slice(29..30))
2765    }
2766    pub fn nth30(&self) -> Byte {
2767        Byte::new_unchecked(self.0.slice(30..31))
2768    }
2769    pub fn nth31(&self) -> Byte {
2770        Byte::new_unchecked(self.0.slice(31..32))
2771    }
2772    pub fn nth32(&self) -> Byte {
2773        Byte::new_unchecked(self.0.slice(32..33))
2774    }
2775    pub fn raw_data(&self) -> molecule::bytes::Bytes {
2776        self.as_bytes()
2777    }
2778    pub fn as_reader<'r>(&'r self) -> PubkeyReader<'r> {
2779        PubkeyReader::new_unchecked(self.as_slice())
2780    }
2781}
2782impl molecule::prelude::Entity for Pubkey {
2783    type Builder = PubkeyBuilder;
2784    const NAME: &'static str = "Pubkey";
2785    fn new_unchecked(data: molecule::bytes::Bytes) -> Self {
2786        Pubkey(data)
2787    }
2788    fn as_bytes(&self) -> molecule::bytes::Bytes {
2789        self.0.clone()
2790    }
2791    fn as_slice(&self) -> &[u8] {
2792        &self.0[..]
2793    }
2794    fn from_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
2795        PubkeyReader::from_slice(slice).map(|reader| reader.to_entity())
2796    }
2797    fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
2798        PubkeyReader::from_compatible_slice(slice).map(|reader| reader.to_entity())
2799    }
2800    fn new_builder() -> Self::Builder {
2801        ::core::default::Default::default()
2802    }
2803    fn as_builder(self) -> Self::Builder {
2804        Self::new_builder().set([
2805            self.nth0(),
2806            self.nth1(),
2807            self.nth2(),
2808            self.nth3(),
2809            self.nth4(),
2810            self.nth5(),
2811            self.nth6(),
2812            self.nth7(),
2813            self.nth8(),
2814            self.nth9(),
2815            self.nth10(),
2816            self.nth11(),
2817            self.nth12(),
2818            self.nth13(),
2819            self.nth14(),
2820            self.nth15(),
2821            self.nth16(),
2822            self.nth17(),
2823            self.nth18(),
2824            self.nth19(),
2825            self.nth20(),
2826            self.nth21(),
2827            self.nth22(),
2828            self.nth23(),
2829            self.nth24(),
2830            self.nth25(),
2831            self.nth26(),
2832            self.nth27(),
2833            self.nth28(),
2834            self.nth29(),
2835            self.nth30(),
2836            self.nth31(),
2837            self.nth32(),
2838        ])
2839    }
2840}
2841#[derive(Clone, Copy)]
2842pub struct PubkeyReader<'r>(&'r [u8]);
2843impl<'r> ::core::fmt::LowerHex for PubkeyReader<'r> {
2844    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
2845        use molecule::hex_string;
2846        if f.alternate() {
2847            write!(f, "0x")?;
2848        }
2849        write!(f, "{}", hex_string(self.as_slice()))
2850    }
2851}
2852impl<'r> ::core::fmt::Debug for PubkeyReader<'r> {
2853    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
2854        write!(f, "{}({:#x})", Self::NAME, self)
2855    }
2856}
2857impl<'r> ::core::fmt::Display for PubkeyReader<'r> {
2858    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
2859        use molecule::hex_string;
2860        let raw_data = hex_string(&self.raw_data());
2861        write!(f, "{}(0x{})", Self::NAME, raw_data)
2862    }
2863}
2864impl<'r> PubkeyReader<'r> {
2865    pub const TOTAL_SIZE: usize = 33;
2866    pub const ITEM_SIZE: usize = 1;
2867    pub const ITEM_COUNT: usize = 33;
2868    pub fn nth0(&self) -> ByteReader<'r> {
2869        ByteReader::new_unchecked(&self.as_slice()[0..1])
2870    }
2871    pub fn nth1(&self) -> ByteReader<'r> {
2872        ByteReader::new_unchecked(&self.as_slice()[1..2])
2873    }
2874    pub fn nth2(&self) -> ByteReader<'r> {
2875        ByteReader::new_unchecked(&self.as_slice()[2..3])
2876    }
2877    pub fn nth3(&self) -> ByteReader<'r> {
2878        ByteReader::new_unchecked(&self.as_slice()[3..4])
2879    }
2880    pub fn nth4(&self) -> ByteReader<'r> {
2881        ByteReader::new_unchecked(&self.as_slice()[4..5])
2882    }
2883    pub fn nth5(&self) -> ByteReader<'r> {
2884        ByteReader::new_unchecked(&self.as_slice()[5..6])
2885    }
2886    pub fn nth6(&self) -> ByteReader<'r> {
2887        ByteReader::new_unchecked(&self.as_slice()[6..7])
2888    }
2889    pub fn nth7(&self) -> ByteReader<'r> {
2890        ByteReader::new_unchecked(&self.as_slice()[7..8])
2891    }
2892    pub fn nth8(&self) -> ByteReader<'r> {
2893        ByteReader::new_unchecked(&self.as_slice()[8..9])
2894    }
2895    pub fn nth9(&self) -> ByteReader<'r> {
2896        ByteReader::new_unchecked(&self.as_slice()[9..10])
2897    }
2898    pub fn nth10(&self) -> ByteReader<'r> {
2899        ByteReader::new_unchecked(&self.as_slice()[10..11])
2900    }
2901    pub fn nth11(&self) -> ByteReader<'r> {
2902        ByteReader::new_unchecked(&self.as_slice()[11..12])
2903    }
2904    pub fn nth12(&self) -> ByteReader<'r> {
2905        ByteReader::new_unchecked(&self.as_slice()[12..13])
2906    }
2907    pub fn nth13(&self) -> ByteReader<'r> {
2908        ByteReader::new_unchecked(&self.as_slice()[13..14])
2909    }
2910    pub fn nth14(&self) -> ByteReader<'r> {
2911        ByteReader::new_unchecked(&self.as_slice()[14..15])
2912    }
2913    pub fn nth15(&self) -> ByteReader<'r> {
2914        ByteReader::new_unchecked(&self.as_slice()[15..16])
2915    }
2916    pub fn nth16(&self) -> ByteReader<'r> {
2917        ByteReader::new_unchecked(&self.as_slice()[16..17])
2918    }
2919    pub fn nth17(&self) -> ByteReader<'r> {
2920        ByteReader::new_unchecked(&self.as_slice()[17..18])
2921    }
2922    pub fn nth18(&self) -> ByteReader<'r> {
2923        ByteReader::new_unchecked(&self.as_slice()[18..19])
2924    }
2925    pub fn nth19(&self) -> ByteReader<'r> {
2926        ByteReader::new_unchecked(&self.as_slice()[19..20])
2927    }
2928    pub fn nth20(&self) -> ByteReader<'r> {
2929        ByteReader::new_unchecked(&self.as_slice()[20..21])
2930    }
2931    pub fn nth21(&self) -> ByteReader<'r> {
2932        ByteReader::new_unchecked(&self.as_slice()[21..22])
2933    }
2934    pub fn nth22(&self) -> ByteReader<'r> {
2935        ByteReader::new_unchecked(&self.as_slice()[22..23])
2936    }
2937    pub fn nth23(&self) -> ByteReader<'r> {
2938        ByteReader::new_unchecked(&self.as_slice()[23..24])
2939    }
2940    pub fn nth24(&self) -> ByteReader<'r> {
2941        ByteReader::new_unchecked(&self.as_slice()[24..25])
2942    }
2943    pub fn nth25(&self) -> ByteReader<'r> {
2944        ByteReader::new_unchecked(&self.as_slice()[25..26])
2945    }
2946    pub fn nth26(&self) -> ByteReader<'r> {
2947        ByteReader::new_unchecked(&self.as_slice()[26..27])
2948    }
2949    pub fn nth27(&self) -> ByteReader<'r> {
2950        ByteReader::new_unchecked(&self.as_slice()[27..28])
2951    }
2952    pub fn nth28(&self) -> ByteReader<'r> {
2953        ByteReader::new_unchecked(&self.as_slice()[28..29])
2954    }
2955    pub fn nth29(&self) -> ByteReader<'r> {
2956        ByteReader::new_unchecked(&self.as_slice()[29..30])
2957    }
2958    pub fn nth30(&self) -> ByteReader<'r> {
2959        ByteReader::new_unchecked(&self.as_slice()[30..31])
2960    }
2961    pub fn nth31(&self) -> ByteReader<'r> {
2962        ByteReader::new_unchecked(&self.as_slice()[31..32])
2963    }
2964    pub fn nth32(&self) -> ByteReader<'r> {
2965        ByteReader::new_unchecked(&self.as_slice()[32..33])
2966    }
2967    pub fn raw_data(&self) -> &'r [u8] {
2968        self.as_slice()
2969    }
2970}
2971impl<'r> molecule::prelude::Reader<'r> for PubkeyReader<'r> {
2972    type Entity = Pubkey;
2973    const NAME: &'static str = "PubkeyReader";
2974    fn to_entity(&self) -> Self::Entity {
2975        Self::Entity::new_unchecked(self.as_slice().to_owned().into())
2976    }
2977    fn new_unchecked(slice: &'r [u8]) -> Self {
2978        PubkeyReader(slice)
2979    }
2980    fn as_slice(&self) -> &'r [u8] {
2981        self.0
2982    }
2983    fn verify(slice: &[u8], _compatible: bool) -> molecule::error::VerificationResult<()> {
2984        use molecule::verification_error as ve;
2985        let slice_len = slice.len();
2986        if slice_len != Self::TOTAL_SIZE {
2987            return ve!(Self, TotalSizeNotMatch, Self::TOTAL_SIZE, slice_len);
2988        }
2989        Ok(())
2990    }
2991}
2992#[derive(Clone)]
2993pub struct PubkeyBuilder(pub(crate) [Byte; 33]);
2994impl ::core::fmt::Debug for PubkeyBuilder {
2995    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
2996        write!(f, "{}({:?})", Self::NAME, &self.0[..])
2997    }
2998}
2999impl ::core::default::Default for PubkeyBuilder {
3000    fn default() -> Self {
3001        PubkeyBuilder([
3002            Byte::default(),
3003            Byte::default(),
3004            Byte::default(),
3005            Byte::default(),
3006            Byte::default(),
3007            Byte::default(),
3008            Byte::default(),
3009            Byte::default(),
3010            Byte::default(),
3011            Byte::default(),
3012            Byte::default(),
3013            Byte::default(),
3014            Byte::default(),
3015            Byte::default(),
3016            Byte::default(),
3017            Byte::default(),
3018            Byte::default(),
3019            Byte::default(),
3020            Byte::default(),
3021            Byte::default(),
3022            Byte::default(),
3023            Byte::default(),
3024            Byte::default(),
3025            Byte::default(),
3026            Byte::default(),
3027            Byte::default(),
3028            Byte::default(),
3029            Byte::default(),
3030            Byte::default(),
3031            Byte::default(),
3032            Byte::default(),
3033            Byte::default(),
3034            Byte::default(),
3035        ])
3036    }
3037}
3038impl PubkeyBuilder {
3039    pub const TOTAL_SIZE: usize = 33;
3040    pub const ITEM_SIZE: usize = 1;
3041    pub const ITEM_COUNT: usize = 33;
3042    pub fn set(mut self, v: [Byte; 33]) -> Self {
3043        self.0 = v;
3044        self
3045    }
3046    pub fn nth0(mut self, v: Byte) -> Self {
3047        self.0[0] = v;
3048        self
3049    }
3050    pub fn nth1(mut self, v: Byte) -> Self {
3051        self.0[1] = v;
3052        self
3053    }
3054    pub fn nth2(mut self, v: Byte) -> Self {
3055        self.0[2] = v;
3056        self
3057    }
3058    pub fn nth3(mut self, v: Byte) -> Self {
3059        self.0[3] = v;
3060        self
3061    }
3062    pub fn nth4(mut self, v: Byte) -> Self {
3063        self.0[4] = v;
3064        self
3065    }
3066    pub fn nth5(mut self, v: Byte) -> Self {
3067        self.0[5] = v;
3068        self
3069    }
3070    pub fn nth6(mut self, v: Byte) -> Self {
3071        self.0[6] = v;
3072        self
3073    }
3074    pub fn nth7(mut self, v: Byte) -> Self {
3075        self.0[7] = v;
3076        self
3077    }
3078    pub fn nth8(mut self, v: Byte) -> Self {
3079        self.0[8] = v;
3080        self
3081    }
3082    pub fn nth9(mut self, v: Byte) -> Self {
3083        self.0[9] = v;
3084        self
3085    }
3086    pub fn nth10(mut self, v: Byte) -> Self {
3087        self.0[10] = v;
3088        self
3089    }
3090    pub fn nth11(mut self, v: Byte) -> Self {
3091        self.0[11] = v;
3092        self
3093    }
3094    pub fn nth12(mut self, v: Byte) -> Self {
3095        self.0[12] = v;
3096        self
3097    }
3098    pub fn nth13(mut self, v: Byte) -> Self {
3099        self.0[13] = v;
3100        self
3101    }
3102    pub fn nth14(mut self, v: Byte) -> Self {
3103        self.0[14] = v;
3104        self
3105    }
3106    pub fn nth15(mut self, v: Byte) -> Self {
3107        self.0[15] = v;
3108        self
3109    }
3110    pub fn nth16(mut self, v: Byte) -> Self {
3111        self.0[16] = v;
3112        self
3113    }
3114    pub fn nth17(mut self, v: Byte) -> Self {
3115        self.0[17] = v;
3116        self
3117    }
3118    pub fn nth18(mut self, v: Byte) -> Self {
3119        self.0[18] = v;
3120        self
3121    }
3122    pub fn nth19(mut self, v: Byte) -> Self {
3123        self.0[19] = v;
3124        self
3125    }
3126    pub fn nth20(mut self, v: Byte) -> Self {
3127        self.0[20] = v;
3128        self
3129    }
3130    pub fn nth21(mut self, v: Byte) -> Self {
3131        self.0[21] = v;
3132        self
3133    }
3134    pub fn nth22(mut self, v: Byte) -> Self {
3135        self.0[22] = v;
3136        self
3137    }
3138    pub fn nth23(mut self, v: Byte) -> Self {
3139        self.0[23] = v;
3140        self
3141    }
3142    pub fn nth24(mut self, v: Byte) -> Self {
3143        self.0[24] = v;
3144        self
3145    }
3146    pub fn nth25(mut self, v: Byte) -> Self {
3147        self.0[25] = v;
3148        self
3149    }
3150    pub fn nth26(mut self, v: Byte) -> Self {
3151        self.0[26] = v;
3152        self
3153    }
3154    pub fn nth27(mut self, v: Byte) -> Self {
3155        self.0[27] = v;
3156        self
3157    }
3158    pub fn nth28(mut self, v: Byte) -> Self {
3159        self.0[28] = v;
3160        self
3161    }
3162    pub fn nth29(mut self, v: Byte) -> Self {
3163        self.0[29] = v;
3164        self
3165    }
3166    pub fn nth30(mut self, v: Byte) -> Self {
3167        self.0[30] = v;
3168        self
3169    }
3170    pub fn nth31(mut self, v: Byte) -> Self {
3171        self.0[31] = v;
3172        self
3173    }
3174    pub fn nth32(mut self, v: Byte) -> Self {
3175        self.0[32] = v;
3176        self
3177    }
3178}
3179impl molecule::prelude::Builder for PubkeyBuilder {
3180    type Entity = Pubkey;
3181    const NAME: &'static str = "PubkeyBuilder";
3182    fn expected_length(&self) -> usize {
3183        Self::TOTAL_SIZE
3184    }
3185    fn write<W: molecule::io::Write>(&self, writer: &mut W) -> molecule::io::Result<()> {
3186        writer.write_all(self.0[0].as_slice())?;
3187        writer.write_all(self.0[1].as_slice())?;
3188        writer.write_all(self.0[2].as_slice())?;
3189        writer.write_all(self.0[3].as_slice())?;
3190        writer.write_all(self.0[4].as_slice())?;
3191        writer.write_all(self.0[5].as_slice())?;
3192        writer.write_all(self.0[6].as_slice())?;
3193        writer.write_all(self.0[7].as_slice())?;
3194        writer.write_all(self.0[8].as_slice())?;
3195        writer.write_all(self.0[9].as_slice())?;
3196        writer.write_all(self.0[10].as_slice())?;
3197        writer.write_all(self.0[11].as_slice())?;
3198        writer.write_all(self.0[12].as_slice())?;
3199        writer.write_all(self.0[13].as_slice())?;
3200        writer.write_all(self.0[14].as_slice())?;
3201        writer.write_all(self.0[15].as_slice())?;
3202        writer.write_all(self.0[16].as_slice())?;
3203        writer.write_all(self.0[17].as_slice())?;
3204        writer.write_all(self.0[18].as_slice())?;
3205        writer.write_all(self.0[19].as_slice())?;
3206        writer.write_all(self.0[20].as_slice())?;
3207        writer.write_all(self.0[21].as_slice())?;
3208        writer.write_all(self.0[22].as_slice())?;
3209        writer.write_all(self.0[23].as_slice())?;
3210        writer.write_all(self.0[24].as_slice())?;
3211        writer.write_all(self.0[25].as_slice())?;
3212        writer.write_all(self.0[26].as_slice())?;
3213        writer.write_all(self.0[27].as_slice())?;
3214        writer.write_all(self.0[28].as_slice())?;
3215        writer.write_all(self.0[29].as_slice())?;
3216        writer.write_all(self.0[30].as_slice())?;
3217        writer.write_all(self.0[31].as_slice())?;
3218        writer.write_all(self.0[32].as_slice())?;
3219        Ok(())
3220    }
3221    fn build(&self) -> Self::Entity {
3222        let mut inner = Vec::with_capacity(self.expected_length());
3223        self.write(&mut inner)
3224            .unwrap_or_else(|_| panic!("{} build should be ok", Self::NAME));
3225        Pubkey::new_unchecked(inner.into())
3226    }
3227}
3228impl From<[Byte; 33usize]> for Pubkey {
3229    fn from(value: [Byte; 33usize]) -> Self {
3230        Self::new_builder().set(value).build()
3231    }
3232}
3233impl ::core::convert::TryFrom<&[Byte]> for Pubkey {
3234    type Error = ::core::array::TryFromSliceError;
3235    fn try_from(value: &[Byte]) -> Result<Self, ::core::array::TryFromSliceError> {
3236        Ok(Self::new_builder()
3237            .set(<&[Byte; 33usize]>::try_from(value)?.clone())
3238            .build())
3239    }
3240}
3241impl From<Pubkey> for [Byte; 33usize] {
3242    #[track_caller]
3243    fn from(value: Pubkey) -> Self {
3244        [
3245            value.nth0(),
3246            value.nth1(),
3247            value.nth2(),
3248            value.nth3(),
3249            value.nth4(),
3250            value.nth5(),
3251            value.nth6(),
3252            value.nth7(),
3253            value.nth8(),
3254            value.nth9(),
3255            value.nth10(),
3256            value.nth11(),
3257            value.nth12(),
3258            value.nth13(),
3259            value.nth14(),
3260            value.nth15(),
3261            value.nth16(),
3262            value.nth17(),
3263            value.nth18(),
3264            value.nth19(),
3265            value.nth20(),
3266            value.nth21(),
3267            value.nth22(),
3268            value.nth23(),
3269            value.nth24(),
3270            value.nth25(),
3271            value.nth26(),
3272            value.nth27(),
3273            value.nth28(),
3274            value.nth29(),
3275            value.nth30(),
3276            value.nth31(),
3277            value.nth32(),
3278        ]
3279    }
3280}
3281impl From<[u8; 33usize]> for Pubkey {
3282    fn from(value: [u8; 33usize]) -> Self {
3283        PubkeyReader::new_unchecked(&value).to_entity()
3284    }
3285}
3286impl ::core::convert::TryFrom<&[u8]> for Pubkey {
3287    type Error = ::core::array::TryFromSliceError;
3288    fn try_from(value: &[u8]) -> Result<Self, ::core::array::TryFromSliceError> {
3289        Ok(<[u8; 33usize]>::try_from(value)?.into())
3290    }
3291}
3292impl From<Pubkey> for [u8; 33usize] {
3293    #[track_caller]
3294    fn from(value: Pubkey) -> Self {
3295        ::core::convert::TryFrom::try_from(value.as_slice()).unwrap()
3296    }
3297}
3298impl<'a> From<PubkeyReader<'a>> for &'a [u8; 33usize] {
3299    #[track_caller]
3300    fn from(value: PubkeyReader<'a>) -> Self {
3301        ::core::convert::TryFrom::try_from(value.as_slice()).unwrap()
3302    }
3303}
3304impl<'a> From<&'a PubkeyReader<'a>> for &'a [u8; 33usize] {
3305    #[track_caller]
3306    fn from(value: &'a PubkeyReader<'a>) -> Self {
3307        ::core::convert::TryFrom::try_from(value.as_slice()).unwrap()
3308    }
3309}
3310#[derive(Clone)]
3311pub struct Uint64Opt(molecule::bytes::Bytes);
3312impl ::core::fmt::LowerHex for Uint64Opt {
3313    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
3314        use molecule::hex_string;
3315        if f.alternate() {
3316            write!(f, "0x")?;
3317        }
3318        write!(f, "{}", hex_string(self.as_slice()))
3319    }
3320}
3321impl ::core::fmt::Debug for Uint64Opt {
3322    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
3323        write!(f, "{}({:#x})", Self::NAME, self)
3324    }
3325}
3326impl ::core::fmt::Display for Uint64Opt {
3327    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
3328        if let Some(v) = self.to_opt() {
3329            write!(f, "{}(Some({}))", Self::NAME, v)
3330        } else {
3331            write!(f, "{}(None)", Self::NAME)
3332        }
3333    }
3334}
3335impl ::core::default::Default for Uint64Opt {
3336    fn default() -> Self {
3337        let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE);
3338        Uint64Opt::new_unchecked(v)
3339    }
3340}
3341impl Uint64Opt {
3342    const DEFAULT_VALUE: [u8; 0] = [];
3343    pub fn is_none(&self) -> bool {
3344        self.0.is_empty()
3345    }
3346    pub fn is_some(&self) -> bool {
3347        !self.0.is_empty()
3348    }
3349    pub fn to_opt(&self) -> Option<Uint64> {
3350        if self.is_none() {
3351            None
3352        } else {
3353            Some(Uint64::new_unchecked(self.0.clone()))
3354        }
3355    }
3356    pub fn as_reader<'r>(&'r self) -> Uint64OptReader<'r> {
3357        Uint64OptReader::new_unchecked(self.as_slice())
3358    }
3359}
3360impl molecule::prelude::Entity for Uint64Opt {
3361    type Builder = Uint64OptBuilder;
3362    const NAME: &'static str = "Uint64Opt";
3363    fn new_unchecked(data: molecule::bytes::Bytes) -> Self {
3364        Uint64Opt(data)
3365    }
3366    fn as_bytes(&self) -> molecule::bytes::Bytes {
3367        self.0.clone()
3368    }
3369    fn as_slice(&self) -> &[u8] {
3370        &self.0[..]
3371    }
3372    fn from_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
3373        Uint64OptReader::from_slice(slice).map(|reader| reader.to_entity())
3374    }
3375    fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
3376        Uint64OptReader::from_compatible_slice(slice).map(|reader| reader.to_entity())
3377    }
3378    fn new_builder() -> Self::Builder {
3379        ::core::default::Default::default()
3380    }
3381    fn as_builder(self) -> Self::Builder {
3382        Self::new_builder().set(self.to_opt())
3383    }
3384}
3385#[derive(Clone, Copy)]
3386pub struct Uint64OptReader<'r>(&'r [u8]);
3387impl<'r> ::core::fmt::LowerHex for Uint64OptReader<'r> {
3388    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
3389        use molecule::hex_string;
3390        if f.alternate() {
3391            write!(f, "0x")?;
3392        }
3393        write!(f, "{}", hex_string(self.as_slice()))
3394    }
3395}
3396impl<'r> ::core::fmt::Debug for Uint64OptReader<'r> {
3397    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
3398        write!(f, "{}({:#x})", Self::NAME, self)
3399    }
3400}
3401impl<'r> ::core::fmt::Display for Uint64OptReader<'r> {
3402    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
3403        if let Some(v) = self.to_opt() {
3404            write!(f, "{}(Some({}))", Self::NAME, v)
3405        } else {
3406            write!(f, "{}(None)", Self::NAME)
3407        }
3408    }
3409}
3410impl<'r> Uint64OptReader<'r> {
3411    pub fn is_none(&self) -> bool {
3412        self.0.is_empty()
3413    }
3414    pub fn is_some(&self) -> bool {
3415        !self.0.is_empty()
3416    }
3417    pub fn to_opt(&self) -> Option<Uint64Reader<'r>> {
3418        if self.is_none() {
3419            None
3420        } else {
3421            Some(Uint64Reader::new_unchecked(self.as_slice()))
3422        }
3423    }
3424}
3425impl<'r> molecule::prelude::Reader<'r> for Uint64OptReader<'r> {
3426    type Entity = Uint64Opt;
3427    const NAME: &'static str = "Uint64OptReader";
3428    fn to_entity(&self) -> Self::Entity {
3429        Self::Entity::new_unchecked(self.as_slice().to_owned().into())
3430    }
3431    fn new_unchecked(slice: &'r [u8]) -> Self {
3432        Uint64OptReader(slice)
3433    }
3434    fn as_slice(&self) -> &'r [u8] {
3435        self.0
3436    }
3437    fn verify(slice: &[u8], compatible: bool) -> molecule::error::VerificationResult<()> {
3438        if !slice.is_empty() {
3439            Uint64Reader::verify(&slice[..], compatible)?;
3440        }
3441        Ok(())
3442    }
3443}
3444#[derive(Clone, Debug, Default)]
3445pub struct Uint64OptBuilder(pub(crate) Option<Uint64>);
3446impl Uint64OptBuilder {
3447    pub fn set(mut self, v: Option<Uint64>) -> Self {
3448        self.0 = v;
3449        self
3450    }
3451}
3452impl molecule::prelude::Builder for Uint64OptBuilder {
3453    type Entity = Uint64Opt;
3454    const NAME: &'static str = "Uint64OptBuilder";
3455    fn expected_length(&self) -> usize {
3456        self.0
3457            .as_ref()
3458            .map(|ref inner| inner.as_slice().len())
3459            .unwrap_or(0)
3460    }
3461    fn write<W: molecule::io::Write>(&self, writer: &mut W) -> molecule::io::Result<()> {
3462        self.0
3463            .as_ref()
3464            .map(|ref inner| writer.write_all(inner.as_slice()))
3465            .unwrap_or(Ok(()))
3466    }
3467    fn build(&self) -> Self::Entity {
3468        let mut inner = Vec::with_capacity(self.expected_length());
3469        self.write(&mut inner)
3470            .unwrap_or_else(|_| panic!("{} build should be ok", Self::NAME));
3471        Uint64Opt::new_unchecked(inner.into())
3472    }
3473}
3474impl From<Uint64> for Uint64Opt {
3475    fn from(value: Uint64) -> Self {
3476        Self::new_builder().set(Some(value)).build()
3477    }
3478}
3479#[derive(Clone)]
3480pub struct Uint128Opt(molecule::bytes::Bytes);
3481impl ::core::fmt::LowerHex for Uint128Opt {
3482    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
3483        use molecule::hex_string;
3484        if f.alternate() {
3485            write!(f, "0x")?;
3486        }
3487        write!(f, "{}", hex_string(self.as_slice()))
3488    }
3489}
3490impl ::core::fmt::Debug for Uint128Opt {
3491    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
3492        write!(f, "{}({:#x})", Self::NAME, self)
3493    }
3494}
3495impl ::core::fmt::Display for Uint128Opt {
3496    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
3497        if let Some(v) = self.to_opt() {
3498            write!(f, "{}(Some({}))", Self::NAME, v)
3499        } else {
3500            write!(f, "{}(None)", Self::NAME)
3501        }
3502    }
3503}
3504impl ::core::default::Default for Uint128Opt {
3505    fn default() -> Self {
3506        let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE);
3507        Uint128Opt::new_unchecked(v)
3508    }
3509}
3510impl Uint128Opt {
3511    const DEFAULT_VALUE: [u8; 0] = [];
3512    pub fn is_none(&self) -> bool {
3513        self.0.is_empty()
3514    }
3515    pub fn is_some(&self) -> bool {
3516        !self.0.is_empty()
3517    }
3518    pub fn to_opt(&self) -> Option<Uint128> {
3519        if self.is_none() {
3520            None
3521        } else {
3522            Some(Uint128::new_unchecked(self.0.clone()))
3523        }
3524    }
3525    pub fn as_reader<'r>(&'r self) -> Uint128OptReader<'r> {
3526        Uint128OptReader::new_unchecked(self.as_slice())
3527    }
3528}
3529impl molecule::prelude::Entity for Uint128Opt {
3530    type Builder = Uint128OptBuilder;
3531    const NAME: &'static str = "Uint128Opt";
3532    fn new_unchecked(data: molecule::bytes::Bytes) -> Self {
3533        Uint128Opt(data)
3534    }
3535    fn as_bytes(&self) -> molecule::bytes::Bytes {
3536        self.0.clone()
3537    }
3538    fn as_slice(&self) -> &[u8] {
3539        &self.0[..]
3540    }
3541    fn from_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
3542        Uint128OptReader::from_slice(slice).map(|reader| reader.to_entity())
3543    }
3544    fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
3545        Uint128OptReader::from_compatible_slice(slice).map(|reader| reader.to_entity())
3546    }
3547    fn new_builder() -> Self::Builder {
3548        ::core::default::Default::default()
3549    }
3550    fn as_builder(self) -> Self::Builder {
3551        Self::new_builder().set(self.to_opt())
3552    }
3553}
3554#[derive(Clone, Copy)]
3555pub struct Uint128OptReader<'r>(&'r [u8]);
3556impl<'r> ::core::fmt::LowerHex for Uint128OptReader<'r> {
3557    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
3558        use molecule::hex_string;
3559        if f.alternate() {
3560            write!(f, "0x")?;
3561        }
3562        write!(f, "{}", hex_string(self.as_slice()))
3563    }
3564}
3565impl<'r> ::core::fmt::Debug for Uint128OptReader<'r> {
3566    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
3567        write!(f, "{}({:#x})", Self::NAME, self)
3568    }
3569}
3570impl<'r> ::core::fmt::Display for Uint128OptReader<'r> {
3571    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
3572        if let Some(v) = self.to_opt() {
3573            write!(f, "{}(Some({}))", Self::NAME, v)
3574        } else {
3575            write!(f, "{}(None)", Self::NAME)
3576        }
3577    }
3578}
3579impl<'r> Uint128OptReader<'r> {
3580    pub fn is_none(&self) -> bool {
3581        self.0.is_empty()
3582    }
3583    pub fn is_some(&self) -> bool {
3584        !self.0.is_empty()
3585    }
3586    pub fn to_opt(&self) -> Option<Uint128Reader<'r>> {
3587        if self.is_none() {
3588            None
3589        } else {
3590            Some(Uint128Reader::new_unchecked(self.as_slice()))
3591        }
3592    }
3593}
3594impl<'r> molecule::prelude::Reader<'r> for Uint128OptReader<'r> {
3595    type Entity = Uint128Opt;
3596    const NAME: &'static str = "Uint128OptReader";
3597    fn to_entity(&self) -> Self::Entity {
3598        Self::Entity::new_unchecked(self.as_slice().to_owned().into())
3599    }
3600    fn new_unchecked(slice: &'r [u8]) -> Self {
3601        Uint128OptReader(slice)
3602    }
3603    fn as_slice(&self) -> &'r [u8] {
3604        self.0
3605    }
3606    fn verify(slice: &[u8], compatible: bool) -> molecule::error::VerificationResult<()> {
3607        if !slice.is_empty() {
3608            Uint128Reader::verify(&slice[..], compatible)?;
3609        }
3610        Ok(())
3611    }
3612}
3613#[derive(Clone, Debug, Default)]
3614pub struct Uint128OptBuilder(pub(crate) Option<Uint128>);
3615impl Uint128OptBuilder {
3616    pub fn set(mut self, v: Option<Uint128>) -> Self {
3617        self.0 = v;
3618        self
3619    }
3620}
3621impl molecule::prelude::Builder for Uint128OptBuilder {
3622    type Entity = Uint128Opt;
3623    const NAME: &'static str = "Uint128OptBuilder";
3624    fn expected_length(&self) -> usize {
3625        self.0
3626            .as_ref()
3627            .map(|ref inner| inner.as_slice().len())
3628            .unwrap_or(0)
3629    }
3630    fn write<W: molecule::io::Write>(&self, writer: &mut W) -> molecule::io::Result<()> {
3631        self.0
3632            .as_ref()
3633            .map(|ref inner| writer.write_all(inner.as_slice()))
3634            .unwrap_or(Ok(()))
3635    }
3636    fn build(&self) -> Self::Entity {
3637        let mut inner = Vec::with_capacity(self.expected_length());
3638        self.write(&mut inner)
3639            .unwrap_or_else(|_| panic!("{} build should be ok", Self::NAME));
3640        Uint128Opt::new_unchecked(inner.into())
3641    }
3642}
3643impl From<Uint128> for Uint128Opt {
3644    fn from(value: Uint128) -> Self {
3645        Self::new_builder().set(Some(value)).build()
3646    }
3647}
3648#[derive(Clone)]
3649pub struct CustomRecordsOpt(molecule::bytes::Bytes);
3650impl ::core::fmt::LowerHex for CustomRecordsOpt {
3651    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
3652        use molecule::hex_string;
3653        if f.alternate() {
3654            write!(f, "0x")?;
3655        }
3656        write!(f, "{}", hex_string(self.as_slice()))
3657    }
3658}
3659impl ::core::fmt::Debug for CustomRecordsOpt {
3660    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
3661        write!(f, "{}({:#x})", Self::NAME, self)
3662    }
3663}
3664impl ::core::fmt::Display for CustomRecordsOpt {
3665    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
3666        if let Some(v) = self.to_opt() {
3667            write!(f, "{}(Some({}))", Self::NAME, v)
3668        } else {
3669            write!(f, "{}(None)", Self::NAME)
3670        }
3671    }
3672}
3673impl ::core::default::Default for CustomRecordsOpt {
3674    fn default() -> Self {
3675        let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE);
3676        CustomRecordsOpt::new_unchecked(v)
3677    }
3678}
3679impl CustomRecordsOpt {
3680    const DEFAULT_VALUE: [u8; 0] = [];
3681    pub fn is_none(&self) -> bool {
3682        self.0.is_empty()
3683    }
3684    pub fn is_some(&self) -> bool {
3685        !self.0.is_empty()
3686    }
3687    pub fn to_opt(&self) -> Option<CustomRecords> {
3688        if self.is_none() {
3689            None
3690        } else {
3691            Some(CustomRecords::new_unchecked(self.0.clone()))
3692        }
3693    }
3694    pub fn as_reader<'r>(&'r self) -> CustomRecordsOptReader<'r> {
3695        CustomRecordsOptReader::new_unchecked(self.as_slice())
3696    }
3697}
3698impl molecule::prelude::Entity for CustomRecordsOpt {
3699    type Builder = CustomRecordsOptBuilder;
3700    const NAME: &'static str = "CustomRecordsOpt";
3701    fn new_unchecked(data: molecule::bytes::Bytes) -> Self {
3702        CustomRecordsOpt(data)
3703    }
3704    fn as_bytes(&self) -> molecule::bytes::Bytes {
3705        self.0.clone()
3706    }
3707    fn as_slice(&self) -> &[u8] {
3708        &self.0[..]
3709    }
3710    fn from_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
3711        CustomRecordsOptReader::from_slice(slice).map(|reader| reader.to_entity())
3712    }
3713    fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
3714        CustomRecordsOptReader::from_compatible_slice(slice).map(|reader| reader.to_entity())
3715    }
3716    fn new_builder() -> Self::Builder {
3717        ::core::default::Default::default()
3718    }
3719    fn as_builder(self) -> Self::Builder {
3720        Self::new_builder().set(self.to_opt())
3721    }
3722}
3723#[derive(Clone, Copy)]
3724pub struct CustomRecordsOptReader<'r>(&'r [u8]);
3725impl<'r> ::core::fmt::LowerHex for CustomRecordsOptReader<'r> {
3726    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
3727        use molecule::hex_string;
3728        if f.alternate() {
3729            write!(f, "0x")?;
3730        }
3731        write!(f, "{}", hex_string(self.as_slice()))
3732    }
3733}
3734impl<'r> ::core::fmt::Debug for CustomRecordsOptReader<'r> {
3735    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
3736        write!(f, "{}({:#x})", Self::NAME, self)
3737    }
3738}
3739impl<'r> ::core::fmt::Display for CustomRecordsOptReader<'r> {
3740    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
3741        if let Some(v) = self.to_opt() {
3742            write!(f, "{}(Some({}))", Self::NAME, v)
3743        } else {
3744            write!(f, "{}(None)", Self::NAME)
3745        }
3746    }
3747}
3748impl<'r> CustomRecordsOptReader<'r> {
3749    pub fn is_none(&self) -> bool {
3750        self.0.is_empty()
3751    }
3752    pub fn is_some(&self) -> bool {
3753        !self.0.is_empty()
3754    }
3755    pub fn to_opt(&self) -> Option<CustomRecordsReader<'r>> {
3756        if self.is_none() {
3757            None
3758        } else {
3759            Some(CustomRecordsReader::new_unchecked(self.as_slice()))
3760        }
3761    }
3762}
3763impl<'r> molecule::prelude::Reader<'r> for CustomRecordsOptReader<'r> {
3764    type Entity = CustomRecordsOpt;
3765    const NAME: &'static str = "CustomRecordsOptReader";
3766    fn to_entity(&self) -> Self::Entity {
3767        Self::Entity::new_unchecked(self.as_slice().to_owned().into())
3768    }
3769    fn new_unchecked(slice: &'r [u8]) -> Self {
3770        CustomRecordsOptReader(slice)
3771    }
3772    fn as_slice(&self) -> &'r [u8] {
3773        self.0
3774    }
3775    fn verify(slice: &[u8], compatible: bool) -> molecule::error::VerificationResult<()> {
3776        if !slice.is_empty() {
3777            CustomRecordsReader::verify(&slice[..], compatible)?;
3778        }
3779        Ok(())
3780    }
3781}
3782#[derive(Clone, Debug, Default)]
3783pub struct CustomRecordsOptBuilder(pub(crate) Option<CustomRecords>);
3784impl CustomRecordsOptBuilder {
3785    pub fn set(mut self, v: Option<CustomRecords>) -> Self {
3786        self.0 = v;
3787        self
3788    }
3789}
3790impl molecule::prelude::Builder for CustomRecordsOptBuilder {
3791    type Entity = CustomRecordsOpt;
3792    const NAME: &'static str = "CustomRecordsOptBuilder";
3793    fn expected_length(&self) -> usize {
3794        self.0
3795            .as_ref()
3796            .map(|ref inner| inner.as_slice().len())
3797            .unwrap_or(0)
3798    }
3799    fn write<W: molecule::io::Write>(&self, writer: &mut W) -> molecule::io::Result<()> {
3800        self.0
3801            .as_ref()
3802            .map(|ref inner| writer.write_all(inner.as_slice()))
3803            .unwrap_or(Ok(()))
3804    }
3805    fn build(&self) -> Self::Entity {
3806        let mut inner = Vec::with_capacity(self.expected_length());
3807        self.write(&mut inner)
3808            .unwrap_or_else(|_| panic!("{} build should be ok", Self::NAME));
3809        CustomRecordsOpt::new_unchecked(inner.into())
3810    }
3811}
3812impl From<CustomRecords> for CustomRecordsOpt {
3813    fn from(value: CustomRecords) -> Self {
3814        Self::new_builder().set(Some(value)).build()
3815    }
3816}
3817#[derive(Clone)]
3818pub struct CustomRecordDataPair(molecule::bytes::Bytes);
3819impl ::core::fmt::LowerHex for CustomRecordDataPair {
3820    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
3821        use molecule::hex_string;
3822        if f.alternate() {
3823            write!(f, "0x")?;
3824        }
3825        write!(f, "{}", hex_string(self.as_slice()))
3826    }
3827}
3828impl ::core::fmt::Debug for CustomRecordDataPair {
3829    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
3830        write!(f, "{}({:#x})", Self::NAME, self)
3831    }
3832}
3833impl ::core::fmt::Display for CustomRecordDataPair {
3834    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
3835        write!(f, "{} {{ ", Self::NAME)?;
3836        write!(f, "{}: {}", "key", self.key())?;
3837        write!(f, ", {}: {}", "value", self.value())?;
3838        let extra_count = self.count_extra_fields();
3839        if extra_count != 0 {
3840            write!(f, ", .. ({} fields)", extra_count)?;
3841        }
3842        write!(f, " }}")
3843    }
3844}
3845impl ::core::default::Default for CustomRecordDataPair {
3846    fn default() -> Self {
3847        let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE);
3848        CustomRecordDataPair::new_unchecked(v)
3849    }
3850}
3851impl CustomRecordDataPair {
3852    const DEFAULT_VALUE: [u8; 20] = [
3853        20, 0, 0, 0, 12, 0, 0, 0, 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3854    ];
3855    pub const FIELD_COUNT: usize = 2;
3856    pub fn total_size(&self) -> usize {
3857        molecule::unpack_number(self.as_slice()) as usize
3858    }
3859    pub fn field_count(&self) -> usize {
3860        if self.total_size() == molecule::NUMBER_SIZE {
3861            0
3862        } else {
3863            (molecule::unpack_number(&self.as_slice()[molecule::NUMBER_SIZE..]) as usize / 4) - 1
3864        }
3865    }
3866    pub fn count_extra_fields(&self) -> usize {
3867        self.field_count() - Self::FIELD_COUNT
3868    }
3869    pub fn has_extra_fields(&self) -> bool {
3870        Self::FIELD_COUNT != self.field_count()
3871    }
3872    pub fn key(&self) -> Uint32 {
3873        let slice = self.as_slice();
3874        let start = molecule::unpack_number(&slice[4..]) as usize;
3875        let end = molecule::unpack_number(&slice[8..]) as usize;
3876        Uint32::new_unchecked(self.0.slice(start..end))
3877    }
3878    pub fn value(&self) -> Bytes {
3879        let slice = self.as_slice();
3880        let start = molecule::unpack_number(&slice[8..]) as usize;
3881        if self.has_extra_fields() {
3882            let end = molecule::unpack_number(&slice[12..]) as usize;
3883            Bytes::new_unchecked(self.0.slice(start..end))
3884        } else {
3885            Bytes::new_unchecked(self.0.slice(start..))
3886        }
3887    }
3888    pub fn as_reader<'r>(&'r self) -> CustomRecordDataPairReader<'r> {
3889        CustomRecordDataPairReader::new_unchecked(self.as_slice())
3890    }
3891}
3892impl molecule::prelude::Entity for CustomRecordDataPair {
3893    type Builder = CustomRecordDataPairBuilder;
3894    const NAME: &'static str = "CustomRecordDataPair";
3895    fn new_unchecked(data: molecule::bytes::Bytes) -> Self {
3896        CustomRecordDataPair(data)
3897    }
3898    fn as_bytes(&self) -> molecule::bytes::Bytes {
3899        self.0.clone()
3900    }
3901    fn as_slice(&self) -> &[u8] {
3902        &self.0[..]
3903    }
3904    fn from_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
3905        CustomRecordDataPairReader::from_slice(slice).map(|reader| reader.to_entity())
3906    }
3907    fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
3908        CustomRecordDataPairReader::from_compatible_slice(slice).map(|reader| reader.to_entity())
3909    }
3910    fn new_builder() -> Self::Builder {
3911        ::core::default::Default::default()
3912    }
3913    fn as_builder(self) -> Self::Builder {
3914        Self::new_builder().key(self.key()).value(self.value())
3915    }
3916}
3917#[derive(Clone, Copy)]
3918pub struct CustomRecordDataPairReader<'r>(&'r [u8]);
3919impl<'r> ::core::fmt::LowerHex for CustomRecordDataPairReader<'r> {
3920    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
3921        use molecule::hex_string;
3922        if f.alternate() {
3923            write!(f, "0x")?;
3924        }
3925        write!(f, "{}", hex_string(self.as_slice()))
3926    }
3927}
3928impl<'r> ::core::fmt::Debug for CustomRecordDataPairReader<'r> {
3929    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
3930        write!(f, "{}({:#x})", Self::NAME, self)
3931    }
3932}
3933impl<'r> ::core::fmt::Display for CustomRecordDataPairReader<'r> {
3934    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
3935        write!(f, "{} {{ ", Self::NAME)?;
3936        write!(f, "{}: {}", "key", self.key())?;
3937        write!(f, ", {}: {}", "value", self.value())?;
3938        let extra_count = self.count_extra_fields();
3939        if extra_count != 0 {
3940            write!(f, ", .. ({} fields)", extra_count)?;
3941        }
3942        write!(f, " }}")
3943    }
3944}
3945impl<'r> CustomRecordDataPairReader<'r> {
3946    pub const FIELD_COUNT: usize = 2;
3947    pub fn total_size(&self) -> usize {
3948        molecule::unpack_number(self.as_slice()) as usize
3949    }
3950    pub fn field_count(&self) -> usize {
3951        if self.total_size() == molecule::NUMBER_SIZE {
3952            0
3953        } else {
3954            (molecule::unpack_number(&self.as_slice()[molecule::NUMBER_SIZE..]) as usize / 4) - 1
3955        }
3956    }
3957    pub fn count_extra_fields(&self) -> usize {
3958        self.field_count() - Self::FIELD_COUNT
3959    }
3960    pub fn has_extra_fields(&self) -> bool {
3961        Self::FIELD_COUNT != self.field_count()
3962    }
3963    pub fn key(&self) -> Uint32Reader<'r> {
3964        let slice = self.as_slice();
3965        let start = molecule::unpack_number(&slice[4..]) as usize;
3966        let end = molecule::unpack_number(&slice[8..]) as usize;
3967        Uint32Reader::new_unchecked(&self.as_slice()[start..end])
3968    }
3969    pub fn value(&self) -> BytesReader<'r> {
3970        let slice = self.as_slice();
3971        let start = molecule::unpack_number(&slice[8..]) as usize;
3972        if self.has_extra_fields() {
3973            let end = molecule::unpack_number(&slice[12..]) as usize;
3974            BytesReader::new_unchecked(&self.as_slice()[start..end])
3975        } else {
3976            BytesReader::new_unchecked(&self.as_slice()[start..])
3977        }
3978    }
3979}
3980impl<'r> molecule::prelude::Reader<'r> for CustomRecordDataPairReader<'r> {
3981    type Entity = CustomRecordDataPair;
3982    const NAME: &'static str = "CustomRecordDataPairReader";
3983    fn to_entity(&self) -> Self::Entity {
3984        Self::Entity::new_unchecked(self.as_slice().to_owned().into())
3985    }
3986    fn new_unchecked(slice: &'r [u8]) -> Self {
3987        CustomRecordDataPairReader(slice)
3988    }
3989    fn as_slice(&self) -> &'r [u8] {
3990        self.0
3991    }
3992    fn verify(slice: &[u8], compatible: bool) -> molecule::error::VerificationResult<()> {
3993        use molecule::verification_error as ve;
3994        let slice_len = slice.len();
3995        if slice_len < molecule::NUMBER_SIZE {
3996            return ve!(Self, HeaderIsBroken, molecule::NUMBER_SIZE, slice_len);
3997        }
3998        let total_size = molecule::unpack_number(slice) as usize;
3999        if slice_len != total_size {
4000            return ve!(Self, TotalSizeNotMatch, total_size, slice_len);
4001        }
4002        if slice_len < molecule::NUMBER_SIZE * 2 {
4003            return ve!(Self, HeaderIsBroken, molecule::NUMBER_SIZE * 2, slice_len);
4004        }
4005        let offset_first = molecule::unpack_number(&slice[molecule::NUMBER_SIZE..]) as usize;
4006        if offset_first % molecule::NUMBER_SIZE != 0 || offset_first < molecule::NUMBER_SIZE * 2 {
4007            return ve!(Self, OffsetsNotMatch);
4008        }
4009        if slice_len < offset_first {
4010            return ve!(Self, HeaderIsBroken, offset_first, slice_len);
4011        }
4012        let field_count = offset_first / molecule::NUMBER_SIZE - 1;
4013        if field_count < Self::FIELD_COUNT {
4014            return ve!(Self, FieldCountNotMatch, Self::FIELD_COUNT, field_count);
4015        } else if !compatible && field_count > Self::FIELD_COUNT {
4016            return ve!(Self, FieldCountNotMatch, Self::FIELD_COUNT, field_count);
4017        };
4018        let mut offsets: Vec<usize> = slice[molecule::NUMBER_SIZE..offset_first]
4019            .chunks_exact(molecule::NUMBER_SIZE)
4020            .map(|x| molecule::unpack_number(x) as usize)
4021            .collect();
4022        offsets.push(total_size);
4023        if offsets.windows(2).any(|i| i[0] > i[1]) {
4024            return ve!(Self, OffsetsNotMatch);
4025        }
4026        Uint32Reader::verify(&slice[offsets[0]..offsets[1]], compatible)?;
4027        BytesReader::verify(&slice[offsets[1]..offsets[2]], compatible)?;
4028        Ok(())
4029    }
4030}
4031#[derive(Clone, Debug, Default)]
4032pub struct CustomRecordDataPairBuilder {
4033    pub(crate) key: Uint32,
4034    pub(crate) value: Bytes,
4035}
4036impl CustomRecordDataPairBuilder {
4037    pub const FIELD_COUNT: usize = 2;
4038    pub fn key(mut self, v: Uint32) -> Self {
4039        self.key = v;
4040        self
4041    }
4042    pub fn value(mut self, v: Bytes) -> Self {
4043        self.value = v;
4044        self
4045    }
4046}
4047impl molecule::prelude::Builder for CustomRecordDataPairBuilder {
4048    type Entity = CustomRecordDataPair;
4049    const NAME: &'static str = "CustomRecordDataPairBuilder";
4050    fn expected_length(&self) -> usize {
4051        molecule::NUMBER_SIZE * (Self::FIELD_COUNT + 1)
4052            + self.key.as_slice().len()
4053            + self.value.as_slice().len()
4054    }
4055    fn write<W: molecule::io::Write>(&self, writer: &mut W) -> molecule::io::Result<()> {
4056        let mut total_size = molecule::NUMBER_SIZE * (Self::FIELD_COUNT + 1);
4057        let mut offsets = Vec::with_capacity(Self::FIELD_COUNT);
4058        offsets.push(total_size);
4059        total_size += self.key.as_slice().len();
4060        offsets.push(total_size);
4061        total_size += self.value.as_slice().len();
4062        writer.write_all(&molecule::pack_number(total_size as molecule::Number))?;
4063        for offset in offsets.into_iter() {
4064            writer.write_all(&molecule::pack_number(offset as molecule::Number))?;
4065        }
4066        writer.write_all(self.key.as_slice())?;
4067        writer.write_all(self.value.as_slice())?;
4068        Ok(())
4069    }
4070    fn build(&self) -> Self::Entity {
4071        let mut inner = Vec::with_capacity(self.expected_length());
4072        self.write(&mut inner)
4073            .unwrap_or_else(|_| panic!("{} build should be ok", Self::NAME));
4074        CustomRecordDataPair::new_unchecked(inner.into())
4075    }
4076}
4077#[derive(Clone)]
4078pub struct CustomRecordData(molecule::bytes::Bytes);
4079impl ::core::fmt::LowerHex for CustomRecordData {
4080    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
4081        use molecule::hex_string;
4082        if f.alternate() {
4083            write!(f, "0x")?;
4084        }
4085        write!(f, "{}", hex_string(self.as_slice()))
4086    }
4087}
4088impl ::core::fmt::Debug for CustomRecordData {
4089    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
4090        write!(f, "{}({:#x})", Self::NAME, self)
4091    }
4092}
4093impl ::core::fmt::Display for CustomRecordData {
4094    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
4095        write!(f, "{} [", Self::NAME)?;
4096        for i in 0..self.len() {
4097            if i == 0 {
4098                write!(f, "{}", self.get_unchecked(i))?;
4099            } else {
4100                write!(f, ", {}", self.get_unchecked(i))?;
4101            }
4102        }
4103        write!(f, "]")
4104    }
4105}
4106impl ::core::default::Default for CustomRecordData {
4107    fn default() -> Self {
4108        let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE);
4109        CustomRecordData::new_unchecked(v)
4110    }
4111}
4112impl CustomRecordData {
4113    const DEFAULT_VALUE: [u8; 4] = [4, 0, 0, 0];
4114    pub fn total_size(&self) -> usize {
4115        molecule::unpack_number(self.as_slice()) as usize
4116    }
4117    pub fn item_count(&self) -> usize {
4118        if self.total_size() == molecule::NUMBER_SIZE {
4119            0
4120        } else {
4121            (molecule::unpack_number(&self.as_slice()[molecule::NUMBER_SIZE..]) as usize / 4) - 1
4122        }
4123    }
4124    pub fn len(&self) -> usize {
4125        self.item_count()
4126    }
4127    pub fn is_empty(&self) -> bool {
4128        self.len() == 0
4129    }
4130    pub fn get(&self, idx: usize) -> Option<CustomRecordDataPair> {
4131        if idx >= self.len() {
4132            None
4133        } else {
4134            Some(self.get_unchecked(idx))
4135        }
4136    }
4137    pub fn get_unchecked(&self, idx: usize) -> CustomRecordDataPair {
4138        let slice = self.as_slice();
4139        let start_idx = molecule::NUMBER_SIZE * (1 + idx);
4140        let start = molecule::unpack_number(&slice[start_idx..]) as usize;
4141        if idx == self.len() - 1 {
4142            CustomRecordDataPair::new_unchecked(self.0.slice(start..))
4143        } else {
4144            let end_idx = start_idx + molecule::NUMBER_SIZE;
4145            let end = molecule::unpack_number(&slice[end_idx..]) as usize;
4146            CustomRecordDataPair::new_unchecked(self.0.slice(start..end))
4147        }
4148    }
4149    pub fn as_reader<'r>(&'r self) -> CustomRecordDataReader<'r> {
4150        CustomRecordDataReader::new_unchecked(self.as_slice())
4151    }
4152}
4153impl molecule::prelude::Entity for CustomRecordData {
4154    type Builder = CustomRecordDataBuilder;
4155    const NAME: &'static str = "CustomRecordData";
4156    fn new_unchecked(data: molecule::bytes::Bytes) -> Self {
4157        CustomRecordData(data)
4158    }
4159    fn as_bytes(&self) -> molecule::bytes::Bytes {
4160        self.0.clone()
4161    }
4162    fn as_slice(&self) -> &[u8] {
4163        &self.0[..]
4164    }
4165    fn from_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
4166        CustomRecordDataReader::from_slice(slice).map(|reader| reader.to_entity())
4167    }
4168    fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
4169        CustomRecordDataReader::from_compatible_slice(slice).map(|reader| reader.to_entity())
4170    }
4171    fn new_builder() -> Self::Builder {
4172        ::core::default::Default::default()
4173    }
4174    fn as_builder(self) -> Self::Builder {
4175        Self::new_builder().extend(self.into_iter())
4176    }
4177}
4178#[derive(Clone, Copy)]
4179pub struct CustomRecordDataReader<'r>(&'r [u8]);
4180impl<'r> ::core::fmt::LowerHex for CustomRecordDataReader<'r> {
4181    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
4182        use molecule::hex_string;
4183        if f.alternate() {
4184            write!(f, "0x")?;
4185        }
4186        write!(f, "{}", hex_string(self.as_slice()))
4187    }
4188}
4189impl<'r> ::core::fmt::Debug for CustomRecordDataReader<'r> {
4190    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
4191        write!(f, "{}({:#x})", Self::NAME, self)
4192    }
4193}
4194impl<'r> ::core::fmt::Display for CustomRecordDataReader<'r> {
4195    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
4196        write!(f, "{} [", Self::NAME)?;
4197        for i in 0..self.len() {
4198            if i == 0 {
4199                write!(f, "{}", self.get_unchecked(i))?;
4200            } else {
4201                write!(f, ", {}", self.get_unchecked(i))?;
4202            }
4203        }
4204        write!(f, "]")
4205    }
4206}
4207impl<'r> CustomRecordDataReader<'r> {
4208    pub fn total_size(&self) -> usize {
4209        molecule::unpack_number(self.as_slice()) as usize
4210    }
4211    pub fn item_count(&self) -> usize {
4212        if self.total_size() == molecule::NUMBER_SIZE {
4213            0
4214        } else {
4215            (molecule::unpack_number(&self.as_slice()[molecule::NUMBER_SIZE..]) as usize / 4) - 1
4216        }
4217    }
4218    pub fn len(&self) -> usize {
4219        self.item_count()
4220    }
4221    pub fn is_empty(&self) -> bool {
4222        self.len() == 0
4223    }
4224    pub fn get(&self, idx: usize) -> Option<CustomRecordDataPairReader<'r>> {
4225        if idx >= self.len() {
4226            None
4227        } else {
4228            Some(self.get_unchecked(idx))
4229        }
4230    }
4231    pub fn get_unchecked(&self, idx: usize) -> CustomRecordDataPairReader<'r> {
4232        let slice = self.as_slice();
4233        let start_idx = molecule::NUMBER_SIZE * (1 + idx);
4234        let start = molecule::unpack_number(&slice[start_idx..]) as usize;
4235        if idx == self.len() - 1 {
4236            CustomRecordDataPairReader::new_unchecked(&self.as_slice()[start..])
4237        } else {
4238            let end_idx = start_idx + molecule::NUMBER_SIZE;
4239            let end = molecule::unpack_number(&slice[end_idx..]) as usize;
4240            CustomRecordDataPairReader::new_unchecked(&self.as_slice()[start..end])
4241        }
4242    }
4243}
4244impl<'r> molecule::prelude::Reader<'r> for CustomRecordDataReader<'r> {
4245    type Entity = CustomRecordData;
4246    const NAME: &'static str = "CustomRecordDataReader";
4247    fn to_entity(&self) -> Self::Entity {
4248        Self::Entity::new_unchecked(self.as_slice().to_owned().into())
4249    }
4250    fn new_unchecked(slice: &'r [u8]) -> Self {
4251        CustomRecordDataReader(slice)
4252    }
4253    fn as_slice(&self) -> &'r [u8] {
4254        self.0
4255    }
4256    fn verify(slice: &[u8], compatible: bool) -> molecule::error::VerificationResult<()> {
4257        use molecule::verification_error as ve;
4258        let slice_len = slice.len();
4259        if slice_len < molecule::NUMBER_SIZE {
4260            return ve!(Self, HeaderIsBroken, molecule::NUMBER_SIZE, slice_len);
4261        }
4262        let total_size = molecule::unpack_number(slice) as usize;
4263        if slice_len != total_size {
4264            return ve!(Self, TotalSizeNotMatch, total_size, slice_len);
4265        }
4266        if slice_len == molecule::NUMBER_SIZE {
4267            return Ok(());
4268        }
4269        if slice_len < molecule::NUMBER_SIZE * 2 {
4270            return ve!(
4271                Self,
4272                TotalSizeNotMatch,
4273                molecule::NUMBER_SIZE * 2,
4274                slice_len
4275            );
4276        }
4277        let offset_first = molecule::unpack_number(&slice[molecule::NUMBER_SIZE..]) as usize;
4278        if offset_first % molecule::NUMBER_SIZE != 0 || offset_first < molecule::NUMBER_SIZE * 2 {
4279            return ve!(Self, OffsetsNotMatch);
4280        }
4281        if slice_len < offset_first {
4282            return ve!(Self, HeaderIsBroken, offset_first, slice_len);
4283        }
4284        let mut offsets: Vec<usize> = slice[molecule::NUMBER_SIZE..offset_first]
4285            .chunks_exact(molecule::NUMBER_SIZE)
4286            .map(|x| molecule::unpack_number(x) as usize)
4287            .collect();
4288        offsets.push(total_size);
4289        if offsets.windows(2).any(|i| i[0] > i[1]) {
4290            return ve!(Self, OffsetsNotMatch);
4291        }
4292        for pair in offsets.windows(2) {
4293            let start = pair[0];
4294            let end = pair[1];
4295            CustomRecordDataPairReader::verify(&slice[start..end], compatible)?;
4296        }
4297        Ok(())
4298    }
4299}
4300#[derive(Clone, Debug, Default)]
4301pub struct CustomRecordDataBuilder(pub(crate) Vec<CustomRecordDataPair>);
4302impl CustomRecordDataBuilder {
4303    pub fn set(mut self, v: Vec<CustomRecordDataPair>) -> Self {
4304        self.0 = v;
4305        self
4306    }
4307    pub fn push(mut self, v: CustomRecordDataPair) -> Self {
4308        self.0.push(v);
4309        self
4310    }
4311    pub fn extend<T: ::core::iter::IntoIterator<Item = CustomRecordDataPair>>(
4312        mut self,
4313        iter: T,
4314    ) -> Self {
4315        for elem in iter {
4316            self.0.push(elem);
4317        }
4318        self
4319    }
4320    pub fn replace(
4321        &mut self,
4322        index: usize,
4323        v: CustomRecordDataPair,
4324    ) -> Option<CustomRecordDataPair> {
4325        self.0
4326            .get_mut(index)
4327            .map(|item| ::core::mem::replace(item, v))
4328    }
4329}
4330impl molecule::prelude::Builder for CustomRecordDataBuilder {
4331    type Entity = CustomRecordData;
4332    const NAME: &'static str = "CustomRecordDataBuilder";
4333    fn expected_length(&self) -> usize {
4334        molecule::NUMBER_SIZE * (self.0.len() + 1)
4335            + self
4336                .0
4337                .iter()
4338                .map(|inner| inner.as_slice().len())
4339                .sum::<usize>()
4340    }
4341    fn write<W: molecule::io::Write>(&self, writer: &mut W) -> molecule::io::Result<()> {
4342        let item_count = self.0.len();
4343        if item_count == 0 {
4344            writer.write_all(&molecule::pack_number(
4345                molecule::NUMBER_SIZE as molecule::Number,
4346            ))?;
4347        } else {
4348            let (total_size, offsets) = self.0.iter().fold(
4349                (
4350                    molecule::NUMBER_SIZE * (item_count + 1),
4351                    Vec::with_capacity(item_count),
4352                ),
4353                |(start, mut offsets), inner| {
4354                    offsets.push(start);
4355                    (start + inner.as_slice().len(), offsets)
4356                },
4357            );
4358            writer.write_all(&molecule::pack_number(total_size as molecule::Number))?;
4359            for offset in offsets.into_iter() {
4360                writer.write_all(&molecule::pack_number(offset as molecule::Number))?;
4361            }
4362            for inner in self.0.iter() {
4363                writer.write_all(inner.as_slice())?;
4364            }
4365        }
4366        Ok(())
4367    }
4368    fn build(&self) -> Self::Entity {
4369        let mut inner = Vec::with_capacity(self.expected_length());
4370        self.write(&mut inner)
4371            .unwrap_or_else(|_| panic!("{} build should be ok", Self::NAME));
4372        CustomRecordData::new_unchecked(inner.into())
4373    }
4374}
4375pub struct CustomRecordDataIterator(CustomRecordData, usize, usize);
4376impl ::core::iter::Iterator for CustomRecordDataIterator {
4377    type Item = CustomRecordDataPair;
4378    fn next(&mut self) -> Option<Self::Item> {
4379        if self.1 >= self.2 {
4380            None
4381        } else {
4382            let ret = self.0.get_unchecked(self.1);
4383            self.1 += 1;
4384            Some(ret)
4385        }
4386    }
4387}
4388impl ::core::iter::ExactSizeIterator for CustomRecordDataIterator {
4389    fn len(&self) -> usize {
4390        self.2 - self.1
4391    }
4392}
4393impl ::core::iter::IntoIterator for CustomRecordData {
4394    type Item = CustomRecordDataPair;
4395    type IntoIter = CustomRecordDataIterator;
4396    fn into_iter(self) -> Self::IntoIter {
4397        let len = self.len();
4398        CustomRecordDataIterator(self, 0, len)
4399    }
4400}
4401impl<'r> CustomRecordDataReader<'r> {
4402    pub fn iter<'t>(&'t self) -> CustomRecordDataReaderIterator<'t, 'r> {
4403        CustomRecordDataReaderIterator(&self, 0, self.len())
4404    }
4405}
4406pub struct CustomRecordDataReaderIterator<'t, 'r>(&'t CustomRecordDataReader<'r>, usize, usize);
4407impl<'t: 'r, 'r> ::core::iter::Iterator for CustomRecordDataReaderIterator<'t, 'r> {
4408    type Item = CustomRecordDataPairReader<'t>;
4409    fn next(&mut self) -> Option<Self::Item> {
4410        if self.1 >= self.2 {
4411            None
4412        } else {
4413            let ret = self.0.get_unchecked(self.1);
4414            self.1 += 1;
4415            Some(ret)
4416        }
4417    }
4418}
4419impl<'t: 'r, 'r> ::core::iter::ExactSizeIterator for CustomRecordDataReaderIterator<'t, 'r> {
4420    fn len(&self) -> usize {
4421        self.2 - self.1
4422    }
4423}
4424impl ::core::iter::FromIterator<CustomRecordDataPair> for CustomRecordData {
4425    fn from_iter<T: IntoIterator<Item = CustomRecordDataPair>>(iter: T) -> Self {
4426        Self::new_builder().extend(iter).build()
4427    }
4428}
4429#[derive(Clone)]
4430pub struct CustomRecords(molecule::bytes::Bytes);
4431impl ::core::fmt::LowerHex for CustomRecords {
4432    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
4433        use molecule::hex_string;
4434        if f.alternate() {
4435            write!(f, "0x")?;
4436        }
4437        write!(f, "{}", hex_string(self.as_slice()))
4438    }
4439}
4440impl ::core::fmt::Debug for CustomRecords {
4441    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
4442        write!(f, "{}({:#x})", Self::NAME, self)
4443    }
4444}
4445impl ::core::fmt::Display for CustomRecords {
4446    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
4447        write!(f, "{} {{ ", Self::NAME)?;
4448        write!(f, "{}: {}", "data", self.data())?;
4449        let extra_count = self.count_extra_fields();
4450        if extra_count != 0 {
4451            write!(f, ", .. ({} fields)", extra_count)?;
4452        }
4453        write!(f, " }}")
4454    }
4455}
4456impl ::core::default::Default for CustomRecords {
4457    fn default() -> Self {
4458        let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE);
4459        CustomRecords::new_unchecked(v)
4460    }
4461}
4462impl CustomRecords {
4463    const DEFAULT_VALUE: [u8; 12] = [12, 0, 0, 0, 8, 0, 0, 0, 4, 0, 0, 0];
4464    pub const FIELD_COUNT: usize = 1;
4465    pub fn total_size(&self) -> usize {
4466        molecule::unpack_number(self.as_slice()) as usize
4467    }
4468    pub fn field_count(&self) -> usize {
4469        if self.total_size() == molecule::NUMBER_SIZE {
4470            0
4471        } else {
4472            (molecule::unpack_number(&self.as_slice()[molecule::NUMBER_SIZE..]) as usize / 4) - 1
4473        }
4474    }
4475    pub fn count_extra_fields(&self) -> usize {
4476        self.field_count() - Self::FIELD_COUNT
4477    }
4478    pub fn has_extra_fields(&self) -> bool {
4479        Self::FIELD_COUNT != self.field_count()
4480    }
4481    pub fn data(&self) -> CustomRecordData {
4482        let slice = self.as_slice();
4483        let start = molecule::unpack_number(&slice[4..]) as usize;
4484        if self.has_extra_fields() {
4485            let end = molecule::unpack_number(&slice[8..]) as usize;
4486            CustomRecordData::new_unchecked(self.0.slice(start..end))
4487        } else {
4488            CustomRecordData::new_unchecked(self.0.slice(start..))
4489        }
4490    }
4491    pub fn as_reader<'r>(&'r self) -> CustomRecordsReader<'r> {
4492        CustomRecordsReader::new_unchecked(self.as_slice())
4493    }
4494}
4495impl molecule::prelude::Entity for CustomRecords {
4496    type Builder = CustomRecordsBuilder;
4497    const NAME: &'static str = "CustomRecords";
4498    fn new_unchecked(data: molecule::bytes::Bytes) -> Self {
4499        CustomRecords(data)
4500    }
4501    fn as_bytes(&self) -> molecule::bytes::Bytes {
4502        self.0.clone()
4503    }
4504    fn as_slice(&self) -> &[u8] {
4505        &self.0[..]
4506    }
4507    fn from_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
4508        CustomRecordsReader::from_slice(slice).map(|reader| reader.to_entity())
4509    }
4510    fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
4511        CustomRecordsReader::from_compatible_slice(slice).map(|reader| reader.to_entity())
4512    }
4513    fn new_builder() -> Self::Builder {
4514        ::core::default::Default::default()
4515    }
4516    fn as_builder(self) -> Self::Builder {
4517        Self::new_builder().data(self.data())
4518    }
4519}
4520#[derive(Clone, Copy)]
4521pub struct CustomRecordsReader<'r>(&'r [u8]);
4522impl<'r> ::core::fmt::LowerHex for CustomRecordsReader<'r> {
4523    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
4524        use molecule::hex_string;
4525        if f.alternate() {
4526            write!(f, "0x")?;
4527        }
4528        write!(f, "{}", hex_string(self.as_slice()))
4529    }
4530}
4531impl<'r> ::core::fmt::Debug for CustomRecordsReader<'r> {
4532    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
4533        write!(f, "{}({:#x})", Self::NAME, self)
4534    }
4535}
4536impl<'r> ::core::fmt::Display for CustomRecordsReader<'r> {
4537    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
4538        write!(f, "{} {{ ", Self::NAME)?;
4539        write!(f, "{}: {}", "data", self.data())?;
4540        let extra_count = self.count_extra_fields();
4541        if extra_count != 0 {
4542            write!(f, ", .. ({} fields)", extra_count)?;
4543        }
4544        write!(f, " }}")
4545    }
4546}
4547impl<'r> CustomRecordsReader<'r> {
4548    pub const FIELD_COUNT: usize = 1;
4549    pub fn total_size(&self) -> usize {
4550        molecule::unpack_number(self.as_slice()) as usize
4551    }
4552    pub fn field_count(&self) -> usize {
4553        if self.total_size() == molecule::NUMBER_SIZE {
4554            0
4555        } else {
4556            (molecule::unpack_number(&self.as_slice()[molecule::NUMBER_SIZE..]) as usize / 4) - 1
4557        }
4558    }
4559    pub fn count_extra_fields(&self) -> usize {
4560        self.field_count() - Self::FIELD_COUNT
4561    }
4562    pub fn has_extra_fields(&self) -> bool {
4563        Self::FIELD_COUNT != self.field_count()
4564    }
4565    pub fn data(&self) -> CustomRecordDataReader<'r> {
4566        let slice = self.as_slice();
4567        let start = molecule::unpack_number(&slice[4..]) as usize;
4568        if self.has_extra_fields() {
4569            let end = molecule::unpack_number(&slice[8..]) as usize;
4570            CustomRecordDataReader::new_unchecked(&self.as_slice()[start..end])
4571        } else {
4572            CustomRecordDataReader::new_unchecked(&self.as_slice()[start..])
4573        }
4574    }
4575}
4576impl<'r> molecule::prelude::Reader<'r> for CustomRecordsReader<'r> {
4577    type Entity = CustomRecords;
4578    const NAME: &'static str = "CustomRecordsReader";
4579    fn to_entity(&self) -> Self::Entity {
4580        Self::Entity::new_unchecked(self.as_slice().to_owned().into())
4581    }
4582    fn new_unchecked(slice: &'r [u8]) -> Self {
4583        CustomRecordsReader(slice)
4584    }
4585    fn as_slice(&self) -> &'r [u8] {
4586        self.0
4587    }
4588    fn verify(slice: &[u8], compatible: bool) -> molecule::error::VerificationResult<()> {
4589        use molecule::verification_error as ve;
4590        let slice_len = slice.len();
4591        if slice_len < molecule::NUMBER_SIZE {
4592            return ve!(Self, HeaderIsBroken, molecule::NUMBER_SIZE, slice_len);
4593        }
4594        let total_size = molecule::unpack_number(slice) as usize;
4595        if slice_len != total_size {
4596            return ve!(Self, TotalSizeNotMatch, total_size, slice_len);
4597        }
4598        if slice_len < molecule::NUMBER_SIZE * 2 {
4599            return ve!(Self, HeaderIsBroken, molecule::NUMBER_SIZE * 2, slice_len);
4600        }
4601        let offset_first = molecule::unpack_number(&slice[molecule::NUMBER_SIZE..]) as usize;
4602        if offset_first % molecule::NUMBER_SIZE != 0 || offset_first < molecule::NUMBER_SIZE * 2 {
4603            return ve!(Self, OffsetsNotMatch);
4604        }
4605        if slice_len < offset_first {
4606            return ve!(Self, HeaderIsBroken, offset_first, slice_len);
4607        }
4608        let field_count = offset_first / molecule::NUMBER_SIZE - 1;
4609        if field_count < Self::FIELD_COUNT {
4610            return ve!(Self, FieldCountNotMatch, Self::FIELD_COUNT, field_count);
4611        } else if !compatible && field_count > Self::FIELD_COUNT {
4612            return ve!(Self, FieldCountNotMatch, Self::FIELD_COUNT, field_count);
4613        };
4614        let mut offsets: Vec<usize> = slice[molecule::NUMBER_SIZE..offset_first]
4615            .chunks_exact(molecule::NUMBER_SIZE)
4616            .map(|x| molecule::unpack_number(x) as usize)
4617            .collect();
4618        offsets.push(total_size);
4619        if offsets.windows(2).any(|i| i[0] > i[1]) {
4620            return ve!(Self, OffsetsNotMatch);
4621        }
4622        CustomRecordDataReader::verify(&slice[offsets[0]..offsets[1]], compatible)?;
4623        Ok(())
4624    }
4625}
4626#[derive(Clone, Debug, Default)]
4627pub struct CustomRecordsBuilder {
4628    pub(crate) data: CustomRecordData,
4629}
4630impl CustomRecordsBuilder {
4631    pub const FIELD_COUNT: usize = 1;
4632    pub fn data(mut self, v: CustomRecordData) -> Self {
4633        self.data = v;
4634        self
4635    }
4636}
4637impl molecule::prelude::Builder for CustomRecordsBuilder {
4638    type Entity = CustomRecords;
4639    const NAME: &'static str = "CustomRecordsBuilder";
4640    fn expected_length(&self) -> usize {
4641        molecule::NUMBER_SIZE * (Self::FIELD_COUNT + 1) + self.data.as_slice().len()
4642    }
4643    fn write<W: molecule::io::Write>(&self, writer: &mut W) -> molecule::io::Result<()> {
4644        let mut total_size = molecule::NUMBER_SIZE * (Self::FIELD_COUNT + 1);
4645        let mut offsets = Vec::with_capacity(Self::FIELD_COUNT);
4646        offsets.push(total_size);
4647        total_size += self.data.as_slice().len();
4648        writer.write_all(&molecule::pack_number(total_size as molecule::Number))?;
4649        for offset in offsets.into_iter() {
4650            writer.write_all(&molecule::pack_number(offset as molecule::Number))?;
4651        }
4652        writer.write_all(self.data.as_slice())?;
4653        Ok(())
4654    }
4655    fn build(&self) -> Self::Entity {
4656        let mut inner = Vec::with_capacity(self.expected_length());
4657        self.write(&mut inner)
4658            .unwrap_or_else(|_| panic!("{} build should be ok", Self::NAME));
4659        CustomRecords::new_unchecked(inner.into())
4660    }
4661}
4662#[derive(Clone)]
4663pub struct Init(molecule::bytes::Bytes);
4664impl ::core::fmt::LowerHex for Init {
4665    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
4666        use molecule::hex_string;
4667        if f.alternate() {
4668            write!(f, "0x")?;
4669        }
4670        write!(f, "{}", hex_string(self.as_slice()))
4671    }
4672}
4673impl ::core::fmt::Debug for Init {
4674    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
4675        write!(f, "{}({:#x})", Self::NAME, self)
4676    }
4677}
4678impl ::core::fmt::Display for Init {
4679    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
4680        write!(f, "{} {{ ", Self::NAME)?;
4681        write!(f, "{}: {}", "features", self.features())?;
4682        write!(f, ", {}: {}", "chain_hash", self.chain_hash())?;
4683        let extra_count = self.count_extra_fields();
4684        if extra_count != 0 {
4685            write!(f, ", .. ({} fields)", extra_count)?;
4686        }
4687        write!(f, " }}")
4688    }
4689}
4690impl ::core::default::Default for Init {
4691    fn default() -> Self {
4692        let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE);
4693        Init::new_unchecked(v)
4694    }
4695}
4696impl Init {
4697    const DEFAULT_VALUE: [u8; 48] = [
4698        48, 0, 0, 0, 12, 0, 0, 0, 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
4699        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
4700    ];
4701    pub const FIELD_COUNT: usize = 2;
4702    pub fn total_size(&self) -> usize {
4703        molecule::unpack_number(self.as_slice()) as usize
4704    }
4705    pub fn field_count(&self) -> usize {
4706        if self.total_size() == molecule::NUMBER_SIZE {
4707            0
4708        } else {
4709            (molecule::unpack_number(&self.as_slice()[molecule::NUMBER_SIZE..]) as usize / 4) - 1
4710        }
4711    }
4712    pub fn count_extra_fields(&self) -> usize {
4713        self.field_count() - Self::FIELD_COUNT
4714    }
4715    pub fn has_extra_fields(&self) -> bool {
4716        Self::FIELD_COUNT != self.field_count()
4717    }
4718    pub fn features(&self) -> Bytes {
4719        let slice = self.as_slice();
4720        let start = molecule::unpack_number(&slice[4..]) as usize;
4721        let end = molecule::unpack_number(&slice[8..]) as usize;
4722        Bytes::new_unchecked(self.0.slice(start..end))
4723    }
4724    pub fn chain_hash(&self) -> Byte32 {
4725        let slice = self.as_slice();
4726        let start = molecule::unpack_number(&slice[8..]) as usize;
4727        if self.has_extra_fields() {
4728            let end = molecule::unpack_number(&slice[12..]) as usize;
4729            Byte32::new_unchecked(self.0.slice(start..end))
4730        } else {
4731            Byte32::new_unchecked(self.0.slice(start..))
4732        }
4733    }
4734    pub fn as_reader<'r>(&'r self) -> InitReader<'r> {
4735        InitReader::new_unchecked(self.as_slice())
4736    }
4737}
4738impl molecule::prelude::Entity for Init {
4739    type Builder = InitBuilder;
4740    const NAME: &'static str = "Init";
4741    fn new_unchecked(data: molecule::bytes::Bytes) -> Self {
4742        Init(data)
4743    }
4744    fn as_bytes(&self) -> molecule::bytes::Bytes {
4745        self.0.clone()
4746    }
4747    fn as_slice(&self) -> &[u8] {
4748        &self.0[..]
4749    }
4750    fn from_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
4751        InitReader::from_slice(slice).map(|reader| reader.to_entity())
4752    }
4753    fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
4754        InitReader::from_compatible_slice(slice).map(|reader| reader.to_entity())
4755    }
4756    fn new_builder() -> Self::Builder {
4757        ::core::default::Default::default()
4758    }
4759    fn as_builder(self) -> Self::Builder {
4760        Self::new_builder()
4761            .features(self.features())
4762            .chain_hash(self.chain_hash())
4763    }
4764}
4765#[derive(Clone, Copy)]
4766pub struct InitReader<'r>(&'r [u8]);
4767impl<'r> ::core::fmt::LowerHex for InitReader<'r> {
4768    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
4769        use molecule::hex_string;
4770        if f.alternate() {
4771            write!(f, "0x")?;
4772        }
4773        write!(f, "{}", hex_string(self.as_slice()))
4774    }
4775}
4776impl<'r> ::core::fmt::Debug for InitReader<'r> {
4777    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
4778        write!(f, "{}({:#x})", Self::NAME, self)
4779    }
4780}
4781impl<'r> ::core::fmt::Display for InitReader<'r> {
4782    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
4783        write!(f, "{} {{ ", Self::NAME)?;
4784        write!(f, "{}: {}", "features", self.features())?;
4785        write!(f, ", {}: {}", "chain_hash", self.chain_hash())?;
4786        let extra_count = self.count_extra_fields();
4787        if extra_count != 0 {
4788            write!(f, ", .. ({} fields)", extra_count)?;
4789        }
4790        write!(f, " }}")
4791    }
4792}
4793impl<'r> InitReader<'r> {
4794    pub const FIELD_COUNT: usize = 2;
4795    pub fn total_size(&self) -> usize {
4796        molecule::unpack_number(self.as_slice()) as usize
4797    }
4798    pub fn field_count(&self) -> usize {
4799        if self.total_size() == molecule::NUMBER_SIZE {
4800            0
4801        } else {
4802            (molecule::unpack_number(&self.as_slice()[molecule::NUMBER_SIZE..]) as usize / 4) - 1
4803        }
4804    }
4805    pub fn count_extra_fields(&self) -> usize {
4806        self.field_count() - Self::FIELD_COUNT
4807    }
4808    pub fn has_extra_fields(&self) -> bool {
4809        Self::FIELD_COUNT != self.field_count()
4810    }
4811    pub fn features(&self) -> BytesReader<'r> {
4812        let slice = self.as_slice();
4813        let start = molecule::unpack_number(&slice[4..]) as usize;
4814        let end = molecule::unpack_number(&slice[8..]) as usize;
4815        BytesReader::new_unchecked(&self.as_slice()[start..end])
4816    }
4817    pub fn chain_hash(&self) -> Byte32Reader<'r> {
4818        let slice = self.as_slice();
4819        let start = molecule::unpack_number(&slice[8..]) as usize;
4820        if self.has_extra_fields() {
4821            let end = molecule::unpack_number(&slice[12..]) as usize;
4822            Byte32Reader::new_unchecked(&self.as_slice()[start..end])
4823        } else {
4824            Byte32Reader::new_unchecked(&self.as_slice()[start..])
4825        }
4826    }
4827}
4828impl<'r> molecule::prelude::Reader<'r> for InitReader<'r> {
4829    type Entity = Init;
4830    const NAME: &'static str = "InitReader";
4831    fn to_entity(&self) -> Self::Entity {
4832        Self::Entity::new_unchecked(self.as_slice().to_owned().into())
4833    }
4834    fn new_unchecked(slice: &'r [u8]) -> Self {
4835        InitReader(slice)
4836    }
4837    fn as_slice(&self) -> &'r [u8] {
4838        self.0
4839    }
4840    fn verify(slice: &[u8], compatible: bool) -> molecule::error::VerificationResult<()> {
4841        use molecule::verification_error as ve;
4842        let slice_len = slice.len();
4843        if slice_len < molecule::NUMBER_SIZE {
4844            return ve!(Self, HeaderIsBroken, molecule::NUMBER_SIZE, slice_len);
4845        }
4846        let total_size = molecule::unpack_number(slice) as usize;
4847        if slice_len != total_size {
4848            return ve!(Self, TotalSizeNotMatch, total_size, slice_len);
4849        }
4850        if slice_len < molecule::NUMBER_SIZE * 2 {
4851            return ve!(Self, HeaderIsBroken, molecule::NUMBER_SIZE * 2, slice_len);
4852        }
4853        let offset_first = molecule::unpack_number(&slice[molecule::NUMBER_SIZE..]) as usize;
4854        if offset_first % molecule::NUMBER_SIZE != 0 || offset_first < molecule::NUMBER_SIZE * 2 {
4855            return ve!(Self, OffsetsNotMatch);
4856        }
4857        if slice_len < offset_first {
4858            return ve!(Self, HeaderIsBroken, offset_first, slice_len);
4859        }
4860        let field_count = offset_first / molecule::NUMBER_SIZE - 1;
4861        if field_count < Self::FIELD_COUNT {
4862            return ve!(Self, FieldCountNotMatch, Self::FIELD_COUNT, field_count);
4863        } else if !compatible && field_count > Self::FIELD_COUNT {
4864            return ve!(Self, FieldCountNotMatch, Self::FIELD_COUNT, field_count);
4865        };
4866        let mut offsets: Vec<usize> = slice[molecule::NUMBER_SIZE..offset_first]
4867            .chunks_exact(molecule::NUMBER_SIZE)
4868            .map(|x| molecule::unpack_number(x) as usize)
4869            .collect();
4870        offsets.push(total_size);
4871        if offsets.windows(2).any(|i| i[0] > i[1]) {
4872            return ve!(Self, OffsetsNotMatch);
4873        }
4874        BytesReader::verify(&slice[offsets[0]..offsets[1]], compatible)?;
4875        Byte32Reader::verify(&slice[offsets[1]..offsets[2]], compatible)?;
4876        Ok(())
4877    }
4878}
4879#[derive(Clone, Debug, Default)]
4880pub struct InitBuilder {
4881    pub(crate) features: Bytes,
4882    pub(crate) chain_hash: Byte32,
4883}
4884impl InitBuilder {
4885    pub const FIELD_COUNT: usize = 2;
4886    pub fn features(mut self, v: Bytes) -> Self {
4887        self.features = v;
4888        self
4889    }
4890    pub fn chain_hash(mut self, v: Byte32) -> Self {
4891        self.chain_hash = v;
4892        self
4893    }
4894}
4895impl molecule::prelude::Builder for InitBuilder {
4896    type Entity = Init;
4897    const NAME: &'static str = "InitBuilder";
4898    fn expected_length(&self) -> usize {
4899        molecule::NUMBER_SIZE * (Self::FIELD_COUNT + 1)
4900            + self.features.as_slice().len()
4901            + self.chain_hash.as_slice().len()
4902    }
4903    fn write<W: molecule::io::Write>(&self, writer: &mut W) -> molecule::io::Result<()> {
4904        let mut total_size = molecule::NUMBER_SIZE * (Self::FIELD_COUNT + 1);
4905        let mut offsets = Vec::with_capacity(Self::FIELD_COUNT);
4906        offsets.push(total_size);
4907        total_size += self.features.as_slice().len();
4908        offsets.push(total_size);
4909        total_size += self.chain_hash.as_slice().len();
4910        writer.write_all(&molecule::pack_number(total_size as molecule::Number))?;
4911        for offset in offsets.into_iter() {
4912            writer.write_all(&molecule::pack_number(offset as molecule::Number))?;
4913        }
4914        writer.write_all(self.features.as_slice())?;
4915        writer.write_all(self.chain_hash.as_slice())?;
4916        Ok(())
4917    }
4918    fn build(&self) -> Self::Entity {
4919        let mut inner = Vec::with_capacity(self.expected_length());
4920        self.write(&mut inner)
4921            .unwrap_or_else(|_| panic!("{} build should be ok", Self::NAME));
4922        Init::new_unchecked(inner.into())
4923    }
4924}
4925#[derive(Clone)]
4926pub struct OpenChannel(molecule::bytes::Bytes);
4927impl ::core::fmt::LowerHex for OpenChannel {
4928    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
4929        use molecule::hex_string;
4930        if f.alternate() {
4931            write!(f, "0x")?;
4932        }
4933        write!(f, "{}", hex_string(self.as_slice()))
4934    }
4935}
4936impl ::core::fmt::Debug for OpenChannel {
4937    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
4938        write!(f, "{}({:#x})", Self::NAME, self)
4939    }
4940}
4941impl ::core::fmt::Display for OpenChannel {
4942    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
4943        write!(f, "{} {{ ", Self::NAME)?;
4944        write!(f, "{}: {}", "chain_hash", self.chain_hash())?;
4945        write!(f, ", {}: {}", "channel_id", self.channel_id())?;
4946        write!(
4947            f,
4948            ", {}: {}",
4949            "funding_udt_type_script",
4950            self.funding_udt_type_script()
4951        )?;
4952        write!(f, ", {}: {}", "funding_amount", self.funding_amount())?;
4953        write!(f, ", {}: {}", "shutdown_script", self.shutdown_script())?;
4954        write!(
4955            f,
4956            ", {}: {}",
4957            "reserved_ckb_amount",
4958            self.reserved_ckb_amount()
4959        )?;
4960        write!(f, ", {}: {}", "funding_fee_rate", self.funding_fee_rate())?;
4961        write!(
4962            f,
4963            ", {}: {}",
4964            "commitment_fee_rate",
4965            self.commitment_fee_rate()
4966        )?;
4967        write!(
4968            f,
4969            ", {}: {}",
4970            "max_tlc_value_in_flight",
4971            self.max_tlc_value_in_flight()
4972        )?;
4973        write!(
4974            f,
4975            ", {}: {}",
4976            "max_tlc_number_in_flight",
4977            self.max_tlc_number_in_flight()
4978        )?;
4979        write!(
4980            f,
4981            ", {}: {}",
4982            "commitment_delay_epoch",
4983            self.commitment_delay_epoch()
4984        )?;
4985        write!(f, ", {}: {}", "funding_pubkey", self.funding_pubkey())?;
4986        write!(f, ", {}: {}", "tlc_basepoint", self.tlc_basepoint())?;
4987        write!(
4988            f,
4989            ", {}: {}",
4990            "first_per_commitment_point",
4991            self.first_per_commitment_point()
4992        )?;
4993        write!(
4994            f,
4995            ", {}: {}",
4996            "second_per_commitment_point",
4997            self.second_per_commitment_point()
4998        )?;
4999        write!(
5000            f,
5001            ", {}: {}",
5002            "channel_announcement_nonce",
5003            self.channel_announcement_nonce()
5004        )?;
5005        write!(
5006            f,
5007            ", {}: {}",
5008            "next_commitment_nonce",
5009            self.next_commitment_nonce()
5010        )?;
5011        write!(
5012            f,
5013            ", {}: {}",
5014            "next_revocation_nonce",
5015            self.next_revocation_nonce()
5016        )?;
5017        write!(f, ", {}: {}", "channel_flags", self.channel_flags())?;
5018        let extra_count = self.count_extra_fields();
5019        if extra_count != 0 {
5020            write!(f, ", .. ({} fields)", extra_count)?;
5021        }
5022        write!(f, " }}")
5023    }
5024}
5025impl ::core::default::Default for OpenChannel {
5026    fn default() -> Self {
5027        let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE);
5028        OpenChannel::new_unchecked(v)
5029    }
5030}
5031impl OpenChannel {
5032    const DEFAULT_VALUE: [u8; 534] = [
5033        22, 2, 0, 0, 80, 0, 0, 0, 112, 0, 0, 0, 144, 0, 0, 0, 144, 0, 0, 0, 160, 0, 0, 0, 213, 0,
5034        0, 0, 221, 0, 0, 0, 229, 0, 0, 0, 237, 0, 0, 0, 253, 0, 0, 0, 5, 1, 0, 0, 13, 1, 0, 0, 46,
5035        1, 0, 0, 79, 1, 0, 0, 112, 1, 0, 0, 145, 1, 0, 0, 145, 1, 0, 0, 211, 1, 0, 0, 21, 2, 0, 0,
5036        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,
5037        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,
5038        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 53, 0, 0, 0, 16, 0, 0, 0, 48,
5039        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,
5040        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,
5041        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,
5042        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,
5043        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,
5044        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,
5045        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,
5046        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,
5047        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,
5048        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,
5049        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,
5050        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,
5051        0, 0, 0, 0, 0,
5052    ];
5053    pub const FIELD_COUNT: usize = 19;
5054    pub fn total_size(&self) -> usize {
5055        molecule::unpack_number(self.as_slice()) as usize
5056    }
5057    pub fn field_count(&self) -> usize {
5058        if self.total_size() == molecule::NUMBER_SIZE {
5059            0
5060        } else {
5061            (molecule::unpack_number(&self.as_slice()[molecule::NUMBER_SIZE..]) as usize / 4) - 1
5062        }
5063    }
5064    pub fn count_extra_fields(&self) -> usize {
5065        self.field_count() - Self::FIELD_COUNT
5066    }
5067    pub fn has_extra_fields(&self) -> bool {
5068        Self::FIELD_COUNT != self.field_count()
5069    }
5070    pub fn chain_hash(&self) -> Byte32 {
5071        let slice = self.as_slice();
5072        let start = molecule::unpack_number(&slice[4..]) as usize;
5073        let end = molecule::unpack_number(&slice[8..]) as usize;
5074        Byte32::new_unchecked(self.0.slice(start..end))
5075    }
5076    pub fn channel_id(&self) -> Byte32 {
5077        let slice = self.as_slice();
5078        let start = molecule::unpack_number(&slice[8..]) as usize;
5079        let end = molecule::unpack_number(&slice[12..]) as usize;
5080        Byte32::new_unchecked(self.0.slice(start..end))
5081    }
5082    pub fn funding_udt_type_script(&self) -> ScriptOpt {
5083        let slice = self.as_slice();
5084        let start = molecule::unpack_number(&slice[12..]) as usize;
5085        let end = molecule::unpack_number(&slice[16..]) as usize;
5086        ScriptOpt::new_unchecked(self.0.slice(start..end))
5087    }
5088    pub fn funding_amount(&self) -> Uint128 {
5089        let slice = self.as_slice();
5090        let start = molecule::unpack_number(&slice[16..]) as usize;
5091        let end = molecule::unpack_number(&slice[20..]) as usize;
5092        Uint128::new_unchecked(self.0.slice(start..end))
5093    }
5094    pub fn shutdown_script(&self) -> Script {
5095        let slice = self.as_slice();
5096        let start = molecule::unpack_number(&slice[20..]) as usize;
5097        let end = molecule::unpack_number(&slice[24..]) as usize;
5098        Script::new_unchecked(self.0.slice(start..end))
5099    }
5100    pub fn reserved_ckb_amount(&self) -> Uint64 {
5101        let slice = self.as_slice();
5102        let start = molecule::unpack_number(&slice[24..]) as usize;
5103        let end = molecule::unpack_number(&slice[28..]) as usize;
5104        Uint64::new_unchecked(self.0.slice(start..end))
5105    }
5106    pub fn funding_fee_rate(&self) -> Uint64 {
5107        let slice = self.as_slice();
5108        let start = molecule::unpack_number(&slice[28..]) as usize;
5109        let end = molecule::unpack_number(&slice[32..]) as usize;
5110        Uint64::new_unchecked(self.0.slice(start..end))
5111    }
5112    pub fn commitment_fee_rate(&self) -> Uint64 {
5113        let slice = self.as_slice();
5114        let start = molecule::unpack_number(&slice[32..]) as usize;
5115        let end = molecule::unpack_number(&slice[36..]) as usize;
5116        Uint64::new_unchecked(self.0.slice(start..end))
5117    }
5118    pub fn max_tlc_value_in_flight(&self) -> Uint128 {
5119        let slice = self.as_slice();
5120        let start = molecule::unpack_number(&slice[36..]) as usize;
5121        let end = molecule::unpack_number(&slice[40..]) as usize;
5122        Uint128::new_unchecked(self.0.slice(start..end))
5123    }
5124    pub fn max_tlc_number_in_flight(&self) -> Uint64 {
5125        let slice = self.as_slice();
5126        let start = molecule::unpack_number(&slice[40..]) as usize;
5127        let end = molecule::unpack_number(&slice[44..]) as usize;
5128        Uint64::new_unchecked(self.0.slice(start..end))
5129    }
5130    pub fn commitment_delay_epoch(&self) -> Uint64 {
5131        let slice = self.as_slice();
5132        let start = molecule::unpack_number(&slice[44..]) as usize;
5133        let end = molecule::unpack_number(&slice[48..]) as usize;
5134        Uint64::new_unchecked(self.0.slice(start..end))
5135    }
5136    pub fn funding_pubkey(&self) -> Pubkey {
5137        let slice = self.as_slice();
5138        let start = molecule::unpack_number(&slice[48..]) as usize;
5139        let end = molecule::unpack_number(&slice[52..]) as usize;
5140        Pubkey::new_unchecked(self.0.slice(start..end))
5141    }
5142    pub fn tlc_basepoint(&self) -> Pubkey {
5143        let slice = self.as_slice();
5144        let start = molecule::unpack_number(&slice[52..]) as usize;
5145        let end = molecule::unpack_number(&slice[56..]) as usize;
5146        Pubkey::new_unchecked(self.0.slice(start..end))
5147    }
5148    pub fn first_per_commitment_point(&self) -> Pubkey {
5149        let slice = self.as_slice();
5150        let start = molecule::unpack_number(&slice[56..]) as usize;
5151        let end = molecule::unpack_number(&slice[60..]) as usize;
5152        Pubkey::new_unchecked(self.0.slice(start..end))
5153    }
5154    pub fn second_per_commitment_point(&self) -> Pubkey {
5155        let slice = self.as_slice();
5156        let start = molecule::unpack_number(&slice[60..]) as usize;
5157        let end = molecule::unpack_number(&slice[64..]) as usize;
5158        Pubkey::new_unchecked(self.0.slice(start..end))
5159    }
5160    pub fn channel_announcement_nonce(&self) -> PubNonceOpt {
5161        let slice = self.as_slice();
5162        let start = molecule::unpack_number(&slice[64..]) as usize;
5163        let end = molecule::unpack_number(&slice[68..]) as usize;
5164        PubNonceOpt::new_unchecked(self.0.slice(start..end))
5165    }
5166    pub fn next_commitment_nonce(&self) -> PubNonce {
5167        let slice = self.as_slice();
5168        let start = molecule::unpack_number(&slice[68..]) as usize;
5169        let end = molecule::unpack_number(&slice[72..]) as usize;
5170        PubNonce::new_unchecked(self.0.slice(start..end))
5171    }
5172    pub fn next_revocation_nonce(&self) -> PubNonce {
5173        let slice = self.as_slice();
5174        let start = molecule::unpack_number(&slice[72..]) as usize;
5175        let end = molecule::unpack_number(&slice[76..]) as usize;
5176        PubNonce::new_unchecked(self.0.slice(start..end))
5177    }
5178    pub fn channel_flags(&self) -> Byte {
5179        let slice = self.as_slice();
5180        let start = molecule::unpack_number(&slice[76..]) as usize;
5181        if self.has_extra_fields() {
5182            let end = molecule::unpack_number(&slice[80..]) as usize;
5183            Byte::new_unchecked(self.0.slice(start..end))
5184        } else {
5185            Byte::new_unchecked(self.0.slice(start..))
5186        }
5187    }
5188    pub fn as_reader<'r>(&'r self) -> OpenChannelReader<'r> {
5189        OpenChannelReader::new_unchecked(self.as_slice())
5190    }
5191}
5192impl molecule::prelude::Entity for OpenChannel {
5193    type Builder = OpenChannelBuilder;
5194    const NAME: &'static str = "OpenChannel";
5195    fn new_unchecked(data: molecule::bytes::Bytes) -> Self {
5196        OpenChannel(data)
5197    }
5198    fn as_bytes(&self) -> molecule::bytes::Bytes {
5199        self.0.clone()
5200    }
5201    fn as_slice(&self) -> &[u8] {
5202        &self.0[..]
5203    }
5204    fn from_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
5205        OpenChannelReader::from_slice(slice).map(|reader| reader.to_entity())
5206    }
5207    fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
5208        OpenChannelReader::from_compatible_slice(slice).map(|reader| reader.to_entity())
5209    }
5210    fn new_builder() -> Self::Builder {
5211        ::core::default::Default::default()
5212    }
5213    fn as_builder(self) -> Self::Builder {
5214        Self::new_builder()
5215            .chain_hash(self.chain_hash())
5216            .channel_id(self.channel_id())
5217            .funding_udt_type_script(self.funding_udt_type_script())
5218            .funding_amount(self.funding_amount())
5219            .shutdown_script(self.shutdown_script())
5220            .reserved_ckb_amount(self.reserved_ckb_amount())
5221            .funding_fee_rate(self.funding_fee_rate())
5222            .commitment_fee_rate(self.commitment_fee_rate())
5223            .max_tlc_value_in_flight(self.max_tlc_value_in_flight())
5224            .max_tlc_number_in_flight(self.max_tlc_number_in_flight())
5225            .commitment_delay_epoch(self.commitment_delay_epoch())
5226            .funding_pubkey(self.funding_pubkey())
5227            .tlc_basepoint(self.tlc_basepoint())
5228            .first_per_commitment_point(self.first_per_commitment_point())
5229            .second_per_commitment_point(self.second_per_commitment_point())
5230            .channel_announcement_nonce(self.channel_announcement_nonce())
5231            .next_commitment_nonce(self.next_commitment_nonce())
5232            .next_revocation_nonce(self.next_revocation_nonce())
5233            .channel_flags(self.channel_flags())
5234    }
5235}
5236#[derive(Clone, Copy)]
5237pub struct OpenChannelReader<'r>(&'r [u8]);
5238impl<'r> ::core::fmt::LowerHex for OpenChannelReader<'r> {
5239    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
5240        use molecule::hex_string;
5241        if f.alternate() {
5242            write!(f, "0x")?;
5243        }
5244        write!(f, "{}", hex_string(self.as_slice()))
5245    }
5246}
5247impl<'r> ::core::fmt::Debug for OpenChannelReader<'r> {
5248    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
5249        write!(f, "{}({:#x})", Self::NAME, self)
5250    }
5251}
5252impl<'r> ::core::fmt::Display for OpenChannelReader<'r> {
5253    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
5254        write!(f, "{} {{ ", Self::NAME)?;
5255        write!(f, "{}: {}", "chain_hash", self.chain_hash())?;
5256        write!(f, ", {}: {}", "channel_id", self.channel_id())?;
5257        write!(
5258            f,
5259            ", {}: {}",
5260            "funding_udt_type_script",
5261            self.funding_udt_type_script()
5262        )?;
5263        write!(f, ", {}: {}", "funding_amount", self.funding_amount())?;
5264        write!(f, ", {}: {}", "shutdown_script", self.shutdown_script())?;
5265        write!(
5266            f,
5267            ", {}: {}",
5268            "reserved_ckb_amount",
5269            self.reserved_ckb_amount()
5270        )?;
5271        write!(f, ", {}: {}", "funding_fee_rate", self.funding_fee_rate())?;
5272        write!(
5273            f,
5274            ", {}: {}",
5275            "commitment_fee_rate",
5276            self.commitment_fee_rate()
5277        )?;
5278        write!(
5279            f,
5280            ", {}: {}",
5281            "max_tlc_value_in_flight",
5282            self.max_tlc_value_in_flight()
5283        )?;
5284        write!(
5285            f,
5286            ", {}: {}",
5287            "max_tlc_number_in_flight",
5288            self.max_tlc_number_in_flight()
5289        )?;
5290        write!(
5291            f,
5292            ", {}: {}",
5293            "commitment_delay_epoch",
5294            self.commitment_delay_epoch()
5295        )?;
5296        write!(f, ", {}: {}", "funding_pubkey", self.funding_pubkey())?;
5297        write!(f, ", {}: {}", "tlc_basepoint", self.tlc_basepoint())?;
5298        write!(
5299            f,
5300            ", {}: {}",
5301            "first_per_commitment_point",
5302            self.first_per_commitment_point()
5303        )?;
5304        write!(
5305            f,
5306            ", {}: {}",
5307            "second_per_commitment_point",
5308            self.second_per_commitment_point()
5309        )?;
5310        write!(
5311            f,
5312            ", {}: {}",
5313            "channel_announcement_nonce",
5314            self.channel_announcement_nonce()
5315        )?;
5316        write!(
5317            f,
5318            ", {}: {}",
5319            "next_commitment_nonce",
5320            self.next_commitment_nonce()
5321        )?;
5322        write!(
5323            f,
5324            ", {}: {}",
5325            "next_revocation_nonce",
5326            self.next_revocation_nonce()
5327        )?;
5328        write!(f, ", {}: {}", "channel_flags", self.channel_flags())?;
5329        let extra_count = self.count_extra_fields();
5330        if extra_count != 0 {
5331            write!(f, ", .. ({} fields)", extra_count)?;
5332        }
5333        write!(f, " }}")
5334    }
5335}
5336impl<'r> OpenChannelReader<'r> {
5337    pub const FIELD_COUNT: usize = 19;
5338    pub fn total_size(&self) -> usize {
5339        molecule::unpack_number(self.as_slice()) as usize
5340    }
5341    pub fn field_count(&self) -> usize {
5342        if self.total_size() == molecule::NUMBER_SIZE {
5343            0
5344        } else {
5345            (molecule::unpack_number(&self.as_slice()[molecule::NUMBER_SIZE..]) as usize / 4) - 1
5346        }
5347    }
5348    pub fn count_extra_fields(&self) -> usize {
5349        self.field_count() - Self::FIELD_COUNT
5350    }
5351    pub fn has_extra_fields(&self) -> bool {
5352        Self::FIELD_COUNT != self.field_count()
5353    }
5354    pub fn chain_hash(&self) -> Byte32Reader<'r> {
5355        let slice = self.as_slice();
5356        let start = molecule::unpack_number(&slice[4..]) as usize;
5357        let end = molecule::unpack_number(&slice[8..]) as usize;
5358        Byte32Reader::new_unchecked(&self.as_slice()[start..end])
5359    }
5360    pub fn channel_id(&self) -> Byte32Reader<'r> {
5361        let slice = self.as_slice();
5362        let start = molecule::unpack_number(&slice[8..]) as usize;
5363        let end = molecule::unpack_number(&slice[12..]) as usize;
5364        Byte32Reader::new_unchecked(&self.as_slice()[start..end])
5365    }
5366    pub fn funding_udt_type_script(&self) -> ScriptOptReader<'r> {
5367        let slice = self.as_slice();
5368        let start = molecule::unpack_number(&slice[12..]) as usize;
5369        let end = molecule::unpack_number(&slice[16..]) as usize;
5370        ScriptOptReader::new_unchecked(&self.as_slice()[start..end])
5371    }
5372    pub fn funding_amount(&self) -> Uint128Reader<'r> {
5373        let slice = self.as_slice();
5374        let start = molecule::unpack_number(&slice[16..]) as usize;
5375        let end = molecule::unpack_number(&slice[20..]) as usize;
5376        Uint128Reader::new_unchecked(&self.as_slice()[start..end])
5377    }
5378    pub fn shutdown_script(&self) -> ScriptReader<'r> {
5379        let slice = self.as_slice();
5380        let start = molecule::unpack_number(&slice[20..]) as usize;
5381        let end = molecule::unpack_number(&slice[24..]) as usize;
5382        ScriptReader::new_unchecked(&self.as_slice()[start..end])
5383    }
5384    pub fn reserved_ckb_amount(&self) -> Uint64Reader<'r> {
5385        let slice = self.as_slice();
5386        let start = molecule::unpack_number(&slice[24..]) as usize;
5387        let end = molecule::unpack_number(&slice[28..]) as usize;
5388        Uint64Reader::new_unchecked(&self.as_slice()[start..end])
5389    }
5390    pub fn funding_fee_rate(&self) -> Uint64Reader<'r> {
5391        let slice = self.as_slice();
5392        let start = molecule::unpack_number(&slice[28..]) as usize;
5393        let end = molecule::unpack_number(&slice[32..]) as usize;
5394        Uint64Reader::new_unchecked(&self.as_slice()[start..end])
5395    }
5396    pub fn commitment_fee_rate(&self) -> Uint64Reader<'r> {
5397        let slice = self.as_slice();
5398        let start = molecule::unpack_number(&slice[32..]) as usize;
5399        let end = molecule::unpack_number(&slice[36..]) as usize;
5400        Uint64Reader::new_unchecked(&self.as_slice()[start..end])
5401    }
5402    pub fn max_tlc_value_in_flight(&self) -> Uint128Reader<'r> {
5403        let slice = self.as_slice();
5404        let start = molecule::unpack_number(&slice[36..]) as usize;
5405        let end = molecule::unpack_number(&slice[40..]) as usize;
5406        Uint128Reader::new_unchecked(&self.as_slice()[start..end])
5407    }
5408    pub fn max_tlc_number_in_flight(&self) -> Uint64Reader<'r> {
5409        let slice = self.as_slice();
5410        let start = molecule::unpack_number(&slice[40..]) as usize;
5411        let end = molecule::unpack_number(&slice[44..]) as usize;
5412        Uint64Reader::new_unchecked(&self.as_slice()[start..end])
5413    }
5414    pub fn commitment_delay_epoch(&self) -> Uint64Reader<'r> {
5415        let slice = self.as_slice();
5416        let start = molecule::unpack_number(&slice[44..]) as usize;
5417        let end = molecule::unpack_number(&slice[48..]) as usize;
5418        Uint64Reader::new_unchecked(&self.as_slice()[start..end])
5419    }
5420    pub fn funding_pubkey(&self) -> PubkeyReader<'r> {
5421        let slice = self.as_slice();
5422        let start = molecule::unpack_number(&slice[48..]) as usize;
5423        let end = molecule::unpack_number(&slice[52..]) as usize;
5424        PubkeyReader::new_unchecked(&self.as_slice()[start..end])
5425    }
5426    pub fn tlc_basepoint(&self) -> PubkeyReader<'r> {
5427        let slice = self.as_slice();
5428        let start = molecule::unpack_number(&slice[52..]) as usize;
5429        let end = molecule::unpack_number(&slice[56..]) as usize;
5430        PubkeyReader::new_unchecked(&self.as_slice()[start..end])
5431    }
5432    pub fn first_per_commitment_point(&self) -> PubkeyReader<'r> {
5433        let slice = self.as_slice();
5434        let start = molecule::unpack_number(&slice[56..]) as usize;
5435        let end = molecule::unpack_number(&slice[60..]) as usize;
5436        PubkeyReader::new_unchecked(&self.as_slice()[start..end])
5437    }
5438    pub fn second_per_commitment_point(&self) -> PubkeyReader<'r> {
5439        let slice = self.as_slice();
5440        let start = molecule::unpack_number(&slice[60..]) as usize;
5441        let end = molecule::unpack_number(&slice[64..]) as usize;
5442        PubkeyReader::new_unchecked(&self.as_slice()[start..end])
5443    }
5444    pub fn channel_announcement_nonce(&self) -> PubNonceOptReader<'r> {
5445        let slice = self.as_slice();
5446        let start = molecule::unpack_number(&slice[64..]) as usize;
5447        let end = molecule::unpack_number(&slice[68..]) as usize;
5448        PubNonceOptReader::new_unchecked(&self.as_slice()[start..end])
5449    }
5450    pub fn next_commitment_nonce(&self) -> PubNonceReader<'r> {
5451        let slice = self.as_slice();
5452        let start = molecule::unpack_number(&slice[68..]) as usize;
5453        let end = molecule::unpack_number(&slice[72..]) as usize;
5454        PubNonceReader::new_unchecked(&self.as_slice()[start..end])
5455    }
5456    pub fn next_revocation_nonce(&self) -> PubNonceReader<'r> {
5457        let slice = self.as_slice();
5458        let start = molecule::unpack_number(&slice[72..]) as usize;
5459        let end = molecule::unpack_number(&slice[76..]) as usize;
5460        PubNonceReader::new_unchecked(&self.as_slice()[start..end])
5461    }
5462    pub fn channel_flags(&self) -> ByteReader<'r> {
5463        let slice = self.as_slice();
5464        let start = molecule::unpack_number(&slice[76..]) as usize;
5465        if self.has_extra_fields() {
5466            let end = molecule::unpack_number(&slice[80..]) as usize;
5467            ByteReader::new_unchecked(&self.as_slice()[start..end])
5468        } else {
5469            ByteReader::new_unchecked(&self.as_slice()[start..])
5470        }
5471    }
5472}
5473impl<'r> molecule::prelude::Reader<'r> for OpenChannelReader<'r> {
5474    type Entity = OpenChannel;
5475    const NAME: &'static str = "OpenChannelReader";
5476    fn to_entity(&self) -> Self::Entity {
5477        Self::Entity::new_unchecked(self.as_slice().to_owned().into())
5478    }
5479    fn new_unchecked(slice: &'r [u8]) -> Self {
5480        OpenChannelReader(slice)
5481    }
5482    fn as_slice(&self) -> &'r [u8] {
5483        self.0
5484    }
5485    fn verify(slice: &[u8], compatible: bool) -> molecule::error::VerificationResult<()> {
5486        use molecule::verification_error as ve;
5487        let slice_len = slice.len();
5488        if slice_len < molecule::NUMBER_SIZE {
5489            return ve!(Self, HeaderIsBroken, molecule::NUMBER_SIZE, slice_len);
5490        }
5491        let total_size = molecule::unpack_number(slice) as usize;
5492        if slice_len != total_size {
5493            return ve!(Self, TotalSizeNotMatch, total_size, slice_len);
5494        }
5495        if slice_len < molecule::NUMBER_SIZE * 2 {
5496            return ve!(Self, HeaderIsBroken, molecule::NUMBER_SIZE * 2, slice_len);
5497        }
5498        let offset_first = molecule::unpack_number(&slice[molecule::NUMBER_SIZE..]) as usize;
5499        if offset_first % molecule::NUMBER_SIZE != 0 || offset_first < molecule::NUMBER_SIZE * 2 {
5500            return ve!(Self, OffsetsNotMatch);
5501        }
5502        if slice_len < offset_first {
5503            return ve!(Self, HeaderIsBroken, offset_first, slice_len);
5504        }
5505        let field_count = offset_first / molecule::NUMBER_SIZE - 1;
5506        if field_count < Self::FIELD_COUNT {
5507            return ve!(Self, FieldCountNotMatch, Self::FIELD_COUNT, field_count);
5508        } else if !compatible && field_count > Self::FIELD_COUNT {
5509            return ve!(Self, FieldCountNotMatch, Self::FIELD_COUNT, field_count);
5510        };
5511        let mut offsets: Vec<usize> = slice[molecule::NUMBER_SIZE..offset_first]
5512            .chunks_exact(molecule::NUMBER_SIZE)
5513            .map(|x| molecule::unpack_number(x) as usize)
5514            .collect();
5515        offsets.push(total_size);
5516        if offsets.windows(2).any(|i| i[0] > i[1]) {
5517            return ve!(Self, OffsetsNotMatch);
5518        }
5519        Byte32Reader::verify(&slice[offsets[0]..offsets[1]], compatible)?;
5520        Byte32Reader::verify(&slice[offsets[1]..offsets[2]], compatible)?;
5521        ScriptOptReader::verify(&slice[offsets[2]..offsets[3]], compatible)?;
5522        Uint128Reader::verify(&slice[offsets[3]..offsets[4]], compatible)?;
5523        ScriptReader::verify(&slice[offsets[4]..offsets[5]], compatible)?;
5524        Uint64Reader::verify(&slice[offsets[5]..offsets[6]], compatible)?;
5525        Uint64Reader::verify(&slice[offsets[6]..offsets[7]], compatible)?;
5526        Uint64Reader::verify(&slice[offsets[7]..offsets[8]], compatible)?;
5527        Uint128Reader::verify(&slice[offsets[8]..offsets[9]], compatible)?;
5528        Uint64Reader::verify(&slice[offsets[9]..offsets[10]], compatible)?;
5529        Uint64Reader::verify(&slice[offsets[10]..offsets[11]], compatible)?;
5530        PubkeyReader::verify(&slice[offsets[11]..offsets[12]], compatible)?;
5531        PubkeyReader::verify(&slice[offsets[12]..offsets[13]], compatible)?;
5532        PubkeyReader::verify(&slice[offsets[13]..offsets[14]], compatible)?;
5533        PubkeyReader::verify(&slice[offsets[14]..offsets[15]], compatible)?;
5534        PubNonceOptReader::verify(&slice[offsets[15]..offsets[16]], compatible)?;
5535        PubNonceReader::verify(&slice[offsets[16]..offsets[17]], compatible)?;
5536        PubNonceReader::verify(&slice[offsets[17]..offsets[18]], compatible)?;
5537        ByteReader::verify(&slice[offsets[18]..offsets[19]], compatible)?;
5538        Ok(())
5539    }
5540}
5541#[derive(Clone, Debug, Default)]
5542pub struct OpenChannelBuilder {
5543    pub(crate) chain_hash: Byte32,
5544    pub(crate) channel_id: Byte32,
5545    pub(crate) funding_udt_type_script: ScriptOpt,
5546    pub(crate) funding_amount: Uint128,
5547    pub(crate) shutdown_script: Script,
5548    pub(crate) reserved_ckb_amount: Uint64,
5549    pub(crate) funding_fee_rate: Uint64,
5550    pub(crate) commitment_fee_rate: Uint64,
5551    pub(crate) max_tlc_value_in_flight: Uint128,
5552    pub(crate) max_tlc_number_in_flight: Uint64,
5553    pub(crate) commitment_delay_epoch: Uint64,
5554    pub(crate) funding_pubkey: Pubkey,
5555    pub(crate) tlc_basepoint: Pubkey,
5556    pub(crate) first_per_commitment_point: Pubkey,
5557    pub(crate) second_per_commitment_point: Pubkey,
5558    pub(crate) channel_announcement_nonce: PubNonceOpt,
5559    pub(crate) next_commitment_nonce: PubNonce,
5560    pub(crate) next_revocation_nonce: PubNonce,
5561    pub(crate) channel_flags: Byte,
5562}
5563impl OpenChannelBuilder {
5564    pub const FIELD_COUNT: usize = 19;
5565    pub fn chain_hash(mut self, v: Byte32) -> Self {
5566        self.chain_hash = v;
5567        self
5568    }
5569    pub fn channel_id(mut self, v: Byte32) -> Self {
5570        self.channel_id = v;
5571        self
5572    }
5573    pub fn funding_udt_type_script(mut self, v: ScriptOpt) -> Self {
5574        self.funding_udt_type_script = v;
5575        self
5576    }
5577    pub fn funding_amount(mut self, v: Uint128) -> Self {
5578        self.funding_amount = v;
5579        self
5580    }
5581    pub fn shutdown_script(mut self, v: Script) -> Self {
5582        self.shutdown_script = v;
5583        self
5584    }
5585    pub fn reserved_ckb_amount(mut self, v: Uint64) -> Self {
5586        self.reserved_ckb_amount = v;
5587        self
5588    }
5589    pub fn funding_fee_rate(mut self, v: Uint64) -> Self {
5590        self.funding_fee_rate = v;
5591        self
5592    }
5593    pub fn commitment_fee_rate(mut self, v: Uint64) -> Self {
5594        self.commitment_fee_rate = v;
5595        self
5596    }
5597    pub fn max_tlc_value_in_flight(mut self, v: Uint128) -> Self {
5598        self.max_tlc_value_in_flight = v;
5599        self
5600    }
5601    pub fn max_tlc_number_in_flight(mut self, v: Uint64) -> Self {
5602        self.max_tlc_number_in_flight = v;
5603        self
5604    }
5605    pub fn commitment_delay_epoch(mut self, v: Uint64) -> Self {
5606        self.commitment_delay_epoch = v;
5607        self
5608    }
5609    pub fn funding_pubkey(mut self, v: Pubkey) -> Self {
5610        self.funding_pubkey = v;
5611        self
5612    }
5613    pub fn tlc_basepoint(mut self, v: Pubkey) -> Self {
5614        self.tlc_basepoint = v;
5615        self
5616    }
5617    pub fn first_per_commitment_point(mut self, v: Pubkey) -> Self {
5618        self.first_per_commitment_point = v;
5619        self
5620    }
5621    pub fn second_per_commitment_point(mut self, v: Pubkey) -> Self {
5622        self.second_per_commitment_point = v;
5623        self
5624    }
5625    pub fn channel_announcement_nonce(mut self, v: PubNonceOpt) -> Self {
5626        self.channel_announcement_nonce = v;
5627        self
5628    }
5629    pub fn next_commitment_nonce(mut self, v: PubNonce) -> Self {
5630        self.next_commitment_nonce = v;
5631        self
5632    }
5633    pub fn next_revocation_nonce(mut self, v: PubNonce) -> Self {
5634        self.next_revocation_nonce = v;
5635        self
5636    }
5637    pub fn channel_flags(mut self, v: Byte) -> Self {
5638        self.channel_flags = v;
5639        self
5640    }
5641}
5642impl molecule::prelude::Builder for OpenChannelBuilder {
5643    type Entity = OpenChannel;
5644    const NAME: &'static str = "OpenChannelBuilder";
5645    fn expected_length(&self) -> usize {
5646        molecule::NUMBER_SIZE * (Self::FIELD_COUNT + 1)
5647            + self.chain_hash.as_slice().len()
5648            + self.channel_id.as_slice().len()
5649            + self.funding_udt_type_script.as_slice().len()
5650            + self.funding_amount.as_slice().len()
5651            + self.shutdown_script.as_slice().len()
5652            + self.reserved_ckb_amount.as_slice().len()
5653            + self.funding_fee_rate.as_slice().len()
5654            + self.commitment_fee_rate.as_slice().len()
5655            + self.max_tlc_value_in_flight.as_slice().len()
5656            + self.max_tlc_number_in_flight.as_slice().len()
5657            + self.commitment_delay_epoch.as_slice().len()
5658            + self.funding_pubkey.as_slice().len()
5659            + self.tlc_basepoint.as_slice().len()
5660            + self.first_per_commitment_point.as_slice().len()
5661            + self.second_per_commitment_point.as_slice().len()
5662            + self.channel_announcement_nonce.as_slice().len()
5663            + self.next_commitment_nonce.as_slice().len()
5664            + self.next_revocation_nonce.as_slice().len()
5665            + self.channel_flags.as_slice().len()
5666    }
5667    fn write<W: molecule::io::Write>(&self, writer: &mut W) -> molecule::io::Result<()> {
5668        let mut total_size = molecule::NUMBER_SIZE * (Self::FIELD_COUNT + 1);
5669        let mut offsets = Vec::with_capacity(Self::FIELD_COUNT);
5670        offsets.push(total_size);
5671        total_size += self.chain_hash.as_slice().len();
5672        offsets.push(total_size);
5673        total_size += self.channel_id.as_slice().len();
5674        offsets.push(total_size);
5675        total_size += self.funding_udt_type_script.as_slice().len();
5676        offsets.push(total_size);
5677        total_size += self.funding_amount.as_slice().len();
5678        offsets.push(total_size);
5679        total_size += self.shutdown_script.as_slice().len();
5680        offsets.push(total_size);
5681        total_size += self.reserved_ckb_amount.as_slice().len();
5682        offsets.push(total_size);
5683        total_size += self.funding_fee_rate.as_slice().len();
5684        offsets.push(total_size);
5685        total_size += self.commitment_fee_rate.as_slice().len();
5686        offsets.push(total_size);
5687        total_size += self.max_tlc_value_in_flight.as_slice().len();
5688        offsets.push(total_size);
5689        total_size += self.max_tlc_number_in_flight.as_slice().len();
5690        offsets.push(total_size);
5691        total_size += self.commitment_delay_epoch.as_slice().len();
5692        offsets.push(total_size);
5693        total_size += self.funding_pubkey.as_slice().len();
5694        offsets.push(total_size);
5695        total_size += self.tlc_basepoint.as_slice().len();
5696        offsets.push(total_size);
5697        total_size += self.first_per_commitment_point.as_slice().len();
5698        offsets.push(total_size);
5699        total_size += self.second_per_commitment_point.as_slice().len();
5700        offsets.push(total_size);
5701        total_size += self.channel_announcement_nonce.as_slice().len();
5702        offsets.push(total_size);
5703        total_size += self.next_commitment_nonce.as_slice().len();
5704        offsets.push(total_size);
5705        total_size += self.next_revocation_nonce.as_slice().len();
5706        offsets.push(total_size);
5707        total_size += self.channel_flags.as_slice().len();
5708        writer.write_all(&molecule::pack_number(total_size as molecule::Number))?;
5709        for offset in offsets.into_iter() {
5710            writer.write_all(&molecule::pack_number(offset as molecule::Number))?;
5711        }
5712        writer.write_all(self.chain_hash.as_slice())?;
5713        writer.write_all(self.channel_id.as_slice())?;
5714        writer.write_all(self.funding_udt_type_script.as_slice())?;
5715        writer.write_all(self.funding_amount.as_slice())?;
5716        writer.write_all(self.shutdown_script.as_slice())?;
5717        writer.write_all(self.reserved_ckb_amount.as_slice())?;
5718        writer.write_all(self.funding_fee_rate.as_slice())?;
5719        writer.write_all(self.commitment_fee_rate.as_slice())?;
5720        writer.write_all(self.max_tlc_value_in_flight.as_slice())?;
5721        writer.write_all(self.max_tlc_number_in_flight.as_slice())?;
5722        writer.write_all(self.commitment_delay_epoch.as_slice())?;
5723        writer.write_all(self.funding_pubkey.as_slice())?;
5724        writer.write_all(self.tlc_basepoint.as_slice())?;
5725        writer.write_all(self.first_per_commitment_point.as_slice())?;
5726        writer.write_all(self.second_per_commitment_point.as_slice())?;
5727        writer.write_all(self.channel_announcement_nonce.as_slice())?;
5728        writer.write_all(self.next_commitment_nonce.as_slice())?;
5729        writer.write_all(self.next_revocation_nonce.as_slice())?;
5730        writer.write_all(self.channel_flags.as_slice())?;
5731        Ok(())
5732    }
5733    fn build(&self) -> Self::Entity {
5734        let mut inner = Vec::with_capacity(self.expected_length());
5735        self.write(&mut inner)
5736            .unwrap_or_else(|_| panic!("{} build should be ok", Self::NAME));
5737        OpenChannel::new_unchecked(inner.into())
5738    }
5739}
5740#[derive(Clone)]
5741pub struct AcceptChannel(molecule::bytes::Bytes);
5742impl ::core::fmt::LowerHex for AcceptChannel {
5743    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
5744        use molecule::hex_string;
5745        if f.alternate() {
5746            write!(f, "0x")?;
5747        }
5748        write!(f, "{}", hex_string(self.as_slice()))
5749    }
5750}
5751impl ::core::fmt::Debug for AcceptChannel {
5752    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
5753        write!(f, "{}({:#x})", Self::NAME, self)
5754    }
5755}
5756impl ::core::fmt::Display for AcceptChannel {
5757    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
5758        write!(f, "{} {{ ", Self::NAME)?;
5759        write!(f, "{}: {}", "channel_id", self.channel_id())?;
5760        write!(f, ", {}: {}", "funding_amount", self.funding_amount())?;
5761        write!(f, ", {}: {}", "shutdown_script", self.shutdown_script())?;
5762        write!(
5763            f,
5764            ", {}: {}",
5765            "reserved_ckb_amount",
5766            self.reserved_ckb_amount()
5767        )?;
5768        write!(
5769            f,
5770            ", {}: {}",
5771            "max_tlc_value_in_flight",
5772            self.max_tlc_value_in_flight()
5773        )?;
5774        write!(
5775            f,
5776            ", {}: {}",
5777            "max_tlc_number_in_flight",
5778            self.max_tlc_number_in_flight()
5779        )?;
5780        write!(f, ", {}: {}", "funding_pubkey", self.funding_pubkey())?;
5781        write!(f, ", {}: {}", "tlc_basepoint", self.tlc_basepoint())?;
5782        write!(
5783            f,
5784            ", {}: {}",
5785            "first_per_commitment_point",
5786            self.first_per_commitment_point()
5787        )?;
5788        write!(
5789            f,
5790            ", {}: {}",
5791            "second_per_commitment_point",
5792            self.second_per_commitment_point()
5793        )?;
5794        write!(
5795            f,
5796            ", {}: {}",
5797            "channel_announcement_nonce",
5798            self.channel_announcement_nonce()
5799        )?;
5800        write!(
5801            f,
5802            ", {}: {}",
5803            "next_commitment_nonce",
5804            self.next_commitment_nonce()
5805        )?;
5806        write!(
5807            f,
5808            ", {}: {}",
5809            "next_revocation_nonce",
5810            self.next_revocation_nonce()
5811        )?;
5812        let extra_count = self.count_extra_fields();
5813        if extra_count != 0 {
5814            write!(f, ", .. ({} fields)", extra_count)?;
5815        }
5816        write!(f, " }}")
5817    }
5818}
5819impl ::core::default::Default for AcceptChannel {
5820    fn default() -> Self {
5821        let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE);
5822        AcceptChannel::new_unchecked(v)
5823    }
5824}
5825impl AcceptChannel {
5826    const DEFAULT_VALUE: [u8; 453] = [
5827        197, 1, 0, 0, 56, 0, 0, 0, 88, 0, 0, 0, 104, 0, 0, 0, 157, 0, 0, 0, 165, 0, 0, 0, 181, 0,
5828        0, 0, 189, 0, 0, 0, 222, 0, 0, 0, 255, 0, 0, 0, 32, 1, 0, 0, 65, 1, 0, 0, 65, 1, 0, 0, 131,
5829        1, 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,
5830        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 53, 0, 0, 0, 16, 0, 0, 0,
5831        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,
5832        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,
5833        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,
5834        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,
5835        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,
5836        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,
5837        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,
5838        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,
5839        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,
5840        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,
5841        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,
5842        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
5843    ];
5844    pub const FIELD_COUNT: usize = 13;
5845    pub fn total_size(&self) -> usize {
5846        molecule::unpack_number(self.as_slice()) as usize
5847    }
5848    pub fn field_count(&self) -> usize {
5849        if self.total_size() == molecule::NUMBER_SIZE {
5850            0
5851        } else {
5852            (molecule::unpack_number(&self.as_slice()[molecule::NUMBER_SIZE..]) as usize / 4) - 1
5853        }
5854    }
5855    pub fn count_extra_fields(&self) -> usize {
5856        self.field_count() - Self::FIELD_COUNT
5857    }
5858    pub fn has_extra_fields(&self) -> bool {
5859        Self::FIELD_COUNT != self.field_count()
5860    }
5861    pub fn channel_id(&self) -> Byte32 {
5862        let slice = self.as_slice();
5863        let start = molecule::unpack_number(&slice[4..]) as usize;
5864        let end = molecule::unpack_number(&slice[8..]) as usize;
5865        Byte32::new_unchecked(self.0.slice(start..end))
5866    }
5867    pub fn funding_amount(&self) -> Uint128 {
5868        let slice = self.as_slice();
5869        let start = molecule::unpack_number(&slice[8..]) as usize;
5870        let end = molecule::unpack_number(&slice[12..]) as usize;
5871        Uint128::new_unchecked(self.0.slice(start..end))
5872    }
5873    pub fn shutdown_script(&self) -> Script {
5874        let slice = self.as_slice();
5875        let start = molecule::unpack_number(&slice[12..]) as usize;
5876        let end = molecule::unpack_number(&slice[16..]) as usize;
5877        Script::new_unchecked(self.0.slice(start..end))
5878    }
5879    pub fn reserved_ckb_amount(&self) -> Uint64 {
5880        let slice = self.as_slice();
5881        let start = molecule::unpack_number(&slice[16..]) as usize;
5882        let end = molecule::unpack_number(&slice[20..]) as usize;
5883        Uint64::new_unchecked(self.0.slice(start..end))
5884    }
5885    pub fn max_tlc_value_in_flight(&self) -> Uint128 {
5886        let slice = self.as_slice();
5887        let start = molecule::unpack_number(&slice[20..]) as usize;
5888        let end = molecule::unpack_number(&slice[24..]) as usize;
5889        Uint128::new_unchecked(self.0.slice(start..end))
5890    }
5891    pub fn max_tlc_number_in_flight(&self) -> Uint64 {
5892        let slice = self.as_slice();
5893        let start = molecule::unpack_number(&slice[24..]) as usize;
5894        let end = molecule::unpack_number(&slice[28..]) as usize;
5895        Uint64::new_unchecked(self.0.slice(start..end))
5896    }
5897    pub fn funding_pubkey(&self) -> Pubkey {
5898        let slice = self.as_slice();
5899        let start = molecule::unpack_number(&slice[28..]) as usize;
5900        let end = molecule::unpack_number(&slice[32..]) as usize;
5901        Pubkey::new_unchecked(self.0.slice(start..end))
5902    }
5903    pub fn tlc_basepoint(&self) -> Pubkey {
5904        let slice = self.as_slice();
5905        let start = molecule::unpack_number(&slice[32..]) as usize;
5906        let end = molecule::unpack_number(&slice[36..]) as usize;
5907        Pubkey::new_unchecked(self.0.slice(start..end))
5908    }
5909    pub fn first_per_commitment_point(&self) -> Pubkey {
5910        let slice = self.as_slice();
5911        let start = molecule::unpack_number(&slice[36..]) as usize;
5912        let end = molecule::unpack_number(&slice[40..]) as usize;
5913        Pubkey::new_unchecked(self.0.slice(start..end))
5914    }
5915    pub fn second_per_commitment_point(&self) -> Pubkey {
5916        let slice = self.as_slice();
5917        let start = molecule::unpack_number(&slice[40..]) as usize;
5918        let end = molecule::unpack_number(&slice[44..]) as usize;
5919        Pubkey::new_unchecked(self.0.slice(start..end))
5920    }
5921    pub fn channel_announcement_nonce(&self) -> PubNonceOpt {
5922        let slice = self.as_slice();
5923        let start = molecule::unpack_number(&slice[44..]) as usize;
5924        let end = molecule::unpack_number(&slice[48..]) as usize;
5925        PubNonceOpt::new_unchecked(self.0.slice(start..end))
5926    }
5927    pub fn next_commitment_nonce(&self) -> PubNonce {
5928        let slice = self.as_slice();
5929        let start = molecule::unpack_number(&slice[48..]) as usize;
5930        let end = molecule::unpack_number(&slice[52..]) as usize;
5931        PubNonce::new_unchecked(self.0.slice(start..end))
5932    }
5933    pub fn next_revocation_nonce(&self) -> PubNonce {
5934        let slice = self.as_slice();
5935        let start = molecule::unpack_number(&slice[52..]) as usize;
5936        if self.has_extra_fields() {
5937            let end = molecule::unpack_number(&slice[56..]) as usize;
5938            PubNonce::new_unchecked(self.0.slice(start..end))
5939        } else {
5940            PubNonce::new_unchecked(self.0.slice(start..))
5941        }
5942    }
5943    pub fn as_reader<'r>(&'r self) -> AcceptChannelReader<'r> {
5944        AcceptChannelReader::new_unchecked(self.as_slice())
5945    }
5946}
5947impl molecule::prelude::Entity for AcceptChannel {
5948    type Builder = AcceptChannelBuilder;
5949    const NAME: &'static str = "AcceptChannel";
5950    fn new_unchecked(data: molecule::bytes::Bytes) -> Self {
5951        AcceptChannel(data)
5952    }
5953    fn as_bytes(&self) -> molecule::bytes::Bytes {
5954        self.0.clone()
5955    }
5956    fn as_slice(&self) -> &[u8] {
5957        &self.0[..]
5958    }
5959    fn from_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
5960        AcceptChannelReader::from_slice(slice).map(|reader| reader.to_entity())
5961    }
5962    fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
5963        AcceptChannelReader::from_compatible_slice(slice).map(|reader| reader.to_entity())
5964    }
5965    fn new_builder() -> Self::Builder {
5966        ::core::default::Default::default()
5967    }
5968    fn as_builder(self) -> Self::Builder {
5969        Self::new_builder()
5970            .channel_id(self.channel_id())
5971            .funding_amount(self.funding_amount())
5972            .shutdown_script(self.shutdown_script())
5973            .reserved_ckb_amount(self.reserved_ckb_amount())
5974            .max_tlc_value_in_flight(self.max_tlc_value_in_flight())
5975            .max_tlc_number_in_flight(self.max_tlc_number_in_flight())
5976            .funding_pubkey(self.funding_pubkey())
5977            .tlc_basepoint(self.tlc_basepoint())
5978            .first_per_commitment_point(self.first_per_commitment_point())
5979            .second_per_commitment_point(self.second_per_commitment_point())
5980            .channel_announcement_nonce(self.channel_announcement_nonce())
5981            .next_commitment_nonce(self.next_commitment_nonce())
5982            .next_revocation_nonce(self.next_revocation_nonce())
5983    }
5984}
5985#[derive(Clone, Copy)]
5986pub struct AcceptChannelReader<'r>(&'r [u8]);
5987impl<'r> ::core::fmt::LowerHex for AcceptChannelReader<'r> {
5988    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
5989        use molecule::hex_string;
5990        if f.alternate() {
5991            write!(f, "0x")?;
5992        }
5993        write!(f, "{}", hex_string(self.as_slice()))
5994    }
5995}
5996impl<'r> ::core::fmt::Debug for AcceptChannelReader<'r> {
5997    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
5998        write!(f, "{}({:#x})", Self::NAME, self)
5999    }
6000}
6001impl<'r> ::core::fmt::Display for AcceptChannelReader<'r> {
6002    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
6003        write!(f, "{} {{ ", Self::NAME)?;
6004        write!(f, "{}: {}", "channel_id", self.channel_id())?;
6005        write!(f, ", {}: {}", "funding_amount", self.funding_amount())?;
6006        write!(f, ", {}: {}", "shutdown_script", self.shutdown_script())?;
6007        write!(
6008            f,
6009            ", {}: {}",
6010            "reserved_ckb_amount",
6011            self.reserved_ckb_amount()
6012        )?;
6013        write!(
6014            f,
6015            ", {}: {}",
6016            "max_tlc_value_in_flight",
6017            self.max_tlc_value_in_flight()
6018        )?;
6019        write!(
6020            f,
6021            ", {}: {}",
6022            "max_tlc_number_in_flight",
6023            self.max_tlc_number_in_flight()
6024        )?;
6025        write!(f, ", {}: {}", "funding_pubkey", self.funding_pubkey())?;
6026        write!(f, ", {}: {}", "tlc_basepoint", self.tlc_basepoint())?;
6027        write!(
6028            f,
6029            ", {}: {}",
6030            "first_per_commitment_point",
6031            self.first_per_commitment_point()
6032        )?;
6033        write!(
6034            f,
6035            ", {}: {}",
6036            "second_per_commitment_point",
6037            self.second_per_commitment_point()
6038        )?;
6039        write!(
6040            f,
6041            ", {}: {}",
6042            "channel_announcement_nonce",
6043            self.channel_announcement_nonce()
6044        )?;
6045        write!(
6046            f,
6047            ", {}: {}",
6048            "next_commitment_nonce",
6049            self.next_commitment_nonce()
6050        )?;
6051        write!(
6052            f,
6053            ", {}: {}",
6054            "next_revocation_nonce",
6055            self.next_revocation_nonce()
6056        )?;
6057        let extra_count = self.count_extra_fields();
6058        if extra_count != 0 {
6059            write!(f, ", .. ({} fields)", extra_count)?;
6060        }
6061        write!(f, " }}")
6062    }
6063}
6064impl<'r> AcceptChannelReader<'r> {
6065    pub const FIELD_COUNT: usize = 13;
6066    pub fn total_size(&self) -> usize {
6067        molecule::unpack_number(self.as_slice()) as usize
6068    }
6069    pub fn field_count(&self) -> usize {
6070        if self.total_size() == molecule::NUMBER_SIZE {
6071            0
6072        } else {
6073            (molecule::unpack_number(&self.as_slice()[molecule::NUMBER_SIZE..]) as usize / 4) - 1
6074        }
6075    }
6076    pub fn count_extra_fields(&self) -> usize {
6077        self.field_count() - Self::FIELD_COUNT
6078    }
6079    pub fn has_extra_fields(&self) -> bool {
6080        Self::FIELD_COUNT != self.field_count()
6081    }
6082    pub fn channel_id(&self) -> Byte32Reader<'r> {
6083        let slice = self.as_slice();
6084        let start = molecule::unpack_number(&slice[4..]) as usize;
6085        let end = molecule::unpack_number(&slice[8..]) as usize;
6086        Byte32Reader::new_unchecked(&self.as_slice()[start..end])
6087    }
6088    pub fn funding_amount(&self) -> Uint128Reader<'r> {
6089        let slice = self.as_slice();
6090        let start = molecule::unpack_number(&slice[8..]) as usize;
6091        let end = molecule::unpack_number(&slice[12..]) as usize;
6092        Uint128Reader::new_unchecked(&self.as_slice()[start..end])
6093    }
6094    pub fn shutdown_script(&self) -> ScriptReader<'r> {
6095        let slice = self.as_slice();
6096        let start = molecule::unpack_number(&slice[12..]) as usize;
6097        let end = molecule::unpack_number(&slice[16..]) as usize;
6098        ScriptReader::new_unchecked(&self.as_slice()[start..end])
6099    }
6100    pub fn reserved_ckb_amount(&self) -> Uint64Reader<'r> {
6101        let slice = self.as_slice();
6102        let start = molecule::unpack_number(&slice[16..]) as usize;
6103        let end = molecule::unpack_number(&slice[20..]) as usize;
6104        Uint64Reader::new_unchecked(&self.as_slice()[start..end])
6105    }
6106    pub fn max_tlc_value_in_flight(&self) -> Uint128Reader<'r> {
6107        let slice = self.as_slice();
6108        let start = molecule::unpack_number(&slice[20..]) as usize;
6109        let end = molecule::unpack_number(&slice[24..]) as usize;
6110        Uint128Reader::new_unchecked(&self.as_slice()[start..end])
6111    }
6112    pub fn max_tlc_number_in_flight(&self) -> Uint64Reader<'r> {
6113        let slice = self.as_slice();
6114        let start = molecule::unpack_number(&slice[24..]) as usize;
6115        let end = molecule::unpack_number(&slice[28..]) as usize;
6116        Uint64Reader::new_unchecked(&self.as_slice()[start..end])
6117    }
6118    pub fn funding_pubkey(&self) -> PubkeyReader<'r> {
6119        let slice = self.as_slice();
6120        let start = molecule::unpack_number(&slice[28..]) as usize;
6121        let end = molecule::unpack_number(&slice[32..]) as usize;
6122        PubkeyReader::new_unchecked(&self.as_slice()[start..end])
6123    }
6124    pub fn tlc_basepoint(&self) -> PubkeyReader<'r> {
6125        let slice = self.as_slice();
6126        let start = molecule::unpack_number(&slice[32..]) as usize;
6127        let end = molecule::unpack_number(&slice[36..]) as usize;
6128        PubkeyReader::new_unchecked(&self.as_slice()[start..end])
6129    }
6130    pub fn first_per_commitment_point(&self) -> PubkeyReader<'r> {
6131        let slice = self.as_slice();
6132        let start = molecule::unpack_number(&slice[36..]) as usize;
6133        let end = molecule::unpack_number(&slice[40..]) as usize;
6134        PubkeyReader::new_unchecked(&self.as_slice()[start..end])
6135    }
6136    pub fn second_per_commitment_point(&self) -> PubkeyReader<'r> {
6137        let slice = self.as_slice();
6138        let start = molecule::unpack_number(&slice[40..]) as usize;
6139        let end = molecule::unpack_number(&slice[44..]) as usize;
6140        PubkeyReader::new_unchecked(&self.as_slice()[start..end])
6141    }
6142    pub fn channel_announcement_nonce(&self) -> PubNonceOptReader<'r> {
6143        let slice = self.as_slice();
6144        let start = molecule::unpack_number(&slice[44..]) as usize;
6145        let end = molecule::unpack_number(&slice[48..]) as usize;
6146        PubNonceOptReader::new_unchecked(&self.as_slice()[start..end])
6147    }
6148    pub fn next_commitment_nonce(&self) -> PubNonceReader<'r> {
6149        let slice = self.as_slice();
6150        let start = molecule::unpack_number(&slice[48..]) as usize;
6151        let end = molecule::unpack_number(&slice[52..]) as usize;
6152        PubNonceReader::new_unchecked(&self.as_slice()[start..end])
6153    }
6154    pub fn next_revocation_nonce(&self) -> PubNonceReader<'r> {
6155        let slice = self.as_slice();
6156        let start = molecule::unpack_number(&slice[52..]) as usize;
6157        if self.has_extra_fields() {
6158            let end = molecule::unpack_number(&slice[56..]) as usize;
6159            PubNonceReader::new_unchecked(&self.as_slice()[start..end])
6160        } else {
6161            PubNonceReader::new_unchecked(&self.as_slice()[start..])
6162        }
6163    }
6164}
6165impl<'r> molecule::prelude::Reader<'r> for AcceptChannelReader<'r> {
6166    type Entity = AcceptChannel;
6167    const NAME: &'static str = "AcceptChannelReader";
6168    fn to_entity(&self) -> Self::Entity {
6169        Self::Entity::new_unchecked(self.as_slice().to_owned().into())
6170    }
6171    fn new_unchecked(slice: &'r [u8]) -> Self {
6172        AcceptChannelReader(slice)
6173    }
6174    fn as_slice(&self) -> &'r [u8] {
6175        self.0
6176    }
6177    fn verify(slice: &[u8], compatible: bool) -> molecule::error::VerificationResult<()> {
6178        use molecule::verification_error as ve;
6179        let slice_len = slice.len();
6180        if slice_len < molecule::NUMBER_SIZE {
6181            return ve!(Self, HeaderIsBroken, molecule::NUMBER_SIZE, slice_len);
6182        }
6183        let total_size = molecule::unpack_number(slice) as usize;
6184        if slice_len != total_size {
6185            return ve!(Self, TotalSizeNotMatch, total_size, slice_len);
6186        }
6187        if slice_len < molecule::NUMBER_SIZE * 2 {
6188            return ve!(Self, HeaderIsBroken, molecule::NUMBER_SIZE * 2, slice_len);
6189        }
6190        let offset_first = molecule::unpack_number(&slice[molecule::NUMBER_SIZE..]) as usize;
6191        if offset_first % molecule::NUMBER_SIZE != 0 || offset_first < molecule::NUMBER_SIZE * 2 {
6192            return ve!(Self, OffsetsNotMatch);
6193        }
6194        if slice_len < offset_first {
6195            return ve!(Self, HeaderIsBroken, offset_first, slice_len);
6196        }
6197        let field_count = offset_first / molecule::NUMBER_SIZE - 1;
6198        if field_count < Self::FIELD_COUNT {
6199            return ve!(Self, FieldCountNotMatch, Self::FIELD_COUNT, field_count);
6200        } else if !compatible && field_count > Self::FIELD_COUNT {
6201            return ve!(Self, FieldCountNotMatch, Self::FIELD_COUNT, field_count);
6202        };
6203        let mut offsets: Vec<usize> = slice[molecule::NUMBER_SIZE..offset_first]
6204            .chunks_exact(molecule::NUMBER_SIZE)
6205            .map(|x| molecule::unpack_number(x) as usize)
6206            .collect();
6207        offsets.push(total_size);
6208        if offsets.windows(2).any(|i| i[0] > i[1]) {
6209            return ve!(Self, OffsetsNotMatch);
6210        }
6211        Byte32Reader::verify(&slice[offsets[0]..offsets[1]], compatible)?;
6212        Uint128Reader::verify(&slice[offsets[1]..offsets[2]], compatible)?;
6213        ScriptReader::verify(&slice[offsets[2]..offsets[3]], compatible)?;
6214        Uint64Reader::verify(&slice[offsets[3]..offsets[4]], compatible)?;
6215        Uint128Reader::verify(&slice[offsets[4]..offsets[5]], compatible)?;
6216        Uint64Reader::verify(&slice[offsets[5]..offsets[6]], compatible)?;
6217        PubkeyReader::verify(&slice[offsets[6]..offsets[7]], compatible)?;
6218        PubkeyReader::verify(&slice[offsets[7]..offsets[8]], compatible)?;
6219        PubkeyReader::verify(&slice[offsets[8]..offsets[9]], compatible)?;
6220        PubkeyReader::verify(&slice[offsets[9]..offsets[10]], compatible)?;
6221        PubNonceOptReader::verify(&slice[offsets[10]..offsets[11]], compatible)?;
6222        PubNonceReader::verify(&slice[offsets[11]..offsets[12]], compatible)?;
6223        PubNonceReader::verify(&slice[offsets[12]..offsets[13]], compatible)?;
6224        Ok(())
6225    }
6226}
6227#[derive(Clone, Debug, Default)]
6228pub struct AcceptChannelBuilder {
6229    pub(crate) channel_id: Byte32,
6230    pub(crate) funding_amount: Uint128,
6231    pub(crate) shutdown_script: Script,
6232    pub(crate) reserved_ckb_amount: Uint64,
6233    pub(crate) max_tlc_value_in_flight: Uint128,
6234    pub(crate) max_tlc_number_in_flight: Uint64,
6235    pub(crate) funding_pubkey: Pubkey,
6236    pub(crate) tlc_basepoint: Pubkey,
6237    pub(crate) first_per_commitment_point: Pubkey,
6238    pub(crate) second_per_commitment_point: Pubkey,
6239    pub(crate) channel_announcement_nonce: PubNonceOpt,
6240    pub(crate) next_commitment_nonce: PubNonce,
6241    pub(crate) next_revocation_nonce: PubNonce,
6242}
6243impl AcceptChannelBuilder {
6244    pub const FIELD_COUNT: usize = 13;
6245    pub fn channel_id(mut self, v: Byte32) -> Self {
6246        self.channel_id = v;
6247        self
6248    }
6249    pub fn funding_amount(mut self, v: Uint128) -> Self {
6250        self.funding_amount = v;
6251        self
6252    }
6253    pub fn shutdown_script(mut self, v: Script) -> Self {
6254        self.shutdown_script = v;
6255        self
6256    }
6257    pub fn reserved_ckb_amount(mut self, v: Uint64) -> Self {
6258        self.reserved_ckb_amount = v;
6259        self
6260    }
6261    pub fn max_tlc_value_in_flight(mut self, v: Uint128) -> Self {
6262        self.max_tlc_value_in_flight = v;
6263        self
6264    }
6265    pub fn max_tlc_number_in_flight(mut self, v: Uint64) -> Self {
6266        self.max_tlc_number_in_flight = v;
6267        self
6268    }
6269    pub fn funding_pubkey(mut self, v: Pubkey) -> Self {
6270        self.funding_pubkey = v;
6271        self
6272    }
6273    pub fn tlc_basepoint(mut self, v: Pubkey) -> Self {
6274        self.tlc_basepoint = v;
6275        self
6276    }
6277    pub fn first_per_commitment_point(mut self, v: Pubkey) -> Self {
6278        self.first_per_commitment_point = v;
6279        self
6280    }
6281    pub fn second_per_commitment_point(mut self, v: Pubkey) -> Self {
6282        self.second_per_commitment_point = v;
6283        self
6284    }
6285    pub fn channel_announcement_nonce(mut self, v: PubNonceOpt) -> Self {
6286        self.channel_announcement_nonce = v;
6287        self
6288    }
6289    pub fn next_commitment_nonce(mut self, v: PubNonce) -> Self {
6290        self.next_commitment_nonce = v;
6291        self
6292    }
6293    pub fn next_revocation_nonce(mut self, v: PubNonce) -> Self {
6294        self.next_revocation_nonce = v;
6295        self
6296    }
6297}
6298impl molecule::prelude::Builder for AcceptChannelBuilder {
6299    type Entity = AcceptChannel;
6300    const NAME: &'static str = "AcceptChannelBuilder";
6301    fn expected_length(&self) -> usize {
6302        molecule::NUMBER_SIZE * (Self::FIELD_COUNT + 1)
6303            + self.channel_id.as_slice().len()
6304            + self.funding_amount.as_slice().len()
6305            + self.shutdown_script.as_slice().len()
6306            + self.reserved_ckb_amount.as_slice().len()
6307            + self.max_tlc_value_in_flight.as_slice().len()
6308            + self.max_tlc_number_in_flight.as_slice().len()
6309            + self.funding_pubkey.as_slice().len()
6310            + self.tlc_basepoint.as_slice().len()
6311            + self.first_per_commitment_point.as_slice().len()
6312            + self.second_per_commitment_point.as_slice().len()
6313            + self.channel_announcement_nonce.as_slice().len()
6314            + self.next_commitment_nonce.as_slice().len()
6315            + self.next_revocation_nonce.as_slice().len()
6316    }
6317    fn write<W: molecule::io::Write>(&self, writer: &mut W) -> molecule::io::Result<()> {
6318        let mut total_size = molecule::NUMBER_SIZE * (Self::FIELD_COUNT + 1);
6319        let mut offsets = Vec::with_capacity(Self::FIELD_COUNT);
6320        offsets.push(total_size);
6321        total_size += self.channel_id.as_slice().len();
6322        offsets.push(total_size);
6323        total_size += self.funding_amount.as_slice().len();
6324        offsets.push(total_size);
6325        total_size += self.shutdown_script.as_slice().len();
6326        offsets.push(total_size);
6327        total_size += self.reserved_ckb_amount.as_slice().len();
6328        offsets.push(total_size);
6329        total_size += self.max_tlc_value_in_flight.as_slice().len();
6330        offsets.push(total_size);
6331        total_size += self.max_tlc_number_in_flight.as_slice().len();
6332        offsets.push(total_size);
6333        total_size += self.funding_pubkey.as_slice().len();
6334        offsets.push(total_size);
6335        total_size += self.tlc_basepoint.as_slice().len();
6336        offsets.push(total_size);
6337        total_size += self.first_per_commitment_point.as_slice().len();
6338        offsets.push(total_size);
6339        total_size += self.second_per_commitment_point.as_slice().len();
6340        offsets.push(total_size);
6341        total_size += self.channel_announcement_nonce.as_slice().len();
6342        offsets.push(total_size);
6343        total_size += self.next_commitment_nonce.as_slice().len();
6344        offsets.push(total_size);
6345        total_size += self.next_revocation_nonce.as_slice().len();
6346        writer.write_all(&molecule::pack_number(total_size as molecule::Number))?;
6347        for offset in offsets.into_iter() {
6348            writer.write_all(&molecule::pack_number(offset as molecule::Number))?;
6349        }
6350        writer.write_all(self.channel_id.as_slice())?;
6351        writer.write_all(self.funding_amount.as_slice())?;
6352        writer.write_all(self.shutdown_script.as_slice())?;
6353        writer.write_all(self.reserved_ckb_amount.as_slice())?;
6354        writer.write_all(self.max_tlc_value_in_flight.as_slice())?;
6355        writer.write_all(self.max_tlc_number_in_flight.as_slice())?;
6356        writer.write_all(self.funding_pubkey.as_slice())?;
6357        writer.write_all(self.tlc_basepoint.as_slice())?;
6358        writer.write_all(self.first_per_commitment_point.as_slice())?;
6359        writer.write_all(self.second_per_commitment_point.as_slice())?;
6360        writer.write_all(self.channel_announcement_nonce.as_slice())?;
6361        writer.write_all(self.next_commitment_nonce.as_slice())?;
6362        writer.write_all(self.next_revocation_nonce.as_slice())?;
6363        Ok(())
6364    }
6365    fn build(&self) -> Self::Entity {
6366        let mut inner = Vec::with_capacity(self.expected_length());
6367        self.write(&mut inner)
6368            .unwrap_or_else(|_| panic!("{} build should be ok", Self::NAME));
6369        AcceptChannel::new_unchecked(inner.into())
6370    }
6371}
6372#[derive(Clone)]
6373pub struct CommitmentSigned(molecule::bytes::Bytes);
6374impl ::core::fmt::LowerHex for CommitmentSigned {
6375    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
6376        use molecule::hex_string;
6377        if f.alternate() {
6378            write!(f, "0x")?;
6379        }
6380        write!(f, "{}", hex_string(self.as_slice()))
6381    }
6382}
6383impl ::core::fmt::Debug for CommitmentSigned {
6384    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
6385        write!(f, "{}({:#x})", Self::NAME, self)
6386    }
6387}
6388impl ::core::fmt::Display for CommitmentSigned {
6389    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
6390        write!(f, "{} {{ ", Self::NAME)?;
6391        write!(f, "{}: {}", "channel_id", self.channel_id())?;
6392        write!(
6393            f,
6394            ", {}: {}",
6395            "funding_tx_partial_signature",
6396            self.funding_tx_partial_signature()
6397        )?;
6398        write!(
6399            f,
6400            ", {}: {}",
6401            "next_commitment_nonce",
6402            self.next_commitment_nonce()
6403        )?;
6404        write!(f, " }}")
6405    }
6406}
6407impl ::core::default::Default for CommitmentSigned {
6408    fn default() -> Self {
6409        let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE);
6410        CommitmentSigned::new_unchecked(v)
6411    }
6412}
6413impl CommitmentSigned {
6414    const DEFAULT_VALUE: [u8; 130] = [
6415        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,
6416        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,
6417        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,
6418        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,
6419        0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
6420    ];
6421    pub const TOTAL_SIZE: usize = 130;
6422    pub const FIELD_SIZES: [usize; 3] = [32, 32, 66];
6423    pub const FIELD_COUNT: usize = 3;
6424    pub fn channel_id(&self) -> Byte32 {
6425        Byte32::new_unchecked(self.0.slice(0..32))
6426    }
6427    pub fn funding_tx_partial_signature(&self) -> Byte32 {
6428        Byte32::new_unchecked(self.0.slice(32..64))
6429    }
6430    pub fn next_commitment_nonce(&self) -> PubNonce {
6431        PubNonce::new_unchecked(self.0.slice(64..130))
6432    }
6433    pub fn as_reader<'r>(&'r self) -> CommitmentSignedReader<'r> {
6434        CommitmentSignedReader::new_unchecked(self.as_slice())
6435    }
6436}
6437impl molecule::prelude::Entity for CommitmentSigned {
6438    type Builder = CommitmentSignedBuilder;
6439    const NAME: &'static str = "CommitmentSigned";
6440    fn new_unchecked(data: molecule::bytes::Bytes) -> Self {
6441        CommitmentSigned(data)
6442    }
6443    fn as_bytes(&self) -> molecule::bytes::Bytes {
6444        self.0.clone()
6445    }
6446    fn as_slice(&self) -> &[u8] {
6447        &self.0[..]
6448    }
6449    fn from_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
6450        CommitmentSignedReader::from_slice(slice).map(|reader| reader.to_entity())
6451    }
6452    fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
6453        CommitmentSignedReader::from_compatible_slice(slice).map(|reader| reader.to_entity())
6454    }
6455    fn new_builder() -> Self::Builder {
6456        ::core::default::Default::default()
6457    }
6458    fn as_builder(self) -> Self::Builder {
6459        Self::new_builder()
6460            .channel_id(self.channel_id())
6461            .funding_tx_partial_signature(self.funding_tx_partial_signature())
6462            .next_commitment_nonce(self.next_commitment_nonce())
6463    }
6464}
6465#[derive(Clone, Copy)]
6466pub struct CommitmentSignedReader<'r>(&'r [u8]);
6467impl<'r> ::core::fmt::LowerHex for CommitmentSignedReader<'r> {
6468    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
6469        use molecule::hex_string;
6470        if f.alternate() {
6471            write!(f, "0x")?;
6472        }
6473        write!(f, "{}", hex_string(self.as_slice()))
6474    }
6475}
6476impl<'r> ::core::fmt::Debug for CommitmentSignedReader<'r> {
6477    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
6478        write!(f, "{}({:#x})", Self::NAME, self)
6479    }
6480}
6481impl<'r> ::core::fmt::Display for CommitmentSignedReader<'r> {
6482    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
6483        write!(f, "{} {{ ", Self::NAME)?;
6484        write!(f, "{}: {}", "channel_id", self.channel_id())?;
6485        write!(
6486            f,
6487            ", {}: {}",
6488            "funding_tx_partial_signature",
6489            self.funding_tx_partial_signature()
6490        )?;
6491        write!(
6492            f,
6493            ", {}: {}",
6494            "next_commitment_nonce",
6495            self.next_commitment_nonce()
6496        )?;
6497        write!(f, " }}")
6498    }
6499}
6500impl<'r> CommitmentSignedReader<'r> {
6501    pub const TOTAL_SIZE: usize = 130;
6502    pub const FIELD_SIZES: [usize; 3] = [32, 32, 66];
6503    pub const FIELD_COUNT: usize = 3;
6504    pub fn channel_id(&self) -> Byte32Reader<'r> {
6505        Byte32Reader::new_unchecked(&self.as_slice()[0..32])
6506    }
6507    pub fn funding_tx_partial_signature(&self) -> Byte32Reader<'r> {
6508        Byte32Reader::new_unchecked(&self.as_slice()[32..64])
6509    }
6510    pub fn next_commitment_nonce(&self) -> PubNonceReader<'r> {
6511        PubNonceReader::new_unchecked(&self.as_slice()[64..130])
6512    }
6513}
6514impl<'r> molecule::prelude::Reader<'r> for CommitmentSignedReader<'r> {
6515    type Entity = CommitmentSigned;
6516    const NAME: &'static str = "CommitmentSignedReader";
6517    fn to_entity(&self) -> Self::Entity {
6518        Self::Entity::new_unchecked(self.as_slice().to_owned().into())
6519    }
6520    fn new_unchecked(slice: &'r [u8]) -> Self {
6521        CommitmentSignedReader(slice)
6522    }
6523    fn as_slice(&self) -> &'r [u8] {
6524        self.0
6525    }
6526    fn verify(slice: &[u8], _compatible: bool) -> molecule::error::VerificationResult<()> {
6527        use molecule::verification_error as ve;
6528        let slice_len = slice.len();
6529        if slice_len != Self::TOTAL_SIZE {
6530            return ve!(Self, TotalSizeNotMatch, Self::TOTAL_SIZE, slice_len);
6531        }
6532        Ok(())
6533    }
6534}
6535#[derive(Clone, Debug, Default)]
6536pub struct CommitmentSignedBuilder {
6537    pub(crate) channel_id: Byte32,
6538    pub(crate) funding_tx_partial_signature: Byte32,
6539    pub(crate) next_commitment_nonce: PubNonce,
6540}
6541impl CommitmentSignedBuilder {
6542    pub const TOTAL_SIZE: usize = 130;
6543    pub const FIELD_SIZES: [usize; 3] = [32, 32, 66];
6544    pub const FIELD_COUNT: usize = 3;
6545    pub fn channel_id(mut self, v: Byte32) -> Self {
6546        self.channel_id = v;
6547        self
6548    }
6549    pub fn funding_tx_partial_signature(mut self, v: Byte32) -> Self {
6550        self.funding_tx_partial_signature = v;
6551        self
6552    }
6553    pub fn next_commitment_nonce(mut self, v: PubNonce) -> Self {
6554        self.next_commitment_nonce = v;
6555        self
6556    }
6557}
6558impl molecule::prelude::Builder for CommitmentSignedBuilder {
6559    type Entity = CommitmentSigned;
6560    const NAME: &'static str = "CommitmentSignedBuilder";
6561    fn expected_length(&self) -> usize {
6562        Self::TOTAL_SIZE
6563    }
6564    fn write<W: molecule::io::Write>(&self, writer: &mut W) -> molecule::io::Result<()> {
6565        writer.write_all(self.channel_id.as_slice())?;
6566        writer.write_all(self.funding_tx_partial_signature.as_slice())?;
6567        writer.write_all(self.next_commitment_nonce.as_slice())?;
6568        Ok(())
6569    }
6570    fn build(&self) -> Self::Entity {
6571        let mut inner = Vec::with_capacity(self.expected_length());
6572        self.write(&mut inner)
6573            .unwrap_or_else(|_| panic!("{} build should be ok", Self::NAME));
6574        CommitmentSigned::new_unchecked(inner.into())
6575    }
6576}
6577#[derive(Clone)]
6578pub struct TxSignatures(molecule::bytes::Bytes);
6579impl ::core::fmt::LowerHex for TxSignatures {
6580    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
6581        use molecule::hex_string;
6582        if f.alternate() {
6583            write!(f, "0x")?;
6584        }
6585        write!(f, "{}", hex_string(self.as_slice()))
6586    }
6587}
6588impl ::core::fmt::Debug for TxSignatures {
6589    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
6590        write!(f, "{}({:#x})", Self::NAME, self)
6591    }
6592}
6593impl ::core::fmt::Display for TxSignatures {
6594    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
6595        write!(f, "{} {{ ", Self::NAME)?;
6596        write!(f, "{}: {}", "channel_id", self.channel_id())?;
6597        write!(f, ", {}: {}", "witnesses", self.witnesses())?;
6598        let extra_count = self.count_extra_fields();
6599        if extra_count != 0 {
6600            write!(f, ", .. ({} fields)", extra_count)?;
6601        }
6602        write!(f, " }}")
6603    }
6604}
6605impl ::core::default::Default for TxSignatures {
6606    fn default() -> Self {
6607        let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE);
6608        TxSignatures::new_unchecked(v)
6609    }
6610}
6611impl TxSignatures {
6612    const DEFAULT_VALUE: [u8; 48] = [
6613        48, 0, 0, 0, 12, 0, 0, 0, 44, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
6614        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0,
6615    ];
6616    pub const FIELD_COUNT: usize = 2;
6617    pub fn total_size(&self) -> usize {
6618        molecule::unpack_number(self.as_slice()) as usize
6619    }
6620    pub fn field_count(&self) -> usize {
6621        if self.total_size() == molecule::NUMBER_SIZE {
6622            0
6623        } else {
6624            (molecule::unpack_number(&self.as_slice()[molecule::NUMBER_SIZE..]) as usize / 4) - 1
6625        }
6626    }
6627    pub fn count_extra_fields(&self) -> usize {
6628        self.field_count() - Self::FIELD_COUNT
6629    }
6630    pub fn has_extra_fields(&self) -> bool {
6631        Self::FIELD_COUNT != self.field_count()
6632    }
6633    pub fn channel_id(&self) -> Byte32 {
6634        let slice = self.as_slice();
6635        let start = molecule::unpack_number(&slice[4..]) as usize;
6636        let end = molecule::unpack_number(&slice[8..]) as usize;
6637        Byte32::new_unchecked(self.0.slice(start..end))
6638    }
6639    pub fn witnesses(&self) -> BytesVec {
6640        let slice = self.as_slice();
6641        let start = molecule::unpack_number(&slice[8..]) as usize;
6642        if self.has_extra_fields() {
6643            let end = molecule::unpack_number(&slice[12..]) as usize;
6644            BytesVec::new_unchecked(self.0.slice(start..end))
6645        } else {
6646            BytesVec::new_unchecked(self.0.slice(start..))
6647        }
6648    }
6649    pub fn as_reader<'r>(&'r self) -> TxSignaturesReader<'r> {
6650        TxSignaturesReader::new_unchecked(self.as_slice())
6651    }
6652}
6653impl molecule::prelude::Entity for TxSignatures {
6654    type Builder = TxSignaturesBuilder;
6655    const NAME: &'static str = "TxSignatures";
6656    fn new_unchecked(data: molecule::bytes::Bytes) -> Self {
6657        TxSignatures(data)
6658    }
6659    fn as_bytes(&self) -> molecule::bytes::Bytes {
6660        self.0.clone()
6661    }
6662    fn as_slice(&self) -> &[u8] {
6663        &self.0[..]
6664    }
6665    fn from_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
6666        TxSignaturesReader::from_slice(slice).map(|reader| reader.to_entity())
6667    }
6668    fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
6669        TxSignaturesReader::from_compatible_slice(slice).map(|reader| reader.to_entity())
6670    }
6671    fn new_builder() -> Self::Builder {
6672        ::core::default::Default::default()
6673    }
6674    fn as_builder(self) -> Self::Builder {
6675        Self::new_builder()
6676            .channel_id(self.channel_id())
6677            .witnesses(self.witnesses())
6678    }
6679}
6680#[derive(Clone, Copy)]
6681pub struct TxSignaturesReader<'r>(&'r [u8]);
6682impl<'r> ::core::fmt::LowerHex for TxSignaturesReader<'r> {
6683    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
6684        use molecule::hex_string;
6685        if f.alternate() {
6686            write!(f, "0x")?;
6687        }
6688        write!(f, "{}", hex_string(self.as_slice()))
6689    }
6690}
6691impl<'r> ::core::fmt::Debug for TxSignaturesReader<'r> {
6692    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
6693        write!(f, "{}({:#x})", Self::NAME, self)
6694    }
6695}
6696impl<'r> ::core::fmt::Display for TxSignaturesReader<'r> {
6697    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
6698        write!(f, "{} {{ ", Self::NAME)?;
6699        write!(f, "{}: {}", "channel_id", self.channel_id())?;
6700        write!(f, ", {}: {}", "witnesses", self.witnesses())?;
6701        let extra_count = self.count_extra_fields();
6702        if extra_count != 0 {
6703            write!(f, ", .. ({} fields)", extra_count)?;
6704        }
6705        write!(f, " }}")
6706    }
6707}
6708impl<'r> TxSignaturesReader<'r> {
6709    pub const FIELD_COUNT: usize = 2;
6710    pub fn total_size(&self) -> usize {
6711        molecule::unpack_number(self.as_slice()) as usize
6712    }
6713    pub fn field_count(&self) -> usize {
6714        if self.total_size() == molecule::NUMBER_SIZE {
6715            0
6716        } else {
6717            (molecule::unpack_number(&self.as_slice()[molecule::NUMBER_SIZE..]) as usize / 4) - 1
6718        }
6719    }
6720    pub fn count_extra_fields(&self) -> usize {
6721        self.field_count() - Self::FIELD_COUNT
6722    }
6723    pub fn has_extra_fields(&self) -> bool {
6724        Self::FIELD_COUNT != self.field_count()
6725    }
6726    pub fn channel_id(&self) -> Byte32Reader<'r> {
6727        let slice = self.as_slice();
6728        let start = molecule::unpack_number(&slice[4..]) as usize;
6729        let end = molecule::unpack_number(&slice[8..]) as usize;
6730        Byte32Reader::new_unchecked(&self.as_slice()[start..end])
6731    }
6732    pub fn witnesses(&self) -> BytesVecReader<'r> {
6733        let slice = self.as_slice();
6734        let start = molecule::unpack_number(&slice[8..]) as usize;
6735        if self.has_extra_fields() {
6736            let end = molecule::unpack_number(&slice[12..]) as usize;
6737            BytesVecReader::new_unchecked(&self.as_slice()[start..end])
6738        } else {
6739            BytesVecReader::new_unchecked(&self.as_slice()[start..])
6740        }
6741    }
6742}
6743impl<'r> molecule::prelude::Reader<'r> for TxSignaturesReader<'r> {
6744    type Entity = TxSignatures;
6745    const NAME: &'static str = "TxSignaturesReader";
6746    fn to_entity(&self) -> Self::Entity {
6747        Self::Entity::new_unchecked(self.as_slice().to_owned().into())
6748    }
6749    fn new_unchecked(slice: &'r [u8]) -> Self {
6750        TxSignaturesReader(slice)
6751    }
6752    fn as_slice(&self) -> &'r [u8] {
6753        self.0
6754    }
6755    fn verify(slice: &[u8], compatible: bool) -> molecule::error::VerificationResult<()> {
6756        use molecule::verification_error as ve;
6757        let slice_len = slice.len();
6758        if slice_len < molecule::NUMBER_SIZE {
6759            return ve!(Self, HeaderIsBroken, molecule::NUMBER_SIZE, slice_len);
6760        }
6761        let total_size = molecule::unpack_number(slice) as usize;
6762        if slice_len != total_size {
6763            return ve!(Self, TotalSizeNotMatch, total_size, slice_len);
6764        }
6765        if slice_len < molecule::NUMBER_SIZE * 2 {
6766            return ve!(Self, HeaderIsBroken, molecule::NUMBER_SIZE * 2, slice_len);
6767        }
6768        let offset_first = molecule::unpack_number(&slice[molecule::NUMBER_SIZE..]) as usize;
6769        if offset_first % molecule::NUMBER_SIZE != 0 || offset_first < molecule::NUMBER_SIZE * 2 {
6770            return ve!(Self, OffsetsNotMatch);
6771        }
6772        if slice_len < offset_first {
6773            return ve!(Self, HeaderIsBroken, offset_first, slice_len);
6774        }
6775        let field_count = offset_first / molecule::NUMBER_SIZE - 1;
6776        if field_count < Self::FIELD_COUNT {
6777            return ve!(Self, FieldCountNotMatch, Self::FIELD_COUNT, field_count);
6778        } else if !compatible && field_count > Self::FIELD_COUNT {
6779            return ve!(Self, FieldCountNotMatch, Self::FIELD_COUNT, field_count);
6780        };
6781        let mut offsets: Vec<usize> = slice[molecule::NUMBER_SIZE..offset_first]
6782            .chunks_exact(molecule::NUMBER_SIZE)
6783            .map(|x| molecule::unpack_number(x) as usize)
6784            .collect();
6785        offsets.push(total_size);
6786        if offsets.windows(2).any(|i| i[0] > i[1]) {
6787            return ve!(Self, OffsetsNotMatch);
6788        }
6789        Byte32Reader::verify(&slice[offsets[0]..offsets[1]], compatible)?;
6790        BytesVecReader::verify(&slice[offsets[1]..offsets[2]], compatible)?;
6791        Ok(())
6792    }
6793}
6794#[derive(Clone, Debug, Default)]
6795pub struct TxSignaturesBuilder {
6796    pub(crate) channel_id: Byte32,
6797    pub(crate) witnesses: BytesVec,
6798}
6799impl TxSignaturesBuilder {
6800    pub const FIELD_COUNT: usize = 2;
6801    pub fn channel_id(mut self, v: Byte32) -> Self {
6802        self.channel_id = v;
6803        self
6804    }
6805    pub fn witnesses(mut self, v: BytesVec) -> Self {
6806        self.witnesses = v;
6807        self
6808    }
6809}
6810impl molecule::prelude::Builder for TxSignaturesBuilder {
6811    type Entity = TxSignatures;
6812    const NAME: &'static str = "TxSignaturesBuilder";
6813    fn expected_length(&self) -> usize {
6814        molecule::NUMBER_SIZE * (Self::FIELD_COUNT + 1)
6815            + self.channel_id.as_slice().len()
6816            + self.witnesses.as_slice().len()
6817    }
6818    fn write<W: molecule::io::Write>(&self, writer: &mut W) -> molecule::io::Result<()> {
6819        let mut total_size = molecule::NUMBER_SIZE * (Self::FIELD_COUNT + 1);
6820        let mut offsets = Vec::with_capacity(Self::FIELD_COUNT);
6821        offsets.push(total_size);
6822        total_size += self.channel_id.as_slice().len();
6823        offsets.push(total_size);
6824        total_size += self.witnesses.as_slice().len();
6825        writer.write_all(&molecule::pack_number(total_size as molecule::Number))?;
6826        for offset in offsets.into_iter() {
6827            writer.write_all(&molecule::pack_number(offset as molecule::Number))?;
6828        }
6829        writer.write_all(self.channel_id.as_slice())?;
6830        writer.write_all(self.witnesses.as_slice())?;
6831        Ok(())
6832    }
6833    fn build(&self) -> Self::Entity {
6834        let mut inner = Vec::with_capacity(self.expected_length());
6835        self.write(&mut inner)
6836            .unwrap_or_else(|_| panic!("{} build should be ok", Self::NAME));
6837        TxSignatures::new_unchecked(inner.into())
6838    }
6839}
6840#[derive(Clone)]
6841pub struct ChannelReady(molecule::bytes::Bytes);
6842impl ::core::fmt::LowerHex for ChannelReady {
6843    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
6844        use molecule::hex_string;
6845        if f.alternate() {
6846            write!(f, "0x")?;
6847        }
6848        write!(f, "{}", hex_string(self.as_slice()))
6849    }
6850}
6851impl ::core::fmt::Debug for ChannelReady {
6852    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
6853        write!(f, "{}({:#x})", Self::NAME, self)
6854    }
6855}
6856impl ::core::fmt::Display for ChannelReady {
6857    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
6858        write!(f, "{} {{ ", Self::NAME)?;
6859        write!(f, "{}: {}", "channel_id", self.channel_id())?;
6860        write!(f, " }}")
6861    }
6862}
6863impl ::core::default::Default for ChannelReady {
6864    fn default() -> Self {
6865        let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE);
6866        ChannelReady::new_unchecked(v)
6867    }
6868}
6869impl ChannelReady {
6870    const DEFAULT_VALUE: [u8; 32] = [
6871        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,
6872        0, 0,
6873    ];
6874    pub const TOTAL_SIZE: usize = 32;
6875    pub const FIELD_SIZES: [usize; 1] = [32];
6876    pub const FIELD_COUNT: usize = 1;
6877    pub fn channel_id(&self) -> Byte32 {
6878        Byte32::new_unchecked(self.0.slice(0..32))
6879    }
6880    pub fn as_reader<'r>(&'r self) -> ChannelReadyReader<'r> {
6881        ChannelReadyReader::new_unchecked(self.as_slice())
6882    }
6883}
6884impl molecule::prelude::Entity for ChannelReady {
6885    type Builder = ChannelReadyBuilder;
6886    const NAME: &'static str = "ChannelReady";
6887    fn new_unchecked(data: molecule::bytes::Bytes) -> Self {
6888        ChannelReady(data)
6889    }
6890    fn as_bytes(&self) -> molecule::bytes::Bytes {
6891        self.0.clone()
6892    }
6893    fn as_slice(&self) -> &[u8] {
6894        &self.0[..]
6895    }
6896    fn from_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
6897        ChannelReadyReader::from_slice(slice).map(|reader| reader.to_entity())
6898    }
6899    fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
6900        ChannelReadyReader::from_compatible_slice(slice).map(|reader| reader.to_entity())
6901    }
6902    fn new_builder() -> Self::Builder {
6903        ::core::default::Default::default()
6904    }
6905    fn as_builder(self) -> Self::Builder {
6906        Self::new_builder().channel_id(self.channel_id())
6907    }
6908}
6909#[derive(Clone, Copy)]
6910pub struct ChannelReadyReader<'r>(&'r [u8]);
6911impl<'r> ::core::fmt::LowerHex for ChannelReadyReader<'r> {
6912    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
6913        use molecule::hex_string;
6914        if f.alternate() {
6915            write!(f, "0x")?;
6916        }
6917        write!(f, "{}", hex_string(self.as_slice()))
6918    }
6919}
6920impl<'r> ::core::fmt::Debug for ChannelReadyReader<'r> {
6921    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
6922        write!(f, "{}({:#x})", Self::NAME, self)
6923    }
6924}
6925impl<'r> ::core::fmt::Display for ChannelReadyReader<'r> {
6926    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
6927        write!(f, "{} {{ ", Self::NAME)?;
6928        write!(f, "{}: {}", "channel_id", self.channel_id())?;
6929        write!(f, " }}")
6930    }
6931}
6932impl<'r> ChannelReadyReader<'r> {
6933    pub const TOTAL_SIZE: usize = 32;
6934    pub const FIELD_SIZES: [usize; 1] = [32];
6935    pub const FIELD_COUNT: usize = 1;
6936    pub fn channel_id(&self) -> Byte32Reader<'r> {
6937        Byte32Reader::new_unchecked(&self.as_slice()[0..32])
6938    }
6939}
6940impl<'r> molecule::prelude::Reader<'r> for ChannelReadyReader<'r> {
6941    type Entity = ChannelReady;
6942    const NAME: &'static str = "ChannelReadyReader";
6943    fn to_entity(&self) -> Self::Entity {
6944        Self::Entity::new_unchecked(self.as_slice().to_owned().into())
6945    }
6946    fn new_unchecked(slice: &'r [u8]) -> Self {
6947        ChannelReadyReader(slice)
6948    }
6949    fn as_slice(&self) -> &'r [u8] {
6950        self.0
6951    }
6952    fn verify(slice: &[u8], _compatible: bool) -> molecule::error::VerificationResult<()> {
6953        use molecule::verification_error as ve;
6954        let slice_len = slice.len();
6955        if slice_len != Self::TOTAL_SIZE {
6956            return ve!(Self, TotalSizeNotMatch, Self::TOTAL_SIZE, slice_len);
6957        }
6958        Ok(())
6959    }
6960}
6961#[derive(Clone, Debug, Default)]
6962pub struct ChannelReadyBuilder {
6963    pub(crate) channel_id: Byte32,
6964}
6965impl ChannelReadyBuilder {
6966    pub const TOTAL_SIZE: usize = 32;
6967    pub const FIELD_SIZES: [usize; 1] = [32];
6968    pub const FIELD_COUNT: usize = 1;
6969    pub fn channel_id(mut self, v: Byte32) -> Self {
6970        self.channel_id = v;
6971        self
6972    }
6973}
6974impl molecule::prelude::Builder for ChannelReadyBuilder {
6975    type Entity = ChannelReady;
6976    const NAME: &'static str = "ChannelReadyBuilder";
6977    fn expected_length(&self) -> usize {
6978        Self::TOTAL_SIZE
6979    }
6980    fn write<W: molecule::io::Write>(&self, writer: &mut W) -> molecule::io::Result<()> {
6981        writer.write_all(self.channel_id.as_slice())?;
6982        Ok(())
6983    }
6984    fn build(&self) -> Self::Entity {
6985        let mut inner = Vec::with_capacity(self.expected_length());
6986        self.write(&mut inner)
6987            .unwrap_or_else(|_| panic!("{} build should be ok", Self::NAME));
6988        ChannelReady::new_unchecked(inner.into())
6989    }
6990}
6991#[derive(Clone)]
6992pub struct TxUpdate(molecule::bytes::Bytes);
6993impl ::core::fmt::LowerHex for TxUpdate {
6994    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
6995        use molecule::hex_string;
6996        if f.alternate() {
6997            write!(f, "0x")?;
6998        }
6999        write!(f, "{}", hex_string(self.as_slice()))
7000    }
7001}
7002impl ::core::fmt::Debug for TxUpdate {
7003    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
7004        write!(f, "{}({:#x})", Self::NAME, self)
7005    }
7006}
7007impl ::core::fmt::Display for TxUpdate {
7008    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
7009        write!(f, "{} {{ ", Self::NAME)?;
7010        write!(f, "{}: {}", "channel_id", self.channel_id())?;
7011        write!(f, ", {}: {}", "tx", self.tx())?;
7012        let extra_count = self.count_extra_fields();
7013        if extra_count != 0 {
7014            write!(f, ", .. ({} fields)", extra_count)?;
7015        }
7016        write!(f, " }}")
7017    }
7018}
7019impl ::core::default::Default for TxUpdate {
7020    fn default() -> Self {
7021        let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE);
7022        TxUpdate::new_unchecked(v)
7023    }
7024}
7025impl TxUpdate {
7026    const DEFAULT_VALUE: [u8; 112] = [
7027        112, 0, 0, 0, 12, 0, 0, 0, 44, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
7028        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 68, 0, 0, 0, 12, 0, 0, 0, 64, 0, 0, 0, 52, 0,
7029        0, 0, 28, 0, 0, 0, 32, 0, 0, 0, 36, 0, 0, 0, 40, 0, 0, 0, 44, 0, 0, 0, 48, 0, 0, 0, 0, 0,
7030        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 4, 0, 0, 0, 4, 0, 0, 0,
7031    ];
7032    pub const FIELD_COUNT: usize = 2;
7033    pub fn total_size(&self) -> usize {
7034        molecule::unpack_number(self.as_slice()) as usize
7035    }
7036    pub fn field_count(&self) -> usize {
7037        if self.total_size() == molecule::NUMBER_SIZE {
7038            0
7039        } else {
7040            (molecule::unpack_number(&self.as_slice()[molecule::NUMBER_SIZE..]) as usize / 4) - 1
7041        }
7042    }
7043    pub fn count_extra_fields(&self) -> usize {
7044        self.field_count() - Self::FIELD_COUNT
7045    }
7046    pub fn has_extra_fields(&self) -> bool {
7047        Self::FIELD_COUNT != self.field_count()
7048    }
7049    pub fn channel_id(&self) -> Byte32 {
7050        let slice = self.as_slice();
7051        let start = molecule::unpack_number(&slice[4..]) as usize;
7052        let end = molecule::unpack_number(&slice[8..]) as usize;
7053        Byte32::new_unchecked(self.0.slice(start..end))
7054    }
7055    pub fn tx(&self) -> Transaction {
7056        let slice = self.as_slice();
7057        let start = molecule::unpack_number(&slice[8..]) as usize;
7058        if self.has_extra_fields() {
7059            let end = molecule::unpack_number(&slice[12..]) as usize;
7060            Transaction::new_unchecked(self.0.slice(start..end))
7061        } else {
7062            Transaction::new_unchecked(self.0.slice(start..))
7063        }
7064    }
7065    pub fn as_reader<'r>(&'r self) -> TxUpdateReader<'r> {
7066        TxUpdateReader::new_unchecked(self.as_slice())
7067    }
7068}
7069impl molecule::prelude::Entity for TxUpdate {
7070    type Builder = TxUpdateBuilder;
7071    const NAME: &'static str = "TxUpdate";
7072    fn new_unchecked(data: molecule::bytes::Bytes) -> Self {
7073        TxUpdate(data)
7074    }
7075    fn as_bytes(&self) -> molecule::bytes::Bytes {
7076        self.0.clone()
7077    }
7078    fn as_slice(&self) -> &[u8] {
7079        &self.0[..]
7080    }
7081    fn from_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
7082        TxUpdateReader::from_slice(slice).map(|reader| reader.to_entity())
7083    }
7084    fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
7085        TxUpdateReader::from_compatible_slice(slice).map(|reader| reader.to_entity())
7086    }
7087    fn new_builder() -> Self::Builder {
7088        ::core::default::Default::default()
7089    }
7090    fn as_builder(self) -> Self::Builder {
7091        Self::new_builder()
7092            .channel_id(self.channel_id())
7093            .tx(self.tx())
7094    }
7095}
7096#[derive(Clone, Copy)]
7097pub struct TxUpdateReader<'r>(&'r [u8]);
7098impl<'r> ::core::fmt::LowerHex for TxUpdateReader<'r> {
7099    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
7100        use molecule::hex_string;
7101        if f.alternate() {
7102            write!(f, "0x")?;
7103        }
7104        write!(f, "{}", hex_string(self.as_slice()))
7105    }
7106}
7107impl<'r> ::core::fmt::Debug for TxUpdateReader<'r> {
7108    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
7109        write!(f, "{}({:#x})", Self::NAME, self)
7110    }
7111}
7112impl<'r> ::core::fmt::Display for TxUpdateReader<'r> {
7113    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
7114        write!(f, "{} {{ ", Self::NAME)?;
7115        write!(f, "{}: {}", "channel_id", self.channel_id())?;
7116        write!(f, ", {}: {}", "tx", self.tx())?;
7117        let extra_count = self.count_extra_fields();
7118        if extra_count != 0 {
7119            write!(f, ", .. ({} fields)", extra_count)?;
7120        }
7121        write!(f, " }}")
7122    }
7123}
7124impl<'r> TxUpdateReader<'r> {
7125    pub const FIELD_COUNT: usize = 2;
7126    pub fn total_size(&self) -> usize {
7127        molecule::unpack_number(self.as_slice()) as usize
7128    }
7129    pub fn field_count(&self) -> usize {
7130        if self.total_size() == molecule::NUMBER_SIZE {
7131            0
7132        } else {
7133            (molecule::unpack_number(&self.as_slice()[molecule::NUMBER_SIZE..]) as usize / 4) - 1
7134        }
7135    }
7136    pub fn count_extra_fields(&self) -> usize {
7137        self.field_count() - Self::FIELD_COUNT
7138    }
7139    pub fn has_extra_fields(&self) -> bool {
7140        Self::FIELD_COUNT != self.field_count()
7141    }
7142    pub fn channel_id(&self) -> Byte32Reader<'r> {
7143        let slice = self.as_slice();
7144        let start = molecule::unpack_number(&slice[4..]) as usize;
7145        let end = molecule::unpack_number(&slice[8..]) as usize;
7146        Byte32Reader::new_unchecked(&self.as_slice()[start..end])
7147    }
7148    pub fn tx(&self) -> TransactionReader<'r> {
7149        let slice = self.as_slice();
7150        let start = molecule::unpack_number(&slice[8..]) as usize;
7151        if self.has_extra_fields() {
7152            let end = molecule::unpack_number(&slice[12..]) as usize;
7153            TransactionReader::new_unchecked(&self.as_slice()[start..end])
7154        } else {
7155            TransactionReader::new_unchecked(&self.as_slice()[start..])
7156        }
7157    }
7158}
7159impl<'r> molecule::prelude::Reader<'r> for TxUpdateReader<'r> {
7160    type Entity = TxUpdate;
7161    const NAME: &'static str = "TxUpdateReader";
7162    fn to_entity(&self) -> Self::Entity {
7163        Self::Entity::new_unchecked(self.as_slice().to_owned().into())
7164    }
7165    fn new_unchecked(slice: &'r [u8]) -> Self {
7166        TxUpdateReader(slice)
7167    }
7168    fn as_slice(&self) -> &'r [u8] {
7169        self.0
7170    }
7171    fn verify(slice: &[u8], compatible: bool) -> molecule::error::VerificationResult<()> {
7172        use molecule::verification_error as ve;
7173        let slice_len = slice.len();
7174        if slice_len < molecule::NUMBER_SIZE {
7175            return ve!(Self, HeaderIsBroken, molecule::NUMBER_SIZE, slice_len);
7176        }
7177        let total_size = molecule::unpack_number(slice) as usize;
7178        if slice_len != total_size {
7179            return ve!(Self, TotalSizeNotMatch, total_size, slice_len);
7180        }
7181        if slice_len < molecule::NUMBER_SIZE * 2 {
7182            return ve!(Self, HeaderIsBroken, molecule::NUMBER_SIZE * 2, slice_len);
7183        }
7184        let offset_first = molecule::unpack_number(&slice[molecule::NUMBER_SIZE..]) as usize;
7185        if offset_first % molecule::NUMBER_SIZE != 0 || offset_first < molecule::NUMBER_SIZE * 2 {
7186            return ve!(Self, OffsetsNotMatch);
7187        }
7188        if slice_len < offset_first {
7189            return ve!(Self, HeaderIsBroken, offset_first, slice_len);
7190        }
7191        let field_count = offset_first / molecule::NUMBER_SIZE - 1;
7192        if field_count < Self::FIELD_COUNT {
7193            return ve!(Self, FieldCountNotMatch, Self::FIELD_COUNT, field_count);
7194        } else if !compatible && field_count > Self::FIELD_COUNT {
7195            return ve!(Self, FieldCountNotMatch, Self::FIELD_COUNT, field_count);
7196        };
7197        let mut offsets: Vec<usize> = slice[molecule::NUMBER_SIZE..offset_first]
7198            .chunks_exact(molecule::NUMBER_SIZE)
7199            .map(|x| molecule::unpack_number(x) as usize)
7200            .collect();
7201        offsets.push(total_size);
7202        if offsets.windows(2).any(|i| i[0] > i[1]) {
7203            return ve!(Self, OffsetsNotMatch);
7204        }
7205        Byte32Reader::verify(&slice[offsets[0]..offsets[1]], compatible)?;
7206        TransactionReader::verify(&slice[offsets[1]..offsets[2]], compatible)?;
7207        Ok(())
7208    }
7209}
7210#[derive(Clone, Debug, Default)]
7211pub struct TxUpdateBuilder {
7212    pub(crate) channel_id: Byte32,
7213    pub(crate) tx: Transaction,
7214}
7215impl TxUpdateBuilder {
7216    pub const FIELD_COUNT: usize = 2;
7217    pub fn channel_id(mut self, v: Byte32) -> Self {
7218        self.channel_id = v;
7219        self
7220    }
7221    pub fn tx(mut self, v: Transaction) -> Self {
7222        self.tx = v;
7223        self
7224    }
7225}
7226impl molecule::prelude::Builder for TxUpdateBuilder {
7227    type Entity = TxUpdate;
7228    const NAME: &'static str = "TxUpdateBuilder";
7229    fn expected_length(&self) -> usize {
7230        molecule::NUMBER_SIZE * (Self::FIELD_COUNT + 1)
7231            + self.channel_id.as_slice().len()
7232            + self.tx.as_slice().len()
7233    }
7234    fn write<W: molecule::io::Write>(&self, writer: &mut W) -> molecule::io::Result<()> {
7235        let mut total_size = molecule::NUMBER_SIZE * (Self::FIELD_COUNT + 1);
7236        let mut offsets = Vec::with_capacity(Self::FIELD_COUNT);
7237        offsets.push(total_size);
7238        total_size += self.channel_id.as_slice().len();
7239        offsets.push(total_size);
7240        total_size += self.tx.as_slice().len();
7241        writer.write_all(&molecule::pack_number(total_size as molecule::Number))?;
7242        for offset in offsets.into_iter() {
7243            writer.write_all(&molecule::pack_number(offset as molecule::Number))?;
7244        }
7245        writer.write_all(self.channel_id.as_slice())?;
7246        writer.write_all(self.tx.as_slice())?;
7247        Ok(())
7248    }
7249    fn build(&self) -> Self::Entity {
7250        let mut inner = Vec::with_capacity(self.expected_length());
7251        self.write(&mut inner)
7252            .unwrap_or_else(|_| panic!("{} build should be ok", Self::NAME));
7253        TxUpdate::new_unchecked(inner.into())
7254    }
7255}
7256#[derive(Clone)]
7257pub struct TxComplete(molecule::bytes::Bytes);
7258impl ::core::fmt::LowerHex for TxComplete {
7259    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
7260        use molecule::hex_string;
7261        if f.alternate() {
7262            write!(f, "0x")?;
7263        }
7264        write!(f, "{}", hex_string(self.as_slice()))
7265    }
7266}
7267impl ::core::fmt::Debug for TxComplete {
7268    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
7269        write!(f, "{}({:#x})", Self::NAME, self)
7270    }
7271}
7272impl ::core::fmt::Display for TxComplete {
7273    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
7274        write!(f, "{} {{ ", Self::NAME)?;
7275        write!(f, "{}: {}", "channel_id", self.channel_id())?;
7276        write!(
7277            f,
7278            ", {}: {}",
7279            "next_commitment_nonce",
7280            self.next_commitment_nonce()
7281        )?;
7282        write!(f, " }}")
7283    }
7284}
7285impl ::core::default::Default for TxComplete {
7286    fn default() -> Self {
7287        let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE);
7288        TxComplete::new_unchecked(v)
7289    }
7290}
7291impl TxComplete {
7292    const DEFAULT_VALUE: [u8; 98] = [
7293        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,
7294        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,
7295        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,
7296        0, 0, 0, 0, 0, 0, 0, 0,
7297    ];
7298    pub const TOTAL_SIZE: usize = 98;
7299    pub const FIELD_SIZES: [usize; 2] = [32, 66];
7300    pub const FIELD_COUNT: usize = 2;
7301    pub fn channel_id(&self) -> Byte32 {
7302        Byte32::new_unchecked(self.0.slice(0..32))
7303    }
7304    pub fn next_commitment_nonce(&self) -> PubNonce {
7305        PubNonce::new_unchecked(self.0.slice(32..98))
7306    }
7307    pub fn as_reader<'r>(&'r self) -> TxCompleteReader<'r> {
7308        TxCompleteReader::new_unchecked(self.as_slice())
7309    }
7310}
7311impl molecule::prelude::Entity for TxComplete {
7312    type Builder = TxCompleteBuilder;
7313    const NAME: &'static str = "TxComplete";
7314    fn new_unchecked(data: molecule::bytes::Bytes) -> Self {
7315        TxComplete(data)
7316    }
7317    fn as_bytes(&self) -> molecule::bytes::Bytes {
7318        self.0.clone()
7319    }
7320    fn as_slice(&self) -> &[u8] {
7321        &self.0[..]
7322    }
7323    fn from_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
7324        TxCompleteReader::from_slice(slice).map(|reader| reader.to_entity())
7325    }
7326    fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
7327        TxCompleteReader::from_compatible_slice(slice).map(|reader| reader.to_entity())
7328    }
7329    fn new_builder() -> Self::Builder {
7330        ::core::default::Default::default()
7331    }
7332    fn as_builder(self) -> Self::Builder {
7333        Self::new_builder()
7334            .channel_id(self.channel_id())
7335            .next_commitment_nonce(self.next_commitment_nonce())
7336    }
7337}
7338#[derive(Clone, Copy)]
7339pub struct TxCompleteReader<'r>(&'r [u8]);
7340impl<'r> ::core::fmt::LowerHex for TxCompleteReader<'r> {
7341    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
7342        use molecule::hex_string;
7343        if f.alternate() {
7344            write!(f, "0x")?;
7345        }
7346        write!(f, "{}", hex_string(self.as_slice()))
7347    }
7348}
7349impl<'r> ::core::fmt::Debug for TxCompleteReader<'r> {
7350    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
7351        write!(f, "{}({:#x})", Self::NAME, self)
7352    }
7353}
7354impl<'r> ::core::fmt::Display for TxCompleteReader<'r> {
7355    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
7356        write!(f, "{} {{ ", Self::NAME)?;
7357        write!(f, "{}: {}", "channel_id", self.channel_id())?;
7358        write!(
7359            f,
7360            ", {}: {}",
7361            "next_commitment_nonce",
7362            self.next_commitment_nonce()
7363        )?;
7364        write!(f, " }}")
7365    }
7366}
7367impl<'r> TxCompleteReader<'r> {
7368    pub const TOTAL_SIZE: usize = 98;
7369    pub const FIELD_SIZES: [usize; 2] = [32, 66];
7370    pub const FIELD_COUNT: usize = 2;
7371    pub fn channel_id(&self) -> Byte32Reader<'r> {
7372        Byte32Reader::new_unchecked(&self.as_slice()[0..32])
7373    }
7374    pub fn next_commitment_nonce(&self) -> PubNonceReader<'r> {
7375        PubNonceReader::new_unchecked(&self.as_slice()[32..98])
7376    }
7377}
7378impl<'r> molecule::prelude::Reader<'r> for TxCompleteReader<'r> {
7379    type Entity = TxComplete;
7380    const NAME: &'static str = "TxCompleteReader";
7381    fn to_entity(&self) -> Self::Entity {
7382        Self::Entity::new_unchecked(self.as_slice().to_owned().into())
7383    }
7384    fn new_unchecked(slice: &'r [u8]) -> Self {
7385        TxCompleteReader(slice)
7386    }
7387    fn as_slice(&self) -> &'r [u8] {
7388        self.0
7389    }
7390    fn verify(slice: &[u8], _compatible: bool) -> molecule::error::VerificationResult<()> {
7391        use molecule::verification_error as ve;
7392        let slice_len = slice.len();
7393        if slice_len != Self::TOTAL_SIZE {
7394            return ve!(Self, TotalSizeNotMatch, Self::TOTAL_SIZE, slice_len);
7395        }
7396        Ok(())
7397    }
7398}
7399#[derive(Clone, Debug, Default)]
7400pub struct TxCompleteBuilder {
7401    pub(crate) channel_id: Byte32,
7402    pub(crate) next_commitment_nonce: PubNonce,
7403}
7404impl TxCompleteBuilder {
7405    pub const TOTAL_SIZE: usize = 98;
7406    pub const FIELD_SIZES: [usize; 2] = [32, 66];
7407    pub const FIELD_COUNT: usize = 2;
7408    pub fn channel_id(mut self, v: Byte32) -> Self {
7409        self.channel_id = v;
7410        self
7411    }
7412    pub fn next_commitment_nonce(mut self, v: PubNonce) -> Self {
7413        self.next_commitment_nonce = v;
7414        self
7415    }
7416}
7417impl molecule::prelude::Builder for TxCompleteBuilder {
7418    type Entity = TxComplete;
7419    const NAME: &'static str = "TxCompleteBuilder";
7420    fn expected_length(&self) -> usize {
7421        Self::TOTAL_SIZE
7422    }
7423    fn write<W: molecule::io::Write>(&self, writer: &mut W) -> molecule::io::Result<()> {
7424        writer.write_all(self.channel_id.as_slice())?;
7425        writer.write_all(self.next_commitment_nonce.as_slice())?;
7426        Ok(())
7427    }
7428    fn build(&self) -> Self::Entity {
7429        let mut inner = Vec::with_capacity(self.expected_length());
7430        self.write(&mut inner)
7431            .unwrap_or_else(|_| panic!("{} build should be ok", Self::NAME));
7432        TxComplete::new_unchecked(inner.into())
7433    }
7434}
7435#[derive(Clone)]
7436pub struct TxAbort(molecule::bytes::Bytes);
7437impl ::core::fmt::LowerHex for TxAbort {
7438    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
7439        use molecule::hex_string;
7440        if f.alternate() {
7441            write!(f, "0x")?;
7442        }
7443        write!(f, "{}", hex_string(self.as_slice()))
7444    }
7445}
7446impl ::core::fmt::Debug for TxAbort {
7447    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
7448        write!(f, "{}({:#x})", Self::NAME, self)
7449    }
7450}
7451impl ::core::fmt::Display for TxAbort {
7452    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
7453        write!(f, "{} {{ ", Self::NAME)?;
7454        write!(f, "{}: {}", "channel_id", self.channel_id())?;
7455        write!(f, ", {}: {}", "message", self.message())?;
7456        let extra_count = self.count_extra_fields();
7457        if extra_count != 0 {
7458            write!(f, ", .. ({} fields)", extra_count)?;
7459        }
7460        write!(f, " }}")
7461    }
7462}
7463impl ::core::default::Default for TxAbort {
7464    fn default() -> Self {
7465        let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE);
7466        TxAbort::new_unchecked(v)
7467    }
7468}
7469impl TxAbort {
7470    const DEFAULT_VALUE: [u8; 48] = [
7471        48, 0, 0, 0, 12, 0, 0, 0, 44, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
7472        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
7473    ];
7474    pub const FIELD_COUNT: usize = 2;
7475    pub fn total_size(&self) -> usize {
7476        molecule::unpack_number(self.as_slice()) as usize
7477    }
7478    pub fn field_count(&self) -> usize {
7479        if self.total_size() == molecule::NUMBER_SIZE {
7480            0
7481        } else {
7482            (molecule::unpack_number(&self.as_slice()[molecule::NUMBER_SIZE..]) as usize / 4) - 1
7483        }
7484    }
7485    pub fn count_extra_fields(&self) -> usize {
7486        self.field_count() - Self::FIELD_COUNT
7487    }
7488    pub fn has_extra_fields(&self) -> bool {
7489        Self::FIELD_COUNT != self.field_count()
7490    }
7491    pub fn channel_id(&self) -> Byte32 {
7492        let slice = self.as_slice();
7493        let start = molecule::unpack_number(&slice[4..]) as usize;
7494        let end = molecule::unpack_number(&slice[8..]) as usize;
7495        Byte32::new_unchecked(self.0.slice(start..end))
7496    }
7497    pub fn message(&self) -> Bytes {
7498        let slice = self.as_slice();
7499        let start = molecule::unpack_number(&slice[8..]) as usize;
7500        if self.has_extra_fields() {
7501            let end = molecule::unpack_number(&slice[12..]) as usize;
7502            Bytes::new_unchecked(self.0.slice(start..end))
7503        } else {
7504            Bytes::new_unchecked(self.0.slice(start..))
7505        }
7506    }
7507    pub fn as_reader<'r>(&'r self) -> TxAbortReader<'r> {
7508        TxAbortReader::new_unchecked(self.as_slice())
7509    }
7510}
7511impl molecule::prelude::Entity for TxAbort {
7512    type Builder = TxAbortBuilder;
7513    const NAME: &'static str = "TxAbort";
7514    fn new_unchecked(data: molecule::bytes::Bytes) -> Self {
7515        TxAbort(data)
7516    }
7517    fn as_bytes(&self) -> molecule::bytes::Bytes {
7518        self.0.clone()
7519    }
7520    fn as_slice(&self) -> &[u8] {
7521        &self.0[..]
7522    }
7523    fn from_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
7524        TxAbortReader::from_slice(slice).map(|reader| reader.to_entity())
7525    }
7526    fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
7527        TxAbortReader::from_compatible_slice(slice).map(|reader| reader.to_entity())
7528    }
7529    fn new_builder() -> Self::Builder {
7530        ::core::default::Default::default()
7531    }
7532    fn as_builder(self) -> Self::Builder {
7533        Self::new_builder()
7534            .channel_id(self.channel_id())
7535            .message(self.message())
7536    }
7537}
7538#[derive(Clone, Copy)]
7539pub struct TxAbortReader<'r>(&'r [u8]);
7540impl<'r> ::core::fmt::LowerHex for TxAbortReader<'r> {
7541    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
7542        use molecule::hex_string;
7543        if f.alternate() {
7544            write!(f, "0x")?;
7545        }
7546        write!(f, "{}", hex_string(self.as_slice()))
7547    }
7548}
7549impl<'r> ::core::fmt::Debug for TxAbortReader<'r> {
7550    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
7551        write!(f, "{}({:#x})", Self::NAME, self)
7552    }
7553}
7554impl<'r> ::core::fmt::Display for TxAbortReader<'r> {
7555    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
7556        write!(f, "{} {{ ", Self::NAME)?;
7557        write!(f, "{}: {}", "channel_id", self.channel_id())?;
7558        write!(f, ", {}: {}", "message", self.message())?;
7559        let extra_count = self.count_extra_fields();
7560        if extra_count != 0 {
7561            write!(f, ", .. ({} fields)", extra_count)?;
7562        }
7563        write!(f, " }}")
7564    }
7565}
7566impl<'r> TxAbortReader<'r> {
7567    pub const FIELD_COUNT: usize = 2;
7568    pub fn total_size(&self) -> usize {
7569        molecule::unpack_number(self.as_slice()) as usize
7570    }
7571    pub fn field_count(&self) -> usize {
7572        if self.total_size() == molecule::NUMBER_SIZE {
7573            0
7574        } else {
7575            (molecule::unpack_number(&self.as_slice()[molecule::NUMBER_SIZE..]) as usize / 4) - 1
7576        }
7577    }
7578    pub fn count_extra_fields(&self) -> usize {
7579        self.field_count() - Self::FIELD_COUNT
7580    }
7581    pub fn has_extra_fields(&self) -> bool {
7582        Self::FIELD_COUNT != self.field_count()
7583    }
7584    pub fn channel_id(&self) -> Byte32Reader<'r> {
7585        let slice = self.as_slice();
7586        let start = molecule::unpack_number(&slice[4..]) as usize;
7587        let end = molecule::unpack_number(&slice[8..]) as usize;
7588        Byte32Reader::new_unchecked(&self.as_slice()[start..end])
7589    }
7590    pub fn message(&self) -> BytesReader<'r> {
7591        let slice = self.as_slice();
7592        let start = molecule::unpack_number(&slice[8..]) as usize;
7593        if self.has_extra_fields() {
7594            let end = molecule::unpack_number(&slice[12..]) as usize;
7595            BytesReader::new_unchecked(&self.as_slice()[start..end])
7596        } else {
7597            BytesReader::new_unchecked(&self.as_slice()[start..])
7598        }
7599    }
7600}
7601impl<'r> molecule::prelude::Reader<'r> for TxAbortReader<'r> {
7602    type Entity = TxAbort;
7603    const NAME: &'static str = "TxAbortReader";
7604    fn to_entity(&self) -> Self::Entity {
7605        Self::Entity::new_unchecked(self.as_slice().to_owned().into())
7606    }
7607    fn new_unchecked(slice: &'r [u8]) -> Self {
7608        TxAbortReader(slice)
7609    }
7610    fn as_slice(&self) -> &'r [u8] {
7611        self.0
7612    }
7613    fn verify(slice: &[u8], compatible: bool) -> molecule::error::VerificationResult<()> {
7614        use molecule::verification_error as ve;
7615        let slice_len = slice.len();
7616        if slice_len < molecule::NUMBER_SIZE {
7617            return ve!(Self, HeaderIsBroken, molecule::NUMBER_SIZE, slice_len);
7618        }
7619        let total_size = molecule::unpack_number(slice) as usize;
7620        if slice_len != total_size {
7621            return ve!(Self, TotalSizeNotMatch, total_size, slice_len);
7622        }
7623        if slice_len < molecule::NUMBER_SIZE * 2 {
7624            return ve!(Self, HeaderIsBroken, molecule::NUMBER_SIZE * 2, slice_len);
7625        }
7626        let offset_first = molecule::unpack_number(&slice[molecule::NUMBER_SIZE..]) as usize;
7627        if offset_first % molecule::NUMBER_SIZE != 0 || offset_first < molecule::NUMBER_SIZE * 2 {
7628            return ve!(Self, OffsetsNotMatch);
7629        }
7630        if slice_len < offset_first {
7631            return ve!(Self, HeaderIsBroken, offset_first, slice_len);
7632        }
7633        let field_count = offset_first / molecule::NUMBER_SIZE - 1;
7634        if field_count < Self::FIELD_COUNT {
7635            return ve!(Self, FieldCountNotMatch, Self::FIELD_COUNT, field_count);
7636        } else if !compatible && field_count > Self::FIELD_COUNT {
7637            return ve!(Self, FieldCountNotMatch, Self::FIELD_COUNT, field_count);
7638        };
7639        let mut offsets: Vec<usize> = slice[molecule::NUMBER_SIZE..offset_first]
7640            .chunks_exact(molecule::NUMBER_SIZE)
7641            .map(|x| molecule::unpack_number(x) as usize)
7642            .collect();
7643        offsets.push(total_size);
7644        if offsets.windows(2).any(|i| i[0] > i[1]) {
7645            return ve!(Self, OffsetsNotMatch);
7646        }
7647        Byte32Reader::verify(&slice[offsets[0]..offsets[1]], compatible)?;
7648        BytesReader::verify(&slice[offsets[1]..offsets[2]], compatible)?;
7649        Ok(())
7650    }
7651}
7652#[derive(Clone, Debug, Default)]
7653pub struct TxAbortBuilder {
7654    pub(crate) channel_id: Byte32,
7655    pub(crate) message: Bytes,
7656}
7657impl TxAbortBuilder {
7658    pub const FIELD_COUNT: usize = 2;
7659    pub fn channel_id(mut self, v: Byte32) -> Self {
7660        self.channel_id = v;
7661        self
7662    }
7663    pub fn message(mut self, v: Bytes) -> Self {
7664        self.message = v;
7665        self
7666    }
7667}
7668impl molecule::prelude::Builder for TxAbortBuilder {
7669    type Entity = TxAbort;
7670    const NAME: &'static str = "TxAbortBuilder";
7671    fn expected_length(&self) -> usize {
7672        molecule::NUMBER_SIZE * (Self::FIELD_COUNT + 1)
7673            + self.channel_id.as_slice().len()
7674            + self.message.as_slice().len()
7675    }
7676    fn write<W: molecule::io::Write>(&self, writer: &mut W) -> molecule::io::Result<()> {
7677        let mut total_size = molecule::NUMBER_SIZE * (Self::FIELD_COUNT + 1);
7678        let mut offsets = Vec::with_capacity(Self::FIELD_COUNT);
7679        offsets.push(total_size);
7680        total_size += self.channel_id.as_slice().len();
7681        offsets.push(total_size);
7682        total_size += self.message.as_slice().len();
7683        writer.write_all(&molecule::pack_number(total_size as molecule::Number))?;
7684        for offset in offsets.into_iter() {
7685            writer.write_all(&molecule::pack_number(offset as molecule::Number))?;
7686        }
7687        writer.write_all(self.channel_id.as_slice())?;
7688        writer.write_all(self.message.as_slice())?;
7689        Ok(())
7690    }
7691    fn build(&self) -> Self::Entity {
7692        let mut inner = Vec::with_capacity(self.expected_length());
7693        self.write(&mut inner)
7694            .unwrap_or_else(|_| panic!("{} build should be ok", Self::NAME));
7695        TxAbort::new_unchecked(inner.into())
7696    }
7697}
7698#[derive(Clone)]
7699pub struct TxInitRBF(molecule::bytes::Bytes);
7700impl ::core::fmt::LowerHex for TxInitRBF {
7701    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
7702        use molecule::hex_string;
7703        if f.alternate() {
7704            write!(f, "0x")?;
7705        }
7706        write!(f, "{}", hex_string(self.as_slice()))
7707    }
7708}
7709impl ::core::fmt::Debug for TxInitRBF {
7710    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
7711        write!(f, "{}({:#x})", Self::NAME, self)
7712    }
7713}
7714impl ::core::fmt::Display for TxInitRBF {
7715    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
7716        write!(f, "{} {{ ", Self::NAME)?;
7717        write!(f, "{}: {}", "channel_id", self.channel_id())?;
7718        write!(f, ", {}: {}", "fee_rate", self.fee_rate())?;
7719        let extra_count = self.count_extra_fields();
7720        if extra_count != 0 {
7721            write!(f, ", .. ({} fields)", extra_count)?;
7722        }
7723        write!(f, " }}")
7724    }
7725}
7726impl ::core::default::Default for TxInitRBF {
7727    fn default() -> Self {
7728        let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE);
7729        TxInitRBF::new_unchecked(v)
7730    }
7731}
7732impl TxInitRBF {
7733    const DEFAULT_VALUE: [u8; 52] = [
7734        52, 0, 0, 0, 12, 0, 0, 0, 44, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
7735        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
7736    ];
7737    pub const FIELD_COUNT: usize = 2;
7738    pub fn total_size(&self) -> usize {
7739        molecule::unpack_number(self.as_slice()) as usize
7740    }
7741    pub fn field_count(&self) -> usize {
7742        if self.total_size() == molecule::NUMBER_SIZE {
7743            0
7744        } else {
7745            (molecule::unpack_number(&self.as_slice()[molecule::NUMBER_SIZE..]) as usize / 4) - 1
7746        }
7747    }
7748    pub fn count_extra_fields(&self) -> usize {
7749        self.field_count() - Self::FIELD_COUNT
7750    }
7751    pub fn has_extra_fields(&self) -> bool {
7752        Self::FIELD_COUNT != self.field_count()
7753    }
7754    pub fn channel_id(&self) -> Byte32 {
7755        let slice = self.as_slice();
7756        let start = molecule::unpack_number(&slice[4..]) as usize;
7757        let end = molecule::unpack_number(&slice[8..]) as usize;
7758        Byte32::new_unchecked(self.0.slice(start..end))
7759    }
7760    pub fn fee_rate(&self) -> Uint64 {
7761        let slice = self.as_slice();
7762        let start = molecule::unpack_number(&slice[8..]) as usize;
7763        if self.has_extra_fields() {
7764            let end = molecule::unpack_number(&slice[12..]) as usize;
7765            Uint64::new_unchecked(self.0.slice(start..end))
7766        } else {
7767            Uint64::new_unchecked(self.0.slice(start..))
7768        }
7769    }
7770    pub fn as_reader<'r>(&'r self) -> TxInitRBFReader<'r> {
7771        TxInitRBFReader::new_unchecked(self.as_slice())
7772    }
7773}
7774impl molecule::prelude::Entity for TxInitRBF {
7775    type Builder = TxInitRBFBuilder;
7776    const NAME: &'static str = "TxInitRBF";
7777    fn new_unchecked(data: molecule::bytes::Bytes) -> Self {
7778        TxInitRBF(data)
7779    }
7780    fn as_bytes(&self) -> molecule::bytes::Bytes {
7781        self.0.clone()
7782    }
7783    fn as_slice(&self) -> &[u8] {
7784        &self.0[..]
7785    }
7786    fn from_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
7787        TxInitRBFReader::from_slice(slice).map(|reader| reader.to_entity())
7788    }
7789    fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
7790        TxInitRBFReader::from_compatible_slice(slice).map(|reader| reader.to_entity())
7791    }
7792    fn new_builder() -> Self::Builder {
7793        ::core::default::Default::default()
7794    }
7795    fn as_builder(self) -> Self::Builder {
7796        Self::new_builder()
7797            .channel_id(self.channel_id())
7798            .fee_rate(self.fee_rate())
7799    }
7800}
7801#[derive(Clone, Copy)]
7802pub struct TxInitRBFReader<'r>(&'r [u8]);
7803impl<'r> ::core::fmt::LowerHex for TxInitRBFReader<'r> {
7804    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
7805        use molecule::hex_string;
7806        if f.alternate() {
7807            write!(f, "0x")?;
7808        }
7809        write!(f, "{}", hex_string(self.as_slice()))
7810    }
7811}
7812impl<'r> ::core::fmt::Debug for TxInitRBFReader<'r> {
7813    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
7814        write!(f, "{}({:#x})", Self::NAME, self)
7815    }
7816}
7817impl<'r> ::core::fmt::Display for TxInitRBFReader<'r> {
7818    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
7819        write!(f, "{} {{ ", Self::NAME)?;
7820        write!(f, "{}: {}", "channel_id", self.channel_id())?;
7821        write!(f, ", {}: {}", "fee_rate", self.fee_rate())?;
7822        let extra_count = self.count_extra_fields();
7823        if extra_count != 0 {
7824            write!(f, ", .. ({} fields)", extra_count)?;
7825        }
7826        write!(f, " }}")
7827    }
7828}
7829impl<'r> TxInitRBFReader<'r> {
7830    pub const FIELD_COUNT: usize = 2;
7831    pub fn total_size(&self) -> usize {
7832        molecule::unpack_number(self.as_slice()) as usize
7833    }
7834    pub fn field_count(&self) -> usize {
7835        if self.total_size() == molecule::NUMBER_SIZE {
7836            0
7837        } else {
7838            (molecule::unpack_number(&self.as_slice()[molecule::NUMBER_SIZE..]) as usize / 4) - 1
7839        }
7840    }
7841    pub fn count_extra_fields(&self) -> usize {
7842        self.field_count() - Self::FIELD_COUNT
7843    }
7844    pub fn has_extra_fields(&self) -> bool {
7845        Self::FIELD_COUNT != self.field_count()
7846    }
7847    pub fn channel_id(&self) -> Byte32Reader<'r> {
7848        let slice = self.as_slice();
7849        let start = molecule::unpack_number(&slice[4..]) as usize;
7850        let end = molecule::unpack_number(&slice[8..]) as usize;
7851        Byte32Reader::new_unchecked(&self.as_slice()[start..end])
7852    }
7853    pub fn fee_rate(&self) -> Uint64Reader<'r> {
7854        let slice = self.as_slice();
7855        let start = molecule::unpack_number(&slice[8..]) as usize;
7856        if self.has_extra_fields() {
7857            let end = molecule::unpack_number(&slice[12..]) as usize;
7858            Uint64Reader::new_unchecked(&self.as_slice()[start..end])
7859        } else {
7860            Uint64Reader::new_unchecked(&self.as_slice()[start..])
7861        }
7862    }
7863}
7864impl<'r> molecule::prelude::Reader<'r> for TxInitRBFReader<'r> {
7865    type Entity = TxInitRBF;
7866    const NAME: &'static str = "TxInitRBFReader";
7867    fn to_entity(&self) -> Self::Entity {
7868        Self::Entity::new_unchecked(self.as_slice().to_owned().into())
7869    }
7870    fn new_unchecked(slice: &'r [u8]) -> Self {
7871        TxInitRBFReader(slice)
7872    }
7873    fn as_slice(&self) -> &'r [u8] {
7874        self.0
7875    }
7876    fn verify(slice: &[u8], compatible: bool) -> molecule::error::VerificationResult<()> {
7877        use molecule::verification_error as ve;
7878        let slice_len = slice.len();
7879        if slice_len < molecule::NUMBER_SIZE {
7880            return ve!(Self, HeaderIsBroken, molecule::NUMBER_SIZE, slice_len);
7881        }
7882        let total_size = molecule::unpack_number(slice) as usize;
7883        if slice_len != total_size {
7884            return ve!(Self, TotalSizeNotMatch, total_size, slice_len);
7885        }
7886        if slice_len < molecule::NUMBER_SIZE * 2 {
7887            return ve!(Self, HeaderIsBroken, molecule::NUMBER_SIZE * 2, slice_len);
7888        }
7889        let offset_first = molecule::unpack_number(&slice[molecule::NUMBER_SIZE..]) as usize;
7890        if offset_first % molecule::NUMBER_SIZE != 0 || offset_first < molecule::NUMBER_SIZE * 2 {
7891            return ve!(Self, OffsetsNotMatch);
7892        }
7893        if slice_len < offset_first {
7894            return ve!(Self, HeaderIsBroken, offset_first, slice_len);
7895        }
7896        let field_count = offset_first / molecule::NUMBER_SIZE - 1;
7897        if field_count < Self::FIELD_COUNT {
7898            return ve!(Self, FieldCountNotMatch, Self::FIELD_COUNT, field_count);
7899        } else if !compatible && field_count > Self::FIELD_COUNT {
7900            return ve!(Self, FieldCountNotMatch, Self::FIELD_COUNT, field_count);
7901        };
7902        let mut offsets: Vec<usize> = slice[molecule::NUMBER_SIZE..offset_first]
7903            .chunks_exact(molecule::NUMBER_SIZE)
7904            .map(|x| molecule::unpack_number(x) as usize)
7905            .collect();
7906        offsets.push(total_size);
7907        if offsets.windows(2).any(|i| i[0] > i[1]) {
7908            return ve!(Self, OffsetsNotMatch);
7909        }
7910        Byte32Reader::verify(&slice[offsets[0]..offsets[1]], compatible)?;
7911        Uint64Reader::verify(&slice[offsets[1]..offsets[2]], compatible)?;
7912        Ok(())
7913    }
7914}
7915#[derive(Clone, Debug, Default)]
7916pub struct TxInitRBFBuilder {
7917    pub(crate) channel_id: Byte32,
7918    pub(crate) fee_rate: Uint64,
7919}
7920impl TxInitRBFBuilder {
7921    pub const FIELD_COUNT: usize = 2;
7922    pub fn channel_id(mut self, v: Byte32) -> Self {
7923        self.channel_id = v;
7924        self
7925    }
7926    pub fn fee_rate(mut self, v: Uint64) -> Self {
7927        self.fee_rate = v;
7928        self
7929    }
7930}
7931impl molecule::prelude::Builder for TxInitRBFBuilder {
7932    type Entity = TxInitRBF;
7933    const NAME: &'static str = "TxInitRBFBuilder";
7934    fn expected_length(&self) -> usize {
7935        molecule::NUMBER_SIZE * (Self::FIELD_COUNT + 1)
7936            + self.channel_id.as_slice().len()
7937            + self.fee_rate.as_slice().len()
7938    }
7939    fn write<W: molecule::io::Write>(&self, writer: &mut W) -> molecule::io::Result<()> {
7940        let mut total_size = molecule::NUMBER_SIZE * (Self::FIELD_COUNT + 1);
7941        let mut offsets = Vec::with_capacity(Self::FIELD_COUNT);
7942        offsets.push(total_size);
7943        total_size += self.channel_id.as_slice().len();
7944        offsets.push(total_size);
7945        total_size += self.fee_rate.as_slice().len();
7946        writer.write_all(&molecule::pack_number(total_size as molecule::Number))?;
7947        for offset in offsets.into_iter() {
7948            writer.write_all(&molecule::pack_number(offset as molecule::Number))?;
7949        }
7950        writer.write_all(self.channel_id.as_slice())?;
7951        writer.write_all(self.fee_rate.as_slice())?;
7952        Ok(())
7953    }
7954    fn build(&self) -> Self::Entity {
7955        let mut inner = Vec::with_capacity(self.expected_length());
7956        self.write(&mut inner)
7957            .unwrap_or_else(|_| panic!("{} build should be ok", Self::NAME));
7958        TxInitRBF::new_unchecked(inner.into())
7959    }
7960}
7961#[derive(Clone)]
7962pub struct TxAckRBF(molecule::bytes::Bytes);
7963impl ::core::fmt::LowerHex for TxAckRBF {
7964    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
7965        use molecule::hex_string;
7966        if f.alternate() {
7967            write!(f, "0x")?;
7968        }
7969        write!(f, "{}", hex_string(self.as_slice()))
7970    }
7971}
7972impl ::core::fmt::Debug for TxAckRBF {
7973    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
7974        write!(f, "{}({:#x})", Self::NAME, self)
7975    }
7976}
7977impl ::core::fmt::Display for TxAckRBF {
7978    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
7979        write!(f, "{} {{ ", Self::NAME)?;
7980        write!(f, "{}: {}", "channel_id", self.channel_id())?;
7981        let extra_count = self.count_extra_fields();
7982        if extra_count != 0 {
7983            write!(f, ", .. ({} fields)", extra_count)?;
7984        }
7985        write!(f, " }}")
7986    }
7987}
7988impl ::core::default::Default for TxAckRBF {
7989    fn default() -> Self {
7990        let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE);
7991        TxAckRBF::new_unchecked(v)
7992    }
7993}
7994impl TxAckRBF {
7995    const DEFAULT_VALUE: [u8; 40] = [
7996        40, 0, 0, 0, 8, 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,
7997        0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
7998    ];
7999    pub const FIELD_COUNT: usize = 1;
8000    pub fn total_size(&self) -> usize {
8001        molecule::unpack_number(self.as_slice()) as usize
8002    }
8003    pub fn field_count(&self) -> usize {
8004        if self.total_size() == molecule::NUMBER_SIZE {
8005            0
8006        } else {
8007            (molecule::unpack_number(&self.as_slice()[molecule::NUMBER_SIZE..]) as usize / 4) - 1
8008        }
8009    }
8010    pub fn count_extra_fields(&self) -> usize {
8011        self.field_count() - Self::FIELD_COUNT
8012    }
8013    pub fn has_extra_fields(&self) -> bool {
8014        Self::FIELD_COUNT != self.field_count()
8015    }
8016    pub fn channel_id(&self) -> Byte32 {
8017        let slice = self.as_slice();
8018        let start = molecule::unpack_number(&slice[4..]) as usize;
8019        if self.has_extra_fields() {
8020            let end = molecule::unpack_number(&slice[8..]) as usize;
8021            Byte32::new_unchecked(self.0.slice(start..end))
8022        } else {
8023            Byte32::new_unchecked(self.0.slice(start..))
8024        }
8025    }
8026    pub fn as_reader<'r>(&'r self) -> TxAckRBFReader<'r> {
8027        TxAckRBFReader::new_unchecked(self.as_slice())
8028    }
8029}
8030impl molecule::prelude::Entity for TxAckRBF {
8031    type Builder = TxAckRBFBuilder;
8032    const NAME: &'static str = "TxAckRBF";
8033    fn new_unchecked(data: molecule::bytes::Bytes) -> Self {
8034        TxAckRBF(data)
8035    }
8036    fn as_bytes(&self) -> molecule::bytes::Bytes {
8037        self.0.clone()
8038    }
8039    fn as_slice(&self) -> &[u8] {
8040        &self.0[..]
8041    }
8042    fn from_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
8043        TxAckRBFReader::from_slice(slice).map(|reader| reader.to_entity())
8044    }
8045    fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
8046        TxAckRBFReader::from_compatible_slice(slice).map(|reader| reader.to_entity())
8047    }
8048    fn new_builder() -> Self::Builder {
8049        ::core::default::Default::default()
8050    }
8051    fn as_builder(self) -> Self::Builder {
8052        Self::new_builder().channel_id(self.channel_id())
8053    }
8054}
8055#[derive(Clone, Copy)]
8056pub struct TxAckRBFReader<'r>(&'r [u8]);
8057impl<'r> ::core::fmt::LowerHex for TxAckRBFReader<'r> {
8058    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
8059        use molecule::hex_string;
8060        if f.alternate() {
8061            write!(f, "0x")?;
8062        }
8063        write!(f, "{}", hex_string(self.as_slice()))
8064    }
8065}
8066impl<'r> ::core::fmt::Debug for TxAckRBFReader<'r> {
8067    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
8068        write!(f, "{}({:#x})", Self::NAME, self)
8069    }
8070}
8071impl<'r> ::core::fmt::Display for TxAckRBFReader<'r> {
8072    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
8073        write!(f, "{} {{ ", Self::NAME)?;
8074        write!(f, "{}: {}", "channel_id", self.channel_id())?;
8075        let extra_count = self.count_extra_fields();
8076        if extra_count != 0 {
8077            write!(f, ", .. ({} fields)", extra_count)?;
8078        }
8079        write!(f, " }}")
8080    }
8081}
8082impl<'r> TxAckRBFReader<'r> {
8083    pub const FIELD_COUNT: usize = 1;
8084    pub fn total_size(&self) -> usize {
8085        molecule::unpack_number(self.as_slice()) as usize
8086    }
8087    pub fn field_count(&self) -> usize {
8088        if self.total_size() == molecule::NUMBER_SIZE {
8089            0
8090        } else {
8091            (molecule::unpack_number(&self.as_slice()[molecule::NUMBER_SIZE..]) as usize / 4) - 1
8092        }
8093    }
8094    pub fn count_extra_fields(&self) -> usize {
8095        self.field_count() - Self::FIELD_COUNT
8096    }
8097    pub fn has_extra_fields(&self) -> bool {
8098        Self::FIELD_COUNT != self.field_count()
8099    }
8100    pub fn channel_id(&self) -> Byte32Reader<'r> {
8101        let slice = self.as_slice();
8102        let start = molecule::unpack_number(&slice[4..]) as usize;
8103        if self.has_extra_fields() {
8104            let end = molecule::unpack_number(&slice[8..]) as usize;
8105            Byte32Reader::new_unchecked(&self.as_slice()[start..end])
8106        } else {
8107            Byte32Reader::new_unchecked(&self.as_slice()[start..])
8108        }
8109    }
8110}
8111impl<'r> molecule::prelude::Reader<'r> for TxAckRBFReader<'r> {
8112    type Entity = TxAckRBF;
8113    const NAME: &'static str = "TxAckRBFReader";
8114    fn to_entity(&self) -> Self::Entity {
8115        Self::Entity::new_unchecked(self.as_slice().to_owned().into())
8116    }
8117    fn new_unchecked(slice: &'r [u8]) -> Self {
8118        TxAckRBFReader(slice)
8119    }
8120    fn as_slice(&self) -> &'r [u8] {
8121        self.0
8122    }
8123    fn verify(slice: &[u8], compatible: bool) -> molecule::error::VerificationResult<()> {
8124        use molecule::verification_error as ve;
8125        let slice_len = slice.len();
8126        if slice_len < molecule::NUMBER_SIZE {
8127            return ve!(Self, HeaderIsBroken, molecule::NUMBER_SIZE, slice_len);
8128        }
8129        let total_size = molecule::unpack_number(slice) as usize;
8130        if slice_len != total_size {
8131            return ve!(Self, TotalSizeNotMatch, total_size, slice_len);
8132        }
8133        if slice_len < molecule::NUMBER_SIZE * 2 {
8134            return ve!(Self, HeaderIsBroken, molecule::NUMBER_SIZE * 2, slice_len);
8135        }
8136        let offset_first = molecule::unpack_number(&slice[molecule::NUMBER_SIZE..]) as usize;
8137        if offset_first % molecule::NUMBER_SIZE != 0 || offset_first < molecule::NUMBER_SIZE * 2 {
8138            return ve!(Self, OffsetsNotMatch);
8139        }
8140        if slice_len < offset_first {
8141            return ve!(Self, HeaderIsBroken, offset_first, slice_len);
8142        }
8143        let field_count = offset_first / molecule::NUMBER_SIZE - 1;
8144        if field_count < Self::FIELD_COUNT {
8145            return ve!(Self, FieldCountNotMatch, Self::FIELD_COUNT, field_count);
8146        } else if !compatible && field_count > Self::FIELD_COUNT {
8147            return ve!(Self, FieldCountNotMatch, Self::FIELD_COUNT, field_count);
8148        };
8149        let mut offsets: Vec<usize> = slice[molecule::NUMBER_SIZE..offset_first]
8150            .chunks_exact(molecule::NUMBER_SIZE)
8151            .map(|x| molecule::unpack_number(x) as usize)
8152            .collect();
8153        offsets.push(total_size);
8154        if offsets.windows(2).any(|i| i[0] > i[1]) {
8155            return ve!(Self, OffsetsNotMatch);
8156        }
8157        Byte32Reader::verify(&slice[offsets[0]..offsets[1]], compatible)?;
8158        Ok(())
8159    }
8160}
8161#[derive(Clone, Debug, Default)]
8162pub struct TxAckRBFBuilder {
8163    pub(crate) channel_id: Byte32,
8164}
8165impl TxAckRBFBuilder {
8166    pub const FIELD_COUNT: usize = 1;
8167    pub fn channel_id(mut self, v: Byte32) -> Self {
8168        self.channel_id = v;
8169        self
8170    }
8171}
8172impl molecule::prelude::Builder for TxAckRBFBuilder {
8173    type Entity = TxAckRBF;
8174    const NAME: &'static str = "TxAckRBFBuilder";
8175    fn expected_length(&self) -> usize {
8176        molecule::NUMBER_SIZE * (Self::FIELD_COUNT + 1) + self.channel_id.as_slice().len()
8177    }
8178    fn write<W: molecule::io::Write>(&self, writer: &mut W) -> molecule::io::Result<()> {
8179        let mut total_size = molecule::NUMBER_SIZE * (Self::FIELD_COUNT + 1);
8180        let mut offsets = Vec::with_capacity(Self::FIELD_COUNT);
8181        offsets.push(total_size);
8182        total_size += self.channel_id.as_slice().len();
8183        writer.write_all(&molecule::pack_number(total_size as molecule::Number))?;
8184        for offset in offsets.into_iter() {
8185            writer.write_all(&molecule::pack_number(offset as molecule::Number))?;
8186        }
8187        writer.write_all(self.channel_id.as_slice())?;
8188        Ok(())
8189    }
8190    fn build(&self) -> Self::Entity {
8191        let mut inner = Vec::with_capacity(self.expected_length());
8192        self.write(&mut inner)
8193            .unwrap_or_else(|_| panic!("{} build should be ok", Self::NAME));
8194        TxAckRBF::new_unchecked(inner.into())
8195    }
8196}
8197#[derive(Clone)]
8198pub struct Shutdown(molecule::bytes::Bytes);
8199impl ::core::fmt::LowerHex for Shutdown {
8200    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
8201        use molecule::hex_string;
8202        if f.alternate() {
8203            write!(f, "0x")?;
8204        }
8205        write!(f, "{}", hex_string(self.as_slice()))
8206    }
8207}
8208impl ::core::fmt::Debug for Shutdown {
8209    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
8210        write!(f, "{}({:#x})", Self::NAME, self)
8211    }
8212}
8213impl ::core::fmt::Display for Shutdown {
8214    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
8215        write!(f, "{} {{ ", Self::NAME)?;
8216        write!(f, "{}: {}", "channel_id", self.channel_id())?;
8217        write!(f, ", {}: {}", "fee_rate", self.fee_rate())?;
8218        write!(f, ", {}: {}", "close_script", self.close_script())?;
8219        let extra_count = self.count_extra_fields();
8220        if extra_count != 0 {
8221            write!(f, ", .. ({} fields)", extra_count)?;
8222        }
8223        write!(f, " }}")
8224    }
8225}
8226impl ::core::default::Default for Shutdown {
8227    fn default() -> Self {
8228        let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE);
8229        Shutdown::new_unchecked(v)
8230    }
8231}
8232impl Shutdown {
8233    const DEFAULT_VALUE: [u8; 109] = [
8234        109, 0, 0, 0, 16, 0, 0, 0, 48, 0, 0, 0, 56, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
8235        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, 53, 0, 0,
8236        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,
8237        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
8238    ];
8239    pub const FIELD_COUNT: usize = 3;
8240    pub fn total_size(&self) -> usize {
8241        molecule::unpack_number(self.as_slice()) as usize
8242    }
8243    pub fn field_count(&self) -> usize {
8244        if self.total_size() == molecule::NUMBER_SIZE {
8245            0
8246        } else {
8247            (molecule::unpack_number(&self.as_slice()[molecule::NUMBER_SIZE..]) as usize / 4) - 1
8248        }
8249    }
8250    pub fn count_extra_fields(&self) -> usize {
8251        self.field_count() - Self::FIELD_COUNT
8252    }
8253    pub fn has_extra_fields(&self) -> bool {
8254        Self::FIELD_COUNT != self.field_count()
8255    }
8256    pub fn channel_id(&self) -> Byte32 {
8257        let slice = self.as_slice();
8258        let start = molecule::unpack_number(&slice[4..]) as usize;
8259        let end = molecule::unpack_number(&slice[8..]) as usize;
8260        Byte32::new_unchecked(self.0.slice(start..end))
8261    }
8262    pub fn fee_rate(&self) -> Uint64 {
8263        let slice = self.as_slice();
8264        let start = molecule::unpack_number(&slice[8..]) as usize;
8265        let end = molecule::unpack_number(&slice[12..]) as usize;
8266        Uint64::new_unchecked(self.0.slice(start..end))
8267    }
8268    pub fn close_script(&self) -> Script {
8269        let slice = self.as_slice();
8270        let start = molecule::unpack_number(&slice[12..]) as usize;
8271        if self.has_extra_fields() {
8272            let end = molecule::unpack_number(&slice[16..]) as usize;
8273            Script::new_unchecked(self.0.slice(start..end))
8274        } else {
8275            Script::new_unchecked(self.0.slice(start..))
8276        }
8277    }
8278    pub fn as_reader<'r>(&'r self) -> ShutdownReader<'r> {
8279        ShutdownReader::new_unchecked(self.as_slice())
8280    }
8281}
8282impl molecule::prelude::Entity for Shutdown {
8283    type Builder = ShutdownBuilder;
8284    const NAME: &'static str = "Shutdown";
8285    fn new_unchecked(data: molecule::bytes::Bytes) -> Self {
8286        Shutdown(data)
8287    }
8288    fn as_bytes(&self) -> molecule::bytes::Bytes {
8289        self.0.clone()
8290    }
8291    fn as_slice(&self) -> &[u8] {
8292        &self.0[..]
8293    }
8294    fn from_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
8295        ShutdownReader::from_slice(slice).map(|reader| reader.to_entity())
8296    }
8297    fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
8298        ShutdownReader::from_compatible_slice(slice).map(|reader| reader.to_entity())
8299    }
8300    fn new_builder() -> Self::Builder {
8301        ::core::default::Default::default()
8302    }
8303    fn as_builder(self) -> Self::Builder {
8304        Self::new_builder()
8305            .channel_id(self.channel_id())
8306            .fee_rate(self.fee_rate())
8307            .close_script(self.close_script())
8308    }
8309}
8310#[derive(Clone, Copy)]
8311pub struct ShutdownReader<'r>(&'r [u8]);
8312impl<'r> ::core::fmt::LowerHex for ShutdownReader<'r> {
8313    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
8314        use molecule::hex_string;
8315        if f.alternate() {
8316            write!(f, "0x")?;
8317        }
8318        write!(f, "{}", hex_string(self.as_slice()))
8319    }
8320}
8321impl<'r> ::core::fmt::Debug for ShutdownReader<'r> {
8322    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
8323        write!(f, "{}({:#x})", Self::NAME, self)
8324    }
8325}
8326impl<'r> ::core::fmt::Display for ShutdownReader<'r> {
8327    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
8328        write!(f, "{} {{ ", Self::NAME)?;
8329        write!(f, "{}: {}", "channel_id", self.channel_id())?;
8330        write!(f, ", {}: {}", "fee_rate", self.fee_rate())?;
8331        write!(f, ", {}: {}", "close_script", self.close_script())?;
8332        let extra_count = self.count_extra_fields();
8333        if extra_count != 0 {
8334            write!(f, ", .. ({} fields)", extra_count)?;
8335        }
8336        write!(f, " }}")
8337    }
8338}
8339impl<'r> ShutdownReader<'r> {
8340    pub const FIELD_COUNT: usize = 3;
8341    pub fn total_size(&self) -> usize {
8342        molecule::unpack_number(self.as_slice()) as usize
8343    }
8344    pub fn field_count(&self) -> usize {
8345        if self.total_size() == molecule::NUMBER_SIZE {
8346            0
8347        } else {
8348            (molecule::unpack_number(&self.as_slice()[molecule::NUMBER_SIZE..]) as usize / 4) - 1
8349        }
8350    }
8351    pub fn count_extra_fields(&self) -> usize {
8352        self.field_count() - Self::FIELD_COUNT
8353    }
8354    pub fn has_extra_fields(&self) -> bool {
8355        Self::FIELD_COUNT != self.field_count()
8356    }
8357    pub fn channel_id(&self) -> Byte32Reader<'r> {
8358        let slice = self.as_slice();
8359        let start = molecule::unpack_number(&slice[4..]) as usize;
8360        let end = molecule::unpack_number(&slice[8..]) as usize;
8361        Byte32Reader::new_unchecked(&self.as_slice()[start..end])
8362    }
8363    pub fn fee_rate(&self) -> Uint64Reader<'r> {
8364        let slice = self.as_slice();
8365        let start = molecule::unpack_number(&slice[8..]) as usize;
8366        let end = molecule::unpack_number(&slice[12..]) as usize;
8367        Uint64Reader::new_unchecked(&self.as_slice()[start..end])
8368    }
8369    pub fn close_script(&self) -> ScriptReader<'r> {
8370        let slice = self.as_slice();
8371        let start = molecule::unpack_number(&slice[12..]) as usize;
8372        if self.has_extra_fields() {
8373            let end = molecule::unpack_number(&slice[16..]) as usize;
8374            ScriptReader::new_unchecked(&self.as_slice()[start..end])
8375        } else {
8376            ScriptReader::new_unchecked(&self.as_slice()[start..])
8377        }
8378    }
8379}
8380impl<'r> molecule::prelude::Reader<'r> for ShutdownReader<'r> {
8381    type Entity = Shutdown;
8382    const NAME: &'static str = "ShutdownReader";
8383    fn to_entity(&self) -> Self::Entity {
8384        Self::Entity::new_unchecked(self.as_slice().to_owned().into())
8385    }
8386    fn new_unchecked(slice: &'r [u8]) -> Self {
8387        ShutdownReader(slice)
8388    }
8389    fn as_slice(&self) -> &'r [u8] {
8390        self.0
8391    }
8392    fn verify(slice: &[u8], compatible: bool) -> molecule::error::VerificationResult<()> {
8393        use molecule::verification_error as ve;
8394        let slice_len = slice.len();
8395        if slice_len < molecule::NUMBER_SIZE {
8396            return ve!(Self, HeaderIsBroken, molecule::NUMBER_SIZE, slice_len);
8397        }
8398        let total_size = molecule::unpack_number(slice) as usize;
8399        if slice_len != total_size {
8400            return ve!(Self, TotalSizeNotMatch, total_size, slice_len);
8401        }
8402        if slice_len < molecule::NUMBER_SIZE * 2 {
8403            return ve!(Self, HeaderIsBroken, molecule::NUMBER_SIZE * 2, slice_len);
8404        }
8405        let offset_first = molecule::unpack_number(&slice[molecule::NUMBER_SIZE..]) as usize;
8406        if offset_first % molecule::NUMBER_SIZE != 0 || offset_first < molecule::NUMBER_SIZE * 2 {
8407            return ve!(Self, OffsetsNotMatch);
8408        }
8409        if slice_len < offset_first {
8410            return ve!(Self, HeaderIsBroken, offset_first, slice_len);
8411        }
8412        let field_count = offset_first / molecule::NUMBER_SIZE - 1;
8413        if field_count < Self::FIELD_COUNT {
8414            return ve!(Self, FieldCountNotMatch, Self::FIELD_COUNT, field_count);
8415        } else if !compatible && field_count > Self::FIELD_COUNT {
8416            return ve!(Self, FieldCountNotMatch, Self::FIELD_COUNT, field_count);
8417        };
8418        let mut offsets: Vec<usize> = slice[molecule::NUMBER_SIZE..offset_first]
8419            .chunks_exact(molecule::NUMBER_SIZE)
8420            .map(|x| molecule::unpack_number(x) as usize)
8421            .collect();
8422        offsets.push(total_size);
8423        if offsets.windows(2).any(|i| i[0] > i[1]) {
8424            return ve!(Self, OffsetsNotMatch);
8425        }
8426        Byte32Reader::verify(&slice[offsets[0]..offsets[1]], compatible)?;
8427        Uint64Reader::verify(&slice[offsets[1]..offsets[2]], compatible)?;
8428        ScriptReader::verify(&slice[offsets[2]..offsets[3]], compatible)?;
8429        Ok(())
8430    }
8431}
8432#[derive(Clone, Debug, Default)]
8433pub struct ShutdownBuilder {
8434    pub(crate) channel_id: Byte32,
8435    pub(crate) fee_rate: Uint64,
8436    pub(crate) close_script: Script,
8437}
8438impl ShutdownBuilder {
8439    pub const FIELD_COUNT: usize = 3;
8440    pub fn channel_id(mut self, v: Byte32) -> Self {
8441        self.channel_id = v;
8442        self
8443    }
8444    pub fn fee_rate(mut self, v: Uint64) -> Self {
8445        self.fee_rate = v;
8446        self
8447    }
8448    pub fn close_script(mut self, v: Script) -> Self {
8449        self.close_script = v;
8450        self
8451    }
8452}
8453impl molecule::prelude::Builder for ShutdownBuilder {
8454    type Entity = Shutdown;
8455    const NAME: &'static str = "ShutdownBuilder";
8456    fn expected_length(&self) -> usize {
8457        molecule::NUMBER_SIZE * (Self::FIELD_COUNT + 1)
8458            + self.channel_id.as_slice().len()
8459            + self.fee_rate.as_slice().len()
8460            + self.close_script.as_slice().len()
8461    }
8462    fn write<W: molecule::io::Write>(&self, writer: &mut W) -> molecule::io::Result<()> {
8463        let mut total_size = molecule::NUMBER_SIZE * (Self::FIELD_COUNT + 1);
8464        let mut offsets = Vec::with_capacity(Self::FIELD_COUNT);
8465        offsets.push(total_size);
8466        total_size += self.channel_id.as_slice().len();
8467        offsets.push(total_size);
8468        total_size += self.fee_rate.as_slice().len();
8469        offsets.push(total_size);
8470        total_size += self.close_script.as_slice().len();
8471        writer.write_all(&molecule::pack_number(total_size as molecule::Number))?;
8472        for offset in offsets.into_iter() {
8473            writer.write_all(&molecule::pack_number(offset as molecule::Number))?;
8474        }
8475        writer.write_all(self.channel_id.as_slice())?;
8476        writer.write_all(self.fee_rate.as_slice())?;
8477        writer.write_all(self.close_script.as_slice())?;
8478        Ok(())
8479    }
8480    fn build(&self) -> Self::Entity {
8481        let mut inner = Vec::with_capacity(self.expected_length());
8482        self.write(&mut inner)
8483            .unwrap_or_else(|_| panic!("{} build should be ok", Self::NAME));
8484        Shutdown::new_unchecked(inner.into())
8485    }
8486}
8487#[derive(Clone)]
8488pub struct ClosingSigned(molecule::bytes::Bytes);
8489impl ::core::fmt::LowerHex for ClosingSigned {
8490    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
8491        use molecule::hex_string;
8492        if f.alternate() {
8493            write!(f, "0x")?;
8494        }
8495        write!(f, "{}", hex_string(self.as_slice()))
8496    }
8497}
8498impl ::core::fmt::Debug for ClosingSigned {
8499    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
8500        write!(f, "{}({:#x})", Self::NAME, self)
8501    }
8502}
8503impl ::core::fmt::Display for ClosingSigned {
8504    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
8505        write!(f, "{} {{ ", Self::NAME)?;
8506        write!(f, "{}: {}", "channel_id", self.channel_id())?;
8507        write!(f, ", {}: {}", "partial_signature", self.partial_signature())?;
8508        write!(f, " }}")
8509    }
8510}
8511impl ::core::default::Default for ClosingSigned {
8512    fn default() -> Self {
8513        let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE);
8514        ClosingSigned::new_unchecked(v)
8515    }
8516}
8517impl ClosingSigned {
8518    const DEFAULT_VALUE: [u8; 64] = [
8519        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,
8520        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,
8521        0, 0, 0, 0,
8522    ];
8523    pub const TOTAL_SIZE: usize = 64;
8524    pub const FIELD_SIZES: [usize; 2] = [32, 32];
8525    pub const FIELD_COUNT: usize = 2;
8526    pub fn channel_id(&self) -> Byte32 {
8527        Byte32::new_unchecked(self.0.slice(0..32))
8528    }
8529    pub fn partial_signature(&self) -> Byte32 {
8530        Byte32::new_unchecked(self.0.slice(32..64))
8531    }
8532    pub fn as_reader<'r>(&'r self) -> ClosingSignedReader<'r> {
8533        ClosingSignedReader::new_unchecked(self.as_slice())
8534    }
8535}
8536impl molecule::prelude::Entity for ClosingSigned {
8537    type Builder = ClosingSignedBuilder;
8538    const NAME: &'static str = "ClosingSigned";
8539    fn new_unchecked(data: molecule::bytes::Bytes) -> Self {
8540        ClosingSigned(data)
8541    }
8542    fn as_bytes(&self) -> molecule::bytes::Bytes {
8543        self.0.clone()
8544    }
8545    fn as_slice(&self) -> &[u8] {
8546        &self.0[..]
8547    }
8548    fn from_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
8549        ClosingSignedReader::from_slice(slice).map(|reader| reader.to_entity())
8550    }
8551    fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
8552        ClosingSignedReader::from_compatible_slice(slice).map(|reader| reader.to_entity())
8553    }
8554    fn new_builder() -> Self::Builder {
8555        ::core::default::Default::default()
8556    }
8557    fn as_builder(self) -> Self::Builder {
8558        Self::new_builder()
8559            .channel_id(self.channel_id())
8560            .partial_signature(self.partial_signature())
8561    }
8562}
8563#[derive(Clone, Copy)]
8564pub struct ClosingSignedReader<'r>(&'r [u8]);
8565impl<'r> ::core::fmt::LowerHex for ClosingSignedReader<'r> {
8566    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
8567        use molecule::hex_string;
8568        if f.alternate() {
8569            write!(f, "0x")?;
8570        }
8571        write!(f, "{}", hex_string(self.as_slice()))
8572    }
8573}
8574impl<'r> ::core::fmt::Debug for ClosingSignedReader<'r> {
8575    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
8576        write!(f, "{}({:#x})", Self::NAME, self)
8577    }
8578}
8579impl<'r> ::core::fmt::Display for ClosingSignedReader<'r> {
8580    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
8581        write!(f, "{} {{ ", Self::NAME)?;
8582        write!(f, "{}: {}", "channel_id", self.channel_id())?;
8583        write!(f, ", {}: {}", "partial_signature", self.partial_signature())?;
8584        write!(f, " }}")
8585    }
8586}
8587impl<'r> ClosingSignedReader<'r> {
8588    pub const TOTAL_SIZE: usize = 64;
8589    pub const FIELD_SIZES: [usize; 2] = [32, 32];
8590    pub const FIELD_COUNT: usize = 2;
8591    pub fn channel_id(&self) -> Byte32Reader<'r> {
8592        Byte32Reader::new_unchecked(&self.as_slice()[0..32])
8593    }
8594    pub fn partial_signature(&self) -> Byte32Reader<'r> {
8595        Byte32Reader::new_unchecked(&self.as_slice()[32..64])
8596    }
8597}
8598impl<'r> molecule::prelude::Reader<'r> for ClosingSignedReader<'r> {
8599    type Entity = ClosingSigned;
8600    const NAME: &'static str = "ClosingSignedReader";
8601    fn to_entity(&self) -> Self::Entity {
8602        Self::Entity::new_unchecked(self.as_slice().to_owned().into())
8603    }
8604    fn new_unchecked(slice: &'r [u8]) -> Self {
8605        ClosingSignedReader(slice)
8606    }
8607    fn as_slice(&self) -> &'r [u8] {
8608        self.0
8609    }
8610    fn verify(slice: &[u8], _compatible: bool) -> molecule::error::VerificationResult<()> {
8611        use molecule::verification_error as ve;
8612        let slice_len = slice.len();
8613        if slice_len != Self::TOTAL_SIZE {
8614            return ve!(Self, TotalSizeNotMatch, Self::TOTAL_SIZE, slice_len);
8615        }
8616        Ok(())
8617    }
8618}
8619#[derive(Clone, Debug, Default)]
8620pub struct ClosingSignedBuilder {
8621    pub(crate) channel_id: Byte32,
8622    pub(crate) partial_signature: Byte32,
8623}
8624impl ClosingSignedBuilder {
8625    pub const TOTAL_SIZE: usize = 64;
8626    pub const FIELD_SIZES: [usize; 2] = [32, 32];
8627    pub const FIELD_COUNT: usize = 2;
8628    pub fn channel_id(mut self, v: Byte32) -> Self {
8629        self.channel_id = v;
8630        self
8631    }
8632    pub fn partial_signature(mut self, v: Byte32) -> Self {
8633        self.partial_signature = v;
8634        self
8635    }
8636}
8637impl molecule::prelude::Builder for ClosingSignedBuilder {
8638    type Entity = ClosingSigned;
8639    const NAME: &'static str = "ClosingSignedBuilder";
8640    fn expected_length(&self) -> usize {
8641        Self::TOTAL_SIZE
8642    }
8643    fn write<W: molecule::io::Write>(&self, writer: &mut W) -> molecule::io::Result<()> {
8644        writer.write_all(self.channel_id.as_slice())?;
8645        writer.write_all(self.partial_signature.as_slice())?;
8646        Ok(())
8647    }
8648    fn build(&self) -> Self::Entity {
8649        let mut inner = Vec::with_capacity(self.expected_length());
8650        self.write(&mut inner)
8651            .unwrap_or_else(|_| panic!("{} build should be ok", Self::NAME));
8652        ClosingSigned::new_unchecked(inner.into())
8653    }
8654}
8655#[derive(Clone)]
8656pub struct UpdateTlcInfo(molecule::bytes::Bytes);
8657impl ::core::fmt::LowerHex for UpdateTlcInfo {
8658    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
8659        use molecule::hex_string;
8660        if f.alternate() {
8661            write!(f, "0x")?;
8662        }
8663        write!(f, "{}", hex_string(self.as_slice()))
8664    }
8665}
8666impl ::core::fmt::Debug for UpdateTlcInfo {
8667    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
8668        write!(f, "{}({:#x})", Self::NAME, self)
8669    }
8670}
8671impl ::core::fmt::Display for UpdateTlcInfo {
8672    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
8673        write!(f, "{} {{ ", Self::NAME)?;
8674        write!(f, "{}: {}", "channel_id", self.channel_id())?;
8675        write!(f, ", {}: {}", "timestamp", self.timestamp())?;
8676        write!(f, ", {}: {}", "channel_flags", self.channel_flags())?;
8677        write!(f, ", {}: {}", "tlc_expiry_delta", self.tlc_expiry_delta())?;
8678        write!(f, ", {}: {}", "tlc_minimum_value", self.tlc_minimum_value())?;
8679        write!(
8680            f,
8681            ", {}: {}",
8682            "tlc_fee_proportional_millionths",
8683            self.tlc_fee_proportional_millionths()
8684        )?;
8685        write!(f, " }}")
8686    }
8687}
8688impl ::core::default::Default for UpdateTlcInfo {
8689    fn default() -> Self {
8690        let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE);
8691        UpdateTlcInfo::new_unchecked(v)
8692    }
8693}
8694impl UpdateTlcInfo {
8695    const DEFAULT_VALUE: [u8; 84] = [
8696        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,
8697        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,
8698        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
8699    ];
8700    pub const TOTAL_SIZE: usize = 84;
8701    pub const FIELD_SIZES: [usize; 6] = [32, 8, 4, 8, 16, 16];
8702    pub const FIELD_COUNT: usize = 6;
8703    pub fn channel_id(&self) -> Byte32 {
8704        Byte32::new_unchecked(self.0.slice(0..32))
8705    }
8706    pub fn timestamp(&self) -> Uint64 {
8707        Uint64::new_unchecked(self.0.slice(32..40))
8708    }
8709    pub fn channel_flags(&self) -> Uint32 {
8710        Uint32::new_unchecked(self.0.slice(40..44))
8711    }
8712    pub fn tlc_expiry_delta(&self) -> Uint64 {
8713        Uint64::new_unchecked(self.0.slice(44..52))
8714    }
8715    pub fn tlc_minimum_value(&self) -> Uint128 {
8716        Uint128::new_unchecked(self.0.slice(52..68))
8717    }
8718    pub fn tlc_fee_proportional_millionths(&self) -> Uint128 {
8719        Uint128::new_unchecked(self.0.slice(68..84))
8720    }
8721    pub fn as_reader<'r>(&'r self) -> UpdateTlcInfoReader<'r> {
8722        UpdateTlcInfoReader::new_unchecked(self.as_slice())
8723    }
8724}
8725impl molecule::prelude::Entity for UpdateTlcInfo {
8726    type Builder = UpdateTlcInfoBuilder;
8727    const NAME: &'static str = "UpdateTlcInfo";
8728    fn new_unchecked(data: molecule::bytes::Bytes) -> Self {
8729        UpdateTlcInfo(data)
8730    }
8731    fn as_bytes(&self) -> molecule::bytes::Bytes {
8732        self.0.clone()
8733    }
8734    fn as_slice(&self) -> &[u8] {
8735        &self.0[..]
8736    }
8737    fn from_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
8738        UpdateTlcInfoReader::from_slice(slice).map(|reader| reader.to_entity())
8739    }
8740    fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
8741        UpdateTlcInfoReader::from_compatible_slice(slice).map(|reader| reader.to_entity())
8742    }
8743    fn new_builder() -> Self::Builder {
8744        ::core::default::Default::default()
8745    }
8746    fn as_builder(self) -> Self::Builder {
8747        Self::new_builder()
8748            .channel_id(self.channel_id())
8749            .timestamp(self.timestamp())
8750            .channel_flags(self.channel_flags())
8751            .tlc_expiry_delta(self.tlc_expiry_delta())
8752            .tlc_minimum_value(self.tlc_minimum_value())
8753            .tlc_fee_proportional_millionths(self.tlc_fee_proportional_millionths())
8754    }
8755}
8756#[derive(Clone, Copy)]
8757pub struct UpdateTlcInfoReader<'r>(&'r [u8]);
8758impl<'r> ::core::fmt::LowerHex for UpdateTlcInfoReader<'r> {
8759    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
8760        use molecule::hex_string;
8761        if f.alternate() {
8762            write!(f, "0x")?;
8763        }
8764        write!(f, "{}", hex_string(self.as_slice()))
8765    }
8766}
8767impl<'r> ::core::fmt::Debug for UpdateTlcInfoReader<'r> {
8768    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
8769        write!(f, "{}({:#x})", Self::NAME, self)
8770    }
8771}
8772impl<'r> ::core::fmt::Display for UpdateTlcInfoReader<'r> {
8773    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
8774        write!(f, "{} {{ ", Self::NAME)?;
8775        write!(f, "{}: {}", "channel_id", self.channel_id())?;
8776        write!(f, ", {}: {}", "timestamp", self.timestamp())?;
8777        write!(f, ", {}: {}", "channel_flags", self.channel_flags())?;
8778        write!(f, ", {}: {}", "tlc_expiry_delta", self.tlc_expiry_delta())?;
8779        write!(f, ", {}: {}", "tlc_minimum_value", self.tlc_minimum_value())?;
8780        write!(
8781            f,
8782            ", {}: {}",
8783            "tlc_fee_proportional_millionths",
8784            self.tlc_fee_proportional_millionths()
8785        )?;
8786        write!(f, " }}")
8787    }
8788}
8789impl<'r> UpdateTlcInfoReader<'r> {
8790    pub const TOTAL_SIZE: usize = 84;
8791    pub const FIELD_SIZES: [usize; 6] = [32, 8, 4, 8, 16, 16];
8792    pub const FIELD_COUNT: usize = 6;
8793    pub fn channel_id(&self) -> Byte32Reader<'r> {
8794        Byte32Reader::new_unchecked(&self.as_slice()[0..32])
8795    }
8796    pub fn timestamp(&self) -> Uint64Reader<'r> {
8797        Uint64Reader::new_unchecked(&self.as_slice()[32..40])
8798    }
8799    pub fn channel_flags(&self) -> Uint32Reader<'r> {
8800        Uint32Reader::new_unchecked(&self.as_slice()[40..44])
8801    }
8802    pub fn tlc_expiry_delta(&self) -> Uint64Reader<'r> {
8803        Uint64Reader::new_unchecked(&self.as_slice()[44..52])
8804    }
8805    pub fn tlc_minimum_value(&self) -> Uint128Reader<'r> {
8806        Uint128Reader::new_unchecked(&self.as_slice()[52..68])
8807    }
8808    pub fn tlc_fee_proportional_millionths(&self) -> Uint128Reader<'r> {
8809        Uint128Reader::new_unchecked(&self.as_slice()[68..84])
8810    }
8811}
8812impl<'r> molecule::prelude::Reader<'r> for UpdateTlcInfoReader<'r> {
8813    type Entity = UpdateTlcInfo;
8814    const NAME: &'static str = "UpdateTlcInfoReader";
8815    fn to_entity(&self) -> Self::Entity {
8816        Self::Entity::new_unchecked(self.as_slice().to_owned().into())
8817    }
8818    fn new_unchecked(slice: &'r [u8]) -> Self {
8819        UpdateTlcInfoReader(slice)
8820    }
8821    fn as_slice(&self) -> &'r [u8] {
8822        self.0
8823    }
8824    fn verify(slice: &[u8], _compatible: bool) -> molecule::error::VerificationResult<()> {
8825        use molecule::verification_error as ve;
8826        let slice_len = slice.len();
8827        if slice_len != Self::TOTAL_SIZE {
8828            return ve!(Self, TotalSizeNotMatch, Self::TOTAL_SIZE, slice_len);
8829        }
8830        Ok(())
8831    }
8832}
8833#[derive(Clone, Debug, Default)]
8834pub struct UpdateTlcInfoBuilder {
8835    pub(crate) channel_id: Byte32,
8836    pub(crate) timestamp: Uint64,
8837    pub(crate) channel_flags: Uint32,
8838    pub(crate) tlc_expiry_delta: Uint64,
8839    pub(crate) tlc_minimum_value: Uint128,
8840    pub(crate) tlc_fee_proportional_millionths: Uint128,
8841}
8842impl UpdateTlcInfoBuilder {
8843    pub const TOTAL_SIZE: usize = 84;
8844    pub const FIELD_SIZES: [usize; 6] = [32, 8, 4, 8, 16, 16];
8845    pub const FIELD_COUNT: usize = 6;
8846    pub fn channel_id(mut self, v: Byte32) -> Self {
8847        self.channel_id = v;
8848        self
8849    }
8850    pub fn timestamp(mut self, v: Uint64) -> Self {
8851        self.timestamp = v;
8852        self
8853    }
8854    pub fn channel_flags(mut self, v: Uint32) -> Self {
8855        self.channel_flags = v;
8856        self
8857    }
8858    pub fn tlc_expiry_delta(mut self, v: Uint64) -> Self {
8859        self.tlc_expiry_delta = v;
8860        self
8861    }
8862    pub fn tlc_minimum_value(mut self, v: Uint128) -> Self {
8863        self.tlc_minimum_value = v;
8864        self
8865    }
8866    pub fn tlc_fee_proportional_millionths(mut self, v: Uint128) -> Self {
8867        self.tlc_fee_proportional_millionths = v;
8868        self
8869    }
8870}
8871impl molecule::prelude::Builder for UpdateTlcInfoBuilder {
8872    type Entity = UpdateTlcInfo;
8873    const NAME: &'static str = "UpdateTlcInfoBuilder";
8874    fn expected_length(&self) -> usize {
8875        Self::TOTAL_SIZE
8876    }
8877    fn write<W: molecule::io::Write>(&self, writer: &mut W) -> molecule::io::Result<()> {
8878        writer.write_all(self.channel_id.as_slice())?;
8879        writer.write_all(self.timestamp.as_slice())?;
8880        writer.write_all(self.channel_flags.as_slice())?;
8881        writer.write_all(self.tlc_expiry_delta.as_slice())?;
8882        writer.write_all(self.tlc_minimum_value.as_slice())?;
8883        writer.write_all(self.tlc_fee_proportional_millionths.as_slice())?;
8884        Ok(())
8885    }
8886    fn build(&self) -> Self::Entity {
8887        let mut inner = Vec::with_capacity(self.expected_length());
8888        self.write(&mut inner)
8889            .unwrap_or_else(|_| panic!("{} build should be ok", Self::NAME));
8890        UpdateTlcInfo::new_unchecked(inner.into())
8891    }
8892}
8893#[derive(Clone)]
8894pub struct AddTlc(molecule::bytes::Bytes);
8895impl ::core::fmt::LowerHex for AddTlc {
8896    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
8897        use molecule::hex_string;
8898        if f.alternate() {
8899            write!(f, "0x")?;
8900        }
8901        write!(f, "{}", hex_string(self.as_slice()))
8902    }
8903}
8904impl ::core::fmt::Debug for AddTlc {
8905    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
8906        write!(f, "{}({:#x})", Self::NAME, self)
8907    }
8908}
8909impl ::core::fmt::Display for AddTlc {
8910    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
8911        write!(f, "{} {{ ", Self::NAME)?;
8912        write!(f, "{}: {}", "channel_id", self.channel_id())?;
8913        write!(f, ", {}: {}", "tlc_id", self.tlc_id())?;
8914        write!(f, ", {}: {}", "amount", self.amount())?;
8915        write!(f, ", {}: {}", "payment_hash", self.payment_hash())?;
8916        write!(f, ", {}: {}", "expiry", self.expiry())?;
8917        write!(f, ", {}: {}", "hash_algorithm", self.hash_algorithm())?;
8918        write!(f, ", {}: {}", "onion_packet", self.onion_packet())?;
8919        let extra_count = self.count_extra_fields();
8920        if extra_count != 0 {
8921            write!(f, ", .. ({} fields)", extra_count)?;
8922        }
8923        write!(f, " }}")
8924    }
8925}
8926impl ::core::default::Default for AddTlc {
8927    fn default() -> Self {
8928        let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE);
8929        AddTlc::new_unchecked(v)
8930    }
8931}
8932impl AddTlc {
8933    const DEFAULT_VALUE: [u8; 133] = [
8934        133, 0, 0, 0, 32, 0, 0, 0, 64, 0, 0, 0, 72, 0, 0, 0, 88, 0, 0, 0, 120, 0, 0, 0, 128, 0, 0,
8935        0, 129, 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,
8936        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,
8937        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,
8938        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
8939    ];
8940    pub const FIELD_COUNT: usize = 7;
8941    pub fn total_size(&self) -> usize {
8942        molecule::unpack_number(self.as_slice()) as usize
8943    }
8944    pub fn field_count(&self) -> usize {
8945        if self.total_size() == molecule::NUMBER_SIZE {
8946            0
8947        } else {
8948            (molecule::unpack_number(&self.as_slice()[molecule::NUMBER_SIZE..]) as usize / 4) - 1
8949        }
8950    }
8951    pub fn count_extra_fields(&self) -> usize {
8952        self.field_count() - Self::FIELD_COUNT
8953    }
8954    pub fn has_extra_fields(&self) -> bool {
8955        Self::FIELD_COUNT != self.field_count()
8956    }
8957    pub fn channel_id(&self) -> Byte32 {
8958        let slice = self.as_slice();
8959        let start = molecule::unpack_number(&slice[4..]) as usize;
8960        let end = molecule::unpack_number(&slice[8..]) as usize;
8961        Byte32::new_unchecked(self.0.slice(start..end))
8962    }
8963    pub fn tlc_id(&self) -> Uint64 {
8964        let slice = self.as_slice();
8965        let start = molecule::unpack_number(&slice[8..]) as usize;
8966        let end = molecule::unpack_number(&slice[12..]) as usize;
8967        Uint64::new_unchecked(self.0.slice(start..end))
8968    }
8969    pub fn amount(&self) -> Uint128 {
8970        let slice = self.as_slice();
8971        let start = molecule::unpack_number(&slice[12..]) as usize;
8972        let end = molecule::unpack_number(&slice[16..]) as usize;
8973        Uint128::new_unchecked(self.0.slice(start..end))
8974    }
8975    pub fn payment_hash(&self) -> Byte32 {
8976        let slice = self.as_slice();
8977        let start = molecule::unpack_number(&slice[16..]) as usize;
8978        let end = molecule::unpack_number(&slice[20..]) as usize;
8979        Byte32::new_unchecked(self.0.slice(start..end))
8980    }
8981    pub fn expiry(&self) -> Uint64 {
8982        let slice = self.as_slice();
8983        let start = molecule::unpack_number(&slice[20..]) as usize;
8984        let end = molecule::unpack_number(&slice[24..]) as usize;
8985        Uint64::new_unchecked(self.0.slice(start..end))
8986    }
8987    pub fn hash_algorithm(&self) -> Byte {
8988        let slice = self.as_slice();
8989        let start = molecule::unpack_number(&slice[24..]) as usize;
8990        let end = molecule::unpack_number(&slice[28..]) as usize;
8991        Byte::new_unchecked(self.0.slice(start..end))
8992    }
8993    pub fn onion_packet(&self) -> Bytes {
8994        let slice = self.as_slice();
8995        let start = molecule::unpack_number(&slice[28..]) as usize;
8996        if self.has_extra_fields() {
8997            let end = molecule::unpack_number(&slice[32..]) as usize;
8998            Bytes::new_unchecked(self.0.slice(start..end))
8999        } else {
9000            Bytes::new_unchecked(self.0.slice(start..))
9001        }
9002    }
9003    pub fn as_reader<'r>(&'r self) -> AddTlcReader<'r> {
9004        AddTlcReader::new_unchecked(self.as_slice())
9005    }
9006}
9007impl molecule::prelude::Entity for AddTlc {
9008    type Builder = AddTlcBuilder;
9009    const NAME: &'static str = "AddTlc";
9010    fn new_unchecked(data: molecule::bytes::Bytes) -> Self {
9011        AddTlc(data)
9012    }
9013    fn as_bytes(&self) -> molecule::bytes::Bytes {
9014        self.0.clone()
9015    }
9016    fn as_slice(&self) -> &[u8] {
9017        &self.0[..]
9018    }
9019    fn from_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
9020        AddTlcReader::from_slice(slice).map(|reader| reader.to_entity())
9021    }
9022    fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
9023        AddTlcReader::from_compatible_slice(slice).map(|reader| reader.to_entity())
9024    }
9025    fn new_builder() -> Self::Builder {
9026        ::core::default::Default::default()
9027    }
9028    fn as_builder(self) -> Self::Builder {
9029        Self::new_builder()
9030            .channel_id(self.channel_id())
9031            .tlc_id(self.tlc_id())
9032            .amount(self.amount())
9033            .payment_hash(self.payment_hash())
9034            .expiry(self.expiry())
9035            .hash_algorithm(self.hash_algorithm())
9036            .onion_packet(self.onion_packet())
9037    }
9038}
9039#[derive(Clone, Copy)]
9040pub struct AddTlcReader<'r>(&'r [u8]);
9041impl<'r> ::core::fmt::LowerHex for AddTlcReader<'r> {
9042    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
9043        use molecule::hex_string;
9044        if f.alternate() {
9045            write!(f, "0x")?;
9046        }
9047        write!(f, "{}", hex_string(self.as_slice()))
9048    }
9049}
9050impl<'r> ::core::fmt::Debug for AddTlcReader<'r> {
9051    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
9052        write!(f, "{}({:#x})", Self::NAME, self)
9053    }
9054}
9055impl<'r> ::core::fmt::Display for AddTlcReader<'r> {
9056    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
9057        write!(f, "{} {{ ", Self::NAME)?;
9058        write!(f, "{}: {}", "channel_id", self.channel_id())?;
9059        write!(f, ", {}: {}", "tlc_id", self.tlc_id())?;
9060        write!(f, ", {}: {}", "amount", self.amount())?;
9061        write!(f, ", {}: {}", "payment_hash", self.payment_hash())?;
9062        write!(f, ", {}: {}", "expiry", self.expiry())?;
9063        write!(f, ", {}: {}", "hash_algorithm", self.hash_algorithm())?;
9064        write!(f, ", {}: {}", "onion_packet", self.onion_packet())?;
9065        let extra_count = self.count_extra_fields();
9066        if extra_count != 0 {
9067            write!(f, ", .. ({} fields)", extra_count)?;
9068        }
9069        write!(f, " }}")
9070    }
9071}
9072impl<'r> AddTlcReader<'r> {
9073    pub const FIELD_COUNT: usize = 7;
9074    pub fn total_size(&self) -> usize {
9075        molecule::unpack_number(self.as_slice()) as usize
9076    }
9077    pub fn field_count(&self) -> usize {
9078        if self.total_size() == molecule::NUMBER_SIZE {
9079            0
9080        } else {
9081            (molecule::unpack_number(&self.as_slice()[molecule::NUMBER_SIZE..]) as usize / 4) - 1
9082        }
9083    }
9084    pub fn count_extra_fields(&self) -> usize {
9085        self.field_count() - Self::FIELD_COUNT
9086    }
9087    pub fn has_extra_fields(&self) -> bool {
9088        Self::FIELD_COUNT != self.field_count()
9089    }
9090    pub fn channel_id(&self) -> Byte32Reader<'r> {
9091        let slice = self.as_slice();
9092        let start = molecule::unpack_number(&slice[4..]) as usize;
9093        let end = molecule::unpack_number(&slice[8..]) as usize;
9094        Byte32Reader::new_unchecked(&self.as_slice()[start..end])
9095    }
9096    pub fn tlc_id(&self) -> Uint64Reader<'r> {
9097        let slice = self.as_slice();
9098        let start = molecule::unpack_number(&slice[8..]) as usize;
9099        let end = molecule::unpack_number(&slice[12..]) as usize;
9100        Uint64Reader::new_unchecked(&self.as_slice()[start..end])
9101    }
9102    pub fn amount(&self) -> Uint128Reader<'r> {
9103        let slice = self.as_slice();
9104        let start = molecule::unpack_number(&slice[12..]) as usize;
9105        let end = molecule::unpack_number(&slice[16..]) as usize;
9106        Uint128Reader::new_unchecked(&self.as_slice()[start..end])
9107    }
9108    pub fn payment_hash(&self) -> Byte32Reader<'r> {
9109        let slice = self.as_slice();
9110        let start = molecule::unpack_number(&slice[16..]) as usize;
9111        let end = molecule::unpack_number(&slice[20..]) as usize;
9112        Byte32Reader::new_unchecked(&self.as_slice()[start..end])
9113    }
9114    pub fn expiry(&self) -> Uint64Reader<'r> {
9115        let slice = self.as_slice();
9116        let start = molecule::unpack_number(&slice[20..]) as usize;
9117        let end = molecule::unpack_number(&slice[24..]) as usize;
9118        Uint64Reader::new_unchecked(&self.as_slice()[start..end])
9119    }
9120    pub fn hash_algorithm(&self) -> ByteReader<'r> {
9121        let slice = self.as_slice();
9122        let start = molecule::unpack_number(&slice[24..]) as usize;
9123        let end = molecule::unpack_number(&slice[28..]) as usize;
9124        ByteReader::new_unchecked(&self.as_slice()[start..end])
9125    }
9126    pub fn onion_packet(&self) -> BytesReader<'r> {
9127        let slice = self.as_slice();
9128        let start = molecule::unpack_number(&slice[28..]) as usize;
9129        if self.has_extra_fields() {
9130            let end = molecule::unpack_number(&slice[32..]) as usize;
9131            BytesReader::new_unchecked(&self.as_slice()[start..end])
9132        } else {
9133            BytesReader::new_unchecked(&self.as_slice()[start..])
9134        }
9135    }
9136}
9137impl<'r> molecule::prelude::Reader<'r> for AddTlcReader<'r> {
9138    type Entity = AddTlc;
9139    const NAME: &'static str = "AddTlcReader";
9140    fn to_entity(&self) -> Self::Entity {
9141        Self::Entity::new_unchecked(self.as_slice().to_owned().into())
9142    }
9143    fn new_unchecked(slice: &'r [u8]) -> Self {
9144        AddTlcReader(slice)
9145    }
9146    fn as_slice(&self) -> &'r [u8] {
9147        self.0
9148    }
9149    fn verify(slice: &[u8], compatible: bool) -> molecule::error::VerificationResult<()> {
9150        use molecule::verification_error as ve;
9151        let slice_len = slice.len();
9152        if slice_len < molecule::NUMBER_SIZE {
9153            return ve!(Self, HeaderIsBroken, molecule::NUMBER_SIZE, slice_len);
9154        }
9155        let total_size = molecule::unpack_number(slice) as usize;
9156        if slice_len != total_size {
9157            return ve!(Self, TotalSizeNotMatch, total_size, slice_len);
9158        }
9159        if slice_len < molecule::NUMBER_SIZE * 2 {
9160            return ve!(Self, HeaderIsBroken, molecule::NUMBER_SIZE * 2, slice_len);
9161        }
9162        let offset_first = molecule::unpack_number(&slice[molecule::NUMBER_SIZE..]) as usize;
9163        if offset_first % molecule::NUMBER_SIZE != 0 || offset_first < molecule::NUMBER_SIZE * 2 {
9164            return ve!(Self, OffsetsNotMatch);
9165        }
9166        if slice_len < offset_first {
9167            return ve!(Self, HeaderIsBroken, offset_first, slice_len);
9168        }
9169        let field_count = offset_first / molecule::NUMBER_SIZE - 1;
9170        if field_count < Self::FIELD_COUNT {
9171            return ve!(Self, FieldCountNotMatch, Self::FIELD_COUNT, field_count);
9172        } else if !compatible && field_count > Self::FIELD_COUNT {
9173            return ve!(Self, FieldCountNotMatch, Self::FIELD_COUNT, field_count);
9174        };
9175        let mut offsets: Vec<usize> = slice[molecule::NUMBER_SIZE..offset_first]
9176            .chunks_exact(molecule::NUMBER_SIZE)
9177            .map(|x| molecule::unpack_number(x) as usize)
9178            .collect();
9179        offsets.push(total_size);
9180        if offsets.windows(2).any(|i| i[0] > i[1]) {
9181            return ve!(Self, OffsetsNotMatch);
9182        }
9183        Byte32Reader::verify(&slice[offsets[0]..offsets[1]], compatible)?;
9184        Uint64Reader::verify(&slice[offsets[1]..offsets[2]], compatible)?;
9185        Uint128Reader::verify(&slice[offsets[2]..offsets[3]], compatible)?;
9186        Byte32Reader::verify(&slice[offsets[3]..offsets[4]], compatible)?;
9187        Uint64Reader::verify(&slice[offsets[4]..offsets[5]], compatible)?;
9188        ByteReader::verify(&slice[offsets[5]..offsets[6]], compatible)?;
9189        BytesReader::verify(&slice[offsets[6]..offsets[7]], compatible)?;
9190        Ok(())
9191    }
9192}
9193#[derive(Clone, Debug, Default)]
9194pub struct AddTlcBuilder {
9195    pub(crate) channel_id: Byte32,
9196    pub(crate) tlc_id: Uint64,
9197    pub(crate) amount: Uint128,
9198    pub(crate) payment_hash: Byte32,
9199    pub(crate) expiry: Uint64,
9200    pub(crate) hash_algorithm: Byte,
9201    pub(crate) onion_packet: Bytes,
9202}
9203impl AddTlcBuilder {
9204    pub const FIELD_COUNT: usize = 7;
9205    pub fn channel_id(mut self, v: Byte32) -> Self {
9206        self.channel_id = v;
9207        self
9208    }
9209    pub fn tlc_id(mut self, v: Uint64) -> Self {
9210        self.tlc_id = v;
9211        self
9212    }
9213    pub fn amount(mut self, v: Uint128) -> Self {
9214        self.amount = v;
9215        self
9216    }
9217    pub fn payment_hash(mut self, v: Byte32) -> Self {
9218        self.payment_hash = v;
9219        self
9220    }
9221    pub fn expiry(mut self, v: Uint64) -> Self {
9222        self.expiry = v;
9223        self
9224    }
9225    pub fn hash_algorithm(mut self, v: Byte) -> Self {
9226        self.hash_algorithm = v;
9227        self
9228    }
9229    pub fn onion_packet(mut self, v: Bytes) -> Self {
9230        self.onion_packet = v;
9231        self
9232    }
9233}
9234impl molecule::prelude::Builder for AddTlcBuilder {
9235    type Entity = AddTlc;
9236    const NAME: &'static str = "AddTlcBuilder";
9237    fn expected_length(&self) -> usize {
9238        molecule::NUMBER_SIZE * (Self::FIELD_COUNT + 1)
9239            + self.channel_id.as_slice().len()
9240            + self.tlc_id.as_slice().len()
9241            + self.amount.as_slice().len()
9242            + self.payment_hash.as_slice().len()
9243            + self.expiry.as_slice().len()
9244            + self.hash_algorithm.as_slice().len()
9245            + self.onion_packet.as_slice().len()
9246    }
9247    fn write<W: molecule::io::Write>(&self, writer: &mut W) -> molecule::io::Result<()> {
9248        let mut total_size = molecule::NUMBER_SIZE * (Self::FIELD_COUNT + 1);
9249        let mut offsets = Vec::with_capacity(Self::FIELD_COUNT);
9250        offsets.push(total_size);
9251        total_size += self.channel_id.as_slice().len();
9252        offsets.push(total_size);
9253        total_size += self.tlc_id.as_slice().len();
9254        offsets.push(total_size);
9255        total_size += self.amount.as_slice().len();
9256        offsets.push(total_size);
9257        total_size += self.payment_hash.as_slice().len();
9258        offsets.push(total_size);
9259        total_size += self.expiry.as_slice().len();
9260        offsets.push(total_size);
9261        total_size += self.hash_algorithm.as_slice().len();
9262        offsets.push(total_size);
9263        total_size += self.onion_packet.as_slice().len();
9264        writer.write_all(&molecule::pack_number(total_size as molecule::Number))?;
9265        for offset in offsets.into_iter() {
9266            writer.write_all(&molecule::pack_number(offset as molecule::Number))?;
9267        }
9268        writer.write_all(self.channel_id.as_slice())?;
9269        writer.write_all(self.tlc_id.as_slice())?;
9270        writer.write_all(self.amount.as_slice())?;
9271        writer.write_all(self.payment_hash.as_slice())?;
9272        writer.write_all(self.expiry.as_slice())?;
9273        writer.write_all(self.hash_algorithm.as_slice())?;
9274        writer.write_all(self.onion_packet.as_slice())?;
9275        Ok(())
9276    }
9277    fn build(&self) -> Self::Entity {
9278        let mut inner = Vec::with_capacity(self.expected_length());
9279        self.write(&mut inner)
9280            .unwrap_or_else(|_| panic!("{} build should be ok", Self::NAME));
9281        AddTlc::new_unchecked(inner.into())
9282    }
9283}
9284#[derive(Clone)]
9285pub struct RevokeAndAck(molecule::bytes::Bytes);
9286impl ::core::fmt::LowerHex for RevokeAndAck {
9287    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
9288        use molecule::hex_string;
9289        if f.alternate() {
9290            write!(f, "0x")?;
9291        }
9292        write!(f, "{}", hex_string(self.as_slice()))
9293    }
9294}
9295impl ::core::fmt::Debug for RevokeAndAck {
9296    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
9297        write!(f, "{}({:#x})", Self::NAME, self)
9298    }
9299}
9300impl ::core::fmt::Display for RevokeAndAck {
9301    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
9302        write!(f, "{} {{ ", Self::NAME)?;
9303        write!(f, "{}: {}", "channel_id", self.channel_id())?;
9304        write!(
9305            f,
9306            ", {}: {}",
9307            "revocation_partial_signature",
9308            self.revocation_partial_signature()
9309        )?;
9310        write!(
9311            f,
9312            ", {}: {}",
9313            "next_per_commitment_point",
9314            self.next_per_commitment_point()
9315        )?;
9316        write!(
9317            f,
9318            ", {}: {}",
9319            "next_revocation_nonce",
9320            self.next_revocation_nonce()
9321        )?;
9322        write!(f, " }}")
9323    }
9324}
9325impl ::core::default::Default for RevokeAndAck {
9326    fn default() -> Self {
9327        let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE);
9328        RevokeAndAck::new_unchecked(v)
9329    }
9330}
9331impl RevokeAndAck {
9332    const DEFAULT_VALUE: [u8; 163] = [
9333        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,
9334        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,
9335        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,
9336        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,
9337        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,
9338        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
9339    ];
9340    pub const TOTAL_SIZE: usize = 163;
9341    pub const FIELD_SIZES: [usize; 4] = [32, 32, 33, 66];
9342    pub const FIELD_COUNT: usize = 4;
9343    pub fn channel_id(&self) -> Byte32 {
9344        Byte32::new_unchecked(self.0.slice(0..32))
9345    }
9346    pub fn revocation_partial_signature(&self) -> Byte32 {
9347        Byte32::new_unchecked(self.0.slice(32..64))
9348    }
9349    pub fn next_per_commitment_point(&self) -> Pubkey {
9350        Pubkey::new_unchecked(self.0.slice(64..97))
9351    }
9352    pub fn next_revocation_nonce(&self) -> PubNonce {
9353        PubNonce::new_unchecked(self.0.slice(97..163))
9354    }
9355    pub fn as_reader<'r>(&'r self) -> RevokeAndAckReader<'r> {
9356        RevokeAndAckReader::new_unchecked(self.as_slice())
9357    }
9358}
9359impl molecule::prelude::Entity for RevokeAndAck {
9360    type Builder = RevokeAndAckBuilder;
9361    const NAME: &'static str = "RevokeAndAck";
9362    fn new_unchecked(data: molecule::bytes::Bytes) -> Self {
9363        RevokeAndAck(data)
9364    }
9365    fn as_bytes(&self) -> molecule::bytes::Bytes {
9366        self.0.clone()
9367    }
9368    fn as_slice(&self) -> &[u8] {
9369        &self.0[..]
9370    }
9371    fn from_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
9372        RevokeAndAckReader::from_slice(slice).map(|reader| reader.to_entity())
9373    }
9374    fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
9375        RevokeAndAckReader::from_compatible_slice(slice).map(|reader| reader.to_entity())
9376    }
9377    fn new_builder() -> Self::Builder {
9378        ::core::default::Default::default()
9379    }
9380    fn as_builder(self) -> Self::Builder {
9381        Self::new_builder()
9382            .channel_id(self.channel_id())
9383            .revocation_partial_signature(self.revocation_partial_signature())
9384            .next_per_commitment_point(self.next_per_commitment_point())
9385            .next_revocation_nonce(self.next_revocation_nonce())
9386    }
9387}
9388#[derive(Clone, Copy)]
9389pub struct RevokeAndAckReader<'r>(&'r [u8]);
9390impl<'r> ::core::fmt::LowerHex for RevokeAndAckReader<'r> {
9391    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
9392        use molecule::hex_string;
9393        if f.alternate() {
9394            write!(f, "0x")?;
9395        }
9396        write!(f, "{}", hex_string(self.as_slice()))
9397    }
9398}
9399impl<'r> ::core::fmt::Debug for RevokeAndAckReader<'r> {
9400    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
9401        write!(f, "{}({:#x})", Self::NAME, self)
9402    }
9403}
9404impl<'r> ::core::fmt::Display for RevokeAndAckReader<'r> {
9405    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
9406        write!(f, "{} {{ ", Self::NAME)?;
9407        write!(f, "{}: {}", "channel_id", self.channel_id())?;
9408        write!(
9409            f,
9410            ", {}: {}",
9411            "revocation_partial_signature",
9412            self.revocation_partial_signature()
9413        )?;
9414        write!(
9415            f,
9416            ", {}: {}",
9417            "next_per_commitment_point",
9418            self.next_per_commitment_point()
9419        )?;
9420        write!(
9421            f,
9422            ", {}: {}",
9423            "next_revocation_nonce",
9424            self.next_revocation_nonce()
9425        )?;
9426        write!(f, " }}")
9427    }
9428}
9429impl<'r> RevokeAndAckReader<'r> {
9430    pub const TOTAL_SIZE: usize = 163;
9431    pub const FIELD_SIZES: [usize; 4] = [32, 32, 33, 66];
9432    pub const FIELD_COUNT: usize = 4;
9433    pub fn channel_id(&self) -> Byte32Reader<'r> {
9434        Byte32Reader::new_unchecked(&self.as_slice()[0..32])
9435    }
9436    pub fn revocation_partial_signature(&self) -> Byte32Reader<'r> {
9437        Byte32Reader::new_unchecked(&self.as_slice()[32..64])
9438    }
9439    pub fn next_per_commitment_point(&self) -> PubkeyReader<'r> {
9440        PubkeyReader::new_unchecked(&self.as_slice()[64..97])
9441    }
9442    pub fn next_revocation_nonce(&self) -> PubNonceReader<'r> {
9443        PubNonceReader::new_unchecked(&self.as_slice()[97..163])
9444    }
9445}
9446impl<'r> molecule::prelude::Reader<'r> for RevokeAndAckReader<'r> {
9447    type Entity = RevokeAndAck;
9448    const NAME: &'static str = "RevokeAndAckReader";
9449    fn to_entity(&self) -> Self::Entity {
9450        Self::Entity::new_unchecked(self.as_slice().to_owned().into())
9451    }
9452    fn new_unchecked(slice: &'r [u8]) -> Self {
9453        RevokeAndAckReader(slice)
9454    }
9455    fn as_slice(&self) -> &'r [u8] {
9456        self.0
9457    }
9458    fn verify(slice: &[u8], _compatible: bool) -> molecule::error::VerificationResult<()> {
9459        use molecule::verification_error as ve;
9460        let slice_len = slice.len();
9461        if slice_len != Self::TOTAL_SIZE {
9462            return ve!(Self, TotalSizeNotMatch, Self::TOTAL_SIZE, slice_len);
9463        }
9464        Ok(())
9465    }
9466}
9467#[derive(Clone, Debug, Default)]
9468pub struct RevokeAndAckBuilder {
9469    pub(crate) channel_id: Byte32,
9470    pub(crate) revocation_partial_signature: Byte32,
9471    pub(crate) next_per_commitment_point: Pubkey,
9472    pub(crate) next_revocation_nonce: PubNonce,
9473}
9474impl RevokeAndAckBuilder {
9475    pub const TOTAL_SIZE: usize = 163;
9476    pub const FIELD_SIZES: [usize; 4] = [32, 32, 33, 66];
9477    pub const FIELD_COUNT: usize = 4;
9478    pub fn channel_id(mut self, v: Byte32) -> Self {
9479        self.channel_id = v;
9480        self
9481    }
9482    pub fn revocation_partial_signature(mut self, v: Byte32) -> Self {
9483        self.revocation_partial_signature = v;
9484        self
9485    }
9486    pub fn next_per_commitment_point(mut self, v: Pubkey) -> Self {
9487        self.next_per_commitment_point = v;
9488        self
9489    }
9490    pub fn next_revocation_nonce(mut self, v: PubNonce) -> Self {
9491        self.next_revocation_nonce = v;
9492        self
9493    }
9494}
9495impl molecule::prelude::Builder for RevokeAndAckBuilder {
9496    type Entity = RevokeAndAck;
9497    const NAME: &'static str = "RevokeAndAckBuilder";
9498    fn expected_length(&self) -> usize {
9499        Self::TOTAL_SIZE
9500    }
9501    fn write<W: molecule::io::Write>(&self, writer: &mut W) -> molecule::io::Result<()> {
9502        writer.write_all(self.channel_id.as_slice())?;
9503        writer.write_all(self.revocation_partial_signature.as_slice())?;
9504        writer.write_all(self.next_per_commitment_point.as_slice())?;
9505        writer.write_all(self.next_revocation_nonce.as_slice())?;
9506        Ok(())
9507    }
9508    fn build(&self) -> Self::Entity {
9509        let mut inner = Vec::with_capacity(self.expected_length());
9510        self.write(&mut inner)
9511            .unwrap_or_else(|_| panic!("{} build should be ok", Self::NAME));
9512        RevokeAndAck::new_unchecked(inner.into())
9513    }
9514}
9515#[derive(Clone)]
9516pub struct RemoveTlcFulfill(molecule::bytes::Bytes);
9517impl ::core::fmt::LowerHex for RemoveTlcFulfill {
9518    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
9519        use molecule::hex_string;
9520        if f.alternate() {
9521            write!(f, "0x")?;
9522        }
9523        write!(f, "{}", hex_string(self.as_slice()))
9524    }
9525}
9526impl ::core::fmt::Debug for RemoveTlcFulfill {
9527    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
9528        write!(f, "{}({:#x})", Self::NAME, self)
9529    }
9530}
9531impl ::core::fmt::Display for RemoveTlcFulfill {
9532    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
9533        write!(f, "{} {{ ", Self::NAME)?;
9534        write!(f, "{}: {}", "payment_preimage", self.payment_preimage())?;
9535        write!(f, " }}")
9536    }
9537}
9538impl ::core::default::Default for RemoveTlcFulfill {
9539    fn default() -> Self {
9540        let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE);
9541        RemoveTlcFulfill::new_unchecked(v)
9542    }
9543}
9544impl RemoveTlcFulfill {
9545    const DEFAULT_VALUE: [u8; 32] = [
9546        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,
9547        0, 0,
9548    ];
9549    pub const TOTAL_SIZE: usize = 32;
9550    pub const FIELD_SIZES: [usize; 1] = [32];
9551    pub const FIELD_COUNT: usize = 1;
9552    pub fn payment_preimage(&self) -> Byte32 {
9553        Byte32::new_unchecked(self.0.slice(0..32))
9554    }
9555    pub fn as_reader<'r>(&'r self) -> RemoveTlcFulfillReader<'r> {
9556        RemoveTlcFulfillReader::new_unchecked(self.as_slice())
9557    }
9558}
9559impl molecule::prelude::Entity for RemoveTlcFulfill {
9560    type Builder = RemoveTlcFulfillBuilder;
9561    const NAME: &'static str = "RemoveTlcFulfill";
9562    fn new_unchecked(data: molecule::bytes::Bytes) -> Self {
9563        RemoveTlcFulfill(data)
9564    }
9565    fn as_bytes(&self) -> molecule::bytes::Bytes {
9566        self.0.clone()
9567    }
9568    fn as_slice(&self) -> &[u8] {
9569        &self.0[..]
9570    }
9571    fn from_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
9572        RemoveTlcFulfillReader::from_slice(slice).map(|reader| reader.to_entity())
9573    }
9574    fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
9575        RemoveTlcFulfillReader::from_compatible_slice(slice).map(|reader| reader.to_entity())
9576    }
9577    fn new_builder() -> Self::Builder {
9578        ::core::default::Default::default()
9579    }
9580    fn as_builder(self) -> Self::Builder {
9581        Self::new_builder().payment_preimage(self.payment_preimage())
9582    }
9583}
9584#[derive(Clone, Copy)]
9585pub struct RemoveTlcFulfillReader<'r>(&'r [u8]);
9586impl<'r> ::core::fmt::LowerHex for RemoveTlcFulfillReader<'r> {
9587    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
9588        use molecule::hex_string;
9589        if f.alternate() {
9590            write!(f, "0x")?;
9591        }
9592        write!(f, "{}", hex_string(self.as_slice()))
9593    }
9594}
9595impl<'r> ::core::fmt::Debug for RemoveTlcFulfillReader<'r> {
9596    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
9597        write!(f, "{}({:#x})", Self::NAME, self)
9598    }
9599}
9600impl<'r> ::core::fmt::Display for RemoveTlcFulfillReader<'r> {
9601    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
9602        write!(f, "{} {{ ", Self::NAME)?;
9603        write!(f, "{}: {}", "payment_preimage", self.payment_preimage())?;
9604        write!(f, " }}")
9605    }
9606}
9607impl<'r> RemoveTlcFulfillReader<'r> {
9608    pub const TOTAL_SIZE: usize = 32;
9609    pub const FIELD_SIZES: [usize; 1] = [32];
9610    pub const FIELD_COUNT: usize = 1;
9611    pub fn payment_preimage(&self) -> Byte32Reader<'r> {
9612        Byte32Reader::new_unchecked(&self.as_slice()[0..32])
9613    }
9614}
9615impl<'r> molecule::prelude::Reader<'r> for RemoveTlcFulfillReader<'r> {
9616    type Entity = RemoveTlcFulfill;
9617    const NAME: &'static str = "RemoveTlcFulfillReader";
9618    fn to_entity(&self) -> Self::Entity {
9619        Self::Entity::new_unchecked(self.as_slice().to_owned().into())
9620    }
9621    fn new_unchecked(slice: &'r [u8]) -> Self {
9622        RemoveTlcFulfillReader(slice)
9623    }
9624    fn as_slice(&self) -> &'r [u8] {
9625        self.0
9626    }
9627    fn verify(slice: &[u8], _compatible: bool) -> molecule::error::VerificationResult<()> {
9628        use molecule::verification_error as ve;
9629        let slice_len = slice.len();
9630        if slice_len != Self::TOTAL_SIZE {
9631            return ve!(Self, TotalSizeNotMatch, Self::TOTAL_SIZE, slice_len);
9632        }
9633        Ok(())
9634    }
9635}
9636#[derive(Clone, Debug, Default)]
9637pub struct RemoveTlcFulfillBuilder {
9638    pub(crate) payment_preimage: Byte32,
9639}
9640impl RemoveTlcFulfillBuilder {
9641    pub const TOTAL_SIZE: usize = 32;
9642    pub const FIELD_SIZES: [usize; 1] = [32];
9643    pub const FIELD_COUNT: usize = 1;
9644    pub fn payment_preimage(mut self, v: Byte32) -> Self {
9645        self.payment_preimage = v;
9646        self
9647    }
9648}
9649impl molecule::prelude::Builder for RemoveTlcFulfillBuilder {
9650    type Entity = RemoveTlcFulfill;
9651    const NAME: &'static str = "RemoveTlcFulfillBuilder";
9652    fn expected_length(&self) -> usize {
9653        Self::TOTAL_SIZE
9654    }
9655    fn write<W: molecule::io::Write>(&self, writer: &mut W) -> molecule::io::Result<()> {
9656        writer.write_all(self.payment_preimage.as_slice())?;
9657        Ok(())
9658    }
9659    fn build(&self) -> Self::Entity {
9660        let mut inner = Vec::with_capacity(self.expected_length());
9661        self.write(&mut inner)
9662            .unwrap_or_else(|_| panic!("{} build should be ok", Self::NAME));
9663        RemoveTlcFulfill::new_unchecked(inner.into())
9664    }
9665}
9666#[derive(Clone)]
9667pub struct TlcErrPacket(molecule::bytes::Bytes);
9668impl ::core::fmt::LowerHex for TlcErrPacket {
9669    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
9670        use molecule::hex_string;
9671        if f.alternate() {
9672            write!(f, "0x")?;
9673        }
9674        write!(f, "{}", hex_string(self.as_slice()))
9675    }
9676}
9677impl ::core::fmt::Debug for TlcErrPacket {
9678    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
9679        write!(f, "{}({:#x})", Self::NAME, self)
9680    }
9681}
9682impl ::core::fmt::Display for TlcErrPacket {
9683    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
9684        write!(f, "{} {{ ", Self::NAME)?;
9685        write!(f, "{}: {}", "onion_packet", self.onion_packet())?;
9686        let extra_count = self.count_extra_fields();
9687        if extra_count != 0 {
9688            write!(f, ", .. ({} fields)", extra_count)?;
9689        }
9690        write!(f, " }}")
9691    }
9692}
9693impl ::core::default::Default for TlcErrPacket {
9694    fn default() -> Self {
9695        let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE);
9696        TlcErrPacket::new_unchecked(v)
9697    }
9698}
9699impl TlcErrPacket {
9700    const DEFAULT_VALUE: [u8; 12] = [12, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0];
9701    pub const FIELD_COUNT: usize = 1;
9702    pub fn total_size(&self) -> usize {
9703        molecule::unpack_number(self.as_slice()) as usize
9704    }
9705    pub fn field_count(&self) -> usize {
9706        if self.total_size() == molecule::NUMBER_SIZE {
9707            0
9708        } else {
9709            (molecule::unpack_number(&self.as_slice()[molecule::NUMBER_SIZE..]) as usize / 4) - 1
9710        }
9711    }
9712    pub fn count_extra_fields(&self) -> usize {
9713        self.field_count() - Self::FIELD_COUNT
9714    }
9715    pub fn has_extra_fields(&self) -> bool {
9716        Self::FIELD_COUNT != self.field_count()
9717    }
9718    pub fn onion_packet(&self) -> Bytes {
9719        let slice = self.as_slice();
9720        let start = molecule::unpack_number(&slice[4..]) as usize;
9721        if self.has_extra_fields() {
9722            let end = molecule::unpack_number(&slice[8..]) as usize;
9723            Bytes::new_unchecked(self.0.slice(start..end))
9724        } else {
9725            Bytes::new_unchecked(self.0.slice(start..))
9726        }
9727    }
9728    pub fn as_reader<'r>(&'r self) -> TlcErrPacketReader<'r> {
9729        TlcErrPacketReader::new_unchecked(self.as_slice())
9730    }
9731}
9732impl molecule::prelude::Entity for TlcErrPacket {
9733    type Builder = TlcErrPacketBuilder;
9734    const NAME: &'static str = "TlcErrPacket";
9735    fn new_unchecked(data: molecule::bytes::Bytes) -> Self {
9736        TlcErrPacket(data)
9737    }
9738    fn as_bytes(&self) -> molecule::bytes::Bytes {
9739        self.0.clone()
9740    }
9741    fn as_slice(&self) -> &[u8] {
9742        &self.0[..]
9743    }
9744    fn from_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
9745        TlcErrPacketReader::from_slice(slice).map(|reader| reader.to_entity())
9746    }
9747    fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
9748        TlcErrPacketReader::from_compatible_slice(slice).map(|reader| reader.to_entity())
9749    }
9750    fn new_builder() -> Self::Builder {
9751        ::core::default::Default::default()
9752    }
9753    fn as_builder(self) -> Self::Builder {
9754        Self::new_builder().onion_packet(self.onion_packet())
9755    }
9756}
9757#[derive(Clone, Copy)]
9758pub struct TlcErrPacketReader<'r>(&'r [u8]);
9759impl<'r> ::core::fmt::LowerHex for TlcErrPacketReader<'r> {
9760    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
9761        use molecule::hex_string;
9762        if f.alternate() {
9763            write!(f, "0x")?;
9764        }
9765        write!(f, "{}", hex_string(self.as_slice()))
9766    }
9767}
9768impl<'r> ::core::fmt::Debug for TlcErrPacketReader<'r> {
9769    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
9770        write!(f, "{}({:#x})", Self::NAME, self)
9771    }
9772}
9773impl<'r> ::core::fmt::Display for TlcErrPacketReader<'r> {
9774    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
9775        write!(f, "{} {{ ", Self::NAME)?;
9776        write!(f, "{}: {}", "onion_packet", self.onion_packet())?;
9777        let extra_count = self.count_extra_fields();
9778        if extra_count != 0 {
9779            write!(f, ", .. ({} fields)", extra_count)?;
9780        }
9781        write!(f, " }}")
9782    }
9783}
9784impl<'r> TlcErrPacketReader<'r> {
9785    pub const FIELD_COUNT: usize = 1;
9786    pub fn total_size(&self) -> usize {
9787        molecule::unpack_number(self.as_slice()) as usize
9788    }
9789    pub fn field_count(&self) -> usize {
9790        if self.total_size() == molecule::NUMBER_SIZE {
9791            0
9792        } else {
9793            (molecule::unpack_number(&self.as_slice()[molecule::NUMBER_SIZE..]) as usize / 4) - 1
9794        }
9795    }
9796    pub fn count_extra_fields(&self) -> usize {
9797        self.field_count() - Self::FIELD_COUNT
9798    }
9799    pub fn has_extra_fields(&self) -> bool {
9800        Self::FIELD_COUNT != self.field_count()
9801    }
9802    pub fn onion_packet(&self) -> BytesReader<'r> {
9803        let slice = self.as_slice();
9804        let start = molecule::unpack_number(&slice[4..]) as usize;
9805        if self.has_extra_fields() {
9806            let end = molecule::unpack_number(&slice[8..]) as usize;
9807            BytesReader::new_unchecked(&self.as_slice()[start..end])
9808        } else {
9809            BytesReader::new_unchecked(&self.as_slice()[start..])
9810        }
9811    }
9812}
9813impl<'r> molecule::prelude::Reader<'r> for TlcErrPacketReader<'r> {
9814    type Entity = TlcErrPacket;
9815    const NAME: &'static str = "TlcErrPacketReader";
9816    fn to_entity(&self) -> Self::Entity {
9817        Self::Entity::new_unchecked(self.as_slice().to_owned().into())
9818    }
9819    fn new_unchecked(slice: &'r [u8]) -> Self {
9820        TlcErrPacketReader(slice)
9821    }
9822    fn as_slice(&self) -> &'r [u8] {
9823        self.0
9824    }
9825    fn verify(slice: &[u8], compatible: bool) -> molecule::error::VerificationResult<()> {
9826        use molecule::verification_error as ve;
9827        let slice_len = slice.len();
9828        if slice_len < molecule::NUMBER_SIZE {
9829            return ve!(Self, HeaderIsBroken, molecule::NUMBER_SIZE, slice_len);
9830        }
9831        let total_size = molecule::unpack_number(slice) as usize;
9832        if slice_len != total_size {
9833            return ve!(Self, TotalSizeNotMatch, total_size, slice_len);
9834        }
9835        if slice_len < molecule::NUMBER_SIZE * 2 {
9836            return ve!(Self, HeaderIsBroken, molecule::NUMBER_SIZE * 2, slice_len);
9837        }
9838        let offset_first = molecule::unpack_number(&slice[molecule::NUMBER_SIZE..]) as usize;
9839        if offset_first % molecule::NUMBER_SIZE != 0 || offset_first < molecule::NUMBER_SIZE * 2 {
9840            return ve!(Self, OffsetsNotMatch);
9841        }
9842        if slice_len < offset_first {
9843            return ve!(Self, HeaderIsBroken, offset_first, slice_len);
9844        }
9845        let field_count = offset_first / molecule::NUMBER_SIZE - 1;
9846        if field_count < Self::FIELD_COUNT {
9847            return ve!(Self, FieldCountNotMatch, Self::FIELD_COUNT, field_count);
9848        } else if !compatible && field_count > Self::FIELD_COUNT {
9849            return ve!(Self, FieldCountNotMatch, Self::FIELD_COUNT, field_count);
9850        };
9851        let mut offsets: Vec<usize> = slice[molecule::NUMBER_SIZE..offset_first]
9852            .chunks_exact(molecule::NUMBER_SIZE)
9853            .map(|x| molecule::unpack_number(x) as usize)
9854            .collect();
9855        offsets.push(total_size);
9856        if offsets.windows(2).any(|i| i[0] > i[1]) {
9857            return ve!(Self, OffsetsNotMatch);
9858        }
9859        BytesReader::verify(&slice[offsets[0]..offsets[1]], compatible)?;
9860        Ok(())
9861    }
9862}
9863#[derive(Clone, Debug, Default)]
9864pub struct TlcErrPacketBuilder {
9865    pub(crate) onion_packet: Bytes,
9866}
9867impl TlcErrPacketBuilder {
9868    pub const FIELD_COUNT: usize = 1;
9869    pub fn onion_packet(mut self, v: Bytes) -> Self {
9870        self.onion_packet = v;
9871        self
9872    }
9873}
9874impl molecule::prelude::Builder for TlcErrPacketBuilder {
9875    type Entity = TlcErrPacket;
9876    const NAME: &'static str = "TlcErrPacketBuilder";
9877    fn expected_length(&self) -> usize {
9878        molecule::NUMBER_SIZE * (Self::FIELD_COUNT + 1) + self.onion_packet.as_slice().len()
9879    }
9880    fn write<W: molecule::io::Write>(&self, writer: &mut W) -> molecule::io::Result<()> {
9881        let mut total_size = molecule::NUMBER_SIZE * (Self::FIELD_COUNT + 1);
9882        let mut offsets = Vec::with_capacity(Self::FIELD_COUNT);
9883        offsets.push(total_size);
9884        total_size += self.onion_packet.as_slice().len();
9885        writer.write_all(&molecule::pack_number(total_size as molecule::Number))?;
9886        for offset in offsets.into_iter() {
9887            writer.write_all(&molecule::pack_number(offset as molecule::Number))?;
9888        }
9889        writer.write_all(self.onion_packet.as_slice())?;
9890        Ok(())
9891    }
9892    fn build(&self) -> Self::Entity {
9893        let mut inner = Vec::with_capacity(self.expected_length());
9894        self.write(&mut inner)
9895            .unwrap_or_else(|_| panic!("{} build should be ok", Self::NAME));
9896        TlcErrPacket::new_unchecked(inner.into())
9897    }
9898}
9899#[derive(Clone)]
9900pub struct RemoveTlcReason(molecule::bytes::Bytes);
9901impl ::core::fmt::LowerHex for RemoveTlcReason {
9902    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
9903        use molecule::hex_string;
9904        if f.alternate() {
9905            write!(f, "0x")?;
9906        }
9907        write!(f, "{}", hex_string(self.as_slice()))
9908    }
9909}
9910impl ::core::fmt::Debug for RemoveTlcReason {
9911    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
9912        write!(f, "{}({:#x})", Self::NAME, self)
9913    }
9914}
9915impl ::core::fmt::Display for RemoveTlcReason {
9916    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
9917        write!(f, "{}(", Self::NAME)?;
9918        self.to_enum().display_inner(f)?;
9919        write!(f, ")")
9920    }
9921}
9922impl ::core::default::Default for RemoveTlcReason {
9923    fn default() -> Self {
9924        let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE);
9925        RemoveTlcReason::new_unchecked(v)
9926    }
9927}
9928impl RemoveTlcReason {
9929    const DEFAULT_VALUE: [u8; 36] = [
9930        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,
9931        0, 0, 0, 0, 0, 0,
9932    ];
9933    pub const ITEMS_COUNT: usize = 2;
9934    pub fn item_id(&self) -> molecule::Number {
9935        molecule::unpack_number(self.as_slice())
9936    }
9937    pub fn to_enum(&self) -> RemoveTlcReasonUnion {
9938        let inner = self.0.slice(molecule::NUMBER_SIZE..);
9939        match self.item_id() {
9940            0 => RemoveTlcFulfill::new_unchecked(inner).into(),
9941            1 => TlcErrPacket::new_unchecked(inner).into(),
9942            _ => panic!("{}: invalid data", Self::NAME),
9943        }
9944    }
9945    pub fn as_reader<'r>(&'r self) -> RemoveTlcReasonReader<'r> {
9946        RemoveTlcReasonReader::new_unchecked(self.as_slice())
9947    }
9948}
9949impl molecule::prelude::Entity for RemoveTlcReason {
9950    type Builder = RemoveTlcReasonBuilder;
9951    const NAME: &'static str = "RemoveTlcReason";
9952    fn new_unchecked(data: molecule::bytes::Bytes) -> Self {
9953        RemoveTlcReason(data)
9954    }
9955    fn as_bytes(&self) -> molecule::bytes::Bytes {
9956        self.0.clone()
9957    }
9958    fn as_slice(&self) -> &[u8] {
9959        &self.0[..]
9960    }
9961    fn from_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
9962        RemoveTlcReasonReader::from_slice(slice).map(|reader| reader.to_entity())
9963    }
9964    fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
9965        RemoveTlcReasonReader::from_compatible_slice(slice).map(|reader| reader.to_entity())
9966    }
9967    fn new_builder() -> Self::Builder {
9968        ::core::default::Default::default()
9969    }
9970    fn as_builder(self) -> Self::Builder {
9971        Self::new_builder().set(self.to_enum())
9972    }
9973}
9974#[derive(Clone, Copy)]
9975pub struct RemoveTlcReasonReader<'r>(&'r [u8]);
9976impl<'r> ::core::fmt::LowerHex for RemoveTlcReasonReader<'r> {
9977    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
9978        use molecule::hex_string;
9979        if f.alternate() {
9980            write!(f, "0x")?;
9981        }
9982        write!(f, "{}", hex_string(self.as_slice()))
9983    }
9984}
9985impl<'r> ::core::fmt::Debug for RemoveTlcReasonReader<'r> {
9986    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
9987        write!(f, "{}({:#x})", Self::NAME, self)
9988    }
9989}
9990impl<'r> ::core::fmt::Display for RemoveTlcReasonReader<'r> {
9991    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
9992        write!(f, "{}(", Self::NAME)?;
9993        self.to_enum().display_inner(f)?;
9994        write!(f, ")")
9995    }
9996}
9997impl<'r> RemoveTlcReasonReader<'r> {
9998    pub const ITEMS_COUNT: usize = 2;
9999    pub fn item_id(&self) -> molecule::Number {
10000        molecule::unpack_number(self.as_slice())
10001    }
10002    pub fn to_enum(&self) -> RemoveTlcReasonUnionReader<'r> {
10003        let inner = &self.as_slice()[molecule::NUMBER_SIZE..];
10004        match self.item_id() {
10005            0 => RemoveTlcFulfillReader::new_unchecked(inner).into(),
10006            1 => TlcErrPacketReader::new_unchecked(inner).into(),
10007            _ => panic!("{}: invalid data", Self::NAME),
10008        }
10009    }
10010}
10011impl<'r> molecule::prelude::Reader<'r> for RemoveTlcReasonReader<'r> {
10012    type Entity = RemoveTlcReason;
10013    const NAME: &'static str = "RemoveTlcReasonReader";
10014    fn to_entity(&self) -> Self::Entity {
10015        Self::Entity::new_unchecked(self.as_slice().to_owned().into())
10016    }
10017    fn new_unchecked(slice: &'r [u8]) -> Self {
10018        RemoveTlcReasonReader(slice)
10019    }
10020    fn as_slice(&self) -> &'r [u8] {
10021        self.0
10022    }
10023    fn verify(slice: &[u8], compatible: bool) -> molecule::error::VerificationResult<()> {
10024        use molecule::verification_error as ve;
10025        let slice_len = slice.len();
10026        if slice_len < molecule::NUMBER_SIZE {
10027            return ve!(Self, HeaderIsBroken, molecule::NUMBER_SIZE, slice_len);
10028        }
10029        let item_id = molecule::unpack_number(slice);
10030        let inner_slice = &slice[molecule::NUMBER_SIZE..];
10031        match item_id {
10032            0 => RemoveTlcFulfillReader::verify(inner_slice, compatible),
10033            1 => TlcErrPacketReader::verify(inner_slice, compatible),
10034            _ => ve!(Self, UnknownItem, Self::ITEMS_COUNT, item_id),
10035        }?;
10036        Ok(())
10037    }
10038}
10039#[derive(Clone, Debug, Default)]
10040pub struct RemoveTlcReasonBuilder(pub(crate) RemoveTlcReasonUnion);
10041impl RemoveTlcReasonBuilder {
10042    pub const ITEMS_COUNT: usize = 2;
10043    pub fn set<I>(mut self, v: I) -> Self
10044    where
10045        I: ::core::convert::Into<RemoveTlcReasonUnion>,
10046    {
10047        self.0 = v.into();
10048        self
10049    }
10050}
10051impl molecule::prelude::Builder for RemoveTlcReasonBuilder {
10052    type Entity = RemoveTlcReason;
10053    const NAME: &'static str = "RemoveTlcReasonBuilder";
10054    fn expected_length(&self) -> usize {
10055        molecule::NUMBER_SIZE + self.0.as_slice().len()
10056    }
10057    fn write<W: molecule::io::Write>(&self, writer: &mut W) -> molecule::io::Result<()> {
10058        writer.write_all(&molecule::pack_number(self.0.item_id()))?;
10059        writer.write_all(self.0.as_slice())
10060    }
10061    fn build(&self) -> Self::Entity {
10062        let mut inner = Vec::with_capacity(self.expected_length());
10063        self.write(&mut inner)
10064            .unwrap_or_else(|_| panic!("{} build should be ok", Self::NAME));
10065        RemoveTlcReason::new_unchecked(inner.into())
10066    }
10067}
10068#[derive(Debug, Clone)]
10069pub enum RemoveTlcReasonUnion {
10070    RemoveTlcFulfill(RemoveTlcFulfill),
10071    TlcErrPacket(TlcErrPacket),
10072}
10073#[derive(Debug, Clone, Copy)]
10074pub enum RemoveTlcReasonUnionReader<'r> {
10075    RemoveTlcFulfill(RemoveTlcFulfillReader<'r>),
10076    TlcErrPacket(TlcErrPacketReader<'r>),
10077}
10078impl ::core::default::Default for RemoveTlcReasonUnion {
10079    fn default() -> Self {
10080        RemoveTlcReasonUnion::RemoveTlcFulfill(::core::default::Default::default())
10081    }
10082}
10083impl ::core::fmt::Display for RemoveTlcReasonUnion {
10084    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
10085        match self {
10086            RemoveTlcReasonUnion::RemoveTlcFulfill(ref item) => {
10087                write!(f, "{}::{}({})", Self::NAME, RemoveTlcFulfill::NAME, item)
10088            }
10089            RemoveTlcReasonUnion::TlcErrPacket(ref item) => {
10090                write!(f, "{}::{}({})", Self::NAME, TlcErrPacket::NAME, item)
10091            }
10092        }
10093    }
10094}
10095impl<'r> ::core::fmt::Display for RemoveTlcReasonUnionReader<'r> {
10096    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
10097        match self {
10098            RemoveTlcReasonUnionReader::RemoveTlcFulfill(ref item) => {
10099                write!(f, "{}::{}({})", Self::NAME, RemoveTlcFulfill::NAME, item)
10100            }
10101            RemoveTlcReasonUnionReader::TlcErrPacket(ref item) => {
10102                write!(f, "{}::{}({})", Self::NAME, TlcErrPacket::NAME, item)
10103            }
10104        }
10105    }
10106}
10107impl RemoveTlcReasonUnion {
10108    pub(crate) fn display_inner(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
10109        match self {
10110            RemoveTlcReasonUnion::RemoveTlcFulfill(ref item) => write!(f, "{}", item),
10111            RemoveTlcReasonUnion::TlcErrPacket(ref item) => write!(f, "{}", item),
10112        }
10113    }
10114}
10115impl<'r> RemoveTlcReasonUnionReader<'r> {
10116    pub(crate) fn display_inner(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
10117        match self {
10118            RemoveTlcReasonUnionReader::RemoveTlcFulfill(ref item) => write!(f, "{}", item),
10119            RemoveTlcReasonUnionReader::TlcErrPacket(ref item) => write!(f, "{}", item),
10120        }
10121    }
10122}
10123impl ::core::convert::From<RemoveTlcFulfill> for RemoveTlcReasonUnion {
10124    fn from(item: RemoveTlcFulfill) -> Self {
10125        RemoveTlcReasonUnion::RemoveTlcFulfill(item)
10126    }
10127}
10128impl ::core::convert::From<TlcErrPacket> for RemoveTlcReasonUnion {
10129    fn from(item: TlcErrPacket) -> Self {
10130        RemoveTlcReasonUnion::TlcErrPacket(item)
10131    }
10132}
10133impl<'r> ::core::convert::From<RemoveTlcFulfillReader<'r>> for RemoveTlcReasonUnionReader<'r> {
10134    fn from(item: RemoveTlcFulfillReader<'r>) -> Self {
10135        RemoveTlcReasonUnionReader::RemoveTlcFulfill(item)
10136    }
10137}
10138impl<'r> ::core::convert::From<TlcErrPacketReader<'r>> for RemoveTlcReasonUnionReader<'r> {
10139    fn from(item: TlcErrPacketReader<'r>) -> Self {
10140        RemoveTlcReasonUnionReader::TlcErrPacket(item)
10141    }
10142}
10143impl RemoveTlcReasonUnion {
10144    pub const NAME: &'static str = "RemoveTlcReasonUnion";
10145    pub fn as_bytes(&self) -> molecule::bytes::Bytes {
10146        match self {
10147            RemoveTlcReasonUnion::RemoveTlcFulfill(item) => item.as_bytes(),
10148            RemoveTlcReasonUnion::TlcErrPacket(item) => item.as_bytes(),
10149        }
10150    }
10151    pub fn as_slice(&self) -> &[u8] {
10152        match self {
10153            RemoveTlcReasonUnion::RemoveTlcFulfill(item) => item.as_slice(),
10154            RemoveTlcReasonUnion::TlcErrPacket(item) => item.as_slice(),
10155        }
10156    }
10157    pub fn item_id(&self) -> molecule::Number {
10158        match self {
10159            RemoveTlcReasonUnion::RemoveTlcFulfill(_) => 0,
10160            RemoveTlcReasonUnion::TlcErrPacket(_) => 1,
10161        }
10162    }
10163    pub fn item_name(&self) -> &str {
10164        match self {
10165            RemoveTlcReasonUnion::RemoveTlcFulfill(_) => "RemoveTlcFulfill",
10166            RemoveTlcReasonUnion::TlcErrPacket(_) => "TlcErrPacket",
10167        }
10168    }
10169    pub fn as_reader<'r>(&'r self) -> RemoveTlcReasonUnionReader<'r> {
10170        match self {
10171            RemoveTlcReasonUnion::RemoveTlcFulfill(item) => item.as_reader().into(),
10172            RemoveTlcReasonUnion::TlcErrPacket(item) => item.as_reader().into(),
10173        }
10174    }
10175}
10176impl<'r> RemoveTlcReasonUnionReader<'r> {
10177    pub const NAME: &'r str = "RemoveTlcReasonUnionReader";
10178    pub fn as_slice(&self) -> &'r [u8] {
10179        match self {
10180            RemoveTlcReasonUnionReader::RemoveTlcFulfill(item) => item.as_slice(),
10181            RemoveTlcReasonUnionReader::TlcErrPacket(item) => item.as_slice(),
10182        }
10183    }
10184    pub fn item_id(&self) -> molecule::Number {
10185        match self {
10186            RemoveTlcReasonUnionReader::RemoveTlcFulfill(_) => 0,
10187            RemoveTlcReasonUnionReader::TlcErrPacket(_) => 1,
10188        }
10189    }
10190    pub fn item_name(&self) -> &str {
10191        match self {
10192            RemoveTlcReasonUnionReader::RemoveTlcFulfill(_) => "RemoveTlcFulfill",
10193            RemoveTlcReasonUnionReader::TlcErrPacket(_) => "TlcErrPacket",
10194        }
10195    }
10196}
10197impl From<RemoveTlcFulfill> for RemoveTlcReason {
10198    fn from(value: RemoveTlcFulfill) -> Self {
10199        Self::new_builder().set(value).build()
10200    }
10201}
10202impl From<TlcErrPacket> for RemoveTlcReason {
10203    fn from(value: TlcErrPacket) -> Self {
10204        Self::new_builder().set(value).build()
10205    }
10206}
10207#[derive(Clone)]
10208pub struct RemoveTlc(molecule::bytes::Bytes);
10209impl ::core::fmt::LowerHex for RemoveTlc {
10210    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
10211        use molecule::hex_string;
10212        if f.alternate() {
10213            write!(f, "0x")?;
10214        }
10215        write!(f, "{}", hex_string(self.as_slice()))
10216    }
10217}
10218impl ::core::fmt::Debug for RemoveTlc {
10219    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
10220        write!(f, "{}({:#x})", Self::NAME, self)
10221    }
10222}
10223impl ::core::fmt::Display for RemoveTlc {
10224    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
10225        write!(f, "{} {{ ", Self::NAME)?;
10226        write!(f, "{}: {}", "channel_id", self.channel_id())?;
10227        write!(f, ", {}: {}", "tlc_id", self.tlc_id())?;
10228        write!(f, ", {}: {}", "reason", self.reason())?;
10229        let extra_count = self.count_extra_fields();
10230        if extra_count != 0 {
10231            write!(f, ", .. ({} fields)", extra_count)?;
10232        }
10233        write!(f, " }}")
10234    }
10235}
10236impl ::core::default::Default for RemoveTlc {
10237    fn default() -> Self {
10238        let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE);
10239        RemoveTlc::new_unchecked(v)
10240    }
10241}
10242impl RemoveTlc {
10243    const DEFAULT_VALUE: [u8; 92] = [
10244        92, 0, 0, 0, 16, 0, 0, 0, 48, 0, 0, 0, 56, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
10245        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,
10246        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,
10247        0, 0, 0,
10248    ];
10249    pub const FIELD_COUNT: usize = 3;
10250    pub fn total_size(&self) -> usize {
10251        molecule::unpack_number(self.as_slice()) as usize
10252    }
10253    pub fn field_count(&self) -> usize {
10254        if self.total_size() == molecule::NUMBER_SIZE {
10255            0
10256        } else {
10257            (molecule::unpack_number(&self.as_slice()[molecule::NUMBER_SIZE..]) as usize / 4) - 1
10258        }
10259    }
10260    pub fn count_extra_fields(&self) -> usize {
10261        self.field_count() - Self::FIELD_COUNT
10262    }
10263    pub fn has_extra_fields(&self) -> bool {
10264        Self::FIELD_COUNT != self.field_count()
10265    }
10266    pub fn channel_id(&self) -> Byte32 {
10267        let slice = self.as_slice();
10268        let start = molecule::unpack_number(&slice[4..]) as usize;
10269        let end = molecule::unpack_number(&slice[8..]) as usize;
10270        Byte32::new_unchecked(self.0.slice(start..end))
10271    }
10272    pub fn tlc_id(&self) -> Uint64 {
10273        let slice = self.as_slice();
10274        let start = molecule::unpack_number(&slice[8..]) as usize;
10275        let end = molecule::unpack_number(&slice[12..]) as usize;
10276        Uint64::new_unchecked(self.0.slice(start..end))
10277    }
10278    pub fn reason(&self) -> RemoveTlcReason {
10279        let slice = self.as_slice();
10280        let start = molecule::unpack_number(&slice[12..]) as usize;
10281        if self.has_extra_fields() {
10282            let end = molecule::unpack_number(&slice[16..]) as usize;
10283            RemoveTlcReason::new_unchecked(self.0.slice(start..end))
10284        } else {
10285            RemoveTlcReason::new_unchecked(self.0.slice(start..))
10286        }
10287    }
10288    pub fn as_reader<'r>(&'r self) -> RemoveTlcReader<'r> {
10289        RemoveTlcReader::new_unchecked(self.as_slice())
10290    }
10291}
10292impl molecule::prelude::Entity for RemoveTlc {
10293    type Builder = RemoveTlcBuilder;
10294    const NAME: &'static str = "RemoveTlc";
10295    fn new_unchecked(data: molecule::bytes::Bytes) -> Self {
10296        RemoveTlc(data)
10297    }
10298    fn as_bytes(&self) -> molecule::bytes::Bytes {
10299        self.0.clone()
10300    }
10301    fn as_slice(&self) -> &[u8] {
10302        &self.0[..]
10303    }
10304    fn from_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
10305        RemoveTlcReader::from_slice(slice).map(|reader| reader.to_entity())
10306    }
10307    fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
10308        RemoveTlcReader::from_compatible_slice(slice).map(|reader| reader.to_entity())
10309    }
10310    fn new_builder() -> Self::Builder {
10311        ::core::default::Default::default()
10312    }
10313    fn as_builder(self) -> Self::Builder {
10314        Self::new_builder()
10315            .channel_id(self.channel_id())
10316            .tlc_id(self.tlc_id())
10317            .reason(self.reason())
10318    }
10319}
10320#[derive(Clone, Copy)]
10321pub struct RemoveTlcReader<'r>(&'r [u8]);
10322impl<'r> ::core::fmt::LowerHex for RemoveTlcReader<'r> {
10323    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
10324        use molecule::hex_string;
10325        if f.alternate() {
10326            write!(f, "0x")?;
10327        }
10328        write!(f, "{}", hex_string(self.as_slice()))
10329    }
10330}
10331impl<'r> ::core::fmt::Debug for RemoveTlcReader<'r> {
10332    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
10333        write!(f, "{}({:#x})", Self::NAME, self)
10334    }
10335}
10336impl<'r> ::core::fmt::Display for RemoveTlcReader<'r> {
10337    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
10338        write!(f, "{} {{ ", Self::NAME)?;
10339        write!(f, "{}: {}", "channel_id", self.channel_id())?;
10340        write!(f, ", {}: {}", "tlc_id", self.tlc_id())?;
10341        write!(f, ", {}: {}", "reason", self.reason())?;
10342        let extra_count = self.count_extra_fields();
10343        if extra_count != 0 {
10344            write!(f, ", .. ({} fields)", extra_count)?;
10345        }
10346        write!(f, " }}")
10347    }
10348}
10349impl<'r> RemoveTlcReader<'r> {
10350    pub const FIELD_COUNT: usize = 3;
10351    pub fn total_size(&self) -> usize {
10352        molecule::unpack_number(self.as_slice()) as usize
10353    }
10354    pub fn field_count(&self) -> usize {
10355        if self.total_size() == molecule::NUMBER_SIZE {
10356            0
10357        } else {
10358            (molecule::unpack_number(&self.as_slice()[molecule::NUMBER_SIZE..]) as usize / 4) - 1
10359        }
10360    }
10361    pub fn count_extra_fields(&self) -> usize {
10362        self.field_count() - Self::FIELD_COUNT
10363    }
10364    pub fn has_extra_fields(&self) -> bool {
10365        Self::FIELD_COUNT != self.field_count()
10366    }
10367    pub fn channel_id(&self) -> Byte32Reader<'r> {
10368        let slice = self.as_slice();
10369        let start = molecule::unpack_number(&slice[4..]) as usize;
10370        let end = molecule::unpack_number(&slice[8..]) as usize;
10371        Byte32Reader::new_unchecked(&self.as_slice()[start..end])
10372    }
10373    pub fn tlc_id(&self) -> Uint64Reader<'r> {
10374        let slice = self.as_slice();
10375        let start = molecule::unpack_number(&slice[8..]) as usize;
10376        let end = molecule::unpack_number(&slice[12..]) as usize;
10377        Uint64Reader::new_unchecked(&self.as_slice()[start..end])
10378    }
10379    pub fn reason(&self) -> RemoveTlcReasonReader<'r> {
10380        let slice = self.as_slice();
10381        let start = molecule::unpack_number(&slice[12..]) as usize;
10382        if self.has_extra_fields() {
10383            let end = molecule::unpack_number(&slice[16..]) as usize;
10384            RemoveTlcReasonReader::new_unchecked(&self.as_slice()[start..end])
10385        } else {
10386            RemoveTlcReasonReader::new_unchecked(&self.as_slice()[start..])
10387        }
10388    }
10389}
10390impl<'r> molecule::prelude::Reader<'r> for RemoveTlcReader<'r> {
10391    type Entity = RemoveTlc;
10392    const NAME: &'static str = "RemoveTlcReader";
10393    fn to_entity(&self) -> Self::Entity {
10394        Self::Entity::new_unchecked(self.as_slice().to_owned().into())
10395    }
10396    fn new_unchecked(slice: &'r [u8]) -> Self {
10397        RemoveTlcReader(slice)
10398    }
10399    fn as_slice(&self) -> &'r [u8] {
10400        self.0
10401    }
10402    fn verify(slice: &[u8], compatible: bool) -> molecule::error::VerificationResult<()> {
10403        use molecule::verification_error as ve;
10404        let slice_len = slice.len();
10405        if slice_len < molecule::NUMBER_SIZE {
10406            return ve!(Self, HeaderIsBroken, molecule::NUMBER_SIZE, slice_len);
10407        }
10408        let total_size = molecule::unpack_number(slice) as usize;
10409        if slice_len != total_size {
10410            return ve!(Self, TotalSizeNotMatch, total_size, slice_len);
10411        }
10412        if slice_len < molecule::NUMBER_SIZE * 2 {
10413            return ve!(Self, HeaderIsBroken, molecule::NUMBER_SIZE * 2, slice_len);
10414        }
10415        let offset_first = molecule::unpack_number(&slice[molecule::NUMBER_SIZE..]) as usize;
10416        if offset_first % molecule::NUMBER_SIZE != 0 || offset_first < molecule::NUMBER_SIZE * 2 {
10417            return ve!(Self, OffsetsNotMatch);
10418        }
10419        if slice_len < offset_first {
10420            return ve!(Self, HeaderIsBroken, offset_first, slice_len);
10421        }
10422        let field_count = offset_first / molecule::NUMBER_SIZE - 1;
10423        if field_count < Self::FIELD_COUNT {
10424            return ve!(Self, FieldCountNotMatch, Self::FIELD_COUNT, field_count);
10425        } else if !compatible && field_count > Self::FIELD_COUNT {
10426            return ve!(Self, FieldCountNotMatch, Self::FIELD_COUNT, field_count);
10427        };
10428        let mut offsets: Vec<usize> = slice[molecule::NUMBER_SIZE..offset_first]
10429            .chunks_exact(molecule::NUMBER_SIZE)
10430            .map(|x| molecule::unpack_number(x) as usize)
10431            .collect();
10432        offsets.push(total_size);
10433        if offsets.windows(2).any(|i| i[0] > i[1]) {
10434            return ve!(Self, OffsetsNotMatch);
10435        }
10436        Byte32Reader::verify(&slice[offsets[0]..offsets[1]], compatible)?;
10437        Uint64Reader::verify(&slice[offsets[1]..offsets[2]], compatible)?;
10438        RemoveTlcReasonReader::verify(&slice[offsets[2]..offsets[3]], compatible)?;
10439        Ok(())
10440    }
10441}
10442#[derive(Clone, Debug, Default)]
10443pub struct RemoveTlcBuilder {
10444    pub(crate) channel_id: Byte32,
10445    pub(crate) tlc_id: Uint64,
10446    pub(crate) reason: RemoveTlcReason,
10447}
10448impl RemoveTlcBuilder {
10449    pub const FIELD_COUNT: usize = 3;
10450    pub fn channel_id(mut self, v: Byte32) -> Self {
10451        self.channel_id = v;
10452        self
10453    }
10454    pub fn tlc_id(mut self, v: Uint64) -> Self {
10455        self.tlc_id = v;
10456        self
10457    }
10458    pub fn reason(mut self, v: RemoveTlcReason) -> Self {
10459        self.reason = v;
10460        self
10461    }
10462}
10463impl molecule::prelude::Builder for RemoveTlcBuilder {
10464    type Entity = RemoveTlc;
10465    const NAME: &'static str = "RemoveTlcBuilder";
10466    fn expected_length(&self) -> usize {
10467        molecule::NUMBER_SIZE * (Self::FIELD_COUNT + 1)
10468            + self.channel_id.as_slice().len()
10469            + self.tlc_id.as_slice().len()
10470            + self.reason.as_slice().len()
10471    }
10472    fn write<W: molecule::io::Write>(&self, writer: &mut W) -> molecule::io::Result<()> {
10473        let mut total_size = molecule::NUMBER_SIZE * (Self::FIELD_COUNT + 1);
10474        let mut offsets = Vec::with_capacity(Self::FIELD_COUNT);
10475        offsets.push(total_size);
10476        total_size += self.channel_id.as_slice().len();
10477        offsets.push(total_size);
10478        total_size += self.tlc_id.as_slice().len();
10479        offsets.push(total_size);
10480        total_size += self.reason.as_slice().len();
10481        writer.write_all(&molecule::pack_number(total_size as molecule::Number))?;
10482        for offset in offsets.into_iter() {
10483            writer.write_all(&molecule::pack_number(offset as molecule::Number))?;
10484        }
10485        writer.write_all(self.channel_id.as_slice())?;
10486        writer.write_all(self.tlc_id.as_slice())?;
10487        writer.write_all(self.reason.as_slice())?;
10488        Ok(())
10489    }
10490    fn build(&self) -> Self::Entity {
10491        let mut inner = Vec::with_capacity(self.expected_length());
10492        self.write(&mut inner)
10493            .unwrap_or_else(|_| panic!("{} build should be ok", Self::NAME));
10494        RemoveTlc::new_unchecked(inner.into())
10495    }
10496}
10497#[derive(Clone)]
10498pub struct ReestablishChannel(molecule::bytes::Bytes);
10499impl ::core::fmt::LowerHex for ReestablishChannel {
10500    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
10501        use molecule::hex_string;
10502        if f.alternate() {
10503            write!(f, "0x")?;
10504        }
10505        write!(f, "{}", hex_string(self.as_slice()))
10506    }
10507}
10508impl ::core::fmt::Debug for ReestablishChannel {
10509    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
10510        write!(f, "{}({:#x})", Self::NAME, self)
10511    }
10512}
10513impl ::core::fmt::Display for ReestablishChannel {
10514    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
10515        write!(f, "{} {{ ", Self::NAME)?;
10516        write!(f, "{}: {}", "channel_id", self.channel_id())?;
10517        write!(
10518            f,
10519            ", {}: {}",
10520            "local_commitment_number",
10521            self.local_commitment_number()
10522        )?;
10523        write!(
10524            f,
10525            ", {}: {}",
10526            "remote_commitment_number",
10527            self.remote_commitment_number()
10528        )?;
10529        let extra_count = self.count_extra_fields();
10530        if extra_count != 0 {
10531            write!(f, ", .. ({} fields)", extra_count)?;
10532        }
10533        write!(f, " }}")
10534    }
10535}
10536impl ::core::default::Default for ReestablishChannel {
10537    fn default() -> Self {
10538        let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE);
10539        ReestablishChannel::new_unchecked(v)
10540    }
10541}
10542impl ReestablishChannel {
10543    const DEFAULT_VALUE: [u8; 64] = [
10544        64, 0, 0, 0, 16, 0, 0, 0, 48, 0, 0, 0, 56, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
10545        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,
10546        0, 0, 0, 0, 0,
10547    ];
10548    pub const FIELD_COUNT: usize = 3;
10549    pub fn total_size(&self) -> usize {
10550        molecule::unpack_number(self.as_slice()) as usize
10551    }
10552    pub fn field_count(&self) -> usize {
10553        if self.total_size() == molecule::NUMBER_SIZE {
10554            0
10555        } else {
10556            (molecule::unpack_number(&self.as_slice()[molecule::NUMBER_SIZE..]) as usize / 4) - 1
10557        }
10558    }
10559    pub fn count_extra_fields(&self) -> usize {
10560        self.field_count() - Self::FIELD_COUNT
10561    }
10562    pub fn has_extra_fields(&self) -> bool {
10563        Self::FIELD_COUNT != self.field_count()
10564    }
10565    pub fn channel_id(&self) -> Byte32 {
10566        let slice = self.as_slice();
10567        let start = molecule::unpack_number(&slice[4..]) as usize;
10568        let end = molecule::unpack_number(&slice[8..]) as usize;
10569        Byte32::new_unchecked(self.0.slice(start..end))
10570    }
10571    pub fn local_commitment_number(&self) -> Uint64 {
10572        let slice = self.as_slice();
10573        let start = molecule::unpack_number(&slice[8..]) as usize;
10574        let end = molecule::unpack_number(&slice[12..]) as usize;
10575        Uint64::new_unchecked(self.0.slice(start..end))
10576    }
10577    pub fn remote_commitment_number(&self) -> Uint64 {
10578        let slice = self.as_slice();
10579        let start = molecule::unpack_number(&slice[12..]) as usize;
10580        if self.has_extra_fields() {
10581            let end = molecule::unpack_number(&slice[16..]) as usize;
10582            Uint64::new_unchecked(self.0.slice(start..end))
10583        } else {
10584            Uint64::new_unchecked(self.0.slice(start..))
10585        }
10586    }
10587    pub fn as_reader<'r>(&'r self) -> ReestablishChannelReader<'r> {
10588        ReestablishChannelReader::new_unchecked(self.as_slice())
10589    }
10590}
10591impl molecule::prelude::Entity for ReestablishChannel {
10592    type Builder = ReestablishChannelBuilder;
10593    const NAME: &'static str = "ReestablishChannel";
10594    fn new_unchecked(data: molecule::bytes::Bytes) -> Self {
10595        ReestablishChannel(data)
10596    }
10597    fn as_bytes(&self) -> molecule::bytes::Bytes {
10598        self.0.clone()
10599    }
10600    fn as_slice(&self) -> &[u8] {
10601        &self.0[..]
10602    }
10603    fn from_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
10604        ReestablishChannelReader::from_slice(slice).map(|reader| reader.to_entity())
10605    }
10606    fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
10607        ReestablishChannelReader::from_compatible_slice(slice).map(|reader| reader.to_entity())
10608    }
10609    fn new_builder() -> Self::Builder {
10610        ::core::default::Default::default()
10611    }
10612    fn as_builder(self) -> Self::Builder {
10613        Self::new_builder()
10614            .channel_id(self.channel_id())
10615            .local_commitment_number(self.local_commitment_number())
10616            .remote_commitment_number(self.remote_commitment_number())
10617    }
10618}
10619#[derive(Clone, Copy)]
10620pub struct ReestablishChannelReader<'r>(&'r [u8]);
10621impl<'r> ::core::fmt::LowerHex for ReestablishChannelReader<'r> {
10622    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
10623        use molecule::hex_string;
10624        if f.alternate() {
10625            write!(f, "0x")?;
10626        }
10627        write!(f, "{}", hex_string(self.as_slice()))
10628    }
10629}
10630impl<'r> ::core::fmt::Debug for ReestablishChannelReader<'r> {
10631    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
10632        write!(f, "{}({:#x})", Self::NAME, self)
10633    }
10634}
10635impl<'r> ::core::fmt::Display for ReestablishChannelReader<'r> {
10636    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
10637        write!(f, "{} {{ ", Self::NAME)?;
10638        write!(f, "{}: {}", "channel_id", self.channel_id())?;
10639        write!(
10640            f,
10641            ", {}: {}",
10642            "local_commitment_number",
10643            self.local_commitment_number()
10644        )?;
10645        write!(
10646            f,
10647            ", {}: {}",
10648            "remote_commitment_number",
10649            self.remote_commitment_number()
10650        )?;
10651        let extra_count = self.count_extra_fields();
10652        if extra_count != 0 {
10653            write!(f, ", .. ({} fields)", extra_count)?;
10654        }
10655        write!(f, " }}")
10656    }
10657}
10658impl<'r> ReestablishChannelReader<'r> {
10659    pub const FIELD_COUNT: usize = 3;
10660    pub fn total_size(&self) -> usize {
10661        molecule::unpack_number(self.as_slice()) as usize
10662    }
10663    pub fn field_count(&self) -> usize {
10664        if self.total_size() == molecule::NUMBER_SIZE {
10665            0
10666        } else {
10667            (molecule::unpack_number(&self.as_slice()[molecule::NUMBER_SIZE..]) as usize / 4) - 1
10668        }
10669    }
10670    pub fn count_extra_fields(&self) -> usize {
10671        self.field_count() - Self::FIELD_COUNT
10672    }
10673    pub fn has_extra_fields(&self) -> bool {
10674        Self::FIELD_COUNT != self.field_count()
10675    }
10676    pub fn channel_id(&self) -> Byte32Reader<'r> {
10677        let slice = self.as_slice();
10678        let start = molecule::unpack_number(&slice[4..]) as usize;
10679        let end = molecule::unpack_number(&slice[8..]) as usize;
10680        Byte32Reader::new_unchecked(&self.as_slice()[start..end])
10681    }
10682    pub fn local_commitment_number(&self) -> Uint64Reader<'r> {
10683        let slice = self.as_slice();
10684        let start = molecule::unpack_number(&slice[8..]) as usize;
10685        let end = molecule::unpack_number(&slice[12..]) as usize;
10686        Uint64Reader::new_unchecked(&self.as_slice()[start..end])
10687    }
10688    pub fn remote_commitment_number(&self) -> Uint64Reader<'r> {
10689        let slice = self.as_slice();
10690        let start = molecule::unpack_number(&slice[12..]) as usize;
10691        if self.has_extra_fields() {
10692            let end = molecule::unpack_number(&slice[16..]) as usize;
10693            Uint64Reader::new_unchecked(&self.as_slice()[start..end])
10694        } else {
10695            Uint64Reader::new_unchecked(&self.as_slice()[start..])
10696        }
10697    }
10698}
10699impl<'r> molecule::prelude::Reader<'r> for ReestablishChannelReader<'r> {
10700    type Entity = ReestablishChannel;
10701    const NAME: &'static str = "ReestablishChannelReader";
10702    fn to_entity(&self) -> Self::Entity {
10703        Self::Entity::new_unchecked(self.as_slice().to_owned().into())
10704    }
10705    fn new_unchecked(slice: &'r [u8]) -> Self {
10706        ReestablishChannelReader(slice)
10707    }
10708    fn as_slice(&self) -> &'r [u8] {
10709        self.0
10710    }
10711    fn verify(slice: &[u8], compatible: bool) -> molecule::error::VerificationResult<()> {
10712        use molecule::verification_error as ve;
10713        let slice_len = slice.len();
10714        if slice_len < molecule::NUMBER_SIZE {
10715            return ve!(Self, HeaderIsBroken, molecule::NUMBER_SIZE, slice_len);
10716        }
10717        let total_size = molecule::unpack_number(slice) as usize;
10718        if slice_len != total_size {
10719            return ve!(Self, TotalSizeNotMatch, total_size, slice_len);
10720        }
10721        if slice_len < molecule::NUMBER_SIZE * 2 {
10722            return ve!(Self, HeaderIsBroken, molecule::NUMBER_SIZE * 2, slice_len);
10723        }
10724        let offset_first = molecule::unpack_number(&slice[molecule::NUMBER_SIZE..]) as usize;
10725        if offset_first % molecule::NUMBER_SIZE != 0 || offset_first < molecule::NUMBER_SIZE * 2 {
10726            return ve!(Self, OffsetsNotMatch);
10727        }
10728        if slice_len < offset_first {
10729            return ve!(Self, HeaderIsBroken, offset_first, slice_len);
10730        }
10731        let field_count = offset_first / molecule::NUMBER_SIZE - 1;
10732        if field_count < Self::FIELD_COUNT {
10733            return ve!(Self, FieldCountNotMatch, Self::FIELD_COUNT, field_count);
10734        } else if !compatible && field_count > Self::FIELD_COUNT {
10735            return ve!(Self, FieldCountNotMatch, Self::FIELD_COUNT, field_count);
10736        };
10737        let mut offsets: Vec<usize> = slice[molecule::NUMBER_SIZE..offset_first]
10738            .chunks_exact(molecule::NUMBER_SIZE)
10739            .map(|x| molecule::unpack_number(x) as usize)
10740            .collect();
10741        offsets.push(total_size);
10742        if offsets.windows(2).any(|i| i[0] > i[1]) {
10743            return ve!(Self, OffsetsNotMatch);
10744        }
10745        Byte32Reader::verify(&slice[offsets[0]..offsets[1]], compatible)?;
10746        Uint64Reader::verify(&slice[offsets[1]..offsets[2]], compatible)?;
10747        Uint64Reader::verify(&slice[offsets[2]..offsets[3]], compatible)?;
10748        Ok(())
10749    }
10750}
10751#[derive(Clone, Debug, Default)]
10752pub struct ReestablishChannelBuilder {
10753    pub(crate) channel_id: Byte32,
10754    pub(crate) local_commitment_number: Uint64,
10755    pub(crate) remote_commitment_number: Uint64,
10756}
10757impl ReestablishChannelBuilder {
10758    pub const FIELD_COUNT: usize = 3;
10759    pub fn channel_id(mut self, v: Byte32) -> Self {
10760        self.channel_id = v;
10761        self
10762    }
10763    pub fn local_commitment_number(mut self, v: Uint64) -> Self {
10764        self.local_commitment_number = v;
10765        self
10766    }
10767    pub fn remote_commitment_number(mut self, v: Uint64) -> Self {
10768        self.remote_commitment_number = v;
10769        self
10770    }
10771}
10772impl molecule::prelude::Builder for ReestablishChannelBuilder {
10773    type Entity = ReestablishChannel;
10774    const NAME: &'static str = "ReestablishChannelBuilder";
10775    fn expected_length(&self) -> usize {
10776        molecule::NUMBER_SIZE * (Self::FIELD_COUNT + 1)
10777            + self.channel_id.as_slice().len()
10778            + self.local_commitment_number.as_slice().len()
10779            + self.remote_commitment_number.as_slice().len()
10780    }
10781    fn write<W: molecule::io::Write>(&self, writer: &mut W) -> molecule::io::Result<()> {
10782        let mut total_size = molecule::NUMBER_SIZE * (Self::FIELD_COUNT + 1);
10783        let mut offsets = Vec::with_capacity(Self::FIELD_COUNT);
10784        offsets.push(total_size);
10785        total_size += self.channel_id.as_slice().len();
10786        offsets.push(total_size);
10787        total_size += self.local_commitment_number.as_slice().len();
10788        offsets.push(total_size);
10789        total_size += self.remote_commitment_number.as_slice().len();
10790        writer.write_all(&molecule::pack_number(total_size as molecule::Number))?;
10791        for offset in offsets.into_iter() {
10792            writer.write_all(&molecule::pack_number(offset as molecule::Number))?;
10793        }
10794        writer.write_all(self.channel_id.as_slice())?;
10795        writer.write_all(self.local_commitment_number.as_slice())?;
10796        writer.write_all(self.remote_commitment_number.as_slice())?;
10797        Ok(())
10798    }
10799    fn build(&self) -> Self::Entity {
10800        let mut inner = Vec::with_capacity(self.expected_length());
10801        self.write(&mut inner)
10802            .unwrap_or_else(|_| panic!("{} build should be ok", Self::NAME));
10803        ReestablishChannel::new_unchecked(inner.into())
10804    }
10805}
10806#[derive(Clone)]
10807pub struct AnnouncementSignatures(molecule::bytes::Bytes);
10808impl ::core::fmt::LowerHex for AnnouncementSignatures {
10809    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
10810        use molecule::hex_string;
10811        if f.alternate() {
10812            write!(f, "0x")?;
10813        }
10814        write!(f, "{}", hex_string(self.as_slice()))
10815    }
10816}
10817impl ::core::fmt::Debug for AnnouncementSignatures {
10818    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
10819        write!(f, "{}({:#x})", Self::NAME, self)
10820    }
10821}
10822impl ::core::fmt::Display for AnnouncementSignatures {
10823    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
10824        write!(f, "{} {{ ", Self::NAME)?;
10825        write!(f, "{}: {}", "channel_id", self.channel_id())?;
10826        write!(f, ", {}: {}", "channel_outpoint", self.channel_outpoint())?;
10827        write!(f, ", {}: {}", "node_signature", self.node_signature())?;
10828        write!(f, ", {}: {}", "partial_signature", self.partial_signature())?;
10829        let extra_count = self.count_extra_fields();
10830        if extra_count != 0 {
10831            write!(f, ", .. ({} fields)", extra_count)?;
10832        }
10833        write!(f, " }}")
10834    }
10835}
10836impl ::core::default::Default for AnnouncementSignatures {
10837    fn default() -> Self {
10838        let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE);
10839        AnnouncementSignatures::new_unchecked(v)
10840    }
10841}
10842impl AnnouncementSignatures {
10843    const DEFAULT_VALUE: [u8; 184] = [
10844        184, 0, 0, 0, 20, 0, 0, 0, 52, 0, 0, 0, 88, 0, 0, 0, 152, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
10845        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,
10846        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,
10847        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,
10848        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,
10849        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,
10850        0, 0, 0, 0, 0, 0,
10851    ];
10852    pub const FIELD_COUNT: usize = 4;
10853    pub fn total_size(&self) -> usize {
10854        molecule::unpack_number(self.as_slice()) as usize
10855    }
10856    pub fn field_count(&self) -> usize {
10857        if self.total_size() == molecule::NUMBER_SIZE {
10858            0
10859        } else {
10860            (molecule::unpack_number(&self.as_slice()[molecule::NUMBER_SIZE..]) as usize / 4) - 1
10861        }
10862    }
10863    pub fn count_extra_fields(&self) -> usize {
10864        self.field_count() - Self::FIELD_COUNT
10865    }
10866    pub fn has_extra_fields(&self) -> bool {
10867        Self::FIELD_COUNT != self.field_count()
10868    }
10869    pub fn channel_id(&self) -> Byte32 {
10870        let slice = self.as_slice();
10871        let start = molecule::unpack_number(&slice[4..]) as usize;
10872        let end = molecule::unpack_number(&slice[8..]) as usize;
10873        Byte32::new_unchecked(self.0.slice(start..end))
10874    }
10875    pub fn channel_outpoint(&self) -> OutPoint {
10876        let slice = self.as_slice();
10877        let start = molecule::unpack_number(&slice[8..]) as usize;
10878        let end = molecule::unpack_number(&slice[12..]) as usize;
10879        OutPoint::new_unchecked(self.0.slice(start..end))
10880    }
10881    pub fn node_signature(&self) -> EcdsaSignature {
10882        let slice = self.as_slice();
10883        let start = molecule::unpack_number(&slice[12..]) as usize;
10884        let end = molecule::unpack_number(&slice[16..]) as usize;
10885        EcdsaSignature::new_unchecked(self.0.slice(start..end))
10886    }
10887    pub fn partial_signature(&self) -> Byte32 {
10888        let slice = self.as_slice();
10889        let start = molecule::unpack_number(&slice[16..]) as usize;
10890        if self.has_extra_fields() {
10891            let end = molecule::unpack_number(&slice[20..]) as usize;
10892            Byte32::new_unchecked(self.0.slice(start..end))
10893        } else {
10894            Byte32::new_unchecked(self.0.slice(start..))
10895        }
10896    }
10897    pub fn as_reader<'r>(&'r self) -> AnnouncementSignaturesReader<'r> {
10898        AnnouncementSignaturesReader::new_unchecked(self.as_slice())
10899    }
10900}
10901impl molecule::prelude::Entity for AnnouncementSignatures {
10902    type Builder = AnnouncementSignaturesBuilder;
10903    const NAME: &'static str = "AnnouncementSignatures";
10904    fn new_unchecked(data: molecule::bytes::Bytes) -> Self {
10905        AnnouncementSignatures(data)
10906    }
10907    fn as_bytes(&self) -> molecule::bytes::Bytes {
10908        self.0.clone()
10909    }
10910    fn as_slice(&self) -> &[u8] {
10911        &self.0[..]
10912    }
10913    fn from_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
10914        AnnouncementSignaturesReader::from_slice(slice).map(|reader| reader.to_entity())
10915    }
10916    fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
10917        AnnouncementSignaturesReader::from_compatible_slice(slice).map(|reader| reader.to_entity())
10918    }
10919    fn new_builder() -> Self::Builder {
10920        ::core::default::Default::default()
10921    }
10922    fn as_builder(self) -> Self::Builder {
10923        Self::new_builder()
10924            .channel_id(self.channel_id())
10925            .channel_outpoint(self.channel_outpoint())
10926            .node_signature(self.node_signature())
10927            .partial_signature(self.partial_signature())
10928    }
10929}
10930#[derive(Clone, Copy)]
10931pub struct AnnouncementSignaturesReader<'r>(&'r [u8]);
10932impl<'r> ::core::fmt::LowerHex for AnnouncementSignaturesReader<'r> {
10933    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
10934        use molecule::hex_string;
10935        if f.alternate() {
10936            write!(f, "0x")?;
10937        }
10938        write!(f, "{}", hex_string(self.as_slice()))
10939    }
10940}
10941impl<'r> ::core::fmt::Debug for AnnouncementSignaturesReader<'r> {
10942    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
10943        write!(f, "{}({:#x})", Self::NAME, self)
10944    }
10945}
10946impl<'r> ::core::fmt::Display for AnnouncementSignaturesReader<'r> {
10947    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
10948        write!(f, "{} {{ ", Self::NAME)?;
10949        write!(f, "{}: {}", "channel_id", self.channel_id())?;
10950        write!(f, ", {}: {}", "channel_outpoint", self.channel_outpoint())?;
10951        write!(f, ", {}: {}", "node_signature", self.node_signature())?;
10952        write!(f, ", {}: {}", "partial_signature", self.partial_signature())?;
10953        let extra_count = self.count_extra_fields();
10954        if extra_count != 0 {
10955            write!(f, ", .. ({} fields)", extra_count)?;
10956        }
10957        write!(f, " }}")
10958    }
10959}
10960impl<'r> AnnouncementSignaturesReader<'r> {
10961    pub const FIELD_COUNT: usize = 4;
10962    pub fn total_size(&self) -> usize {
10963        molecule::unpack_number(self.as_slice()) as usize
10964    }
10965    pub fn field_count(&self) -> usize {
10966        if self.total_size() == molecule::NUMBER_SIZE {
10967            0
10968        } else {
10969            (molecule::unpack_number(&self.as_slice()[molecule::NUMBER_SIZE..]) as usize / 4) - 1
10970        }
10971    }
10972    pub fn count_extra_fields(&self) -> usize {
10973        self.field_count() - Self::FIELD_COUNT
10974    }
10975    pub fn has_extra_fields(&self) -> bool {
10976        Self::FIELD_COUNT != self.field_count()
10977    }
10978    pub fn channel_id(&self) -> Byte32Reader<'r> {
10979        let slice = self.as_slice();
10980        let start = molecule::unpack_number(&slice[4..]) as usize;
10981        let end = molecule::unpack_number(&slice[8..]) as usize;
10982        Byte32Reader::new_unchecked(&self.as_slice()[start..end])
10983    }
10984    pub fn channel_outpoint(&self) -> OutPointReader<'r> {
10985        let slice = self.as_slice();
10986        let start = molecule::unpack_number(&slice[8..]) as usize;
10987        let end = molecule::unpack_number(&slice[12..]) as usize;
10988        OutPointReader::new_unchecked(&self.as_slice()[start..end])
10989    }
10990    pub fn node_signature(&self) -> EcdsaSignatureReader<'r> {
10991        let slice = self.as_slice();
10992        let start = molecule::unpack_number(&slice[12..]) as usize;
10993        let end = molecule::unpack_number(&slice[16..]) as usize;
10994        EcdsaSignatureReader::new_unchecked(&self.as_slice()[start..end])
10995    }
10996    pub fn partial_signature(&self) -> Byte32Reader<'r> {
10997        let slice = self.as_slice();
10998        let start = molecule::unpack_number(&slice[16..]) as usize;
10999        if self.has_extra_fields() {
11000            let end = molecule::unpack_number(&slice[20..]) as usize;
11001            Byte32Reader::new_unchecked(&self.as_slice()[start..end])
11002        } else {
11003            Byte32Reader::new_unchecked(&self.as_slice()[start..])
11004        }
11005    }
11006}
11007impl<'r> molecule::prelude::Reader<'r> for AnnouncementSignaturesReader<'r> {
11008    type Entity = AnnouncementSignatures;
11009    const NAME: &'static str = "AnnouncementSignaturesReader";
11010    fn to_entity(&self) -> Self::Entity {
11011        Self::Entity::new_unchecked(self.as_slice().to_owned().into())
11012    }
11013    fn new_unchecked(slice: &'r [u8]) -> Self {
11014        AnnouncementSignaturesReader(slice)
11015    }
11016    fn as_slice(&self) -> &'r [u8] {
11017        self.0
11018    }
11019    fn verify(slice: &[u8], compatible: bool) -> molecule::error::VerificationResult<()> {
11020        use molecule::verification_error as ve;
11021        let slice_len = slice.len();
11022        if slice_len < molecule::NUMBER_SIZE {
11023            return ve!(Self, HeaderIsBroken, molecule::NUMBER_SIZE, slice_len);
11024        }
11025        let total_size = molecule::unpack_number(slice) as usize;
11026        if slice_len != total_size {
11027            return ve!(Self, TotalSizeNotMatch, total_size, slice_len);
11028        }
11029        if slice_len < molecule::NUMBER_SIZE * 2 {
11030            return ve!(Self, HeaderIsBroken, molecule::NUMBER_SIZE * 2, slice_len);
11031        }
11032        let offset_first = molecule::unpack_number(&slice[molecule::NUMBER_SIZE..]) as usize;
11033        if offset_first % molecule::NUMBER_SIZE != 0 || offset_first < molecule::NUMBER_SIZE * 2 {
11034            return ve!(Self, OffsetsNotMatch);
11035        }
11036        if slice_len < offset_first {
11037            return ve!(Self, HeaderIsBroken, offset_first, slice_len);
11038        }
11039        let field_count = offset_first / molecule::NUMBER_SIZE - 1;
11040        if field_count < Self::FIELD_COUNT {
11041            return ve!(Self, FieldCountNotMatch, Self::FIELD_COUNT, field_count);
11042        } else if !compatible && field_count > Self::FIELD_COUNT {
11043            return ve!(Self, FieldCountNotMatch, Self::FIELD_COUNT, field_count);
11044        };
11045        let mut offsets: Vec<usize> = slice[molecule::NUMBER_SIZE..offset_first]
11046            .chunks_exact(molecule::NUMBER_SIZE)
11047            .map(|x| molecule::unpack_number(x) as usize)
11048            .collect();
11049        offsets.push(total_size);
11050        if offsets.windows(2).any(|i| i[0] > i[1]) {
11051            return ve!(Self, OffsetsNotMatch);
11052        }
11053        Byte32Reader::verify(&slice[offsets[0]..offsets[1]], compatible)?;
11054        OutPointReader::verify(&slice[offsets[1]..offsets[2]], compatible)?;
11055        EcdsaSignatureReader::verify(&slice[offsets[2]..offsets[3]], compatible)?;
11056        Byte32Reader::verify(&slice[offsets[3]..offsets[4]], compatible)?;
11057        Ok(())
11058    }
11059}
11060#[derive(Clone, Debug, Default)]
11061pub struct AnnouncementSignaturesBuilder {
11062    pub(crate) channel_id: Byte32,
11063    pub(crate) channel_outpoint: OutPoint,
11064    pub(crate) node_signature: EcdsaSignature,
11065    pub(crate) partial_signature: Byte32,
11066}
11067impl AnnouncementSignaturesBuilder {
11068    pub const FIELD_COUNT: usize = 4;
11069    pub fn channel_id(mut self, v: Byte32) -> Self {
11070        self.channel_id = v;
11071        self
11072    }
11073    pub fn channel_outpoint(mut self, v: OutPoint) -> Self {
11074        self.channel_outpoint = v;
11075        self
11076    }
11077    pub fn node_signature(mut self, v: EcdsaSignature) -> Self {
11078        self.node_signature = v;
11079        self
11080    }
11081    pub fn partial_signature(mut self, v: Byte32) -> Self {
11082        self.partial_signature = v;
11083        self
11084    }
11085}
11086impl molecule::prelude::Builder for AnnouncementSignaturesBuilder {
11087    type Entity = AnnouncementSignatures;
11088    const NAME: &'static str = "AnnouncementSignaturesBuilder";
11089    fn expected_length(&self) -> usize {
11090        molecule::NUMBER_SIZE * (Self::FIELD_COUNT + 1)
11091            + self.channel_id.as_slice().len()
11092            + self.channel_outpoint.as_slice().len()
11093            + self.node_signature.as_slice().len()
11094            + self.partial_signature.as_slice().len()
11095    }
11096    fn write<W: molecule::io::Write>(&self, writer: &mut W) -> molecule::io::Result<()> {
11097        let mut total_size = molecule::NUMBER_SIZE * (Self::FIELD_COUNT + 1);
11098        let mut offsets = Vec::with_capacity(Self::FIELD_COUNT);
11099        offsets.push(total_size);
11100        total_size += self.channel_id.as_slice().len();
11101        offsets.push(total_size);
11102        total_size += self.channel_outpoint.as_slice().len();
11103        offsets.push(total_size);
11104        total_size += self.node_signature.as_slice().len();
11105        offsets.push(total_size);
11106        total_size += self.partial_signature.as_slice().len();
11107        writer.write_all(&molecule::pack_number(total_size as molecule::Number))?;
11108        for offset in offsets.into_iter() {
11109            writer.write_all(&molecule::pack_number(offset as molecule::Number))?;
11110        }
11111        writer.write_all(self.channel_id.as_slice())?;
11112        writer.write_all(self.channel_outpoint.as_slice())?;
11113        writer.write_all(self.node_signature.as_slice())?;
11114        writer.write_all(self.partial_signature.as_slice())?;
11115        Ok(())
11116    }
11117    fn build(&self) -> Self::Entity {
11118        let mut inner = Vec::with_capacity(self.expected_length());
11119        self.write(&mut inner)
11120            .unwrap_or_else(|_| panic!("{} build should be ok", Self::NAME));
11121        AnnouncementSignatures::new_unchecked(inner.into())
11122    }
11123}
11124#[derive(Clone)]
11125pub struct UdtDep(molecule::bytes::Bytes);
11126impl ::core::fmt::LowerHex for UdtDep {
11127    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
11128        use molecule::hex_string;
11129        if f.alternate() {
11130            write!(f, "0x")?;
11131        }
11132        write!(f, "{}", hex_string(self.as_slice()))
11133    }
11134}
11135impl ::core::fmt::Debug for UdtDep {
11136    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
11137        write!(f, "{}({:#x})", Self::NAME, self)
11138    }
11139}
11140impl ::core::fmt::Display for UdtDep {
11141    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
11142        write!(f, "{}(", Self::NAME)?;
11143        self.to_enum().display_inner(f)?;
11144        write!(f, ")")
11145    }
11146}
11147impl ::core::default::Default for UdtDep {
11148    fn default() -> Self {
11149        let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE);
11150        UdtDep::new_unchecked(v)
11151    }
11152}
11153impl UdtDep {
11154    const DEFAULT_VALUE: [u8; 53] = [
11155        0, 0, 0, 0, 49, 0, 0, 0, 12, 0, 0, 0, 48, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
11156        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
11157    ];
11158    pub const ITEMS_COUNT: usize = 2;
11159    pub fn item_id(&self) -> molecule::Number {
11160        molecule::unpack_number(self.as_slice())
11161    }
11162    pub fn to_enum(&self) -> UdtDepUnion {
11163        let inner = self.0.slice(molecule::NUMBER_SIZE..);
11164        match self.item_id() {
11165            0 => UdtCellDep::new_unchecked(inner).into(),
11166            1 => Script::new_unchecked(inner).into(),
11167            _ => panic!("{}: invalid data", Self::NAME),
11168        }
11169    }
11170    pub fn as_reader<'r>(&'r self) -> UdtDepReader<'r> {
11171        UdtDepReader::new_unchecked(self.as_slice())
11172    }
11173}
11174impl molecule::prelude::Entity for UdtDep {
11175    type Builder = UdtDepBuilder;
11176    const NAME: &'static str = "UdtDep";
11177    fn new_unchecked(data: molecule::bytes::Bytes) -> Self {
11178        UdtDep(data)
11179    }
11180    fn as_bytes(&self) -> molecule::bytes::Bytes {
11181        self.0.clone()
11182    }
11183    fn as_slice(&self) -> &[u8] {
11184        &self.0[..]
11185    }
11186    fn from_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
11187        UdtDepReader::from_slice(slice).map(|reader| reader.to_entity())
11188    }
11189    fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
11190        UdtDepReader::from_compatible_slice(slice).map(|reader| reader.to_entity())
11191    }
11192    fn new_builder() -> Self::Builder {
11193        ::core::default::Default::default()
11194    }
11195    fn as_builder(self) -> Self::Builder {
11196        Self::new_builder().set(self.to_enum())
11197    }
11198}
11199#[derive(Clone, Copy)]
11200pub struct UdtDepReader<'r>(&'r [u8]);
11201impl<'r> ::core::fmt::LowerHex for UdtDepReader<'r> {
11202    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
11203        use molecule::hex_string;
11204        if f.alternate() {
11205            write!(f, "0x")?;
11206        }
11207        write!(f, "{}", hex_string(self.as_slice()))
11208    }
11209}
11210impl<'r> ::core::fmt::Debug for UdtDepReader<'r> {
11211    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
11212        write!(f, "{}({:#x})", Self::NAME, self)
11213    }
11214}
11215impl<'r> ::core::fmt::Display for UdtDepReader<'r> {
11216    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
11217        write!(f, "{}(", Self::NAME)?;
11218        self.to_enum().display_inner(f)?;
11219        write!(f, ")")
11220    }
11221}
11222impl<'r> UdtDepReader<'r> {
11223    pub const ITEMS_COUNT: usize = 2;
11224    pub fn item_id(&self) -> molecule::Number {
11225        molecule::unpack_number(self.as_slice())
11226    }
11227    pub fn to_enum(&self) -> UdtDepUnionReader<'r> {
11228        let inner = &self.as_slice()[molecule::NUMBER_SIZE..];
11229        match self.item_id() {
11230            0 => UdtCellDepReader::new_unchecked(inner).into(),
11231            1 => ScriptReader::new_unchecked(inner).into(),
11232            _ => panic!("{}: invalid data", Self::NAME),
11233        }
11234    }
11235}
11236impl<'r> molecule::prelude::Reader<'r> for UdtDepReader<'r> {
11237    type Entity = UdtDep;
11238    const NAME: &'static str = "UdtDepReader";
11239    fn to_entity(&self) -> Self::Entity {
11240        Self::Entity::new_unchecked(self.as_slice().to_owned().into())
11241    }
11242    fn new_unchecked(slice: &'r [u8]) -> Self {
11243        UdtDepReader(slice)
11244    }
11245    fn as_slice(&self) -> &'r [u8] {
11246        self.0
11247    }
11248    fn verify(slice: &[u8], compatible: bool) -> molecule::error::VerificationResult<()> {
11249        use molecule::verification_error as ve;
11250        let slice_len = slice.len();
11251        if slice_len < molecule::NUMBER_SIZE {
11252            return ve!(Self, HeaderIsBroken, molecule::NUMBER_SIZE, slice_len);
11253        }
11254        let item_id = molecule::unpack_number(slice);
11255        let inner_slice = &slice[molecule::NUMBER_SIZE..];
11256        match item_id {
11257            0 => UdtCellDepReader::verify(inner_slice, compatible),
11258            1 => ScriptReader::verify(inner_slice, compatible),
11259            _ => ve!(Self, UnknownItem, Self::ITEMS_COUNT, item_id),
11260        }?;
11261        Ok(())
11262    }
11263}
11264#[derive(Clone, Debug, Default)]
11265pub struct UdtDepBuilder(pub(crate) UdtDepUnion);
11266impl UdtDepBuilder {
11267    pub const ITEMS_COUNT: usize = 2;
11268    pub fn set<I>(mut self, v: I) -> Self
11269    where
11270        I: ::core::convert::Into<UdtDepUnion>,
11271    {
11272        self.0 = v.into();
11273        self
11274    }
11275}
11276impl molecule::prelude::Builder for UdtDepBuilder {
11277    type Entity = UdtDep;
11278    const NAME: &'static str = "UdtDepBuilder";
11279    fn expected_length(&self) -> usize {
11280        molecule::NUMBER_SIZE + self.0.as_slice().len()
11281    }
11282    fn write<W: molecule::io::Write>(&self, writer: &mut W) -> molecule::io::Result<()> {
11283        writer.write_all(&molecule::pack_number(self.0.item_id()))?;
11284        writer.write_all(self.0.as_slice())
11285    }
11286    fn build(&self) -> Self::Entity {
11287        let mut inner = Vec::with_capacity(self.expected_length());
11288        self.write(&mut inner)
11289            .unwrap_or_else(|_| panic!("{} build should be ok", Self::NAME));
11290        UdtDep::new_unchecked(inner.into())
11291    }
11292}
11293#[derive(Debug, Clone)]
11294pub enum UdtDepUnion {
11295    UdtCellDep(UdtCellDep),
11296    Script(Script),
11297}
11298#[derive(Debug, Clone, Copy)]
11299pub enum UdtDepUnionReader<'r> {
11300    UdtCellDep(UdtCellDepReader<'r>),
11301    Script(ScriptReader<'r>),
11302}
11303impl ::core::default::Default for UdtDepUnion {
11304    fn default() -> Self {
11305        UdtDepUnion::UdtCellDep(::core::default::Default::default())
11306    }
11307}
11308impl ::core::fmt::Display for UdtDepUnion {
11309    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
11310        match self {
11311            UdtDepUnion::UdtCellDep(ref item) => {
11312                write!(f, "{}::{}({})", Self::NAME, UdtCellDep::NAME, item)
11313            }
11314            UdtDepUnion::Script(ref item) => {
11315                write!(f, "{}::{}({})", Self::NAME, Script::NAME, item)
11316            }
11317        }
11318    }
11319}
11320impl<'r> ::core::fmt::Display for UdtDepUnionReader<'r> {
11321    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
11322        match self {
11323            UdtDepUnionReader::UdtCellDep(ref item) => {
11324                write!(f, "{}::{}({})", Self::NAME, UdtCellDep::NAME, item)
11325            }
11326            UdtDepUnionReader::Script(ref item) => {
11327                write!(f, "{}::{}({})", Self::NAME, Script::NAME, item)
11328            }
11329        }
11330    }
11331}
11332impl UdtDepUnion {
11333    pub(crate) fn display_inner(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
11334        match self {
11335            UdtDepUnion::UdtCellDep(ref item) => write!(f, "{}", item),
11336            UdtDepUnion::Script(ref item) => write!(f, "{}", item),
11337        }
11338    }
11339}
11340impl<'r> UdtDepUnionReader<'r> {
11341    pub(crate) fn display_inner(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
11342        match self {
11343            UdtDepUnionReader::UdtCellDep(ref item) => write!(f, "{}", item),
11344            UdtDepUnionReader::Script(ref item) => write!(f, "{}", item),
11345        }
11346    }
11347}
11348impl ::core::convert::From<UdtCellDep> for UdtDepUnion {
11349    fn from(item: UdtCellDep) -> Self {
11350        UdtDepUnion::UdtCellDep(item)
11351    }
11352}
11353impl ::core::convert::From<Script> for UdtDepUnion {
11354    fn from(item: Script) -> Self {
11355        UdtDepUnion::Script(item)
11356    }
11357}
11358impl<'r> ::core::convert::From<UdtCellDepReader<'r>> for UdtDepUnionReader<'r> {
11359    fn from(item: UdtCellDepReader<'r>) -> Self {
11360        UdtDepUnionReader::UdtCellDep(item)
11361    }
11362}
11363impl<'r> ::core::convert::From<ScriptReader<'r>> for UdtDepUnionReader<'r> {
11364    fn from(item: ScriptReader<'r>) -> Self {
11365        UdtDepUnionReader::Script(item)
11366    }
11367}
11368impl UdtDepUnion {
11369    pub const NAME: &'static str = "UdtDepUnion";
11370    pub fn as_bytes(&self) -> molecule::bytes::Bytes {
11371        match self {
11372            UdtDepUnion::UdtCellDep(item) => item.as_bytes(),
11373            UdtDepUnion::Script(item) => item.as_bytes(),
11374        }
11375    }
11376    pub fn as_slice(&self) -> &[u8] {
11377        match self {
11378            UdtDepUnion::UdtCellDep(item) => item.as_slice(),
11379            UdtDepUnion::Script(item) => item.as_slice(),
11380        }
11381    }
11382    pub fn item_id(&self) -> molecule::Number {
11383        match self {
11384            UdtDepUnion::UdtCellDep(_) => 0,
11385            UdtDepUnion::Script(_) => 1,
11386        }
11387    }
11388    pub fn item_name(&self) -> &str {
11389        match self {
11390            UdtDepUnion::UdtCellDep(_) => "UdtCellDep",
11391            UdtDepUnion::Script(_) => "Script",
11392        }
11393    }
11394    pub fn as_reader<'r>(&'r self) -> UdtDepUnionReader<'r> {
11395        match self {
11396            UdtDepUnion::UdtCellDep(item) => item.as_reader().into(),
11397            UdtDepUnion::Script(item) => item.as_reader().into(),
11398        }
11399    }
11400}
11401impl<'r> UdtDepUnionReader<'r> {
11402    pub const NAME: &'r str = "UdtDepUnionReader";
11403    pub fn as_slice(&self) -> &'r [u8] {
11404        match self {
11405            UdtDepUnionReader::UdtCellDep(item) => item.as_slice(),
11406            UdtDepUnionReader::Script(item) => item.as_slice(),
11407        }
11408    }
11409    pub fn item_id(&self) -> molecule::Number {
11410        match self {
11411            UdtDepUnionReader::UdtCellDep(_) => 0,
11412            UdtDepUnionReader::Script(_) => 1,
11413        }
11414    }
11415    pub fn item_name(&self) -> &str {
11416        match self {
11417            UdtDepUnionReader::UdtCellDep(_) => "UdtCellDep",
11418            UdtDepUnionReader::Script(_) => "Script",
11419        }
11420    }
11421}
11422impl From<UdtCellDep> for UdtDep {
11423    fn from(value: UdtCellDep) -> Self {
11424        Self::new_builder().set(value).build()
11425    }
11426}
11427impl From<Script> for UdtDep {
11428    fn from(value: Script) -> Self {
11429        Self::new_builder().set(value).build()
11430    }
11431}
11432#[derive(Clone)]
11433pub struct UdtCellDep(molecule::bytes::Bytes);
11434impl ::core::fmt::LowerHex for UdtCellDep {
11435    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
11436        use molecule::hex_string;
11437        if f.alternate() {
11438            write!(f, "0x")?;
11439        }
11440        write!(f, "{}", hex_string(self.as_slice()))
11441    }
11442}
11443impl ::core::fmt::Debug for UdtCellDep {
11444    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
11445        write!(f, "{}({:#x})", Self::NAME, self)
11446    }
11447}
11448impl ::core::fmt::Display for UdtCellDep {
11449    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
11450        write!(f, "{} {{ ", Self::NAME)?;
11451        write!(f, "{}: {}", "out_point", self.out_point())?;
11452        write!(f, ", {}: {}", "dep_type", self.dep_type())?;
11453        let extra_count = self.count_extra_fields();
11454        if extra_count != 0 {
11455            write!(f, ", .. ({} fields)", extra_count)?;
11456        }
11457        write!(f, " }}")
11458    }
11459}
11460impl ::core::default::Default for UdtCellDep {
11461    fn default() -> Self {
11462        let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE);
11463        UdtCellDep::new_unchecked(v)
11464    }
11465}
11466impl UdtCellDep {
11467    const DEFAULT_VALUE: [u8; 49] = [
11468        49, 0, 0, 0, 12, 0, 0, 0, 48, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
11469        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
11470    ];
11471    pub const FIELD_COUNT: usize = 2;
11472    pub fn total_size(&self) -> usize {
11473        molecule::unpack_number(self.as_slice()) as usize
11474    }
11475    pub fn field_count(&self) -> usize {
11476        if self.total_size() == molecule::NUMBER_SIZE {
11477            0
11478        } else {
11479            (molecule::unpack_number(&self.as_slice()[molecule::NUMBER_SIZE..]) as usize / 4) - 1
11480        }
11481    }
11482    pub fn count_extra_fields(&self) -> usize {
11483        self.field_count() - Self::FIELD_COUNT
11484    }
11485    pub fn has_extra_fields(&self) -> bool {
11486        Self::FIELD_COUNT != self.field_count()
11487    }
11488    pub fn out_point(&self) -> OutPoint {
11489        let slice = self.as_slice();
11490        let start = molecule::unpack_number(&slice[4..]) as usize;
11491        let end = molecule::unpack_number(&slice[8..]) as usize;
11492        OutPoint::new_unchecked(self.0.slice(start..end))
11493    }
11494    pub fn dep_type(&self) -> Byte {
11495        let slice = self.as_slice();
11496        let start = molecule::unpack_number(&slice[8..]) as usize;
11497        if self.has_extra_fields() {
11498            let end = molecule::unpack_number(&slice[12..]) as usize;
11499            Byte::new_unchecked(self.0.slice(start..end))
11500        } else {
11501            Byte::new_unchecked(self.0.slice(start..))
11502        }
11503    }
11504    pub fn as_reader<'r>(&'r self) -> UdtCellDepReader<'r> {
11505        UdtCellDepReader::new_unchecked(self.as_slice())
11506    }
11507}
11508impl molecule::prelude::Entity for UdtCellDep {
11509    type Builder = UdtCellDepBuilder;
11510    const NAME: &'static str = "UdtCellDep";
11511    fn new_unchecked(data: molecule::bytes::Bytes) -> Self {
11512        UdtCellDep(data)
11513    }
11514    fn as_bytes(&self) -> molecule::bytes::Bytes {
11515        self.0.clone()
11516    }
11517    fn as_slice(&self) -> &[u8] {
11518        &self.0[..]
11519    }
11520    fn from_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
11521        UdtCellDepReader::from_slice(slice).map(|reader| reader.to_entity())
11522    }
11523    fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
11524        UdtCellDepReader::from_compatible_slice(slice).map(|reader| reader.to_entity())
11525    }
11526    fn new_builder() -> Self::Builder {
11527        ::core::default::Default::default()
11528    }
11529    fn as_builder(self) -> Self::Builder {
11530        Self::new_builder()
11531            .out_point(self.out_point())
11532            .dep_type(self.dep_type())
11533    }
11534}
11535#[derive(Clone, Copy)]
11536pub struct UdtCellDepReader<'r>(&'r [u8]);
11537impl<'r> ::core::fmt::LowerHex for UdtCellDepReader<'r> {
11538    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
11539        use molecule::hex_string;
11540        if f.alternate() {
11541            write!(f, "0x")?;
11542        }
11543        write!(f, "{}", hex_string(self.as_slice()))
11544    }
11545}
11546impl<'r> ::core::fmt::Debug for UdtCellDepReader<'r> {
11547    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
11548        write!(f, "{}({:#x})", Self::NAME, self)
11549    }
11550}
11551impl<'r> ::core::fmt::Display for UdtCellDepReader<'r> {
11552    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
11553        write!(f, "{} {{ ", Self::NAME)?;
11554        write!(f, "{}: {}", "out_point", self.out_point())?;
11555        write!(f, ", {}: {}", "dep_type", self.dep_type())?;
11556        let extra_count = self.count_extra_fields();
11557        if extra_count != 0 {
11558            write!(f, ", .. ({} fields)", extra_count)?;
11559        }
11560        write!(f, " }}")
11561    }
11562}
11563impl<'r> UdtCellDepReader<'r> {
11564    pub const FIELD_COUNT: usize = 2;
11565    pub fn total_size(&self) -> usize {
11566        molecule::unpack_number(self.as_slice()) as usize
11567    }
11568    pub fn field_count(&self) -> usize {
11569        if self.total_size() == molecule::NUMBER_SIZE {
11570            0
11571        } else {
11572            (molecule::unpack_number(&self.as_slice()[molecule::NUMBER_SIZE..]) as usize / 4) - 1
11573        }
11574    }
11575    pub fn count_extra_fields(&self) -> usize {
11576        self.field_count() - Self::FIELD_COUNT
11577    }
11578    pub fn has_extra_fields(&self) -> bool {
11579        Self::FIELD_COUNT != self.field_count()
11580    }
11581    pub fn out_point(&self) -> OutPointReader<'r> {
11582        let slice = self.as_slice();
11583        let start = molecule::unpack_number(&slice[4..]) as usize;
11584        let end = molecule::unpack_number(&slice[8..]) as usize;
11585        OutPointReader::new_unchecked(&self.as_slice()[start..end])
11586    }
11587    pub fn dep_type(&self) -> ByteReader<'r> {
11588        let slice = self.as_slice();
11589        let start = molecule::unpack_number(&slice[8..]) as usize;
11590        if self.has_extra_fields() {
11591            let end = molecule::unpack_number(&slice[12..]) as usize;
11592            ByteReader::new_unchecked(&self.as_slice()[start..end])
11593        } else {
11594            ByteReader::new_unchecked(&self.as_slice()[start..])
11595        }
11596    }
11597}
11598impl<'r> molecule::prelude::Reader<'r> for UdtCellDepReader<'r> {
11599    type Entity = UdtCellDep;
11600    const NAME: &'static str = "UdtCellDepReader";
11601    fn to_entity(&self) -> Self::Entity {
11602        Self::Entity::new_unchecked(self.as_slice().to_owned().into())
11603    }
11604    fn new_unchecked(slice: &'r [u8]) -> Self {
11605        UdtCellDepReader(slice)
11606    }
11607    fn as_slice(&self) -> &'r [u8] {
11608        self.0
11609    }
11610    fn verify(slice: &[u8], compatible: bool) -> molecule::error::VerificationResult<()> {
11611        use molecule::verification_error as ve;
11612        let slice_len = slice.len();
11613        if slice_len < molecule::NUMBER_SIZE {
11614            return ve!(Self, HeaderIsBroken, molecule::NUMBER_SIZE, slice_len);
11615        }
11616        let total_size = molecule::unpack_number(slice) as usize;
11617        if slice_len != total_size {
11618            return ve!(Self, TotalSizeNotMatch, total_size, slice_len);
11619        }
11620        if slice_len < molecule::NUMBER_SIZE * 2 {
11621            return ve!(Self, HeaderIsBroken, molecule::NUMBER_SIZE * 2, slice_len);
11622        }
11623        let offset_first = molecule::unpack_number(&slice[molecule::NUMBER_SIZE..]) as usize;
11624        if offset_first % molecule::NUMBER_SIZE != 0 || offset_first < molecule::NUMBER_SIZE * 2 {
11625            return ve!(Self, OffsetsNotMatch);
11626        }
11627        if slice_len < offset_first {
11628            return ve!(Self, HeaderIsBroken, offset_first, slice_len);
11629        }
11630        let field_count = offset_first / molecule::NUMBER_SIZE - 1;
11631        if field_count < Self::FIELD_COUNT {
11632            return ve!(Self, FieldCountNotMatch, Self::FIELD_COUNT, field_count);
11633        } else if !compatible && field_count > Self::FIELD_COUNT {
11634            return ve!(Self, FieldCountNotMatch, Self::FIELD_COUNT, field_count);
11635        };
11636        let mut offsets: Vec<usize> = slice[molecule::NUMBER_SIZE..offset_first]
11637            .chunks_exact(molecule::NUMBER_SIZE)
11638            .map(|x| molecule::unpack_number(x) as usize)
11639            .collect();
11640        offsets.push(total_size);
11641        if offsets.windows(2).any(|i| i[0] > i[1]) {
11642            return ve!(Self, OffsetsNotMatch);
11643        }
11644        OutPointReader::verify(&slice[offsets[0]..offsets[1]], compatible)?;
11645        ByteReader::verify(&slice[offsets[1]..offsets[2]], compatible)?;
11646        Ok(())
11647    }
11648}
11649#[derive(Clone, Debug, Default)]
11650pub struct UdtCellDepBuilder {
11651    pub(crate) out_point: OutPoint,
11652    pub(crate) dep_type: Byte,
11653}
11654impl UdtCellDepBuilder {
11655    pub const FIELD_COUNT: usize = 2;
11656    pub fn out_point(mut self, v: OutPoint) -> Self {
11657        self.out_point = v;
11658        self
11659    }
11660    pub fn dep_type(mut self, v: Byte) -> Self {
11661        self.dep_type = v;
11662        self
11663    }
11664}
11665impl molecule::prelude::Builder for UdtCellDepBuilder {
11666    type Entity = UdtCellDep;
11667    const NAME: &'static str = "UdtCellDepBuilder";
11668    fn expected_length(&self) -> usize {
11669        molecule::NUMBER_SIZE * (Self::FIELD_COUNT + 1)
11670            + self.out_point.as_slice().len()
11671            + self.dep_type.as_slice().len()
11672    }
11673    fn write<W: molecule::io::Write>(&self, writer: &mut W) -> molecule::io::Result<()> {
11674        let mut total_size = molecule::NUMBER_SIZE * (Self::FIELD_COUNT + 1);
11675        let mut offsets = Vec::with_capacity(Self::FIELD_COUNT);
11676        offsets.push(total_size);
11677        total_size += self.out_point.as_slice().len();
11678        offsets.push(total_size);
11679        total_size += self.dep_type.as_slice().len();
11680        writer.write_all(&molecule::pack_number(total_size as molecule::Number))?;
11681        for offset in offsets.into_iter() {
11682            writer.write_all(&molecule::pack_number(offset as molecule::Number))?;
11683        }
11684        writer.write_all(self.out_point.as_slice())?;
11685        writer.write_all(self.dep_type.as_slice())?;
11686        Ok(())
11687    }
11688    fn build(&self) -> Self::Entity {
11689        let mut inner = Vec::with_capacity(self.expected_length());
11690        self.write(&mut inner)
11691            .unwrap_or_else(|_| panic!("{} build should be ok", Self::NAME));
11692        UdtCellDep::new_unchecked(inner.into())
11693    }
11694}
11695#[derive(Clone)]
11696pub struct UdtScript(molecule::bytes::Bytes);
11697impl ::core::fmt::LowerHex for UdtScript {
11698    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
11699        use molecule::hex_string;
11700        if f.alternate() {
11701            write!(f, "0x")?;
11702        }
11703        write!(f, "{}", hex_string(self.as_slice()))
11704    }
11705}
11706impl ::core::fmt::Debug for UdtScript {
11707    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
11708        write!(f, "{}({:#x})", Self::NAME, self)
11709    }
11710}
11711impl ::core::fmt::Display for UdtScript {
11712    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
11713        write!(f, "{} {{ ", Self::NAME)?;
11714        write!(f, "{}: {}", "code_hash", self.code_hash())?;
11715        write!(f, ", {}: {}", "hash_type", self.hash_type())?;
11716        write!(f, ", {}: {}", "args", self.args())?;
11717        let extra_count = self.count_extra_fields();
11718        if extra_count != 0 {
11719            write!(f, ", .. ({} fields)", extra_count)?;
11720        }
11721        write!(f, " }}")
11722    }
11723}
11724impl ::core::default::Default for UdtScript {
11725    fn default() -> Self {
11726        let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE);
11727        UdtScript::new_unchecked(v)
11728    }
11729}
11730impl UdtScript {
11731    const DEFAULT_VALUE: [u8; 53] = [
11732        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,
11733        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
11734    ];
11735    pub const FIELD_COUNT: usize = 3;
11736    pub fn total_size(&self) -> usize {
11737        molecule::unpack_number(self.as_slice()) as usize
11738    }
11739    pub fn field_count(&self) -> usize {
11740        if self.total_size() == molecule::NUMBER_SIZE {
11741            0
11742        } else {
11743            (molecule::unpack_number(&self.as_slice()[molecule::NUMBER_SIZE..]) as usize / 4) - 1
11744        }
11745    }
11746    pub fn count_extra_fields(&self) -> usize {
11747        self.field_count() - Self::FIELD_COUNT
11748    }
11749    pub fn has_extra_fields(&self) -> bool {
11750        Self::FIELD_COUNT != self.field_count()
11751    }
11752    pub fn code_hash(&self) -> Byte32 {
11753        let slice = self.as_slice();
11754        let start = molecule::unpack_number(&slice[4..]) as usize;
11755        let end = molecule::unpack_number(&slice[8..]) as usize;
11756        Byte32::new_unchecked(self.0.slice(start..end))
11757    }
11758    pub fn hash_type(&self) -> Byte {
11759        let slice = self.as_slice();
11760        let start = molecule::unpack_number(&slice[8..]) as usize;
11761        let end = molecule::unpack_number(&slice[12..]) as usize;
11762        Byte::new_unchecked(self.0.slice(start..end))
11763    }
11764    pub fn args(&self) -> Bytes {
11765        let slice = self.as_slice();
11766        let start = molecule::unpack_number(&slice[12..]) as usize;
11767        if self.has_extra_fields() {
11768            let end = molecule::unpack_number(&slice[16..]) as usize;
11769            Bytes::new_unchecked(self.0.slice(start..end))
11770        } else {
11771            Bytes::new_unchecked(self.0.slice(start..))
11772        }
11773    }
11774    pub fn as_reader<'r>(&'r self) -> UdtScriptReader<'r> {
11775        UdtScriptReader::new_unchecked(self.as_slice())
11776    }
11777}
11778impl molecule::prelude::Entity for UdtScript {
11779    type Builder = UdtScriptBuilder;
11780    const NAME: &'static str = "UdtScript";
11781    fn new_unchecked(data: molecule::bytes::Bytes) -> Self {
11782        UdtScript(data)
11783    }
11784    fn as_bytes(&self) -> molecule::bytes::Bytes {
11785        self.0.clone()
11786    }
11787    fn as_slice(&self) -> &[u8] {
11788        &self.0[..]
11789    }
11790    fn from_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
11791        UdtScriptReader::from_slice(slice).map(|reader| reader.to_entity())
11792    }
11793    fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
11794        UdtScriptReader::from_compatible_slice(slice).map(|reader| reader.to_entity())
11795    }
11796    fn new_builder() -> Self::Builder {
11797        ::core::default::Default::default()
11798    }
11799    fn as_builder(self) -> Self::Builder {
11800        Self::new_builder()
11801            .code_hash(self.code_hash())
11802            .hash_type(self.hash_type())
11803            .args(self.args())
11804    }
11805}
11806#[derive(Clone, Copy)]
11807pub struct UdtScriptReader<'r>(&'r [u8]);
11808impl<'r> ::core::fmt::LowerHex for UdtScriptReader<'r> {
11809    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
11810        use molecule::hex_string;
11811        if f.alternate() {
11812            write!(f, "0x")?;
11813        }
11814        write!(f, "{}", hex_string(self.as_slice()))
11815    }
11816}
11817impl<'r> ::core::fmt::Debug for UdtScriptReader<'r> {
11818    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
11819        write!(f, "{}({:#x})", Self::NAME, self)
11820    }
11821}
11822impl<'r> ::core::fmt::Display for UdtScriptReader<'r> {
11823    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
11824        write!(f, "{} {{ ", Self::NAME)?;
11825        write!(f, "{}: {}", "code_hash", self.code_hash())?;
11826        write!(f, ", {}: {}", "hash_type", self.hash_type())?;
11827        write!(f, ", {}: {}", "args", self.args())?;
11828        let extra_count = self.count_extra_fields();
11829        if extra_count != 0 {
11830            write!(f, ", .. ({} fields)", extra_count)?;
11831        }
11832        write!(f, " }}")
11833    }
11834}
11835impl<'r> UdtScriptReader<'r> {
11836    pub const FIELD_COUNT: usize = 3;
11837    pub fn total_size(&self) -> usize {
11838        molecule::unpack_number(self.as_slice()) as usize
11839    }
11840    pub fn field_count(&self) -> usize {
11841        if self.total_size() == molecule::NUMBER_SIZE {
11842            0
11843        } else {
11844            (molecule::unpack_number(&self.as_slice()[molecule::NUMBER_SIZE..]) as usize / 4) - 1
11845        }
11846    }
11847    pub fn count_extra_fields(&self) -> usize {
11848        self.field_count() - Self::FIELD_COUNT
11849    }
11850    pub fn has_extra_fields(&self) -> bool {
11851        Self::FIELD_COUNT != self.field_count()
11852    }
11853    pub fn code_hash(&self) -> Byte32Reader<'r> {
11854        let slice = self.as_slice();
11855        let start = molecule::unpack_number(&slice[4..]) as usize;
11856        let end = molecule::unpack_number(&slice[8..]) as usize;
11857        Byte32Reader::new_unchecked(&self.as_slice()[start..end])
11858    }
11859    pub fn hash_type(&self) -> ByteReader<'r> {
11860        let slice = self.as_slice();
11861        let start = molecule::unpack_number(&slice[8..]) as usize;
11862        let end = molecule::unpack_number(&slice[12..]) as usize;
11863        ByteReader::new_unchecked(&self.as_slice()[start..end])
11864    }
11865    pub fn args(&self) -> BytesReader<'r> {
11866        let slice = self.as_slice();
11867        let start = molecule::unpack_number(&slice[12..]) as usize;
11868        if self.has_extra_fields() {
11869            let end = molecule::unpack_number(&slice[16..]) as usize;
11870            BytesReader::new_unchecked(&self.as_slice()[start..end])
11871        } else {
11872            BytesReader::new_unchecked(&self.as_slice()[start..])
11873        }
11874    }
11875}
11876impl<'r> molecule::prelude::Reader<'r> for UdtScriptReader<'r> {
11877    type Entity = UdtScript;
11878    const NAME: &'static str = "UdtScriptReader";
11879    fn to_entity(&self) -> Self::Entity {
11880        Self::Entity::new_unchecked(self.as_slice().to_owned().into())
11881    }
11882    fn new_unchecked(slice: &'r [u8]) -> Self {
11883        UdtScriptReader(slice)
11884    }
11885    fn as_slice(&self) -> &'r [u8] {
11886        self.0
11887    }
11888    fn verify(slice: &[u8], compatible: bool) -> molecule::error::VerificationResult<()> {
11889        use molecule::verification_error as ve;
11890        let slice_len = slice.len();
11891        if slice_len < molecule::NUMBER_SIZE {
11892            return ve!(Self, HeaderIsBroken, molecule::NUMBER_SIZE, slice_len);
11893        }
11894        let total_size = molecule::unpack_number(slice) as usize;
11895        if slice_len != total_size {
11896            return ve!(Self, TotalSizeNotMatch, total_size, slice_len);
11897        }
11898        if slice_len < molecule::NUMBER_SIZE * 2 {
11899            return ve!(Self, HeaderIsBroken, molecule::NUMBER_SIZE * 2, slice_len);
11900        }
11901        let offset_first = molecule::unpack_number(&slice[molecule::NUMBER_SIZE..]) as usize;
11902        if offset_first % molecule::NUMBER_SIZE != 0 || offset_first < molecule::NUMBER_SIZE * 2 {
11903            return ve!(Self, OffsetsNotMatch);
11904        }
11905        if slice_len < offset_first {
11906            return ve!(Self, HeaderIsBroken, offset_first, slice_len);
11907        }
11908        let field_count = offset_first / molecule::NUMBER_SIZE - 1;
11909        if field_count < Self::FIELD_COUNT {
11910            return ve!(Self, FieldCountNotMatch, Self::FIELD_COUNT, field_count);
11911        } else if !compatible && field_count > Self::FIELD_COUNT {
11912            return ve!(Self, FieldCountNotMatch, Self::FIELD_COUNT, field_count);
11913        };
11914        let mut offsets: Vec<usize> = slice[molecule::NUMBER_SIZE..offset_first]
11915            .chunks_exact(molecule::NUMBER_SIZE)
11916            .map(|x| molecule::unpack_number(x) as usize)
11917            .collect();
11918        offsets.push(total_size);
11919        if offsets.windows(2).any(|i| i[0] > i[1]) {
11920            return ve!(Self, OffsetsNotMatch);
11921        }
11922        Byte32Reader::verify(&slice[offsets[0]..offsets[1]], compatible)?;
11923        ByteReader::verify(&slice[offsets[1]..offsets[2]], compatible)?;
11924        BytesReader::verify(&slice[offsets[2]..offsets[3]], compatible)?;
11925        Ok(())
11926    }
11927}
11928#[derive(Clone, Debug, Default)]
11929pub struct UdtScriptBuilder {
11930    pub(crate) code_hash: Byte32,
11931    pub(crate) hash_type: Byte,
11932    pub(crate) args: Bytes,
11933}
11934impl UdtScriptBuilder {
11935    pub const FIELD_COUNT: usize = 3;
11936    pub fn code_hash(mut self, v: Byte32) -> Self {
11937        self.code_hash = v;
11938        self
11939    }
11940    pub fn hash_type(mut self, v: Byte) -> Self {
11941        self.hash_type = v;
11942        self
11943    }
11944    pub fn args(mut self, v: Bytes) -> Self {
11945        self.args = v;
11946        self
11947    }
11948}
11949impl molecule::prelude::Builder for UdtScriptBuilder {
11950    type Entity = UdtScript;
11951    const NAME: &'static str = "UdtScriptBuilder";
11952    fn expected_length(&self) -> usize {
11953        molecule::NUMBER_SIZE * (Self::FIELD_COUNT + 1)
11954            + self.code_hash.as_slice().len()
11955            + self.hash_type.as_slice().len()
11956            + self.args.as_slice().len()
11957    }
11958    fn write<W: molecule::io::Write>(&self, writer: &mut W) -> molecule::io::Result<()> {
11959        let mut total_size = molecule::NUMBER_SIZE * (Self::FIELD_COUNT + 1);
11960        let mut offsets = Vec::with_capacity(Self::FIELD_COUNT);
11961        offsets.push(total_size);
11962        total_size += self.code_hash.as_slice().len();
11963        offsets.push(total_size);
11964        total_size += self.hash_type.as_slice().len();
11965        offsets.push(total_size);
11966        total_size += self.args.as_slice().len();
11967        writer.write_all(&molecule::pack_number(total_size as molecule::Number))?;
11968        for offset in offsets.into_iter() {
11969            writer.write_all(&molecule::pack_number(offset as molecule::Number))?;
11970        }
11971        writer.write_all(self.code_hash.as_slice())?;
11972        writer.write_all(self.hash_type.as_slice())?;
11973        writer.write_all(self.args.as_slice())?;
11974        Ok(())
11975    }
11976    fn build(&self) -> Self::Entity {
11977        let mut inner = Vec::with_capacity(self.expected_length());
11978        self.write(&mut inner)
11979            .unwrap_or_else(|_| panic!("{} build should be ok", Self::NAME));
11980        UdtScript::new_unchecked(inner.into())
11981    }
11982}
11983#[derive(Clone)]
11984pub struct UdtCellDeps(molecule::bytes::Bytes);
11985impl ::core::fmt::LowerHex for UdtCellDeps {
11986    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
11987        use molecule::hex_string;
11988        if f.alternate() {
11989            write!(f, "0x")?;
11990        }
11991        write!(f, "{}", hex_string(self.as_slice()))
11992    }
11993}
11994impl ::core::fmt::Debug for UdtCellDeps {
11995    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
11996        write!(f, "{}({:#x})", Self::NAME, self)
11997    }
11998}
11999impl ::core::fmt::Display for UdtCellDeps {
12000    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
12001        write!(f, "{} [", Self::NAME)?;
12002        for i in 0..self.len() {
12003            if i == 0 {
12004                write!(f, "{}", self.get_unchecked(i))?;
12005            } else {
12006                write!(f, ", {}", self.get_unchecked(i))?;
12007            }
12008        }
12009        write!(f, "]")
12010    }
12011}
12012impl ::core::default::Default for UdtCellDeps {
12013    fn default() -> Self {
12014        let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE);
12015        UdtCellDeps::new_unchecked(v)
12016    }
12017}
12018impl UdtCellDeps {
12019    const DEFAULT_VALUE: [u8; 4] = [4, 0, 0, 0];
12020    pub fn total_size(&self) -> usize {
12021        molecule::unpack_number(self.as_slice()) as usize
12022    }
12023    pub fn item_count(&self) -> usize {
12024        if self.total_size() == molecule::NUMBER_SIZE {
12025            0
12026        } else {
12027            (molecule::unpack_number(&self.as_slice()[molecule::NUMBER_SIZE..]) as usize / 4) - 1
12028        }
12029    }
12030    pub fn len(&self) -> usize {
12031        self.item_count()
12032    }
12033    pub fn is_empty(&self) -> bool {
12034        self.len() == 0
12035    }
12036    pub fn get(&self, idx: usize) -> Option<UdtDep> {
12037        if idx >= self.len() {
12038            None
12039        } else {
12040            Some(self.get_unchecked(idx))
12041        }
12042    }
12043    pub fn get_unchecked(&self, idx: usize) -> UdtDep {
12044        let slice = self.as_slice();
12045        let start_idx = molecule::NUMBER_SIZE * (1 + idx);
12046        let start = molecule::unpack_number(&slice[start_idx..]) as usize;
12047        if idx == self.len() - 1 {
12048            UdtDep::new_unchecked(self.0.slice(start..))
12049        } else {
12050            let end_idx = start_idx + molecule::NUMBER_SIZE;
12051            let end = molecule::unpack_number(&slice[end_idx..]) as usize;
12052            UdtDep::new_unchecked(self.0.slice(start..end))
12053        }
12054    }
12055    pub fn as_reader<'r>(&'r self) -> UdtCellDepsReader<'r> {
12056        UdtCellDepsReader::new_unchecked(self.as_slice())
12057    }
12058}
12059impl molecule::prelude::Entity for UdtCellDeps {
12060    type Builder = UdtCellDepsBuilder;
12061    const NAME: &'static str = "UdtCellDeps";
12062    fn new_unchecked(data: molecule::bytes::Bytes) -> Self {
12063        UdtCellDeps(data)
12064    }
12065    fn as_bytes(&self) -> molecule::bytes::Bytes {
12066        self.0.clone()
12067    }
12068    fn as_slice(&self) -> &[u8] {
12069        &self.0[..]
12070    }
12071    fn from_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
12072        UdtCellDepsReader::from_slice(slice).map(|reader| reader.to_entity())
12073    }
12074    fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
12075        UdtCellDepsReader::from_compatible_slice(slice).map(|reader| reader.to_entity())
12076    }
12077    fn new_builder() -> Self::Builder {
12078        ::core::default::Default::default()
12079    }
12080    fn as_builder(self) -> Self::Builder {
12081        Self::new_builder().extend(self.into_iter())
12082    }
12083}
12084#[derive(Clone, Copy)]
12085pub struct UdtCellDepsReader<'r>(&'r [u8]);
12086impl<'r> ::core::fmt::LowerHex for UdtCellDepsReader<'r> {
12087    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
12088        use molecule::hex_string;
12089        if f.alternate() {
12090            write!(f, "0x")?;
12091        }
12092        write!(f, "{}", hex_string(self.as_slice()))
12093    }
12094}
12095impl<'r> ::core::fmt::Debug for UdtCellDepsReader<'r> {
12096    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
12097        write!(f, "{}({:#x})", Self::NAME, self)
12098    }
12099}
12100impl<'r> ::core::fmt::Display for UdtCellDepsReader<'r> {
12101    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
12102        write!(f, "{} [", Self::NAME)?;
12103        for i in 0..self.len() {
12104            if i == 0 {
12105                write!(f, "{}", self.get_unchecked(i))?;
12106            } else {
12107                write!(f, ", {}", self.get_unchecked(i))?;
12108            }
12109        }
12110        write!(f, "]")
12111    }
12112}
12113impl<'r> UdtCellDepsReader<'r> {
12114    pub fn total_size(&self) -> usize {
12115        molecule::unpack_number(self.as_slice()) as usize
12116    }
12117    pub fn item_count(&self) -> usize {
12118        if self.total_size() == molecule::NUMBER_SIZE {
12119            0
12120        } else {
12121            (molecule::unpack_number(&self.as_slice()[molecule::NUMBER_SIZE..]) as usize / 4) - 1
12122        }
12123    }
12124    pub fn len(&self) -> usize {
12125        self.item_count()
12126    }
12127    pub fn is_empty(&self) -> bool {
12128        self.len() == 0
12129    }
12130    pub fn get(&self, idx: usize) -> Option<UdtDepReader<'r>> {
12131        if idx >= self.len() {
12132            None
12133        } else {
12134            Some(self.get_unchecked(idx))
12135        }
12136    }
12137    pub fn get_unchecked(&self, idx: usize) -> UdtDepReader<'r> {
12138        let slice = self.as_slice();
12139        let start_idx = molecule::NUMBER_SIZE * (1 + idx);
12140        let start = molecule::unpack_number(&slice[start_idx..]) as usize;
12141        if idx == self.len() - 1 {
12142            UdtDepReader::new_unchecked(&self.as_slice()[start..])
12143        } else {
12144            let end_idx = start_idx + molecule::NUMBER_SIZE;
12145            let end = molecule::unpack_number(&slice[end_idx..]) as usize;
12146            UdtDepReader::new_unchecked(&self.as_slice()[start..end])
12147        }
12148    }
12149}
12150impl<'r> molecule::prelude::Reader<'r> for UdtCellDepsReader<'r> {
12151    type Entity = UdtCellDeps;
12152    const NAME: &'static str = "UdtCellDepsReader";
12153    fn to_entity(&self) -> Self::Entity {
12154        Self::Entity::new_unchecked(self.as_slice().to_owned().into())
12155    }
12156    fn new_unchecked(slice: &'r [u8]) -> Self {
12157        UdtCellDepsReader(slice)
12158    }
12159    fn as_slice(&self) -> &'r [u8] {
12160        self.0
12161    }
12162    fn verify(slice: &[u8], compatible: bool) -> molecule::error::VerificationResult<()> {
12163        use molecule::verification_error as ve;
12164        let slice_len = slice.len();
12165        if slice_len < molecule::NUMBER_SIZE {
12166            return ve!(Self, HeaderIsBroken, molecule::NUMBER_SIZE, slice_len);
12167        }
12168        let total_size = molecule::unpack_number(slice) as usize;
12169        if slice_len != total_size {
12170            return ve!(Self, TotalSizeNotMatch, total_size, slice_len);
12171        }
12172        if slice_len == molecule::NUMBER_SIZE {
12173            return Ok(());
12174        }
12175        if slice_len < molecule::NUMBER_SIZE * 2 {
12176            return ve!(
12177                Self,
12178                TotalSizeNotMatch,
12179                molecule::NUMBER_SIZE * 2,
12180                slice_len
12181            );
12182        }
12183        let offset_first = molecule::unpack_number(&slice[molecule::NUMBER_SIZE..]) as usize;
12184        if offset_first % molecule::NUMBER_SIZE != 0 || offset_first < molecule::NUMBER_SIZE * 2 {
12185            return ve!(Self, OffsetsNotMatch);
12186        }
12187        if slice_len < offset_first {
12188            return ve!(Self, HeaderIsBroken, offset_first, slice_len);
12189        }
12190        let mut offsets: Vec<usize> = slice[molecule::NUMBER_SIZE..offset_first]
12191            .chunks_exact(molecule::NUMBER_SIZE)
12192            .map(|x| molecule::unpack_number(x) as usize)
12193            .collect();
12194        offsets.push(total_size);
12195        if offsets.windows(2).any(|i| i[0] > i[1]) {
12196            return ve!(Self, OffsetsNotMatch);
12197        }
12198        for pair in offsets.windows(2) {
12199            let start = pair[0];
12200            let end = pair[1];
12201            UdtDepReader::verify(&slice[start..end], compatible)?;
12202        }
12203        Ok(())
12204    }
12205}
12206#[derive(Clone, Debug, Default)]
12207pub struct UdtCellDepsBuilder(pub(crate) Vec<UdtDep>);
12208impl UdtCellDepsBuilder {
12209    pub fn set(mut self, v: Vec<UdtDep>) -> Self {
12210        self.0 = v;
12211        self
12212    }
12213    pub fn push(mut self, v: UdtDep) -> Self {
12214        self.0.push(v);
12215        self
12216    }
12217    pub fn extend<T: ::core::iter::IntoIterator<Item = UdtDep>>(mut self, iter: T) -> Self {
12218        for elem in iter {
12219            self.0.push(elem);
12220        }
12221        self
12222    }
12223    pub fn replace(&mut self, index: usize, v: UdtDep) -> Option<UdtDep> {
12224        self.0
12225            .get_mut(index)
12226            .map(|item| ::core::mem::replace(item, v))
12227    }
12228}
12229impl molecule::prelude::Builder for UdtCellDepsBuilder {
12230    type Entity = UdtCellDeps;
12231    const NAME: &'static str = "UdtCellDepsBuilder";
12232    fn expected_length(&self) -> usize {
12233        molecule::NUMBER_SIZE * (self.0.len() + 1)
12234            + self
12235                .0
12236                .iter()
12237                .map(|inner| inner.as_slice().len())
12238                .sum::<usize>()
12239    }
12240    fn write<W: molecule::io::Write>(&self, writer: &mut W) -> molecule::io::Result<()> {
12241        let item_count = self.0.len();
12242        if item_count == 0 {
12243            writer.write_all(&molecule::pack_number(
12244                molecule::NUMBER_SIZE as molecule::Number,
12245            ))?;
12246        } else {
12247            let (total_size, offsets) = self.0.iter().fold(
12248                (
12249                    molecule::NUMBER_SIZE * (item_count + 1),
12250                    Vec::with_capacity(item_count),
12251                ),
12252                |(start, mut offsets), inner| {
12253                    offsets.push(start);
12254                    (start + inner.as_slice().len(), offsets)
12255                },
12256            );
12257            writer.write_all(&molecule::pack_number(total_size as molecule::Number))?;
12258            for offset in offsets.into_iter() {
12259                writer.write_all(&molecule::pack_number(offset as molecule::Number))?;
12260            }
12261            for inner in self.0.iter() {
12262                writer.write_all(inner.as_slice())?;
12263            }
12264        }
12265        Ok(())
12266    }
12267    fn build(&self) -> Self::Entity {
12268        let mut inner = Vec::with_capacity(self.expected_length());
12269        self.write(&mut inner)
12270            .unwrap_or_else(|_| panic!("{} build should be ok", Self::NAME));
12271        UdtCellDeps::new_unchecked(inner.into())
12272    }
12273}
12274pub struct UdtCellDepsIterator(UdtCellDeps, usize, usize);
12275impl ::core::iter::Iterator for UdtCellDepsIterator {
12276    type Item = UdtDep;
12277    fn next(&mut self) -> Option<Self::Item> {
12278        if self.1 >= self.2 {
12279            None
12280        } else {
12281            let ret = self.0.get_unchecked(self.1);
12282            self.1 += 1;
12283            Some(ret)
12284        }
12285    }
12286}
12287impl ::core::iter::ExactSizeIterator for UdtCellDepsIterator {
12288    fn len(&self) -> usize {
12289        self.2 - self.1
12290    }
12291}
12292impl ::core::iter::IntoIterator for UdtCellDeps {
12293    type Item = UdtDep;
12294    type IntoIter = UdtCellDepsIterator;
12295    fn into_iter(self) -> Self::IntoIter {
12296        let len = self.len();
12297        UdtCellDepsIterator(self, 0, len)
12298    }
12299}
12300impl<'r> UdtCellDepsReader<'r> {
12301    pub fn iter<'t>(&'t self) -> UdtCellDepsReaderIterator<'t, 'r> {
12302        UdtCellDepsReaderIterator(&self, 0, self.len())
12303    }
12304}
12305pub struct UdtCellDepsReaderIterator<'t, 'r>(&'t UdtCellDepsReader<'r>, usize, usize);
12306impl<'t: 'r, 'r> ::core::iter::Iterator for UdtCellDepsReaderIterator<'t, 'r> {
12307    type Item = UdtDepReader<'t>;
12308    fn next(&mut self) -> Option<Self::Item> {
12309        if self.1 >= self.2 {
12310            None
12311        } else {
12312            let ret = self.0.get_unchecked(self.1);
12313            self.1 += 1;
12314            Some(ret)
12315        }
12316    }
12317}
12318impl<'t: 'r, 'r> ::core::iter::ExactSizeIterator for UdtCellDepsReaderIterator<'t, 'r> {
12319    fn len(&self) -> usize {
12320        self.2 - self.1
12321    }
12322}
12323impl ::core::iter::FromIterator<UdtDep> for UdtCellDeps {
12324    fn from_iter<T: IntoIterator<Item = UdtDep>>(iter: T) -> Self {
12325        Self::new_builder().extend(iter).build()
12326    }
12327}
12328#[derive(Clone)]
12329pub struct UdtArgInfo(molecule::bytes::Bytes);
12330impl ::core::fmt::LowerHex for UdtArgInfo {
12331    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
12332        use molecule::hex_string;
12333        if f.alternate() {
12334            write!(f, "0x")?;
12335        }
12336        write!(f, "{}", hex_string(self.as_slice()))
12337    }
12338}
12339impl ::core::fmt::Debug for UdtArgInfo {
12340    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
12341        write!(f, "{}({:#x})", Self::NAME, self)
12342    }
12343}
12344impl ::core::fmt::Display for UdtArgInfo {
12345    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
12346        write!(f, "{} {{ ", Self::NAME)?;
12347        write!(f, "{}: {}", "name", self.name())?;
12348        write!(f, ", {}: {}", "script", self.script())?;
12349        write!(
12350            f,
12351            ", {}: {}",
12352            "auto_accept_amount",
12353            self.auto_accept_amount()
12354        )?;
12355        write!(f, ", {}: {}", "cell_deps", self.cell_deps())?;
12356        let extra_count = self.count_extra_fields();
12357        if extra_count != 0 {
12358            write!(f, ", .. ({} fields)", extra_count)?;
12359        }
12360        write!(f, " }}")
12361    }
12362}
12363impl ::core::default::Default for UdtArgInfo {
12364    fn default() -> Self {
12365        let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE);
12366        UdtArgInfo::new_unchecked(v)
12367    }
12368}
12369impl UdtArgInfo {
12370    const DEFAULT_VALUE: [u8; 81] = [
12371        81, 0, 0, 0, 20, 0, 0, 0, 24, 0, 0, 0, 77, 0, 0, 0, 77, 0, 0, 0, 0, 0, 0, 0, 53, 0, 0, 0,
12372        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,
12373        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0,
12374    ];
12375    pub const FIELD_COUNT: usize = 4;
12376    pub fn total_size(&self) -> usize {
12377        molecule::unpack_number(self.as_slice()) as usize
12378    }
12379    pub fn field_count(&self) -> usize {
12380        if self.total_size() == molecule::NUMBER_SIZE {
12381            0
12382        } else {
12383            (molecule::unpack_number(&self.as_slice()[molecule::NUMBER_SIZE..]) as usize / 4) - 1
12384        }
12385    }
12386    pub fn count_extra_fields(&self) -> usize {
12387        self.field_count() - Self::FIELD_COUNT
12388    }
12389    pub fn has_extra_fields(&self) -> bool {
12390        Self::FIELD_COUNT != self.field_count()
12391    }
12392    pub fn name(&self) -> Bytes {
12393        let slice = self.as_slice();
12394        let start = molecule::unpack_number(&slice[4..]) as usize;
12395        let end = molecule::unpack_number(&slice[8..]) as usize;
12396        Bytes::new_unchecked(self.0.slice(start..end))
12397    }
12398    pub fn script(&self) -> UdtScript {
12399        let slice = self.as_slice();
12400        let start = molecule::unpack_number(&slice[8..]) as usize;
12401        let end = molecule::unpack_number(&slice[12..]) as usize;
12402        UdtScript::new_unchecked(self.0.slice(start..end))
12403    }
12404    pub fn auto_accept_amount(&self) -> Uint128Opt {
12405        let slice = self.as_slice();
12406        let start = molecule::unpack_number(&slice[12..]) as usize;
12407        let end = molecule::unpack_number(&slice[16..]) as usize;
12408        Uint128Opt::new_unchecked(self.0.slice(start..end))
12409    }
12410    pub fn cell_deps(&self) -> UdtCellDeps {
12411        let slice = self.as_slice();
12412        let start = molecule::unpack_number(&slice[16..]) as usize;
12413        if self.has_extra_fields() {
12414            let end = molecule::unpack_number(&slice[20..]) as usize;
12415            UdtCellDeps::new_unchecked(self.0.slice(start..end))
12416        } else {
12417            UdtCellDeps::new_unchecked(self.0.slice(start..))
12418        }
12419    }
12420    pub fn as_reader<'r>(&'r self) -> UdtArgInfoReader<'r> {
12421        UdtArgInfoReader::new_unchecked(self.as_slice())
12422    }
12423}
12424impl molecule::prelude::Entity for UdtArgInfo {
12425    type Builder = UdtArgInfoBuilder;
12426    const NAME: &'static str = "UdtArgInfo";
12427    fn new_unchecked(data: molecule::bytes::Bytes) -> Self {
12428        UdtArgInfo(data)
12429    }
12430    fn as_bytes(&self) -> molecule::bytes::Bytes {
12431        self.0.clone()
12432    }
12433    fn as_slice(&self) -> &[u8] {
12434        &self.0[..]
12435    }
12436    fn from_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
12437        UdtArgInfoReader::from_slice(slice).map(|reader| reader.to_entity())
12438    }
12439    fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
12440        UdtArgInfoReader::from_compatible_slice(slice).map(|reader| reader.to_entity())
12441    }
12442    fn new_builder() -> Self::Builder {
12443        ::core::default::Default::default()
12444    }
12445    fn as_builder(self) -> Self::Builder {
12446        Self::new_builder()
12447            .name(self.name())
12448            .script(self.script())
12449            .auto_accept_amount(self.auto_accept_amount())
12450            .cell_deps(self.cell_deps())
12451    }
12452}
12453#[derive(Clone, Copy)]
12454pub struct UdtArgInfoReader<'r>(&'r [u8]);
12455impl<'r> ::core::fmt::LowerHex for UdtArgInfoReader<'r> {
12456    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
12457        use molecule::hex_string;
12458        if f.alternate() {
12459            write!(f, "0x")?;
12460        }
12461        write!(f, "{}", hex_string(self.as_slice()))
12462    }
12463}
12464impl<'r> ::core::fmt::Debug for UdtArgInfoReader<'r> {
12465    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
12466        write!(f, "{}({:#x})", Self::NAME, self)
12467    }
12468}
12469impl<'r> ::core::fmt::Display for UdtArgInfoReader<'r> {
12470    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
12471        write!(f, "{} {{ ", Self::NAME)?;
12472        write!(f, "{}: {}", "name", self.name())?;
12473        write!(f, ", {}: {}", "script", self.script())?;
12474        write!(
12475            f,
12476            ", {}: {}",
12477            "auto_accept_amount",
12478            self.auto_accept_amount()
12479        )?;
12480        write!(f, ", {}: {}", "cell_deps", self.cell_deps())?;
12481        let extra_count = self.count_extra_fields();
12482        if extra_count != 0 {
12483            write!(f, ", .. ({} fields)", extra_count)?;
12484        }
12485        write!(f, " }}")
12486    }
12487}
12488impl<'r> UdtArgInfoReader<'r> {
12489    pub const FIELD_COUNT: usize = 4;
12490    pub fn total_size(&self) -> usize {
12491        molecule::unpack_number(self.as_slice()) as usize
12492    }
12493    pub fn field_count(&self) -> usize {
12494        if self.total_size() == molecule::NUMBER_SIZE {
12495            0
12496        } else {
12497            (molecule::unpack_number(&self.as_slice()[molecule::NUMBER_SIZE..]) as usize / 4) - 1
12498        }
12499    }
12500    pub fn count_extra_fields(&self) -> usize {
12501        self.field_count() - Self::FIELD_COUNT
12502    }
12503    pub fn has_extra_fields(&self) -> bool {
12504        Self::FIELD_COUNT != self.field_count()
12505    }
12506    pub fn name(&self) -> BytesReader<'r> {
12507        let slice = self.as_slice();
12508        let start = molecule::unpack_number(&slice[4..]) as usize;
12509        let end = molecule::unpack_number(&slice[8..]) as usize;
12510        BytesReader::new_unchecked(&self.as_slice()[start..end])
12511    }
12512    pub fn script(&self) -> UdtScriptReader<'r> {
12513        let slice = self.as_slice();
12514        let start = molecule::unpack_number(&slice[8..]) as usize;
12515        let end = molecule::unpack_number(&slice[12..]) as usize;
12516        UdtScriptReader::new_unchecked(&self.as_slice()[start..end])
12517    }
12518    pub fn auto_accept_amount(&self) -> Uint128OptReader<'r> {
12519        let slice = self.as_slice();
12520        let start = molecule::unpack_number(&slice[12..]) as usize;
12521        let end = molecule::unpack_number(&slice[16..]) as usize;
12522        Uint128OptReader::new_unchecked(&self.as_slice()[start..end])
12523    }
12524    pub fn cell_deps(&self) -> UdtCellDepsReader<'r> {
12525        let slice = self.as_slice();
12526        let start = molecule::unpack_number(&slice[16..]) as usize;
12527        if self.has_extra_fields() {
12528            let end = molecule::unpack_number(&slice[20..]) as usize;
12529            UdtCellDepsReader::new_unchecked(&self.as_slice()[start..end])
12530        } else {
12531            UdtCellDepsReader::new_unchecked(&self.as_slice()[start..])
12532        }
12533    }
12534}
12535impl<'r> molecule::prelude::Reader<'r> for UdtArgInfoReader<'r> {
12536    type Entity = UdtArgInfo;
12537    const NAME: &'static str = "UdtArgInfoReader";
12538    fn to_entity(&self) -> Self::Entity {
12539        Self::Entity::new_unchecked(self.as_slice().to_owned().into())
12540    }
12541    fn new_unchecked(slice: &'r [u8]) -> Self {
12542        UdtArgInfoReader(slice)
12543    }
12544    fn as_slice(&self) -> &'r [u8] {
12545        self.0
12546    }
12547    fn verify(slice: &[u8], compatible: bool) -> molecule::error::VerificationResult<()> {
12548        use molecule::verification_error as ve;
12549        let slice_len = slice.len();
12550        if slice_len < molecule::NUMBER_SIZE {
12551            return ve!(Self, HeaderIsBroken, molecule::NUMBER_SIZE, slice_len);
12552        }
12553        let total_size = molecule::unpack_number(slice) as usize;
12554        if slice_len != total_size {
12555            return ve!(Self, TotalSizeNotMatch, total_size, slice_len);
12556        }
12557        if slice_len < molecule::NUMBER_SIZE * 2 {
12558            return ve!(Self, HeaderIsBroken, molecule::NUMBER_SIZE * 2, slice_len);
12559        }
12560        let offset_first = molecule::unpack_number(&slice[molecule::NUMBER_SIZE..]) as usize;
12561        if offset_first % molecule::NUMBER_SIZE != 0 || offset_first < molecule::NUMBER_SIZE * 2 {
12562            return ve!(Self, OffsetsNotMatch);
12563        }
12564        if slice_len < offset_first {
12565            return ve!(Self, HeaderIsBroken, offset_first, slice_len);
12566        }
12567        let field_count = offset_first / molecule::NUMBER_SIZE - 1;
12568        if field_count < Self::FIELD_COUNT {
12569            return ve!(Self, FieldCountNotMatch, Self::FIELD_COUNT, field_count);
12570        } else if !compatible && field_count > Self::FIELD_COUNT {
12571            return ve!(Self, FieldCountNotMatch, Self::FIELD_COUNT, field_count);
12572        };
12573        let mut offsets: Vec<usize> = slice[molecule::NUMBER_SIZE..offset_first]
12574            .chunks_exact(molecule::NUMBER_SIZE)
12575            .map(|x| molecule::unpack_number(x) as usize)
12576            .collect();
12577        offsets.push(total_size);
12578        if offsets.windows(2).any(|i| i[0] > i[1]) {
12579            return ve!(Self, OffsetsNotMatch);
12580        }
12581        BytesReader::verify(&slice[offsets[0]..offsets[1]], compatible)?;
12582        UdtScriptReader::verify(&slice[offsets[1]..offsets[2]], compatible)?;
12583        Uint128OptReader::verify(&slice[offsets[2]..offsets[3]], compatible)?;
12584        UdtCellDepsReader::verify(&slice[offsets[3]..offsets[4]], compatible)?;
12585        Ok(())
12586    }
12587}
12588#[derive(Clone, Debug, Default)]
12589pub struct UdtArgInfoBuilder {
12590    pub(crate) name: Bytes,
12591    pub(crate) script: UdtScript,
12592    pub(crate) auto_accept_amount: Uint128Opt,
12593    pub(crate) cell_deps: UdtCellDeps,
12594}
12595impl UdtArgInfoBuilder {
12596    pub const FIELD_COUNT: usize = 4;
12597    pub fn name(mut self, v: Bytes) -> Self {
12598        self.name = v;
12599        self
12600    }
12601    pub fn script(mut self, v: UdtScript) -> Self {
12602        self.script = v;
12603        self
12604    }
12605    pub fn auto_accept_amount(mut self, v: Uint128Opt) -> Self {
12606        self.auto_accept_amount = v;
12607        self
12608    }
12609    pub fn cell_deps(mut self, v: UdtCellDeps) -> Self {
12610        self.cell_deps = v;
12611        self
12612    }
12613}
12614impl molecule::prelude::Builder for UdtArgInfoBuilder {
12615    type Entity = UdtArgInfo;
12616    const NAME: &'static str = "UdtArgInfoBuilder";
12617    fn expected_length(&self) -> usize {
12618        molecule::NUMBER_SIZE * (Self::FIELD_COUNT + 1)
12619            + self.name.as_slice().len()
12620            + self.script.as_slice().len()
12621            + self.auto_accept_amount.as_slice().len()
12622            + self.cell_deps.as_slice().len()
12623    }
12624    fn write<W: molecule::io::Write>(&self, writer: &mut W) -> molecule::io::Result<()> {
12625        let mut total_size = molecule::NUMBER_SIZE * (Self::FIELD_COUNT + 1);
12626        let mut offsets = Vec::with_capacity(Self::FIELD_COUNT);
12627        offsets.push(total_size);
12628        total_size += self.name.as_slice().len();
12629        offsets.push(total_size);
12630        total_size += self.script.as_slice().len();
12631        offsets.push(total_size);
12632        total_size += self.auto_accept_amount.as_slice().len();
12633        offsets.push(total_size);
12634        total_size += self.cell_deps.as_slice().len();
12635        writer.write_all(&molecule::pack_number(total_size as molecule::Number))?;
12636        for offset in offsets.into_iter() {
12637            writer.write_all(&molecule::pack_number(offset as molecule::Number))?;
12638        }
12639        writer.write_all(self.name.as_slice())?;
12640        writer.write_all(self.script.as_slice())?;
12641        writer.write_all(self.auto_accept_amount.as_slice())?;
12642        writer.write_all(self.cell_deps.as_slice())?;
12643        Ok(())
12644    }
12645    fn build(&self) -> Self::Entity {
12646        let mut inner = Vec::with_capacity(self.expected_length());
12647        self.write(&mut inner)
12648            .unwrap_or_else(|_| panic!("{} build should be ok", Self::NAME));
12649        UdtArgInfo::new_unchecked(inner.into())
12650    }
12651}
12652#[derive(Clone)]
12653pub struct UdtCfgInfos(molecule::bytes::Bytes);
12654impl ::core::fmt::LowerHex for UdtCfgInfos {
12655    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
12656        use molecule::hex_string;
12657        if f.alternate() {
12658            write!(f, "0x")?;
12659        }
12660        write!(f, "{}", hex_string(self.as_slice()))
12661    }
12662}
12663impl ::core::fmt::Debug for UdtCfgInfos {
12664    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
12665        write!(f, "{}({:#x})", Self::NAME, self)
12666    }
12667}
12668impl ::core::fmt::Display for UdtCfgInfos {
12669    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
12670        write!(f, "{} [", Self::NAME)?;
12671        for i in 0..self.len() {
12672            if i == 0 {
12673                write!(f, "{}", self.get_unchecked(i))?;
12674            } else {
12675                write!(f, ", {}", self.get_unchecked(i))?;
12676            }
12677        }
12678        write!(f, "]")
12679    }
12680}
12681impl ::core::default::Default for UdtCfgInfos {
12682    fn default() -> Self {
12683        let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE);
12684        UdtCfgInfos::new_unchecked(v)
12685    }
12686}
12687impl UdtCfgInfos {
12688    const DEFAULT_VALUE: [u8; 4] = [4, 0, 0, 0];
12689    pub fn total_size(&self) -> usize {
12690        molecule::unpack_number(self.as_slice()) as usize
12691    }
12692    pub fn item_count(&self) -> usize {
12693        if self.total_size() == molecule::NUMBER_SIZE {
12694            0
12695        } else {
12696            (molecule::unpack_number(&self.as_slice()[molecule::NUMBER_SIZE..]) as usize / 4) - 1
12697        }
12698    }
12699    pub fn len(&self) -> usize {
12700        self.item_count()
12701    }
12702    pub fn is_empty(&self) -> bool {
12703        self.len() == 0
12704    }
12705    pub fn get(&self, idx: usize) -> Option<UdtArgInfo> {
12706        if idx >= self.len() {
12707            None
12708        } else {
12709            Some(self.get_unchecked(idx))
12710        }
12711    }
12712    pub fn get_unchecked(&self, idx: usize) -> UdtArgInfo {
12713        let slice = self.as_slice();
12714        let start_idx = molecule::NUMBER_SIZE * (1 + idx);
12715        let start = molecule::unpack_number(&slice[start_idx..]) as usize;
12716        if idx == self.len() - 1 {
12717            UdtArgInfo::new_unchecked(self.0.slice(start..))
12718        } else {
12719            let end_idx = start_idx + molecule::NUMBER_SIZE;
12720            let end = molecule::unpack_number(&slice[end_idx..]) as usize;
12721            UdtArgInfo::new_unchecked(self.0.slice(start..end))
12722        }
12723    }
12724    pub fn as_reader<'r>(&'r self) -> UdtCfgInfosReader<'r> {
12725        UdtCfgInfosReader::new_unchecked(self.as_slice())
12726    }
12727}
12728impl molecule::prelude::Entity for UdtCfgInfos {
12729    type Builder = UdtCfgInfosBuilder;
12730    const NAME: &'static str = "UdtCfgInfos";
12731    fn new_unchecked(data: molecule::bytes::Bytes) -> Self {
12732        UdtCfgInfos(data)
12733    }
12734    fn as_bytes(&self) -> molecule::bytes::Bytes {
12735        self.0.clone()
12736    }
12737    fn as_slice(&self) -> &[u8] {
12738        &self.0[..]
12739    }
12740    fn from_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
12741        UdtCfgInfosReader::from_slice(slice).map(|reader| reader.to_entity())
12742    }
12743    fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
12744        UdtCfgInfosReader::from_compatible_slice(slice).map(|reader| reader.to_entity())
12745    }
12746    fn new_builder() -> Self::Builder {
12747        ::core::default::Default::default()
12748    }
12749    fn as_builder(self) -> Self::Builder {
12750        Self::new_builder().extend(self.into_iter())
12751    }
12752}
12753#[derive(Clone, Copy)]
12754pub struct UdtCfgInfosReader<'r>(&'r [u8]);
12755impl<'r> ::core::fmt::LowerHex for UdtCfgInfosReader<'r> {
12756    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
12757        use molecule::hex_string;
12758        if f.alternate() {
12759            write!(f, "0x")?;
12760        }
12761        write!(f, "{}", hex_string(self.as_slice()))
12762    }
12763}
12764impl<'r> ::core::fmt::Debug for UdtCfgInfosReader<'r> {
12765    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
12766        write!(f, "{}({:#x})", Self::NAME, self)
12767    }
12768}
12769impl<'r> ::core::fmt::Display for UdtCfgInfosReader<'r> {
12770    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
12771        write!(f, "{} [", Self::NAME)?;
12772        for i in 0..self.len() {
12773            if i == 0 {
12774                write!(f, "{}", self.get_unchecked(i))?;
12775            } else {
12776                write!(f, ", {}", self.get_unchecked(i))?;
12777            }
12778        }
12779        write!(f, "]")
12780    }
12781}
12782impl<'r> UdtCfgInfosReader<'r> {
12783    pub fn total_size(&self) -> usize {
12784        molecule::unpack_number(self.as_slice()) as usize
12785    }
12786    pub fn item_count(&self) -> usize {
12787        if self.total_size() == molecule::NUMBER_SIZE {
12788            0
12789        } else {
12790            (molecule::unpack_number(&self.as_slice()[molecule::NUMBER_SIZE..]) as usize / 4) - 1
12791        }
12792    }
12793    pub fn len(&self) -> usize {
12794        self.item_count()
12795    }
12796    pub fn is_empty(&self) -> bool {
12797        self.len() == 0
12798    }
12799    pub fn get(&self, idx: usize) -> Option<UdtArgInfoReader<'r>> {
12800        if idx >= self.len() {
12801            None
12802        } else {
12803            Some(self.get_unchecked(idx))
12804        }
12805    }
12806    pub fn get_unchecked(&self, idx: usize) -> UdtArgInfoReader<'r> {
12807        let slice = self.as_slice();
12808        let start_idx = molecule::NUMBER_SIZE * (1 + idx);
12809        let start = molecule::unpack_number(&slice[start_idx..]) as usize;
12810        if idx == self.len() - 1 {
12811            UdtArgInfoReader::new_unchecked(&self.as_slice()[start..])
12812        } else {
12813            let end_idx = start_idx + molecule::NUMBER_SIZE;
12814            let end = molecule::unpack_number(&slice[end_idx..]) as usize;
12815            UdtArgInfoReader::new_unchecked(&self.as_slice()[start..end])
12816        }
12817    }
12818}
12819impl<'r> molecule::prelude::Reader<'r> for UdtCfgInfosReader<'r> {
12820    type Entity = UdtCfgInfos;
12821    const NAME: &'static str = "UdtCfgInfosReader";
12822    fn to_entity(&self) -> Self::Entity {
12823        Self::Entity::new_unchecked(self.as_slice().to_owned().into())
12824    }
12825    fn new_unchecked(slice: &'r [u8]) -> Self {
12826        UdtCfgInfosReader(slice)
12827    }
12828    fn as_slice(&self) -> &'r [u8] {
12829        self.0
12830    }
12831    fn verify(slice: &[u8], compatible: bool) -> molecule::error::VerificationResult<()> {
12832        use molecule::verification_error as ve;
12833        let slice_len = slice.len();
12834        if slice_len < molecule::NUMBER_SIZE {
12835            return ve!(Self, HeaderIsBroken, molecule::NUMBER_SIZE, slice_len);
12836        }
12837        let total_size = molecule::unpack_number(slice) as usize;
12838        if slice_len != total_size {
12839            return ve!(Self, TotalSizeNotMatch, total_size, slice_len);
12840        }
12841        if slice_len == molecule::NUMBER_SIZE {
12842            return Ok(());
12843        }
12844        if slice_len < molecule::NUMBER_SIZE * 2 {
12845            return ve!(
12846                Self,
12847                TotalSizeNotMatch,
12848                molecule::NUMBER_SIZE * 2,
12849                slice_len
12850            );
12851        }
12852        let offset_first = molecule::unpack_number(&slice[molecule::NUMBER_SIZE..]) as usize;
12853        if offset_first % molecule::NUMBER_SIZE != 0 || offset_first < molecule::NUMBER_SIZE * 2 {
12854            return ve!(Self, OffsetsNotMatch);
12855        }
12856        if slice_len < offset_first {
12857            return ve!(Self, HeaderIsBroken, offset_first, slice_len);
12858        }
12859        let mut offsets: Vec<usize> = slice[molecule::NUMBER_SIZE..offset_first]
12860            .chunks_exact(molecule::NUMBER_SIZE)
12861            .map(|x| molecule::unpack_number(x) as usize)
12862            .collect();
12863        offsets.push(total_size);
12864        if offsets.windows(2).any(|i| i[0] > i[1]) {
12865            return ve!(Self, OffsetsNotMatch);
12866        }
12867        for pair in offsets.windows(2) {
12868            let start = pair[0];
12869            let end = pair[1];
12870            UdtArgInfoReader::verify(&slice[start..end], compatible)?;
12871        }
12872        Ok(())
12873    }
12874}
12875#[derive(Clone, Debug, Default)]
12876pub struct UdtCfgInfosBuilder(pub(crate) Vec<UdtArgInfo>);
12877impl UdtCfgInfosBuilder {
12878    pub fn set(mut self, v: Vec<UdtArgInfo>) -> Self {
12879        self.0 = v;
12880        self
12881    }
12882    pub fn push(mut self, v: UdtArgInfo) -> Self {
12883        self.0.push(v);
12884        self
12885    }
12886    pub fn extend<T: ::core::iter::IntoIterator<Item = UdtArgInfo>>(mut self, iter: T) -> Self {
12887        for elem in iter {
12888            self.0.push(elem);
12889        }
12890        self
12891    }
12892    pub fn replace(&mut self, index: usize, v: UdtArgInfo) -> Option<UdtArgInfo> {
12893        self.0
12894            .get_mut(index)
12895            .map(|item| ::core::mem::replace(item, v))
12896    }
12897}
12898impl molecule::prelude::Builder for UdtCfgInfosBuilder {
12899    type Entity = UdtCfgInfos;
12900    const NAME: &'static str = "UdtCfgInfosBuilder";
12901    fn expected_length(&self) -> usize {
12902        molecule::NUMBER_SIZE * (self.0.len() + 1)
12903            + self
12904                .0
12905                .iter()
12906                .map(|inner| inner.as_slice().len())
12907                .sum::<usize>()
12908    }
12909    fn write<W: molecule::io::Write>(&self, writer: &mut W) -> molecule::io::Result<()> {
12910        let item_count = self.0.len();
12911        if item_count == 0 {
12912            writer.write_all(&molecule::pack_number(
12913                molecule::NUMBER_SIZE as molecule::Number,
12914            ))?;
12915        } else {
12916            let (total_size, offsets) = self.0.iter().fold(
12917                (
12918                    molecule::NUMBER_SIZE * (item_count + 1),
12919                    Vec::with_capacity(item_count),
12920                ),
12921                |(start, mut offsets), inner| {
12922                    offsets.push(start);
12923                    (start + inner.as_slice().len(), offsets)
12924                },
12925            );
12926            writer.write_all(&molecule::pack_number(total_size as molecule::Number))?;
12927            for offset in offsets.into_iter() {
12928                writer.write_all(&molecule::pack_number(offset as molecule::Number))?;
12929            }
12930            for inner in self.0.iter() {
12931                writer.write_all(inner.as_slice())?;
12932            }
12933        }
12934        Ok(())
12935    }
12936    fn build(&self) -> Self::Entity {
12937        let mut inner = Vec::with_capacity(self.expected_length());
12938        self.write(&mut inner)
12939            .unwrap_or_else(|_| panic!("{} build should be ok", Self::NAME));
12940        UdtCfgInfos::new_unchecked(inner.into())
12941    }
12942}
12943pub struct UdtCfgInfosIterator(UdtCfgInfos, usize, usize);
12944impl ::core::iter::Iterator for UdtCfgInfosIterator {
12945    type Item = UdtArgInfo;
12946    fn next(&mut self) -> Option<Self::Item> {
12947        if self.1 >= self.2 {
12948            None
12949        } else {
12950            let ret = self.0.get_unchecked(self.1);
12951            self.1 += 1;
12952            Some(ret)
12953        }
12954    }
12955}
12956impl ::core::iter::ExactSizeIterator for UdtCfgInfosIterator {
12957    fn len(&self) -> usize {
12958        self.2 - self.1
12959    }
12960}
12961impl ::core::iter::IntoIterator for UdtCfgInfos {
12962    type Item = UdtArgInfo;
12963    type IntoIter = UdtCfgInfosIterator;
12964    fn into_iter(self) -> Self::IntoIter {
12965        let len = self.len();
12966        UdtCfgInfosIterator(self, 0, len)
12967    }
12968}
12969impl<'r> UdtCfgInfosReader<'r> {
12970    pub fn iter<'t>(&'t self) -> UdtCfgInfosReaderIterator<'t, 'r> {
12971        UdtCfgInfosReaderIterator(&self, 0, self.len())
12972    }
12973}
12974pub struct UdtCfgInfosReaderIterator<'t, 'r>(&'t UdtCfgInfosReader<'r>, usize, usize);
12975impl<'t: 'r, 'r> ::core::iter::Iterator for UdtCfgInfosReaderIterator<'t, 'r> {
12976    type Item = UdtArgInfoReader<'t>;
12977    fn next(&mut self) -> Option<Self::Item> {
12978        if self.1 >= self.2 {
12979            None
12980        } else {
12981            let ret = self.0.get_unchecked(self.1);
12982            self.1 += 1;
12983            Some(ret)
12984        }
12985    }
12986}
12987impl<'t: 'r, 'r> ::core::iter::ExactSizeIterator for UdtCfgInfosReaderIterator<'t, 'r> {
12988    fn len(&self) -> usize {
12989        self.2 - self.1
12990    }
12991}
12992impl ::core::iter::FromIterator<UdtArgInfo> for UdtCfgInfos {
12993    fn from_iter<T: IntoIterator<Item = UdtArgInfo>>(iter: T) -> Self {
12994        Self::new_builder().extend(iter).build()
12995    }
12996}
12997#[derive(Clone)]
12998pub struct FiberMessage(molecule::bytes::Bytes);
12999impl ::core::fmt::LowerHex for FiberMessage {
13000    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
13001        use molecule::hex_string;
13002        if f.alternate() {
13003            write!(f, "0x")?;
13004        }
13005        write!(f, "{}", hex_string(self.as_slice()))
13006    }
13007}
13008impl ::core::fmt::Debug for FiberMessage {
13009    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
13010        write!(f, "{}({:#x})", Self::NAME, self)
13011    }
13012}
13013impl ::core::fmt::Display for FiberMessage {
13014    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
13015        write!(f, "{}(", Self::NAME)?;
13016        self.to_enum().display_inner(f)?;
13017        write!(f, ")")
13018    }
13019}
13020impl ::core::default::Default for FiberMessage {
13021    fn default() -> Self {
13022        let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE);
13023        FiberMessage::new_unchecked(v)
13024    }
13025}
13026impl FiberMessage {
13027    const DEFAULT_VALUE: [u8; 52] = [
13028        0, 0, 0, 0, 48, 0, 0, 0, 12, 0, 0, 0, 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
13029        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
13030    ];
13031    pub const ITEMS_COUNT: usize = 19;
13032    pub fn item_id(&self) -> molecule::Number {
13033        molecule::unpack_number(self.as_slice())
13034    }
13035    pub fn to_enum(&self) -> FiberMessageUnion {
13036        let inner = self.0.slice(molecule::NUMBER_SIZE..);
13037        match self.item_id() {
13038            0 => Init::new_unchecked(inner).into(),
13039            1 => OpenChannel::new_unchecked(inner).into(),
13040            2 => AcceptChannel::new_unchecked(inner).into(),
13041            3 => TxSignatures::new_unchecked(inner).into(),
13042            4 => TxUpdate::new_unchecked(inner).into(),
13043            5 => TxComplete::new_unchecked(inner).into(),
13044            6 => TxAbort::new_unchecked(inner).into(),
13045            7 => TxInitRBF::new_unchecked(inner).into(),
13046            8 => TxAckRBF::new_unchecked(inner).into(),
13047            9 => CommitmentSigned::new_unchecked(inner).into(),
13048            10 => ChannelReady::new_unchecked(inner).into(),
13049            11 => UpdateTlcInfo::new_unchecked(inner).into(),
13050            12 => AddTlc::new_unchecked(inner).into(),
13051            13 => RemoveTlc::new_unchecked(inner).into(),
13052            14 => RevokeAndAck::new_unchecked(inner).into(),
13053            15 => Shutdown::new_unchecked(inner).into(),
13054            16 => ClosingSigned::new_unchecked(inner).into(),
13055            17 => ReestablishChannel::new_unchecked(inner).into(),
13056            18 => AnnouncementSignatures::new_unchecked(inner).into(),
13057            _ => panic!("{}: invalid data", Self::NAME),
13058        }
13059    }
13060    pub fn as_reader<'r>(&'r self) -> FiberMessageReader<'r> {
13061        FiberMessageReader::new_unchecked(self.as_slice())
13062    }
13063}
13064impl molecule::prelude::Entity for FiberMessage {
13065    type Builder = FiberMessageBuilder;
13066    const NAME: &'static str = "FiberMessage";
13067    fn new_unchecked(data: molecule::bytes::Bytes) -> Self {
13068        FiberMessage(data)
13069    }
13070    fn as_bytes(&self) -> molecule::bytes::Bytes {
13071        self.0.clone()
13072    }
13073    fn as_slice(&self) -> &[u8] {
13074        &self.0[..]
13075    }
13076    fn from_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
13077        FiberMessageReader::from_slice(slice).map(|reader| reader.to_entity())
13078    }
13079    fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
13080        FiberMessageReader::from_compatible_slice(slice).map(|reader| reader.to_entity())
13081    }
13082    fn new_builder() -> Self::Builder {
13083        ::core::default::Default::default()
13084    }
13085    fn as_builder(self) -> Self::Builder {
13086        Self::new_builder().set(self.to_enum())
13087    }
13088}
13089#[derive(Clone, Copy)]
13090pub struct FiberMessageReader<'r>(&'r [u8]);
13091impl<'r> ::core::fmt::LowerHex for FiberMessageReader<'r> {
13092    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
13093        use molecule::hex_string;
13094        if f.alternate() {
13095            write!(f, "0x")?;
13096        }
13097        write!(f, "{}", hex_string(self.as_slice()))
13098    }
13099}
13100impl<'r> ::core::fmt::Debug for FiberMessageReader<'r> {
13101    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
13102        write!(f, "{}({:#x})", Self::NAME, self)
13103    }
13104}
13105impl<'r> ::core::fmt::Display for FiberMessageReader<'r> {
13106    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
13107        write!(f, "{}(", Self::NAME)?;
13108        self.to_enum().display_inner(f)?;
13109        write!(f, ")")
13110    }
13111}
13112impl<'r> FiberMessageReader<'r> {
13113    pub const ITEMS_COUNT: usize = 19;
13114    pub fn item_id(&self) -> molecule::Number {
13115        molecule::unpack_number(self.as_slice())
13116    }
13117    pub fn to_enum(&self) -> FiberMessageUnionReader<'r> {
13118        let inner = &self.as_slice()[molecule::NUMBER_SIZE..];
13119        match self.item_id() {
13120            0 => InitReader::new_unchecked(inner).into(),
13121            1 => OpenChannelReader::new_unchecked(inner).into(),
13122            2 => AcceptChannelReader::new_unchecked(inner).into(),
13123            3 => TxSignaturesReader::new_unchecked(inner).into(),
13124            4 => TxUpdateReader::new_unchecked(inner).into(),
13125            5 => TxCompleteReader::new_unchecked(inner).into(),
13126            6 => TxAbortReader::new_unchecked(inner).into(),
13127            7 => TxInitRBFReader::new_unchecked(inner).into(),
13128            8 => TxAckRBFReader::new_unchecked(inner).into(),
13129            9 => CommitmentSignedReader::new_unchecked(inner).into(),
13130            10 => ChannelReadyReader::new_unchecked(inner).into(),
13131            11 => UpdateTlcInfoReader::new_unchecked(inner).into(),
13132            12 => AddTlcReader::new_unchecked(inner).into(),
13133            13 => RemoveTlcReader::new_unchecked(inner).into(),
13134            14 => RevokeAndAckReader::new_unchecked(inner).into(),
13135            15 => ShutdownReader::new_unchecked(inner).into(),
13136            16 => ClosingSignedReader::new_unchecked(inner).into(),
13137            17 => ReestablishChannelReader::new_unchecked(inner).into(),
13138            18 => AnnouncementSignaturesReader::new_unchecked(inner).into(),
13139            _ => panic!("{}: invalid data", Self::NAME),
13140        }
13141    }
13142}
13143impl<'r> molecule::prelude::Reader<'r> for FiberMessageReader<'r> {
13144    type Entity = FiberMessage;
13145    const NAME: &'static str = "FiberMessageReader";
13146    fn to_entity(&self) -> Self::Entity {
13147        Self::Entity::new_unchecked(self.as_slice().to_owned().into())
13148    }
13149    fn new_unchecked(slice: &'r [u8]) -> Self {
13150        FiberMessageReader(slice)
13151    }
13152    fn as_slice(&self) -> &'r [u8] {
13153        self.0
13154    }
13155    fn verify(slice: &[u8], compatible: bool) -> molecule::error::VerificationResult<()> {
13156        use molecule::verification_error as ve;
13157        let slice_len = slice.len();
13158        if slice_len < molecule::NUMBER_SIZE {
13159            return ve!(Self, HeaderIsBroken, molecule::NUMBER_SIZE, slice_len);
13160        }
13161        let item_id = molecule::unpack_number(slice);
13162        let inner_slice = &slice[molecule::NUMBER_SIZE..];
13163        match item_id {
13164            0 => InitReader::verify(inner_slice, compatible),
13165            1 => OpenChannelReader::verify(inner_slice, compatible),
13166            2 => AcceptChannelReader::verify(inner_slice, compatible),
13167            3 => TxSignaturesReader::verify(inner_slice, compatible),
13168            4 => TxUpdateReader::verify(inner_slice, compatible),
13169            5 => TxCompleteReader::verify(inner_slice, compatible),
13170            6 => TxAbortReader::verify(inner_slice, compatible),
13171            7 => TxInitRBFReader::verify(inner_slice, compatible),
13172            8 => TxAckRBFReader::verify(inner_slice, compatible),
13173            9 => CommitmentSignedReader::verify(inner_slice, compatible),
13174            10 => ChannelReadyReader::verify(inner_slice, compatible),
13175            11 => UpdateTlcInfoReader::verify(inner_slice, compatible),
13176            12 => AddTlcReader::verify(inner_slice, compatible),
13177            13 => RemoveTlcReader::verify(inner_slice, compatible),
13178            14 => RevokeAndAckReader::verify(inner_slice, compatible),
13179            15 => ShutdownReader::verify(inner_slice, compatible),
13180            16 => ClosingSignedReader::verify(inner_slice, compatible),
13181            17 => ReestablishChannelReader::verify(inner_slice, compatible),
13182            18 => AnnouncementSignaturesReader::verify(inner_slice, compatible),
13183            _ => ve!(Self, UnknownItem, Self::ITEMS_COUNT, item_id),
13184        }?;
13185        Ok(())
13186    }
13187}
13188#[derive(Clone, Debug, Default)]
13189pub struct FiberMessageBuilder(pub(crate) FiberMessageUnion);
13190impl FiberMessageBuilder {
13191    pub const ITEMS_COUNT: usize = 19;
13192    pub fn set<I>(mut self, v: I) -> Self
13193    where
13194        I: ::core::convert::Into<FiberMessageUnion>,
13195    {
13196        self.0 = v.into();
13197        self
13198    }
13199}
13200impl molecule::prelude::Builder for FiberMessageBuilder {
13201    type Entity = FiberMessage;
13202    const NAME: &'static str = "FiberMessageBuilder";
13203    fn expected_length(&self) -> usize {
13204        molecule::NUMBER_SIZE + self.0.as_slice().len()
13205    }
13206    fn write<W: molecule::io::Write>(&self, writer: &mut W) -> molecule::io::Result<()> {
13207        writer.write_all(&molecule::pack_number(self.0.item_id()))?;
13208        writer.write_all(self.0.as_slice())
13209    }
13210    fn build(&self) -> Self::Entity {
13211        let mut inner = Vec::with_capacity(self.expected_length());
13212        self.write(&mut inner)
13213            .unwrap_or_else(|_| panic!("{} build should be ok", Self::NAME));
13214        FiberMessage::new_unchecked(inner.into())
13215    }
13216}
13217#[derive(Debug, Clone)]
13218pub enum FiberMessageUnion {
13219    Init(Init),
13220    OpenChannel(OpenChannel),
13221    AcceptChannel(AcceptChannel),
13222    TxSignatures(TxSignatures),
13223    TxUpdate(TxUpdate),
13224    TxComplete(TxComplete),
13225    TxAbort(TxAbort),
13226    TxInitRBF(TxInitRBF),
13227    TxAckRBF(TxAckRBF),
13228    CommitmentSigned(CommitmentSigned),
13229    ChannelReady(ChannelReady),
13230    UpdateTlcInfo(UpdateTlcInfo),
13231    AddTlc(AddTlc),
13232    RemoveTlc(RemoveTlc),
13233    RevokeAndAck(RevokeAndAck),
13234    Shutdown(Shutdown),
13235    ClosingSigned(ClosingSigned),
13236    ReestablishChannel(ReestablishChannel),
13237    AnnouncementSignatures(AnnouncementSignatures),
13238}
13239#[derive(Debug, Clone, Copy)]
13240pub enum FiberMessageUnionReader<'r> {
13241    Init(InitReader<'r>),
13242    OpenChannel(OpenChannelReader<'r>),
13243    AcceptChannel(AcceptChannelReader<'r>),
13244    TxSignatures(TxSignaturesReader<'r>),
13245    TxUpdate(TxUpdateReader<'r>),
13246    TxComplete(TxCompleteReader<'r>),
13247    TxAbort(TxAbortReader<'r>),
13248    TxInitRBF(TxInitRBFReader<'r>),
13249    TxAckRBF(TxAckRBFReader<'r>),
13250    CommitmentSigned(CommitmentSignedReader<'r>),
13251    ChannelReady(ChannelReadyReader<'r>),
13252    UpdateTlcInfo(UpdateTlcInfoReader<'r>),
13253    AddTlc(AddTlcReader<'r>),
13254    RemoveTlc(RemoveTlcReader<'r>),
13255    RevokeAndAck(RevokeAndAckReader<'r>),
13256    Shutdown(ShutdownReader<'r>),
13257    ClosingSigned(ClosingSignedReader<'r>),
13258    ReestablishChannel(ReestablishChannelReader<'r>),
13259    AnnouncementSignatures(AnnouncementSignaturesReader<'r>),
13260}
13261impl ::core::default::Default for FiberMessageUnion {
13262    fn default() -> Self {
13263        FiberMessageUnion::Init(::core::default::Default::default())
13264    }
13265}
13266impl ::core::fmt::Display for FiberMessageUnion {
13267    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
13268        match self {
13269            FiberMessageUnion::Init(ref item) => {
13270                write!(f, "{}::{}({})", Self::NAME, Init::NAME, item)
13271            }
13272            FiberMessageUnion::OpenChannel(ref item) => {
13273                write!(f, "{}::{}({})", Self::NAME, OpenChannel::NAME, item)
13274            }
13275            FiberMessageUnion::AcceptChannel(ref item) => {
13276                write!(f, "{}::{}({})", Self::NAME, AcceptChannel::NAME, item)
13277            }
13278            FiberMessageUnion::TxSignatures(ref item) => {
13279                write!(f, "{}::{}({})", Self::NAME, TxSignatures::NAME, item)
13280            }
13281            FiberMessageUnion::TxUpdate(ref item) => {
13282                write!(f, "{}::{}({})", Self::NAME, TxUpdate::NAME, item)
13283            }
13284            FiberMessageUnion::TxComplete(ref item) => {
13285                write!(f, "{}::{}({})", Self::NAME, TxComplete::NAME, item)
13286            }
13287            FiberMessageUnion::TxAbort(ref item) => {
13288                write!(f, "{}::{}({})", Self::NAME, TxAbort::NAME, item)
13289            }
13290            FiberMessageUnion::TxInitRBF(ref item) => {
13291                write!(f, "{}::{}({})", Self::NAME, TxInitRBF::NAME, item)
13292            }
13293            FiberMessageUnion::TxAckRBF(ref item) => {
13294                write!(f, "{}::{}({})", Self::NAME, TxAckRBF::NAME, item)
13295            }
13296            FiberMessageUnion::CommitmentSigned(ref item) => {
13297                write!(f, "{}::{}({})", Self::NAME, CommitmentSigned::NAME, item)
13298            }
13299            FiberMessageUnion::ChannelReady(ref item) => {
13300                write!(f, "{}::{}({})", Self::NAME, ChannelReady::NAME, item)
13301            }
13302            FiberMessageUnion::UpdateTlcInfo(ref item) => {
13303                write!(f, "{}::{}({})", Self::NAME, UpdateTlcInfo::NAME, item)
13304            }
13305            FiberMessageUnion::AddTlc(ref item) => {
13306                write!(f, "{}::{}({})", Self::NAME, AddTlc::NAME, item)
13307            }
13308            FiberMessageUnion::RemoveTlc(ref item) => {
13309                write!(f, "{}::{}({})", Self::NAME, RemoveTlc::NAME, item)
13310            }
13311            FiberMessageUnion::RevokeAndAck(ref item) => {
13312                write!(f, "{}::{}({})", Self::NAME, RevokeAndAck::NAME, item)
13313            }
13314            FiberMessageUnion::Shutdown(ref item) => {
13315                write!(f, "{}::{}({})", Self::NAME, Shutdown::NAME, item)
13316            }
13317            FiberMessageUnion::ClosingSigned(ref item) => {
13318                write!(f, "{}::{}({})", Self::NAME, ClosingSigned::NAME, item)
13319            }
13320            FiberMessageUnion::ReestablishChannel(ref item) => {
13321                write!(f, "{}::{}({})", Self::NAME, ReestablishChannel::NAME, item)
13322            }
13323            FiberMessageUnion::AnnouncementSignatures(ref item) => {
13324                write!(
13325                    f,
13326                    "{}::{}({})",
13327                    Self::NAME,
13328                    AnnouncementSignatures::NAME,
13329                    item
13330                )
13331            }
13332        }
13333    }
13334}
13335impl<'r> ::core::fmt::Display for FiberMessageUnionReader<'r> {
13336    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
13337        match self {
13338            FiberMessageUnionReader::Init(ref item) => {
13339                write!(f, "{}::{}({})", Self::NAME, Init::NAME, item)
13340            }
13341            FiberMessageUnionReader::OpenChannel(ref item) => {
13342                write!(f, "{}::{}({})", Self::NAME, OpenChannel::NAME, item)
13343            }
13344            FiberMessageUnionReader::AcceptChannel(ref item) => {
13345                write!(f, "{}::{}({})", Self::NAME, AcceptChannel::NAME, item)
13346            }
13347            FiberMessageUnionReader::TxSignatures(ref item) => {
13348                write!(f, "{}::{}({})", Self::NAME, TxSignatures::NAME, item)
13349            }
13350            FiberMessageUnionReader::TxUpdate(ref item) => {
13351                write!(f, "{}::{}({})", Self::NAME, TxUpdate::NAME, item)
13352            }
13353            FiberMessageUnionReader::TxComplete(ref item) => {
13354                write!(f, "{}::{}({})", Self::NAME, TxComplete::NAME, item)
13355            }
13356            FiberMessageUnionReader::TxAbort(ref item) => {
13357                write!(f, "{}::{}({})", Self::NAME, TxAbort::NAME, item)
13358            }
13359            FiberMessageUnionReader::TxInitRBF(ref item) => {
13360                write!(f, "{}::{}({})", Self::NAME, TxInitRBF::NAME, item)
13361            }
13362            FiberMessageUnionReader::TxAckRBF(ref item) => {
13363                write!(f, "{}::{}({})", Self::NAME, TxAckRBF::NAME, item)
13364            }
13365            FiberMessageUnionReader::CommitmentSigned(ref item) => {
13366                write!(f, "{}::{}({})", Self::NAME, CommitmentSigned::NAME, item)
13367            }
13368            FiberMessageUnionReader::ChannelReady(ref item) => {
13369                write!(f, "{}::{}({})", Self::NAME, ChannelReady::NAME, item)
13370            }
13371            FiberMessageUnionReader::UpdateTlcInfo(ref item) => {
13372                write!(f, "{}::{}({})", Self::NAME, UpdateTlcInfo::NAME, item)
13373            }
13374            FiberMessageUnionReader::AddTlc(ref item) => {
13375                write!(f, "{}::{}({})", Self::NAME, AddTlc::NAME, item)
13376            }
13377            FiberMessageUnionReader::RemoveTlc(ref item) => {
13378                write!(f, "{}::{}({})", Self::NAME, RemoveTlc::NAME, item)
13379            }
13380            FiberMessageUnionReader::RevokeAndAck(ref item) => {
13381                write!(f, "{}::{}({})", Self::NAME, RevokeAndAck::NAME, item)
13382            }
13383            FiberMessageUnionReader::Shutdown(ref item) => {
13384                write!(f, "{}::{}({})", Self::NAME, Shutdown::NAME, item)
13385            }
13386            FiberMessageUnionReader::ClosingSigned(ref item) => {
13387                write!(f, "{}::{}({})", Self::NAME, ClosingSigned::NAME, item)
13388            }
13389            FiberMessageUnionReader::ReestablishChannel(ref item) => {
13390                write!(f, "{}::{}({})", Self::NAME, ReestablishChannel::NAME, item)
13391            }
13392            FiberMessageUnionReader::AnnouncementSignatures(ref item) => {
13393                write!(
13394                    f,
13395                    "{}::{}({})",
13396                    Self::NAME,
13397                    AnnouncementSignatures::NAME,
13398                    item
13399                )
13400            }
13401        }
13402    }
13403}
13404impl FiberMessageUnion {
13405    pub(crate) fn display_inner(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
13406        match self {
13407            FiberMessageUnion::Init(ref item) => write!(f, "{}", item),
13408            FiberMessageUnion::OpenChannel(ref item) => write!(f, "{}", item),
13409            FiberMessageUnion::AcceptChannel(ref item) => write!(f, "{}", item),
13410            FiberMessageUnion::TxSignatures(ref item) => write!(f, "{}", item),
13411            FiberMessageUnion::TxUpdate(ref item) => write!(f, "{}", item),
13412            FiberMessageUnion::TxComplete(ref item) => write!(f, "{}", item),
13413            FiberMessageUnion::TxAbort(ref item) => write!(f, "{}", item),
13414            FiberMessageUnion::TxInitRBF(ref item) => write!(f, "{}", item),
13415            FiberMessageUnion::TxAckRBF(ref item) => write!(f, "{}", item),
13416            FiberMessageUnion::CommitmentSigned(ref item) => write!(f, "{}", item),
13417            FiberMessageUnion::ChannelReady(ref item) => write!(f, "{}", item),
13418            FiberMessageUnion::UpdateTlcInfo(ref item) => write!(f, "{}", item),
13419            FiberMessageUnion::AddTlc(ref item) => write!(f, "{}", item),
13420            FiberMessageUnion::RemoveTlc(ref item) => write!(f, "{}", item),
13421            FiberMessageUnion::RevokeAndAck(ref item) => write!(f, "{}", item),
13422            FiberMessageUnion::Shutdown(ref item) => write!(f, "{}", item),
13423            FiberMessageUnion::ClosingSigned(ref item) => write!(f, "{}", item),
13424            FiberMessageUnion::ReestablishChannel(ref item) => write!(f, "{}", item),
13425            FiberMessageUnion::AnnouncementSignatures(ref item) => write!(f, "{}", item),
13426        }
13427    }
13428}
13429impl<'r> FiberMessageUnionReader<'r> {
13430    pub(crate) fn display_inner(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
13431        match self {
13432            FiberMessageUnionReader::Init(ref item) => write!(f, "{}", item),
13433            FiberMessageUnionReader::OpenChannel(ref item) => write!(f, "{}", item),
13434            FiberMessageUnionReader::AcceptChannel(ref item) => write!(f, "{}", item),
13435            FiberMessageUnionReader::TxSignatures(ref item) => write!(f, "{}", item),
13436            FiberMessageUnionReader::TxUpdate(ref item) => write!(f, "{}", item),
13437            FiberMessageUnionReader::TxComplete(ref item) => write!(f, "{}", item),
13438            FiberMessageUnionReader::TxAbort(ref item) => write!(f, "{}", item),
13439            FiberMessageUnionReader::TxInitRBF(ref item) => write!(f, "{}", item),
13440            FiberMessageUnionReader::TxAckRBF(ref item) => write!(f, "{}", item),
13441            FiberMessageUnionReader::CommitmentSigned(ref item) => write!(f, "{}", item),
13442            FiberMessageUnionReader::ChannelReady(ref item) => write!(f, "{}", item),
13443            FiberMessageUnionReader::UpdateTlcInfo(ref item) => write!(f, "{}", item),
13444            FiberMessageUnionReader::AddTlc(ref item) => write!(f, "{}", item),
13445            FiberMessageUnionReader::RemoveTlc(ref item) => write!(f, "{}", item),
13446            FiberMessageUnionReader::RevokeAndAck(ref item) => write!(f, "{}", item),
13447            FiberMessageUnionReader::Shutdown(ref item) => write!(f, "{}", item),
13448            FiberMessageUnionReader::ClosingSigned(ref item) => write!(f, "{}", item),
13449            FiberMessageUnionReader::ReestablishChannel(ref item) => write!(f, "{}", item),
13450            FiberMessageUnionReader::AnnouncementSignatures(ref item) => write!(f, "{}", item),
13451        }
13452    }
13453}
13454impl ::core::convert::From<Init> for FiberMessageUnion {
13455    fn from(item: Init) -> Self {
13456        FiberMessageUnion::Init(item)
13457    }
13458}
13459impl ::core::convert::From<OpenChannel> for FiberMessageUnion {
13460    fn from(item: OpenChannel) -> Self {
13461        FiberMessageUnion::OpenChannel(item)
13462    }
13463}
13464impl ::core::convert::From<AcceptChannel> for FiberMessageUnion {
13465    fn from(item: AcceptChannel) -> Self {
13466        FiberMessageUnion::AcceptChannel(item)
13467    }
13468}
13469impl ::core::convert::From<TxSignatures> for FiberMessageUnion {
13470    fn from(item: TxSignatures) -> Self {
13471        FiberMessageUnion::TxSignatures(item)
13472    }
13473}
13474impl ::core::convert::From<TxUpdate> for FiberMessageUnion {
13475    fn from(item: TxUpdate) -> Self {
13476        FiberMessageUnion::TxUpdate(item)
13477    }
13478}
13479impl ::core::convert::From<TxComplete> for FiberMessageUnion {
13480    fn from(item: TxComplete) -> Self {
13481        FiberMessageUnion::TxComplete(item)
13482    }
13483}
13484impl ::core::convert::From<TxAbort> for FiberMessageUnion {
13485    fn from(item: TxAbort) -> Self {
13486        FiberMessageUnion::TxAbort(item)
13487    }
13488}
13489impl ::core::convert::From<TxInitRBF> for FiberMessageUnion {
13490    fn from(item: TxInitRBF) -> Self {
13491        FiberMessageUnion::TxInitRBF(item)
13492    }
13493}
13494impl ::core::convert::From<TxAckRBF> for FiberMessageUnion {
13495    fn from(item: TxAckRBF) -> Self {
13496        FiberMessageUnion::TxAckRBF(item)
13497    }
13498}
13499impl ::core::convert::From<CommitmentSigned> for FiberMessageUnion {
13500    fn from(item: CommitmentSigned) -> Self {
13501        FiberMessageUnion::CommitmentSigned(item)
13502    }
13503}
13504impl ::core::convert::From<ChannelReady> for FiberMessageUnion {
13505    fn from(item: ChannelReady) -> Self {
13506        FiberMessageUnion::ChannelReady(item)
13507    }
13508}
13509impl ::core::convert::From<UpdateTlcInfo> for FiberMessageUnion {
13510    fn from(item: UpdateTlcInfo) -> Self {
13511        FiberMessageUnion::UpdateTlcInfo(item)
13512    }
13513}
13514impl ::core::convert::From<AddTlc> for FiberMessageUnion {
13515    fn from(item: AddTlc) -> Self {
13516        FiberMessageUnion::AddTlc(item)
13517    }
13518}
13519impl ::core::convert::From<RemoveTlc> for FiberMessageUnion {
13520    fn from(item: RemoveTlc) -> Self {
13521        FiberMessageUnion::RemoveTlc(item)
13522    }
13523}
13524impl ::core::convert::From<RevokeAndAck> for FiberMessageUnion {
13525    fn from(item: RevokeAndAck) -> Self {
13526        FiberMessageUnion::RevokeAndAck(item)
13527    }
13528}
13529impl ::core::convert::From<Shutdown> for FiberMessageUnion {
13530    fn from(item: Shutdown) -> Self {
13531        FiberMessageUnion::Shutdown(item)
13532    }
13533}
13534impl ::core::convert::From<ClosingSigned> for FiberMessageUnion {
13535    fn from(item: ClosingSigned) -> Self {
13536        FiberMessageUnion::ClosingSigned(item)
13537    }
13538}
13539impl ::core::convert::From<ReestablishChannel> for FiberMessageUnion {
13540    fn from(item: ReestablishChannel) -> Self {
13541        FiberMessageUnion::ReestablishChannel(item)
13542    }
13543}
13544impl ::core::convert::From<AnnouncementSignatures> for FiberMessageUnion {
13545    fn from(item: AnnouncementSignatures) -> Self {
13546        FiberMessageUnion::AnnouncementSignatures(item)
13547    }
13548}
13549impl<'r> ::core::convert::From<InitReader<'r>> for FiberMessageUnionReader<'r> {
13550    fn from(item: InitReader<'r>) -> Self {
13551        FiberMessageUnionReader::Init(item)
13552    }
13553}
13554impl<'r> ::core::convert::From<OpenChannelReader<'r>> for FiberMessageUnionReader<'r> {
13555    fn from(item: OpenChannelReader<'r>) -> Self {
13556        FiberMessageUnionReader::OpenChannel(item)
13557    }
13558}
13559impl<'r> ::core::convert::From<AcceptChannelReader<'r>> for FiberMessageUnionReader<'r> {
13560    fn from(item: AcceptChannelReader<'r>) -> Self {
13561        FiberMessageUnionReader::AcceptChannel(item)
13562    }
13563}
13564impl<'r> ::core::convert::From<TxSignaturesReader<'r>> for FiberMessageUnionReader<'r> {
13565    fn from(item: TxSignaturesReader<'r>) -> Self {
13566        FiberMessageUnionReader::TxSignatures(item)
13567    }
13568}
13569impl<'r> ::core::convert::From<TxUpdateReader<'r>> for FiberMessageUnionReader<'r> {
13570    fn from(item: TxUpdateReader<'r>) -> Self {
13571        FiberMessageUnionReader::TxUpdate(item)
13572    }
13573}
13574impl<'r> ::core::convert::From<TxCompleteReader<'r>> for FiberMessageUnionReader<'r> {
13575    fn from(item: TxCompleteReader<'r>) -> Self {
13576        FiberMessageUnionReader::TxComplete(item)
13577    }
13578}
13579impl<'r> ::core::convert::From<TxAbortReader<'r>> for FiberMessageUnionReader<'r> {
13580    fn from(item: TxAbortReader<'r>) -> Self {
13581        FiberMessageUnionReader::TxAbort(item)
13582    }
13583}
13584impl<'r> ::core::convert::From<TxInitRBFReader<'r>> for FiberMessageUnionReader<'r> {
13585    fn from(item: TxInitRBFReader<'r>) -> Self {
13586        FiberMessageUnionReader::TxInitRBF(item)
13587    }
13588}
13589impl<'r> ::core::convert::From<TxAckRBFReader<'r>> for FiberMessageUnionReader<'r> {
13590    fn from(item: TxAckRBFReader<'r>) -> Self {
13591        FiberMessageUnionReader::TxAckRBF(item)
13592    }
13593}
13594impl<'r> ::core::convert::From<CommitmentSignedReader<'r>> for FiberMessageUnionReader<'r> {
13595    fn from(item: CommitmentSignedReader<'r>) -> Self {
13596        FiberMessageUnionReader::CommitmentSigned(item)
13597    }
13598}
13599impl<'r> ::core::convert::From<ChannelReadyReader<'r>> for FiberMessageUnionReader<'r> {
13600    fn from(item: ChannelReadyReader<'r>) -> Self {
13601        FiberMessageUnionReader::ChannelReady(item)
13602    }
13603}
13604impl<'r> ::core::convert::From<UpdateTlcInfoReader<'r>> for FiberMessageUnionReader<'r> {
13605    fn from(item: UpdateTlcInfoReader<'r>) -> Self {
13606        FiberMessageUnionReader::UpdateTlcInfo(item)
13607    }
13608}
13609impl<'r> ::core::convert::From<AddTlcReader<'r>> for FiberMessageUnionReader<'r> {
13610    fn from(item: AddTlcReader<'r>) -> Self {
13611        FiberMessageUnionReader::AddTlc(item)
13612    }
13613}
13614impl<'r> ::core::convert::From<RemoveTlcReader<'r>> for FiberMessageUnionReader<'r> {
13615    fn from(item: RemoveTlcReader<'r>) -> Self {
13616        FiberMessageUnionReader::RemoveTlc(item)
13617    }
13618}
13619impl<'r> ::core::convert::From<RevokeAndAckReader<'r>> for FiberMessageUnionReader<'r> {
13620    fn from(item: RevokeAndAckReader<'r>) -> Self {
13621        FiberMessageUnionReader::RevokeAndAck(item)
13622    }
13623}
13624impl<'r> ::core::convert::From<ShutdownReader<'r>> for FiberMessageUnionReader<'r> {
13625    fn from(item: ShutdownReader<'r>) -> Self {
13626        FiberMessageUnionReader::Shutdown(item)
13627    }
13628}
13629impl<'r> ::core::convert::From<ClosingSignedReader<'r>> for FiberMessageUnionReader<'r> {
13630    fn from(item: ClosingSignedReader<'r>) -> Self {
13631        FiberMessageUnionReader::ClosingSigned(item)
13632    }
13633}
13634impl<'r> ::core::convert::From<ReestablishChannelReader<'r>> for FiberMessageUnionReader<'r> {
13635    fn from(item: ReestablishChannelReader<'r>) -> Self {
13636        FiberMessageUnionReader::ReestablishChannel(item)
13637    }
13638}
13639impl<'r> ::core::convert::From<AnnouncementSignaturesReader<'r>> for FiberMessageUnionReader<'r> {
13640    fn from(item: AnnouncementSignaturesReader<'r>) -> Self {
13641        FiberMessageUnionReader::AnnouncementSignatures(item)
13642    }
13643}
13644impl FiberMessageUnion {
13645    pub const NAME: &'static str = "FiberMessageUnion";
13646    pub fn as_bytes(&self) -> molecule::bytes::Bytes {
13647        match self {
13648            FiberMessageUnion::Init(item) => item.as_bytes(),
13649            FiberMessageUnion::OpenChannel(item) => item.as_bytes(),
13650            FiberMessageUnion::AcceptChannel(item) => item.as_bytes(),
13651            FiberMessageUnion::TxSignatures(item) => item.as_bytes(),
13652            FiberMessageUnion::TxUpdate(item) => item.as_bytes(),
13653            FiberMessageUnion::TxComplete(item) => item.as_bytes(),
13654            FiberMessageUnion::TxAbort(item) => item.as_bytes(),
13655            FiberMessageUnion::TxInitRBF(item) => item.as_bytes(),
13656            FiberMessageUnion::TxAckRBF(item) => item.as_bytes(),
13657            FiberMessageUnion::CommitmentSigned(item) => item.as_bytes(),
13658            FiberMessageUnion::ChannelReady(item) => item.as_bytes(),
13659            FiberMessageUnion::UpdateTlcInfo(item) => item.as_bytes(),
13660            FiberMessageUnion::AddTlc(item) => item.as_bytes(),
13661            FiberMessageUnion::RemoveTlc(item) => item.as_bytes(),
13662            FiberMessageUnion::RevokeAndAck(item) => item.as_bytes(),
13663            FiberMessageUnion::Shutdown(item) => item.as_bytes(),
13664            FiberMessageUnion::ClosingSigned(item) => item.as_bytes(),
13665            FiberMessageUnion::ReestablishChannel(item) => item.as_bytes(),
13666            FiberMessageUnion::AnnouncementSignatures(item) => item.as_bytes(),
13667        }
13668    }
13669    pub fn as_slice(&self) -> &[u8] {
13670        match self {
13671            FiberMessageUnion::Init(item) => item.as_slice(),
13672            FiberMessageUnion::OpenChannel(item) => item.as_slice(),
13673            FiberMessageUnion::AcceptChannel(item) => item.as_slice(),
13674            FiberMessageUnion::TxSignatures(item) => item.as_slice(),
13675            FiberMessageUnion::TxUpdate(item) => item.as_slice(),
13676            FiberMessageUnion::TxComplete(item) => item.as_slice(),
13677            FiberMessageUnion::TxAbort(item) => item.as_slice(),
13678            FiberMessageUnion::TxInitRBF(item) => item.as_slice(),
13679            FiberMessageUnion::TxAckRBF(item) => item.as_slice(),
13680            FiberMessageUnion::CommitmentSigned(item) => item.as_slice(),
13681            FiberMessageUnion::ChannelReady(item) => item.as_slice(),
13682            FiberMessageUnion::UpdateTlcInfo(item) => item.as_slice(),
13683            FiberMessageUnion::AddTlc(item) => item.as_slice(),
13684            FiberMessageUnion::RemoveTlc(item) => item.as_slice(),
13685            FiberMessageUnion::RevokeAndAck(item) => item.as_slice(),
13686            FiberMessageUnion::Shutdown(item) => item.as_slice(),
13687            FiberMessageUnion::ClosingSigned(item) => item.as_slice(),
13688            FiberMessageUnion::ReestablishChannel(item) => item.as_slice(),
13689            FiberMessageUnion::AnnouncementSignatures(item) => item.as_slice(),
13690        }
13691    }
13692    pub fn item_id(&self) -> molecule::Number {
13693        match self {
13694            FiberMessageUnion::Init(_) => 0,
13695            FiberMessageUnion::OpenChannel(_) => 1,
13696            FiberMessageUnion::AcceptChannel(_) => 2,
13697            FiberMessageUnion::TxSignatures(_) => 3,
13698            FiberMessageUnion::TxUpdate(_) => 4,
13699            FiberMessageUnion::TxComplete(_) => 5,
13700            FiberMessageUnion::TxAbort(_) => 6,
13701            FiberMessageUnion::TxInitRBF(_) => 7,
13702            FiberMessageUnion::TxAckRBF(_) => 8,
13703            FiberMessageUnion::CommitmentSigned(_) => 9,
13704            FiberMessageUnion::ChannelReady(_) => 10,
13705            FiberMessageUnion::UpdateTlcInfo(_) => 11,
13706            FiberMessageUnion::AddTlc(_) => 12,
13707            FiberMessageUnion::RemoveTlc(_) => 13,
13708            FiberMessageUnion::RevokeAndAck(_) => 14,
13709            FiberMessageUnion::Shutdown(_) => 15,
13710            FiberMessageUnion::ClosingSigned(_) => 16,
13711            FiberMessageUnion::ReestablishChannel(_) => 17,
13712            FiberMessageUnion::AnnouncementSignatures(_) => 18,
13713        }
13714    }
13715    pub fn item_name(&self) -> &str {
13716        match self {
13717            FiberMessageUnion::Init(_) => "Init",
13718            FiberMessageUnion::OpenChannel(_) => "OpenChannel",
13719            FiberMessageUnion::AcceptChannel(_) => "AcceptChannel",
13720            FiberMessageUnion::TxSignatures(_) => "TxSignatures",
13721            FiberMessageUnion::TxUpdate(_) => "TxUpdate",
13722            FiberMessageUnion::TxComplete(_) => "TxComplete",
13723            FiberMessageUnion::TxAbort(_) => "TxAbort",
13724            FiberMessageUnion::TxInitRBF(_) => "TxInitRBF",
13725            FiberMessageUnion::TxAckRBF(_) => "TxAckRBF",
13726            FiberMessageUnion::CommitmentSigned(_) => "CommitmentSigned",
13727            FiberMessageUnion::ChannelReady(_) => "ChannelReady",
13728            FiberMessageUnion::UpdateTlcInfo(_) => "UpdateTlcInfo",
13729            FiberMessageUnion::AddTlc(_) => "AddTlc",
13730            FiberMessageUnion::RemoveTlc(_) => "RemoveTlc",
13731            FiberMessageUnion::RevokeAndAck(_) => "RevokeAndAck",
13732            FiberMessageUnion::Shutdown(_) => "Shutdown",
13733            FiberMessageUnion::ClosingSigned(_) => "ClosingSigned",
13734            FiberMessageUnion::ReestablishChannel(_) => "ReestablishChannel",
13735            FiberMessageUnion::AnnouncementSignatures(_) => "AnnouncementSignatures",
13736        }
13737    }
13738    pub fn as_reader<'r>(&'r self) -> FiberMessageUnionReader<'r> {
13739        match self {
13740            FiberMessageUnion::Init(item) => item.as_reader().into(),
13741            FiberMessageUnion::OpenChannel(item) => item.as_reader().into(),
13742            FiberMessageUnion::AcceptChannel(item) => item.as_reader().into(),
13743            FiberMessageUnion::TxSignatures(item) => item.as_reader().into(),
13744            FiberMessageUnion::TxUpdate(item) => item.as_reader().into(),
13745            FiberMessageUnion::TxComplete(item) => item.as_reader().into(),
13746            FiberMessageUnion::TxAbort(item) => item.as_reader().into(),
13747            FiberMessageUnion::TxInitRBF(item) => item.as_reader().into(),
13748            FiberMessageUnion::TxAckRBF(item) => item.as_reader().into(),
13749            FiberMessageUnion::CommitmentSigned(item) => item.as_reader().into(),
13750            FiberMessageUnion::ChannelReady(item) => item.as_reader().into(),
13751            FiberMessageUnion::UpdateTlcInfo(item) => item.as_reader().into(),
13752            FiberMessageUnion::AddTlc(item) => item.as_reader().into(),
13753            FiberMessageUnion::RemoveTlc(item) => item.as_reader().into(),
13754            FiberMessageUnion::RevokeAndAck(item) => item.as_reader().into(),
13755            FiberMessageUnion::Shutdown(item) => item.as_reader().into(),
13756            FiberMessageUnion::ClosingSigned(item) => item.as_reader().into(),
13757            FiberMessageUnion::ReestablishChannel(item) => item.as_reader().into(),
13758            FiberMessageUnion::AnnouncementSignatures(item) => item.as_reader().into(),
13759        }
13760    }
13761}
13762impl<'r> FiberMessageUnionReader<'r> {
13763    pub const NAME: &'r str = "FiberMessageUnionReader";
13764    pub fn as_slice(&self) -> &'r [u8] {
13765        match self {
13766            FiberMessageUnionReader::Init(item) => item.as_slice(),
13767            FiberMessageUnionReader::OpenChannel(item) => item.as_slice(),
13768            FiberMessageUnionReader::AcceptChannel(item) => item.as_slice(),
13769            FiberMessageUnionReader::TxSignatures(item) => item.as_slice(),
13770            FiberMessageUnionReader::TxUpdate(item) => item.as_slice(),
13771            FiberMessageUnionReader::TxComplete(item) => item.as_slice(),
13772            FiberMessageUnionReader::TxAbort(item) => item.as_slice(),
13773            FiberMessageUnionReader::TxInitRBF(item) => item.as_slice(),
13774            FiberMessageUnionReader::TxAckRBF(item) => item.as_slice(),
13775            FiberMessageUnionReader::CommitmentSigned(item) => item.as_slice(),
13776            FiberMessageUnionReader::ChannelReady(item) => item.as_slice(),
13777            FiberMessageUnionReader::UpdateTlcInfo(item) => item.as_slice(),
13778            FiberMessageUnionReader::AddTlc(item) => item.as_slice(),
13779            FiberMessageUnionReader::RemoveTlc(item) => item.as_slice(),
13780            FiberMessageUnionReader::RevokeAndAck(item) => item.as_slice(),
13781            FiberMessageUnionReader::Shutdown(item) => item.as_slice(),
13782            FiberMessageUnionReader::ClosingSigned(item) => item.as_slice(),
13783            FiberMessageUnionReader::ReestablishChannel(item) => item.as_slice(),
13784            FiberMessageUnionReader::AnnouncementSignatures(item) => item.as_slice(),
13785        }
13786    }
13787    pub fn item_id(&self) -> molecule::Number {
13788        match self {
13789            FiberMessageUnionReader::Init(_) => 0,
13790            FiberMessageUnionReader::OpenChannel(_) => 1,
13791            FiberMessageUnionReader::AcceptChannel(_) => 2,
13792            FiberMessageUnionReader::TxSignatures(_) => 3,
13793            FiberMessageUnionReader::TxUpdate(_) => 4,
13794            FiberMessageUnionReader::TxComplete(_) => 5,
13795            FiberMessageUnionReader::TxAbort(_) => 6,
13796            FiberMessageUnionReader::TxInitRBF(_) => 7,
13797            FiberMessageUnionReader::TxAckRBF(_) => 8,
13798            FiberMessageUnionReader::CommitmentSigned(_) => 9,
13799            FiberMessageUnionReader::ChannelReady(_) => 10,
13800            FiberMessageUnionReader::UpdateTlcInfo(_) => 11,
13801            FiberMessageUnionReader::AddTlc(_) => 12,
13802            FiberMessageUnionReader::RemoveTlc(_) => 13,
13803            FiberMessageUnionReader::RevokeAndAck(_) => 14,
13804            FiberMessageUnionReader::Shutdown(_) => 15,
13805            FiberMessageUnionReader::ClosingSigned(_) => 16,
13806            FiberMessageUnionReader::ReestablishChannel(_) => 17,
13807            FiberMessageUnionReader::AnnouncementSignatures(_) => 18,
13808        }
13809    }
13810    pub fn item_name(&self) -> &str {
13811        match self {
13812            FiberMessageUnionReader::Init(_) => "Init",
13813            FiberMessageUnionReader::OpenChannel(_) => "OpenChannel",
13814            FiberMessageUnionReader::AcceptChannel(_) => "AcceptChannel",
13815            FiberMessageUnionReader::TxSignatures(_) => "TxSignatures",
13816            FiberMessageUnionReader::TxUpdate(_) => "TxUpdate",
13817            FiberMessageUnionReader::TxComplete(_) => "TxComplete",
13818            FiberMessageUnionReader::TxAbort(_) => "TxAbort",
13819            FiberMessageUnionReader::TxInitRBF(_) => "TxInitRBF",
13820            FiberMessageUnionReader::TxAckRBF(_) => "TxAckRBF",
13821            FiberMessageUnionReader::CommitmentSigned(_) => "CommitmentSigned",
13822            FiberMessageUnionReader::ChannelReady(_) => "ChannelReady",
13823            FiberMessageUnionReader::UpdateTlcInfo(_) => "UpdateTlcInfo",
13824            FiberMessageUnionReader::AddTlc(_) => "AddTlc",
13825            FiberMessageUnionReader::RemoveTlc(_) => "RemoveTlc",
13826            FiberMessageUnionReader::RevokeAndAck(_) => "RevokeAndAck",
13827            FiberMessageUnionReader::Shutdown(_) => "Shutdown",
13828            FiberMessageUnionReader::ClosingSigned(_) => "ClosingSigned",
13829            FiberMessageUnionReader::ReestablishChannel(_) => "ReestablishChannel",
13830            FiberMessageUnionReader::AnnouncementSignatures(_) => "AnnouncementSignatures",
13831        }
13832    }
13833}
13834impl From<Init> for FiberMessage {
13835    fn from(value: Init) -> Self {
13836        Self::new_builder().set(value).build()
13837    }
13838}
13839impl From<OpenChannel> for FiberMessage {
13840    fn from(value: OpenChannel) -> Self {
13841        Self::new_builder().set(value).build()
13842    }
13843}
13844impl From<AcceptChannel> for FiberMessage {
13845    fn from(value: AcceptChannel) -> Self {
13846        Self::new_builder().set(value).build()
13847    }
13848}
13849impl From<TxSignatures> for FiberMessage {
13850    fn from(value: TxSignatures) -> Self {
13851        Self::new_builder().set(value).build()
13852    }
13853}
13854impl From<TxUpdate> for FiberMessage {
13855    fn from(value: TxUpdate) -> Self {
13856        Self::new_builder().set(value).build()
13857    }
13858}
13859impl From<TxComplete> for FiberMessage {
13860    fn from(value: TxComplete) -> Self {
13861        Self::new_builder().set(value).build()
13862    }
13863}
13864impl From<TxAbort> for FiberMessage {
13865    fn from(value: TxAbort) -> Self {
13866        Self::new_builder().set(value).build()
13867    }
13868}
13869impl From<TxInitRBF> for FiberMessage {
13870    fn from(value: TxInitRBF) -> Self {
13871        Self::new_builder().set(value).build()
13872    }
13873}
13874impl From<TxAckRBF> for FiberMessage {
13875    fn from(value: TxAckRBF) -> Self {
13876        Self::new_builder().set(value).build()
13877    }
13878}
13879impl From<CommitmentSigned> for FiberMessage {
13880    fn from(value: CommitmentSigned) -> Self {
13881        Self::new_builder().set(value).build()
13882    }
13883}
13884impl From<ChannelReady> for FiberMessage {
13885    fn from(value: ChannelReady) -> Self {
13886        Self::new_builder().set(value).build()
13887    }
13888}
13889impl From<UpdateTlcInfo> for FiberMessage {
13890    fn from(value: UpdateTlcInfo) -> Self {
13891        Self::new_builder().set(value).build()
13892    }
13893}
13894impl From<AddTlc> for FiberMessage {
13895    fn from(value: AddTlc) -> Self {
13896        Self::new_builder().set(value).build()
13897    }
13898}
13899impl From<RemoveTlc> for FiberMessage {
13900    fn from(value: RemoveTlc) -> Self {
13901        Self::new_builder().set(value).build()
13902    }
13903}
13904impl From<RevokeAndAck> for FiberMessage {
13905    fn from(value: RevokeAndAck) -> Self {
13906        Self::new_builder().set(value).build()
13907    }
13908}
13909impl From<Shutdown> for FiberMessage {
13910    fn from(value: Shutdown) -> Self {
13911        Self::new_builder().set(value).build()
13912    }
13913}
13914impl From<ClosingSigned> for FiberMessage {
13915    fn from(value: ClosingSigned) -> Self {
13916        Self::new_builder().set(value).build()
13917    }
13918}
13919impl From<ReestablishChannel> for FiberMessage {
13920    fn from(value: ReestablishChannel) -> Self {
13921        Self::new_builder().set(value).build()
13922    }
13923}
13924impl From<AnnouncementSignatures> for FiberMessage {
13925    fn from(value: AnnouncementSignatures) -> Self {
13926        Self::new_builder().set(value).build()
13927    }
13928}
13929#[derive(Clone)]
13930pub struct PaymentPreimageOpt(molecule::bytes::Bytes);
13931impl ::core::fmt::LowerHex for PaymentPreimageOpt {
13932    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
13933        use molecule::hex_string;
13934        if f.alternate() {
13935            write!(f, "0x")?;
13936        }
13937        write!(f, "{}", hex_string(self.as_slice()))
13938    }
13939}
13940impl ::core::fmt::Debug for PaymentPreimageOpt {
13941    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
13942        write!(f, "{}({:#x})", Self::NAME, self)
13943    }
13944}
13945impl ::core::fmt::Display for PaymentPreimageOpt {
13946    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
13947        if let Some(v) = self.to_opt() {
13948            write!(f, "{}(Some({}))", Self::NAME, v)
13949        } else {
13950            write!(f, "{}(None)", Self::NAME)
13951        }
13952    }
13953}
13954impl ::core::default::Default for PaymentPreimageOpt {
13955    fn default() -> Self {
13956        let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE);
13957        PaymentPreimageOpt::new_unchecked(v)
13958    }
13959}
13960impl PaymentPreimageOpt {
13961    const DEFAULT_VALUE: [u8; 0] = [];
13962    pub fn is_none(&self) -> bool {
13963        self.0.is_empty()
13964    }
13965    pub fn is_some(&self) -> bool {
13966        !self.0.is_empty()
13967    }
13968    pub fn to_opt(&self) -> Option<Byte32> {
13969        if self.is_none() {
13970            None
13971        } else {
13972            Some(Byte32::new_unchecked(self.0.clone()))
13973        }
13974    }
13975    pub fn as_reader<'r>(&'r self) -> PaymentPreimageOptReader<'r> {
13976        PaymentPreimageOptReader::new_unchecked(self.as_slice())
13977    }
13978}
13979impl molecule::prelude::Entity for PaymentPreimageOpt {
13980    type Builder = PaymentPreimageOptBuilder;
13981    const NAME: &'static str = "PaymentPreimageOpt";
13982    fn new_unchecked(data: molecule::bytes::Bytes) -> Self {
13983        PaymentPreimageOpt(data)
13984    }
13985    fn as_bytes(&self) -> molecule::bytes::Bytes {
13986        self.0.clone()
13987    }
13988    fn as_slice(&self) -> &[u8] {
13989        &self.0[..]
13990    }
13991    fn from_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
13992        PaymentPreimageOptReader::from_slice(slice).map(|reader| reader.to_entity())
13993    }
13994    fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
13995        PaymentPreimageOptReader::from_compatible_slice(slice).map(|reader| reader.to_entity())
13996    }
13997    fn new_builder() -> Self::Builder {
13998        ::core::default::Default::default()
13999    }
14000    fn as_builder(self) -> Self::Builder {
14001        Self::new_builder().set(self.to_opt())
14002    }
14003}
14004#[derive(Clone, Copy)]
14005pub struct PaymentPreimageOptReader<'r>(&'r [u8]);
14006impl<'r> ::core::fmt::LowerHex for PaymentPreimageOptReader<'r> {
14007    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
14008        use molecule::hex_string;
14009        if f.alternate() {
14010            write!(f, "0x")?;
14011        }
14012        write!(f, "{}", hex_string(self.as_slice()))
14013    }
14014}
14015impl<'r> ::core::fmt::Debug for PaymentPreimageOptReader<'r> {
14016    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
14017        write!(f, "{}({:#x})", Self::NAME, self)
14018    }
14019}
14020impl<'r> ::core::fmt::Display for PaymentPreimageOptReader<'r> {
14021    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
14022        if let Some(v) = self.to_opt() {
14023            write!(f, "{}(Some({}))", Self::NAME, v)
14024        } else {
14025            write!(f, "{}(None)", Self::NAME)
14026        }
14027    }
14028}
14029impl<'r> PaymentPreimageOptReader<'r> {
14030    pub fn is_none(&self) -> bool {
14031        self.0.is_empty()
14032    }
14033    pub fn is_some(&self) -> bool {
14034        !self.0.is_empty()
14035    }
14036    pub fn to_opt(&self) -> Option<Byte32Reader<'r>> {
14037        if self.is_none() {
14038            None
14039        } else {
14040            Some(Byte32Reader::new_unchecked(self.as_slice()))
14041        }
14042    }
14043}
14044impl<'r> molecule::prelude::Reader<'r> for PaymentPreimageOptReader<'r> {
14045    type Entity = PaymentPreimageOpt;
14046    const NAME: &'static str = "PaymentPreimageOptReader";
14047    fn to_entity(&self) -> Self::Entity {
14048        Self::Entity::new_unchecked(self.as_slice().to_owned().into())
14049    }
14050    fn new_unchecked(slice: &'r [u8]) -> Self {
14051        PaymentPreimageOptReader(slice)
14052    }
14053    fn as_slice(&self) -> &'r [u8] {
14054        self.0
14055    }
14056    fn verify(slice: &[u8], compatible: bool) -> molecule::error::VerificationResult<()> {
14057        if !slice.is_empty() {
14058            Byte32Reader::verify(&slice[..], compatible)?;
14059        }
14060        Ok(())
14061    }
14062}
14063#[derive(Clone, Debug, Default)]
14064pub struct PaymentPreimageOptBuilder(pub(crate) Option<Byte32>);
14065impl PaymentPreimageOptBuilder {
14066    pub fn set(mut self, v: Option<Byte32>) -> Self {
14067        self.0 = v;
14068        self
14069    }
14070}
14071impl molecule::prelude::Builder for PaymentPreimageOptBuilder {
14072    type Entity = PaymentPreimageOpt;
14073    const NAME: &'static str = "PaymentPreimageOptBuilder";
14074    fn expected_length(&self) -> usize {
14075        self.0
14076            .as_ref()
14077            .map(|ref inner| inner.as_slice().len())
14078            .unwrap_or(0)
14079    }
14080    fn write<W: molecule::io::Write>(&self, writer: &mut W) -> molecule::io::Result<()> {
14081        self.0
14082            .as_ref()
14083            .map(|ref inner| writer.write_all(inner.as_slice()))
14084            .unwrap_or(Ok(()))
14085    }
14086    fn build(&self) -> Self::Entity {
14087        let mut inner = Vec::with_capacity(self.expected_length());
14088        self.write(&mut inner)
14089            .unwrap_or_else(|_| panic!("{} build should be ok", Self::NAME));
14090        PaymentPreimageOpt::new_unchecked(inner.into())
14091    }
14092}
14093impl From<Byte32> for PaymentPreimageOpt {
14094    fn from(value: Byte32) -> Self {
14095        Self::new_builder().set(Some(value)).build()
14096    }
14097}
14098#[derive(Clone)]
14099pub struct PubkeyOpt(molecule::bytes::Bytes);
14100impl ::core::fmt::LowerHex for PubkeyOpt {
14101    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
14102        use molecule::hex_string;
14103        if f.alternate() {
14104            write!(f, "0x")?;
14105        }
14106        write!(f, "{}", hex_string(self.as_slice()))
14107    }
14108}
14109impl ::core::fmt::Debug for PubkeyOpt {
14110    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
14111        write!(f, "{}({:#x})", Self::NAME, self)
14112    }
14113}
14114impl ::core::fmt::Display for PubkeyOpt {
14115    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
14116        if let Some(v) = self.to_opt() {
14117            write!(f, "{}(Some({}))", Self::NAME, v)
14118        } else {
14119            write!(f, "{}(None)", Self::NAME)
14120        }
14121    }
14122}
14123impl ::core::default::Default for PubkeyOpt {
14124    fn default() -> Self {
14125        let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE);
14126        PubkeyOpt::new_unchecked(v)
14127    }
14128}
14129impl PubkeyOpt {
14130    const DEFAULT_VALUE: [u8; 0] = [];
14131    pub fn is_none(&self) -> bool {
14132        self.0.is_empty()
14133    }
14134    pub fn is_some(&self) -> bool {
14135        !self.0.is_empty()
14136    }
14137    pub fn to_opt(&self) -> Option<Pubkey> {
14138        if self.is_none() {
14139            None
14140        } else {
14141            Some(Pubkey::new_unchecked(self.0.clone()))
14142        }
14143    }
14144    pub fn as_reader<'r>(&'r self) -> PubkeyOptReader<'r> {
14145        PubkeyOptReader::new_unchecked(self.as_slice())
14146    }
14147}
14148impl molecule::prelude::Entity for PubkeyOpt {
14149    type Builder = PubkeyOptBuilder;
14150    const NAME: &'static str = "PubkeyOpt";
14151    fn new_unchecked(data: molecule::bytes::Bytes) -> Self {
14152        PubkeyOpt(data)
14153    }
14154    fn as_bytes(&self) -> molecule::bytes::Bytes {
14155        self.0.clone()
14156    }
14157    fn as_slice(&self) -> &[u8] {
14158        &self.0[..]
14159    }
14160    fn from_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
14161        PubkeyOptReader::from_slice(slice).map(|reader| reader.to_entity())
14162    }
14163    fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
14164        PubkeyOptReader::from_compatible_slice(slice).map(|reader| reader.to_entity())
14165    }
14166    fn new_builder() -> Self::Builder {
14167        ::core::default::Default::default()
14168    }
14169    fn as_builder(self) -> Self::Builder {
14170        Self::new_builder().set(self.to_opt())
14171    }
14172}
14173#[derive(Clone, Copy)]
14174pub struct PubkeyOptReader<'r>(&'r [u8]);
14175impl<'r> ::core::fmt::LowerHex for PubkeyOptReader<'r> {
14176    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
14177        use molecule::hex_string;
14178        if f.alternate() {
14179            write!(f, "0x")?;
14180        }
14181        write!(f, "{}", hex_string(self.as_slice()))
14182    }
14183}
14184impl<'r> ::core::fmt::Debug for PubkeyOptReader<'r> {
14185    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
14186        write!(f, "{}({:#x})", Self::NAME, self)
14187    }
14188}
14189impl<'r> ::core::fmt::Display for PubkeyOptReader<'r> {
14190    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
14191        if let Some(v) = self.to_opt() {
14192            write!(f, "{}(Some({}))", Self::NAME, v)
14193        } else {
14194            write!(f, "{}(None)", Self::NAME)
14195        }
14196    }
14197}
14198impl<'r> PubkeyOptReader<'r> {
14199    pub fn is_none(&self) -> bool {
14200        self.0.is_empty()
14201    }
14202    pub fn is_some(&self) -> bool {
14203        !self.0.is_empty()
14204    }
14205    pub fn to_opt(&self) -> Option<PubkeyReader<'r>> {
14206        if self.is_none() {
14207            None
14208        } else {
14209            Some(PubkeyReader::new_unchecked(self.as_slice()))
14210        }
14211    }
14212}
14213impl<'r> molecule::prelude::Reader<'r> for PubkeyOptReader<'r> {
14214    type Entity = PubkeyOpt;
14215    const NAME: &'static str = "PubkeyOptReader";
14216    fn to_entity(&self) -> Self::Entity {
14217        Self::Entity::new_unchecked(self.as_slice().to_owned().into())
14218    }
14219    fn new_unchecked(slice: &'r [u8]) -> Self {
14220        PubkeyOptReader(slice)
14221    }
14222    fn as_slice(&self) -> &'r [u8] {
14223        self.0
14224    }
14225    fn verify(slice: &[u8], compatible: bool) -> molecule::error::VerificationResult<()> {
14226        if !slice.is_empty() {
14227            PubkeyReader::verify(&slice[..], compatible)?;
14228        }
14229        Ok(())
14230    }
14231}
14232#[derive(Clone, Debug, Default)]
14233pub struct PubkeyOptBuilder(pub(crate) Option<Pubkey>);
14234impl PubkeyOptBuilder {
14235    pub fn set(mut self, v: Option<Pubkey>) -> Self {
14236        self.0 = v;
14237        self
14238    }
14239}
14240impl molecule::prelude::Builder for PubkeyOptBuilder {
14241    type Entity = PubkeyOpt;
14242    const NAME: &'static str = "PubkeyOptBuilder";
14243    fn expected_length(&self) -> usize {
14244        self.0
14245            .as_ref()
14246            .map(|ref inner| inner.as_slice().len())
14247            .unwrap_or(0)
14248    }
14249    fn write<W: molecule::io::Write>(&self, writer: &mut W) -> molecule::io::Result<()> {
14250        self.0
14251            .as_ref()
14252            .map(|ref inner| writer.write_all(inner.as_slice()))
14253            .unwrap_or(Ok(()))
14254    }
14255    fn build(&self) -> Self::Entity {
14256        let mut inner = Vec::with_capacity(self.expected_length());
14257        self.write(&mut inner)
14258            .unwrap_or_else(|_| panic!("{} build should be ok", Self::NAME));
14259        PubkeyOpt::new_unchecked(inner.into())
14260    }
14261}
14262impl From<Pubkey> for PubkeyOpt {
14263    fn from(value: Pubkey) -> Self {
14264        Self::new_builder().set(Some(value)).build()
14265    }
14266}
14267#[derive(Clone)]
14268pub struct PaymentHopData(molecule::bytes::Bytes);
14269impl ::core::fmt::LowerHex for PaymentHopData {
14270    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
14271        use molecule::hex_string;
14272        if f.alternate() {
14273            write!(f, "0x")?;
14274        }
14275        write!(f, "{}", hex_string(self.as_slice()))
14276    }
14277}
14278impl ::core::fmt::Debug for PaymentHopData {
14279    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
14280        write!(f, "{}({:#x})", Self::NAME, self)
14281    }
14282}
14283impl ::core::fmt::Display for PaymentHopData {
14284    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
14285        write!(f, "{} {{ ", Self::NAME)?;
14286        write!(f, "{}: {}", "amount", self.amount())?;
14287        write!(f, ", {}: {}", "expiry", self.expiry())?;
14288        write!(f, ", {}: {}", "payment_preimage", self.payment_preimage())?;
14289        write!(f, ", {}: {}", "hash_algorithm", self.hash_algorithm())?;
14290        write!(f, ", {}: {}", "funding_tx_hash", self.funding_tx_hash())?;
14291        write!(f, ", {}: {}", "next_hop", self.next_hop())?;
14292        write!(f, ", {}: {}", "custom_records", self.custom_records())?;
14293        let extra_count = self.count_extra_fields();
14294        if extra_count != 0 {
14295            write!(f, ", .. ({} fields)", extra_count)?;
14296        }
14297        write!(f, " }}")
14298    }
14299}
14300impl ::core::default::Default for PaymentHopData {
14301    fn default() -> Self {
14302        let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE);
14303        PaymentHopData::new_unchecked(v)
14304    }
14305}
14306impl PaymentHopData {
14307    const DEFAULT_VALUE: [u8; 89] = [
14308        89, 0, 0, 0, 32, 0, 0, 0, 48, 0, 0, 0, 56, 0, 0, 0, 56, 0, 0, 0, 57, 0, 0, 0, 89, 0, 0, 0,
14309        89, 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,
14310        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,
14311        0,
14312    ];
14313    pub const FIELD_COUNT: usize = 7;
14314    pub fn total_size(&self) -> usize {
14315        molecule::unpack_number(self.as_slice()) as usize
14316    }
14317    pub fn field_count(&self) -> usize {
14318        if self.total_size() == molecule::NUMBER_SIZE {
14319            0
14320        } else {
14321            (molecule::unpack_number(&self.as_slice()[molecule::NUMBER_SIZE..]) as usize / 4) - 1
14322        }
14323    }
14324    pub fn count_extra_fields(&self) -> usize {
14325        self.field_count() - Self::FIELD_COUNT
14326    }
14327    pub fn has_extra_fields(&self) -> bool {
14328        Self::FIELD_COUNT != self.field_count()
14329    }
14330    pub fn amount(&self) -> Uint128 {
14331        let slice = self.as_slice();
14332        let start = molecule::unpack_number(&slice[4..]) as usize;
14333        let end = molecule::unpack_number(&slice[8..]) as usize;
14334        Uint128::new_unchecked(self.0.slice(start..end))
14335    }
14336    pub fn expiry(&self) -> Uint64 {
14337        let slice = self.as_slice();
14338        let start = molecule::unpack_number(&slice[8..]) as usize;
14339        let end = molecule::unpack_number(&slice[12..]) as usize;
14340        Uint64::new_unchecked(self.0.slice(start..end))
14341    }
14342    pub fn payment_preimage(&self) -> PaymentPreimageOpt {
14343        let slice = self.as_slice();
14344        let start = molecule::unpack_number(&slice[12..]) as usize;
14345        let end = molecule::unpack_number(&slice[16..]) as usize;
14346        PaymentPreimageOpt::new_unchecked(self.0.slice(start..end))
14347    }
14348    pub fn hash_algorithm(&self) -> Byte {
14349        let slice = self.as_slice();
14350        let start = molecule::unpack_number(&slice[16..]) as usize;
14351        let end = molecule::unpack_number(&slice[20..]) as usize;
14352        Byte::new_unchecked(self.0.slice(start..end))
14353    }
14354    pub fn funding_tx_hash(&self) -> Byte32 {
14355        let slice = self.as_slice();
14356        let start = molecule::unpack_number(&slice[20..]) as usize;
14357        let end = molecule::unpack_number(&slice[24..]) as usize;
14358        Byte32::new_unchecked(self.0.slice(start..end))
14359    }
14360    pub fn next_hop(&self) -> PubkeyOpt {
14361        let slice = self.as_slice();
14362        let start = molecule::unpack_number(&slice[24..]) as usize;
14363        let end = molecule::unpack_number(&slice[28..]) as usize;
14364        PubkeyOpt::new_unchecked(self.0.slice(start..end))
14365    }
14366    pub fn custom_records(&self) -> CustomRecordsOpt {
14367        let slice = self.as_slice();
14368        let start = molecule::unpack_number(&slice[28..]) as usize;
14369        if self.has_extra_fields() {
14370            let end = molecule::unpack_number(&slice[32..]) as usize;
14371            CustomRecordsOpt::new_unchecked(self.0.slice(start..end))
14372        } else {
14373            CustomRecordsOpt::new_unchecked(self.0.slice(start..))
14374        }
14375    }
14376    pub fn as_reader<'r>(&'r self) -> PaymentHopDataReader<'r> {
14377        PaymentHopDataReader::new_unchecked(self.as_slice())
14378    }
14379}
14380impl molecule::prelude::Entity for PaymentHopData {
14381    type Builder = PaymentHopDataBuilder;
14382    const NAME: &'static str = "PaymentHopData";
14383    fn new_unchecked(data: molecule::bytes::Bytes) -> Self {
14384        PaymentHopData(data)
14385    }
14386    fn as_bytes(&self) -> molecule::bytes::Bytes {
14387        self.0.clone()
14388    }
14389    fn as_slice(&self) -> &[u8] {
14390        &self.0[..]
14391    }
14392    fn from_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
14393        PaymentHopDataReader::from_slice(slice).map(|reader| reader.to_entity())
14394    }
14395    fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
14396        PaymentHopDataReader::from_compatible_slice(slice).map(|reader| reader.to_entity())
14397    }
14398    fn new_builder() -> Self::Builder {
14399        ::core::default::Default::default()
14400    }
14401    fn as_builder(self) -> Self::Builder {
14402        Self::new_builder()
14403            .amount(self.amount())
14404            .expiry(self.expiry())
14405            .payment_preimage(self.payment_preimage())
14406            .hash_algorithm(self.hash_algorithm())
14407            .funding_tx_hash(self.funding_tx_hash())
14408            .next_hop(self.next_hop())
14409            .custom_records(self.custom_records())
14410    }
14411}
14412#[derive(Clone, Copy)]
14413pub struct PaymentHopDataReader<'r>(&'r [u8]);
14414impl<'r> ::core::fmt::LowerHex for PaymentHopDataReader<'r> {
14415    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
14416        use molecule::hex_string;
14417        if f.alternate() {
14418            write!(f, "0x")?;
14419        }
14420        write!(f, "{}", hex_string(self.as_slice()))
14421    }
14422}
14423impl<'r> ::core::fmt::Debug for PaymentHopDataReader<'r> {
14424    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
14425        write!(f, "{}({:#x})", Self::NAME, self)
14426    }
14427}
14428impl<'r> ::core::fmt::Display for PaymentHopDataReader<'r> {
14429    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
14430        write!(f, "{} {{ ", Self::NAME)?;
14431        write!(f, "{}: {}", "amount", self.amount())?;
14432        write!(f, ", {}: {}", "expiry", self.expiry())?;
14433        write!(f, ", {}: {}", "payment_preimage", self.payment_preimage())?;
14434        write!(f, ", {}: {}", "hash_algorithm", self.hash_algorithm())?;
14435        write!(f, ", {}: {}", "funding_tx_hash", self.funding_tx_hash())?;
14436        write!(f, ", {}: {}", "next_hop", self.next_hop())?;
14437        write!(f, ", {}: {}", "custom_records", self.custom_records())?;
14438        let extra_count = self.count_extra_fields();
14439        if extra_count != 0 {
14440            write!(f, ", .. ({} fields)", extra_count)?;
14441        }
14442        write!(f, " }}")
14443    }
14444}
14445impl<'r> PaymentHopDataReader<'r> {
14446    pub const FIELD_COUNT: usize = 7;
14447    pub fn total_size(&self) -> usize {
14448        molecule::unpack_number(self.as_slice()) as usize
14449    }
14450    pub fn field_count(&self) -> usize {
14451        if self.total_size() == molecule::NUMBER_SIZE {
14452            0
14453        } else {
14454            (molecule::unpack_number(&self.as_slice()[molecule::NUMBER_SIZE..]) as usize / 4) - 1
14455        }
14456    }
14457    pub fn count_extra_fields(&self) -> usize {
14458        self.field_count() - Self::FIELD_COUNT
14459    }
14460    pub fn has_extra_fields(&self) -> bool {
14461        Self::FIELD_COUNT != self.field_count()
14462    }
14463    pub fn amount(&self) -> Uint128Reader<'r> {
14464        let slice = self.as_slice();
14465        let start = molecule::unpack_number(&slice[4..]) as usize;
14466        let end = molecule::unpack_number(&slice[8..]) as usize;
14467        Uint128Reader::new_unchecked(&self.as_slice()[start..end])
14468    }
14469    pub fn expiry(&self) -> Uint64Reader<'r> {
14470        let slice = self.as_slice();
14471        let start = molecule::unpack_number(&slice[8..]) as usize;
14472        let end = molecule::unpack_number(&slice[12..]) as usize;
14473        Uint64Reader::new_unchecked(&self.as_slice()[start..end])
14474    }
14475    pub fn payment_preimage(&self) -> PaymentPreimageOptReader<'r> {
14476        let slice = self.as_slice();
14477        let start = molecule::unpack_number(&slice[12..]) as usize;
14478        let end = molecule::unpack_number(&slice[16..]) as usize;
14479        PaymentPreimageOptReader::new_unchecked(&self.as_slice()[start..end])
14480    }
14481    pub fn hash_algorithm(&self) -> ByteReader<'r> {
14482        let slice = self.as_slice();
14483        let start = molecule::unpack_number(&slice[16..]) as usize;
14484        let end = molecule::unpack_number(&slice[20..]) as usize;
14485        ByteReader::new_unchecked(&self.as_slice()[start..end])
14486    }
14487    pub fn funding_tx_hash(&self) -> Byte32Reader<'r> {
14488        let slice = self.as_slice();
14489        let start = molecule::unpack_number(&slice[20..]) as usize;
14490        let end = molecule::unpack_number(&slice[24..]) as usize;
14491        Byte32Reader::new_unchecked(&self.as_slice()[start..end])
14492    }
14493    pub fn next_hop(&self) -> PubkeyOptReader<'r> {
14494        let slice = self.as_slice();
14495        let start = molecule::unpack_number(&slice[24..]) as usize;
14496        let end = molecule::unpack_number(&slice[28..]) as usize;
14497        PubkeyOptReader::new_unchecked(&self.as_slice()[start..end])
14498    }
14499    pub fn custom_records(&self) -> CustomRecordsOptReader<'r> {
14500        let slice = self.as_slice();
14501        let start = molecule::unpack_number(&slice[28..]) as usize;
14502        if self.has_extra_fields() {
14503            let end = molecule::unpack_number(&slice[32..]) as usize;
14504            CustomRecordsOptReader::new_unchecked(&self.as_slice()[start..end])
14505        } else {
14506            CustomRecordsOptReader::new_unchecked(&self.as_slice()[start..])
14507        }
14508    }
14509}
14510impl<'r> molecule::prelude::Reader<'r> for PaymentHopDataReader<'r> {
14511    type Entity = PaymentHopData;
14512    const NAME: &'static str = "PaymentHopDataReader";
14513    fn to_entity(&self) -> Self::Entity {
14514        Self::Entity::new_unchecked(self.as_slice().to_owned().into())
14515    }
14516    fn new_unchecked(slice: &'r [u8]) -> Self {
14517        PaymentHopDataReader(slice)
14518    }
14519    fn as_slice(&self) -> &'r [u8] {
14520        self.0
14521    }
14522    fn verify(slice: &[u8], compatible: bool) -> molecule::error::VerificationResult<()> {
14523        use molecule::verification_error as ve;
14524        let slice_len = slice.len();
14525        if slice_len < molecule::NUMBER_SIZE {
14526            return ve!(Self, HeaderIsBroken, molecule::NUMBER_SIZE, slice_len);
14527        }
14528        let total_size = molecule::unpack_number(slice) as usize;
14529        if slice_len != total_size {
14530            return ve!(Self, TotalSizeNotMatch, total_size, slice_len);
14531        }
14532        if slice_len < molecule::NUMBER_SIZE * 2 {
14533            return ve!(Self, HeaderIsBroken, molecule::NUMBER_SIZE * 2, slice_len);
14534        }
14535        let offset_first = molecule::unpack_number(&slice[molecule::NUMBER_SIZE..]) as usize;
14536        if offset_first % molecule::NUMBER_SIZE != 0 || offset_first < molecule::NUMBER_SIZE * 2 {
14537            return ve!(Self, OffsetsNotMatch);
14538        }
14539        if slice_len < offset_first {
14540            return ve!(Self, HeaderIsBroken, offset_first, slice_len);
14541        }
14542        let field_count = offset_first / molecule::NUMBER_SIZE - 1;
14543        if field_count < Self::FIELD_COUNT {
14544            return ve!(Self, FieldCountNotMatch, Self::FIELD_COUNT, field_count);
14545        } else if !compatible && field_count > Self::FIELD_COUNT {
14546            return ve!(Self, FieldCountNotMatch, Self::FIELD_COUNT, field_count);
14547        };
14548        let mut offsets: Vec<usize> = slice[molecule::NUMBER_SIZE..offset_first]
14549            .chunks_exact(molecule::NUMBER_SIZE)
14550            .map(|x| molecule::unpack_number(x) as usize)
14551            .collect();
14552        offsets.push(total_size);
14553        if offsets.windows(2).any(|i| i[0] > i[1]) {
14554            return ve!(Self, OffsetsNotMatch);
14555        }
14556        Uint128Reader::verify(&slice[offsets[0]..offsets[1]], compatible)?;
14557        Uint64Reader::verify(&slice[offsets[1]..offsets[2]], compatible)?;
14558        PaymentPreimageOptReader::verify(&slice[offsets[2]..offsets[3]], compatible)?;
14559        ByteReader::verify(&slice[offsets[3]..offsets[4]], compatible)?;
14560        Byte32Reader::verify(&slice[offsets[4]..offsets[5]], compatible)?;
14561        PubkeyOptReader::verify(&slice[offsets[5]..offsets[6]], compatible)?;
14562        CustomRecordsOptReader::verify(&slice[offsets[6]..offsets[7]], compatible)?;
14563        Ok(())
14564    }
14565}
14566#[derive(Clone, Debug, Default)]
14567pub struct PaymentHopDataBuilder {
14568    pub(crate) amount: Uint128,
14569    pub(crate) expiry: Uint64,
14570    pub(crate) payment_preimage: PaymentPreimageOpt,
14571    pub(crate) hash_algorithm: Byte,
14572    pub(crate) funding_tx_hash: Byte32,
14573    pub(crate) next_hop: PubkeyOpt,
14574    pub(crate) custom_records: CustomRecordsOpt,
14575}
14576impl PaymentHopDataBuilder {
14577    pub const FIELD_COUNT: usize = 7;
14578    pub fn amount(mut self, v: Uint128) -> Self {
14579        self.amount = v;
14580        self
14581    }
14582    pub fn expiry(mut self, v: Uint64) -> Self {
14583        self.expiry = v;
14584        self
14585    }
14586    pub fn payment_preimage(mut self, v: PaymentPreimageOpt) -> Self {
14587        self.payment_preimage = v;
14588        self
14589    }
14590    pub fn hash_algorithm(mut self, v: Byte) -> Self {
14591        self.hash_algorithm = v;
14592        self
14593    }
14594    pub fn funding_tx_hash(mut self, v: Byte32) -> Self {
14595        self.funding_tx_hash = v;
14596        self
14597    }
14598    pub fn next_hop(mut self, v: PubkeyOpt) -> Self {
14599        self.next_hop = v;
14600        self
14601    }
14602    pub fn custom_records(mut self, v: CustomRecordsOpt) -> Self {
14603        self.custom_records = v;
14604        self
14605    }
14606}
14607impl molecule::prelude::Builder for PaymentHopDataBuilder {
14608    type Entity = PaymentHopData;
14609    const NAME: &'static str = "PaymentHopDataBuilder";
14610    fn expected_length(&self) -> usize {
14611        molecule::NUMBER_SIZE * (Self::FIELD_COUNT + 1)
14612            + self.amount.as_slice().len()
14613            + self.expiry.as_slice().len()
14614            + self.payment_preimage.as_slice().len()
14615            + self.hash_algorithm.as_slice().len()
14616            + self.funding_tx_hash.as_slice().len()
14617            + self.next_hop.as_slice().len()
14618            + self.custom_records.as_slice().len()
14619    }
14620    fn write<W: molecule::io::Write>(&self, writer: &mut W) -> molecule::io::Result<()> {
14621        let mut total_size = molecule::NUMBER_SIZE * (Self::FIELD_COUNT + 1);
14622        let mut offsets = Vec::with_capacity(Self::FIELD_COUNT);
14623        offsets.push(total_size);
14624        total_size += self.amount.as_slice().len();
14625        offsets.push(total_size);
14626        total_size += self.expiry.as_slice().len();
14627        offsets.push(total_size);
14628        total_size += self.payment_preimage.as_slice().len();
14629        offsets.push(total_size);
14630        total_size += self.hash_algorithm.as_slice().len();
14631        offsets.push(total_size);
14632        total_size += self.funding_tx_hash.as_slice().len();
14633        offsets.push(total_size);
14634        total_size += self.next_hop.as_slice().len();
14635        offsets.push(total_size);
14636        total_size += self.custom_records.as_slice().len();
14637        writer.write_all(&molecule::pack_number(total_size as molecule::Number))?;
14638        for offset in offsets.into_iter() {
14639            writer.write_all(&molecule::pack_number(offset as molecule::Number))?;
14640        }
14641        writer.write_all(self.amount.as_slice())?;
14642        writer.write_all(self.expiry.as_slice())?;
14643        writer.write_all(self.payment_preimage.as_slice())?;
14644        writer.write_all(self.hash_algorithm.as_slice())?;
14645        writer.write_all(self.funding_tx_hash.as_slice())?;
14646        writer.write_all(self.next_hop.as_slice())?;
14647        writer.write_all(self.custom_records.as_slice())?;
14648        Ok(())
14649    }
14650    fn build(&self) -> Self::Entity {
14651        let mut inner = Vec::with_capacity(self.expected_length());
14652        self.write(&mut inner)
14653            .unwrap_or_else(|_| panic!("{} build should be ok", Self::NAME));
14654        PaymentHopData::new_unchecked(inner.into())
14655    }
14656}
14657#[derive(Clone)]
14658pub struct TrampolineForwardPayload(molecule::bytes::Bytes);
14659impl ::core::fmt::LowerHex for TrampolineForwardPayload {
14660    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
14661        use molecule::hex_string;
14662        if f.alternate() {
14663            write!(f, "0x")?;
14664        }
14665        write!(f, "{}", hex_string(self.as_slice()))
14666    }
14667}
14668impl ::core::fmt::Debug for TrampolineForwardPayload {
14669    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
14670        write!(f, "{}({:#x})", Self::NAME, self)
14671    }
14672}
14673impl ::core::fmt::Display for TrampolineForwardPayload {
14674    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
14675        write!(f, "{} {{ ", Self::NAME)?;
14676        write!(f, "{}: {}", "next_node_id", self.next_node_id())?;
14677        write!(f, ", {}: {}", "amount_to_forward", self.amount_to_forward())?;
14678        write!(f, ", {}: {}", "hash_algorithm", self.hash_algorithm())?;
14679        write!(
14680            f,
14681            ", {}: {}",
14682            "build_max_fee_amount",
14683            self.build_max_fee_amount()
14684        )?;
14685        write!(f, ", {}: {}", "tlc_expiry_delta", self.tlc_expiry_delta())?;
14686        write!(f, ", {}: {}", "tlc_expiry_limit", self.tlc_expiry_limit())?;
14687        write!(f, ", {}: {}", "max_parts", self.max_parts())?;
14688        let extra_count = self.count_extra_fields();
14689        if extra_count != 0 {
14690            write!(f, ", .. ({} fields)", extra_count)?;
14691        }
14692        write!(f, " }}")
14693    }
14694}
14695impl ::core::default::Default for TrampolineForwardPayload {
14696    fn default() -> Self {
14697        let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE);
14698        TrampolineForwardPayload::new_unchecked(v)
14699    }
14700}
14701impl TrampolineForwardPayload {
14702    const DEFAULT_VALUE: [u8; 114] = [
14703        114, 0, 0, 0, 32, 0, 0, 0, 65, 0, 0, 0, 81, 0, 0, 0, 82, 0, 0, 0, 98, 0, 0, 0, 106, 0, 0,
14704        0, 114, 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,
14705        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,
14706        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,
14707    ];
14708    pub const FIELD_COUNT: usize = 7;
14709    pub fn total_size(&self) -> usize {
14710        molecule::unpack_number(self.as_slice()) as usize
14711    }
14712    pub fn field_count(&self) -> usize {
14713        if self.total_size() == molecule::NUMBER_SIZE {
14714            0
14715        } else {
14716            (molecule::unpack_number(&self.as_slice()[molecule::NUMBER_SIZE..]) as usize / 4) - 1
14717        }
14718    }
14719    pub fn count_extra_fields(&self) -> usize {
14720        self.field_count() - Self::FIELD_COUNT
14721    }
14722    pub fn has_extra_fields(&self) -> bool {
14723        Self::FIELD_COUNT != self.field_count()
14724    }
14725    pub fn next_node_id(&self) -> Pubkey {
14726        let slice = self.as_slice();
14727        let start = molecule::unpack_number(&slice[4..]) as usize;
14728        let end = molecule::unpack_number(&slice[8..]) as usize;
14729        Pubkey::new_unchecked(self.0.slice(start..end))
14730    }
14731    pub fn amount_to_forward(&self) -> Uint128 {
14732        let slice = self.as_slice();
14733        let start = molecule::unpack_number(&slice[8..]) as usize;
14734        let end = molecule::unpack_number(&slice[12..]) as usize;
14735        Uint128::new_unchecked(self.0.slice(start..end))
14736    }
14737    pub fn hash_algorithm(&self) -> Byte {
14738        let slice = self.as_slice();
14739        let start = molecule::unpack_number(&slice[12..]) as usize;
14740        let end = molecule::unpack_number(&slice[16..]) as usize;
14741        Byte::new_unchecked(self.0.slice(start..end))
14742    }
14743    pub fn build_max_fee_amount(&self) -> Uint128 {
14744        let slice = self.as_slice();
14745        let start = molecule::unpack_number(&slice[16..]) as usize;
14746        let end = molecule::unpack_number(&slice[20..]) as usize;
14747        Uint128::new_unchecked(self.0.slice(start..end))
14748    }
14749    pub fn tlc_expiry_delta(&self) -> Uint64 {
14750        let slice = self.as_slice();
14751        let start = molecule::unpack_number(&slice[20..]) as usize;
14752        let end = molecule::unpack_number(&slice[24..]) as usize;
14753        Uint64::new_unchecked(self.0.slice(start..end))
14754    }
14755    pub fn tlc_expiry_limit(&self) -> Uint64 {
14756        let slice = self.as_slice();
14757        let start = molecule::unpack_number(&slice[24..]) as usize;
14758        let end = molecule::unpack_number(&slice[28..]) as usize;
14759        Uint64::new_unchecked(self.0.slice(start..end))
14760    }
14761    pub fn max_parts(&self) -> Uint64Opt {
14762        let slice = self.as_slice();
14763        let start = molecule::unpack_number(&slice[28..]) as usize;
14764        if self.has_extra_fields() {
14765            let end = molecule::unpack_number(&slice[32..]) as usize;
14766            Uint64Opt::new_unchecked(self.0.slice(start..end))
14767        } else {
14768            Uint64Opt::new_unchecked(self.0.slice(start..))
14769        }
14770    }
14771    pub fn as_reader<'r>(&'r self) -> TrampolineForwardPayloadReader<'r> {
14772        TrampolineForwardPayloadReader::new_unchecked(self.as_slice())
14773    }
14774}
14775impl molecule::prelude::Entity for TrampolineForwardPayload {
14776    type Builder = TrampolineForwardPayloadBuilder;
14777    const NAME: &'static str = "TrampolineForwardPayload";
14778    fn new_unchecked(data: molecule::bytes::Bytes) -> Self {
14779        TrampolineForwardPayload(data)
14780    }
14781    fn as_bytes(&self) -> molecule::bytes::Bytes {
14782        self.0.clone()
14783    }
14784    fn as_slice(&self) -> &[u8] {
14785        &self.0[..]
14786    }
14787    fn from_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
14788        TrampolineForwardPayloadReader::from_slice(slice).map(|reader| reader.to_entity())
14789    }
14790    fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
14791        TrampolineForwardPayloadReader::from_compatible_slice(slice)
14792            .map(|reader| reader.to_entity())
14793    }
14794    fn new_builder() -> Self::Builder {
14795        ::core::default::Default::default()
14796    }
14797    fn as_builder(self) -> Self::Builder {
14798        Self::new_builder()
14799            .next_node_id(self.next_node_id())
14800            .amount_to_forward(self.amount_to_forward())
14801            .hash_algorithm(self.hash_algorithm())
14802            .build_max_fee_amount(self.build_max_fee_amount())
14803            .tlc_expiry_delta(self.tlc_expiry_delta())
14804            .tlc_expiry_limit(self.tlc_expiry_limit())
14805            .max_parts(self.max_parts())
14806    }
14807}
14808#[derive(Clone, Copy)]
14809pub struct TrampolineForwardPayloadReader<'r>(&'r [u8]);
14810impl<'r> ::core::fmt::LowerHex for TrampolineForwardPayloadReader<'r> {
14811    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
14812        use molecule::hex_string;
14813        if f.alternate() {
14814            write!(f, "0x")?;
14815        }
14816        write!(f, "{}", hex_string(self.as_slice()))
14817    }
14818}
14819impl<'r> ::core::fmt::Debug for TrampolineForwardPayloadReader<'r> {
14820    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
14821        write!(f, "{}({:#x})", Self::NAME, self)
14822    }
14823}
14824impl<'r> ::core::fmt::Display for TrampolineForwardPayloadReader<'r> {
14825    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
14826        write!(f, "{} {{ ", Self::NAME)?;
14827        write!(f, "{}: {}", "next_node_id", self.next_node_id())?;
14828        write!(f, ", {}: {}", "amount_to_forward", self.amount_to_forward())?;
14829        write!(f, ", {}: {}", "hash_algorithm", self.hash_algorithm())?;
14830        write!(
14831            f,
14832            ", {}: {}",
14833            "build_max_fee_amount",
14834            self.build_max_fee_amount()
14835        )?;
14836        write!(f, ", {}: {}", "tlc_expiry_delta", self.tlc_expiry_delta())?;
14837        write!(f, ", {}: {}", "tlc_expiry_limit", self.tlc_expiry_limit())?;
14838        write!(f, ", {}: {}", "max_parts", self.max_parts())?;
14839        let extra_count = self.count_extra_fields();
14840        if extra_count != 0 {
14841            write!(f, ", .. ({} fields)", extra_count)?;
14842        }
14843        write!(f, " }}")
14844    }
14845}
14846impl<'r> TrampolineForwardPayloadReader<'r> {
14847    pub const FIELD_COUNT: usize = 7;
14848    pub fn total_size(&self) -> usize {
14849        molecule::unpack_number(self.as_slice()) as usize
14850    }
14851    pub fn field_count(&self) -> usize {
14852        if self.total_size() == molecule::NUMBER_SIZE {
14853            0
14854        } else {
14855            (molecule::unpack_number(&self.as_slice()[molecule::NUMBER_SIZE..]) as usize / 4) - 1
14856        }
14857    }
14858    pub fn count_extra_fields(&self) -> usize {
14859        self.field_count() - Self::FIELD_COUNT
14860    }
14861    pub fn has_extra_fields(&self) -> bool {
14862        Self::FIELD_COUNT != self.field_count()
14863    }
14864    pub fn next_node_id(&self) -> PubkeyReader<'r> {
14865        let slice = self.as_slice();
14866        let start = molecule::unpack_number(&slice[4..]) as usize;
14867        let end = molecule::unpack_number(&slice[8..]) as usize;
14868        PubkeyReader::new_unchecked(&self.as_slice()[start..end])
14869    }
14870    pub fn amount_to_forward(&self) -> Uint128Reader<'r> {
14871        let slice = self.as_slice();
14872        let start = molecule::unpack_number(&slice[8..]) as usize;
14873        let end = molecule::unpack_number(&slice[12..]) as usize;
14874        Uint128Reader::new_unchecked(&self.as_slice()[start..end])
14875    }
14876    pub fn hash_algorithm(&self) -> ByteReader<'r> {
14877        let slice = self.as_slice();
14878        let start = molecule::unpack_number(&slice[12..]) as usize;
14879        let end = molecule::unpack_number(&slice[16..]) as usize;
14880        ByteReader::new_unchecked(&self.as_slice()[start..end])
14881    }
14882    pub fn build_max_fee_amount(&self) -> Uint128Reader<'r> {
14883        let slice = self.as_slice();
14884        let start = molecule::unpack_number(&slice[16..]) as usize;
14885        let end = molecule::unpack_number(&slice[20..]) as usize;
14886        Uint128Reader::new_unchecked(&self.as_slice()[start..end])
14887    }
14888    pub fn tlc_expiry_delta(&self) -> Uint64Reader<'r> {
14889        let slice = self.as_slice();
14890        let start = molecule::unpack_number(&slice[20..]) as usize;
14891        let end = molecule::unpack_number(&slice[24..]) as usize;
14892        Uint64Reader::new_unchecked(&self.as_slice()[start..end])
14893    }
14894    pub fn tlc_expiry_limit(&self) -> Uint64Reader<'r> {
14895        let slice = self.as_slice();
14896        let start = molecule::unpack_number(&slice[24..]) as usize;
14897        let end = molecule::unpack_number(&slice[28..]) as usize;
14898        Uint64Reader::new_unchecked(&self.as_slice()[start..end])
14899    }
14900    pub fn max_parts(&self) -> Uint64OptReader<'r> {
14901        let slice = self.as_slice();
14902        let start = molecule::unpack_number(&slice[28..]) as usize;
14903        if self.has_extra_fields() {
14904            let end = molecule::unpack_number(&slice[32..]) as usize;
14905            Uint64OptReader::new_unchecked(&self.as_slice()[start..end])
14906        } else {
14907            Uint64OptReader::new_unchecked(&self.as_slice()[start..])
14908        }
14909    }
14910}
14911impl<'r> molecule::prelude::Reader<'r> for TrampolineForwardPayloadReader<'r> {
14912    type Entity = TrampolineForwardPayload;
14913    const NAME: &'static str = "TrampolineForwardPayloadReader";
14914    fn to_entity(&self) -> Self::Entity {
14915        Self::Entity::new_unchecked(self.as_slice().to_owned().into())
14916    }
14917    fn new_unchecked(slice: &'r [u8]) -> Self {
14918        TrampolineForwardPayloadReader(slice)
14919    }
14920    fn as_slice(&self) -> &'r [u8] {
14921        self.0
14922    }
14923    fn verify(slice: &[u8], compatible: bool) -> molecule::error::VerificationResult<()> {
14924        use molecule::verification_error as ve;
14925        let slice_len = slice.len();
14926        if slice_len < molecule::NUMBER_SIZE {
14927            return ve!(Self, HeaderIsBroken, molecule::NUMBER_SIZE, slice_len);
14928        }
14929        let total_size = molecule::unpack_number(slice) as usize;
14930        if slice_len != total_size {
14931            return ve!(Self, TotalSizeNotMatch, total_size, slice_len);
14932        }
14933        if slice_len < molecule::NUMBER_SIZE * 2 {
14934            return ve!(Self, HeaderIsBroken, molecule::NUMBER_SIZE * 2, slice_len);
14935        }
14936        let offset_first = molecule::unpack_number(&slice[molecule::NUMBER_SIZE..]) as usize;
14937        if offset_first % molecule::NUMBER_SIZE != 0 || offset_first < molecule::NUMBER_SIZE * 2 {
14938            return ve!(Self, OffsetsNotMatch);
14939        }
14940        if slice_len < offset_first {
14941            return ve!(Self, HeaderIsBroken, offset_first, slice_len);
14942        }
14943        let field_count = offset_first / molecule::NUMBER_SIZE - 1;
14944        if field_count < Self::FIELD_COUNT {
14945            return ve!(Self, FieldCountNotMatch, Self::FIELD_COUNT, field_count);
14946        } else if !compatible && field_count > Self::FIELD_COUNT {
14947            return ve!(Self, FieldCountNotMatch, Self::FIELD_COUNT, field_count);
14948        };
14949        let mut offsets: Vec<usize> = slice[molecule::NUMBER_SIZE..offset_first]
14950            .chunks_exact(molecule::NUMBER_SIZE)
14951            .map(|x| molecule::unpack_number(x) as usize)
14952            .collect();
14953        offsets.push(total_size);
14954        if offsets.windows(2).any(|i| i[0] > i[1]) {
14955            return ve!(Self, OffsetsNotMatch);
14956        }
14957        PubkeyReader::verify(&slice[offsets[0]..offsets[1]], compatible)?;
14958        Uint128Reader::verify(&slice[offsets[1]..offsets[2]], compatible)?;
14959        ByteReader::verify(&slice[offsets[2]..offsets[3]], compatible)?;
14960        Uint128Reader::verify(&slice[offsets[3]..offsets[4]], compatible)?;
14961        Uint64Reader::verify(&slice[offsets[4]..offsets[5]], compatible)?;
14962        Uint64Reader::verify(&slice[offsets[5]..offsets[6]], compatible)?;
14963        Uint64OptReader::verify(&slice[offsets[6]..offsets[7]], compatible)?;
14964        Ok(())
14965    }
14966}
14967#[derive(Clone, Debug, Default)]
14968pub struct TrampolineForwardPayloadBuilder {
14969    pub(crate) next_node_id: Pubkey,
14970    pub(crate) amount_to_forward: Uint128,
14971    pub(crate) hash_algorithm: Byte,
14972    pub(crate) build_max_fee_amount: Uint128,
14973    pub(crate) tlc_expiry_delta: Uint64,
14974    pub(crate) tlc_expiry_limit: Uint64,
14975    pub(crate) max_parts: Uint64Opt,
14976}
14977impl TrampolineForwardPayloadBuilder {
14978    pub const FIELD_COUNT: usize = 7;
14979    pub fn next_node_id(mut self, v: Pubkey) -> Self {
14980        self.next_node_id = v;
14981        self
14982    }
14983    pub fn amount_to_forward(mut self, v: Uint128) -> Self {
14984        self.amount_to_forward = v;
14985        self
14986    }
14987    pub fn hash_algorithm(mut self, v: Byte) -> Self {
14988        self.hash_algorithm = v;
14989        self
14990    }
14991    pub fn build_max_fee_amount(mut self, v: Uint128) -> Self {
14992        self.build_max_fee_amount = v;
14993        self
14994    }
14995    pub fn tlc_expiry_delta(mut self, v: Uint64) -> Self {
14996        self.tlc_expiry_delta = v;
14997        self
14998    }
14999    pub fn tlc_expiry_limit(mut self, v: Uint64) -> Self {
15000        self.tlc_expiry_limit = v;
15001        self
15002    }
15003    pub fn max_parts(mut self, v: Uint64Opt) -> Self {
15004        self.max_parts = v;
15005        self
15006    }
15007}
15008impl molecule::prelude::Builder for TrampolineForwardPayloadBuilder {
15009    type Entity = TrampolineForwardPayload;
15010    const NAME: &'static str = "TrampolineForwardPayloadBuilder";
15011    fn expected_length(&self) -> usize {
15012        molecule::NUMBER_SIZE * (Self::FIELD_COUNT + 1)
15013            + self.next_node_id.as_slice().len()
15014            + self.amount_to_forward.as_slice().len()
15015            + self.hash_algorithm.as_slice().len()
15016            + self.build_max_fee_amount.as_slice().len()
15017            + self.tlc_expiry_delta.as_slice().len()
15018            + self.tlc_expiry_limit.as_slice().len()
15019            + self.max_parts.as_slice().len()
15020    }
15021    fn write<W: molecule::io::Write>(&self, writer: &mut W) -> molecule::io::Result<()> {
15022        let mut total_size = molecule::NUMBER_SIZE * (Self::FIELD_COUNT + 1);
15023        let mut offsets = Vec::with_capacity(Self::FIELD_COUNT);
15024        offsets.push(total_size);
15025        total_size += self.next_node_id.as_slice().len();
15026        offsets.push(total_size);
15027        total_size += self.amount_to_forward.as_slice().len();
15028        offsets.push(total_size);
15029        total_size += self.hash_algorithm.as_slice().len();
15030        offsets.push(total_size);
15031        total_size += self.build_max_fee_amount.as_slice().len();
15032        offsets.push(total_size);
15033        total_size += self.tlc_expiry_delta.as_slice().len();
15034        offsets.push(total_size);
15035        total_size += self.tlc_expiry_limit.as_slice().len();
15036        offsets.push(total_size);
15037        total_size += self.max_parts.as_slice().len();
15038        writer.write_all(&molecule::pack_number(total_size as molecule::Number))?;
15039        for offset in offsets.into_iter() {
15040            writer.write_all(&molecule::pack_number(offset as molecule::Number))?;
15041        }
15042        writer.write_all(self.next_node_id.as_slice())?;
15043        writer.write_all(self.amount_to_forward.as_slice())?;
15044        writer.write_all(self.hash_algorithm.as_slice())?;
15045        writer.write_all(self.build_max_fee_amount.as_slice())?;
15046        writer.write_all(self.tlc_expiry_delta.as_slice())?;
15047        writer.write_all(self.tlc_expiry_limit.as_slice())?;
15048        writer.write_all(self.max_parts.as_slice())?;
15049        Ok(())
15050    }
15051    fn build(&self) -> Self::Entity {
15052        let mut inner = Vec::with_capacity(self.expected_length());
15053        self.write(&mut inner)
15054            .unwrap_or_else(|_| panic!("{} build should be ok", Self::NAME));
15055        TrampolineForwardPayload::new_unchecked(inner.into())
15056    }
15057}
15058#[derive(Clone)]
15059pub struct TrampolineFinalPayload(molecule::bytes::Bytes);
15060impl ::core::fmt::LowerHex for TrampolineFinalPayload {
15061    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
15062        use molecule::hex_string;
15063        if f.alternate() {
15064            write!(f, "0x")?;
15065        }
15066        write!(f, "{}", hex_string(self.as_slice()))
15067    }
15068}
15069impl ::core::fmt::Debug for TrampolineFinalPayload {
15070    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
15071        write!(f, "{}({:#x})", Self::NAME, self)
15072    }
15073}
15074impl ::core::fmt::Display for TrampolineFinalPayload {
15075    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
15076        write!(f, "{} {{ ", Self::NAME)?;
15077        write!(f, "{}: {}", "final_amount", self.final_amount())?;
15078        write!(
15079            f,
15080            ", {}: {}",
15081            "final_tlc_expiry_delta",
15082            self.final_tlc_expiry_delta()
15083        )?;
15084        write!(f, ", {}: {}", "payment_preimage", self.payment_preimage())?;
15085        write!(f, ", {}: {}", "custom_records", self.custom_records())?;
15086        let extra_count = self.count_extra_fields();
15087        if extra_count != 0 {
15088            write!(f, ", .. ({} fields)", extra_count)?;
15089        }
15090        write!(f, " }}")
15091    }
15092}
15093impl ::core::default::Default for TrampolineFinalPayload {
15094    fn default() -> Self {
15095        let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE);
15096        TrampolineFinalPayload::new_unchecked(v)
15097    }
15098}
15099impl TrampolineFinalPayload {
15100    const DEFAULT_VALUE: [u8; 44] = [
15101        44, 0, 0, 0, 20, 0, 0, 0, 36, 0, 0, 0, 44, 0, 0, 0, 44, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
15102        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
15103    ];
15104    pub const FIELD_COUNT: usize = 4;
15105    pub fn total_size(&self) -> usize {
15106        molecule::unpack_number(self.as_slice()) as usize
15107    }
15108    pub fn field_count(&self) -> usize {
15109        if self.total_size() == molecule::NUMBER_SIZE {
15110            0
15111        } else {
15112            (molecule::unpack_number(&self.as_slice()[molecule::NUMBER_SIZE..]) as usize / 4) - 1
15113        }
15114    }
15115    pub fn count_extra_fields(&self) -> usize {
15116        self.field_count() - Self::FIELD_COUNT
15117    }
15118    pub fn has_extra_fields(&self) -> bool {
15119        Self::FIELD_COUNT != self.field_count()
15120    }
15121    pub fn final_amount(&self) -> Uint128 {
15122        let slice = self.as_slice();
15123        let start = molecule::unpack_number(&slice[4..]) as usize;
15124        let end = molecule::unpack_number(&slice[8..]) as usize;
15125        Uint128::new_unchecked(self.0.slice(start..end))
15126    }
15127    pub fn final_tlc_expiry_delta(&self) -> Uint64 {
15128        let slice = self.as_slice();
15129        let start = molecule::unpack_number(&slice[8..]) as usize;
15130        let end = molecule::unpack_number(&slice[12..]) as usize;
15131        Uint64::new_unchecked(self.0.slice(start..end))
15132    }
15133    pub fn payment_preimage(&self) -> PaymentPreimageOpt {
15134        let slice = self.as_slice();
15135        let start = molecule::unpack_number(&slice[12..]) as usize;
15136        let end = molecule::unpack_number(&slice[16..]) as usize;
15137        PaymentPreimageOpt::new_unchecked(self.0.slice(start..end))
15138    }
15139    pub fn custom_records(&self) -> CustomRecordsOpt {
15140        let slice = self.as_slice();
15141        let start = molecule::unpack_number(&slice[16..]) as usize;
15142        if self.has_extra_fields() {
15143            let end = molecule::unpack_number(&slice[20..]) as usize;
15144            CustomRecordsOpt::new_unchecked(self.0.slice(start..end))
15145        } else {
15146            CustomRecordsOpt::new_unchecked(self.0.slice(start..))
15147        }
15148    }
15149    pub fn as_reader<'r>(&'r self) -> TrampolineFinalPayloadReader<'r> {
15150        TrampolineFinalPayloadReader::new_unchecked(self.as_slice())
15151    }
15152}
15153impl molecule::prelude::Entity for TrampolineFinalPayload {
15154    type Builder = TrampolineFinalPayloadBuilder;
15155    const NAME: &'static str = "TrampolineFinalPayload";
15156    fn new_unchecked(data: molecule::bytes::Bytes) -> Self {
15157        TrampolineFinalPayload(data)
15158    }
15159    fn as_bytes(&self) -> molecule::bytes::Bytes {
15160        self.0.clone()
15161    }
15162    fn as_slice(&self) -> &[u8] {
15163        &self.0[..]
15164    }
15165    fn from_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
15166        TrampolineFinalPayloadReader::from_slice(slice).map(|reader| reader.to_entity())
15167    }
15168    fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
15169        TrampolineFinalPayloadReader::from_compatible_slice(slice).map(|reader| reader.to_entity())
15170    }
15171    fn new_builder() -> Self::Builder {
15172        ::core::default::Default::default()
15173    }
15174    fn as_builder(self) -> Self::Builder {
15175        Self::new_builder()
15176            .final_amount(self.final_amount())
15177            .final_tlc_expiry_delta(self.final_tlc_expiry_delta())
15178            .payment_preimage(self.payment_preimage())
15179            .custom_records(self.custom_records())
15180    }
15181}
15182#[derive(Clone, Copy)]
15183pub struct TrampolineFinalPayloadReader<'r>(&'r [u8]);
15184impl<'r> ::core::fmt::LowerHex for TrampolineFinalPayloadReader<'r> {
15185    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
15186        use molecule::hex_string;
15187        if f.alternate() {
15188            write!(f, "0x")?;
15189        }
15190        write!(f, "{}", hex_string(self.as_slice()))
15191    }
15192}
15193impl<'r> ::core::fmt::Debug for TrampolineFinalPayloadReader<'r> {
15194    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
15195        write!(f, "{}({:#x})", Self::NAME, self)
15196    }
15197}
15198impl<'r> ::core::fmt::Display for TrampolineFinalPayloadReader<'r> {
15199    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
15200        write!(f, "{} {{ ", Self::NAME)?;
15201        write!(f, "{}: {}", "final_amount", self.final_amount())?;
15202        write!(
15203            f,
15204            ", {}: {}",
15205            "final_tlc_expiry_delta",
15206            self.final_tlc_expiry_delta()
15207        )?;
15208        write!(f, ", {}: {}", "payment_preimage", self.payment_preimage())?;
15209        write!(f, ", {}: {}", "custom_records", self.custom_records())?;
15210        let extra_count = self.count_extra_fields();
15211        if extra_count != 0 {
15212            write!(f, ", .. ({} fields)", extra_count)?;
15213        }
15214        write!(f, " }}")
15215    }
15216}
15217impl<'r> TrampolineFinalPayloadReader<'r> {
15218    pub const FIELD_COUNT: usize = 4;
15219    pub fn total_size(&self) -> usize {
15220        molecule::unpack_number(self.as_slice()) as usize
15221    }
15222    pub fn field_count(&self) -> usize {
15223        if self.total_size() == molecule::NUMBER_SIZE {
15224            0
15225        } else {
15226            (molecule::unpack_number(&self.as_slice()[molecule::NUMBER_SIZE..]) as usize / 4) - 1
15227        }
15228    }
15229    pub fn count_extra_fields(&self) -> usize {
15230        self.field_count() - Self::FIELD_COUNT
15231    }
15232    pub fn has_extra_fields(&self) -> bool {
15233        Self::FIELD_COUNT != self.field_count()
15234    }
15235    pub fn final_amount(&self) -> Uint128Reader<'r> {
15236        let slice = self.as_slice();
15237        let start = molecule::unpack_number(&slice[4..]) as usize;
15238        let end = molecule::unpack_number(&slice[8..]) as usize;
15239        Uint128Reader::new_unchecked(&self.as_slice()[start..end])
15240    }
15241    pub fn final_tlc_expiry_delta(&self) -> Uint64Reader<'r> {
15242        let slice = self.as_slice();
15243        let start = molecule::unpack_number(&slice[8..]) as usize;
15244        let end = molecule::unpack_number(&slice[12..]) as usize;
15245        Uint64Reader::new_unchecked(&self.as_slice()[start..end])
15246    }
15247    pub fn payment_preimage(&self) -> PaymentPreimageOptReader<'r> {
15248        let slice = self.as_slice();
15249        let start = molecule::unpack_number(&slice[12..]) as usize;
15250        let end = molecule::unpack_number(&slice[16..]) as usize;
15251        PaymentPreimageOptReader::new_unchecked(&self.as_slice()[start..end])
15252    }
15253    pub fn custom_records(&self) -> CustomRecordsOptReader<'r> {
15254        let slice = self.as_slice();
15255        let start = molecule::unpack_number(&slice[16..]) as usize;
15256        if self.has_extra_fields() {
15257            let end = molecule::unpack_number(&slice[20..]) as usize;
15258            CustomRecordsOptReader::new_unchecked(&self.as_slice()[start..end])
15259        } else {
15260            CustomRecordsOptReader::new_unchecked(&self.as_slice()[start..])
15261        }
15262    }
15263}
15264impl<'r> molecule::prelude::Reader<'r> for TrampolineFinalPayloadReader<'r> {
15265    type Entity = TrampolineFinalPayload;
15266    const NAME: &'static str = "TrampolineFinalPayloadReader";
15267    fn to_entity(&self) -> Self::Entity {
15268        Self::Entity::new_unchecked(self.as_slice().to_owned().into())
15269    }
15270    fn new_unchecked(slice: &'r [u8]) -> Self {
15271        TrampolineFinalPayloadReader(slice)
15272    }
15273    fn as_slice(&self) -> &'r [u8] {
15274        self.0
15275    }
15276    fn verify(slice: &[u8], compatible: bool) -> molecule::error::VerificationResult<()> {
15277        use molecule::verification_error as ve;
15278        let slice_len = slice.len();
15279        if slice_len < molecule::NUMBER_SIZE {
15280            return ve!(Self, HeaderIsBroken, molecule::NUMBER_SIZE, slice_len);
15281        }
15282        let total_size = molecule::unpack_number(slice) as usize;
15283        if slice_len != total_size {
15284            return ve!(Self, TotalSizeNotMatch, total_size, slice_len);
15285        }
15286        if slice_len < molecule::NUMBER_SIZE * 2 {
15287            return ve!(Self, HeaderIsBroken, molecule::NUMBER_SIZE * 2, slice_len);
15288        }
15289        let offset_first = molecule::unpack_number(&slice[molecule::NUMBER_SIZE..]) as usize;
15290        if offset_first % molecule::NUMBER_SIZE != 0 || offset_first < molecule::NUMBER_SIZE * 2 {
15291            return ve!(Self, OffsetsNotMatch);
15292        }
15293        if slice_len < offset_first {
15294            return ve!(Self, HeaderIsBroken, offset_first, slice_len);
15295        }
15296        let field_count = offset_first / molecule::NUMBER_SIZE - 1;
15297        if field_count < Self::FIELD_COUNT {
15298            return ve!(Self, FieldCountNotMatch, Self::FIELD_COUNT, field_count);
15299        } else if !compatible && field_count > Self::FIELD_COUNT {
15300            return ve!(Self, FieldCountNotMatch, Self::FIELD_COUNT, field_count);
15301        };
15302        let mut offsets: Vec<usize> = slice[molecule::NUMBER_SIZE..offset_first]
15303            .chunks_exact(molecule::NUMBER_SIZE)
15304            .map(|x| molecule::unpack_number(x) as usize)
15305            .collect();
15306        offsets.push(total_size);
15307        if offsets.windows(2).any(|i| i[0] > i[1]) {
15308            return ve!(Self, OffsetsNotMatch);
15309        }
15310        Uint128Reader::verify(&slice[offsets[0]..offsets[1]], compatible)?;
15311        Uint64Reader::verify(&slice[offsets[1]..offsets[2]], compatible)?;
15312        PaymentPreimageOptReader::verify(&slice[offsets[2]..offsets[3]], compatible)?;
15313        CustomRecordsOptReader::verify(&slice[offsets[3]..offsets[4]], compatible)?;
15314        Ok(())
15315    }
15316}
15317#[derive(Clone, Debug, Default)]
15318pub struct TrampolineFinalPayloadBuilder {
15319    pub(crate) final_amount: Uint128,
15320    pub(crate) final_tlc_expiry_delta: Uint64,
15321    pub(crate) payment_preimage: PaymentPreimageOpt,
15322    pub(crate) custom_records: CustomRecordsOpt,
15323}
15324impl TrampolineFinalPayloadBuilder {
15325    pub const FIELD_COUNT: usize = 4;
15326    pub fn final_amount(mut self, v: Uint128) -> Self {
15327        self.final_amount = v;
15328        self
15329    }
15330    pub fn final_tlc_expiry_delta(mut self, v: Uint64) -> Self {
15331        self.final_tlc_expiry_delta = v;
15332        self
15333    }
15334    pub fn payment_preimage(mut self, v: PaymentPreimageOpt) -> Self {
15335        self.payment_preimage = v;
15336        self
15337    }
15338    pub fn custom_records(mut self, v: CustomRecordsOpt) -> Self {
15339        self.custom_records = v;
15340        self
15341    }
15342}
15343impl molecule::prelude::Builder for TrampolineFinalPayloadBuilder {
15344    type Entity = TrampolineFinalPayload;
15345    const NAME: &'static str = "TrampolineFinalPayloadBuilder";
15346    fn expected_length(&self) -> usize {
15347        molecule::NUMBER_SIZE * (Self::FIELD_COUNT + 1)
15348            + self.final_amount.as_slice().len()
15349            + self.final_tlc_expiry_delta.as_slice().len()
15350            + self.payment_preimage.as_slice().len()
15351            + self.custom_records.as_slice().len()
15352    }
15353    fn write<W: molecule::io::Write>(&self, writer: &mut W) -> molecule::io::Result<()> {
15354        let mut total_size = molecule::NUMBER_SIZE * (Self::FIELD_COUNT + 1);
15355        let mut offsets = Vec::with_capacity(Self::FIELD_COUNT);
15356        offsets.push(total_size);
15357        total_size += self.final_amount.as_slice().len();
15358        offsets.push(total_size);
15359        total_size += self.final_tlc_expiry_delta.as_slice().len();
15360        offsets.push(total_size);
15361        total_size += self.payment_preimage.as_slice().len();
15362        offsets.push(total_size);
15363        total_size += self.custom_records.as_slice().len();
15364        writer.write_all(&molecule::pack_number(total_size as molecule::Number))?;
15365        for offset in offsets.into_iter() {
15366            writer.write_all(&molecule::pack_number(offset as molecule::Number))?;
15367        }
15368        writer.write_all(self.final_amount.as_slice())?;
15369        writer.write_all(self.final_tlc_expiry_delta.as_slice())?;
15370        writer.write_all(self.payment_preimage.as_slice())?;
15371        writer.write_all(self.custom_records.as_slice())?;
15372        Ok(())
15373    }
15374    fn build(&self) -> Self::Entity {
15375        let mut inner = Vec::with_capacity(self.expected_length());
15376        self.write(&mut inner)
15377            .unwrap_or_else(|_| panic!("{} build should be ok", Self::NAME));
15378        TrampolineFinalPayload::new_unchecked(inner.into())
15379    }
15380}
15381#[derive(Clone)]
15382pub struct TrampolineHopPayload(molecule::bytes::Bytes);
15383impl ::core::fmt::LowerHex for TrampolineHopPayload {
15384    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
15385        use molecule::hex_string;
15386        if f.alternate() {
15387            write!(f, "0x")?;
15388        }
15389        write!(f, "{}", hex_string(self.as_slice()))
15390    }
15391}
15392impl ::core::fmt::Debug for TrampolineHopPayload {
15393    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
15394        write!(f, "{}({:#x})", Self::NAME, self)
15395    }
15396}
15397impl ::core::fmt::Display for TrampolineHopPayload {
15398    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
15399        write!(f, "{}(", Self::NAME)?;
15400        self.to_enum().display_inner(f)?;
15401        write!(f, ")")
15402    }
15403}
15404impl ::core::default::Default for TrampolineHopPayload {
15405    fn default() -> Self {
15406        let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE);
15407        TrampolineHopPayload::new_unchecked(v)
15408    }
15409}
15410impl TrampolineHopPayload {
15411    const DEFAULT_VALUE: [u8; 118] = [
15412        0, 0, 0, 0, 114, 0, 0, 0, 32, 0, 0, 0, 65, 0, 0, 0, 81, 0, 0, 0, 82, 0, 0, 0, 98, 0, 0, 0,
15413        106, 0, 0, 0, 114, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
15414        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,
15415        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,
15416        0,
15417    ];
15418    pub const ITEMS_COUNT: usize = 2;
15419    pub fn item_id(&self) -> molecule::Number {
15420        molecule::unpack_number(self.as_slice())
15421    }
15422    pub fn to_enum(&self) -> TrampolineHopPayloadUnion {
15423        let inner = self.0.slice(molecule::NUMBER_SIZE..);
15424        match self.item_id() {
15425            0 => TrampolineForwardPayload::new_unchecked(inner).into(),
15426            1 => TrampolineFinalPayload::new_unchecked(inner).into(),
15427            _ => panic!("{}: invalid data", Self::NAME),
15428        }
15429    }
15430    pub fn as_reader<'r>(&'r self) -> TrampolineHopPayloadReader<'r> {
15431        TrampolineHopPayloadReader::new_unchecked(self.as_slice())
15432    }
15433}
15434impl molecule::prelude::Entity for TrampolineHopPayload {
15435    type Builder = TrampolineHopPayloadBuilder;
15436    const NAME: &'static str = "TrampolineHopPayload";
15437    fn new_unchecked(data: molecule::bytes::Bytes) -> Self {
15438        TrampolineHopPayload(data)
15439    }
15440    fn as_bytes(&self) -> molecule::bytes::Bytes {
15441        self.0.clone()
15442    }
15443    fn as_slice(&self) -> &[u8] {
15444        &self.0[..]
15445    }
15446    fn from_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
15447        TrampolineHopPayloadReader::from_slice(slice).map(|reader| reader.to_entity())
15448    }
15449    fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
15450        TrampolineHopPayloadReader::from_compatible_slice(slice).map(|reader| reader.to_entity())
15451    }
15452    fn new_builder() -> Self::Builder {
15453        ::core::default::Default::default()
15454    }
15455    fn as_builder(self) -> Self::Builder {
15456        Self::new_builder().set(self.to_enum())
15457    }
15458}
15459#[derive(Clone, Copy)]
15460pub struct TrampolineHopPayloadReader<'r>(&'r [u8]);
15461impl<'r> ::core::fmt::LowerHex for TrampolineHopPayloadReader<'r> {
15462    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
15463        use molecule::hex_string;
15464        if f.alternate() {
15465            write!(f, "0x")?;
15466        }
15467        write!(f, "{}", hex_string(self.as_slice()))
15468    }
15469}
15470impl<'r> ::core::fmt::Debug for TrampolineHopPayloadReader<'r> {
15471    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
15472        write!(f, "{}({:#x})", Self::NAME, self)
15473    }
15474}
15475impl<'r> ::core::fmt::Display for TrampolineHopPayloadReader<'r> {
15476    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
15477        write!(f, "{}(", Self::NAME)?;
15478        self.to_enum().display_inner(f)?;
15479        write!(f, ")")
15480    }
15481}
15482impl<'r> TrampolineHopPayloadReader<'r> {
15483    pub const ITEMS_COUNT: usize = 2;
15484    pub fn item_id(&self) -> molecule::Number {
15485        molecule::unpack_number(self.as_slice())
15486    }
15487    pub fn to_enum(&self) -> TrampolineHopPayloadUnionReader<'r> {
15488        let inner = &self.as_slice()[molecule::NUMBER_SIZE..];
15489        match self.item_id() {
15490            0 => TrampolineForwardPayloadReader::new_unchecked(inner).into(),
15491            1 => TrampolineFinalPayloadReader::new_unchecked(inner).into(),
15492            _ => panic!("{}: invalid data", Self::NAME),
15493        }
15494    }
15495}
15496impl<'r> molecule::prelude::Reader<'r> for TrampolineHopPayloadReader<'r> {
15497    type Entity = TrampolineHopPayload;
15498    const NAME: &'static str = "TrampolineHopPayloadReader";
15499    fn to_entity(&self) -> Self::Entity {
15500        Self::Entity::new_unchecked(self.as_slice().to_owned().into())
15501    }
15502    fn new_unchecked(slice: &'r [u8]) -> Self {
15503        TrampolineHopPayloadReader(slice)
15504    }
15505    fn as_slice(&self) -> &'r [u8] {
15506        self.0
15507    }
15508    fn verify(slice: &[u8], compatible: bool) -> molecule::error::VerificationResult<()> {
15509        use molecule::verification_error as ve;
15510        let slice_len = slice.len();
15511        if slice_len < molecule::NUMBER_SIZE {
15512            return ve!(Self, HeaderIsBroken, molecule::NUMBER_SIZE, slice_len);
15513        }
15514        let item_id = molecule::unpack_number(slice);
15515        let inner_slice = &slice[molecule::NUMBER_SIZE..];
15516        match item_id {
15517            0 => TrampolineForwardPayloadReader::verify(inner_slice, compatible),
15518            1 => TrampolineFinalPayloadReader::verify(inner_slice, compatible),
15519            _ => ve!(Self, UnknownItem, Self::ITEMS_COUNT, item_id),
15520        }?;
15521        Ok(())
15522    }
15523}
15524#[derive(Clone, Debug, Default)]
15525pub struct TrampolineHopPayloadBuilder(pub(crate) TrampolineHopPayloadUnion);
15526impl TrampolineHopPayloadBuilder {
15527    pub const ITEMS_COUNT: usize = 2;
15528    pub fn set<I>(mut self, v: I) -> Self
15529    where
15530        I: ::core::convert::Into<TrampolineHopPayloadUnion>,
15531    {
15532        self.0 = v.into();
15533        self
15534    }
15535}
15536impl molecule::prelude::Builder for TrampolineHopPayloadBuilder {
15537    type Entity = TrampolineHopPayload;
15538    const NAME: &'static str = "TrampolineHopPayloadBuilder";
15539    fn expected_length(&self) -> usize {
15540        molecule::NUMBER_SIZE + self.0.as_slice().len()
15541    }
15542    fn write<W: molecule::io::Write>(&self, writer: &mut W) -> molecule::io::Result<()> {
15543        writer.write_all(&molecule::pack_number(self.0.item_id()))?;
15544        writer.write_all(self.0.as_slice())
15545    }
15546    fn build(&self) -> Self::Entity {
15547        let mut inner = Vec::with_capacity(self.expected_length());
15548        self.write(&mut inner)
15549            .unwrap_or_else(|_| panic!("{} build should be ok", Self::NAME));
15550        TrampolineHopPayload::new_unchecked(inner.into())
15551    }
15552}
15553#[derive(Debug, Clone)]
15554pub enum TrampolineHopPayloadUnion {
15555    TrampolineForwardPayload(TrampolineForwardPayload),
15556    TrampolineFinalPayload(TrampolineFinalPayload),
15557}
15558#[derive(Debug, Clone, Copy)]
15559pub enum TrampolineHopPayloadUnionReader<'r> {
15560    TrampolineForwardPayload(TrampolineForwardPayloadReader<'r>),
15561    TrampolineFinalPayload(TrampolineFinalPayloadReader<'r>),
15562}
15563impl ::core::default::Default for TrampolineHopPayloadUnion {
15564    fn default() -> Self {
15565        TrampolineHopPayloadUnion::TrampolineForwardPayload(::core::default::Default::default())
15566    }
15567}
15568impl ::core::fmt::Display for TrampolineHopPayloadUnion {
15569    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
15570        match self {
15571            TrampolineHopPayloadUnion::TrampolineForwardPayload(ref item) => {
15572                write!(
15573                    f,
15574                    "{}::{}({})",
15575                    Self::NAME,
15576                    TrampolineForwardPayload::NAME,
15577                    item
15578                )
15579            }
15580            TrampolineHopPayloadUnion::TrampolineFinalPayload(ref item) => {
15581                write!(
15582                    f,
15583                    "{}::{}({})",
15584                    Self::NAME,
15585                    TrampolineFinalPayload::NAME,
15586                    item
15587                )
15588            }
15589        }
15590    }
15591}
15592impl<'r> ::core::fmt::Display for TrampolineHopPayloadUnionReader<'r> {
15593    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
15594        match self {
15595            TrampolineHopPayloadUnionReader::TrampolineForwardPayload(ref item) => {
15596                write!(
15597                    f,
15598                    "{}::{}({})",
15599                    Self::NAME,
15600                    TrampolineForwardPayload::NAME,
15601                    item
15602                )
15603            }
15604            TrampolineHopPayloadUnionReader::TrampolineFinalPayload(ref item) => {
15605                write!(
15606                    f,
15607                    "{}::{}({})",
15608                    Self::NAME,
15609                    TrampolineFinalPayload::NAME,
15610                    item
15611                )
15612            }
15613        }
15614    }
15615}
15616impl TrampolineHopPayloadUnion {
15617    pub(crate) fn display_inner(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
15618        match self {
15619            TrampolineHopPayloadUnion::TrampolineForwardPayload(ref item) => write!(f, "{}", item),
15620            TrampolineHopPayloadUnion::TrampolineFinalPayload(ref item) => write!(f, "{}", item),
15621        }
15622    }
15623}
15624impl<'r> TrampolineHopPayloadUnionReader<'r> {
15625    pub(crate) fn display_inner(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
15626        match self {
15627            TrampolineHopPayloadUnionReader::TrampolineForwardPayload(ref item) => {
15628                write!(f, "{}", item)
15629            }
15630            TrampolineHopPayloadUnionReader::TrampolineFinalPayload(ref item) => {
15631                write!(f, "{}", item)
15632            }
15633        }
15634    }
15635}
15636impl ::core::convert::From<TrampolineForwardPayload> for TrampolineHopPayloadUnion {
15637    fn from(item: TrampolineForwardPayload) -> Self {
15638        TrampolineHopPayloadUnion::TrampolineForwardPayload(item)
15639    }
15640}
15641impl ::core::convert::From<TrampolineFinalPayload> for TrampolineHopPayloadUnion {
15642    fn from(item: TrampolineFinalPayload) -> Self {
15643        TrampolineHopPayloadUnion::TrampolineFinalPayload(item)
15644    }
15645}
15646impl<'r> ::core::convert::From<TrampolineForwardPayloadReader<'r>>
15647    for TrampolineHopPayloadUnionReader<'r>
15648{
15649    fn from(item: TrampolineForwardPayloadReader<'r>) -> Self {
15650        TrampolineHopPayloadUnionReader::TrampolineForwardPayload(item)
15651    }
15652}
15653impl<'r> ::core::convert::From<TrampolineFinalPayloadReader<'r>>
15654    for TrampolineHopPayloadUnionReader<'r>
15655{
15656    fn from(item: TrampolineFinalPayloadReader<'r>) -> Self {
15657        TrampolineHopPayloadUnionReader::TrampolineFinalPayload(item)
15658    }
15659}
15660impl TrampolineHopPayloadUnion {
15661    pub const NAME: &'static str = "TrampolineHopPayloadUnion";
15662    pub fn as_bytes(&self) -> molecule::bytes::Bytes {
15663        match self {
15664            TrampolineHopPayloadUnion::TrampolineForwardPayload(item) => item.as_bytes(),
15665            TrampolineHopPayloadUnion::TrampolineFinalPayload(item) => item.as_bytes(),
15666        }
15667    }
15668    pub fn as_slice(&self) -> &[u8] {
15669        match self {
15670            TrampolineHopPayloadUnion::TrampolineForwardPayload(item) => item.as_slice(),
15671            TrampolineHopPayloadUnion::TrampolineFinalPayload(item) => item.as_slice(),
15672        }
15673    }
15674    pub fn item_id(&self) -> molecule::Number {
15675        match self {
15676            TrampolineHopPayloadUnion::TrampolineForwardPayload(_) => 0,
15677            TrampolineHopPayloadUnion::TrampolineFinalPayload(_) => 1,
15678        }
15679    }
15680    pub fn item_name(&self) -> &str {
15681        match self {
15682            TrampolineHopPayloadUnion::TrampolineForwardPayload(_) => "TrampolineForwardPayload",
15683            TrampolineHopPayloadUnion::TrampolineFinalPayload(_) => "TrampolineFinalPayload",
15684        }
15685    }
15686    pub fn as_reader<'r>(&'r self) -> TrampolineHopPayloadUnionReader<'r> {
15687        match self {
15688            TrampolineHopPayloadUnion::TrampolineForwardPayload(item) => item.as_reader().into(),
15689            TrampolineHopPayloadUnion::TrampolineFinalPayload(item) => item.as_reader().into(),
15690        }
15691    }
15692}
15693impl<'r> TrampolineHopPayloadUnionReader<'r> {
15694    pub const NAME: &'r str = "TrampolineHopPayloadUnionReader";
15695    pub fn as_slice(&self) -> &'r [u8] {
15696        match self {
15697            TrampolineHopPayloadUnionReader::TrampolineForwardPayload(item) => item.as_slice(),
15698            TrampolineHopPayloadUnionReader::TrampolineFinalPayload(item) => item.as_slice(),
15699        }
15700    }
15701    pub fn item_id(&self) -> molecule::Number {
15702        match self {
15703            TrampolineHopPayloadUnionReader::TrampolineForwardPayload(_) => 0,
15704            TrampolineHopPayloadUnionReader::TrampolineFinalPayload(_) => 1,
15705        }
15706    }
15707    pub fn item_name(&self) -> &str {
15708        match self {
15709            TrampolineHopPayloadUnionReader::TrampolineForwardPayload(_) => {
15710                "TrampolineForwardPayload"
15711            }
15712            TrampolineHopPayloadUnionReader::TrampolineFinalPayload(_) => "TrampolineFinalPayload",
15713        }
15714    }
15715}
15716impl From<TrampolineForwardPayload> for TrampolineHopPayload {
15717    fn from(value: TrampolineForwardPayload) -> Self {
15718        Self::new_builder().set(value).build()
15719    }
15720}
15721impl From<TrampolineFinalPayload> for TrampolineHopPayload {
15722    fn from(value: TrampolineFinalPayload) -> Self {
15723        Self::new_builder().set(value).build()
15724    }
15725}
15726#[derive(Clone)]
15727pub struct ChannelUpdate(molecule::bytes::Bytes);
15728impl ::core::fmt::LowerHex for ChannelUpdate {
15729    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
15730        use molecule::hex_string;
15731        if f.alternate() {
15732            write!(f, "0x")?;
15733        }
15734        write!(f, "{}", hex_string(self.as_slice()))
15735    }
15736}
15737impl ::core::fmt::Debug for ChannelUpdate {
15738    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
15739        write!(f, "{}({:#x})", Self::NAME, self)
15740    }
15741}
15742impl ::core::fmt::Display for ChannelUpdate {
15743    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
15744        write!(f, "{} {{ ", Self::NAME)?;
15745        write!(f, "{}: {}", "signature", self.signature())?;
15746        write!(f, ", {}: {}", "chain_hash", self.chain_hash())?;
15747        write!(f, ", {}: {}", "channel_outpoint", self.channel_outpoint())?;
15748        write!(f, ", {}: {}", "timestamp", self.timestamp())?;
15749        write!(f, ", {}: {}", "message_flags", self.message_flags())?;
15750        write!(f, ", {}: {}", "channel_flags", self.channel_flags())?;
15751        write!(f, ", {}: {}", "tlc_expiry_delta", self.tlc_expiry_delta())?;
15752        write!(f, ", {}: {}", "tlc_minimum_value", self.tlc_minimum_value())?;
15753        write!(f, ", {}: {}", "tlc_maximum_value", self.tlc_maximum_value())?;
15754        write!(
15755            f,
15756            ", {}: {}",
15757            "tlc_fee_proportional_millionths",
15758            self.tlc_fee_proportional_millionths()
15759        )?;
15760        write!(f, " }}")
15761    }
15762}
15763impl ::core::default::Default for ChannelUpdate {
15764    fn default() -> Self {
15765        let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE);
15766        ChannelUpdate::new_unchecked(v)
15767    }
15768}
15769impl ChannelUpdate {
15770    const DEFAULT_VALUE: [u8; 204] = [
15771        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,
15772        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,
15773        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,
15774        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,
15775        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,
15776        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,
15777        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
15778    ];
15779    pub const TOTAL_SIZE: usize = 204;
15780    pub const FIELD_SIZES: [usize; 10] = [64, 32, 36, 8, 4, 4, 8, 16, 16, 16];
15781    pub const FIELD_COUNT: usize = 10;
15782    pub fn signature(&self) -> EcdsaSignature {
15783        EcdsaSignature::new_unchecked(self.0.slice(0..64))
15784    }
15785    pub fn chain_hash(&self) -> Byte32 {
15786        Byte32::new_unchecked(self.0.slice(64..96))
15787    }
15788    pub fn channel_outpoint(&self) -> OutPoint {
15789        OutPoint::new_unchecked(self.0.slice(96..132))
15790    }
15791    pub fn timestamp(&self) -> Uint64 {
15792        Uint64::new_unchecked(self.0.slice(132..140))
15793    }
15794    pub fn message_flags(&self) -> Uint32 {
15795        Uint32::new_unchecked(self.0.slice(140..144))
15796    }
15797    pub fn channel_flags(&self) -> Uint32 {
15798        Uint32::new_unchecked(self.0.slice(144..148))
15799    }
15800    pub fn tlc_expiry_delta(&self) -> Uint64 {
15801        Uint64::new_unchecked(self.0.slice(148..156))
15802    }
15803    pub fn tlc_minimum_value(&self) -> Uint128 {
15804        Uint128::new_unchecked(self.0.slice(156..172))
15805    }
15806    pub fn tlc_maximum_value(&self) -> Uint128 {
15807        Uint128::new_unchecked(self.0.slice(172..188))
15808    }
15809    pub fn tlc_fee_proportional_millionths(&self) -> Uint128 {
15810        Uint128::new_unchecked(self.0.slice(188..204))
15811    }
15812    pub fn as_reader<'r>(&'r self) -> ChannelUpdateReader<'r> {
15813        ChannelUpdateReader::new_unchecked(self.as_slice())
15814    }
15815}
15816impl molecule::prelude::Entity for ChannelUpdate {
15817    type Builder = ChannelUpdateBuilder;
15818    const NAME: &'static str = "ChannelUpdate";
15819    fn new_unchecked(data: molecule::bytes::Bytes) -> Self {
15820        ChannelUpdate(data)
15821    }
15822    fn as_bytes(&self) -> molecule::bytes::Bytes {
15823        self.0.clone()
15824    }
15825    fn as_slice(&self) -> &[u8] {
15826        &self.0[..]
15827    }
15828    fn from_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
15829        ChannelUpdateReader::from_slice(slice).map(|reader| reader.to_entity())
15830    }
15831    fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
15832        ChannelUpdateReader::from_compatible_slice(slice).map(|reader| reader.to_entity())
15833    }
15834    fn new_builder() -> Self::Builder {
15835        ::core::default::Default::default()
15836    }
15837    fn as_builder(self) -> Self::Builder {
15838        Self::new_builder()
15839            .signature(self.signature())
15840            .chain_hash(self.chain_hash())
15841            .channel_outpoint(self.channel_outpoint())
15842            .timestamp(self.timestamp())
15843            .message_flags(self.message_flags())
15844            .channel_flags(self.channel_flags())
15845            .tlc_expiry_delta(self.tlc_expiry_delta())
15846            .tlc_minimum_value(self.tlc_minimum_value())
15847            .tlc_maximum_value(self.tlc_maximum_value())
15848            .tlc_fee_proportional_millionths(self.tlc_fee_proportional_millionths())
15849    }
15850}
15851#[derive(Clone, Copy)]
15852pub struct ChannelUpdateReader<'r>(&'r [u8]);
15853impl<'r> ::core::fmt::LowerHex for ChannelUpdateReader<'r> {
15854    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
15855        use molecule::hex_string;
15856        if f.alternate() {
15857            write!(f, "0x")?;
15858        }
15859        write!(f, "{}", hex_string(self.as_slice()))
15860    }
15861}
15862impl<'r> ::core::fmt::Debug for ChannelUpdateReader<'r> {
15863    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
15864        write!(f, "{}({:#x})", Self::NAME, self)
15865    }
15866}
15867impl<'r> ::core::fmt::Display for ChannelUpdateReader<'r> {
15868    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
15869        write!(f, "{} {{ ", Self::NAME)?;
15870        write!(f, "{}: {}", "signature", self.signature())?;
15871        write!(f, ", {}: {}", "chain_hash", self.chain_hash())?;
15872        write!(f, ", {}: {}", "channel_outpoint", self.channel_outpoint())?;
15873        write!(f, ", {}: {}", "timestamp", self.timestamp())?;
15874        write!(f, ", {}: {}", "message_flags", self.message_flags())?;
15875        write!(f, ", {}: {}", "channel_flags", self.channel_flags())?;
15876        write!(f, ", {}: {}", "tlc_expiry_delta", self.tlc_expiry_delta())?;
15877        write!(f, ", {}: {}", "tlc_minimum_value", self.tlc_minimum_value())?;
15878        write!(f, ", {}: {}", "tlc_maximum_value", self.tlc_maximum_value())?;
15879        write!(
15880            f,
15881            ", {}: {}",
15882            "tlc_fee_proportional_millionths",
15883            self.tlc_fee_proportional_millionths()
15884        )?;
15885        write!(f, " }}")
15886    }
15887}
15888impl<'r> ChannelUpdateReader<'r> {
15889    pub const TOTAL_SIZE: usize = 204;
15890    pub const FIELD_SIZES: [usize; 10] = [64, 32, 36, 8, 4, 4, 8, 16, 16, 16];
15891    pub const FIELD_COUNT: usize = 10;
15892    pub fn signature(&self) -> EcdsaSignatureReader<'r> {
15893        EcdsaSignatureReader::new_unchecked(&self.as_slice()[0..64])
15894    }
15895    pub fn chain_hash(&self) -> Byte32Reader<'r> {
15896        Byte32Reader::new_unchecked(&self.as_slice()[64..96])
15897    }
15898    pub fn channel_outpoint(&self) -> OutPointReader<'r> {
15899        OutPointReader::new_unchecked(&self.as_slice()[96..132])
15900    }
15901    pub fn timestamp(&self) -> Uint64Reader<'r> {
15902        Uint64Reader::new_unchecked(&self.as_slice()[132..140])
15903    }
15904    pub fn message_flags(&self) -> Uint32Reader<'r> {
15905        Uint32Reader::new_unchecked(&self.as_slice()[140..144])
15906    }
15907    pub fn channel_flags(&self) -> Uint32Reader<'r> {
15908        Uint32Reader::new_unchecked(&self.as_slice()[144..148])
15909    }
15910    pub fn tlc_expiry_delta(&self) -> Uint64Reader<'r> {
15911        Uint64Reader::new_unchecked(&self.as_slice()[148..156])
15912    }
15913    pub fn tlc_minimum_value(&self) -> Uint128Reader<'r> {
15914        Uint128Reader::new_unchecked(&self.as_slice()[156..172])
15915    }
15916    pub fn tlc_maximum_value(&self) -> Uint128Reader<'r> {
15917        Uint128Reader::new_unchecked(&self.as_slice()[172..188])
15918    }
15919    pub fn tlc_fee_proportional_millionths(&self) -> Uint128Reader<'r> {
15920        Uint128Reader::new_unchecked(&self.as_slice()[188..204])
15921    }
15922}
15923impl<'r> molecule::prelude::Reader<'r> for ChannelUpdateReader<'r> {
15924    type Entity = ChannelUpdate;
15925    const NAME: &'static str = "ChannelUpdateReader";
15926    fn to_entity(&self) -> Self::Entity {
15927        Self::Entity::new_unchecked(self.as_slice().to_owned().into())
15928    }
15929    fn new_unchecked(slice: &'r [u8]) -> Self {
15930        ChannelUpdateReader(slice)
15931    }
15932    fn as_slice(&self) -> &'r [u8] {
15933        self.0
15934    }
15935    fn verify(slice: &[u8], _compatible: bool) -> molecule::error::VerificationResult<()> {
15936        use molecule::verification_error as ve;
15937        let slice_len = slice.len();
15938        if slice_len != Self::TOTAL_SIZE {
15939            return ve!(Self, TotalSizeNotMatch, Self::TOTAL_SIZE, slice_len);
15940        }
15941        Ok(())
15942    }
15943}
15944#[derive(Clone, Debug, Default)]
15945pub struct ChannelUpdateBuilder {
15946    pub(crate) signature: EcdsaSignature,
15947    pub(crate) chain_hash: Byte32,
15948    pub(crate) channel_outpoint: OutPoint,
15949    pub(crate) timestamp: Uint64,
15950    pub(crate) message_flags: Uint32,
15951    pub(crate) channel_flags: Uint32,
15952    pub(crate) tlc_expiry_delta: Uint64,
15953    pub(crate) tlc_minimum_value: Uint128,
15954    pub(crate) tlc_maximum_value: Uint128,
15955    pub(crate) tlc_fee_proportional_millionths: Uint128,
15956}
15957impl ChannelUpdateBuilder {
15958    pub const TOTAL_SIZE: usize = 204;
15959    pub const FIELD_SIZES: [usize; 10] = [64, 32, 36, 8, 4, 4, 8, 16, 16, 16];
15960    pub const FIELD_COUNT: usize = 10;
15961    pub fn signature(mut self, v: EcdsaSignature) -> Self {
15962        self.signature = v;
15963        self
15964    }
15965    pub fn chain_hash(mut self, v: Byte32) -> Self {
15966        self.chain_hash = v;
15967        self
15968    }
15969    pub fn channel_outpoint(mut self, v: OutPoint) -> Self {
15970        self.channel_outpoint = v;
15971        self
15972    }
15973    pub fn timestamp(mut self, v: Uint64) -> Self {
15974        self.timestamp = v;
15975        self
15976    }
15977    pub fn message_flags(mut self, v: Uint32) -> Self {
15978        self.message_flags = v;
15979        self
15980    }
15981    pub fn channel_flags(mut self, v: Uint32) -> Self {
15982        self.channel_flags = v;
15983        self
15984    }
15985    pub fn tlc_expiry_delta(mut self, v: Uint64) -> Self {
15986        self.tlc_expiry_delta = v;
15987        self
15988    }
15989    pub fn tlc_minimum_value(mut self, v: Uint128) -> Self {
15990        self.tlc_minimum_value = v;
15991        self
15992    }
15993    pub fn tlc_maximum_value(mut self, v: Uint128) -> Self {
15994        self.tlc_maximum_value = v;
15995        self
15996    }
15997    pub fn tlc_fee_proportional_millionths(mut self, v: Uint128) -> Self {
15998        self.tlc_fee_proportional_millionths = v;
15999        self
16000    }
16001}
16002impl molecule::prelude::Builder for ChannelUpdateBuilder {
16003    type Entity = ChannelUpdate;
16004    const NAME: &'static str = "ChannelUpdateBuilder";
16005    fn expected_length(&self) -> usize {
16006        Self::TOTAL_SIZE
16007    }
16008    fn write<W: molecule::io::Write>(&self, writer: &mut W) -> molecule::io::Result<()> {
16009        writer.write_all(self.signature.as_slice())?;
16010        writer.write_all(self.chain_hash.as_slice())?;
16011        writer.write_all(self.channel_outpoint.as_slice())?;
16012        writer.write_all(self.timestamp.as_slice())?;
16013        writer.write_all(self.message_flags.as_slice())?;
16014        writer.write_all(self.channel_flags.as_slice())?;
16015        writer.write_all(self.tlc_expiry_delta.as_slice())?;
16016        writer.write_all(self.tlc_minimum_value.as_slice())?;
16017        writer.write_all(self.tlc_maximum_value.as_slice())?;
16018        writer.write_all(self.tlc_fee_proportional_millionths.as_slice())?;
16019        Ok(())
16020    }
16021    fn build(&self) -> Self::Entity {
16022        let mut inner = Vec::with_capacity(self.expected_length());
16023        self.write(&mut inner)
16024            .unwrap_or_else(|_| panic!("{} build should be ok", Self::NAME));
16025        ChannelUpdate::new_unchecked(inner.into())
16026    }
16027}
16028#[derive(Clone)]
16029pub struct ChannelUpdateOpt(molecule::bytes::Bytes);
16030impl ::core::fmt::LowerHex for ChannelUpdateOpt {
16031    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
16032        use molecule::hex_string;
16033        if f.alternate() {
16034            write!(f, "0x")?;
16035        }
16036        write!(f, "{}", hex_string(self.as_slice()))
16037    }
16038}
16039impl ::core::fmt::Debug for ChannelUpdateOpt {
16040    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
16041        write!(f, "{}({:#x})", Self::NAME, self)
16042    }
16043}
16044impl ::core::fmt::Display for ChannelUpdateOpt {
16045    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
16046        if let Some(v) = self.to_opt() {
16047            write!(f, "{}(Some({}))", Self::NAME, v)
16048        } else {
16049            write!(f, "{}(None)", Self::NAME)
16050        }
16051    }
16052}
16053impl ::core::default::Default for ChannelUpdateOpt {
16054    fn default() -> Self {
16055        let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE);
16056        ChannelUpdateOpt::new_unchecked(v)
16057    }
16058}
16059impl ChannelUpdateOpt {
16060    const DEFAULT_VALUE: [u8; 0] = [];
16061    pub fn is_none(&self) -> bool {
16062        self.0.is_empty()
16063    }
16064    pub fn is_some(&self) -> bool {
16065        !self.0.is_empty()
16066    }
16067    pub fn to_opt(&self) -> Option<ChannelUpdate> {
16068        if self.is_none() {
16069            None
16070        } else {
16071            Some(ChannelUpdate::new_unchecked(self.0.clone()))
16072        }
16073    }
16074    pub fn as_reader<'r>(&'r self) -> ChannelUpdateOptReader<'r> {
16075        ChannelUpdateOptReader::new_unchecked(self.as_slice())
16076    }
16077}
16078impl molecule::prelude::Entity for ChannelUpdateOpt {
16079    type Builder = ChannelUpdateOptBuilder;
16080    const NAME: &'static str = "ChannelUpdateOpt";
16081    fn new_unchecked(data: molecule::bytes::Bytes) -> Self {
16082        ChannelUpdateOpt(data)
16083    }
16084    fn as_bytes(&self) -> molecule::bytes::Bytes {
16085        self.0.clone()
16086    }
16087    fn as_slice(&self) -> &[u8] {
16088        &self.0[..]
16089    }
16090    fn from_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
16091        ChannelUpdateOptReader::from_slice(slice).map(|reader| reader.to_entity())
16092    }
16093    fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
16094        ChannelUpdateOptReader::from_compatible_slice(slice).map(|reader| reader.to_entity())
16095    }
16096    fn new_builder() -> Self::Builder {
16097        ::core::default::Default::default()
16098    }
16099    fn as_builder(self) -> Self::Builder {
16100        Self::new_builder().set(self.to_opt())
16101    }
16102}
16103#[derive(Clone, Copy)]
16104pub struct ChannelUpdateOptReader<'r>(&'r [u8]);
16105impl<'r> ::core::fmt::LowerHex for ChannelUpdateOptReader<'r> {
16106    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
16107        use molecule::hex_string;
16108        if f.alternate() {
16109            write!(f, "0x")?;
16110        }
16111        write!(f, "{}", hex_string(self.as_slice()))
16112    }
16113}
16114impl<'r> ::core::fmt::Debug for ChannelUpdateOptReader<'r> {
16115    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
16116        write!(f, "{}({:#x})", Self::NAME, self)
16117    }
16118}
16119impl<'r> ::core::fmt::Display for ChannelUpdateOptReader<'r> {
16120    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
16121        if let Some(v) = self.to_opt() {
16122            write!(f, "{}(Some({}))", Self::NAME, v)
16123        } else {
16124            write!(f, "{}(None)", Self::NAME)
16125        }
16126    }
16127}
16128impl<'r> ChannelUpdateOptReader<'r> {
16129    pub fn is_none(&self) -> bool {
16130        self.0.is_empty()
16131    }
16132    pub fn is_some(&self) -> bool {
16133        !self.0.is_empty()
16134    }
16135    pub fn to_opt(&self) -> Option<ChannelUpdateReader<'r>> {
16136        if self.is_none() {
16137            None
16138        } else {
16139            Some(ChannelUpdateReader::new_unchecked(self.as_slice()))
16140        }
16141    }
16142}
16143impl<'r> molecule::prelude::Reader<'r> for ChannelUpdateOptReader<'r> {
16144    type Entity = ChannelUpdateOpt;
16145    const NAME: &'static str = "ChannelUpdateOptReader";
16146    fn to_entity(&self) -> Self::Entity {
16147        Self::Entity::new_unchecked(self.as_slice().to_owned().into())
16148    }
16149    fn new_unchecked(slice: &'r [u8]) -> Self {
16150        ChannelUpdateOptReader(slice)
16151    }
16152    fn as_slice(&self) -> &'r [u8] {
16153        self.0
16154    }
16155    fn verify(slice: &[u8], compatible: bool) -> molecule::error::VerificationResult<()> {
16156        if !slice.is_empty() {
16157            ChannelUpdateReader::verify(&slice[..], compatible)?;
16158        }
16159        Ok(())
16160    }
16161}
16162#[derive(Clone, Debug, Default)]
16163pub struct ChannelUpdateOptBuilder(pub(crate) Option<ChannelUpdate>);
16164impl ChannelUpdateOptBuilder {
16165    pub fn set(mut self, v: Option<ChannelUpdate>) -> Self {
16166        self.0 = v;
16167        self
16168    }
16169}
16170impl molecule::prelude::Builder for ChannelUpdateOptBuilder {
16171    type Entity = ChannelUpdateOpt;
16172    const NAME: &'static str = "ChannelUpdateOptBuilder";
16173    fn expected_length(&self) -> usize {
16174        self.0
16175            .as_ref()
16176            .map(|ref inner| inner.as_slice().len())
16177            .unwrap_or(0)
16178    }
16179    fn write<W: molecule::io::Write>(&self, writer: &mut W) -> molecule::io::Result<()> {
16180        self.0
16181            .as_ref()
16182            .map(|ref inner| writer.write_all(inner.as_slice()))
16183            .unwrap_or(Ok(()))
16184    }
16185    fn build(&self) -> Self::Entity {
16186        let mut inner = Vec::with_capacity(self.expected_length());
16187        self.write(&mut inner)
16188            .unwrap_or_else(|_| panic!("{} build should be ok", Self::NAME));
16189        ChannelUpdateOpt::new_unchecked(inner.into())
16190    }
16191}
16192impl From<ChannelUpdate> for ChannelUpdateOpt {
16193    fn from(value: ChannelUpdate) -> Self {
16194        Self::new_builder().set(Some(value)).build()
16195    }
16196}
16197#[derive(Clone)]
16198pub struct ChannelFailed(molecule::bytes::Bytes);
16199impl ::core::fmt::LowerHex for ChannelFailed {
16200    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
16201        use molecule::hex_string;
16202        if f.alternate() {
16203            write!(f, "0x")?;
16204        }
16205        write!(f, "{}", hex_string(self.as_slice()))
16206    }
16207}
16208impl ::core::fmt::Debug for ChannelFailed {
16209    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
16210        write!(f, "{}({:#x})", Self::NAME, self)
16211    }
16212}
16213impl ::core::fmt::Display for ChannelFailed {
16214    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
16215        write!(f, "{} {{ ", Self::NAME)?;
16216        write!(f, "{}: {}", "channel_outpoint", self.channel_outpoint())?;
16217        write!(f, ", {}: {}", "channel_update", self.channel_update())?;
16218        write!(f, ", {}: {}", "node_id", self.node_id())?;
16219        let extra_count = self.count_extra_fields();
16220        if extra_count != 0 {
16221            write!(f, ", .. ({} fields)", extra_count)?;
16222        }
16223        write!(f, " }}")
16224    }
16225}
16226impl ::core::default::Default for ChannelFailed {
16227    fn default() -> Self {
16228        let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE);
16229        ChannelFailed::new_unchecked(v)
16230    }
16231}
16232impl ChannelFailed {
16233    const DEFAULT_VALUE: [u8; 85] = [
16234        85, 0, 0, 0, 16, 0, 0, 0, 52, 0, 0, 0, 52, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
16235        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,
16236        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,
16237    ];
16238    pub const FIELD_COUNT: usize = 3;
16239    pub fn total_size(&self) -> usize {
16240        molecule::unpack_number(self.as_slice()) as usize
16241    }
16242    pub fn field_count(&self) -> usize {
16243        if self.total_size() == molecule::NUMBER_SIZE {
16244            0
16245        } else {
16246            (molecule::unpack_number(&self.as_slice()[molecule::NUMBER_SIZE..]) as usize / 4) - 1
16247        }
16248    }
16249    pub fn count_extra_fields(&self) -> usize {
16250        self.field_count() - Self::FIELD_COUNT
16251    }
16252    pub fn has_extra_fields(&self) -> bool {
16253        Self::FIELD_COUNT != self.field_count()
16254    }
16255    pub fn channel_outpoint(&self) -> OutPoint {
16256        let slice = self.as_slice();
16257        let start = molecule::unpack_number(&slice[4..]) as usize;
16258        let end = molecule::unpack_number(&slice[8..]) as usize;
16259        OutPoint::new_unchecked(self.0.slice(start..end))
16260    }
16261    pub fn channel_update(&self) -> ChannelUpdateOpt {
16262        let slice = self.as_slice();
16263        let start = molecule::unpack_number(&slice[8..]) as usize;
16264        let end = molecule::unpack_number(&slice[12..]) as usize;
16265        ChannelUpdateOpt::new_unchecked(self.0.slice(start..end))
16266    }
16267    pub fn node_id(&self) -> Pubkey {
16268        let slice = self.as_slice();
16269        let start = molecule::unpack_number(&slice[12..]) as usize;
16270        if self.has_extra_fields() {
16271            let end = molecule::unpack_number(&slice[16..]) as usize;
16272            Pubkey::new_unchecked(self.0.slice(start..end))
16273        } else {
16274            Pubkey::new_unchecked(self.0.slice(start..))
16275        }
16276    }
16277    pub fn as_reader<'r>(&'r self) -> ChannelFailedReader<'r> {
16278        ChannelFailedReader::new_unchecked(self.as_slice())
16279    }
16280}
16281impl molecule::prelude::Entity for ChannelFailed {
16282    type Builder = ChannelFailedBuilder;
16283    const NAME: &'static str = "ChannelFailed";
16284    fn new_unchecked(data: molecule::bytes::Bytes) -> Self {
16285        ChannelFailed(data)
16286    }
16287    fn as_bytes(&self) -> molecule::bytes::Bytes {
16288        self.0.clone()
16289    }
16290    fn as_slice(&self) -> &[u8] {
16291        &self.0[..]
16292    }
16293    fn from_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
16294        ChannelFailedReader::from_slice(slice).map(|reader| reader.to_entity())
16295    }
16296    fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
16297        ChannelFailedReader::from_compatible_slice(slice).map(|reader| reader.to_entity())
16298    }
16299    fn new_builder() -> Self::Builder {
16300        ::core::default::Default::default()
16301    }
16302    fn as_builder(self) -> Self::Builder {
16303        Self::new_builder()
16304            .channel_outpoint(self.channel_outpoint())
16305            .channel_update(self.channel_update())
16306            .node_id(self.node_id())
16307    }
16308}
16309#[derive(Clone, Copy)]
16310pub struct ChannelFailedReader<'r>(&'r [u8]);
16311impl<'r> ::core::fmt::LowerHex for ChannelFailedReader<'r> {
16312    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
16313        use molecule::hex_string;
16314        if f.alternate() {
16315            write!(f, "0x")?;
16316        }
16317        write!(f, "{}", hex_string(self.as_slice()))
16318    }
16319}
16320impl<'r> ::core::fmt::Debug for ChannelFailedReader<'r> {
16321    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
16322        write!(f, "{}({:#x})", Self::NAME, self)
16323    }
16324}
16325impl<'r> ::core::fmt::Display for ChannelFailedReader<'r> {
16326    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
16327        write!(f, "{} {{ ", Self::NAME)?;
16328        write!(f, "{}: {}", "channel_outpoint", self.channel_outpoint())?;
16329        write!(f, ", {}: {}", "channel_update", self.channel_update())?;
16330        write!(f, ", {}: {}", "node_id", self.node_id())?;
16331        let extra_count = self.count_extra_fields();
16332        if extra_count != 0 {
16333            write!(f, ", .. ({} fields)", extra_count)?;
16334        }
16335        write!(f, " }}")
16336    }
16337}
16338impl<'r> ChannelFailedReader<'r> {
16339    pub const FIELD_COUNT: usize = 3;
16340    pub fn total_size(&self) -> usize {
16341        molecule::unpack_number(self.as_slice()) as usize
16342    }
16343    pub fn field_count(&self) -> usize {
16344        if self.total_size() == molecule::NUMBER_SIZE {
16345            0
16346        } else {
16347            (molecule::unpack_number(&self.as_slice()[molecule::NUMBER_SIZE..]) as usize / 4) - 1
16348        }
16349    }
16350    pub fn count_extra_fields(&self) -> usize {
16351        self.field_count() - Self::FIELD_COUNT
16352    }
16353    pub fn has_extra_fields(&self) -> bool {
16354        Self::FIELD_COUNT != self.field_count()
16355    }
16356    pub fn channel_outpoint(&self) -> OutPointReader<'r> {
16357        let slice = self.as_slice();
16358        let start = molecule::unpack_number(&slice[4..]) as usize;
16359        let end = molecule::unpack_number(&slice[8..]) as usize;
16360        OutPointReader::new_unchecked(&self.as_slice()[start..end])
16361    }
16362    pub fn channel_update(&self) -> ChannelUpdateOptReader<'r> {
16363        let slice = self.as_slice();
16364        let start = molecule::unpack_number(&slice[8..]) as usize;
16365        let end = molecule::unpack_number(&slice[12..]) as usize;
16366        ChannelUpdateOptReader::new_unchecked(&self.as_slice()[start..end])
16367    }
16368    pub fn node_id(&self) -> PubkeyReader<'r> {
16369        let slice = self.as_slice();
16370        let start = molecule::unpack_number(&slice[12..]) as usize;
16371        if self.has_extra_fields() {
16372            let end = molecule::unpack_number(&slice[16..]) as usize;
16373            PubkeyReader::new_unchecked(&self.as_slice()[start..end])
16374        } else {
16375            PubkeyReader::new_unchecked(&self.as_slice()[start..])
16376        }
16377    }
16378}
16379impl<'r> molecule::prelude::Reader<'r> for ChannelFailedReader<'r> {
16380    type Entity = ChannelFailed;
16381    const NAME: &'static str = "ChannelFailedReader";
16382    fn to_entity(&self) -> Self::Entity {
16383        Self::Entity::new_unchecked(self.as_slice().to_owned().into())
16384    }
16385    fn new_unchecked(slice: &'r [u8]) -> Self {
16386        ChannelFailedReader(slice)
16387    }
16388    fn as_slice(&self) -> &'r [u8] {
16389        self.0
16390    }
16391    fn verify(slice: &[u8], compatible: bool) -> molecule::error::VerificationResult<()> {
16392        use molecule::verification_error as ve;
16393        let slice_len = slice.len();
16394        if slice_len < molecule::NUMBER_SIZE {
16395            return ve!(Self, HeaderIsBroken, molecule::NUMBER_SIZE, slice_len);
16396        }
16397        let total_size = molecule::unpack_number(slice) as usize;
16398        if slice_len != total_size {
16399            return ve!(Self, TotalSizeNotMatch, total_size, slice_len);
16400        }
16401        if slice_len < molecule::NUMBER_SIZE * 2 {
16402            return ve!(Self, HeaderIsBroken, molecule::NUMBER_SIZE * 2, slice_len);
16403        }
16404        let offset_first = molecule::unpack_number(&slice[molecule::NUMBER_SIZE..]) as usize;
16405        if offset_first % molecule::NUMBER_SIZE != 0 || offset_first < molecule::NUMBER_SIZE * 2 {
16406            return ve!(Self, OffsetsNotMatch);
16407        }
16408        if slice_len < offset_first {
16409            return ve!(Self, HeaderIsBroken, offset_first, slice_len);
16410        }
16411        let field_count = offset_first / molecule::NUMBER_SIZE - 1;
16412        if field_count < Self::FIELD_COUNT {
16413            return ve!(Self, FieldCountNotMatch, Self::FIELD_COUNT, field_count);
16414        } else if !compatible && field_count > Self::FIELD_COUNT {
16415            return ve!(Self, FieldCountNotMatch, Self::FIELD_COUNT, field_count);
16416        };
16417        let mut offsets: Vec<usize> = slice[molecule::NUMBER_SIZE..offset_first]
16418            .chunks_exact(molecule::NUMBER_SIZE)
16419            .map(|x| molecule::unpack_number(x) as usize)
16420            .collect();
16421        offsets.push(total_size);
16422        if offsets.windows(2).any(|i| i[0] > i[1]) {
16423            return ve!(Self, OffsetsNotMatch);
16424        }
16425        OutPointReader::verify(&slice[offsets[0]..offsets[1]], compatible)?;
16426        ChannelUpdateOptReader::verify(&slice[offsets[1]..offsets[2]], compatible)?;
16427        PubkeyReader::verify(&slice[offsets[2]..offsets[3]], compatible)?;
16428        Ok(())
16429    }
16430}
16431#[derive(Clone, Debug, Default)]
16432pub struct ChannelFailedBuilder {
16433    pub(crate) channel_outpoint: OutPoint,
16434    pub(crate) channel_update: ChannelUpdateOpt,
16435    pub(crate) node_id: Pubkey,
16436}
16437impl ChannelFailedBuilder {
16438    pub const FIELD_COUNT: usize = 3;
16439    pub fn channel_outpoint(mut self, v: OutPoint) -> Self {
16440        self.channel_outpoint = v;
16441        self
16442    }
16443    pub fn channel_update(mut self, v: ChannelUpdateOpt) -> Self {
16444        self.channel_update = v;
16445        self
16446    }
16447    pub fn node_id(mut self, v: Pubkey) -> Self {
16448        self.node_id = v;
16449        self
16450    }
16451}
16452impl molecule::prelude::Builder for ChannelFailedBuilder {
16453    type Entity = ChannelFailed;
16454    const NAME: &'static str = "ChannelFailedBuilder";
16455    fn expected_length(&self) -> usize {
16456        molecule::NUMBER_SIZE * (Self::FIELD_COUNT + 1)
16457            + self.channel_outpoint.as_slice().len()
16458            + self.channel_update.as_slice().len()
16459            + self.node_id.as_slice().len()
16460    }
16461    fn write<W: molecule::io::Write>(&self, writer: &mut W) -> molecule::io::Result<()> {
16462        let mut total_size = molecule::NUMBER_SIZE * (Self::FIELD_COUNT + 1);
16463        let mut offsets = Vec::with_capacity(Self::FIELD_COUNT);
16464        offsets.push(total_size);
16465        total_size += self.channel_outpoint.as_slice().len();
16466        offsets.push(total_size);
16467        total_size += self.channel_update.as_slice().len();
16468        offsets.push(total_size);
16469        total_size += self.node_id.as_slice().len();
16470        writer.write_all(&molecule::pack_number(total_size as molecule::Number))?;
16471        for offset in offsets.into_iter() {
16472            writer.write_all(&molecule::pack_number(offset as molecule::Number))?;
16473        }
16474        writer.write_all(self.channel_outpoint.as_slice())?;
16475        writer.write_all(self.channel_update.as_slice())?;
16476        writer.write_all(self.node_id.as_slice())?;
16477        Ok(())
16478    }
16479    fn build(&self) -> Self::Entity {
16480        let mut inner = Vec::with_capacity(self.expected_length());
16481        self.write(&mut inner)
16482            .unwrap_or_else(|_| panic!("{} build should be ok", Self::NAME));
16483        ChannelFailed::new_unchecked(inner.into())
16484    }
16485}
16486#[derive(Clone)]
16487pub struct NodeFailed(molecule::bytes::Bytes);
16488impl ::core::fmt::LowerHex for NodeFailed {
16489    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
16490        use molecule::hex_string;
16491        if f.alternate() {
16492            write!(f, "0x")?;
16493        }
16494        write!(f, "{}", hex_string(self.as_slice()))
16495    }
16496}
16497impl ::core::fmt::Debug for NodeFailed {
16498    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
16499        write!(f, "{}({:#x})", Self::NAME, self)
16500    }
16501}
16502impl ::core::fmt::Display for NodeFailed {
16503    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
16504        write!(f, "{} {{ ", Self::NAME)?;
16505        write!(f, "{}: {}", "node_id", self.node_id())?;
16506        let extra_count = self.count_extra_fields();
16507        if extra_count != 0 {
16508            write!(f, ", .. ({} fields)", extra_count)?;
16509        }
16510        write!(f, " }}")
16511    }
16512}
16513impl ::core::default::Default for NodeFailed {
16514    fn default() -> Self {
16515        let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE);
16516        NodeFailed::new_unchecked(v)
16517    }
16518}
16519impl NodeFailed {
16520    const DEFAULT_VALUE: [u8; 41] = [
16521        41, 0, 0, 0, 8, 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,
16522        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
16523    ];
16524    pub const FIELD_COUNT: usize = 1;
16525    pub fn total_size(&self) -> usize {
16526        molecule::unpack_number(self.as_slice()) as usize
16527    }
16528    pub fn field_count(&self) -> usize {
16529        if self.total_size() == molecule::NUMBER_SIZE {
16530            0
16531        } else {
16532            (molecule::unpack_number(&self.as_slice()[molecule::NUMBER_SIZE..]) as usize / 4) - 1
16533        }
16534    }
16535    pub fn count_extra_fields(&self) -> usize {
16536        self.field_count() - Self::FIELD_COUNT
16537    }
16538    pub fn has_extra_fields(&self) -> bool {
16539        Self::FIELD_COUNT != self.field_count()
16540    }
16541    pub fn node_id(&self) -> Pubkey {
16542        let slice = self.as_slice();
16543        let start = molecule::unpack_number(&slice[4..]) as usize;
16544        if self.has_extra_fields() {
16545            let end = molecule::unpack_number(&slice[8..]) as usize;
16546            Pubkey::new_unchecked(self.0.slice(start..end))
16547        } else {
16548            Pubkey::new_unchecked(self.0.slice(start..))
16549        }
16550    }
16551    pub fn as_reader<'r>(&'r self) -> NodeFailedReader<'r> {
16552        NodeFailedReader::new_unchecked(self.as_slice())
16553    }
16554}
16555impl molecule::prelude::Entity for NodeFailed {
16556    type Builder = NodeFailedBuilder;
16557    const NAME: &'static str = "NodeFailed";
16558    fn new_unchecked(data: molecule::bytes::Bytes) -> Self {
16559        NodeFailed(data)
16560    }
16561    fn as_bytes(&self) -> molecule::bytes::Bytes {
16562        self.0.clone()
16563    }
16564    fn as_slice(&self) -> &[u8] {
16565        &self.0[..]
16566    }
16567    fn from_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
16568        NodeFailedReader::from_slice(slice).map(|reader| reader.to_entity())
16569    }
16570    fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
16571        NodeFailedReader::from_compatible_slice(slice).map(|reader| reader.to_entity())
16572    }
16573    fn new_builder() -> Self::Builder {
16574        ::core::default::Default::default()
16575    }
16576    fn as_builder(self) -> Self::Builder {
16577        Self::new_builder().node_id(self.node_id())
16578    }
16579}
16580#[derive(Clone, Copy)]
16581pub struct NodeFailedReader<'r>(&'r [u8]);
16582impl<'r> ::core::fmt::LowerHex for NodeFailedReader<'r> {
16583    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
16584        use molecule::hex_string;
16585        if f.alternate() {
16586            write!(f, "0x")?;
16587        }
16588        write!(f, "{}", hex_string(self.as_slice()))
16589    }
16590}
16591impl<'r> ::core::fmt::Debug for NodeFailedReader<'r> {
16592    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
16593        write!(f, "{}({:#x})", Self::NAME, self)
16594    }
16595}
16596impl<'r> ::core::fmt::Display for NodeFailedReader<'r> {
16597    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
16598        write!(f, "{} {{ ", Self::NAME)?;
16599        write!(f, "{}: {}", "node_id", self.node_id())?;
16600        let extra_count = self.count_extra_fields();
16601        if extra_count != 0 {
16602            write!(f, ", .. ({} fields)", extra_count)?;
16603        }
16604        write!(f, " }}")
16605    }
16606}
16607impl<'r> NodeFailedReader<'r> {
16608    pub const FIELD_COUNT: usize = 1;
16609    pub fn total_size(&self) -> usize {
16610        molecule::unpack_number(self.as_slice()) as usize
16611    }
16612    pub fn field_count(&self) -> usize {
16613        if self.total_size() == molecule::NUMBER_SIZE {
16614            0
16615        } else {
16616            (molecule::unpack_number(&self.as_slice()[molecule::NUMBER_SIZE..]) as usize / 4) - 1
16617        }
16618    }
16619    pub fn count_extra_fields(&self) -> usize {
16620        self.field_count() - Self::FIELD_COUNT
16621    }
16622    pub fn has_extra_fields(&self) -> bool {
16623        Self::FIELD_COUNT != self.field_count()
16624    }
16625    pub fn node_id(&self) -> PubkeyReader<'r> {
16626        let slice = self.as_slice();
16627        let start = molecule::unpack_number(&slice[4..]) as usize;
16628        if self.has_extra_fields() {
16629            let end = molecule::unpack_number(&slice[8..]) as usize;
16630            PubkeyReader::new_unchecked(&self.as_slice()[start..end])
16631        } else {
16632            PubkeyReader::new_unchecked(&self.as_slice()[start..])
16633        }
16634    }
16635}
16636impl<'r> molecule::prelude::Reader<'r> for NodeFailedReader<'r> {
16637    type Entity = NodeFailed;
16638    const NAME: &'static str = "NodeFailedReader";
16639    fn to_entity(&self) -> Self::Entity {
16640        Self::Entity::new_unchecked(self.as_slice().to_owned().into())
16641    }
16642    fn new_unchecked(slice: &'r [u8]) -> Self {
16643        NodeFailedReader(slice)
16644    }
16645    fn as_slice(&self) -> &'r [u8] {
16646        self.0
16647    }
16648    fn verify(slice: &[u8], compatible: bool) -> molecule::error::VerificationResult<()> {
16649        use molecule::verification_error as ve;
16650        let slice_len = slice.len();
16651        if slice_len < molecule::NUMBER_SIZE {
16652            return ve!(Self, HeaderIsBroken, molecule::NUMBER_SIZE, slice_len);
16653        }
16654        let total_size = molecule::unpack_number(slice) as usize;
16655        if slice_len != total_size {
16656            return ve!(Self, TotalSizeNotMatch, total_size, slice_len);
16657        }
16658        if slice_len < molecule::NUMBER_SIZE * 2 {
16659            return ve!(Self, HeaderIsBroken, molecule::NUMBER_SIZE * 2, slice_len);
16660        }
16661        let offset_first = molecule::unpack_number(&slice[molecule::NUMBER_SIZE..]) as usize;
16662        if offset_first % molecule::NUMBER_SIZE != 0 || offset_first < molecule::NUMBER_SIZE * 2 {
16663            return ve!(Self, OffsetsNotMatch);
16664        }
16665        if slice_len < offset_first {
16666            return ve!(Self, HeaderIsBroken, offset_first, slice_len);
16667        }
16668        let field_count = offset_first / molecule::NUMBER_SIZE - 1;
16669        if field_count < Self::FIELD_COUNT {
16670            return ve!(Self, FieldCountNotMatch, Self::FIELD_COUNT, field_count);
16671        } else if !compatible && field_count > Self::FIELD_COUNT {
16672            return ve!(Self, FieldCountNotMatch, Self::FIELD_COUNT, field_count);
16673        };
16674        let mut offsets: Vec<usize> = slice[molecule::NUMBER_SIZE..offset_first]
16675            .chunks_exact(molecule::NUMBER_SIZE)
16676            .map(|x| molecule::unpack_number(x) as usize)
16677            .collect();
16678        offsets.push(total_size);
16679        if offsets.windows(2).any(|i| i[0] > i[1]) {
16680            return ve!(Self, OffsetsNotMatch);
16681        }
16682        PubkeyReader::verify(&slice[offsets[0]..offsets[1]], compatible)?;
16683        Ok(())
16684    }
16685}
16686#[derive(Clone, Debug, Default)]
16687pub struct NodeFailedBuilder {
16688    pub(crate) node_id: Pubkey,
16689}
16690impl NodeFailedBuilder {
16691    pub const FIELD_COUNT: usize = 1;
16692    pub fn node_id(mut self, v: Pubkey) -> Self {
16693        self.node_id = v;
16694        self
16695    }
16696}
16697impl molecule::prelude::Builder for NodeFailedBuilder {
16698    type Entity = NodeFailed;
16699    const NAME: &'static str = "NodeFailedBuilder";
16700    fn expected_length(&self) -> usize {
16701        molecule::NUMBER_SIZE * (Self::FIELD_COUNT + 1) + self.node_id.as_slice().len()
16702    }
16703    fn write<W: molecule::io::Write>(&self, writer: &mut W) -> molecule::io::Result<()> {
16704        let mut total_size = molecule::NUMBER_SIZE * (Self::FIELD_COUNT + 1);
16705        let mut offsets = Vec::with_capacity(Self::FIELD_COUNT);
16706        offsets.push(total_size);
16707        total_size += self.node_id.as_slice().len();
16708        writer.write_all(&molecule::pack_number(total_size as molecule::Number))?;
16709        for offset in offsets.into_iter() {
16710            writer.write_all(&molecule::pack_number(offset as molecule::Number))?;
16711        }
16712        writer.write_all(self.node_id.as_slice())?;
16713        Ok(())
16714    }
16715    fn build(&self) -> Self::Entity {
16716        let mut inner = Vec::with_capacity(self.expected_length());
16717        self.write(&mut inner)
16718            .unwrap_or_else(|_| panic!("{} build should be ok", Self::NAME));
16719        NodeFailed::new_unchecked(inner.into())
16720    }
16721}
16722#[derive(Clone)]
16723pub struct TrampolineFailed(molecule::bytes::Bytes);
16724impl ::core::fmt::LowerHex for TrampolineFailed {
16725    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
16726        use molecule::hex_string;
16727        if f.alternate() {
16728            write!(f, "0x")?;
16729        }
16730        write!(f, "{}", hex_string(self.as_slice()))
16731    }
16732}
16733impl ::core::fmt::Debug for TrampolineFailed {
16734    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
16735        write!(f, "{}({:#x})", Self::NAME, self)
16736    }
16737}
16738impl ::core::fmt::Display for TrampolineFailed {
16739    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
16740        write!(f, "{} {{ ", Self::NAME)?;
16741        write!(f, "{}: {}", "node_id", self.node_id())?;
16742        write!(
16743            f,
16744            ", {}: {}",
16745            "inner_error_packet",
16746            self.inner_error_packet()
16747        )?;
16748        let extra_count = self.count_extra_fields();
16749        if extra_count != 0 {
16750            write!(f, ", .. ({} fields)", extra_count)?;
16751        }
16752        write!(f, " }}")
16753    }
16754}
16755impl ::core::default::Default for TrampolineFailed {
16756    fn default() -> Self {
16757        let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE);
16758        TrampolineFailed::new_unchecked(v)
16759    }
16760}
16761impl TrampolineFailed {
16762    const DEFAULT_VALUE: [u8; 49] = [
16763        49, 0, 0, 0, 12, 0, 0, 0, 45, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
16764        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
16765    ];
16766    pub const FIELD_COUNT: usize = 2;
16767    pub fn total_size(&self) -> usize {
16768        molecule::unpack_number(self.as_slice()) as usize
16769    }
16770    pub fn field_count(&self) -> usize {
16771        if self.total_size() == molecule::NUMBER_SIZE {
16772            0
16773        } else {
16774            (molecule::unpack_number(&self.as_slice()[molecule::NUMBER_SIZE..]) as usize / 4) - 1
16775        }
16776    }
16777    pub fn count_extra_fields(&self) -> usize {
16778        self.field_count() - Self::FIELD_COUNT
16779    }
16780    pub fn has_extra_fields(&self) -> bool {
16781        Self::FIELD_COUNT != self.field_count()
16782    }
16783    pub fn node_id(&self) -> Pubkey {
16784        let slice = self.as_slice();
16785        let start = molecule::unpack_number(&slice[4..]) as usize;
16786        let end = molecule::unpack_number(&slice[8..]) as usize;
16787        Pubkey::new_unchecked(self.0.slice(start..end))
16788    }
16789    pub fn inner_error_packet(&self) -> Bytes {
16790        let slice = self.as_slice();
16791        let start = molecule::unpack_number(&slice[8..]) as usize;
16792        if self.has_extra_fields() {
16793            let end = molecule::unpack_number(&slice[12..]) as usize;
16794            Bytes::new_unchecked(self.0.slice(start..end))
16795        } else {
16796            Bytes::new_unchecked(self.0.slice(start..))
16797        }
16798    }
16799    pub fn as_reader<'r>(&'r self) -> TrampolineFailedReader<'r> {
16800        TrampolineFailedReader::new_unchecked(self.as_slice())
16801    }
16802}
16803impl molecule::prelude::Entity for TrampolineFailed {
16804    type Builder = TrampolineFailedBuilder;
16805    const NAME: &'static str = "TrampolineFailed";
16806    fn new_unchecked(data: molecule::bytes::Bytes) -> Self {
16807        TrampolineFailed(data)
16808    }
16809    fn as_bytes(&self) -> molecule::bytes::Bytes {
16810        self.0.clone()
16811    }
16812    fn as_slice(&self) -> &[u8] {
16813        &self.0[..]
16814    }
16815    fn from_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
16816        TrampolineFailedReader::from_slice(slice).map(|reader| reader.to_entity())
16817    }
16818    fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
16819        TrampolineFailedReader::from_compatible_slice(slice).map(|reader| reader.to_entity())
16820    }
16821    fn new_builder() -> Self::Builder {
16822        ::core::default::Default::default()
16823    }
16824    fn as_builder(self) -> Self::Builder {
16825        Self::new_builder()
16826            .node_id(self.node_id())
16827            .inner_error_packet(self.inner_error_packet())
16828    }
16829}
16830#[derive(Clone, Copy)]
16831pub struct TrampolineFailedReader<'r>(&'r [u8]);
16832impl<'r> ::core::fmt::LowerHex for TrampolineFailedReader<'r> {
16833    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
16834        use molecule::hex_string;
16835        if f.alternate() {
16836            write!(f, "0x")?;
16837        }
16838        write!(f, "{}", hex_string(self.as_slice()))
16839    }
16840}
16841impl<'r> ::core::fmt::Debug for TrampolineFailedReader<'r> {
16842    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
16843        write!(f, "{}({:#x})", Self::NAME, self)
16844    }
16845}
16846impl<'r> ::core::fmt::Display for TrampolineFailedReader<'r> {
16847    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
16848        write!(f, "{} {{ ", Self::NAME)?;
16849        write!(f, "{}: {}", "node_id", self.node_id())?;
16850        write!(
16851            f,
16852            ", {}: {}",
16853            "inner_error_packet",
16854            self.inner_error_packet()
16855        )?;
16856        let extra_count = self.count_extra_fields();
16857        if extra_count != 0 {
16858            write!(f, ", .. ({} fields)", extra_count)?;
16859        }
16860        write!(f, " }}")
16861    }
16862}
16863impl<'r> TrampolineFailedReader<'r> {
16864    pub const FIELD_COUNT: usize = 2;
16865    pub fn total_size(&self) -> usize {
16866        molecule::unpack_number(self.as_slice()) as usize
16867    }
16868    pub fn field_count(&self) -> usize {
16869        if self.total_size() == molecule::NUMBER_SIZE {
16870            0
16871        } else {
16872            (molecule::unpack_number(&self.as_slice()[molecule::NUMBER_SIZE..]) as usize / 4) - 1
16873        }
16874    }
16875    pub fn count_extra_fields(&self) -> usize {
16876        self.field_count() - Self::FIELD_COUNT
16877    }
16878    pub fn has_extra_fields(&self) -> bool {
16879        Self::FIELD_COUNT != self.field_count()
16880    }
16881    pub fn node_id(&self) -> PubkeyReader<'r> {
16882        let slice = self.as_slice();
16883        let start = molecule::unpack_number(&slice[4..]) as usize;
16884        let end = molecule::unpack_number(&slice[8..]) as usize;
16885        PubkeyReader::new_unchecked(&self.as_slice()[start..end])
16886    }
16887    pub fn inner_error_packet(&self) -> BytesReader<'r> {
16888        let slice = self.as_slice();
16889        let start = molecule::unpack_number(&slice[8..]) as usize;
16890        if self.has_extra_fields() {
16891            let end = molecule::unpack_number(&slice[12..]) as usize;
16892            BytesReader::new_unchecked(&self.as_slice()[start..end])
16893        } else {
16894            BytesReader::new_unchecked(&self.as_slice()[start..])
16895        }
16896    }
16897}
16898impl<'r> molecule::prelude::Reader<'r> for TrampolineFailedReader<'r> {
16899    type Entity = TrampolineFailed;
16900    const NAME: &'static str = "TrampolineFailedReader";
16901    fn to_entity(&self) -> Self::Entity {
16902        Self::Entity::new_unchecked(self.as_slice().to_owned().into())
16903    }
16904    fn new_unchecked(slice: &'r [u8]) -> Self {
16905        TrampolineFailedReader(slice)
16906    }
16907    fn as_slice(&self) -> &'r [u8] {
16908        self.0
16909    }
16910    fn verify(slice: &[u8], compatible: bool) -> molecule::error::VerificationResult<()> {
16911        use molecule::verification_error as ve;
16912        let slice_len = slice.len();
16913        if slice_len < molecule::NUMBER_SIZE {
16914            return ve!(Self, HeaderIsBroken, molecule::NUMBER_SIZE, slice_len);
16915        }
16916        let total_size = molecule::unpack_number(slice) as usize;
16917        if slice_len != total_size {
16918            return ve!(Self, TotalSizeNotMatch, total_size, slice_len);
16919        }
16920        if slice_len < molecule::NUMBER_SIZE * 2 {
16921            return ve!(Self, HeaderIsBroken, molecule::NUMBER_SIZE * 2, slice_len);
16922        }
16923        let offset_first = molecule::unpack_number(&slice[molecule::NUMBER_SIZE..]) as usize;
16924        if offset_first % molecule::NUMBER_SIZE != 0 || offset_first < molecule::NUMBER_SIZE * 2 {
16925            return ve!(Self, OffsetsNotMatch);
16926        }
16927        if slice_len < offset_first {
16928            return ve!(Self, HeaderIsBroken, offset_first, slice_len);
16929        }
16930        let field_count = offset_first / molecule::NUMBER_SIZE - 1;
16931        if field_count < Self::FIELD_COUNT {
16932            return ve!(Self, FieldCountNotMatch, Self::FIELD_COUNT, field_count);
16933        } else if !compatible && field_count > Self::FIELD_COUNT {
16934            return ve!(Self, FieldCountNotMatch, Self::FIELD_COUNT, field_count);
16935        };
16936        let mut offsets: Vec<usize> = slice[molecule::NUMBER_SIZE..offset_first]
16937            .chunks_exact(molecule::NUMBER_SIZE)
16938            .map(|x| molecule::unpack_number(x) as usize)
16939            .collect();
16940        offsets.push(total_size);
16941        if offsets.windows(2).any(|i| i[0] > i[1]) {
16942            return ve!(Self, OffsetsNotMatch);
16943        }
16944        PubkeyReader::verify(&slice[offsets[0]..offsets[1]], compatible)?;
16945        BytesReader::verify(&slice[offsets[1]..offsets[2]], compatible)?;
16946        Ok(())
16947    }
16948}
16949#[derive(Clone, Debug, Default)]
16950pub struct TrampolineFailedBuilder {
16951    pub(crate) node_id: Pubkey,
16952    pub(crate) inner_error_packet: Bytes,
16953}
16954impl TrampolineFailedBuilder {
16955    pub const FIELD_COUNT: usize = 2;
16956    pub fn node_id(mut self, v: Pubkey) -> Self {
16957        self.node_id = v;
16958        self
16959    }
16960    pub fn inner_error_packet(mut self, v: Bytes) -> Self {
16961        self.inner_error_packet = v;
16962        self
16963    }
16964}
16965impl molecule::prelude::Builder for TrampolineFailedBuilder {
16966    type Entity = TrampolineFailed;
16967    const NAME: &'static str = "TrampolineFailedBuilder";
16968    fn expected_length(&self) -> usize {
16969        molecule::NUMBER_SIZE * (Self::FIELD_COUNT + 1)
16970            + self.node_id.as_slice().len()
16971            + self.inner_error_packet.as_slice().len()
16972    }
16973    fn write<W: molecule::io::Write>(&self, writer: &mut W) -> molecule::io::Result<()> {
16974        let mut total_size = molecule::NUMBER_SIZE * (Self::FIELD_COUNT + 1);
16975        let mut offsets = Vec::with_capacity(Self::FIELD_COUNT);
16976        offsets.push(total_size);
16977        total_size += self.node_id.as_slice().len();
16978        offsets.push(total_size);
16979        total_size += self.inner_error_packet.as_slice().len();
16980        writer.write_all(&molecule::pack_number(total_size as molecule::Number))?;
16981        for offset in offsets.into_iter() {
16982            writer.write_all(&molecule::pack_number(offset as molecule::Number))?;
16983        }
16984        writer.write_all(self.node_id.as_slice())?;
16985        writer.write_all(self.inner_error_packet.as_slice())?;
16986        Ok(())
16987    }
16988    fn build(&self) -> Self::Entity {
16989        let mut inner = Vec::with_capacity(self.expected_length());
16990        self.write(&mut inner)
16991            .unwrap_or_else(|_| panic!("{} build should be ok", Self::NAME));
16992        TrampolineFailed::new_unchecked(inner.into())
16993    }
16994}
16995#[derive(Clone)]
16996pub struct TlcErrData(molecule::bytes::Bytes);
16997impl ::core::fmt::LowerHex for TlcErrData {
16998    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
16999        use molecule::hex_string;
17000        if f.alternate() {
17001            write!(f, "0x")?;
17002        }
17003        write!(f, "{}", hex_string(self.as_slice()))
17004    }
17005}
17006impl ::core::fmt::Debug for TlcErrData {
17007    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
17008        write!(f, "{}({:#x})", Self::NAME, self)
17009    }
17010}
17011impl ::core::fmt::Display for TlcErrData {
17012    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
17013        write!(f, "{}(", Self::NAME)?;
17014        self.to_enum().display_inner(f)?;
17015        write!(f, ")")
17016    }
17017}
17018impl ::core::default::Default for TlcErrData {
17019    fn default() -> Self {
17020        let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE);
17021        TlcErrData::new_unchecked(v)
17022    }
17023}
17024impl TlcErrData {
17025    const DEFAULT_VALUE: [u8; 89] = [
17026        0, 0, 0, 0, 85, 0, 0, 0, 16, 0, 0, 0, 52, 0, 0, 0, 52, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
17027        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,
17028        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,
17029    ];
17030    pub const ITEMS_COUNT: usize = 3;
17031    pub fn item_id(&self) -> molecule::Number {
17032        molecule::unpack_number(self.as_slice())
17033    }
17034    pub fn to_enum(&self) -> TlcErrDataUnion {
17035        let inner = self.0.slice(molecule::NUMBER_SIZE..);
17036        match self.item_id() {
17037            0 => ChannelFailed::new_unchecked(inner).into(),
17038            1 => NodeFailed::new_unchecked(inner).into(),
17039            2 => TrampolineFailed::new_unchecked(inner).into(),
17040            _ => panic!("{}: invalid data", Self::NAME),
17041        }
17042    }
17043    pub fn as_reader<'r>(&'r self) -> TlcErrDataReader<'r> {
17044        TlcErrDataReader::new_unchecked(self.as_slice())
17045    }
17046}
17047impl molecule::prelude::Entity for TlcErrData {
17048    type Builder = TlcErrDataBuilder;
17049    const NAME: &'static str = "TlcErrData";
17050    fn new_unchecked(data: molecule::bytes::Bytes) -> Self {
17051        TlcErrData(data)
17052    }
17053    fn as_bytes(&self) -> molecule::bytes::Bytes {
17054        self.0.clone()
17055    }
17056    fn as_slice(&self) -> &[u8] {
17057        &self.0[..]
17058    }
17059    fn from_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
17060        TlcErrDataReader::from_slice(slice).map(|reader| reader.to_entity())
17061    }
17062    fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
17063        TlcErrDataReader::from_compatible_slice(slice).map(|reader| reader.to_entity())
17064    }
17065    fn new_builder() -> Self::Builder {
17066        ::core::default::Default::default()
17067    }
17068    fn as_builder(self) -> Self::Builder {
17069        Self::new_builder().set(self.to_enum())
17070    }
17071}
17072#[derive(Clone, Copy)]
17073pub struct TlcErrDataReader<'r>(&'r [u8]);
17074impl<'r> ::core::fmt::LowerHex for TlcErrDataReader<'r> {
17075    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
17076        use molecule::hex_string;
17077        if f.alternate() {
17078            write!(f, "0x")?;
17079        }
17080        write!(f, "{}", hex_string(self.as_slice()))
17081    }
17082}
17083impl<'r> ::core::fmt::Debug for TlcErrDataReader<'r> {
17084    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
17085        write!(f, "{}({:#x})", Self::NAME, self)
17086    }
17087}
17088impl<'r> ::core::fmt::Display for TlcErrDataReader<'r> {
17089    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
17090        write!(f, "{}(", Self::NAME)?;
17091        self.to_enum().display_inner(f)?;
17092        write!(f, ")")
17093    }
17094}
17095impl<'r> TlcErrDataReader<'r> {
17096    pub const ITEMS_COUNT: usize = 3;
17097    pub fn item_id(&self) -> molecule::Number {
17098        molecule::unpack_number(self.as_slice())
17099    }
17100    pub fn to_enum(&self) -> TlcErrDataUnionReader<'r> {
17101        let inner = &self.as_slice()[molecule::NUMBER_SIZE..];
17102        match self.item_id() {
17103            0 => ChannelFailedReader::new_unchecked(inner).into(),
17104            1 => NodeFailedReader::new_unchecked(inner).into(),
17105            2 => TrampolineFailedReader::new_unchecked(inner).into(),
17106            _ => panic!("{}: invalid data", Self::NAME),
17107        }
17108    }
17109}
17110impl<'r> molecule::prelude::Reader<'r> for TlcErrDataReader<'r> {
17111    type Entity = TlcErrData;
17112    const NAME: &'static str = "TlcErrDataReader";
17113    fn to_entity(&self) -> Self::Entity {
17114        Self::Entity::new_unchecked(self.as_slice().to_owned().into())
17115    }
17116    fn new_unchecked(slice: &'r [u8]) -> Self {
17117        TlcErrDataReader(slice)
17118    }
17119    fn as_slice(&self) -> &'r [u8] {
17120        self.0
17121    }
17122    fn verify(slice: &[u8], compatible: bool) -> molecule::error::VerificationResult<()> {
17123        use molecule::verification_error as ve;
17124        let slice_len = slice.len();
17125        if slice_len < molecule::NUMBER_SIZE {
17126            return ve!(Self, HeaderIsBroken, molecule::NUMBER_SIZE, slice_len);
17127        }
17128        let item_id = molecule::unpack_number(slice);
17129        let inner_slice = &slice[molecule::NUMBER_SIZE..];
17130        match item_id {
17131            0 => ChannelFailedReader::verify(inner_slice, compatible),
17132            1 => NodeFailedReader::verify(inner_slice, compatible),
17133            2 => TrampolineFailedReader::verify(inner_slice, compatible),
17134            _ => ve!(Self, UnknownItem, Self::ITEMS_COUNT, item_id),
17135        }?;
17136        Ok(())
17137    }
17138}
17139#[derive(Clone, Debug, Default)]
17140pub struct TlcErrDataBuilder(pub(crate) TlcErrDataUnion);
17141impl TlcErrDataBuilder {
17142    pub const ITEMS_COUNT: usize = 3;
17143    pub fn set<I>(mut self, v: I) -> Self
17144    where
17145        I: ::core::convert::Into<TlcErrDataUnion>,
17146    {
17147        self.0 = v.into();
17148        self
17149    }
17150}
17151impl molecule::prelude::Builder for TlcErrDataBuilder {
17152    type Entity = TlcErrData;
17153    const NAME: &'static str = "TlcErrDataBuilder";
17154    fn expected_length(&self) -> usize {
17155        molecule::NUMBER_SIZE + self.0.as_slice().len()
17156    }
17157    fn write<W: molecule::io::Write>(&self, writer: &mut W) -> molecule::io::Result<()> {
17158        writer.write_all(&molecule::pack_number(self.0.item_id()))?;
17159        writer.write_all(self.0.as_slice())
17160    }
17161    fn build(&self) -> Self::Entity {
17162        let mut inner = Vec::with_capacity(self.expected_length());
17163        self.write(&mut inner)
17164            .unwrap_or_else(|_| panic!("{} build should be ok", Self::NAME));
17165        TlcErrData::new_unchecked(inner.into())
17166    }
17167}
17168#[derive(Debug, Clone)]
17169pub enum TlcErrDataUnion {
17170    ChannelFailed(ChannelFailed),
17171    NodeFailed(NodeFailed),
17172    TrampolineFailed(TrampolineFailed),
17173}
17174#[derive(Debug, Clone, Copy)]
17175pub enum TlcErrDataUnionReader<'r> {
17176    ChannelFailed(ChannelFailedReader<'r>),
17177    NodeFailed(NodeFailedReader<'r>),
17178    TrampolineFailed(TrampolineFailedReader<'r>),
17179}
17180impl ::core::default::Default for TlcErrDataUnion {
17181    fn default() -> Self {
17182        TlcErrDataUnion::ChannelFailed(::core::default::Default::default())
17183    }
17184}
17185impl ::core::fmt::Display for TlcErrDataUnion {
17186    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
17187        match self {
17188            TlcErrDataUnion::ChannelFailed(ref item) => {
17189                write!(f, "{}::{}({})", Self::NAME, ChannelFailed::NAME, item)
17190            }
17191            TlcErrDataUnion::NodeFailed(ref item) => {
17192                write!(f, "{}::{}({})", Self::NAME, NodeFailed::NAME, item)
17193            }
17194            TlcErrDataUnion::TrampolineFailed(ref item) => {
17195                write!(f, "{}::{}({})", Self::NAME, TrampolineFailed::NAME, item)
17196            }
17197        }
17198    }
17199}
17200impl<'r> ::core::fmt::Display for TlcErrDataUnionReader<'r> {
17201    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
17202        match self {
17203            TlcErrDataUnionReader::ChannelFailed(ref item) => {
17204                write!(f, "{}::{}({})", Self::NAME, ChannelFailed::NAME, item)
17205            }
17206            TlcErrDataUnionReader::NodeFailed(ref item) => {
17207                write!(f, "{}::{}({})", Self::NAME, NodeFailed::NAME, item)
17208            }
17209            TlcErrDataUnionReader::TrampolineFailed(ref item) => {
17210                write!(f, "{}::{}({})", Self::NAME, TrampolineFailed::NAME, item)
17211            }
17212        }
17213    }
17214}
17215impl TlcErrDataUnion {
17216    pub(crate) fn display_inner(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
17217        match self {
17218            TlcErrDataUnion::ChannelFailed(ref item) => write!(f, "{}", item),
17219            TlcErrDataUnion::NodeFailed(ref item) => write!(f, "{}", item),
17220            TlcErrDataUnion::TrampolineFailed(ref item) => write!(f, "{}", item),
17221        }
17222    }
17223}
17224impl<'r> TlcErrDataUnionReader<'r> {
17225    pub(crate) fn display_inner(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
17226        match self {
17227            TlcErrDataUnionReader::ChannelFailed(ref item) => write!(f, "{}", item),
17228            TlcErrDataUnionReader::NodeFailed(ref item) => write!(f, "{}", item),
17229            TlcErrDataUnionReader::TrampolineFailed(ref item) => write!(f, "{}", item),
17230        }
17231    }
17232}
17233impl ::core::convert::From<ChannelFailed> for TlcErrDataUnion {
17234    fn from(item: ChannelFailed) -> Self {
17235        TlcErrDataUnion::ChannelFailed(item)
17236    }
17237}
17238impl ::core::convert::From<NodeFailed> for TlcErrDataUnion {
17239    fn from(item: NodeFailed) -> Self {
17240        TlcErrDataUnion::NodeFailed(item)
17241    }
17242}
17243impl ::core::convert::From<TrampolineFailed> for TlcErrDataUnion {
17244    fn from(item: TrampolineFailed) -> Self {
17245        TlcErrDataUnion::TrampolineFailed(item)
17246    }
17247}
17248impl<'r> ::core::convert::From<ChannelFailedReader<'r>> for TlcErrDataUnionReader<'r> {
17249    fn from(item: ChannelFailedReader<'r>) -> Self {
17250        TlcErrDataUnionReader::ChannelFailed(item)
17251    }
17252}
17253impl<'r> ::core::convert::From<NodeFailedReader<'r>> for TlcErrDataUnionReader<'r> {
17254    fn from(item: NodeFailedReader<'r>) -> Self {
17255        TlcErrDataUnionReader::NodeFailed(item)
17256    }
17257}
17258impl<'r> ::core::convert::From<TrampolineFailedReader<'r>> for TlcErrDataUnionReader<'r> {
17259    fn from(item: TrampolineFailedReader<'r>) -> Self {
17260        TlcErrDataUnionReader::TrampolineFailed(item)
17261    }
17262}
17263impl TlcErrDataUnion {
17264    pub const NAME: &'static str = "TlcErrDataUnion";
17265    pub fn as_bytes(&self) -> molecule::bytes::Bytes {
17266        match self {
17267            TlcErrDataUnion::ChannelFailed(item) => item.as_bytes(),
17268            TlcErrDataUnion::NodeFailed(item) => item.as_bytes(),
17269            TlcErrDataUnion::TrampolineFailed(item) => item.as_bytes(),
17270        }
17271    }
17272    pub fn as_slice(&self) -> &[u8] {
17273        match self {
17274            TlcErrDataUnion::ChannelFailed(item) => item.as_slice(),
17275            TlcErrDataUnion::NodeFailed(item) => item.as_slice(),
17276            TlcErrDataUnion::TrampolineFailed(item) => item.as_slice(),
17277        }
17278    }
17279    pub fn item_id(&self) -> molecule::Number {
17280        match self {
17281            TlcErrDataUnion::ChannelFailed(_) => 0,
17282            TlcErrDataUnion::NodeFailed(_) => 1,
17283            TlcErrDataUnion::TrampolineFailed(_) => 2,
17284        }
17285    }
17286    pub fn item_name(&self) -> &str {
17287        match self {
17288            TlcErrDataUnion::ChannelFailed(_) => "ChannelFailed",
17289            TlcErrDataUnion::NodeFailed(_) => "NodeFailed",
17290            TlcErrDataUnion::TrampolineFailed(_) => "TrampolineFailed",
17291        }
17292    }
17293    pub fn as_reader<'r>(&'r self) -> TlcErrDataUnionReader<'r> {
17294        match self {
17295            TlcErrDataUnion::ChannelFailed(item) => item.as_reader().into(),
17296            TlcErrDataUnion::NodeFailed(item) => item.as_reader().into(),
17297            TlcErrDataUnion::TrampolineFailed(item) => item.as_reader().into(),
17298        }
17299    }
17300}
17301impl<'r> TlcErrDataUnionReader<'r> {
17302    pub const NAME: &'r str = "TlcErrDataUnionReader";
17303    pub fn as_slice(&self) -> &'r [u8] {
17304        match self {
17305            TlcErrDataUnionReader::ChannelFailed(item) => item.as_slice(),
17306            TlcErrDataUnionReader::NodeFailed(item) => item.as_slice(),
17307            TlcErrDataUnionReader::TrampolineFailed(item) => item.as_slice(),
17308        }
17309    }
17310    pub fn item_id(&self) -> molecule::Number {
17311        match self {
17312            TlcErrDataUnionReader::ChannelFailed(_) => 0,
17313            TlcErrDataUnionReader::NodeFailed(_) => 1,
17314            TlcErrDataUnionReader::TrampolineFailed(_) => 2,
17315        }
17316    }
17317    pub fn item_name(&self) -> &str {
17318        match self {
17319            TlcErrDataUnionReader::ChannelFailed(_) => "ChannelFailed",
17320            TlcErrDataUnionReader::NodeFailed(_) => "NodeFailed",
17321            TlcErrDataUnionReader::TrampolineFailed(_) => "TrampolineFailed",
17322        }
17323    }
17324}
17325impl From<ChannelFailed> for TlcErrData {
17326    fn from(value: ChannelFailed) -> Self {
17327        Self::new_builder().set(value).build()
17328    }
17329}
17330impl From<NodeFailed> for TlcErrData {
17331    fn from(value: NodeFailed) -> Self {
17332        Self::new_builder().set(value).build()
17333    }
17334}
17335impl From<TrampolineFailed> for TlcErrData {
17336    fn from(value: TrampolineFailed) -> Self {
17337        Self::new_builder().set(value).build()
17338    }
17339}
17340#[derive(Clone)]
17341pub struct TlcErrDataOpt(molecule::bytes::Bytes);
17342impl ::core::fmt::LowerHex for TlcErrDataOpt {
17343    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
17344        use molecule::hex_string;
17345        if f.alternate() {
17346            write!(f, "0x")?;
17347        }
17348        write!(f, "{}", hex_string(self.as_slice()))
17349    }
17350}
17351impl ::core::fmt::Debug for TlcErrDataOpt {
17352    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
17353        write!(f, "{}({:#x})", Self::NAME, self)
17354    }
17355}
17356impl ::core::fmt::Display for TlcErrDataOpt {
17357    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
17358        if let Some(v) = self.to_opt() {
17359            write!(f, "{}(Some({}))", Self::NAME, v)
17360        } else {
17361            write!(f, "{}(None)", Self::NAME)
17362        }
17363    }
17364}
17365impl ::core::default::Default for TlcErrDataOpt {
17366    fn default() -> Self {
17367        let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE);
17368        TlcErrDataOpt::new_unchecked(v)
17369    }
17370}
17371impl TlcErrDataOpt {
17372    const DEFAULT_VALUE: [u8; 0] = [];
17373    pub fn is_none(&self) -> bool {
17374        self.0.is_empty()
17375    }
17376    pub fn is_some(&self) -> bool {
17377        !self.0.is_empty()
17378    }
17379    pub fn to_opt(&self) -> Option<TlcErrData> {
17380        if self.is_none() {
17381            None
17382        } else {
17383            Some(TlcErrData::new_unchecked(self.0.clone()))
17384        }
17385    }
17386    pub fn as_reader<'r>(&'r self) -> TlcErrDataOptReader<'r> {
17387        TlcErrDataOptReader::new_unchecked(self.as_slice())
17388    }
17389}
17390impl molecule::prelude::Entity for TlcErrDataOpt {
17391    type Builder = TlcErrDataOptBuilder;
17392    const NAME: &'static str = "TlcErrDataOpt";
17393    fn new_unchecked(data: molecule::bytes::Bytes) -> Self {
17394        TlcErrDataOpt(data)
17395    }
17396    fn as_bytes(&self) -> molecule::bytes::Bytes {
17397        self.0.clone()
17398    }
17399    fn as_slice(&self) -> &[u8] {
17400        &self.0[..]
17401    }
17402    fn from_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
17403        TlcErrDataOptReader::from_slice(slice).map(|reader| reader.to_entity())
17404    }
17405    fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
17406        TlcErrDataOptReader::from_compatible_slice(slice).map(|reader| reader.to_entity())
17407    }
17408    fn new_builder() -> Self::Builder {
17409        ::core::default::Default::default()
17410    }
17411    fn as_builder(self) -> Self::Builder {
17412        Self::new_builder().set(self.to_opt())
17413    }
17414}
17415#[derive(Clone, Copy)]
17416pub struct TlcErrDataOptReader<'r>(&'r [u8]);
17417impl<'r> ::core::fmt::LowerHex for TlcErrDataOptReader<'r> {
17418    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
17419        use molecule::hex_string;
17420        if f.alternate() {
17421            write!(f, "0x")?;
17422        }
17423        write!(f, "{}", hex_string(self.as_slice()))
17424    }
17425}
17426impl<'r> ::core::fmt::Debug for TlcErrDataOptReader<'r> {
17427    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
17428        write!(f, "{}({:#x})", Self::NAME, self)
17429    }
17430}
17431impl<'r> ::core::fmt::Display for TlcErrDataOptReader<'r> {
17432    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
17433        if let Some(v) = self.to_opt() {
17434            write!(f, "{}(Some({}))", Self::NAME, v)
17435        } else {
17436            write!(f, "{}(None)", Self::NAME)
17437        }
17438    }
17439}
17440impl<'r> TlcErrDataOptReader<'r> {
17441    pub fn is_none(&self) -> bool {
17442        self.0.is_empty()
17443    }
17444    pub fn is_some(&self) -> bool {
17445        !self.0.is_empty()
17446    }
17447    pub fn to_opt(&self) -> Option<TlcErrDataReader<'r>> {
17448        if self.is_none() {
17449            None
17450        } else {
17451            Some(TlcErrDataReader::new_unchecked(self.as_slice()))
17452        }
17453    }
17454}
17455impl<'r> molecule::prelude::Reader<'r> for TlcErrDataOptReader<'r> {
17456    type Entity = TlcErrDataOpt;
17457    const NAME: &'static str = "TlcErrDataOptReader";
17458    fn to_entity(&self) -> Self::Entity {
17459        Self::Entity::new_unchecked(self.as_slice().to_owned().into())
17460    }
17461    fn new_unchecked(slice: &'r [u8]) -> Self {
17462        TlcErrDataOptReader(slice)
17463    }
17464    fn as_slice(&self) -> &'r [u8] {
17465        self.0
17466    }
17467    fn verify(slice: &[u8], compatible: bool) -> molecule::error::VerificationResult<()> {
17468        if !slice.is_empty() {
17469            TlcErrDataReader::verify(&slice[..], compatible)?;
17470        }
17471        Ok(())
17472    }
17473}
17474#[derive(Clone, Debug, Default)]
17475pub struct TlcErrDataOptBuilder(pub(crate) Option<TlcErrData>);
17476impl TlcErrDataOptBuilder {
17477    pub fn set(mut self, v: Option<TlcErrData>) -> Self {
17478        self.0 = v;
17479        self
17480    }
17481}
17482impl molecule::prelude::Builder for TlcErrDataOptBuilder {
17483    type Entity = TlcErrDataOpt;
17484    const NAME: &'static str = "TlcErrDataOptBuilder";
17485    fn expected_length(&self) -> usize {
17486        self.0
17487            .as_ref()
17488            .map(|ref inner| inner.as_slice().len())
17489            .unwrap_or(0)
17490    }
17491    fn write<W: molecule::io::Write>(&self, writer: &mut W) -> molecule::io::Result<()> {
17492        self.0
17493            .as_ref()
17494            .map(|ref inner| writer.write_all(inner.as_slice()))
17495            .unwrap_or(Ok(()))
17496    }
17497    fn build(&self) -> Self::Entity {
17498        let mut inner = Vec::with_capacity(self.expected_length());
17499        self.write(&mut inner)
17500            .unwrap_or_else(|_| panic!("{} build should be ok", Self::NAME));
17501        TlcErrDataOpt::new_unchecked(inner.into())
17502    }
17503}
17504impl From<TlcErrData> for TlcErrDataOpt {
17505    fn from(value: TlcErrData) -> Self {
17506        Self::new_builder().set(Some(value)).build()
17507    }
17508}
17509#[derive(Clone)]
17510pub struct TlcErr(molecule::bytes::Bytes);
17511impl ::core::fmt::LowerHex for TlcErr {
17512    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
17513        use molecule::hex_string;
17514        if f.alternate() {
17515            write!(f, "0x")?;
17516        }
17517        write!(f, "{}", hex_string(self.as_slice()))
17518    }
17519}
17520impl ::core::fmt::Debug for TlcErr {
17521    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
17522        write!(f, "{}({:#x})", Self::NAME, self)
17523    }
17524}
17525impl ::core::fmt::Display for TlcErr {
17526    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
17527        write!(f, "{} {{ ", Self::NAME)?;
17528        write!(f, "{}: {}", "error_code", self.error_code())?;
17529        write!(f, ", {}: {}", "extra_data", self.extra_data())?;
17530        let extra_count = self.count_extra_fields();
17531        if extra_count != 0 {
17532            write!(f, ", .. ({} fields)", extra_count)?;
17533        }
17534        write!(f, " }}")
17535    }
17536}
17537impl ::core::default::Default for TlcErr {
17538    fn default() -> Self {
17539        let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE);
17540        TlcErr::new_unchecked(v)
17541    }
17542}
17543impl TlcErr {
17544    const DEFAULT_VALUE: [u8; 14] = [14, 0, 0, 0, 12, 0, 0, 0, 14, 0, 0, 0, 0, 0];
17545    pub const FIELD_COUNT: usize = 2;
17546    pub fn total_size(&self) -> usize {
17547        molecule::unpack_number(self.as_slice()) as usize
17548    }
17549    pub fn field_count(&self) -> usize {
17550        if self.total_size() == molecule::NUMBER_SIZE {
17551            0
17552        } else {
17553            (molecule::unpack_number(&self.as_slice()[molecule::NUMBER_SIZE..]) as usize / 4) - 1
17554        }
17555    }
17556    pub fn count_extra_fields(&self) -> usize {
17557        self.field_count() - Self::FIELD_COUNT
17558    }
17559    pub fn has_extra_fields(&self) -> bool {
17560        Self::FIELD_COUNT != self.field_count()
17561    }
17562    pub fn error_code(&self) -> Uint16 {
17563        let slice = self.as_slice();
17564        let start = molecule::unpack_number(&slice[4..]) as usize;
17565        let end = molecule::unpack_number(&slice[8..]) as usize;
17566        Uint16::new_unchecked(self.0.slice(start..end))
17567    }
17568    pub fn extra_data(&self) -> TlcErrDataOpt {
17569        let slice = self.as_slice();
17570        let start = molecule::unpack_number(&slice[8..]) as usize;
17571        if self.has_extra_fields() {
17572            let end = molecule::unpack_number(&slice[12..]) as usize;
17573            TlcErrDataOpt::new_unchecked(self.0.slice(start..end))
17574        } else {
17575            TlcErrDataOpt::new_unchecked(self.0.slice(start..))
17576        }
17577    }
17578    pub fn as_reader<'r>(&'r self) -> TlcErrReader<'r> {
17579        TlcErrReader::new_unchecked(self.as_slice())
17580    }
17581}
17582impl molecule::prelude::Entity for TlcErr {
17583    type Builder = TlcErrBuilder;
17584    const NAME: &'static str = "TlcErr";
17585    fn new_unchecked(data: molecule::bytes::Bytes) -> Self {
17586        TlcErr(data)
17587    }
17588    fn as_bytes(&self) -> molecule::bytes::Bytes {
17589        self.0.clone()
17590    }
17591    fn as_slice(&self) -> &[u8] {
17592        &self.0[..]
17593    }
17594    fn from_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
17595        TlcErrReader::from_slice(slice).map(|reader| reader.to_entity())
17596    }
17597    fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
17598        TlcErrReader::from_compatible_slice(slice).map(|reader| reader.to_entity())
17599    }
17600    fn new_builder() -> Self::Builder {
17601        ::core::default::Default::default()
17602    }
17603    fn as_builder(self) -> Self::Builder {
17604        Self::new_builder()
17605            .error_code(self.error_code())
17606            .extra_data(self.extra_data())
17607    }
17608}
17609#[derive(Clone, Copy)]
17610pub struct TlcErrReader<'r>(&'r [u8]);
17611impl<'r> ::core::fmt::LowerHex for TlcErrReader<'r> {
17612    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
17613        use molecule::hex_string;
17614        if f.alternate() {
17615            write!(f, "0x")?;
17616        }
17617        write!(f, "{}", hex_string(self.as_slice()))
17618    }
17619}
17620impl<'r> ::core::fmt::Debug for TlcErrReader<'r> {
17621    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
17622        write!(f, "{}({:#x})", Self::NAME, self)
17623    }
17624}
17625impl<'r> ::core::fmt::Display for TlcErrReader<'r> {
17626    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
17627        write!(f, "{} {{ ", Self::NAME)?;
17628        write!(f, "{}: {}", "error_code", self.error_code())?;
17629        write!(f, ", {}: {}", "extra_data", self.extra_data())?;
17630        let extra_count = self.count_extra_fields();
17631        if extra_count != 0 {
17632            write!(f, ", .. ({} fields)", extra_count)?;
17633        }
17634        write!(f, " }}")
17635    }
17636}
17637impl<'r> TlcErrReader<'r> {
17638    pub const FIELD_COUNT: usize = 2;
17639    pub fn total_size(&self) -> usize {
17640        molecule::unpack_number(self.as_slice()) as usize
17641    }
17642    pub fn field_count(&self) -> usize {
17643        if self.total_size() == molecule::NUMBER_SIZE {
17644            0
17645        } else {
17646            (molecule::unpack_number(&self.as_slice()[molecule::NUMBER_SIZE..]) as usize / 4) - 1
17647        }
17648    }
17649    pub fn count_extra_fields(&self) -> usize {
17650        self.field_count() - Self::FIELD_COUNT
17651    }
17652    pub fn has_extra_fields(&self) -> bool {
17653        Self::FIELD_COUNT != self.field_count()
17654    }
17655    pub fn error_code(&self) -> Uint16Reader<'r> {
17656        let slice = self.as_slice();
17657        let start = molecule::unpack_number(&slice[4..]) as usize;
17658        let end = molecule::unpack_number(&slice[8..]) as usize;
17659        Uint16Reader::new_unchecked(&self.as_slice()[start..end])
17660    }
17661    pub fn extra_data(&self) -> TlcErrDataOptReader<'r> {
17662        let slice = self.as_slice();
17663        let start = molecule::unpack_number(&slice[8..]) as usize;
17664        if self.has_extra_fields() {
17665            let end = molecule::unpack_number(&slice[12..]) as usize;
17666            TlcErrDataOptReader::new_unchecked(&self.as_slice()[start..end])
17667        } else {
17668            TlcErrDataOptReader::new_unchecked(&self.as_slice()[start..])
17669        }
17670    }
17671}
17672impl<'r> molecule::prelude::Reader<'r> for TlcErrReader<'r> {
17673    type Entity = TlcErr;
17674    const NAME: &'static str = "TlcErrReader";
17675    fn to_entity(&self) -> Self::Entity {
17676        Self::Entity::new_unchecked(self.as_slice().to_owned().into())
17677    }
17678    fn new_unchecked(slice: &'r [u8]) -> Self {
17679        TlcErrReader(slice)
17680    }
17681    fn as_slice(&self) -> &'r [u8] {
17682        self.0
17683    }
17684    fn verify(slice: &[u8], compatible: bool) -> molecule::error::VerificationResult<()> {
17685        use molecule::verification_error as ve;
17686        let slice_len = slice.len();
17687        if slice_len < molecule::NUMBER_SIZE {
17688            return ve!(Self, HeaderIsBroken, molecule::NUMBER_SIZE, slice_len);
17689        }
17690        let total_size = molecule::unpack_number(slice) as usize;
17691        if slice_len != total_size {
17692            return ve!(Self, TotalSizeNotMatch, total_size, slice_len);
17693        }
17694        if slice_len < molecule::NUMBER_SIZE * 2 {
17695            return ve!(Self, HeaderIsBroken, molecule::NUMBER_SIZE * 2, slice_len);
17696        }
17697        let offset_first = molecule::unpack_number(&slice[molecule::NUMBER_SIZE..]) as usize;
17698        if offset_first % molecule::NUMBER_SIZE != 0 || offset_first < molecule::NUMBER_SIZE * 2 {
17699            return ve!(Self, OffsetsNotMatch);
17700        }
17701        if slice_len < offset_first {
17702            return ve!(Self, HeaderIsBroken, offset_first, slice_len);
17703        }
17704        let field_count = offset_first / molecule::NUMBER_SIZE - 1;
17705        if field_count < Self::FIELD_COUNT {
17706            return ve!(Self, FieldCountNotMatch, Self::FIELD_COUNT, field_count);
17707        } else if !compatible && field_count > Self::FIELD_COUNT {
17708            return ve!(Self, FieldCountNotMatch, Self::FIELD_COUNT, field_count);
17709        };
17710        let mut offsets: Vec<usize> = slice[molecule::NUMBER_SIZE..offset_first]
17711            .chunks_exact(molecule::NUMBER_SIZE)
17712            .map(|x| molecule::unpack_number(x) as usize)
17713            .collect();
17714        offsets.push(total_size);
17715        if offsets.windows(2).any(|i| i[0] > i[1]) {
17716            return ve!(Self, OffsetsNotMatch);
17717        }
17718        Uint16Reader::verify(&slice[offsets[0]..offsets[1]], compatible)?;
17719        TlcErrDataOptReader::verify(&slice[offsets[1]..offsets[2]], compatible)?;
17720        Ok(())
17721    }
17722}
17723#[derive(Clone, Debug, Default)]
17724pub struct TlcErrBuilder {
17725    pub(crate) error_code: Uint16,
17726    pub(crate) extra_data: TlcErrDataOpt,
17727}
17728impl TlcErrBuilder {
17729    pub const FIELD_COUNT: usize = 2;
17730    pub fn error_code(mut self, v: Uint16) -> Self {
17731        self.error_code = v;
17732        self
17733    }
17734    pub fn extra_data(mut self, v: TlcErrDataOpt) -> Self {
17735        self.extra_data = v;
17736        self
17737    }
17738}
17739impl molecule::prelude::Builder for TlcErrBuilder {
17740    type Entity = TlcErr;
17741    const NAME: &'static str = "TlcErrBuilder";
17742    fn expected_length(&self) -> usize {
17743        molecule::NUMBER_SIZE * (Self::FIELD_COUNT + 1)
17744            + self.error_code.as_slice().len()
17745            + self.extra_data.as_slice().len()
17746    }
17747    fn write<W: molecule::io::Write>(&self, writer: &mut W) -> molecule::io::Result<()> {
17748        let mut total_size = molecule::NUMBER_SIZE * (Self::FIELD_COUNT + 1);
17749        let mut offsets = Vec::with_capacity(Self::FIELD_COUNT);
17750        offsets.push(total_size);
17751        total_size += self.error_code.as_slice().len();
17752        offsets.push(total_size);
17753        total_size += self.extra_data.as_slice().len();
17754        writer.write_all(&molecule::pack_number(total_size as molecule::Number))?;
17755        for offset in offsets.into_iter() {
17756            writer.write_all(&molecule::pack_number(offset as molecule::Number))?;
17757        }
17758        writer.write_all(self.error_code.as_slice())?;
17759        writer.write_all(self.extra_data.as_slice())?;
17760        Ok(())
17761    }
17762    fn build(&self) -> Self::Entity {
17763        let mut inner = Vec::with_capacity(self.expected_length());
17764        self.write(&mut inner)
17765            .unwrap_or_else(|_| panic!("{} build should be ok", Self::NAME));
17766        TlcErr::new_unchecked(inner.into())
17767    }
17768}