github.com/gnolang/gno@v0.0.0-20240520182011-228e9d0192ce/examples/gno.land/p/demo/grc/grc20/user_token.gno (about)

     1  package grc20
     2  
     3  import (
     4  	"std"
     5  )
     6  
     7  // userToken implements the IGRC20 interface.
     8  //
     9  // It is generated by userToken.GRC20().
    10  // It can safely be explosed publicly.
    11  type userToken struct {
    12  	IGRC20 // implements the GRC20 interface.
    13  
    14  	admin *AdminToken
    15  }
    16  
    17  // IGRC20 implementation.
    18  //
    19  
    20  func (t *userToken) GetName() string     { return t.admin.name }
    21  func (t *userToken) GetSymbol() string   { return t.admin.symbol }
    22  func (t *userToken) GetDecimals() uint   { return t.admin.decimals }
    23  func (t *userToken) TotalSupply() uint64 { return t.admin.totalSupply }
    24  
    25  func (t *userToken) BalanceOf(owner std.Address) (uint64, error) {
    26  	return t.admin.balanceOf(owner)
    27  }
    28  
    29  func (t *userToken) Transfer(to std.Address, amount uint64) error {
    30  	caller := std.PrevRealm().Addr()
    31  	return t.admin.transfer(caller, to, amount)
    32  }
    33  
    34  func (t *userToken) Allowance(owner, spender std.Address) (uint64, error) {
    35  	return t.admin.allowance(owner, spender)
    36  }
    37  
    38  func (t *userToken) Approve(spender std.Address, amount uint64) error {
    39  	caller := std.PrevRealm().Addr()
    40  	return t.admin.approve(caller, spender, amount)
    41  }
    42  
    43  func (t *userToken) TransferFrom(from, to std.Address, amount uint64) error {
    44  	spender := std.PrevRealm().Addr()
    45  	if err := t.admin.spendAllowance(from, spender, amount); err != nil {
    46  		return err
    47  	}
    48  	return t.admin.transfer(from, to, amount)
    49  }