From fdd2281045613f57bfd83d595912c5dc7edaadd7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 27 Jul 2018 02:07:40 -1100 Subject: [PATCH] Rewardslist rewardsinfo --- src/cc/CCrewards.h | 2 ++ src/cc/rewards.cpp | 47 ++++++++++++++++++++++++++++++++++++++++ src/rpcserver.cpp | 2 ++ src/rpcserver.h | 2 ++ src/wallet/rpcwallet.cpp | 21 ++++++++++++++++++ 5 files changed, 74 insertions(+) diff --git a/src/cc/CCrewards.h b/src/cc/CCrewards.h index fe9c33b07..b9d36054f 100644 --- a/src/cc/CCrewards.h +++ b/src/cc/CCrewards.h @@ -22,6 +22,8 @@ #define EVAL_REWARDS 0xe5 bool RewardsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx); +UniValue RewardsInfo(uint256 rewardid); +UniValue RewardsList(); 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); diff --git a/src/cc/rewards.cpp b/src/cc/rewards.cpp index 006085ed3..d654c5f66 100644 --- a/src/cc/rewards.cpp +++ b/src/cc/rewards.cpp @@ -245,6 +245,53 @@ bool RewardsPlanExists(struct CCcontract_info *cp,uint64_t refsbits,CPubKey rewa return(false); } +UniValue RewardsInfo(uint256 rewardsid) +{ + UniValue result(UniValue::VOBJ); uint256 hashBlock; CTransaction vintx; int64_t APR,minseconds,maxseconds,mindeposit; char str[67],numstr[65]; + if ( GetTransaction(rewardsid,vintx,hashBlock,false) == 0 ) + { + fprintf(stderr,"cant find assetid\n"); + result.push_back(Pair("error","cant find assetid")); + return(0); + } + if ( vintx.vout.size() > 0 && (funcid= DecodeRewardsFundingOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,sbits,APR,minseconds,maxseconds,mindeposit)) == 'F' ) + { + fprintf(stderr,"assetid isnt assetcreation txid\n"); + result.push_back(Pair("error","assetid isnt assetcreation txid")); + } + result.push_back(Pair("result","success")); + result.push_back(Pair("fundingtxid",uint256_str(str,rewardsid))); + result.push_back(Pair("name",name)); + sprintf(numstr,"%.8f",(double)APR/COIN); + result.push_back(Pair("APR",numstr)); + result.push_back(Pair("minseconds",minseconds)); + result.push_back(Pair("maxseconds",maxseconds)); + sprintf(numstr,"%.8f",(double)mindeposit/COIN); + result.push_back(Pair("mindeposit",numstr)); + sprintf(numstr,"%.8f",(double)vintx.vout[0].nValue/COIN); + result.push_back(Pair("funding",numstr)); + return(result); +} + +UniValue RewardsList() +{ + UniValue result(UniValue::VARR); std::vector > addressIndex; struct CCcontract_info *cp,C; uint256 txid,hashBlock; CTransaction vintx; std::vector origpubkey; std::string name,description; char str[65]; + cp = CCinit(&C,EVAL_REWARDS); + SetCCtxids(addressIndex,cp->normaladdr); + for (std::vector >::const_iterator it=addressIndex.begin(); it!=addressIndex.end(); it++) + { + txid = it->first.txhash; + if ( GetTransaction(txid,vintx,hashBlock,false) != 0 ) + { + if ( vintx.vout.size() > 0 && DecodeRewardsCreateOpRet(vintx.vout[vintx.vout.size()-1].scriptPubKey,origpubkey,name,description) != 0 ) + { + result.push_back(uint256_str(str,txid)); + } + } + } + return(result); +} + std::string RewardsUnlock(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 locktxid) { CMutableTransaction mtx; CPubKey mypk,rewardspk; CScript opret; uint64_t funding,sbits,reward,amount=0,inputs,CCchange=0,APR,minseconds,maxseconds,mindeposit; struct CCcontract_info *cp,C; diff --git a/src/rpcserver.cpp b/src/rpcserver.cpp index 1e665cea5..a7e16652a 100644 --- a/src/rpcserver.cpp +++ b/src/rpcserver.cpp @@ -354,6 +354,8 @@ static const CRPCCommand vRPCCommands[] = { "ponzi", "ponziaddress", &ponziaddress, true }, /* rewards */ + { "rewards", "rewardslist", &rewardslist, true }, + { "rewards", "rewardsinfo", &rewardsinfo, true }, { "rewards", "rewardscreatefunding", &rewardscreatefunding, true }, { "rewards", "rewardsaddfunding", &rewardsaddfunding, true }, { "rewards", "rewardslock", &rewardslock, true }, diff --git a/src/rpcserver.h b/src/rpcserver.h index 2b82e6e64..9144b874a 100644 --- a/src/rpcserver.h +++ b/src/rpcserver.h @@ -226,6 +226,8 @@ extern UniValue tokenfillswap(const UniValue& params, bool fHelp); extern UniValue faucetfund(const UniValue& params, bool fHelp); extern UniValue faucetget(const UniValue& params, bool fHelp); extern UniValue faucetaddress(const UniValue& params, bool fHelp); +extern UniValue rewardsinfo(const UniValue& params, bool fHelp); +extern UniValue rewardslist(const UniValue& params, bool fHelp); extern UniValue rewardsaddress(const UniValue& params, bool fHelp); extern UniValue rewardscreatefunding(const UniValue& params, bool fHelp); extern UniValue rewardsaddfunding(const UniValue& params, bool fHelp); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index e06e4292e..3678b25e0 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5122,6 +5122,27 @@ UniValue dicebet(const UniValue& params, bool fHelp) return(result); } +UniValue rewardslist(const UniValue& params, bool fHelp) +{ + uint256 tokenid; + if ( fHelp || params.size() > 0 ) + 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"); + return(RewardsList()); +} + +UniValue rewardsinfo(const UniValue& params, bool fHelp) +{ + uint256 fundingtxid; + if ( fHelp || params.size() != 1 ) + 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"); + fundingtxid = Parseuint256((char *)params[0].get_str().c_str()); + return(RewardsInfo(fundingtxid)); +} + UniValue tokenlist(const UniValue& params, bool fHelp) { uint256 tokenid;