From 3f56c13e95aaad3967657e7a8a6f3b736bc4d9d0 Mon Sep 17 00:00:00 2001 From: Tanmay Date: Wed, 24 Apr 2024 00:24:07 -0400 Subject: [PATCH] add comments --- pkg/chains/chain.go | 39 +++++++++++++++++---------------------- pkg/chains/chains.go | 15 +++++++++++++++ 2 files changed, 32 insertions(+), 22 deletions(-) diff --git a/pkg/chains/chain.go b/pkg/chains/chain.go index 0eebe1f7c9..7f876ec2b7 100644 --- a/pkg/chains/chain.go +++ b/pkg/chains/chain.go @@ -81,20 +81,29 @@ 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 @@ -102,20 +111,6 @@ 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()) == "" diff --git a/pkg/chains/chains.go b/pkg/chains/chains.go index f3c3c9a47f..179fbe24c4 100644 --- a/pkg/chains/chains.go +++ b/pkg/chains/chains.go @@ -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{