From dda20b2760790a098bbfb94fdf792139010d18a7 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Sun, 6 Jan 2019 01:39:04 +0100 Subject: [PATCH] Correctly lookup height of joinsplits in z_listunspent --- src/wallet/rpcwallet.cpp | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index f179ea45a..ccecb3794 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -2963,10 +2963,27 @@ UniValue z_listunspent(const UniValue& params, bool fHelp) for (auto & entry : sproutEntries) { UniValue obj(UniValue::VOBJ); + int nHeight = 0; + CTransaction tx; + uint256 hashBlock; + obj.push_back(Pair("txid", entry.jsop.hash.ToString())); obj.push_back(Pair("jsindex", (int)entry.jsop.js )); obj.push_back(Pair("jsoutindex", (int)entry.jsop.n)); - int nHeight = mapBlockIndex[entry.jsop.hash]->GetHeight(); + + if (!GetTransaction(entry.jsop.hash, tx, hashBlock, true)) { + // TODO: should we throw JSONRPCError ? + fprintf(stderr,"tx hash %s does not exist!\n", entry.jsop.hash.ToString().c_str() ); + } + + BlockMap::const_iterator it = mapBlockIndex.find(hashBlock); + if (it != mapBlockIndex.end()) { + nHeight = it->second->GetHeight(); + fprintf(stderr,"blockHash %s height %d\n",hashBlock.ToString().c_str(), nHeight); + } else { + // TODO: should we throw JSONRPCError ? + fprintf(stderr,"block hash %s does not exist!\n", hashBlock.ToString().c_str() ); + } obj.push_back(Pair("confirmations", komodo_dpowconfs(nHeight, entry.confirmations))); obj.push_back(Pair("rawconfirmations", entry.confirmations)); bool hasSproutSpendingKey = pwalletMain->HaveSproutSpendingKey(boost::get(entry.address)); @@ -2985,7 +3002,23 @@ UniValue z_listunspent(const UniValue& params, bool fHelp) UniValue obj(UniValue::VOBJ); obj.push_back(Pair("txid", entry.op.hash.ToString())); obj.push_back(Pair("outindex", (int)entry.op.n)); - int nHeight = mapBlockIndex[entry.op.hash]->GetHeight(); + // this is a txid hash but needs to be block hash + int nHeight = 0; + CTransaction tx; + uint256 hashBlock; + if (!GetTransaction(entry.op.hash, tx, hashBlock, true)) { + // TODO: should we throw JSONRPCError ? + fprintf(stderr,"tx hash %s does not exist!\n", entry.op.hash.ToString().c_str() ); + } + + BlockMap::const_iterator it = mapBlockIndex.find(hashBlock); + if (it != mapBlockIndex.end()) { + nHeight = it->second->GetHeight(); + fprintf(stderr,"blockHash %s height %d\n",hashBlock.ToString().c_str(), nHeight); + } else { + // TODO: should we throw JSONRPCError ? + fprintf(stderr,"block hash %s does not exist!\n", hashBlock.ToString().c_str() ); + } obj.push_back(Pair("confirmations", komodo_dpowconfs(nHeight, entry.confirmations))); obj.push_back(Pair("rawconfirmations", entry.confirmations)); libzcash::SaplingIncomingViewingKey ivk;