status-go/multiaccounts/settings/value_handlers.go

84 lines
1.8 KiB
Go
Raw Normal View History

Sync Settings (#2478) * Sync Settings * Added valueHandlers and Database singleton Some issues remain, need a way to comparing incoming sql.DB to check if the connection is to a different file or not. Maybe make singleton instance per filename * Added functionality to check the sqlite filename * Refactor of Database.SaveSyncSettings to be used as a handler * Implemented inteface for setting sync protobuf factories * Refactored and completed adhoc send setting sync * Tidying up * Immutability refactor * Refactor settings into dedicated package * Breakout structs * Tidy up * Refactor of bulk settings sync * Bug fixes * Addressing feedback * Fix code dropped during rebase * Fix for db closed * Fix for node config related crashes * Provisional fix for type assertion - issue 2 * Adding robust type assertion checks * Partial fix for null literal db storage and json encoding * Fix for passively handling nil sql.DB, and checking if elem has len and if len is 0 * Added test for preferred name behaviour * Adding saved sync settings to MessengerResponse * Completed granular initial sync and clock from network on save * add Settings to isEmpty * Refactor of protobufs, partially done * Added syncSetting receiver handling, some bug fixes * Fix for sticker packs * Implement inactive flag on sync protobuf factory * Refactor of types and structs * Added SettingField.CanSync functionality * Addressing rebase artifact * Refactor of Setting SELECT queries * Refactor of string return queries * VERSION bump and migration index bump * Deactiveate Sync Settings * Deactiveated preferred_name and send_status_updates Co-authored-by: Andrea Maria Piana <andrea.maria.piana@gmail.com>
2022-03-23 18:47:00 +00:00
package settings
import (
"encoding/json"
"github.com/status-im/status-go/eth-node/types"
"github.com/status-im/status-go/multiaccounts/errors"
"github.com/status-im/status-go/params"
"github.com/status-im/status-go/protocol/protobuf"
"github.com/status-im/status-go/sqlite"
)
func StringFromSyncProtobuf(ss *protobuf.SyncSetting) interface{} {
return ss.GetValueString()
}
func BoolFromSyncProtobuf(ss *protobuf.SyncSetting) interface{} {
return ss.GetValueBool()
}
func BytesFromSyncProtobuf(ss *protobuf.SyncSetting) interface{} {
return ss.GetValueBytes()
}
func Int64FromSyncProtobuf(ss *protobuf.SyncSetting) interface{} {
return ss.GetValueInt64()
}
func BoolHandler(value interface{}) (interface{}, error) {
_, ok := value.(bool)
if !ok {
return value, errors.ErrInvalidConfig
}
return value, nil
}
func Int64Handler(value interface{}) (interface{}, error) {
_, ok := value.(int64)
if !ok {
return value, errors.ErrInvalidConfig
}
return value, nil
}
Sync Settings (#2478) * Sync Settings * Added valueHandlers and Database singleton Some issues remain, need a way to comparing incoming sql.DB to check if the connection is to a different file or not. Maybe make singleton instance per filename * Added functionality to check the sqlite filename * Refactor of Database.SaveSyncSettings to be used as a handler * Implemented inteface for setting sync protobuf factories * Refactored and completed adhoc send setting sync * Tidying up * Immutability refactor * Refactor settings into dedicated package * Breakout structs * Tidy up * Refactor of bulk settings sync * Bug fixes * Addressing feedback * Fix code dropped during rebase * Fix for db closed * Fix for node config related crashes * Provisional fix for type assertion - issue 2 * Adding robust type assertion checks * Partial fix for null literal db storage and json encoding * Fix for passively handling nil sql.DB, and checking if elem has len and if len is 0 * Added test for preferred name behaviour * Adding saved sync settings to MessengerResponse * Completed granular initial sync and clock from network on save * add Settings to isEmpty * Refactor of protobufs, partially done * Added syncSetting receiver handling, some bug fixes * Fix for sticker packs * Implement inactive flag on sync protobuf factory * Refactor of types and structs * Added SettingField.CanSync functionality * Addressing rebase artifact * Refactor of Setting SELECT queries * Refactor of string return queries * VERSION bump and migration index bump * Deactiveate Sync Settings * Deactiveated preferred_name and send_status_updates Co-authored-by: Andrea Maria Piana <andrea.maria.piana@gmail.com>
2022-03-23 18:47:00 +00:00
func JSONBlobHandler(value interface{}) (interface{}, error) {
return &sqlite.JSONBlob{Data: value}, nil
}
func AddressHandler(value interface{}) (interface{}, error) {
str, ok := value.(string)
if ok {
value = types.HexToAddress(str)
} else {
return value, errors.ErrInvalidConfig
}
return value, nil
}
func NodeConfigHandler(value interface{}) (interface{}, error) {
jsonString, err := json.Marshal(value)
if err != nil {
return nil, err
}
nodeConfig := new(params.NodeConfig)
err = json.Unmarshal(jsonString, nodeConfig)
if err != nil {
return nil, err
}
return nodeConfig, nil
}
2024-02-19 12:09:02 +00:00
func Float64ToInt64Handler(value interface{}) (interface{}, error) {
floatValue, ok := value.(float64)
if !ok {
// Ignore if not float64
return value, nil
}
return int64(floatValue), nil
}