mirror of
https://github.com/status-im/status-go.git
synced 2025-02-12 06:47:47 +00:00
fix_: add SetChainUserRpcProviders and SetChainEnabled API
This commit is contained in:
parent
29847c9501
commit
c01c901bc5
@ -30,6 +30,7 @@ type NetworksPersistenceInterface interface {
|
|||||||
DeleteAllNetworks() error
|
DeleteAllNetworks() error
|
||||||
|
|
||||||
GetRpcPersistence() RpcProvidersPersistenceInterface
|
GetRpcPersistence() RpcProvidersPersistenceInterface
|
||||||
|
SetEnabled(chainID uint64, enabled bool) error
|
||||||
}
|
}
|
||||||
|
|
||||||
// NetworksPersistence manages networks and their providers.
|
// NetworksPersistence manages networks and their providers.
|
||||||
@ -255,3 +256,22 @@ func (n *NetworksPersistence) DeleteNetwork(chainID uint64) error {
|
|||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetEnabled updates the enabled status of a network.
|
||||||
|
func (n *NetworksPersistence) SetEnabled(chainID uint64, enabled bool) error {
|
||||||
|
q := sq.Update("networks").
|
||||||
|
Set("enabled", enabled).
|
||||||
|
Where(sq.Eq{"chain_id": chainID})
|
||||||
|
|
||||||
|
query, args, err := q.ToSql()
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to build update query: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = n.db.Exec(query, args...)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to execute update query for chain_id %d: %w", chainID, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
@ -195,3 +195,28 @@ func (s *NetworksPersistenceTestSuite) TestValidationForNetworksAndProviders() {
|
|||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
s.Require().Len(allNetworks, 0, "No invalid networks should be saved")
|
s.Require().Len(allNetworks, 0, "No invalid networks should be saved")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *NetworksPersistenceTestSuite) TestSetEnabled() {
|
||||||
|
network := testutil.CreateNetwork(api.OptimismChainID, "Optimism Mainnet", DefaultProviders(api.OptimismChainID))
|
||||||
|
s.addAndVerifyNetworks([]*params.Network{network})
|
||||||
|
|
||||||
|
// Disable the network
|
||||||
|
err := s.networksPersistence.SetEnabled(network.ChainID, false)
|
||||||
|
s.Require().NoError(err)
|
||||||
|
|
||||||
|
// Verify the network is disabled
|
||||||
|
updatedNetwork, err := s.networksPersistence.GetNetworkByChainID(network.ChainID)
|
||||||
|
s.Require().NoError(err)
|
||||||
|
s.Require().Len(updatedNetwork, 1)
|
||||||
|
s.Require().False(updatedNetwork[0].Enabled)
|
||||||
|
|
||||||
|
// Enable the network
|
||||||
|
err = s.networksPersistence.SetEnabled(network.ChainID, true)
|
||||||
|
s.Require().NoError(err)
|
||||||
|
|
||||||
|
// Verify the network is enabled
|
||||||
|
updatedNetwork, err = s.networksPersistence.GetNetworkByChainID(network.ChainID)
|
||||||
|
s.Require().NoError(err)
|
||||||
|
s.Require().Len(updatedNetwork, 1)
|
||||||
|
s.Require().True(updatedNetwork[0].Enabled)
|
||||||
|
}
|
||||||
|
@ -36,6 +36,7 @@ type ManagerInterface interface {
|
|||||||
GetTestNetworksEnabled() (bool, error)
|
GetTestNetworksEnabled() (bool, error)
|
||||||
|
|
||||||
SetUserRpcProviders(chainID uint64, providers []params.RpcProvider) error
|
SetUserRpcProviders(chainID uint64, providers []params.RpcProvider) error
|
||||||
|
SetEnabled(chainID uint64, enabled bool) error
|
||||||
}
|
}
|
||||||
|
|
||||||
type Manager struct {
|
type Manager struct {
|
||||||
@ -174,6 +175,15 @@ func (nm *Manager) SetUserRpcProviders(chainID uint64, userProviders []params.Rp
|
|||||||
return rpcPersistence.SetRpcProviders(chainID, networkhelper.GetUserProviders(userProviders))
|
return rpcPersistence.SetRpcProviders(chainID, networkhelper.GetUserProviders(userProviders))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetEnabled updates the enabled status of a network
|
||||||
|
func (nm *Manager) SetEnabled(chainID uint64, enabled bool) error {
|
||||||
|
err := nm.networkPersistence.SetEnabled(chainID, enabled)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to set enabled status: %w", err)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// Find locates a network by ChainID.
|
// Find locates a network by ChainID.
|
||||||
func (nm *Manager) Find(chainID uint64) *params.Network {
|
func (nm *Manager) Find(chainID uint64) *params.Network {
|
||||||
networks, err := nm.networkPersistence.GetNetworkByChainID(chainID)
|
networks, err := nm.networkPersistence.GetNetworkByChainID(chainID)
|
||||||
|
@ -400,6 +400,16 @@ func (api *API) AddEthereumChain(ctx context.Context, network params.Network) er
|
|||||||
return api.s.rpcClient.NetworkManager.Upsert(&network)
|
return api.s.rpcClient.NetworkManager.Upsert(&network)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (api *API) SetChainUserRpcProviders(ctx context.Context, chainID uint64, rpcProviders []params.RpcProvider) error {
|
||||||
|
logutils.ZapLogger().Debug("call to SetChainUserRpcProviders")
|
||||||
|
return api.s.rpcClient.NetworkManager.SetUserRpcProviders(chainID, rpcProviders)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (api *API) SetChainEnabled(ctx context.Context, chainID uint64, enabled bool) error {
|
||||||
|
logutils.ZapLogger().Debug("call to SetChainEnabled")
|
||||||
|
return api.s.rpcClient.NetworkManager.SetEnabled(chainID, enabled)
|
||||||
|
}
|
||||||
|
|
||||||
func (api *API) DeleteEthereumChain(ctx context.Context, chainID uint64) error {
|
func (api *API) DeleteEthereumChain(ctx context.Context, chainID uint64) error {
|
||||||
logutils.ZapLogger().Debug("call to DeleteEthereumChain")
|
logutils.ZapLogger().Debug("call to DeleteEthereumChain")
|
||||||
return api.s.rpcClient.NetworkManager.Delete(chainID)
|
return api.s.rpcClient.NetworkManager.Delete(chainID)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user