Skip to content

Commit f693378

Browse files
authored
refactor: replace common package with pkg (#1936)
1 parent 2b77e0b commit f693378

File tree

461 files changed

+3938
-3562
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

461 files changed

+3938
-3562
lines changed

.goreleaser.yaml

+4-4
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,10 @@ builds:
5656
- -X github.com/cosmos/cosmos-sdk/version.ClientName=zetaclientd
5757
- -X github.com/cosmos/cosmos-sdk/version.Version={{ .Version }}
5858
- -X github.com/cosmos/cosmos-sdk/version.Commit={{ .Env.COMMIT }}
59-
- -X github.com/zeta-chain/zetacore/common.Name=zetacored
60-
- -X github.com/zeta-chain/zetacore/common.Version={{ .Version }}
61-
- -X github.com/zeta-chain/zetacore/common.CommitHash={{ .Env.COMMIT }}
62-
- -X github.com/zeta-chain/zetacore/common.BuildTime=={{ .Env.BUILDTIME }}
59+
- -X github.com/zeta-chain/zetacore/pkg/constant.Name=zetacored
60+
- -X github.com/zeta-chain/zetacore/pkg/constant.Version={{ .Version }}
61+
- -X github.com/zeta-chain/zetacore/pkg/constant.CommitHash={{ .Env.COMMIT }}
62+
- -X github.com/zeta-chain/zetacore/pkg/constant.BuildTime={{ .Env.BUILDTIME }}
6363
- -X github.com/cosmos/cosmos-sdk/types.DBBackend=pebbledb
6464

6565
- id: "zetaclientd"

Makefile

+4-4
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ ldflags = -X github.com/cosmos/cosmos-sdk/version.Name=zetacore \
1212
-X github.com/cosmos/cosmos-sdk/version.ClientName=zetaclientd \
1313
-X github.com/cosmos/cosmos-sdk/version.Version=$(VERSION) \
1414
-X github.com/cosmos/cosmos-sdk/version.Commit=$(COMMIT) \
15-
-X github.com/zeta-chain/zetacore/common.Name=zetacored \
16-
-X github.com/zeta-chain/zetacore/common.Version=$(VERSION) \
17-
-X github.com/zeta-chain/zetacore/common.CommitHash=$(COMMIT) \
18-
-X github.com/zeta-chain/zetacore/common.BuildTime=$(BUILDTIME) \
15+
-X github.com/zeta-chain/zetacore/pkg/constant.Name=zetacored \
16+
-X github.com/zeta-chain/zetacore/pkg/constant.Version=$(VERSION) \
17+
-X github.com/zeta-chain/zetacore/pkg/constant.CommitHash=$(COMMIT) \
18+
-X github.com/zeta-chain/zetacore/pkg/constant.BuildTime=$(BUILDTIME) \
1919
-X github.com/cosmos/cosmos-sdk/types.DBBackend=pebbledb
2020

2121
BUILD_FLAGS := -ldflags '$(ldflags)' -tags pebbledb,ledger

changelog.md

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
* [1885](https://github.com/zeta-chain/node/pull/1885) - change important metrics on port 8123 to be prometheus compatible
2121
* [1863](https://github.com/zeta-chain/node/pull/1863) - remove duplicate ValidateChainParams function
2222
* [1914](https://github.com/zeta-chain/node/pull/1914) - move crosschain flags to core context in zetaclient
23+
* [1936](https://github.com/zeta-chain/node/pull/1936) - refactor common package into subpackages and rename to pkg
2324

2425
### Features
2526

cmd/zetaclientd/debug.go

+14-13
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import (
1010

1111
"github.com/ethereum/go-ethereum/ethclient"
1212
"github.com/onrik/ethrpc"
13+
"github.com/zeta-chain/zetacore/pkg/chains"
14+
"github.com/zeta-chain/zetacore/pkg/coin"
1315
"github.com/zeta-chain/zetacore/zetaclient/bitcoin"
1416
corecontext "github.com/zeta-chain/zetacore/zetaclient/core_context"
1517
"github.com/zeta-chain/zetacore/zetaclient/evm"
@@ -22,7 +24,6 @@ import (
2224
ethcommon "github.com/ethereum/go-ethereum/common"
2325
"github.com/rs/zerolog"
2426
"github.com/spf13/cobra"
25-
"github.com/zeta-chain/zetacore/common"
2627
"github.com/zeta-chain/zetacore/testutil/sample"
2728
observertypes "github.com/zeta-chain/zetacore/x/observer/types"
2829
"github.com/zeta-chain/zetacore/zetaclient/config"
@@ -90,12 +91,12 @@ func DebugCmd() *cobra.Command {
9091
return err
9192
}
9293

93-
chain := common.GetChainFromChainID(chainID)
94+
chain := chains.GetChainFromChainID(chainID)
9495
if chain == nil {
9596
return fmt.Errorf("invalid chain id")
9697
}
9798

98-
if common.IsEVMChain(chain.ChainId) {
99+
if chains.IsEVMChain(chain.ChainId) {
99100

100101
ob := evm.ChainClient{
101102
Mu: &sync.Mutex{},
@@ -104,7 +105,7 @@ func DebugCmd() *cobra.Command {
104105
ob.WithLogger(chainLogger)
105106
var ethRPC *ethrpc.EthRPC
106107
var client *ethclient.Client
107-
coinType := common.CoinType_Cmd
108+
coinType := coin.CoinType_Cmd
108109
for chain, evmConfig := range cfg.GetAllEVMConfigs() {
109110
if chainID == chain {
110111
ethRPC = ethrpc.NewEthRPC(evmConfig.Endpoint)
@@ -114,7 +115,7 @@ func DebugCmd() *cobra.Command {
114115
}
115116
ob.WithEvmClient(client)
116117
ob.WithEvmJSONRPC(ethRPC)
117-
ob.WithChain(*common.GetChainFromChainID(chainID))
118+
ob.WithChain(*chains.GetChainFromChainID(chainID))
118119
}
119120
}
120121
hash := ethcommon.HexToHash(txHash)
@@ -144,29 +145,29 @@ func DebugCmd() *cobra.Command {
144145
}
145146
evmChainParams.ZetaTokenContractAddress = chainParams.ZetaTokenContractAddress
146147
if strings.EqualFold(tx.To, chainParams.ConnectorContractAddress) {
147-
coinType = common.CoinType_Zeta
148+
coinType = coin.CoinType_Zeta
148149
} else if strings.EqualFold(tx.To, chainParams.Erc20CustodyContractAddress) {
149-
coinType = common.CoinType_ERC20
150+
coinType = coin.CoinType_ERC20
150151
} else if strings.EqualFold(tx.To, tssEthAddress) {
151-
coinType = common.CoinType_Gas
152+
coinType = coin.CoinType_Gas
152153
}
153154
}
154155
}
155156

156157
switch coinType {
157-
case common.CoinType_Zeta:
158+
case coin.CoinType_Zeta:
158159
ballotIdentifier, err = ob.CheckAndVoteInboundTokenZeta(tx, receipt, false)
159160
if err != nil {
160161
return err
161162
}
162163

163-
case common.CoinType_ERC20:
164+
case coin.CoinType_ERC20:
164165
ballotIdentifier, err = ob.CheckAndVoteInboundTokenERC20(tx, receipt, false)
165166
if err != nil {
166167
return err
167168
}
168169

169-
case common.CoinType_Gas:
170+
case coin.CoinType_Gas:
170171
ballotIdentifier, err = ob.CheckAndVoteInboundTokenGas(tx, receipt, false)
171172
if err != nil {
172173
return err
@@ -175,13 +176,13 @@ func DebugCmd() *cobra.Command {
175176
fmt.Println("CoinType not detected")
176177
}
177178
fmt.Println("CoinType : ", coinType)
178-
} else if common.IsBitcoinChain(chain.ChainId) {
179+
} else if chains.IsBitcoinChain(chain.ChainId) {
179180
obBtc := bitcoin.BTCChainClient{
180181
Mu: &sync.Mutex{},
181182
}
182183
obBtc.WithZetaClient(bridge)
183184
obBtc.WithLogger(chainLogger)
184-
obBtc.WithChain(*common.GetChainFromChainID(chainID))
185+
obBtc.WithChain(*chains.GetChainFromChainID(chainID))
185186
connCfg := &rpcclient.ConnConfig{
186187
Host: cfg.BitcoinConfig.RPCHost,
187188
User: cfg.BitcoinConfig.RPCUsername,

cmd/zetaclientd/hsm.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@ package main
33
import (
44
"fmt"
55

6+
sdk "github.com/cosmos/cosmos-sdk/types"
67
"github.com/pkg/errors"
78
"github.com/spf13/cobra"
89
keystone "github.com/zeta-chain/keystone/keys"
910
"github.com/zeta-chain/zetacore/cmd"
10-
"github.com/zeta-chain/zetacore/common/cosmos"
11+
"github.com/zeta-chain/zetacore/pkg/cosmos"
1112
"github.com/zeta-chain/zetacore/zetaclient/hsm"
1213
)
1314

@@ -63,7 +64,7 @@ func GetHsmAddress(_ *cobra.Command, _ []string) error {
6364
return err
6465
}
6566

66-
address, err := cosmos.Bech32ifyAddressBytes(cmd.Bech32PrefixAccAddr, pubKey.Address().Bytes())
67+
address, err := sdk.Bech32ifyAddressBytes(cmd.Bech32PrefixAccAddr, pubKey.Address().Bytes())
6768
if err != nil {
6869
return err
6970
}

cmd/zetaclientd/keygen_tss.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import (
1717
tsscommon "github.com/zeta-chain/go-tss/common"
1818
"github.com/zeta-chain/go-tss/keygen"
1919
"github.com/zeta-chain/go-tss/p2p"
20-
"github.com/zeta-chain/zetacore/common"
20+
"github.com/zeta-chain/zetacore/pkg/chains"
2121
observertypes "github.com/zeta-chain/zetacore/x/observer/types"
2222
"github.com/zeta-chain/zetacore/zetaclient/metrics"
2323
)
@@ -37,7 +37,7 @@ func GenerateTss(
3737
// Bitcoin chain ID is currently used for using the correct signature format
3838
// TODO: remove this once we have a better way to determine the signature format
3939
// https://github.com/zeta-chain/node/issues/1397
40-
bitcoinChainID := common.BtcRegtestChain().ChainId
40+
bitcoinChainID := chains.BtcRegtestChain().ChainId
4141
btcChain, _, btcEnabled := appContext.GetBTCChainAndConfig()
4242
if btcEnabled {
4343
bitcoinChainID = btcChain.ChainId
@@ -109,7 +109,7 @@ func GenerateTss(
109109
err = keygenTss(keyGen, tss, keygenLogger)
110110
if err != nil {
111111
keygenLogger.Error().Err(err).Msg("keygenTss error")
112-
tssFailedVoteHash, err := zetaBridge.SetTSS("", keyGen.BlockNumber, common.ReceiveStatus_Failed)
112+
tssFailedVoteHash, err := zetaBridge.SetTSS("", keyGen.BlockNumber, chains.ReceiveStatus_Failed)
113113
if err != nil {
114114
keygenLogger.Error().Err(err).Msg("Failed to broadcast Failed TSS Vote to zetacore")
115115
return nil, err
@@ -127,7 +127,7 @@ func GenerateTss(
127127
}
128128

129129
// If TSS is successful , broadcast the vote to zetacore and set Pubkey
130-
tssSuccessVoteHash, err := zetaBridge.SetTSS(newTss.CurrentPubkey, keyGen.BlockNumber, common.ReceiveStatus_Success)
130+
tssSuccessVoteHash, err := zetaBridge.SetTSS(newTss.CurrentPubkey, keyGen.BlockNumber, chains.ReceiveStatus_Success)
131131
if err != nil {
132132
keygenLogger.Error().Err(err).Msg("TSS successful but unable to broadcast vote to zeta-core")
133133
return nil, err

cmd/zetaclientd/main.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import (
1313
"github.com/zeta-chain/zetacore/zetaclient/config"
1414

1515
"github.com/zeta-chain/zetacore/cmd"
16-
"github.com/zeta-chain/zetacore/common/cosmos"
1716

1817
//mcconfig "github.com/Meta-Protocol/zetacore/metaclient/config"
1918
"github.com/cosmos/cosmos-sdk/types"
@@ -46,7 +45,7 @@ func main() {
4645
}
4746

4847
func SetupConfigForTest() {
49-
config := cosmos.GetConfig()
48+
config := types.GetConfig()
5049
config.SetBech32PrefixForAccount(cmd.Bech32PrefixAccAddr, cmd.Bech32PrefixAccPub)
5150
config.SetBech32PrefixForValidator(cmd.Bech32PrefixValAddr, cmd.Bech32PrefixValPub)
5251
config.SetBech32PrefixForConsensusNode(cmd.Bech32PrefixConsAddr, cmd.Bech32PrefixConsPub)

cmd/zetaclientd/p2p_diagnostics.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222
"github.com/rs/zerolog"
2323
"github.com/tendermint/tendermint/crypto/secp256k1"
2424
"github.com/zeta-chain/go-tss/p2p"
25-
"github.com/zeta-chain/zetacore/common/cosmos"
25+
"github.com/zeta-chain/zetacore/pkg/cosmos"
2626
"github.com/zeta-chain/zetacore/zetaclient/config"
2727
)
2828

cmd/zetaclientd/start.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ import (
2020
"github.com/spf13/cobra"
2121
"github.com/tendermint/tendermint/crypto/secp256k1"
2222
"github.com/zeta-chain/go-tss/p2p"
23-
"github.com/zeta-chain/zetacore/common"
23+
"github.com/zeta-chain/zetacore/pkg/authz"
24+
"github.com/zeta-chain/zetacore/pkg/constant"
2425
observerTypes "github.com/zeta-chain/zetacore/x/observer/types"
2526
mc "github.com/zeta-chain/zetacore/zetaclient"
2627
appcontext "github.com/zeta-chain/zetacore/zetaclient/app_context"
@@ -99,7 +100,7 @@ func start(_ *cobra.Command, _ []string) error {
99100
}
100101
zetaBridge.WaitForCoreToCreateBlocks()
101102
startLogger.Info().Msgf("ZetaBridge is ready")
102-
zetaBridge.SetAccountNumber(common.ZetaClientGranteeKey)
103+
zetaBridge.SetAccountNumber(authz.ZetaClientGranteeKey)
103104

104105
// cross-check chainid
105106
res, err := zetaBridge.GetNodeInfo()
@@ -169,7 +170,7 @@ func start(_ *cobra.Command, _ []string) error {
169170
}
170171
m.Start()
171172

172-
metrics.Info.WithLabelValues(common.Version).Set(1)
173+
metrics.Info.WithLabelValues(constant.Version).Set(1)
173174
metrics.LastStartTime.SetToCurrentTime()
174175

175176
var tssHistoricalList []observerTypes.TSS

cmd/zetaclientd/utils.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package main
33
import (
44
sdk "github.com/cosmos/cosmos-sdk/types"
55
ethcommon "github.com/ethereum/go-ethereum/common"
6-
"github.com/zeta-chain/zetacore/common/cosmos"
76
appcontext "github.com/zeta-chain/zetacore/zetaclient/app_context"
87
"github.com/zeta-chain/zetacore/zetaclient/authz"
98
"github.com/zeta-chain/zetacore/zetaclient/bitcoin"
@@ -34,7 +33,7 @@ func CreateZetaBridge(cfg config.Config, telemetry *metrics.TelemetryServer, hot
3433
return nil, err
3534
}
3635

37-
granterAddreess, err := cosmos.AccAddressFromBech32(cfg.AuthzGranter)
36+
granterAddreess, err := sdk.AccAddressFromBech32(cfg.AuthzGranter)
3837
if err != nil {
3938
return nil, err
4039
}

cmd/zetaclientd/version.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"fmt"
55

66
"github.com/spf13/cobra"
7-
"github.com/zeta-chain/zetacore/common"
7+
"github.com/zeta-chain/zetacore/pkg/constant"
88
)
99

1010
var VersionCmd = &cobra.Command{
@@ -14,6 +14,6 @@ var VersionCmd = &cobra.Command{
1414
}
1515

1616
func Version(_ *cobra.Command, _ []string) error {
17-
fmt.Printf(common.Version)
17+
fmt.Printf(constant.Version)
1818
return nil
1919
}

cmd/zetacored/get_pubkey.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import (
66
"github.com/cosmos/cosmos-sdk/client"
77
"github.com/cosmos/cosmos-sdk/crypto"
88
"github.com/spf13/cobra"
9-
"github.com/zeta-chain/zetacore/common"
10-
"github.com/zeta-chain/zetacore/common/cosmos"
9+
"github.com/zeta-chain/zetacore/pkg/cosmos"
10+
zetacrypto "github.com/zeta-chain/zetacore/pkg/crypto"
1111
)
1212

1313
func GetPubKeyCmd() *cobra.Command {
@@ -33,8 +33,8 @@ func GetPubKeyCmd() *cobra.Command {
3333
return cmd
3434
}
3535

36-
func GetPubKeySet(clientctx client.Context, tssAccountName, password string) (common.PubKeySet, error) {
37-
pubkeySet := common.PubKeySet{
36+
func GetPubKeySet(clientctx client.Context, tssAccountName, password string) (zetacrypto.PubKeySet, error) {
37+
pubkeySet := zetacrypto.PubKeySet{
3838
Secp256k1: "",
3939
Ed25519: "",
4040
}
@@ -52,7 +52,7 @@ func GetPubKeySet(clientctx client.Context, tssAccountName, password string) (co
5252
if err != nil {
5353
return pubkeySet, err
5454
}
55-
pubkey, err := common.NewPubKey(s)
55+
pubkey, err := zetacrypto.NewPubKey(s)
5656
if err != nil {
5757
return pubkeySet, err
5858
}

cmd/zetacored/observer_accounts.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import (
2323
"github.com/spf13/cobra"
2424
"github.com/zeta-chain/zetacore/app"
2525
"github.com/zeta-chain/zetacore/cmd/zetacored/config"
26-
"github.com/zeta-chain/zetacore/common"
26+
"github.com/zeta-chain/zetacore/pkg/crypto"
2727
crosschaintypes "github.com/zeta-chain/zetacore/x/crosschain/types"
2828
"github.com/zeta-chain/zetacore/x/observer/types"
2929
)
@@ -115,11 +115,11 @@ func AddObserverAccountsCmd() *cobra.Command {
115115

116116
observerSet.ObserverList = append(observerSet.ObserverList, info.ObserverAddress)
117117
if info.ZetaClientGranteePubKey != "" {
118-
pubkey, err := common.NewPubKey(info.ZetaClientGranteePubKey)
118+
pubkey, err := crypto.NewPubKey(info.ZetaClientGranteePubKey)
119119
if err != nil {
120120
panic(err)
121121
}
122-
pubkeySet := common.PubKeySet{
122+
pubkeySet := crypto.PubKeySet{
123123
Secp256k1: pubkey,
124124
Ed25519: "",
125125
}

cmd/zetatool/filterdeposit/btc.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313

1414
"github.com/spf13/cobra"
1515
"github.com/zeta-chain/zetacore/cmd/zetatool/config"
16-
"github.com/zeta-chain/zetacore/common"
16+
"github.com/zeta-chain/zetacore/pkg/constant"
1717
)
1818

1919
func NewBtcCmd() *cobra.Command {
@@ -162,7 +162,7 @@ func getHashList(cfg *config.Config, tssAddress string) ([]Deposit, error) {
162162
if err != nil {
163163
continue
164164
}
165-
if bytes.Equal(memoBytes, []byte(common.DonationMessage)) {
165+
if bytes.Equal(memoBytes, []byte(constant.DonationMessage)) {
166166
continue
167167
}
168168
} else {

cmd/zetatool/filterdeposit/evm.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import (
1818
"github.com/zeta-chain/protocol-contracts/pkg/contracts/evm/erc20custody.sol"
1919
"github.com/zeta-chain/protocol-contracts/pkg/contracts/evm/zetaconnector.non-eth.sol"
2020
"github.com/zeta-chain/zetacore/cmd/zetatool/config"
21-
zetacommon "github.com/zeta-chain/zetacore/common"
21+
"github.com/zeta-chain/zetacore/pkg/constant"
2222
)
2323

2424
const (
@@ -202,7 +202,7 @@ func getTSSDeposits(tssAddress string, startBlock uint64, endBlock uint64, apiKe
202202

203203
for _, tx := range txns {
204204
if tx.To == tssAddress {
205-
if strings.Compare(tx.Input, zetacommon.DonationMessage) == 0 {
205+
if strings.Compare(tx.Input, constant.DonationMessage) == 0 {
206206
continue // skip donation tx
207207
}
208208
if tx.TxReceiptStatus != "1" {

common/commands.go

-8
This file was deleted.

common/constant.go

-7
This file was deleted.

0 commit comments

Comments
 (0)