From be2bba94bdbfd9fbf22381c64945e39d93aa1838 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Mon, 22 Sep 2014 12:27:33 -0700 Subject: [PATCH] cleanup. allow no block hash. --- example/index.js | 3 ++- lib/bitcoind.js | 25 +++++++++++++++++-------- src/bitcoindjs.cc | 9 ++++++++- 3 files changed, 27 insertions(+), 10 deletions(-) diff --git a/example/index.js b/example/index.js index 2c75ff9b..a5a386a5 100755 --- a/example/index.js +++ b/example/index.js @@ -15,7 +15,8 @@ bitcoind.start(function(err) { bitcoind.on('open', function(status) { console.log('bitcoind: status="%s"', status); return setTimeout(function() { - return bitcoind.getTx(genesisTx, genesisBlock, function(err, tx) { + // return bitcoind.getTx(genesisTx, genesisBlock, function(err, tx) { + return bitcoind.getTx(genesisTx, function(err, tx) { if (err) throw err; return print(tx); }); diff --git a/lib/bitcoind.js b/lib/bitcoind.js index ffef12bd..efdbec21 100644 --- a/lib/bitcoind.js +++ b/lib/bitcoind.js @@ -140,16 +140,25 @@ Bitcoin.prototype.start = function(callback) { } }; -Bitcoin.prototype.getBlock = function(hash, callback) { - return bitcoindjs.getBlock(hash, callback); +Bitcoin.prototype.getBlock = function(blockHash, callback) { + return bitcoindjs.getBlock(blockHash, callback); }; -Bitcoin.prototype.getTx = function(hash, blockHash, callback) { - if (hash[1] === 'x') hash = hash.slice(2); - if (blockHash[1] === 'x') blockHash = blockHash.slice(2); - // hash = utils.revHex(hash); - // blockHash = utils.revHex(blockHash); - return bitcoindjs.getTx(hash, blockHash, callback); +Bitcoin.prototype.getTx = function(txHash, blockHash, callback) { + if (!callback) { + callback = blockHash; + blockHash = ''; + } + + // if (txHash[1] === 'x') txHash = txHash.slice(2); + // txHash = utils.revHex(txHash); + + // if (blockHash) { + // if (blockHash[1] === 'x') blockHash = blockHash.slice(2); + // blockHash = utils.revHex(blockHash); + // } + + return bitcoindjs.getTx(txHash, blockHash, callback); }; Bitcoin.prototype.log = diff --git a/src/bitcoindjs.cc b/src/bitcoindjs.cc index 1210a716..cb0b907c 100644 --- a/src/bitcoindjs.cc +++ b/src/bitcoindjs.cc @@ -896,6 +896,12 @@ NAN_METHOD(GetTx) { std::string txHash = std::string(*txHash_); std::string blockHash = std::string(*blockHash_); + bool noBlockHash = false; + if (blockHash.empty()) { + blockHash = std::string("0x0000000000000000000000000000000000000000000000000000000000000000"); + noBlockHash = true; + } + if (txHash[1] != 'x') { txHash = "0x" + txHash; } @@ -910,9 +916,10 @@ NAN_METHOD(GetTx) { uint256 hash(txHash); uint256 hashBlock(blockHash); // uint256 hashBlock = 0; + // if (noBlockHash) hashBlock = 0; CTransaction tx; - if (!GetTransaction(hash, tx, hashBlock, true)) { + if (!GetTransaction(hash, tx, hashBlock, noBlockHash ? true : false)) { Local err = Exception::Error(String::New("Bad Transaction.")); const unsigned argc = 1; Local argv[argc] = { err };