github.com/bigzoro/my_simplechain@v0.0.0-20240315012955-8ad0a2a29bb9/core/state/parallel_state_object.go (about) 1 // Copyright 2020 The go-simplechain Authors 2 // This file is part of the go-simplechain library. 3 // 4 // The go-simplechain library is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU Lesser General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // The go-simplechain library is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU Lesser General Public License for more details. 13 // 14 // You should have received a copy of the GNU Lesser General Public License 15 // along with the go-simplechain library. If not, see <http://www.gnu.org/licenses/>. 16 17 package state 18 19 import ( 20 "math/big" 21 ) 22 23 type ParallelStateObject struct { 24 stateObject *stateObject 25 prevAmount *big.Int 26 createFlag bool 27 } 28 29 func NewParallelStateObject(stateObject *stateObject, createFlag bool) *ParallelStateObject { 30 return &ParallelStateObject{ 31 stateObject: stateObject, 32 prevAmount: new(big.Int).Set(stateObject.Balance()), 33 createFlag: createFlag, 34 } 35 } 36 37 func (parallelObject *ParallelStateObject) GetNonce() uint64 { 38 return parallelObject.stateObject.Nonce() 39 } 40 41 func (parallelObject *ParallelStateObject) SetNonce(nonce uint64) { 42 parallelObject.stateObject.setNonce(nonce) 43 } 44 45 func (parallelObject *ParallelStateObject) GetBalance() *big.Int { 46 return parallelObject.stateObject.Balance() 47 } 48 49 func (parallelObject *ParallelStateObject) AddBalance(amount *big.Int) { 50 if amount.Sign() == 0 { 51 return 52 } 53 parallelObject.stateObject.setBalance(new(big.Int).Add(parallelObject.stateObject.Balance(), amount)) 54 } 55 56 func (parallelObject *ParallelStateObject) SubBalance(amount *big.Int) { 57 if amount.Sign() == 0 { 58 return 59 } 60 parallelObject.stateObject.setBalance(new(big.Int).Sub(parallelObject.stateObject.Balance(), amount)) 61 } 62 63 func (parallelObject *ParallelStateObject) UpdateRoot() { 64 parallelObject.stateObject.updateRoot(parallelObject.stateObject.db.db) 65 }