]> Git Repo - VerusCoin.git/commitdiff
Add rewards rpc
authorjl777 <[email protected]>
Tue, 24 Jul 2018 05:52:27 +0000 (18:52 -1100)
committerjl777 <[email protected]>
Tue, 24 Jul 2018 05:52:27 +0000 (18:52 -1100)
src/rpcserver.cpp
src/rpcserver.h
src/wallet/rpcwallet.cpp

index c8a8c4291624a43e0c4704914e4d75d866d6c4f9..2e454c7aa684c6724369240424bbe3bb277ee650 100644 (file)
@@ -344,6 +344,12 @@ static const CRPCCommand vRPCCommands[] =
 #ifdef ENABLE_WALLET
     { "rawtransactions",    "fundrawtransaction",     &fundrawtransaction,     false },
 #endif
+    /* rewards */
+    { "rewards",       "rewardsfund",       &rewardsfund,     true },
+    { "rewards",       "rewardslock",       &rewardslock,     true },
+    { "rewards",       "rewardsunlock",     &rewardsunlock,   true },
+    { "rewards",       "rewardsaddress",    &rewardsaddress   true },
+    
     /* faucet */
     { "faucet",       "faucetfund",      &faucetfund,     true },
     { "faucet",       "faucetget",       &faucetget,      true },
index 5c330497a77eaf7c89aa053fd27c3cd65bd0e47b..70407673a78e1f6d3f1012e009b6e99745aae9f4 100644 (file)
@@ -223,7 +223,11 @@ extern UniValue tokenswapask(const UniValue& params, bool fHelp);
 extern UniValue tokenfillswap(const UniValue& params, bool fHelp);
 extern UniValue faucetfund(const UniValue& params, bool fHelp);
 extern UniValue faucetget(const UniValue& params, bool fHelp);
-UniValue faucetaddress(const UniValue& params, bool fHelp);
+extern UniValue faucetaddress(const UniValue& params, bool fHelp);
+extern UniValue rewardsaddress(const UniValue& params, bool fHelp)
+extern UniValue rewardsfund(const UniValue& params, bool fHelp)
+extern UniValue rewardslock(const UniValue& params, bool fHelp)
+extern UniValue rewardsunlock(const UniValue& params, bool fHelp)
 
 extern UniValue getnewaddress(const UniValue& params, bool fHelp); // in rpcwallet.cpp
 //extern UniValue getnewaddress64(const UniValue& params, bool fHelp); // in rpcwallet.cpp
index ed00ef3734aecff7e7eb140ebe8f9090aef6aec4..7fcd50cd612a2bd02725c4b5d684ded7776face3 100644 (file)
@@ -4840,6 +4840,100 @@ int32_t ensure_CCrequirements()
     else return(0);
 }
 
+#define EVAL_REWARDS 0xe5
+std::string RewardsFund(uint64_t txfee,uint64_t funds,uint64_t APR,uint64_t minseconds,uint64_t maxseconds,uint64_t mindeposit);
+std::string RewardsLock(uint64_t txfee,uint64_t amount);
+std::string RewardsUnlock(uint64_t txfee);
+
+UniValue rewardsaddress(const UniValue& params, bool fHelp)
+{
+    UniValue result(UniValue::VOBJ); std::vector<unsigned char> pubkey; char destaddr[64];
+    if ( fHelp || params.size() > 1 )
+        throw runtime_error("rewardsaddress [pubkey]\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");
+    result.push_back(Pair("result", "success"));
+    if ( GetCCaddress(EVAL_REWARDS,destaddr,pubkey2pk(pubkey)) != 0 )
+        result.push_back(Pair("RewardsCCaddress",destaddr));
+    if ( params.size() == 1 )
+    {
+        pubkey = ParseHex(params[0].get_str().c_str());
+        if ( GetCCaddress(EVAL_REWARDS,destaddr,pubkey2pk(pubkey)) != 0 )
+            result.push_back(Pair("CCaddress",destaddr));
+    }
+    if ( GetCCaddress(EVAL_REWARDS,destaddr,pubkey2pk(Mypubkey())) != 0 )
+        result.push_back(Pair("myCCaddress",destaddr));
+    return(result);
+}
+
+UniValue rewardsfund(const UniValue& params, bool fHelp)
+{
+    UniValue result(UniValue::VOBJ); uint64_t funds,APR,minseconds,maxseconds,mindeposit; std::string hex;
+    if ( fHelp || params.size() > 5 || params.size() < 1 )
+        throw runtime_error("rewardsfund amount APR mindays maxdays mindeposit\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");
+    // default to OOT params
+    APR = 5 * COIN;
+    minseconds = maxseconds = 60 * 3600 * 24;
+    mindeposit = 100 * COIN;
+    funds = atof(params[0].get_str().c_str()) * COIN;
+    if ( params.size() > 1 )
+    {
+        APR = atof(params[1].get_str().c_str()) * COIN;
+        if ( params.size() > 2 )
+        {
+            minseconds = atol(params[2].get_str().c_str()) * 3600 * 24;
+            if ( params.size() > 3 )
+            {
+                maxseconds = atol(params[3].get_str().c_str()) * 3600 * 24;
+                if ( params.size() > 4 )
+                    mindeposit = atof(params[4].get_str().c_str()) * COIN;
+            }
+        }
+    }
+    hex = RewardsFund(0,funds,APR,minseconds,maxseconds,mindeposit);
+    if ( hex.size() > 0 )
+    {
+        result.push_back(Pair("result", "success"));
+        result.push_back(Pair("hex", hex));
+    } else result.push_back(Pair("error", "couldnt create rewards funding transaction"));
+    return(result);
+}
+
+UniValue rewardslock(const UniValue& params, bool fHelp)
+{
+    UniValue result(UniValue::VOBJ); uint64_t amount; std::string hex;
+    if ( fHelp || params.size() > 1 )
+        throw runtime_error("rewardslock amount\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");
+    amount = atof(params[0].get_str().c_str()) * COIN;
+    hex = RewardsLock(0,amount);
+    if ( hex.size() > 0 )
+    {
+        result.push_back(Pair("result", "success"));
+        result.push_back(Pair("hex", hex));
+    } else result.push_back(Pair("error", "couldnt create rewards lock transaction"));
+    return(result);
+}
+
+UniValue rewardsunlock(const UniValue& params, bool fHelp)
+{
+    UniValue result(UniValue::VOBJ); std::string hex;
+    if ( fHelp || params.size() > 0 )
+        throw runtime_error("rewardsunlock [txid]\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");
+    hex = RewardsUnlock(0);
+    if ( hex.size() > 0 )
+    {
+        result.push_back(Pair("result", "success"));
+        result.push_back(Pair("hex", hex));
+    } else result.push_back(Pair("error", "couldnt create rewards unlock transaction"));
+    return(result);
+}
+
 #include "../cc/CCfaucet.h"
 
 UniValue faucetaddress(const UniValue& params, bool fHelp)
@@ -4882,7 +4976,7 @@ UniValue faucetfund(const UniValue& params, bool fHelp)
 
 UniValue faucetget(const UniValue& params, bool fHelp)
 {
-    UniValue result(UniValue::VOBJ); uint64_t funds; std::string hex;
+    UniValue result(UniValue::VOBJ); std::string hex;
     if ( fHelp || params.size() > 0 )
         throw runtime_error("faucetget\n");
     if ( ensure_CCrequirements() < 0 )
This page took 0.04394 seconds and 4 git commands to generate.