From 8ceece2007059e47d1a1e11128c19e18848ce6fa Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 31 Jan 2019 08:32:06 -1100 Subject: [PATCH 1/5] Marmaralock fix --- src/cc/marmara.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 0e301ba97..f10e88924 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -441,7 +441,7 @@ UniValue MarmaraLock(uint64_t txfee,int64_t amount,int32_t height) val -= txfee; else val = amount; if ( val > txfee ) - inputsum = AddNormalinputs2(mtx,val,CC_MAXVINS/2); + inputsum = AddNormalinputs(mtx,val,CC_MAXVINS/2); //fprintf(stderr,"normal inputs %.8f val %.8f\n",(double)inputsum/COIN,(double)val/COIN); mtx.vout.push_back(MakeCC1of2vout(EVAL_MARMARA,amount,Marmarapk,mypk)); if ( inputsum < amount+txfee ) From 02398a92e58380bf71731eebe2c58ad4e111c0f9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 31 Jan 2019 08:35:23 -1100 Subject: [PATCH 2/5] Addnormalinputs --- src/cc/marmara.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index f10e88924..be3c02432 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -441,7 +441,7 @@ UniValue MarmaraLock(uint64_t txfee,int64_t amount,int32_t height) val -= txfee; else val = amount; if ( val > txfee ) - inputsum = AddNormalinputs(mtx,val,CC_MAXVINS/2); + inputsum = AddNormalinputs(mtx,mypk,val,CC_MAXVINS/2); //fprintf(stderr,"normal inputs %.8f val %.8f\n",(double)inputsum/COIN,(double)val/COIN); mtx.vout.push_back(MakeCC1of2vout(EVAL_MARMARA,amount,Marmarapk,mypk)); if ( inputsum < amount+txfee ) From 7f042611e4f21d0d40722448b8d120e8e8bcb4dd Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 31 Jan 2019 08:59:09 -1100 Subject: [PATCH 3/5] Add rpcwallet locks --- src/cc/marmara.cpp | 2 +- src/wallet/rpcwallet.cpp | 46 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index be3c02432..0e301ba97 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -441,7 +441,7 @@ UniValue MarmaraLock(uint64_t txfee,int64_t amount,int32_t height) val -= txfee; else val = amount; if ( val > txfee ) - inputsum = AddNormalinputs(mtx,mypk,val,CC_MAXVINS/2); + inputsum = AddNormalinputs2(mtx,val,CC_MAXVINS/2); //fprintf(stderr,"normal inputs %.8f val %.8f\n",(double)inputsum/COIN,(double)val/COIN); mtx.vout.push_back(MakeCC1of2vout(EVAL_MARMARA,amount,Marmarapk,mypk)); if ( inputsum < amount+txfee ) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 74733e08c..f8fe7de20 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5390,6 +5390,8 @@ UniValue cclib(const UniValue& params, bool fHelp) throw runtime_error("cclib method [evalcode] [JSON params]\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"); + const CKeyStore& keystore = *pwalletMain; + LOCK2(cs_main, pwalletMain->cs_wallet); method = (char *)params[0].get_str().c_str(); if ( params.size() >= 2 ) { @@ -5625,6 +5627,8 @@ UniValue marmara_poolpayout(const UniValue& params, bool fHelp) } 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"); + const CKeyStore& keystore = *pwalletMain; + LOCK2(cs_main, pwalletMain->cs_wallet); perc = atof(params[0].get_str().c_str()) / 100.; firstheight = atol(params[1].get_str().c_str()); jsonstr = (char *)params[2].get_str().c_str(); @@ -5643,6 +5647,8 @@ UniValue marmara_receive(const UniValue& params, bool fHelp) } 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"); + const CKeyStore& keystore = *pwalletMain; + LOCK2(cs_main, pwalletMain->cs_wallet); memset(&batontxid,0,sizeof(batontxid)); senderpub = ParseHex(params[0].get_str().c_str()); if (senderpub.size()!= 33) @@ -5672,6 +5678,8 @@ UniValue marmara_issue(const UniValue& params, bool fHelp) } 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"); + const CKeyStore& keystore = *pwalletMain; + LOCK2(cs_main, pwalletMain->cs_wallet); receiverpub = ParseHex(params[0].get_str().c_str()); if (receiverpub.size()!= 33) { @@ -5701,6 +5709,8 @@ UniValue marmara_transfer(const UniValue& params, bool fHelp) ERR_RESULT("invalid receiverpub pubkey"); return result; } + const CKeyStore& keystore = *pwalletMain; + LOCK2(cs_main, pwalletMain->cs_wallet); amount = atof(params[1].get_str().c_str()) * COIN + 0.00000000499999; currency = params[2].get_str(); matures = atol(params[3].get_str().c_str()); @@ -5719,6 +5729,8 @@ UniValue marmara_info(const UniValue& params, bool fHelp) } 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"); + const CKeyStore& keystore = *pwalletMain; + LOCK2(cs_main, pwalletMain->cs_wallet); firstheight = atol(params[0].get_str().c_str()); lastheight = atol(params[1].get_str().c_str()); minamount = atof(params[2].get_str().c_str()) * COIN + 0.00000000499999; @@ -5749,6 +5761,8 @@ UniValue marmara_creditloop(const UniValue& params, bool fHelp) } 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"); + const CKeyStore& keystore = *pwalletMain; + LOCK2(cs_main, pwalletMain->cs_wallet); txid = Parseuint256((char *)params[0].get_str().c_str()); result = MarmaraCreditloop(txid); return(result); @@ -5765,6 +5779,8 @@ UniValue marmara_settlement(const UniValue& params, bool fHelp) } 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"); + const CKeyStore& keystore = *pwalletMain; + LOCK2(cs_main, pwalletMain->cs_wallet); batontxid = Parseuint256((char *)params[0].get_str().c_str()); result = MarmaraSettlement(0,batontxid); return(result); @@ -5777,6 +5793,8 @@ UniValue marmara_lock(const UniValue& params, bool fHelp) { throw runtime_error("marmaralock amount unlockht\n"); } + const CKeyStore& keystore = *pwalletMain; + LOCK2(cs_main, pwalletMain->cs_wallet); amount = atof(params[0].get_str().c_str()) * COIN + 0.00000000499999; if ( params.size() == 2 ) height = atol(params[1].get_str().c_str()); @@ -5790,6 +5808,8 @@ UniValue channelslist(const UniValue& params, bool fHelp) throw runtime_error("channelsinfo\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"); + const CKeyStore& keystore = *pwalletMain; + LOCK2(cs_main, pwalletMain->cs_wallet); return(ChannelsList()); } @@ -5800,6 +5820,8 @@ UniValue channelsinfo(const UniValue& params, bool fHelp) throw runtime_error("channelsinfo [opentxid]\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"); + const CKeyStore& keystore = *pwalletMain; + LOCK2(cs_main, pwalletMain->cs_wallet); opentxid=zeroid; if (params.size() > 0 && !params[0].isNull() && !params[0].get_str().empty()) opentxid = Parseuint256((char *)params[0].get_str().c_str()); @@ -6089,6 +6111,8 @@ UniValue rewardslist(const UniValue& params, bool fHelp) throw runtime_error("rewardslist\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"); + const CKeyStore& keystore = *pwalletMain; + LOCK2(cs_main, pwalletMain->cs_wallet); return(RewardsList()); } @@ -6099,6 +6123,8 @@ UniValue rewardsinfo(const UniValue& params, bool fHelp) throw runtime_error("rewardsinfo fundingtxid\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"); + const CKeyStore& keystore = *pwalletMain; + LOCK2(cs_main, pwalletMain->cs_wallet); fundingtxid = Parseuint256((char *)params[0].get_str().c_str()); return(RewardsInfo(fundingtxid)); } @@ -6109,6 +6135,8 @@ UniValue gatewayslist(const UniValue& params, bool fHelp) throw runtime_error("gatewayslist\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"); + const CKeyStore& keystore = *pwalletMain; + LOCK2(cs_main, pwalletMain->cs_wallet); return(GatewaysList()); } @@ -6119,6 +6147,8 @@ UniValue gatewaysinfo(const UniValue& params, bool fHelp) throw runtime_error("gatewaysinfo bindtxid\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"); + const CKeyStore& keystore = *pwalletMain; + LOCK2(cs_main, pwalletMain->cs_wallet); txid = Parseuint256((char *)params[0].get_str().c_str()); return(GatewaysInfo(txid)); } @@ -6314,6 +6344,8 @@ UniValue gatewayspendingdeposits(const UniValue& params, bool fHelp) throw runtime_error("gatewayspendingdeposits bindtxid coin\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"); + const CKeyStore& keystore = *pwalletMain; + LOCK2(cs_main, pwalletMain->cs_wallet); bindtxid = Parseuint256((char *)params[0].get_str().c_str()); coin = params[1].get_str(); return(GatewaysPendingDeposits(bindtxid,coin)); @@ -6326,6 +6358,8 @@ UniValue gatewayspendingwithdraws(const UniValue& params, bool fHelp) throw runtime_error("gatewayspendingwithdraws bindtxid coin\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"); + const CKeyStore& keystore = *pwalletMain; + LOCK2(cs_main, pwalletMain->cs_wallet); bindtxid = Parseuint256((char *)params[0].get_str().c_str()); coin = params[1].get_str(); return(GatewaysPendingWithdraws(bindtxid,coin)); @@ -6338,6 +6372,8 @@ UniValue gatewaysprocessed(const UniValue& params, bool fHelp) throw runtime_error("gatewaysprocessed bindtxid coin\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"); + const CKeyStore& keystore = *pwalletMain; + LOCK2(cs_main, pwalletMain->cs_wallet); bindtxid = Parseuint256((char *)params[0].get_str().c_str()); coin = params[1].get_str(); return(GatewaysProcessedWithdraws(bindtxid,coin)); @@ -6349,6 +6385,8 @@ UniValue oracleslist(const UniValue& params, bool fHelp) throw runtime_error("oracleslist\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"); + const CKeyStore& keystore = *pwalletMain; + LOCK2(cs_main, pwalletMain->cs_wallet); return(OraclesList()); } @@ -6359,6 +6397,8 @@ UniValue oraclesinfo(const UniValue& params, bool fHelp) throw runtime_error("oraclesinfo oracletxid\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"); + const CKeyStore& keystore = *pwalletMain; + LOCK2(cs_main, pwalletMain->cs_wallet); txid = Parseuint256((char *)params[0].get_str().c_str()); return(OracleInfo(txid)); } @@ -6414,6 +6454,8 @@ UniValue oraclessamples(const UniValue& params, bool fHelp) throw runtime_error("oraclessamples oracletxid batonutxo num\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"); + const CKeyStore& keystore = *pwalletMain; + LOCK2(cs_main, pwalletMain->cs_wallet); txid = Parseuint256((char *)params[0].get_str().c_str()); batontxid = Parseuint256((char *)params[1].get_str().c_str()); num = atoi((char *)params[2].get_str().c_str()); @@ -6931,6 +6973,8 @@ UniValue tokeninfo(const UniValue& params, bool fHelp) throw runtime_error("tokeninfo tokenid\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"); + const CKeyStore& keystore = *pwalletMain; + LOCK2(cs_main, pwalletMain->cs_wallet); tokenid = Parseuint256((char *)params[0].get_str().c_str()); return(TokenInfo(tokenid)); } @@ -6942,6 +6986,8 @@ UniValue tokenorders(const UniValue& params, bool fHelp) throw runtime_error("tokenorders [tokenid]\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"); + const CKeyStore& keystore = *pwalletMain; + LOCK2(cs_main, pwalletMain->cs_wallet); if (params.size() == 1) { tokenid = Parseuint256((char *)params[0].get_str().c_str()); if (tokenid == zeroid) From 6d4d25ca102b4cb55d582b0c8d07413c1ceb8300 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 31 Jan 2019 09:15:14 -1100 Subject: [PATCH 4/5] Test --- src/cc/CCtx.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index 48b5927a5..c9af64e59 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -579,7 +579,7 @@ int64_t AddNormalinputs2(CMutableTransaction &mtx,int64_t total,int32_t maxinput vout = (int32_t)it->first.index; if ( it->second.satoshis < threshold ) continue; - if ( myGetTransaction(txid,tx,hashBlock) != 0 && tx.vout.size() > 0 && vout < tx.vout.size() && tx.vout[vout].scriptPubKey.IsPayToCryptoCondition() == 0 ) + if ( GetTransaction(txid,tx,hashBlock,false) != 0 && tx.vout.size() > 0 && vout < tx.vout.size() && tx.vout[vout].scriptPubKey.IsPayToCryptoCondition() == 0 ) { //fprintf(stderr,"check %.8f to vins array.%d of %d %s/v%d\n",(double)out.tx->vout[out.i].nValue/COIN,n,maxutxos,txid.GetHex().c_str(),(int32_t)vout); if ( mtx.vin.size() > 0 ) From f3a93ed84b602d5db45e3ca5444be5d17f4a0d59 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 31 Jan 2019 09:18:28 -1100 Subject: [PATCH 5/5] CC_MAXVINS --- src/cc/CCtx.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index c9af64e59..d93185ca4 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -471,7 +471,7 @@ int32_t CC_vinselect(int32_t *aboveip,int64_t *abovep,int32_t *belowip,int64_t * int64_t AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,int64_t total,int32_t maxinputs) { - int32_t abovei,belowi,ind,vout,i,n = 0,maxutxos=64; int64_t sum,threshold,above,below; int64_t remains,nValue,totalinputs = 0; uint256 txid,hashBlock; std::vector vecOutputs; CTransaction tx; struct CC_utxo *utxos,*up; + int32_t abovei,belowi,ind,vout,i,n = 0,maxutxos=CC_MAXVINS; int64_t sum,threshold,above,below; int64_t remains,nValue,totalinputs = 0; uint256 txid,hashBlock; std::vector vecOutputs; CTransaction tx; struct CC_utxo *utxos,*up; #ifdef ENABLE_WALLET assert(pwalletMain != NULL); const CKeyStore& keystore = *pwalletMain; @@ -564,7 +564,7 @@ int64_t AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,int64_t total,int3 int64_t AddNormalinputs2(CMutableTransaction &mtx,int64_t total,int32_t maxinputs) { - int32_t abovei,belowi,ind,vout,i,n = 0,maxutxos=64; int64_t sum,threshold,above,below; int64_t remains,nValue,totalinputs = 0; char coinaddr[64]; uint256 txid,hashBlock; CTransaction tx; struct CC_utxo *utxos,*up; + int32_t abovei,belowi,ind,vout,i,n = 0,maxutxos=CC_MAXVINS; int64_t sum,threshold,above,below; int64_t remains,nValue,totalinputs = 0; char coinaddr[64]; uint256 txid,hashBlock; CTransaction tx; struct CC_utxo *utxos,*up; std::vector > unspentOutputs; utxos = (struct CC_utxo *)calloc(maxutxos,sizeof(*utxos)); threshold = total/(maxinputs+1); @@ -579,7 +579,7 @@ int64_t AddNormalinputs2(CMutableTransaction &mtx,int64_t total,int32_t maxinput vout = (int32_t)it->first.index; if ( it->second.satoshis < threshold ) continue; - if ( GetTransaction(txid,tx,hashBlock,false) != 0 && tx.vout.size() > 0 && vout < tx.vout.size() && tx.vout[vout].scriptPubKey.IsPayToCryptoCondition() == 0 ) + if ( myGetTransaction(txid,tx,hashBlock) != 0 && tx.vout.size() > 0 && vout < tx.vout.size() && tx.vout[vout].scriptPubKey.IsPayToCryptoCondition() == 0 ) { //fprintf(stderr,"check %.8f to vins array.%d of %d %s/v%d\n",(double)out.tx->vout[out.i].nValue/COIN,n,maxutxos,txid.GetHex().c_str(),(int32_t)vout); if ( mtx.vin.size() > 0 )