-
Notifications
You must be signed in to change notification settings - Fork 246
/
contract.go
56 lines (47 loc) · 1.29 KB
/
contract.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
// 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 (
"encoding/hex"
"github.com/pkg/errors"
"github.com/vechain/thor/v2/abi"
"github.com/vechain/thor/v2/builtin/gen"
"github.com/vechain/thor/v2/thor"
)
type contract struct {
name string
Address thor.Address
ABI *abi.ABI
}
func mustLoadContract(name string) *contract {
asset := "compiled/" + name + ".abi"
data := gen.MustAsset(asset)
abi, err := abi.New(data)
if err != nil {
panic(errors.Wrap(err, "load ABI for '"+name+"'"))
}
return &contract{
name,
thor.BytesToAddress([]byte(name)),
abi,
}
}
// RuntimeBytecodes load runtime byte codes.
func (c *contract) RuntimeBytecodes() []byte {
asset := "compiled/" + c.name + ".bin-runtime"
data, err := hex.DecodeString(string(gen.MustAsset(asset)))
if err != nil {
panic(errors.Wrap(err, "load runtime byte code for '"+c.name+"'"))
}
return data
}
func (c *contract) NativeABI() *abi.ABI {
asset := "compiled/" + c.name + "Native.abi"
data := gen.MustAsset(asset)
abi, err := abi.New(data)
if err != nil {
panic(errors.Wrap(err, "load native ABI for '"+c.name+"'"))
}
return abi
}