interface.go 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. // Copyright 2016 The go-ethereum Authors
  2. // This file is part of the go-ethereum library.
  3. //
  4. // The go-ethereum 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-ethereum 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-ethereum library. If not, see <http://www.gnu.org/licenses/>.
  16. package vm
  17. import (
  18. "math/big"
  19. "github.com/ethereum/go-ethereum/common"
  20. "github.com/ethereum/go-ethereum/core/types"
  21. )
  22. // StateDB is an EVM database for full state querying.
  23. type StateDB interface {
  24. CreateAccount(common.Address)
  25. SubBalance(common.Address, *big.Int)
  26. AddBalance(common.Address, *big.Int)
  27. GetBalance(common.Address) *big.Int
  28. GetNonce(common.Address) uint64
  29. SetNonce(common.Address, uint64)
  30. GetCodeHash(common.Address) common.Hash
  31. GetCode(common.Address) []byte
  32. SetCode(common.Address, []byte)
  33. GetCodeSize(common.Address) int
  34. AddRefund(uint64)
  35. SubRefund(uint64)
  36. GetRefund() uint64
  37. GetCommittedState(common.Address, common.Hash) common.Hash
  38. GetState(common.Address, common.Hash) common.Hash
  39. SetState(common.Address, common.Hash, common.Hash)
  40. Suicide(common.Address) bool
  41. HasSuicided(common.Address) bool
  42. // Exist reports whether the given account exists in state.
  43. // Notably this should also return true for suicided accounts.
  44. Exist(common.Address) bool
  45. // Empty returns whether the given account is empty. Empty
  46. // is defined according to EIP161 (balance = nonce = code = 0).
  47. Empty(common.Address) bool
  48. PrepareAccessList(sender common.Address, dest *common.Address, precompiles []common.Address, txAccesses types.AccessList)
  49. AddressInAccessList(addr common.Address) bool
  50. SlotInAccessList(addr common.Address, slot common.Hash) (addressOk bool, slotOk bool)
  51. // AddAddressToAccessList adds the given address to the access list. This operation is safe to perform
  52. // even if the feature/fork is not active yet
  53. AddAddressToAccessList(addr common.Address)
  54. // AddSlotToAccessList adds the given (address,slot) to the access list. This operation is safe to perform
  55. // even if the feature/fork is not active yet
  56. AddSlotToAccessList(addr common.Address, slot common.Hash)
  57. RevertToSnapshot(int)
  58. Snapshot() int
  59. AddLog(*types.Log)
  60. AddPreimage(common.Hash, []byte)
  61. ForEachStorage(common.Address, func(common.Hash, common.Hash) bool) error
  62. }
  63. // CallContext provides a basic interface for the EVM calling conventions. The EVM
  64. // depends on this context being implemented for doing subcalls and initialising new EVM contracts.
  65. type CallContext interface {
  66. // Call another contract
  67. Call(env *EVM, me ContractRef, addr common.Address, data []byte, gas, value *big.Int) ([]byte, error)
  68. // Take another's contract code and execute within our own context
  69. CallCode(env *EVM, me ContractRef, addr common.Address, data []byte, gas, value *big.Int) ([]byte, error)
  70. // Same as CallCode except sender and value is propagated from parent to child scope
  71. DelegateCall(env *EVM, me ContractRef, addr common.Address, data []byte, gas *big.Int) ([]byte, error)
  72. // Create a new contract
  73. Create(env *EVM, me ContractRef, data []byte, gas, value *big.Int) ([]byte, common.Address, error)
  74. }