diff --git a/qa/rpc-tests/cryptoconditions.py b/qa/rpc-tests/cryptoconditions.py index 68b381272..3b4700858 100755 --- a/qa/rpc-tests/cryptoconditions.py +++ b/qa/rpc-tests/cryptoconditions.py @@ -6,7 +6,7 @@ from test_framework.test_framework import BitcoinTestFramework from test_framework.authproxy import JSONRPCException from test_framework.util import assert_equal, assert_greater_than, \ - initialize_chain_clean, start_nodes, start_node, connect_nodes_bi, \ + initialize_chain_clean, initialize_chain, start_nodes, start_node, connect_nodes_bi, \ stop_nodes, sync_blocks, sync_mempools, wait_bitcoinds, rpc_port import time @@ -43,7 +43,7 @@ class CryptoConditionsTest (BitcoinTestFramework): '-ac_supply=5555555', '-ac_reward=10000000', '-pubkey=' + self.pubkey, - '-ac_cc=1', + '-ac_cc=2', '-whitelist=127.0.0.1', '-debug', '-daemon', @@ -68,7 +68,7 @@ class CryptoConditionsTest (BitcoinTestFramework): # basic sanity tests result = rpc.getwalletinfo() - assert_equal(result['txcount'], 101) + assert_greater_than(result['txcount'], 100) assert_greater_than(result['balance'], 0.0) balance = result['balance'] @@ -327,10 +327,10 @@ class CryptoConditionsTest (BitcoinTestFramework): print("Importing privkey") rpc.importprivkey(self.privkey) - self.run_faucet_tests() self.run_rewards_tests() self.run_dice_tests() self.run_token_tests() + self.run_faucet_tests() if __name__ == '__main__': diff --git a/src/cc/CCinclude.h b/src/cc/CCinclude.h index 761e64bcd..4795ead3c 100644 --- a/src/cc/CCinclude.h +++ b/src/cc/CCinclude.h @@ -28,7 +28,7 @@ #include #include -extern int32_t KOMODO_CONNECTING; +extern int32_t KOMODO_CONNECTING,KOMODO_CCACTIVATE; #define SMALLVAL 0.000000000000001 union _bits256 { uint8_t bytes[32]; uint16_t ushorts[16]; uint32_t uints[8]; uint64_t ulongs[4]; uint64_t txid; }; diff --git a/src/cc/CCutils.cpp b/src/cc/CCutils.cpp index 54a9a0225..a57197537 100644 --- a/src/cc/CCutils.cpp +++ b/src/cc/CCutils.cpp @@ -256,9 +256,11 @@ CPubKey GetUnspendable(struct CCcontract_info *cp,uint8_t *unspendablepriv) bool ProcessCC(struct CCcontract_info *cp,Eval* eval, std::vector paramsNull,const CTransaction &ctx, unsigned int nIn) { CTransaction createTx; uint256 assetid,assetid2,hashBlock; uint8_t funcid; int32_t height,i,n,from_mempool = 0; int64_t amount; std::vector origpubkey; + height = KOMODO_CONNECTING; if ( KOMODO_CONNECTING < 0 ) // always comes back with > 0 for final confirmation return(true); - height = KOMODO_CONNECTING; + if ( ASSETCHAINS_CC == 0 || height < KOMODO_CCACTIVATE ) + return eval->Invalid("CC are disabled or not active yet"); if ( (KOMODO_CONNECTING & (1<<30)) != 0 ) { from_mempool = 1; diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 8da052c86..dd9322eeb 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -15,6 +15,8 @@ #include "CCdice.h" +extern std::string CCerror; + // timeout /* @@ -663,6 +665,8 @@ int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbit { char coinaddr[64],str[65]; uint64_t sbits; int64_t nValue,totalinputs = 0; uint256 hash,txid,proof,hashBlock,fundingtxid; CScript fundingPubKey; CTransaction tx,vinTx; int32_t vout,first=0,n=0; uint8_t funcid; std::vector > unspentOutputs; + entropyval = 0; + entropytxid = zeroid; if ( GetTransaction(reffundingtxid,tx,hashBlock,false) != 0 && tx.vout.size() > 1 && ConstrainVout(tx.vout[0],1,cp->unspendableCCaddr,0) != 0 ) { fundingPubKey = tx.vout[1].scriptPubKey; @@ -741,20 +745,21 @@ int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbit bool DicePlanExists(CScript &fundingPubKey,uint256 &fundingtxid,struct CCcontract_info *cp,uint64_t refsbits,CPubKey dicepk,int64_t &minbet,int64_t &maxbet,int64_t &maxodds,int64_t &timeoutblocks) { - char CCaddr[64]; uint64_t sbits; uint256 txid,hashBlock; CTransaction tx; + char CCaddr[64]; uint64_t sbits=0; uint256 txid,hashBlock; CTransaction tx; std::vector > txids; GetCCaddress(cp,CCaddr,dicepk); SetCCtxids(txids,cp->normaladdr); if ( fundingtxid != zeroid ) // avoid scan unless creating new funding plan { + //fprintf(stderr,"check fundingtxid\n"); if ( GetTransaction(fundingtxid,tx,hashBlock,false) != 0 && tx.vout.size() > 1 && ConstrainVout(tx.vout[0],1,CCaddr,0) != 0 ) { if ( DecodeDiceFundingOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,sbits,minbet,maxbet,maxodds,timeoutblocks) == 'F' && sbits == refsbits ) { fundingPubKey = tx.vout[1].scriptPubKey; return(true); - } - } + } else fprintf(stderr,"error decoding opret or sbits mismatch %llx vs %llx\n",(long long)sbits,(long long)refsbits); + } else fprintf(stderr,"couldnt get funding tx\n"); return(false); } for (std::vector >::const_iterator it=txids.begin(); it!=txids.end(); it++) @@ -793,7 +798,7 @@ struct CCcontract_info *Diceinit(CScript &fundingPubKey,uint256 reffundingtxid,s else cmpflag = 1; if ( DicePlanExists(fundingPubKey,reffundingtxid,cp,sbits,dicepk,minbet,maxbet,maxodds,timeoutblocks) != cmpflag ) { - fprintf(stderr,"Dice plan (%s) already exists cmpflag.%d\n",planstr,cmpflag); + fprintf(stderr,"Dice plan (%s) exists.%d vs cmpflag.%d\n",planstr,!cmpflag,cmpflag); return(0); } return(cp); @@ -857,12 +862,23 @@ std::string DiceCreateFunding(uint64_t txfee,char *planstr,int64_t funds,int64_t CMutableTransaction mtx; uint256 zero; CScript fundingPubKey; CPubKey mypk,dicepk; int64_t a,b,c,d; uint64_t sbits; struct CCcontract_info *cp,C; if ( funds < 0 || minbet < 0 || maxbet < 0 || maxodds < 1 || maxodds > 9999 || timeoutblocks < 0 || timeoutblocks > 1440 ) { - fprintf(stderr,"negative parameter error\n"); + CCerror = "invalid parameter error"; + fprintf(stderr,"%s\n", CCerror.c_str() ); + return(""); + } + if ( funds < 100*COIN ) + { + CCerror = "dice plan needs at least 100 coins"; + fprintf(stderr,"%s\n", CCerror.c_str() ); return(""); } memset(&zero,0,sizeof(zero)); if ( (cp= Diceinit(fundingPubKey,zero,&C,planstr,txfee,mypk,dicepk,sbits,a,b,c,d)) == 0 ) + { + CCerror = "Diceinit error in create funding"; + fprintf(stderr,"%s\n", CCerror.c_str() ); return(""); + } if ( AddNormalinputs(mtx,mypk,funds+3*txfee,60) > 0 ) { mtx.vout.push_back(MakeCC1vout(cp->evalcode,funds,dicepk)); @@ -870,7 +886,8 @@ std::string DiceCreateFunding(uint64_t txfee,char *planstr,int64_t funds,int64_t mtx.vout.push_back(CTxOut(txfee,CScript() << ParseHex(HexStr(dicepk)) << OP_CHECKSIG)); return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodeDiceFundingOpRet('F',sbits,minbet,maxbet,maxodds,timeoutblocks))); } - fprintf(stderr,"cant find enough inputs\n"); + CCerror = "cant find enough inputs"; + fprintf(stderr,"%s\n", CCerror.c_str() ); return(""); } @@ -879,7 +896,8 @@ std::string DiceAddfunding(uint64_t txfee,char *planstr,uint256 fundingtxid,int6 CMutableTransaction mtx; CScript fundingPubKey,scriptPubKey; uint256 entropy,hentropy; CPubKey mypk,dicepk; uint64_t sbits; struct CCcontract_info *cp,C; int64_t minbet,maxbet,maxodds,timeoutblocks; if ( amount < 0 ) { - fprintf(stderr,"negative parameter\n"); + CCerror = "amount must be positive"; + fprintf(stderr,"%s\n", CCerror.c_str() ); return(""); } if ( (cp= Diceinit(fundingPubKey,fundingtxid,&C,planstr,txfee,mypk,dicepk,sbits,minbet,maxbet,maxodds,timeoutblocks)) == 0 ) @@ -905,31 +923,46 @@ std::string DiceAddfunding(uint64_t txfee,char *planstr,uint256 fundingtxid,int6 mtx.vout.push_back(MakeCC1vout(cp->evalcode,amount,dicepk)); mtx.vout.push_back(CTxOut(txfee,fundingPubKey)); return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodeDiceOpRet('E',sbits,fundingtxid,hentropy,zeroid))); - } else fprintf(stderr,"cant find enough inputs\n"); - } else fprintf(stderr,"only fund creator can add more funds (entropy)\n"); + } else { + CCerror = "cant find enough inputs"; + fprintf(stderr,"%s\n", CCerror.c_str() ); + } + } else { + CCerror = "only fund creator can add more funds (entropy)"; + fprintf(stderr,"%s\n", CCerror.c_str() ); + } return(""); } std::string DiceBet(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t bet,int32_t odds) { CMutableTransaction mtx; CScript fundingPubKey; CPubKey mypk,dicepk; uint64_t sbits,entropyval; int64_t funding,minbet,maxbet,maxodds,timeoutblocks; uint256 entropytxid,entropy,hentropy; struct CCcontract_info *cp,C; - if ( bet < 0 || odds < 1 || odds > 9999 ) + if ( bet < 0 ) { - fprintf(stderr,"negative parameter or odds too big error\n"); + CCerror = "bet must be positive"; + fprintf(stderr,"%s\n", CCerror.c_str() ); + return(""); + } + if ( odds < 1 || odds > 9999 ) + { + CCerror = "odds must be between 1 and 9999"; + fprintf(stderr,"%s\n", CCerror.c_str() ); return(""); } if ( (cp= Diceinit(fundingPubKey,fundingtxid,&C,planstr,txfee,mypk,dicepk,sbits,minbet,maxbet,maxodds,timeoutblocks)) == 0 ) return(""); if ( bet < minbet || bet > maxbet || odds > maxodds ) { - fprintf(stderr,"Dice plan %s illegal bet %.8f: minbet %.8f maxbet %.8f or odds %d vs max.%d\n",planstr,(double)bet/COIN,(double)minbet/COIN,(double)maxbet/COIN,(int32_t)odds,(int32_t)maxodds); + CCerror = strprintf("Dice plan %s illegal bet %.8f: minbet %.8f maxbet %.8f or odds %d vs max.%d\n",planstr,(double)bet/COIN,(double)minbet/COIN,(double)maxbet/COIN,(int32_t)odds,(int32_t)maxodds); + fprintf(stderr,"%s\n", CCerror.c_str() ); return(""); } if ( (funding= DicePlanFunds(entropyval,entropytxid,sbits,cp,dicepk,fundingtxid)) >= 2*bet*odds+txfee && entropyval != 0 ) { if ( myIsutxo_spentinmempool(entropytxid,0) != 0 ) { - fprintf(stderr,"entropy txid is spent\n"); + CCerror = "entropy txid is spent"; + fprintf(stderr,"%s\n", CCerror.c_str() ); return(""); } mtx.vin.push_back(CTxIn(entropytxid,0,CScript())); @@ -940,11 +973,13 @@ std::string DiceBet(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t bet mtx.vout.push_back(MakeCC1vout(cp->evalcode,bet,dicepk)); mtx.vout.push_back(CTxOut(txfee+odds,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodeDiceOpRet('B',sbits,fundingtxid,entropy,zeroid))); - } else fprintf(stderr,"cant find enough inputs %.8f note enough for %.8f\n",(double)funding/COIN,(double)bet/COIN); + } else fprintf(stderr,"cant find enough normal inputs for %.8f, plan funding %.8f\n",(double)bet/COIN,(double)funding/COIN); } if ( entropyval == 0 && funding != 0 ) - fprintf(stderr,"cant find dice entropy inputs\n"); - else fprintf(stderr,"cant find dice inputs\n"); + CCerror = "cant find dice entropy inputs"; + else + CCerror = "cant find dice input"; + fprintf(stderr,"%s\n", CCerror.c_str() ); return(""); } @@ -955,7 +990,8 @@ std::string DiceBetFinish(int32_t *resultp,uint64_t txfee,char *planstr,uint256 //char str[65]; fprintf(stderr,"DiceBetFinish.%s %s\n",planstr,uint256_str(str,bettxid)); if ( (cp= Diceinit(fundingPubKey,fundingtxid,&C,planstr,txfee,mypk,dicepk,sbits,minbet,maxbet,maxodds,timeoutblocks)) == 0 ) { - fprintf(stderr,"Diceinit error\n"); + CCerror = "Diceinit error in finish"; + fprintf(stderr,"%s\n", CCerror.c_str() ); return(""); } fundingpk = DiceFundingPk(fundingPubKey); @@ -970,7 +1006,8 @@ std::string DiceBetFinish(int32_t *resultp,uint64_t txfee,char *planstr,uint256 } if ( AddNormalinputs(mtx,mypk,txfee,1) == 0 ) { - fprintf(stderr,"no txfee inputs for win/lose\n"); + CCerror = "no txfee inputs for win/lose"; + fprintf(stderr,"%s\n", CCerror.c_str() ); return(""); } if ( GetTransaction(bettxid,betTx,hashBlock,false) != 0 && GetTransaction(betTx.vin[0].prevout.hash,entropyTx,hashBlock,false) != 0 ) @@ -984,7 +1021,8 @@ std::string DiceBetFinish(int32_t *resultp,uint64_t txfee,char *planstr,uint256 { if ( myIsutxo_spentinmempool(bettxid,0) != 0 || myIsutxo_spentinmempool(bettxid,1) != 0 ) { - fprintf(stderr,"bettxid already spent\n"); + CCerror = "bettxid already spent"; + fprintf(stderr,"%s\n", CCerror.c_str() ); return(""); } //fprintf(stderr,"iswin.%d matches\n",iswin); @@ -1010,7 +1048,8 @@ std::string DiceBetFinish(int32_t *resultp,uint64_t txfee,char *planstr,uint256 odds = (betTx.vout[2].nValue - txfee); if ( odds < 1 || odds > maxodds ) { - fprintf(stderr,"illegal odds.%d vs maxodds.%d\n",(int32_t)odds,(int32_t)maxodds); + CCerror = strprintf("illegal odds.%d vs maxodds.%d\n",(int32_t)odds,(int32_t)maxodds); + fprintf(stderr,"%s\n", CCerror.c_str() ); return(""); } CCchange = betTx.vout[0].nValue + betTx.vout[1].nValue; @@ -1024,7 +1063,8 @@ std::string DiceBetFinish(int32_t *resultp,uint64_t txfee,char *planstr,uint256 } else { - fprintf(stderr,"not enough inputs for %.8f\n",(double)fundsneeded/COIN); + CCerror = strprintf("not enough inputs for %.8f\n",(double)fundsneeded/COIN); + fprintf(stderr,"%s\n", CCerror.c_str() ); return(""); } mtx.vout.push_back(MakeCC1vout(cp->evalcode,CCchange,dicepk)); @@ -1053,7 +1093,8 @@ std::string DiceBetFinish(int32_t *resultp,uint64_t txfee,char *planstr,uint256 } } *resultp = -1; - fprintf(stderr,"couldnt find bettx or entropytx\n"); + CCerror = "couldnt find bettx or entropytx"; + fprintf(stderr,"%s\n", CCerror.c_str() ); return(""); } @@ -1062,7 +1103,8 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx CScript fundingPubKey,scriptPubKey; CTransaction spenttx,betTx; uint256 hash,proof,txid,hashBlock,spenttxid; CPubKey mypk,dicepk,fundingpk; struct CCcontract_info *cp,C; int32_t i,result,vout,n=0; int64_t minbet,maxbet,maxodds,timeoutblocks; uint64_t sbits; char coinaddr[64]; std::string res; if ( (cp= Diceinit(fundingPubKey,fundingtxid,&C,planstr,txfee,mypk,dicepk,sbits,minbet,maxbet,maxodds,timeoutblocks)) == 0 ) { - fprintf(stderr,"Diceinit error\n"); + CCerror = "Diceinit error in status"; + fprintf(stderr,"%s\n", CCerror.c_str() ); return(0.); } fundingpk = DiceFundingPk(fundingPubKey); diff --git a/src/cc/rewards.cpp b/src/cc/rewards.cpp index 61bcf5ca3..d3d374613 100644 --- a/src/cc/rewards.cpp +++ b/src/cc/rewards.cpp @@ -539,7 +539,8 @@ std::string RewardsAddfunding(uint64_t txfee,char *planstr,uint256 fundingtxid,i sbits = stringbits(planstr); if ( RewardsPlanExists(cp,sbits,rewardspk,a,b,c,d) == 0 ) { - fprintf(stderr,"Rewards plan %s doesnt exist\n",planstr); + CCerror = strprintf("Rewards plan %s doesnt exist\n",planstr); + fprintf(stderr,"%s\n",CCerror.c_str()); return(""); } sbits = stringbits(planstr); @@ -547,8 +548,12 @@ std::string RewardsAddfunding(uint64_t txfee,char *planstr,uint256 fundingtxid,i { mtx.vout.push_back(MakeCC1vout(cp->evalcode,amount,rewardspk)); return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodeRewardsOpRet('A',sbits,fundingtxid))); - } else fprintf(stderr,"cant find enough inputs\n"); - fprintf(stderr,"cant find fundingtxid\n"); + } else { + CCerror = "cant find enough inputs"; + fprintf(stderr,"%s\n", CCerror.c_str()); + } + CCerror = "cant find fundingtxid"; + fprintf(stderr,"%s\n", CCerror.c_str()); return(""); } @@ -557,7 +562,8 @@ std::string RewardsLock(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t CMutableTransaction mtx; CPubKey mypk,rewardspk; CScript opret; uint64_t lockedfunds,sbits,funding,APR,minseconds,maxseconds,mindeposit; struct CCcontract_info *cp,C; if ( deposit < txfee ) { - fprintf(stderr,"deposit amount less than txfee\n"); + CCerror = "deposit amount less than txfee"; + fprintf(stderr,"%s\n",CCerror.c_str()); return(""); } cp = CCinit(&C,EVAL_REWARDS); @@ -568,12 +574,14 @@ std::string RewardsLock(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t sbits = stringbits(planstr); if ( RewardsPlanExists(cp,sbits,rewardspk,APR,minseconds,maxseconds,mindeposit) == 0 ) { - fprintf(stderr,"Rewards plan %s doesnt exist\n",planstr); + CCerror = strprintf("Rewards plan %s doesnt exist\n",planstr); + fprintf(stderr,"%s\n",CCerror.c_str()); return(""); } if ( deposit < mindeposit ) { - fprintf(stderr,"Rewards plan %s deposit %.8f < mindeposit %.8f\n",planstr,(double)deposit/COIN,(double)mindeposit/COIN); + CCerror = strprintf("Rewards plan %s deposit %.8f < mindeposit %.8f\n",planstr,(double)deposit/COIN,(double)mindeposit/COIN); + fprintf(stderr,"%s\n",CCerror.c_str()); return(""); } if ( (funding= RewardsPlanFunds(lockedfunds,sbits,cp,rewardspk,fundingtxid)) >= deposit ) // arbitrary cmpval @@ -583,7 +591,10 @@ std::string RewardsLock(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t mtx.vout.push_back(MakeCC1vout(cp->evalcode,deposit,rewardspk)); mtx.vout.push_back(CTxOut(txfee,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodeRewardsOpRet('L',sbits,fundingtxid))); - } else fprintf(stderr,"cant find enough inputs %.8f not enough for %.8f, make sure you imported privkey for the -pubkey address\n",(double)funding/COIN,(double)deposit/COIN); + } else { + CCerror = strprintf("cant find enough inputs %.8f not enough for %.8f, make sure you imported privkey for the -pubkey address\n",(double)funding/COIN,(double)deposit/COIN); + fprintf(stderr,"%s\n",CCerror.c_str()); + } } fprintf(stderr,"cant find rewards inputs funding %.8f locked %.8f vs deposit %.8f\n",(double)funding/COIN,(double)lockedfunds/COIN,(double)deposit/COIN); return(""); diff --git a/src/komodo_globals.h b/src/komodo_globals.h index 2d64bc8fc..918e7c4f6 100644 --- a/src/komodo_globals.h +++ b/src/komodo_globals.h @@ -46,7 +46,7 @@ struct komodo_state KOMODO_STATES[34]; int COINBASE_MATURITY = _COINBASE_MATURITY;//100; int32_t KOMODO_MININGTHREADS = -1,IS_KOMODO_NOTARY,USE_EXTERNAL_PUBKEY,KOMODO_CHOSEN_ONE,ASSETCHAINS_SEED,KOMODO_ON_DEMAND,KOMODO_EXTERNAL_NOTARIES,KOMODO_PASSPORT_INITDONE,KOMODO_PAX,KOMODO_EXCHANGEWALLET,KOMODO_REWIND,KOMODO_CONNECTING = -1; -int32_t KOMODO_INSYNC,KOMODO_LASTMINED,prevKOMODO_LASTMINED,JUMBLR_PAUSE = 1; +int32_t KOMODO_INSYNC,KOMODO_LASTMINED,prevKOMODO_LASTMINED,KOMODO_CCACTIVATE,JUMBLR_PAUSE = 1; std::string NOTARY_PUBKEY,ASSETCHAINS_NOTARIES,ASSETCHAINS_OVERRIDE_PUBKEY,DONATION_PUBKEY; uint8_t NOTARY_PUBKEY33[33],ASSETCHAINS_OVERRIDE_PUBKEY33[33],ASSETCHAINS_PUBLIC,ASSETCHAINS_PRIVATE; diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 616f7ecaa..23e6b280e 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1544,6 +1544,7 @@ void komodo_args(char *argv0) } KOMODO_STOPAT = GetArg("-stopat",0); ASSETCHAINS_CC = GetArg("-ac_cc",0); + KOMODO_CCACTIVATE = GetArg("-ac_ccactivate",0); ASSETCHAINS_PUBLIC = GetArg("-ac_public",0); ASSETCHAINS_PRIVATE = GetArg("-ac_private",0); if ( (KOMODO_REWIND= GetArg("-rewind",0)) != 0 ) @@ -1650,6 +1651,11 @@ void komodo_args(char *argv0) //printf("created (%s)\n",fname); } else printf("error creating (%s)\n",fname); #endif + if ( KOMODO_CCACTIVATE != 0 && ASSETCHAINS_CC == 0 ) + { + ASSETCHAINS_CC = 2; + fprintf(stderr,"smart utxo CC contracts will activate at height.%d\n",KOMODO_CCACTIVATE); + } } else { diff --git a/src/main.h b/src/main.h index dfea318cb..fd418502a 100644 --- a/src/main.h +++ b/src/main.h @@ -104,8 +104,8 @@ static const unsigned int MAX_REJECT_MESSAGE_LENGTH = 111; //static const bool DEFAULT_ADDRESSINDEX = false; //static const bool DEFAULT_SPENTINDEX = false; -#define DEFAULT_ADDRESSINDEX (GetArg("-ac_cc",0) != 0) -#define DEFAULT_SPENTINDEX (GetArg("-ac_cc",0) != 0) +#define DEFAULT_ADDRESSINDEX (GetArg("-ac_cc",0) != 0 || GetArg("-ac_ccactivate",0) != 0) +#define DEFAULT_SPENTINDEX (GetArg("-ac_cc",0) != 0 || GetArg("-ac_ccactivate",0) != 0) static const bool DEFAULT_TIMESTAMPINDEX = false; static const unsigned int DEFAULT_DB_MAX_OPEN_FILES = 1000; static const bool DEFAULT_DB_COMPRESSION = true; diff --git a/src/pow.cpp b/src/pow.cpp index 6d218ef13..1291e445e 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -203,6 +203,7 @@ bool CheckProofOfWork(int32_t height,uint8_t *pubkey33,uint256 hash,unsigned int if ( ASSETCHAINS_SYMBOL[0] != 0 || height > 792000 ) { //if ( 0 && height > 792000 ) + if ( Params().NetworkIDString() != "regtest" ) { for (i=31; i>=0; i--) fprintf(stderr,"%02x",((uint8_t *)&hash)[i]); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 05faaeeb1..ffb75983a 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4836,6 +4836,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt int32_t ensure_CCrequirements() { extern uint8_t NOTARY_PUBKEY33[]; + CCerror = ""; if ( NOTARY_PUBKEY33[0] == 0 ) return(-1); else if ( GetBoolArg("-addressindex", DEFAULT_ADDRESSINDEX) == 0 ) @@ -4968,7 +4969,7 @@ UniValue tokenaddress(const UniValue& params, bool fHelp) UniValue rewardscreatefunding(const UniValue& params, bool fHelp) { - UniValue result(UniValue::VOBJ); char *name; uint64_t funds,APR,minseconds,maxseconds,mindeposit; std::string hex; + UniValue result(UniValue::VOBJ); char *name; int64_t funds,APR,minseconds,maxseconds,mindeposit; std::string hex; if ( fHelp || params.size() > 6 || params.size() < 2 ) throw runtime_error("rewardscreatefunding name amount APR mindays maxdays mindeposit\n"); if ( ensure_CCrequirements() < 0 ) @@ -4981,17 +4982,43 @@ UniValue rewardscreatefunding(const UniValue& params, bool fHelp) mindeposit = 100 * COIN; name = (char *)params[0].get_str().c_str(); funds = atof(params[1].get_str().c_str()) * COIN; + + if ( funds <= 0 ) { + ERR_RESULT("funds must be positive"); + return result; + } if ( params.size() > 2 ) { APR = atof(params[2].get_str().c_str()) * COIN; + if ( APR > REWARDSCC_MAXAPR ) + { + ERR_RESULT("25% APR is maximum"); + return result; + } if ( params.size() > 3 ) { minseconds = atol(params[3].get_str().c_str()) * 3600 * 24; + if ( minseconds < 0 ) { + ERR_RESULT("mindays must be non-negative"); + return result; + } if ( params.size() > 4 ) { maxseconds = atol(params[4].get_str().c_str()) * 3600 * 24; + if ( maxseconds <= 0 ) { + ERR_RESULT("maxdays must be positive"); + return result; + } + if ( maxseconds < minseconds ) { + ERR_RESULT("maxdays must be greater than mindays"); + return result; + } if ( params.size() > 5 ) mindeposit = atof(params[5].get_str().c_str()) * COIN; + if ( mindeposit <= 0 ) { + ERR_RESULT("mindeposit must be positive"); + return result; + } } } } @@ -5017,7 +5044,9 @@ UniValue rewardslock(const UniValue& params, bool fHelp) fundingtxid = Parseuint256((char *)params[1].get_str().c_str()); amount = atof(params[2].get_str().c_str()) * COIN; hex = RewardsLock(0,name,fundingtxid,amount); - if ( amount > 0 ) { + if ( CCerror != "" ){ + ERR_RESULT(CCerror); + } else if ( amount > 0 ) { if ( hex.size() > 0 ) { result.push_back(Pair("result", "success")); @@ -5040,7 +5069,9 @@ UniValue rewardsaddfunding(const UniValue& params, bool fHelp) fundingtxid = Parseuint256((char *)params[1].get_str().c_str()); amount = atof(params[2].get_str().c_str()) * COIN; hex = RewardsAddfunding(0,name,fundingtxid,amount); - if (amount > 0) { + if (CCerror != "") { + ERR_RESULT(CCerror); + } else if (amount > 0) { if ( hex.size() > 0 ) { result.push_back(Pair("result", "success")); @@ -5050,8 +5081,7 @@ UniValue rewardsaddfunding(const UniValue& params, bool fHelp) result.push_back(Pair("error", "couldnt create rewards addfunding transaction")); } } else { - result.push_back(Pair("result", "error")); - result.push_back(Pair("error", "funding amount must be positive")); + ERR_RESULT("funding amount must be positive"); } return(result); } @@ -5260,7 +5290,7 @@ UniValue dicebet(const UniValue& params, bool fHelp) { result.push_back(Pair("result", "success")); result.push_back(Pair("hex", hex)); - } else ERR_RESULT("couldnt create faucet get transaction"); + } else ERR_RESULT("couldnt create dice bet transaction. make sure your address has funds"); } else { ERR_RESULT("amount and odds must be positive"); } @@ -5280,7 +5310,10 @@ UniValue dicefinish(const UniValue& params, bool fHelp) fundingtxid = Parseuint256((char *)params[1].get_str().c_str()); bettxid = Parseuint256((char *)params[2].get_str().c_str()); hex = DiceBetFinish(&r,0,name,fundingtxid,bettxid,1); - if ( hex.size() > 0 ) + if ( CCerror != "" ) + { + ERR_RESULT(CCerror); + } else if ( hex.size() > 0 ) { result.push_back(Pair("result", "success")); result.push_back(Pair("hex", hex)); @@ -5303,6 +5336,10 @@ UniValue dicestatus(const UniValue& params, bool fHelp) if ( params.size() == 3 ) bettxid = Parseuint256((char *)params[2].get_str().c_str()); winnings = DiceStatus(0,name,fundingtxid,bettxid); + if (CCerror != "") { + ERR_RESULT(CCerror); + return result; + } result.push_back(Pair("result", "success")); if ( winnings >= 0. ) { @@ -5528,7 +5565,7 @@ UniValue tokencancelbid(const UniValue& params, bool fHelp) UniValue tokenfillbid(const UniValue& params, bool fHelp) { - UniValue result(UniValue::VOBJ); uint64_t fillamount; std::string hex; uint256 tokenid,bidtxid; + UniValue result(UniValue::VOBJ); int64_t fillamount; std::string hex; uint256 tokenid,bidtxid; if ( fHelp || params.size() != 3 ) throw runtime_error("tokenfillbid tokenid bidtxid fillamount\n"); if ( ensure_CCrequirements() < 0 ) @@ -5538,9 +5575,14 @@ UniValue tokenfillbid(const UniValue& params, bool fHelp) tokenid = Parseuint256((char *)params[0].get_str().c_str()); bidtxid = Parseuint256((char *)params[1].get_str().c_str()); fillamount = atol(params[2].get_str().c_str()); - if ( tokenid == zeroid || bidtxid == zeroid || fillamount <= 0 ) + if ( fillamount <= 0 ) { - result.push_back(Pair("error", "invalid parameter")); + ERR_RESULT("fillamount must be positive"); + return(result); + } + if ( tokenid == zeroid || bidtxid == zeroid ) + { + ERR_RESULT("must provide tokenid and bidtxid"); return(result); } hex = FillBuyOffer(0,tokenid,bidtxid,fillamount); @@ -5567,7 +5609,7 @@ UniValue tokenask(const UniValue& params, bool fHelp) askamount = (price * numtokens) * COIN + 0.0000000049999; if ( tokenid == zeroid || numtokens <= 0 || price <= 0 || askamount <= 0 ) { - result.push_back(Pair("error", "invalid parameter")); + ERR_RESULT("invalid parameter"); return(result); } hex = CreateSell(0,numtokens,tokenid,askamount); @@ -5638,7 +5680,7 @@ UniValue tokencancelask(const UniValue& params, bool fHelp) UniValue tokenfillask(const UniValue& params, bool fHelp) { - UniValue result(UniValue::VOBJ); uint64_t fillunits; std::string hex; uint256 tokenid,asktxid; + UniValue result(UniValue::VOBJ); int64_t fillunits; std::string hex; uint256 tokenid,asktxid; if ( fHelp || params.size() != 3 ) throw runtime_error("tokenfillask tokenid asktxid fillunits\n"); if ( ensure_CCrequirements() < 0 ) @@ -5648,7 +5690,12 @@ UniValue tokenfillask(const UniValue& params, bool fHelp) tokenid = Parseuint256((char *)params[0].get_str().c_str()); asktxid = Parseuint256((char *)params[1].get_str().c_str()); fillunits = atol(params[2].get_str().c_str()); - if ( tokenid == zeroid || asktxid == zeroid || fillunits <= 0 ) + if ( fillunits <= 0 ) + { + ERR_RESULT("fillunits must be positive"); + return(result); + } + if ( tokenid == zeroid || asktxid == zeroid ) { result.push_back(Pair("error", "invalid parameter")); return(result);