-
Notifications
You must be signed in to change notification settings - Fork 230
/
contracts.go
67 lines (53 loc) · 1.42 KB
/
contracts.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
package types
import (
// embed compiled smart contract
_ "embed"
"encoding/hex"
"encoding/json"
"fmt"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/common"
)
// ByteString is a byte array that serializes to hex
type ByteString []byte
// MarshalJSON serializes ByteArray to hex
func (s ByteString) MarshalJSON() ([]byte, error) {
bytes, err := json.Marshal(fmt.Sprintf("%x", string(s)))
return bytes, err
}
// UnmarshalJSON deserializes ByteArray to hex
func (s *ByteString) UnmarshalJSON(data []byte) error {
var x string
err := json.Unmarshal(data, &x)
if err == nil {
str, e := hex.DecodeString(x)
*s = str
err = e
}
return err
}
// CompiledContract contains compiled bytecode and abi
type CompiledContract struct {
ABI abi.ABI
Bin ByteString
}
const EVMModuleName = "cronos-evm"
var (
//go:embed contracts/ModuleCRC20.json
cronosCRC20JSON []byte
// ModuleCRC20Contract is the compiled cronos erc20 contract
ModuleCRC20Contract CompiledContract
// EVMModuleAddress is the native module address for EVM
EVMModuleAddress common.Address
)
func init() {
EVMModuleAddress = common.BytesToAddress(authtypes.NewModuleAddress(EVMModuleName).Bytes())
err := json.Unmarshal(cronosCRC20JSON, &ModuleCRC20Contract)
if err != nil {
panic(err)
}
if len(ModuleCRC20Contract.Bin) == 0 {
panic("load contract failed")
}
}