From c9df1cb710b705d66a2ecaf6e84de170f4ac01c4 Mon Sep 17 00:00:00 2001 From: ucwong Date: Tue, 26 Dec 2023 22:20:10 +0800 Subject: [PATCH] state object mdl methods added --- core/state/state_object.go | 56 ----------------------------- core/state/state_object_mdl.go | 66 ++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+), 56 deletions(-) create mode 100644 core/state/state_object_mdl.go diff --git a/core/state/state_object.go b/core/state/state_object.go index 1c6eb18480..0492327760 100644 --- a/core/state/state_object.go +++ b/core/state/state_object.go @@ -31,8 +31,6 @@ import ( "github.com/CortexFoundation/CortexTheseus/rlp" ) -var big0 = big.NewInt(0) - type Code []byte func (s Code) String() string { @@ -434,53 +432,6 @@ func (s *stateObject) setBalance(amount *big.Int) { s.data.Balance = amount } -//func (s *stateObject) AddUpload(amount *big.Int) { -// if amount.Sign() == 0 { -// if s.empty() { -// s.touch() -// } -// -// return -// } -// s.SetUpload(new(big.Int).Add(s.Upload(), amount)) -//} - -func (s *stateObject) SubUpload(amount *big.Int) *big.Int { - if amount.Sign() == 0 { - return s.Upload() - } - var ret *big.Int = big0 - if s.Upload().Cmp(amount) > 0 { - ret = new(big.Int).Sub(s.Upload(), amount) - } - s.SetUpload(ret) - return ret -} - -func (s *stateObject) SetUpload(amount *big.Int) { - s.db.journal.append(uploadChange{ - account: &s.address, - prev: new(big.Int).Set(s.data.Upload), - }) - s.setUpload(amount) -} - -func (s *stateObject) setNum(num *big.Int) { - s.data.Num = num -} - -func (s *stateObject) SetNum(num *big.Int) { - s.db.journal.append(numChange{ - account: &s.address, - prev: new(big.Int).Set(s.data.Num), - }) - s.setNum(num) -} - -func (s *stateObject) setUpload(amount *big.Int) { - s.data.Upload = amount -} - // Return the gas back to the origin. Used by the Virtual machine or Closures func (s *stateObject) ReturnGas(gas *big.Int) {} @@ -583,13 +534,6 @@ func (s *stateObject) Balance() *big.Int { return s.data.Balance } -func (s *stateObject) Upload() *big.Int { - return s.data.Upload -} -func (s *stateObject) Num() *big.Int { - return s.data.Num -} - func (s *stateObject) Nonce() uint64 { return s.data.Nonce } diff --git a/core/state/state_object_mdl.go b/core/state/state_object_mdl.go new file mode 100644 index 0000000000..79330b126e --- /dev/null +++ b/core/state/state_object_mdl.go @@ -0,0 +1,66 @@ +// Copyright 2023 The CortexTheseus Authors +// This file is part of the CortexFoundation library. +// +// The CortexFoundation library is free software: you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// The CortexFoundation library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with the CortexFoundation library. If not, see . + +package state + +import ( + "math/big" +) + +var big0 = big.NewInt(0) + +func (s *stateObject) SubUpload(amount *big.Int) *big.Int { + if amount.Sign() == 0 { + return s.Upload() + } + var ret *big.Int = big0 + if s.Upload().Cmp(amount) > 0 { + ret = new(big.Int).Sub(s.Upload(), amount) + } + s.SetUpload(ret) + return ret +} + +func (s *stateObject) SetUpload(amount *big.Int) { + s.db.journal.append(uploadChange{ + account: &s.address, + prev: new(big.Int).Set(s.data.Upload), + }) + s.setUpload(amount) +} + +func (s *stateObject) setNum(num *big.Int) { + s.data.Num = num +} + +func (s *stateObject) SetNum(num *big.Int) { + s.db.journal.append(numChange{ + account: &s.address, + prev: new(big.Int).Set(s.data.Num), + }) + s.setNum(num) +} + +func (s *stateObject) setUpload(amount *big.Int) { + s.data.Upload = amount +} + +func (s *stateObject) Upload() *big.Int { + return s.data.Upload +} +func (s *stateObject) Num() *big.Int { + return s.data.Num +}