Skip to content

Commit

Permalink
refactor: replace common package with pkg (#1936)
Browse files Browse the repository at this point in the history
  • Loading branch information
skosito authored Mar 27, 2024
1 parent 2b77e0b commit f693378
Show file tree
Hide file tree
Showing 461 changed files with 3,938 additions and 3,562 deletions.
8 changes: 4 additions & 4 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ builds:
- -X github.com/cosmos/cosmos-sdk/version.ClientName=zetaclientd
- -X github.com/cosmos/cosmos-sdk/version.Version={{ .Version }}
- -X github.com/cosmos/cosmos-sdk/version.Commit={{ .Env.COMMIT }}
- -X github.com/zeta-chain/zetacore/common.Name=zetacored
- -X github.com/zeta-chain/zetacore/common.Version={{ .Version }}
- -X github.com/zeta-chain/zetacore/common.CommitHash={{ .Env.COMMIT }}
- -X github.com/zeta-chain/zetacore/common.BuildTime=={{ .Env.BUILDTIME }}
- -X github.com/zeta-chain/zetacore/pkg/constant.Name=zetacored
- -X github.com/zeta-chain/zetacore/pkg/constant.Version={{ .Version }}
- -X github.com/zeta-chain/zetacore/pkg/constant.CommitHash={{ .Env.COMMIT }}
- -X github.com/zeta-chain/zetacore/pkg/constant.BuildTime={{ .Env.BUILDTIME }}
- -X github.com/cosmos/cosmos-sdk/types.DBBackend=pebbledb

- id: "zetaclientd"
Expand Down
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ ldflags = -X github.com/cosmos/cosmos-sdk/version.Name=zetacore \
-X github.com/cosmos/cosmos-sdk/version.ClientName=zetaclientd \
-X github.com/cosmos/cosmos-sdk/version.Version=$(VERSION) \
-X github.com/cosmos/cosmos-sdk/version.Commit=$(COMMIT) \
-X github.com/zeta-chain/zetacore/common.Name=zetacored \
-X github.com/zeta-chain/zetacore/common.Version=$(VERSION) \
-X github.com/zeta-chain/zetacore/common.CommitHash=$(COMMIT) \
-X github.com/zeta-chain/zetacore/common.BuildTime=$(BUILDTIME) \
-X github.com/zeta-chain/zetacore/pkg/constant.Name=zetacored \
-X github.com/zeta-chain/zetacore/pkg/constant.Version=$(VERSION) \
-X github.com/zeta-chain/zetacore/pkg/constant.CommitHash=$(COMMIT) \
-X github.com/zeta-chain/zetacore/pkg/constant.BuildTime=$(BUILDTIME) \
-X github.com/cosmos/cosmos-sdk/types.DBBackend=pebbledb

BUILD_FLAGS := -ldflags '$(ldflags)' -tags pebbledb,ledger
Expand Down
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
* [1885](https://github.com/zeta-chain/node/pull/1885) - change important metrics on port 8123 to be prometheus compatible
* [1863](https://github.com/zeta-chain/node/pull/1863) - remove duplicate ValidateChainParams function
* [1914](https://github.com/zeta-chain/node/pull/1914) - move crosschain flags to core context in zetaclient
* [1936](https://github.com/zeta-chain/node/pull/1936) - refactor common package into subpackages and rename to pkg

### Features

Expand Down
27 changes: 14 additions & 13 deletions cmd/zetaclientd/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (

"github.com/ethereum/go-ethereum/ethclient"
"github.com/onrik/ethrpc"
"github.com/zeta-chain/zetacore/pkg/chains"
"github.com/zeta-chain/zetacore/pkg/coin"
"github.com/zeta-chain/zetacore/zetaclient/bitcoin"
corecontext "github.com/zeta-chain/zetacore/zetaclient/core_context"
"github.com/zeta-chain/zetacore/zetaclient/evm"
Expand All @@ -22,7 +24,6 @@ import (
ethcommon "github.com/ethereum/go-ethereum/common"
"github.com/rs/zerolog"
"github.com/spf13/cobra"
"github.com/zeta-chain/zetacore/common"
"github.com/zeta-chain/zetacore/testutil/sample"
observertypes "github.com/zeta-chain/zetacore/x/observer/types"
"github.com/zeta-chain/zetacore/zetaclient/config"
Expand Down Expand Up @@ -90,12 +91,12 @@ func DebugCmd() *cobra.Command {
return err
}

chain := common.GetChainFromChainID(chainID)
chain := chains.GetChainFromChainID(chainID)
if chain == nil {
return fmt.Errorf("invalid chain id")
}

if common.IsEVMChain(chain.ChainId) {
if chains.IsEVMChain(chain.ChainId) {

ob := evm.ChainClient{
Mu: &sync.Mutex{},
Expand All @@ -104,7 +105,7 @@ func DebugCmd() *cobra.Command {
ob.WithLogger(chainLogger)
var ethRPC *ethrpc.EthRPC
var client *ethclient.Client
coinType := common.CoinType_Cmd
coinType := coin.CoinType_Cmd
for chain, evmConfig := range cfg.GetAllEVMConfigs() {
if chainID == chain {
ethRPC = ethrpc.NewEthRPC(evmConfig.Endpoint)
Expand All @@ -114,7 +115,7 @@ func DebugCmd() *cobra.Command {
}
ob.WithEvmClient(client)
ob.WithEvmJSONRPC(ethRPC)
ob.WithChain(*common.GetChainFromChainID(chainID))
ob.WithChain(*chains.GetChainFromChainID(chainID))
}
}
hash := ethcommon.HexToHash(txHash)
Expand Down Expand Up @@ -144,29 +145,29 @@ func DebugCmd() *cobra.Command {
}
evmChainParams.ZetaTokenContractAddress = chainParams.ZetaTokenContractAddress
if strings.EqualFold(tx.To, chainParams.ConnectorContractAddress) {
coinType = common.CoinType_Zeta
coinType = coin.CoinType_Zeta
} else if strings.EqualFold(tx.To, chainParams.Erc20CustodyContractAddress) {
coinType = common.CoinType_ERC20
coinType = coin.CoinType_ERC20
} else if strings.EqualFold(tx.To, tssEthAddress) {
coinType = common.CoinType_Gas
coinType = coin.CoinType_Gas
}
}
}

switch coinType {
case common.CoinType_Zeta:
case coin.CoinType_Zeta:
ballotIdentifier, err = ob.CheckAndVoteInboundTokenZeta(tx, receipt, false)
if err != nil {
return err
}

case common.CoinType_ERC20:
case coin.CoinType_ERC20:
ballotIdentifier, err = ob.CheckAndVoteInboundTokenERC20(tx, receipt, false)
if err != nil {
return err
}

case common.CoinType_Gas:
case coin.CoinType_Gas:
ballotIdentifier, err = ob.CheckAndVoteInboundTokenGas(tx, receipt, false)
if err != nil {
return err
Expand All @@ -175,13 +176,13 @@ func DebugCmd() *cobra.Command {
fmt.Println("CoinType not detected")
}
fmt.Println("CoinType : ", coinType)
} else if common.IsBitcoinChain(chain.ChainId) {
} else if chains.IsBitcoinChain(chain.ChainId) {
obBtc := bitcoin.BTCChainClient{
Mu: &sync.Mutex{},
}
obBtc.WithZetaClient(bridge)
obBtc.WithLogger(chainLogger)
obBtc.WithChain(*common.GetChainFromChainID(chainID))
obBtc.WithChain(*chains.GetChainFromChainID(chainID))
connCfg := &rpcclient.ConnConfig{
Host: cfg.BitcoinConfig.RPCHost,
User: cfg.BitcoinConfig.RPCUsername,
Expand Down
5 changes: 3 additions & 2 deletions cmd/zetaclientd/hsm.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ package main
import (
"fmt"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/pkg/errors"
"github.com/spf13/cobra"
keystone "github.com/zeta-chain/keystone/keys"
"github.com/zeta-chain/zetacore/cmd"
"github.com/zeta-chain/zetacore/common/cosmos"
"github.com/zeta-chain/zetacore/pkg/cosmos"
"github.com/zeta-chain/zetacore/zetaclient/hsm"
)

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

address, err := cosmos.Bech32ifyAddressBytes(cmd.Bech32PrefixAccAddr, pubKey.Address().Bytes())
address, err := sdk.Bech32ifyAddressBytes(cmd.Bech32PrefixAccAddr, pubKey.Address().Bytes())
if err != nil {
return err
}
Expand Down
8 changes: 4 additions & 4 deletions cmd/zetaclientd/keygen_tss.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
tsscommon "github.com/zeta-chain/go-tss/common"
"github.com/zeta-chain/go-tss/keygen"
"github.com/zeta-chain/go-tss/p2p"
"github.com/zeta-chain/zetacore/common"
"github.com/zeta-chain/zetacore/pkg/chains"
observertypes "github.com/zeta-chain/zetacore/x/observer/types"
"github.com/zeta-chain/zetacore/zetaclient/metrics"
)
Expand All @@ -37,7 +37,7 @@ func GenerateTss(
// Bitcoin chain ID is currently used for using the correct signature format
// TODO: remove this once we have a better way to determine the signature format
// https://github.com/zeta-chain/node/issues/1397
bitcoinChainID := common.BtcRegtestChain().ChainId
bitcoinChainID := chains.BtcRegtestChain().ChainId
btcChain, _, btcEnabled := appContext.GetBTCChainAndConfig()
if btcEnabled {
bitcoinChainID = btcChain.ChainId
Expand Down Expand Up @@ -109,7 +109,7 @@ func GenerateTss(
err = keygenTss(keyGen, tss, keygenLogger)
if err != nil {
keygenLogger.Error().Err(err).Msg("keygenTss error")
tssFailedVoteHash, err := zetaBridge.SetTSS("", keyGen.BlockNumber, common.ReceiveStatus_Failed)
tssFailedVoteHash, err := zetaBridge.SetTSS("", keyGen.BlockNumber, chains.ReceiveStatus_Failed)
if err != nil {
keygenLogger.Error().Err(err).Msg("Failed to broadcast Failed TSS Vote to zetacore")
return nil, err
Expand All @@ -127,7 +127,7 @@ func GenerateTss(
}

// If TSS is successful , broadcast the vote to zetacore and set Pubkey
tssSuccessVoteHash, err := zetaBridge.SetTSS(newTss.CurrentPubkey, keyGen.BlockNumber, common.ReceiveStatus_Success)
tssSuccessVoteHash, err := zetaBridge.SetTSS(newTss.CurrentPubkey, keyGen.BlockNumber, chains.ReceiveStatus_Success)
if err != nil {
keygenLogger.Error().Err(err).Msg("TSS successful but unable to broadcast vote to zeta-core")
return nil, err
Expand Down
3 changes: 1 addition & 2 deletions cmd/zetaclientd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"github.com/zeta-chain/zetacore/zetaclient/config"

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

//mcconfig "github.com/Meta-Protocol/zetacore/metaclient/config"
"github.com/cosmos/cosmos-sdk/types"
Expand Down Expand Up @@ -46,7 +45,7 @@ func main() {
}

func SetupConfigForTest() {
config := cosmos.GetConfig()
config := types.GetConfig()
config.SetBech32PrefixForAccount(cmd.Bech32PrefixAccAddr, cmd.Bech32PrefixAccPub)
config.SetBech32PrefixForValidator(cmd.Bech32PrefixValAddr, cmd.Bech32PrefixValPub)
config.SetBech32PrefixForConsensusNode(cmd.Bech32PrefixConsAddr, cmd.Bech32PrefixConsPub)
Expand Down
2 changes: 1 addition & 1 deletion cmd/zetaclientd/p2p_diagnostics.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"github.com/rs/zerolog"
"github.com/tendermint/tendermint/crypto/secp256k1"
"github.com/zeta-chain/go-tss/p2p"
"github.com/zeta-chain/zetacore/common/cosmos"
"github.com/zeta-chain/zetacore/pkg/cosmos"
"github.com/zeta-chain/zetacore/zetaclient/config"
)

Expand Down
7 changes: 4 additions & 3 deletions cmd/zetaclientd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ import (
"github.com/spf13/cobra"
"github.com/tendermint/tendermint/crypto/secp256k1"
"github.com/zeta-chain/go-tss/p2p"
"github.com/zeta-chain/zetacore/common"
"github.com/zeta-chain/zetacore/pkg/authz"
"github.com/zeta-chain/zetacore/pkg/constant"
observerTypes "github.com/zeta-chain/zetacore/x/observer/types"
mc "github.com/zeta-chain/zetacore/zetaclient"
appcontext "github.com/zeta-chain/zetacore/zetaclient/app_context"
Expand Down Expand Up @@ -99,7 +100,7 @@ func start(_ *cobra.Command, _ []string) error {
}
zetaBridge.WaitForCoreToCreateBlocks()
startLogger.Info().Msgf("ZetaBridge is ready")
zetaBridge.SetAccountNumber(common.ZetaClientGranteeKey)
zetaBridge.SetAccountNumber(authz.ZetaClientGranteeKey)

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

metrics.Info.WithLabelValues(common.Version).Set(1)
metrics.Info.WithLabelValues(constant.Version).Set(1)
metrics.LastStartTime.SetToCurrentTime()

var tssHistoricalList []observerTypes.TSS
Expand Down
3 changes: 1 addition & 2 deletions cmd/zetaclientd/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package main
import (
sdk "github.com/cosmos/cosmos-sdk/types"
ethcommon "github.com/ethereum/go-ethereum/common"
"github.com/zeta-chain/zetacore/common/cosmos"
appcontext "github.com/zeta-chain/zetacore/zetaclient/app_context"
"github.com/zeta-chain/zetacore/zetaclient/authz"
"github.com/zeta-chain/zetacore/zetaclient/bitcoin"
Expand Down Expand Up @@ -34,7 +33,7 @@ func CreateZetaBridge(cfg config.Config, telemetry *metrics.TelemetryServer, hot
return nil, err
}

granterAddreess, err := cosmos.AccAddressFromBech32(cfg.AuthzGranter)
granterAddreess, err := sdk.AccAddressFromBech32(cfg.AuthzGranter)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/zetaclientd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"

"github.com/spf13/cobra"
"github.com/zeta-chain/zetacore/common"
"github.com/zeta-chain/zetacore/pkg/constant"
)

var VersionCmd = &cobra.Command{
Expand All @@ -14,6 +14,6 @@ var VersionCmd = &cobra.Command{
}

func Version(_ *cobra.Command, _ []string) error {
fmt.Printf(common.Version)
fmt.Printf(constant.Version)
return nil
}
10 changes: 5 additions & 5 deletions cmd/zetacored/get_pubkey.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/crypto"
"github.com/spf13/cobra"
"github.com/zeta-chain/zetacore/common"
"github.com/zeta-chain/zetacore/common/cosmos"
"github.com/zeta-chain/zetacore/pkg/cosmos"
zetacrypto "github.com/zeta-chain/zetacore/pkg/crypto"
)

func GetPubKeyCmd() *cobra.Command {
Expand All @@ -33,8 +33,8 @@ func GetPubKeyCmd() *cobra.Command {
return cmd
}

func GetPubKeySet(clientctx client.Context, tssAccountName, password string) (common.PubKeySet, error) {
pubkeySet := common.PubKeySet{
func GetPubKeySet(clientctx client.Context, tssAccountName, password string) (zetacrypto.PubKeySet, error) {
pubkeySet := zetacrypto.PubKeySet{
Secp256k1: "",
Ed25519: "",
}
Expand All @@ -52,7 +52,7 @@ func GetPubKeySet(clientctx client.Context, tssAccountName, password string) (co
if err != nil {
return pubkeySet, err
}
pubkey, err := common.NewPubKey(s)
pubkey, err := zetacrypto.NewPubKey(s)
if err != nil {
return pubkeySet, err
}
Expand Down
6 changes: 3 additions & 3 deletions cmd/zetacored/observer_accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"github.com/spf13/cobra"
"github.com/zeta-chain/zetacore/app"
"github.com/zeta-chain/zetacore/cmd/zetacored/config"
"github.com/zeta-chain/zetacore/common"
"github.com/zeta-chain/zetacore/pkg/crypto"
crosschaintypes "github.com/zeta-chain/zetacore/x/crosschain/types"
"github.com/zeta-chain/zetacore/x/observer/types"
)
Expand Down Expand Up @@ -115,11 +115,11 @@ func AddObserverAccountsCmd() *cobra.Command {

observerSet.ObserverList = append(observerSet.ObserverList, info.ObserverAddress)
if info.ZetaClientGranteePubKey != "" {
pubkey, err := common.NewPubKey(info.ZetaClientGranteePubKey)
pubkey, err := crypto.NewPubKey(info.ZetaClientGranteePubKey)
if err != nil {
panic(err)
}
pubkeySet := common.PubKeySet{
pubkeySet := crypto.PubKeySet{
Secp256k1: pubkey,
Ed25519: "",
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/zetatool/filterdeposit/btc.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (

"github.com/spf13/cobra"
"github.com/zeta-chain/zetacore/cmd/zetatool/config"
"github.com/zeta-chain/zetacore/common"
"github.com/zeta-chain/zetacore/pkg/constant"
)

func NewBtcCmd() *cobra.Command {
Expand Down Expand Up @@ -162,7 +162,7 @@ func getHashList(cfg *config.Config, tssAddress string) ([]Deposit, error) {
if err != nil {
continue
}
if bytes.Equal(memoBytes, []byte(common.DonationMessage)) {
if bytes.Equal(memoBytes, []byte(constant.DonationMessage)) {
continue
}
} else {
Expand Down
4 changes: 2 additions & 2 deletions cmd/zetatool/filterdeposit/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"github.com/zeta-chain/protocol-contracts/pkg/contracts/evm/erc20custody.sol"
"github.com/zeta-chain/protocol-contracts/pkg/contracts/evm/zetaconnector.non-eth.sol"
"github.com/zeta-chain/zetacore/cmd/zetatool/config"
zetacommon "github.com/zeta-chain/zetacore/common"
"github.com/zeta-chain/zetacore/pkg/constant"
)

const (
Expand Down Expand Up @@ -202,7 +202,7 @@ func getTSSDeposits(tssAddress string, startBlock uint64, endBlock uint64, apiKe

for _, tx := range txns {
if tx.To == tssAddress {
if strings.Compare(tx.Input, zetacommon.DonationMessage) == 0 {
if strings.Compare(tx.Input, constant.DonationMessage) == 0 {
continue // skip donation tx
}
if tx.TxReceiptStatus != "1" {
Expand Down
8 changes: 0 additions & 8 deletions common/commands.go

This file was deleted.

7 changes: 0 additions & 7 deletions common/constant.go

This file was deleted.

Loading

0 comments on commit f693378

Please sign in to comment.