-
Notifications
You must be signed in to change notification settings - Fork 1
/
statedb_api.go
74 lines (71 loc) · 2.26 KB
/
statedb_api.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
package api
import (
types2 "github.com/artela-network/aspect-runtime/types"
"github.com/ethereum/go-ethereum/common"
"github.com/artela-network/aspect-core/types"
)
func (r *Registry) stateDBAPIs() map[string]*types2.HostFuncWithGasRule {
return map[string]*types2.HostFuncWithGasRule{
"getBalance": {
Func: func(addr []byte) ([]byte, error) {
hook, err := types.GetStateDbHook(r.runnerContext.Ctx)
if err != nil || hook == nil {
panic("GetStateDbHook failed")
}
balance := hook.GetBalance(common.BytesToAddress(addr))
return wrapNilByte(balance.Bytes()), nil
},
GasRule: types2.NewStaticGasRule(2000),
},
"getState": {
Func: func(addr []byte, hash []byte) ([]byte, error) {
hook, err := types.GetStateDbHook(r.runnerContext.Ctx)
if err != nil || hook == nil {
panic("GetStateDbHook failed")
}
return wrapNilByte(hook.GetState(common.BytesToAddress(addr), common.BytesToHash(hash)).Bytes()), nil
},
GasRule: types2.NewStaticGasRule(5000),
},
"getCodeHash": {
Func: func(addr []byte) ([]byte, error) {
hook, err := types.GetStateDbHook(r.runnerContext.Ctx)
if err != nil || hook == nil {
panic("GetStateDbHook failed")
}
return wrapNilByte(hook.GetCodeHash(common.BytesToAddress(addr)).Bytes()), nil
},
GasRule: types2.NewStaticGasRule(40000),
},
"getCodeSize": {
Func: func(addr []byte) (uint64, error) {
hook, err := types.GetStateDbHook(r.runnerContext.Ctx)
if err != nil || hook == nil {
panic("GetStateDbHook failed")
}
return uint64(hook.GetCodeSize(common.BytesToAddress(addr))), nil
},
GasRule: types2.NewStaticGasRule(40000),
},
"getNonce": {
Func: func(addr []byte) (uint64, error) {
hook, err := types.GetStateDbHook(r.runnerContext.Ctx)
if err != nil || hook == nil {
panic("GetStateDbHook failed")
}
return hook.GetNonce(common.BytesToAddress(addr)), nil
},
GasRule: types2.NewStaticGasRule(40000),
},
"hasSuicided": {
Func: func(addr []byte) (bool, error) {
hook, err := types.GetStateDbHook(r.runnerContext.Ctx)
if err != nil || hook == nil {
panic("GetStateDbHook failed")
}
return hook.HasSuicided(common.BytesToAddress(addr)), nil
},
GasRule: types2.NewStaticGasRule(40000),
},
}
}