Browse Source

addfunding rpc added

jl777
dimxy 5 years ago
parent
commit
5c349ea415
  1. 8
      src/cc/CCPrices.h
  2. 8
      src/cc/prices.cpp
  3. 107
      src/rpc/blockchain.cpp
  4. 1
      src/rpc/server.cpp
  5. 1
      src/rpc/server.h

8
src/cc/CCPrices.h

@ -38,11 +38,11 @@ int32_t komodo_priceget(int64_t *buf64,int32_t ind,int32_t height,int32_t numblo
bool PricesValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn);
// CCcustom
UniValue PricesBet(uint64_t txfee,int64_t amount,int16_t leverage,std::vector<std::string> synthetic);
UniValue PricesAddFunding(uint64_t txfee,uint256 bettxid,int64_t amount);
UniValue PricesBet(int64_t txfee,int64_t amount,int16_t leverage,std::vector<std::string> synthetic);
UniValue PricesAddFunding(int64_t txfee,uint256 bettxid,int64_t amount);
UniValue PricesSetcostbasis(int64_t txfee,uint256 bettxid);
UniValue PricesRekt(uint64_t txfee,uint256 bettxid,int32_t rektheight);
UniValue PricesCashout(uint64_t txfee,uint256 bettxid);
UniValue PricesRekt(int64_t txfee,uint256 bettxid,int32_t rektheight);
UniValue PricesCashout(int64_t txfee,uint256 bettxid);
UniValue PricesInfo(uint256 bettxid,int32_t refheight);
UniValue PricesList();

8
src/cc/prices.cpp

@ -497,7 +497,7 @@ int64_t prices_batontxid(uint256 &batontxid,CTransaction bettx,uint256 bettxid)
return(addedbets);
}
UniValue PricesBet(uint64_t txfee,int64_t amount,int16_t leverage,std::vector<std::string> synthetic)
UniValue PricesBet(int64_t txfee,int64_t amount,int16_t leverage,std::vector<std::string> synthetic)
{
int32_t nextheight = komodo_nextheight();
CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(),nextheight); UniValue result(UniValue::VOBJ);
@ -535,7 +535,7 @@ UniValue PricesBet(uint64_t txfee,int64_t amount,int16_t leverage,std::vector<st
return(result);
}
UniValue PricesAddFunding(uint64_t txfee, uint256 bettxid, int64_t amount)
UniValue PricesAddFunding(int64_t txfee, uint256 bettxid, int64_t amount)
{
int32_t nextheight = komodo_nextheight();
CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), nextheight); UniValue result(UniValue::VOBJ);
@ -624,7 +624,7 @@ UniValue PricesSetcostbasis(int64_t txfee, uint256 bettxid)
return(result);
}
UniValue PricesRekt(uint64_t txfee, uint256 bettxid, int32_t rektheight)
UniValue PricesRekt(int64_t txfee, uint256 bettxid, int32_t rektheight)
{
int32_t nextheight = komodo_nextheight();
CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), nextheight); UniValue result(UniValue::VOBJ);
@ -678,7 +678,7 @@ UniValue PricesRekt(uint64_t txfee, uint256 bettxid, int32_t rektheight)
return(result);
}
UniValue PricesCashout(uint64_t txfee, uint256 bettxid)
UniValue PricesCashout(int64_t txfee, uint256 bettxid)
{
int32_t nextheight = komodo_nextheight();
CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), nextheight); UniValue result(UniValue::VOBJ);

107
src/rpc/blockchain.cpp

