Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(config)_: integrate new rpc providers configs #6178

Merged
merged 20 commits into from
Jan 31, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix(test)_: fix nested sql requests deadlock
friofry committed Jan 31, 2025

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit b66339f15e6e8958da4de8df9cd4fd7da5d15709
42 changes: 29 additions & 13 deletions rpc/network/db/network_db.go
Original file line number Diff line number Diff line change
@@ -54,8 +54,8 @@ func (n *NetworksPersistence) GetRpcPersistence() RpcProvidersPersistenceInterfa
return n.rpcPersistence
}

// GetNetworks returns networks based on filters.
func (n *NetworksPersistence) GetNetworks(onlyEnabled bool, chainID *uint64) ([]*params.Network, error) {
// getNetworksWithoutProviders returns networks based on filters without populating providers.
func (n *NetworksPersistence) getNetworksWithoutProviders(onlyEnabled bool, chainID *uint64) ([]*params.Network, error) {
q := sq.Select(
"chain_id", "chain_name", "rpc_url", "fallback_url",
"block_explorer_url", "icon_url", "native_currency_name", "native_currency_symbol", "native_currency_decimals",
@@ -80,7 +80,6 @@ func (n *NetworksPersistence) GetNetworks(onlyEnabled bool, chainID *uint64) ([]
if err != nil {
return nil, err
}
defer rows.Close()

result := make([]*params.Network, 0, 10)
for rows.Next() {
@@ -94,25 +93,42 @@ func (n *NetworksPersistence) GetNetworks(onlyEnabled bool, chainID *uint64) ([]
if err != nil {
return nil, err
}
result = append(result, network)
}

if err = rows.Err(); err != nil {
return nil, err
}
rows.Close()

return result, nil
}

// Fetch RPC providers for the network
providers, err := n.rpcPersistence.GetRpcProviders(network.ChainID)
// populateNetworkProviders populates RPC providers for the given networks.
func (n *NetworksPersistence) populateNetworkProviders(networks []*params.Network) error {
for i := range networks {
providers, err := n.rpcPersistence.GetRpcProviders(networks[i].ChainID)
if err != nil {
return nil, fmt.Errorf("failed to fetch RPC providers for chain_id %d: %w", network.ChainID, err)
return fmt.Errorf("failed to fetch RPC providers for chain_id %d: %w", networks[i].ChainID, err)
}
network.RpcProviders = providers

// Fill deprecated URLs if necessary (assuming this is a function you have)
FillDeprecatedURLs(network, providers)
networks[i].RpcProviders = providers
FillDeprecatedURLs(networks[i], providers)
}
return nil
}

result = append(result, network)
// GetNetworks returns networks based on filters.
func (n *NetworksPersistence) GetNetworks(onlyEnabled bool, chainID *uint64) ([]*params.Network, error) {
networks, err := n.getNetworksWithoutProviders(onlyEnabled, chainID)
if err != nil {
return nil, err
}

if err = rows.Err(); err != nil {
if err := n.populateNetworkProviders(networks); err != nil {
return nil, err
}

return result, nil
return networks, nil
}

// GetAllNetworks returns all networks.