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
|
|
|
|
}
|
|
|
|
|
2024-01-05 11:12:53 +00:00
|
|
|
func Int64Handler(value interface{}) (interface{}, error) {
|
|
|
|
_, ok := value.(int64)
|
|
|
|
if !ok {
|
|
|
|
return value, errors.ErrInvalidConfig
|
|
|
|
}
|
|
|
|
|
|
|
|
return value, nil
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
}
|