forked from OpenBazaar/openbazaar-go
/
Migration002.go
109 lines (97 loc) · 2.13 KB
/
Migration002.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package migrations
import (
"encoding/json"
"errors"
"io/ioutil"
"os"
"path"
)
type Migration002 struct{}
func (Migration002) Up(repoPath string, dbPassword string, testnet bool) error {
configFile, err := ioutil.ReadFile(path.Join(repoPath, "config"))
if err != nil {
return err
}
var cfgIface interface{}
err = json.Unmarshal(configFile, &cfgIface)
if err != nil {
return err
}
cfg, ok := cfgIface.(map[string]interface{})
if !ok {
return errors.New("invalid config file")
}
pushNodes := []string{
"QmY8puEnVx66uEet64gAf4VZRo7oUyMCwG6KdB9KM92EGQ",
"QmPPg2qeF3n2KvTRXRZLaTwHCw8JxzF4uZK93RfMoDvf2o",
"QmPPegaeM4rXfQDF3uu784d93pLEzV8A4zXU7akEgYnTFd",
}
cfg["DataSharing"] = map[string]interface{}{
"AcceptStoreRequests": false,
"PushTo": pushNodes,
}
delete(cfg, "Crosspost-gateways")
out, err := json.MarshalIndent(cfg, "", " ")
if err != nil {
return err
}
f, err := os.Create(path.Join(repoPath, "config"))
if err != nil {
return err
}
_, err = f.Write(out)
if err != nil {
return err
}
f.Close()
f1, err := os.Create(path.Join(repoPath, "repover"))
if err != nil {
return err
}
_, err = f1.Write([]byte("3"))
if err != nil {
return err
}
f1.Close()
return nil
}
func (Migration002) Down(repoPath string, dbPassword string, testnet bool) error {
configFile, err := ioutil.ReadFile(path.Join(repoPath, "config"))
if err != nil {
return err
}
var cfgIface interface{}
err = json.Unmarshal(configFile, &cfgIface)
if err != nil {
return err
}
cfg, ok := cfgIface.(map[string]interface{})
if !ok {
return errors.New("invalid config file")
}
cfg["Crosspost-gateways"] = []string{"https://gateway.ob1.io/", "https://gateway.duosear.ch/"}
delete(cfg, "DataSharing")
out, err := json.MarshalIndent(cfg, "", " ")
if err != nil {
return err
}
f, err := os.Create(path.Join(repoPath, "config"))
if err != nil {
return err
}
_, err = f.Write(out)
if err != nil {
return err
}
f.Close()
f1, err := os.Create(path.Join(repoPath, "repover"))
if err != nil {
return err
}
_, err = f1.Write([]byte("2"))
if err != nil {
return err
}
f1.Close()
return nil
}