From 066c16e5f69aea4d1b08ce639b3c02fa82b55b3b Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 9 Aug 2018 19:06:05 -1100 Subject: [PATCH 1/8] segid print --- src/komodo_bitcoind.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 463901570..53dd21802 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1424,11 +1424,12 @@ int32_t komodo_is_PoSblock(int32_t slowflag,int32_t height,CBlock *pblock,arith_ isPoS = 2; // 2 means staking utxo validated if ( slowflag != 0 && height > 100 ) { + segid = -3; if ( pindex != 0 && pindex->segid == -2 && (segid= komodo_segid(1,height)) >= 0 ) { pindex->segid = segid; fprintf(stderr,"B set segid.%d <- %d\n",height,pindex->segid); - } else fprintf(stderr,"unexpected null pindex for slowflag set ht.%d\n",height); + } else fprintf(stderr,"unexpected null pindex for slowflag set ht.%d segid.%d:%d\n",height,pindex!=0?pindex->segid:-3,segid); } } } From 9e432c97adf3c7b411ca5d6739a2573dfe98ea6e Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 9 Aug 2018 19:08:20 -1100 Subject: [PATCH 2/8] -print --- src/komodo_bitcoind.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 53dd21802..ac76958c4 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1429,7 +1429,7 @@ int32_t komodo_is_PoSblock(int32_t slowflag,int32_t height,CBlock *pblock,arith_ { pindex->segid = segid; fprintf(stderr,"B set segid.%d <- %d\n",height,pindex->segid); - } else fprintf(stderr,"unexpected null pindex for slowflag set ht.%d segid.%d:%d\n",height,pindex!=0?pindex->segid:-3,segid); + } //else fprintf(stderr,"unexpected null pindex for slowflag set ht.%d segid.%d:%d\n",height,pindex!=0?pindex->segid:-3,segid); } } } From 278a61fd5e61309d1f8a0c1d5c73877295aa5a89 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 9 Aug 2018 19:23:40 -1100 Subject: [PATCH 3/8] uint64_t -> int64_t for coin values other than three --- src/cc/CCfaucet.h | 2 +- src/cc/CCinclude.h | 6 +++--- src/cc/dice.cpp | 4 ++-- src/cc/faucet.cpp | 14 +++++++------- src/cc/rewards.cpp | 14 +++++++------- 5 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/cc/CCfaucet.h b/src/cc/CCfaucet.h index b875bd133..f9b933255 100644 --- a/src/cc/CCfaucet.h +++ b/src/cc/CCfaucet.h @@ -24,7 +24,7 @@ bool FaucetValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx); // CCcustom -std::string FaucetFund(uint64_t txfee,uint64_t funds); +std::string FaucetFund(uint64_t txfee,int64_t funds); std::string FaucetGet(uint64_t txfee); UniValue FaucetInfo(); diff --git a/src/cc/CCinclude.h b/src/cc/CCinclude.h index a59a2325c..6a1a25b35 100644 --- a/src/cc/CCinclude.h +++ b/src/cc/CCinclude.h @@ -81,7 +81,7 @@ char *pubkey33_str(char *dest,uint8_t *pubkey33); uint256 Parseuint256(char *hexstr); CPubKey pubkey2pk(std::vector pubkey); bool GetCCaddress(struct CCcontract_info *cp,char *destaddr,CPubKey pk); -bool ConstrainVout(CTxOut vout,int32_t CCflag,char *cmpaddr,uint64_t nValue); +bool ConstrainVout(CTxOut vout,int32_t CCflag,char *cmpaddr,int64_t nValue); bool PreventCC(Eval* eval,const CTransaction &tx,int32_t preventCCvins,int32_t numvins,int32_t preventCCvouts,int32_t numvouts); bool Getscriptaddress(char *destaddr,const CScript &scriptPubKey); std::vector Mypubkey(); @@ -92,8 +92,8 @@ int64_t CCduration(int32_t &numblocks,uint256 txid); std::string FinalizeCCTx(uint64_t skipmask,struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey mypk,uint64_t txfee,CScript opret); void SetCCunspents(std::vector > &unspentOutputs,char *coinaddr); void SetCCtxids(std::vector > &addressIndex,char *coinaddr); -uint64_t AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,uint64_t total,int32_t maxinputs); -uint64_t CCutxovalue(char *coinaddr,uint256 utxotxid,int32_t utxovout); +int64_t AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,int64_t total,int32_t maxinputs); +int64_t CCutxovalue(char *coinaddr,uint256 utxotxid,int32_t utxovout); // curve25519 and sha256 bits256 curve25519_shared(bits256 privkey,bits256 otherpub); diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 8d8600fb6..e35f367f3 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -604,9 +604,9 @@ uint64_t AddDiceInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubK return(totalinputs); } -uint64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbits,struct CCcontract_info *cp,CPubKey dicepk,uint256 reffundingtxid) +int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbits,struct CCcontract_info *cp,CPubKey dicepk,uint256 reffundingtxid) { - char coinaddr[64],str[65]; uint64_t sbits,nValue,totalinputs = 0; uint256 hash,txid,proof,hashBlock,fundingtxid; CScript fundingPubKey; CTransaction tx,vinTx; int32_t vout,first=0,n=0; uint8_t funcid; + 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; if ( GetTransaction(reffundingtxid,tx,hashBlock,false) != 0 && tx.vout.size() > 1 && ConstrainVout(tx.vout[0],1,cp->unspendableCCaddr,0) != 0 ) { diff --git a/src/cc/faucet.cpp b/src/cc/faucet.cpp index b8b3b62cb..403b56c3e 100644 --- a/src/cc/faucet.cpp +++ b/src/cc/faucet.cpp @@ -28,7 +28,7 @@ // start of consensus code -uint64_t IsFaucetvout(struct CCcontract_info *cp,const CTransaction& tx,int32_t v) +int64_t IsFaucetvout(struct CCcontract_info *cp,const CTransaction& tx,int32_t v) { char destaddr[64]; if ( tx.vout[v].scriptPubKey.IsPayToCryptoCondition() != 0 ) @@ -42,7 +42,7 @@ uint64_t IsFaucetvout(struct CCcontract_info *cp,const CTransaction& tx,int32_t bool FaucetExactAmounts(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; uint64_t inputs=0,outputs=0,assetoshis; + CTransaction vinTx; uint256 hashBlock,activehash; int32_t i,numvins,numvouts; int64_t inputs=0,outputs=0,assetoshis; numvins = tx.vin.size(); numvouts = tx.vout.size(); for (i=0; i origpubkey; CTransaction vintx; int32_t vout,n = 0; + char coinaddr[64]; int64_t nValue,price,totalinputs = 0; uint256 txid,hashBlock; std::vector origpubkey; CTransaction vintx; int32_t vout,n = 0; std::vector > unspentOutputs; GetCCaddress(cp,coinaddr,pk); SetCCunspents(unspentOutputs,coinaddr); @@ -154,7 +154,7 @@ uint64_t AddFaucetInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPu std::string FaucetGet(uint64_t txfee) { - CMutableTransaction mtx; CPubKey mypk,faucetpk; CScript opret; uint64_t inputs,CCchange=0,nValue=COIN; struct CCcontract_info *cp,C; + CMutableTransaction mtx; CPubKey mypk,faucetpk; CScript opret; int64_t inputs,CCchange=0,nValue=COIN; struct CCcontract_info *cp,C; cp = CCinit(&C,EVAL_FAUCET); if ( txfee == 0 ) txfee = 10000; @@ -172,7 +172,7 @@ std::string FaucetGet(uint64_t txfee) return(0); } -std::string FaucetFund(uint64_t txfee,uint64_t funds) +std::string FaucetFund(uint64_t txfee,int64_t funds) { CMutableTransaction mtx; CPubKey mypk,faucetpk; CScript opret; struct CCcontract_info *cp,C; cp = CCinit(&C,EVAL_FAUCET); @@ -191,7 +191,7 @@ std::string FaucetFund(uint64_t txfee,uint64_t funds) UniValue FaucetInfo() { UniValue result(UniValue::VOBJ); char numstr[64]; - CMutableTransaction mtx; CPubKey faucetpk; struct CCcontract_info *cp,C; uint64_t funding; + CMutableTransaction mtx; CPubKey faucetpk; struct CCcontract_info *cp,C; int64_t funding; result.push_back(Pair("result","success")); result.push_back(Pair("name","Faucet")); cp = CCinit(&C,EVAL_FAUCET); diff --git a/src/cc/rewards.cpp b/src/cc/rewards.cpp index 6c5975e51..442f0e460 100644 --- a/src/cc/rewards.cpp +++ b/src/cc/rewards.cpp @@ -66,7 +66,7 @@ */ -uint64_t RewardsCalc(uint64_t amount,uint256 txid,uint64_t APR,uint64_t minseconds,uint64_t maxseconds,uint64_t mindeposit) +int64_t RewardsCalc(int64_t amount,uint256 txid,uint64_t APR,uint64_t minseconds,uint64_t maxseconds,uint64_t mindeposit) { int32_t numblocks; uint64_t duration,reward = 0; fprintf(stderr,"minseconds %llu maxseconds %llu\n",(long long)minseconds,(long long)maxseconds); @@ -137,7 +137,7 @@ uint8_t DecodeRewardsOpRet(uint256 txid,const CScript &scriptPubKey,uint64_t &sb return(0); } -uint64_t IsRewardsvout(struct CCcontract_info *cp,const CTransaction& tx,int32_t v,uint64_t refsbits,uint256 reffundingtxid) +int64_t IsRewardsvout(struct CCcontract_info *cp,const CTransaction& tx,int32_t v,uint64_t refsbits,uint256 reffundingtxid) { char destaddr[64]; uint64_t sbits; uint256 fundingtxid,txid; uint8_t funcid; int32_t numvouts; if ( tx.vout[v].scriptPubKey.IsPayToCryptoCondition() != 0 && (numvouts= (int32_t)tx.vout.size()) > 0 ) @@ -156,7 +156,7 @@ uint64_t IsRewardsvout(struct CCcontract_info *cp,const CTransaction& tx,int32_t bool RewardsExactAmounts(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx,uint64_t txfee,uint64_t refsbits,uint256 reffundingtxid) { static uint256 zerohash; - CTransaction vinTx; uint256 hashBlock; int32_t i,numvins,numvouts; uint64_t inputs=0,outputs=0,assetoshis; + CTransaction vinTx; uint256 hashBlock; int32_t i,numvins,numvouts; int64_t inputs=0,outputs=0,assetoshis; numvins = tx.vin.size(); numvouts = tx.vout.size(); for (i=0; i > unspentOutputs; @@ -314,9 +314,9 @@ uint64_t AddRewardsInputs(CScript &scriptPubKey,int32_t fundsflag,struct CCcontr return(totalinputs); } -uint64_t RewardsPlanFunds(uint64_t refsbits,struct CCcontract_info *cp,CPubKey pk,uint256 reffundingtxid) +int64_t RewardsPlanFunds(uint64_t refsbits,struct CCcontract_info *cp,CPubKey pk,uint256 reffundingtxid) { - char coinaddr[64]; uint64_t sbits,nValue,totalinputs = 0; uint256 txid,hashBlock,fundingtxid; CTransaction tx; int32_t vout; uint8_t funcid; + char coinaddr[64]; uint64_t sbits; int64_t nValue,totalinputs = 0; uint256 txid,hashBlock,fundingtxid; CTransaction tx; int32_t vout; uint8_t funcid; std::vector > unspentOutputs; GetCCaddress(cp,coinaddr,pk); SetCCunspents(unspentOutputs,coinaddr); @@ -513,7 +513,7 @@ std::string RewardsLock(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t std::string RewardsUnlock(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 locktxid) { - CMutableTransaction mtx; CTransaction tx; char coinaddr[64]; CPubKey mypk,rewardspk; CScript opret,scriptPubKey,ignore; uint256 hashBlock; uint64_t funding,sbits,reward=0,amount=0,inputs,CCchange=0,APR,minseconds,maxseconds,mindeposit; struct CCcontract_info *cp,C; + CMutableTransaction mtx; CTransaction tx; char coinaddr[64]; CPubKey mypk,rewardspk; CScript opret,scriptPubKey,ignore; uint256 hashBlock; uint64_t sbits,APR,minseconds,maxseconds,mindeposit; int64_t funding,reward=0,amount=0,inputs,CCchange=0; struct CCcontract_info *cp,C; cp = CCinit(&C,EVAL_REWARDS); if ( txfee == 0 ) txfee = 10000; From c4a4cd05ecb25144d21c0e72ca9ff1b2b836f38f Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 9 Aug 2018 19:25:25 -1100 Subject: [PATCH 4/8] Fix --- src/cc/CCtx.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index 072f86877..4bc081e15 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -23,7 +23,7 @@ By using -addressindex=1, it allows tracking of all the CC addresses */ -bool SignTx(CMutableTransaction &mtx,int32_t vini,uint64_t utxovalue,const CScript scriptPubKey) +bool SignTx(CMutableTransaction &mtx,int32_t vini,int64_t utxovalue,const CScript scriptPubKey) { #ifdef ENABLE_WALLET CTransaction txNewConst(mtx); SignatureData sigdata; const CKeyStore& keystore = *pwalletMain; @@ -41,7 +41,7 @@ bool SignTx(CMutableTransaction &mtx,int32_t vini,uint64_t utxovalue,const CScri std::string FinalizeCCTx(uint64_t CCmask,struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey mypk,uint64_t txfee,CScript opret) { auto consensusBranchId = CurrentEpochBranchId(chainActive.Height() + 1, Params().GetConsensus()); - CTransaction vintx; std::string hex; uint256 hashBlock; uint64_t mask=0,nmask=0,vinimask=0,utxovalues[64],change,normalinputs=0,totaloutputs=0,normaloutputs=0,totalinputs=0; int32_t i,utxovout,n,err = 0; char myaddr[64],destaddr[64],unspendable[64]; uint8_t *privkey,myprivkey[32],unspendablepriv[32],*msg32 = 0; CC *mycond=0,*othercond=0,*cond; CPubKey unspendablepk; + CTransaction vintx; std::string hex; uint256 hashBlock; uint64_t mask=0,nmask=0,vinimask=0; int64_t utxovalues[64],change,normalinputs=0,totaloutputs=0,normaloutputs=0,totalinputs=0; int32_t i,utxovout,n,err = 0; char myaddr[64],destaddr[64],unspendable[64]; uint8_t *privkey,myprivkey[32],unspendablepriv[32],*msg32 = 0; CC *mycond=0,*othercond=0,*cond; CPubKey unspendablepk; n = mtx.vout.size(); for (i=0; i > &addressIndex } } -uint64_t CCutxovalue(char *coinaddr,uint256 utxotxid,int32_t utxovout) +int64_t CCutxovalue(char *coinaddr,uint256 utxotxid,int32_t utxovout) { uint256 txid; std::vector > unspentOutputs; SetCCunspents(unspentOutputs,coinaddr); @@ -201,7 +201,7 @@ uint64_t CCutxovalue(char *coinaddr,uint256 utxotxid,int32_t utxovout) return(0); } -int32_t CC_vinselect(int32_t *aboveip,int64_t *abovep,int32_t *belowip,int64_t *belowp,struct CC_utxo utxos[],int32_t numunspents,uint64_t value) +int32_t CC_vinselect(int32_t *aboveip,int64_t *abovep,int32_t *belowip,int64_t *belowp,struct CC_utxo utxos[],int32_t numunspents,int64_t value) { int32_t i,abovei,belowi; int64_t above,below,gap,atx_value; abovei = belowi = -1; @@ -252,9 +252,9 @@ int32_t CC_vinselect(int32_t *aboveip,int64_t *abovep,int32_t *belowip,int64_t * //return(abovei >= 0 && above < (below>>1) ? abovei : belowi); } -uint64_t AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,uint64_t total,int32_t maxinputs) +int64_t AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,int64_t total,int32_t maxinputs) { - int32_t abovei,belowi,ind,vout,i,n = 0,maxutxos=1024; int64_t above,below; uint64_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=1024; int64_t above,below; int64_t remains,nValue,totalinputs = 0; uint256 txid,hashBlock; std::vector vecOutputs; CTransaction tx; struct CC_utxo *utxos,*up; #ifdef ENABLE_WALLET const CKeyStore& keystore = *pwalletMain; assert(pwalletMain != NULL); From 59da6d30dd7bf503a4e14c7fac94bf117e852a81 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 9 Aug 2018 19:31:25 -1100 Subject: [PATCH 5/8] REWARDSCC_MAXAPR and use int64_t for all coin values --- src/cc/CCauction.h | 4 ++-- src/cc/CClotto.h | 2 +- src/cc/CCrewards.h | 1 + src/cc/CCutils.cpp | 4 ++-- src/cc/auction.cpp | 18 +++++++++--------- src/cc/fsm.cpp | 12 ++++++------ src/cc/lotto.cpp | 14 +++++++------- src/cc/rewards.cpp | 7 +++++++ 8 files changed, 35 insertions(+), 27 deletions(-) diff --git a/src/cc/CCauction.h b/src/cc/CCauction.h index 52cd03d14..855cdf72e 100644 --- a/src/cc/CCauction.h +++ b/src/cc/CCauction.h @@ -23,8 +23,8 @@ bool AuctionValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx); -std::string AuctionPost(uint64_t txfee,uint256 itemhash,uint64_t minbid,char *title,char *description); -std::string AuctionBid(uint64_t txfee,uint256 itemhash,uint64_t amount); +std::string AuctionPost(uint64_t txfee,uint256 itemhash,int64_t minbid,char *title,char *description); +std::string AuctionBid(uint64_t txfee,uint256 itemhash,int64_t amount); std::string AuctionDeliver(uint64_t txfee,uint256 itemhash,uint256 bidtxid); #endif diff --git a/src/cc/CClotto.h b/src/cc/CClotto.h index a0354252e..41e3cb5b1 100644 --- a/src/cc/CClotto.h +++ b/src/cc/CClotto.h @@ -23,7 +23,7 @@ bool LottoValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx); -std::string LottoTicket(uint64_t txfee,uint64_t numtickets); +std::string LottoTicket(uint64_t txfee,int64_t numtickets); std::string LottoWinner(uint64_t txfee); #endif diff --git a/src/cc/CCrewards.h b/src/cc/CCrewards.h index e7db9d4a9..26819e9b9 100644 --- a/src/cc/CCrewards.h +++ b/src/cc/CCrewards.h @@ -20,6 +20,7 @@ #include "CCinclude.h" #define EVAL_REWARDS 0xe5 +#define REWARDSCC_MAXAPR (COIN/4) bool RewardsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx); UniValue RewardsInfo(uint256 rewardid); diff --git a/src/cc/CCutils.cpp b/src/cc/CCutils.cpp index 240e5b7e0..8cb06ab25 100644 --- a/src/cc/CCutils.cpp +++ b/src/cc/CCutils.cpp @@ -156,7 +156,7 @@ bool GetCCaddress(struct CCcontract_info *cp,char *destaddr,CPubKey pk) return(destaddr[0] != 0); } -bool ConstrainVout(CTxOut vout,int32_t CCflag,char *cmpaddr,uint64_t nValue) +bool ConstrainVout(CTxOut vout,int32_t CCflag,char *cmpaddr,int64_t nValue) { char destaddr[64]; if ( vout.scriptPubKey.IsPayToCryptoCondition() != CCflag ) @@ -255,7 +255,7 @@ 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 i,n; uint64_t amount; std::vector origpubkey; + CTransaction createTx; uint256 assetid,assetid2,hashBlock; uint8_t funcid; int32_t i,n; int64_t amount; std::vector origpubkey; // there is a chance CC tx is valid in mempool, but invalid when in block, so we cant filter duplicate requests. if any of the vins are spent, for example //txid = ctx.GetHash(); //if ( txid == cp->prevtxid ) diff --git a/src/cc/auction.cpp b/src/cc/auction.cpp index 7d8512ede..8265dfc45 100644 --- a/src/cc/auction.cpp +++ b/src/cc/auction.cpp @@ -21,7 +21,7 @@ // start of consensus code -uint64_t IsAuctionvout(struct CCcontract_info *cp,const CTransaction& tx,int32_t v) +int64_t IsAuctionvout(struct CCcontract_info *cp,const CTransaction& tx,int32_t v) { char destaddr[64]; if ( tx.vout[v].scriptPubKey.IsPayToCryptoCondition() != 0 ) @@ -35,7 +35,7 @@ uint64_t IsAuctionvout(struct CCcontract_info *cp,const CTransaction& tx,int32_t bool AuctionExactAmounts(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; uint64_t inputs=0,outputs=0,assetoshis; + CTransaction vinTx; uint256 hashBlock,activehash; int32_t i,numvins,numvouts; int64_t inputs=0,outputs=0,assetoshis; numvins = tx.vin.size(); numvouts = tx.vout.size(); for (i=0; i origpubkey; CTransaction vintx; int32_t n = 0; + char coinaddr[64]; int64_t nValue,price,totalinputs = 0; uint256 txid,hashBlock; std::vector origpubkey; CTransaction vintx; int32_t n = 0; std::vector > unspentOutputs; GetCCaddress(cp,coinaddr,pk); SetCCunspents(unspentOutputs,coinaddr); @@ -147,9 +147,9 @@ uint64_t AddAuctionInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CP return(totalinputs); } -std::string AuctionBid(uint64_t txfee,uint256 itemhash,uint64_t amount) +std::string AuctionBid(uint64_t txfee,uint256 itemhash,int64_t amount) { - CMutableTransaction mtx; CPubKey mypk,Auctionpk; CScript opret; uint64_t inputs,CCchange=0,nValue=COIN; struct CCcontract_info *cp,C; + CMutableTransaction mtx; CPubKey mypk,Auctionpk; CScript opret; int64_t inputs,CCchange=0,nValue=COIN; struct CCcontract_info *cp,C; cp = CCinit(&C,EVAL_AUCTION); if ( txfee == 0 ) txfee = 10000; @@ -169,7 +169,7 @@ std::string AuctionBid(uint64_t txfee,uint256 itemhash,uint64_t amount) std::string AuctionDeliver(uint64_t txfee,uint256 itemhash,uint256 bidtxid) { - CMutableTransaction mtx; CPubKey mypk,Auctionpk; CScript opret; uint64_t inputs,CCchange=0,nValue=COIN; struct CCcontract_info *cp,C; + CMutableTransaction mtx; CPubKey mypk,Auctionpk; CScript opret; int64_t inputs,CCchange=0,nValue=COIN; struct CCcontract_info *cp,C; cp = CCinit(&C,EVAL_AUCTION); if ( txfee == 0 ) txfee = 10000; @@ -187,9 +187,9 @@ std::string AuctionDeliver(uint64_t txfee,uint256 itemhash,uint256 bidtxid) return(0); } -std::string AuctionPost(uint64_t txfee,uint256 itemhash,uint64_t minbid,char *title,char *description) +std::string AuctionPost(uint64_t txfee,uint256 itemhash,int64_t minbid,char *title,char *description) { - CMutableTransaction mtx; CPubKey mypk,Auctionpk; uint64_t funds = 0; CScript opret; struct CCcontract_info *cp,C; + CMutableTransaction mtx; CPubKey mypk,Auctionpk; int64_t funds = 0; CScript opret; struct CCcontract_info *cp,C; cp = CCinit(&C,EVAL_AUCTION); if ( txfee == 0 ) txfee = 10000; diff --git a/src/cc/fsm.cpp b/src/cc/fsm.cpp index e3e112bf6..6141d8a4a 100644 --- a/src/cc/fsm.cpp +++ b/src/cc/fsm.cpp @@ -21,7 +21,7 @@ // start of consensus code -uint64_t IsFSMvout(struct CCcontract_info *cp,const CTransaction& tx,int32_t v) +int64_t IsFSMvout(struct CCcontract_info *cp,const CTransaction& tx,int32_t v) { char destaddr[64]; if ( tx.vout[v].scriptPubKey.IsPayToCryptoCondition() != 0 ) @@ -35,7 +35,7 @@ uint64_t IsFSMvout(struct CCcontract_info *cp,const CTransaction& tx,int32_t v) bool FSMExactAmounts(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; uint64_t inputs=0,outputs=0,assetoshis; + CTransaction vinTx; uint256 hashBlock,activehash; int32_t i,numvins,numvouts; int64_t inputs=0,outputs=0,assetoshis; numvins = tx.vin.size(); numvouts = tx.vout.size(); for (i=0; i origpubkey; CTransaction vintx; int32_t n = 0; + char coinaddr[64]; int64_t nValue,price,totalinputs = 0; uint256 txid,hashBlock; std::vector origpubkey; CTransaction vintx; int32_t n = 0; std::vector > unspentOutputs; GetCCaddress(cp,coinaddr,pk); SetCCunspents(unspentOutputs,coinaddr); @@ -154,7 +154,7 @@ std::string FSMList() std::string FSMCreate(uint64_t txfee,std::string name,std::string states) { - CMutableTransaction mtx; CPubKey mypk,fsmpk; CScript opret; uint64_t inputs,CCchange=0,nValue=COIN; struct CCcontract_info *cp,C; + CMutableTransaction mtx; CPubKey mypk,fsmpk; CScript opret; int64_t inputs,CCchange=0,nValue=COIN; struct CCcontract_info *cp,C; cp = CCinit(&C,EVAL_FSM); if ( txfee == 0 ) txfee = 10000; @@ -174,7 +174,7 @@ std::string FSMCreate(uint64_t txfee,std::string name,std::string states) std::string FSMInfo(uint256 fsmtxid) { - CMutableTransaction mtx; CPubKey mypk,fsmpk; uint64_t funds = 0; CScript opret; struct CCcontract_info *cp,C; + CMutableTransaction mtx; CPubKey mypk,fsmpk; int64_t funds = 0; CScript opret; struct CCcontract_info *cp,C; cp = CCinit(&C,EVAL_FSM); mypk = pubkey2pk(Mypubkey()); fsmpk = GetUnspendable(cp,0); diff --git a/src/cc/lotto.cpp b/src/cc/lotto.cpp index 0ed223c25..0d03d5e15 100644 --- a/src/cc/lotto.cpp +++ b/src/cc/lotto.cpp @@ -21,7 +21,7 @@ // start of consensus code -uint64_t IsLottovout(struct CCcontract_info *cp,const CTransaction& tx,int32_t v) +int64_t IsLottovout(struct CCcontract_info *cp,const CTransaction& tx,int32_t v) { char destaddr[64]; if ( tx.vout[v].scriptPubKey.IsPayToCryptoCondition() != 0 ) @@ -35,7 +35,7 @@ uint64_t IsLottovout(struct CCcontract_info *cp,const CTransaction& tx,int32_t v bool LottoExactAmounts(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; uint64_t inputs=0,outputs=0,assetoshis; + CTransaction vinTx; uint256 hashBlock,activehash; int32_t i,numvins,numvouts; int64_t inputs=0,outputs=0,assetoshis; numvins = tx.vin.size(); numvouts = tx.vout.size(); for (i=0; i origpubkey; CTransaction vintx; int32_t n = 0; + char coinaddr[64]; int64_t nValue,price,totalinputs = 0; uint256 txid,hashBlock; std::vector origpubkey; CTransaction vintx; int32_t n = 0; std::vector > unspentOutputs; GetCCaddress(cp,coinaddr,pk); SetCCunspents(unspentOutputs,coinaddr); @@ -147,9 +147,9 @@ uint64_t AddLottoInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPub return(totalinputs); } -std::string LottoTicket(uint64_t txfee,uint64_t numtickets) +std::string LottoTicket(uint64_t txfee,int64_t numtickets) { - CMutableTransaction mtx; CPubKey mypk,Lottopk; CScript opret; uint64_t inputs,CCchange=0,nValue=COIN; struct CCcontract_info *cp,C; + CMutableTransaction mtx; CPubKey mypk,Lottopk; CScript opret; int64_t inputs,CCchange=0,nValue=COIN; struct CCcontract_info *cp,C; cp = CCinit(&C,EVAL_LOTTO); if ( txfee == 0 ) txfee = 10000; @@ -169,7 +169,7 @@ std::string LottoTicket(uint64_t txfee,uint64_t numtickets) std::string LottoWinner(uint64_t txfee) { - CMutableTransaction mtx; CPubKey mypk,Lottopk; uint64_t winnings = 0; CScript opret; struct CCcontract_info *cp,C; + CMutableTransaction mtx; CPubKey mypk,Lottopk; int64_t winnings = 0; CScript opret; struct CCcontract_info *cp,C; cp = CCinit(&C,EVAL_LOTTO); if ( txfee == 0 ) txfee = 10000; diff --git a/src/cc/rewards.cpp b/src/cc/rewards.cpp index 442f0e460..64d95c846 100644 --- a/src/cc/rewards.cpp +++ b/src/cc/rewards.cpp @@ -205,6 +205,8 @@ bool RewardsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &t return eval->Invalid("cant find fundingtxid"); else if ( fundingTx.vout.size() > 0 && DecodeRewardsFundingOpRet(fundingTx.vout[fundingTx.vout.size()-1].scriptPubKey,sbits,APR,minseconds,maxseconds,mindeposit) != 'F' ) return eval->Invalid("fundingTx not valid"); + if ( APR > REWARDSCC_MAXAPR ) + return eval->Invalid("excessive APR"); switch ( funcid ) { case 'F': @@ -424,6 +426,11 @@ std::string RewardsCreateFunding(uint64_t txfee,char *planstr,int64_t funds,int6 fprintf(stderr,"negative parameter error\n"); return(0); } + if ( APR > REWARDSCC_MAXAPR ) + { + fprintf(stderr,"25% APR is maximum\n"); + return(0); + } cp = CCinit(&C,EVAL_REWARDS); if ( txfee == 0 ) txfee = 10000; From 984a9dc30a4e2609af080364e00a288e9c2b4614 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 9 Aug 2018 19:33:02 -1100 Subject: [PATCH 6/8] %% --- src/cc/rewards.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/rewards.cpp b/src/cc/rewards.cpp index 64d95c846..c84c73591 100644 --- a/src/cc/rewards.cpp +++ b/src/cc/rewards.cpp @@ -13,7 +13,7 @@ * * ******************************************************************************/ -#include "CCinclude.h" +#include "CCrewards.h" /* The rewards CC contract is initially for OOT, which needs this functionality. However, many of the attributes can be parameterized to allow different rewards programs to run. Multiple rewards plans could even run on the same blockchain, though the user would need to choose which one to lock funds into. @@ -428,7 +428,7 @@ std::string RewardsCreateFunding(uint64_t txfee,char *planstr,int64_t funds,int6 } if ( APR > REWARDSCC_MAXAPR ) { - fprintf(stderr,"25% APR is maximum\n"); + fprintf(stderr,"25%% APR is maximum\n"); return(0); } cp = CCinit(&C,EVAL_REWARDS); From 0d84fb208ec4b3a0a35f09b43711b4d96f3ccf84 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 9 Aug 2018 19:38:55 -1100 Subject: [PATCH 7/8] Error check add inputs loop --- src/cc/CCtx.cpp | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index 4bc081e15..a22b4fd7d 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -249,7 +249,6 @@ int32_t CC_vinselect(int32_t *aboveip,int64_t *abovep,int32_t *belowip,int64_t * else if ( abovei >= 0 ) return(abovei); else return(belowi); - //return(abovei >= 0 && above < (below>>1) ? abovei : belowi); } int64_t AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,int64_t total,int32_t maxinputs) @@ -283,19 +282,13 @@ int64_t AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,int64_t total,int3 up->txid = txid; up->nValue = out.tx->vout[out.i].nValue; up->vout = vout; - /*mtx.vin.push_back(CTxIn(txid,vout,CScript())); - nValue = out.tx->vout[out.i].nValue; - totalinputs += nValue; - n++; - if ( totalinputs >= total || n >= maxinputs ) - break;*/ if ( n >= maxutxos ) break; } } } remains = total; - for (i=0; i0; i++) { below = above = 0; abovei = belowi = -1; From 2b6315fd1370a6a95d5e89e4c707500c2f51f6c0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 9 Aug 2018 20:24:33 -1100 Subject: [PATCH 8/8] Fix utxo selection --- src/cc/CCtx.cpp | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index a22b4fd7d..65adc6655 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -266,16 +266,22 @@ int64_t AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,int64_t total,int3 { txid = out.tx->GetHash(); vout = out.i; - for (i=0; i 0 ) + { + for (i=0; i 0 ) + { + for (i=0; itxid,up->vout,CScript())); totalinputs += up->nValue; remains -= up->nValue; + utxos[ind] = utxos[--n]; + memset(&utxos[n],0,sizeof(utxos[n])); if ( totalinputs >= total || (i+1) >= maxinputs ) break; }