This commit is contained in:
blackjok3r
2019-01-10 02:25:59 +08:00
27 changed files with 226 additions and 801 deletions

View File

@@ -1538,11 +1538,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;
}
};
@@ -1588,6 +1590,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;
@@ -1607,11 +1610,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)
@@ -1624,12 +1629,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())
{
@@ -1649,12 +1656,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);
}
}
@@ -3057,10 +3066,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)));
@@ -3077,7 +3105,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);
@@ -3805,7 +3850,11 @@ UniValue z_listreceivedbyaddress(const UniValue& params, bool fHelp)
"{\n"
" \"txid\": xxxxx, (string) the transaction id\n"
" \"amount\": xxxxx, (numeric) the amount of value in the note\n"
" \"memo\": xxxxx, (string) hexademical string representation of memo field\n"
" \"memo\": xxxxx, (string) hexadecimal string representation of memo field\n"
" \"confirmations\" : n, (numeric) the number of confirmations\n"
" \"jsindex\" (sprout) : n, (numeric) the joinsplit index\n"
" \"jsoutindex\" (sprout) : n, (numeric) the output index of the joinsplit\n"
" \"outindex\" (sapling) : n, (numeric) the output index\n"
" \"change\": true|false, (boolean) true if the address that received the note is also one of the sending addresses\n"
"}\n"
"\nExamples:\n"
@@ -3850,12 +3899,30 @@ UniValue z_listreceivedbyaddress(const UniValue& params, bool fHelp)
if (boost::get<libzcash::SproutPaymentAddress>(&zaddr) != nullptr) {
for (CSproutNotePlaintextEntry & entry : sproutEntries) {
UniValue obj(UniValue::VOBJ);
int nHeight = 0;
CTransaction tx;
uint256 hashBlock;
if (GetTransaction(entry.jsop.hash, tx, hashBlock, true)) {
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 {
fprintf(stderr,"block hash %s does not exist!\n", hashBlock.ToString().c_str() );
}
} else {
fprintf(stderr,"tx hash %s does not exist!\n", entry.jsop.hash.ToString().c_str() );
}
obj.push_back(Pair("txid", entry.jsop.hash.ToString()));
obj.push_back(Pair("amount", ValueFromAmount(CAmount(entry.plaintext.value()))));
std::string data(entry.plaintext.memo().begin(), entry.plaintext.memo().end());
obj.push_back(Pair("memo", HexStr(data)));
obj.push_back(Pair("jsindex", entry.jsop.js));
obj.push_back(Pair("jsoutindex", entry.jsop.n));
obj.push_back(Pair("rawconfirmations", entry.confirmations));
obj.push_back(Pair("confirmations", komodo_dpowconfs(nHeight, entry.confirmations)));
if (hasSpendingKey) {
obj.push_back(Pair("change", pwalletMain->IsNoteSproutChange(nullifierSet, entry.address, entry.jsop)));
}
@@ -3864,10 +3931,27 @@ UniValue z_listreceivedbyaddress(const UniValue& params, bool fHelp)
} else if (boost::get<libzcash::SaplingPaymentAddress>(&zaddr) != nullptr) {
for (SaplingNoteEntry & entry : saplingEntries) {
UniValue obj(UniValue::VOBJ);
int nHeight = 0;
CTransaction tx;
uint256 hashBlock;
if (GetTransaction(entry.op.hash, tx, hashBlock, true)) {
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 {
fprintf(stderr,"block hash %s does not exist!\n", hashBlock.ToString().c_str() );
}
} else {
fprintf(stderr,"tx hash %s does not exist!\n", entry.op.hash.ToString().c_str() );
}
obj.push_back(Pair("txid", entry.op.hash.ToString()));
obj.push_back(Pair("amount", ValueFromAmount(CAmount(entry.note.value()))));
obj.push_back(Pair("memo", HexStr(entry.memo)));
obj.push_back(Pair("outindex", (int)entry.op.n));
obj.push_back(Pair("rawconfirmations", entry.confirmations));
obj.push_back(Pair("confirmations", komodo_dpowconfs(nHeight, entry.confirmations)));
if (hasSpendingKey) {
obj.push_back(Pair("change", pwalletMain->IsNoteSaplingChange(nullifierSet, entry.address, entry.op)));
}
@@ -5233,6 +5317,7 @@ int32_t ensure_CCrequirements()
#include "../cc/CCGateways.h"
#include "../cc/CCPrices.h"
#include "../cc/CCHeir.h"
#include "../cc/CCMarmara.h"
UniValue CCaddress(struct CCcontract_info *cp,char *name,std::vector<unsigned char> &pubkey)
{
@@ -5423,17 +5508,17 @@ UniValue pegsaddress(const UniValue& params, bool fHelp)
return(CCaddress(cp,(char *)"Pegs",pubkey));
}
UniValue triggersaddress(const UniValue& params, bool fHelp)
UniValue marmaraaddress(const UniValue& params, bool fHelp)
{
struct CCcontract_info *cp,C; std::vector<unsigned char> pubkey;
cp = CCinit(&C,EVAL_TRIGGERS);
cp = CCinit(&C,EVAL_MARMARA);
if ( fHelp || params.size() > 1 )
throw runtime_error("triggersaddress [pubkey]\n");
throw runtime_error("Marmaraaddress [pubkey]\n");
if ( ensure_CCrequirements() < 0 )
throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n");
if ( params.size() == 1 )
pubkey = ParseHex(params[0].get_str().c_str());
return(CCaddress(cp,(char *)"Triggers",pubkey));
return(CCaddress(cp,(char *)"Marmara",pubkey));
}
UniValue paymentsaddress(const UniValue& params, bool fHelp)