-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathexport.js
More file actions
76 lines (57 loc) · 1.79 KB
/
export.js
File metadata and controls
76 lines (57 loc) · 1.79 KB
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
var Client = require('bitcoin-core'),
async = require('async'),
fs = require('fs');
//////// Begin Config ////////
var clientConnection = new Client({
username: 'bitcoinrpc',
password: 'YourRPCPassword'
});
var walletPassword = 'YourBitcoinCorePassphaseOrLeaveThisBlank';
///////// End Config /////////
var totalCoinBal = 0;
var addressesToGetPriKey = [];
var privateKeys = [];
function runDumpPrivKey() {
async.eachLimit(addressesToGetPriKey, 1, function (address, callback) {
console.log('Getting private key for', address);
clientConnection.dumpPrivKey(address, function (err, result) {
if (err) return callback(err);
privateKeys.push(result);
callback();
});
}, function done(err) {
if (err) return console.log(err);
var txtContents = '';
var firstLineWrote = false;
privateKeys.forEach(function (key) {
if (firstLineWrote) txtContents += '\n';
firstLineWrote = true;
txtContents += key;
});
console.log('Saving ' + privateKeys.length + ' private keys to txt file');
fs.writeFile('./keys.txt', txtContents, function (err) {
if (err) throw err;
console.log('The file has been saved!');
});
});
}
clientConnection.listAddressGroupings(function (err, group) {
if (err) return console.log(err);
group.forEach(function (addressGroup) {
addressGroup.forEach(function (address) {
addressesToGetPriKey.push(address[0]);
totalCoinBal += address[1];
});
});
console.log('You have ' + totalCoinBal + ' coins and ' + addressesToGetPriKey.length + ' addresses');
if (walletPassword.length > 0) //unlock wallet
{
clientConnection.walletPassphrase(walletPassword, 86400, function (err, result) { //unlock for one day - should export much faster however
if (err) return console.log(err);
runDumpPrivKey();
});
}
else {
runDumpPrivKey();
}
})