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 2504744..43411ee 100755 --- a/src/lib.rs +++ b/src/lib.rs @@ -9,6 +9,7 @@ pub mod mint; pub mod registry; pub mod smt; pub mod transfer; +pub mod transfer_update; pub mod update; cfg_if::cfg_if! { 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()) + } +} diff --git a/src/transfer_update.mol b/src/transfer_update.mol new file mode 100644 index 0000000..54c9825 --- /dev/null +++ b/src/transfer_update.mol @@ -0,0 +1,21 @@ +import common; + +table ClaimUpdateCotaNFTEntries { + hold_keys: HoldCotaNFTKeyVec, + hold_values: HoldCotaNFTValueVec, + claim_keys: ClaimCotaNFTKeyVec, + claim_infos: ClaimCotaNFTInfoVec, + proof: Bytes, + withdrawal_proof: Bytes, + action: Bytes, +} + +table TransferUpdateCotaNFTEntries { + claim_keys: ClaimCotaNFTKeyVec, + claim_infos: ClaimCotaNFTInfoVec, + 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..0066552 --- /dev/null +++ b/src/transfer_update.rs @@ -0,0 +1,893 @@ +// 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::*; +// these lines above are manually added +// replace "::molecule" to "molecule" in below code + +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_values", self.hold_values())?; + write!(f, ", {}: {}", "claim_keys", self.claim_keys())?; + write!(f, ", {}: {}", "claim_infos", self.claim_infos())?; + 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![ + 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 = 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 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_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 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; + ClaimCotaNFTKeyVec::new_unchecked(self.0.slice(start..end)) + } + + 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; + ClaimCotaNFTInfoVec::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) -> 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_values(self.hold_values()) + .claim_keys(self.claim_keys()) + .claim_infos(self.claim_infos()) + .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_values", self.hold_values())?; + write!(f, ", {}: {}", "claim_keys", self.claim_keys())?; + write!(f, ", {}: {}", "claim_infos", self.claim_infos())?; + 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 = 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 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_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 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; + ClaimCotaNFTKeyVecReader::new_unchecked(&self.as_slice()[start..end]) + } + + 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; + ClaimCotaNFTInfoVecReader::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 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)?; + 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)?; + Ok(()) + } +} +#[derive(Debug, Default)] +pub struct ClaimUpdateCotaNFTEntriesBuilder { + pub(crate) hold_keys: HoldCotaNFTKeyVec, + pub(crate) hold_values: HoldCotaNFTValueVec, + pub(crate) claim_keys: ClaimCotaNFTKeyVec, + 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 = 7; + + pub fn hold_keys(mut self, v: HoldCotaNFTKeyVec) -> Self { + self.hold_keys = v; + self + } + + pub fn hold_values(mut self, v: HoldCotaNFTValueVec) -> Self { + self.hold_values = v; + self + } + + pub fn claim_keys(mut self, v: ClaimCotaNFTKeyVec) -> Self { + self.claim_keys = v; + self + } + + pub fn claim_infos(mut self, v: ClaimCotaNFTInfoVec) -> Self { + self.claim_infos = 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_values.as_slice().len() + + self.claim_keys.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() + } + + 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_values.as_slice().len(); + offsets.push(total_size); + total_size += self.claim_keys.as_slice().len(); + offsets.push(total_size); + total_size += self.claim_infos.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_values.as_slice())?; + writer.write_all(self.claim_keys.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())?; + 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, "{}: {}", "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())?; + 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![ + 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 = 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_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; + ClaimCotaNFTInfoVec::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) -> 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() + .claim_keys(self.claim_keys()) + .claim_infos(self.claim_infos()) + .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, "{}: {}", "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())?; + 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 = 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_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; + ClaimCotaNFTInfoVecReader::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 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); + } + 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) claim_keys: ClaimCotaNFTKeyVec, + pub(crate) claim_infos: ClaimCotaNFTInfoVec, + 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 = 7; + + pub fn claim_keys(mut self, v: ClaimCotaNFTKeyVec) -> Self { + self.claim_keys = v; + self + } + + pub fn claim_infos(mut self, v: ClaimCotaNFTInfoVec) -> Self { + self.claim_infos = 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.claim_keys.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() + + 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_infos.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_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())?; + 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()) + } +}