+ pub(super) fn check_quantity(&self, quantity: Option<u64>) -> Result<(), SemanticError> {
+ let expects_quantity = self.expects_quantity();
+ match quantity {
+ None if expects_quantity => Err(SemanticError::MissingQuantity),
+ Some(_) if !expects_quantity => Err(SemanticError::UnexpectedQuantity),
+ Some(quantity) if !self.is_valid_quantity(quantity) => {
+ Err(SemanticError::InvalidQuantity)
+ },
+ _ => Ok(()),
+ }
+ }
+
+ fn is_valid_quantity(&self, quantity: u64) -> bool {
+ match self.supported_quantity {
+ Quantity::Bounded(n) => {
+ let n = n.get();
+ if n == 1 { false }
+ else { quantity > 0 && quantity <= n }
+ },
+ Quantity::Unbounded => quantity > 0,
+ }
+ }
+
+ fn expects_quantity(&self) -> bool {
+ match self.supported_quantity {
+ Quantity::Bounded(n) => n.get() != 1,
+ Quantity::Unbounded => true,
+ }
+ }
+
+ pub(super) fn as_tlv_stream(&self) -> OfferTlvStreamRef {