Trait WritableShardedVault
pub trait WritableShardedVault: WritableNativeBalance + ReadableShardedVault {
// Required methods
fn set_data(&mut self, data: Option<VaultDataType>);
fn apply_diff(
&mut self,
diff: &StateDiffOperation,
) -> Result<(), VaultError>;
fn set_token_balance(
&mut self,
token_kind: &TokenKind,
balance: u64,
) -> Result<(), VaultError>;
fn set_nft_holdings(
&mut self,
token_kind: &TokenKind,
holdings: BTreeSet<u64>,
) -> Result<(), VaultError>;
// Provided methods
fn checked_add_token_balance(
&mut self,
token_kind: &TokenKind,
balance: u64,
) -> Result<(), VaultError> { ... }
fn checked_sub_token_balance(
&mut self,
token_kind: &TokenKind,
balance: u64,
) -> Result<(), VaultError> { ... }
fn add_nft_holdings(
&mut self,
token_kind: &TokenKind,
holdings: BTreeSet<u64>,
) -> Result<(), VaultError> { ... }
fn apply_nft_diff(
&mut self,
token_kind: &TokenKind,
diff: &Diff,
) -> Result<(), VaultError> { ... }
}Expand description
Trait for modifying sharded vault data.
Required Methods§
fn set_data(&mut self, data: Option<VaultDataType>)
fn set_data(&mut self, data: Option<VaultDataType>)
fn apply_diff(&mut self, diff: &StateDiffOperation) -> Result<(), VaultError>
fn apply_diff(&mut self, diff: &StateDiffOperation) -> Result<(), VaultError>
Applies a state diff operation to the vault.
This method updates the vault’s state based on the operations defined in the state diff operation, such as balance changes or custom data updates.
§Parameters
diff- state diff operation to apply
fn set_token_balance(
&mut self,
token_kind: &TokenKind,
balance: u64,
) -> Result<(), VaultError>
fn set_token_balance( &mut self, token_kind: &TokenKind, balance: u64, ) -> Result<(), VaultError>
Sets the balance of a fungible token type in the vault.
§Parameters
token_kind- type of token to set the balance forbalance- new balance in Planck
§Errors
Returns VaultError::IncompatibleVaultDataType if the vault’s data
is not compatible with storing the specified token type, or
VaultError::IncompatibleTokenKind if the token is an NFT.
fn set_nft_holdings(
&mut self,
token_kind: &TokenKind,
holdings: BTreeSet<u64>,
) -> Result<(), VaultError>
fn set_nft_holdings( &mut self, token_kind: &TokenKind, holdings: BTreeSet<u64>, ) -> Result<(), VaultError>
Sets holdings of a specific NFT token in the vault.
§Parameters
token_kind- type of NFT token to set the holdings forholdings- new NFT holdings
§Errors
Returns VaultError::IncompatibleVaultDataType if the vault’s data is
not compatible with storing the specified token type or
IncompatibleTokenKind if the token is not an NFT.
Provided Methods§
fn checked_add_token_balance(
&mut self,
token_kind: &TokenKind,
balance: u64,
) -> Result<(), VaultError>
fn checked_add_token_balance( &mut self, token_kind: &TokenKind, balance: u64, ) -> Result<(), VaultError>
Adds to a token balance with overflow checking.
§Parameters
token_kind- type of token to add tobalance- amount to add to the balance
§Errors
Returns VaultError::ArithmeticOverflow if the addition would overflow,
VaultError::IncompatibleVaultDataType if the vault’s data is not compatible, or
VaultError::IncompatibleTokenKind if the token is an NFT.
fn checked_sub_token_balance(
&mut self,
token_kind: &TokenKind,
balance: u64,
) -> Result<(), VaultError>
fn checked_sub_token_balance( &mut self, token_kind: &TokenKind, balance: u64, ) -> Result<(), VaultError>
Subtracts from a token balance with underflow checking.
§Parameters
token_kind- type of token to subtract frombalance- amount to subtract from the balance
§Errors
Returns VaultError::ArithmeticUnderflow if the subtraction would underflow,
VaultError::IncompatibleVaultDataType if the vault’s data is not compatible, or
VaultError::IncompatibleTokenKind if the token is an NFT.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.