forked from BlueWallet/LndHub
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbitcoin.js
26 lines (26 loc) · 940 Bytes
/
bitcoin.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
// setup bitcoind rpc
const config = require('./config');
let jayson = require('jayson/promise');
let url = require('url');
if (config.bitcoind) {
let rpc = url.parse(config.bitcoind.rpc);
rpc.timeout = 5000;
let bitcoinclient = jayson.client.http(rpc)
bitcoinclient.request('createwallet', [config.bitcoind.wallet], function (err, info) {
if (err && err.message && !err.message.includes("already exists")) {
console.log('could not create wallet:', err, info);
process.exit(1);
}
});
bitcoinclient.request('loadwallet', [config.bitcoind.wallet], function (err, info) {
if (err && err.message && !err.message.includes("already loaded")) {
console.log('could not load wallet:', err, info);
process.exit(2);
}
});
rpc = url.parse(config.bitcoind.rpc+'/wallet/'+config.bitcoind.wallet);
rpc.timeout = 15000;
module.exports = jayson.client.http(rpc);
} else {
module.exports = {};
}