Skip to content

Commit

Permalink
refactor chains
Browse files Browse the repository at this point in the history
  • Loading branch information
lumtis committed Nov 14, 2023
1 parent 4201324 commit b79304e
Show file tree
Hide file tree
Showing 9 changed files with 126 additions and 310 deletions.
21 changes: 3 additions & 18 deletions common/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,7 @@ import (
ethcommon "github.com/ethereum/go-ethereum/common"
)

var (
SigningAlgoSecp256k1 = SigninAlgo("secp256k1")
SigningAlgoEd25519 = SigninAlgo("ed25519")
)

// return the ChainName from a string
// ParseChainName returns the ChainName from a string
// if no such name exists, returns the empty chain name: ChainName_empty
func ParseChainName(chain string) ChainName {
c := ChainName_value[chain]
Expand All @@ -29,7 +24,7 @@ type SigninAlgo string
// Chains represent a slice of Chain
type Chains []Chain

// Equals compare two chain to see whether they represent the same chain
// IsEqual compare two chain to see whether they represent the same chain
func (chain Chain) IsEqual(c Chain) bool {
if chain.ChainName == c.ChainName && chain.ChainId == c.ChainId {
return true
Expand All @@ -44,7 +39,7 @@ func (chain Chain) IsExternalChain() bool {
return !chain.IsEqual(ZetaChain())
}

// bytes representations of address
// EncodeAddress bytes representations of address
// on EVM chain, it is 20Bytes
// on Bitcoin chain, it is P2WPKH address, []byte(bech32 encoded string)
func (chain Chain) EncodeAddress(b []byte) (string, error) {
Expand Down Expand Up @@ -168,16 +163,6 @@ func (chains Chains) Strings() []string {
return strings
}

func GetChainFromChainName(chainName ChainName) *Chain {
chains := DefaultChainsList()
for _, chain := range chains {
if chainName == chain.ChainName {
return chain
}
}
return nil
}

func GetChainFromChainID(chainID int64) *Chain {
chains := DefaultChainsList()
for _, chain := range chains {
Expand Down
40 changes: 0 additions & 40 deletions common/chain_network.go

This file was deleted.

18 changes: 0 additions & 18 deletions common/chain_network_test.go

This file was deleted.

92 changes: 71 additions & 21 deletions common/default_chains_mainnet.go → common/chains.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,6 @@
package common

func EthChain() Chain {
return Chain{
ChainName: ChainName_eth_mainnet,
ChainId: 1,
}
}

func BscMainnetChain() Chain {
return Chain{
ChainName: ChainName_bsc_mainnet,
ChainId: 56,
}
}
// Zeta chains

func ZetaChain() Chain {
return Chain{
Expand Down Expand Up @@ -42,19 +30,27 @@ func ZetaPrivnetChain() Chain {
}
}

func BtcMainnetChain() Chain {
// Mainnet chains

func EthChain() Chain {
return Chain{
ChainName: ChainName_btc_mainnet,
ChainId: 8332,
ChainName: ChainName_eth_mainnet,
ChainId: 1,
}
}

func BtcChainID() int64 {
return BtcMainnetChain().ChainId
func BscMainnetChain() Chain {
return Chain{
ChainName: ChainName_bsc_mainnet,
ChainId: 56,
}
}

func BtcDustOffset() int64 {
return 2000
func BtcMainnetChain() Chain {
return Chain{
ChainName: ChainName_btc_mainnet,
ChainId: 8332,
}
}

func PolygonChain() Chain {
Expand All @@ -64,25 +60,72 @@ func PolygonChain() Chain {
}
}

// Testnet chains

func GoerliChain() Chain {
return Chain{
ChainName: ChainName_goerli_testnet,
ChainId: 5,
}
}

func BscTestnetChain() Chain {
return Chain{
ChainName: ChainName_bsc_testnet,
ChainId: 97,
}
}

func BtcTestNetChain() Chain {
return Chain{
ChainName: ChainName_btc_testnet,
ChainId: 18332,
}
}

func MumbaiChain() Chain {
return Chain{
ChainName: ChainName_mumbai_testnet,
ChainId: 80001,
}
}

// Privnet chains

func BtcRegtestChain() Chain {
return Chain{
ChainName: ChainName_btc_regtest,
ChainId: 18444,
}
}

func GoerliChain() Chain {
func GoerliLocalnetChain() Chain {
return Chain{
ChainName: ChainName_goerli_localnet,
ChainId: 1337,
}
}

func BtcChainID() int64 {
return BtcRegtestChain().ChainId
}

func BtcDustOffset() int64 {
return 2000
}

// DefaultChainsList returns a list of default chains
func DefaultChainsList() []*Chain {
chains := []Chain{
BtcMainnetChain(),
BscMainnetChain(),
EthChain(),
BtcTestNetChain(),
MumbaiChain(),
BscTestnetChain(),
GoerliChain(),
BtcRegtestChain(),
GoerliLocalnetChain(),
ZetaChain(),
}
var c []*Chain
Expand All @@ -92,11 +135,18 @@ func DefaultChainsList() []*Chain {
return c
}

// ExternalChainList returns a list chains that are not Zeta
func ExternalChainList() []*Chain {
chains := []Chain{
BtcMainnetChain(),
BscMainnetChain(),
EthChain(),
BtcTestNetChain(),
MumbaiChain(),
BscTestnetChain(),
GoerliChain(),
BtcRegtestChain(),
GoerliLocalnetChain(),
}
var c []*Chain
for i := 0; i < len(chains); i++ {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
//go:build TESTNET
// +build TESTNET

package types

import (
Expand All @@ -13,6 +10,45 @@ import (
func GetCoreParams() CoreParamsList {
params := CoreParamsList{
CoreParams: []*CoreParams{
{
ChainId: common.EthChain().ChainId,
ConfirmationCount: 14,
ZetaTokenContractAddress: "",
ConnectorContractAddress: "",
Erc20CustodyContractAddress: "",
InTxTicker: 12,
OutTxTicker: 15,
WatchUtxoTicker: 0,
GasPriceTicker: 30,
OutboundTxScheduleInterval: 30,
OutboundTxScheduleLookahead: 60,
},
{
ChainId: common.BscMainnetChain().ChainId,
ConfirmationCount: 14,
ZetaTokenContractAddress: "",
ConnectorContractAddress: "",
Erc20CustodyContractAddress: "",
InTxTicker: 5,
OutTxTicker: 15,
WatchUtxoTicker: 0,
GasPriceTicker: 30,
OutboundTxScheduleInterval: 30,
OutboundTxScheduleLookahead: 60,
},
{
ChainId: common.BtcMainnetChain().ChainId,
ConfirmationCount: 2,
ZetaTokenContractAddress: "",
ConnectorContractAddress: "",
Erc20CustodyContractAddress: "",
WatchUtxoTicker: 30,
InTxTicker: 120,
OutTxTicker: 60,
GasPriceTicker: 30,
OutboundTxScheduleInterval: 30,
OutboundTxScheduleLookahead: 60,
},
{
ChainId: common.GoerliChain().ChainId,
ConfirmationCount: 6,
Expand Down Expand Up @@ -66,6 +102,19 @@ func GetCoreParams() CoreParamsList {
OutboundTxScheduleInterval: 30,
OutboundTxScheduleLookahead: 100,
},
{
ChainId: common.BtcRegtestChain().ChainId,
ConfirmationCount: 2,
ZetaTokenContractAddress: "",
ConnectorContractAddress: "",
Erc20CustodyContractAddress: "",
GasPriceTicker: 5,
WatchUtxoTicker: 1,
InTxTicker: 1,
OutTxTicker: 2,
OutboundTxScheduleInterval: 2,
OutboundTxScheduleLookahead: 5,
},
},
}
chainList := common.ExternalChainList()
Expand Down
69 changes: 0 additions & 69 deletions x/observer/types/core_params_mainnet.go

This file was deleted.

Loading

0 comments on commit b79304e

Please sign in to comment.