From 3667b573fa62925a1e2398598f1e25977598cdcb Mon Sep 17 00:00:00 2001 From: dimxy Date: Wed, 15 May 2019 16:36:24 +0500 Subject: [PATCH] added refillfund rpc --- src/cc/CCPrices.h | 1 + src/cc/prices.cpp | 28 ++++++++++++++++++++++++++++ src/rpc/blockchain.cpp | 17 +++++++++++++++++ src/rpc/server.cpp | 2 +- src/rpc/server.h | 1 + 5 files changed, 48 insertions(+), 1 deletion(-) diff --git a/src/cc/CCPrices.h b/src/cc/CCPrices.h index 5e1699fde..b8c7a74e0 100644 --- a/src/cc/CCPrices.h +++ b/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 diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index d9a536424..952814761 100644 --- a/src/cc/prices.cpp +++ b/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; diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index 042b6591f..730ff7491 100644 --- a/src/rpc/blockchain.cpp +++ b/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) diff --git a/src/rpc/server.cpp b/src/rpc/server.cpp index c35647f8c..500d175e0 100644 --- a/src/rpc/server.cpp +++ b/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 }, diff --git a/src/rpc/server.h b/src/rpc/server.h index c61f62dc3..b9fb33198 100644 --- a/src/rpc/server.h +++ b/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);