From 1d801ae6897c312d6688f7bec916e8c7e0d2dba0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 26 Jul 2018 03:52:22 -1100 Subject: [PATCH] Create funding, addfunding, lock --- src/cc/rewards.cpp | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/cc/rewards.cpp b/src/cc/rewards.cpp index a14fe3c62..fc8a61fd6 100644 --- a/src/cc/rewards.cpp +++ b/src/cc/rewards.cpp @@ -328,7 +328,7 @@ std::string RewardsAddfunding(uint64_t txfee,char *planstr,uint256 fundingtxid,u return(0); } -std::string RewardsLock(uint64_t txfee,char *planstr,uint256 fundingtxid,uint64_t amount) +std::string RewardsLock(uint64_t txfee,char *planstr,uint256 fundingtxid,uint64_t deposit) { CMutableTransaction mtx; CPubKey mypk,rewardspk; CScript opret; uint64_t sbits,funding; struct CCcontract_info *cp,C; cp = CCinit(&C,EVAL_REWARDS); @@ -337,11 +337,21 @@ std::string RewardsLock(uint64_t txfee,char *planstr,uint256 fundingtxid,uint64_ mypk = pubkey2pk(Mypubkey()); rewardspk = GetUnspendable(cp,0); sbits = stringbits(planstr); - if ( (funding= RewardsPlanFunds(sbits,cp,rewardspk,fundingtxid)) >= amount ) // arbitrary cmpval + if ( RewardsPlanExists(cp,sbits,rewardspk,APR,minseconds,maxseconds,mindeposit) == 0 ) { - if ( AddNormalinputs(mtx,mypk,amount+txfee,64) > 0 ) + fprintf(stderr,"Rewards plan %s doesnt exist\n",planstr); + return(0); + } + if ( deposit < mindeposit ) + { + fprintf(stderr,"Rewards plan %s deposit %.8f < mindeposit %.8f\n",planstr,(double)deposit/COIN,(double)mindeposit/COIN); + return(0); + } + if ( (funding= RewardsPlanFunds(sbits,cp,rewardspk,fundingtxid)) >= deposit ) // arbitrary cmpval + { + if ( AddNormalinputs(mtx,mypk,deposit+txfee,64) > 0 ) { - mtx.vout.push_back(MakeCC1vout(cp->evalcode,amount,rewardspk)); + mtx.vout.push_back(MakeCC1vout(cp->evalcode,deposit,rewardspk)); return(FinalizeCCTx(cp,mtx,mypk,txfee,EncodeRewardsOpRet('L',sbits,fundingtxid))); } else fprintf(stderr,"cant find enough inputs\n"); }