-
Notifications
You must be signed in to change notification settings - Fork 246
/
params_native.go
66 lines (59 loc) · 1.61 KB
/
params_native.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
// Copyright (c) 2018 The VeChainThor developers
// Distributed under the GNU Lesser General Public License v3.0 software license, see the accompanying
// file LICENSE or <https://www.gnu.org/licenses/lgpl-3.0.html>
package builtin
import (
"math/big"
"github.com/ethereum/go-ethereum/common"
"github.com/vechain/thor/v2/thor"
"github.com/vechain/thor/v2/xenv"
)
func init() {
defines := []struct {
name string
run func(env *xenv.Environment) []interface{}
}{
{"native_executor", func(env *xenv.Environment) []interface{} {
env.UseGas(thor.SloadGas)
val, err := Params.Native(env.State()).Get(thor.KeyExecutorAddress)
if err != nil {
panic(err)
}
addr := thor.BytesToAddress(val.Bytes())
return []interface{}{addr}
}},
{"native_get", func(env *xenv.Environment) []interface{} {
var key common.Hash
env.ParseArgs(&key)
env.UseGas(thor.SloadGas)
v, err := Params.Native(env.State()).Get(thor.Bytes32(key))
if err != nil {
panic(err)
}
return []interface{}{v}
}},
{"native_set", func(env *xenv.Environment) []interface{} {
var args struct {
Key common.Hash
Value *big.Int
}
env.ParseArgs(&args)
env.UseGas(thor.SstoreSetGas)
if err := Params.Native(env.State()).Set(thor.Bytes32(args.Key), args.Value); err != nil {
panic(err)
}
return nil
}},
}
abi := Params.NativeABI()
for _, def := range defines {
if method, found := abi.MethodByName(def.name); found {
nativeMethods[methodKey{Params.Address, method.ID()}] = &nativeMethod{
abi: method,
run: def.run,
}
} else {
panic("method not found: " + def.name)
}
}
}