Merge pull request #1140 from letolabs/dpowconfs_fix
Add dpowconfs to z_listunspent + listreceivedbyaddress and other small fixes
This commit is contained in:
@@ -695,7 +695,8 @@ UniValue getblockheader(const UniValue& params, bool fHelp)
|
||||
"\nResult (for verbose = true):\n"
|
||||
"{\n"
|
||||
" \"hash\" : \"hash\", (string) the block hash (same as provided)\n"
|
||||
" \"confirmations\" : n, (numeric) The number of confirmations, or -1 if the block is not on the main chain\n"
|
||||
" \"confirmations\" : n, (numeric) The number of notarized DPoW confirmations, or -1 if the block is not on the main chain\n"
|
||||
" \"rawconfirmations\" : n,(numeric) The number of raw confirmations, or -1 if the block is not on the main chain\n"
|
||||
" \"height\" : n, (numeric) The block height or index\n"
|
||||
" \"version\" : n, (numeric) The block version\n"
|
||||
" \"merkleroot\" : \"xxxx\", (string) The merkle root\n"
|
||||
@@ -755,7 +756,8 @@ UniValue getblock(const UniValue& params, bool fHelp)
|
||||
"\nResult (for verbosity = 1):\n"
|
||||
"{\n"
|
||||
" \"hash\" : \"hash\", (string) the block hash (same as provided hash)\n"
|
||||
" \"confirmations\" : n, (numeric) The number of confirmations, or -1 if the block is not on the main chain\n"
|
||||
" \"confirmations\" : n, (numeric) The number of notarized DPoW confirmations, or -1 if the block is not on the main chain\n"
|
||||
" \"rawconfirmations\" : n,(numeric) The number of raw confirmations, or -1 if the block is not on the main chain\n"
|
||||
" \"size\" : n, (numeric) The block size\n"
|
||||
" \"height\" : n, (numeric) The block height or index (same as provided height)\n"
|
||||
" \"version\" : n, (numeric) The block version\n"
|
||||
@@ -1198,7 +1200,8 @@ UniValue gettxout(const UniValue& params, bool fHelp)
|
||||
"\nResult:\n"
|
||||
"{\n"
|
||||
" \"bestblock\" : \"hash\", (string) the block hash\n"
|
||||
" \"confirmations\" : n, (numeric) The number of confirmations\n"
|
||||
" \"confirmations\" : n, (numeric) The number of notarized DPoW confirmations\n"
|
||||
" \"rawconfirmations\" : n, (numeric) The number of raw confirmations\n"
|
||||
" \"value\" : x.xxx, (numeric) The transaction value in " + CURRENCY_UNIT + "\n"
|
||||
" \"scriptPubKey\" : { (json object)\n"
|
||||
" \"asm\" : \"code\", (string) \n"
|
||||
@@ -1251,10 +1254,10 @@ UniValue gettxout(const UniValue& params, bool fHelp)
|
||||
BlockMap::iterator it = mapBlockIndex.find(pcoinsTip->GetBestBlock());
|
||||
CBlockIndex *pindex = it->second;
|
||||
ret.push_back(Pair("bestblock", pindex->GetBlockHash().GetHex()));
|
||||
if ((unsigned int)coins.nHeight == MEMPOOL_HEIGHT)
|
||||
if ((unsigned int)coins.nHeight == MEMPOOL_HEIGHT) {
|
||||
ret.push_back(Pair("confirmations", 0));
|
||||
else
|
||||
{
|
||||
ret.push_back(Pair("rawconfirmations", 0));
|
||||
} else {
|
||||
ret.push_back(Pair("confirmations", komodo_dpowconfs(coins.nHeight,pindex->GetHeight() - coins.nHeight + 1)));
|
||||
ret.push_back(Pair("rawconfirmations", pindex->GetHeight() - coins.nHeight + 1));
|
||||
}
|
||||
|
||||
@@ -297,6 +297,7 @@ void TxToJSONExpanded(const CTransaction& tx, const uint256 hashBlock, UniValue&
|
||||
} else {
|
||||
entry.push_back(Pair("height", -1));
|
||||
entry.push_back(Pair("confirmations", 0));
|
||||
entry.push_back(Pair("rawconfirmations", 0));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -379,9 +380,10 @@ void TxToJSON(const CTransaction& tx, const uint256 hashBlock, UniValue& entry)
|
||||
entry.push_back(Pair("confirmations", komodo_dpowconfs(pindex->GetHeight(),1 + chainActive.Height() - pindex->GetHeight())));
|
||||
entry.push_back(Pair("time", pindex->GetBlockTime()));
|
||||
entry.push_back(Pair("blocktime", pindex->GetBlockTime()));
|
||||
}
|
||||
else
|
||||
} else {
|
||||
entry.push_back(Pair("confirmations", 0));
|
||||
entry.push_back(Pair("rawconfirmations", 0));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -469,7 +471,8 @@ UniValue getrawtransaction(const UniValue& params, bool fHelp)
|
||||
" ,...\n"
|
||||
" ],\n"
|
||||
" \"blockhash\" : \"hash\", (string) the block hash\n"
|
||||
" \"confirmations\" : n, (numeric) The confirmations\n"
|
||||
" \"confirmations\" : n, (numeric) The number of notarized DPoW confirmations\n"
|
||||
" \"rawconfirmations\" : n, (numeric) The number of raw confirmations\n"
|
||||
" \"time\" : ttt, (numeric) The transaction time in seconds since epoch (Jan 1 1970 GMT)\n"
|
||||
" \"blocktime\" : ttt (numeric) The block time in seconds since epoch (Jan 1 1970 GMT)\n"
|
||||
"}\n"
|
||||
|
||||
@@ -1435,11 +1435,13 @@ struct tallyitem
|
||||
int nConf;
|
||||
vector<uint256> txids;
|
||||
bool fIsWatchonly;
|
||||
int nHeight;
|
||||
tallyitem()
|
||||
{
|
||||
nAmount = 0;
|
||||
nConf = std::numeric_limits<int>::max();
|
||||
fIsWatchonly = false;
|
||||
nHeight = 0;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1485,6 +1487,7 @@ UniValue ListReceived(const UniValue& params, bool fByAccounts)
|
||||
tallyitem& item = mapTally[address];
|
||||
item.nAmount += txout.nValue; // komodo_interest?
|
||||
item.nConf = min(item.nConf, nDepth);
|
||||
item.nHeight = mapBlockIndex[wtx.hashBlock]->GetHeight();
|
||||
item.txids.push_back(wtx.GetHash());
|
||||
if (mine & ISMINE_WATCH_ONLY)
|
||||
item.fIsWatchonly = true;
|
||||
@@ -1504,11 +1507,13 @@ UniValue ListReceived(const UniValue& params, bool fByAccounts)
|
||||
CAmount nAmount = 0;
|
||||
int nConf = std::numeric_limits<int>::max();
|
||||
bool fIsWatchonly = false;
|
||||
int nHeight=0;
|
||||
if (it != mapTally.end())
|
||||
{
|
||||
nAmount = (*it).second.nAmount;
|
||||
nConf = (*it).second.nConf;
|
||||
fIsWatchonly = (*it).second.fIsWatchonly;
|
||||
nHeight = (*it).second.nHeight;
|
||||
}
|
||||
|
||||
if (fByAccounts)
|
||||
@@ -1521,12 +1526,14 @@ UniValue ListReceived(const UniValue& params, bool fByAccounts)
|
||||
else
|
||||
{
|
||||
UniValue obj(UniValue::VOBJ);
|
||||
|
||||
if(fIsWatchonly)
|
||||
obj.push_back(Pair("involvesWatchonly", true));
|
||||
obj.push_back(Pair("address", EncodeDestination(dest)));
|
||||
obj.push_back(Pair("account", strAccount));
|
||||
obj.push_back(Pair("amount", ValueFromAmount(nAmount)));
|
||||
obj.push_back(Pair("confirmations", (nConf == std::numeric_limits<int>::max() ? 0 : nConf)));
|
||||
obj.push_back(Pair("rawconfirmations", (nConf == std::numeric_limits<int>::max() ? 0 : nConf)));
|
||||
obj.push_back(Pair("confirmations", (nConf == std::numeric_limits<int>::max() ? 0 : komodo_dpowconfs(nHeight, nConf))));
|
||||
UniValue transactions(UniValue::VARR);
|
||||
if (it != mapTally.end())
|
||||
{
|
||||
@@ -1546,12 +1553,14 @@ UniValue ListReceived(const UniValue& params, bool fByAccounts)
|
||||
{
|
||||
CAmount nAmount = (*it).second.nAmount;
|
||||
int nConf = (*it).second.nConf;
|
||||
int nHeight = (*it).second.nHeight;
|
||||
UniValue obj(UniValue::VOBJ);
|
||||
if((*it).second.fIsWatchonly)
|
||||
obj.push_back(Pair("involvesWatchonly", true));
|
||||
obj.push_back(Pair("account", (*it).first));
|
||||
obj.push_back(Pair("amount", ValueFromAmount(nAmount)));
|
||||
obj.push_back(Pair("confirmations", (nConf == std::numeric_limits<int>::max() ? 0 : nConf)));
|
||||
obj.push_back(Pair("rawconfirmations", (nConf == std::numeric_limits<int>::max() ? 0 : nConf)));
|
||||
obj.push_back(Pair("confirmations", (nConf == std::numeric_limits<int>::max() ? 0 : komodo_dpowconfs(nHeight, nConf))));
|
||||
ret.push_back(obj);
|
||||
}
|
||||
}
|
||||
@@ -2954,10 +2963,29 @@ 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));
|
||||
obj.push_back(Pair("confirmations", entry.confirmations));
|
||||
|
||||
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<libzcash::SproutPaymentAddress>(entry.address));
|
||||
obj.push_back(Pair("spendable", hasSproutSpendingKey));
|
||||
obj.push_back(Pair("address", EncodePaymentAddress(entry.address)));
|
||||
@@ -2974,7 +3002,24 @@ 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));
|
||||
obj.push_back(Pair("confirmations", entry.confirmations));
|
||||
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;
|
||||
libzcash::SaplingFullViewingKey fvk;
|
||||
pwalletMain->GetSaplingIncomingViewingKey(boost::get<libzcash::SaplingPaymentAddress>(entry.address), ivk);
|
||||
|
||||
Reference in New Issue
Block a user