From 2a8a02e5733e4401bb7724718eb723b324905f06 Mon Sep 17 00:00:00 2001 From: dimxy Date: Thu, 2 May 2019 23:56:56 +0500 Subject: [PATCH] corr rekt tx --- src/cc/prices.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index afa4f6e56..0344e983f 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -1508,12 +1508,15 @@ UniValue PricesRekt(int64_t txfee, uint256 bettxid, int32_t rektheight) std::vector vec; CPubKey pk, mypk, pricespk; std::string rawtx; + char destaddr[64]; cp = CCinit(&C, EVAL_PRICES); if (txfee == 0) txfee = PRICES_TXFEE; mypk = pubkey2pk(Mypubkey()); pricespk = GetUnspendable(cp, 0); + GetCCaddress(cp, destaddr, pricespk); + if (myGetTransaction(bettxid, bettx, hashBlock) != 0 && bettx.vout.size() > 3) { if (prices_betopretdecode(bettx.vout.back().scriptPubKey, pk, firstheight, positionsize, leverage, firstprice, vec, tokenid) == 'B') @@ -1558,9 +1561,16 @@ UniValue PricesRekt(int64_t txfee, uint256 bettxid, int32_t rektheight) } if (myfee != 0) { + int64_t CCchange = 0, inputsum; + mtx.vin.push_back(CTxIn(bettxid, 1, CScript())); // spend cc marker + if ((inputsum = AddPricesInputs(cp, mtx, destaddr, myfee + txfee, 64)) > myfee + txfee) // TODO: why do we take txfee from global addr and not from user's addr? + CCchange = (inputsum - myfee); mtx.vout.push_back(CTxOut(myfee, CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); - mtx.vout.push_back(MakeCC1vout(cp->evalcode, bettx.vout[2].nValue - myfee - txfee, pricespk)); // change + if (CCchange >= txfee) + mtx.vout.push_back(MakeCC1vout(cp->evalcode, CCchange, pricespk)); + + /// mtx.vout.push_back(MakeCC1vout(cp->evalcode, bettx.vout[2].nValue - myfee - txfee, pricespk)); // change rawtx = FinalizeCCTx(0, cp, mtx, mypk, txfee, prices_finalopret(bettxid, totalprofits, rektheight, mypk, firstprice, 0, totalbets - positionsize, positionsize, leverage)); return(prices_rawtxresult(result, rawtx, 0)); }