forked from bcoin-org/bcoin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlatest
executable file
·49 lines (42 loc) · 1.23 KB
/
latest
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
#!/usr/bin/env node
const assert = require('assert');
const fs = require('fs');
const cp = require('child_process');
const res = require('path').resolve;
const {argv} = process;
if (argv.length < 3) {
console.error('Usage: $ ./migrate/latest [bcoin-prefix]');
console.error('Example: $ ./migrate/latest ~/.bcoin');
process.exit(1);
return;
}
function mv(from, to) {
try {
fs.renameSync(from, to);
} catch (e) {
console.error(e.message);
}
}
function exec(file, ...args) {
try {
const result = cp.spawnSync(file, args, {
stdio: 'inherit',
env: process.env,
maxBuffer: -1 >>> 0,
windowsHide: true
});
if (result.error)
console.error(result.error.message);
} catch (e) {
console.error(e.message);
}
}
const node = argv[0];
const prefix = argv[2];
mv(res(prefix, 'chain.ldb'), res(prefix, 'chain'));
mv(res(prefix, 'spvchain.ldb'), res(prefix, 'spvchain'));
mv(res(prefix, 'mempool.ldb'), res(prefix, 'mempool'));
mv(res(prefix, 'walletdb.ldb'), res(prefix, 'wallet'));
exec(node, res(__dirname, 'chaindb3to4.js'), res(prefix, 'chain'));
exec(node, res(__dirname, 'chaindb3to4.js'), res(prefix, 'spvchain'));
exec(node, res(__dirname, 'walletdb6to7.js'), res(prefix, 'wallet'));