Skip to main content

fiber_types/gen/
invoice.rs

1// Generated by Molecule 0.8.0
2
3use super::blockchain::*;
4use molecule::prelude::*;
5#[derive(Clone)]
6pub struct PaymentHash(molecule::bytes::Bytes);
7impl ::core::fmt::LowerHex for PaymentHash {
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 PaymentHash {
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 PaymentHash {
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 PaymentHash {
29    fn default() -> Self {
30        let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE);
31        PaymentHash::new_unchecked(v)
32    }
33}
34impl PaymentHash {
35    const DEFAULT_VALUE: [u8; 32] = [
36        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
37        0, 0,
38    ];
39    pub const TOTAL_SIZE: usize = 32;
40    pub const ITEM_SIZE: usize = 1;
41    pub const ITEM_COUNT: usize = 32;
42    pub fn nth0(&self) -> Byte {
43        Byte::new_unchecked(self.0.slice(0..1))
44    }
45    pub fn nth1(&self) -> Byte {
46        Byte::new_unchecked(self.0.slice(1..2))
47    }
48    pub fn nth2(&self) -> Byte {
49        Byte::new_unchecked(self.0.slice(2..3))
50    }
51    pub fn nth3(&self) -> Byte {
52        Byte::new_unchecked(self.0.slice(3..4))
53    }
54    pub fn nth4(&self) -> Byte {
55        Byte::new_unchecked(self.0.slice(4..5))
56    }
57    pub fn nth5(&self) -> Byte {
58        Byte::new_unchecked(self.0.slice(5..6))
59    }
60    pub fn nth6(&self) -> Byte {
61        Byte::new_unchecked(self.0.slice(6..7))
62    }
63    pub fn nth7(&self) -> Byte {
64        Byte::new_unchecked(self.0.slice(7..8))
65    }
66    pub fn nth8(&self) -> Byte {
67        Byte::new_unchecked(self.0.slice(8..9))
68    }
69    pub fn nth9(&self) -> Byte {
70        Byte::new_unchecked(self.0.slice(9..10))
71    }
72    pub fn nth10(&self) -> Byte {
73        Byte::new_unchecked(self.0.slice(10..11))
74    }
75    pub fn nth11(&self) -> Byte {
76        Byte::new_unchecked(self.0.slice(11..12))
77    }
78    pub fn nth12(&self) -> Byte {
79        Byte::new_unchecked(self.0.slice(12..13))
80    }
81    pub fn nth13(&self) -> Byte {
82        Byte::new_unchecked(self.0.slice(13..14))
83    }
84    pub fn nth14(&self) -> Byte {
85        Byte::new_unchecked(self.0.slice(14..15))
86    }
87    pub fn nth15(&self) -> Byte {
88        Byte::new_unchecked(self.0.slice(15..16))
89    }
90    pub fn nth16(&self) -> Byte {
91        Byte::new_unchecked(self.0.slice(16..17))
92    }
93    pub fn nth17(&self) -> Byte {
94        Byte::new_unchecked(self.0.slice(17..18))
95    }
96    pub fn nth18(&self) -> Byte {
97        Byte::new_unchecked(self.0.slice(18..19))
98    }
99    pub fn nth19(&self) -> Byte {
100        Byte::new_unchecked(self.0.slice(19..20))
101    }
102    pub fn nth20(&self) -> Byte {
103        Byte::new_unchecked(self.0.slice(20..21))
104    }
105    pub fn nth21(&self) -> Byte {
106        Byte::new_unchecked(self.0.slice(21..22))
107    }
108    pub fn nth22(&self) -> Byte {
109        Byte::new_unchecked(self.0.slice(22..23))
110    }
111    pub fn nth23(&self) -> Byte {
112        Byte::new_unchecked(self.0.slice(23..24))
113    }
114    pub fn nth24(&self) -> Byte {
115        Byte::new_unchecked(self.0.slice(24..25))
116    }
117    pub fn nth25(&self) -> Byte {
118        Byte::new_unchecked(self.0.slice(25..26))
119    }
120    pub fn nth26(&self) -> Byte {
121        Byte::new_unchecked(self.0.slice(26..27))
122    }
123    pub fn nth27(&self) -> Byte {
124        Byte::new_unchecked(self.0.slice(27..28))
125    }
126    pub fn nth28(&self) -> Byte {
127        Byte::new_unchecked(self.0.slice(28..29))
128    }
129    pub fn nth29(&self) -> Byte {
130        Byte::new_unchecked(self.0.slice(29..30))
131    }
132    pub fn nth30(&self) -> Byte {
133        Byte::new_unchecked(self.0.slice(30..31))
134    }
135    pub fn nth31(&self) -> Byte {
136        Byte::new_unchecked(self.0.slice(31..32))
137    }
138    pub fn raw_data(&self) -> molecule::bytes::Bytes {
139        self.as_bytes()
140    }
141    pub fn as_reader<'r>(&'r self) -> PaymentHashReader<'r> {
142        PaymentHashReader::new_unchecked(self.as_slice())
143    }
144}
145impl molecule::prelude::Entity for PaymentHash {
146    type Builder = PaymentHashBuilder;
147    const NAME: &'static str = "PaymentHash";
148    fn new_unchecked(data: molecule::bytes::Bytes) -> Self {
149        PaymentHash(data)
150    }
151    fn as_bytes(&self) -> molecule::bytes::Bytes {
152        self.0.clone()
153    }
154    fn as_slice(&self) -> &[u8] {
155        &self.0[..]
156    }
157    fn from_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
158        PaymentHashReader::from_slice(slice).map(|reader| reader.to_entity())
159    }
160    fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
161        PaymentHashReader::from_compatible_slice(slice).map(|reader| reader.to_entity())
162    }
163    fn new_builder() -> Self::Builder {
164        ::core::default::Default::default()
165    }
166    fn as_builder(self) -> Self::Builder {
167        Self::new_builder().set([
168            self.nth0(),
169            self.nth1(),
170            self.nth2(),
171            self.nth3(),
172            self.nth4(),
173            self.nth5(),
174            self.nth6(),
175            self.nth7(),
176            self.nth8(),
177            self.nth9(),
178            self.nth10(),
179            self.nth11(),
180            self.nth12(),
181            self.nth13(),
182            self.nth14(),
183            self.nth15(),
184            self.nth16(),
185            self.nth17(),
186            self.nth18(),
187            self.nth19(),
188            self.nth20(),
189            self.nth21(),
190            self.nth22(),
191            self.nth23(),
192            self.nth24(),
193            self.nth25(),
194            self.nth26(),
195            self.nth27(),
196            self.nth28(),
197            self.nth29(),
198            self.nth30(),
199            self.nth31(),
200        ])
201    }
202}
203#[derive(Clone, Copy)]
204pub struct PaymentHashReader<'r>(&'r [u8]);
205impl<'r> ::core::fmt::LowerHex for PaymentHashReader<'r> {
206    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
207        use molecule::hex_string;
208        if f.alternate() {
209            write!(f, "0x")?;
210        }
211        write!(f, "{}", hex_string(self.as_slice()))
212    }
213}
214impl<'r> ::core::fmt::Debug for PaymentHashReader<'r> {
215    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
216        write!(f, "{}({:#x})", Self::NAME, self)
217    }
218}
219impl<'r> ::core::fmt::Display for PaymentHashReader<'r> {
220    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
221        use molecule::hex_string;
222        let raw_data = hex_string(&self.raw_data());
223        write!(f, "{}(0x{})", Self::NAME, raw_data)
224    }
225}
226impl<'r> PaymentHashReader<'r> {
227    pub const TOTAL_SIZE: usize = 32;
228    pub const ITEM_SIZE: usize = 1;
229    pub const ITEM_COUNT: usize = 32;
230    pub fn nth0(&self) -> ByteReader<'r> {
231        ByteReader::new_unchecked(&self.as_slice()[0..1])
232    }
233    pub fn nth1(&self) -> ByteReader<'r> {
234        ByteReader::new_unchecked(&self.as_slice()[1..2])
235    }
236    pub fn nth2(&self) -> ByteReader<'r> {
237        ByteReader::new_unchecked(&self.as_slice()[2..3])
238    }
239    pub fn nth3(&self) -> ByteReader<'r> {
240        ByteReader::new_unchecked(&self.as_slice()[3..4])
241    }
242    pub fn nth4(&self) -> ByteReader<'r> {
243        ByteReader::new_unchecked(&self.as_slice()[4..5])
244    }
245    pub fn nth5(&self) -> ByteReader<'r> {
246        ByteReader::new_unchecked(&self.as_slice()[5..6])
247    }
248    pub fn nth6(&self) -> ByteReader<'r> {
249        ByteReader::new_unchecked(&self.as_slice()[6..7])
250    }
251    pub fn nth7(&self) -> ByteReader<'r> {
252        ByteReader::new_unchecked(&self.as_slice()[7..8])
253    }
254    pub fn nth8(&self) -> ByteReader<'r> {
255        ByteReader::new_unchecked(&self.as_slice()[8..9])
256    }
257    pub fn nth9(&self) -> ByteReader<'r> {
258        ByteReader::new_unchecked(&self.as_slice()[9..10])
259    }
260    pub fn nth10(&self) -> ByteReader<'r> {
261        ByteReader::new_unchecked(&self.as_slice()[10..11])
262    }
263    pub fn nth11(&self) -> ByteReader<'r> {
264        ByteReader::new_unchecked(&self.as_slice()[11..12])
265    }
266    pub fn nth12(&self) -> ByteReader<'r> {
267        ByteReader::new_unchecked(&self.as_slice()[12..13])
268    }
269    pub fn nth13(&self) -> ByteReader<'r> {
270        ByteReader::new_unchecked(&self.as_slice()[13..14])
271    }
272    pub fn nth14(&self) -> ByteReader<'r> {
273        ByteReader::new_unchecked(&self.as_slice()[14..15])
274    }
275    pub fn nth15(&self) -> ByteReader<'r> {
276        ByteReader::new_unchecked(&self.as_slice()[15..16])
277    }
278    pub fn nth16(&self) -> ByteReader<'r> {
279        ByteReader::new_unchecked(&self.as_slice()[16..17])
280    }
281    pub fn nth17(&self) -> ByteReader<'r> {
282        ByteReader::new_unchecked(&self.as_slice()[17..18])
283    }
284    pub fn nth18(&self) -> ByteReader<'r> {
285        ByteReader::new_unchecked(&self.as_slice()[18..19])
286    }
287    pub fn nth19(&self) -> ByteReader<'r> {
288        ByteReader::new_unchecked(&self.as_slice()[19..20])
289    }
290    pub fn nth20(&self) -> ByteReader<'r> {
291        ByteReader::new_unchecked(&self.as_slice()[20..21])
292    }
293    pub fn nth21(&self) -> ByteReader<'r> {
294        ByteReader::new_unchecked(&self.as_slice()[21..22])
295    }
296    pub fn nth22(&self) -> ByteReader<'r> {
297        ByteReader::new_unchecked(&self.as_slice()[22..23])
298    }
299    pub fn nth23(&self) -> ByteReader<'r> {
300        ByteReader::new_unchecked(&self.as_slice()[23..24])
301    }
302    pub fn nth24(&self) -> ByteReader<'r> {
303        ByteReader::new_unchecked(&self.as_slice()[24..25])
304    }
305    pub fn nth25(&self) -> ByteReader<'r> {
306        ByteReader::new_unchecked(&self.as_slice()[25..26])
307    }
308    pub fn nth26(&self) -> ByteReader<'r> {
309        ByteReader::new_unchecked(&self.as_slice()[26..27])
310    }
311    pub fn nth27(&self) -> ByteReader<'r> {
312        ByteReader::new_unchecked(&self.as_slice()[27..28])
313    }
314    pub fn nth28(&self) -> ByteReader<'r> {
315        ByteReader::new_unchecked(&self.as_slice()[28..29])
316    }
317    pub fn nth29(&self) -> ByteReader<'r> {
318        ByteReader::new_unchecked(&self.as_slice()[29..30])
319    }
320    pub fn nth30(&self) -> ByteReader<'r> {
321        ByteReader::new_unchecked(&self.as_slice()[30..31])
322    }
323    pub fn nth31(&self) -> ByteReader<'r> {
324        ByteReader::new_unchecked(&self.as_slice()[31..32])
325    }
326    pub fn raw_data(&self) -> &'r [u8] {
327        self.as_slice()
328    }
329}
330impl<'r> molecule::prelude::Reader<'r> for PaymentHashReader<'r> {
331    type Entity = PaymentHash;
332    const NAME: &'static str = "PaymentHashReader";
333    fn to_entity(&self) -> Self::Entity {
334        Self::Entity::new_unchecked(self.as_slice().to_owned().into())
335    }
336    fn new_unchecked(slice: &'r [u8]) -> Self {
337        PaymentHashReader(slice)
338    }
339    fn as_slice(&self) -> &'r [u8] {
340        self.0
341    }
342    fn verify(slice: &[u8], _compatible: bool) -> molecule::error::VerificationResult<()> {
343        use molecule::verification_error as ve;
344        let slice_len = slice.len();
345        if slice_len != Self::TOTAL_SIZE {
346            return ve!(Self, TotalSizeNotMatch, Self::TOTAL_SIZE, slice_len);
347        }
348        Ok(())
349    }
350}
351#[derive(Clone)]
352pub struct PaymentHashBuilder(pub(crate) [Byte; 32]);
353impl ::core::fmt::Debug for PaymentHashBuilder {
354    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
355        write!(f, "{}({:?})", Self::NAME, &self.0[..])
356    }
357}
358impl ::core::default::Default for PaymentHashBuilder {
359    fn default() -> Self {
360        PaymentHashBuilder([
361            Byte::default(),
362            Byte::default(),
363            Byte::default(),
364            Byte::default(),
365            Byte::default(),
366            Byte::default(),
367            Byte::default(),
368            Byte::default(),
369            Byte::default(),
370            Byte::default(),
371            Byte::default(),
372            Byte::default(),
373            Byte::default(),
374            Byte::default(),
375            Byte::default(),
376            Byte::default(),
377            Byte::default(),
378            Byte::default(),
379            Byte::default(),
380            Byte::default(),
381            Byte::default(),
382            Byte::default(),
383            Byte::default(),
384            Byte::default(),
385            Byte::default(),
386            Byte::default(),
387            Byte::default(),
388            Byte::default(),
389            Byte::default(),
390            Byte::default(),
391            Byte::default(),
392            Byte::default(),
393        ])
394    }
395}
396impl PaymentHashBuilder {
397    pub const TOTAL_SIZE: usize = 32;
398    pub const ITEM_SIZE: usize = 1;
399    pub const ITEM_COUNT: usize = 32;
400    pub fn set(mut self, v: [Byte; 32]) -> Self {
401        self.0 = v;
402        self
403    }
404    pub fn nth0(mut self, v: Byte) -> Self {
405        self.0[0] = v;
406        self
407    }
408    pub fn nth1(mut self, v: Byte) -> Self {
409        self.0[1] = v;
410        self
411    }
412    pub fn nth2(mut self, v: Byte) -> Self {
413        self.0[2] = v;
414        self
415    }
416    pub fn nth3(mut self, v: Byte) -> Self {
417        self.0[3] = v;
418        self
419    }
420    pub fn nth4(mut self, v: Byte) -> Self {
421        self.0[4] = v;
422        self
423    }
424    pub fn nth5(mut self, v: Byte) -> Self {
425        self.0[5] = v;
426        self
427    }
428    pub fn nth6(mut self, v: Byte) -> Self {
429        self.0[6] = v;
430        self
431    }
432    pub fn nth7(mut self, v: Byte) -> Self {
433        self.0[7] = v;
434        self
435    }
436    pub fn nth8(mut self, v: Byte) -> Self {
437        self.0[8] = v;
438        self
439    }
440    pub fn nth9(mut self, v: Byte) -> Self {
441        self.0[9] = v;
442        self
443    }
444    pub fn nth10(mut self, v: Byte) -> Self {
445        self.0[10] = v;
446        self
447    }
448    pub fn nth11(mut self, v: Byte) -> Self {
449        self.0[11] = v;
450        self
451    }
452    pub fn nth12(mut self, v: Byte) -> Self {
453        self.0[12] = v;
454        self
455    }
456    pub fn nth13(mut self, v: Byte) -> Self {
457        self.0[13] = v;
458        self
459    }
460    pub fn nth14(mut self, v: Byte) -> Self {
461        self.0[14] = v;
462        self
463    }
464    pub fn nth15(mut self, v: Byte) -> Self {
465        self.0[15] = v;
466        self
467    }
468    pub fn nth16(mut self, v: Byte) -> Self {
469        self.0[16] = v;
470        self
471    }
472    pub fn nth17(mut self, v: Byte) -> Self {
473        self.0[17] = v;
474        self
475    }
476    pub fn nth18(mut self, v: Byte) -> Self {
477        self.0[18] = v;
478        self
479    }
480    pub fn nth19(mut self, v: Byte) -> Self {
481        self.0[19] = v;
482        self
483    }
484    pub fn nth20(mut self, v: Byte) -> Self {
485        self.0[20] = v;
486        self
487    }
488    pub fn nth21(mut self, v: Byte) -> Self {
489        self.0[21] = v;
490        self
491    }
492    pub fn nth22(mut self, v: Byte) -> Self {
493        self.0[22] = v;
494        self
495    }
496    pub fn nth23(mut self, v: Byte) -> Self {
497        self.0[23] = v;
498        self
499    }
500    pub fn nth24(mut self, v: Byte) -> Self {
501        self.0[24] = v;
502        self
503    }
504    pub fn nth25(mut self, v: Byte) -> Self {
505        self.0[25] = v;
506        self
507    }
508    pub fn nth26(mut self, v: Byte) -> Self {
509        self.0[26] = v;
510        self
511    }
512    pub fn nth27(mut self, v: Byte) -> Self {
513        self.0[27] = v;
514        self
515    }
516    pub fn nth28(mut self, v: Byte) -> Self {
517        self.0[28] = v;
518        self
519    }
520    pub fn nth29(mut self, v: Byte) -> Self {
521        self.0[29] = v;
522        self
523    }
524    pub fn nth30(mut self, v: Byte) -> Self {
525        self.0[30] = v;
526        self
527    }
528    pub fn nth31(mut self, v: Byte) -> Self {
529        self.0[31] = v;
530        self
531    }
532}
533impl molecule::prelude::Builder for PaymentHashBuilder {
534    type Entity = PaymentHash;
535    const NAME: &'static str = "PaymentHashBuilder";
536    fn expected_length(&self) -> usize {
537        Self::TOTAL_SIZE
538    }
539    fn write<W: molecule::io::Write>(&self, writer: &mut W) -> molecule::io::Result<()> {
540        writer.write_all(self.0[0].as_slice())?;
541        writer.write_all(self.0[1].as_slice())?;
542        writer.write_all(self.0[2].as_slice())?;
543        writer.write_all(self.0[3].as_slice())?;
544        writer.write_all(self.0[4].as_slice())?;
545        writer.write_all(self.0[5].as_slice())?;
546        writer.write_all(self.0[6].as_slice())?;
547        writer.write_all(self.0[7].as_slice())?;
548        writer.write_all(self.0[8].as_slice())?;
549        writer.write_all(self.0[9].as_slice())?;
550        writer.write_all(self.0[10].as_slice())?;
551        writer.write_all(self.0[11].as_slice())?;
552        writer.write_all(self.0[12].as_slice())?;
553        writer.write_all(self.0[13].as_slice())?;
554        writer.write_all(self.0[14].as_slice())?;
555        writer.write_all(self.0[15].as_slice())?;
556        writer.write_all(self.0[16].as_slice())?;
557        writer.write_all(self.0[17].as_slice())?;
558        writer.write_all(self.0[18].as_slice())?;
559        writer.write_all(self.0[19].as_slice())?;
560        writer.write_all(self.0[20].as_slice())?;
561        writer.write_all(self.0[21].as_slice())?;
562        writer.write_all(self.0[22].as_slice())?;
563        writer.write_all(self.0[23].as_slice())?;
564        writer.write_all(self.0[24].as_slice())?;
565        writer.write_all(self.0[25].as_slice())?;
566        writer.write_all(self.0[26].as_slice())?;
567        writer.write_all(self.0[27].as_slice())?;
568        writer.write_all(self.0[28].as_slice())?;
569        writer.write_all(self.0[29].as_slice())?;
570        writer.write_all(self.0[30].as_slice())?;
571        writer.write_all(self.0[31].as_slice())?;
572        Ok(())
573    }
574    fn build(&self) -> Self::Entity {
575        let mut inner = Vec::with_capacity(self.expected_length());
576        self.write(&mut inner)
577            .unwrap_or_else(|_| panic!("{} build should be ok", Self::NAME));
578        PaymentHash::new_unchecked(inner.into())
579    }
580}
581impl From<[Byte; 32usize]> for PaymentHash {
582    fn from(value: [Byte; 32usize]) -> Self {
583        Self::new_builder().set(value).build()
584    }
585}
586impl ::core::convert::TryFrom<&[Byte]> for PaymentHash {
587    type Error = ::core::array::TryFromSliceError;
588    fn try_from(value: &[Byte]) -> Result<Self, ::core::array::TryFromSliceError> {
589        Ok(Self::new_builder()
590            .set(<&[Byte; 32usize]>::try_from(value)?.clone())
591            .build())
592    }
593}
594impl From<PaymentHash> for [Byte; 32usize] {
595    #[track_caller]
596    fn from(value: PaymentHash) -> Self {
597        [
598            value.nth0(),
599            value.nth1(),
600            value.nth2(),
601            value.nth3(),
602            value.nth4(),
603            value.nth5(),
604            value.nth6(),
605            value.nth7(),
606            value.nth8(),
607            value.nth9(),
608            value.nth10(),
609            value.nth11(),
610            value.nth12(),
611            value.nth13(),
612            value.nth14(),
613            value.nth15(),
614            value.nth16(),
615            value.nth17(),
616            value.nth18(),
617            value.nth19(),
618            value.nth20(),
619            value.nth21(),
620            value.nth22(),
621            value.nth23(),
622            value.nth24(),
623            value.nth25(),
624            value.nth26(),
625            value.nth27(),
626            value.nth28(),
627            value.nth29(),
628            value.nth30(),
629            value.nth31(),
630        ]
631    }
632}
633impl From<[u8; 32usize]> for PaymentHash {
634    fn from(value: [u8; 32usize]) -> Self {
635        PaymentHashReader::new_unchecked(&value).to_entity()
636    }
637}
638impl ::core::convert::TryFrom<&[u8]> for PaymentHash {
639    type Error = ::core::array::TryFromSliceError;
640    fn try_from(value: &[u8]) -> Result<Self, ::core::array::TryFromSliceError> {
641        Ok(<[u8; 32usize]>::try_from(value)?.into())
642    }
643}
644impl From<PaymentHash> for [u8; 32usize] {
645    #[track_caller]
646    fn from(value: PaymentHash) -> Self {
647        ::core::convert::TryFrom::try_from(value.as_slice()).unwrap()
648    }
649}
650impl<'a> From<PaymentHashReader<'a>> for &'a [u8; 32usize] {
651    #[track_caller]
652    fn from(value: PaymentHashReader<'a>) -> Self {
653        ::core::convert::TryFrom::try_from(value.as_slice()).unwrap()
654    }
655}
656impl<'a> From<&'a PaymentHashReader<'a>> for &'a [u8; 32usize] {
657    #[track_caller]
658    fn from(value: &'a PaymentHashReader<'a>) -> Self {
659        ::core::convert::TryFrom::try_from(value.as_slice()).unwrap()
660    }
661}
662#[derive(Clone)]
663pub struct Signature(molecule::bytes::Bytes);
664impl ::core::fmt::LowerHex for Signature {
665    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
666        use molecule::hex_string;
667        if f.alternate() {
668            write!(f, "0x")?;
669        }
670        write!(f, "{}", hex_string(self.as_slice()))
671    }
672}
673impl ::core::fmt::Debug for Signature {
674    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
675        write!(f, "{}({:#x})", Self::NAME, self)
676    }
677}
678impl ::core::fmt::Display for Signature {
679    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
680        use molecule::hex_string;
681        let raw_data = hex_string(&self.raw_data());
682        write!(f, "{}(0x{})", Self::NAME, raw_data)
683    }
684}
685impl ::core::default::Default for Signature {
686    fn default() -> Self {
687        let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE);
688        Signature::new_unchecked(v)
689    }
690}
691impl Signature {
692    const DEFAULT_VALUE: [u8; 104] = [
693        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
694        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
695        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
696        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
697    ];
698    pub const TOTAL_SIZE: usize = 104;
699    pub const ITEM_SIZE: usize = 1;
700    pub const ITEM_COUNT: usize = 104;
701    pub fn nth0(&self) -> Byte {
702        Byte::new_unchecked(self.0.slice(0..1))
703    }
704    pub fn nth1(&self) -> Byte {
705        Byte::new_unchecked(self.0.slice(1..2))
706    }
707    pub fn nth2(&self) -> Byte {
708        Byte::new_unchecked(self.0.slice(2..3))
709    }
710    pub fn nth3(&self) -> Byte {
711        Byte::new_unchecked(self.0.slice(3..4))
712    }
713    pub fn nth4(&self) -> Byte {
714        Byte::new_unchecked(self.0.slice(4..5))
715    }
716    pub fn nth5(&self) -> Byte {
717        Byte::new_unchecked(self.0.slice(5..6))
718    }
719    pub fn nth6(&self) -> Byte {
720        Byte::new_unchecked(self.0.slice(6..7))
721    }
722    pub fn nth7(&self) -> Byte {
723        Byte::new_unchecked(self.0.slice(7..8))
724    }
725    pub fn nth8(&self) -> Byte {
726        Byte::new_unchecked(self.0.slice(8..9))
727    }
728    pub fn nth9(&self) -> Byte {
729        Byte::new_unchecked(self.0.slice(9..10))
730    }
731    pub fn nth10(&self) -> Byte {
732        Byte::new_unchecked(self.0.slice(10..11))
733    }
734    pub fn nth11(&self) -> Byte {
735        Byte::new_unchecked(self.0.slice(11..12))
736    }
737    pub fn nth12(&self) -> Byte {
738        Byte::new_unchecked(self.0.slice(12..13))
739    }
740    pub fn nth13(&self) -> Byte {
741        Byte::new_unchecked(self.0.slice(13..14))
742    }
743    pub fn nth14(&self) -> Byte {
744        Byte::new_unchecked(self.0.slice(14..15))
745    }
746    pub fn nth15(&self) -> Byte {
747        Byte::new_unchecked(self.0.slice(15..16))
748    }
749    pub fn nth16(&self) -> Byte {
750        Byte::new_unchecked(self.0.slice(16..17))
751    }
752    pub fn nth17(&self) -> Byte {
753        Byte::new_unchecked(self.0.slice(17..18))
754    }
755    pub fn nth18(&self) -> Byte {
756        Byte::new_unchecked(self.0.slice(18..19))
757    }
758    pub fn nth19(&self) -> Byte {
759        Byte::new_unchecked(self.0.slice(19..20))
760    }
761    pub fn nth20(&self) -> Byte {
762        Byte::new_unchecked(self.0.slice(20..21))
763    }
764    pub fn nth21(&self) -> Byte {
765        Byte::new_unchecked(self.0.slice(21..22))
766    }
767    pub fn nth22(&self) -> Byte {
768        Byte::new_unchecked(self.0.slice(22..23))
769    }
770    pub fn nth23(&self) -> Byte {
771        Byte::new_unchecked(self.0.slice(23..24))
772    }
773    pub fn nth24(&self) -> Byte {
774        Byte::new_unchecked(self.0.slice(24..25))
775    }
776    pub fn nth25(&self) -> Byte {
777        Byte::new_unchecked(self.0.slice(25..26))
778    }
779    pub fn nth26(&self) -> Byte {
780        Byte::new_unchecked(self.0.slice(26..27))
781    }
782    pub fn nth27(&self) -> Byte {
783        Byte::new_unchecked(self.0.slice(27..28))
784    }
785    pub fn nth28(&self) -> Byte {
786        Byte::new_unchecked(self.0.slice(28..29))
787    }
788    pub fn nth29(&self) -> Byte {
789        Byte::new_unchecked(self.0.slice(29..30))
790    }
791    pub fn nth30(&self) -> Byte {
792        Byte::new_unchecked(self.0.slice(30..31))
793    }
794    pub fn nth31(&self) -> Byte {
795        Byte::new_unchecked(self.0.slice(31..32))
796    }
797    pub fn nth32(&self) -> Byte {
798        Byte::new_unchecked(self.0.slice(32..33))
799    }
800    pub fn nth33(&self) -> Byte {
801        Byte::new_unchecked(self.0.slice(33..34))
802    }
803    pub fn nth34(&self) -> Byte {
804        Byte::new_unchecked(self.0.slice(34..35))
805    }
806    pub fn nth35(&self) -> Byte {
807        Byte::new_unchecked(self.0.slice(35..36))
808    }
809    pub fn nth36(&self) -> Byte {
810        Byte::new_unchecked(self.0.slice(36..37))
811    }
812    pub fn nth37(&self) -> Byte {
813        Byte::new_unchecked(self.0.slice(37..38))
814    }
815    pub fn nth38(&self) -> Byte {
816        Byte::new_unchecked(self.0.slice(38..39))
817    }
818    pub fn nth39(&self) -> Byte {
819        Byte::new_unchecked(self.0.slice(39..40))
820    }
821    pub fn nth40(&self) -> Byte {
822        Byte::new_unchecked(self.0.slice(40..41))
823    }
824    pub fn nth41(&self) -> Byte {
825        Byte::new_unchecked(self.0.slice(41..42))
826    }
827    pub fn nth42(&self) -> Byte {
828        Byte::new_unchecked(self.0.slice(42..43))
829    }
830    pub fn nth43(&self) -> Byte {
831        Byte::new_unchecked(self.0.slice(43..44))
832    }
833    pub fn nth44(&self) -> Byte {
834        Byte::new_unchecked(self.0.slice(44..45))
835    }
836    pub fn nth45(&self) -> Byte {
837        Byte::new_unchecked(self.0.slice(45..46))
838    }
839    pub fn nth46(&self) -> Byte {
840        Byte::new_unchecked(self.0.slice(46..47))
841    }
842    pub fn nth47(&self) -> Byte {
843        Byte::new_unchecked(self.0.slice(47..48))
844    }
845    pub fn nth48(&self) -> Byte {
846        Byte::new_unchecked(self.0.slice(48..49))
847    }
848    pub fn nth49(&self) -> Byte {
849        Byte::new_unchecked(self.0.slice(49..50))
850    }
851    pub fn nth50(&self) -> Byte {
852        Byte::new_unchecked(self.0.slice(50..51))
853    }
854    pub fn nth51(&self) -> Byte {
855        Byte::new_unchecked(self.0.slice(51..52))
856    }
857    pub fn nth52(&self) -> Byte {
858        Byte::new_unchecked(self.0.slice(52..53))
859    }
860    pub fn nth53(&self) -> Byte {
861        Byte::new_unchecked(self.0.slice(53..54))
862    }
863    pub fn nth54(&self) -> Byte {
864        Byte::new_unchecked(self.0.slice(54..55))
865    }
866    pub fn nth55(&self) -> Byte {
867        Byte::new_unchecked(self.0.slice(55..56))
868    }
869    pub fn nth56(&self) -> Byte {
870        Byte::new_unchecked(self.0.slice(56..57))
871    }
872    pub fn nth57(&self) -> Byte {
873        Byte::new_unchecked(self.0.slice(57..58))
874    }
875    pub fn nth58(&self) -> Byte {
876        Byte::new_unchecked(self.0.slice(58..59))
877    }
878    pub fn nth59(&self) -> Byte {
879        Byte::new_unchecked(self.0.slice(59..60))
880    }
881    pub fn nth60(&self) -> Byte {
882        Byte::new_unchecked(self.0.slice(60..61))
883    }
884    pub fn nth61(&self) -> Byte {
885        Byte::new_unchecked(self.0.slice(61..62))
886    }
887    pub fn nth62(&self) -> Byte {
888        Byte::new_unchecked(self.0.slice(62..63))
889    }
890    pub fn nth63(&self) -> Byte {
891        Byte::new_unchecked(self.0.slice(63..64))
892    }
893    pub fn nth64(&self) -> Byte {
894        Byte::new_unchecked(self.0.slice(64..65))
895    }
896    pub fn nth65(&self) -> Byte {
897        Byte::new_unchecked(self.0.slice(65..66))
898    }
899    pub fn nth66(&self) -> Byte {
900        Byte::new_unchecked(self.0.slice(66..67))
901    }
902    pub fn nth67(&self) -> Byte {
903        Byte::new_unchecked(self.0.slice(67..68))
904    }
905    pub fn nth68(&self) -> Byte {
906        Byte::new_unchecked(self.0.slice(68..69))
907    }
908    pub fn nth69(&self) -> Byte {
909        Byte::new_unchecked(self.0.slice(69..70))
910    }
911    pub fn nth70(&self) -> Byte {
912        Byte::new_unchecked(self.0.slice(70..71))
913    }
914    pub fn nth71(&self) -> Byte {
915        Byte::new_unchecked(self.0.slice(71..72))
916    }
917    pub fn nth72(&self) -> Byte {
918        Byte::new_unchecked(self.0.slice(72..73))
919    }
920    pub fn nth73(&self) -> Byte {
921        Byte::new_unchecked(self.0.slice(73..74))
922    }
923    pub fn nth74(&self) -> Byte {
924        Byte::new_unchecked(self.0.slice(74..75))
925    }
926    pub fn nth75(&self) -> Byte {
927        Byte::new_unchecked(self.0.slice(75..76))
928    }
929    pub fn nth76(&self) -> Byte {
930        Byte::new_unchecked(self.0.slice(76..77))
931    }
932    pub fn nth77(&self) -> Byte {
933        Byte::new_unchecked(self.0.slice(77..78))
934    }
935    pub fn nth78(&self) -> Byte {
936        Byte::new_unchecked(self.0.slice(78..79))
937    }
938    pub fn nth79(&self) -> Byte {
939        Byte::new_unchecked(self.0.slice(79..80))
940    }
941    pub fn nth80(&self) -> Byte {
942        Byte::new_unchecked(self.0.slice(80..81))
943    }
944    pub fn nth81(&self) -> Byte {
945        Byte::new_unchecked(self.0.slice(81..82))
946    }
947    pub fn nth82(&self) -> Byte {
948        Byte::new_unchecked(self.0.slice(82..83))
949    }
950    pub fn nth83(&self) -> Byte {
951        Byte::new_unchecked(self.0.slice(83..84))
952    }
953    pub fn nth84(&self) -> Byte {
954        Byte::new_unchecked(self.0.slice(84..85))
955    }
956    pub fn nth85(&self) -> Byte {
957        Byte::new_unchecked(self.0.slice(85..86))
958    }
959    pub fn nth86(&self) -> Byte {
960        Byte::new_unchecked(self.0.slice(86..87))
961    }
962    pub fn nth87(&self) -> Byte {
963        Byte::new_unchecked(self.0.slice(87..88))
964    }
965    pub fn nth88(&self) -> Byte {
966        Byte::new_unchecked(self.0.slice(88..89))
967    }
968    pub fn nth89(&self) -> Byte {
969        Byte::new_unchecked(self.0.slice(89..90))
970    }
971    pub fn nth90(&self) -> Byte {
972        Byte::new_unchecked(self.0.slice(90..91))
973    }
974    pub fn nth91(&self) -> Byte {
975        Byte::new_unchecked(self.0.slice(91..92))
976    }
977    pub fn nth92(&self) -> Byte {
978        Byte::new_unchecked(self.0.slice(92..93))
979    }
980    pub fn nth93(&self) -> Byte {
981        Byte::new_unchecked(self.0.slice(93..94))
982    }
983    pub fn nth94(&self) -> Byte {
984        Byte::new_unchecked(self.0.slice(94..95))
985    }
986    pub fn nth95(&self) -> Byte {
987        Byte::new_unchecked(self.0.slice(95..96))
988    }
989    pub fn nth96(&self) -> Byte {
990        Byte::new_unchecked(self.0.slice(96..97))
991    }
992    pub fn nth97(&self) -> Byte {
993        Byte::new_unchecked(self.0.slice(97..98))
994    }
995    pub fn nth98(&self) -> Byte {
996        Byte::new_unchecked(self.0.slice(98..99))
997    }
998    pub fn nth99(&self) -> Byte {
999        Byte::new_unchecked(self.0.slice(99..100))
1000    }
1001    pub fn nth100(&self) -> Byte {
1002        Byte::new_unchecked(self.0.slice(100..101))
1003    }
1004    pub fn nth101(&self) -> Byte {
1005        Byte::new_unchecked(self.0.slice(101..102))
1006    }
1007    pub fn nth102(&self) -> Byte {
1008        Byte::new_unchecked(self.0.slice(102..103))
1009    }
1010    pub fn nth103(&self) -> Byte {
1011        Byte::new_unchecked(self.0.slice(103..104))
1012    }
1013    pub fn raw_data(&self) -> molecule::bytes::Bytes {
1014        self.as_bytes()
1015    }
1016    pub fn as_reader<'r>(&'r self) -> SignatureReader<'r> {
1017        SignatureReader::new_unchecked(self.as_slice())
1018    }
1019}
1020impl molecule::prelude::Entity for Signature {
1021    type Builder = SignatureBuilder;
1022    const NAME: &'static str = "Signature";
1023    fn new_unchecked(data: molecule::bytes::Bytes) -> Self {
1024        Signature(data)
1025    }
1026    fn as_bytes(&self) -> molecule::bytes::Bytes {
1027        self.0.clone()
1028    }
1029    fn as_slice(&self) -> &[u8] {
1030        &self.0[..]
1031    }
1032    fn from_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
1033        SignatureReader::from_slice(slice).map(|reader| reader.to_entity())
1034    }
1035    fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
1036        SignatureReader::from_compatible_slice(slice).map(|reader| reader.to_entity())
1037    }
1038    fn new_builder() -> Self::Builder {
1039        ::core::default::Default::default()
1040    }
1041    fn as_builder(self) -> Self::Builder {
1042        Self::new_builder().set([
1043            self.nth0(),
1044            self.nth1(),
1045            self.nth2(),
1046            self.nth3(),
1047            self.nth4(),
1048            self.nth5(),
1049            self.nth6(),
1050            self.nth7(),
1051            self.nth8(),
1052            self.nth9(),
1053            self.nth10(),
1054            self.nth11(),
1055            self.nth12(),
1056            self.nth13(),
1057            self.nth14(),
1058            self.nth15(),
1059            self.nth16(),
1060            self.nth17(),
1061            self.nth18(),
1062            self.nth19(),
1063            self.nth20(),
1064            self.nth21(),
1065            self.nth22(),
1066            self.nth23(),
1067            self.nth24(),
1068            self.nth25(),
1069            self.nth26(),
1070            self.nth27(),
1071            self.nth28(),
1072            self.nth29(),
1073            self.nth30(),
1074            self.nth31(),
1075            self.nth32(),
1076            self.nth33(),
1077            self.nth34(),
1078            self.nth35(),
1079            self.nth36(),
1080            self.nth37(),
1081            self.nth38(),
1082            self.nth39(),
1083            self.nth40(),
1084            self.nth41(),
1085            self.nth42(),
1086            self.nth43(),
1087            self.nth44(),
1088            self.nth45(),
1089            self.nth46(),
1090            self.nth47(),
1091            self.nth48(),
1092            self.nth49(),
1093            self.nth50(),
1094            self.nth51(),
1095            self.nth52(),
1096            self.nth53(),
1097            self.nth54(),
1098            self.nth55(),
1099            self.nth56(),
1100            self.nth57(),
1101            self.nth58(),
1102            self.nth59(),
1103            self.nth60(),
1104            self.nth61(),
1105            self.nth62(),
1106            self.nth63(),
1107            self.nth64(),
1108            self.nth65(),
1109            self.nth66(),
1110            self.nth67(),
1111            self.nth68(),
1112            self.nth69(),
1113            self.nth70(),
1114            self.nth71(),
1115            self.nth72(),
1116            self.nth73(),
1117            self.nth74(),
1118            self.nth75(),
1119            self.nth76(),
1120            self.nth77(),
1121            self.nth78(),
1122            self.nth79(),
1123            self.nth80(),
1124            self.nth81(),
1125            self.nth82(),
1126            self.nth83(),
1127            self.nth84(),
1128            self.nth85(),
1129            self.nth86(),
1130            self.nth87(),
1131            self.nth88(),
1132            self.nth89(),
1133            self.nth90(),
1134            self.nth91(),
1135            self.nth92(),
1136            self.nth93(),
1137            self.nth94(),
1138            self.nth95(),
1139            self.nth96(),
1140            self.nth97(),
1141            self.nth98(),
1142            self.nth99(),
1143            self.nth100(),
1144            self.nth101(),
1145            self.nth102(),
1146            self.nth103(),
1147        ])
1148    }
1149}
1150#[derive(Clone, Copy)]
1151pub struct SignatureReader<'r>(&'r [u8]);
1152impl<'r> ::core::fmt::LowerHex for SignatureReader<'r> {
1153    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
1154        use molecule::hex_string;
1155        if f.alternate() {
1156            write!(f, "0x")?;
1157        }
1158        write!(f, "{}", hex_string(self.as_slice()))
1159    }
1160}
1161impl<'r> ::core::fmt::Debug for SignatureReader<'r> {
1162    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
1163        write!(f, "{}({:#x})", Self::NAME, self)
1164    }
1165}
1166impl<'r> ::core::fmt::Display for SignatureReader<'r> {
1167    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
1168        use molecule::hex_string;
1169        let raw_data = hex_string(&self.raw_data());
1170        write!(f, "{}(0x{})", Self::NAME, raw_data)
1171    }
1172}
1173impl<'r> SignatureReader<'r> {
1174    pub const TOTAL_SIZE: usize = 104;
1175    pub const ITEM_SIZE: usize = 1;
1176    pub const ITEM_COUNT: usize = 104;
1177    pub fn nth0(&self) -> ByteReader<'r> {
1178        ByteReader::new_unchecked(&self.as_slice()[0..1])
1179    }
1180    pub fn nth1(&self) -> ByteReader<'r> {
1181        ByteReader::new_unchecked(&self.as_slice()[1..2])
1182    }
1183    pub fn nth2(&self) -> ByteReader<'r> {
1184        ByteReader::new_unchecked(&self.as_slice()[2..3])
1185    }
1186    pub fn nth3(&self) -> ByteReader<'r> {
1187        ByteReader::new_unchecked(&self.as_slice()[3..4])
1188    }
1189    pub fn nth4(&self) -> ByteReader<'r> {
1190        ByteReader::new_unchecked(&self.as_slice()[4..5])
1191    }
1192    pub fn nth5(&self) -> ByteReader<'r> {
1193        ByteReader::new_unchecked(&self.as_slice()[5..6])
1194    }
1195    pub fn nth6(&self) -> ByteReader<'r> {
1196        ByteReader::new_unchecked(&self.as_slice()[6..7])
1197    }
1198    pub fn nth7(&self) -> ByteReader<'r> {
1199        ByteReader::new_unchecked(&self.as_slice()[7..8])
1200    }
1201    pub fn nth8(&self) -> ByteReader<'r> {
1202        ByteReader::new_unchecked(&self.as_slice()[8..9])
1203    }
1204    pub fn nth9(&self) -> ByteReader<'r> {
1205        ByteReader::new_unchecked(&self.as_slice()[9..10])
1206    }
1207    pub fn nth10(&self) -> ByteReader<'r> {
1208        ByteReader::new_unchecked(&self.as_slice()[10..11])
1209    }
1210    pub fn nth11(&self) -> ByteReader<'r> {
1211        ByteReader::new_unchecked(&self.as_slice()[11..12])
1212    }
1213    pub fn nth12(&self) -> ByteReader<'r> {
1214        ByteReader::new_unchecked(&self.as_slice()[12..13])
1215    }
1216    pub fn nth13(&self) -> ByteReader<'r> {
1217        ByteReader::new_unchecked(&self.as_slice()[13..14])
1218    }
1219    pub fn nth14(&self) -> ByteReader<'r> {
1220        ByteReader::new_unchecked(&self.as_slice()[14..15])
1221    }
1222    pub fn nth15(&self) -> ByteReader<'r> {
1223        ByteReader::new_unchecked(&self.as_slice()[15..16])
1224    }
1225    pub fn nth16(&self) -> ByteReader<'r> {
1226        ByteReader::new_unchecked(&self.as_slice()[16..17])
1227    }
1228    pub fn nth17(&self) -> ByteReader<'r> {
1229        ByteReader::new_unchecked(&self.as_slice()[17..18])
1230    }
1231    pub fn nth18(&self) -> ByteReader<'r> {
1232        ByteReader::new_unchecked(&self.as_slice()[18..19])
1233    }
1234    pub fn nth19(&self) -> ByteReader<'r> {
1235        ByteReader::new_unchecked(&self.as_slice()[19..20])
1236    }
1237    pub fn nth20(&self) -> ByteReader<'r> {
1238        ByteReader::new_unchecked(&self.as_slice()[20..21])
1239    }
1240    pub fn nth21(&self) -> ByteReader<'r> {
1241        ByteReader::new_unchecked(&self.as_slice()[21..22])
1242    }
1243    pub fn nth22(&self) -> ByteReader<'r> {
1244        ByteReader::new_unchecked(&self.as_slice()[22..23])
1245    }
1246    pub fn nth23(&self) -> ByteReader<'r> {
1247        ByteReader::new_unchecked(&self.as_slice()[23..24])
1248    }
1249    pub fn nth24(&self) -> ByteReader<'r> {
1250        ByteReader::new_unchecked(&self.as_slice()[24..25])
1251    }
1252    pub fn nth25(&self) -> ByteReader<'r> {
1253        ByteReader::new_unchecked(&self.as_slice()[25..26])
1254    }
1255    pub fn nth26(&self) -> ByteReader<'r> {
1256        ByteReader::new_unchecked(&self.as_slice()[26..27])
1257    }
1258    pub fn nth27(&self) -> ByteReader<'r> {
1259        ByteReader::new_unchecked(&self.as_slice()[27..28])
1260    }
1261    pub fn nth28(&self) -> ByteReader<'r> {
1262        ByteReader::new_unchecked(&self.as_slice()[28..29])
1263    }
1264    pub fn nth29(&self) -> ByteReader<'r> {
1265        ByteReader::new_unchecked(&self.as_slice()[29..30])
1266    }
1267    pub fn nth30(&self) -> ByteReader<'r> {
1268        ByteReader::new_unchecked(&self.as_slice()[30..31])
1269    }
1270    pub fn nth31(&self) -> ByteReader<'r> {
1271        ByteReader::new_unchecked(&self.as_slice()[31..32])
1272    }
1273    pub fn nth32(&self) -> ByteReader<'r> {
1274        ByteReader::new_unchecked(&self.as_slice()[32..33])
1275    }
1276    pub fn nth33(&self) -> ByteReader<'r> {
1277        ByteReader::new_unchecked(&self.as_slice()[33..34])
1278    }
1279    pub fn nth34(&self) -> ByteReader<'r> {
1280        ByteReader::new_unchecked(&self.as_slice()[34..35])
1281    }
1282    pub fn nth35(&self) -> ByteReader<'r> {
1283        ByteReader::new_unchecked(&self.as_slice()[35..36])
1284    }
1285    pub fn nth36(&self) -> ByteReader<'r> {
1286        ByteReader::new_unchecked(&self.as_slice()[36..37])
1287    }
1288    pub fn nth37(&self) -> ByteReader<'r> {
1289        ByteReader::new_unchecked(&self.as_slice()[37..38])
1290    }
1291    pub fn nth38(&self) -> ByteReader<'r> {
1292        ByteReader::new_unchecked(&self.as_slice()[38..39])
1293    }
1294    pub fn nth39(&self) -> ByteReader<'r> {
1295        ByteReader::new_unchecked(&self.as_slice()[39..40])
1296    }
1297    pub fn nth40(&self) -> ByteReader<'r> {
1298        ByteReader::new_unchecked(&self.as_slice()[40..41])
1299    }
1300    pub fn nth41(&self) -> ByteReader<'r> {
1301        ByteReader::new_unchecked(&self.as_slice()[41..42])
1302    }
1303    pub fn nth42(&self) -> ByteReader<'r> {
1304        ByteReader::new_unchecked(&self.as_slice()[42..43])
1305    }
1306    pub fn nth43(&self) -> ByteReader<'r> {
1307        ByteReader::new_unchecked(&self.as_slice()[43..44])
1308    }
1309    pub fn nth44(&self) -> ByteReader<'r> {
1310        ByteReader::new_unchecked(&self.as_slice()[44..45])
1311    }
1312    pub fn nth45(&self) -> ByteReader<'r> {
1313        ByteReader::new_unchecked(&self.as_slice()[45..46])
1314    }
1315    pub fn nth46(&self) -> ByteReader<'r> {
1316        ByteReader::new_unchecked(&self.as_slice()[46..47])
1317    }
1318    pub fn nth47(&self) -> ByteReader<'r> {
1319        ByteReader::new_unchecked(&self.as_slice()[47..48])
1320    }
1321    pub fn nth48(&self) -> ByteReader<'r> {
1322        ByteReader::new_unchecked(&self.as_slice()[48..49])
1323    }
1324    pub fn nth49(&self) -> ByteReader<'r> {
1325        ByteReader::new_unchecked(&self.as_slice()[49..50])
1326    }
1327    pub fn nth50(&self) -> ByteReader<'r> {
1328        ByteReader::new_unchecked(&self.as_slice()[50..51])
1329    }
1330    pub fn nth51(&self) -> ByteReader<'r> {
1331        ByteReader::new_unchecked(&self.as_slice()[51..52])
1332    }
1333    pub fn nth52(&self) -> ByteReader<'r> {
1334        ByteReader::new_unchecked(&self.as_slice()[52..53])
1335    }
1336    pub fn nth53(&self) -> ByteReader<'r> {
1337        ByteReader::new_unchecked(&self.as_slice()[53..54])
1338    }
1339    pub fn nth54(&self) -> ByteReader<'r> {
1340        ByteReader::new_unchecked(&self.as_slice()[54..55])
1341    }
1342    pub fn nth55(&self) -> ByteReader<'r> {
1343        ByteReader::new_unchecked(&self.as_slice()[55..56])
1344    }
1345    pub fn nth56(&self) -> ByteReader<'r> {
1346        ByteReader::new_unchecked(&self.as_slice()[56..57])
1347    }
1348    pub fn nth57(&self) -> ByteReader<'r> {
1349        ByteReader::new_unchecked(&self.as_slice()[57..58])
1350    }
1351    pub fn nth58(&self) -> ByteReader<'r> {
1352        ByteReader::new_unchecked(&self.as_slice()[58..59])
1353    }
1354    pub fn nth59(&self) -> ByteReader<'r> {
1355        ByteReader::new_unchecked(&self.as_slice()[59..60])
1356    }
1357    pub fn nth60(&self) -> ByteReader<'r> {
1358        ByteReader::new_unchecked(&self.as_slice()[60..61])
1359    }
1360    pub fn nth61(&self) -> ByteReader<'r> {
1361        ByteReader::new_unchecked(&self.as_slice()[61..62])
1362    }
1363    pub fn nth62(&self) -> ByteReader<'r> {
1364        ByteReader::new_unchecked(&self.as_slice()[62..63])
1365    }
1366    pub fn nth63(&self) -> ByteReader<'r> {
1367        ByteReader::new_unchecked(&self.as_slice()[63..64])
1368    }
1369    pub fn nth64(&self) -> ByteReader<'r> {
1370        ByteReader::new_unchecked(&self.as_slice()[64..65])
1371    }
1372    pub fn nth65(&self) -> ByteReader<'r> {
1373        ByteReader::new_unchecked(&self.as_slice()[65..66])
1374    }
1375    pub fn nth66(&self) -> ByteReader<'r> {
1376        ByteReader::new_unchecked(&self.as_slice()[66..67])
1377    }
1378    pub fn nth67(&self) -> ByteReader<'r> {
1379        ByteReader::new_unchecked(&self.as_slice()[67..68])
1380    }
1381    pub fn nth68(&self) -> ByteReader<'r> {
1382        ByteReader::new_unchecked(&self.as_slice()[68..69])
1383    }
1384    pub fn nth69(&self) -> ByteReader<'r> {
1385        ByteReader::new_unchecked(&self.as_slice()[69..70])
1386    }
1387    pub fn nth70(&self) -> ByteReader<'r> {
1388        ByteReader::new_unchecked(&self.as_slice()[70..71])
1389    }
1390    pub fn nth71(&self) -> ByteReader<'r> {
1391        ByteReader::new_unchecked(&self.as_slice()[71..72])
1392    }
1393    pub fn nth72(&self) -> ByteReader<'r> {
1394        ByteReader::new_unchecked(&self.as_slice()[72..73])
1395    }
1396    pub fn nth73(&self) -> ByteReader<'r> {
1397        ByteReader::new_unchecked(&self.as_slice()[73..74])
1398    }
1399    pub fn nth74(&self) -> ByteReader<'r> {
1400        ByteReader::new_unchecked(&self.as_slice()[74..75])
1401    }
1402    pub fn nth75(&self) -> ByteReader<'r> {
1403        ByteReader::new_unchecked(&self.as_slice()[75..76])
1404    }
1405    pub fn nth76(&self) -> ByteReader<'r> {
1406        ByteReader::new_unchecked(&self.as_slice()[76..77])
1407    }
1408    pub fn nth77(&self) -> ByteReader<'r> {
1409        ByteReader::new_unchecked(&self.as_slice()[77..78])
1410    }
1411    pub fn nth78(&self) -> ByteReader<'r> {
1412        ByteReader::new_unchecked(&self.as_slice()[78..79])
1413    }
1414    pub fn nth79(&self) -> ByteReader<'r> {
1415        ByteReader::new_unchecked(&self.as_slice()[79..80])
1416    }
1417    pub fn nth80(&self) -> ByteReader<'r> {
1418        ByteReader::new_unchecked(&self.as_slice()[80..81])
1419    }
1420    pub fn nth81(&self) -> ByteReader<'r> {
1421        ByteReader::new_unchecked(&self.as_slice()[81..82])
1422    }
1423    pub fn nth82(&self) -> ByteReader<'r> {
1424        ByteReader::new_unchecked(&self.as_slice()[82..83])
1425    }
1426    pub fn nth83(&self) -> ByteReader<'r> {
1427        ByteReader::new_unchecked(&self.as_slice()[83..84])
1428    }
1429    pub fn nth84(&self) -> ByteReader<'r> {
1430        ByteReader::new_unchecked(&self.as_slice()[84..85])
1431    }
1432    pub fn nth85(&self) -> ByteReader<'r> {
1433        ByteReader::new_unchecked(&self.as_slice()[85..86])
1434    }
1435    pub fn nth86(&self) -> ByteReader<'r> {
1436        ByteReader::new_unchecked(&self.as_slice()[86..87])
1437    }
1438    pub fn nth87(&self) -> ByteReader<'r> {
1439        ByteReader::new_unchecked(&self.as_slice()[87..88])
1440    }
1441    pub fn nth88(&self) -> ByteReader<'r> {
1442        ByteReader::new_unchecked(&self.as_slice()[88..89])
1443    }
1444    pub fn nth89(&self) -> ByteReader<'r> {
1445        ByteReader::new_unchecked(&self.as_slice()[89..90])
1446    }
1447    pub fn nth90(&self) -> ByteReader<'r> {
1448        ByteReader::new_unchecked(&self.as_slice()[90..91])
1449    }
1450    pub fn nth91(&self) -> ByteReader<'r> {
1451        ByteReader::new_unchecked(&self.as_slice()[91..92])
1452    }
1453    pub fn nth92(&self) -> ByteReader<'r> {
1454        ByteReader::new_unchecked(&self.as_slice()[92..93])
1455    }
1456    pub fn nth93(&self) -> ByteReader<'r> {
1457        ByteReader::new_unchecked(&self.as_slice()[93..94])
1458    }
1459    pub fn nth94(&self) -> ByteReader<'r> {
1460        ByteReader::new_unchecked(&self.as_slice()[94..95])
1461    }
1462    pub fn nth95(&self) -> ByteReader<'r> {
1463        ByteReader::new_unchecked(&self.as_slice()[95..96])
1464    }
1465    pub fn nth96(&self) -> ByteReader<'r> {
1466        ByteReader::new_unchecked(&self.as_slice()[96..97])
1467    }
1468    pub fn nth97(&self) -> ByteReader<'r> {
1469        ByteReader::new_unchecked(&self.as_slice()[97..98])
1470    }
1471    pub fn nth98(&self) -> ByteReader<'r> {
1472        ByteReader::new_unchecked(&self.as_slice()[98..99])
1473    }
1474    pub fn nth99(&self) -> ByteReader<'r> {
1475        ByteReader::new_unchecked(&self.as_slice()[99..100])
1476    }
1477    pub fn nth100(&self) -> ByteReader<'r> {
1478        ByteReader::new_unchecked(&self.as_slice()[100..101])
1479    }
1480    pub fn nth101(&self) -> ByteReader<'r> {
1481        ByteReader::new_unchecked(&self.as_slice()[101..102])
1482    }
1483    pub fn nth102(&self) -> ByteReader<'r> {
1484        ByteReader::new_unchecked(&self.as_slice()[102..103])
1485    }
1486    pub fn nth103(&self) -> ByteReader<'r> {
1487        ByteReader::new_unchecked(&self.as_slice()[103..104])
1488    }
1489    pub fn raw_data(&self) -> &'r [u8] {
1490        self.as_slice()
1491    }
1492}
1493impl<'r> molecule::prelude::Reader<'r> for SignatureReader<'r> {
1494    type Entity = Signature;
1495    const NAME: &'static str = "SignatureReader";
1496    fn to_entity(&self) -> Self::Entity {
1497        Self::Entity::new_unchecked(self.as_slice().to_owned().into())
1498    }
1499    fn new_unchecked(slice: &'r [u8]) -> Self {
1500        SignatureReader(slice)
1501    }
1502    fn as_slice(&self) -> &'r [u8] {
1503        self.0
1504    }
1505    fn verify(slice: &[u8], _compatible: bool) -> molecule::error::VerificationResult<()> {
1506        use molecule::verification_error as ve;
1507        let slice_len = slice.len();
1508        if slice_len != Self::TOTAL_SIZE {
1509            return ve!(Self, TotalSizeNotMatch, Self::TOTAL_SIZE, slice_len);
1510        }
1511        Ok(())
1512    }
1513}
1514#[derive(Clone)]
1515pub struct SignatureBuilder(pub(crate) [Byte; 104]);
1516impl ::core::fmt::Debug for SignatureBuilder {
1517    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
1518        write!(f, "{}({:?})", Self::NAME, &self.0[..])
1519    }
1520}
1521impl ::core::default::Default for SignatureBuilder {
1522    fn default() -> Self {
1523        SignatureBuilder([
1524            Byte::default(),
1525            Byte::default(),
1526            Byte::default(),
1527            Byte::default(),
1528            Byte::default(),
1529            Byte::default(),
1530            Byte::default(),
1531            Byte::default(),
1532            Byte::default(),
1533            Byte::default(),
1534            Byte::default(),
1535            Byte::default(),
1536            Byte::default(),
1537            Byte::default(),
1538            Byte::default(),
1539            Byte::default(),
1540            Byte::default(),
1541            Byte::default(),
1542            Byte::default(),
1543            Byte::default(),
1544            Byte::default(),
1545            Byte::default(),
1546            Byte::default(),
1547            Byte::default(),
1548            Byte::default(),
1549            Byte::default(),
1550            Byte::default(),
1551            Byte::default(),
1552            Byte::default(),
1553            Byte::default(),
1554            Byte::default(),
1555            Byte::default(),
1556            Byte::default(),
1557            Byte::default(),
1558            Byte::default(),
1559            Byte::default(),
1560            Byte::default(),
1561            Byte::default(),
1562            Byte::default(),
1563            Byte::default(),
1564            Byte::default(),
1565            Byte::default(),
1566            Byte::default(),
1567            Byte::default(),
1568            Byte::default(),
1569            Byte::default(),
1570            Byte::default(),
1571            Byte::default(),
1572            Byte::default(),
1573            Byte::default(),
1574            Byte::default(),
1575            Byte::default(),
1576            Byte::default(),
1577            Byte::default(),
1578            Byte::default(),
1579            Byte::default(),
1580            Byte::default(),
1581            Byte::default(),
1582            Byte::default(),
1583            Byte::default(),
1584            Byte::default(),
1585            Byte::default(),
1586            Byte::default(),
1587            Byte::default(),
1588            Byte::default(),
1589            Byte::default(),
1590            Byte::default(),
1591            Byte::default(),
1592            Byte::default(),
1593            Byte::default(),
1594            Byte::default(),
1595            Byte::default(),
1596            Byte::default(),
1597            Byte::default(),
1598            Byte::default(),
1599            Byte::default(),
1600            Byte::default(),
1601            Byte::default(),
1602            Byte::default(),
1603            Byte::default(),
1604            Byte::default(),
1605            Byte::default(),
1606            Byte::default(),
1607            Byte::default(),
1608            Byte::default(),
1609            Byte::default(),
1610            Byte::default(),
1611            Byte::default(),
1612            Byte::default(),
1613            Byte::default(),
1614            Byte::default(),
1615            Byte::default(),
1616            Byte::default(),
1617            Byte::default(),
1618            Byte::default(),
1619            Byte::default(),
1620            Byte::default(),
1621            Byte::default(),
1622            Byte::default(),
1623            Byte::default(),
1624            Byte::default(),
1625            Byte::default(),
1626            Byte::default(),
1627            Byte::default(),
1628        ])
1629    }
1630}
1631impl SignatureBuilder {
1632    pub const TOTAL_SIZE: usize = 104;
1633    pub const ITEM_SIZE: usize = 1;
1634    pub const ITEM_COUNT: usize = 104;
1635    pub fn set(mut self, v: [Byte; 104]) -> Self {
1636        self.0 = v;
1637        self
1638    }
1639    pub fn nth0(mut self, v: Byte) -> Self {
1640        self.0[0] = v;
1641        self
1642    }
1643    pub fn nth1(mut self, v: Byte) -> Self {
1644        self.0[1] = v;
1645        self
1646    }
1647    pub fn nth2(mut self, v: Byte) -> Self {
1648        self.0[2] = v;
1649        self
1650    }
1651    pub fn nth3(mut self, v: Byte) -> Self {
1652        self.0[3] = v;
1653        self
1654    }
1655    pub fn nth4(mut self, v: Byte) -> Self {
1656        self.0[4] = v;
1657        self
1658    }
1659    pub fn nth5(mut self, v: Byte) -> Self {
1660        self.0[5] = v;
1661        self
1662    }
1663    pub fn nth6(mut self, v: Byte) -> Self {
1664        self.0[6] = v;
1665        self
1666    }
1667    pub fn nth7(mut self, v: Byte) -> Self {
1668        self.0[7] = v;
1669        self
1670    }
1671    pub fn nth8(mut self, v: Byte) -> Self {
1672        self.0[8] = v;
1673        self
1674    }
1675    pub fn nth9(mut self, v: Byte) -> Self {
1676        self.0[9] = v;
1677        self
1678    }
1679    pub fn nth10(mut self, v: Byte) -> Self {
1680        self.0[10] = v;
1681        self
1682    }
1683    pub fn nth11(mut self, v: Byte) -> Self {
1684        self.0[11] = v;
1685        self
1686    }
1687    pub fn nth12(mut self, v: Byte) -> Self {
1688        self.0[12] = v;
1689        self
1690    }
1691    pub fn nth13(mut self, v: Byte) -> Self {
1692        self.0[13] = v;
1693        self
1694    }
1695    pub fn nth14(mut self, v: Byte) -> Self {
1696        self.0[14] = v;
1697        self
1698    }
1699    pub fn nth15(mut self, v: Byte) -> Self {
1700        self.0[15] = v;
1701        self
1702    }
1703    pub fn nth16(mut self, v: Byte) -> Self {
1704        self.0[16] = v;
1705        self
1706    }
1707    pub fn nth17(mut self, v: Byte) -> Self {
1708        self.0[17] = v;
1709        self
1710    }
1711    pub fn nth18(mut self, v: Byte) -> Self {
1712        self.0[18] = v;
1713        self
1714    }
1715    pub fn nth19(mut self, v: Byte) -> Self {
1716        self.0[19] = v;
1717        self
1718    }
1719    pub fn nth20(mut self, v: Byte) -> Self {
1720        self.0[20] = v;
1721        self
1722    }
1723    pub fn nth21(mut self, v: Byte) -> Self {
1724        self.0[21] = v;
1725        self
1726    }
1727    pub fn nth22(mut self, v: Byte) -> Self {
1728        self.0[22] = v;
1729        self
1730    }
1731    pub fn nth23(mut self, v: Byte) -> Self {
1732        self.0[23] = v;
1733        self
1734    }
1735    pub fn nth24(mut self, v: Byte) -> Self {
1736        self.0[24] = v;
1737        self
1738    }
1739    pub fn nth25(mut self, v: Byte) -> Self {
1740        self.0[25] = v;
1741        self
1742    }
1743    pub fn nth26(mut self, v: Byte) -> Self {
1744        self.0[26] = v;
1745        self
1746    }
1747    pub fn nth27(mut self, v: Byte) -> Self {
1748        self.0[27] = v;
1749        self
1750    }
1751    pub fn nth28(mut self, v: Byte) -> Self {
1752        self.0[28] = v;
1753        self
1754    }
1755    pub fn nth29(mut self, v: Byte) -> Self {
1756        self.0[29] = v;
1757        self
1758    }
1759    pub fn nth30(mut self, v: Byte) -> Self {
1760        self.0[30] = v;
1761        self
1762    }
1763    pub fn nth31(mut self, v: Byte) -> Self {
1764        self.0[31] = v;
1765        self
1766    }
1767    pub fn nth32(mut self, v: Byte) -> Self {
1768        self.0[32] = v;
1769        self
1770    }
1771    pub fn nth33(mut self, v: Byte) -> Self {
1772        self.0[33] = v;
1773        self
1774    }
1775    pub fn nth34(mut self, v: Byte) -> Self {
1776        self.0[34] = v;
1777        self
1778    }
1779    pub fn nth35(mut self, v: Byte) -> Self {
1780        self.0[35] = v;
1781        self
1782    }
1783    pub fn nth36(mut self, v: Byte) -> Self {
1784        self.0[36] = v;
1785        self
1786    }
1787    pub fn nth37(mut self, v: Byte) -> Self {
1788        self.0[37] = v;
1789        self
1790    }
1791    pub fn nth38(mut self, v: Byte) -> Self {
1792        self.0[38] = v;
1793        self
1794    }
1795    pub fn nth39(mut self, v: Byte) -> Self {
1796        self.0[39] = v;
1797        self
1798    }
1799    pub fn nth40(mut self, v: Byte) -> Self {
1800        self.0[40] = v;
1801        self
1802    }
1803    pub fn nth41(mut self, v: Byte) -> Self {
1804        self.0[41] = v;
1805        self
1806    }
1807    pub fn nth42(mut self, v: Byte) -> Self {
1808        self.0[42] = v;
1809        self
1810    }
1811    pub fn nth43(mut self, v: Byte) -> Self {
1812        self.0[43] = v;
1813        self
1814    }
1815    pub fn nth44(mut self, v: Byte) -> Self {
1816        self.0[44] = v;
1817        self
1818    }
1819    pub fn nth45(mut self, v: Byte) -> Self {
1820        self.0[45] = v;
1821        self
1822    }
1823    pub fn nth46(mut self, v: Byte) -> Self {
1824        self.0[46] = v;
1825        self
1826    }
1827    pub fn nth47(mut self, v: Byte) -> Self {
1828        self.0[47] = v;
1829        self
1830    }
1831    pub fn nth48(mut self, v: Byte) -> Self {
1832        self.0[48] = v;
1833        self
1834    }
1835    pub fn nth49(mut self, v: Byte) -> Self {
1836        self.0[49] = v;
1837        self
1838    }
1839    pub fn nth50(mut self, v: Byte) -> Self {
1840        self.0[50] = v;
1841        self
1842    }
1843    pub fn nth51(mut self, v: Byte) -> Self {
1844        self.0[51] = v;
1845        self
1846    }
1847    pub fn nth52(mut self, v: Byte) -> Self {
1848        self.0[52] = v;
1849        self
1850    }
1851    pub fn nth53(mut self, v: Byte) -> Self {
1852        self.0[53] = v;
1853        self
1854    }
1855    pub fn nth54(mut self, v: Byte) -> Self {
1856        self.0[54] = v;
1857        self
1858    }
1859    pub fn nth55(mut self, v: Byte) -> Self {
1860        self.0[55] = v;
1861        self
1862    }
1863    pub fn nth56(mut self, v: Byte) -> Self {
1864        self.0[56] = v;
1865        self
1866    }
1867    pub fn nth57(mut self, v: Byte) -> Self {
1868        self.0[57] = v;
1869        self
1870    }
1871    pub fn nth58(mut self, v: Byte) -> Self {
1872        self.0[58] = v;
1873        self
1874    }
1875    pub fn nth59(mut self, v: Byte) -> Self {
1876        self.0[59] = v;
1877        self
1878    }
1879    pub fn nth60(mut self, v: Byte) -> Self {
1880        self.0[60] = v;
1881        self
1882    }
1883    pub fn nth61(mut self, v: Byte) -> Self {
1884        self.0[61] = v;
1885        self
1886    }
1887    pub fn nth62(mut self, v: Byte) -> Self {
1888        self.0[62] = v;
1889        self
1890    }
1891    pub fn nth63(mut self, v: Byte) -> Self {
1892        self.0[63] = v;
1893        self
1894    }
1895    pub fn nth64(mut self, v: Byte) -> Self {
1896        self.0[64] = v;
1897        self
1898    }
1899    pub fn nth65(mut self, v: Byte) -> Self {
1900        self.0[65] = v;
1901        self
1902    }
1903    pub fn nth66(mut self, v: Byte) -> Self {
1904        self.0[66] = v;
1905        self
1906    }
1907    pub fn nth67(mut self, v: Byte) -> Self {
1908        self.0[67] = v;
1909        self
1910    }
1911    pub fn nth68(mut self, v: Byte) -> Self {
1912        self.0[68] = v;
1913        self
1914    }
1915    pub fn nth69(mut self, v: Byte) -> Self {
1916        self.0[69] = v;
1917        self
1918    }
1919    pub fn nth70(mut self, v: Byte) -> Self {
1920        self.0[70] = v;
1921        self
1922    }
1923    pub fn nth71(mut self, v: Byte) -> Self {
1924        self.0[71] = v;
1925        self
1926    }
1927    pub fn nth72(mut self, v: Byte) -> Self {
1928        self.0[72] = v;
1929        self
1930    }
1931    pub fn nth73(mut self, v: Byte) -> Self {
1932        self.0[73] = v;
1933        self
1934    }
1935    pub fn nth74(mut self, v: Byte) -> Self {
1936        self.0[74] = v;
1937        self
1938    }
1939    pub fn nth75(mut self, v: Byte) -> Self {
1940        self.0[75] = v;
1941        self
1942    }
1943    pub fn nth76(mut self, v: Byte) -> Self {
1944        self.0[76] = v;
1945        self
1946    }
1947    pub fn nth77(mut self, v: Byte) -> Self {
1948        self.0[77] = v;
1949        self
1950    }
1951    pub fn nth78(mut self, v: Byte) -> Self {
1952        self.0[78] = v;
1953        self
1954    }
1955    pub fn nth79(mut self, v: Byte) -> Self {
1956        self.0[79] = v;
1957        self
1958    }
1959    pub fn nth80(mut self, v: Byte) -> Self {
1960        self.0[80] = v;
1961        self
1962    }
1963    pub fn nth81(mut self, v: Byte) -> Self {
1964        self.0[81] = v;
1965        self
1966    }
1967    pub fn nth82(mut self, v: Byte) -> Self {
1968        self.0[82] = v;
1969        self
1970    }
1971    pub fn nth83(mut self, v: Byte) -> Self {
1972        self.0[83] = v;
1973        self
1974    }
1975    pub fn nth84(mut self, v: Byte) -> Self {
1976        self.0[84] = v;
1977        self
1978    }
1979    pub fn nth85(mut self, v: Byte) -> Self {
1980        self.0[85] = v;
1981        self
1982    }
1983    pub fn nth86(mut self, v: Byte) -> Self {
1984        self.0[86] = v;
1985        self
1986    }
1987    pub fn nth87(mut self, v: Byte) -> Self {
1988        self.0[87] = v;
1989        self
1990    }
1991    pub fn nth88(mut self, v: Byte) -> Self {
1992        self.0[88] = v;
1993        self
1994    }
1995    pub fn nth89(mut self, v: Byte) -> Self {
1996        self.0[89] = v;
1997        self
1998    }
1999    pub fn nth90(mut self, v: Byte) -> Self {
2000        self.0[90] = v;
2001        self
2002    }
2003    pub fn nth91(mut self, v: Byte) -> Self {
2004        self.0[91] = v;
2005        self
2006    }
2007    pub fn nth92(mut self, v: Byte) -> Self {
2008        self.0[92] = v;
2009        self
2010    }
2011    pub fn nth93(mut self, v: Byte) -> Self {
2012        self.0[93] = v;
2013        self
2014    }
2015    pub fn nth94(mut self, v: Byte) -> Self {
2016        self.0[94] = v;
2017        self
2018    }
2019    pub fn nth95(mut self, v: Byte) -> Self {
2020        self.0[95] = v;
2021        self
2022    }
2023    pub fn nth96(mut self, v: Byte) -> Self {
2024        self.0[96] = v;
2025        self
2026    }
2027    pub fn nth97(mut self, v: Byte) -> Self {
2028        self.0[97] = v;
2029        self
2030    }
2031    pub fn nth98(mut self, v: Byte) -> Self {
2032        self.0[98] = v;
2033        self
2034    }
2035    pub fn nth99(mut self, v: Byte) -> Self {
2036        self.0[99] = v;
2037        self
2038    }
2039    pub fn nth100(mut self, v: Byte) -> Self {
2040        self.0[100] = v;
2041        self
2042    }
2043    pub fn nth101(mut self, v: Byte) -> Self {
2044        self.0[101] = v;
2045        self
2046    }
2047    pub fn nth102(mut self, v: Byte) -> Self {
2048        self.0[102] = v;
2049        self
2050    }
2051    pub fn nth103(mut self, v: Byte) -> Self {
2052        self.0[103] = v;
2053        self
2054    }
2055}
2056impl molecule::prelude::Builder for SignatureBuilder {
2057    type Entity = Signature;
2058    const NAME: &'static str = "SignatureBuilder";
2059    fn expected_length(&self) -> usize {
2060        Self::TOTAL_SIZE
2061    }
2062    fn write<W: molecule::io::Write>(&self, writer: &mut W) -> molecule::io::Result<()> {
2063        writer.write_all(self.0[0].as_slice())?;
2064        writer.write_all(self.0[1].as_slice())?;
2065        writer.write_all(self.0[2].as_slice())?;
2066        writer.write_all(self.0[3].as_slice())?;
2067        writer.write_all(self.0[4].as_slice())?;
2068        writer.write_all(self.0[5].as_slice())?;
2069        writer.write_all(self.0[6].as_slice())?;
2070        writer.write_all(self.0[7].as_slice())?;
2071        writer.write_all(self.0[8].as_slice())?;
2072        writer.write_all(self.0[9].as_slice())?;
2073        writer.write_all(self.0[10].as_slice())?;
2074        writer.write_all(self.0[11].as_slice())?;
2075        writer.write_all(self.0[12].as_slice())?;
2076        writer.write_all(self.0[13].as_slice())?;
2077        writer.write_all(self.0[14].as_slice())?;
2078        writer.write_all(self.0[15].as_slice())?;
2079        writer.write_all(self.0[16].as_slice())?;
2080        writer.write_all(self.0[17].as_slice())?;
2081        writer.write_all(self.0[18].as_slice())?;
2082        writer.write_all(self.0[19].as_slice())?;
2083        writer.write_all(self.0[20].as_slice())?;
2084        writer.write_all(self.0[21].as_slice())?;
2085        writer.write_all(self.0[22].as_slice())?;
2086        writer.write_all(self.0[23].as_slice())?;
2087        writer.write_all(self.0[24].as_slice())?;
2088        writer.write_all(self.0[25].as_slice())?;
2089        writer.write_all(self.0[26].as_slice())?;
2090        writer.write_all(self.0[27].as_slice())?;
2091        writer.write_all(self.0[28].as_slice())?;
2092        writer.write_all(self.0[29].as_slice())?;
2093        writer.write_all(self.0[30].as_slice())?;
2094        writer.write_all(self.0[31].as_slice())?;
2095        writer.write_all(self.0[32].as_slice())?;
2096        writer.write_all(self.0[33].as_slice())?;
2097        writer.write_all(self.0[34].as_slice())?;
2098        writer.write_all(self.0[35].as_slice())?;
2099        writer.write_all(self.0[36].as_slice())?;
2100        writer.write_all(self.0[37].as_slice())?;
2101        writer.write_all(self.0[38].as_slice())?;
2102        writer.write_all(self.0[39].as_slice())?;
2103        writer.write_all(self.0[40].as_slice())?;
2104        writer.write_all(self.0[41].as_slice())?;
2105        writer.write_all(self.0[42].as_slice())?;
2106        writer.write_all(self.0[43].as_slice())?;
2107        writer.write_all(self.0[44].as_slice())?;
2108        writer.write_all(self.0[45].as_slice())?;
2109        writer.write_all(self.0[46].as_slice())?;
2110        writer.write_all(self.0[47].as_slice())?;
2111        writer.write_all(self.0[48].as_slice())?;
2112        writer.write_all(self.0[49].as_slice())?;
2113        writer.write_all(self.0[50].as_slice())?;
2114        writer.write_all(self.0[51].as_slice())?;
2115        writer.write_all(self.0[52].as_slice())?;
2116        writer.write_all(self.0[53].as_slice())?;
2117        writer.write_all(self.0[54].as_slice())?;
2118        writer.write_all(self.0[55].as_slice())?;
2119        writer.write_all(self.0[56].as_slice())?;
2120        writer.write_all(self.0[57].as_slice())?;
2121        writer.write_all(self.0[58].as_slice())?;
2122        writer.write_all(self.0[59].as_slice())?;
2123        writer.write_all(self.0[60].as_slice())?;
2124        writer.write_all(self.0[61].as_slice())?;
2125        writer.write_all(self.0[62].as_slice())?;
2126        writer.write_all(self.0[63].as_slice())?;
2127        writer.write_all(self.0[64].as_slice())?;
2128        writer.write_all(self.0[65].as_slice())?;
2129        writer.write_all(self.0[66].as_slice())?;
2130        writer.write_all(self.0[67].as_slice())?;
2131        writer.write_all(self.0[68].as_slice())?;
2132        writer.write_all(self.0[69].as_slice())?;
2133        writer.write_all(self.0[70].as_slice())?;
2134        writer.write_all(self.0[71].as_slice())?;
2135        writer.write_all(self.0[72].as_slice())?;
2136        writer.write_all(self.0[73].as_slice())?;
2137        writer.write_all(self.0[74].as_slice())?;
2138        writer.write_all(self.0[75].as_slice())?;
2139        writer.write_all(self.0[76].as_slice())?;
2140        writer.write_all(self.0[77].as_slice())?;
2141        writer.write_all(self.0[78].as_slice())?;
2142        writer.write_all(self.0[79].as_slice())?;
2143        writer.write_all(self.0[80].as_slice())?;
2144        writer.write_all(self.0[81].as_slice())?;
2145        writer.write_all(self.0[82].as_slice())?;
2146        writer.write_all(self.0[83].as_slice())?;
2147        writer.write_all(self.0[84].as_slice())?;
2148        writer.write_all(self.0[85].as_slice())?;
2149        writer.write_all(self.0[86].as_slice())?;
2150        writer.write_all(self.0[87].as_slice())?;
2151        writer.write_all(self.0[88].as_slice())?;
2152        writer.write_all(self.0[89].as_slice())?;
2153        writer.write_all(self.0[90].as_slice())?;
2154        writer.write_all(self.0[91].as_slice())?;
2155        writer.write_all(self.0[92].as_slice())?;
2156        writer.write_all(self.0[93].as_slice())?;
2157        writer.write_all(self.0[94].as_slice())?;
2158        writer.write_all(self.0[95].as_slice())?;
2159        writer.write_all(self.0[96].as_slice())?;
2160        writer.write_all(self.0[97].as_slice())?;
2161        writer.write_all(self.0[98].as_slice())?;
2162        writer.write_all(self.0[99].as_slice())?;
2163        writer.write_all(self.0[100].as_slice())?;
2164        writer.write_all(self.0[101].as_slice())?;
2165        writer.write_all(self.0[102].as_slice())?;
2166        writer.write_all(self.0[103].as_slice())?;
2167        Ok(())
2168    }
2169    fn build(&self) -> Self::Entity {
2170        let mut inner = Vec::with_capacity(self.expected_length());
2171        self.write(&mut inner)
2172            .unwrap_or_else(|_| panic!("{} build should be ok", Self::NAME));
2173        Signature::new_unchecked(inner.into())
2174    }
2175}
2176impl From<[Byte; 104usize]> for Signature {
2177    fn from(value: [Byte; 104usize]) -> Self {
2178        Self::new_builder().set(value).build()
2179    }
2180}
2181impl ::core::convert::TryFrom<&[Byte]> for Signature {
2182    type Error = ::core::array::TryFromSliceError;
2183    fn try_from(value: &[Byte]) -> Result<Self, ::core::array::TryFromSliceError> {
2184        Ok(Self::new_builder()
2185            .set(<&[Byte; 104usize]>::try_from(value)?.clone())
2186            .build())
2187    }
2188}
2189impl From<Signature> for [Byte; 104usize] {
2190    #[track_caller]
2191    fn from(value: Signature) -> Self {
2192        [
2193            value.nth0(),
2194            value.nth1(),
2195            value.nth2(),
2196            value.nth3(),
2197            value.nth4(),
2198            value.nth5(),
2199            value.nth6(),
2200            value.nth7(),
2201            value.nth8(),
2202            value.nth9(),
2203            value.nth10(),
2204            value.nth11(),
2205            value.nth12(),
2206            value.nth13(),
2207            value.nth14(),
2208            value.nth15(),
2209            value.nth16(),
2210            value.nth17(),
2211            value.nth18(),
2212            value.nth19(),
2213            value.nth20(),
2214            value.nth21(),
2215            value.nth22(),
2216            value.nth23(),
2217            value.nth24(),
2218            value.nth25(),
2219            value.nth26(),
2220            value.nth27(),
2221            value.nth28(),
2222            value.nth29(),
2223            value.nth30(),
2224            value.nth31(),
2225            value.nth32(),
2226            value.nth33(),
2227            value.nth34(),
2228            value.nth35(),
2229            value.nth36(),
2230            value.nth37(),
2231            value.nth38(),
2232            value.nth39(),
2233            value.nth40(),
2234            value.nth41(),
2235            value.nth42(),
2236            value.nth43(),
2237            value.nth44(),
2238            value.nth45(),
2239            value.nth46(),
2240            value.nth47(),
2241            value.nth48(),
2242            value.nth49(),
2243            value.nth50(),
2244            value.nth51(),
2245            value.nth52(),
2246            value.nth53(),
2247            value.nth54(),
2248            value.nth55(),
2249            value.nth56(),
2250            value.nth57(),
2251            value.nth58(),
2252            value.nth59(),
2253            value.nth60(),
2254            value.nth61(),
2255            value.nth62(),
2256            value.nth63(),
2257            value.nth64(),
2258            value.nth65(),
2259            value.nth66(),
2260            value.nth67(),
2261            value.nth68(),
2262            value.nth69(),
2263            value.nth70(),
2264            value.nth71(),
2265            value.nth72(),
2266            value.nth73(),
2267            value.nth74(),
2268            value.nth75(),
2269            value.nth76(),
2270            value.nth77(),
2271            value.nth78(),
2272            value.nth79(),
2273            value.nth80(),
2274            value.nth81(),
2275            value.nth82(),
2276            value.nth83(),
2277            value.nth84(),
2278            value.nth85(),
2279            value.nth86(),
2280            value.nth87(),
2281            value.nth88(),
2282            value.nth89(),
2283            value.nth90(),
2284            value.nth91(),
2285            value.nth92(),
2286            value.nth93(),
2287            value.nth94(),
2288            value.nth95(),
2289            value.nth96(),
2290            value.nth97(),
2291            value.nth98(),
2292            value.nth99(),
2293            value.nth100(),
2294            value.nth101(),
2295            value.nth102(),
2296            value.nth103(),
2297        ]
2298    }
2299}
2300impl From<[u8; 104usize]> for Signature {
2301    fn from(value: [u8; 104usize]) -> Self {
2302        SignatureReader::new_unchecked(&value).to_entity()
2303    }
2304}
2305impl ::core::convert::TryFrom<&[u8]> for Signature {
2306    type Error = ::core::array::TryFromSliceError;
2307    fn try_from(value: &[u8]) -> Result<Self, ::core::array::TryFromSliceError> {
2308        Ok(<[u8; 104usize]>::try_from(value)?.into())
2309    }
2310}
2311impl From<Signature> for [u8; 104usize] {
2312    #[track_caller]
2313    fn from(value: Signature) -> Self {
2314        ::core::convert::TryFrom::try_from(value.as_slice()).unwrap()
2315    }
2316}
2317impl<'a> From<SignatureReader<'a>> for &'a [u8; 104usize] {
2318    #[track_caller]
2319    fn from(value: SignatureReader<'a>) -> Self {
2320        ::core::convert::TryFrom::try_from(value.as_slice()).unwrap()
2321    }
2322}
2323impl<'a> From<&'a SignatureReader<'a>> for &'a [u8; 104usize] {
2324    #[track_caller]
2325    fn from(value: &'a SignatureReader<'a>) -> Self {
2326        ::core::convert::TryFrom::try_from(value.as_slice()).unwrap()
2327    }
2328}
2329#[derive(Clone)]
2330pub struct SignatureOpt(molecule::bytes::Bytes);
2331impl ::core::fmt::LowerHex for SignatureOpt {
2332    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
2333        use molecule::hex_string;
2334        if f.alternate() {
2335            write!(f, "0x")?;
2336        }
2337        write!(f, "{}", hex_string(self.as_slice()))
2338    }
2339}
2340impl ::core::fmt::Debug for SignatureOpt {
2341    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
2342        write!(f, "{}({:#x})", Self::NAME, self)
2343    }
2344}
2345impl ::core::fmt::Display for SignatureOpt {
2346    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
2347        if let Some(v) = self.to_opt() {
2348            write!(f, "{}(Some({}))", Self::NAME, v)
2349        } else {
2350            write!(f, "{}(None)", Self::NAME)
2351        }
2352    }
2353}
2354impl ::core::default::Default for SignatureOpt {
2355    fn default() -> Self {
2356        let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE);
2357        SignatureOpt::new_unchecked(v)
2358    }
2359}
2360impl SignatureOpt {
2361    const DEFAULT_VALUE: [u8; 0] = [];
2362    pub fn is_none(&self) -> bool {
2363        self.0.is_empty()
2364    }
2365    pub fn is_some(&self) -> bool {
2366        !self.0.is_empty()
2367    }
2368    pub fn to_opt(&self) -> Option<Signature> {
2369        if self.is_none() {
2370            None
2371        } else {
2372            Some(Signature::new_unchecked(self.0.clone()))
2373        }
2374    }
2375    pub fn as_reader<'r>(&'r self) -> SignatureOptReader<'r> {
2376        SignatureOptReader::new_unchecked(self.as_slice())
2377    }
2378}
2379impl molecule::prelude::Entity for SignatureOpt {
2380    type Builder = SignatureOptBuilder;
2381    const NAME: &'static str = "SignatureOpt";
2382    fn new_unchecked(data: molecule::bytes::Bytes) -> Self {
2383        SignatureOpt(data)
2384    }
2385    fn as_bytes(&self) -> molecule::bytes::Bytes {
2386        self.0.clone()
2387    }
2388    fn as_slice(&self) -> &[u8] {
2389        &self.0[..]
2390    }
2391    fn from_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
2392        SignatureOptReader::from_slice(slice).map(|reader| reader.to_entity())
2393    }
2394    fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
2395        SignatureOptReader::from_compatible_slice(slice).map(|reader| reader.to_entity())
2396    }
2397    fn new_builder() -> Self::Builder {
2398        ::core::default::Default::default()
2399    }
2400    fn as_builder(self) -> Self::Builder {
2401        Self::new_builder().set(self.to_opt())
2402    }
2403}
2404#[derive(Clone, Copy)]
2405pub struct SignatureOptReader<'r>(&'r [u8]);
2406impl<'r> ::core::fmt::LowerHex for SignatureOptReader<'r> {
2407    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
2408        use molecule::hex_string;
2409        if f.alternate() {
2410            write!(f, "0x")?;
2411        }
2412        write!(f, "{}", hex_string(self.as_slice()))
2413    }
2414}
2415impl<'r> ::core::fmt::Debug for SignatureOptReader<'r> {
2416    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
2417        write!(f, "{}({:#x})", Self::NAME, self)
2418    }
2419}
2420impl<'r> ::core::fmt::Display for SignatureOptReader<'r> {
2421    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
2422        if let Some(v) = self.to_opt() {
2423            write!(f, "{}(Some({}))", Self::NAME, v)
2424        } else {
2425            write!(f, "{}(None)", Self::NAME)
2426        }
2427    }
2428}
2429impl<'r> SignatureOptReader<'r> {
2430    pub fn is_none(&self) -> bool {
2431        self.0.is_empty()
2432    }
2433    pub fn is_some(&self) -> bool {
2434        !self.0.is_empty()
2435    }
2436    pub fn to_opt(&self) -> Option<SignatureReader<'r>> {
2437        if self.is_none() {
2438            None
2439        } else {
2440            Some(SignatureReader::new_unchecked(self.as_slice()))
2441        }
2442    }
2443}
2444impl<'r> molecule::prelude::Reader<'r> for SignatureOptReader<'r> {
2445    type Entity = SignatureOpt;
2446    const NAME: &'static str = "SignatureOptReader";
2447    fn to_entity(&self) -> Self::Entity {
2448        Self::Entity::new_unchecked(self.as_slice().to_owned().into())
2449    }
2450    fn new_unchecked(slice: &'r [u8]) -> Self {
2451        SignatureOptReader(slice)
2452    }
2453    fn as_slice(&self) -> &'r [u8] {
2454        self.0
2455    }
2456    fn verify(slice: &[u8], compatible: bool) -> molecule::error::VerificationResult<()> {
2457        if !slice.is_empty() {
2458            SignatureReader::verify(&slice[..], compatible)?;
2459        }
2460        Ok(())
2461    }
2462}
2463#[derive(Clone, Debug, Default)]
2464pub struct SignatureOptBuilder(pub(crate) Option<Signature>);
2465impl SignatureOptBuilder {
2466    pub fn set(mut self, v: Option<Signature>) -> Self {
2467        self.0 = v;
2468        self
2469    }
2470}
2471impl molecule::prelude::Builder for SignatureOptBuilder {
2472    type Entity = SignatureOpt;
2473    const NAME: &'static str = "SignatureOptBuilder";
2474    fn expected_length(&self) -> usize {
2475        self.0
2476            .as_ref()
2477            .map(|ref inner| inner.as_slice().len())
2478            .unwrap_or(0)
2479    }
2480    fn write<W: molecule::io::Write>(&self, writer: &mut W) -> molecule::io::Result<()> {
2481        self.0
2482            .as_ref()
2483            .map(|ref inner| writer.write_all(inner.as_slice()))
2484            .unwrap_or(Ok(()))
2485    }
2486    fn build(&self) -> Self::Entity {
2487        let mut inner = Vec::with_capacity(self.expected_length());
2488        self.write(&mut inner)
2489            .unwrap_or_else(|_| panic!("{} build should be ok", Self::NAME));
2490        SignatureOpt::new_unchecked(inner.into())
2491    }
2492}
2493impl From<Signature> for SignatureOpt {
2494    fn from(value: Signature) -> Self {
2495        Self::new_builder().set(Some(value)).build()
2496    }
2497}
2498#[derive(Clone)]
2499pub struct AmountOpt(molecule::bytes::Bytes);
2500impl ::core::fmt::LowerHex for AmountOpt {
2501    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
2502        use molecule::hex_string;
2503        if f.alternate() {
2504            write!(f, "0x")?;
2505        }
2506        write!(f, "{}", hex_string(self.as_slice()))
2507    }
2508}
2509impl ::core::fmt::Debug for AmountOpt {
2510    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
2511        write!(f, "{}({:#x})", Self::NAME, self)
2512    }
2513}
2514impl ::core::fmt::Display for AmountOpt {
2515    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
2516        if let Some(v) = self.to_opt() {
2517            write!(f, "{}(Some({}))", Self::NAME, v)
2518        } else {
2519            write!(f, "{}(None)", Self::NAME)
2520        }
2521    }
2522}
2523impl ::core::default::Default for AmountOpt {
2524    fn default() -> Self {
2525        let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE);
2526        AmountOpt::new_unchecked(v)
2527    }
2528}
2529impl AmountOpt {
2530    const DEFAULT_VALUE: [u8; 0] = [];
2531    pub fn is_none(&self) -> bool {
2532        self.0.is_empty()
2533    }
2534    pub fn is_some(&self) -> bool {
2535        !self.0.is_empty()
2536    }
2537    pub fn to_opt(&self) -> Option<Uint128> {
2538        if self.is_none() {
2539            None
2540        } else {
2541            Some(Uint128::new_unchecked(self.0.clone()))
2542        }
2543    }
2544    pub fn as_reader<'r>(&'r self) -> AmountOptReader<'r> {
2545        AmountOptReader::new_unchecked(self.as_slice())
2546    }
2547}
2548impl molecule::prelude::Entity for AmountOpt {
2549    type Builder = AmountOptBuilder;
2550    const NAME: &'static str = "AmountOpt";
2551    fn new_unchecked(data: molecule::bytes::Bytes) -> Self {
2552        AmountOpt(data)
2553    }
2554    fn as_bytes(&self) -> molecule::bytes::Bytes {
2555        self.0.clone()
2556    }
2557    fn as_slice(&self) -> &[u8] {
2558        &self.0[..]
2559    }
2560    fn from_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
2561        AmountOptReader::from_slice(slice).map(|reader| reader.to_entity())
2562    }
2563    fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
2564        AmountOptReader::from_compatible_slice(slice).map(|reader| reader.to_entity())
2565    }
2566    fn new_builder() -> Self::Builder {
2567        ::core::default::Default::default()
2568    }
2569    fn as_builder(self) -> Self::Builder {
2570        Self::new_builder().set(self.to_opt())
2571    }
2572}
2573#[derive(Clone, Copy)]
2574pub struct AmountOptReader<'r>(&'r [u8]);
2575impl<'r> ::core::fmt::LowerHex for AmountOptReader<'r> {
2576    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
2577        use molecule::hex_string;
2578        if f.alternate() {
2579            write!(f, "0x")?;
2580        }
2581        write!(f, "{}", hex_string(self.as_slice()))
2582    }
2583}
2584impl<'r> ::core::fmt::Debug for AmountOptReader<'r> {
2585    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
2586        write!(f, "{}({:#x})", Self::NAME, self)
2587    }
2588}
2589impl<'r> ::core::fmt::Display for AmountOptReader<'r> {
2590    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
2591        if let Some(v) = self.to_opt() {
2592            write!(f, "{}(Some({}))", Self::NAME, v)
2593        } else {
2594            write!(f, "{}(None)", Self::NAME)
2595        }
2596    }
2597}
2598impl<'r> AmountOptReader<'r> {
2599    pub fn is_none(&self) -> bool {
2600        self.0.is_empty()
2601    }
2602    pub fn is_some(&self) -> bool {
2603        !self.0.is_empty()
2604    }
2605    pub fn to_opt(&self) -> Option<Uint128Reader<'r>> {
2606        if self.is_none() {
2607            None
2608        } else {
2609            Some(Uint128Reader::new_unchecked(self.as_slice()))
2610        }
2611    }
2612}
2613impl<'r> molecule::prelude::Reader<'r> for AmountOptReader<'r> {
2614    type Entity = AmountOpt;
2615    const NAME: &'static str = "AmountOptReader";
2616    fn to_entity(&self) -> Self::Entity {
2617        Self::Entity::new_unchecked(self.as_slice().to_owned().into())
2618    }
2619    fn new_unchecked(slice: &'r [u8]) -> Self {
2620        AmountOptReader(slice)
2621    }
2622    fn as_slice(&self) -> &'r [u8] {
2623        self.0
2624    }
2625    fn verify(slice: &[u8], compatible: bool) -> molecule::error::VerificationResult<()> {
2626        if !slice.is_empty() {
2627            Uint128Reader::verify(&slice[..], compatible)?;
2628        }
2629        Ok(())
2630    }
2631}
2632#[derive(Clone, Debug, Default)]
2633pub struct AmountOptBuilder(pub(crate) Option<Uint128>);
2634impl AmountOptBuilder {
2635    pub fn set(mut self, v: Option<Uint128>) -> Self {
2636        self.0 = v;
2637        self
2638    }
2639}
2640impl molecule::prelude::Builder for AmountOptBuilder {
2641    type Entity = AmountOpt;
2642    const NAME: &'static str = "AmountOptBuilder";
2643    fn expected_length(&self) -> usize {
2644        self.0
2645            .as_ref()
2646            .map(|ref inner| inner.as_slice().len())
2647            .unwrap_or(0)
2648    }
2649    fn write<W: molecule::io::Write>(&self, writer: &mut W) -> molecule::io::Result<()> {
2650        self.0
2651            .as_ref()
2652            .map(|ref inner| writer.write_all(inner.as_slice()))
2653            .unwrap_or(Ok(()))
2654    }
2655    fn build(&self) -> Self::Entity {
2656        let mut inner = Vec::with_capacity(self.expected_length());
2657        self.write(&mut inner)
2658            .unwrap_or_else(|_| panic!("{} build should be ok", Self::NAME));
2659        AmountOpt::new_unchecked(inner.into())
2660    }
2661}
2662impl From<Uint128> for AmountOpt {
2663    fn from(value: Uint128) -> Self {
2664        Self::new_builder().set(Some(value)).build()
2665    }
2666}
2667#[derive(Clone)]
2668pub struct FinalHtlcTimeout(molecule::bytes::Bytes);
2669impl ::core::fmt::LowerHex for FinalHtlcTimeout {
2670    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
2671        use molecule::hex_string;
2672        if f.alternate() {
2673            write!(f, "0x")?;
2674        }
2675        write!(f, "{}", hex_string(self.as_slice()))
2676    }
2677}
2678impl ::core::fmt::Debug for FinalHtlcTimeout {
2679    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
2680        write!(f, "{}({:#x})", Self::NAME, self)
2681    }
2682}
2683impl ::core::fmt::Display for FinalHtlcTimeout {
2684    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
2685        write!(f, "{} {{ ", Self::NAME)?;
2686        write!(f, "{}: {}", "value", self.value())?;
2687        write!(f, " }}")
2688    }
2689}
2690impl ::core::default::Default for FinalHtlcTimeout {
2691    fn default() -> Self {
2692        let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE);
2693        FinalHtlcTimeout::new_unchecked(v)
2694    }
2695}
2696impl FinalHtlcTimeout {
2697    const DEFAULT_VALUE: [u8; 8] = [0, 0, 0, 0, 0, 0, 0, 0];
2698    pub const TOTAL_SIZE: usize = 8;
2699    pub const FIELD_SIZES: [usize; 1] = [8];
2700    pub const FIELD_COUNT: usize = 1;
2701    pub fn value(&self) -> Uint64 {
2702        Uint64::new_unchecked(self.0.slice(0..8))
2703    }
2704    pub fn as_reader<'r>(&'r self) -> FinalHtlcTimeoutReader<'r> {
2705        FinalHtlcTimeoutReader::new_unchecked(self.as_slice())
2706    }
2707}
2708impl molecule::prelude::Entity for FinalHtlcTimeout {
2709    type Builder = FinalHtlcTimeoutBuilder;
2710    const NAME: &'static str = "FinalHtlcTimeout";
2711    fn new_unchecked(data: molecule::bytes::Bytes) -> Self {
2712        FinalHtlcTimeout(data)
2713    }
2714    fn as_bytes(&self) -> molecule::bytes::Bytes {
2715        self.0.clone()
2716    }
2717    fn as_slice(&self) -> &[u8] {
2718        &self.0[..]
2719    }
2720    fn from_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
2721        FinalHtlcTimeoutReader::from_slice(slice).map(|reader| reader.to_entity())
2722    }
2723    fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
2724        FinalHtlcTimeoutReader::from_compatible_slice(slice).map(|reader| reader.to_entity())
2725    }
2726    fn new_builder() -> Self::Builder {
2727        ::core::default::Default::default()
2728    }
2729    fn as_builder(self) -> Self::Builder {
2730        Self::new_builder().value(self.value())
2731    }
2732}
2733#[derive(Clone, Copy)]
2734pub struct FinalHtlcTimeoutReader<'r>(&'r [u8]);
2735impl<'r> ::core::fmt::LowerHex for FinalHtlcTimeoutReader<'r> {
2736    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
2737        use molecule::hex_string;
2738        if f.alternate() {
2739            write!(f, "0x")?;
2740        }
2741        write!(f, "{}", hex_string(self.as_slice()))
2742    }
2743}
2744impl<'r> ::core::fmt::Debug for FinalHtlcTimeoutReader<'r> {
2745    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
2746        write!(f, "{}({:#x})", Self::NAME, self)
2747    }
2748}
2749impl<'r> ::core::fmt::Display for FinalHtlcTimeoutReader<'r> {
2750    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
2751        write!(f, "{} {{ ", Self::NAME)?;
2752        write!(f, "{}: {}", "value", self.value())?;
2753        write!(f, " }}")
2754    }
2755}
2756impl<'r> FinalHtlcTimeoutReader<'r> {
2757    pub const TOTAL_SIZE: usize = 8;
2758    pub const FIELD_SIZES: [usize; 1] = [8];
2759    pub const FIELD_COUNT: usize = 1;
2760    pub fn value(&self) -> Uint64Reader<'r> {
2761        Uint64Reader::new_unchecked(&self.as_slice()[0..8])
2762    }
2763}
2764impl<'r> molecule::prelude::Reader<'r> for FinalHtlcTimeoutReader<'r> {
2765    type Entity = FinalHtlcTimeout;
2766    const NAME: &'static str = "FinalHtlcTimeoutReader";
2767    fn to_entity(&self) -> Self::Entity {
2768        Self::Entity::new_unchecked(self.as_slice().to_owned().into())
2769    }
2770    fn new_unchecked(slice: &'r [u8]) -> Self {
2771        FinalHtlcTimeoutReader(slice)
2772    }
2773    fn as_slice(&self) -> &'r [u8] {
2774        self.0
2775    }
2776    fn verify(slice: &[u8], _compatible: bool) -> molecule::error::VerificationResult<()> {
2777        use molecule::verification_error as ve;
2778        let slice_len = slice.len();
2779        if slice_len != Self::TOTAL_SIZE {
2780            return ve!(Self, TotalSizeNotMatch, Self::TOTAL_SIZE, slice_len);
2781        }
2782        Ok(())
2783    }
2784}
2785#[derive(Clone, Debug, Default)]
2786pub struct FinalHtlcTimeoutBuilder {
2787    pub(crate) value: Uint64,
2788}
2789impl FinalHtlcTimeoutBuilder {
2790    pub const TOTAL_SIZE: usize = 8;
2791    pub const FIELD_SIZES: [usize; 1] = [8];
2792    pub const FIELD_COUNT: usize = 1;
2793    pub fn value(mut self, v: Uint64) -> Self {
2794        self.value = v;
2795        self
2796    }
2797}
2798impl molecule::prelude::Builder for FinalHtlcTimeoutBuilder {
2799    type Entity = FinalHtlcTimeout;
2800    const NAME: &'static str = "FinalHtlcTimeoutBuilder";
2801    fn expected_length(&self) -> usize {
2802        Self::TOTAL_SIZE
2803    }
2804    fn write<W: molecule::io::Write>(&self, writer: &mut W) -> molecule::io::Result<()> {
2805        writer.write_all(self.value.as_slice())?;
2806        Ok(())
2807    }
2808    fn build(&self) -> Self::Entity {
2809        let mut inner = Vec::with_capacity(self.expected_length());
2810        self.write(&mut inner)
2811            .unwrap_or_else(|_| panic!("{} build should be ok", Self::NAME));
2812        FinalHtlcTimeout::new_unchecked(inner.into())
2813    }
2814}
2815#[derive(Clone)]
2816pub struct FinalHtlcMinimumExpiryDelta(molecule::bytes::Bytes);
2817impl ::core::fmt::LowerHex for FinalHtlcMinimumExpiryDelta {
2818    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
2819        use molecule::hex_string;
2820        if f.alternate() {
2821            write!(f, "0x")?;
2822        }
2823        write!(f, "{}", hex_string(self.as_slice()))
2824    }
2825}
2826impl ::core::fmt::Debug for FinalHtlcMinimumExpiryDelta {
2827    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
2828        write!(f, "{}({:#x})", Self::NAME, self)
2829    }
2830}
2831impl ::core::fmt::Display for FinalHtlcMinimumExpiryDelta {
2832    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
2833        write!(f, "{} {{ ", Self::NAME)?;
2834        write!(f, "{}: {}", "value", self.value())?;
2835        write!(f, " }}")
2836    }
2837}
2838impl ::core::default::Default for FinalHtlcMinimumExpiryDelta {
2839    fn default() -> Self {
2840        let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE);
2841        FinalHtlcMinimumExpiryDelta::new_unchecked(v)
2842    }
2843}
2844impl FinalHtlcMinimumExpiryDelta {
2845    const DEFAULT_VALUE: [u8; 8] = [0, 0, 0, 0, 0, 0, 0, 0];
2846    pub const TOTAL_SIZE: usize = 8;
2847    pub const FIELD_SIZES: [usize; 1] = [8];
2848    pub const FIELD_COUNT: usize = 1;
2849    pub fn value(&self) -> Uint64 {
2850        Uint64::new_unchecked(self.0.slice(0..8))
2851    }
2852    pub fn as_reader<'r>(&'r self) -> FinalHtlcMinimumExpiryDeltaReader<'r> {
2853        FinalHtlcMinimumExpiryDeltaReader::new_unchecked(self.as_slice())
2854    }
2855}
2856impl molecule::prelude::Entity for FinalHtlcMinimumExpiryDelta {
2857    type Builder = FinalHtlcMinimumExpiryDeltaBuilder;
2858    const NAME: &'static str = "FinalHtlcMinimumExpiryDelta";
2859    fn new_unchecked(data: molecule::bytes::Bytes) -> Self {
2860        FinalHtlcMinimumExpiryDelta(data)
2861    }
2862    fn as_bytes(&self) -> molecule::bytes::Bytes {
2863        self.0.clone()
2864    }
2865    fn as_slice(&self) -> &[u8] {
2866        &self.0[..]
2867    }
2868    fn from_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
2869        FinalHtlcMinimumExpiryDeltaReader::from_slice(slice).map(|reader| reader.to_entity())
2870    }
2871    fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
2872        FinalHtlcMinimumExpiryDeltaReader::from_compatible_slice(slice)
2873            .map(|reader| reader.to_entity())
2874    }
2875    fn new_builder() -> Self::Builder {
2876        ::core::default::Default::default()
2877    }
2878    fn as_builder(self) -> Self::Builder {
2879        Self::new_builder().value(self.value())
2880    }
2881}
2882#[derive(Clone, Copy)]
2883pub struct FinalHtlcMinimumExpiryDeltaReader<'r>(&'r [u8]);
2884impl<'r> ::core::fmt::LowerHex for FinalHtlcMinimumExpiryDeltaReader<'r> {
2885    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
2886        use molecule::hex_string;
2887        if f.alternate() {
2888            write!(f, "0x")?;
2889        }
2890        write!(f, "{}", hex_string(self.as_slice()))
2891    }
2892}
2893impl<'r> ::core::fmt::Debug for FinalHtlcMinimumExpiryDeltaReader<'r> {
2894    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
2895        write!(f, "{}({:#x})", Self::NAME, self)
2896    }
2897}
2898impl<'r> ::core::fmt::Display for FinalHtlcMinimumExpiryDeltaReader<'r> {
2899    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
2900        write!(f, "{} {{ ", Self::NAME)?;
2901        write!(f, "{}: {}", "value", self.value())?;
2902        write!(f, " }}")
2903    }
2904}
2905impl<'r> FinalHtlcMinimumExpiryDeltaReader<'r> {
2906    pub const TOTAL_SIZE: usize = 8;
2907    pub const FIELD_SIZES: [usize; 1] = [8];
2908    pub const FIELD_COUNT: usize = 1;
2909    pub fn value(&self) -> Uint64Reader<'r> {
2910        Uint64Reader::new_unchecked(&self.as_slice()[0..8])
2911    }
2912}
2913impl<'r> molecule::prelude::Reader<'r> for FinalHtlcMinimumExpiryDeltaReader<'r> {
2914    type Entity = FinalHtlcMinimumExpiryDelta;
2915    const NAME: &'static str = "FinalHtlcMinimumExpiryDeltaReader";
2916    fn to_entity(&self) -> Self::Entity {
2917        Self::Entity::new_unchecked(self.as_slice().to_owned().into())
2918    }
2919    fn new_unchecked(slice: &'r [u8]) -> Self {
2920        FinalHtlcMinimumExpiryDeltaReader(slice)
2921    }
2922    fn as_slice(&self) -> &'r [u8] {
2923        self.0
2924    }
2925    fn verify(slice: &[u8], _compatible: bool) -> molecule::error::VerificationResult<()> {
2926        use molecule::verification_error as ve;
2927        let slice_len = slice.len();
2928        if slice_len != Self::TOTAL_SIZE {
2929            return ve!(Self, TotalSizeNotMatch, Self::TOTAL_SIZE, slice_len);
2930        }
2931        Ok(())
2932    }
2933}
2934#[derive(Clone, Debug, Default)]
2935pub struct FinalHtlcMinimumExpiryDeltaBuilder {
2936    pub(crate) value: Uint64,
2937}
2938impl FinalHtlcMinimumExpiryDeltaBuilder {
2939    pub const TOTAL_SIZE: usize = 8;
2940    pub const FIELD_SIZES: [usize; 1] = [8];
2941    pub const FIELD_COUNT: usize = 1;
2942    pub fn value(mut self, v: Uint64) -> Self {
2943        self.value = v;
2944        self
2945    }
2946}
2947impl molecule::prelude::Builder for FinalHtlcMinimumExpiryDeltaBuilder {
2948    type Entity = FinalHtlcMinimumExpiryDelta;
2949    const NAME: &'static str = "FinalHtlcMinimumExpiryDeltaBuilder";
2950    fn expected_length(&self) -> usize {
2951        Self::TOTAL_SIZE
2952    }
2953    fn write<W: molecule::io::Write>(&self, writer: &mut W) -> molecule::io::Result<()> {
2954        writer.write_all(self.value.as_slice())?;
2955        Ok(())
2956    }
2957    fn build(&self) -> Self::Entity {
2958        let mut inner = Vec::with_capacity(self.expected_length());
2959        self.write(&mut inner)
2960            .unwrap_or_else(|_| panic!("{} build should be ok", Self::NAME));
2961        FinalHtlcMinimumExpiryDelta::new_unchecked(inner.into())
2962    }
2963}
2964#[derive(Clone)]
2965pub struct ExpiryTime(molecule::bytes::Bytes);
2966impl ::core::fmt::LowerHex for ExpiryTime {
2967    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
2968        use molecule::hex_string;
2969        if f.alternate() {
2970            write!(f, "0x")?;
2971        }
2972        write!(f, "{}", hex_string(self.as_slice()))
2973    }
2974}
2975impl ::core::fmt::Debug for ExpiryTime {
2976    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
2977        write!(f, "{}({:#x})", Self::NAME, self)
2978    }
2979}
2980impl ::core::fmt::Display for ExpiryTime {
2981    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
2982        write!(f, "{} {{ ", Self::NAME)?;
2983        write!(f, "{}: {}", "value", self.value())?;
2984        write!(f, " }}")
2985    }
2986}
2987impl ::core::default::Default for ExpiryTime {
2988    fn default() -> Self {
2989        let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE);
2990        ExpiryTime::new_unchecked(v)
2991    }
2992}
2993impl ExpiryTime {
2994    const DEFAULT_VALUE: [u8; 8] = [0, 0, 0, 0, 0, 0, 0, 0];
2995    pub const TOTAL_SIZE: usize = 8;
2996    pub const FIELD_SIZES: [usize; 1] = [8];
2997    pub const FIELD_COUNT: usize = 1;
2998    pub fn value(&self) -> Uint64 {
2999        Uint64::new_unchecked(self.0.slice(0..8))
3000    }
3001    pub fn as_reader<'r>(&'r self) -> ExpiryTimeReader<'r> {
3002        ExpiryTimeReader::new_unchecked(self.as_slice())
3003    }
3004}
3005impl molecule::prelude::Entity for ExpiryTime {
3006    type Builder = ExpiryTimeBuilder;
3007    const NAME: &'static str = "ExpiryTime";
3008    fn new_unchecked(data: molecule::bytes::Bytes) -> Self {
3009        ExpiryTime(data)
3010    }
3011    fn as_bytes(&self) -> molecule::bytes::Bytes {
3012        self.0.clone()
3013    }
3014    fn as_slice(&self) -> &[u8] {
3015        &self.0[..]
3016    }
3017    fn from_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
3018        ExpiryTimeReader::from_slice(slice).map(|reader| reader.to_entity())
3019    }
3020    fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
3021        ExpiryTimeReader::from_compatible_slice(slice).map(|reader| reader.to_entity())
3022    }
3023    fn new_builder() -> Self::Builder {
3024        ::core::default::Default::default()
3025    }
3026    fn as_builder(self) -> Self::Builder {
3027        Self::new_builder().value(self.value())
3028    }
3029}
3030#[derive(Clone, Copy)]
3031pub struct ExpiryTimeReader<'r>(&'r [u8]);
3032impl<'r> ::core::fmt::LowerHex for ExpiryTimeReader<'r> {
3033    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
3034        use molecule::hex_string;
3035        if f.alternate() {
3036            write!(f, "0x")?;
3037        }
3038        write!(f, "{}", hex_string(self.as_slice()))
3039    }
3040}
3041impl<'r> ::core::fmt::Debug for ExpiryTimeReader<'r> {
3042    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
3043        write!(f, "{}({:#x})", Self::NAME, self)
3044    }
3045}
3046impl<'r> ::core::fmt::Display for ExpiryTimeReader<'r> {
3047    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
3048        write!(f, "{} {{ ", Self::NAME)?;
3049        write!(f, "{}: {}", "value", self.value())?;
3050        write!(f, " }}")
3051    }
3052}
3053impl<'r> ExpiryTimeReader<'r> {
3054    pub const TOTAL_SIZE: usize = 8;
3055    pub const FIELD_SIZES: [usize; 1] = [8];
3056    pub const FIELD_COUNT: usize = 1;
3057    pub fn value(&self) -> Uint64Reader<'r> {
3058        Uint64Reader::new_unchecked(&self.as_slice()[0..8])
3059    }
3060}
3061impl<'r> molecule::prelude::Reader<'r> for ExpiryTimeReader<'r> {
3062    type Entity = ExpiryTime;
3063    const NAME: &'static str = "ExpiryTimeReader";
3064    fn to_entity(&self) -> Self::Entity {
3065        Self::Entity::new_unchecked(self.as_slice().to_owned().into())
3066    }
3067    fn new_unchecked(slice: &'r [u8]) -> Self {
3068        ExpiryTimeReader(slice)
3069    }
3070    fn as_slice(&self) -> &'r [u8] {
3071        self.0
3072    }
3073    fn verify(slice: &[u8], _compatible: bool) -> molecule::error::VerificationResult<()> {
3074        use molecule::verification_error as ve;
3075        let slice_len = slice.len();
3076        if slice_len != Self::TOTAL_SIZE {
3077            return ve!(Self, TotalSizeNotMatch, Self::TOTAL_SIZE, slice_len);
3078        }
3079        Ok(())
3080    }
3081}
3082#[derive(Clone, Debug, Default)]
3083pub struct ExpiryTimeBuilder {
3084    pub(crate) value: Uint64,
3085}
3086impl ExpiryTimeBuilder {
3087    pub const TOTAL_SIZE: usize = 8;
3088    pub const FIELD_SIZES: [usize; 1] = [8];
3089    pub const FIELD_COUNT: usize = 1;
3090    pub fn value(mut self, v: Uint64) -> Self {
3091        self.value = v;
3092        self
3093    }
3094}
3095impl molecule::prelude::Builder for ExpiryTimeBuilder {
3096    type Entity = ExpiryTime;
3097    const NAME: &'static str = "ExpiryTimeBuilder";
3098    fn expected_length(&self) -> usize {
3099        Self::TOTAL_SIZE
3100    }
3101    fn write<W: molecule::io::Write>(&self, writer: &mut W) -> molecule::io::Result<()> {
3102        writer.write_all(self.value.as_slice())?;
3103        Ok(())
3104    }
3105    fn build(&self) -> Self::Entity {
3106        let mut inner = Vec::with_capacity(self.expected_length());
3107        self.write(&mut inner)
3108            .unwrap_or_else(|_| panic!("{} build should be ok", Self::NAME));
3109        ExpiryTime::new_unchecked(inner.into())
3110    }
3111}
3112#[derive(Clone)]
3113pub struct Description(molecule::bytes::Bytes);
3114impl ::core::fmt::LowerHex for Description {
3115    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
3116        use molecule::hex_string;
3117        if f.alternate() {
3118            write!(f, "0x")?;
3119        }
3120        write!(f, "{}", hex_string(self.as_slice()))
3121    }
3122}
3123impl ::core::fmt::Debug for Description {
3124    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
3125        write!(f, "{}({:#x})", Self::NAME, self)
3126    }
3127}
3128impl ::core::fmt::Display for Description {
3129    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
3130        write!(f, "{} {{ ", Self::NAME)?;
3131        write!(f, "{}: {}", "value", self.value())?;
3132        let extra_count = self.count_extra_fields();
3133        if extra_count != 0 {
3134            write!(f, ", .. ({} fields)", extra_count)?;
3135        }
3136        write!(f, " }}")
3137    }
3138}
3139impl ::core::default::Default for Description {
3140    fn default() -> Self {
3141        let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE);
3142        Description::new_unchecked(v)
3143    }
3144}
3145impl Description {
3146    const DEFAULT_VALUE: [u8; 12] = [12, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0];
3147    pub const FIELD_COUNT: usize = 1;
3148    pub fn total_size(&self) -> usize {
3149        molecule::unpack_number(self.as_slice()) as usize
3150    }
3151    pub fn field_count(&self) -> usize {
3152        if self.total_size() == molecule::NUMBER_SIZE {
3153            0
3154        } else {
3155            (molecule::unpack_number(&self.as_slice()[molecule::NUMBER_SIZE..]) as usize / 4) - 1
3156        }
3157    }
3158    pub fn count_extra_fields(&self) -> usize {
3159        self.field_count() - Self::FIELD_COUNT
3160    }
3161    pub fn has_extra_fields(&self) -> bool {
3162        Self::FIELD_COUNT != self.field_count()
3163    }
3164    pub fn value(&self) -> Bytes {
3165        let slice = self.as_slice();
3166        let start = molecule::unpack_number(&slice[4..]) as usize;
3167        if self.has_extra_fields() {
3168            let end = molecule::unpack_number(&slice[8..]) as usize;
3169            Bytes::new_unchecked(self.0.slice(start..end))
3170        } else {
3171            Bytes::new_unchecked(self.0.slice(start..))
3172        }
3173    }
3174    pub fn as_reader<'r>(&'r self) -> DescriptionReader<'r> {
3175        DescriptionReader::new_unchecked(self.as_slice())
3176    }
3177}
3178impl molecule::prelude::Entity for Description {
3179    type Builder = DescriptionBuilder;
3180    const NAME: &'static str = "Description";
3181    fn new_unchecked(data: molecule::bytes::Bytes) -> Self {
3182        Description(data)
3183    }
3184    fn as_bytes(&self) -> molecule::bytes::Bytes {
3185        self.0.clone()
3186    }
3187    fn as_slice(&self) -> &[u8] {
3188        &self.0[..]
3189    }
3190    fn from_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
3191        DescriptionReader::from_slice(slice).map(|reader| reader.to_entity())
3192    }
3193    fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
3194        DescriptionReader::from_compatible_slice(slice).map(|reader| reader.to_entity())
3195    }
3196    fn new_builder() -> Self::Builder {
3197        ::core::default::Default::default()
3198    }
3199    fn as_builder(self) -> Self::Builder {
3200        Self::new_builder().value(self.value())
3201    }
3202}
3203#[derive(Clone, Copy)]
3204pub struct DescriptionReader<'r>(&'r [u8]);
3205impl<'r> ::core::fmt::LowerHex for DescriptionReader<'r> {
3206    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
3207        use molecule::hex_string;
3208        if f.alternate() {
3209            write!(f, "0x")?;
3210        }
3211        write!(f, "{}", hex_string(self.as_slice()))
3212    }
3213}
3214impl<'r> ::core::fmt::Debug for DescriptionReader<'r> {
3215    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
3216        write!(f, "{}({:#x})", Self::NAME, self)
3217    }
3218}
3219impl<'r> ::core::fmt::Display for DescriptionReader<'r> {
3220    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
3221        write!(f, "{} {{ ", Self::NAME)?;
3222        write!(f, "{}: {}", "value", self.value())?;
3223        let extra_count = self.count_extra_fields();
3224        if extra_count != 0 {
3225            write!(f, ", .. ({} fields)", extra_count)?;
3226        }
3227        write!(f, " }}")
3228    }
3229}
3230impl<'r> DescriptionReader<'r> {
3231    pub const FIELD_COUNT: usize = 1;
3232    pub fn total_size(&self) -> usize {
3233        molecule::unpack_number(self.as_slice()) as usize
3234    }
3235    pub fn field_count(&self) -> usize {
3236        if self.total_size() == molecule::NUMBER_SIZE {
3237            0
3238        } else {
3239            (molecule::unpack_number(&self.as_slice()[molecule::NUMBER_SIZE..]) as usize / 4) - 1
3240        }
3241    }
3242    pub fn count_extra_fields(&self) -> usize {
3243        self.field_count() - Self::FIELD_COUNT
3244    }
3245    pub fn has_extra_fields(&self) -> bool {
3246        Self::FIELD_COUNT != self.field_count()
3247    }
3248    pub fn value(&self) -> BytesReader<'r> {
3249        let slice = self.as_slice();
3250        let start = molecule::unpack_number(&slice[4..]) as usize;
3251        if self.has_extra_fields() {
3252            let end = molecule::unpack_number(&slice[8..]) as usize;
3253            BytesReader::new_unchecked(&self.as_slice()[start..end])
3254        } else {
3255            BytesReader::new_unchecked(&self.as_slice()[start..])
3256        }
3257    }
3258}
3259impl<'r> molecule::prelude::Reader<'r> for DescriptionReader<'r> {
3260    type Entity = Description;
3261    const NAME: &'static str = "DescriptionReader";
3262    fn to_entity(&self) -> Self::Entity {
3263        Self::Entity::new_unchecked(self.as_slice().to_owned().into())
3264    }
3265    fn new_unchecked(slice: &'r [u8]) -> Self {
3266        DescriptionReader(slice)
3267    }
3268    fn as_slice(&self) -> &'r [u8] {
3269        self.0
3270    }
3271    fn verify(slice: &[u8], compatible: bool) -> molecule::error::VerificationResult<()> {
3272        use molecule::verification_error as ve;
3273        let slice_len = slice.len();
3274        if slice_len < molecule::NUMBER_SIZE {
3275            return ve!(Self, HeaderIsBroken, molecule::NUMBER_SIZE, slice_len);
3276        }
3277        let total_size = molecule::unpack_number(slice) as usize;
3278        if slice_len != total_size {
3279            return ve!(Self, TotalSizeNotMatch, total_size, slice_len);
3280        }
3281        if slice_len < molecule::NUMBER_SIZE * 2 {
3282            return ve!(Self, HeaderIsBroken, molecule::NUMBER_SIZE * 2, slice_len);
3283        }
3284        let offset_first = molecule::unpack_number(&slice[molecule::NUMBER_SIZE..]) as usize;
3285        if offset_first % molecule::NUMBER_SIZE != 0 || offset_first < molecule::NUMBER_SIZE * 2 {
3286            return ve!(Self, OffsetsNotMatch);
3287        }
3288        if slice_len < offset_first {
3289            return ve!(Self, HeaderIsBroken, offset_first, slice_len);
3290        }
3291        let field_count = offset_first / molecule::NUMBER_SIZE - 1;
3292        if field_count < Self::FIELD_COUNT {
3293            return ve!(Self, FieldCountNotMatch, Self::FIELD_COUNT, field_count);
3294        } else if !compatible && field_count > Self::FIELD_COUNT {
3295            return ve!(Self, FieldCountNotMatch, Self::FIELD_COUNT, field_count);
3296        };
3297        let mut offsets: Vec<usize> = slice[molecule::NUMBER_SIZE..offset_first]
3298            .chunks_exact(molecule::NUMBER_SIZE)
3299            .map(|x| molecule::unpack_number(x) as usize)
3300            .collect();
3301        offsets.push(total_size);
3302        if offsets.windows(2).any(|i| i[0] > i[1]) {
3303            return ve!(Self, OffsetsNotMatch);
3304        }
3305        BytesReader::verify(&slice[offsets[0]..offsets[1]], compatible)?;
3306        Ok(())
3307    }
3308}
3309#[derive(Clone, Debug, Default)]
3310pub struct DescriptionBuilder {
3311    pub(crate) value: Bytes,
3312}
3313impl DescriptionBuilder {
3314    pub const FIELD_COUNT: usize = 1;
3315    pub fn value(mut self, v: Bytes) -> Self {
3316        self.value = v;
3317        self
3318    }
3319}
3320impl molecule::prelude::Builder for DescriptionBuilder {
3321    type Entity = Description;
3322    const NAME: &'static str = "DescriptionBuilder";
3323    fn expected_length(&self) -> usize {
3324        molecule::NUMBER_SIZE * (Self::FIELD_COUNT + 1) + self.value.as_slice().len()
3325    }
3326    fn write<W: molecule::io::Write>(&self, writer: &mut W) -> molecule::io::Result<()> {
3327        let mut total_size = molecule::NUMBER_SIZE * (Self::FIELD_COUNT + 1);
3328        let mut offsets = Vec::with_capacity(Self::FIELD_COUNT);
3329        offsets.push(total_size);
3330        total_size += self.value.as_slice().len();
3331        writer.write_all(&molecule::pack_number(total_size as molecule::Number))?;
3332        for offset in offsets.into_iter() {
3333            writer.write_all(&molecule::pack_number(offset as molecule::Number))?;
3334        }
3335        writer.write_all(self.value.as_slice())?;
3336        Ok(())
3337    }
3338    fn build(&self) -> Self::Entity {
3339        let mut inner = Vec::with_capacity(self.expected_length());
3340        self.write(&mut inner)
3341            .unwrap_or_else(|_| panic!("{} build should be ok", Self::NAME));
3342        Description::new_unchecked(inner.into())
3343    }
3344}
3345#[derive(Clone)]
3346pub struct FallbackAddr(molecule::bytes::Bytes);
3347impl ::core::fmt::LowerHex for FallbackAddr {
3348    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
3349        use molecule::hex_string;
3350        if f.alternate() {
3351            write!(f, "0x")?;
3352        }
3353        write!(f, "{}", hex_string(self.as_slice()))
3354    }
3355}
3356impl ::core::fmt::Debug for FallbackAddr {
3357    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
3358        write!(f, "{}({:#x})", Self::NAME, self)
3359    }
3360}
3361impl ::core::fmt::Display for FallbackAddr {
3362    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
3363        write!(f, "{} {{ ", Self::NAME)?;
3364        write!(f, "{}: {}", "value", self.value())?;
3365        let extra_count = self.count_extra_fields();
3366        if extra_count != 0 {
3367            write!(f, ", .. ({} fields)", extra_count)?;
3368        }
3369        write!(f, " }}")
3370    }
3371}
3372impl ::core::default::Default for FallbackAddr {
3373    fn default() -> Self {
3374        let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE);
3375        FallbackAddr::new_unchecked(v)
3376    }
3377}
3378impl FallbackAddr {
3379    const DEFAULT_VALUE: [u8; 12] = [12, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0];
3380    pub const FIELD_COUNT: usize = 1;
3381    pub fn total_size(&self) -> usize {
3382        molecule::unpack_number(self.as_slice()) as usize
3383    }
3384    pub fn field_count(&self) -> usize {
3385        if self.total_size() == molecule::NUMBER_SIZE {
3386            0
3387        } else {
3388            (molecule::unpack_number(&self.as_slice()[molecule::NUMBER_SIZE..]) as usize / 4) - 1
3389        }
3390    }
3391    pub fn count_extra_fields(&self) -> usize {
3392        self.field_count() - Self::FIELD_COUNT
3393    }
3394    pub fn has_extra_fields(&self) -> bool {
3395        Self::FIELD_COUNT != self.field_count()
3396    }
3397    pub fn value(&self) -> Bytes {
3398        let slice = self.as_slice();
3399        let start = molecule::unpack_number(&slice[4..]) as usize;
3400        if self.has_extra_fields() {
3401            let end = molecule::unpack_number(&slice[8..]) as usize;
3402            Bytes::new_unchecked(self.0.slice(start..end))
3403        } else {
3404            Bytes::new_unchecked(self.0.slice(start..))
3405        }
3406    }
3407    pub fn as_reader<'r>(&'r self) -> FallbackAddrReader<'r> {
3408        FallbackAddrReader::new_unchecked(self.as_slice())
3409    }
3410}
3411impl molecule::prelude::Entity for FallbackAddr {
3412    type Builder = FallbackAddrBuilder;
3413    const NAME: &'static str = "FallbackAddr";
3414    fn new_unchecked(data: molecule::bytes::Bytes) -> Self {
3415        FallbackAddr(data)
3416    }
3417    fn as_bytes(&self) -> molecule::bytes::Bytes {
3418        self.0.clone()
3419    }
3420    fn as_slice(&self) -> &[u8] {
3421        &self.0[..]
3422    }
3423    fn from_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
3424        FallbackAddrReader::from_slice(slice).map(|reader| reader.to_entity())
3425    }
3426    fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
3427        FallbackAddrReader::from_compatible_slice(slice).map(|reader| reader.to_entity())
3428    }
3429    fn new_builder() -> Self::Builder {
3430        ::core::default::Default::default()
3431    }
3432    fn as_builder(self) -> Self::Builder {
3433        Self::new_builder().value(self.value())
3434    }
3435}
3436#[derive(Clone, Copy)]
3437pub struct FallbackAddrReader<'r>(&'r [u8]);
3438impl<'r> ::core::fmt::LowerHex for FallbackAddrReader<'r> {
3439    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
3440        use molecule::hex_string;
3441        if f.alternate() {
3442            write!(f, "0x")?;
3443        }
3444        write!(f, "{}", hex_string(self.as_slice()))
3445    }
3446}
3447impl<'r> ::core::fmt::Debug for FallbackAddrReader<'r> {
3448    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
3449        write!(f, "{}({:#x})", Self::NAME, self)
3450    }
3451}
3452impl<'r> ::core::fmt::Display for FallbackAddrReader<'r> {
3453    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
3454        write!(f, "{} {{ ", Self::NAME)?;
3455        write!(f, "{}: {}", "value", self.value())?;
3456        let extra_count = self.count_extra_fields();
3457        if extra_count != 0 {
3458            write!(f, ", .. ({} fields)", extra_count)?;
3459        }
3460        write!(f, " }}")
3461    }
3462}
3463impl<'r> FallbackAddrReader<'r> {
3464    pub const FIELD_COUNT: usize = 1;
3465    pub fn total_size(&self) -> usize {
3466        molecule::unpack_number(self.as_slice()) as usize
3467    }
3468    pub fn field_count(&self) -> usize {
3469        if self.total_size() == molecule::NUMBER_SIZE {
3470            0
3471        } else {
3472            (molecule::unpack_number(&self.as_slice()[molecule::NUMBER_SIZE..]) as usize / 4) - 1
3473        }
3474    }
3475    pub fn count_extra_fields(&self) -> usize {
3476        self.field_count() - Self::FIELD_COUNT
3477    }
3478    pub fn has_extra_fields(&self) -> bool {
3479        Self::FIELD_COUNT != self.field_count()
3480    }
3481    pub fn value(&self) -> BytesReader<'r> {
3482        let slice = self.as_slice();
3483        let start = molecule::unpack_number(&slice[4..]) as usize;
3484        if self.has_extra_fields() {
3485            let end = molecule::unpack_number(&slice[8..]) as usize;
3486            BytesReader::new_unchecked(&self.as_slice()[start..end])
3487        } else {
3488            BytesReader::new_unchecked(&self.as_slice()[start..])
3489        }
3490    }
3491}
3492impl<'r> molecule::prelude::Reader<'r> for FallbackAddrReader<'r> {
3493    type Entity = FallbackAddr;
3494    const NAME: &'static str = "FallbackAddrReader";
3495    fn to_entity(&self) -> Self::Entity {
3496        Self::Entity::new_unchecked(self.as_slice().to_owned().into())
3497    }
3498    fn new_unchecked(slice: &'r [u8]) -> Self {
3499        FallbackAddrReader(slice)
3500    }
3501    fn as_slice(&self) -> &'r [u8] {
3502        self.0
3503    }
3504    fn verify(slice: &[u8], compatible: bool) -> molecule::error::VerificationResult<()> {
3505        use molecule::verification_error as ve;
3506        let slice_len = slice.len();
3507        if slice_len < molecule::NUMBER_SIZE {
3508            return ve!(Self, HeaderIsBroken, molecule::NUMBER_SIZE, slice_len);
3509        }
3510        let total_size = molecule::unpack_number(slice) as usize;
3511        if slice_len != total_size {
3512            return ve!(Self, TotalSizeNotMatch, total_size, slice_len);
3513        }
3514        if slice_len < molecule::NUMBER_SIZE * 2 {
3515            return ve!(Self, HeaderIsBroken, molecule::NUMBER_SIZE * 2, slice_len);
3516        }
3517        let offset_first = molecule::unpack_number(&slice[molecule::NUMBER_SIZE..]) as usize;
3518        if offset_first % molecule::NUMBER_SIZE != 0 || offset_first < molecule::NUMBER_SIZE * 2 {
3519            return ve!(Self, OffsetsNotMatch);
3520        }
3521        if slice_len < offset_first {
3522            return ve!(Self, HeaderIsBroken, offset_first, slice_len);
3523        }
3524        let field_count = offset_first / molecule::NUMBER_SIZE - 1;
3525        if field_count < Self::FIELD_COUNT {
3526            return ve!(Self, FieldCountNotMatch, Self::FIELD_COUNT, field_count);
3527        } else if !compatible && field_count > Self::FIELD_COUNT {
3528            return ve!(Self, FieldCountNotMatch, Self::FIELD_COUNT, field_count);
3529        };
3530        let mut offsets: Vec<usize> = slice[molecule::NUMBER_SIZE..offset_first]
3531            .chunks_exact(molecule::NUMBER_SIZE)
3532            .map(|x| molecule::unpack_number(x) as usize)
3533            .collect();
3534        offsets.push(total_size);
3535        if offsets.windows(2).any(|i| i[0] > i[1]) {
3536            return ve!(Self, OffsetsNotMatch);
3537        }
3538        BytesReader::verify(&slice[offsets[0]..offsets[1]], compatible)?;
3539        Ok(())
3540    }
3541}
3542#[derive(Clone, Debug, Default)]
3543pub struct FallbackAddrBuilder {
3544    pub(crate) value: Bytes,
3545}
3546impl FallbackAddrBuilder {
3547    pub const FIELD_COUNT: usize = 1;
3548    pub fn value(mut self, v: Bytes) -> Self {
3549        self.value = v;
3550        self
3551    }
3552}
3553impl molecule::prelude::Builder for FallbackAddrBuilder {
3554    type Entity = FallbackAddr;
3555    const NAME: &'static str = "FallbackAddrBuilder";
3556    fn expected_length(&self) -> usize {
3557        molecule::NUMBER_SIZE * (Self::FIELD_COUNT + 1) + self.value.as_slice().len()
3558    }
3559    fn write<W: molecule::io::Write>(&self, writer: &mut W) -> molecule::io::Result<()> {
3560        let mut total_size = molecule::NUMBER_SIZE * (Self::FIELD_COUNT + 1);
3561        let mut offsets = Vec::with_capacity(Self::FIELD_COUNT);
3562        offsets.push(total_size);
3563        total_size += self.value.as_slice().len();
3564        writer.write_all(&molecule::pack_number(total_size as molecule::Number))?;
3565        for offset in offsets.into_iter() {
3566            writer.write_all(&molecule::pack_number(offset as molecule::Number))?;
3567        }
3568        writer.write_all(self.value.as_slice())?;
3569        Ok(())
3570    }
3571    fn build(&self) -> Self::Entity {
3572        let mut inner = Vec::with_capacity(self.expected_length());
3573        self.write(&mut inner)
3574            .unwrap_or_else(|_| panic!("{} build should be ok", Self::NAME));
3575        FallbackAddr::new_unchecked(inner.into())
3576    }
3577}
3578#[derive(Clone)]
3579pub struct Feature(molecule::bytes::Bytes);
3580impl ::core::fmt::LowerHex for Feature {
3581    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
3582        use molecule::hex_string;
3583        if f.alternate() {
3584            write!(f, "0x")?;
3585        }
3586        write!(f, "{}", hex_string(self.as_slice()))
3587    }
3588}
3589impl ::core::fmt::Debug for Feature {
3590    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
3591        write!(f, "{}({:#x})", Self::NAME, self)
3592    }
3593}
3594impl ::core::fmt::Display for Feature {
3595    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
3596        write!(f, "{} {{ ", Self::NAME)?;
3597        write!(f, "{}: {}", "value", self.value())?;
3598        let extra_count = self.count_extra_fields();
3599        if extra_count != 0 {
3600            write!(f, ", .. ({} fields)", extra_count)?;
3601        }
3602        write!(f, " }}")
3603    }
3604}
3605impl ::core::default::Default for Feature {
3606    fn default() -> Self {
3607        let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE);
3608        Feature::new_unchecked(v)
3609    }
3610}
3611impl Feature {
3612    const DEFAULT_VALUE: [u8; 12] = [12, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0];
3613    pub const FIELD_COUNT: usize = 1;
3614    pub fn total_size(&self) -> usize {
3615        molecule::unpack_number(self.as_slice()) as usize
3616    }
3617    pub fn field_count(&self) -> usize {
3618        if self.total_size() == molecule::NUMBER_SIZE {
3619            0
3620        } else {
3621            (molecule::unpack_number(&self.as_slice()[molecule::NUMBER_SIZE..]) as usize / 4) - 1
3622        }
3623    }
3624    pub fn count_extra_fields(&self) -> usize {
3625        self.field_count() - Self::FIELD_COUNT
3626    }
3627    pub fn has_extra_fields(&self) -> bool {
3628        Self::FIELD_COUNT != self.field_count()
3629    }
3630    pub fn value(&self) -> Bytes {
3631        let slice = self.as_slice();
3632        let start = molecule::unpack_number(&slice[4..]) as usize;
3633        if self.has_extra_fields() {
3634            let end = molecule::unpack_number(&slice[8..]) as usize;
3635            Bytes::new_unchecked(self.0.slice(start..end))
3636        } else {
3637            Bytes::new_unchecked(self.0.slice(start..))
3638        }
3639    }
3640    pub fn as_reader<'r>(&'r self) -> FeatureReader<'r> {
3641        FeatureReader::new_unchecked(self.as_slice())
3642    }
3643}
3644impl molecule::prelude::Entity for Feature {
3645    type Builder = FeatureBuilder;
3646    const NAME: &'static str = "Feature";
3647    fn new_unchecked(data: molecule::bytes::Bytes) -> Self {
3648        Feature(data)
3649    }
3650    fn as_bytes(&self) -> molecule::bytes::Bytes {
3651        self.0.clone()
3652    }
3653    fn as_slice(&self) -> &[u8] {
3654        &self.0[..]
3655    }
3656    fn from_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
3657        FeatureReader::from_slice(slice).map(|reader| reader.to_entity())
3658    }
3659    fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
3660        FeatureReader::from_compatible_slice(slice).map(|reader| reader.to_entity())
3661    }
3662    fn new_builder() -> Self::Builder {
3663        ::core::default::Default::default()
3664    }
3665    fn as_builder(self) -> Self::Builder {
3666        Self::new_builder().value(self.value())
3667    }
3668}
3669#[derive(Clone, Copy)]
3670pub struct FeatureReader<'r>(&'r [u8]);
3671impl<'r> ::core::fmt::LowerHex for FeatureReader<'r> {
3672    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
3673        use molecule::hex_string;
3674        if f.alternate() {
3675            write!(f, "0x")?;
3676        }
3677        write!(f, "{}", hex_string(self.as_slice()))
3678    }
3679}
3680impl<'r> ::core::fmt::Debug for FeatureReader<'r> {
3681    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
3682        write!(f, "{}({:#x})", Self::NAME, self)
3683    }
3684}
3685impl<'r> ::core::fmt::Display for FeatureReader<'r> {
3686    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
3687        write!(f, "{} {{ ", Self::NAME)?;
3688        write!(f, "{}: {}", "value", self.value())?;
3689        let extra_count = self.count_extra_fields();
3690        if extra_count != 0 {
3691            write!(f, ", .. ({} fields)", extra_count)?;
3692        }
3693        write!(f, " }}")
3694    }
3695}
3696impl<'r> FeatureReader<'r> {
3697    pub const FIELD_COUNT: usize = 1;
3698    pub fn total_size(&self) -> usize {
3699        molecule::unpack_number(self.as_slice()) as usize
3700    }
3701    pub fn field_count(&self) -> usize {
3702        if self.total_size() == molecule::NUMBER_SIZE {
3703            0
3704        } else {
3705            (molecule::unpack_number(&self.as_slice()[molecule::NUMBER_SIZE..]) as usize / 4) - 1
3706        }
3707    }
3708    pub fn count_extra_fields(&self) -> usize {
3709        self.field_count() - Self::FIELD_COUNT
3710    }
3711    pub fn has_extra_fields(&self) -> bool {
3712        Self::FIELD_COUNT != self.field_count()
3713    }
3714    pub fn value(&self) -> BytesReader<'r> {
3715        let slice = self.as_slice();
3716        let start = molecule::unpack_number(&slice[4..]) as usize;
3717        if self.has_extra_fields() {
3718            let end = molecule::unpack_number(&slice[8..]) as usize;
3719            BytesReader::new_unchecked(&self.as_slice()[start..end])
3720        } else {
3721            BytesReader::new_unchecked(&self.as_slice()[start..])
3722        }
3723    }
3724}
3725impl<'r> molecule::prelude::Reader<'r> for FeatureReader<'r> {
3726    type Entity = Feature;
3727    const NAME: &'static str = "FeatureReader";
3728    fn to_entity(&self) -> Self::Entity {
3729        Self::Entity::new_unchecked(self.as_slice().to_owned().into())
3730    }
3731    fn new_unchecked(slice: &'r [u8]) -> Self {
3732        FeatureReader(slice)
3733    }
3734    fn as_slice(&self) -> &'r [u8] {
3735        self.0
3736    }
3737    fn verify(slice: &[u8], compatible: bool) -> molecule::error::VerificationResult<()> {
3738        use molecule::verification_error as ve;
3739        let slice_len = slice.len();
3740        if slice_len < molecule::NUMBER_SIZE {
3741            return ve!(Self, HeaderIsBroken, molecule::NUMBER_SIZE, slice_len);
3742        }
3743        let total_size = molecule::unpack_number(slice) as usize;
3744        if slice_len != total_size {
3745            return ve!(Self, TotalSizeNotMatch, total_size, slice_len);
3746        }
3747        if slice_len < molecule::NUMBER_SIZE * 2 {
3748            return ve!(Self, HeaderIsBroken, molecule::NUMBER_SIZE * 2, slice_len);
3749        }
3750        let offset_first = molecule::unpack_number(&slice[molecule::NUMBER_SIZE..]) as usize;
3751        if offset_first % molecule::NUMBER_SIZE != 0 || offset_first < molecule::NUMBER_SIZE * 2 {
3752            return ve!(Self, OffsetsNotMatch);
3753        }
3754        if slice_len < offset_first {
3755            return ve!(Self, HeaderIsBroken, offset_first, slice_len);
3756        }
3757        let field_count = offset_first / molecule::NUMBER_SIZE - 1;
3758        if field_count < Self::FIELD_COUNT {
3759            return ve!(Self, FieldCountNotMatch, Self::FIELD_COUNT, field_count);
3760        } else if !compatible && field_count > Self::FIELD_COUNT {
3761            return ve!(Self, FieldCountNotMatch, Self::FIELD_COUNT, field_count);
3762        };
3763        let mut offsets: Vec<usize> = slice[molecule::NUMBER_SIZE..offset_first]
3764            .chunks_exact(molecule::NUMBER_SIZE)
3765            .map(|x| molecule::unpack_number(x) as usize)
3766            .collect();
3767        offsets.push(total_size);
3768        if offsets.windows(2).any(|i| i[0] > i[1]) {
3769            return ve!(Self, OffsetsNotMatch);
3770        }
3771        BytesReader::verify(&slice[offsets[0]..offsets[1]], compatible)?;
3772        Ok(())
3773    }
3774}
3775#[derive(Clone, Debug, Default)]
3776pub struct FeatureBuilder {
3777    pub(crate) value: Bytes,
3778}
3779impl FeatureBuilder {
3780    pub const FIELD_COUNT: usize = 1;
3781    pub fn value(mut self, v: Bytes) -> Self {
3782        self.value = v;
3783        self
3784    }
3785}
3786impl molecule::prelude::Builder for FeatureBuilder {
3787    type Entity = Feature;
3788    const NAME: &'static str = "FeatureBuilder";
3789    fn expected_length(&self) -> usize {
3790        molecule::NUMBER_SIZE * (Self::FIELD_COUNT + 1) + self.value.as_slice().len()
3791    }
3792    fn write<W: molecule::io::Write>(&self, writer: &mut W) -> molecule::io::Result<()> {
3793        let mut total_size = molecule::NUMBER_SIZE * (Self::FIELD_COUNT + 1);
3794        let mut offsets = Vec::with_capacity(Self::FIELD_COUNT);
3795        offsets.push(total_size);
3796        total_size += self.value.as_slice().len();
3797        writer.write_all(&molecule::pack_number(total_size as molecule::Number))?;
3798        for offset in offsets.into_iter() {
3799            writer.write_all(&molecule::pack_number(offset as molecule::Number))?;
3800        }
3801        writer.write_all(self.value.as_slice())?;
3802        Ok(())
3803    }
3804    fn build(&self) -> Self::Entity {
3805        let mut inner = Vec::with_capacity(self.expected_length());
3806        self.write(&mut inner)
3807            .unwrap_or_else(|_| panic!("{} build should be ok", Self::NAME));
3808        Feature::new_unchecked(inner.into())
3809    }
3810}
3811#[derive(Clone)]
3812pub struct UdtScript(molecule::bytes::Bytes);
3813impl ::core::fmt::LowerHex for UdtScript {
3814    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
3815        use molecule::hex_string;
3816        if f.alternate() {
3817            write!(f, "0x")?;
3818        }
3819        write!(f, "{}", hex_string(self.as_slice()))
3820    }
3821}
3822impl ::core::fmt::Debug for UdtScript {
3823    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
3824        write!(f, "{}({:#x})", Self::NAME, self)
3825    }
3826}
3827impl ::core::fmt::Display for UdtScript {
3828    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
3829        write!(f, "{} {{ ", Self::NAME)?;
3830        write!(f, "{}: {}", "value", self.value())?;
3831        let extra_count = self.count_extra_fields();
3832        if extra_count != 0 {
3833            write!(f, ", .. ({} fields)", extra_count)?;
3834        }
3835        write!(f, " }}")
3836    }
3837}
3838impl ::core::default::Default for UdtScript {
3839    fn default() -> Self {
3840        let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE);
3841        UdtScript::new_unchecked(v)
3842    }
3843}
3844impl UdtScript {
3845    const DEFAULT_VALUE: [u8; 61] = [
3846        61, 0, 0, 0, 8, 0, 0, 0, 53, 0, 0, 0, 16, 0, 0, 0, 48, 0, 0, 0, 49, 0, 0, 0, 0, 0, 0, 0, 0,
3847        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3848        0, 0,
3849    ];
3850    pub const FIELD_COUNT: usize = 1;
3851    pub fn total_size(&self) -> usize {
3852        molecule::unpack_number(self.as_slice()) as usize
3853    }
3854    pub fn field_count(&self) -> usize {
3855        if self.total_size() == molecule::NUMBER_SIZE {
3856            0
3857        } else {
3858            (molecule::unpack_number(&self.as_slice()[molecule::NUMBER_SIZE..]) as usize / 4) - 1
3859        }
3860    }
3861    pub fn count_extra_fields(&self) -> usize {
3862        self.field_count() - Self::FIELD_COUNT
3863    }
3864    pub fn has_extra_fields(&self) -> bool {
3865        Self::FIELD_COUNT != self.field_count()
3866    }
3867    pub fn value(&self) -> Script {
3868        let slice = self.as_slice();
3869        let start = molecule::unpack_number(&slice[4..]) as usize;
3870        if self.has_extra_fields() {
3871            let end = molecule::unpack_number(&slice[8..]) as usize;
3872            Script::new_unchecked(self.0.slice(start..end))
3873        } else {
3874            Script::new_unchecked(self.0.slice(start..))
3875        }
3876    }
3877    pub fn as_reader<'r>(&'r self) -> UdtScriptReader<'r> {
3878        UdtScriptReader::new_unchecked(self.as_slice())
3879    }
3880}
3881impl molecule::prelude::Entity for UdtScript {
3882    type Builder = UdtScriptBuilder;
3883    const NAME: &'static str = "UdtScript";
3884    fn new_unchecked(data: molecule::bytes::Bytes) -> Self {
3885        UdtScript(data)
3886    }
3887    fn as_bytes(&self) -> molecule::bytes::Bytes {
3888        self.0.clone()
3889    }
3890    fn as_slice(&self) -> &[u8] {
3891        &self.0[..]
3892    }
3893    fn from_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
3894        UdtScriptReader::from_slice(slice).map(|reader| reader.to_entity())
3895    }
3896    fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
3897        UdtScriptReader::from_compatible_slice(slice).map(|reader| reader.to_entity())
3898    }
3899    fn new_builder() -> Self::Builder {
3900        ::core::default::Default::default()
3901    }
3902    fn as_builder(self) -> Self::Builder {
3903        Self::new_builder().value(self.value())
3904    }
3905}
3906#[derive(Clone, Copy)]
3907pub struct UdtScriptReader<'r>(&'r [u8]);
3908impl<'r> ::core::fmt::LowerHex for UdtScriptReader<'r> {
3909    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
3910        use molecule::hex_string;
3911        if f.alternate() {
3912            write!(f, "0x")?;
3913        }
3914        write!(f, "{}", hex_string(self.as_slice()))
3915    }
3916}
3917impl<'r> ::core::fmt::Debug for UdtScriptReader<'r> {
3918    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
3919        write!(f, "{}({:#x})", Self::NAME, self)
3920    }
3921}
3922impl<'r> ::core::fmt::Display for UdtScriptReader<'r> {
3923    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
3924        write!(f, "{} {{ ", Self::NAME)?;
3925        write!(f, "{}: {}", "value", self.value())?;
3926        let extra_count = self.count_extra_fields();
3927        if extra_count != 0 {
3928            write!(f, ", .. ({} fields)", extra_count)?;
3929        }
3930        write!(f, " }}")
3931    }
3932}
3933impl<'r> UdtScriptReader<'r> {
3934    pub const FIELD_COUNT: usize = 1;
3935    pub fn total_size(&self) -> usize {
3936        molecule::unpack_number(self.as_slice()) as usize
3937    }
3938    pub fn field_count(&self) -> usize {
3939        if self.total_size() == molecule::NUMBER_SIZE {
3940            0
3941        } else {
3942            (molecule::unpack_number(&self.as_slice()[molecule::NUMBER_SIZE..]) as usize / 4) - 1
3943        }
3944    }
3945    pub fn count_extra_fields(&self) -> usize {
3946        self.field_count() - Self::FIELD_COUNT
3947    }
3948    pub fn has_extra_fields(&self) -> bool {
3949        Self::FIELD_COUNT != self.field_count()
3950    }
3951    pub fn value(&self) -> ScriptReader<'r> {
3952        let slice = self.as_slice();
3953        let start = molecule::unpack_number(&slice[4..]) as usize;
3954        if self.has_extra_fields() {
3955            let end = molecule::unpack_number(&slice[8..]) as usize;
3956            ScriptReader::new_unchecked(&self.as_slice()[start..end])
3957        } else {
3958            ScriptReader::new_unchecked(&self.as_slice()[start..])
3959        }
3960    }
3961}
3962impl<'r> molecule::prelude::Reader<'r> for UdtScriptReader<'r> {
3963    type Entity = UdtScript;
3964    const NAME: &'static str = "UdtScriptReader";
3965    fn to_entity(&self) -> Self::Entity {
3966        Self::Entity::new_unchecked(self.as_slice().to_owned().into())
3967    }
3968    fn new_unchecked(slice: &'r [u8]) -> Self {
3969        UdtScriptReader(slice)
3970    }
3971    fn as_slice(&self) -> &'r [u8] {
3972        self.0
3973    }
3974    fn verify(slice: &[u8], compatible: bool) -> molecule::error::VerificationResult<()> {
3975        use molecule::verification_error as ve;
3976        let slice_len = slice.len();
3977        if slice_len < molecule::NUMBER_SIZE {
3978            return ve!(Self, HeaderIsBroken, molecule::NUMBER_SIZE, slice_len);
3979        }
3980        let total_size = molecule::unpack_number(slice) as usize;
3981        if slice_len != total_size {
3982            return ve!(Self, TotalSizeNotMatch, total_size, slice_len);
3983        }
3984        if slice_len < molecule::NUMBER_SIZE * 2 {
3985            return ve!(Self, HeaderIsBroken, molecule::NUMBER_SIZE * 2, slice_len);
3986        }
3987        let offset_first = molecule::unpack_number(&slice[molecule::NUMBER_SIZE..]) as usize;
3988        if offset_first % molecule::NUMBER_SIZE != 0 || offset_first < molecule::NUMBER_SIZE * 2 {
3989            return ve!(Self, OffsetsNotMatch);
3990        }
3991        if slice_len < offset_first {
3992            return ve!(Self, HeaderIsBroken, offset_first, slice_len);
3993        }
3994        let field_count = offset_first / molecule::NUMBER_SIZE - 1;
3995        if field_count < Self::FIELD_COUNT {
3996            return ve!(Self, FieldCountNotMatch, Self::FIELD_COUNT, field_count);
3997        } else if !compatible && field_count > Self::FIELD_COUNT {
3998            return ve!(Self, FieldCountNotMatch, Self::FIELD_COUNT, field_count);
3999        };
4000        let mut offsets: Vec<usize> = slice[molecule::NUMBER_SIZE..offset_first]
4001            .chunks_exact(molecule::NUMBER_SIZE)
4002            .map(|x| molecule::unpack_number(x) as usize)
4003            .collect();
4004        offsets.push(total_size);
4005        if offsets.windows(2).any(|i| i[0] > i[1]) {
4006            return ve!(Self, OffsetsNotMatch);
4007        }
4008        ScriptReader::verify(&slice[offsets[0]..offsets[1]], compatible)?;
4009        Ok(())
4010    }
4011}
4012#[derive(Clone, Debug, Default)]
4013pub struct UdtScriptBuilder {
4014    pub(crate) value: Script,
4015}
4016impl UdtScriptBuilder {
4017    pub const FIELD_COUNT: usize = 1;
4018    pub fn value(mut self, v: Script) -> Self {
4019        self.value = v;
4020        self
4021    }
4022}
4023impl molecule::prelude::Builder for UdtScriptBuilder {
4024    type Entity = UdtScript;
4025    const NAME: &'static str = "UdtScriptBuilder";
4026    fn expected_length(&self) -> usize {
4027        molecule::NUMBER_SIZE * (Self::FIELD_COUNT + 1) + self.value.as_slice().len()
4028    }
4029    fn write<W: molecule::io::Write>(&self, writer: &mut W) -> molecule::io::Result<()> {
4030        let mut total_size = molecule::NUMBER_SIZE * (Self::FIELD_COUNT + 1);
4031        let mut offsets = Vec::with_capacity(Self::FIELD_COUNT);
4032        offsets.push(total_size);
4033        total_size += self.value.as_slice().len();
4034        writer.write_all(&molecule::pack_number(total_size as molecule::Number))?;
4035        for offset in offsets.into_iter() {
4036            writer.write_all(&molecule::pack_number(offset as molecule::Number))?;
4037        }
4038        writer.write_all(self.value.as_slice())?;
4039        Ok(())
4040    }
4041    fn build(&self) -> Self::Entity {
4042        let mut inner = Vec::with_capacity(self.expected_length());
4043        self.write(&mut inner)
4044            .unwrap_or_else(|_| panic!("{} build should be ok", Self::NAME));
4045        UdtScript::new_unchecked(inner.into())
4046    }
4047}
4048#[derive(Clone)]
4049pub struct PayeePublicKey(molecule::bytes::Bytes);
4050impl ::core::fmt::LowerHex for PayeePublicKey {
4051    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
4052        use molecule::hex_string;
4053        if f.alternate() {
4054            write!(f, "0x")?;
4055        }
4056        write!(f, "{}", hex_string(self.as_slice()))
4057    }
4058}
4059impl ::core::fmt::Debug for PayeePublicKey {
4060    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
4061        write!(f, "{}({:#x})", Self::NAME, self)
4062    }
4063}
4064impl ::core::fmt::Display for PayeePublicKey {
4065    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
4066        write!(f, "{} {{ ", Self::NAME)?;
4067        write!(f, "{}: {}", "value", self.value())?;
4068        let extra_count = self.count_extra_fields();
4069        if extra_count != 0 {
4070            write!(f, ", .. ({} fields)", extra_count)?;
4071        }
4072        write!(f, " }}")
4073    }
4074}
4075impl ::core::default::Default for PayeePublicKey {
4076    fn default() -> Self {
4077        let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE);
4078        PayeePublicKey::new_unchecked(v)
4079    }
4080}
4081impl PayeePublicKey {
4082    const DEFAULT_VALUE: [u8; 12] = [12, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0];
4083    pub const FIELD_COUNT: usize = 1;
4084    pub fn total_size(&self) -> usize {
4085        molecule::unpack_number(self.as_slice()) as usize
4086    }
4087    pub fn field_count(&self) -> usize {
4088        if self.total_size() == molecule::NUMBER_SIZE {
4089            0
4090        } else {
4091            (molecule::unpack_number(&self.as_slice()[molecule::NUMBER_SIZE..]) as usize / 4) - 1
4092        }
4093    }
4094    pub fn count_extra_fields(&self) -> usize {
4095        self.field_count() - Self::FIELD_COUNT
4096    }
4097    pub fn has_extra_fields(&self) -> bool {
4098        Self::FIELD_COUNT != self.field_count()
4099    }
4100    pub fn value(&self) -> Bytes {
4101        let slice = self.as_slice();
4102        let start = molecule::unpack_number(&slice[4..]) as usize;
4103        if self.has_extra_fields() {
4104            let end = molecule::unpack_number(&slice[8..]) as usize;
4105            Bytes::new_unchecked(self.0.slice(start..end))
4106        } else {
4107            Bytes::new_unchecked(self.0.slice(start..))
4108        }
4109    }
4110    pub fn as_reader<'r>(&'r self) -> PayeePublicKeyReader<'r> {
4111        PayeePublicKeyReader::new_unchecked(self.as_slice())
4112    }
4113}
4114impl molecule::prelude::Entity for PayeePublicKey {
4115    type Builder = PayeePublicKeyBuilder;
4116    const NAME: &'static str = "PayeePublicKey";
4117    fn new_unchecked(data: molecule::bytes::Bytes) -> Self {
4118        PayeePublicKey(data)
4119    }
4120    fn as_bytes(&self) -> molecule::bytes::Bytes {
4121        self.0.clone()
4122    }
4123    fn as_slice(&self) -> &[u8] {
4124        &self.0[..]
4125    }
4126    fn from_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
4127        PayeePublicKeyReader::from_slice(slice).map(|reader| reader.to_entity())
4128    }
4129    fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
4130        PayeePublicKeyReader::from_compatible_slice(slice).map(|reader| reader.to_entity())
4131    }
4132    fn new_builder() -> Self::Builder {
4133        ::core::default::Default::default()
4134    }
4135    fn as_builder(self) -> Self::Builder {
4136        Self::new_builder().value(self.value())
4137    }
4138}
4139#[derive(Clone, Copy)]
4140pub struct PayeePublicKeyReader<'r>(&'r [u8]);
4141impl<'r> ::core::fmt::LowerHex for PayeePublicKeyReader<'r> {
4142    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
4143        use molecule::hex_string;
4144        if f.alternate() {
4145            write!(f, "0x")?;
4146        }
4147        write!(f, "{}", hex_string(self.as_slice()))
4148    }
4149}
4150impl<'r> ::core::fmt::Debug for PayeePublicKeyReader<'r> {
4151    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
4152        write!(f, "{}({:#x})", Self::NAME, self)
4153    }
4154}
4155impl<'r> ::core::fmt::Display for PayeePublicKeyReader<'r> {
4156    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
4157        write!(f, "{} {{ ", Self::NAME)?;
4158        write!(f, "{}: {}", "value", self.value())?;
4159        let extra_count = self.count_extra_fields();
4160        if extra_count != 0 {
4161            write!(f, ", .. ({} fields)", extra_count)?;
4162        }
4163        write!(f, " }}")
4164    }
4165}
4166impl<'r> PayeePublicKeyReader<'r> {
4167    pub const FIELD_COUNT: usize = 1;
4168    pub fn total_size(&self) -> usize {
4169        molecule::unpack_number(self.as_slice()) as usize
4170    }
4171    pub fn field_count(&self) -> usize {
4172        if self.total_size() == molecule::NUMBER_SIZE {
4173            0
4174        } else {
4175            (molecule::unpack_number(&self.as_slice()[molecule::NUMBER_SIZE..]) as usize / 4) - 1
4176        }
4177    }
4178    pub fn count_extra_fields(&self) -> usize {
4179        self.field_count() - Self::FIELD_COUNT
4180    }
4181    pub fn has_extra_fields(&self) -> bool {
4182        Self::FIELD_COUNT != self.field_count()
4183    }
4184    pub fn value(&self) -> BytesReader<'r> {
4185        let slice = self.as_slice();
4186        let start = molecule::unpack_number(&slice[4..]) as usize;
4187        if self.has_extra_fields() {
4188            let end = molecule::unpack_number(&slice[8..]) as usize;
4189            BytesReader::new_unchecked(&self.as_slice()[start..end])
4190        } else {
4191            BytesReader::new_unchecked(&self.as_slice()[start..])
4192        }
4193    }
4194}
4195impl<'r> molecule::prelude::Reader<'r> for PayeePublicKeyReader<'r> {
4196    type Entity = PayeePublicKey;
4197    const NAME: &'static str = "PayeePublicKeyReader";
4198    fn to_entity(&self) -> Self::Entity {
4199        Self::Entity::new_unchecked(self.as_slice().to_owned().into())
4200    }
4201    fn new_unchecked(slice: &'r [u8]) -> Self {
4202        PayeePublicKeyReader(slice)
4203    }
4204    fn as_slice(&self) -> &'r [u8] {
4205        self.0
4206    }
4207    fn verify(slice: &[u8], compatible: bool) -> molecule::error::VerificationResult<()> {
4208        use molecule::verification_error as ve;
4209        let slice_len = slice.len();
4210        if slice_len < molecule::NUMBER_SIZE {
4211            return ve!(Self, HeaderIsBroken, molecule::NUMBER_SIZE, slice_len);
4212        }
4213        let total_size = molecule::unpack_number(slice) as usize;
4214        if slice_len != total_size {
4215            return ve!(Self, TotalSizeNotMatch, total_size, slice_len);
4216        }
4217        if slice_len < molecule::NUMBER_SIZE * 2 {
4218            return ve!(Self, HeaderIsBroken, molecule::NUMBER_SIZE * 2, slice_len);
4219        }
4220        let offset_first = molecule::unpack_number(&slice[molecule::NUMBER_SIZE..]) as usize;
4221        if offset_first % molecule::NUMBER_SIZE != 0 || offset_first < molecule::NUMBER_SIZE * 2 {
4222            return ve!(Self, OffsetsNotMatch);
4223        }
4224        if slice_len < offset_first {
4225            return ve!(Self, HeaderIsBroken, offset_first, slice_len);
4226        }
4227        let field_count = offset_first / molecule::NUMBER_SIZE - 1;
4228        if field_count < Self::FIELD_COUNT {
4229            return ve!(Self, FieldCountNotMatch, Self::FIELD_COUNT, field_count);
4230        } else if !compatible && field_count > Self::FIELD_COUNT {
4231            return ve!(Self, FieldCountNotMatch, Self::FIELD_COUNT, field_count);
4232        };
4233        let mut offsets: Vec<usize> = slice[molecule::NUMBER_SIZE..offset_first]
4234            .chunks_exact(molecule::NUMBER_SIZE)
4235            .map(|x| molecule::unpack_number(x) as usize)
4236            .collect();
4237        offsets.push(total_size);
4238        if offsets.windows(2).any(|i| i[0] > i[1]) {
4239            return ve!(Self, OffsetsNotMatch);
4240        }
4241        BytesReader::verify(&slice[offsets[0]..offsets[1]], compatible)?;
4242        Ok(())
4243    }
4244}
4245#[derive(Clone, Debug, Default)]
4246pub struct PayeePublicKeyBuilder {
4247    pub(crate) value: Bytes,
4248}
4249impl PayeePublicKeyBuilder {
4250    pub const FIELD_COUNT: usize = 1;
4251    pub fn value(mut self, v: Bytes) -> Self {
4252        self.value = v;
4253        self
4254    }
4255}
4256impl molecule::prelude::Builder for PayeePublicKeyBuilder {
4257    type Entity = PayeePublicKey;
4258    const NAME: &'static str = "PayeePublicKeyBuilder";
4259    fn expected_length(&self) -> usize {
4260        molecule::NUMBER_SIZE * (Self::FIELD_COUNT + 1) + self.value.as_slice().len()
4261    }
4262    fn write<W: molecule::io::Write>(&self, writer: &mut W) -> molecule::io::Result<()> {
4263        let mut total_size = molecule::NUMBER_SIZE * (Self::FIELD_COUNT + 1);
4264        let mut offsets = Vec::with_capacity(Self::FIELD_COUNT);
4265        offsets.push(total_size);
4266        total_size += self.value.as_slice().len();
4267        writer.write_all(&molecule::pack_number(total_size as molecule::Number))?;
4268        for offset in offsets.into_iter() {
4269            writer.write_all(&molecule::pack_number(offset as molecule::Number))?;
4270        }
4271        writer.write_all(self.value.as_slice())?;
4272        Ok(())
4273    }
4274    fn build(&self) -> Self::Entity {
4275        let mut inner = Vec::with_capacity(self.expected_length());
4276        self.write(&mut inner)
4277            .unwrap_or_else(|_| panic!("{} build should be ok", Self::NAME));
4278        PayeePublicKey::new_unchecked(inner.into())
4279    }
4280}
4281#[derive(Clone)]
4282pub struct HashAlgorithm(molecule::bytes::Bytes);
4283impl ::core::fmt::LowerHex for HashAlgorithm {
4284    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
4285        use molecule::hex_string;
4286        if f.alternate() {
4287            write!(f, "0x")?;
4288        }
4289        write!(f, "{}", hex_string(self.as_slice()))
4290    }
4291}
4292impl ::core::fmt::Debug for HashAlgorithm {
4293    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
4294        write!(f, "{}({:#x})", Self::NAME, self)
4295    }
4296}
4297impl ::core::fmt::Display for HashAlgorithm {
4298    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
4299        write!(f, "{} {{ ", Self::NAME)?;
4300        write!(f, "{}: {}", "value", self.value())?;
4301        write!(f, " }}")
4302    }
4303}
4304impl ::core::default::Default for HashAlgorithm {
4305    fn default() -> Self {
4306        let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE);
4307        HashAlgorithm::new_unchecked(v)
4308    }
4309}
4310impl HashAlgorithm {
4311    const DEFAULT_VALUE: [u8; 1] = [0];
4312    pub const TOTAL_SIZE: usize = 1;
4313    pub const FIELD_SIZES: [usize; 1] = [1];
4314    pub const FIELD_COUNT: usize = 1;
4315    pub fn value(&self) -> Byte {
4316        Byte::new_unchecked(self.0.slice(0..1))
4317    }
4318    pub fn as_reader<'r>(&'r self) -> HashAlgorithmReader<'r> {
4319        HashAlgorithmReader::new_unchecked(self.as_slice())
4320    }
4321}
4322impl molecule::prelude::Entity for HashAlgorithm {
4323    type Builder = HashAlgorithmBuilder;
4324    const NAME: &'static str = "HashAlgorithm";
4325    fn new_unchecked(data: molecule::bytes::Bytes) -> Self {
4326        HashAlgorithm(data)
4327    }
4328    fn as_bytes(&self) -> molecule::bytes::Bytes {
4329        self.0.clone()
4330    }
4331    fn as_slice(&self) -> &[u8] {
4332        &self.0[..]
4333    }
4334    fn from_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
4335        HashAlgorithmReader::from_slice(slice).map(|reader| reader.to_entity())
4336    }
4337    fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
4338        HashAlgorithmReader::from_compatible_slice(slice).map(|reader| reader.to_entity())
4339    }
4340    fn new_builder() -> Self::Builder {
4341        ::core::default::Default::default()
4342    }
4343    fn as_builder(self) -> Self::Builder {
4344        Self::new_builder().value(self.value())
4345    }
4346}
4347#[derive(Clone, Copy)]
4348pub struct HashAlgorithmReader<'r>(&'r [u8]);
4349impl<'r> ::core::fmt::LowerHex for HashAlgorithmReader<'r> {
4350    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
4351        use molecule::hex_string;
4352        if f.alternate() {
4353            write!(f, "0x")?;
4354        }
4355        write!(f, "{}", hex_string(self.as_slice()))
4356    }
4357}
4358impl<'r> ::core::fmt::Debug for HashAlgorithmReader<'r> {
4359    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
4360        write!(f, "{}({:#x})", Self::NAME, self)
4361    }
4362}
4363impl<'r> ::core::fmt::Display for HashAlgorithmReader<'r> {
4364    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
4365        write!(f, "{} {{ ", Self::NAME)?;
4366        write!(f, "{}: {}", "value", self.value())?;
4367        write!(f, " }}")
4368    }
4369}
4370impl<'r> HashAlgorithmReader<'r> {
4371    pub const TOTAL_SIZE: usize = 1;
4372    pub const FIELD_SIZES: [usize; 1] = [1];
4373    pub const FIELD_COUNT: usize = 1;
4374    pub fn value(&self) -> ByteReader<'r> {
4375        ByteReader::new_unchecked(&self.as_slice()[0..1])
4376    }
4377}
4378impl<'r> molecule::prelude::Reader<'r> for HashAlgorithmReader<'r> {
4379    type Entity = HashAlgorithm;
4380    const NAME: &'static str = "HashAlgorithmReader";
4381    fn to_entity(&self) -> Self::Entity {
4382        Self::Entity::new_unchecked(self.as_slice().to_owned().into())
4383    }
4384    fn new_unchecked(slice: &'r [u8]) -> Self {
4385        HashAlgorithmReader(slice)
4386    }
4387    fn as_slice(&self) -> &'r [u8] {
4388        self.0
4389    }
4390    fn verify(slice: &[u8], _compatible: bool) -> molecule::error::VerificationResult<()> {
4391        use molecule::verification_error as ve;
4392        let slice_len = slice.len();
4393        if slice_len != Self::TOTAL_SIZE {
4394            return ve!(Self, TotalSizeNotMatch, Self::TOTAL_SIZE, slice_len);
4395        }
4396        Ok(())
4397    }
4398}
4399#[derive(Clone, Debug, Default)]
4400pub struct HashAlgorithmBuilder {
4401    pub(crate) value: Byte,
4402}
4403impl HashAlgorithmBuilder {
4404    pub const TOTAL_SIZE: usize = 1;
4405    pub const FIELD_SIZES: [usize; 1] = [1];
4406    pub const FIELD_COUNT: usize = 1;
4407    pub fn value(mut self, v: Byte) -> Self {
4408        self.value = v;
4409        self
4410    }
4411}
4412impl molecule::prelude::Builder for HashAlgorithmBuilder {
4413    type Entity = HashAlgorithm;
4414    const NAME: &'static str = "HashAlgorithmBuilder";
4415    fn expected_length(&self) -> usize {
4416        Self::TOTAL_SIZE
4417    }
4418    fn write<W: molecule::io::Write>(&self, writer: &mut W) -> molecule::io::Result<()> {
4419        writer.write_all(self.value.as_slice())?;
4420        Ok(())
4421    }
4422    fn build(&self) -> Self::Entity {
4423        let mut inner = Vec::with_capacity(self.expected_length());
4424        self.write(&mut inner)
4425            .unwrap_or_else(|_| panic!("{} build should be ok", Self::NAME));
4426        HashAlgorithm::new_unchecked(inner.into())
4427    }
4428}
4429#[derive(Clone)]
4430pub struct PaymentSecret(molecule::bytes::Bytes);
4431impl ::core::fmt::LowerHex for PaymentSecret {
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 PaymentSecret {
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 PaymentSecret {
4446    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
4447        write!(f, "{} {{ ", Self::NAME)?;
4448        write!(f, "{}: {}", "value", self.value())?;
4449        write!(f, " }}")
4450    }
4451}
4452impl ::core::default::Default for PaymentSecret {
4453    fn default() -> Self {
4454        let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE);
4455        PaymentSecret::new_unchecked(v)
4456    }
4457}
4458impl PaymentSecret {
4459    const DEFAULT_VALUE: [u8; 32] = [
4460        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
4461        0, 0,
4462    ];
4463    pub const TOTAL_SIZE: usize = 32;
4464    pub const FIELD_SIZES: [usize; 1] = [32];
4465    pub const FIELD_COUNT: usize = 1;
4466    pub fn value(&self) -> Byte32 {
4467        Byte32::new_unchecked(self.0.slice(0..32))
4468    }
4469    pub fn as_reader<'r>(&'r self) -> PaymentSecretReader<'r> {
4470        PaymentSecretReader::new_unchecked(self.as_slice())
4471    }
4472}
4473impl molecule::prelude::Entity for PaymentSecret {
4474    type Builder = PaymentSecretBuilder;
4475    const NAME: &'static str = "PaymentSecret";
4476    fn new_unchecked(data: molecule::bytes::Bytes) -> Self {
4477        PaymentSecret(data)
4478    }
4479    fn as_bytes(&self) -> molecule::bytes::Bytes {
4480        self.0.clone()
4481    }
4482    fn as_slice(&self) -> &[u8] {
4483        &self.0[..]
4484    }
4485    fn from_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
4486        PaymentSecretReader::from_slice(slice).map(|reader| reader.to_entity())
4487    }
4488    fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
4489        PaymentSecretReader::from_compatible_slice(slice).map(|reader| reader.to_entity())
4490    }
4491    fn new_builder() -> Self::Builder {
4492        ::core::default::Default::default()
4493    }
4494    fn as_builder(self) -> Self::Builder {
4495        Self::new_builder().value(self.value())
4496    }
4497}
4498#[derive(Clone, Copy)]
4499pub struct PaymentSecretReader<'r>(&'r [u8]);
4500impl<'r> ::core::fmt::LowerHex for PaymentSecretReader<'r> {
4501    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
4502        use molecule::hex_string;
4503        if f.alternate() {
4504            write!(f, "0x")?;
4505        }
4506        write!(f, "{}", hex_string(self.as_slice()))
4507    }
4508}
4509impl<'r> ::core::fmt::Debug for PaymentSecretReader<'r> {
4510    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
4511        write!(f, "{}({:#x})", Self::NAME, self)
4512    }
4513}
4514impl<'r> ::core::fmt::Display for PaymentSecretReader<'r> {
4515    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
4516        write!(f, "{} {{ ", Self::NAME)?;
4517        write!(f, "{}: {}", "value", self.value())?;
4518        write!(f, " }}")
4519    }
4520}
4521impl<'r> PaymentSecretReader<'r> {
4522    pub const TOTAL_SIZE: usize = 32;
4523    pub const FIELD_SIZES: [usize; 1] = [32];
4524    pub const FIELD_COUNT: usize = 1;
4525    pub fn value(&self) -> Byte32Reader<'r> {
4526        Byte32Reader::new_unchecked(&self.as_slice()[0..32])
4527    }
4528}
4529impl<'r> molecule::prelude::Reader<'r> for PaymentSecretReader<'r> {
4530    type Entity = PaymentSecret;
4531    const NAME: &'static str = "PaymentSecretReader";
4532    fn to_entity(&self) -> Self::Entity {
4533        Self::Entity::new_unchecked(self.as_slice().to_owned().into())
4534    }
4535    fn new_unchecked(slice: &'r [u8]) -> Self {
4536        PaymentSecretReader(slice)
4537    }
4538    fn as_slice(&self) -> &'r [u8] {
4539        self.0
4540    }
4541    fn verify(slice: &[u8], _compatible: bool) -> molecule::error::VerificationResult<()> {
4542        use molecule::verification_error as ve;
4543        let slice_len = slice.len();
4544        if slice_len != Self::TOTAL_SIZE {
4545            return ve!(Self, TotalSizeNotMatch, Self::TOTAL_SIZE, slice_len);
4546        }
4547        Ok(())
4548    }
4549}
4550#[derive(Clone, Debug, Default)]
4551pub struct PaymentSecretBuilder {
4552    pub(crate) value: Byte32,
4553}
4554impl PaymentSecretBuilder {
4555    pub const TOTAL_SIZE: usize = 32;
4556    pub const FIELD_SIZES: [usize; 1] = [32];
4557    pub const FIELD_COUNT: usize = 1;
4558    pub fn value(mut self, v: Byte32) -> Self {
4559        self.value = v;
4560        self
4561    }
4562}
4563impl molecule::prelude::Builder for PaymentSecretBuilder {
4564    type Entity = PaymentSecret;
4565    const NAME: &'static str = "PaymentSecretBuilder";
4566    fn expected_length(&self) -> usize {
4567        Self::TOTAL_SIZE
4568    }
4569    fn write<W: molecule::io::Write>(&self, writer: &mut W) -> molecule::io::Result<()> {
4570        writer.write_all(self.value.as_slice())?;
4571        Ok(())
4572    }
4573    fn build(&self) -> Self::Entity {
4574        let mut inner = Vec::with_capacity(self.expected_length());
4575        self.write(&mut inner)
4576            .unwrap_or_else(|_| panic!("{} build should be ok", Self::NAME));
4577        PaymentSecret::new_unchecked(inner.into())
4578    }
4579}
4580#[derive(Clone)]
4581pub struct InvoiceAttr(molecule::bytes::Bytes);
4582impl ::core::fmt::LowerHex for InvoiceAttr {
4583    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
4584        use molecule::hex_string;
4585        if f.alternate() {
4586            write!(f, "0x")?;
4587        }
4588        write!(f, "{}", hex_string(self.as_slice()))
4589    }
4590}
4591impl ::core::fmt::Debug for InvoiceAttr {
4592    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
4593        write!(f, "{}({:#x})", Self::NAME, self)
4594    }
4595}
4596impl ::core::fmt::Display for InvoiceAttr {
4597    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
4598        write!(f, "{}(", Self::NAME)?;
4599        self.to_enum().display_inner(f)?;
4600        write!(f, ")")
4601    }
4602}
4603impl ::core::default::Default for InvoiceAttr {
4604    fn default() -> Self {
4605        let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE);
4606        InvoiceAttr::new_unchecked(v)
4607    }
4608}
4609impl InvoiceAttr {
4610    const DEFAULT_VALUE: [u8; 12] = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
4611    pub const ITEMS_COUNT: usize = 10;
4612    pub fn item_id(&self) -> molecule::Number {
4613        molecule::unpack_number(self.as_slice())
4614    }
4615    pub fn to_enum(&self) -> InvoiceAttrUnion {
4616        let inner = self.0.slice(molecule::NUMBER_SIZE..);
4617        match self.item_id() {
4618            0 => ExpiryTime::new_unchecked(inner).into(),
4619            1 => Description::new_unchecked(inner).into(),
4620            2 => FinalHtlcTimeout::new_unchecked(inner).into(),
4621            3 => FinalHtlcMinimumExpiryDelta::new_unchecked(inner).into(),
4622            4 => FallbackAddr::new_unchecked(inner).into(),
4623            5 => Feature::new_unchecked(inner).into(),
4624            6 => UdtScript::new_unchecked(inner).into(),
4625            7 => PayeePublicKey::new_unchecked(inner).into(),
4626            8 => HashAlgorithm::new_unchecked(inner).into(),
4627            9 => PaymentSecret::new_unchecked(inner).into(),
4628            _ => panic!("{}: invalid data", Self::NAME),
4629        }
4630    }
4631    pub fn as_reader<'r>(&'r self) -> InvoiceAttrReader<'r> {
4632        InvoiceAttrReader::new_unchecked(self.as_slice())
4633    }
4634}
4635impl molecule::prelude::Entity for InvoiceAttr {
4636    type Builder = InvoiceAttrBuilder;
4637    const NAME: &'static str = "InvoiceAttr";
4638    fn new_unchecked(data: molecule::bytes::Bytes) -> Self {
4639        InvoiceAttr(data)
4640    }
4641    fn as_bytes(&self) -> molecule::bytes::Bytes {
4642        self.0.clone()
4643    }
4644    fn as_slice(&self) -> &[u8] {
4645        &self.0[..]
4646    }
4647    fn from_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
4648        InvoiceAttrReader::from_slice(slice).map(|reader| reader.to_entity())
4649    }
4650    fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
4651        InvoiceAttrReader::from_compatible_slice(slice).map(|reader| reader.to_entity())
4652    }
4653    fn new_builder() -> Self::Builder {
4654        ::core::default::Default::default()
4655    }
4656    fn as_builder(self) -> Self::Builder {
4657        Self::new_builder().set(self.to_enum())
4658    }
4659}
4660#[derive(Clone, Copy)]
4661pub struct InvoiceAttrReader<'r>(&'r [u8]);
4662impl<'r> ::core::fmt::LowerHex for InvoiceAttrReader<'r> {
4663    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
4664        use molecule::hex_string;
4665        if f.alternate() {
4666            write!(f, "0x")?;
4667        }
4668        write!(f, "{}", hex_string(self.as_slice()))
4669    }
4670}
4671impl<'r> ::core::fmt::Debug for InvoiceAttrReader<'r> {
4672    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
4673        write!(f, "{}({:#x})", Self::NAME, self)
4674    }
4675}
4676impl<'r> ::core::fmt::Display for InvoiceAttrReader<'r> {
4677    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
4678        write!(f, "{}(", Self::NAME)?;
4679        self.to_enum().display_inner(f)?;
4680        write!(f, ")")
4681    }
4682}
4683impl<'r> InvoiceAttrReader<'r> {
4684    pub const ITEMS_COUNT: usize = 10;
4685    pub fn item_id(&self) -> molecule::Number {
4686        molecule::unpack_number(self.as_slice())
4687    }
4688    pub fn to_enum(&self) -> InvoiceAttrUnionReader<'r> {
4689        let inner = &self.as_slice()[molecule::NUMBER_SIZE..];
4690        match self.item_id() {
4691            0 => ExpiryTimeReader::new_unchecked(inner).into(),
4692            1 => DescriptionReader::new_unchecked(inner).into(),
4693            2 => FinalHtlcTimeoutReader::new_unchecked(inner).into(),
4694            3 => FinalHtlcMinimumExpiryDeltaReader::new_unchecked(inner).into(),
4695            4 => FallbackAddrReader::new_unchecked(inner).into(),
4696            5 => FeatureReader::new_unchecked(inner).into(),
4697            6 => UdtScriptReader::new_unchecked(inner).into(),
4698            7 => PayeePublicKeyReader::new_unchecked(inner).into(),
4699            8 => HashAlgorithmReader::new_unchecked(inner).into(),
4700            9 => PaymentSecretReader::new_unchecked(inner).into(),
4701            _ => panic!("{}: invalid data", Self::NAME),
4702        }
4703    }
4704}
4705impl<'r> molecule::prelude::Reader<'r> for InvoiceAttrReader<'r> {
4706    type Entity = InvoiceAttr;
4707    const NAME: &'static str = "InvoiceAttrReader";
4708    fn to_entity(&self) -> Self::Entity {
4709        Self::Entity::new_unchecked(self.as_slice().to_owned().into())
4710    }
4711    fn new_unchecked(slice: &'r [u8]) -> Self {
4712        InvoiceAttrReader(slice)
4713    }
4714    fn as_slice(&self) -> &'r [u8] {
4715        self.0
4716    }
4717    fn verify(slice: &[u8], compatible: bool) -> molecule::error::VerificationResult<()> {
4718        use molecule::verification_error as ve;
4719        let slice_len = slice.len();
4720        if slice_len < molecule::NUMBER_SIZE {
4721            return ve!(Self, HeaderIsBroken, molecule::NUMBER_SIZE, slice_len);
4722        }
4723        let item_id = molecule::unpack_number(slice);
4724        let inner_slice = &slice[molecule::NUMBER_SIZE..];
4725        match item_id {
4726            0 => ExpiryTimeReader::verify(inner_slice, compatible),
4727            1 => DescriptionReader::verify(inner_slice, compatible),
4728            2 => FinalHtlcTimeoutReader::verify(inner_slice, compatible),
4729            3 => FinalHtlcMinimumExpiryDeltaReader::verify(inner_slice, compatible),
4730            4 => FallbackAddrReader::verify(inner_slice, compatible),
4731            5 => FeatureReader::verify(inner_slice, compatible),
4732            6 => UdtScriptReader::verify(inner_slice, compatible),
4733            7 => PayeePublicKeyReader::verify(inner_slice, compatible),
4734            8 => HashAlgorithmReader::verify(inner_slice, compatible),
4735            9 => PaymentSecretReader::verify(inner_slice, compatible),
4736            _ => ve!(Self, UnknownItem, Self::ITEMS_COUNT, item_id),
4737        }?;
4738        Ok(())
4739    }
4740}
4741#[derive(Clone, Debug, Default)]
4742pub struct InvoiceAttrBuilder(pub(crate) InvoiceAttrUnion);
4743impl InvoiceAttrBuilder {
4744    pub const ITEMS_COUNT: usize = 10;
4745    pub fn set<I>(mut self, v: I) -> Self
4746    where
4747        I: ::core::convert::Into<InvoiceAttrUnion>,
4748    {
4749        self.0 = v.into();
4750        self
4751    }
4752}
4753impl molecule::prelude::Builder for InvoiceAttrBuilder {
4754    type Entity = InvoiceAttr;
4755    const NAME: &'static str = "InvoiceAttrBuilder";
4756    fn expected_length(&self) -> usize {
4757        molecule::NUMBER_SIZE + self.0.as_slice().len()
4758    }
4759    fn write<W: molecule::io::Write>(&self, writer: &mut W) -> molecule::io::Result<()> {
4760        writer.write_all(&molecule::pack_number(self.0.item_id()))?;
4761        writer.write_all(self.0.as_slice())
4762    }
4763    fn build(&self) -> Self::Entity {
4764        let mut inner = Vec::with_capacity(self.expected_length());
4765        self.write(&mut inner)
4766            .unwrap_or_else(|_| panic!("{} build should be ok", Self::NAME));
4767        InvoiceAttr::new_unchecked(inner.into())
4768    }
4769}
4770#[derive(Debug, Clone)]
4771pub enum InvoiceAttrUnion {
4772    ExpiryTime(ExpiryTime),
4773    Description(Description),
4774    FinalHtlcTimeout(FinalHtlcTimeout),
4775    FinalHtlcMinimumExpiryDelta(FinalHtlcMinimumExpiryDelta),
4776    FallbackAddr(FallbackAddr),
4777    Feature(Feature),
4778    UdtScript(UdtScript),
4779    PayeePublicKey(PayeePublicKey),
4780    HashAlgorithm(HashAlgorithm),
4781    PaymentSecret(PaymentSecret),
4782}
4783#[derive(Debug, Clone, Copy)]
4784pub enum InvoiceAttrUnionReader<'r> {
4785    ExpiryTime(ExpiryTimeReader<'r>),
4786    Description(DescriptionReader<'r>),
4787    FinalHtlcTimeout(FinalHtlcTimeoutReader<'r>),
4788    FinalHtlcMinimumExpiryDelta(FinalHtlcMinimumExpiryDeltaReader<'r>),
4789    FallbackAddr(FallbackAddrReader<'r>),
4790    Feature(FeatureReader<'r>),
4791    UdtScript(UdtScriptReader<'r>),
4792    PayeePublicKey(PayeePublicKeyReader<'r>),
4793    HashAlgorithm(HashAlgorithmReader<'r>),
4794    PaymentSecret(PaymentSecretReader<'r>),
4795}
4796impl ::core::default::Default for InvoiceAttrUnion {
4797    fn default() -> Self {
4798        InvoiceAttrUnion::ExpiryTime(::core::default::Default::default())
4799    }
4800}
4801impl ::core::fmt::Display for InvoiceAttrUnion {
4802    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
4803        match self {
4804            InvoiceAttrUnion::ExpiryTime(ref item) => {
4805                write!(f, "{}::{}({})", Self::NAME, ExpiryTime::NAME, item)
4806            }
4807            InvoiceAttrUnion::Description(ref item) => {
4808                write!(f, "{}::{}({})", Self::NAME, Description::NAME, item)
4809            }
4810            InvoiceAttrUnion::FinalHtlcTimeout(ref item) => {
4811                write!(f, "{}::{}({})", Self::NAME, FinalHtlcTimeout::NAME, item)
4812            }
4813            InvoiceAttrUnion::FinalHtlcMinimumExpiryDelta(ref item) => {
4814                write!(
4815                    f,
4816                    "{}::{}({})",
4817                    Self::NAME,
4818                    FinalHtlcMinimumExpiryDelta::NAME,
4819                    item
4820                )
4821            }
4822            InvoiceAttrUnion::FallbackAddr(ref item) => {
4823                write!(f, "{}::{}({})", Self::NAME, FallbackAddr::NAME, item)
4824            }
4825            InvoiceAttrUnion::Feature(ref item) => {
4826                write!(f, "{}::{}({})", Self::NAME, Feature::NAME, item)
4827            }
4828            InvoiceAttrUnion::UdtScript(ref item) => {
4829                write!(f, "{}::{}({})", Self::NAME, UdtScript::NAME, item)
4830            }
4831            InvoiceAttrUnion::PayeePublicKey(ref item) => {
4832                write!(f, "{}::{}({})", Self::NAME, PayeePublicKey::NAME, item)
4833            }
4834            InvoiceAttrUnion::HashAlgorithm(ref item) => {
4835                write!(f, "{}::{}({})", Self::NAME, HashAlgorithm::NAME, item)
4836            }
4837            InvoiceAttrUnion::PaymentSecret(ref item) => {
4838                write!(f, "{}::{}({})", Self::NAME, PaymentSecret::NAME, item)
4839            }
4840        }
4841    }
4842}
4843impl<'r> ::core::fmt::Display for InvoiceAttrUnionReader<'r> {
4844    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
4845        match self {
4846            InvoiceAttrUnionReader::ExpiryTime(ref item) => {
4847                write!(f, "{}::{}({})", Self::NAME, ExpiryTime::NAME, item)
4848            }
4849            InvoiceAttrUnionReader::Description(ref item) => {
4850                write!(f, "{}::{}({})", Self::NAME, Description::NAME, item)
4851            }
4852            InvoiceAttrUnionReader::FinalHtlcTimeout(ref item) => {
4853                write!(f, "{}::{}({})", Self::NAME, FinalHtlcTimeout::NAME, item)
4854            }
4855            InvoiceAttrUnionReader::FinalHtlcMinimumExpiryDelta(ref item) => {
4856                write!(
4857                    f,
4858                    "{}::{}({})",
4859                    Self::NAME,
4860                    FinalHtlcMinimumExpiryDelta::NAME,
4861                    item
4862                )
4863            }
4864            InvoiceAttrUnionReader::FallbackAddr(ref item) => {
4865                write!(f, "{}::{}({})", Self::NAME, FallbackAddr::NAME, item)
4866            }
4867            InvoiceAttrUnionReader::Feature(ref item) => {
4868                write!(f, "{}::{}({})", Self::NAME, Feature::NAME, item)
4869            }
4870            InvoiceAttrUnionReader::UdtScript(ref item) => {
4871                write!(f, "{}::{}({})", Self::NAME, UdtScript::NAME, item)
4872            }
4873            InvoiceAttrUnionReader::PayeePublicKey(ref item) => {
4874                write!(f, "{}::{}({})", Self::NAME, PayeePublicKey::NAME, item)
4875            }
4876            InvoiceAttrUnionReader::HashAlgorithm(ref item) => {
4877                write!(f, "{}::{}({})", Self::NAME, HashAlgorithm::NAME, item)
4878            }
4879            InvoiceAttrUnionReader::PaymentSecret(ref item) => {
4880                write!(f, "{}::{}({})", Self::NAME, PaymentSecret::NAME, item)
4881            }
4882        }
4883    }
4884}
4885impl InvoiceAttrUnion {
4886    pub(crate) fn display_inner(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
4887        match self {
4888            InvoiceAttrUnion::ExpiryTime(ref item) => write!(f, "{}", item),
4889            InvoiceAttrUnion::Description(ref item) => write!(f, "{}", item),
4890            InvoiceAttrUnion::FinalHtlcTimeout(ref item) => write!(f, "{}", item),
4891            InvoiceAttrUnion::FinalHtlcMinimumExpiryDelta(ref item) => write!(f, "{}", item),
4892            InvoiceAttrUnion::FallbackAddr(ref item) => write!(f, "{}", item),
4893            InvoiceAttrUnion::Feature(ref item) => write!(f, "{}", item),
4894            InvoiceAttrUnion::UdtScript(ref item) => write!(f, "{}", item),
4895            InvoiceAttrUnion::PayeePublicKey(ref item) => write!(f, "{}", item),
4896            InvoiceAttrUnion::HashAlgorithm(ref item) => write!(f, "{}", item),
4897            InvoiceAttrUnion::PaymentSecret(ref item) => write!(f, "{}", item),
4898        }
4899    }
4900}
4901impl<'r> InvoiceAttrUnionReader<'r> {
4902    pub(crate) fn display_inner(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
4903        match self {
4904            InvoiceAttrUnionReader::ExpiryTime(ref item) => write!(f, "{}", item),
4905            InvoiceAttrUnionReader::Description(ref item) => write!(f, "{}", item),
4906            InvoiceAttrUnionReader::FinalHtlcTimeout(ref item) => write!(f, "{}", item),
4907            InvoiceAttrUnionReader::FinalHtlcMinimumExpiryDelta(ref item) => write!(f, "{}", item),
4908            InvoiceAttrUnionReader::FallbackAddr(ref item) => write!(f, "{}", item),
4909            InvoiceAttrUnionReader::Feature(ref item) => write!(f, "{}", item),
4910            InvoiceAttrUnionReader::UdtScript(ref item) => write!(f, "{}", item),
4911            InvoiceAttrUnionReader::PayeePublicKey(ref item) => write!(f, "{}", item),
4912            InvoiceAttrUnionReader::HashAlgorithm(ref item) => write!(f, "{}", item),
4913            InvoiceAttrUnionReader::PaymentSecret(ref item) => write!(f, "{}", item),
4914        }
4915    }
4916}
4917impl ::core::convert::From<ExpiryTime> for InvoiceAttrUnion {
4918    fn from(item: ExpiryTime) -> Self {
4919        InvoiceAttrUnion::ExpiryTime(item)
4920    }
4921}
4922impl ::core::convert::From<Description> for InvoiceAttrUnion {
4923    fn from(item: Description) -> Self {
4924        InvoiceAttrUnion::Description(item)
4925    }
4926}
4927impl ::core::convert::From<FinalHtlcTimeout> for InvoiceAttrUnion {
4928    fn from(item: FinalHtlcTimeout) -> Self {
4929        InvoiceAttrUnion::FinalHtlcTimeout(item)
4930    }
4931}
4932impl ::core::convert::From<FinalHtlcMinimumExpiryDelta> for InvoiceAttrUnion {
4933    fn from(item: FinalHtlcMinimumExpiryDelta) -> Self {
4934        InvoiceAttrUnion::FinalHtlcMinimumExpiryDelta(item)
4935    }
4936}
4937impl ::core::convert::From<FallbackAddr> for InvoiceAttrUnion {
4938    fn from(item: FallbackAddr) -> Self {
4939        InvoiceAttrUnion::FallbackAddr(item)
4940    }
4941}
4942impl ::core::convert::From<Feature> for InvoiceAttrUnion {
4943    fn from(item: Feature) -> Self {
4944        InvoiceAttrUnion::Feature(item)
4945    }
4946}
4947impl ::core::convert::From<UdtScript> for InvoiceAttrUnion {
4948    fn from(item: UdtScript) -> Self {
4949        InvoiceAttrUnion::UdtScript(item)
4950    }
4951}
4952impl ::core::convert::From<PayeePublicKey> for InvoiceAttrUnion {
4953    fn from(item: PayeePublicKey) -> Self {
4954        InvoiceAttrUnion::PayeePublicKey(item)
4955    }
4956}
4957impl ::core::convert::From<HashAlgorithm> for InvoiceAttrUnion {
4958    fn from(item: HashAlgorithm) -> Self {
4959        InvoiceAttrUnion::HashAlgorithm(item)
4960    }
4961}
4962impl ::core::convert::From<PaymentSecret> for InvoiceAttrUnion {
4963    fn from(item: PaymentSecret) -> Self {
4964        InvoiceAttrUnion::PaymentSecret(item)
4965    }
4966}
4967impl<'r> ::core::convert::From<ExpiryTimeReader<'r>> for InvoiceAttrUnionReader<'r> {
4968    fn from(item: ExpiryTimeReader<'r>) -> Self {
4969        InvoiceAttrUnionReader::ExpiryTime(item)
4970    }
4971}
4972impl<'r> ::core::convert::From<DescriptionReader<'r>> for InvoiceAttrUnionReader<'r> {
4973    fn from(item: DescriptionReader<'r>) -> Self {
4974        InvoiceAttrUnionReader::Description(item)
4975    }
4976}
4977impl<'r> ::core::convert::From<FinalHtlcTimeoutReader<'r>> for InvoiceAttrUnionReader<'r> {
4978    fn from(item: FinalHtlcTimeoutReader<'r>) -> Self {
4979        InvoiceAttrUnionReader::FinalHtlcTimeout(item)
4980    }
4981}
4982impl<'r> ::core::convert::From<FinalHtlcMinimumExpiryDeltaReader<'r>>
4983    for InvoiceAttrUnionReader<'r>
4984{
4985    fn from(item: FinalHtlcMinimumExpiryDeltaReader<'r>) -> Self {
4986        InvoiceAttrUnionReader::FinalHtlcMinimumExpiryDelta(item)
4987    }
4988}
4989impl<'r> ::core::convert::From<FallbackAddrReader<'r>> for InvoiceAttrUnionReader<'r> {
4990    fn from(item: FallbackAddrReader<'r>) -> Self {
4991        InvoiceAttrUnionReader::FallbackAddr(item)
4992    }
4993}
4994impl<'r> ::core::convert::From<FeatureReader<'r>> for InvoiceAttrUnionReader<'r> {
4995    fn from(item: FeatureReader<'r>) -> Self {
4996        InvoiceAttrUnionReader::Feature(item)
4997    }
4998}
4999impl<'r> ::core::convert::From<UdtScriptReader<'r>> for InvoiceAttrUnionReader<'r> {
5000    fn from(item: UdtScriptReader<'r>) -> Self {
5001        InvoiceAttrUnionReader::UdtScript(item)
5002    }
5003}
5004impl<'r> ::core::convert::From<PayeePublicKeyReader<'r>> for InvoiceAttrUnionReader<'r> {
5005    fn from(item: PayeePublicKeyReader<'r>) -> Self {
5006        InvoiceAttrUnionReader::PayeePublicKey(item)
5007    }
5008}
5009impl<'r> ::core::convert::From<HashAlgorithmReader<'r>> for InvoiceAttrUnionReader<'r> {
5010    fn from(item: HashAlgorithmReader<'r>) -> Self {
5011        InvoiceAttrUnionReader::HashAlgorithm(item)
5012    }
5013}
5014impl<'r> ::core::convert::From<PaymentSecretReader<'r>> for InvoiceAttrUnionReader<'r> {
5015    fn from(item: PaymentSecretReader<'r>) -> Self {
5016        InvoiceAttrUnionReader::PaymentSecret(item)
5017    }
5018}
5019impl InvoiceAttrUnion {
5020    pub const NAME: &'static str = "InvoiceAttrUnion";
5021    pub fn as_bytes(&self) -> molecule::bytes::Bytes {
5022        match self {
5023            InvoiceAttrUnion::ExpiryTime(item) => item.as_bytes(),
5024            InvoiceAttrUnion::Description(item) => item.as_bytes(),
5025            InvoiceAttrUnion::FinalHtlcTimeout(item) => item.as_bytes(),
5026            InvoiceAttrUnion::FinalHtlcMinimumExpiryDelta(item) => item.as_bytes(),
5027            InvoiceAttrUnion::FallbackAddr(item) => item.as_bytes(),
5028            InvoiceAttrUnion::Feature(item) => item.as_bytes(),
5029            InvoiceAttrUnion::UdtScript(item) => item.as_bytes(),
5030            InvoiceAttrUnion::PayeePublicKey(item) => item.as_bytes(),
5031            InvoiceAttrUnion::HashAlgorithm(item) => item.as_bytes(),
5032            InvoiceAttrUnion::PaymentSecret(item) => item.as_bytes(),
5033        }
5034    }
5035    pub fn as_slice(&self) -> &[u8] {
5036        match self {
5037            InvoiceAttrUnion::ExpiryTime(item) => item.as_slice(),
5038            InvoiceAttrUnion::Description(item) => item.as_slice(),
5039            InvoiceAttrUnion::FinalHtlcTimeout(item) => item.as_slice(),
5040            InvoiceAttrUnion::FinalHtlcMinimumExpiryDelta(item) => item.as_slice(),
5041            InvoiceAttrUnion::FallbackAddr(item) => item.as_slice(),
5042            InvoiceAttrUnion::Feature(item) => item.as_slice(),
5043            InvoiceAttrUnion::UdtScript(item) => item.as_slice(),
5044            InvoiceAttrUnion::PayeePublicKey(item) => item.as_slice(),
5045            InvoiceAttrUnion::HashAlgorithm(item) => item.as_slice(),
5046            InvoiceAttrUnion::PaymentSecret(item) => item.as_slice(),
5047        }
5048    }
5049    pub fn item_id(&self) -> molecule::Number {
5050        match self {
5051            InvoiceAttrUnion::ExpiryTime(_) => 0,
5052            InvoiceAttrUnion::Description(_) => 1,
5053            InvoiceAttrUnion::FinalHtlcTimeout(_) => 2,
5054            InvoiceAttrUnion::FinalHtlcMinimumExpiryDelta(_) => 3,
5055            InvoiceAttrUnion::FallbackAddr(_) => 4,
5056            InvoiceAttrUnion::Feature(_) => 5,
5057            InvoiceAttrUnion::UdtScript(_) => 6,
5058            InvoiceAttrUnion::PayeePublicKey(_) => 7,
5059            InvoiceAttrUnion::HashAlgorithm(_) => 8,
5060            InvoiceAttrUnion::PaymentSecret(_) => 9,
5061        }
5062    }
5063    pub fn item_name(&self) -> &str {
5064        match self {
5065            InvoiceAttrUnion::ExpiryTime(_) => "ExpiryTime",
5066            InvoiceAttrUnion::Description(_) => "Description",
5067            InvoiceAttrUnion::FinalHtlcTimeout(_) => "FinalHtlcTimeout",
5068            InvoiceAttrUnion::FinalHtlcMinimumExpiryDelta(_) => "FinalHtlcMinimumExpiryDelta",
5069            InvoiceAttrUnion::FallbackAddr(_) => "FallbackAddr",
5070            InvoiceAttrUnion::Feature(_) => "Feature",
5071            InvoiceAttrUnion::UdtScript(_) => "UdtScript",
5072            InvoiceAttrUnion::PayeePublicKey(_) => "PayeePublicKey",
5073            InvoiceAttrUnion::HashAlgorithm(_) => "HashAlgorithm",
5074            InvoiceAttrUnion::PaymentSecret(_) => "PaymentSecret",
5075        }
5076    }
5077    pub fn as_reader<'r>(&'r self) -> InvoiceAttrUnionReader<'r> {
5078        match self {
5079            InvoiceAttrUnion::ExpiryTime(item) => item.as_reader().into(),
5080            InvoiceAttrUnion::Description(item) => item.as_reader().into(),
5081            InvoiceAttrUnion::FinalHtlcTimeout(item) => item.as_reader().into(),
5082            InvoiceAttrUnion::FinalHtlcMinimumExpiryDelta(item) => item.as_reader().into(),
5083            InvoiceAttrUnion::FallbackAddr(item) => item.as_reader().into(),
5084            InvoiceAttrUnion::Feature(item) => item.as_reader().into(),
5085            InvoiceAttrUnion::UdtScript(item) => item.as_reader().into(),
5086            InvoiceAttrUnion::PayeePublicKey(item) => item.as_reader().into(),
5087            InvoiceAttrUnion::HashAlgorithm(item) => item.as_reader().into(),
5088            InvoiceAttrUnion::PaymentSecret(item) => item.as_reader().into(),
5089        }
5090    }
5091}
5092impl<'r> InvoiceAttrUnionReader<'r> {
5093    pub const NAME: &'r str = "InvoiceAttrUnionReader";
5094    pub fn as_slice(&self) -> &'r [u8] {
5095        match self {
5096            InvoiceAttrUnionReader::ExpiryTime(item) => item.as_slice(),
5097            InvoiceAttrUnionReader::Description(item) => item.as_slice(),
5098            InvoiceAttrUnionReader::FinalHtlcTimeout(item) => item.as_slice(),
5099            InvoiceAttrUnionReader::FinalHtlcMinimumExpiryDelta(item) => item.as_slice(),
5100            InvoiceAttrUnionReader::FallbackAddr(item) => item.as_slice(),
5101            InvoiceAttrUnionReader::Feature(item) => item.as_slice(),
5102            InvoiceAttrUnionReader::UdtScript(item) => item.as_slice(),
5103            InvoiceAttrUnionReader::PayeePublicKey(item) => item.as_slice(),
5104            InvoiceAttrUnionReader::HashAlgorithm(item) => item.as_slice(),
5105            InvoiceAttrUnionReader::PaymentSecret(item) => item.as_slice(),
5106        }
5107    }
5108    pub fn item_id(&self) -> molecule::Number {
5109        match self {
5110            InvoiceAttrUnionReader::ExpiryTime(_) => 0,
5111            InvoiceAttrUnionReader::Description(_) => 1,
5112            InvoiceAttrUnionReader::FinalHtlcTimeout(_) => 2,
5113            InvoiceAttrUnionReader::FinalHtlcMinimumExpiryDelta(_) => 3,
5114            InvoiceAttrUnionReader::FallbackAddr(_) => 4,
5115            InvoiceAttrUnionReader::Feature(_) => 5,
5116            InvoiceAttrUnionReader::UdtScript(_) => 6,
5117            InvoiceAttrUnionReader::PayeePublicKey(_) => 7,
5118            InvoiceAttrUnionReader::HashAlgorithm(_) => 8,
5119            InvoiceAttrUnionReader::PaymentSecret(_) => 9,
5120        }
5121    }
5122    pub fn item_name(&self) -> &str {
5123        match self {
5124            InvoiceAttrUnionReader::ExpiryTime(_) => "ExpiryTime",
5125            InvoiceAttrUnionReader::Description(_) => "Description",
5126            InvoiceAttrUnionReader::FinalHtlcTimeout(_) => "FinalHtlcTimeout",
5127            InvoiceAttrUnionReader::FinalHtlcMinimumExpiryDelta(_) => "FinalHtlcMinimumExpiryDelta",
5128            InvoiceAttrUnionReader::FallbackAddr(_) => "FallbackAddr",
5129            InvoiceAttrUnionReader::Feature(_) => "Feature",
5130            InvoiceAttrUnionReader::UdtScript(_) => "UdtScript",
5131            InvoiceAttrUnionReader::PayeePublicKey(_) => "PayeePublicKey",
5132            InvoiceAttrUnionReader::HashAlgorithm(_) => "HashAlgorithm",
5133            InvoiceAttrUnionReader::PaymentSecret(_) => "PaymentSecret",
5134        }
5135    }
5136}
5137impl From<ExpiryTime> for InvoiceAttr {
5138    fn from(value: ExpiryTime) -> Self {
5139        Self::new_builder().set(value).build()
5140    }
5141}
5142impl From<Description> for InvoiceAttr {
5143    fn from(value: Description) -> Self {
5144        Self::new_builder().set(value).build()
5145    }
5146}
5147impl From<FinalHtlcTimeout> for InvoiceAttr {
5148    fn from(value: FinalHtlcTimeout) -> Self {
5149        Self::new_builder().set(value).build()
5150    }
5151}
5152impl From<FinalHtlcMinimumExpiryDelta> for InvoiceAttr {
5153    fn from(value: FinalHtlcMinimumExpiryDelta) -> Self {
5154        Self::new_builder().set(value).build()
5155    }
5156}
5157impl From<FallbackAddr> for InvoiceAttr {
5158    fn from(value: FallbackAddr) -> Self {
5159        Self::new_builder().set(value).build()
5160    }
5161}
5162impl From<Feature> for InvoiceAttr {
5163    fn from(value: Feature) -> Self {
5164        Self::new_builder().set(value).build()
5165    }
5166}
5167impl From<UdtScript> for InvoiceAttr {
5168    fn from(value: UdtScript) -> Self {
5169        Self::new_builder().set(value).build()
5170    }
5171}
5172impl From<PayeePublicKey> for InvoiceAttr {
5173    fn from(value: PayeePublicKey) -> Self {
5174        Self::new_builder().set(value).build()
5175    }
5176}
5177impl From<HashAlgorithm> for InvoiceAttr {
5178    fn from(value: HashAlgorithm) -> Self {
5179        Self::new_builder().set(value).build()
5180    }
5181}
5182impl From<PaymentSecret> for InvoiceAttr {
5183    fn from(value: PaymentSecret) -> Self {
5184        Self::new_builder().set(value).build()
5185    }
5186}
5187#[derive(Clone)]
5188pub struct InvoiceAttrsVec(molecule::bytes::Bytes);
5189impl ::core::fmt::LowerHex for InvoiceAttrsVec {
5190    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
5191        use molecule::hex_string;
5192        if f.alternate() {
5193            write!(f, "0x")?;
5194        }
5195        write!(f, "{}", hex_string(self.as_slice()))
5196    }
5197}
5198impl ::core::fmt::Debug for InvoiceAttrsVec {
5199    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
5200        write!(f, "{}({:#x})", Self::NAME, self)
5201    }
5202}
5203impl ::core::fmt::Display for InvoiceAttrsVec {
5204    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
5205        write!(f, "{} [", Self::NAME)?;
5206        for i in 0..self.len() {
5207            if i == 0 {
5208                write!(f, "{}", self.get_unchecked(i))?;
5209            } else {
5210                write!(f, ", {}", self.get_unchecked(i))?;
5211            }
5212        }
5213        write!(f, "]")
5214    }
5215}
5216impl ::core::default::Default for InvoiceAttrsVec {
5217    fn default() -> Self {
5218        let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE);
5219        InvoiceAttrsVec::new_unchecked(v)
5220    }
5221}
5222impl InvoiceAttrsVec {
5223    const DEFAULT_VALUE: [u8; 4] = [4, 0, 0, 0];
5224    pub fn total_size(&self) -> usize {
5225        molecule::unpack_number(self.as_slice()) as usize
5226    }
5227    pub fn item_count(&self) -> usize {
5228        if self.total_size() == molecule::NUMBER_SIZE {
5229            0
5230        } else {
5231            (molecule::unpack_number(&self.as_slice()[molecule::NUMBER_SIZE..]) as usize / 4) - 1
5232        }
5233    }
5234    pub fn len(&self) -> usize {
5235        self.item_count()
5236    }
5237    pub fn is_empty(&self) -> bool {
5238        self.len() == 0
5239    }
5240    pub fn get(&self, idx: usize) -> Option<InvoiceAttr> {
5241        if idx >= self.len() {
5242            None
5243        } else {
5244            Some(self.get_unchecked(idx))
5245        }
5246    }
5247    pub fn get_unchecked(&self, idx: usize) -> InvoiceAttr {
5248        let slice = self.as_slice();
5249        let start_idx = molecule::NUMBER_SIZE * (1 + idx);
5250        let start = molecule::unpack_number(&slice[start_idx..]) as usize;
5251        if idx == self.len() - 1 {
5252            InvoiceAttr::new_unchecked(self.0.slice(start..))
5253        } else {
5254            let end_idx = start_idx + molecule::NUMBER_SIZE;
5255            let end = molecule::unpack_number(&slice[end_idx..]) as usize;
5256            InvoiceAttr::new_unchecked(self.0.slice(start..end))
5257        }
5258    }
5259    pub fn as_reader<'r>(&'r self) -> InvoiceAttrsVecReader<'r> {
5260        InvoiceAttrsVecReader::new_unchecked(self.as_slice())
5261    }
5262}
5263impl molecule::prelude::Entity for InvoiceAttrsVec {
5264    type Builder = InvoiceAttrsVecBuilder;
5265    const NAME: &'static str = "InvoiceAttrsVec";
5266    fn new_unchecked(data: molecule::bytes::Bytes) -> Self {
5267        InvoiceAttrsVec(data)
5268    }
5269    fn as_bytes(&self) -> molecule::bytes::Bytes {
5270        self.0.clone()
5271    }
5272    fn as_slice(&self) -> &[u8] {
5273        &self.0[..]
5274    }
5275    fn from_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
5276        InvoiceAttrsVecReader::from_slice(slice).map(|reader| reader.to_entity())
5277    }
5278    fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
5279        InvoiceAttrsVecReader::from_compatible_slice(slice).map(|reader| reader.to_entity())
5280    }
5281    fn new_builder() -> Self::Builder {
5282        ::core::default::Default::default()
5283    }
5284    fn as_builder(self) -> Self::Builder {
5285        Self::new_builder().extend(self.into_iter())
5286    }
5287}
5288#[derive(Clone, Copy)]
5289pub struct InvoiceAttrsVecReader<'r>(&'r [u8]);
5290impl<'r> ::core::fmt::LowerHex for InvoiceAttrsVecReader<'r> {
5291    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
5292        use molecule::hex_string;
5293        if f.alternate() {
5294            write!(f, "0x")?;
5295        }
5296        write!(f, "{}", hex_string(self.as_slice()))
5297    }
5298}
5299impl<'r> ::core::fmt::Debug for InvoiceAttrsVecReader<'r> {
5300    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
5301        write!(f, "{}({:#x})", Self::NAME, self)
5302    }
5303}
5304impl<'r> ::core::fmt::Display for InvoiceAttrsVecReader<'r> {
5305    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
5306        write!(f, "{} [", Self::NAME)?;
5307        for i in 0..self.len() {
5308            if i == 0 {
5309                write!(f, "{}", self.get_unchecked(i))?;
5310            } else {
5311                write!(f, ", {}", self.get_unchecked(i))?;
5312            }
5313        }
5314        write!(f, "]")
5315    }
5316}
5317impl<'r> InvoiceAttrsVecReader<'r> {
5318    pub fn total_size(&self) -> usize {
5319        molecule::unpack_number(self.as_slice()) as usize
5320    }
5321    pub fn item_count(&self) -> usize {
5322        if self.total_size() == molecule::NUMBER_SIZE {
5323            0
5324        } else {
5325            (molecule::unpack_number(&self.as_slice()[molecule::NUMBER_SIZE..]) as usize / 4) - 1
5326        }
5327    }
5328    pub fn len(&self) -> usize {
5329        self.item_count()
5330    }
5331    pub fn is_empty(&self) -> bool {
5332        self.len() == 0
5333    }
5334    pub fn get(&self, idx: usize) -> Option<InvoiceAttrReader<'r>> {
5335        if idx >= self.len() {
5336            None
5337        } else {
5338            Some(self.get_unchecked(idx))
5339        }
5340    }
5341    pub fn get_unchecked(&self, idx: usize) -> InvoiceAttrReader<'r> {
5342        let slice = self.as_slice();
5343        let start_idx = molecule::NUMBER_SIZE * (1 + idx);
5344        let start = molecule::unpack_number(&slice[start_idx..]) as usize;
5345        if idx == self.len() - 1 {
5346            InvoiceAttrReader::new_unchecked(&self.as_slice()[start..])
5347        } else {
5348            let end_idx = start_idx + molecule::NUMBER_SIZE;
5349            let end = molecule::unpack_number(&slice[end_idx..]) as usize;
5350            InvoiceAttrReader::new_unchecked(&self.as_slice()[start..end])
5351        }
5352    }
5353}
5354impl<'r> molecule::prelude::Reader<'r> for InvoiceAttrsVecReader<'r> {
5355    type Entity = InvoiceAttrsVec;
5356    const NAME: &'static str = "InvoiceAttrsVecReader";
5357    fn to_entity(&self) -> Self::Entity {
5358        Self::Entity::new_unchecked(self.as_slice().to_owned().into())
5359    }
5360    fn new_unchecked(slice: &'r [u8]) -> Self {
5361        InvoiceAttrsVecReader(slice)
5362    }
5363    fn as_slice(&self) -> &'r [u8] {
5364        self.0
5365    }
5366    fn verify(slice: &[u8], compatible: bool) -> molecule::error::VerificationResult<()> {
5367        use molecule::verification_error as ve;
5368        let slice_len = slice.len();
5369        if slice_len < molecule::NUMBER_SIZE {
5370            return ve!(Self, HeaderIsBroken, molecule::NUMBER_SIZE, slice_len);
5371        }
5372        let total_size = molecule::unpack_number(slice) as usize;
5373        if slice_len != total_size {
5374            return ve!(Self, TotalSizeNotMatch, total_size, slice_len);
5375        }
5376        if slice_len == molecule::NUMBER_SIZE {
5377            return Ok(());
5378        }
5379        if slice_len < molecule::NUMBER_SIZE * 2 {
5380            return ve!(
5381                Self,
5382                TotalSizeNotMatch,
5383                molecule::NUMBER_SIZE * 2,
5384                slice_len
5385            );
5386        }
5387        let offset_first = molecule::unpack_number(&slice[molecule::NUMBER_SIZE..]) as usize;
5388        if offset_first % molecule::NUMBER_SIZE != 0 || offset_first < molecule::NUMBER_SIZE * 2 {
5389            return ve!(Self, OffsetsNotMatch);
5390        }
5391        if slice_len < offset_first {
5392            return ve!(Self, HeaderIsBroken, offset_first, slice_len);
5393        }
5394        let mut offsets: Vec<usize> = slice[molecule::NUMBER_SIZE..offset_first]
5395            .chunks_exact(molecule::NUMBER_SIZE)
5396            .map(|x| molecule::unpack_number(x) as usize)
5397            .collect();
5398        offsets.push(total_size);
5399        if offsets.windows(2).any(|i| i[0] > i[1]) {
5400            return ve!(Self, OffsetsNotMatch);
5401        }
5402        for pair in offsets.windows(2) {
5403            let start = pair[0];
5404            let end = pair[1];
5405            InvoiceAttrReader::verify(&slice[start..end], compatible)?;
5406        }
5407        Ok(())
5408    }
5409}
5410#[derive(Clone, Debug, Default)]
5411pub struct InvoiceAttrsVecBuilder(pub(crate) Vec<InvoiceAttr>);
5412impl InvoiceAttrsVecBuilder {
5413    pub fn set(mut self, v: Vec<InvoiceAttr>) -> Self {
5414        self.0 = v;
5415        self
5416    }
5417    pub fn push(mut self, v: InvoiceAttr) -> Self {
5418        self.0.push(v);
5419        self
5420    }
5421    pub fn extend<T: ::core::iter::IntoIterator<Item = InvoiceAttr>>(mut self, iter: T) -> Self {
5422        for elem in iter {
5423            self.0.push(elem);
5424        }
5425        self
5426    }
5427    pub fn replace(&mut self, index: usize, v: InvoiceAttr) -> Option<InvoiceAttr> {
5428        self.0
5429            .get_mut(index)
5430            .map(|item| ::core::mem::replace(item, v))
5431    }
5432}
5433impl molecule::prelude::Builder for InvoiceAttrsVecBuilder {
5434    type Entity = InvoiceAttrsVec;
5435    const NAME: &'static str = "InvoiceAttrsVecBuilder";
5436    fn expected_length(&self) -> usize {
5437        molecule::NUMBER_SIZE * (self.0.len() + 1)
5438            + self
5439                .0
5440                .iter()
5441                .map(|inner| inner.as_slice().len())
5442                .sum::<usize>()
5443    }
5444    fn write<W: molecule::io::Write>(&self, writer: &mut W) -> molecule::io::Result<()> {
5445        let item_count = self.0.len();
5446        if item_count == 0 {
5447            writer.write_all(&molecule::pack_number(
5448                molecule::NUMBER_SIZE as molecule::Number,
5449            ))?;
5450        } else {
5451            let (total_size, offsets) = self.0.iter().fold(
5452                (
5453                    molecule::NUMBER_SIZE * (item_count + 1),
5454                    Vec::with_capacity(item_count),
5455                ),
5456                |(start, mut offsets), inner| {
5457                    offsets.push(start);
5458                    (start + inner.as_slice().len(), offsets)
5459                },
5460            );
5461            writer.write_all(&molecule::pack_number(total_size as molecule::Number))?;
5462            for offset in offsets.into_iter() {
5463                writer.write_all(&molecule::pack_number(offset as molecule::Number))?;
5464            }
5465            for inner in self.0.iter() {
5466                writer.write_all(inner.as_slice())?;
5467            }
5468        }
5469        Ok(())
5470    }
5471    fn build(&self) -> Self::Entity {
5472        let mut inner = Vec::with_capacity(self.expected_length());
5473        self.write(&mut inner)
5474            .unwrap_or_else(|_| panic!("{} build should be ok", Self::NAME));
5475        InvoiceAttrsVec::new_unchecked(inner.into())
5476    }
5477}
5478pub struct InvoiceAttrsVecIterator(InvoiceAttrsVec, usize, usize);
5479impl ::core::iter::Iterator for InvoiceAttrsVecIterator {
5480    type Item = InvoiceAttr;
5481    fn next(&mut self) -> Option<Self::Item> {
5482        if self.1 >= self.2 {
5483            None
5484        } else {
5485            let ret = self.0.get_unchecked(self.1);
5486            self.1 += 1;
5487            Some(ret)
5488        }
5489    }
5490}
5491impl ::core::iter::ExactSizeIterator for InvoiceAttrsVecIterator {
5492    fn len(&self) -> usize {
5493        self.2 - self.1
5494    }
5495}
5496impl ::core::iter::IntoIterator for InvoiceAttrsVec {
5497    type Item = InvoiceAttr;
5498    type IntoIter = InvoiceAttrsVecIterator;
5499    fn into_iter(self) -> Self::IntoIter {
5500        let len = self.len();
5501        InvoiceAttrsVecIterator(self, 0, len)
5502    }
5503}
5504impl<'r> InvoiceAttrsVecReader<'r> {
5505    pub fn iter<'t>(&'t self) -> InvoiceAttrsVecReaderIterator<'t, 'r> {
5506        InvoiceAttrsVecReaderIterator(&self, 0, self.len())
5507    }
5508}
5509pub struct InvoiceAttrsVecReaderIterator<'t, 'r>(&'t InvoiceAttrsVecReader<'r>, usize, usize);
5510impl<'t: 'r, 'r> ::core::iter::Iterator for InvoiceAttrsVecReaderIterator<'t, 'r> {
5511    type Item = InvoiceAttrReader<'t>;
5512    fn next(&mut self) -> Option<Self::Item> {
5513        if self.1 >= self.2 {
5514            None
5515        } else {
5516            let ret = self.0.get_unchecked(self.1);
5517            self.1 += 1;
5518            Some(ret)
5519        }
5520    }
5521}
5522impl<'t: 'r, 'r> ::core::iter::ExactSizeIterator for InvoiceAttrsVecReaderIterator<'t, 'r> {
5523    fn len(&self) -> usize {
5524        self.2 - self.1
5525    }
5526}
5527impl ::core::iter::FromIterator<InvoiceAttr> for InvoiceAttrsVec {
5528    fn from_iter<T: IntoIterator<Item = InvoiceAttr>>(iter: T) -> Self {
5529        Self::new_builder().extend(iter).build()
5530    }
5531}
5532#[derive(Clone)]
5533pub struct RawInvoiceData(molecule::bytes::Bytes);
5534impl ::core::fmt::LowerHex for RawInvoiceData {
5535    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
5536        use molecule::hex_string;
5537        if f.alternate() {
5538            write!(f, "0x")?;
5539        }
5540        write!(f, "{}", hex_string(self.as_slice()))
5541    }
5542}
5543impl ::core::fmt::Debug for RawInvoiceData {
5544    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
5545        write!(f, "{}({:#x})", Self::NAME, self)
5546    }
5547}
5548impl ::core::fmt::Display for RawInvoiceData {
5549    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
5550        write!(f, "{} {{ ", Self::NAME)?;
5551        write!(f, "{}: {}", "timestamp", self.timestamp())?;
5552        write!(f, ", {}: {}", "payment_hash", self.payment_hash())?;
5553        write!(f, ", {}: {}", "attrs", self.attrs())?;
5554        let extra_count = self.count_extra_fields();
5555        if extra_count != 0 {
5556            write!(f, ", .. ({} fields)", extra_count)?;
5557        }
5558        write!(f, " }}")
5559    }
5560}
5561impl ::core::default::Default for RawInvoiceData {
5562    fn default() -> Self {
5563        let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE);
5564        RawInvoiceData::new_unchecked(v)
5565    }
5566}
5567impl RawInvoiceData {
5568    const DEFAULT_VALUE: [u8; 68] = [
5569        68, 0, 0, 0, 16, 0, 0, 0, 32, 0, 0, 0, 64, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
5570        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
5571        0, 0, 0, 0, 0, 4, 0, 0, 0,
5572    ];
5573    pub const FIELD_COUNT: usize = 3;
5574    pub fn total_size(&self) -> usize {
5575        molecule::unpack_number(self.as_slice()) as usize
5576    }
5577    pub fn field_count(&self) -> usize {
5578        if self.total_size() == molecule::NUMBER_SIZE {
5579            0
5580        } else {
5581            (molecule::unpack_number(&self.as_slice()[molecule::NUMBER_SIZE..]) as usize / 4) - 1
5582        }
5583    }
5584    pub fn count_extra_fields(&self) -> usize {
5585        self.field_count() - Self::FIELD_COUNT
5586    }
5587    pub fn has_extra_fields(&self) -> bool {
5588        Self::FIELD_COUNT != self.field_count()
5589    }
5590    pub fn timestamp(&self) -> Uint128 {
5591        let slice = self.as_slice();
5592        let start = molecule::unpack_number(&slice[4..]) as usize;
5593        let end = molecule::unpack_number(&slice[8..]) as usize;
5594        Uint128::new_unchecked(self.0.slice(start..end))
5595    }
5596    pub fn payment_hash(&self) -> PaymentHash {
5597        let slice = self.as_slice();
5598        let start = molecule::unpack_number(&slice[8..]) as usize;
5599        let end = molecule::unpack_number(&slice[12..]) as usize;
5600        PaymentHash::new_unchecked(self.0.slice(start..end))
5601    }
5602    pub fn attrs(&self) -> InvoiceAttrsVec {
5603        let slice = self.as_slice();
5604        let start = molecule::unpack_number(&slice[12..]) as usize;
5605        if self.has_extra_fields() {
5606            let end = molecule::unpack_number(&slice[16..]) as usize;
5607            InvoiceAttrsVec::new_unchecked(self.0.slice(start..end))
5608        } else {
5609            InvoiceAttrsVec::new_unchecked(self.0.slice(start..))
5610        }
5611    }
5612    pub fn as_reader<'r>(&'r self) -> RawInvoiceDataReader<'r> {
5613        RawInvoiceDataReader::new_unchecked(self.as_slice())
5614    }
5615}
5616impl molecule::prelude::Entity for RawInvoiceData {
5617    type Builder = RawInvoiceDataBuilder;
5618    const NAME: &'static str = "RawInvoiceData";
5619    fn new_unchecked(data: molecule::bytes::Bytes) -> Self {
5620        RawInvoiceData(data)
5621    }
5622    fn as_bytes(&self) -> molecule::bytes::Bytes {
5623        self.0.clone()
5624    }
5625    fn as_slice(&self) -> &[u8] {
5626        &self.0[..]
5627    }
5628    fn from_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
5629        RawInvoiceDataReader::from_slice(slice).map(|reader| reader.to_entity())
5630    }
5631    fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
5632        RawInvoiceDataReader::from_compatible_slice(slice).map(|reader| reader.to_entity())
5633    }
5634    fn new_builder() -> Self::Builder {
5635        ::core::default::Default::default()
5636    }
5637    fn as_builder(self) -> Self::Builder {
5638        Self::new_builder()
5639            .timestamp(self.timestamp())
5640            .payment_hash(self.payment_hash())
5641            .attrs(self.attrs())
5642    }
5643}
5644#[derive(Clone, Copy)]
5645pub struct RawInvoiceDataReader<'r>(&'r [u8]);
5646impl<'r> ::core::fmt::LowerHex for RawInvoiceDataReader<'r> {
5647    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
5648        use molecule::hex_string;
5649        if f.alternate() {
5650            write!(f, "0x")?;
5651        }
5652        write!(f, "{}", hex_string(self.as_slice()))
5653    }
5654}
5655impl<'r> ::core::fmt::Debug for RawInvoiceDataReader<'r> {
5656    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
5657        write!(f, "{}({:#x})", Self::NAME, self)
5658    }
5659}
5660impl<'r> ::core::fmt::Display for RawInvoiceDataReader<'r> {
5661    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
5662        write!(f, "{} {{ ", Self::NAME)?;
5663        write!(f, "{}: {}", "timestamp", self.timestamp())?;
5664        write!(f, ", {}: {}", "payment_hash", self.payment_hash())?;
5665        write!(f, ", {}: {}", "attrs", self.attrs())?;
5666        let extra_count = self.count_extra_fields();
5667        if extra_count != 0 {
5668            write!(f, ", .. ({} fields)", extra_count)?;
5669        }
5670        write!(f, " }}")
5671    }
5672}
5673impl<'r> RawInvoiceDataReader<'r> {
5674    pub const FIELD_COUNT: usize = 3;
5675    pub fn total_size(&self) -> usize {
5676        molecule::unpack_number(self.as_slice()) as usize
5677    }
5678    pub fn field_count(&self) -> usize {
5679        if self.total_size() == molecule::NUMBER_SIZE {
5680            0
5681        } else {
5682            (molecule::unpack_number(&self.as_slice()[molecule::NUMBER_SIZE..]) as usize / 4) - 1
5683        }
5684    }
5685    pub fn count_extra_fields(&self) -> usize {
5686        self.field_count() - Self::FIELD_COUNT
5687    }
5688    pub fn has_extra_fields(&self) -> bool {
5689        Self::FIELD_COUNT != self.field_count()
5690    }
5691    pub fn timestamp(&self) -> Uint128Reader<'r> {
5692        let slice = self.as_slice();
5693        let start = molecule::unpack_number(&slice[4..]) as usize;
5694        let end = molecule::unpack_number(&slice[8..]) as usize;
5695        Uint128Reader::new_unchecked(&self.as_slice()[start..end])
5696    }
5697    pub fn payment_hash(&self) -> PaymentHashReader<'r> {
5698        let slice = self.as_slice();
5699        let start = molecule::unpack_number(&slice[8..]) as usize;
5700        let end = molecule::unpack_number(&slice[12..]) as usize;
5701        PaymentHashReader::new_unchecked(&self.as_slice()[start..end])
5702    }
5703    pub fn attrs(&self) -> InvoiceAttrsVecReader<'r> {
5704        let slice = self.as_slice();
5705        let start = molecule::unpack_number(&slice[12..]) as usize;
5706        if self.has_extra_fields() {
5707            let end = molecule::unpack_number(&slice[16..]) as usize;
5708            InvoiceAttrsVecReader::new_unchecked(&self.as_slice()[start..end])
5709        } else {
5710            InvoiceAttrsVecReader::new_unchecked(&self.as_slice()[start..])
5711        }
5712    }
5713}
5714impl<'r> molecule::prelude::Reader<'r> for RawInvoiceDataReader<'r> {
5715    type Entity = RawInvoiceData;
5716    const NAME: &'static str = "RawInvoiceDataReader";
5717    fn to_entity(&self) -> Self::Entity {
5718        Self::Entity::new_unchecked(self.as_slice().to_owned().into())
5719    }
5720    fn new_unchecked(slice: &'r [u8]) -> Self {
5721        RawInvoiceDataReader(slice)
5722    }
5723    fn as_slice(&self) -> &'r [u8] {
5724        self.0
5725    }
5726    fn verify(slice: &[u8], compatible: bool) -> molecule::error::VerificationResult<()> {
5727        use molecule::verification_error as ve;
5728        let slice_len = slice.len();
5729        if slice_len < molecule::NUMBER_SIZE {
5730            return ve!(Self, HeaderIsBroken, molecule::NUMBER_SIZE, slice_len);
5731        }
5732        let total_size = molecule::unpack_number(slice) as usize;
5733        if slice_len != total_size {
5734            return ve!(Self, TotalSizeNotMatch, total_size, slice_len);
5735        }
5736        if slice_len < molecule::NUMBER_SIZE * 2 {
5737            return ve!(Self, HeaderIsBroken, molecule::NUMBER_SIZE * 2, slice_len);
5738        }
5739        let offset_first = molecule::unpack_number(&slice[molecule::NUMBER_SIZE..]) as usize;
5740        if offset_first % molecule::NUMBER_SIZE != 0 || offset_first < molecule::NUMBER_SIZE * 2 {
5741            return ve!(Self, OffsetsNotMatch);
5742        }
5743        if slice_len < offset_first {
5744            return ve!(Self, HeaderIsBroken, offset_first, slice_len);
5745        }
5746        let field_count = offset_first / molecule::NUMBER_SIZE - 1;
5747        if field_count < Self::FIELD_COUNT {
5748            return ve!(Self, FieldCountNotMatch, Self::FIELD_COUNT, field_count);
5749        } else if !compatible && field_count > Self::FIELD_COUNT {
5750            return ve!(Self, FieldCountNotMatch, Self::FIELD_COUNT, field_count);
5751        };
5752        let mut offsets: Vec<usize> = slice[molecule::NUMBER_SIZE..offset_first]
5753            .chunks_exact(molecule::NUMBER_SIZE)
5754            .map(|x| molecule::unpack_number(x) as usize)
5755            .collect();
5756        offsets.push(total_size);
5757        if offsets.windows(2).any(|i| i[0] > i[1]) {
5758            return ve!(Self, OffsetsNotMatch);
5759        }
5760        Uint128Reader::verify(&slice[offsets[0]..offsets[1]], compatible)?;
5761        PaymentHashReader::verify(&slice[offsets[1]..offsets[2]], compatible)?;
5762        InvoiceAttrsVecReader::verify(&slice[offsets[2]..offsets[3]], compatible)?;
5763        Ok(())
5764    }
5765}
5766#[derive(Clone, Debug, Default)]
5767pub struct RawInvoiceDataBuilder {
5768    pub(crate) timestamp: Uint128,
5769    pub(crate) payment_hash: PaymentHash,
5770    pub(crate) attrs: InvoiceAttrsVec,
5771}
5772impl RawInvoiceDataBuilder {
5773    pub const FIELD_COUNT: usize = 3;
5774    pub fn timestamp(mut self, v: Uint128) -> Self {
5775        self.timestamp = v;
5776        self
5777    }
5778    pub fn payment_hash(mut self, v: PaymentHash) -> Self {
5779        self.payment_hash = v;
5780        self
5781    }
5782    pub fn attrs(mut self, v: InvoiceAttrsVec) -> Self {
5783        self.attrs = v;
5784        self
5785    }
5786}
5787impl molecule::prelude::Builder for RawInvoiceDataBuilder {
5788    type Entity = RawInvoiceData;
5789    const NAME: &'static str = "RawInvoiceDataBuilder";
5790    fn expected_length(&self) -> usize {
5791        molecule::NUMBER_SIZE * (Self::FIELD_COUNT + 1)
5792            + self.timestamp.as_slice().len()
5793            + self.payment_hash.as_slice().len()
5794            + self.attrs.as_slice().len()
5795    }
5796    fn write<W: molecule::io::Write>(&self, writer: &mut W) -> molecule::io::Result<()> {
5797        let mut total_size = molecule::NUMBER_SIZE * (Self::FIELD_COUNT + 1);
5798        let mut offsets = Vec::with_capacity(Self::FIELD_COUNT);
5799        offsets.push(total_size);
5800        total_size += self.timestamp.as_slice().len();
5801        offsets.push(total_size);
5802        total_size += self.payment_hash.as_slice().len();
5803        offsets.push(total_size);
5804        total_size += self.attrs.as_slice().len();
5805        writer.write_all(&molecule::pack_number(total_size as molecule::Number))?;
5806        for offset in offsets.into_iter() {
5807            writer.write_all(&molecule::pack_number(offset as molecule::Number))?;
5808        }
5809        writer.write_all(self.timestamp.as_slice())?;
5810        writer.write_all(self.payment_hash.as_slice())?;
5811        writer.write_all(self.attrs.as_slice())?;
5812        Ok(())
5813    }
5814    fn build(&self) -> Self::Entity {
5815        let mut inner = Vec::with_capacity(self.expected_length());
5816        self.write(&mut inner)
5817            .unwrap_or_else(|_| panic!("{} build should be ok", Self::NAME));
5818        RawInvoiceData::new_unchecked(inner.into())
5819    }
5820}
5821#[derive(Clone)]
5822pub struct RawCkbInvoice(molecule::bytes::Bytes);
5823impl ::core::fmt::LowerHex for RawCkbInvoice {
5824    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
5825        use molecule::hex_string;
5826        if f.alternate() {
5827            write!(f, "0x")?;
5828        }
5829        write!(f, "{}", hex_string(self.as_slice()))
5830    }
5831}
5832impl ::core::fmt::Debug for RawCkbInvoice {
5833    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
5834        write!(f, "{}({:#x})", Self::NAME, self)
5835    }
5836}
5837impl ::core::fmt::Display for RawCkbInvoice {
5838    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
5839        write!(f, "{} {{ ", Self::NAME)?;
5840        write!(f, "{}: {}", "currency", self.currency())?;
5841        write!(f, ", {}: {}", "amount", self.amount())?;
5842        write!(f, ", {}: {}", "signature", self.signature())?;
5843        write!(f, ", {}: {}", "data", self.data())?;
5844        let extra_count = self.count_extra_fields();
5845        if extra_count != 0 {
5846            write!(f, ", .. ({} fields)", extra_count)?;
5847        }
5848        write!(f, " }}")
5849    }
5850}
5851impl ::core::default::Default for RawCkbInvoice {
5852    fn default() -> Self {
5853        let v = molecule::bytes::Bytes::from_static(&Self::DEFAULT_VALUE);
5854        RawCkbInvoice::new_unchecked(v)
5855    }
5856}
5857impl RawCkbInvoice {
5858    const DEFAULT_VALUE: [u8; 89] = [
5859        89, 0, 0, 0, 20, 0, 0, 0, 21, 0, 0, 0, 21, 0, 0, 0, 21, 0, 0, 0, 0, 68, 0, 0, 0, 16, 0, 0,
5860        0, 32, 0, 0, 0, 64, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
5861        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0,
5862        0,
5863    ];
5864    pub const FIELD_COUNT: usize = 4;
5865    pub fn total_size(&self) -> usize {
5866        molecule::unpack_number(self.as_slice()) as usize
5867    }
5868    pub fn field_count(&self) -> usize {
5869        if self.total_size() == molecule::NUMBER_SIZE {
5870            0
5871        } else {
5872            (molecule::unpack_number(&self.as_slice()[molecule::NUMBER_SIZE..]) as usize / 4) - 1
5873        }
5874    }
5875    pub fn count_extra_fields(&self) -> usize {
5876        self.field_count() - Self::FIELD_COUNT
5877    }
5878    pub fn has_extra_fields(&self) -> bool {
5879        Self::FIELD_COUNT != self.field_count()
5880    }
5881    pub fn currency(&self) -> Byte {
5882        let slice = self.as_slice();
5883        let start = molecule::unpack_number(&slice[4..]) as usize;
5884        let end = molecule::unpack_number(&slice[8..]) as usize;
5885        Byte::new_unchecked(self.0.slice(start..end))
5886    }
5887    pub fn amount(&self) -> AmountOpt {
5888        let slice = self.as_slice();
5889        let start = molecule::unpack_number(&slice[8..]) as usize;
5890        let end = molecule::unpack_number(&slice[12..]) as usize;
5891        AmountOpt::new_unchecked(self.0.slice(start..end))
5892    }
5893    pub fn signature(&self) -> SignatureOpt {
5894        let slice = self.as_slice();
5895        let start = molecule::unpack_number(&slice[12..]) as usize;
5896        let end = molecule::unpack_number(&slice[16..]) as usize;
5897        SignatureOpt::new_unchecked(self.0.slice(start..end))
5898    }
5899    pub fn data(&self) -> RawInvoiceData {
5900        let slice = self.as_slice();
5901        let start = molecule::unpack_number(&slice[16..]) as usize;
5902        if self.has_extra_fields() {
5903            let end = molecule::unpack_number(&slice[20..]) as usize;
5904            RawInvoiceData::new_unchecked(self.0.slice(start..end))
5905        } else {
5906            RawInvoiceData::new_unchecked(self.0.slice(start..))
5907        }
5908    }
5909    pub fn as_reader<'r>(&'r self) -> RawCkbInvoiceReader<'r> {
5910        RawCkbInvoiceReader::new_unchecked(self.as_slice())
5911    }
5912}
5913impl molecule::prelude::Entity for RawCkbInvoice {
5914    type Builder = RawCkbInvoiceBuilder;
5915    const NAME: &'static str = "RawCkbInvoice";
5916    fn new_unchecked(data: molecule::bytes::Bytes) -> Self {
5917        RawCkbInvoice(data)
5918    }
5919    fn as_bytes(&self) -> molecule::bytes::Bytes {
5920        self.0.clone()
5921    }
5922    fn as_slice(&self) -> &[u8] {
5923        &self.0[..]
5924    }
5925    fn from_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
5926        RawCkbInvoiceReader::from_slice(slice).map(|reader| reader.to_entity())
5927    }
5928    fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult<Self> {
5929        RawCkbInvoiceReader::from_compatible_slice(slice).map(|reader| reader.to_entity())
5930    }
5931    fn new_builder() -> Self::Builder {
5932        ::core::default::Default::default()
5933    }
5934    fn as_builder(self) -> Self::Builder {
5935        Self::new_builder()
5936            .currency(self.currency())
5937            .amount(self.amount())
5938            .signature(self.signature())
5939            .data(self.data())
5940    }
5941}
5942#[derive(Clone, Copy)]
5943pub struct RawCkbInvoiceReader<'r>(&'r [u8]);
5944impl<'r> ::core::fmt::LowerHex for RawCkbInvoiceReader<'r> {
5945    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
5946        use molecule::hex_string;
5947        if f.alternate() {
5948            write!(f, "0x")?;
5949        }
5950        write!(f, "{}", hex_string(self.as_slice()))
5951    }
5952}
5953impl<'r> ::core::fmt::Debug for RawCkbInvoiceReader<'r> {
5954    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
5955        write!(f, "{}({:#x})", Self::NAME, self)
5956    }
5957}
5958impl<'r> ::core::fmt::Display for RawCkbInvoiceReader<'r> {
5959    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
5960        write!(f, "{} {{ ", Self::NAME)?;
5961        write!(f, "{}: {}", "currency", self.currency())?;
5962        write!(f, ", {}: {}", "amount", self.amount())?;
5963        write!(f, ", {}: {}", "signature", self.signature())?;
5964        write!(f, ", {}: {}", "data", self.data())?;
5965        let extra_count = self.count_extra_fields();
5966        if extra_count != 0 {
5967            write!(f, ", .. ({} fields)", extra_count)?;
5968        }
5969        write!(f, " }}")
5970    }
5971}
5972impl<'r> RawCkbInvoiceReader<'r> {
5973    pub const FIELD_COUNT: usize = 4;
5974    pub fn total_size(&self) -> usize {
5975        molecule::unpack_number(self.as_slice()) as usize
5976    }
5977    pub fn field_count(&self) -> usize {
5978        if self.total_size() == molecule::NUMBER_SIZE {
5979            0
5980        } else {
5981            (molecule::unpack_number(&self.as_slice()[molecule::NUMBER_SIZE..]) as usize / 4) - 1
5982        }
5983    }
5984    pub fn count_extra_fields(&self) -> usize {
5985        self.field_count() - Self::FIELD_COUNT
5986    }
5987    pub fn has_extra_fields(&self) -> bool {
5988        Self::FIELD_COUNT != self.field_count()
5989    }
5990    pub fn currency(&self) -> ByteReader<'r> {
5991        let slice = self.as_slice();
5992        let start = molecule::unpack_number(&slice[4..]) as usize;
5993        let end = molecule::unpack_number(&slice[8..]) as usize;
5994        ByteReader::new_unchecked(&self.as_slice()[start..end])
5995    }
5996    pub fn amount(&self) -> AmountOptReader<'r> {
5997        let slice = self.as_slice();
5998        let start = molecule::unpack_number(&slice[8..]) as usize;
5999        let end = molecule::unpack_number(&slice[12..]) as usize;
6000        AmountOptReader::new_unchecked(&self.as_slice()[start..end])
6001    }
6002    pub fn signature(&self) -> SignatureOptReader<'r> {
6003        let slice = self.as_slice();
6004        let start = molecule::unpack_number(&slice[12..]) as usize;
6005        let end = molecule::unpack_number(&slice[16..]) as usize;
6006        SignatureOptReader::new_unchecked(&self.as_slice()[start..end])
6007    }
6008    pub fn data(&self) -> RawInvoiceDataReader<'r> {
6009        let slice = self.as_slice();
6010        let start = molecule::unpack_number(&slice[16..]) as usize;
6011        if self.has_extra_fields() {
6012            let end = molecule::unpack_number(&slice[20..]) as usize;
6013            RawInvoiceDataReader::new_unchecked(&self.as_slice()[start..end])
6014        } else {
6015            RawInvoiceDataReader::new_unchecked(&self.as_slice()[start..])
6016        }
6017    }
6018}
6019impl<'r> molecule::prelude::Reader<'r> for RawCkbInvoiceReader<'r> {
6020    type Entity = RawCkbInvoice;
6021    const NAME: &'static str = "RawCkbInvoiceReader";
6022    fn to_entity(&self) -> Self::Entity {
6023        Self::Entity::new_unchecked(self.as_slice().to_owned().into())
6024    }
6025    fn new_unchecked(slice: &'r [u8]) -> Self {
6026        RawCkbInvoiceReader(slice)
6027    }
6028    fn as_slice(&self) -> &'r [u8] {
6029        self.0
6030    }
6031    fn verify(slice: &[u8], compatible: bool) -> molecule::error::VerificationResult<()> {
6032        use molecule::verification_error as ve;
6033        let slice_len = slice.len();
6034        if slice_len < molecule::NUMBER_SIZE {
6035            return ve!(Self, HeaderIsBroken, molecule::NUMBER_SIZE, slice_len);
6036        }
6037        let total_size = molecule::unpack_number(slice) as usize;
6038        if slice_len != total_size {
6039            return ve!(Self, TotalSizeNotMatch, total_size, slice_len);
6040        }
6041        if slice_len < molecule::NUMBER_SIZE * 2 {
6042            return ve!(Self, HeaderIsBroken, molecule::NUMBER_SIZE * 2, slice_len);
6043        }
6044        let offset_first = molecule::unpack_number(&slice[molecule::NUMBER_SIZE..]) as usize;
6045        if offset_first % molecule::NUMBER_SIZE != 0 || offset_first < molecule::NUMBER_SIZE * 2 {
6046            return ve!(Self, OffsetsNotMatch);
6047        }
6048        if slice_len < offset_first {
6049            return ve!(Self, HeaderIsBroken, offset_first, slice_len);
6050        }
6051        let field_count = offset_first / molecule::NUMBER_SIZE - 1;
6052        if field_count < Self::FIELD_COUNT {
6053            return ve!(Self, FieldCountNotMatch, Self::FIELD_COUNT, field_count);
6054        } else if !compatible && field_count > Self::FIELD_COUNT {
6055            return ve!(Self, FieldCountNotMatch, Self::FIELD_COUNT, field_count);
6056        };
6057        let mut offsets: Vec<usize> = slice[molecule::NUMBER_SIZE..offset_first]
6058            .chunks_exact(molecule::NUMBER_SIZE)
6059            .map(|x| molecule::unpack_number(x) as usize)
6060            .collect();
6061        offsets.push(total_size);
6062        if offsets.windows(2).any(|i| i[0] > i[1]) {
6063            return ve!(Self, OffsetsNotMatch);
6064        }
6065        ByteReader::verify(&slice[offsets[0]..offsets[1]], compatible)?;
6066        AmountOptReader::verify(&slice[offsets[1]..offsets[2]], compatible)?;
6067        SignatureOptReader::verify(&slice[offsets[2]..offsets[3]], compatible)?;
6068        RawInvoiceDataReader::verify(&slice[offsets[3]..offsets[4]], compatible)?;
6069        Ok(())
6070    }
6071}
6072#[derive(Clone, Debug, Default)]
6073pub struct RawCkbInvoiceBuilder {
6074    pub(crate) currency: Byte,
6075    pub(crate) amount: AmountOpt,
6076    pub(crate) signature: SignatureOpt,
6077    pub(crate) data: RawInvoiceData,
6078}
6079impl RawCkbInvoiceBuilder {
6080    pub const FIELD_COUNT: usize = 4;
6081    pub fn currency(mut self, v: Byte) -> Self {
6082        self.currency = v;
6083        self
6084    }
6085    pub fn amount(mut self, v: AmountOpt) -> Self {
6086        self.amount = v;
6087        self
6088    }
6089    pub fn signature(mut self, v: SignatureOpt) -> Self {
6090        self.signature = v;
6091        self
6092    }
6093    pub fn data(mut self, v: RawInvoiceData) -> Self {
6094        self.data = v;
6095        self
6096    }
6097}
6098impl molecule::prelude::Builder for RawCkbInvoiceBuilder {
6099    type Entity = RawCkbInvoice;
6100    const NAME: &'static str = "RawCkbInvoiceBuilder";
6101    fn expected_length(&self) -> usize {
6102        molecule::NUMBER_SIZE * (Self::FIELD_COUNT + 1)
6103            + self.currency.as_slice().len()
6104            + self.amount.as_slice().len()
6105            + self.signature.as_slice().len()
6106            + self.data.as_slice().len()
6107    }
6108    fn write<W: molecule::io::Write>(&self, writer: &mut W) -> molecule::io::Result<()> {
6109        let mut total_size = molecule::NUMBER_SIZE * (Self::FIELD_COUNT + 1);
6110        let mut offsets = Vec::with_capacity(Self::FIELD_COUNT);
6111        offsets.push(total_size);
6112        total_size += self.currency.as_slice().len();
6113        offsets.push(total_size);
6114        total_size += self.amount.as_slice().len();
6115        offsets.push(total_size);
6116        total_size += self.signature.as_slice().len();
6117        offsets.push(total_size);
6118        total_size += self.data.as_slice().len();
6119        writer.write_all(&molecule::pack_number(total_size as molecule::Number))?;
6120        for offset in offsets.into_iter() {
6121            writer.write_all(&molecule::pack_number(offset as molecule::Number))?;
6122        }
6123        writer.write_all(self.currency.as_slice())?;
6124        writer.write_all(self.amount.as_slice())?;
6125        writer.write_all(self.signature.as_slice())?;
6126        writer.write_all(self.data.as_slice())?;
6127        Ok(())
6128    }
6129    fn build(&self) -> Self::Entity {
6130        let mut inner = Vec::with_capacity(self.expected_length());
6131        self.write(&mut inner)
6132            .unwrap_or_else(|_| panic!("{} build should be ok", Self::NAME));
6133        RawCkbInvoice::new_unchecked(inner.into())
6134    }
6135}