From 31e466f6c7e37b903e640d039e2328ba045d2381 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 2 Jan 2019 19:10:10 -1100 Subject: [PATCH 1/9] Triggers -> Marmara stubs --- src/cc/CCcustom.cpp | 30 ++++++------- src/cc/eval.h | 2 +- src/cc/{triggers.cpp => marmara.cpp} | 66 ++++++++++++++-------------- src/importcoin.cpp | 4 +- src/rpc/server.cpp | 4 +- src/rpc/server.h | 2 +- src/wallet/rpcwallet.cpp | 8 ++-- 7 files changed, 58 insertions(+), 58 deletions(-) rename src/cc/{triggers.cpp => marmara.cpp} (73%) diff --git a/src/cc/CCcustom.cpp b/src/cc/CCcustom.cpp index 3e42109fc..7fdd1b920 100644 --- a/src/cc/CCcustom.cpp +++ b/src/cc/CCcustom.cpp @@ -27,7 +27,7 @@ #include "CCOracles.h" #include "CCPrices.h" #include "CCPegs.h" -#include "CCTriggers.h" +#include "CCMarmara.h" #include "CCPayments.h" #include "CCGateways.h" @@ -189,13 +189,13 @@ uint8_t PegsCCpriv[32] = { 0x52, 0x56, 0x4c, 0x78, 0x87, 0xf7, 0xa2, 0x39, 0xb0, #undef FUNCNAME #undef EVALCODE -// Triggers -#define FUNCNAME IsTriggersInput -#define EVALCODE EVAL_TRIGGERS -const char *TriggersCCaddr = "RGLSRDnUqTB43bYtRtNVgmwSSd1sun2te8"; -const char *TriggersNormaladdr = "RMN25Tn8NNzcyQDiQNuMp8UmwLMFd9thYc"; -char TriggersCChexstr[67] = { "03afc5be570d0ff419425cfcc580cc762ab82baad88c148f5b028d7db7bfeee61d" }; -uint8_t TriggersCCpriv[32] = { 0x7c, 0x0b, 0x54, 0x9b, 0x65, 0xd4, 0x89, 0x57, 0xdf, 0x05, 0xfe, 0xa2, 0x62, 0x41, 0xa9, 0x09, 0x0f, 0x2a, 0x6b, 0x11, 0x2c, 0xbe, 0xbd, 0x06, 0x31, 0x8d, 0xc0, 0xb9, 0x96, 0x76, 0x3f, 0x24 }; +// Marmara +#define FUNCNAME IsMarmaraInput +#define EVALCODE EVAL_MARMARA +const char *MarmaraCCaddr = "RGLSRDnUqTB43bYtRtNVgmwSSd1sun2te8"; +const char *MarmaraNormaladdr = "RMN25Tn8NNzcyQDiQNuMp8UmwLMFd9thYc"; +char MarmaraCChexstr[67] = { "03afc5be570d0ff419425cfcc580cc762ab82baad88c148f5b028d7db7bfeee61d" }; +uint8_t MarmaraCCpriv[32] = { 0x7c, 0x0b, 0x54, 0x9b, 0x65, 0xd4, 0x89, 0x57, 0xdf, 0x05, 0xfe, 0xa2, 0x62, 0x41, 0xa9, 0x09, 0x0f, 0x2a, 0x6b, 0x11, 0x2c, 0xbe, 0xbd, 0x06, 0x31, 0x8d, 0xc0, 0xb9, 0x96, 0x76, 0x3f, 0x24 }; #include "CCcustom.inc" #undef FUNCNAME #undef EVALCODE @@ -323,13 +323,13 @@ struct CCcontract_info *CCinit(struct CCcontract_info *cp, uint8_t evalcode) cp->validate = PegsValidate; cp->ismyvin = IsPegsInput; break; - case EVAL_TRIGGERS: - strcpy(cp->unspendableCCaddr,TriggersCCaddr); - strcpy(cp->normaladdr,TriggersNormaladdr); - strcpy(cp->CChexstr,TriggersCChexstr); - memcpy(cp->CCpriv,TriggersCCpriv,32); - cp->validate = TriggersValidate; - cp->ismyvin = IsTriggersInput; + case EVAL_MARMARA: + strcpy(cp->unspendableCCaddr,MarmaraCCaddr); + strcpy(cp->normaladdr,MarmaraNormaladdr); + strcpy(cp->CChexstr,MarmaraCChexstr); + memcpy(cp->CCpriv,MarmaraCCpriv,32); + cp->validate = MarmaraValidate; + cp->ismyvin = IsMarmaraInput; break; case EVAL_PAYMENTS: strcpy(cp->unspendableCCaddr,PaymentsCCaddr); diff --git a/src/cc/eval.h b/src/cc/eval.h index 9c6a050b7..87b98349b 100644 --- a/src/cc/eval.h +++ b/src/cc/eval.h @@ -53,7 +53,7 @@ EVAL(EVAL_ORACLES, 0xec) \ EVAL(EVAL_PRICES, 0xed) \ EVAL(EVAL_PEGS, 0xee) \ - EVAL(EVAL_TRIGGERS, 0xef) \ + EVAL(EVAL_MARMARA, 0xef) \ EVAL(EVAL_PAYMENTS, 0xf0) \ EVAL(EVAL_GATEWAYS, 0xf1) diff --git a/src/cc/triggers.cpp b/src/cc/marmara.cpp similarity index 73% rename from src/cc/triggers.cpp rename to src/cc/marmara.cpp index a98e4da02..4bbccee4a 100644 --- a/src/cc/triggers.cpp +++ b/src/cc/marmara.cpp @@ -13,16 +13,16 @@ * * ******************************************************************************/ -#include "CCTriggers.h" +#include "CCMarmara.h" /* - Triggers CC is a building block CC that allows creation of event -> action processing, where events are defined during trigger creation and actions to be mostly done via payments, but by making payments to other CC contracts, it can be used to invoke other CC contracts + Marmara CC is for the MARMARA project */ // start of consensus code -int64_t IsTriggersvout(struct CCcontract_info *cp,const CTransaction& tx,int32_t v) +int64_t IsMarmaravout(struct CCcontract_info *cp,const CTransaction& tx,int32_t v) { char destaddr[64]; if ( tx.vout[v].scriptPubKey.IsPayToCryptoCondition() != 0 ) @@ -33,7 +33,7 @@ int64_t IsTriggersvout(struct CCcontract_info *cp,const CTransaction& tx,int32_t return(0); } -bool TriggersExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx,int32_t minage,uint64_t txfee) +bool MarmaraExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx,int32_t minage,uint64_t txfee) { static uint256 zerohash; CTransaction vinTx; uint256 hashBlock,activehash; int32_t i,numvins,numvouts; int64_t inputs=0,outputs=0,assetoshis; @@ -51,8 +51,8 @@ bool TriggersExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransacti { //fprintf(stderr,"vini.%d check hash and vout\n",i); if ( hashBlock == zerohash ) - return eval->Invalid("cant Triggers from mempool"); - if ( (assetoshis= IsTriggersvout(cp,vinTx,tx.vin[i].prevout.n)) != 0 ) + return eval->Invalid("cant Marmara from mempool"); + if ( (assetoshis= IsMarmaravout(cp,vinTx,tx.vin[i].prevout.n)) != 0 ) inputs += assetoshis; } } @@ -60,7 +60,7 @@ bool TriggersExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransacti for (i=0; i origpubkey; CTransaction vintx; int32_t vout,n = 0; @@ -126,7 +126,7 @@ int64_t AddTriggersInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CP // no need to prevent dup if ( GetTransaction(txid,vintx,hashBlock,false) != 0 ) { - if ( (nValue= IsTriggersvout(cp,vintx,vout)) > 1000000 && myIsutxo_spentinmempool(txid,vout) == 0 ) + if ( (nValue= IsMarmaravout(cp,vintx,vout)) > 1000000 && myIsutxo_spentinmempool(txid,vout) == 0 ) { if ( total != 0 && maxinputs != 0 ) mtx.vin.push_back(CTxIn(txid,vout,CScript())); @@ -141,28 +141,28 @@ int64_t AddTriggersInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CP return(totalinputs); } -std::string TriggersGet(uint64_t txfee,int64_t nValue) +std::string MarmaraGet(uint64_t txfee,int64_t nValue) { CMutableTransaction tmpmtx,mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey mypk,Triggerspk; int64_t inputs,CCchange=0; struct CCcontract_info *cp,C; std::string rawhex; uint32_t j; int32_t i,len; uint8_t buf[32768]; bits256 hash; - cp = CCinit(&C,EVAL_TRIGGERS); + CPubKey mypk,Marmarapk; int64_t inputs,CCchange=0; struct CCcontract_info *cp,C; std::string rawhex; uint32_t j; int32_t i,len; uint8_t buf[32768]; bits256 hash; + cp = CCinit(&C,EVAL_MARMARA); if ( txfee == 0 ) txfee = 10000; - Triggerspk = GetUnspendable(cp,0); + Marmarapk = GetUnspendable(cp,0); mypk = pubkey2pk(Mypubkey()); - if ( (inputs= AddTriggersInputs(cp,mtx,Triggerspk,nValue+txfee,60)) > 0 ) + if ( (inputs= AddMarmaraInputs(cp,mtx,Marmarapk,nValue+txfee,60)) > 0 ) { if ( inputs > nValue ) CCchange = (inputs - nValue - txfee); if ( CCchange != 0 ) - mtx.vout.push_back(MakeCC1vout(EVAL_TRIGGERS,CCchange,Triggerspk)); + mtx.vout.push_back(MakeCC1vout(EVAL_MARMARA,CCchange,Marmarapk)); mtx.vout.push_back(CTxOut(nValue,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); fprintf(stderr,"start at %u\n",(uint32_t)time(NULL)); j = rand() & 0xfffffff; for (i=0; i<1000000; i++,j++) { tmpmtx = mtx; - rawhex = FinalizeCCTx(-1LL,cp,tmpmtx,mypk,txfee,CScript() << OP_RETURN << E_MARSHAL(ss << (uint8_t)EVAL_TRIGGERS << (uint8_t)'G' << j)); + rawhex = FinalizeCCTx(-1LL,cp,tmpmtx,mypk,txfee,CScript() << OP_RETURN << E_MARSHAL(ss << (uint8_t)EVAL_MARMARA << (uint8_t)'G' << j)); if ( (len= (int32_t)rawhex.size()) > 0 && len < 65536 ) { len >>= 1; @@ -178,37 +178,37 @@ std::string TriggersGet(uint64_t txfee,int64_t nValue) } fprintf(stderr,"couldnt generate valid txid %u\n",(uint32_t)time(NULL)); return(""); - } else fprintf(stderr,"cant find Triggers inputs\n"); + } else fprintf(stderr,"cant find Marmara inputs\n"); return(""); } -std::string TriggersFund(uint64_t txfee,int64_t funds) +std::string MarmaraFund(uint64_t txfee,int64_t funds) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey mypk,Triggerspk; CScript opret; struct CCcontract_info *cp,C; - cp = CCinit(&C,EVAL_TRIGGERS); + CPubKey mypk,Marmarapk; CScript opret; struct CCcontract_info *cp,C; + cp = CCinit(&C,EVAL_MARMARA); if ( txfee == 0 ) txfee = 10000; mypk = pubkey2pk(Mypubkey()); - Triggerspk = GetUnspendable(cp,0); + Marmarapk = GetUnspendable(cp,0); if ( AddNormalinputs(mtx,mypk,funds+txfee,64) > 0 ) { - mtx.vout.push_back(MakeCC1vout(EVAL_TRIGGERS,funds,Triggerspk)); + mtx.vout.push_back(MakeCC1vout(EVAL_MARMARA,funds,Marmarapk)); return(FinalizeCCTx(0,cp,mtx,mypk,txfee,opret)); } return(""); } -UniValue TriggersInfo() +UniValue MarmaraInfo() { UniValue result(UniValue::VOBJ); char numstr[64]; CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey Triggerspk; struct CCcontract_info *cp,C; int64_t funding; + CPubKey Marmarapk; struct CCcontract_info *cp,C; int64_t funding; result.push_back(Pair("result","success")); - result.push_back(Pair("name","Triggers")); - cp = CCinit(&C,EVAL_TRIGGERS); - Triggerspk = GetUnspendable(cp,0); - funding = AddTriggersInputs(cp,mtx,Triggerspk,0,0); + result.push_back(Pair("name","Marmara")); + cp = CCinit(&C,EVAL_MARMARA); + Marmarapk = GetUnspendable(cp,0); + funding = AddMarmaraInputs(cp,mtx,Marmarapk,0,0); sprintf(numstr,"%.8f",(double)funding/COIN); result.push_back(Pair("funding",numstr)); return(result); diff --git a/src/importcoin.cpp b/src/importcoin.cpp index 010fbeb7d..39ff01d68 100644 --- a/src/importcoin.cpp +++ b/src/importcoin.cpp @@ -68,13 +68,13 @@ bool UnmarshalBurnTx(const CTransaction &burnTx, std::string &targetSymbol, uint if (burnTx.vout.size() == 0) return false; GetOpReturnData(burnTx.vout.back().scriptPubKey, burnOpret); E_UNMARSHAL(burnOpret, ss >> VARINT(ccid)); - if ( ccid != 0xffffffff ) + /*if ( ccid != 0xffffffff ) { return E_UNMARSHAL(burnOpret, ss >> VARINT(*targetCCid); ss >> targetSymbol; ss >> payoutsHash); } - else + else*/ { return E_UNMARSHAL(burnOpret, ss >> VARINT(*targetCCid); ss >> targetSymbol; diff --git a/src/rpc/server.cpp b/src/rpc/server.cpp index acd8c4bb8..2a3e9afcf 100644 --- a/src/rpc/server.cpp +++ b/src/rpc/server.cpp @@ -441,8 +441,8 @@ static const CRPCCommand vRPCCommands[] = // Pegs { "pegs", "pegsaddress", &pegsaddress, true }, - // Triggers - { "triggers", "triggersaddress", &triggersaddress, true }, + // Marmara + { "marmara", "Marmaraaddress", &Marmaraaddress, true }, // Payments { "payments", "paymentsaddress", &paymentsaddress, true }, diff --git a/src/rpc/server.h b/src/rpc/server.h index f5b28538c..3614f0232 100644 --- a/src/rpc/server.h +++ b/src/rpc/server.h @@ -271,7 +271,7 @@ extern UniValue pricesbet(const UniValue& params, bool fHelp); extern UniValue pricesstatus(const UniValue& params, bool fHelp); extern UniValue pricesfinish(const UniValue& params, bool fHelp); extern UniValue pegsaddress(const UniValue& params, bool fHelp); -extern UniValue triggersaddress(const UniValue& params, bool fHelp); +extern UniValue marmaraaddress(const UniValue& params, bool fHelp); extern UniValue paymentsaddress(const UniValue& params, bool fHelp); extern UniValue gatewaysaddress(const UniValue& params, bool fHelp); extern UniValue gatewayslist(const UniValue& params, bool fHelp); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index c3faff238..1e7ee5462 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5291,17 +5291,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 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) From 520964ae40a535472aeb7cf9258850e98baa639c Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 2 Jan 2019 19:11:26 -1100 Subject: [PATCH 2/9] marmara.cpp --- src/Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Makefile.am b/src/Makefile.am index 874c3a8b4..e6cc5d756 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -300,7 +300,7 @@ libbitcoin_server_a_SOURCES = \ cc/oracles.cpp \ cc/prices.cpp \ cc/pegs.cpp \ - cc/triggers.cpp \ + cc/marmara.cpp \ cc/payments.cpp \ cc/gateways.cpp \ cc/channels.cpp \ From 6392d7f9a05865b0b6fb8745c113e67e6f9fb305 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 2 Jan 2019 19:13:02 -1100 Subject: [PATCH 3/9] Marmara files --- src/cc/{CCTriggers.h => CCMarmara.h} | 4 ++-- src/wallet/rpcwallet.cpp | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) rename src/cc/{CCTriggers.h => CCMarmara.h} (90%) diff --git a/src/cc/CCTriggers.h b/src/cc/CCMarmara.h similarity index 90% rename from src/cc/CCTriggers.h rename to src/cc/CCMarmara.h index a75806dce..45fda83bd 100644 --- a/src/cc/CCTriggers.h +++ b/src/cc/CCMarmara.h @@ -19,9 +19,9 @@ #include "CCinclude.h" -bool TriggersValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); +bool MarmaraValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); // CCcustom -UniValue TriggersInfo(); +UniValue MarmaraInfo(); #endif diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 1e7ee5462..45cc99b0f 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5111,6 +5111,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 &pubkey) { From 6a1259ba5b2a8a73e8d46a916c7dcec7ee1124ef Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 2 Jan 2019 19:17:55 -1100 Subject: [PATCH 4/9] marmaraaddress --- src/rpc/server.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rpc/server.cpp b/src/rpc/server.cpp index 2a3e9afcf..61b83fbd7 100644 --- a/src/rpc/server.cpp +++ b/src/rpc/server.cpp @@ -442,7 +442,7 @@ static const CRPCCommand vRPCCommands[] = { "pegs", "pegsaddress", &pegsaddress, true }, // Marmara - { "marmara", "Marmaraaddress", &Marmaraaddress, true }, + { "marmara", "Marmaraaddress", &marmaraaddress, true }, // Payments { "payments", "paymentsaddress", &paymentsaddress, true }, From f24ae214d220ec7ba9cab43192d5dea5fbd30710 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Sat, 5 Jan 2019 19:24:14 +0100 Subject: [PATCH 5/9] Add dpowconfs to z_listunspent + listreceivedbyaddress and other small fixes --- src/rpc/blockchain.cpp | 15 +++++++++------ src/rpc/rawtransaction.cpp | 9 ++++++--- src/wallet/rpcwallet.cpp | 21 +++++++++++++++++---- 3 files changed, 32 insertions(+), 13 deletions(-) diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index 8e08056df..c210e3099 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -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)); } diff --git a/src/rpc/rawtransaction.cpp b/src/rpc/rawtransaction.cpp index 067471c2c..5ab040711 100644 --- a/src/rpc/rawtransaction.cpp +++ b/src/rpc/rawtransaction.cpp @@ -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" diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 45cc99b0f..f179ea45a 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -1435,11 +1435,13 @@ struct tallyitem int nConf; vector txids; bool fIsWatchonly; + int nHeight; tallyitem() { nAmount = 0; nConf = std::numeric_limits::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::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::max() ? 0 : nConf))); + obj.push_back(Pair("rawconfirmations", (nConf == std::numeric_limits::max() ? 0 : nConf))); + obj.push_back(Pair("confirmations", (nConf == std::numeric_limits::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::max() ? 0 : nConf))); + obj.push_back(Pair("rawconfirmations", (nConf == std::numeric_limits::max() ? 0 : nConf))); + obj.push_back(Pair("confirmations", (nConf == std::numeric_limits::max() ? 0 : komodo_dpowconfs(nHeight, nConf)))); ret.push_back(obj); } } @@ -2957,7 +2966,9 @@ UniValue z_listunspent(const UniValue& params, bool fHelp) 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)); + int nHeight = mapBlockIndex[entry.jsop.hash]->GetHeight(); + 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)); obj.push_back(Pair("spendable", hasSproutSpendingKey)); obj.push_back(Pair("address", EncodePaymentAddress(entry.address))); @@ -2974,7 +2985,9 @@ 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 = mapBlockIndex[entry.op.hash]->GetHeight(); + 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(entry.address), ivk); From dda20b2760790a098bbfb94fdf792139010d18a7 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Sun, 6 Jan 2019 01:39:04 +0100 Subject: [PATCH 6/9] 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; From 5070f4397ab7718937b43fdf4661461499209f1c Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Sat, 5 Jan 2019 17:02:20 -0800 Subject: [PATCH 7/9] cleanup --- src/wallet/rpcwallet.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index ccecb3794..f3159a94d 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -3002,7 +3002,6 @@ 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)); - // this is a txid hash but needs to be block hash int nHeight = 0; CTransaction tx; uint256 hashBlock; From 18b0a92c3ed23740a8541b2895c2cf6a2275d1de Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Sun, 6 Jan 2019 09:46:22 -0800 Subject: [PATCH 8/9] Add confirmations to z_listreceivedbyaddress --- src/wallet/rpcwallet.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index f3159a94d..5c4e21bfe 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -3747,7 +3747,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" @@ -3798,6 +3802,7 @@ UniValue z_listreceivedbyaddress(const UniValue& params, bool fHelp) 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("confirmations", entry.confirmations)); if (hasSpendingKey) { obj.push_back(Pair("change", pwalletMain->IsNoteSproutChange(nullifierSet, entry.address, entry.jsop))); } @@ -3810,6 +3815,7 @@ UniValue z_listreceivedbyaddress(const UniValue& params, bool fHelp) 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("confirmations", entry.confirmations)); if (hasSpendingKey) { obj.push_back(Pair("change", pwalletMain->IsNoteSaplingChange(nullifierSet, entry.address, entry.op))); } From 5d5af91e5d19fdb9f6f00da74934e105d02fa41e Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Sun, 6 Jan 2019 14:00:09 -0800 Subject: [PATCH 9/9] Add dpowconfs to z_listreceivedbyaddress --- 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 5c4e21bfe..74231a58b 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -3796,13 +3796,30 @@ UniValue z_listreceivedbyaddress(const UniValue& params, bool fHelp) if (boost::get(&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("confirmations", entry.confirmations)); + 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))); } @@ -3811,11 +3828,27 @@ UniValue z_listreceivedbyaddress(const UniValue& params, bool fHelp) } else if (boost::get(&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("confirmations", entry.confirmations)); + 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))); }