-
Notifications
You must be signed in to change notification settings - Fork 0
/
contract.go
93 lines (76 loc) · 2.08 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
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
package types
import (
_ "embed"
"encoding/hex"
"encoding/json"
"errors"
"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/common"
sdk "github.com/evoblockchain/evochain/libs/cosmos-sdk/types"
authtypes "github.com/evoblockchain/evochain/libs/cosmos-sdk/x/auth/types"
)
// CompiledContract contains compiled bytecode and abi
type CompiledContract struct {
ABI abi.ABI
Bin string
}
var (
IbcEvmModuleETHAddr common.Address
IbcEvmModuleBechAddr sdk.AccAddress
// ModuleERC20Contract is the compiled evo erc20 contract
ModuleERC20Contract CompiledContract
//go:embed contracts/implement.json
implementationERC20ContractJson []byte
//go:embed contracts/proxy.json
proxyERC20ContractJson []byte
)
const (
IbcEvmModuleName = "ibc-evm"
ContractMintMethod = "mint_by_evo_module"
ProxyContractUpgradeTo = "upgradeTo"
ProxyContractChangeAdmin = "changeAdmin"
)
func init() {
IbcEvmModuleBechAddr = authtypes.NewModuleAddress(IbcEvmModuleName)
IbcEvmModuleETHAddr = common.BytesToAddress(IbcEvmModuleBechAddr.Bytes())
MustUnmarshalCompileContract(implementationERC20ContractJson)
MustUnmarshalCompileContract(proxyERC20ContractJson)
}
func (c CompiledContract) ValidBasic() error {
if len(c.Bin) == 0 {
return errors.New("empty bin data")
}
_, err := hex.DecodeString(c.Bin)
return err
}
func MustMarshalCompileContract(data CompiledContract) []byte {
ret, err := MarshalCompileContract(data)
if nil != err {
panic(err)
}
return ret
}
func MarshalCompileContract(data CompiledContract) ([]byte, error) {
return json.Marshal(data)
}
func MustUnmarshalCompileContract(data []byte) CompiledContract {
ret, err := UnmarshalCompileContract(data)
if nil != err {
panic(err)
}
return ret
}
func UnmarshalCompileContract(data []byte) (CompiledContract, error) {
var ret CompiledContract
err := json.Unmarshal(data, &ret)
if nil != err {
return CompiledContract{}, err
}
return ret, nil
}
func GetInternalImplementationBytes() []byte {
return implementationERC20ContractJson
}
func GetInternalProxyBytes() []byte {
return proxyERC20ContractJson
}