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
impl Bucket
Sourcepub fn resource_address(&self) -> ResourceAddress
pub fn resource_address(&self) -> ResourceAddress
Returns the resource address of the tokens held in this bucket
Sourcepub fn resource_type(&self) -> ResourceType
pub fn resource_type(&self) -> ResourceType
Returns the type of resource held in this bucket
Sourcepub fn take(&mut self, amount: Amount) -> Self
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
amountis the number of tokens to withdraw - for non-fungible resources, the
amountis 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
amountis the number of revealed tokens to withdraw. Usetake_confidentialto withdraw confidential tokens with a proof.
pub fn stealth_transfer(self, statement: StealthTransferStatement) -> Self
Sourcepub fn take_confidential(&mut self, proof: ConfidentialWithdrawProof) -> Self
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.
Sourcepub fn burn(&self)
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.
Sourcepub fn join(self, other: Bucket) -> Self
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.
Sourcepub fn drop_empty(self)
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.
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns true if the bucket is empty (i.e. contains zero tokens), otherwise false.
Sourcepub fn amount(&self) -> Amount
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.
Sourcepub fn locked_amount(&self) -> Amount
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.
Sourcepub fn create_proof(&self) -> Proof
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.
Sourcepub fn get_non_fungible_ids(&self) -> Vec<NonFungibleId>
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.
Sourcepub fn get_non_fungibles(&self) -> Vec<NonFungible>
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.
Sourcepub fn count_confidential_commitments(&self) -> u32
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.
Sourcepub fn assert_contains_no_confidential_funds(&self)
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.