github.com/amazechain/amc@v0.1.3/modules/state/database.go (about)

     1  // Copyright 2023 The AmazeChain Authors
     2  // This file is part of the AmazeChain library.
     3  //
     4  // The AmazeChain 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 AmazeChain 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 AmazeChain library. If not, see <http://www.gnu.org/licenses/>.
    16  
    17  //nolint:scopelint
    18  package state
    19  
    20  import (
    21  	"github.com/amazechain/amc/common/account"
    22  	"github.com/amazechain/amc/common/types"
    23  	"github.com/holiman/uint256"
    24  )
    25  
    26  const (
    27  	//FirstContractIncarnation - first incarnation for contract accounts. After 1 it increases by 1.
    28  	FirstContractIncarnation = 1
    29  	//NonContractIncarnation incarnation for non contracts
    30  	NonContractIncarnation = 0
    31  )
    32  
    33  type StateReader interface {
    34  	ReadAccountData(address types.Address) (*account.StateAccount, error)
    35  	ReadAccountStorage(address types.Address, incarnation uint16, key *types.Hash) ([]byte, error)
    36  	ReadAccountCode(address types.Address, incarnation uint16, codeHash types.Hash) ([]byte, error)
    37  	ReadAccountCodeSize(address types.Address, incarnation uint16, codeHash types.Hash) (int, error)
    38  	ReadAccountIncarnation(address types.Address) (uint16, error)
    39  }
    40  
    41  type StateWriter interface {
    42  	UpdateAccountData(address types.Address, original, account *account.StateAccount) error
    43  	UpdateAccountCode(address types.Address, incarnation uint16, codeHash types.Hash, code []byte) error
    44  	DeleteAccount(address types.Address, original *account.StateAccount) error
    45  	WriteAccountStorage(address types.Address, incarnation uint16, key *types.Hash, original, value *uint256.Int) error
    46  	CreateContract(address types.Address) error
    47  }
    48  
    49  type WriterWithChangeSets interface {
    50  	StateWriter
    51  	WriteChangeSets() error
    52  	WriteHistory() error
    53  }
    54  
    55  type NoopWriter struct {
    56  }
    57  
    58  var noopWriter = &NoopWriter{}
    59  
    60  func NewNoopWriter() *NoopWriter {
    61  	return noopWriter
    62  }
    63  
    64  func (nw *NoopWriter) UpdateAccountData(address types.Address, original, account *account.StateAccount) error {
    65  	return nil
    66  }
    67  
    68  func (nw *NoopWriter) DeleteAccount(address types.Address, original *account.StateAccount) error {
    69  	return nil
    70  }
    71  
    72  func (nw *NoopWriter) UpdateAccountCode(address types.Address, incarnation uint16, codeHash types.Hash, code []byte) error {
    73  	return nil
    74  }
    75  
    76  func (nw *NoopWriter) WriteAccountStorage(address types.Address, incarnation uint16, key *types.Hash, original, value *uint256.Int) error {
    77  	return nil
    78  }
    79  
    80  func (nw *NoopWriter) CreateContract(address types.Address) error {
    81  	return nil
    82  }
    83  
    84  func (nw *NoopWriter) WriteChangeSets() error {
    85  	return nil
    86  }
    87  
    88  func (nw *NoopWriter) WriteHistory() error {
    89  	return nil
    90  }