aboutsummaryrefslogtreecommitdiffstats
path: root/core/vm/stateDB.go
blob: 753b042472a4f126671c68c9b2137b35d83650f4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package vm

import (
    "math/big"

    "github.com/dexon-foundation/dexon/common"
    "github.com/dexon-foundation/dexon/core/state"
    "github.com/dexon-foundation/dexon/core/types"
)

type (
    // CanTransferFunc is the signature of a transfer guard function
    CanTransferFunc func(StateDB, common.Address, *big.Int) bool
    // TransferFunc is the signature of a transfer function
    TransferFunc func(StateDB, common.Address, common.Address, *big.Int)
    // GetHashFunc returns the nth block hash in the blockchain
    // and is used by the BLOCKHASH EVM op code.
    GetHashFunc func(uint64) common.Hash
    // StateAtFunc returns the statedb given a root hash.
    StateAtNumberFunc func(uint64) (*state.StateDB, error)
    // GetRoundHeightFunc returns the round height.
    GetRoundHeightFunc func(uint64) (uint64, bool)
)

// Context provides the EVM with auxiliary information. Once provided
// it shouldn't be modified.
type Context struct {
    // CanTransfer returns whether the account contains
    // sufficient ether to transfer the value
    CanTransfer CanTransferFunc
    // Transfer transfers ether from one account to the other
    Transfer TransferFunc
    // GetHash returns the hash corresponding to n
    GetHash GetHashFunc
    // StateAtNumber returns the statedb given a root hash.
    StateAtNumber StateAtNumberFunc
    // GetRoundHeight returns the round height.
    GetRoundHeight GetRoundHeightFunc

    // Message information
    Origin   common.Address // Provides information for ORIGIN
    GasPrice *big.Int       // Provides information for GASPRICE

    // Block information
    Coinbase    common.Address // Provides information for COINBASE
    GasLimit    uint64         // Provides information for GASLIMIT
    BlockNumber *big.Int       // Provides information for NUMBER
    Time        *big.Int       // Provides information for TIME
    Randomness  []byte         // Provides information for RAND
    Difficulty  *big.Int       // Provides information for DIFFICULTY
    Round       *big.Int       // Current round number.

    RandCallIndex uint64 // Number of times opRand is called
}

// StateDB is an EVM database for full state querying.
type StateDB interface {
    CreateAccount(common.Address)

    SubBalance(common.Address, *big.Int)
    AddBalance(common.Address, *big.Int)
    GetBalance(common.Address) *big.Int

    GetNonce(common.Address) uint64
    SetNonce(common.Address, uint64)

    GetCodeHash(common.Address) common.Hash
    GetCode(common.Address) []byte
    SetCode(common.Address, []byte)
    GetCodeSize(common.Address) int

    AddRefund(uint64)
    SubRefund(uint64)
    GetRefund() uint64

    GetCommittedState(common.Address, common.Hash) common.Hash
    GetState(common.Address, common.Hash) common.Hash
    SetState(common.Address, common.Hash, common.Hash)

    Suicide(common.Address) bool
    HasSuicided(common.Address) bool

    // Exist reports whether the given account exists in state.
    // Notably this should also return true for suicided accounts.
    Exist(common.Address) bool
    // Empty returns whether the given account is empty. Empty
    // is defined according to EIP161 (balance = nonce = code = 0).
    Empty(common.Address) bool

    RevertToSnapshot(int)
    Snapshot() int

    AddLog(*types.Log)
    AddPreimage(common.Hash, []byte)

    ForEachStorage(common.Address, func(common.Hash, common.Hash) bool)
}