From 918dc08ddcec94a15521f9b5f0dc8ac3fcba6870 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Wed, 19 Nov 2014 10:08:02 -0800 Subject: [PATCH] check whether tx is ours. add walletconflicts if so. --- src/bitcoindjs.cc | 49 ++++++++++++++++++++--------------------------- 1 file changed, 21 insertions(+), 28 deletions(-) diff --git a/src/bitcoindjs.cc b/src/bitcoindjs.cc index 9417d301..1b35bcfb 100644 --- a/src/bitcoindjs.cc +++ b/src/bitcoindjs.cc @@ -5607,6 +5607,7 @@ ctx_to_jstx(const CTransaction& ctx, uint256 block_hash, Local jstx) { jstx->Set(NanNew("size"), NanNew((int)::GetSerializeSize(ctx, SER_NETWORK, PROTOCOL_VERSION))->ToInt32()); + bool is_mine = false; Local vin = NanNew(); int vi = 0; BOOST_FOREACH(const CTxIn& txin, ctx.vin) { @@ -5630,6 +5631,13 @@ ctx_to_jstx(const CTransaction& ctx, uint256 block_hash, Local jstx) { CTxOut prev_out = prev_tx.vout[txin.prevout.n]; ExtractDestination(prev_out.scriptPubKey, from); CBitcoinAddress addrFrom(from); + + // XXX Determine wether this is our transaction + CTxDestination dest = addrFrom.Get(); + if (IsMine(*pwalletMain, dest)) { + is_mine = true; + } + jsprev->Set(NanNew("address"), NanNew(addrFrom.ToString())); jsprev->Set(NanNew("value"), NanNew((int64_t)prev_out.nValue)->ToInteger()); } else { @@ -5647,7 +5655,6 @@ ctx_to_jstx(const CTransaction& ctx, uint256 block_hash, Local jstx) { } jstx->Set(NanNew("vin"), vin); - //bool is_mine = false; Local vout = NanNew(); for (unsigned int vo = 0; vo < ctx.vout.size(); vo++) { const CTxOut& txout = ctx.vout[vo]; @@ -5661,9 +5668,10 @@ ctx_to_jstx(const CTransaction& ctx, uint256 block_hash, Local jstx) { const CScript& scriptPubKey = txout.scriptPubKey; Local out = o; - //if (IsMine(*pwalletMain, scriptPubKey)) { - // is_mine = true; - //} + // XXX Determine wether this is our transaction + if (IsMine(*pwalletMain, scriptPubKey)) { + is_mine = true; + } txnouttype type; vector addresses; @@ -5690,6 +5698,11 @@ ctx_to_jstx(const CTransaction& ctx, uint256 block_hash, Local jstx) { } jstx->Set(NanNew("vout"), vout); + //CWalletTx cwtx(pwalletMain, ctx); + //bool is_mine = cwtx.hashBlock != uint256(0); + //bool is_mine = cwtx.hashBlock != 0; + //jstx->Set(NanNew("ismine"), NanNew(is_mine)); + if (block_hash != 0) { jstx->Set(NanNew("blockhash"), NanNew(block_hash.GetHex())); if (ctx.IsCoinBase()) { @@ -5707,12 +5720,6 @@ ctx_to_jstx(const CTransaction& ctx, uint256 block_hash, Local jstx) { NanNew((int64_t)pindex->GetBlockTime())->ToInteger()); jstx->Set(NanNew("timereceived"), NanNew((int64_t)pindex->GetBlockTime())->ToInteger()); - //jstx->Set(NanNew("blocktime"), - // NanNew(pindex->GetBlockTime())); - //jstx->Set(NanNew("time"), - // NanNew(pindex->GetBlockTime())); - //jstx->Set(NanNew("timereceived"), - // NanNew(pindex->GetBlockTime())); } else { jstx->Set(NanNew("confirmations"), NanNew(0)); jstx->Set(NanNew("blockindex"), NanNew(-1)); @@ -5720,25 +5727,12 @@ ctx_to_jstx(const CTransaction& ctx, uint256 block_hash, Local jstx) { jstx->Set(NanNew("time"), NanNew(0)); jstx->Set(NanNew("timereceived"), NanNew(0)); } - jstx->Set(NanNew("walletconflicts"), NanNew()); -#if 0 - if (is_mine) { - jstx->Set(NanNew("blockhash"), NanNew(block_hash.GetHex())); - CWalletTx cwtx(pwalletMain, ctx); + if (!is_mine) { + jstx->Set(NanNew("walletconflicts"), NanNew()); + } else { + // XXX If the tx is ours int confirms = cwtx.GetDepthInMainChain(); jstx->Set(NanNew("confirmations"), NanNew(confirms)); - if (ctx.IsCoinBase()) { - jstx->Set(NanNew("generated"), NanNew(true)); - } - if (confirms > 0) { - jstx->Set(NanNew("blockhash"), NanNew(cwtx.hashBlock.GetHex())); - jstx->Set(NanNew("blockindex"), NanNew(cwtx.nIndex)); - jstx->Set(NanNew("blocktime"), NanNew(mapBlockIndex[cwtx.hashBlock]->GetBlockTime())); - } else { - jstx->Set(NanNew("blockhash"), NanNew(uint256(0).GetHex())); - jstx->Set(NanNew("blockindex"), NanNew(-1)); - jstx->Set(NanNew("blocktime"), NanNew(0)); - } Local conflicts = NanNew(); int co = 0; BOOST_FOREACH(const uint256& conflict, cwtx.GetConflicts()) { @@ -5748,7 +5742,6 @@ ctx_to_jstx(const CTransaction& ctx, uint256 block_hash, Local jstx) { jstx->Set(NanNew("time"), NanNew(cwtx.GetTxTime())); jstx->Set(NanNew("timereceived"), NanNew((int64_t)cwtx.nTimeReceived)); } -#endif } else { jstx->Set(NanNew("blockhash"), NanNew(uint256(0).GetHex())); jstx->Set(NanNew("confirmations"), NanNew(-1));