interface.go 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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. //go:generate mockgen -source interface.go -destination mock_interface.go -package vm
  17. package vm
  18. import (
  19. "math/big"
  20. "github.com/ethereum/go-ethereum/common"
  21. "github.com/ethereum/go-ethereum/core/state"
  22. "github.com/ethereum/go-ethereum/core/types"
  23. )
  24. // Quorum
  25. type AccountExtraDataStateGetter interface {
  26. // Return nil for public contract
  27. GetPrivacyMetadata(addr common.Address) (*state.PrivacyMetadata, error)
  28. GetManagedParties(addr common.Address) ([]string, error)
  29. }
  30. type AccountExtraDataStateSetter interface {
  31. SetPrivacyMetadata(addr common.Address, pm *state.PrivacyMetadata)
  32. SetManagedParties(addr common.Address, managedParties []string)
  33. }
  34. // Quorum uses a cut-down StateDB, MinimalApiState. We leave the methods in StateDB commented out so they'll produce a
  35. // conflict when upstream changes.
  36. type MinimalApiState interface {
  37. AccountExtraDataStateGetter
  38. GetBalance(addr common.Address) *big.Int
  39. SetBalance(addr common.Address, balance *big.Int)
  40. GetCode(addr common.Address) []byte
  41. GetState(a common.Address, b common.Hash) common.Hash
  42. GetNonce(addr common.Address) uint64
  43. SetNonce(addr common.Address, nonce uint64)
  44. SetCode(common.Address, []byte)
  45. // RLP-encoded of the state object in a given address
  46. // Throw error if no state object is found
  47. GetRLPEncodedStateObject(addr common.Address) ([]byte, error)
  48. GetProof(common.Address) ([][]byte, error)
  49. GetStorageProof(common.Address, common.Hash) ([][]byte, error)
  50. StorageTrie(addr common.Address) state.Trie
  51. Error() error
  52. GetCodeHash(common.Address) common.Hash
  53. SetState(common.Address, common.Hash, common.Hash)
  54. SetStorage(addr common.Address, storage map[common.Hash]common.Hash)
  55. }
  56. // End Quorum
  57. // StateDB is an EVM database for full state querying.
  58. type StateDB interface {
  59. // Quorum
  60. MinimalApiState
  61. AccountExtraDataStateSetter
  62. // End Quorum
  63. CreateAccount(common.Address)
  64. SubBalance(common.Address, *big.Int)
  65. AddBalance(common.Address, *big.Int)
  66. //GetBalance(common.Address) *big.Int
  67. //GetNonce(common.Address) uint64
  68. //SetNonce(common.Address, uint64)
  69. //GetCodeHash(common.Address) common.Hash
  70. //GetCode(common.Address) []byte
  71. //SetCode(common.Address, []byte)
  72. GetCodeSize(common.Address) int
  73. AddRefund(uint64)
  74. SubRefund(uint64)
  75. GetRefund() uint64
  76. GetCommittedState(common.Address, common.Hash) common.Hash
  77. //GetState(common.Address, common.Hash) common.Hash
  78. //SetState(common.Address, common.Hash, common.Hash)
  79. Suicide(common.Address) bool
  80. HasSuicided(common.Address) bool
  81. // Exist reports whether the given account exists in state.
  82. // Notably this should also return true for suicided accounts.
  83. Exist(common.Address) bool
  84. // Empty returns whether the given account is empty. Empty
  85. // is defined according to EIP161 (balance = nonce = code = 0).
  86. Empty(common.Address) bool
  87. PrepareAccessList(sender common.Address, dest *common.Address, precompiles []common.Address, txAccesses types.AccessList)
  88. AddressInAccessList(addr common.Address) bool
  89. SlotInAccessList(addr common.Address, slot common.Hash) (addressOk bool, slotOk bool)
  90. // AddAddressToAccessList adds the given address to the access list. This operation is safe to perform
  91. // even if the feature/fork is not active yet
  92. AddAddressToAccessList(addr common.Address)
  93. // AddSlotToAccessList adds the given (address,slot) to the access list. This operation is safe to perform
  94. // even if the feature/fork is not active yet
  95. AddSlotToAccessList(addr common.Address, slot common.Hash)
  96. RevertToSnapshot(int)
  97. Snapshot() int
  98. AddLog(*types.Log)
  99. AddPreimage(common.Hash, []byte)
  100. ForEachStorage(common.Address, func(common.Hash, common.Hash) bool) error
  101. }
  102. // CallContext provides a basic interface for the EVM calling conventions. The EVM
  103. // depends on this context being implemented for doing subcalls and initialising new EVM contracts.
  104. type CallContext interface {
  105. // Call another contract
  106. Call(env *EVM, me ContractRef, addr common.Address, data []byte, gas, value *big.Int) ([]byte, error)
  107. // Take another's contract code and execute within our own context
  108. CallCode(env *EVM, me ContractRef, addr common.Address, data []byte, gas, value *big.Int) ([]byte, error)
  109. // Same as CallCode except sender and value is propagated from parent to child scope
  110. DelegateCall(env *EVM, me ContractRef, addr common.Address, data []byte, gas *big.Int) ([]byte, error)
  111. // Create a new contract
  112. Create(env *EVM, me ContractRef, data []byte, gas, value *big.Int) ([]byte, common.Address, error)
  113. }