2019-08-20 18:38:40 +03:00
|
|
|
package accounts
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
"github.com/status-im/status-go/multiaccounts/accounts"
|
2022-03-23 18:47:00 +00:00
|
|
|
"github.com/status-im/status-go/multiaccounts/settings"
|
2022-01-12 20:04:43 +00:00
|
|
|
"github.com/status-im/status-go/nodecfg"
|
|
|
|
"github.com/status-im/status-go/params"
|
2019-08-20 18:38:40 +03:00
|
|
|
)
|
|
|
|
|
2022-02-27 10:46:17 -04:00
|
|
|
func NewSettingsAPI(db *accounts.Database, config *params.NodeConfig) *SettingsAPI {
|
|
|
|
return &SettingsAPI{db, config}
|
2019-08-20 18:38:40 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// SettingsAPI is class with methods available over RPC.
|
|
|
|
type SettingsAPI struct {
|
2022-02-27 10:46:17 -04:00
|
|
|
db *accounts.Database
|
|
|
|
config *params.NodeConfig
|
2019-08-20 18:38:40 +03:00
|
|
|
}
|
|
|
|
|
2019-12-27 10:58:25 +01:00
|
|
|
func (api *SettingsAPI) SaveSetting(ctx context.Context, typ string, val interface{}) error {
|
2020-09-16 10:31:01 +03:00
|
|
|
// NOTE(Ferossgp): v0.62.0 Backward compatibility, skip this for older clients instead of returning error
|
|
|
|
if typ == "waku-enabled" {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2019-12-27 10:58:25 +01:00
|
|
|
return api.db.SaveSetting(typ, val)
|
2019-08-20 18:38:40 +03:00
|
|
|
}
|
|
|
|
|
2022-03-23 18:47:00 +00:00
|
|
|
func (api *SettingsAPI) GetSettings(ctx context.Context) (settings.Settings, error) {
|
2019-12-27 10:58:25 +01:00
|
|
|
return api.db.GetSettings()
|
2019-08-20 18:38:40 +03:00
|
|
|
}
|
2022-01-12 20:04:43 +00:00
|
|
|
|
2022-02-27 10:46:17 -04:00
|
|
|
// NodeConfig returns the currently used node configuration
|
2022-01-12 20:04:43 +00:00
|
|
|
func (api *SettingsAPI) NodeConfig(ctx context.Context) (*params.NodeConfig, error) {
|
2022-02-27 10:46:17 -04:00
|
|
|
return api.config, nil
|
2022-01-12 20:04:43 +00:00
|
|
|
}
|
|
|
|
|
2022-02-27 10:46:17 -04:00
|
|
|
// Saves the nodeconfig in the database. The node must be restarted for the changes to be applied
|
2022-01-12 20:04:43 +00:00
|
|
|
func (api *SettingsAPI) SaveNodeConfig(ctx context.Context, n *params.NodeConfig) error {
|
|
|
|
return nodecfg.SaveNodeConfig(api.db.DB(), n)
|
|
|
|
}
|