Skip to main content

Bucket

Struct Bucket 

Source
pub struct Bucket { /* private fields */ }
Expand description

A temporary container of resources. Buckets exist during a transaction execution. All buckets must be consumed (deposited into a vault, burned etc) before the end of the transaction or the entire transaction will fail.

Implementations§

Source§

impl Bucket

Source

pub fn resource_address(&self) -> ResourceAddress

Returns the resource address of the tokens held in this bucket

Source

pub fn resource_type(&self) -> ResourceType

Returns the type of resource held in this bucket

Source

pub fn take(&mut self, amount: Amount) -> Self

Withdraws amount tokens from the bucket into a new bucket. It will panic if there are not enough tokens in the bucket

  • for fungible resources, the amount is the number of tokens to withdraw
  • for non-fungible resources, the amount is the number of non-specific non-fungible tokens to withdraw. Prefer take_non_fungible if you want to withdraw specific non-fungible tokens.
  • for confidential resources, the amount is the number of revealed tokens to withdraw. Use take_confidential to withdraw confidential tokens with a proof.
Source

pub fn stealth_transfer(self, statement: StealthTransferStatement) -> Self

Source

pub fn take_confidential(&mut self, proof: ConfidentialWithdrawProof) -> Self

Takes (withdraws) confidential resources from the bucket into a new bucket. It will panic if the withdraw fails for any reason, including if the proof withdraws from unknown inputs, withdraws more funds than are available or is otherwise invalid.

Source

pub fn burn(&self)

Destroy all the tokens that this bucket holds. It will panic if the caller does not have the appropriate permission to burn the resource.

Source

pub fn join(self, other: Bucket) -> Self

Joins the bucket with another of the same resource, returning a new joined bucket with the value of both. Will panic if the other bucket does not contain the same resource.

Source

pub fn drop_empty(self)

Drops the bucket if it is empty. Panics if the bucket is not empty. This must be called if all funds have been taken out of the bucket to prevent a dangling bucket error.

Source

pub fn is_empty(&self) -> bool

Returns true if the bucket is empty (i.e. contains zero tokens), otherwise false.

Source

pub fn amount(&self) -> Amount

Returns the amount of tokens held in this bucket.

Fungible: Returns the number of fungible tokens in the bucket excluding locked amounts. Non-Fungible: Returns the number of NFT tokens for non-fungible resources. Confidential: Returns the number of revealed tokens in the bucket excluding locked amounts and confidential commitments. Stealth: Returns the number of revealed tokens in the bucket excluding locked amounts. Stealth UTXOs are not able to be contained in buckets, and so are not counted.

Note that if the resource is confidential, only the revealed amount is returned.

Source

pub fn locked_amount(&self) -> Amount

Returns the amount of tokens held in this bucket excluding unlocked amounts.

Note that if the resource is confidential, only the revealed amount is returned.

Source

pub fn create_proof(&self) -> Proof

Create a proof of ownership for all tokens in the bucket, used mainly for cross-template calls. Note that until the proof is dropped, the contained tokens are locked and cannot be used/deposited.

Source

pub fn get_non_fungible_ids(&self) -> Vec<NonFungibleId>

Returns the IDs of all the non-fungibles in this bucket If the resource is not a non-fungible resource, an empty vector is returned.

Source

pub fn get_non_fungibles(&self) -> Vec<NonFungible>

Returns all the non-fungibles in this bucket. If the resource is not a non-fungible resource, an empty vector is returned.

Source

pub fn count_confidential_commitments(&self) -> u32

Returns the number of confidential commitments in this bucket. Note that this is not indicative of the number of tokens in the bucket, as these are blinded.

Source

pub fn assert_contains_no_confidential_funds(&self)

Asserts that the bucket does not contain any confidential commitments. This is useful to ensure that a bucket is not holding any confidential commitments before performing an operation e.g. depositing it into a vault that expects only revealed funds.

Source

pub const fn from_id(id: BucketId) -> Self

Creates a new bucket from a bucket ID. This is used internally. Performing any operations on this bucket will fail if the bucket is not in scope or does not exist. Rather use methods like Vault::withdraw to obtain a bucket.

Trait Implementations§

Source§

impl Clone for Bucket

Source§

fn clone(&self) -> Bucket

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Bucket

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for Bucket

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for Bucket

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Serialize for Bucket

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,