Merge pull request #1470 from blackjok3rtt/prices

Prices
This commit is contained in:
jl777
2019-05-08 06:42:41 -11:00
committed by GitHub
19 changed files with 2383 additions and 722 deletions

View File

@@ -17,34 +17,41 @@
#ifndef CC_PRICES_H
#define CC_PRICES_H
#include "komodo_defs.h"
#include "CCinclude.h"
int32_t komodo_priceget(int64_t *buf64,int32_t ind,int32_t height,int32_t numblocks);
extern void GetKomodoEarlytxidScriptPub();
extern CScript KOMODO_EARLYTXID_SCRIPTPUB;
#define PRICES_DAYWINDOW ((3600*24/ASSETCHAINS_BLOCKTIME) + 1)
// #define PRICES_DAYWINDOW ((3600*24/ASSETCHAINS_BLOCKTIME) + 1) // defined in komodo_defs.h
#define PRICES_TXFEE 10000
#define PRICES_MAXLEVERAGE 777
#define PRICES_SMOOTHWIDTH 1
#define KOMODO_MAXPRICES 2048 // must be power of 2 and less than 8192
#define KOMODO_PRICEMASK (~(KOMODO_MAXPRICES - 1))
#define PRICES_WEIGHT (KOMODO_MAXPRICES * 1)
#define PRICES_MULT (KOMODO_MAXPRICES * 2)
#define PRICES_DIV (KOMODO_MAXPRICES * 3)
#define PRICES_INV (KOMODO_MAXPRICES * 4)
#define PRICES_MDD (KOMODO_MAXPRICES * 5)
#define PRICES_MMD (KOMODO_MAXPRICES * 6)
#define PRICES_MMM (KOMODO_MAXPRICES * 7)
#define PRICES_DDD (KOMODO_MAXPRICES * 8)
#define KOMODO_PRICEMASK (~(KOMODO_MAXPRICES - 1)) // actually 1111 1000 0000 0000
#define PRICES_WEIGHT (KOMODO_MAXPRICES * 1) // 0000 1000 0000 0000
#define PRICES_MULT (KOMODO_MAXPRICES * 2) // 0001 0000 0000 0000
#define PRICES_DIV (KOMODO_MAXPRICES * 3) // 0001 1000 0000 0000
#define PRICES_INV (KOMODO_MAXPRICES * 4) // 0010 0000 0000 0000
#define PRICES_MDD (KOMODO_MAXPRICES * 5) // 0010 1000 0000 0000
#define PRICES_MMD (KOMODO_MAXPRICES * 6) // 0011 0000 0000 0000
#define PRICES_MMM (KOMODO_MAXPRICES * 7) // 0011 1000 0000 0000
#define PRICES_DDD (KOMODO_MAXPRICES * 8) // 0100 0000 0000 0000
#define PRICES_NORMFACTOR (int64_t)(SATOSHIDEN)
#define PRICES_POINTFACTOR (int64_t)10000
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 PricesSetcostbasis(uint64_t txfee,uint256 bettxid);
UniValue PricesRekt(uint64_t txfee,uint256 bettxid,int32_t rektheight);
UniValue PricesCashout(uint64_t txfee,uint256 bettxid);
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(int64_t txfee,uint256 bettxid,int32_t rektheight);
UniValue PricesCashout(int64_t txfee,uint256 bettxid);
UniValue PricesInfo(uint256 bettxid,int32_t refheight);
UniValue PricesList();
UniValue PricesList(uint32_t filter, CPubKey mypk);
UniValue PricesGetOrderbook();
#endif

View File

@@ -298,6 +298,7 @@ UniValue ValueFromAmount(const CAmount& amount);
int64_t TotalPubkeyNormalInputs(const CTransaction &tx, const CPubKey &pubkey);
int64_t TotalPubkeyCCInputs(const CTransaction &tx, const CPubKey &pubkey);
inline std::string STR_TOLOWER(const std::string &str) { std::string out; for (std::string::const_iterator i = str.begin(); i != str.end(); i++) out += std::tolower(*i); return out; }
// bitcoin LogPrintStr with category "-debug" cmdarg support for C++ ostringstream:
#define CCLOG_INFO 0

