forked from booo/node-bitcoin-p2p
-
Notifications
You must be signed in to change notification settings - Fork 10
/
db-del-block.js
38 lines (32 loc) · 1.19 KB
/
db-del-block.js
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
var leveldown = require('leveldown'); // database
var Settings = require('./lib/settings').Settings;
if (process.argv.length <= 2 || process.argv[2] == '-h' || process.argv[2] == '-?' || process.argv[2] == 'help') {
console.log('This script deletes a block header from the levelDB database, forcing it to be re-synced from the network.');
console.log('Useful if your process got halted mid-block-save, so not all block metadata (transactions, etc.) are in the database.');
console.log('Call this script with one argument, the full block hash in hex format, zeroes at the beginning');
process.exit(1);
}
var blockHash = new Buffer(process.argv[2], 'ascii').fromHex().reverse();
cfg = new Settings();
var dataDir = cfg.getDataDir();
storageUri = dataDir + '/leveldb/';
hMain = leveldown(storageUri+'main.db');
var defaultCreateOpts = {
createIfMissing: true,
cacheSize: 100 * 1024 * 1024,
keyEncoding: 'json',
valueEncoding: 'json'
};
hMain.open(defaultCreateOpts, function (err, value) {
if (err !== undefined) {
console.log('err:', err);
process.exit(1);
}
hMain.del(blockHash, function(err) {
if (err === undefined) {
console.log('Success!');
} else {
console.log('err:', err);
}
});
});