Skip to content

Commit

Permalink
refactor is EVM chain
Browse files Browse the repository at this point in the history
  • Loading branch information
lumtis committed Aug 30, 2024
1 parent 7b34d1d commit d68263f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
10 changes: 7 additions & 3 deletions pkg/chains/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func (chain Chain) EncodeAddress(b []byte) (string, error) {
}

func (chain Chain) IsEVMChain() bool {
return chain.Consensus == Consensus_ethereum
return chain.Vm == Vm_evm
}

func (chain Chain) IsBitcoinChain() bool {
Expand All @@ -109,11 +109,15 @@ func DecodeAddressFromChainID(chainID int64, addr string, additionalChains []Cha
}
}

// IsEVMChain returns true if the chain is an EVM chain or uses the ethereum consensus mechanism for block finality
// IsEVMChain returns true if the chain is an EVM chain
// additionalChains is a list of additional chains to search from
// in practice, it is used in the protocol to dynamically support new chains without doing an upgrade
func IsEVMChain(chainID int64, additionalChains []Chain) bool {
return ChainIDInChainList(chainID, ChainListByConsensus(Consensus_ethereum, additionalChains))
chain, found := GetChainFromChainID(chainID, additionalChains)
if !found {
return false
}
return chain.IsEVMChain()
}

// IsBitcoinChain returns true if the chain is a Bitcoin-based chain or uses the bitcoin consensus mechanism for block finality
Expand Down
4 changes: 2 additions & 2 deletions pkg/chains/chain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ func TestChain_IsEVMChain(t *testing.T) {
{"Goerli Testnet", chains.Goerli, true},
{"Sepolia Testnet", chains.Sepolia, true},
{"Non-EVM", chains.BitcoinMainnet, false},
{"Zeta Mainnet", chains.ZetaChainMainnet, false},
{"Zeta Mainnet", chains.ZetaChainMainnet, true},
}

for _, tt := range tests {
Expand Down Expand Up @@ -331,7 +331,7 @@ func TestIsEVMChain(t *testing.T) {
{"Goerli Testnet", chains.Goerli.ChainId, true},
{"Sepolia Testnet", chains.Sepolia.ChainId, true},
{"Non-EVM", chains.BitcoinMainnet.ChainId, false},
{"Zeta Mainnet", chains.ZetaChainMainnet.ChainId, false},
{"Zeta Mainnet", chains.ZetaChainMainnet.ChainId, true},
}

for _, tt := range tests {
Expand Down

0 comments on commit d68263f

Please sign in to comment.