diff --git a/lib/bitcoind.js b/lib/bitcoind.js index 91de7cb8..933511d9 100644 --- a/lib/bitcoind.js +++ b/lib/bitcoind.js @@ -7,6 +7,7 @@ var net = require('net'); var EventEmitter = require('events').EventEmitter; var bitcoindjs = require('../build/Release/bitcoindjs.node'); +var util = require('util'); /** * Bitcoin @@ -23,17 +24,39 @@ function Bitcoin(options) { this.options = options; - bitcoindjs.start(function(err, status) { + this.log_pipe = bitcoindjs.start(function(err, status) { if (err) { self.emit('error', err); return; } self.emit('open', status); }); + + this.log('log pipe opened: %d', this.log_pipe); } Bitcoin.prototype.__proto__ = EventEmitter.prototype; +Bitcoin.prototype.log = +Bitcoin.prototype.info = function() { + if (typeof arguments[0] !== 'string') { + var out = util.inspect(arguments[0], null, 20, true); + return process.stdout.write('bitcoind: ' + out + '\n'); + } + var out = util.format.apply(util, arguments); + return process.stdout.write('bitcoind: ' + out + '\n'); +}; + +Bitcoin.prototype.error = function() { + if (typeof arguments[0] !== 'string') { + var out = util.inspect(arguments[0], null, 20, true); + return process.stderr.write('bitcoind: ' + out + '\n'); + } + var out = util.format.apply(util, arguments); + return process.stderr.write('bitcoind: ' + out + '\n'); +}; + + /** * Expose */ diff --git a/package.json b/package.json index 1cd088ba..54b127d9 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,7 @@ "bitcoind" ], "dependencies": { - "nan": "~1.0.0" + "nan": "1.3.0" }, "devDependencies": { "mocha": "~1.16.2" diff --git a/src/bitcoindjs.cc b/src/bitcoindjs.cc index 1fd0f5d2..22e16afb 100644 --- a/src/bitcoindjs.cc +++ b/src/bitcoindjs.cc @@ -177,8 +177,6 @@ NAN_METHOD(StartBitcoind) { open_pipes(&out_pipe, &log_pipe); - // handle->Set(NanNew("log_fd"), NanNew(log_pipe[1])); - uv_work_t *req_parse_logs = new uv_work_t(); async_log_data* data_parse_logs = new async_log_data(); data_parse_logs->out_pipe = &out_pipe; @@ -208,7 +206,7 @@ NAN_METHOD(StartBitcoind) { assert(status_start_node == 0); - NanReturnValue(Undefined()); + NanReturnValue(NanNew(log_pipe[1])); } /**