forked from mercuryoio/tonlib-go
-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathutils.go
79 lines (70 loc) · 1.94 KB
/
utils.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package tonlib
import (
"encoding/json"
"io/ioutil"
"os"
)
type TonlibConfigServer struct {
Liteservers []TonlibListenserverConfig `json:"liteservers"`
Validator ValidatorConfig `json:"validator"`
}
type TonlibListenserverConfig struct {
Type string `json:"@type"`
Ip int64 `json:"ip"`
Port string `json:"port"`
ID map[string]string `json:"id"`
}
type ValidatorConfig struct {
Type string `json:"@type"`
ZeroState InitBlock `json:"zero_state"`
InitBlock InitBlock `json:"init_block,omitempty"`
Hardforks []InitBlock `json:"hardforks,omitempty"`
}
type InitBlock struct {
Workchain int `json:"workchain"`
Shard int64 `json:"shard"`
Seqno int `json:"seqno"`
RootHash string `json:"root_hash"`
FileHash string `json:"file_hash"`
}
type TonlibConfigFileConfig struct {
Config TonlibConfigServer `json:"config"`
BlockchainName string `json:"blockchain_name"`
UseCallbacksForNetwork bool `json:"use_callbacks_for_network"`
IgnoreCache bool `json:"ignore_cache"`
}
type TonlibConfigFile struct {
Config TonlibConfigFileConfig `json:"config"`
Keystore KeyStoreType `json:"keystore_type"`
}
// ParseConfigFile parse JSON config file to
func ParseConfigFile(path string) (*Options, error) {
jsonFile, err := os.Open(path)
defer jsonFile.Close()
if err != nil {
return nil, err
}
byteValue, err := ioutil.ReadAll(jsonFile)
if err != nil {
return nil, err
}
conf := new(TonlibConfigFile)
err = json.Unmarshal(byteValue, &conf)
if err != nil {
return nil, err
}
// marshal back Internal config
internalConfig, err := json.Marshal(&conf.Config.Config)
if err != nil {
return nil, err
}
return NewOptions(
NewConfig(
conf.Config.BlockchainName,
string(internalConfig),
conf.Config.IgnoreCache,
conf.Config.UseCallbacksForNetwork,
),
&conf.Keystore,
), nil
}