Skip to content

Commit

Permalink
Merge branch 'main' into badge-pkg-docs
Browse files Browse the repository at this point in the history
  • Loading branch information
jmank88 authored Nov 19, 2024
2 parents 861dfca + a7cb436 commit 859e596
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 0 deletions.
8 changes: 8 additions & 0 deletions aptos_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,11 @@ func Test_AptosGetChainDetailsByChainIDAndFamily(t *testing.T) {
assert.Equal(t, v, details)
}
}

func Test_AptosGetChainIDByChainSelector(t *testing.T) {
for k, v := range aptosSelectorsMap {
chainID, err := GetChainIDFromSelector(v.ChainSelector)
assert.NoError(t, err)
assert.Equal(t, chainID, fmt.Sprintf("%v", k))
}
}
9 changes: 9 additions & 0 deletions evm_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package chain_selectors

import (
"fmt"
"math/rand"
"strconv"
"testing"
Expand Down Expand Up @@ -235,3 +236,11 @@ func Test_EVMGetChainDetailsByChainIDAndFamily(t *testing.T) {
assert.Equal(t, v, details)
}
}

func Test_EVMGetChainIDByChainSelector(t *testing.T) {
for k, v := range evmSelectorsMap {
chainID, err := GetChainIDFromSelector(v.ChainSelector)
assert.NoError(t, err)
assert.Equal(t, chainID, fmt.Sprintf("%v", k))
}
}
4 changes: 4 additions & 0 deletions generated_chains_evm.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 33 additions & 0 deletions selectors.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,39 @@ func GetSelectorFamily(selector uint64) (string, error) {
return "", fmt.Errorf("unknown chain selector %d", selector)
}

func GetChainIDFromSelector(selector uint64) (string, error) {
destChainFamily, err := GetSelectorFamily(selector)
if err != nil {
return "", err
}

var id uint64
var destChainID string
switch destChainFamily {
case FamilyEVM:
id, err = ChainIdFromSelector(selector)
if err != nil {
return "", fmt.Errorf("failed to get %v chain ID from selector %d: %w", destChainFamily, selector, err)
}
destChainID = fmt.Sprintf("%d", id)
case FamilySolana:
destChainID, err = SolanaChainIdFromSelector(selector)
if err != nil {
return "", fmt.Errorf("failed to get %v chain ID from selector %d: %w", destChainFamily, selector, err)
}
case FamilyAptos:
id, err = AptosChainIdFromSelector(selector)
if err != nil {
return "", fmt.Errorf("failed to get %v chain ID from selector %d: %w", destChainFamily, selector, err)
}
destChainID = fmt.Sprintf("%d", id)
default:
return "", fmt.Errorf("selector %d is not supported", selector)
}

return destChainID, nil
}

func GetChainDetailsByChainIDAndFamily(chainID string, family string) (ChainDetails, error) {
switch family {
case FamilyEVM:
Expand Down
6 changes: 6 additions & 0 deletions selectors.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ selectors:
97:
selector: 13264668187771770619
name: "binance_smart_chain-testnet"
157:
selector: 17833296867764334567
name: "shibarium-testnet-puppynet"
111:
selector: 572210378683744374
name: "velas-testnet"
Expand Down Expand Up @@ -281,6 +284,9 @@ selectors:
106:
selector: 374210358663784372
name: "velas-mainnet"
109:
selector: 3993510008929295315
name: "shibarium-mainnet"
137:
selector: 4051577828743386545
name: "polygon-mainnet"
Expand Down
9 changes: 9 additions & 0 deletions solana_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package chain_selectors

import (
"fmt"
"math/rand"
"testing"

Expand Down Expand Up @@ -75,3 +76,11 @@ func Test_SolanaGetChainDetailsByChainIDAndFamily(t *testing.T) {
assert.Equal(t, v, details)
}
}

func Test_SolanaGetChainIDByChainSelector(t *testing.T) {
for k, v := range solanaSelectorsMap {
chainID, err := GetChainIDFromSelector(v.ChainSelector)
assert.NoError(t, err)
assert.Equal(t, chainID, fmt.Sprintf("%v", k))
}
}

0 comments on commit 859e596

Please sign in to comment.