|
@ -6,7 +6,7 @@ require('classtool'); |
|
|
function ClassSpec(b) { |
|
|
function ClassSpec(b) { |
|
|
var http = b.http || require('http'); |
|
|
var http = b.http || require('http'); |
|
|
var https = b.https || require('https'); |
|
|
var https = b.https || require('https'); |
|
|
var log = b.log || {err: function(){}}; |
|
|
var log = b.log || require('./util/log'); |
|
|
|
|
|
|
|
|
function RpcClient(opts) { |
|
|
function RpcClient(opts) { |
|
|
opts = opts || {}; |
|
|
opts = opts || {}; |
|
@ -64,7 +64,7 @@ function ClassSpec(b) { |
|
|
help: '', |
|
|
help: '', |
|
|
importAddress: 'str str bool', |
|
|
importAddress: 'str str bool', |
|
|
importPrivKey: 'str str bool', |
|
|
importPrivKey: 'str str bool', |
|
|
keypoolRefill: '', |
|
|
keyPoolRefill: '', |
|
|
listAccounts: 'int', |
|
|
listAccounts: 'int', |
|
|
listAddressGroupings: '', |
|
|
listAddressGroupings: '', |
|
|
listReceivedByAccount: 'int bool', |
|
|
listReceivedByAccount: 'int bool', |
|
@ -152,12 +152,22 @@ function ClassSpec(b) { |
|
|
options[k] = self.httpOptions[k]; |
|
|
options[k] = self.httpOptions[k]; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
var err = null; |
|
|
var req = this.protocol.request(options, function(res) { |
|
|
var req = this.protocol.request(options, function(res) { |
|
|
|
|
|
|
|
|
var buf = ''; |
|
|
var buf = ''; |
|
|
res.on('data', function(data) { |
|
|
res.on('data', function(data) { |
|
|
buf += data; |
|
|
buf += data; |
|
|
}); |
|
|
}); |
|
|
res.on('end', function() { |
|
|
res.on('end', function() { |
|
|
|
|
|
if(res.statusCode == 401) { |
|
|
|
|
|
callback(new Error('bitcoin JSON-RPC connection rejected: unauthorized')); |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
if(err) { |
|
|
|
|
|
callback(err); |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
try { |
|
|
try { |
|
|
var parsedBuf = JSON.parse(buf); |
|
|
var parsedBuf = JSON.parse(buf); |
|
|
} catch(e) { |
|
|
} catch(e) { |
|
@ -170,7 +180,7 @@ function ClassSpec(b) { |
|
|
}); |
|
|
}); |
|
|
}); |
|
|
}); |
|
|
req.on('error', function(e) { |
|
|
req.on('error', function(e) { |
|
|
callback(e); |
|
|
log.err('Could not connect to bitcoin via RPC: '+e); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
req.setHeader('Content-Length', request.length); |
|
|
req.setHeader('Content-Length', request.length); |
|
|