View File

@@ -64,7 +64,7 @@ int32_t has_opret(const CTransaction &tx, uint8_t evalcode)
for ( auto vout : tx.vout )
{
//fprintf(stderr, "[txid.%s] 1.%i 2.%i 3.%i 4.%i\n",tx.GetHash().GetHex().c_str(), vout.scriptPubKey[0], vout.scriptPubKey[1], vout.scriptPubKey[2], vout.scriptPubKey[3]);
if ( vout.scriptPubKey[0] == OP_RETURN && vout.scriptPubKey[2] == evalcode )
if ( vout.scriptPubKey.size() > 3 && vout.scriptPubKey[0] == OP_RETURN && vout.scriptPubKey[2] == evalcode )
return i;
i++;
}

View File

@@ -575,8 +575,11 @@ int64_t AddPaymentsInputs(bool fLockedBlocks,int8_t GetBalance,struct CCcontract
}
if ( (nValue= IsPaymentsvout(cp,vintx,vout,coinaddr,ccopret)) > PAYMENTS_TXFEE && nValue >= threshold && myIsutxo_spentinmempool(ignoretxid,ignorevin,txid,vout) == 0 )
{
int32_t offset = 0;
if ( ccopret.size() > 2 && DecodePaymentsMergeOpRet(ccopret,checktxid) == 'M' )
offset = PAYMENTS_MERGEOFSET;
int32_t tmpblocksleft = 0;
if ( fLockedBlocks && !payments_lockedblocks(hashBlock, lockedblocks+(GetBalance == 4 ? PAYMENTS_MERGEOFSET : 0), tmpblocksleft) )
if ( fLockedBlocks && !payments_lockedblocks(hashBlock, lockedblocks+offset, tmpblocksleft) )
{
blocksleft_balance.push_back(std::make_pair(tmpblocksleft,nValue));
continue;
@@ -1029,6 +1032,7 @@ UniValue PaymentsMerge(struct CCcontract_info *cp,char *jsonstr)
// encode the checktxid into the end of the ccvout, along with 'M' to flag merge type tx.
opret = EncodePaymentsMergeOpRet(createtxid);
std::vector<std::vector<unsigned char>> vData = std::vector<std::vector<unsigned char>>();
// try to pay to diffrent pubkey here... change txidpk.
if ( makeCCopret(opret, vData) )
mtx.vout.push_back(MakeCC1of2vout(EVAL_PAYMENTS,inputsum-PAYMENTS_TXFEE,Paymentspk,txidpk,&vData));
GetCCaddress1of2(cp,destaddr,Paymentspk,txidpk);
@@ -1036,7 +1040,7 @@ UniValue PaymentsMerge(struct CCcontract_info *cp,char *jsonstr)
rawtx = FinalizeCCTx(0,cp,mtx,mypk,PAYMENTS_TXFEE,CScript());
if ( params != 0 )
free_json(params);
return(payments_rawtxresult(result,rawtx,0));
return(payments_rawtxresult(result,rawtx,1));
}
}
else
@@ -1188,6 +1192,7 @@ UniValue PaymentsAirdrop(struct CCcontract_info *cp,char *jsonstr)
lockedblocks = juint(jitem(params,0),0);
minrelease = juint(jitem(params,1),0);
minimum = juint(jitem(params,2),0);
if ( minimum < 10000 ) minimum = 10000;
top = juint(jitem(params,3),0);
bottom = juint(jitem(params,4),0);
fixedAmount = juint(jitem(params,5),0); // fixed amount is a flag, set to 7 does game mode, 0 normal snapshot, anything else fixed allocations.

File diff suppressed because it is too large Load Diff