pub struct Bank<C: Context> { /* private fields */ }
Expand description
The sov-bank module manages user balances. It provides functionality for:
- Token creation.
- Token transfers.
- Token burn.
Implementations§
source§impl<C: Context> Bank<C>
impl<C: Context> Bank<C>
sourcepub fn create_token(
&self,
token_name: String,
salt: u64,
initial_balance: Amount,
minter_address: C::Address,
authorized_minters: Vec<C::Address>,
context: &C,
working_set: &mut WorkingSet<C::Storage>
) -> Result<C::Address>
pub fn create_token( &self, token_name: String, salt: u64, initial_balance: Amount, minter_address: C::Address, authorized_minters: Vec<C::Address>, context: &C, working_set: &mut WorkingSet<C::Storage> ) -> Result<C::Address>
Creates a token from a set of configuration parameters. Checks if a token already exists at that address. If so return an error.
sourcepub fn transfer(
&self,
to: C::Address,
coins: Coins<C>,
context: &C,
working_set: &mut WorkingSet<C::Storage>
) -> Result<CallResponse>
pub fn transfer( &self, to: C::Address, coins: Coins<C>, context: &C, working_set: &mut WorkingSet<C::Storage> ) -> Result<CallResponse>
Transfers the set of coins
to the address specified by to
.
sourcepub fn burn(
&self,
coins: Coins<C>,
owner: &C::Address,
working_set: &mut WorkingSet<C::Storage>
) -> Result<()>
pub fn burn( &self, coins: Coins<C>, owner: &C::Address, working_set: &mut WorkingSet<C::Storage> ) -> Result<()>
Burns the set of coins
.
If there is no token at the address specified in the
Coins
structure, return an error; on success it updates the total
supply of tokens.
sourcepub fn mint_from_eoa(
&self,
coins: &Coins<C>,
mint_to_address: &C::Address,
context: &C,
working_set: &mut WorkingSet<C::Storage>
) -> Result<()>
pub fn mint_from_eoa( &self, coins: &Coins<C>, mint_to_address: &C::Address, context: &C, working_set: &mut WorkingSet<C::Storage> ) -> Result<()>
Mints the coins
to the address mint_to_address
using the externally owned account (“EOA”) supplied by
context.sender()
as the authorizer.
Returns an error if the token address doesn’t exist or context.sender()
is not authorized to mint tokens.
On success, it updates the self.tokens
set to store the new balance.
sourcepub fn mint(
&self,
coins: &Coins<C>,
mint_to_address: &C::Address,
authorizer: &C::Address,
working_set: &mut WorkingSet<C::Storage>
) -> Result<()>
pub fn mint( &self, coins: &Coins<C>, mint_to_address: &C::Address, authorizer: &C::Address, working_set: &mut WorkingSet<C::Storage> ) -> Result<()>
Mints the coins
to the address mint_to_address
if authorizer
is an allowed minter.
Returns an error if the token address doesn’t exist or context.sender()
is not authorized to mint tokens.
On success, it updates the self.tokens
set to store the new minted address.
source§impl<C: Context> Bank<C>
impl<C: Context> Bank<C>
sourcepub fn transfer_from(
&self,
from: &C::Address,
to: &C::Address,
coins: Coins<C>,
working_set: &mut WorkingSet<C::Storage>
) -> Result<CallResponse>
pub fn transfer_from( &self, from: &C::Address, to: &C::Address, coins: Coins<C>, working_set: &mut WorkingSet<C::Storage> ) -> Result<CallResponse>
Transfers the set of coins
from the address from
to the address to
.
Returns an error if the token address doesn’t exist.
sourcepub fn get_balance_of(
&self,
user_address: C::Address,
token_address: C::Address,
working_set: &mut WorkingSet<C::Storage>
) -> Option<u64>
pub fn get_balance_of( &self, user_address: C::Address, token_address: C::Address, working_set: &mut WorkingSet<C::Storage> ) -> Option<u64>
Helper function used by the rpc method balance_of
to return the balance of the token stored at token_address
for the user having the address user_address
from the underlying storage. If the token address doesn’t exist, or
if the user doesn’t have tokens of that type, return None
. Otherwise, wrap the resulting balance in Some
.
sourcepub fn get_token_name(
&self,
token_address: &C::Address,
working_set: &mut WorkingSet<C::Storage>
) -> Option<String>
pub fn get_token_name( &self, token_address: &C::Address, working_set: &mut WorkingSet<C::Storage> ) -> Option<String>
Get the name of a token by address