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_ids
which areNonFungibleLocalId
s which are required to be in the balance. - A
lower_bound
on the decimal balance amount. - An
upper_bound
on the decimal balance amount. - Constraints on the
allowed_ids
. These are either:AllowedIds::Any
AllowedIds::Allowlist(allowlist)
ofNonFungibleLocalId
s. 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
/Eq
implementations 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_ids
isAllowedIds::Any
- Or
allowed_ids
isAllowedIds::Allowlist(allowlist)
andrequired_ids
is 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_ids
must be empty, andallowed_ids
must beAllowedIds::Any
(or, if the upper bound is zero,AllowedIds::Allowlist
with 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: AllowedIds
Implementations§
Source§impl GeneralResourceConstraint
impl GeneralResourceConstraint
pub fn fungible( lower_bound: impl Resolve<LowerBound>, upper_bound: impl Resolve<UpperBound>, ) -> GeneralResourceConstraint
pub fn non_fungible_no_allow_list( required_ids: impl IntoIterator<Item = NonFungibleLocalId>, lower_bound: impl Resolve<LowerBound>, upper_bound: impl Resolve<UpperBound>, ) -> GeneralResourceConstraint
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>, ) -> GeneralResourceConstraint
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> Decode<ManifestCustomValueKind, D> for GeneralResourceConstraintwhere
D: Decoder<ManifestCustomValueKind>,
impl<D> Decode<ManifestCustomValueKind, D> for GeneralResourceConstraintwhere
D: Decoder<ManifestCustomValueKind>,
Source§fn decode_body_with_value_kind(
decoder: &mut D,
value_kind: ValueKind<ManifestCustomValueKind>,
) -> Result<GeneralResourceConstraint, DecodeError>
fn decode_body_with_value_kind( decoder: &mut D, value_kind: ValueKind<ManifestCustomValueKind>, ) -> Result<GeneralResourceConstraint, DecodeError>
Source§impl<D> Decode<ScryptoCustomValueKind, D> for GeneralResourceConstraintwhere
D: Decoder<ScryptoCustomValueKind>,
impl<D> Decode<ScryptoCustomValueKind, D> for GeneralResourceConstraintwhere
D: Decoder<ScryptoCustomValueKind>,
Source§fn decode_body_with_value_kind(
decoder: &mut D,
value_kind: ValueKind<ScryptoCustomValueKind>,
) -> Result<GeneralResourceConstraint, DecodeError>
fn decode_body_with_value_kind( decoder: &mut D, value_kind: ValueKind<ScryptoCustomValueKind>, ) -> Result<GeneralResourceConstraint, 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> Encode<ManifestCustomValueKind, E> for GeneralResourceConstraintwhere
E: Encoder<ManifestCustomValueKind>,
impl<E> Encode<ManifestCustomValueKind, E> for GeneralResourceConstraintwhere
E: Encoder<ManifestCustomValueKind>,
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> Encode<ScryptoCustomValueKind, E> for GeneralResourceConstraintwhere
E: Encoder<ScryptoCustomValueKind>,
impl<E> Encode<ScryptoCustomValueKind, E> for GeneralResourceConstraintwhere
E: Encoder<ScryptoCustomValueKind>,
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<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
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.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.Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more