github.com/intfoundation/intchain@v0.0.0-20220727031208-4316ad31ca73/core/state/statedb1.go (about)

     1  package state
     2  
     3  import (
     4  	"github.com/intfoundation/intchain/common"
     5  	"math/big"
     6  )
     7  
     8  // Retrieve the deposit balance from the given address or 0 if object not found
     9  func (self *StateDB) GetDepositBalance(addr common.Address) *big.Int {
    10  	stateObject := self.getStateObject(addr)
    11  	if stateObject != nil {
    12  		return stateObject.DepositBalance()
    13  	}
    14  	return common.Big0
    15  }
    16  
    17  // Retrieve the child chain deposit balance from the given address or 0 if object not found
    18  func (self *StateDB) GetChildChainDepositBalance(chainId string, addr common.Address) *big.Int {
    19  	stateObject := self.getStateObject(addr)
    20  	if stateObject != nil {
    21  		return stateObject.ChildChainDepositBalance(chainId)
    22  	}
    23  	return common.Big0
    24  }
    25  
    26  // Retrieve the chain balance from the given address or 0 if object not found
    27  func (self *StateDB) GetChainBalance(addr common.Address) *big.Int {
    28  	stateObject := self.getStateObject(addr)
    29  	if stateObject != nil {
    30  		return stateObject.ChainBalance()
    31  	}
    32  	return common.Big0
    33  }
    34  
    35  // AddDepositBalance adds amount to the deposit balance associated with addr
    36  func (self *StateDB) AddDepositBalance(addr common.Address, amount *big.Int) {
    37  	stateObject := self.GetOrNewStateObject(addr)
    38  	if stateObject != nil {
    39  		stateObject.AddDepositBalance(amount)
    40  	}
    41  }
    42  
    43  // SubDepositBalance subs amount to the deposit balance associated with addr
    44  func (self *StateDB) SubDepositBalance(addr common.Address, amount *big.Int) {
    45  	stateObject := self.GetOrNewStateObject(addr)
    46  	if stateObject != nil {
    47  		stateObject.SubDepositBalance(amount)
    48  	}
    49  }
    50  
    51  func (self *StateDB) SetDepositBalance(addr common.Address, amount *big.Int) {
    52  	stateObject := self.GetOrNewStateObject(addr)
    53  	if stateObject != nil {
    54  		stateObject.SetDepositBalance(amount)
    55  	}
    56  }
    57  
    58  // AddChildChainDepositBalance adds amount to the child chain deposit balance associated with addr
    59  func (self *StateDB) AddChildChainDepositBalance(addr common.Address, chainId string, amount *big.Int) {
    60  	stateObject := self.GetOrNewStateObject(addr)
    61  	if stateObject != nil {
    62  		stateObject.AddChildChainDepositBalance(chainId, amount)
    63  	}
    64  }
    65  
    66  // SubDepositBalance subs amount to the child chain deposit balance associated with addr
    67  func (self *StateDB) SubChildChainDepositBalance(addr common.Address, chainId string, amount *big.Int) {
    68  	stateObject := self.GetOrNewStateObject(addr)
    69  	if stateObject != nil {
    70  		stateObject.SubChildChainDepositBalance(chainId, amount)
    71  	}
    72  }
    73  
    74  func (self *StateDB) SetChildChainDepositBalance(addr common.Address, chainId string, amount *big.Int) {
    75  	stateObject := self.GetOrNewStateObject(addr)
    76  	if stateObject != nil {
    77  		stateObject.SetChildChainDepositBalance(chainId, amount)
    78  	}
    79  }
    80  
    81  // AddChainBalance adds amount to the account associated with addr
    82  func (self *StateDB) AddChainBalance(addr common.Address, amount *big.Int) {
    83  	stateObject := self.GetOrNewStateObject(addr)
    84  	if stateObject != nil {
    85  		stateObject.AddChainBalance(amount)
    86  	}
    87  }
    88  
    89  // SubBalance subtracts amount from the account associated with addr
    90  func (self *StateDB) SubChainBalance(addr common.Address, amount *big.Int) {
    91  	stateObject := self.GetOrNewStateObject(addr)
    92  	if stateObject != nil {
    93  		stateObject.SubChainBalance(amount)
    94  	}
    95  }
    96  
    97  func (self *StateDB) SetChainBalance(addr common.Address, amount *big.Int) {
    98  	stateObject := self.GetOrNewStateObject(addr)
    99  	if stateObject != nil {
   100  		stateObject.SetChainBalance(amount)
   101  	}
   102  }