@ -1315,6 +1315,113 @@ UniValue prices(const UniValue& params, bool fHelp)
return ret;
}
uint64_t komodo_d_interest(int32_t *txheightp,uint32_t *locktimep,uint256 hash,int32_t n,int32_t checkheight,uint64_t checkvalue,int32_t tipheight);
// pricesbet rpc implementation
UniValue pricesbet(const UniValue& params, bool fHelp)
{
if (fHelp || params.size() != 3)
throw runtime_error("pricesbet amount leverage \"synthetic-expression\"\n");
LOCK(cs_main);
UniValue ret(UniValue::VOBJ);
if (ASSETCHAINS_CBOPRET == 0)
throw JSONRPCError(RPC_INVALID_PARAMETER, "only -ac_cbopret chains have prices");
CAmount txfee = 10000;
CAmount amount = atoll(params[0].get_str().c_str());
int16_t leverage = (int16_t) atoi(params[1].get_str().c_str());
std::string sexpr = params[2].get_str();
std::vector<std::string> vexpr;
SplitStr(sexpr, vexpr);
// debug print parsed strings:
std::cerr << "parsed synthetic: ";
for (auto s : vexpr)
std::cerr << s << " ";
std::cerr << std::endl;
return PricesBet(txfee, amount, leverage, vexpr);
}
// pricesaddfunding rpc implementation
UniValue pricesaddfunding(const UniValue& params, bool fHelp)
{
if (fHelp || params.size() != 2)
throw runtime_error("pricesaddfunding bettxid amount\n");
LOCK(cs_main);
UniValue ret(UniValue::VOBJ);
if (ASSETCHAINS_CBOPRET == 0)
throw JSONRPCError(RPC_INVALID_PARAMETER, "only -ac_cbopret chains have prices");
CAmount txfee = 10000;
uint256 bettxid = Parseuint256(params[0].get_str().c_str());
CAmount amount = atoll(params[1].get_str().c_str());
return PricesAddFunding(txfee, bettxid, amount);
}
// rpc pricessetcostbasis implementation
UniValue pricessetcostbasis(const UniValue& params, bool fHelp)
{
if (fHelp || params.size() != 1)
throw runtime_error("pricessetcostbasis bettxid\n");
LOCK(cs_main);
UniValue ret(UniValue::VOBJ);
if (ASSETCHAINS_CBOPRET == 0)
throw JSONRPCError(RPC_INVALID_PARAMETER, "only -ac_cbopret chains have prices");
uint256 bettxid = Parseuint256(params[0].get_str().c_str());
if( bettxid.IsNull() )
throw runtime_error("invalid bettxid\n");
int64_t txfee = 10000;
return PricesSetcostbasis(txfee, bettxid);
}
UniValue pricescashout(const UniValue& params, bool fHelp)
{
if (fHelp || params.size() != 1)
throw runtime_error("pricescashout bettxid\n");
LOCK(cs_main);
UniValue ret(UniValue::VOBJ);
if (ASSETCHAINS_CBOPRET == 0)
throw JSONRPCError(RPC_INVALID_PARAMETER, "only -ac_cbopret chains have prices");
uint256 bettxid = Parseuint256(params[0].get_str().c_str());
if (bettxid.IsNull())
throw runtime_error("invalid bettxid\n");
int64_t txfee = 10000;
return PricesCashout(txfee, bettxid);
}
UniValue pricesrekt(const UniValue& params, bool fHelp)
{
if (fHelp || params.size() != 2)
throw runtime_error("pricesrekt bettxid height\n");
LOCK(cs_main);
UniValue ret(UniValue::VOBJ);
if (ASSETCHAINS_CBOPRET == 0)
throw JSONRPCError(RPC_INVALID_PARAMETER, "only -ac_cbopret chains have prices");
uint256 bettxid = Parseuint256(params[0].get_str().c_str());
if (bettxid.IsNull())
throw runtime_error("invalid bettxid\n");
int32_t height = atoi(params[0].get_str().c_str());
int64_t txfee = 10000;
return PricesRekt(txfee, bettxid, height);
}
UniValue gettxout(const UniValue& params, bool fHelp)
{
if (fHelp || params.size() < 2 || params.size() > 3)

1
src/rpc/server.cpp

@ -468,6 +468,7 @@ static const CRPCCommand vRPCCommands[] =
{ "prices", "pricessetcostbasis", &pricessetcostbasis, true },
{ "prices", "pricescashout", &pricescashout, true },
{ "prices", "pricesrekt", &pricesrekt, true },
{ "prices", "pricesaddfunding", &pricesaddfunding, true },
// Pegs
{ "pegs", "pegsaddress", &pegsaddress, true },

1
src/rpc/server.h

@ -501,6 +501,7 @@ extern UniValue pricesbet(const UniValue& params, bool fHelp);
extern UniValue pricessetcostbasis(const UniValue& params, bool fHelp);
extern UniValue pricescashout(const UniValue& params, bool fHelp);
extern UniValue pricesrekt(const UniValue& params, bool fHelp);
extern UniValue pricesaddfunding(const UniValue& params, bool fHelp);
// test rpc:

Loading…
Cancel
Save