-
Notifications
You must be signed in to change notification settings - Fork 0
/
statedb.go
77 lines (60 loc) · 3.33 KB
/
statedb.go
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
package keeper
import (
"math/big"
"github.com/furyaxyz/fuxchain/x/evm/types"
sdk "github.com/furyaxyz/fuxchain/libs/cosmos-sdk/types"
ethcmn "github.com/ethereum/go-ethereum/common"
)
// ----------------------------------------------------------------------------
// Setters, only for test use
// ----------------------------------------------------------------------------
// SetBalance calls CommitStateDB.SetBalance using the passed in context
func (k *Keeper) SetBalance(ctx sdk.Context, addr ethcmn.Address, amount *big.Int) {
csdb := types.CreateEmptyCommitStateDB(k.GenerateCSDBParams(), ctx)
csdb.SetBalance(addr, amount)
csdb.Commit(false)
}
// SetNonce calls CommitStateDB.SetNonce using the passed in context
func (k *Keeper) SetNonce(ctx sdk.Context, addr ethcmn.Address, nonce uint64) {
csdb := types.CreateEmptyCommitStateDB(k.GenerateCSDBParams(), ctx)
csdb.SetNonce(addr, nonce)
csdb.Commit(false)
}
// ----------------------------------------------------------------------------
// Getters, for test and query case
// ----------------------------------------------------------------------------
// GetBalance calls CommitStateDB.GetBalance using the passed in context
func (k *Keeper) GetBalance(ctx sdk.Context, addr ethcmn.Address) *big.Int {
return types.CreateEmptyCommitStateDB(k.GenerateCSDBParams(), ctx).GetBalance(addr)
}
// GetCode calls CommitStateDB.GetCode using the passed in context
func (k *Keeper) GetCode(ctx sdk.Context, addr ethcmn.Address) []byte {
return types.CreateEmptyCommitStateDB(k.GenerateCSDBParams(), ctx).GetCode(addr)
}
// GetCodeByHash calls CommitStateDB.GetCode using the passed in context
func (k *Keeper) GetCodeByHash(ctx sdk.Context, hash ethcmn.Hash) []byte {
return types.CreateEmptyCommitStateDB(k.GenerateCSDBParams(), ctx).GetCodeByHash(hash)
}
// GetState calls CommitStateDB.GetState using the passed in context
func (k *Keeper) GetState(ctx sdk.Context, addr ethcmn.Address, hash ethcmn.Hash) ethcmn.Hash {
return types.CreateEmptyCommitStateDB(k.GenerateCSDBParams(), ctx).GetState(addr, hash)
}
// GetState calls CommitStateDB.GetState using the passed in context
func (k *Keeper) GetStorageProof(ctx sdk.Context, addr ethcmn.Address, key ethcmn.Hash) ([][]byte, error) {
return types.CreateEmptyCommitStateDB(k.GenerateCSDBParams(), ctx).GetStorageProof(addr, key)
}
// GetStateByKey calls CommitStateDB.GetState using the passed in context
func (k *Keeper) GetStateByKey(ctx sdk.Context, addr ethcmn.Address, key ethcmn.Hash) []byte {
return types.CreateEmptyCommitStateDB(k.GenerateCSDBParams(), ctx).GetCommittedStateForQuery(addr, key)
}
// ----------------------------------------------------------------------------
// Auxiliary, for test and query case
// ----------------------------------------------------------------------------
// ForEachStorage calls CommitStateDB.ForEachStorage using passed in context
func (k *Keeper) ForEachStorage(ctx sdk.Context, addr ethcmn.Address, cb func(key, value ethcmn.Hash) bool) error {
return types.CreateEmptyCommitStateDB(k.GenerateCSDBParams(), ctx).ForEachStorage(addr, cb)
}
// GetOrNewStateObject calls CommitStateDB.GetOrNetStateObject using the passed in context
func (k *Keeper) GetOrNewStateObject(ctx sdk.Context, addr ethcmn.Address) types.StateObject {
return types.CreateEmptyCommitStateDB(k.GenerateCSDBParams(), ctx).GetOrNewStateObject(addr)
}