forked from OpenBazaar/openbazaar-go
/
Migration014.go
198 lines (182 loc) · 6.44 KB
/
Migration014.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
package migrations
import "errors"
// Migration014 is deprecated to remove support for bitcoind and zcashd runtime
// dependencies. The migration behavior is intact for historical purposes.
type Migration014 struct{}
func (Migration014) Up(_, _ string, _ bool) error {
//var (
//WalletCoinType = "BTC" // use single-coin currency code
//databaseFilePath string
//)
//if testnetEnabled {
//databaseFilePath = path.Join(repoPath, "datastore", "testnet.db")
//} else {
//databaseFilePath = path.Join(repoPath, "datastore", "mainnet.db")
//}
//const (
//alterKeysSQL = "alter table keys add coin text;"
//createKeysIndexSQL = "create index index_keys on keys (coin);"
//alterUTXOSQL = "alter table utxos add coin text;"
//createUTXOIndexSQL = "create index index_utxos on utxos (coin);"
//alterSTXOSQL = "alter table stxos add coin text;"
//createSTXOIndexSQL = "create index index_stxos on stxos (coin);"
//alterTXNSSQL = "alter table txns add coin text;"
//createTXNSIndexSQL = "create index index_txns on txns (coin);"
//alterWatchedScriptsSQL = "alter table watchedscripts add coin text;"
//createWatchedScriptsIndexSQL = "create index index_watchedscripts on watchedscripts (coin);"
//)
//db, err := sql.Open("sqlite3", databaseFilePath)
//if err != nil {
//return err
//}
//defer db.Close()
//if databasePassword != "" {
//p := fmt.Sprintf("pragma key = '%s';", databasePassword)
//_, err := db.Exec(p)
//if err != nil {
//return err
//}
//}
//migration := strings.Join([]string{
//alterKeysSQL,
//alterUTXOSQL,
//alterSTXOSQL,
//alterTXNSSQL,
//alterWatchedScriptsSQL,
//createKeysIndexSQL,
//createUTXOIndexSQL,
//createSTXOIndexSQL,
//createTXNSIndexSQL,
//createWatchedScriptsIndexSQL,
//}, " ")
//tx, err := db.Begin()
//if err != nil {
//return err
//}
//if _, err = tx.Exec(migration); err != nil {
//err0 := tx.Rollback()
//if err0 != nil {
//log.Error(err0)
//}
//return err
//}
//if err = tx.Commit(); err != nil {
//return err
//}
//_, err = db.Exec("update keys set coin = ?", WalletCoinType.CurrencyCode())
//if err != nil {
//return err
//}
//_, err = db.Exec("update utxos set coin = ?", WalletCoinType.CurrencyCode())
//if err != nil {
//return err
//}
//_, err = db.Exec("update stxos set coin = ?", WalletCoinType.CurrencyCode())
//if err != nil {
//return err
//}
//_, err = db.Exec("update txns set coin = ?", WalletCoinType.CurrencyCode())
//if err != nil {
//return err
//}
//_, err = db.Exec("update watchedscripts set coin = ?", WalletCoinType.CurrencyCode())
//if err != nil {
//return err
//}
// Bump schema version
//err = writeRepoVer(repoPath, 15)
//if err != nil {
//return err
//}
//return nil
log.Error("Migration014 has been deprecated and requires manual recovery")
return errors.New("Migration014 has been deprecated and cannot proceed")
}
func (Migration014) Down(_, _ string, _ bool) error {
//var (
//databaseFilePath string
//)
//if testnetEnabled {
//databaseFilePath = path.Join(repoPath, "datastore", "testnet.db")
//} else {
//databaseFilePath = path.Join(repoPath, "datastore", "mainnet.db")
//}
//db, err := sql.Open("sqlite3", databaseFilePath)
//if err != nil {
//return err
//}
//defer db.Close()
//if databasePassword != "" {
//p := fmt.Sprintf("pragma key = '%s';", databasePassword)
//_, err := db.Exec(p)
//if err != nil {
//return err
//}
//}
//const (
//alterKeysSQL = "alter table keys rename to keys_old;"
//createKeysSQL = "create table keys (scriptAddress text primary key not null, purpose integer, keyIndex integer, used integer, key text);"
//insertKeysSQL = "insert into keys select scriptAddress, purpose, keyIndex, used, key from keys_old;"
//dropKeysTableSQL = "drop table keys_old;"
//alterUtxosSQL = "alter table utxos rename to utxos_old;"
//createUtxosSQL = "create table utxos (outpoint text primary key not null, value integer, height integer, scriptPubKey text, watchOnly integer);"
//insertUtxosSQL = "insert into utxos select outpoint, value, height, scriptPubKey, watchOnly from utxos_old;"
//dropUtxosTableSQL = "drop table utxos_old;"
//alterStxosSQL = "alter table stxos rename to stxos_old;"
//createStxosSQL = "create table stxos (outpoint text primary key not null, value integer, height integer, scriptPubKey text, watchOnly integer, spendHeight integer, spendTxid text);"
//insertStxosSQL = "insert into stxos select outpoint, value, height, scriptPubKey, watchOnly, spendHeight, spendTxid from stxos_old;"
//dropStxosTableSQL = "drop table stxos_old;"
//alterTxnsSQL = "alter table txns rename to txns_old;"
//createTxnsSQL = "create table txns (txid text primary key not null, value integer, height integer, timestamp integer, watchOnly integer, tx blob);"
//insertTxnsSQL = "insert into txns select txid, value, height, timestamp, watchOnly, tx from txns_old;"
//dropTxnsTableSQL = "drop table txns_old;"
//alterWatchedScriptsSQL = "alter table watchedscripts rename to watchedscripts_old;"
//createWatchedScriptSQL = "create table watchedscripts (scriptPubKey text primary key not null);"
//insertWatchedScriptsSQL = "insert into watchedscripts select scriptPubKey from watchedscripts_old;"
//dropWatchedScriptsTableSQL = "drop table watchedscripts_old;"
//)
//migration := strings.Join([]string{
//alterKeysSQL,
//createKeysSQL,
//insertKeysSQL,
//dropKeysTableSQL,
//alterUtxosSQL,
//createUtxosSQL,
//insertUtxosSQL,
//dropUtxosTableSQL,
//alterStxosSQL,
//createStxosSQL,
//insertStxosSQL,
//dropStxosTableSQL,
//alterTxnsSQL,
//createTxnsSQL,
//insertTxnsSQL,
//dropTxnsTableSQL,
//alterWatchedScriptsSQL,
//createWatchedScriptSQL,
//insertWatchedScriptsSQL,
//dropWatchedScriptsTableSQL,
//}, " ")
//tx, err := db.Begin()
//if err != nil {
//return err
//}
//if _, err = tx.Exec(migration); err != nil {
//err0 := tx.Rollback()
//if err0 != nil {
//log.Error(err0)
//}
//return err
//}
//if err = tx.Commit(); err != nil {
//return err
//}
// Revert schema version
//err = writeRepoVer(repoPath, 14)
//if err != nil {
//return err
//}
//return nil
log.Error("Migration014 has been deprecated and requires manual recovery")
return errors.New("Migration014 has been deprecated and cannot proceed")
}