Skip to content

Commit

Permalink
add comments
Browse files Browse the repository at this point in the history
  • Loading branch information
kingpinXD committed Apr 24, 2024
1 parent 27ba5cb commit 3f56c13
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 22 deletions.
39 changes: 17 additions & 22 deletions pkg/chains/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,41 +81,36 @@ func DecodeAddressFromChainID(chainID int64, addr string) ([]byte, error) {
return nil, fmt.Errorf("chain (%d) not supported", chainID)
}

func IsZetaChain(chainID int64) bool {
return ChainIDInChainList(chainID, ChainListByNetwork(Network_ZETA))
// IsEVMChain returns true if the chain is an EVM chain or uses the ethereum consensus mechanism for block finality
func IsEVMChain(chainID int64) bool {
return ChainIDInChainList(chainID, ChainListByConsensus(Consensus_Ethereum))
}

// IsEVMChain returns true if the chain is an EVM chain
func IsEVMChain(chainID int64) bool {
evmChainList := ChainListByConsensus(Consensus_Ethereum)
return ChainIDInChainList(chainID, evmChainList)
// IsBitcoinChain returns true if the chain is a Bitcoin-based chain or uses the bitcoin consensus mechanism for block finality
func IsBitcoinChain(chainID int64) bool {
return ChainIDInChainList(chainID, ChainListByConsensus(Consensus_Bitcoin))
}

// IsEthereumChain returns true if the chain is an Ethereum chain
func IsEthereumChain(chainID int64) bool {
return ChainIDInChainList(chainID, ChainListByNetwork(Network_ETH))
}

// IsZetaChain returns true if the chain is a Zeta chain
func IsZetaChain(chainID int64) bool {
return ChainIDInChainList(chainID, ChainListByNetwork(Network_ZETA))
}

// IsHeaderSupportedEvmChain returns true if the chain is an EVM chain supporting block header-based verification
func IsHeaderSupportedEvmChain(chainID int64) bool {
chainList := ChainListForHeaderSupport()
return ChainIDInChainList(chainID, chainList)
return ChainIDInChainList(chainID, ChainListForHeaderSupport())
}

// SupportMerkleProof returns true if the chain supports block header-based verification
func (chain Chain) SupportMerkleProof() bool {
return IsEVMChain(chain.ChainId) || IsBitcoinChain(chain.ChainId)
}

// IsBitcoinChain returns true if the chain is a Bitcoin chain
// TODO: put this information directly in chain object
// https://github.com/zeta-chain/node-private/issues/63
func IsBitcoinChain(chainID int64) bool {
btcChainList := ChainListByNetwork(Network_BTC)
return ChainIDInChainList(chainID, btcChainList)
}

// IsEthereumChain returns true if the chain is an Ethereum chain
func IsEthereumChain(chainID int64) bool {
ethChainList := ChainListByNetwork(Network_ETH)
return ChainIDInChainList(chainID, ethChainList)
}

// IsEmpty is to determinate whether the chain is empty
func (chain Chain) IsEmpty() bool {
return strings.TrimSpace(chain.String()) == ""
Expand Down
15 changes: 15 additions & 0 deletions pkg/chains/chains.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,21 @@ package chains

import "fmt"

/*
Chain represents a blockchain network with its unique chain ID
ChainName is the name of the chain
ChainId is the unique identifier of the chain
Network is the network type of the chain , this can be ZETA, ETH, BSC, BTC, POLYGON
NetworkType is the network type of the chain, this can be MAINNET, TESTNET, DEVNET, PRIVNET
Vm is the virtual machine type of the chain to support smart contracts, this can be EVM, NO_VM
Consensus is the consensus algorithm used by the chain, this can be Tendermint, Ethereum, Bitcoin
IsExternal is a boolean value to determine if the chain is external to Zeta
IsHeaderSupported is a boolean value to determine if the chain supports headers
Note ChainName is normally NetworkName + NetworkType,but in some cases the value of NetworkName + NetworkType is not unique.This is true for chains which have been deprecated or have been renamed.
Such as GoerliChain and MumbaiChain which have been replaced by SepoliaChain and AmoyChain respectively.
*/

// Mainnet chains
func ZetaChainMainnet() Chain {
return Chain{
Expand Down

0 comments on commit 3f56c13

Please sign in to comment.