interface.go 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. // Copyright 2014 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. GetAccount(common.Address) Account
  25. CreateAccount(common.Address) Account
  26. SubBalance(common.Address, *big.Int)
  27. AddBalance(common.Address, *big.Int)
  28. GetBalance(common.Address) *big.Int
  29. GetNonce(common.Address) uint64
  30. SetNonce(common.Address, uint64)
  31. GetCodeHash(common.Address) common.Hash
  32. GetCode(common.Address) []byte
  33. SetCode(common.Address, []byte)
  34. GetCodeSize(common.Address) int
  35. AddRefund(*big.Int)
  36. GetRefund() *big.Int
  37. GetState(common.Address, common.Hash) common.Hash
  38. SetState(common.Address, common.Hash, common.Hash)
  39. Suicide(common.Address) bool
  40. HasSuicided(common.Address) bool
  41. // Exist reports whether the given account exists in state.
  42. // Notably this should also return true for suicided accounts.
  43. Exist(common.Address) bool
  44. // Empty returns whether the given account is empty. Empty
  45. // is defined according to EIP161 (balance = nonce = code = 0).
  46. Empty(common.Address) bool
  47. RevertToSnapshot(int)
  48. Snapshot() int
  49. AddLog(*types.Log)
  50. AddPreimage(common.Hash, []byte)
  51. }
  52. // Account represents a contract or basic ethereum account.
  53. type Account interface {
  54. SubBalance(amount *big.Int)
  55. AddBalance(amount *big.Int)
  56. SetBalance(*big.Int)
  57. SetNonce(uint64)
  58. Balance() *big.Int
  59. Address() common.Address
  60. ReturnGas(*big.Int)
  61. SetCode(common.Hash, []byte)
  62. ForEachStorage(cb func(key, value common.Hash) bool)
  63. Value() *big.Int
  64. }
  65. // CallContext provides a basic interface for the EVM calling conventions. The EVM EVM
  66. // depends on this context being implemented for doing subcalls and initialising new EVM contracts.
  67. type CallContext interface {
  68. // Call another contract
  69. Call(env *EVM, me ContractRef, addr common.Address, data []byte, gas, value *big.Int) ([]byte, error)
  70. // Take another's contract code and execute within our own context
  71. CallCode(env *EVM, me ContractRef, addr common.Address, data []byte, gas, value *big.Int) ([]byte, error)
  72. // Same as CallCode except sender and value is propagated from parent to child scope
  73. DelegateCall(env *EVM, me ContractRef, addr common.Address, data []byte, gas *big.Int) ([]byte, error)
  74. // Create a new contract
  75. Create(env *EVM, me ContractRef, data []byte, gas, value *big.Int) ([]byte, common.Address, error)
  76. }