From e95b95821eae175b7fd90c0a81fc37d91e57985d Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 25 Jul 2018 05:59:14 -1100 Subject: [PATCH] Fix --- src/cc/CCrewards.h | 4 ++-- src/cc/rewards.cpp | 22 +++++++++++++++++++++- src/wallet/rpcwallet.cpp | 4 ++-- 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/src/cc/CCrewards.h b/src/cc/CCrewards.h index 619bf4ddb..fe9c33b07 100644 --- a/src/cc/CCrewards.h +++ b/src/cc/CCrewards.h @@ -23,8 +23,8 @@ bool RewardsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx); -std::string RewardsCreateFund(uint64_t txfee,char *planstr,uint64_t funds,uint64_t APR,uint64_t minseconds,uint64_t maxseconds,uint64_t mindeposit); -std::string RewardsAddfunds(uint64_t txfee,char *planstr,uint256 fundingtxid,uint64_t amount); +std::string RewardsCreateFunding(uint64_t txfee,char *planstr,uint64_t funds,uint64_t APR,uint64_t minseconds,uint64_t maxseconds,uint64_t mindeposit); +std::string RewardsAddfunding(uint64_t txfee,char *planstr,uint256 fundingtxid,uint64_t amount); std::string RewardsLock(uint64_t txfee,char *planstr,uint256 fundingtxid,uint64_t amount); std::string RewardsUnlock(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 locktxid); diff --git a/src/cc/rewards.cpp b/src/cc/rewards.cpp index 054fdfde8..01228b5f3 100644 --- a/src/cc/rewards.cpp +++ b/src/cc/rewards.cpp @@ -244,7 +244,7 @@ std::string RewardsUnlock(uint64_t txfee,char *planstr,uint256 fundingtxid,uint2 return(0); } -std::string RewardsCreateFund(uint64_t txfee,char *planstr,uint64_t funds,uint64_t APR,uint64_t minseconds,uint64_t maxseconds,uint64_t mindeposit) +std::string RewardsCreateFunding(uint64_t txfee,char *planstr,uint64_t funds,uint64_t APR,uint64_t minseconds,uint64_t maxseconds,uint64_t mindeposit) { CMutableTransaction mtx; CPubKey mypk,rewardspk; CScript opret; uint64_t sbits,funding; struct CCcontract_info *cp,C; cp = CCinit(&C,EVAL_REWARDS); @@ -263,6 +263,26 @@ std::string RewardsCreateFund(uint64_t txfee,char *planstr,uint64_t funds,uint64 return(0); } +std::string RewardsAddfunding(uint64_t txfee,char *planstr,uint256 fundingtxid,uint64_t amount) +{ + CMutableTransaction mtx; CPubKey mypk,rewardspk; CScript opret; uint64_t sbits,funding; struct CCcontract_info *cp,C; + cp = CCinit(&C,EVAL_REWARDS); + if ( txfee == 0 ) + txfee = 10000; + mypk = pubkey2pk(Mypubkey()); + rewardspk = GetUnspendable(cp,0); + if ( (funding= RewardsPlanFunds(sbits,cp,rewardspk,planstr,fundingtxid)) >= amount ) + { + if ( AddNormalinputs(mtx,mypk,amount+txfee,64) > 0 ) + { + mtx.vout.push_back(MakeCC1vout(cp->evalcode,amount,rewardspk)); + return(FinalizeCCTx(cp,mtx,mypk,txfee,EncodeRewardsOpRet('L',sbits,fundingtxid))); + } else fprintf(stderr,"cant find enough inputs\n"); + } + fprintf(stderr,"cant find rewards inputs\n"); + return(0); +} + std::string RewardsLock(uint64_t txfee,char *planstr,uint256 fundingtxid,uint64_t amount) { CMutableTransaction mtx; CPubKey mypk,rewardspk; CScript opret; uint64_t sbits,funding; struct CCcontract_info *cp,C; diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 6354afb3d..d4fc9605b 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4957,7 +4957,7 @@ UniValue tokenaddress(const UniValue& params, bool fHelp) return(CCaddress(cp,(char *)"Assets",pubkey)); } -UniValue rewardscreatefund(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; if ( fHelp || params.size() > 6 || params.size() < 2 ) @@ -5022,7 +5022,7 @@ UniValue rewardsaddfunding(const UniValue& params, bool fHelp) name = (char *)params[0].get_str().c_str(); fundingtxid = Parseuint256((char *)params[1].get_str().c_str()); amount = atof(params[2].get_str().c_str()) * COIN; - hex = RewardsAddFunds(0,name,fundingtxid,amount); + hex = RewardsAddfunding(0,name,fundingtxid,amount); if ( hex.size() > 0 ) { result.push_back(Pair("result", "success"));