-
Notifications
You must be signed in to change notification settings - Fork 244
/
value_handlers.go
65 lines (52 loc) · 1.41 KB
/
value_handlers.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
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 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
}