improve start_node and example.
This commit is contained in:
parent
13604f1e07
commit
e2ad9320ff
|
@ -27,6 +27,20 @@ bitcoind.on('error', function(err) {
|
|||
bitcoind.on('open', function(status) {
|
||||
print('status="%s"', status);
|
||||
|
||||
if (!argv.list
|
||||
|| !argv.blocks
|
||||
|| !argv['on-block']
|
||||
|| !argv['on-tx']
|
||||
|| !argv.broadcast
|
||||
|| !argv['get-tx']) {
|
||||
argv['list'] = true;
|
||||
argv['on-block'] = true;
|
||||
setTimeout(function() {
|
||||
argv['on-block'] = false;
|
||||
print(bitcoind.wallet.listAccounts());
|
||||
}, 5000);
|
||||
}
|
||||
|
||||
if (argv.list) {
|
||||
print(bitcoind.wallet.listAccounts());
|
||||
}
|
||||
|
@ -35,9 +49,11 @@ bitcoind.on('open', function(status) {
|
|||
getBlocks(bitcoind);
|
||||
}
|
||||
|
||||
// var tx = bitcoind.tx.fromHex(testTx);
|
||||
// console.log(tx);
|
||||
// console.log(tx.txid === tx.getHash('hex'));
|
||||
if (argv['test-tx']) {
|
||||
var tx = bitcoind.tx.fromHex(testTx);
|
||||
console.log(tx);
|
||||
console.log(tx.txid === tx.getHash('hex'));
|
||||
}
|
||||
|
||||
function compareObj(obj) {
|
||||
// Hash
|
||||
|
@ -64,7 +80,10 @@ bitcoind.on('open', function(status) {
|
|||
}
|
||||
|
||||
if (argv['on-block']) {
|
||||
bitcoind.on('block', function(block) {
|
||||
bitcoind.on('block', function callee(block) {
|
||||
if (!argv['on-block']) {
|
||||
return bitcoind.removeListener('block', callee);
|
||||
}
|
||||
print('Found Block:');
|
||||
print(block);
|
||||
compareObj(block);
|
||||
|
|
|
@ -60,9 +60,17 @@ process.on = function(name, listener) {
|
|||
return Bitcoin._processOn.apply(this, arguments);
|
||||
};
|
||||
|
||||
Bitcoin.prototype.start = function(callback) {
|
||||
Bitcoin.prototype.start = function(options, callback) {
|
||||
var self = this;
|
||||
|
||||
if (!callback) {
|
||||
callback = options;
|
||||
options = {};
|
||||
}
|
||||
if (!callback) {
|
||||
callback = utils.NOOP;
|
||||
}
|
||||
|
||||
if (this._startCalled) return;
|
||||
this._startCalled = true;
|
||||
|
||||
|
@ -74,7 +82,7 @@ Bitcoin.prototype.start = function(callback) {
|
|||
var exitCaught = none;
|
||||
var errorCaught = none;
|
||||
|
||||
this.log_pipe = bitcoindjs.start(function(err, status) {
|
||||
this.log_pipe = bitcoindjs.start(options, function(err, status) {
|
||||
self._started = true;
|
||||
|
||||
[sigint, sighup, sigquit].forEach(function(signal) {
|
||||
|
|
|
@ -427,19 +427,24 @@ NAN_METHOD(StartBitcoind) {
|
|||
|
||||
Local<Function> callback;
|
||||
std::string datadir = std::string("");
|
||||
if (args.Length() == 2 && args[0]->IsObject() && args[1]->IsFunction()) {
|
||||
Local<Object> options = Local<Object>::Cast(args[0]);
|
||||
String::Utf8Value datadir_(options->Get(NanNew<String>("datadir"))->ToString());
|
||||
datadir = std::string(*datadir_);
|
||||
callback = Local<Function>::Cast(args[1]);
|
||||
} else {
|
||||
if (args.Length() < 1 || !args[0]->IsFunction()) {
|
||||
return NanThrowError(
|
||||
"Usage: bitcoind.start(callback)");
|
||||
}
|
||||
callback = Local<Function>::Cast(args[0]);
|
||||
}
|
||||
|
||||
if (args.Length() >= 2 && args[0]->IsObject() && args[1]->IsFunction()) {
|
||||
Local<Object> options = Local<Object>::Cast(args[0]);
|
||||
if (options->Get(NanNew<String>("datadir"))->IsString()) {
|
||||
String::Utf8Value datadir_(options->Get(NanNew<String>("datadir"))->ToString());
|
||||
datadir = std::string(*datadir_);
|
||||
}
|
||||
callback = Local<Function>::Cast(args[1]);
|
||||
} else if (args.length >= 2
|
||||
&& (args[0]->IsUndefined() || args[0]->IsNull())
|
||||
&& args[1]->IsFunction()) {
|
||||
callback = Local<Function>::Cast(args[1]);
|
||||
} else if (args.length >= 1 && args[0]->IsFunction()) {
|
||||
callback = Local<Function>::Cast(args[0]);
|
||||
} else {
|
||||
return NanThrowError(
|
||||
"Usage: bitcoind.start(callback)");
|
||||
}
|
||||
|
||||
//
|
||||
// Run bitcoind's StartNode() on a separate thread.
|
||||
|
|
Loading…
Reference in New Issue