From e93527c3a0a4fbd69620b70cde62d1882735487a Mon Sep 17 00:00:00 2001 From: duanyytop Date: Mon, 17 Jan 2022 14:38:31 +0800 Subject: [PATCH 1/3] feat: Add TransferCotaNFTEntries --- src/transfer.mol | 10 ++ src/transfer.rs | 438 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 448 insertions(+) diff --git a/src/transfer.mol b/src/transfer.mol index 4cdd885..27a1adf 100644 --- a/src/transfer.mol +++ b/src/transfer.mol @@ -17,4 +17,14 @@ table ClaimCotaNFTEntries { proof: Bytes, withdrawal_proof: Bytes, action: Bytes, +} + +table TransferCotaNFTEntries { + claim_keys: ClaimCotaNFTKeyVec, + claim_values: ClaimCotaNFTValueVec, + withdrawal_keys: WithdrawalCotaNFTKeyVec, + withdrawal_values: WithdrawalCotaNFTValueVec, + proof: Bytes, + withdrawal_proof: Bytes, + action: Bytes, } \ No newline at end of file diff --git a/src/transfer.rs b/src/transfer.rs index de1fa66..616ee6d 100644 --- a/src/transfer.rs +++ b/src/transfer.rs @@ -861,3 +861,441 @@ impl molecule::prelude::Builder for ClaimCotaNFTEntriesBuilder { ClaimCotaNFTEntries::new_unchecked(inner.into()) } } +#[derive(Clone)] +pub struct TransferCotaNFTEntries(molecule::bytes::Bytes); +impl ::core::fmt::LowerHex for TransferCotaNFTEntries { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + use molecule::hex_string; + if f.alternate() { + write!(f, "0x")?; + } + write!(f, "{}", hex_string(self.as_slice())) + } +} +impl ::core::fmt::Debug for TransferCotaNFTEntries { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl ::core::fmt::Display for TransferCotaNFTEntries { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{} {{ ", Self::NAME)?; + write!(f, "{}: {}", "claim_keys", self.claim_keys())?; + write!(f, ", {}: {}", "claim_values", self.claim_values())?; + write!(f, ", {}: {}", "withdrawal_keys", self.withdrawal_keys())?; + write!(f, ", {}: {}", "withdrawal_values", self.withdrawal_values())?; + write!(f, ", {}: {}", "proof", self.proof())?; + write!(f, ", {}: {}", "withdrawal_proof", self.withdrawal_proof())?; + write!(f, ", {}: {}", "action", self.action())?; + let extra_count = self.count_extra_fields(); + if extra_count != 0 { + write!(f, ", .. ({} fields)", extra_count)?; + } + write!(f, " }}") + } +} +impl ::core::default::Default for TransferCotaNFTEntries { + fn default() -> Self { + let v: Vec = vec![ + 60, 0, 0, 0, 32, 0, 0, 0, 36, 0, 0, 0, 40, 0, 0, 0, 44, 0, 0, 0, 48, 0, 0, 0, 52, 0, 0, + 0, 56, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, + ]; + TransferCotaNFTEntries::new_unchecked(v.into()) + } +} +impl TransferCotaNFTEntries { + pub const FIELD_COUNT: usize = 7; + + pub fn total_size(&self) -> usize { + molecule::unpack_number(self.as_slice()) as usize + } + + pub fn field_count(&self) -> usize { + if self.total_size() == molecule::NUMBER_SIZE { + 0 + } else { + (molecule::unpack_number(&self.as_slice()[molecule::NUMBER_SIZE..]) as usize / 4) - 1 + } + } + + pub fn count_extra_fields(&self) -> usize { + self.field_count() - Self::FIELD_COUNT + } + + pub fn has_extra_fields(&self) -> bool { + Self::FIELD_COUNT != self.field_count() + } + + pub fn claim_keys(&self) -> ClaimCotaNFTKeyVec { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[4..]) as usize; + let end = molecule::unpack_number(&slice[8..]) as usize; + ClaimCotaNFTKeyVec::new_unchecked(self.0.slice(start..end)) + } + + pub fn claim_values(&self) -> ClaimCotaNFTValueVec { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[8..]) as usize; + let end = molecule::unpack_number(&slice[12..]) as usize; + ClaimCotaNFTValueVec::new_unchecked(self.0.slice(start..end)) + } + + pub fn withdrawal_keys(&self) -> WithdrawalCotaNFTKeyVec { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[12..]) as usize; + let end = molecule::unpack_number(&slice[16..]) as usize; + WithdrawalCotaNFTKeyVec::new_unchecked(self.0.slice(start..end)) + } + + pub fn withdrawal_values(&self) -> WithdrawalCotaNFTValueVec { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[16..]) as usize; + let end = molecule::unpack_number(&slice[20..]) as usize; + WithdrawalCotaNFTValueVec::new_unchecked(self.0.slice(start..end)) + } + + pub fn proof(&self) -> Bytes { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[20..]) as usize; + let end = molecule::unpack_number(&slice[24..]) as usize; + Bytes::new_unchecked(self.0.slice(start..end)) + } + + pub fn withdrawal_proof(&self) -> Bytes { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[24..]) as usize; + let end = molecule::unpack_number(&slice[28..]) as usize; + Bytes::new_unchecked(self.0.slice(start..end)) + } + + pub fn action(&self) -> Bytes { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[28..]) as usize; + if self.has_extra_fields() { + let end = molecule::unpack_number(&slice[32..]) as usize; + Bytes::new_unchecked(self.0.slice(start..end)) + } else { + Bytes::new_unchecked(self.0.slice(start..)) + } + } + + pub fn as_reader<'r>(&'r self) -> TransferCotaNFTEntriesReader<'r> { + TransferCotaNFTEntriesReader::new_unchecked(self.as_slice()) + } +} +impl molecule::prelude::Entity for TransferCotaNFTEntries { + type Builder = TransferCotaNFTEntriesBuilder; + + const NAME: &'static str = "TransferCotaNFTEntries"; + + fn new_unchecked(data: molecule::bytes::Bytes) -> Self { + TransferCotaNFTEntries(data) + } + + fn as_bytes(&self) -> molecule::bytes::Bytes { + self.0.clone() + } + + fn as_slice(&self) -> &[u8] { + &self.0[..] + } + + fn from_slice(slice: &[u8]) -> molecule::error::VerificationResult { + TransferCotaNFTEntriesReader::from_slice(slice).map(|reader| reader.to_entity()) + } + + fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult { + TransferCotaNFTEntriesReader::from_compatible_slice(slice).map(|reader| reader.to_entity()) + } + + fn new_builder() -> Self::Builder { + ::core::default::Default::default() + } + + fn as_builder(self) -> Self::Builder { + Self::new_builder() + .claim_keys(self.claim_keys()) + .claim_values(self.claim_values()) + .withdrawal_keys(self.withdrawal_keys()) + .withdrawal_values(self.withdrawal_values()) + .proof(self.proof()) + .withdrawal_proof(self.withdrawal_proof()) + .action(self.action()) + } +} +#[derive(Clone, Copy)] +pub struct TransferCotaNFTEntriesReader<'r>(&'r [u8]); +impl<'r> ::core::fmt::LowerHex for TransferCotaNFTEntriesReader<'r> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + use molecule::hex_string; + if f.alternate() { + write!(f, "0x")?; + } + write!(f, "{}", hex_string(self.as_slice())) + } +} +impl<'r> ::core::fmt::Debug for TransferCotaNFTEntriesReader<'r> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl<'r> ::core::fmt::Display for TransferCotaNFTEntriesReader<'r> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{} {{ ", Self::NAME)?; + write!(f, "{}: {}", "claim_keys", self.claim_keys())?; + write!(f, ", {}: {}", "claim_values", self.claim_values())?; + write!(f, ", {}: {}", "withdrawal_keys", self.withdrawal_keys())?; + write!(f, ", {}: {}", "withdrawal_values", self.withdrawal_values())?; + write!(f, ", {}: {}", "proof", self.proof())?; + write!(f, ", {}: {}", "withdrawal_proof", self.withdrawal_proof())?; + write!(f, ", {}: {}", "action", self.action())?; + let extra_count = self.count_extra_fields(); + if extra_count != 0 { + write!(f, ", .. ({} fields)", extra_count)?; + } + write!(f, " }}") + } +} +impl<'r> TransferCotaNFTEntriesReader<'r> { + pub const FIELD_COUNT: usize = 7; + + pub fn total_size(&self) -> usize { + molecule::unpack_number(self.as_slice()) as usize + } + + pub fn field_count(&self) -> usize { + if self.total_size() == molecule::NUMBER_SIZE { + 0 + } else { + (molecule::unpack_number(&self.as_slice()[molecule::NUMBER_SIZE..]) as usize / 4) - 1 + } + } + + pub fn count_extra_fields(&self) -> usize { + self.field_count() - Self::FIELD_COUNT + } + + pub fn has_extra_fields(&self) -> bool { + Self::FIELD_COUNT != self.field_count() + } + + pub fn claim_keys(&self) -> ClaimCotaNFTKeyVecReader<'r> { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[4..]) as usize; + let end = molecule::unpack_number(&slice[8..]) as usize; + ClaimCotaNFTKeyVecReader::new_unchecked(&self.as_slice()[start..end]) + } + + pub fn claim_values(&self) -> ClaimCotaNFTValueVecReader<'r> { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[8..]) as usize; + let end = molecule::unpack_number(&slice[12..]) as usize; + ClaimCotaNFTValueVecReader::new_unchecked(&self.as_slice()[start..end]) + } + + pub fn withdrawal_keys(&self) -> WithdrawalCotaNFTKeyVecReader<'r> { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[12..]) as usize; + let end = molecule::unpack_number(&slice[16..]) as usize; + WithdrawalCotaNFTKeyVecReader::new_unchecked(&self.as_slice()[start..end]) + } + + pub fn withdrawal_values(&self) -> WithdrawalCotaNFTValueVecReader<'r> { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[16..]) as usize; + let end = molecule::unpack_number(&slice[20..]) as usize; + WithdrawalCotaNFTValueVecReader::new_unchecked(&self.as_slice()[start..end]) + } + + pub fn proof(&self) -> BytesReader<'r> { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[20..]) as usize; + let end = molecule::unpack_number(&slice[24..]) as usize; + BytesReader::new_unchecked(&self.as_slice()[start..end]) + } + + pub fn withdrawal_proof(&self) -> BytesReader<'r> { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[24..]) as usize; + let end = molecule::unpack_number(&slice[28..]) as usize; + BytesReader::new_unchecked(&self.as_slice()[start..end]) + } + + pub fn action(&self) -> BytesReader<'r> { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[28..]) as usize; + if self.has_extra_fields() { + let end = molecule::unpack_number(&slice[32..]) as usize; + BytesReader::new_unchecked(&self.as_slice()[start..end]) + } else { + BytesReader::new_unchecked(&self.as_slice()[start..]) + } + } +} +impl<'r> molecule::prelude::Reader<'r> for TransferCotaNFTEntriesReader<'r> { + type Entity = TransferCotaNFTEntries; + + const NAME: &'static str = "TransferCotaNFTEntriesReader"; + + fn to_entity(&self) -> Self::Entity { + Self::Entity::new_unchecked(self.as_slice().to_owned().into()) + } + + fn new_unchecked(slice: &'r [u8]) -> Self { + TransferCotaNFTEntriesReader(slice) + } + + fn as_slice(&self) -> &'r [u8] { + self.0 + } + + fn verify(slice: &[u8], compatible: bool) -> molecule::error::VerificationResult<()> { + use molecule::verification_error as ve; + let slice_len = slice.len(); + if slice_len < molecule::NUMBER_SIZE { + return ve!(Self, HeaderIsBroken, molecule::NUMBER_SIZE, slice_len); + } + let total_size = molecule::unpack_number(slice) as usize; + if slice_len != total_size { + return ve!(Self, TotalSizeNotMatch, total_size, slice_len); + } + if slice_len == molecule::NUMBER_SIZE && Self::FIELD_COUNT == 0 { + return Ok(()); + } + if slice_len < molecule::NUMBER_SIZE * 2 { + return ve!(Self, HeaderIsBroken, molecule::NUMBER_SIZE * 2, slice_len); + } + let offset_first = molecule::unpack_number(&slice[molecule::NUMBER_SIZE..]) as usize; + if offset_first % molecule::NUMBER_SIZE != 0 || offset_first < molecule::NUMBER_SIZE * 2 { + return ve!(Self, OffsetsNotMatch); + } + if slice_len < offset_first { + return ve!(Self, HeaderIsBroken, offset_first, slice_len); + } + let field_count = offset_first / molecule::NUMBER_SIZE - 1; + if field_count < Self::FIELD_COUNT { + return ve!(Self, FieldCountNotMatch, Self::FIELD_COUNT, field_count); + } else if !compatible && field_count > Self::FIELD_COUNT { + return ve!(Self, FieldCountNotMatch, Self::FIELD_COUNT, field_count); + }; + let mut offsets: Vec = slice[molecule::NUMBER_SIZE..offset_first] + .chunks_exact(molecule::NUMBER_SIZE) + .map(|x| molecule::unpack_number(x) as usize) + .collect(); + offsets.push(total_size); + if offsets.windows(2).any(|i| i[0] > i[1]) { + return ve!(Self, OffsetsNotMatch); + } + ClaimCotaNFTKeyVecReader::verify(&slice[offsets[0]..offsets[1]], compatible)?; + ClaimCotaNFTValueVecReader::verify(&slice[offsets[1]..offsets[2]], compatible)?; + WithdrawalCotaNFTKeyVecReader::verify(&slice[offsets[2]..offsets[3]], compatible)?; + WithdrawalCotaNFTValueVecReader::verify(&slice[offsets[3]..offsets[4]], compatible)?; + BytesReader::verify(&slice[offsets[4]..offsets[5]], compatible)?; + BytesReader::verify(&slice[offsets[5]..offsets[6]], compatible)?; + BytesReader::verify(&slice[offsets[6]..offsets[7]], compatible)?; + Ok(()) + } +} +#[derive(Debug, Default)] +pub struct TransferCotaNFTEntriesBuilder { + pub(crate) claim_keys: ClaimCotaNFTKeyVec, + pub(crate) claim_values: ClaimCotaNFTValueVec, + pub(crate) withdrawal_keys: WithdrawalCotaNFTKeyVec, + pub(crate) withdrawal_values: WithdrawalCotaNFTValueVec, + pub(crate) proof: Bytes, + pub(crate) withdrawal_proof: Bytes, + pub(crate) action: Bytes, +} +impl TransferCotaNFTEntriesBuilder { + pub const FIELD_COUNT: usize = 7; + + pub fn claim_keys(mut self, v: ClaimCotaNFTKeyVec) -> Self { + self.claim_keys = v; + self + } + + pub fn claim_values(mut self, v: ClaimCotaNFTValueVec) -> Self { + self.claim_values = v; + self + } + + pub fn withdrawal_keys(mut self, v: WithdrawalCotaNFTKeyVec) -> Self { + self.withdrawal_keys = v; + self + } + + pub fn withdrawal_values(mut self, v: WithdrawalCotaNFTValueVec) -> Self { + self.withdrawal_values = v; + self + } + + pub fn proof(mut self, v: Bytes) -> Self { + self.proof = v; + self + } + + pub fn withdrawal_proof(mut self, v: Bytes) -> Self { + self.withdrawal_proof = v; + self + } + + pub fn action(mut self, v: Bytes) -> Self { + self.action = v; + self + } +} +impl molecule::prelude::Builder for TransferCotaNFTEntriesBuilder { + type Entity = TransferCotaNFTEntries; + + const NAME: &'static str = "TransferCotaNFTEntriesBuilder"; + + fn expected_length(&self) -> usize { + molecule::NUMBER_SIZE * (Self::FIELD_COUNT + 1) + + self.claim_keys.as_slice().len() + + self.claim_values.as_slice().len() + + self.withdrawal_keys.as_slice().len() + + self.withdrawal_values.as_slice().len() + + self.proof.as_slice().len() + + self.withdrawal_proof.as_slice().len() + + self.action.as_slice().len() + } + + fn write(&self, writer: &mut W) -> molecule::io::Result<()> { + let mut total_size = molecule::NUMBER_SIZE * (Self::FIELD_COUNT + 1); + let mut offsets = Vec::with_capacity(Self::FIELD_COUNT); + offsets.push(total_size); + total_size += self.claim_keys.as_slice().len(); + offsets.push(total_size); + total_size += self.claim_values.as_slice().len(); + offsets.push(total_size); + total_size += self.withdrawal_keys.as_slice().len(); + offsets.push(total_size); + total_size += self.withdrawal_values.as_slice().len(); + offsets.push(total_size); + total_size += self.proof.as_slice().len(); + offsets.push(total_size); + total_size += self.withdrawal_proof.as_slice().len(); + offsets.push(total_size); + total_size += self.action.as_slice().len(); + writer.write_all(&molecule::pack_number(total_size as molecule::Number))?; + for offset in offsets.into_iter() { + writer.write_all(&molecule::pack_number(offset as molecule::Number))?; + } + writer.write_all(self.claim_keys.as_slice())?; + writer.write_all(self.claim_values.as_slice())?; + writer.write_all(self.withdrawal_keys.as_slice())?; + writer.write_all(self.withdrawal_values.as_slice())?; + writer.write_all(self.proof.as_slice())?; + writer.write_all(self.withdrawal_proof.as_slice())?; + writer.write_all(self.action.as_slice())?; + Ok(()) + } + + fn build(&self) -> Self::Entity { + let mut inner = Vec::with_capacity(self.expected_length()); + self.write(&mut inner) + .unwrap_or_else(|_| panic!("{} build should be ok", Self::NAME)); + TransferCotaNFTEntries::new_unchecked(inner.into()) + } +} From 368748f772bdef796cb5ee145cba75667bac9208 Mon Sep 17 00:00:00 2001 From: duanyytop Date: Fri, 25 Feb 2022 12:03:25 +0800 Subject: [PATCH 2/3] feat: Add transfer_update module --- src/lib.rs | 1 + src/transfer_update.mol | 25 + src/transfer_update.rs | 1003 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 1029 insertions(+) create mode 100644 src/transfer_update.mol create mode 100644 src/transfer_update.rs diff --git a/src/lib.rs b/src/lib.rs index 2504744..efd1456 100755 --- a/src/lib.rs +++ b/src/lib.rs @@ -10,6 +10,7 @@ pub mod registry; pub mod smt; pub mod transfer; pub mod update; +pub mod transfer_update; cfg_if::cfg_if! { if #[cfg(feature = "std")] { diff --git a/src/transfer_update.mol b/src/transfer_update.mol new file mode 100644 index 0000000..c008b6d --- /dev/null +++ b/src/transfer_update.mol @@ -0,0 +1,25 @@ +import common; + +table ClaimUpdateCotaNFTEntries { + hold_keys: HoldCotaNFTKeyVec, + hold_old_values: HoldCotaNFTValueVec, + hold_new_values: HoldCotaNFTValueVec, + claim_keys: ClaimCotaNFTKeyVec, + claim_values: ClaimCotaNFTValueVec, + proof: Bytes, + withdrawal_proof: Bytes, + action: Bytes, +} + +table TransferUpdateCotaNFTEntries { + hold_keys: HoldCotaNFTKeyVec, + hold_old_values: HoldCotaNFTValueVec, + hold_new_values: HoldCotaNFTValueVec, + claim_keys: ClaimCotaNFTKeyVec, + claim_values: ClaimCotaNFTValueVec, + withdrawal_keys: WithdrawalCotaNFTKeyVec, + withdrawal_values: WithdrawalCotaNFTValueVec, + proof: Bytes, + withdrawal_proof: Bytes, + action: Bytes, +} \ No newline at end of file diff --git a/src/transfer_update.rs b/src/transfer_update.rs new file mode 100644 index 0000000..34cca86 --- /dev/null +++ b/src/transfer_update.rs @@ -0,0 +1,1003 @@ +// Generated by Molecule 0.7.3 + +#![allow(unused_imports)] +#![allow(dead_code)] +#![allow(clippy::if_same_then_else)] + +use super::ckb_types::prelude::*; +use super::molecule::{self, prelude::*}; +extern crate alloc; +pub use alloc::vec::*; + +use super::common::*; +use molecule::prelude::*; +#[derive(Clone)] +pub struct ClaimUpdateCotaNFTEntries(molecule::bytes::Bytes); +impl ::core::fmt::LowerHex for ClaimUpdateCotaNFTEntries { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + use molecule::hex_string; + if f.alternate() { + write!(f, "0x")?; + } + write!(f, "{}", hex_string(self.as_slice())) + } +} +impl ::core::fmt::Debug for ClaimUpdateCotaNFTEntries { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl ::core::fmt::Display for ClaimUpdateCotaNFTEntries { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{} {{ ", Self::NAME)?; + write!(f, "{}: {}", "hold_keys", self.hold_keys())?; + write!(f, ", {}: {}", "hold_old_values", self.hold_old_values())?; + write!(f, ", {}: {}", "hold_new_values", self.hold_new_values())?; + write!(f, ", {}: {}", "claim_keys", self.claim_keys())?; + write!(f, ", {}: {}", "claim_values", self.claim_values())?; + write!(f, ", {}: {}", "proof", self.proof())?; + write!(f, ", {}: {}", "withdrawal_proof", self.withdrawal_proof())?; + write!(f, ", {}: {}", "action", self.action())?; + let extra_count = self.count_extra_fields(); + if extra_count != 0 { + write!(f, ", .. ({} fields)", extra_count)?; + } + write!(f, " }}") + } +} +impl ::core::default::Default for ClaimUpdateCotaNFTEntries { + fn default() -> Self { + let v: Vec = vec![ + 68, 0, 0, 0, 36, 0, 0, 0, 40, 0, 0, 0, 44, 0, 0, 0, 48, 0, 0, 0, 52, 0, 0, 0, 56, 0, 0, + 0, 60, 0, 0, 0, 64, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + ]; + ClaimUpdateCotaNFTEntries::new_unchecked(v.into()) + } +} +impl ClaimUpdateCotaNFTEntries { + pub const FIELD_COUNT: usize = 8; + + pub fn total_size(&self) -> usize { + molecule::unpack_number(self.as_slice()) as usize + } + + pub fn field_count(&self) -> usize { + if self.total_size() == molecule::NUMBER_SIZE { + 0 + } else { + (molecule::unpack_number(&self.as_slice()[molecule::NUMBER_SIZE..]) as usize / 4) - 1 + } + } + + pub fn count_extra_fields(&self) -> usize { + self.field_count() - Self::FIELD_COUNT + } + + pub fn has_extra_fields(&self) -> bool { + Self::FIELD_COUNT != self.field_count() + } + + pub fn hold_keys(&self) -> HoldCotaNFTKeyVec { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[4..]) as usize; + let end = molecule::unpack_number(&slice[8..]) as usize; + HoldCotaNFTKeyVec::new_unchecked(self.0.slice(start..end)) + } + + pub fn hold_old_values(&self) -> HoldCotaNFTValueVec { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[8..]) as usize; + let end = molecule::unpack_number(&slice[12..]) as usize; + HoldCotaNFTValueVec::new_unchecked(self.0.slice(start..end)) + } + + pub fn hold_new_values(&self) -> HoldCotaNFTValueVec { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[12..]) as usize; + let end = molecule::unpack_number(&slice[16..]) as usize; + HoldCotaNFTValueVec::new_unchecked(self.0.slice(start..end)) + } + + pub fn claim_keys(&self) -> ClaimCotaNFTKeyVec { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[16..]) as usize; + let end = molecule::unpack_number(&slice[20..]) as usize; + ClaimCotaNFTKeyVec::new_unchecked(self.0.slice(start..end)) + } + + pub fn claim_values(&self) -> ClaimCotaNFTValueVec { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[20..]) as usize; + let end = molecule::unpack_number(&slice[24..]) as usize; + ClaimCotaNFTValueVec::new_unchecked(self.0.slice(start..end)) + } + + pub fn proof(&self) -> Bytes { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[24..]) as usize; + let end = molecule::unpack_number(&slice[28..]) as usize; + Bytes::new_unchecked(self.0.slice(start..end)) + } + + pub fn withdrawal_proof(&self) -> Bytes { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[28..]) as usize; + let end = molecule::unpack_number(&slice[32..]) as usize; + Bytes::new_unchecked(self.0.slice(start..end)) + } + + pub fn action(&self) -> Bytes { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[32..]) as usize; + if self.has_extra_fields() { + let end = molecule::unpack_number(&slice[36..]) as usize; + Bytes::new_unchecked(self.0.slice(start..end)) + } else { + Bytes::new_unchecked(self.0.slice(start..)) + } + } + + pub fn as_reader<'r>(&'r self) -> ClaimUpdateCotaNFTEntriesReader<'r> { + ClaimUpdateCotaNFTEntriesReader::new_unchecked(self.as_slice()) + } +} +impl molecule::prelude::Entity for ClaimUpdateCotaNFTEntries { + type Builder = ClaimUpdateCotaNFTEntriesBuilder; + + const NAME: &'static str = "ClaimUpdateCotaNFTEntries"; + + fn new_unchecked(data: molecule::bytes::Bytes) -> Self { + ClaimUpdateCotaNFTEntries(data) + } + + fn as_bytes(&self) -> molecule::bytes::Bytes { + self.0.clone() + } + + fn as_slice(&self) -> &[u8] { + &self.0[..] + } + + fn from_slice(slice: &[u8]) -> molecule::error::VerificationResult { + ClaimUpdateCotaNFTEntriesReader::from_slice(slice).map(|reader| reader.to_entity()) + } + + fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult { + ClaimUpdateCotaNFTEntriesReader::from_compatible_slice(slice) + .map(|reader| reader.to_entity()) + } + + fn new_builder() -> Self::Builder { + ::core::default::Default::default() + } + + fn as_builder(self) -> Self::Builder { + Self::new_builder() + .hold_keys(self.hold_keys()) + .hold_old_values(self.hold_old_values()) + .hold_new_values(self.hold_new_values()) + .claim_keys(self.claim_keys()) + .claim_values(self.claim_values()) + .proof(self.proof()) + .withdrawal_proof(self.withdrawal_proof()) + .action(self.action()) + } +} +#[derive(Clone, Copy)] +pub struct ClaimUpdateCotaNFTEntriesReader<'r>(&'r [u8]); +impl<'r> ::core::fmt::LowerHex for ClaimUpdateCotaNFTEntriesReader<'r> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + use molecule::hex_string; + if f.alternate() { + write!(f, "0x")?; + } + write!(f, "{}", hex_string(self.as_slice())) + } +} +impl<'r> ::core::fmt::Debug for ClaimUpdateCotaNFTEntriesReader<'r> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl<'r> ::core::fmt::Display for ClaimUpdateCotaNFTEntriesReader<'r> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{} {{ ", Self::NAME)?; + write!(f, "{}: {}", "hold_keys", self.hold_keys())?; + write!(f, ", {}: {}", "hold_old_values", self.hold_old_values())?; + write!(f, ", {}: {}", "hold_new_values", self.hold_new_values())?; + write!(f, ", {}: {}", "claim_keys", self.claim_keys())?; + write!(f, ", {}: {}", "claim_values", self.claim_values())?; + write!(f, ", {}: {}", "proof", self.proof())?; + write!(f, ", {}: {}", "withdrawal_proof", self.withdrawal_proof())?; + write!(f, ", {}: {}", "action", self.action())?; + let extra_count = self.count_extra_fields(); + if extra_count != 0 { + write!(f, ", .. ({} fields)", extra_count)?; + } + write!(f, " }}") + } +} +impl<'r> ClaimUpdateCotaNFTEntriesReader<'r> { + pub const FIELD_COUNT: usize = 8; + + pub fn total_size(&self) -> usize { + molecule::unpack_number(self.as_slice()) as usize + } + + pub fn field_count(&self) -> usize { + if self.total_size() == molecule::NUMBER_SIZE { + 0 + } else { + (molecule::unpack_number(&self.as_slice()[molecule::NUMBER_SIZE..]) as usize / 4) - 1 + } + } + + pub fn count_extra_fields(&self) -> usize { + self.field_count() - Self::FIELD_COUNT + } + + pub fn has_extra_fields(&self) -> bool { + Self::FIELD_COUNT != self.field_count() + } + + pub fn hold_keys(&self) -> HoldCotaNFTKeyVecReader<'r> { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[4..]) as usize; + let end = molecule::unpack_number(&slice[8..]) as usize; + HoldCotaNFTKeyVecReader::new_unchecked(&self.as_slice()[start..end]) + } + + pub fn hold_old_values(&self) -> HoldCotaNFTValueVecReader<'r> { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[8..]) as usize; + let end = molecule::unpack_number(&slice[12..]) as usize; + HoldCotaNFTValueVecReader::new_unchecked(&self.as_slice()[start..end]) + } + + pub fn hold_new_values(&self) -> HoldCotaNFTValueVecReader<'r> { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[12..]) as usize; + let end = molecule::unpack_number(&slice[16..]) as usize; + HoldCotaNFTValueVecReader::new_unchecked(&self.as_slice()[start..end]) + } + + pub fn claim_keys(&self) -> ClaimCotaNFTKeyVecReader<'r> { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[16..]) as usize; + let end = molecule::unpack_number(&slice[20..]) as usize; + ClaimCotaNFTKeyVecReader::new_unchecked(&self.as_slice()[start..end]) + } + + pub fn claim_values(&self) -> ClaimCotaNFTValueVecReader<'r> { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[20..]) as usize; + let end = molecule::unpack_number(&slice[24..]) as usize; + ClaimCotaNFTValueVecReader::new_unchecked(&self.as_slice()[start..end]) + } + + pub fn proof(&self) -> BytesReader<'r> { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[24..]) as usize; + let end = molecule::unpack_number(&slice[28..]) as usize; + BytesReader::new_unchecked(&self.as_slice()[start..end]) + } + + pub fn withdrawal_proof(&self) -> BytesReader<'r> { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[28..]) as usize; + let end = molecule::unpack_number(&slice[32..]) as usize; + BytesReader::new_unchecked(&self.as_slice()[start..end]) + } + + pub fn action(&self) -> BytesReader<'r> { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[32..]) as usize; + if self.has_extra_fields() { + let end = molecule::unpack_number(&slice[36..]) as usize; + BytesReader::new_unchecked(&self.as_slice()[start..end]) + } else { + BytesReader::new_unchecked(&self.as_slice()[start..]) + } + } +} +impl<'r> molecule::prelude::Reader<'r> for ClaimUpdateCotaNFTEntriesReader<'r> { + type Entity = ClaimUpdateCotaNFTEntries; + + const NAME: &'static str = "ClaimUpdateCotaNFTEntriesReader"; + + fn to_entity(&self) -> Self::Entity { + Self::Entity::new_unchecked(self.as_slice().to_owned().into()) + } + + fn new_unchecked(slice: &'r [u8]) -> Self { + ClaimUpdateCotaNFTEntriesReader(slice) + } + + fn as_slice(&self) -> &'r [u8] { + self.0 + } + + fn verify(slice: &[u8], compatible: bool) -> molecule::error::VerificationResult<()> { + use molecule::verification_error as ve; + let slice_len = slice.len(); + if slice_len < molecule::NUMBER_SIZE { + return ve!(Self, HeaderIsBroken, molecule::NUMBER_SIZE, slice_len); + } + let total_size = molecule::unpack_number(slice) as usize; + if slice_len != total_size { + return ve!(Self, TotalSizeNotMatch, total_size, slice_len); + } + if slice_len == molecule::NUMBER_SIZE && Self::FIELD_COUNT == 0 { + return Ok(()); + } + if slice_len < molecule::NUMBER_SIZE * 2 { + return ve!(Self, HeaderIsBroken, molecule::NUMBER_SIZE * 2, slice_len); + } + let offset_first = molecule::unpack_number(&slice[molecule::NUMBER_SIZE..]) as usize; + if offset_first % molecule::NUMBER_SIZE != 0 || offset_first < molecule::NUMBER_SIZE * 2 { + return ve!(Self, OffsetsNotMatch); + } + if slice_len < offset_first { + return ve!(Self, HeaderIsBroken, offset_first, slice_len); + } + let field_count = offset_first / molecule::NUMBER_SIZE - 1; + if field_count < Self::FIELD_COUNT { + return ve!(Self, FieldCountNotMatch, Self::FIELD_COUNT, field_count); + } else if !compatible && field_count > Self::FIELD_COUNT { + return ve!(Self, FieldCountNotMatch, Self::FIELD_COUNT, field_count); + }; + let mut offsets: Vec = slice[molecule::NUMBER_SIZE..offset_first] + .chunks_exact(molecule::NUMBER_SIZE) + .map(|x| molecule::unpack_number(x) as usize) + .collect(); + offsets.push(total_size); + if offsets.windows(2).any(|i| i[0] > i[1]) { + return ve!(Self, OffsetsNotMatch); + } + HoldCotaNFTKeyVecReader::verify(&slice[offsets[0]..offsets[1]], compatible)?; + HoldCotaNFTValueVecReader::verify(&slice[offsets[1]..offsets[2]], compatible)?; + HoldCotaNFTValueVecReader::verify(&slice[offsets[2]..offsets[3]], compatible)?; + ClaimCotaNFTKeyVecReader::verify(&slice[offsets[3]..offsets[4]], compatible)?; + ClaimCotaNFTValueVecReader::verify(&slice[offsets[4]..offsets[5]], compatible)?; + BytesReader::verify(&slice[offsets[5]..offsets[6]], compatible)?; + BytesReader::verify(&slice[offsets[6]..offsets[7]], compatible)?; + BytesReader::verify(&slice[offsets[7]..offsets[8]], compatible)?; + Ok(()) + } +} +#[derive(Debug, Default)] +pub struct ClaimUpdateCotaNFTEntriesBuilder { + pub(crate) hold_keys: HoldCotaNFTKeyVec, + pub(crate) hold_old_values: HoldCotaNFTValueVec, + pub(crate) hold_new_values: HoldCotaNFTValueVec, + pub(crate) claim_keys: ClaimCotaNFTKeyVec, + pub(crate) claim_values: ClaimCotaNFTValueVec, + pub(crate) proof: Bytes, + pub(crate) withdrawal_proof: Bytes, + pub(crate) action: Bytes, +} +impl ClaimUpdateCotaNFTEntriesBuilder { + pub const FIELD_COUNT: usize = 8; + + pub fn hold_keys(mut self, v: HoldCotaNFTKeyVec) -> Self { + self.hold_keys = v; + self + } + + pub fn hold_old_values(mut self, v: HoldCotaNFTValueVec) -> Self { + self.hold_old_values = v; + self + } + + pub fn hold_new_values(mut self, v: HoldCotaNFTValueVec) -> Self { + self.hold_new_values = v; + self + } + + pub fn claim_keys(mut self, v: ClaimCotaNFTKeyVec) -> Self { + self.claim_keys = v; + self + } + + pub fn claim_values(mut self, v: ClaimCotaNFTValueVec) -> Self { + self.claim_values = v; + self + } + + pub fn proof(mut self, v: Bytes) -> Self { + self.proof = v; + self + } + + pub fn withdrawal_proof(mut self, v: Bytes) -> Self { + self.withdrawal_proof = v; + self + } + + pub fn action(mut self, v: Bytes) -> Self { + self.action = v; + self + } +} +impl molecule::prelude::Builder for ClaimUpdateCotaNFTEntriesBuilder { + type Entity = ClaimUpdateCotaNFTEntries; + + const NAME: &'static str = "ClaimUpdateCotaNFTEntriesBuilder"; + + fn expected_length(&self) -> usize { + molecule::NUMBER_SIZE * (Self::FIELD_COUNT + 1) + + self.hold_keys.as_slice().len() + + self.hold_old_values.as_slice().len() + + self.hold_new_values.as_slice().len() + + self.claim_keys.as_slice().len() + + self.claim_values.as_slice().len() + + self.proof.as_slice().len() + + self.withdrawal_proof.as_slice().len() + + self.action.as_slice().len() + } + + fn write(&self, writer: &mut W) -> molecule::io::Result<()> { + let mut total_size = molecule::NUMBER_SIZE * (Self::FIELD_COUNT + 1); + let mut offsets = Vec::with_capacity(Self::FIELD_COUNT); + offsets.push(total_size); + total_size += self.hold_keys.as_slice().len(); + offsets.push(total_size); + total_size += self.hold_old_values.as_slice().len(); + offsets.push(total_size); + total_size += self.hold_new_values.as_slice().len(); + offsets.push(total_size); + total_size += self.claim_keys.as_slice().len(); + offsets.push(total_size); + total_size += self.claim_values.as_slice().len(); + offsets.push(total_size); + total_size += self.proof.as_slice().len(); + offsets.push(total_size); + total_size += self.withdrawal_proof.as_slice().len(); + offsets.push(total_size); + total_size += self.action.as_slice().len(); + writer.write_all(&molecule::pack_number(total_size as molecule::Number))?; + for offset in offsets.into_iter() { + writer.write_all(&molecule::pack_number(offset as molecule::Number))?; + } + writer.write_all(self.hold_keys.as_slice())?; + writer.write_all(self.hold_old_values.as_slice())?; + writer.write_all(self.hold_new_values.as_slice())?; + writer.write_all(self.claim_keys.as_slice())?; + writer.write_all(self.claim_values.as_slice())?; + writer.write_all(self.proof.as_slice())?; + writer.write_all(self.withdrawal_proof.as_slice())?; + writer.write_all(self.action.as_slice())?; + Ok(()) + } + + fn build(&self) -> Self::Entity { + let mut inner = Vec::with_capacity(self.expected_length()); + self.write(&mut inner) + .unwrap_or_else(|_| panic!("{} build should be ok", Self::NAME)); + ClaimUpdateCotaNFTEntries::new_unchecked(inner.into()) + } +} +#[derive(Clone)] +pub struct TransferUpdateCotaNFTEntries(molecule::bytes::Bytes); +impl ::core::fmt::LowerHex for TransferUpdateCotaNFTEntries { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + use molecule::hex_string; + if f.alternate() { + write!(f, "0x")?; + } + write!(f, "{}", hex_string(self.as_slice())) + } +} +impl ::core::fmt::Debug for TransferUpdateCotaNFTEntries { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl ::core::fmt::Display for TransferUpdateCotaNFTEntries { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{} {{ ", Self::NAME)?; + write!(f, "{}: {}", "hold_keys", self.hold_keys())?; + write!(f, ", {}: {}", "hold_old_values", self.hold_old_values())?; + write!(f, ", {}: {}", "hold_new_values", self.hold_new_values())?; + write!(f, ", {}: {}", "claim_keys", self.claim_keys())?; + write!(f, ", {}: {}", "claim_values", self.claim_values())?; + write!(f, ", {}: {}", "withdrawal_keys", self.withdrawal_keys())?; + write!(f, ", {}: {}", "withdrawal_values", self.withdrawal_values())?; + write!(f, ", {}: {}", "proof", self.proof())?; + write!(f, ", {}: {}", "withdrawal_proof", self.withdrawal_proof())?; + write!(f, ", {}: {}", "action", self.action())?; + let extra_count = self.count_extra_fields(); + if extra_count != 0 { + write!(f, ", .. ({} fields)", extra_count)?; + } + write!(f, " }}") + } +} +impl ::core::default::Default for TransferUpdateCotaNFTEntries { + fn default() -> Self { + let v: Vec = vec![ + 84, 0, 0, 0, 44, 0, 0, 0, 48, 0, 0, 0, 52, 0, 0, 0, 56, 0, 0, 0, 60, 0, 0, 0, 64, 0, 0, + 0, 68, 0, 0, 0, 72, 0, 0, 0, 76, 0, 0, 0, 80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + ]; + TransferUpdateCotaNFTEntries::new_unchecked(v.into()) + } +} +impl TransferUpdateCotaNFTEntries { + pub const FIELD_COUNT: usize = 10; + + pub fn total_size(&self) -> usize { + molecule::unpack_number(self.as_slice()) as usize + } + + pub fn field_count(&self) -> usize { + if self.total_size() == molecule::NUMBER_SIZE { + 0 + } else { + (molecule::unpack_number(&self.as_slice()[molecule::NUMBER_SIZE..]) as usize / 4) - 1 + } + } + + pub fn count_extra_fields(&self) -> usize { + self.field_count() - Self::FIELD_COUNT + } + + pub fn has_extra_fields(&self) -> bool { + Self::FIELD_COUNT != self.field_count() + } + + pub fn hold_keys(&self) -> HoldCotaNFTKeyVec { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[4..]) as usize; + let end = molecule::unpack_number(&slice[8..]) as usize; + HoldCotaNFTKeyVec::new_unchecked(self.0.slice(start..end)) + } + + pub fn hold_old_values(&self) -> HoldCotaNFTValueVec { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[8..]) as usize; + let end = molecule::unpack_number(&slice[12..]) as usize; + HoldCotaNFTValueVec::new_unchecked(self.0.slice(start..end)) + } + + pub fn hold_new_values(&self) -> HoldCotaNFTValueVec { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[12..]) as usize; + let end = molecule::unpack_number(&slice[16..]) as usize; + HoldCotaNFTValueVec::new_unchecked(self.0.slice(start..end)) + } + + pub fn claim_keys(&self) -> ClaimCotaNFTKeyVec { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[16..]) as usize; + let end = molecule::unpack_number(&slice[20..]) as usize; + ClaimCotaNFTKeyVec::new_unchecked(self.0.slice(start..end)) + } + + pub fn claim_values(&self) -> ClaimCotaNFTValueVec { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[20..]) as usize; + let end = molecule::unpack_number(&slice[24..]) as usize; + ClaimCotaNFTValueVec::new_unchecked(self.0.slice(start..end)) + } + + pub fn withdrawal_keys(&self) -> WithdrawalCotaNFTKeyVec { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[24..]) as usize; + let end = molecule::unpack_number(&slice[28..]) as usize; + WithdrawalCotaNFTKeyVec::new_unchecked(self.0.slice(start..end)) + } + + pub fn withdrawal_values(&self) -> WithdrawalCotaNFTValueVec { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[28..]) as usize; + let end = molecule::unpack_number(&slice[32..]) as usize; + WithdrawalCotaNFTValueVec::new_unchecked(self.0.slice(start..end)) + } + + pub fn proof(&self) -> Bytes { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[32..]) as usize; + let end = molecule::unpack_number(&slice[36..]) as usize; + Bytes::new_unchecked(self.0.slice(start..end)) + } + + pub fn withdrawal_proof(&self) -> Bytes { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[36..]) as usize; + let end = molecule::unpack_number(&slice[40..]) as usize; + Bytes::new_unchecked(self.0.slice(start..end)) + } + + pub fn action(&self) -> Bytes { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[40..]) as usize; + if self.has_extra_fields() { + let end = molecule::unpack_number(&slice[44..]) as usize; + Bytes::new_unchecked(self.0.slice(start..end)) + } else { + Bytes::new_unchecked(self.0.slice(start..)) + } + } + + pub fn as_reader<'r>(&'r self) -> TransferUpdateCotaNFTEntriesReader<'r> { + TransferUpdateCotaNFTEntriesReader::new_unchecked(self.as_slice()) + } +} +impl molecule::prelude::Entity for TransferUpdateCotaNFTEntries { + type Builder = TransferUpdateCotaNFTEntriesBuilder; + + const NAME: &'static str = "TransferUpdateCotaNFTEntries"; + + fn new_unchecked(data: molecule::bytes::Bytes) -> Self { + TransferUpdateCotaNFTEntries(data) + } + + fn as_bytes(&self) -> molecule::bytes::Bytes { + self.0.clone() + } + + fn as_slice(&self) -> &[u8] { + &self.0[..] + } + + fn from_slice(slice: &[u8]) -> molecule::error::VerificationResult { + TransferUpdateCotaNFTEntriesReader::from_slice(slice).map(|reader| reader.to_entity()) + } + + fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult { + TransferUpdateCotaNFTEntriesReader::from_compatible_slice(slice) + .map(|reader| reader.to_entity()) + } + + fn new_builder() -> Self::Builder { + ::core::default::Default::default() + } + + fn as_builder(self) -> Self::Builder { + Self::new_builder() + .hold_keys(self.hold_keys()) + .hold_old_values(self.hold_old_values()) + .hold_new_values(self.hold_new_values()) + .claim_keys(self.claim_keys()) + .claim_values(self.claim_values()) + .withdrawal_keys(self.withdrawal_keys()) + .withdrawal_values(self.withdrawal_values()) + .proof(self.proof()) + .withdrawal_proof(self.withdrawal_proof()) + .action(self.action()) + } +} +#[derive(Clone, Copy)] +pub struct TransferUpdateCotaNFTEntriesReader<'r>(&'r [u8]); +impl<'r> ::core::fmt::LowerHex for TransferUpdateCotaNFTEntriesReader<'r> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + use molecule::hex_string; + if f.alternate() { + write!(f, "0x")?; + } + write!(f, "{}", hex_string(self.as_slice())) + } +} +impl<'r> ::core::fmt::Debug for TransferUpdateCotaNFTEntriesReader<'r> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl<'r> ::core::fmt::Display for TransferUpdateCotaNFTEntriesReader<'r> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{} {{ ", Self::NAME)?; + write!(f, "{}: {}", "hold_keys", self.hold_keys())?; + write!(f, ", {}: {}", "hold_old_values", self.hold_old_values())?; + write!(f, ", {}: {}", "hold_new_values", self.hold_new_values())?; + write!(f, ", {}: {}", "claim_keys", self.claim_keys())?; + write!(f, ", {}: {}", "claim_values", self.claim_values())?; + write!(f, ", {}: {}", "withdrawal_keys", self.withdrawal_keys())?; + write!(f, ", {}: {}", "withdrawal_values", self.withdrawal_values())?; + write!(f, ", {}: {}", "proof", self.proof())?; + write!(f, ", {}: {}", "withdrawal_proof", self.withdrawal_proof())?; + write!(f, ", {}: {}", "action", self.action())?; + let extra_count = self.count_extra_fields(); + if extra_count != 0 { + write!(f, ", .. ({} fields)", extra_count)?; + } + write!(f, " }}") + } +} +impl<'r> TransferUpdateCotaNFTEntriesReader<'r> { + pub const FIELD_COUNT: usize = 10; + + pub fn total_size(&self) -> usize { + molecule::unpack_number(self.as_slice()) as usize + } + + pub fn field_count(&self) -> usize { + if self.total_size() == molecule::NUMBER_SIZE { + 0 + } else { + (molecule::unpack_number(&self.as_slice()[molecule::NUMBER_SIZE..]) as usize / 4) - 1 + } + } + + pub fn count_extra_fields(&self) -> usize { + self.field_count() - Self::FIELD_COUNT + } + + pub fn has_extra_fields(&self) -> bool { + Self::FIELD_COUNT != self.field_count() + } + + pub fn hold_keys(&self) -> HoldCotaNFTKeyVecReader<'r> { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[4..]) as usize; + let end = molecule::unpack_number(&slice[8..]) as usize; + HoldCotaNFTKeyVecReader::new_unchecked(&self.as_slice()[start..end]) + } + + pub fn hold_old_values(&self) -> HoldCotaNFTValueVecReader<'r> { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[8..]) as usize; + let end = molecule::unpack_number(&slice[12..]) as usize; + HoldCotaNFTValueVecReader::new_unchecked(&self.as_slice()[start..end]) + } + + pub fn hold_new_values(&self) -> HoldCotaNFTValueVecReader<'r> { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[12..]) as usize; + let end = molecule::unpack_number(&slice[16..]) as usize; + HoldCotaNFTValueVecReader::new_unchecked(&self.as_slice()[start..end]) + } + + pub fn claim_keys(&self) -> ClaimCotaNFTKeyVecReader<'r> { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[16..]) as usize; + let end = molecule::unpack_number(&slice[20..]) as usize; + ClaimCotaNFTKeyVecReader::new_unchecked(&self.as_slice()[start..end]) + } + + pub fn claim_values(&self) -> ClaimCotaNFTValueVecReader<'r> { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[20..]) as usize; + let end = molecule::unpack_number(&slice[24..]) as usize; + ClaimCotaNFTValueVecReader::new_unchecked(&self.as_slice()[start..end]) + } + + pub fn withdrawal_keys(&self) -> WithdrawalCotaNFTKeyVecReader<'r> { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[24..]) as usize; + let end = molecule::unpack_number(&slice[28..]) as usize; + WithdrawalCotaNFTKeyVecReader::new_unchecked(&self.as_slice()[start..end]) + } + + pub fn withdrawal_values(&self) -> WithdrawalCotaNFTValueVecReader<'r> { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[28..]) as usize; + let end = molecule::unpack_number(&slice[32..]) as usize; + WithdrawalCotaNFTValueVecReader::new_unchecked(&self.as_slice()[start..end]) + } + + pub fn proof(&self) -> BytesReader<'r> { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[32..]) as usize; + let end = molecule::unpack_number(&slice[36..]) as usize; + BytesReader::new_unchecked(&self.as_slice()[start..end]) + } + + pub fn withdrawal_proof(&self) -> BytesReader<'r> { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[36..]) as usize; + let end = molecule::unpack_number(&slice[40..]) as usize; + BytesReader::new_unchecked(&self.as_slice()[start..end]) + } + + pub fn action(&self) -> BytesReader<'r> { + let slice = self.as_slice(); + let start = molecule::unpack_number(&slice[40..]) as usize; + if self.has_extra_fields() { + let end = molecule::unpack_number(&slice[44..]) as usize; + BytesReader::new_unchecked(&self.as_slice()[start..end]) + } else { + BytesReader::new_unchecked(&self.as_slice()[start..]) + } + } +} +impl<'r> molecule::prelude::Reader<'r> for TransferUpdateCotaNFTEntriesReader<'r> { + type Entity = TransferUpdateCotaNFTEntries; + + const NAME: &'static str = "TransferUpdateCotaNFTEntriesReader"; + + fn to_entity(&self) -> Self::Entity { + Self::Entity::new_unchecked(self.as_slice().to_owned().into()) + } + + fn new_unchecked(slice: &'r [u8]) -> Self { + TransferUpdateCotaNFTEntriesReader(slice) + } + + fn as_slice(&self) -> &'r [u8] { + self.0 + } + + fn verify(slice: &[u8], compatible: bool) -> molecule::error::VerificationResult<()> { + use molecule::verification_error as ve; + let slice_len = slice.len(); + if slice_len < molecule::NUMBER_SIZE { + return ve!(Self, HeaderIsBroken, molecule::NUMBER_SIZE, slice_len); + } + let total_size = molecule::unpack_number(slice) as usize; + if slice_len != total_size { + return ve!(Self, TotalSizeNotMatch, total_size, slice_len); + } + if slice_len == molecule::NUMBER_SIZE && Self::FIELD_COUNT == 0 { + return Ok(()); + } + if slice_len < molecule::NUMBER_SIZE * 2 { + return ve!(Self, HeaderIsBroken, molecule::NUMBER_SIZE * 2, slice_len); + } + let offset_first = molecule::unpack_number(&slice[molecule::NUMBER_SIZE..]) as usize; + if offset_first % molecule::NUMBER_SIZE != 0 || offset_first < molecule::NUMBER_SIZE * 2 { + return ve!(Self, OffsetsNotMatch); + } + if slice_len < offset_first { + return ve!(Self, HeaderIsBroken, offset_first, slice_len); + } + let field_count = offset_first / molecule::NUMBER_SIZE - 1; + if field_count < Self::FIELD_COUNT { + return ve!(Self, FieldCountNotMatch, Self::FIELD_COUNT, field_count); + } else if !compatible && field_count > Self::FIELD_COUNT { + return ve!(Self, FieldCountNotMatch, Self::FIELD_COUNT, field_count); + }; + let mut offsets: Vec = slice[molecule::NUMBER_SIZE..offset_first] + .chunks_exact(molecule::NUMBER_SIZE) + .map(|x| molecule::unpack_number(x) as usize) + .collect(); + offsets.push(total_size); + if offsets.windows(2).any(|i| i[0] > i[1]) { + return ve!(Self, OffsetsNotMatch); + } + HoldCotaNFTKeyVecReader::verify(&slice[offsets[0]..offsets[1]], compatible)?; + HoldCotaNFTValueVecReader::verify(&slice[offsets[1]..offsets[2]], compatible)?; + HoldCotaNFTValueVecReader::verify(&slice[offsets[2]..offsets[3]], compatible)?; + ClaimCotaNFTKeyVecReader::verify(&slice[offsets[3]..offsets[4]], compatible)?; + ClaimCotaNFTValueVecReader::verify(&slice[offsets[4]..offsets[5]], compatible)?; + WithdrawalCotaNFTKeyVecReader::verify(&slice[offsets[5]..offsets[6]], compatible)?; + WithdrawalCotaNFTValueVecReader::verify(&slice[offsets[6]..offsets[7]], compatible)?; + BytesReader::verify(&slice[offsets[7]..offsets[8]], compatible)?; + BytesReader::verify(&slice[offsets[8]..offsets[9]], compatible)?; + BytesReader::verify(&slice[offsets[9]..offsets[10]], compatible)?; + Ok(()) + } +} +#[derive(Debug, Default)] +pub struct TransferUpdateCotaNFTEntriesBuilder { + pub(crate) hold_keys: HoldCotaNFTKeyVec, + pub(crate) hold_old_values: HoldCotaNFTValueVec, + pub(crate) hold_new_values: HoldCotaNFTValueVec, + pub(crate) claim_keys: ClaimCotaNFTKeyVec, + pub(crate) claim_values: ClaimCotaNFTValueVec, + pub(crate) withdrawal_keys: WithdrawalCotaNFTKeyVec, + pub(crate) withdrawal_values: WithdrawalCotaNFTValueVec, + pub(crate) proof: Bytes, + pub(crate) withdrawal_proof: Bytes, + pub(crate) action: Bytes, +} +impl TransferUpdateCotaNFTEntriesBuilder { + pub const FIELD_COUNT: usize = 10; + + pub fn hold_keys(mut self, v: HoldCotaNFTKeyVec) -> Self { + self.hold_keys = v; + self + } + + pub fn hold_old_values(mut self, v: HoldCotaNFTValueVec) -> Self { + self.hold_old_values = v; + self + } + + pub fn hold_new_values(mut self, v: HoldCotaNFTValueVec) -> Self { + self.hold_new_values = v; + self + } + + pub fn claim_keys(mut self, v: ClaimCotaNFTKeyVec) -> Self { + self.claim_keys = v; + self + } + + pub fn claim_values(mut self, v: ClaimCotaNFTValueVec) -> Self { + self.claim_values = v; + self + } + + pub fn withdrawal_keys(mut self, v: WithdrawalCotaNFTKeyVec) -> Self { + self.withdrawal_keys = v; + self + } + + pub fn withdrawal_values(mut self, v: WithdrawalCotaNFTValueVec) -> Self { + self.withdrawal_values = v; + self + } + + pub fn proof(mut self, v: Bytes) -> Self { + self.proof = v; + self + } + + pub fn withdrawal_proof(mut self, v: Bytes) -> Self { + self.withdrawal_proof = v; + self + } + + pub fn action(mut self, v: Bytes) -> Self { + self.action = v; + self + } +} +impl molecule::prelude::Builder for TransferUpdateCotaNFTEntriesBuilder { + type Entity = TransferUpdateCotaNFTEntries; + + const NAME: &'static str = "TransferUpdateCotaNFTEntriesBuilder"; + + fn expected_length(&self) -> usize { + molecule::NUMBER_SIZE * (Self::FIELD_COUNT + 1) + + self.hold_keys.as_slice().len() + + self.hold_old_values.as_slice().len() + + self.hold_new_values.as_slice().len() + + self.claim_keys.as_slice().len() + + self.claim_values.as_slice().len() + + self.withdrawal_keys.as_slice().len() + + self.withdrawal_values.as_slice().len() + + self.proof.as_slice().len() + + self.withdrawal_proof.as_slice().len() + + self.action.as_slice().len() + } + + fn write(&self, writer: &mut W) -> molecule::io::Result<()> { + let mut total_size = molecule::NUMBER_SIZE * (Self::FIELD_COUNT + 1); + let mut offsets = Vec::with_capacity(Self::FIELD_COUNT); + offsets.push(total_size); + total_size += self.hold_keys.as_slice().len(); + offsets.push(total_size); + total_size += self.hold_old_values.as_slice().len(); + offsets.push(total_size); + total_size += self.hold_new_values.as_slice().len(); + offsets.push(total_size); + total_size += self.claim_keys.as_slice().len(); + offsets.push(total_size); + total_size += self.claim_values.as_slice().len(); + offsets.push(total_size); + total_size += self.withdrawal_keys.as_slice().len(); + offsets.push(total_size); + total_size += self.withdrawal_values.as_slice().len(); + offsets.push(total_size); + total_size += self.proof.as_slice().len(); + offsets.push(total_size); + total_size += self.withdrawal_proof.as_slice().len(); + offsets.push(total_size); + total_size += self.action.as_slice().len(); + writer.write_all(&molecule::pack_number(total_size as molecule::Number))?; + for offset in offsets.into_iter() { + writer.write_all(&molecule::pack_number(offset as molecule::Number))?; + } + writer.write_all(self.hold_keys.as_slice())?; + writer.write_all(self.hold_old_values.as_slice())?; + writer.write_all(self.hold_new_values.as_slice())?; + writer.write_all(self.claim_keys.as_slice())?; + writer.write_all(self.claim_values.as_slice())?; + writer.write_all(self.withdrawal_keys.as_slice())?; + writer.write_all(self.withdrawal_values.as_slice())?; + writer.write_all(self.proof.as_slice())?; + writer.write_all(self.withdrawal_proof.as_slice())?; + writer.write_all(self.action.as_slice())?; + Ok(()) + } + + fn build(&self) -> Self::Entity { + let mut inner = Vec::with_capacity(self.expected_length()); + self.write(&mut inner) + .unwrap_or_else(|_| panic!("{} build should be ok", Self::NAME)); + TransferUpdateCotaNFTEntries::new_unchecked(inner.into()) + } +} From beada9bad3f26391f4b42e081b0b54e2b313c654 Mon Sep 17 00:00:00 2001 From: duanyytop Date: Fri, 25 Feb 2022 14:18:29 +0800 Subject: [PATCH 3/3] refactor: Update claim_infos --- src/common.mol | 3 +- src/common.rs | 372 +++++++++++++++++++++++++++++++++++++++- src/lib.rs | 2 +- src/transfer_update.mol | 10 +- src/transfer_update.rs | 308 +++++++++++---------------------- 5 files changed, 476 insertions(+), 219 deletions(-) diff --git a/src/common.mol b/src/common.mol index 7dce988..de25704 100644 --- a/src/common.mol +++ b/src/common.mol @@ -53,4 +53,5 @@ struct ClaimCotaNFTKey { out_point: OutPointSlice, } vector ClaimCotaNFTKeyVec ; -vector ClaimCotaNFTValueVec ; \ No newline at end of file +vector ClaimCotaNFTValueVec ; +vector ClaimCotaNFTInfoVec ; \ No newline at end of file diff --git a/src/common.rs b/src/common.rs index 914c355..dcca3e3 100644 --- a/src/common.rs +++ b/src/common.rs @@ -1,4 +1,4 @@ -// Generated by Molecule 0.7.2 +// Generated by Molecule 0.7.3 #![allow(unused_imports)] #![allow(dead_code)] @@ -1361,6 +1361,12 @@ impl BytesBuilder { } self } + + pub fn replace(&mut self, index: usize, v: Byte) -> Option { + self.0 + .get_mut(index) + .map(|item| ::core::mem::replace(item, v)) + } } impl molecule::prelude::Builder for BytesBuilder { type Entity = Bytes; @@ -4004,6 +4010,12 @@ impl DefineCotaNFTKeyVecBuilder { } self } + + pub fn replace(&mut self, index: usize, v: DefineCotaNFTId) -> Option { + self.0 + .get_mut(index) + .map(|item| ::core::mem::replace(item, v)) + } } impl molecule::prelude::Builder for DefineCotaNFTKeyVecBuilder { type Entity = DefineCotaNFTKeyVec; @@ -4313,6 +4325,12 @@ impl DefineCotaNFTValueVecBuilder { } self } + + pub fn replace(&mut self, index: usize, v: DefineCotaNFTValue) -> Option { + self.0 + .get_mut(index) + .map(|item| ::core::mem::replace(item, v)) + } } impl molecule::prelude::Builder for DefineCotaNFTValueVecBuilder { type Entity = DefineCotaNFTValueVec; @@ -4619,6 +4637,12 @@ impl HoldCotaNFTKeyVecBuilder { } self } + + pub fn replace(&mut self, index: usize, v: CotaNFTId) -> Option { + self.0 + .get_mut(index) + .map(|item| ::core::mem::replace(item, v)) + } } impl molecule::prelude::Builder for HoldCotaNFTKeyVecBuilder { type Entity = HoldCotaNFTKeyVec; @@ -4921,6 +4945,12 @@ impl HoldCotaNFTValueVecBuilder { } self } + + pub fn replace(&mut self, index: usize, v: CotaNFTInfo) -> Option { + self.0 + .get_mut(index) + .map(|item| ::core::mem::replace(item, v)) + } } impl molecule::prelude::Builder for HoldCotaNFTValueVecBuilder { type Entity = HoldCotaNFTValueVec; @@ -5553,6 +5583,12 @@ impl WithdrawalCotaNFTKeyVecBuilder { } self } + + pub fn replace(&mut self, index: usize, v: CotaNFTId) -> Option { + self.0 + .get_mut(index) + .map(|item| ::core::mem::replace(item, v)) + } } impl molecule::prelude::Builder for WithdrawalCotaNFTKeyVecBuilder { type Entity = WithdrawalCotaNFTKeyVec; @@ -5903,6 +5939,16 @@ impl WithdrawalCotaNFTValueVecBuilder { } self } + + pub fn replace( + &mut self, + index: usize, + v: WithdrawalCotaNFTValue, + ) -> Option { + self.0 + .get_mut(index) + .map(|item| ::core::mem::replace(item, v)) + } } impl molecule::prelude::Builder for WithdrawalCotaNFTValueVecBuilder { type Entity = WithdrawalCotaNFTValueVec; @@ -6429,6 +6475,12 @@ impl ClaimCotaNFTKeyVecBuilder { } self } + + pub fn replace(&mut self, index: usize, v: ClaimCotaNFTKey) -> Option { + self.0 + .get_mut(index) + .map(|item| ::core::mem::replace(item, v)) + } } impl molecule::prelude::Builder for ClaimCotaNFTKeyVecBuilder { type Entity = ClaimCotaNFTKeyVec; @@ -6731,6 +6783,12 @@ impl ClaimCotaNFTValueVecBuilder { } self } + + pub fn replace(&mut self, index: usize, v: Byte32) -> Option { + self.0 + .get_mut(index) + .map(|item| ::core::mem::replace(item, v)) + } } impl molecule::prelude::Builder for ClaimCotaNFTValueVecBuilder { type Entity = ClaimCotaNFTValueVec; @@ -6812,3 +6870,315 @@ impl<'t: 'r, 'r> ::core::iter::ExactSizeIterator for ClaimCotaNFTValueVecReaderI self.2 - self.1 } } +#[derive(Clone)] +pub struct ClaimCotaNFTInfoVec(molecule::bytes::Bytes); +impl ::core::fmt::LowerHex for ClaimCotaNFTInfoVec { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + use molecule::hex_string; + if f.alternate() { + write!(f, "0x")?; + } + write!(f, "{}", hex_string(self.as_slice())) + } +} +impl ::core::fmt::Debug for ClaimCotaNFTInfoVec { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl ::core::fmt::Display for ClaimCotaNFTInfoVec { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{} [", Self::NAME)?; + for i in 0..self.len() { + if i == 0 { + write!(f, "{}", self.get_unchecked(i))?; + } else { + write!(f, ", {}", self.get_unchecked(i))?; + } + } + write!(f, "]") + } +} +impl ::core::default::Default for ClaimCotaNFTInfoVec { + fn default() -> Self { + let v: Vec = vec![0, 0, 0, 0]; + ClaimCotaNFTInfoVec::new_unchecked(v.into()) + } +} +impl ClaimCotaNFTInfoVec { + pub const ITEM_SIZE: usize = 22; + + pub fn total_size(&self) -> usize { + molecule::NUMBER_SIZE + Self::ITEM_SIZE * self.item_count() + } + + pub fn item_count(&self) -> usize { + molecule::unpack_number(self.as_slice()) as usize + } + + pub fn len(&self) -> usize { + self.item_count() + } + + pub fn is_empty(&self) -> bool { + self.len() == 0 + } + + pub fn get(&self, idx: usize) -> Option { + if idx >= self.len() { + None + } else { + Some(self.get_unchecked(idx)) + } + } + + pub fn get_unchecked(&self, idx: usize) -> CotaNFTInfo { + let start = molecule::NUMBER_SIZE + Self::ITEM_SIZE * idx; + let end = start + Self::ITEM_SIZE; + CotaNFTInfo::new_unchecked(self.0.slice(start..end)) + } + + pub fn as_reader<'r>(&'r self) -> ClaimCotaNFTInfoVecReader<'r> { + ClaimCotaNFTInfoVecReader::new_unchecked(self.as_slice()) + } +} +impl molecule::prelude::Entity for ClaimCotaNFTInfoVec { + type Builder = ClaimCotaNFTInfoVecBuilder; + + const NAME: &'static str = "ClaimCotaNFTInfoVec"; + + fn new_unchecked(data: molecule::bytes::Bytes) -> Self { + ClaimCotaNFTInfoVec(data) + } + + fn as_bytes(&self) -> molecule::bytes::Bytes { + self.0.clone() + } + + fn as_slice(&self) -> &[u8] { + &self.0[..] + } + + fn from_slice(slice: &[u8]) -> molecule::error::VerificationResult { + ClaimCotaNFTInfoVecReader::from_slice(slice).map(|reader| reader.to_entity()) + } + + fn from_compatible_slice(slice: &[u8]) -> molecule::error::VerificationResult { + ClaimCotaNFTInfoVecReader::from_compatible_slice(slice).map(|reader| reader.to_entity()) + } + + fn new_builder() -> Self::Builder { + ::core::default::Default::default() + } + + fn as_builder(self) -> Self::Builder { + Self::new_builder().extend(self.into_iter()) + } +} +#[derive(Clone, Copy)] +pub struct ClaimCotaNFTInfoVecReader<'r>(&'r [u8]); +impl<'r> ::core::fmt::LowerHex for ClaimCotaNFTInfoVecReader<'r> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + use molecule::hex_string; + if f.alternate() { + write!(f, "0x")?; + } + write!(f, "{}", hex_string(self.as_slice())) + } +} +impl<'r> ::core::fmt::Debug for ClaimCotaNFTInfoVecReader<'r> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{}({:#x})", Self::NAME, self) + } +} +impl<'r> ::core::fmt::Display for ClaimCotaNFTInfoVecReader<'r> { + fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { + write!(f, "{} [", Self::NAME)?; + for i in 0..self.len() { + if i == 0 { + write!(f, "{}", self.get_unchecked(i))?; + } else { + write!(f, ", {}", self.get_unchecked(i))?; + } + } + write!(f, "]") + } +} +impl<'r> ClaimCotaNFTInfoVecReader<'r> { + pub const ITEM_SIZE: usize = 22; + + pub fn total_size(&self) -> usize { + molecule::NUMBER_SIZE + Self::ITEM_SIZE * self.item_count() + } + + pub fn item_count(&self) -> usize { + molecule::unpack_number(self.as_slice()) as usize + } + + pub fn len(&self) -> usize { + self.item_count() + } + + pub fn is_empty(&self) -> bool { + self.len() == 0 + } + + pub fn get(&self, idx: usize) -> Option> { + if idx >= self.len() { + None + } else { + Some(self.get_unchecked(idx)) + } + } + + pub fn get_unchecked(&self, idx: usize) -> CotaNFTInfoReader<'r> { + let start = molecule::NUMBER_SIZE + Self::ITEM_SIZE * idx; + let end = start + Self::ITEM_SIZE; + CotaNFTInfoReader::new_unchecked(&self.as_slice()[start..end]) + } +} +impl<'r> molecule::prelude::Reader<'r> for ClaimCotaNFTInfoVecReader<'r> { + type Entity = ClaimCotaNFTInfoVec; + + const NAME: &'static str = "ClaimCotaNFTInfoVecReader"; + + fn to_entity(&self) -> Self::Entity { + Self::Entity::new_unchecked(self.as_slice().to_owned().into()) + } + + fn new_unchecked(slice: &'r [u8]) -> Self { + ClaimCotaNFTInfoVecReader(slice) + } + + fn as_slice(&self) -> &'r [u8] { + self.0 + } + + fn verify(slice: &[u8], _compatible: bool) -> molecule::error::VerificationResult<()> { + use molecule::verification_error as ve; + let slice_len = slice.len(); + if slice_len < molecule::NUMBER_SIZE { + return ve!(Self, HeaderIsBroken, molecule::NUMBER_SIZE, slice_len); + } + let item_count = molecule::unpack_number(slice) as usize; + if item_count == 0 { + if slice_len != molecule::NUMBER_SIZE { + return ve!(Self, TotalSizeNotMatch, molecule::NUMBER_SIZE, slice_len); + } + return Ok(()); + } + let total_size = molecule::NUMBER_SIZE + Self::ITEM_SIZE * item_count; + if slice_len != total_size { + return ve!(Self, TotalSizeNotMatch, total_size, slice_len); + } + Ok(()) + } +} +#[derive(Debug, Default)] +pub struct ClaimCotaNFTInfoVecBuilder(pub(crate) Vec); +impl ClaimCotaNFTInfoVecBuilder { + pub const ITEM_SIZE: usize = 22; + + pub fn set(mut self, v: Vec) -> Self { + self.0 = v; + self + } + + pub fn push(mut self, v: CotaNFTInfo) -> Self { + self.0.push(v); + self + } + + pub fn extend>(mut self, iter: T) -> Self { + for elem in iter { + self.0.push(elem); + } + self + } + + pub fn replace(&mut self, index: usize, v: CotaNFTInfo) -> Option { + self.0 + .get_mut(index) + .map(|item| ::core::mem::replace(item, v)) + } +} +impl molecule::prelude::Builder for ClaimCotaNFTInfoVecBuilder { + type Entity = ClaimCotaNFTInfoVec; + + const NAME: &'static str = "ClaimCotaNFTInfoVecBuilder"; + + fn expected_length(&self) -> usize { + molecule::NUMBER_SIZE + Self::ITEM_SIZE * self.0.len() + } + + fn write(&self, writer: &mut W) -> molecule::io::Result<()> { + writer.write_all(&molecule::pack_number(self.0.len() as molecule::Number))?; + for inner in &self.0[..] { + writer.write_all(inner.as_slice())?; + } + Ok(()) + } + + fn build(&self) -> Self::Entity { + let mut inner = Vec::with_capacity(self.expected_length()); + self.write(&mut inner) + .unwrap_or_else(|_| panic!("{} build should be ok", Self::NAME)); + ClaimCotaNFTInfoVec::new_unchecked(inner.into()) + } +} +pub struct ClaimCotaNFTInfoVecIterator(ClaimCotaNFTInfoVec, usize, usize); +impl ::core::iter::Iterator for ClaimCotaNFTInfoVecIterator { + type Item = CotaNFTInfo; + + fn next(&mut self) -> Option { + if self.1 >= self.2 { + None + } else { + let ret = self.0.get_unchecked(self.1); + self.1 += 1; + Some(ret) + } + } +} +impl ::core::iter::ExactSizeIterator for ClaimCotaNFTInfoVecIterator { + fn len(&self) -> usize { + self.2 - self.1 + } +} +impl ::core::iter::IntoIterator for ClaimCotaNFTInfoVec { + type IntoIter = ClaimCotaNFTInfoVecIterator; + type Item = CotaNFTInfo; + + fn into_iter(self) -> Self::IntoIter { + let len = self.len(); + ClaimCotaNFTInfoVecIterator(self, 0, len) + } +} +impl<'r> ClaimCotaNFTInfoVecReader<'r> { + pub fn iter<'t>(&'t self) -> ClaimCotaNFTInfoVecReaderIterator<'t, 'r> { + ClaimCotaNFTInfoVecReaderIterator(&self, 0, self.len()) + } +} +pub struct ClaimCotaNFTInfoVecReaderIterator<'t, 'r>( + &'t ClaimCotaNFTInfoVecReader<'r>, + usize, + usize, +); +impl<'t: 'r, 'r> ::core::iter::Iterator for ClaimCotaNFTInfoVecReaderIterator<'t, 'r> { + type Item = CotaNFTInfoReader<'t>; + + fn next(&mut self) -> Option { + if self.1 >= self.2 { + None + } else { + let ret = self.0.get_unchecked(self.1); + self.1 += 1; + Some(ret) + } + } +} +impl<'t: 'r, 'r> ::core::iter::ExactSizeIterator for ClaimCotaNFTInfoVecReaderIterator<'t, 'r> { + fn len(&self) -> usize { + self.2 - self.1 + } +} diff --git a/src/lib.rs b/src/lib.rs index efd1456..43411ee 100755 --- a/src/lib.rs +++ b/src/lib.rs @@ -9,8 +9,8 @@ pub mod mint; pub mod registry; pub mod smt; pub mod transfer; -pub mod update; pub mod transfer_update; +pub mod update; cfg_if::cfg_if! { if #[cfg(feature = "std")] { diff --git a/src/transfer_update.mol b/src/transfer_update.mol index c008b6d..54c9825 100644 --- a/src/transfer_update.mol +++ b/src/transfer_update.mol @@ -2,21 +2,17 @@ import common; table ClaimUpdateCotaNFTEntries { hold_keys: HoldCotaNFTKeyVec, - hold_old_values: HoldCotaNFTValueVec, - hold_new_values: HoldCotaNFTValueVec, + hold_values: HoldCotaNFTValueVec, claim_keys: ClaimCotaNFTKeyVec, - claim_values: ClaimCotaNFTValueVec, + claim_infos: ClaimCotaNFTInfoVec, proof: Bytes, withdrawal_proof: Bytes, action: Bytes, } table TransferUpdateCotaNFTEntries { - hold_keys: HoldCotaNFTKeyVec, - hold_old_values: HoldCotaNFTValueVec, - hold_new_values: HoldCotaNFTValueVec, claim_keys: ClaimCotaNFTKeyVec, - claim_values: ClaimCotaNFTValueVec, + claim_infos: ClaimCotaNFTInfoVec, withdrawal_keys: WithdrawalCotaNFTKeyVec, withdrawal_values: WithdrawalCotaNFTValueVec, proof: Bytes, diff --git a/src/transfer_update.rs b/src/transfer_update.rs index 34cca86..0066552 100644 --- a/src/transfer_update.rs +++ b/src/transfer_update.rs @@ -8,6 +8,8 @@ use super::ckb_types::prelude::*; use super::molecule::{self, prelude::*}; extern crate alloc; pub use alloc::vec::*; +// these lines above are manually added +// replace "::molecule" to "molecule" in below code use super::common::*; use molecule::prelude::*; @@ -31,10 +33,9 @@ impl ::core::fmt::Display for ClaimUpdateCotaNFTEntries { fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { write!(f, "{} {{ ", Self::NAME)?; write!(f, "{}: {}", "hold_keys", self.hold_keys())?; - write!(f, ", {}: {}", "hold_old_values", self.hold_old_values())?; - write!(f, ", {}: {}", "hold_new_values", self.hold_new_values())?; + write!(f, ", {}: {}", "hold_values", self.hold_values())?; write!(f, ", {}: {}", "claim_keys", self.claim_keys())?; - write!(f, ", {}: {}", "claim_values", self.claim_values())?; + write!(f, ", {}: {}", "claim_infos", self.claim_infos())?; write!(f, ", {}: {}", "proof", self.proof())?; write!(f, ", {}: {}", "withdrawal_proof", self.withdrawal_proof())?; write!(f, ", {}: {}", "action", self.action())?; @@ -48,15 +49,15 @@ impl ::core::fmt::Display for ClaimUpdateCotaNFTEntries { impl ::core::default::Default for ClaimUpdateCotaNFTEntries { fn default() -> Self { let v: Vec = vec![ - 68, 0, 0, 0, 36, 0, 0, 0, 40, 0, 0, 0, 44, 0, 0, 0, 48, 0, 0, 0, 52, 0, 0, 0, 56, 0, 0, - 0, 60, 0, 0, 0, 64, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 60, 0, 0, 0, 32, 0, 0, 0, 36, 0, 0, 0, 40, 0, 0, 0, 44, 0, 0, 0, 48, 0, 0, 0, 52, 0, 0, + 0, 56, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, ]; ClaimUpdateCotaNFTEntries::new_unchecked(v.into()) } } impl ClaimUpdateCotaNFTEntries { - pub const FIELD_COUNT: usize = 8; + pub const FIELD_COUNT: usize = 7; pub fn total_size(&self) -> usize { molecule::unpack_number(self.as_slice()) as usize @@ -85,53 +86,46 @@ impl ClaimUpdateCotaNFTEntries { HoldCotaNFTKeyVec::new_unchecked(self.0.slice(start..end)) } - pub fn hold_old_values(&self) -> HoldCotaNFTValueVec { + pub fn hold_values(&self) -> HoldCotaNFTValueVec { let slice = self.as_slice(); let start = molecule::unpack_number(&slice[8..]) as usize; let end = molecule::unpack_number(&slice[12..]) as usize; HoldCotaNFTValueVec::new_unchecked(self.0.slice(start..end)) } - pub fn hold_new_values(&self) -> HoldCotaNFTValueVec { + pub fn claim_keys(&self) -> ClaimCotaNFTKeyVec { let slice = self.as_slice(); let start = molecule::unpack_number(&slice[12..]) as usize; let end = molecule::unpack_number(&slice[16..]) as usize; - HoldCotaNFTValueVec::new_unchecked(self.0.slice(start..end)) + ClaimCotaNFTKeyVec::new_unchecked(self.0.slice(start..end)) } - pub fn claim_keys(&self) -> ClaimCotaNFTKeyVec { + pub fn claim_infos(&self) -> ClaimCotaNFTInfoVec { let slice = self.as_slice(); let start = molecule::unpack_number(&slice[16..]) as usize; let end = molecule::unpack_number(&slice[20..]) as usize; - ClaimCotaNFTKeyVec::new_unchecked(self.0.slice(start..end)) + ClaimCotaNFTInfoVec::new_unchecked(self.0.slice(start..end)) } - pub fn claim_values(&self) -> ClaimCotaNFTValueVec { + pub fn proof(&self) -> Bytes { let slice = self.as_slice(); let start = molecule::unpack_number(&slice[20..]) as usize; let end = molecule::unpack_number(&slice[24..]) as usize; - ClaimCotaNFTValueVec::new_unchecked(self.0.slice(start..end)) - } - - pub fn proof(&self) -> Bytes { - let slice = self.as_slice(); - let start = molecule::unpack_number(&slice[24..]) as usize; - let end = molecule::unpack_number(&slice[28..]) as usize; Bytes::new_unchecked(self.0.slice(start..end)) } pub fn withdrawal_proof(&self) -> Bytes { let slice = self.as_slice(); - let start = molecule::unpack_number(&slice[28..]) as usize; - let end = molecule::unpack_number(&slice[32..]) as usize; + let start = molecule::unpack_number(&slice[24..]) as usize; + let end = molecule::unpack_number(&slice[28..]) as usize; Bytes::new_unchecked(self.0.slice(start..end)) } pub fn action(&self) -> Bytes { let slice = self.as_slice(); - let start = molecule::unpack_number(&slice[32..]) as usize; + let start = molecule::unpack_number(&slice[28..]) as usize; if self.has_extra_fields() { - let end = molecule::unpack_number(&slice[36..]) as usize; + let end = molecule::unpack_number(&slice[32..]) as usize; Bytes::new_unchecked(self.0.slice(start..end)) } else { Bytes::new_unchecked(self.0.slice(start..)) @@ -175,10 +169,9 @@ impl molecule::prelude::Entity for ClaimUpdateCotaNFTEntries { fn as_builder(self) -> Self::Builder { Self::new_builder() .hold_keys(self.hold_keys()) - .hold_old_values(self.hold_old_values()) - .hold_new_values(self.hold_new_values()) + .hold_values(self.hold_values()) .claim_keys(self.claim_keys()) - .claim_values(self.claim_values()) + .claim_infos(self.claim_infos()) .proof(self.proof()) .withdrawal_proof(self.withdrawal_proof()) .action(self.action()) @@ -204,10 +197,9 @@ impl<'r> ::core::fmt::Display for ClaimUpdateCotaNFTEntriesReader<'r> { fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { write!(f, "{} {{ ", Self::NAME)?; write!(f, "{}: {}", "hold_keys", self.hold_keys())?; - write!(f, ", {}: {}", "hold_old_values", self.hold_old_values())?; - write!(f, ", {}: {}", "hold_new_values", self.hold_new_values())?; + write!(f, ", {}: {}", "hold_values", self.hold_values())?; write!(f, ", {}: {}", "claim_keys", self.claim_keys())?; - write!(f, ", {}: {}", "claim_values", self.claim_values())?; + write!(f, ", {}: {}", "claim_infos", self.claim_infos())?; write!(f, ", {}: {}", "proof", self.proof())?; write!(f, ", {}: {}", "withdrawal_proof", self.withdrawal_proof())?; write!(f, ", {}: {}", "action", self.action())?; @@ -219,7 +211,7 @@ impl<'r> ::core::fmt::Display for ClaimUpdateCotaNFTEntriesReader<'r> { } } impl<'r> ClaimUpdateCotaNFTEntriesReader<'r> { - pub const FIELD_COUNT: usize = 8; + pub const FIELD_COUNT: usize = 7; pub fn total_size(&self) -> usize { molecule::unpack_number(self.as_slice()) as usize @@ -248,53 +240,46 @@ impl<'r> ClaimUpdateCotaNFTEntriesReader<'r> { HoldCotaNFTKeyVecReader::new_unchecked(&self.as_slice()[start..end]) } - pub fn hold_old_values(&self) -> HoldCotaNFTValueVecReader<'r> { + pub fn hold_values(&self) -> HoldCotaNFTValueVecReader<'r> { let slice = self.as_slice(); let start = molecule::unpack_number(&slice[8..]) as usize; let end = molecule::unpack_number(&slice[12..]) as usize; HoldCotaNFTValueVecReader::new_unchecked(&self.as_slice()[start..end]) } - pub fn hold_new_values(&self) -> HoldCotaNFTValueVecReader<'r> { + pub fn claim_keys(&self) -> ClaimCotaNFTKeyVecReader<'r> { let slice = self.as_slice(); let start = molecule::unpack_number(&slice[12..]) as usize; let end = molecule::unpack_number(&slice[16..]) as usize; - HoldCotaNFTValueVecReader::new_unchecked(&self.as_slice()[start..end]) + ClaimCotaNFTKeyVecReader::new_unchecked(&self.as_slice()[start..end]) } - pub fn claim_keys(&self) -> ClaimCotaNFTKeyVecReader<'r> { + pub fn claim_infos(&self) -> ClaimCotaNFTInfoVecReader<'r> { let slice = self.as_slice(); let start = molecule::unpack_number(&slice[16..]) as usize; let end = molecule::unpack_number(&slice[20..]) as usize; - ClaimCotaNFTKeyVecReader::new_unchecked(&self.as_slice()[start..end]) + ClaimCotaNFTInfoVecReader::new_unchecked(&self.as_slice()[start..end]) } - pub fn claim_values(&self) -> ClaimCotaNFTValueVecReader<'r> { + pub fn proof(&self) -> BytesReader<'r> { let slice = self.as_slice(); let start = molecule::unpack_number(&slice[20..]) as usize; let end = molecule::unpack_number(&slice[24..]) as usize; - ClaimCotaNFTValueVecReader::new_unchecked(&self.as_slice()[start..end]) - } - - pub fn proof(&self) -> BytesReader<'r> { - let slice = self.as_slice(); - let start = molecule::unpack_number(&slice[24..]) as usize; - let end = molecule::unpack_number(&slice[28..]) as usize; BytesReader::new_unchecked(&self.as_slice()[start..end]) } pub fn withdrawal_proof(&self) -> BytesReader<'r> { let slice = self.as_slice(); - let start = molecule::unpack_number(&slice[28..]) as usize; - let end = molecule::unpack_number(&slice[32..]) as usize; + let start = molecule::unpack_number(&slice[24..]) as usize; + let end = molecule::unpack_number(&slice[28..]) as usize; BytesReader::new_unchecked(&self.as_slice()[start..end]) } pub fn action(&self) -> BytesReader<'r> { let slice = self.as_slice(); - let start = molecule::unpack_number(&slice[32..]) as usize; + let start = molecule::unpack_number(&slice[28..]) as usize; if self.has_extra_fields() { - let end = molecule::unpack_number(&slice[36..]) as usize; + let end = molecule::unpack_number(&slice[32..]) as usize; BytesReader::new_unchecked(&self.as_slice()[start..end]) } else { BytesReader::new_unchecked(&self.as_slice()[start..]) @@ -357,41 +342,34 @@ impl<'r> molecule::prelude::Reader<'r> for ClaimUpdateCotaNFTEntriesReader<'r> { } HoldCotaNFTKeyVecReader::verify(&slice[offsets[0]..offsets[1]], compatible)?; HoldCotaNFTValueVecReader::verify(&slice[offsets[1]..offsets[2]], compatible)?; - HoldCotaNFTValueVecReader::verify(&slice[offsets[2]..offsets[3]], compatible)?; - ClaimCotaNFTKeyVecReader::verify(&slice[offsets[3]..offsets[4]], compatible)?; - ClaimCotaNFTValueVecReader::verify(&slice[offsets[4]..offsets[5]], compatible)?; + ClaimCotaNFTKeyVecReader::verify(&slice[offsets[2]..offsets[3]], compatible)?; + ClaimCotaNFTInfoVecReader::verify(&slice[offsets[3]..offsets[4]], compatible)?; + BytesReader::verify(&slice[offsets[4]..offsets[5]], compatible)?; BytesReader::verify(&slice[offsets[5]..offsets[6]], compatible)?; BytesReader::verify(&slice[offsets[6]..offsets[7]], compatible)?; - BytesReader::verify(&slice[offsets[7]..offsets[8]], compatible)?; Ok(()) } } #[derive(Debug, Default)] pub struct ClaimUpdateCotaNFTEntriesBuilder { pub(crate) hold_keys: HoldCotaNFTKeyVec, - pub(crate) hold_old_values: HoldCotaNFTValueVec, - pub(crate) hold_new_values: HoldCotaNFTValueVec, + pub(crate) hold_values: HoldCotaNFTValueVec, pub(crate) claim_keys: ClaimCotaNFTKeyVec, - pub(crate) claim_values: ClaimCotaNFTValueVec, + pub(crate) claim_infos: ClaimCotaNFTInfoVec, pub(crate) proof: Bytes, pub(crate) withdrawal_proof: Bytes, pub(crate) action: Bytes, } impl ClaimUpdateCotaNFTEntriesBuilder { - pub const FIELD_COUNT: usize = 8; + pub const FIELD_COUNT: usize = 7; pub fn hold_keys(mut self, v: HoldCotaNFTKeyVec) -> Self { self.hold_keys = v; self } - pub fn hold_old_values(mut self, v: HoldCotaNFTValueVec) -> Self { - self.hold_old_values = v; - self - } - - pub fn hold_new_values(mut self, v: HoldCotaNFTValueVec) -> Self { - self.hold_new_values = v; + pub fn hold_values(mut self, v: HoldCotaNFTValueVec) -> Self { + self.hold_values = v; self } @@ -400,8 +378,8 @@ impl ClaimUpdateCotaNFTEntriesBuilder { self } - pub fn claim_values(mut self, v: ClaimCotaNFTValueVec) -> Self { - self.claim_values = v; + pub fn claim_infos(mut self, v: ClaimCotaNFTInfoVec) -> Self { + self.claim_infos = v; self } @@ -428,10 +406,9 @@ impl molecule::prelude::Builder for ClaimUpdateCotaNFTEntriesBuilder { fn expected_length(&self) -> usize { molecule::NUMBER_SIZE * (Self::FIELD_COUNT + 1) + self.hold_keys.as_slice().len() - + self.hold_old_values.as_slice().len() - + self.hold_new_values.as_slice().len() + + self.hold_values.as_slice().len() + self.claim_keys.as_slice().len() - + self.claim_values.as_slice().len() + + self.claim_infos.as_slice().len() + self.proof.as_slice().len() + self.withdrawal_proof.as_slice().len() + self.action.as_slice().len() @@ -443,13 +420,11 @@ impl molecule::prelude::Builder for ClaimUpdateCotaNFTEntriesBuilder { offsets.push(total_size); total_size += self.hold_keys.as_slice().len(); offsets.push(total_size); - total_size += self.hold_old_values.as_slice().len(); - offsets.push(total_size); - total_size += self.hold_new_values.as_slice().len(); + total_size += self.hold_values.as_slice().len(); offsets.push(total_size); total_size += self.claim_keys.as_slice().len(); offsets.push(total_size); - total_size += self.claim_values.as_slice().len(); + total_size += self.claim_infos.as_slice().len(); offsets.push(total_size); total_size += self.proof.as_slice().len(); offsets.push(total_size); @@ -461,10 +436,9 @@ impl molecule::prelude::Builder for ClaimUpdateCotaNFTEntriesBuilder { writer.write_all(&molecule::pack_number(offset as molecule::Number))?; } writer.write_all(self.hold_keys.as_slice())?; - writer.write_all(self.hold_old_values.as_slice())?; - writer.write_all(self.hold_new_values.as_slice())?; + writer.write_all(self.hold_values.as_slice())?; writer.write_all(self.claim_keys.as_slice())?; - writer.write_all(self.claim_values.as_slice())?; + writer.write_all(self.claim_infos.as_slice())?; writer.write_all(self.proof.as_slice())?; writer.write_all(self.withdrawal_proof.as_slice())?; writer.write_all(self.action.as_slice())?; @@ -497,11 +471,8 @@ impl ::core::fmt::Debug for TransferUpdateCotaNFTEntries { impl ::core::fmt::Display for TransferUpdateCotaNFTEntries { fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { write!(f, "{} {{ ", Self::NAME)?; - write!(f, "{}: {}", "hold_keys", self.hold_keys())?; - write!(f, ", {}: {}", "hold_old_values", self.hold_old_values())?; - write!(f, ", {}: {}", "hold_new_values", self.hold_new_values())?; - write!(f, ", {}: {}", "claim_keys", self.claim_keys())?; - write!(f, ", {}: {}", "claim_values", self.claim_values())?; + write!(f, "{}: {}", "claim_keys", self.claim_keys())?; + write!(f, ", {}: {}", "claim_infos", self.claim_infos())?; write!(f, ", {}: {}", "withdrawal_keys", self.withdrawal_keys())?; write!(f, ", {}: {}", "withdrawal_values", self.withdrawal_values())?; write!(f, ", {}: {}", "proof", self.proof())?; @@ -517,15 +488,15 @@ impl ::core::fmt::Display for TransferUpdateCotaNFTEntries { impl ::core::default::Default for TransferUpdateCotaNFTEntries { fn default() -> Self { let v: Vec = vec![ - 84, 0, 0, 0, 44, 0, 0, 0, 48, 0, 0, 0, 52, 0, 0, 0, 56, 0, 0, 0, 60, 0, 0, 0, 64, 0, 0, - 0, 68, 0, 0, 0, 72, 0, 0, 0, 76, 0, 0, 0, 80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 60, 0, 0, 0, 32, 0, 0, 0, 36, 0, 0, 0, 40, 0, 0, 0, 44, 0, 0, 0, 48, 0, 0, 0, 52, 0, 0, + 0, 56, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, ]; TransferUpdateCotaNFTEntries::new_unchecked(v.into()) } } impl TransferUpdateCotaNFTEntries { - pub const FIELD_COUNT: usize = 10; + pub const FIELD_COUNT: usize = 7; pub fn total_size(&self) -> usize { molecule::unpack_number(self.as_slice()) as usize @@ -547,74 +518,53 @@ impl TransferUpdateCotaNFTEntries { Self::FIELD_COUNT != self.field_count() } - pub fn hold_keys(&self) -> HoldCotaNFTKeyVec { + pub fn claim_keys(&self) -> ClaimCotaNFTKeyVec { let slice = self.as_slice(); let start = molecule::unpack_number(&slice[4..]) as usize; let end = molecule::unpack_number(&slice[8..]) as usize; - HoldCotaNFTKeyVec::new_unchecked(self.0.slice(start..end)) + ClaimCotaNFTKeyVec::new_unchecked(self.0.slice(start..end)) } - pub fn hold_old_values(&self) -> HoldCotaNFTValueVec { + pub fn claim_infos(&self) -> ClaimCotaNFTInfoVec { let slice = self.as_slice(); let start = molecule::unpack_number(&slice[8..]) as usize; let end = molecule::unpack_number(&slice[12..]) as usize; - HoldCotaNFTValueVec::new_unchecked(self.0.slice(start..end)) + ClaimCotaNFTInfoVec::new_unchecked(self.0.slice(start..end)) } - pub fn hold_new_values(&self) -> HoldCotaNFTValueVec { + pub fn withdrawal_keys(&self) -> WithdrawalCotaNFTKeyVec { let slice = self.as_slice(); let start = molecule::unpack_number(&slice[12..]) as usize; let end = molecule::unpack_number(&slice[16..]) as usize; - HoldCotaNFTValueVec::new_unchecked(self.0.slice(start..end)) - } - - pub fn claim_keys(&self) -> ClaimCotaNFTKeyVec { - let slice = self.as_slice(); - let start = molecule::unpack_number(&slice[16..]) as usize; - let end = molecule::unpack_number(&slice[20..]) as usize; - ClaimCotaNFTKeyVec::new_unchecked(self.0.slice(start..end)) - } - - pub fn claim_values(&self) -> ClaimCotaNFTValueVec { - let slice = self.as_slice(); - let start = molecule::unpack_number(&slice[20..]) as usize; - let end = molecule::unpack_number(&slice[24..]) as usize; - ClaimCotaNFTValueVec::new_unchecked(self.0.slice(start..end)) - } - - pub fn withdrawal_keys(&self) -> WithdrawalCotaNFTKeyVec { - let slice = self.as_slice(); - let start = molecule::unpack_number(&slice[24..]) as usize; - let end = molecule::unpack_number(&slice[28..]) as usize; WithdrawalCotaNFTKeyVec::new_unchecked(self.0.slice(start..end)) } pub fn withdrawal_values(&self) -> WithdrawalCotaNFTValueVec { let slice = self.as_slice(); - let start = molecule::unpack_number(&slice[28..]) as usize; - let end = molecule::unpack_number(&slice[32..]) as usize; + let start = molecule::unpack_number(&slice[16..]) as usize; + let end = molecule::unpack_number(&slice[20..]) as usize; WithdrawalCotaNFTValueVec::new_unchecked(self.0.slice(start..end)) } pub fn proof(&self) -> Bytes { let slice = self.as_slice(); - let start = molecule::unpack_number(&slice[32..]) as usize; - let end = molecule::unpack_number(&slice[36..]) as usize; + let start = molecule::unpack_number(&slice[20..]) as usize; + let end = molecule::unpack_number(&slice[24..]) as usize; Bytes::new_unchecked(self.0.slice(start..end)) } pub fn withdrawal_proof(&self) -> Bytes { let slice = self.as_slice(); - let start = molecule::unpack_number(&slice[36..]) as usize; - let end = molecule::unpack_number(&slice[40..]) as usize; + let start = molecule::unpack_number(&slice[24..]) as usize; + let end = molecule::unpack_number(&slice[28..]) as usize; Bytes::new_unchecked(self.0.slice(start..end)) } pub fn action(&self) -> Bytes { let slice = self.as_slice(); - let start = molecule::unpack_number(&slice[40..]) as usize; + let start = molecule::unpack_number(&slice[28..]) as usize; if self.has_extra_fields() { - let end = molecule::unpack_number(&slice[44..]) as usize; + let end = molecule::unpack_number(&slice[32..]) as usize; Bytes::new_unchecked(self.0.slice(start..end)) } else { Bytes::new_unchecked(self.0.slice(start..)) @@ -657,11 +607,8 @@ impl molecule::prelude::Entity for TransferUpdateCotaNFTEntries { fn as_builder(self) -> Self::Builder { Self::new_builder() - .hold_keys(self.hold_keys()) - .hold_old_values(self.hold_old_values()) - .hold_new_values(self.hold_new_values()) .claim_keys(self.claim_keys()) - .claim_values(self.claim_values()) + .claim_infos(self.claim_infos()) .withdrawal_keys(self.withdrawal_keys()) .withdrawal_values(self.withdrawal_values()) .proof(self.proof()) @@ -688,11 +635,8 @@ impl<'r> ::core::fmt::Debug for TransferUpdateCotaNFTEntriesReader<'r> { impl<'r> ::core::fmt::Display for TransferUpdateCotaNFTEntriesReader<'r> { fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { write!(f, "{} {{ ", Self::NAME)?; - write!(f, "{}: {}", "hold_keys", self.hold_keys())?; - write!(f, ", {}: {}", "hold_old_values", self.hold_old_values())?; - write!(f, ", {}: {}", "hold_new_values", self.hold_new_values())?; - write!(f, ", {}: {}", "claim_keys", self.claim_keys())?; - write!(f, ", {}: {}", "claim_values", self.claim_values())?; + write!(f, "{}: {}", "claim_keys", self.claim_keys())?; + write!(f, ", {}: {}", "claim_infos", self.claim_infos())?; write!(f, ", {}: {}", "withdrawal_keys", self.withdrawal_keys())?; write!(f, ", {}: {}", "withdrawal_values", self.withdrawal_values())?; write!(f, ", {}: {}", "proof", self.proof())?; @@ -706,7 +650,7 @@ impl<'r> ::core::fmt::Display for TransferUpdateCotaNFTEntriesReader<'r> { } } impl<'r> TransferUpdateCotaNFTEntriesReader<'r> { - pub const FIELD_COUNT: usize = 10; + pub const FIELD_COUNT: usize = 7; pub fn total_size(&self) -> usize { molecule::unpack_number(self.as_slice()) as usize @@ -728,74 +672,53 @@ impl<'r> TransferUpdateCotaNFTEntriesReader<'r> { Self::FIELD_COUNT != self.field_count() } - pub fn hold_keys(&self) -> HoldCotaNFTKeyVecReader<'r> { + pub fn claim_keys(&self) -> ClaimCotaNFTKeyVecReader<'r> { let slice = self.as_slice(); let start = molecule::unpack_number(&slice[4..]) as usize; let end = molecule::unpack_number(&slice[8..]) as usize; - HoldCotaNFTKeyVecReader::new_unchecked(&self.as_slice()[start..end]) + ClaimCotaNFTKeyVecReader::new_unchecked(&self.as_slice()[start..end]) } - pub fn hold_old_values(&self) -> HoldCotaNFTValueVecReader<'r> { + pub fn claim_infos(&self) -> ClaimCotaNFTInfoVecReader<'r> { let slice = self.as_slice(); let start = molecule::unpack_number(&slice[8..]) as usize; let end = molecule::unpack_number(&slice[12..]) as usize; - HoldCotaNFTValueVecReader::new_unchecked(&self.as_slice()[start..end]) + ClaimCotaNFTInfoVecReader::new_unchecked(&self.as_slice()[start..end]) } - pub fn hold_new_values(&self) -> HoldCotaNFTValueVecReader<'r> { + pub fn withdrawal_keys(&self) -> WithdrawalCotaNFTKeyVecReader<'r> { let slice = self.as_slice(); let start = molecule::unpack_number(&slice[12..]) as usize; let end = molecule::unpack_number(&slice[16..]) as usize; - HoldCotaNFTValueVecReader::new_unchecked(&self.as_slice()[start..end]) - } - - pub fn claim_keys(&self) -> ClaimCotaNFTKeyVecReader<'r> { - let slice = self.as_slice(); - let start = molecule::unpack_number(&slice[16..]) as usize; - let end = molecule::unpack_number(&slice[20..]) as usize; - ClaimCotaNFTKeyVecReader::new_unchecked(&self.as_slice()[start..end]) - } - - pub fn claim_values(&self) -> ClaimCotaNFTValueVecReader<'r> { - let slice = self.as_slice(); - let start = molecule::unpack_number(&slice[20..]) as usize; - let end = molecule::unpack_number(&slice[24..]) as usize; - ClaimCotaNFTValueVecReader::new_unchecked(&self.as_slice()[start..end]) - } - - pub fn withdrawal_keys(&self) -> WithdrawalCotaNFTKeyVecReader<'r> { - let slice = self.as_slice(); - let start = molecule::unpack_number(&slice[24..]) as usize; - let end = molecule::unpack_number(&slice[28..]) as usize; WithdrawalCotaNFTKeyVecReader::new_unchecked(&self.as_slice()[start..end]) } pub fn withdrawal_values(&self) -> WithdrawalCotaNFTValueVecReader<'r> { let slice = self.as_slice(); - let start = molecule::unpack_number(&slice[28..]) as usize; - let end = molecule::unpack_number(&slice[32..]) as usize; + let start = molecule::unpack_number(&slice[16..]) as usize; + let end = molecule::unpack_number(&slice[20..]) as usize; WithdrawalCotaNFTValueVecReader::new_unchecked(&self.as_slice()[start..end]) } pub fn proof(&self) -> BytesReader<'r> { let slice = self.as_slice(); - let start = molecule::unpack_number(&slice[32..]) as usize; - let end = molecule::unpack_number(&slice[36..]) as usize; + let start = molecule::unpack_number(&slice[20..]) as usize; + let end = molecule::unpack_number(&slice[24..]) as usize; BytesReader::new_unchecked(&self.as_slice()[start..end]) } pub fn withdrawal_proof(&self) -> BytesReader<'r> { let slice = self.as_slice(); - let start = molecule::unpack_number(&slice[36..]) as usize; - let end = molecule::unpack_number(&slice[40..]) as usize; + let start = molecule::unpack_number(&slice[24..]) as usize; + let end = molecule::unpack_number(&slice[28..]) as usize; BytesReader::new_unchecked(&self.as_slice()[start..end]) } pub fn action(&self) -> BytesReader<'r> { let slice = self.as_slice(); - let start = molecule::unpack_number(&slice[40..]) as usize; + let start = molecule::unpack_number(&slice[28..]) as usize; if self.has_extra_fields() { - let end = molecule::unpack_number(&slice[44..]) as usize; + let end = molecule::unpack_number(&slice[32..]) as usize; BytesReader::new_unchecked(&self.as_slice()[start..end]) } else { BytesReader::new_unchecked(&self.as_slice()[start..]) @@ -856,26 +779,20 @@ impl<'r> molecule::prelude::Reader<'r> for TransferUpdateCotaNFTEntriesReader<'r if offsets.windows(2).any(|i| i[0] > i[1]) { return ve!(Self, OffsetsNotMatch); } - HoldCotaNFTKeyVecReader::verify(&slice[offsets[0]..offsets[1]], compatible)?; - HoldCotaNFTValueVecReader::verify(&slice[offsets[1]..offsets[2]], compatible)?; - HoldCotaNFTValueVecReader::verify(&slice[offsets[2]..offsets[3]], compatible)?; - ClaimCotaNFTKeyVecReader::verify(&slice[offsets[3]..offsets[4]], compatible)?; - ClaimCotaNFTValueVecReader::verify(&slice[offsets[4]..offsets[5]], compatible)?; - WithdrawalCotaNFTKeyVecReader::verify(&slice[offsets[5]..offsets[6]], compatible)?; - WithdrawalCotaNFTValueVecReader::verify(&slice[offsets[6]..offsets[7]], compatible)?; - BytesReader::verify(&slice[offsets[7]..offsets[8]], compatible)?; - BytesReader::verify(&slice[offsets[8]..offsets[9]], compatible)?; - BytesReader::verify(&slice[offsets[9]..offsets[10]], compatible)?; + ClaimCotaNFTKeyVecReader::verify(&slice[offsets[0]..offsets[1]], compatible)?; + ClaimCotaNFTInfoVecReader::verify(&slice[offsets[1]..offsets[2]], compatible)?; + WithdrawalCotaNFTKeyVecReader::verify(&slice[offsets[2]..offsets[3]], compatible)?; + WithdrawalCotaNFTValueVecReader::verify(&slice[offsets[3]..offsets[4]], compatible)?; + BytesReader::verify(&slice[offsets[4]..offsets[5]], compatible)?; + BytesReader::verify(&slice[offsets[5]..offsets[6]], compatible)?; + BytesReader::verify(&slice[offsets[6]..offsets[7]], compatible)?; Ok(()) } } #[derive(Debug, Default)] pub struct TransferUpdateCotaNFTEntriesBuilder { - pub(crate) hold_keys: HoldCotaNFTKeyVec, - pub(crate) hold_old_values: HoldCotaNFTValueVec, - pub(crate) hold_new_values: HoldCotaNFTValueVec, pub(crate) claim_keys: ClaimCotaNFTKeyVec, - pub(crate) claim_values: ClaimCotaNFTValueVec, + pub(crate) claim_infos: ClaimCotaNFTInfoVec, pub(crate) withdrawal_keys: WithdrawalCotaNFTKeyVec, pub(crate) withdrawal_values: WithdrawalCotaNFTValueVec, pub(crate) proof: Bytes, @@ -883,30 +800,15 @@ pub struct TransferUpdateCotaNFTEntriesBuilder { pub(crate) action: Bytes, } impl TransferUpdateCotaNFTEntriesBuilder { - pub const FIELD_COUNT: usize = 10; - - pub fn hold_keys(mut self, v: HoldCotaNFTKeyVec) -> Self { - self.hold_keys = v; - self - } - - pub fn hold_old_values(mut self, v: HoldCotaNFTValueVec) -> Self { - self.hold_old_values = v; - self - } - - pub fn hold_new_values(mut self, v: HoldCotaNFTValueVec) -> Self { - self.hold_new_values = v; - self - } + pub const FIELD_COUNT: usize = 7; pub fn claim_keys(mut self, v: ClaimCotaNFTKeyVec) -> Self { self.claim_keys = v; self } - pub fn claim_values(mut self, v: ClaimCotaNFTValueVec) -> Self { - self.claim_values = v; + pub fn claim_infos(mut self, v: ClaimCotaNFTInfoVec) -> Self { + self.claim_infos = v; self } @@ -942,11 +844,8 @@ impl molecule::prelude::Builder for TransferUpdateCotaNFTEntriesBuilder { fn expected_length(&self) -> usize { molecule::NUMBER_SIZE * (Self::FIELD_COUNT + 1) - + self.hold_keys.as_slice().len() - + self.hold_old_values.as_slice().len() - + self.hold_new_values.as_slice().len() + self.claim_keys.as_slice().len() - + self.claim_values.as_slice().len() + + self.claim_infos.as_slice().len() + self.withdrawal_keys.as_slice().len() + self.withdrawal_values.as_slice().len() + self.proof.as_slice().len() @@ -958,15 +857,9 @@ impl molecule::prelude::Builder for TransferUpdateCotaNFTEntriesBuilder { let mut total_size = molecule::NUMBER_SIZE * (Self::FIELD_COUNT + 1); let mut offsets = Vec::with_capacity(Self::FIELD_COUNT); offsets.push(total_size); - total_size += self.hold_keys.as_slice().len(); - offsets.push(total_size); - total_size += self.hold_old_values.as_slice().len(); - offsets.push(total_size); - total_size += self.hold_new_values.as_slice().len(); - offsets.push(total_size); total_size += self.claim_keys.as_slice().len(); offsets.push(total_size); - total_size += self.claim_values.as_slice().len(); + total_size += self.claim_infos.as_slice().len(); offsets.push(total_size); total_size += self.withdrawal_keys.as_slice().len(); offsets.push(total_size); @@ -981,11 +874,8 @@ impl molecule::prelude::Builder for TransferUpdateCotaNFTEntriesBuilder { for offset in offsets.into_iter() { writer.write_all(&molecule::pack_number(offset as molecule::Number))?; } - writer.write_all(self.hold_keys.as_slice())?; - writer.write_all(self.hold_old_values.as_slice())?; - writer.write_all(self.hold_new_values.as_slice())?; writer.write_all(self.claim_keys.as_slice())?; - writer.write_all(self.claim_values.as_slice())?; + writer.write_all(self.claim_infos.as_slice())?; writer.write_all(self.withdrawal_keys.as_slice())?; writer.write_all(self.withdrawal_values.as_slice())?; writer.write_all(self.proof.as_slice())?;