Browse Source

added refillfund rpc

pull/27/head
dimxy 5 years ago
parent
commit
3667b573fa
  1. 1
      src/cc/CCPrices.h
  2. 28
      src/cc/prices.cpp
  3. 17
      src/rpc/blockchain.cpp
  4. 2
      src/rpc/server.cpp
  5. 1
      src/rpc/server.h

1
src/cc/CCPrices.h

@ -55,6 +55,7 @@ UniValue PricesCashout(int64_t txfee,uint256 bettxid);
UniValue PricesInfo(uint256 bettxid,int32_t refheight);
UniValue PricesList(uint32_t filter, CPubKey mypk);
UniValue PricesGetOrderbook();
UniValue PricesRefillFund(int64_t amount);
#endif

28
src/cc/prices.cpp

@ -1687,6 +1687,34 @@ UniValue PricesSetcostbasis(int64_t txfee, uint256 bettxid)
}
// pricesaddfunding rpc impl: add yet another bet
UniValue PricesRefillFund(int64_t amount)
{
int32_t nextheight = komodo_nextheight();
CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), nextheight); UniValue result(UniValue::VOBJ);
struct CCcontract_info *cp, C;
CPubKey pricespk, mypk, pk;
std::string rawtx;
//char myaddr[64];
cp = CCinit(&C, EVAL_PRICES);
const int64_t txfee = PRICES_TXFEE;
mypk = pubkey2pk(Mypubkey());
pricespk = GetUnspendable(cp, 0);
if (AddNormalinputs(mtx, mypk, amount + txfee, 64) >= amount + txfee)
{
mtx.vout.push_back(MakeCC1vout(cp->evalcode, amount, pricespk)); // vout1 added amount
rawtx = FinalizeCCTx(0, cp, mtx, mypk, txfee, CScript());
return(prices_rawtxresult(result, rawtx, 0));
}
result.push_back(Pair("result", "error"));
result.push_back(Pair("error", "not enough funds"));
return(result);
}
int32_t prices_getbetinfo(uint256 bettxid, BetInfo &betinfo)
{
CTransaction bettx;

17
src/rpc/blockchain.cpp

@ -1454,6 +1454,23 @@ UniValue pricesgetorderbook(const UniValue& params, bool fHelp)
return PricesGetOrderbook();
}
// pricesrekt rpc implementation
UniValue pricesrefillfund(const UniValue& params, bool fHelp)
{
if (fHelp || params.size() != 1)
throw runtime_error("pricesrefillfund\n");
LOCK(cs_main);
UniValue ret(UniValue::VOBJ);
if (ASSETCHAINS_CBOPRET == 0)
throw JSONRPCError(RPC_INVALID_PARAMETER, "only -ac_cbopret chains have prices");
CAmount amount = atof(params[0].get_str().c_str()) * COIN;
return PricesRefillFund(amount);
}
UniValue gettxout(const UniValue& params, bool fHelp)
{
if (fHelp || params.size() < 2 || params.size() > 3)

2
src/rpc/server.cpp

@ -471,7 +471,7 @@ static const CRPCCommand vRPCCommands[] =
{ "prices", "pricesrekt", &pricesrekt, true },
{ "prices", "pricesaddfunding", &pricesaddfunding, true },
{ "prices", "pricesgetorderbook", &pricesgetorderbook, true },
{ "prices", "pricesrefillfund", &pricesrefillfund, true },
// Pegs
{ "pegs", "pegsaddress", &pegsaddress, true },

1
src/rpc/server.h

@ -510,6 +510,7 @@ extern UniValue pricescashout(const UniValue& params, bool fHelp);
extern UniValue pricesrekt(const UniValue& params, bool fHelp);
extern UniValue pricesaddfunding(const UniValue& params, bool fHelp);
extern UniValue pricesgetorderbook(const UniValue& params, bool fHelp);
extern UniValue pricesrefillfund(const UniValue& params, bool fHelp);

Loading…
Cancel
Save