github.com/neatlab/neatio@v1.7.3-0.20220425043230-d903e92fcc75/chain/core/state/statedb1.go (about)

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