pub struct GeneralResourceConstraint {
pub required_ids: IndexSet<NonFungibleLocalId>,
pub lower_bound: LowerBound,
pub upper_bound: UpperBound,
pub allowed_ids: AllowedIds,
}Expand description
GeneralResourceConstraint captures constraints on the balance of a single fungible
or non-fungible resource.
It captures four concepts:
- A set of
required_idswhich areNonFungibleLocalIds which are required to be in the balance. - A
lower_boundon the decimal balance amount. - An
upper_boundon the decimal balance amount. - Constraints on the
allowed_ids. These are either:AllowedIds::AnyAllowedIds::Allowlist(allowlist)ofNonFungibleLocalIds. If this case, the ids in the resource balance must be a subset of the allowlist.
Fungible resources are viewed as a specialization of non-fungible resources where we disregard
ids and permit non-integer balances. So you must use AllowedIds::Any with fungible resources.
An empty allowlist is also permitted if the balance is exactly zero.
§Trait implementations
- The
PartialEq/Eqimplementations both are correctly order-independent on the id sets, from the order-independent implementation ofIndexSet.
§Validity
To be valid, the following checks must be satisfied:
-
The numeric bounds must be satisfiable:
-
The id bounds must be satisfiable:
- Either
allowed_idsisAllowedIds::Any - Or
allowed_idsisAllowedIds::Allowlist(allowlist)andrequired_idsis a subset ofallowlist.
- Either
-
The numeric and id bounds must be jointly satisfiable, that is, they must overlap:
required_ids.len() <= upper_bound.equivalent_decimal()- If there is an allowlist,
lower_bound.equivalent_decimal() <= allowlist.len()
Also, depending on the resource type, further checks must be satisfied:
-
If the constraints are for a fungible resource, then
required_idsmust be empty, andallowed_idsmust beAllowedIds::Any(or, if the upper bound is zero,AllowedIds::Allowlistwith an empty list is also acceptable). -
If the constraints are for a non-fungible resource, then any decimal balances must be integers.
§Normalization
Normalization takes a valid GeneralResourceConstraint and internally tightens it into a canonical
form. The resultant fields satisfies these tighter conditions:
- Strict ordering of constraints:
required_ids.len() <= lower_bound <= upper_bound <= allowlist.len()
- Detection of exact definition:
- If
required_ids.len() == upper_bound, thenallowed_ids == AllowedIds::Allowlist(required_ids) - If
lower_bound == allowlist.len(), thenrequired_ids == allowlist
- If
Fields§
§required_ids: IndexSet<NonFungibleLocalId>§lower_bound: LowerBound§upper_bound: UpperBound§allowed_ids: AllowedIdsImplementations§
Source§impl GeneralResourceConstraint
impl GeneralResourceConstraint
pub fn fungible( lower_bound: impl Resolve<LowerBound>, upper_bound: impl Resolve<UpperBound>, ) -> Self
pub fn non_fungible_no_allow_list( required_ids: impl IntoIterator<Item = NonFungibleLocalId>, lower_bound: impl Resolve<LowerBound>, upper_bound: impl Resolve<UpperBound>, ) -> Self
pub fn non_fungible_with_allow_list( required_ids: impl IntoIterator<Item = NonFungibleLocalId>, lower_bound: impl Resolve<LowerBound>, upper_bound: impl Resolve<UpperBound>, allowed_ids: impl IntoIterator<Item = NonFungibleLocalId>, ) -> Self
pub fn is_valid_for_fungible_use(&self) -> bool
pub fn is_valid_for_non_fungible_use(&self) -> bool
pub fn validate_fungible( &self, amount: Decimal, ) -> Result<(), ResourceConstraintError>
pub fn validate_non_fungible_ids( &self, ids: &IndexSet<NonFungibleLocalId>, ) -> Result<(), ResourceConstraintError>
pub fn is_valid_independent_of_resource_type(&self) -> bool
Sourcepub fn normalize(&mut self)
pub fn normalize(&mut self)
The process of normalization defined under GeneralResourceConstraint.
This method is assumed to apply to a valid GeneralResourceConstraint - else the result is non-sensical.
Trait Implementations§
Source§impl Clone for GeneralResourceConstraint
impl Clone for GeneralResourceConstraint
Source§fn clone(&self) -> GeneralResourceConstraint
fn clone(&self) -> GeneralResourceConstraint
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for GeneralResourceConstraint
impl Debug for GeneralResourceConstraint
Source§impl<D: Decoder<ManifestCustomValueKind>> Decode<ManifestCustomValueKind, D> for GeneralResourceConstraint
impl<D: Decoder<ManifestCustomValueKind>> Decode<ManifestCustomValueKind, D> for GeneralResourceConstraint
Source§fn decode_body_with_value_kind(
decoder: &mut D,
value_kind: ValueKind<ManifestCustomValueKind>,
) -> Result<Self, DecodeError>
fn decode_body_with_value_kind( decoder: &mut D, value_kind: ValueKind<ManifestCustomValueKind>, ) -> Result<Self, DecodeError>
Source§impl<D: Decoder<ScryptoCustomValueKind>> Decode<ScryptoCustomValueKind, D> for GeneralResourceConstraint
impl<D: Decoder<ScryptoCustomValueKind>> Decode<ScryptoCustomValueKind, D> for GeneralResourceConstraint
Source§fn decode_body_with_value_kind(
decoder: &mut D,
value_kind: ValueKind<ScryptoCustomValueKind>,
) -> Result<Self, DecodeError>
fn decode_body_with_value_kind( decoder: &mut D, value_kind: ValueKind<ScryptoCustomValueKind>, ) -> Result<Self, DecodeError>
Source§impl Describe<ScryptoCustomTypeKind> for GeneralResourceConstraint
impl Describe<ScryptoCustomTypeKind> for GeneralResourceConstraint
Source§const TYPE_ID: RustTypeId
const TYPE_ID: RustTypeId
TYPE_ID should give a unique identifier for its SBOR schema type.
An SBOR schema type capture details about the SBOR payload, how it should be interpreted, validated and displayed. Read moreSource§fn type_data() -> TypeData<ScryptoCustomTypeKind, RustTypeId>
fn type_data() -> TypeData<ScryptoCustomTypeKind, RustTypeId>
Source§fn add_all_dependencies(aggregator: &mut TypeAggregator<ScryptoCustomTypeKind>)
fn add_all_dependencies(aggregator: &mut TypeAggregator<ScryptoCustomTypeKind>)
get_local_type_data, we need to ensure that the type and all of its own references
get added to the aggregator. Read moreSource§impl<E: Encoder<ManifestCustomValueKind>> Encode<ManifestCustomValueKind, E> for GeneralResourceConstraint
impl<E: Encoder<ManifestCustomValueKind>> Encode<ManifestCustomValueKind, E> for GeneralResourceConstraint
Source§fn encode_value_kind(&self, encoder: &mut E) -> Result<(), EncodeError>
fn encode_value_kind(&self, encoder: &mut E) -> Result<(), EncodeError>
Source§fn encode_body(&self, encoder: &mut E) -> Result<(), EncodeError>
fn encode_body(&self, encoder: &mut E) -> Result<(), EncodeError>
Source§impl<E: Encoder<ScryptoCustomValueKind>> Encode<ScryptoCustomValueKind, E> for GeneralResourceConstraint
impl<E: Encoder<ScryptoCustomValueKind>> Encode<ScryptoCustomValueKind, E> for GeneralResourceConstraint
Source§fn encode_value_kind(&self, encoder: &mut E) -> Result<(), EncodeError>
fn encode_value_kind(&self, encoder: &mut E) -> Result<(), EncodeError>
Source§fn encode_body(&self, encoder: &mut E) -> Result<(), EncodeError>
fn encode_body(&self, encoder: &mut E) -> Result<(), EncodeError>
Source§impl SborTuple<ManifestCustomValueKind> for GeneralResourceConstraint
impl SborTuple<ManifestCustomValueKind> for GeneralResourceConstraint
fn get_length(&self) -> usize
Source§impl SborTuple<ScryptoCustomValueKind> for GeneralResourceConstraint
impl SborTuple<ScryptoCustomValueKind> for GeneralResourceConstraint
fn get_length(&self) -> usize
impl Eq for GeneralResourceConstraint
impl StructuralPartialEq for GeneralResourceConstraint
Auto Trait Implementations§
impl Freeze for GeneralResourceConstraint
impl RefUnwindSafe for GeneralResourceConstraint
impl Send for GeneralResourceConstraint
impl Sync for GeneralResourceConstraint
impl Unpin for GeneralResourceConstraint
impl UnwindSafe for GeneralResourceConstraint
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T, U> ContextualTryInto<U> for Twhere
U: ContextualTryFrom<T>,
impl<T, U> ContextualTryInto<U> for Twhere
U: ContextualTryFrom<T>,
type Error = <U as ContextualTryFrom<T>>::Error
type Context = <U as ContextualTryFrom<T>>::Context
fn contextual_try_into( self, context: &<U as ContextualTryFrom<T>>::Context, ) -> Result<U, <U as ContextualTryFrom<T>>::Error>
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.