diff --git a/lib/bitcoind.js b/lib/bitcoind.js index fb400888..eaf50387 100644 --- a/lib/bitcoind.js +++ b/lib/bitcoind.js @@ -374,7 +374,11 @@ Bitcoin.prototype.getTx = function(txHash, blockHash, callback) { blockHash = ''; } if (typeof blockHash !== 'string') { - blockHash = ''; + if (blockHash) { + blockHash = blockHash.hash || blockHash.blockhash || ''; + } else { + blockHash = ''; + } } return bitcoindjs.getTx(txHash, blockHash, function(err, tx) { if (err) return callback(err); diff --git a/src/bitcoindjs.cc b/src/bitcoindjs.cc index a886f6d5..0fa054fd 100644 --- a/src/bitcoindjs.cc +++ b/src/bitcoindjs.cc @@ -392,7 +392,7 @@ static inline void cblock_to_jsblock(const CBlock& cblock, CBlockIndex* cblock_index, Local jsblock, bool is_new); static inline void -ctx_to_jstx(const CTransaction& ctx, uint256 block_hash, Local jstx /*, bool parent=false*/ ); +ctx_to_jstx(const CTransaction& ctx, uint256& block_hash, Local jstx); static inline void jsblock_to_cblock(const Local jsblock, CBlock& cblock); @@ -1567,7 +1567,8 @@ NAN_METHOD(FillTransaction) { // Turn our CTransaction into a javascript Transaction Local new_jstx = NanNew(); - ctx_to_jstx(ctx, 0, new_jstx); + uint256 block_hash = uint256(0); + ctx_to_jstx(ctx, block_hash, new_jstx); NanReturnValue(new_jstx); } @@ -2290,7 +2291,8 @@ NAN_METHOD(TxFromHex) { } Local jstx = NanNew(); - ctx_to_jstx(ctx, 0, jstx); + uint256 block_hash = uint256(0); + ctx_to_jstx(ctx, block_hash, jstx); NanReturnValue(jstx); } @@ -2555,8 +2557,8 @@ NAN_METHOD(HookPackets) { CTransaction tx; vRecv >> tx; Local jstx = NanNew(); - ctx_to_jstx(tx, 0, jstx); - // ctx_to_jstx(tx, 0, o); + uint256 block_hash = uint256(0); + ctx_to_jstx(tx, block_hash, jstx); o->Set(NanNew("tx"), jstx); } else if (strCommand == "block" && !fImporting && !fReindex) { // XXX May be able to do prev_list asynchronously @@ -2565,6 +2567,7 @@ NAN_METHOD(HookPackets) { Local jsblock = NanNew(); cblock_to_jsblock(block, NULL, jsblock, true); // cblock_to_jsblock(block, NULL, o, true); + // last_block_hash = block.GetHash(); o->Set(NanNew("block"), jsblock); } else if (strCommand == "getaddr") { ; // not much other information in getaddr as long as we know we got a getaddr @@ -5520,7 +5523,9 @@ cblock_to_jsblock(const CBlock& cblock, CBlockIndex* cblock_index, Local cblock_index = find_new_block_index(cblock.GetHash(), cblock.hashPrevBlock, &is_allocated); } - jsblock->Set(NanNew("hash"), NanNew(cblock.GetHash().GetHex())); + uint256 block_hash = cblock.GetHash(); + + jsblock->Set(NanNew("hash"), NanNew(block_hash.GetHex())); CMerkleTx txGen(cblock.vtx[0]); txGen.SetMerkleBranch(cblock); jsblock->Set(NanNew("confirmations"), NanNew((int)txGen.GetDepthInMainChain())->ToInt32()); @@ -5569,8 +5574,7 @@ cblock_to_jsblock(const CBlock& cblock, CBlockIndex* cblock_index, Local int ti = 0; BOOST_FOREACH(const CTransaction& ctx, cblock.vtx) { Local jstx = NanNew(); - const uint256 block_hash = cblock.GetHash(); - ctx_to_jstx(ctx, block_hash, jstx /*, true*/ ); + ctx_to_jstx(ctx, block_hash, jstx); txs->Set(ti, jstx); ti++; } @@ -5589,7 +5593,7 @@ cblock_to_jsblock(const CBlock& cblock, CBlockIndex* cblock_index, Local } static inline void -ctx_to_jstx(const CTransaction& ctx, uint256 block_hash, Local jstx /*, bool parent=false*/ ) { +ctx_to_jstx(const CTransaction& ctx, uint256& block_hash, Local jstx) { // With v0.9.0 // jstx->Set(NanNew("mintxfee"), NanNew((int64_t)ctx.nMinTxFee)->ToInteger()); // jstx->Set(NanNew("minrelaytxfee"), NanNew((int64_t)ctx.nMinRelayTxFee)->ToInteger()); @@ -5680,7 +5684,21 @@ ctx_to_jstx(const CTransaction& ctx, uint256 block_hash, Local jstx /*, } jstx->Set(NanNew("vout"), vout); - if (block_hash != 0) { + if (block_hash != uint256(0)) { + jstx->Set(NanNew("blockhash"), NanNew(block_hash.GetHex())); + jstx->Set(NanNew("confirmations"), NanNew(0)); + if (ctx.IsCoinBase()) { + jstx->Set(NanNew("generated"), NanNew(true)); + } + jstx->Set(NanNew("blockindex"), NanNew(mapBlockIndex[block_hash]->nHeight)); + jstx->Set(NanNew("blocktime"), NanNew(mapBlockIndex[block_hash]->GetBlockTime())); + Local conflicts = NanNew(); + jstx->Set(NanNew("walletconflicts"), conflicts); + jstx->Set(NanNew("time"), + NanNew((uint32_t)mapBlockIndex[block_hash]->GetBlockTime())->ToUint32()); + jstx->Set(NanNew("timereceived"), + NanNew((uint32_t)mapBlockIndex[block_hash]->GetBlockTime())->ToUint32()); +#if 0 jstx->Set(NanNew("blockhash"), NanNew(block_hash.GetHex())); CWalletTx cwtx(pwalletMain, ctx); int confirms = cwtx.GetDepthInMainChain(); @@ -5705,16 +5723,7 @@ ctx_to_jstx(const CTransaction& ctx, uint256 block_hash, Local jstx /*, jstx->Set(NanNew("walletconflicts"), conflicts); jstx->Set(NanNew("time"), NanNew(cwtx.GetTxTime())); jstx->Set(NanNew("timereceived"), NanNew((int64_t)cwtx.nTimeReceived)); - // if (!parent) { - // CBlock cblock; - // //CBlockIndex *cblock_index = mapBlockIndex[cwtx.hashBlock]; - // CBlockIndex *cblock_index = mapBlockIndex[block_hash]; - // if (ReadBlockFromDisk(cblock, cblock_index)) { - // Local jsblock = NanNew(); - // cblock_to_jsblock(cblock, cblock_index, jsblock, false); - // jstx->Set(NanNew("_block"), jsblock); - // } - // } +#endif } else { jstx->Set(NanNew("blockhash"), NanNew(uint256(0).GetHex())); jstx->Set(NanNew("confirmations"), NanNew(-1));