Skip to content

Commit

Permalink
"robust" chainID handling
Browse files Browse the repository at this point in the history
  • Loading branch information
archseer committed Nov 22, 2024
1 parent 36aa1f1 commit dec4508
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
26 changes: 20 additions & 6 deletions deployment/environment/memory/job_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,28 +190,42 @@ func (j JobClient) ListNodeChainConfigs(ctx context.Context, in *nodev1.ListNode
if err != nil {
return nil, err
}
chainID, err := chainsel.ChainIdFromSelector(selector)
if err != nil {
return nil, err
}

if family == chainsel.FamilyEVM {
// already handled above
continue
}

var chainID string

var ocrtype chaintype.ChainType
switch family {
case chainsel.FamilyEVM:
ocrtype = chaintype.EVM
cid, err := chainsel.ChainIdFromSelector(selector)
if err != nil {
return nil, err
}
chainID = strconv.Itoa(int(cid))
case chainsel.FamilySolana:
ocrtype = chaintype.Solana
cid, err := chainsel.SolanaChainIdFromSelector(selector)
if err != nil {
return nil, err
}
chainID = cid
case chainsel.FamilyStarknet:
ocrtype = chaintype.StarkNet
// TODO: support cid
case chainsel.FamilyCosmos:
ocrtype = chaintype.Cosmos
// TODO: support cid
case chainsel.FamilyAptos:
ocrtype = chaintype.Aptos
cid, err := chainsel.AptosChainIdFromSelector(selector)
if err != nil {
return nil, err
}
chainID = strconv.Itoa(int(cid))
default:
panic(fmt.Sprintf("Unsupported chain family %v", family))
}
Expand Down Expand Up @@ -244,7 +258,7 @@ func (j JobClient) ListNodeChainConfigs(ctx context.Context, in *nodev1.ListNode

chainConfigs = append(chainConfigs, &nodev1.ChainConfig{
Chain: &nodev1.Chain{
Id: strconv.Itoa(int(chainID)),
Id: chainID,
Type: ctype,
},
AccountAddress: "", // TODO: support AccountAddress
Expand Down
4 changes: 4 additions & 0 deletions deployment/environment/memory/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ func NewNode(
) *Node {
evmchains := make(map[uint64]EVMChain)
for _, chain := range chains {
// we're only mapping evm chains here
if family, err := chainsel.GetSelectorFamily(chain.Selector); err != nil || family != chainsel.FamilyEVM {
continue
}
evmChainID, err := chainsel.ChainIdFromSelector(chain.Selector)
if err != nil {
t.Fatal(err)
Expand Down

0 comments on commit dec4508

Please sign in to comment.