From 43e0d2fec6f390fdd391e94c714f306097556252 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 3 Apr 2019 05:58:14 -1100 Subject: [PATCH 01/31] -ac_prices --- src/komodo_gateway.h | 98 ++++++++++++++++++++++++++---------------- src/komodo_utils.h | 13 +++++- src/rpc/blockchain.cpp | 5 ++- 3 files changed, 76 insertions(+), 40 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 6862fcf14..b70574677 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1552,6 +1552,7 @@ extern std::vector Mineropret; // opreturn data set by the data gatheri #define PRICES_MAXCHANGE (COIN / 100) // maximum acceptable change, set at 1% #define PRICES_SIZEBIT0 (sizeof(uint32_t) * 4) // 4 uint32_t unixtimestamp, BTCUSD, BTCGBP and BTCEUR #define KOMODO_LOCALPRICE_CACHESIZE 7 +#define KOMODO_MAXPRICES 2048 #define issue_curl(cmdstr) bitcoind_RPC(0,(char *)"CBCOINBASE",cmdstr,0,0,0) @@ -1561,18 +1562,15 @@ const char *Forex[] = { "BGN","NZD","ILS","RUB","CAD","PHP","CHF","AUD","JPY","TRY","HKD","MYR","HRK","CZK","IDR","DKK","NOK","HUF","GBP","MXN","THB","ISK","ZAR","BRL","SGD","PLN","INR","KRW","RON","CNY","SEK","EUR" }; // must be in ECB list -uint32_t PriceCache[KOMODO_LOCALPRICE_CACHESIZE][4+sizeof(Cryptos)/sizeof(*Cryptos)+sizeof(Forex)/sizeof(*Forex)]; +uint32_t PriceCache[KOMODO_LOCALPRICE_CACHESIZE][KOMODO_MAXPRICES];//4+sizeof(Cryptos)/sizeof(*Cryptos)+sizeof(Forex)/sizeof(*Forex)]; +int64_t PriceMult[KOMODO_MAXPRICES]; int32_t komodo_cbopretsize(uint64_t flags); void komodo_PriceCache_shift() { int32_t i; for (i=KOMODO_LOCALPRICE_CACHESIZE-1; i>0; i--) - { memcpy(PriceCache[i],PriceCache[i-1],sizeof(PriceCache[i])); - //for (j=0; j<4+sizeof(Cryptos)/sizeof(*Cryptos)+sizeof(Forex)/sizeof(*Forex); j++) - // PriceCache[i][j] = PriceCache[i-1][j]; - } memcpy(PriceCache[0],Mineropret.data(),Mineropret.size()); } @@ -1657,7 +1655,7 @@ int32_t komodo_pricecmp(int32_t nHeight,int32_t n,char *maxflags,uint32_t *price // komodo_priceclamp() clamps any price that is beyond tolerance int32_t komodo_priceclamp(int32_t n,uint32_t *pricebits,uint32_t *refprices,int64_t tolerance) { - int32_t i; uint32_t newprice; char maxflags[2048]; + int32_t i; uint32_t newprice; char maxflags[KOMODO_MAXPRICES]; memset(maxflags,0,sizeof(maxflags)); for (i=1; i= PRICES_SIZEBIT0 ) { n = (int32_t)(Mineropret.size() / sizeof(uint32_t)); @@ -1727,13 +1725,11 @@ CScript komodo_mineropret(int32_t nHeight) // reconsiderblock 0034cf582018eacc0b4ae001491ce460113514cb1a3f217567ef4a2207de361a // reconsiderbloc 000abf51c023b64af327c50c1b060797b8cb281c696d30ab92fd002a8b8c9aea // are needed to sync past initial blocks with different data set -// pass in blockhash and nTime, latch if it is rejected due to local price, then if localprice changes in a way that would validate then issue reconsiderblock -// add rpc call for extracting rawprices int32_t komodo_opretvalidate(const CBlock *block,CBlockIndex * const previndex,int32_t nHeight,CScript scriptPubKey) { - int32_t testchain_exemption = 350; - std::vector vopret; char maxflags[2048]; double btcusd,btcgbp,btceur; uint32_t localbits[2048],pricebits[2048],prevbits[2048],newprice; int32_t i,j,prevtime,maxflag,lag,lag2,lag3,n,errflag,iter; uint32_t now = (uint32_t)time(NULL); + int32_t testchain_exemption = 0; + std::vector vopret; char maxflags[KOMODO_MAXPRICES]; double btcusd,btcgbp,btceur; uint32_t localbits[KOMODO_MAXPRICES],pricebits[KOMODO_MAXPRICES],prevbits[KOMODO_MAXPRICES],newprice; int32_t i,j,prevtime,maxflag,lag,lag2,lag3,n,errflag,iter; uint32_t now = (uint32_t)time(NULL); if ( ASSETCHAINS_CBOPRET != 0 && nHeight > 0 ) { GetOpReturnData(scriptPubKey,vopret); @@ -1753,7 +1749,7 @@ int32_t komodo_opretvalidate(const CBlock *block,CBlockIndex * const previndex,i fprintf(stderr,"A ht.%d now.%u htstamp.%u %u - pricebits[0] %u -> lags.%d %d %d\n",nHeight,now,prevtime,block->nTime,pricebits[0],lag,lag2,lag3); return(-1); } - if ( lag2 < -testchain_exemption ) // must be close to last block timestamp + if ( lag2 < -60 ) //testchain_exemption ) // must be close to last block timestamp { fprintf(stderr,"B ht.%d now.%u htstamp.%u %u - pricebits[0] %u -> lags.%d %d %d vs %d cmp.%d\n",nHeight,now,prevtime,block->nTime,pricebits[0],lag,lag2,lag3,ASSETCHAINS_BLOCKTIME,lag2<-ASSETCHAINS_BLOCKTIME); if ( nHeight > testchain_exemption ) @@ -2028,14 +2024,17 @@ uint32_t get_binanceprice(const char *symbol) return(price); } -int32_t get_cryptoprices(uint32_t *prices,const char *list[],int32_t n) +int32_t get_cryptoprices(uint32_t *prices,const char *list[],int32_t n,std::vector strvec) { - int32_t i,errs=0; uint32_t price; + int32_t i,errs=0; uint32_t price; char *symbol; for (i=0; i 333 ) // for debug only! - ASSETCHAINS_CBOPRET = 7; +//if ( komodo_nextheight() > 333 ) // for debug only! +// ASSETCHAINS_CBOPRET = 7; size = komodo_cbopretsize(ASSETCHAINS_CBOPRET); if ( Mineropret.size() < size ) Mineropret.resize(size); @@ -2160,19 +2158,19 @@ if ( komodo_nextheight() > 333 ) // for debug only! flags |= 2; memcpy(&PriceCache[0][size/sizeof(uint32_t)],forexprices,sizeof(forexprices)); } - size += sizeof(forexprices); + size += (sizeof(Forex)/sizeof(*Forex)) * sizeof(uint32_t); } if ( (ASSETCHAINS_CBOPRET & 4) != 0 ) { if ( forceflag != 0 || flags != 0 ) { - get_cryptoprices(cryptoprices,Cryptos,(int32_t)(sizeof(Cryptos)/sizeof(*Cryptos))); + get_cryptoprices(cryptoprices,Cryptos,(int32_t)(sizeof(Cryptos)/sizeof(*Cryptos)),ASSETCHAINS_PRICES); if ( flags == 0 ) komodo_PriceCache_shift(); - memcpy(&PriceCache[0][size/sizeof(uint32_t)],cryptoprices,sizeof(cryptoprices)); + memcpy(&PriceCache[0][size/sizeof(uint32_t)],cryptoprices,(sizeof(Cryptos)/sizeof(*Cryptos)+ASSETCHAINS_PRICES.size()) * sizeof(uint32_t)); flags |= 4; // very rarely we can see flags == 6 case } - size += sizeof(cryptoprices); + size += (sizeof(Cryptos)/sizeof(*Cryptos)+ASSETCHAINS_PRICES.size()) * sizeof(uint32_t); } if ( flags != 0 ) { @@ -2205,10 +2203,35 @@ if ( komodo_nextheight() > 333 ) // for debug only! pending = 0; } +int64_t komodo_pricemult(int32_t ind) +{ + int32_t i,j; + if ( (ASSETCHAINS_CBOPRET & 1) != 0 && ind < KOMODO_MAXPRICES ) + { + if ( PriceMult[0] == 0 ) + { + for (i=0; i<4; i++) + PriceMult[i] = 10000; + if ( (ASSETCHAINS_CBOPRET & 2) != 0 ) + { + for (j=0; j= KOMODO_MAXPRICES ) return(-1); - if ( ind < 36 ) - mult = 10000; - else mult = 1; + mult = PriceMult[ind]; memset(nonzprices,0,sizeof(*nonzprices)*daywindow); for (iter=0; iter outVals); void komodo_args(char *argv0) { extern const char *Notaries_elected1[][2]; - std::string name,addn,hexstr; char *dirname,fname[512],arg0str[64],magicstr[9]; uint8_t magic[4],extrabuf[8192],disablebits[32],*extraptr=0; FILE *fp; uint64_t val; uint16_t port; int32_t i,nonz=0,baseid,len,n,extralen = 0; uint64_t ccenables[256]; + std::string name,addn,hexstr,symbol; char *dirname,fname[512],arg0str[64],magicstr[9]; uint8_t magic[4],extrabuf[8192],disablebits[32],*extraptr=0; FILE *fp; uint64_t val; uint16_t port; int32_t i,nonz=0,baseid,len,n,extralen = 0; uint64_t ccenables[256]; IS_KOMODO_NOTARY = GetBoolArg("-notary", false); IS_STAKED_NOTARY = GetArg("-stakednotary", -1); if ( IS_STAKED_NOTARY != -1 && IS_KOMODO_NOTARY == true ) { @@ -1735,7 +1735,7 @@ void komodo_args(char *argv0) { printf("KOMODO_REWIND %d\n",KOMODO_REWIND); } - if ( name.c_str()[0] != 0 ) + if ( name.c_str()[0] != 0 ) { std::string selectedAlgo = GetArg("-ac_algo", std::string(ASSETCHAINS_ALGORITHMS[0])); @@ -2075,6 +2075,15 @@ void komodo_args(char *argv0) if ( ASSETCHAINS_CBOPRET != 0 ) { extralen += iguana_rwnum(1,&extraptr[extralen],sizeof(ASSETCHAINS_CBOPRET),(void *)&ASSETCHAINS_CBOPRET); + if ( ASSETCHAINS_PRICES.size() != 0 ) + { + for (i=0; i Date: Wed, 3 Apr 2019 06:07:13 -1100 Subject: [PATCH 02/31] Move symbols --- src/komodo_gateway.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index b70574677..8c976ebe1 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1556,8 +1556,8 @@ extern std::vector Mineropret; // opreturn data set by the data gatheri #define issue_curl(cmdstr) bitcoind_RPC(0,(char *)"CBCOINBASE",cmdstr,0,0,0) -const char *Cryptos[] = { "KMD", "ETH", "LTC", "BCHABC", "XMR", "IOTA", "DASH", "XEM", "ZEC", "WAVES", "RVN", "LSK", "DCR", "BTS", "ICX", "HOT", "STEEM", "ENJ", "STRAT" }; // must be on binance (for now) - +const char *Cryptos[] = { "KMD", "ETH", "LTC", "BCHABC", "XMR", "IOTA", "ZEC", "WAVES", "LSK", "DCR" }; // must be on binance (for now) +//"RVN", "DASH", "XEM", "BTS", "ICX", "HOT", "STEEM", "ENJ", "STRAT" const char *Forex[] = { "BGN","NZD","ILS","RUB","CAD","PHP","CHF","AUD","JPY","TRY","HKD","MYR","HRK","CZK","IDR","DKK","NOK","HUF","GBP","MXN","THB","ISK","ZAR","BRL","SGD","PLN","INR","KRW","RON","CNY","SEK","EUR" }; // must be in ECB list From ddee092afbe481b075c4c5107eaad02d06822aa7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 3 Apr 2019 06:08:56 -1100 Subject: [PATCH 03/31] Fix --- src/komodo_gateway.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 8c976ebe1..a81a6c6f3 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -2030,8 +2030,8 @@ int32_t get_cryptoprices(uint32_t *prices,const char *list[],int32_t n,std::vect for (i=0; i Date: Wed, 3 Apr 2019 06:10:27 -1100 Subject: [PATCH 04/31] "RVN", "DASH", "XEM", "BTS", "ICX", "HOT", "STEEM", "ENJ", "STRAT" --- src/rpc/blockchain.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index 7e7a44f7c..5f1d671e4 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -1180,7 +1180,7 @@ int64_t komodo_pricesmoothed(int64_t *correlated,int32_t numprices,int64_t *corr int64_t komodo_pricecorrelated(uint64_t seed,int32_t ind,uint32_t *rawprices,int32_t numprices,uint32_t *rawprices2,int32_t smoothwidth); int32_t komodo_nextheight(); uint32_t komodo_heightstamp(int32_t height); -int64_t komodo_pricesmult(int32_t ind); +int64_t komodo_pricemult(int32_t ind); UniValue prices(const UniValue& params, bool fHelp) { @@ -1252,7 +1252,7 @@ UniValue prices(const UniValue& params, bool fHelp) offset = j*width + i; smoothed = komodo_pricesmoothed(&correlated[i],daywindow,correlated2,smoothwidth); UniValue parr(UniValue::VARR); - parr.push_back(ValueFromAmount((int64_t)prices[offset] * komodo_pricesmult(j))); + parr.push_back(ValueFromAmount((int64_t)prices[offset] * komodo_pricemult(j))); parr.push_back(ValueFromAmount(correlated[i])); parr.push_back(ValueFromAmount(smoothed)); p.push_back(parr); From 02938d0a127484a3e2b979fd09c8a7d57898242c Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 3 Apr 2019 06:13:37 -1100 Subject: [PATCH 05/31] Test --- src/komodo_utils.h | 2 +- src/util.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_utils.h b/src/komodo_utils.h index c807eff48..2d0fe4f4e 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1665,7 +1665,7 @@ uint64_t komodo_ac_block_subsidy(int nHeight) extern int64_t MAX_MONEY; void komodo_cbopretupdate(int32_t forceflag); -void SplitStr(const std::string& strVal, std::vector outVals); +void SplitStr(const std::string& strVal, std::vector &outVals); void komodo_args(char *argv0) { diff --git a/src/util.cpp b/src/util.cpp index 4265ff759..b8733ffca 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -394,7 +394,7 @@ void ParseParameters(int argc, const char* const argv[]) } } -void SplitStr(const std::string& strVal, std::vector outVals) +void SplitStr(const std::string& strVal, std::vector &outVals) { stringstream ss(strVal); std::string str; From cd16c88711502ce727863730fb39b209e363a62a Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 3 Apr 2019 06:22:53 -1100 Subject: [PATCH 06/31] Fix --- src/komodo_gateway.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index a81a6c6f3..28ed3ee3a 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1556,8 +1556,8 @@ extern std::vector Mineropret; // opreturn data set by the data gatheri #define issue_curl(cmdstr) bitcoind_RPC(0,(char *)"CBCOINBASE",cmdstr,0,0,0) -const char *Cryptos[] = { "KMD", "ETH", "LTC", "BCHABC", "XMR", "IOTA", "ZEC", "WAVES", "LSK", "DCR" }; // must be on binance (for now) -//"RVN", "DASH", "XEM", "BTS", "ICX", "HOT", "STEEM", "ENJ", "STRAT" +const char *Cryptos[] = { "KMD", "ETH" }; // must be on binance (for now) +// "LTC", "BCHABC", "XMR", "IOTA", "ZEC", "WAVES", "LSK", "DCR", "RVN", "DASH", "XEM", "BTS", "ICX", "HOT", "STEEM", "ENJ", "STRAT" const char *Forex[] = { "BGN","NZD","ILS","RUB","CAD","PHP","CHF","AUD","JPY","TRY","HKD","MYR","HRK","CZK","IDR","DKK","NOK","HUF","GBP","MXN","THB","ISK","ZAR","BRL","SGD","PLN","INR","KRW","RON","CNY","SEK","EUR" }; // must be in ECB list @@ -2027,7 +2027,7 @@ uint32_t get_binanceprice(const char *symbol) int32_t get_cryptoprices(uint32_t *prices,const char *list[],int32_t n,std::vector strvec) { int32_t i,errs=0; uint32_t price; char *symbol; - for (i=0; i Date: Wed, 3 Apr 2019 06:37:57 -1100 Subject: [PATCH 07/31] Remove , --- src/util.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/util.cpp b/src/util.cpp index b8733ffca..980d82ac9 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -404,6 +404,10 @@ void SplitStr(const std::string& strVal, std::vector &outVals) while ( ss >> str ) { + if ( str.size() == 0 ) + continue; + if ( str[str.size()-1] == ',' ) + str.resize(str.size()-1); outVals.push_back(str); while ( ss.peek() == ' ' ) ss.ignore(); From 9b565ea675e39a68214e51ee64cd992d38f81305 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 3 Apr 2019 07:00:43 -1100 Subject: [PATCH 08/31] Handle early block prices --- src/rpc/blockchain.cpp | 42 ++++++++++++++++++++++++++++-------------- 1 file changed, 28 insertions(+), 14 deletions(-) diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index 5f1d671e4..ce27238a9 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -1188,7 +1188,7 @@ UniValue prices(const UniValue& params, bool fHelp) if ( fHelp || params.size() != 1 ) throw runtime_error("prices maxsamples\n"); LOCK(cs_main); - UniValue ret(UniValue::VOBJ); uint64_t seed,rngval; int64_t smoothed,*correlated,*correlated2; char name[64],*str; uint32_t rawprices[1440*6],*prices,*prices2; uint32_t i,width,j,numpricefeeds=-1,n,nextheight,offset,ht,num=0,daywindow = (3600*24/ASSETCHAINS_BLOCKTIME) + 1; + UniValue ret(UniValue::VOBJ); uint64_t seed,rngval; int64_t smoothed,*correlated,*correlated2; char name[64],*str; uint32_t rawprices[1440*6],*prices,*prices2; uint32_t i,width,j,numpricefeeds=-1,n,num,nextheight,offset,ht,num=0,daywindow = (3600*24/ASSETCHAINS_BLOCKTIME) + 1; if ( ASSETCHAINS_CBOPRET == 0 ) throw JSONRPCError(RPC_INVALID_PARAMETER, "only -ac_cbopret chains have prices"); @@ -1225,6 +1225,7 @@ UniValue prices(const UniValue& params, bool fHelp) } else throw JSONRPCError(RPC_INVALID_PARAMETER, "no komodo_rawprices found"); } } + num = i; ret.push_back(Pair("firstheight", (int64_t)nextheight-1-i)); UniValue timestamps(UniValue::VARR); for (i=0; i= width ) { - offset = j*width + i; - rngval = (rngval*11109 + 13849); - if ( (correlated[i]= komodo_pricecorrelated(rngval,j,&prices[offset],daywindow,prices2,smoothwidth)) < 0 ) - throw JSONRPCError(RPC_INVALID_PARAMETER, "null correlated price"); + for (i=0; i Date: Wed, 3 Apr 2019 07:01:10 -1100 Subject: [PATCH 09/31] Parr -> p --- src/rpc/blockchain.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index ce27238a9..61ea71476 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -1266,9 +1266,7 @@ UniValue prices(const UniValue& params, bool fHelp) for (i=0; i Date: Wed, 3 Apr 2019 07:02:44 -1100 Subject: [PATCH 10/31] numsamples --- src/rpc/blockchain.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index 61ea71476..18927ce8b 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -1188,7 +1188,7 @@ UniValue prices(const UniValue& params, bool fHelp) if ( fHelp || params.size() != 1 ) throw runtime_error("prices maxsamples\n"); LOCK(cs_main); - UniValue ret(UniValue::VOBJ); uint64_t seed,rngval; int64_t smoothed,*correlated,*correlated2; char name[64],*str; uint32_t rawprices[1440*6],*prices,*prices2; uint32_t i,width,j,numpricefeeds=-1,n,num,nextheight,offset,ht,num=0,daywindow = (3600*24/ASSETCHAINS_BLOCKTIME) + 1; + UniValue ret(UniValue::VOBJ); uint64_t seed,rngval; int64_t smoothed,*correlated,*correlated2; char name[64],*str; uint32_t rawprices[1440*6],*prices,*prices2; uint32_t i,width,j,numpricefeeds=-1,n,numsamples,nextheight,offset,ht,daywindow = (3600*24/ASSETCHAINS_BLOCKTIME) + 1; if ( ASSETCHAINS_CBOPRET == 0 ) throw JSONRPCError(RPC_INVALID_PARAMETER, "only -ac_cbopret chains have prices"); @@ -1225,7 +1225,7 @@ UniValue prices(const UniValue& params, bool fHelp) } else throw JSONRPCError(RPC_INVALID_PARAMETER, "no komodo_rawprices found"); } } - num = i; + numsamples = i; ret.push_back(Pair("firstheight", (int64_t)nextheight-1-i)); UniValue timestamps(UniValue::VARR); for (i=0; i= width ) + if ( numsamples >= width ) { - for (i=0; i Date: Wed, 3 Apr 2019 07:07:25 -1100 Subject: [PATCH 11/31] Test --- src/rpc/blockchain.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index 18927ce8b..e7893a458 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -1266,7 +1266,7 @@ UniValue prices(const UniValue& params, bool fHelp) for (i=0; i Date: Wed, 3 Apr 2019 07:10:39 -1100 Subject: [PATCH 12/31] -) --- src/rpc/blockchain.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index e7893a458..fe4d71bf4 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -1266,7 +1266,7 @@ UniValue prices(const UniValue& params, bool fHelp) for (i=0; i Date: Wed, 3 Apr 2019 07:13:40 -1100 Subject: [PATCH 13/31] Nested --- src/rpc/blockchain.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index fe4d71bf4..11c8067f7 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -1266,7 +1266,9 @@ UniValue prices(const UniValue& params, bool fHelp) for (i=0; i Date: Wed, 3 Apr 2019 07:16:02 -1100 Subject: [PATCH 14/31] Ht limit --- src/rpc/blockchain.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index 11c8067f7..0b0f0030c 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -1207,7 +1207,8 @@ UniValue prices(const UniValue& params, bool fHelp) correlated = (int64_t *)calloc(sizeof(*correlated),width); correlated2 = (int64_t *)calloc(sizeof(*correlated2),width); prices2 = (uint32_t *)calloc(sizeof(*prices2),width); - for (ht=nextheight-1,i=0; i2*daywindow+2+smoothwidth; i++,ht--) + i = 0; + for (ht=nextheight-1,i=0; i2; i++,ht--) { if ( ht < 0 || ht > chainActive.Height() ) throw JSONRPCError(RPC_INVALID_PARAMETER, "Block height out of range"); From 3155223e5176b534eea98b4448fb81954a453de3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 5 Apr 2019 21:17:53 -1100 Subject: [PATCH 15/31] Compiler errors --- src/cc/CCPrices.h | 22 +- src/cc/payments.cpp | 72 ++++ src/cc/prices.cpp | 835 +++++++++++++++++++++++++---------------- src/komodo_defs.h | 1 + src/komodo_gateway.h | 117 +++--- src/rpc/blockchain.cpp | 69 +++- src/txdb.cpp | 109 +++++- 7 files changed, 800 insertions(+), 425 deletions(-) diff --git a/src/cc/CCPrices.h b/src/cc/CCPrices.h index 1a68be7dd..9f3039a6b 100644 --- a/src/cc/CCPrices.h +++ b/src/cc/CCPrices.h @@ -18,17 +18,27 @@ #define CC_PRICES_H #include "CCinclude.h" +int32_t prices_extract(int64_t *pricedata,int32_t firstheight,int32_t numblocks,int32_t ind,int32_t daywindow); + +#define PRICES_DAYWINDOW ((3600*24/ASSETCHAINS_BLOCKTIME) + 1) +#define PRICES_TXFEE 10000 +#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_MUL (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) bool PricesValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); // CCcustom UniValue PricesList(); -UniValue PricesInfo(uint256 fundingtxid); -UniValue PricesStatus(uint64_t txfee,uint256 refbettoken,uint256 fundingtxid,uint256 bettxid); -std::string PricesCreateFunding(uint64_t txfee,uint256 bettoken,uint256 oracletxid,uint64_t margin,uint64_t mode,uint256 longtoken,uint256 shorttoken,int32_t maxleverage,int64_t funding,std::vector pubkeys); -std::string PricesAddFunding(uint64_t txfee,uint256 bettoken,uint256 fundingtxid,int64_t amount); -std::string PricesBet(uint64_t txfee,uint256 bettoken,uint256 fundingtxid,int64_t amount,int32_t leverage); -std::string PricesFinish(uint64_t txfee,uint256 bettoken,uint256 fundingtxid,uint256 bettxid); +UniValue PricesBet(uint64_t txfee,int64_t amount,int32_t leverage,std::string synthetic); #endif diff --git a/src/cc/payments.cpp b/src/cc/payments.cpp index e0c4c8ada..ae83e2661 100644 --- a/src/cc/payments.cpp +++ b/src/cc/payments.cpp @@ -732,6 +732,78 @@ UniValue PaymentsCreate(struct CCcontract_info *cp,char *jsonstr) return(result); } +UniValue PaymentsAirdrop(struct CCcontract_info *cp,char *jsonstr) +{ + // need to code: exclude list of tokenid, dust threshold, maxpayees, excluded pubkeys[] + CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); + UniValue result(UniValue::VOBJ); CTransaction tx; CPubKey Paymentspk,mypk; char markeraddr[64]; std::vector txidoprets; uint256 hashBlock; int32_t i,n,numoprets=0,lockedblocks,minrelease; std::string rawtx; int64_t totalallocations = 0; + cJSON *params = payments_reparse(&n,jsonstr); + if ( params != 0 && n >= 4 ) + { + lockedblocks = juint(jitem(params,0),0); + minrelease = juint(jitem(params,1),0); + if ( lockedblocks < 0 || minrelease < 0 ) + { + result.push_back(Pair("result","error")); + result.push_back(Pair("error","negative parameter")); + if ( params != 0 ) + free_json(params); + return(result); + } + for (i=0; i scriptPubKey,opret; int64_t allocation; + if ( myGetTransaction(txidoprets[i],tx,hashBlock) != 0 && tx.vout.size() > 1 && DecodePaymentsTxidOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,allocation,scriptPubKey,opret) == 'T' ) + { + totalallocations += allocation; + if ( opret.size() > 0 ) + numoprets++; + } + else + { + result.push_back(Pair("result","error")); + result.push_back(Pair("error","invalid txidopret")); + result.push_back(Pair("txid",txidoprets[i].GetHex())); + result.push_back(Pair("txi",(int64_t)i)); + if ( params != 0 ) + free_json(params); + return(result); + } + } + if ( numoprets > 1 ) + { + result.push_back(Pair("result","error")); + result.push_back(Pair("error","too many opreturns")); + result.push_back(Pair("numoprets",(int64_t)numoprets)); + if ( params != 0 ) + free_json(params); + return(result); + } + mypk = pubkey2pk(Mypubkey()); + Paymentspk = GetUnspendable(cp,0); + if ( AddNormalinputs(mtx,mypk,2*PAYMENTS_TXFEE,60) > 0 ) + { + mtx.vout.push_back(MakeCC1of2vout(cp->evalcode,PAYMENTS_TXFEE,Paymentspk,Paymentspk)); + rawtx = FinalizeCCTx(0,cp,mtx,mypk,PAYMENTS_TXFEE,EncodePaymentsOpRet(lockedblocks,minrelease,totalallocations,txidoprets)); + if ( params != 0 ) + free_json(params); + return(payments_rawtxresult(result,rawtx,1)); + } + result.push_back(Pair("result","error")); + result.push_back(Pair("error","not enough normal funds")); + } + else + { + result.push_back(Pair("result","error")); + result.push_back(Pair("error","parameters error")); + } + if ( params != 0 ) + free_json(params); + return(result); +} + UniValue PaymentsInfo(struct CCcontract_info *cp,char *jsonstr) { UniValue result(UniValue::VOBJ),a(UniValue::VARR); CTransaction tx,txO; CPubKey Paymentspk,txidpk; int32_t i,j,n,flag=0,numoprets=0,lockedblocks,minrelease; std::vector txidoprets; int64_t funds,fundsopret,totalallocations=0,allocation; char fundsaddr[64],fundsopretaddr[64],txidaddr[64],*outstr; uint256 createtxid,hashBlock; diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 1ab5aa1cb..eab975acd 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -17,123 +17,115 @@ #include "CCPrices.h" /* - Prices CC would best build on top of the oracles CC, ie. to combine payments for multiple oracles and to calculate a 51% protected price feed. +CBOPRET creates trustless oracles, which can be used for making a synthetic cash settlement system based on real world prices; - We need to assume there is an oracle for a specific price. In the event there are more than one provider, the majority need to be within correlation distance to update a pricepoint. - - int64_t OraclePrice(int32_t height,uint256 reforacletxid,char *markeraddr,char *format); - - Using the above function, a consensus price can be obtained for a datasource. + 0.5% fee based on betamount, NOT leveraged betamount!! + 0.1% collected by price basis determinant + 0.2% collected by rekt tx - given an oracletxid, the marketaddr and format can be extracted to be used for future calls to OraclePrice. This allows to set a starting price and that in turn allows cash settled leveraged trading! + PricesBet -> +/-leverage, amount, synthetic -> opreturn includes current price + funds are locked into 1of2 global CC address + for first day, long basis is MAX(correlated,smoothed), short is MIN() + reference price is the smoothed of the previous block + if synthetic value + amount goes negative, then anybody can rekt it to collect a rektfee, proof of rekt must be included to show cost basis, rekt price + original creator can liquidate at anytime and collect (synthetic value + amount) from globalfund + 0.5% of bet -> globalfund + + PricesStatus -> bettxid maxsamples returns initial params, cost basis, amount left, rekt:true/false, rektheight, initial synthetic price, current synthetic price, net gain - Funds work like with dice, ie. there is a Prices plan that traders bet against. + PricesRekt -> bettxid height -> 0.1% to miner, rest to global CC - PricesFunding oracletxid, margin, priceaveraging, maxleverage, funding, longtoken, shorttoken, N [pubkeys] + PricesClose -> bettxid returns (synthetic value + amount) - PricesBet -> oracletxid start with 'L', leverage, funding, direction - funds are locked into global CC address - it can be closed at anytime by the trader for cash settlement - the house account can close it if rekt + PricesList -> all bettxid -> list [bettxid, netgain] - Implementation Notes: - In order to eliminate the need for worrying about sybil attacks, each prices plan would be able to specific pubkey(s?) for whitelisted publishers. It would be possible to have a non-whitelisted plan that would use 50% correlation between publishers. - - delta neutral balancing of riskexposure: fabs(long exposure - short exposure) - bet +B at leverage L - absval(sum(+BLi) - sum(-Bli)) - - validate: update riskexposure and it needs to be <= funds - - PricesProfits: limit withdraw to funds in excess of riskexposure - PricesFinish: payout (if winning) and update riskexposure - need long/short exposure assets - - funding -> 1of2 CC global CC address and dealer address, exposure tokens to global 1of2 assets CC address - pricebet -> user funds and exposure token to 1of2 address. - pricewin -> winnings from dealer funds, exposure token back to global address - priceloss -> exposuretoken back to global address - - exposure address, funds address - - */ // start of consensus code -int64_t PricesOraclePrice(int64_t &rektprice,uint64_t mode,uint256 oracletxid,std::vectorpubkeys,int32_t dir,int64_t amount,int32_t leverage) -{ - int64_t price; - // howto ensure price when block it confirms it not known - // get price from oracle + current chaintip - // normalize leveraged amount - if ( dir > 0 ) - rektprice = price * leverage / (leverage-1); - else rektprice = price * (leverage-1) / leverage; - return(price); -} - -CScript EncodePricesFundingOpRet(uint8_t funcid,CPubKey planpk,uint256 oracletxid,uint256 longtoken,uint256 shorttoken,int32_t millimargin,uint64_t mode,int32_t maxleverage,std::vector pubkeys,uint256 bettoken) +CScript prices_betopret(CPubKey mypk,int32_t height,int64_t amount,int16_t leverage,int64_t firstprice,std::vector vec,uint256 tokenid) { CScript opret; - fprintf(stderr,"implement EncodePricesFundingOpRet\n"); + opret << OP_RETURN << E_MARSHAL(ss << EVAL_PRICES << 'B' << mypk << height << amount << leverage << firstprice << vec << tokenid); return(opret); } -uint8_t DecodePricesFundingOpRet(CScript scriptPubKey,CPubKey &planpk,uint256 &oracletxid,uint256 &longtoken,uint256 &shorttoken,int32_t &millimargin,uint64_t &mode,int32_t &maxleverage,std::vector &pubkeys,uint256 &bettoken) +uint8_t prices_betopretdecode(CScript scriptPubKey,CPubKey &pk,int32_t &height,int64_t &amount,int16_t &leverage,int64_t &firstprice,std::vector &vec,uint256 &tokenid) { - fprintf(stderr,"implement DecodePricesFundingOpRet\n"); + std::vector vopret; uint8_t e,f; + GetOpReturnData(scriptPubKey,vopret); + if ( vopret.size() > 2 && E_UNMARSHAL(vopret,ss >> e; ss >> f; ss >> pk; ss >> height; ss >> amount; ss >> leverage; ss >> firstprice; ss >> vec; ss >> tokenid) != 0 && e == EVAL_PRICES && f == 'B' ) + { + return(f); + } + return(0); +} + +CScript prices_addopret(uint256 bettxid,CPubKey mypk,int64_t amount) +{ + CScript opret; + opret << OP_RETURN << E_MARSHAL(ss << EVAL_PRICES << 'A' << bettxid << mypk << amount); + return(opret); +} + +uint8_t prices_addopretdecode(CScript scriptPubKey,uint256 &bettxid,CPubKey &pk,int64_t &amount) +{ + std::vector vopret; uint8_t e,f; + GetOpReturnData(scriptPubKey,vopret); + if ( vopret.size() > 2 && E_UNMARSHAL(vopret,ss >> e; ss >> f; ss >> bettxid; ss >> pk; ss >> amount) != 0 && e == EVAL_PRICES && f == 'A' ) + { + return(f); + } + return(0); +} + +CScript prices_costbasisopret(uint256 bettxid,CPubKey mypk,int32_t height,int64_t costbasis) +{ + CScript opret; + opret << OP_RETURN << E_MARSHAL(ss << EVAL_PRICES << 'C' << bettxid << mypk << height << costbasis); + return(opret); +} + +uint8_t prices_costbasisopretdecode(CScript scriptPubKey,uint256 &bettxid,CPubKey &pk,int32_t &height,int64_t &costbasis) +{ + std::vector vopret; uint8_t e,f; + GetOpReturnData(scriptPubKey,vopret); + if ( vopret.size() > 2 && E_UNMARSHAL(vopret,ss >> e; ss >> f; ss >> bettxid; ss >> pk; ss >> height; ss >> costbasis) != 0 && e == EVAL_PRICES && f == 'C' ) + { + return(f); + } + return(0); +} + +CScript prices_finalopret(uint256 bettxid,int64_t profits,int32_t height,CPubKey mypk,int64_t firstprice,int64_t costbasis,int64_t addedbets,int64_t positionsize,int16_t leverage) +{ + CScript opret; + opret << OP_RETURN << E_MARSHAL(ss << EVAL_PRICES << 'F' << bettxid << profits << height << mypk << firstprice << costbasis << addedbets << positionsize << leverage); + return(opret); +} + +uint8_t prices_finalopretdecode(CScript scriptPubKey,uint256 &bettxid,int64_t &profits,int32_t &height,CPubKey &pk,int64_t &firstprice,int64_t &costbasis,int64_t &addedbets,int64_t &positionsize,int16_t &leverage) +{ + std::vector vopret; uint8_t e,f; + GetOpReturnData(scriptPubKey,vopret); + if ( vopret.size() > 2 && E_UNMARSHAL(vopret,ss >> e; ss >> f; ss >> bettxid; ss >> profits; ss >> height; ss >> pk; ss >> firstprice; ss >> costbasis; ss >> addedbets; ss >> positionsize; ss >> leverage) != 0 && e == EVAL_PRICES && f == 'F' ) + { + return(f); + } return(0); } bool PricesValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn) { - int32_t numvins,numvouts,preventCCvins,preventCCvouts,i,numblocks; bool retval; uint256 txid; uint8_t hash[32]; char str[65],destaddr[64]; - - return true; // TODO remove, for test dual-evals - - return eval->Invalid("no validation yet"); - std::vector > txids; - numvins = tx.vin.size(); - numvouts = tx.vout.size(); - preventCCvins = preventCCvouts = -1; - if ( numvouts < 1 ) - return eval->Invalid("no vouts"); - else - { - for (i=0; iInvalid("illegal normal vini"); - } - } - //fprintf(stderr,"check amounts\n"); - //if ( PricesExactAmounts(cp,eval,tx,1,10000) == false ) - { - fprintf(stderr,"Pricesget invalid amount\n"); - return false; - } - //else - { - txid = tx.GetHash(); - memcpy(hash,&txid,sizeof(hash)); - retval = PreventCC(eval,tx,preventCCvins,numvins,preventCCvouts,numvouts); - if ( retval != 0 ) - fprintf(stderr,"Pricesget validated\n"); - else fprintf(stderr,"Pricesget invalid\n"); - return(retval); - } - } + return true; } // end of consensus code // helper functions for rpc calls in rpcwallet.cpp -int64_t AddTokensInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,char *destaddr,uint256 tolenid,int64_t total,int32_t maxinputs) +int64_t AddPricesInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,char *destaddr,int64_t total,int32_t maxinputs,uint256 vintxid,int32_t vinvout) { - // add threshold check int64_t nValue,price,totalinputs = 0; uint256 txid,hashBlock; std::vector origpubkey; CTransaction vintx; int32_t vout,n = 0; std::vector > unspentOutputs; SetCCunspents(unspentOutputs,destaddr); @@ -141,11 +133,11 @@ int64_t AddTokensInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,char { txid = it->first.txhash; vout = (int32_t)it->first.index; - // need to prevent dup + if ( vout == vinvout && txid == vintxid ) + continue; if ( GetTransaction(txid,vintx,hashBlock,false) != 0 && vout < vintx.vout.size() ) { - // need to verify assetid - if ( (nValue= vintx.vout[vout].nValue) >= 10000 && myIsutxo_spentinmempool(ignoretxid,ignorevin,txid,vout) == 0 ) + if ( (nValue= vintx.vout[vout].nValue) >= total/maxinputs && myIsutxo_spentinmempool(ignoretxid,ignorevin,txid,vout) == 0 ) { if ( total != 0 && maxinputs != 0 ) mtx.vin.push_back(CTxIn(txid,vout,CScript())); @@ -162,7 +154,7 @@ int64_t AddTokensInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,char UniValue PricesList() { - UniValue result(UniValue::VARR); std::vector > addressIndex; struct CCcontract_info *cp,C; uint64_t mode; int32_t margin,maxleverage; std::vectorpubkeys; uint256 txid,hashBlock,oracletxid,longtoken,shorttoken,bettoken; CPubKey planpk,pricespk; char str[65]; CTransaction vintx; + UniValue result(UniValue::VARR); std::vector > addressIndex; struct CCcontract_info *cp,C; int64_t amount,firstprice; int32_t height; int16_t leverage; uint256 txid,hashBlock; CPubKey pk,pricespk; std::vector vec; CTransaction vintx; cp = CCinit(&C,EVAL_PRICES); pricespk = GetUnspendable(cp,0); SetCCtxids(addressIndex,cp->normaladdr); @@ -171,7 +163,7 @@ UniValue PricesList() txid = it->first.txhash; if ( GetTransaction(txid,vintx,hashBlock,false) != 0 ) { - if ( vintx.vout.size() > 0 && DecodePricesFundingOpRet(vintx.vout[vintx.vout.size()-1].scriptPubKey,planpk,oracletxid,longtoken,shorttoken,margin,mode,maxleverage,pubkeys,bettoken) == 'F' ) + if ( vintx.vout.size() > 0 && prices_betopretdecode(vintx.vout[vintx.vout.size()-1].scriptPubKey,pk,height,amount,leverage,firstprice,vec) == 'B' ) { result.push_back(uint256_str(str,txid)); } @@ -180,274 +172,455 @@ UniValue PricesList() return(result); } -// longtoken satoshis limits long exposure -// shorttoken satoshis limits short exposure -// both must be in the 1of2 CC address with its total supply -// bettoken -std::string PricesCreateFunding(uint64_t txfee,uint256 bettoken,uint256 oracletxid,uint64_t margin,uint64_t mode,uint256 longtoken,uint256 shorttoken,int32_t maxleverage,int64_t funding,std::vector pubkeys) +UniValue prices_rawtxresult(UniValue &result,std::string rawtx,int32_t broadcastflag) { - CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CTransaction oracletx; int64_t fullsupply,inputs,CCchange=0; uint256 hashBlock; char str[65],coinaddr[64],houseaddr[64]; CPubKey mypk,pricespk; int32_t i,N,numvouts; struct CCcontract_info *cp,C; - if ( funding < 100*COIN || maxleverage <= 0 || maxleverage > 10000 ) + CTransaction tx; + if ( rawtx.size() > 0 ) { - CCerror = "invalid parameter error"; - fprintf(stderr,"%s\n", CCerror.c_str() ); - return(""); - } - cp = CCinit(&C,EVAL_PRICES); - if ( txfee == 0 ) - txfee = 10000; - mypk = pubkey2pk(Mypubkey()); - pricespk = GetUnspendable(cp,0); - if ( (N= (int32_t)pubkeys.size()) || N > 15 ) - { - fprintf(stderr,"too many pubkeys N.%d\n",N); - return(""); - } - for (i=0; i 0 ) - { - mtx.vout.push_back(CTxOut(txfee,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); - mtx.vout.push_back(CTxOut(txfee,CScript() << ParseHex(HexStr(pricespk)) << OP_CHECKSIG)); - return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodePricesFundingOpRet('F',mypk,oracletxid,longtoken,shorttoken,margin,mode,maxleverage,pubkeys,bettoken))); - } - else - { - CCerror = "cant find enough inputs"; - fprintf(stderr,"%s\n", CCerror.c_str() ); - } - return(""); + if ( broadcastflag != 0 && myAddtomempool(tx) != 0 ) + RelayTransaction(tx); + result.push_back(Pair("txid",tx.GetHash().ToString())); + result.push_back(Pair("result","success")); + } else result.push_back(Pair("error","decode hex")); + } else result.push_back(Pair("error","couldnt finalize CCtx")); + return(result); } -UniValue PricesInfo(uint256 fundingtxid) +int32_t prices_syntheticvec(std::vector &vec,std::vector synthetic) { - UniValue result(UniValue::VOBJ),a(UniValue::VARR); CPubKey pricespk,planpk; uint256 hashBlock,oracletxid,longtoken,shorttoken,bettoken; CTransaction vintx; int64_t balance,supply,exposure; uint64_t funding,mode; int32_t i,margin,maxleverage; char numstr[65],houseaddr[64],exposureaddr[64],str[65]; std::vectorpubkeys; struct CCcontract_info *cp,C; - cp = CCinit(&C,EVAL_PRICES); - pricespk = GetUnspendable(cp,0); - if ( GetTransaction(fundingtxid,vintx,hashBlock,false) == 0 ) + int32_t i,need,depth = 0; std::string opstr; uint16_t opcode,weight; + if ( synthetic.size() == 0 ) + return(-1); + for (i=0; i= 0 ) + opcode = ind, need = 0; + else if ( (weight= atoi(opstr.c_str())) > 0 && weight < KOMODO_MAXPRICES ) + { + opcode = PRICES_WEIGHT | weight; + need = 1; + } else return(-2); + if ( depth < need ) + return(-3); + depth -= need; + if ( (opcode & KOMODO_PRICEMASK) != PRICES_WEIGHT ) // weight + depth++; + if ( depth > 3 ) + return(-4); + vec.push_back(opcode); + } + if ( depth != 0 ) + { + fprintf(stderr,"depth.%d not empty\n",depth); + return(-5); + } + return(0); +} + +int64_t prices_syntheticprice(std::vector vec,int32_t height,int32_t minmax,int16_t leverage) +{ + int32_t i,errcode,depth,retval = -1; uint16_t opcode; int64_t *pricedata,stack[4],price,den,a,b,c; + pricedata = (int64_t *)calloc(sizeof(*pricedata)*3,numblocks + PRICES_DAYWINDOW*2 + PRICES_SMOOTHWIDTH); + price = den = depth = errcode = 0; + for (i=0; i 0 ) + pricestack[depth] = MAX(pricedata[1],pricedata[2]); + else pricestack[depth] = MIN(pricedata[1],pricedata[2]); + } + } + if ( pricestack[depth] == 0 ) + errcode = -1; + depth++; + break; + case PRICES_WEIGHT: // multiply by weight and consume top of stack by updating price + if ( depth == 1 ) + { + depth--; + price += pricestack[0] * ind; + den += ind; + } else errcode = -2; + break; + case PRICES_MUL: + if ( depth >= 2 ) + { + b = pricestack[--depth]; + a = pricestack[--depth]; + pricestack[depth++] = (a * b) / SATOSHIDEN; + } else errcode = -3; + break; + case PRICES_DIV: + if ( depth >= 2 ) + { + b = pricestack[--depth]; + a = pricestack[--depth]; + pricestack[depth++] = (a * SATOSHIDEN) / b; + } else errcode = -4; + break; + case PRICES_INV: + if ( depth >= 1 ) + { + a = pricestack[--depth]; + pricestack[depth++] = (SATOSHIDEN * SATOSHIDEN) / a; + } else errcode = -5; + break; + case PRICES_MDD: + if ( depth >= 3 ) + { + c = pricestack[--depth]; + b = pricestack[--depth]; + a = pricestack[--depth]; + pricestack[depth++] = (((a * SATOSHIDEN) / b) * SATOSHIDEN) / c; + } else errcode = -6; + break; + case PRICES_MMD: + if ( depth >= 3 ) + { + c = pricestack[--depth]; + b = pricestack[--depth]; + a = pricestack[--depth]; + pricestack[depth++] = (a * b) / c; + } else errcode = -7; + break; + case PRICES_MMM: + if ( depth >= 3 ) + { + c = pricestack[--depth]; + b = pricestack[--depth]; + a = pricestack[--depth]; + pricestack[depth++] = ((a * b) / SATOSHIDEN) * c; + } else errcode = -8; + break; + case PRICES_DDD: + if ( depth >= 3 ) + { + c = pricestack[--depth]; + b = pricestack[--depth]; + a = pricestack[--depth]; + pricestack[depth++] = (((((SATOSHIDEN * SATOSHIDEN) / a) * SATOSHIDEN) / b) * SATOSHIDEN) / c; + } else errcode = -9; + break; + default: + errcode = -10; + break; + } + if ( errcode != 0 ) + break; + } + free(pricedata); + if ( den == 0 ) + return(-11); + else if ( depth != 0 ) + return(-12); + else if ( errcode != 0 ) + return(errcode); + return(price / den); +} + +int64_t prices_syntheticprofits(int64_t &costbasis,int32_t firstheight,int32_t height,int16_t leverage,std::vector vec,int64_t positionsize,int64_t addedbets) +{ + int64_t price,profits = 0; int32_t minmax; + minmax = (height > firstheight+PRICES_DAYWINDOW); + if ( (price= prices_syntheticprice(vec,height,minmax)) < 0 ) + { + fprintf(stderr,"unexpected zero synthetic price at height.%d\n",height); + return(0); + } + if ( minmax != 0 ) + { + if ( leverage > 0 && price > costbasis ) + costbasis = price; + else if ( leverage < 0 && (costbasis == 0 || price < costbasis) ) + costbasis = price; + } + profits = ((price * SATOSHIDEN) / costbasis) - SATOSHIDEN; + profits *= leverage * positionsize; + return(positionsize + addedbets + profits) +} + +void prices_betjson(UniValue &result,int64_t profits,int64_t costbasis,int64_t positionsize,int64_t addedbets,int16_t leverage,int32_t firstheight,int64_t firstprice) +{ + result.push_back(Pair("profits",ValueFromAmount(profits))); + result.push_back(Pair("costbasis",ValueFromAmount(costbasis))); + result.push_back(Pair("positionsize",ValueFromAmount(positionsize))); + result.push_back(Pair("addedbets",ValueFromAmount(addedbets))); + result.push_back(Pair("leverage",(int64_t)leverage)); + result.push_back(Pair("firstheight",(int64_t)firstheight)); + result.push_back(Pair("firstprice",ValueFromAmount(firstprice))); +} + +int64_t prices_costbasis(CTransaction bettx) +{ + int64_t costbasis = 0; + // if vout1 is spent, follow and extract costbasis from opreturn + //uint8_t prices_costbasisopretdecode(CScript scriptPubKey,uint256 &bettxid,CPubKey &pk,int32_t &height,int64_t &costbasis) + + return(costbasis); +} + +int64_t prices_batontxid(uint256 &batontxid,CTransaction bettx,uint256 bettxid); +{ + int64_t addedbets = 0; + // iterate through batons, adding up vout1 -> addedbets + return(addedbets); +} + +UniValue PricesBet(uint64_t txfee,int64_t amount,int16_t leverage,std::vector synthetic) +{ + int32_t nextheight = komodo_nextheight(); + CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(),nextheight); UniValue result(UniValue::VOBJ); + struct CCcontract_info *cp,C; CPubKey pricespk,mypk; int64_t betamount,firstprice; std::vector vec; + if ( leverage > PRICES_MAXLEVERAGE || leverage < -PRICES_MAXLEVERAGE ) + { + result.push_back(Pair("result","error")); + result.push_back(Pair("error","leverage too big")); return(result); } - if ( vintx.vout.size() > 0 && DecodePricesFundingOpRet(vintx.vout[vintx.vout.size()-1].scriptPubKey,planpk,oracletxid,longtoken,shorttoken,margin,mode,maxleverage,pubkeys,bettoken) == 'F' ) - { - result.push_back(Pair("result","success")); - result.push_back(Pair("fundingtxid",uint256_str(str,fundingtxid))); - result.push_back(Pair("bettoken",uint256_str(str,bettoken))); - result.push_back(Pair("oracletxid",uint256_str(str,oracletxid))); - sprintf(numstr,"%.3f",(double)margin/1000); - result.push_back(Pair("profitmargin",numstr)); - result.push_back(Pair("maxleverage",maxleverage)); - result.push_back(Pair("mode",(int64_t)mode)); - for (i=0; ipubkeys; - if ( amount < 10000 ) - { - CCerror = "amount must be positive"; - fprintf(stderr,"%s\n", CCerror.c_str() ); - return(""); - } cp = CCinit(&C,EVAL_PRICES); if ( txfee == 0 ) - txfee = 10000; + txfee = PRICES_TXFEE; mypk = pubkey2pk(Mypubkey()); pricespk = GetUnspendable(cp,0); GetCCaddress(cp,myaddr,mypk); - if ( GetTransaction(fundingtxid,tx,hashBlock,false) == 0 ) + if ( prices_syntheticvec(vec,synthetic) < 0 || (firstprice= prices_syntheticprice(vec,nextheight-1,1)) < 0 || vec.size() == 0 || vec.size() > 4096 ) { - fprintf(stderr,"cant find fundingtxid\n"); - return(""); + result.push_back(Pair("result","error")); + result.push_back(Pair("error","invalid synthetic")); + return(result); } - if ( tx.vout.size() > 0 && DecodePricesFundingOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,planpk,oracletxid,longtoken,shorttoken,margin,mode,maxleverage,pubkeys,bettoken) == 'F' && bettoken == refbettoken ) + if ( AddNormalinputs(mtx,mypk,amount+4*txfee,64) >= amount+4*txfee ) { - GetCCaddress1of2(cp,houseaddr,pricespk,planpk); - if ( AddNormalinputs(mtx,mypk,2*txfee,3) > 0 ) - { - if ( (inputs= AddTokensInputs(cp,mtx,myaddr,bettoken,amount,60)) >= amount ) - { - mtx.vout.push_back(MakeCC1of2vout(cp->evalcode,amount,pricespk,planpk)); - mtx.vout.push_back(CTxOut(txfee,CScript() << ParseHex(HexStr(planpk)) << OP_CHECKSIG)); - if ( inputs > amount+txfee ) - CCchange = (inputs - amount); - mtx.vout.push_back(MakeCC1vout(cp->evalcode,CCchange,mypk)); - // add addr2 + betamount = (amount * 199) / 200; + mtx.vout.push_back(MakeCC1vout(cp->evalcode,txfee,mypk)); // baton for total funding + mtx.vout.push_back(MakeCC1vout(cp->evalcode,(amount-betamount)+2*txfee,pricespk)); + mtx.vout.push_back(MakeCC1of2vout(cp->evalcode,betamount,pricespk,mypk)); + rawtx = FinalizeCCTx(0,cp,mtx,mypk,txfee,prices_betopret(mypk,nextheight-1,amount,leverage,firstprice,vec,zeroid)); + return(prices_rawtxresult(result,rawtx,0)); + } + result.push_back(Pair("result","error")); + result.push_back(Pair("error","not enough funds")); + return(result); +} - std::vector voutTokenPubkeysEmpty; //TODO: add token vout pubkeys - return(FinalizeCCTx(0,cp,mtx,mypk,txfee, - EncodeTokenOpRet(bettoken, voutTokenPubkeysEmpty, - std::make_pair(OPRETID_ASSETSDATA, EncodeAssetOpRet('t',/*bettoken,*/zeroid, 0, Mypubkey()))))); +UniValue PricesAddFunding(uint64_t txfee,uint256 bettxid,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; int64_t addedbets=0,betamount,firstprice; std::vector vec; uint256 batonttxid; + cp = CCinit(&C,EVAL_PRICES); + if ( txfee == 0 ) + txfee = PRICES_TXFEE; + mypk = pubkey2pk(Mypubkey()); + pricespk = GetUnspendable(cp,0); + GetCCaddress(cp,myaddr,mypk); + if ( AddNormalinputs(mtx,mypk,amount+txfee,64) >= amount+txfee ) + { + if ( prices_batontxid(addedbets,batontxid,bettxid) >= 0 ) + { + mtx.vin.push_back(CTxVin(batontxid,0,CScript())); + mtx.vout.push_back(MakeCC1vout(cp->evalcode,txfee,mypk)); // baton for total funding + mtx.vout.push_back(MakeCC1vout(cp->evalcode,amount,pricespk)); + rawtx = FinalizeCCTx(0,cp,mtx,mypk,txfee,prices_addopret(bettxid,mypk,amount)); + return(prices_rawtxresult(result,rawtx,0)); + } + else + { + result.push_back(Pair("result","error")); + result.push_back(Pair("error","couldnt find batonttxid")); + return(result); + } + } + result.push_back(Pair("result","error")); + result.push_back(Pair("error","not enough funds")); + return(result); +} + +UniValue PricesSetcostbasis(uint64_t txfee,uint256 bettxid) +{ + int32_t nextheight = komodo_nextheight(); + CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(),nextheight); UniValue result(UniValue::VOBJ); + struct CCcontract_info *cp,C; CTransaction bettx; uint256 hashBlock; int64_t myfee,positionsize=0,addedbets,firstprice=0,profits=0,costbasis=0; int32_t i,firstheight=0,height,numvouts; int16_t leverage=0; std::vector vec; CPubKey pk,mypk,pricespk; std::string rawtx; + cp = CCinit(&C,EVAL_PRICES); + if ( txfee == 0 ) + txfee = PRICES_TXFEE; + mypk = pubkey2pk(Mypubkey()); + pricespk = GetUnspendable(cp,0); + if ( myGetTransaction(bettxid,bettx,hashBlock) != 0 && (numvouts= bettx.vout.size()) > 3 ) + { + if ( prices_betopretdecode(bettx.vout[numvouts-1].scriptPubKey,pk,firstheight,positionsize,leverage,firstprice,vec) == 'B' ) + { + addedbets = prices_addedbets(bettx); + mtx.vin.push_back(CTxVin(bettx,1,CScript())); + for (i=0; ievalcode,bettx.vout[1].nValue-myfee-txfee,pricespk)); + rawtx = FinalizeCCTx(0,cp,mtx,mypk,txfee,prices_costbasisopret(bettxid,mypk,firstheight+PRICES_DAYWINDOW-1,costbasis)); + return(prices_rawtxresult(result,rawtx,0)); + } + } + result.push_back(Pair("result","error")); + result.push_back(Pair("error","cant find bettxid")); + return(result); +} + +UniValue PricesRekt(uint64_t txfee,uint256 bettxid,int32_t rektheight) +{ + int32_t nextheight = komodo_nextheight(); + CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(),nextheight); UniValue result(UniValue::VOBJ); + struct CCcontract_info *cp,C; CTransaction bettx; uint256 hashBlock,tokenid; int64_t myfee=0,positionsize,addedbets,firstprice,profits,costbasis=0; int32_t firstheight,numvouts; int16_t leverage; std::vector vec; CPubKey pk,mypk,pricespk; std::string rawtx; + cp = CCinit(&C,EVAL_PRICES); + if ( txfee == 0 ) + txfee = PRICES_TXFEE; + mypk = pubkey2pk(Mypubkey()); + pricespk = GetUnspendable(cp,0); + if ( myGetTransaction(bettxid,bettx,hashBlock) != 0 && (numvouts= bettx.vout.size()) > 3 ) + { + if ( prices_betopretdecode(bettx.vout[numvouts-1].scriptPubKey,pk,firstheight,positionsize,leverage,firstprice,vec,tokenid) == 'B' ) + { + costbasis = prices_costbasis(bettx); + addedbets = prices_batontxid(batontxid,bettx,bettxid); + if ( (profits= prices_syntheticprofits(&ignore,firstheight,rektheight,leverage,vec,positionsize,addedbets)) < 0 ) + { + myfee = (positionsize + addedbets) / 500; + } + prices_betjson(result,profits,costbasis,positionsize,addedbets,leverage,firstheight,firstprice); + if ( myfee != 0 ) + { + mtx.vin.push_back(CTxVin(bettxid,2,CScript())); + 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)); + rawtx = FinalizeCCTx(0,cp,mtx,mypk,txfee,prices_finalopret(bettxid,profits,rektheight,mypk,firstprice,costbasis,addedbets,positionsize,leverage)); + return(prices_rawtxresult(result,rawtx,0)); } else { - CCerror = "cant find enough bet inputs"; - fprintf(stderr,"%s\n", CCerror.c_str() ); + result.push_back(Pair("result","error")); + result.push_back(Pair("error","position not rekt")); + return(result); } } else { - CCerror = "cant find enough inputs"; - fprintf(stderr,"%s\n", CCerror.c_str() ); + result.push_back(Pair("result","error")); + result.push_back(Pair("error","cant decode opret")); + return(result); } } - return(""); -} - -std::string PricesBet(uint64_t txfee,uint256 refbettoken,uint256 fundingtxid,int64_t amount,int32_t leverage) -{ - CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - struct CCcontract_info *cp,C; CPubKey pricespk,planpk,mypk; uint256 hashBlock,oracletxid,longtoken,shorttoken,tokenid,bettoken; CTransaction tx; int64_t balance,supply,exposure,inputs,inputs2,longexposure,netexposure,shortexposure,CCchange = 0,CCchange2 = 0; uint64_t funding,mode; int32_t dir,margin,maxleverage; char houseaddr[64],myaddr[64],exposureaddr[64]; std::vectorpubkeys; - if ( amount < 0 ) - { - amount = -amount; - dir = -1; - } else dir = 1; - cp = CCinit(&C,EVAL_PRICES); - if ( txfee == 0 ) - txfee = 10000; - mypk = pubkey2pk(Mypubkey()); - pricespk = GetUnspendable(cp,0); - GetCCaddress(cp,myaddr,mypk); - if ( GetTransaction(fundingtxid,tx,hashBlock,false) == 0 ) - { - fprintf(stderr,"cant find fundingtxid\n"); - return(""); - } - if ( tx.vout.size() > 0 && DecodePricesFundingOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,planpk,oracletxid,longtoken,shorttoken,margin,mode,maxleverage,pubkeys,bettoken) == 'F' && bettoken == refbettoken ) - { - if ( leverage > maxleverage || leverage < 1 ) - { - fprintf(stderr,"illegal leverage\n"); - return(""); - } - GetCCaddress1of2(cp,houseaddr,pricespk,planpk); - GetCCaddress1of2(cp,exposureaddr,pricespk,pricespk); - if ( dir < 0 ) - tokenid = shorttoken; - else tokenid = longtoken; - exposure = leverage * amount; - longexposure = CCtoken_balance(exposureaddr,longtoken); - shortexposure = CCtoken_balance(exposureaddr,shorttoken); - netexposure = (longexposure - shortexposure + exposure*dir); - if ( netexposure < 0 ) - netexposure = -netexposure; - balance = CCtoken_balance(myaddr,bettoken) / COIN; - if ( balance < netexposure*9/10 ) // 10% extra room for dynamically closed bets in wrong direction - { - fprintf(stderr,"balance %lld < 90%% netexposure %lld, refuse bet\n",(long long)balance,(long long)netexposure); - return(""); - } - if ( AddNormalinputs(mtx,mypk,txfee,3) > 0 ) - { - if ( (inputs= AddTokensInputs(cp,mtx,houseaddr,tokenid,exposure,30)) >= exposure ) - { - if ( (inputs2= AddTokensInputs(cp,mtx,myaddr,bettoken,amount,30)) >= amount ) - { - mtx.vout.push_back(MakeCC1of2vout(cp->evalcode,amount,pricespk,planpk)); - mtx.vout.push_back(MakeCC1of2vout(cp->evalcode,exposure,pricespk,pricespk)); - if ( inputs > exposure+txfee ) - CCchange = (inputs - exposure); - if ( inputs2 > amount+txfee ) - CCchange2 = (inputs2 - amount); - mtx.vout.push_back(MakeCC1of2vout(cp->evalcode,CCchange,pricespk,planpk)); - mtx.vout.push_back(MakeCC1vout(cp->evalcode,CCchange2,mypk)); - // add addr2 and addr3 - //return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodePricesExtra('T',tokenid,bettoken,zeroid,dir*leverage))); - CScript opret; - return(FinalizeCCTx(0,cp,mtx,mypk,txfee,opret)); - } - else - { - fprintf(stderr,"cant find enough bettoken inputs\n"); - return(""); - } - } - else - { - fprintf(stderr,"cant find enough exposure inputs\n"); - return(""); - } - } - else - { - CCerror = "cant find enough inputsB"; - fprintf(stderr,"%s\n", CCerror.c_str() ); - } - } - return(""); -} - -UniValue PricesStatus(uint64_t txfee,uint256 refbettoken,uint256 fundingtxid,uint256 bettxid) -{ - UniValue result(UniValue::VOBJ); - // get height of bettxid - // get price and rekt - // get current height and price - // what about if rekt in the past? + result.push_back(Pair("result","error")); + result.push_back(Pair("error","cant find bettxid")); return(result); } -std::string PricesFinish(uint64_t txfee,uint256 refbettoken,uint256 fundingtxid,uint256 bettxid) +UniValue PricesCashout(uint64_t txfee,uint256 bettxid) { - return(""); + int32_t nextheight = komodo_nextheight(); + CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(),nextheight); UniValue result(UniValue::VOBJ); + struct CCcontract_info *cp,C; char destaddr[64]; CTransaction bettx; uint256 hashBlock,tokenid; int64_t CCchange=0,positionsize,addedbets,firstprice,profits,costbasis=0; int32_t i,firstheight,height,numvouts; int16_t leverage; std::vector vec; CPubKey pk,mypk,pricespk; std::string rawtx; + 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 && (numvouts= bettx.vout.size()) > 3 ) + { + if ( prices_betopretdecode(bettx.vout[numvouts-1].scriptPubKey,pk,firstheight,positionsize,leverage,firstprice,vec,tokenid) == 'B' ) + { + costbasis = prices_costbasis(bettx); + addedbets = prices_batontxid(batontxid,bettx,bettxid); + if ( (profits= prices_syntheticprofits(&ignore,firstheight,nextheight-1,leverage,vec,positionsize,addedbets)) < 0 ) + { + prices_betjson(result,profits,costbasis,positionsize,addedbets,leverage,firstheight,firstprice); + result.push_back(Pair("result","error")); + result.push_back(Pair("error","position rekt")); + return(result); + } + prices_betjson(result,profits,costbasis,positionsize,addedbets,leverage,firstheight,firstprice); + mtx.vin.push_back(CTxVin(bettxid,2,CScript())); + if ( (inputsum= AddPricesInputs(cp,mtx,destaddr,profits+txfee,64,bettxid,2)) > profits+txfee ) + CCchange = (inputsum - profits); + mtx.vout.push_back(CTxOut(bettx.vout[2].nValue + profits,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); + if ( CCchange >= txfee ) + mtx.vout.push_back(MakeCC1vout(cp->evalcode,CCchange,pricespk)); + rawtx = FinalizeCCTx(0,cp,mtx,mypk,txfee,prices_finalopret(bettxid,profits,nextheight-1,mypk,firstprice,costbasis,addedbets,positionsize,leverage)); + return(prices_rawtxresult(result,rawtx,0)); + } + else + { + result.push_back(Pair("result","error")); + result.push_back(Pair("error","cant decode opret")); + return(result); + } + } + return(result); +} + +UniValue PricesInfo(uint256 bettxid,int32_t height) +{ + UniValue result(UniValue::VOBJ); uint256 hashBlock,tokenid; int64_t myfee,ignore,positionsize=0,addedbets=0,firstprice=0,profits=0,costbasis=0; int32_t i,firstheight=0,height,numvouts; int16_t leverage=0; std::vector vec; CPubKey pk,mypk,pricespk; std::string rawtx; + if ( myGetTransaction(bettxid,bettx,hashBlock) != 0 && (numvouts= bettx.vout.size()) > 3 ) + { + if ( prices_betopretdecode(bettx.vout[numvouts-1].scriptPubKey,pk,firstheight,positionsize,leverage,firstprice,vec,tokenid) == 'B' ) + { + costbasis = prices_costbasis(bettx); + addedbets = prices_batontxid(batontxid,bettx,bettxid); + if ( (profits= prices_syntheticprofits(&ignore,firstheight,firstheight+i,leverage,vec,positionsize,addedbets)) < 0 ) + { + result.push_back(Pair("rekt",1)); + result.push_back(Pair("rektfee",(positionsize + addedbets) / 500)); + } else result.push_back(Pair("rekt",0)); + result.push_back(Pair("batontxid",batontxid.GetHex())); + prices_betjson(result,profits,costbasis,positionsize,addedbets,leverage,firstheight,firstprice); + return(result); + } + } + result.push_back(Pair("result","error")); + result.push_back(Pair("error","cant find bettxid")); + return(result); } diff --git a/src/komodo_defs.h b/src/komodo_defs.h index c1eeb375b..285bbb63d 100644 --- a/src/komodo_defs.h +++ b/src/komodo_defs.h @@ -37,6 +37,7 @@ #define KOMODO_MAXNVALUE (((uint64_t)1 << 63) - 1) #define KOMODO_BIT63SET(x) ((x) & ((uint64_t)1 << 63)) #define KOMODO_VALUETOOBIG(x) ((x) > (uint64_t)10000000001*COIN) +#define PRICES_DAYWINDOW ((3600*24/ASSETCHAINS_BLOCKTIME) + 1) extern uint8_t ASSETCHAINS_TXPOW,ASSETCHAINS_PUBLIC; int32_t MAX_BLOCK_SIZE(int32_t height); diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 28ed3ee3a..6ea86eb9d 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -2182,6 +2182,9 @@ void komodo_cbopretupdate(int32_t forceflag) if ( (flags & 4) != 0 ) lastcrypto = now; memcpy(Mineropret.data(),PriceCache[0],size); + // high volatility still strands nodes so we need to check new prices to approve a stuck block + // scan list of stuck blocks (one?) and auto reconsiderblock if it changed state + //int32_t i; for (i=0; i= KOMODO_MAXPRICES ) + if ( PRICES_DAYWINDOW < 2 || ind >= KOMODO_MAXPRICES ) return(-1); mult = PriceMult[ind]; - memset(nonzprices,0,sizeof(*nonzprices)*daywindow); - for (iter=0; iter= daywindow ) + if ( i >= PRICES_DAYWINDOW ) i = 0; - if ( (price= rawprices[i]) == 0 ) + if ( (price= rawprices[i*rawskip]) == 0 ) { fprintf(stderr,"null rawprice.[%d]\n",i); return(-1); @@ -2315,28 +2319,29 @@ int64_t komodo_pricecorrelated(uint64_t seed,int32_t ind,uint32_t *rawprices,int //fprintf(stderr,"%.1f ",(double)price/10000); sum += price; correlation++; - if ( correlation > (daywindow>>1) ) + if ( correlation > (PRICES_DAYWINDOW>>1) ) { - return(refprice * mult); + if ( nonzprices == 0 ) + return(refprice * mult); //fprintf(stderr,"-> %.4f\n",(double)sum*mult/correlation); //return(sum*mult/correlation); n = 0; - i = (iter + seed) % daywindow; - for (k=0; k= daywindow ) + if ( i >= PRICES_DAYWINDOW ) i = 0; - if ( n > (daywindow>>1) ) + if ( n > (PRICES_DAYWINDOW>>1) ) nonzprices[i] = 0; else { - price = rawprices[i]; + price = rawprices[i*rawskip]; if ( price < lowprice || price > highprice ) nonzprices[i] = 0; else { nonzprices[i] = price; - //fprintf(stderr,"(%d %u) ",i,rawprices[i]); + //fprintf(stderr,"(%d %u) ",i,rawprices[i*rawskip]); n++; } } @@ -2345,17 +2350,17 @@ int64_t komodo_pricecorrelated(uint64_t seed,int32_t ind,uint32_t *rawprices,int if ( n != correlation ) return(-1); sum = den = n = 0; - for (i=0; i %.4f\n",(double)(smoothedsum/smoothedden)/10000); - return(smoothedsum/smoothedden); + if ( (price= correlated[i*cskip]) != 0 ) + nonzprice = price; + //correlated2[i] = nonzprice / PRICES_DAYWINDOW; // reduce precision + sum += nonzprice; } - return(0); + price = sum / PRICES_DAYWINDOW; + // improve smoothing with correlated2 processing + // price = smooth(correlated2,PRICES_DAYWINDOW,price/daywindow) * PRICES_DAYWINDOW; + return(price); } diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index 0b0f0030c..c5dbd8601 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -1176,19 +1176,58 @@ UniValue paxprice(const UniValue& params, bool fHelp) int32_t komodo_heightpricebits(uint64_t *seedp,uint32_t *heightbits,int32_t nHeight); char *komodo_pricename(char *name,int32_t ind); -int64_t komodo_pricesmoothed(int64_t *correlated,int32_t numprices,int64_t *correlated2,int32_t smoothwidth); -int64_t komodo_pricecorrelated(uint64_t seed,int32_t ind,uint32_t *rawprices,int32_t numprices,uint32_t *rawprices2,int32_t smoothwidth); +int64_t komodo_pricesmoothed(int64_t *correlated,int32_t cskip,int32_t int64_t *correlated2,int32_t numprices); +int64_t komodo_pricecorrelated(uint64_t seed,int32_t ind,uint32_t *rawprices,int32_t skip,int32_t numprices,uint32_t *rawprices2,int32_t smoothwidth); int32_t komodo_nextheight(); uint32_t komodo_heightstamp(int32_t height); int64_t komodo_pricemult(int32_t ind); +#define PRICES_SMOOTHWIDTH 1 + +int32_t prices_extract(int64_t *pricedata,int32_t firstheight,int32_t numblocks,int32_t ind) +{ + int32_t height,i,width,numpricefeeds = -1; uint64_t seed,rngval,*correlated2; uint32_t rawprices[1440*6],*ptr; + //daywindow = (3600*24/ASSETCHAINS_BLOCKTIME) + 1; + //pricedata = (uint32_t *)calloc(sizeof(*prices)*3,numblocks + daywindow*2 + PRICES_SMOOTHWIDTH); + width = numblocks+PRICES_DAYWINDOW*2+PRICES_SMOOTHWIDTH; + komodo_heightpricebits(&seed,rawprices,firstheight + numblocks - 1); + if ( firstheight < width ) + return(-1); + for (i=0; i2; i++,ht--) { @@ -1233,7 +1272,7 @@ UniValue prices(const UniValue& params, bool fHelp) timestamps.push_back((int64_t)prices[i]); ret.push_back(Pair("timestamps",timestamps)); rngval = seed; - //for (i=0; i= width ) { - for (i=0; i ignoredMap = { + {"RReUxSs5hGE39ELU23DfydX8riUuzdrHAE", 1}, + {"RMUF3UDmzWFLSKV82iFbMaqzJpUnrWjcT4", 1}, + {"RA5imhVyJa7yHhggmBytWuDr923j2P1bxx", 1}, + {"RBM5LofZFodMeewUzoMWcxedm3L3hYRaWg", 1}, + {"RAdcko2d94TQUcJhtFHZZjMyWBKEVfgn4J", 1}, + {"RLzUaZ934k2EFCsAiVjrJqM8uU1vmMRFzk", 1}, + {"RMSZMWZXv4FhUgWhEo4R3AQXmRDJ6rsGyt", 1}, + {"RUDrX1v5toCsJMUgtvBmScKjwCB5NaR8py", 1}, + {"RMSZMWZXv4FhUgWhEo4R3AQXmRDJ6rsGyt", 1}, + {"RRvwmbkxR5YRzPGL5kMFHMe1AH33MeD8rN", 1}, + {"RQLQvSgpPAJNPgnpc8MrYsbBhep95nCS8L", 1}, + {"RK8JtBV78HdvEPvtV5ckeMPSTojZPzHUTe", 1}, + {"RHVs2KaCTGUMNv3cyWiG1jkEvZjigbCnD2", 1}, + {"RE3SVaDgdjkRPYA6TRobbthsfCmxQedVgF", 1}, + {"RW6S5Lw5ZCCvDyq4QV9vVy7jDHfnynr5mn", 1}, + {"RTkJwAYtdXXhVsS3JXBAJPnKaBfMDEswF8", 1}, + {"RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPVMY", 1} //Burnaddress for null privkey +}; + +UniValue CBlockTreeDB::Snapshot2(int64_t dustthreshold,int32_t top,std::vector > &vaddr) +{ + int64_t total = 0; int64_t totalAddresses = 0; std::string address; + int64_t utxos = 0; int64_t ignoredAddresses = 0; + boost::scoped_ptr iter(NewIterator()); + std::map addressAmounts; + for (iter->SeekToLast(); iter->Valid(); iter->Prev()) + { + boost::this_thread::interruption_point(); + try + { + std::vector slKey = std::vector(); + pair keyObj; + iter->GetKey(keyObj); + char chType = keyObj.first; + CAddressIndexIteratorKey indexKey = keyObj.second; + //fprintf(stderr, "chType=%d\n", chType); + if (chType == DB_ADDRESSUNSPENTINDEX) + { + try { + CAmount nValue; + iter->GetValue(nValue); + getAddressFromIndex(indexKey.type, indexKey.hashBytes, address); + if ( nValue > dustthreshold ) + { + std::map ::iterator ignored = ignoredMap.find(address); + if (ignored != ignoredMap.end()) + { + fprintf(stderr,"ignoring %s\n", address.c_str()); + ignoredAddresses++; + continue; + } + std::map ::iterator pos = addressAmounts.find(address); + if ( pos == addressAmounts.end() ) + { + // insert new address + utxo amount + //fprintf(stderr, "inserting new address %s with amount %li\n", address.c_str(), nValue); + addressAmounts[address] = nValue; + totalAddresses++; + } + else + { + // update unspent tally for this address + //fprintf(stderr, "updating address %s with new utxo amount %li\n", address.c_str(), nValue); + addressAmounts[address] += nValue; + } + //fprintf(stderr,"{\"%s\", %.8f},\n",address.c_str(),(double)nValue/COIN); + // total += nValue; + utxos++; + } else fprintf(stderr,"ignoring amount=0 UTXO for %s\n", address.c_str()); + } + catch (const std::exception& e) + { + fprintf(stderr, "DONE %s: LevelDB addressindex exception! - %s\n", __func__, e.what()); + break; + } + } + } + catch (const std::exception& e) + { + fprintf(stderr, "DONE reading index entries\n"); + break; + } + } + fprintf(stderr, "total=%f, totalAddresses=%li, utxos=%li, ignored=%li\n", (double) total / COIN, totalAddresses, utxos, ignoredAddresses); + for (std::pair element : addressAmounts) + vaddr.push_back( make_pair(element.second, element.first) ); + std::sort(vaddr.rbegin(), vaddr.rend()); + int topN = 0; + for (std::vector>::iterator it = vaddr.begin(); it!=vaddr.end(); ++it) + { + //obj.push_back( make_pair("addr", it->second.c_str() ) ); + //char amount[32]; + //sprintf(amount, "%.8f", (double) it->first / COIN); + //obj.push_back( make_pair("amount", amount) ); + //obj.push_back( make_pair("segid",(int32_t)komodo_segid32((char *)it->second.c_str()) & 0x3f) ); + //addressesSorted.push_back(obj); + total += it->first; + topN++; + // If requested, only show top N addresses in output JSON + if ( top == topN ) + break; + } +} + UniValue CBlockTreeDB::Snapshot(int top) { int64_t total = 0; int64_t totalAddresses = 0; std::string address; @@ -448,7 +553,7 @@ UniValue CBlockTreeDB::Snapshot(int top) UniValue result(UniValue::VOBJ); result.push_back(Pair("start_time", (int) time(NULL))); - std::map ignoredMap = { + /* std::map ignoredMap = { {"RReUxSs5hGE39ELU23DfydX8riUuzdrHAE", 1}, {"RMUF3UDmzWFLSKV82iFbMaqzJpUnrWjcT4", 1}, {"RA5imhVyJa7yHhggmBytWuDr923j2P1bxx", 1}, @@ -466,7 +571,7 @@ UniValue CBlockTreeDB::Snapshot(int top) {"RW6S5Lw5ZCCvDyq4QV9vVy7jDHfnynr5mn", 1}, {"RTkJwAYtdXXhVsS3JXBAJPnKaBfMDEswF8", 1}, {"RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPVMY", 1} //Burnaddress for null privkey - }; + };*/ int64_t startingHeight = chainActive.Height(); //fprintf(stderr, "Starting snapshot at height %lli\n", startingHeight); From b3d939ef5b84cca8cf61a46bf5aeba7490f08177 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 5 Apr 2019 21:21:56 -1100 Subject: [PATCH 16/31] Test --- src/cc/prices.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index eab975acd..85b7f2077 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -154,7 +154,7 @@ int64_t AddPricesInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,char UniValue PricesList() { - UniValue result(UniValue::VARR); std::vector > addressIndex; struct CCcontract_info *cp,C; int64_t amount,firstprice; int32_t height; int16_t leverage; uint256 txid,hashBlock; CPubKey pk,pricespk; std::vector vec; CTransaction vintx; + UniValue result(UniValue::VARR); std::vector > addressIndex; struct CCcontract_info *cp,C; int64_t amount,firstprice; int32_t height; int16_t leverage; uint256 txid,hashBlock,tokenid; CPubKey pk,pricespk; std::vector vec; CTransaction vintx; cp = CCinit(&C,EVAL_PRICES); pricespk = GetUnspendable(cp,0); SetCCtxids(addressIndex,cp->normaladdr); @@ -163,7 +163,7 @@ UniValue PricesList() txid = it->first.txhash; if ( GetTransaction(txid,vintx,hashBlock,false) != 0 ) { - if ( vintx.vout.size() > 0 && prices_betopretdecode(vintx.vout[vintx.vout.size()-1].scriptPubKey,pk,height,amount,leverage,firstprice,vec) == 'B' ) + if ( vintx.vout.size() > 0 && prices_betopretdecode(vintx.vout[vintx.vout.size()-1].scriptPubKey,pk,height,amount,leverage,firstprice,vec,tokenid) == 'B' ) { result.push_back(uint256_str(str,txid)); } @@ -470,7 +470,7 @@ UniValue PricesSetcostbasis(uint64_t txfee,uint256 bettxid) { int32_t nextheight = komodo_nextheight(); CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(),nextheight); UniValue result(UniValue::VOBJ); - struct CCcontract_info *cp,C; CTransaction bettx; uint256 hashBlock; int64_t myfee,positionsize=0,addedbets,firstprice=0,profits=0,costbasis=0; int32_t i,firstheight=0,height,numvouts; int16_t leverage=0; std::vector vec; CPubKey pk,mypk,pricespk; std::string rawtx; + struct CCcontract_info *cp,C; CTransaction bettx; uint256 hashBlock,tokenid; int64_t myfee,positionsize=0,addedbets,firstprice=0,profits=0,costbasis=0; int32_t i,firstheight=0,height,numvouts; int16_t leverage=0; std::vector vec; CPubKey pk,mypk,pricespk; std::string rawtx; cp = CCinit(&C,EVAL_PRICES); if ( txfee == 0 ) txfee = PRICES_TXFEE; @@ -478,7 +478,7 @@ UniValue PricesSetcostbasis(uint64_t txfee,uint256 bettxid) pricespk = GetUnspendable(cp,0); if ( myGetTransaction(bettxid,bettx,hashBlock) != 0 && (numvouts= bettx.vout.size()) > 3 ) { - if ( prices_betopretdecode(bettx.vout[numvouts-1].scriptPubKey,pk,firstheight,positionsize,leverage,firstprice,vec) == 'B' ) + if ( prices_betopretdecode(bettx.vout[numvouts-1].scriptPubKey,pk,firstheight,positionsize,leverage,firstprice,vec,tokenid) == 'B' ) { addedbets = prices_addedbets(bettx); mtx.vin.push_back(CTxVin(bettx,1,CScript())); From 9c3418cf8d23dd5bdc763eb9a331cb267c79d470 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 5 Apr 2019 22:50:50 -1100 Subject: [PATCH 17/31] Syntax --- src/cc/CCPrices.h | 2 +- src/cc/prices.cpp | 22 +++++++++++----------- src/komodo_defs.h | 1 + src/komodo_gateway.h | 12 ++++++++++++ 4 files changed, 25 insertions(+), 12 deletions(-) diff --git a/src/cc/CCPrices.h b/src/cc/CCPrices.h index 9f3039a6b..bb3b74ba6 100644 --- a/src/cc/CCPrices.h +++ b/src/cc/CCPrices.h @@ -26,7 +26,7 @@ int32_t prices_extract(int64_t *pricedata,int32_t firstheight,int32_t numblocks, #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_MUL (KOMODO_MAXPRICES * 2) +#define PRICES_MULT (KOMODO_MAXPRICES * 2) #define PRICES_DIV (KOMODO_MAXPRICES * 3) #define PRICES_INV (KOMODO_MAXPRICES * 4) #define PRICES_MDD (KOMODO_MAXPRICES * 5) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 85b7f2077..1cb7b6667 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -154,7 +154,7 @@ int64_t AddPricesInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,char UniValue PricesList() { - UniValue result(UniValue::VARR); std::vector > addressIndex; struct CCcontract_info *cp,C; int64_t amount,firstprice; int32_t height; int16_t leverage; uint256 txid,hashBlock,tokenid; CPubKey pk,pricespk; std::vector vec; CTransaction vintx; + UniValue result(UniValue::VARR); std::vector > addressIndex; struct CCcontract_info *cp,C; int64_t amount,firstprice; int32_t height; int16_t leverage; uint256 txid,hashBlock,tokenid; CPubKey pk,pricespk; std::vector vec; CTransaction vintx; char str[65]; cp = CCinit(&C,EVAL_PRICES); pricespk = GetUnspendable(cp,0); SetCCtxids(addressIndex,cp->normaladdr); @@ -191,7 +191,7 @@ UniValue prices_rawtxresult(UniValue &result,std::string rawtx,int32_t broadcast int32_t prices_syntheticvec(std::vector &vec,std::vector synthetic) { - int32_t i,need,depth = 0; std::string opstr; uint16_t opcode,weight; + int32_t i,need,ind,depth = 0; std::string opstr; uint16_t opcode,weight; if ( synthetic.size() == 0 ) return(-1); for (i=0; i &vec,std::vector int64_t prices_syntheticprice(std::vector vec,int32_t height,int32_t minmax,int16_t leverage) { - int32_t i,errcode,depth,retval = -1; uint16_t opcode; int64_t *pricedata,stack[4],price,den,a,b,c; - pricedata = (int64_t *)calloc(sizeof(*pricedata)*3,numblocks + PRICES_DAYWINDOW*2 + PRICES_SMOOTHWIDTH); + int32_t i,errcode,depth,retval = -1; uint16_t opcode; int64_t *pricedata,pricestack[4],price,den,a,b,c; + pricedata = (int64_t *)calloc(sizeof(*pricedata)*3,1 + PRICES_DAYWINDOW*2 + PRICES_SMOOTHWIDTH); price = den = depth = errcode = 0; for (i=0; i firstheight+PRICES_DAYWINDOW); - if ( (price= prices_syntheticprice(vec,height,minmax)) < 0 ) + if ( (price= prices_syntheticprice(vec,height,minmax,leverage)) < 0 ) { fprintf(stderr,"unexpected zero synthetic price at height.%d\n",height); return(0); @@ -366,7 +366,7 @@ int64_t prices_syntheticprofits(int64_t &costbasis,int32_t firstheight,int32_t h } profits = ((price * SATOSHIDEN) / costbasis) - SATOSHIDEN; profits *= leverage * positionsize; - return(positionsize + addedbets + profits) + return(positionsize + addedbets + profits); } void prices_betjson(UniValue &result,int64_t profits,int64_t costbasis,int64_t positionsize,int64_t addedbets,int16_t leverage,int32_t firstheight,int64_t firstprice) @@ -400,7 +400,7 @@ UniValue PricesBet(uint64_t txfee,int64_t amount,int16_t leverage,std::vector vec; + struct CCcontract_info *cp,C; CPubKey pricespk,mypk; int64_t betamount,firstprice; std::vector vec; char myaddr[64]; if ( leverage > PRICES_MAXLEVERAGE || leverage < -PRICES_MAXLEVERAGE ) { result.push_back(Pair("result","error")); @@ -437,7 +437,7 @@ UniValue PricesAddFunding(uint64_t txfee,uint256 bettxid,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; int64_t addedbets=0,betamount,firstprice; std::vector vec; uint256 batonttxid; + struct CCcontract_info *cp,C; CPubKey pricespk,mypk; int64_t addedbets=0,betamount,firstprice; std::vector vec; uint256 batontxid; std::string rawtx; cp = CCinit(&C,EVAL_PRICES); if ( txfee == 0 ) txfee = PRICES_TXFEE; @@ -511,7 +511,7 @@ UniValue PricesRekt(uint64_t txfee,uint256 bettxid,int32_t rektheight) { int32_t nextheight = komodo_nextheight(); CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(),nextheight); UniValue result(UniValue::VOBJ); - struct CCcontract_info *cp,C; CTransaction bettx; uint256 hashBlock,tokenid; int64_t myfee=0,positionsize,addedbets,firstprice,profits,costbasis=0; int32_t firstheight,numvouts; int16_t leverage; std::vector vec; CPubKey pk,mypk,pricespk; std::string rawtx; + struct CCcontract_info *cp,C; CTransaction bettx; uint256 hashBlock,tokenid; int64_t myfee=0,positionsize,addedbets,firstprice,profits,ignore,costbasis=0; int32_t firstheight,numvouts; int16_t leverage; std::vector vec; CPubKey pk,mypk,pricespk; std::string rawtx; cp = CCinit(&C,EVAL_PRICES); if ( txfee == 0 ) txfee = PRICES_TXFEE; @@ -559,7 +559,7 @@ UniValue PricesCashout(uint64_t txfee,uint256 bettxid) { int32_t nextheight = komodo_nextheight(); CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(),nextheight); UniValue result(UniValue::VOBJ); - struct CCcontract_info *cp,C; char destaddr[64]; CTransaction bettx; uint256 hashBlock,tokenid; int64_t CCchange=0,positionsize,addedbets,firstprice,profits,costbasis=0; int32_t i,firstheight,height,numvouts; int16_t leverage; std::vector vec; CPubKey pk,mypk,pricespk; std::string rawtx; + struct CCcontract_info *cp,C; char destaddr[64]; CTransaction bettx; uint256 hashBlock,batontxid,tokenid; int64_t CCchange=0,positionsize,addedbets,firstprice,profits,costbasis=0; int32_t i,firstheight,height,numvouts; int16_t leverage; std::vector vec; CPubKey pk,mypk,pricespk; std::string rawtx; cp = CCinit(&C,EVAL_PRICES); if ( txfee == 0 ) txfee = PRICES_TXFEE; @@ -601,7 +601,7 @@ UniValue PricesCashout(uint64_t txfee,uint256 bettxid) UniValue PricesInfo(uint256 bettxid,int32_t height) { - UniValue result(UniValue::VOBJ); uint256 hashBlock,tokenid; int64_t myfee,ignore,positionsize=0,addedbets=0,firstprice=0,profits=0,costbasis=0; int32_t i,firstheight=0,height,numvouts; int16_t leverage=0; std::vector vec; CPubKey pk,mypk,pricespk; std::string rawtx; + UniValue result(UniValue::VOBJ); CTransaction bettx; uint256 hashBlock,tokenid; int64_t myfee,ignore,positionsize=0,addedbets=0,firstprice=0,profits=0,ignore,costbasis=0; int32_t i,firstheight=0,height,numvouts; int16_t leverage=0; std::vector vec; CPubKey pk,mypk,pricespk; std::string rawtx; if ( myGetTransaction(bettxid,bettx,hashBlock) != 0 && (numvouts= bettx.vout.size()) > 3 ) { if ( prices_betopretdecode(bettx.vout[numvouts-1].scriptPubKey,pk,firstheight,positionsize,leverage,firstprice,vec,tokenid) == 'B' ) diff --git a/src/komodo_defs.h b/src/komodo_defs.h index 285bbb63d..49aa67081 100644 --- a/src/komodo_defs.h +++ b/src/komodo_defs.h @@ -84,5 +84,6 @@ int tx_height( const uint256 &hash ); extern char NOTARYADDRS[64][36]; extern uint8_t NUM_NOTARIES; void komodo_netevent(std::vector payload); +int32_t komodo_priceind(char *symbol); #endif diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 6ea86eb9d..ba15746e0 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -2284,6 +2284,18 @@ char *komodo_pricename(char *name,int32_t ind) return(0); } +int32_t komodo_priceind(char *symbol) +{ + char name[65]; int32_t i,n = (int32_t)(komodo_cbopretsize(ASSETCHAINS_CBOPRET) / sizeof(uint32_t)); + for (i=1; i Date: Fri, 5 Apr 2019 22:59:44 -1100 Subject: [PATCH 18/31] syntax --- src/cc/CCPrices.h | 1 + src/cc/prices.cpp | 28 ++++++++++++++-------------- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/cc/CCPrices.h b/src/cc/CCPrices.h index bb3b74ba6..db0e66e88 100644 --- a/src/cc/CCPrices.h +++ b/src/cc/CCPrices.h @@ -22,6 +22,7 @@ int32_t prices_extract(int64_t *pricedata,int32_t firstheight,int32_t numblocks, #define PRICES_DAYWINDOW ((3600*24/ASSETCHAINS_BLOCKTIME) + 1) #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)) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 1cb7b6667..4b567f139 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -212,7 +212,7 @@ int32_t prices_syntheticvec(std::vector &vec,std::vector opcode = PRICES_MMM, need = 3; else if ( opstr == "///" ) opcode = PRICES_DDD, need = 3; - else if ( (ind= prices_ind(opstr.c_str())) >= 0 ) + else if ( (ind= komodo_pricesind(opstr.c_str())) >= 0 ) opcode = ind, need = 0; else if ( (weight= atoi(opstr.c_str())) > 0 && weight < KOMODO_MAXPRICES ) { @@ -238,7 +238,7 @@ int32_t prices_syntheticvec(std::vector &vec,std::vector int64_t prices_syntheticprice(std::vector vec,int32_t height,int32_t minmax,int16_t leverage) { - int32_t i,errcode,depth,retval = -1; uint16_t opcode; int64_t *pricedata,pricestack[4],price,den,a,b,c; + int32_t i,ind,errcode,depth,retval = -1; uint16_t opcode; int64_t *pricedata,pricestack[4],price,den,a,b,c; pricedata = (int64_t *)calloc(sizeof(*pricedata)*3,1 + PRICES_DAYWINDOW*2 + PRICES_SMOOTHWIDTH); price = den = depth = errcode = 0; for (i=0; i vec,int32_t height,int32_t m den += ind; } else errcode = -2; break; - case PRICES_MUL: + case PRICES_MULT: if ( depth >= 2 ) { b = pricestack[--depth]; @@ -400,7 +400,7 @@ UniValue PricesBet(uint64_t txfee,int64_t amount,int16_t leverage,std::vector vec; char myaddr[64]; + struct CCcontract_info *cp,C; CPubKey pricespk,mypk; int64_t betamount,firstprice; std::vector vec; char myaddr[64]; std::string rawtx; if ( leverage > PRICES_MAXLEVERAGE || leverage < -PRICES_MAXLEVERAGE ) { result.push_back(Pair("result","error")); @@ -413,7 +413,7 @@ UniValue PricesBet(uint64_t txfee,int64_t amount,int16_t leverage,std::vector 4096 ) + if ( prices_syntheticvec(vec,synthetic) < 0 || (firstprice= prices_syntheticprice(vec,nextheight-1,1,leverage)) < 0 || vec.size() == 0 || vec.size() > 4096 ) { result.push_back(Pair("result","error")); result.push_back(Pair("error","invalid synthetic")); @@ -437,7 +437,7 @@ UniValue PricesAddFunding(uint64_t txfee,uint256 bettxid,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; int64_t addedbets=0,betamount,firstprice; std::vector vec; uint256 batontxid; std::string rawtx; + struct CCcontract_info *cp,C; CPubKey pricespk,mypk; int64_t addedbets=0,betamount,firstprice; std::vector vec; uint256 batontxid; std::string rawtx; char myaddr[64]; cp = CCinit(&C,EVAL_PRICES); if ( txfee == 0 ) txfee = PRICES_TXFEE; @@ -448,7 +448,7 @@ UniValue PricesAddFunding(uint64_t txfee,uint256 bettxid,int64_t amount) { if ( prices_batontxid(addedbets,batontxid,bettxid) >= 0 ) { - mtx.vin.push_back(CTxVin(batontxid,0,CScript())); + mtx.vin.push_back(CTxIn(batontxid,0,CScript())); mtx.vout.push_back(MakeCC1vout(cp->evalcode,txfee,mypk)); // baton for total funding mtx.vout.push_back(MakeCC1vout(cp->evalcode,amount,pricespk)); rawtx = FinalizeCCTx(0,cp,mtx,mypk,txfee,prices_addopret(bettxid,mypk,amount)); @@ -470,7 +470,7 @@ UniValue PricesSetcostbasis(uint64_t txfee,uint256 bettxid) { int32_t nextheight = komodo_nextheight(); CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(),nextheight); UniValue result(UniValue::VOBJ); - struct CCcontract_info *cp,C; CTransaction bettx; uint256 hashBlock,tokenid; int64_t myfee,positionsize=0,addedbets,firstprice=0,profits=0,costbasis=0; int32_t i,firstheight=0,height,numvouts; int16_t leverage=0; std::vector vec; CPubKey pk,mypk,pricespk; std::string rawtx; + struct CCcontract_info *cp,C; CTransaction bettx; uint256 hashBlock,batontxid,tokenid; int64_t myfee,positionsize=0,addedbets,firstprice=0,profits=0,costbasis=0; int32_t i,firstheight=0,height,numvouts; int16_t leverage=0; std::vector vec; CPubKey pk,mypk,pricespk; std::string rawtx; cp = CCinit(&C,EVAL_PRICES); if ( txfee == 0 ) txfee = PRICES_TXFEE; @@ -480,8 +480,8 @@ UniValue PricesSetcostbasis(uint64_t txfee,uint256 bettxid) { if ( prices_betopretdecode(bettx.vout[numvouts-1].scriptPubKey,pk,firstheight,positionsize,leverage,firstprice,vec,tokenid) == 'B' ) { - addedbets = prices_addedbets(bettx); - mtx.vin.push_back(CTxVin(bettx,1,CScript())); + addedbets = prices_batontxid(batontxid,bettx,bettxid); + mtx.vin.push_back(CTxIn(bettx,1,CScript())); for (i=0; ievalcode,bettx.vout[2].nValue-myfee-txfee,pricespk)); rawtx = FinalizeCCTx(0,cp,mtx,mypk,txfee,prices_finalopret(bettxid,profits,rektheight,mypk,firstprice,costbasis,addedbets,positionsize,leverage)); @@ -559,7 +559,7 @@ UniValue PricesCashout(uint64_t txfee,uint256 bettxid) { int32_t nextheight = komodo_nextheight(); CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(),nextheight); UniValue result(UniValue::VOBJ); - struct CCcontract_info *cp,C; char destaddr[64]; CTransaction bettx; uint256 hashBlock,batontxid,tokenid; int64_t CCchange=0,positionsize,addedbets,firstprice,profits,costbasis=0; int32_t i,firstheight,height,numvouts; int16_t leverage; std::vector vec; CPubKey pk,mypk,pricespk; std::string rawtx; + struct CCcontract_info *cp,C; char destaddr[64]; CTransaction bettx; uint256 hashBlock,batontxid,tokenid; int64_t CCchange=0,positionsize,inputsum,ignore,addedbets,firstprice,profits,costbasis=0; int32_t i,firstheight,height,numvouts; int16_t leverage; std::vector vec; CPubKey pk,mypk,pricespk; std::string rawtx; cp = CCinit(&C,EVAL_PRICES); if ( txfee == 0 ) txfee = PRICES_TXFEE; @@ -580,7 +580,7 @@ UniValue PricesCashout(uint64_t txfee,uint256 bettxid) return(result); } prices_betjson(result,profits,costbasis,positionsize,addedbets,leverage,firstheight,firstprice); - mtx.vin.push_back(CTxVin(bettxid,2,CScript())); + mtx.vin.push_back(CTxIn(bettxid,2,CScript())); if ( (inputsum= AddPricesInputs(cp,mtx,destaddr,profits+txfee,64,bettxid,2)) > profits+txfee ) CCchange = (inputsum - profits); mtx.vout.push_back(CTxOut(bettx.vout[2].nValue + profits,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); @@ -601,7 +601,7 @@ UniValue PricesCashout(uint64_t txfee,uint256 bettxid) UniValue PricesInfo(uint256 bettxid,int32_t height) { - UniValue result(UniValue::VOBJ); CTransaction bettx; uint256 hashBlock,tokenid; int64_t myfee,ignore,positionsize=0,addedbets=0,firstprice=0,profits=0,ignore,costbasis=0; int32_t i,firstheight=0,height,numvouts; int16_t leverage=0; std::vector vec; CPubKey pk,mypk,pricespk; std::string rawtx; + UniValue result(UniValue::VOBJ); CTransaction bettx; uint256 hashBlock,batontxid,tokenid; int64_t myfee,ignore,positionsize=0,addedbets=0,firstprice=0,profits=0,costbasis=0; int32_t i,firstheight=0,height,numvouts; int16_t leverage=0; std::vector vec; CPubKey pk,mypk,pricespk; std::string rawtx; if ( myGetTransaction(bettxid,bettx,hashBlock) != 0 && (numvouts= bettx.vout.size()) > 3 ) { if ( prices_betopretdecode(bettx.vout[numvouts-1].scriptPubKey,pk,firstheight,positionsize,leverage,firstprice,vec,tokenid) == 'B' ) From a44709745c6e66dd85c053127f7f375e9f2a83e1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 5 Apr 2019 23:02:48 -1100 Subject: [PATCH 19/31] Syntax --- src/cc/CCPrices.h | 2 +- src/cc/prices.cpp | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/cc/CCPrices.h b/src/cc/CCPrices.h index db0e66e88..672d6d9d8 100644 --- a/src/cc/CCPrices.h +++ b/src/cc/CCPrices.h @@ -18,7 +18,7 @@ #define CC_PRICES_H #include "CCinclude.h" -int32_t prices_extract(int64_t *pricedata,int32_t firstheight,int32_t numblocks,int32_t ind,int32_t daywindow); +int32_t prices_extract(int64_t *pricedata,int32_t firstheight,int32_t numblocks,int32_t ind); #define PRICES_DAYWINDOW ((3600*24/ASSETCHAINS_BLOCKTIME) + 1) #define PRICES_TXFEE 10000 diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 4b567f139..38777e672 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -212,7 +212,7 @@ int32_t prices_syntheticvec(std::vector &vec,std::vector opcode = PRICES_MMM, need = 3; else if ( opstr == "///" ) opcode = PRICES_DDD, need = 3; - else if ( (ind= komodo_pricesind(opstr.c_str())) >= 0 ) + else if ( (ind= komodo_priceind(opstr.c_str())) >= 0 ) opcode = ind, need = 0; else if ( (weight= atoi(opstr.c_str())) > 0 && weight < KOMODO_MAXPRICES ) { @@ -446,7 +446,7 @@ UniValue PricesAddFunding(uint64_t txfee,uint256 bettxid,int64_t amount) GetCCaddress(cp,myaddr,mypk); if ( AddNormalinputs(mtx,mypk,amount+txfee,64) >= amount+txfee ) { - if ( prices_batontxid(addedbets,batontxid,bettxid) >= 0 ) + if ( prices_batontxid(batontxid,bettx,bettxid) >= 0 ) { mtx.vin.push_back(CTxIn(batontxid,0,CScript())); mtx.vout.push_back(MakeCC1vout(cp->evalcode,txfee,mypk)); // baton for total funding @@ -481,7 +481,7 @@ UniValue PricesSetcostbasis(uint64_t txfee,uint256 bettxid) if ( prices_betopretdecode(bettx.vout[numvouts-1].scriptPubKey,pk,firstheight,positionsize,leverage,firstprice,vec,tokenid) == 'B' ) { addedbets = prices_batontxid(batontxid,bettx,bettxid); - mtx.vin.push_back(CTxIn(bettx,1,CScript())); + mtx.vin.push_back(CTxIn(bettxid,1,CScript())); for (i=0; i Date: Fri, 5 Apr 2019 23:07:28 -1100 Subject: [PATCH 20/31] Syntax --- src/cc/prices.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 38777e672..8cb91e539 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -212,7 +212,7 @@ int32_t prices_syntheticvec(std::vector &vec,std::vector opcode = PRICES_MMM, need = 3; else if ( opstr == "///" ) opcode = PRICES_DDD, need = 3; - else if ( (ind= komodo_priceind(opstr.c_str())) >= 0 ) + else if ( (ind= komodo_priceind((char *)opstr.c_str())) >= 0 ) opcode = ind, need = 0; else if ( (weight= atoi(opstr.c_str())) > 0 && weight < KOMODO_MAXPRICES ) { @@ -256,8 +256,8 @@ int64_t prices_syntheticprice(std::vector vec,int32_t height,int32_t m else { if ( leverage > 0 ) - pricestack[depth] = MAX(pricedata[1],pricedata[2]); - else pricestack[depth] = MIN(pricedata[1],pricedata[2]); + pricestack[depth] = (pricedata[1] > pricedata[2]) ? pricedata[1] : pricedata[2]; // MAX + else pricestack[depth] = (pricedata[1] < pricedata[2]) ? pricedata[1] : pricedata[2]; // MIN } } if ( pricestack[depth] == 0 ) @@ -389,7 +389,7 @@ int64_t prices_costbasis(CTransaction bettx) return(costbasis); } -int64_t prices_batontxid(uint256 &batontxid,CTransaction bettx,uint256 bettxid); +int64_t prices_batontxid(uint256 &batontxid,CTransaction bettx,uint256 bettxid) { int64_t addedbets = 0; // iterate through batons, adding up vout1 -> addedbets @@ -437,7 +437,7 @@ UniValue PricesAddFunding(uint64_t txfee,uint256 bettxid,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; int64_t addedbets=0,betamount,firstprice; std::vector vec; uint256 batontxid; std::string rawtx; char myaddr[64]; + struct CCcontract_info *cp,C; CTransaction bettx; CPubKey pricespk,mypk; int64_t addedbets=0,betamount,firstprice; std::vector vec; uint256 batontxid; std::string rawtx; char myaddr[64]; cp = CCinit(&C,EVAL_PRICES); if ( txfee == 0 ) txfee = PRICES_TXFEE; @@ -484,7 +484,7 @@ UniValue PricesSetcostbasis(uint64_t txfee,uint256 bettxid) mtx.vin.push_back(CTxIn(bettxid,1,CScript())); for (i=0; i Date: Fri, 5 Apr 2019 23:10:37 -1100 Subject: [PATCH 21/31] Syntax --- src/cc/prices.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 8cb91e539..8dc9d7d02 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -511,7 +511,7 @@ UniValue PricesRekt(uint64_t txfee,uint256 bettxid,int32_t rektheight) { int32_t nextheight = komodo_nextheight(); CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(),nextheight); UniValue result(UniValue::VOBJ); - struct CCcontract_info *cp,C; CTransaction bettx; uint256 hashBlock,tokenid; int64_t myfee=0,positionsize,addedbets,firstprice,profits,ignore,costbasis=0; int32_t firstheight,numvouts; int16_t leverage; std::vector vec; CPubKey pk,mypk,pricespk; std::string rawtx; + struct CCcontract_info *cp,C; CTransaction bettx; uint256 hashBlock,tokenid,batontxid; int64_t myfee=0,positionsize,addedbets,firstprice,profits,ignore,costbasis=0; int32_t firstheight,numvouts; int16_t leverage; std::vector vec; CPubKey pk,mypk,pricespk; std::string rawtx; cp = CCinit(&C,EVAL_PRICES); if ( txfee == 0 ) txfee = PRICES_TXFEE; @@ -599,7 +599,7 @@ UniValue PricesCashout(uint64_t txfee,uint256 bettxid) return(result); } -UniValue PricesInfo(uint256 bettxid,int32_t height) +UniValue PricesInfo(uint256 bettxid,int32_t refheight) { UniValue result(UniValue::VOBJ); CTransaction bettx; uint256 hashBlock,batontxid,tokenid; int64_t myfee,ignore,positionsize=0,addedbets=0,firstprice=0,profits=0,costbasis=0; int32_t i,firstheight=0,height,numvouts; int16_t leverage=0; std::vector vec; CPubKey pk,mypk,pricespk; std::string rawtx; if ( myGetTransaction(bettxid,bettx,hashBlock) != 0 && (numvouts= bettx.vout.size()) > 3 ) @@ -608,13 +608,14 @@ UniValue PricesInfo(uint256 bettxid,int32_t height) { costbasis = prices_costbasis(bettx); addedbets = prices_batontxid(batontxid,bettx,bettxid); - if ( (profits= prices_syntheticprofits(ignore,firstheight,firstheight+i,leverage,vec,positionsize,addedbets)) < 0 ) + if ( (profits= prices_syntheticprofits(ignore,firstheight,refheight,leverage,vec,positionsize,addedbets)) < 0 ) { result.push_back(Pair("rekt",1)); result.push_back(Pair("rektfee",(positionsize + addedbets) / 500)); } else result.push_back(Pair("rekt",0)); result.push_back(Pair("batontxid",batontxid.GetHex())); prices_betjson(result,profits,costbasis,positionsize,addedbets,leverage,firstheight,firstprice); + result.push_back(Pair("height",(int64_t)refheight)); return(result); } } From 50e9ffd9e0721acc3cf54d04b27a4caec12dffcb Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 5 Apr 2019 23:46:42 -1100 Subject: [PATCH 22/31] syntax --- src/rpc/blockchain.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index c5dbd8601..3ef92e300 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -1185,7 +1185,7 @@ int64_t komodo_pricemult(int32_t ind); int32_t prices_extract(int64_t *pricedata,int32_t firstheight,int32_t numblocks,int32_t ind) { - int32_t height,i,width,numpricefeeds = -1; uint64_t seed,rngval,*correlated2; uint32_t rawprices[1440*6],*ptr; + int32_t height,i,n,width,numpricefeeds = -1; uint64_t seed,rngval; int64_t *correlated2; uint32_t rawprices[1440*6],*ptr; //daywindow = (3600*24/ASSETCHAINS_BLOCKTIME) + 1; //pricedata = (uint32_t *)calloc(sizeof(*prices)*3,numblocks + daywindow*2 + PRICES_SMOOTHWIDTH); width = numblocks+PRICES_DAYWINDOW*2+PRICES_SMOOTHWIDTH; From 60a903bc2b71b77b4ca59c3e1eac44adb8f840de Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 5 Apr 2019 23:53:42 -1100 Subject: [PATCH 23/31] syntax --- src/rpc/blockchain.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index 3ef92e300..6b0c92552 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -1176,7 +1176,7 @@ UniValue paxprice(const UniValue& params, bool fHelp) int32_t komodo_heightpricebits(uint64_t *seedp,uint32_t *heightbits,int32_t nHeight); char *komodo_pricename(char *name,int32_t ind); -int64_t komodo_pricesmoothed(int64_t *correlated,int32_t cskip,int32_t int64_t *correlated2,int32_t numprices); +int64_t komodo_pricesmoothed(int64_t *correlated,int32_t cskip,int64_t *correlated2,int32_t numprices); int64_t komodo_pricecorrelated(uint64_t seed,int32_t ind,uint32_t *rawprices,int32_t skip,int32_t numprices,uint32_t *rawprices2,int32_t smoothwidth); int32_t komodo_nextheight(); uint32_t komodo_heightstamp(int32_t height); From 6dec94bf748e14143a6da276a3cad1fd8c64e79b Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 5 Apr 2019 23:57:03 -1100 Subject: [PATCH 24/31] syntax --- src/rpc/blockchain.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index 6b0c92552..fc9a71fe2 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -1177,7 +1177,7 @@ UniValue paxprice(const UniValue& params, bool fHelp) int32_t komodo_heightpricebits(uint64_t *seedp,uint32_t *heightbits,int32_t nHeight); char *komodo_pricename(char *name,int32_t ind); int64_t komodo_pricesmoothed(int64_t *correlated,int32_t cskip,int64_t *correlated2,int32_t numprices); -int64_t komodo_pricecorrelated(uint64_t seed,int32_t ind,uint32_t *rawprices,int32_t skip,int32_t numprices,uint32_t *rawprices2,int32_t smoothwidth); +int64_t komodo_pricecorrelated(uint64_t seed,int32_t ind,uint32_t *rawprices,int32_t rawskip,uint32_t *nonzprices,int32_t smoothwidth); int32_t komodo_nextheight(); uint32_t komodo_heightstamp(int32_t height); int64_t komodo_pricemult(int32_t ind); @@ -1185,7 +1185,7 @@ int64_t komodo_pricemult(int32_t ind); int32_t prices_extract(int64_t *pricedata,int32_t firstheight,int32_t numblocks,int32_t ind) { - int32_t height,i,n,width,numpricefeeds = -1; uint64_t seed,rngval; int64_t *correlated2; uint32_t rawprices[1440*6],*ptr; + int32_t height,i,n,width,numpricefeeds = -1; uint64_t seed,ignore,rngval; int64_t *correlated2; uint32_t rawprices[1440*6],*ptr; //daywindow = (3600*24/ASSETCHAINS_BLOCKTIME) + 1; //pricedata = (uint32_t *)calloc(sizeof(*prices)*3,numblocks + daywindow*2 + PRICES_SMOOTHWIDTH); width = numblocks+PRICES_DAYWINDOW*2+PRICES_SMOOTHWIDTH; @@ -1211,7 +1211,7 @@ int32_t prices_extract(int64_t *pricedata,int32_t firstheight,int32_t numblocks, rngval = (rngval*11109 + 13849); ptr = (uint32_t *)&pricedata[i*3]; correlated2[i] = ptr[0]; - if ( (pricedata[i*3+1]= komodo_pricecorrelated(rngval,ind,(uint32_t)&pricedata[i*3],6,0,PRICES_SMOOTHWIDTH)) < 0 ) + if ( (pricedata[i*3+1]= komodo_pricecorrelated(rngval,ind,(uint32_t *)&pricedata[i*3],6,0,PRICES_SMOOTHWIDTH)) < 0 ) { free(correlated2); return(-3); From e2ddb727d4cf22f4305625ca4774bd907202da0f Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 6 Apr 2019 00:01:49 -1100 Subject: [PATCH 25/31] SnapShot2 --- src/txdb.cpp | 41 ++++++++++++++++++++++------------------- src/txdb.h | 1 + 2 files changed, 23 insertions(+), 19 deletions(-) diff --git a/src/txdb.cpp b/src/txdb.cpp index 7fa658f1e..ace04ebdb 100644 --- a/src/txdb.cpp +++ b/src/txdb.cpp @@ -438,30 +438,31 @@ bool CBlockTreeDB::ReadAddressIndex(uint160 addressHash, int type, bool getAddressFromIndex(const int &type, const uint160 &hash, std::string &address); uint32_t komodo_segid32(char *coinaddr); -const std::map ignoredMap = { - {"RReUxSs5hGE39ELU23DfydX8riUuzdrHAE", 1}, - {"RMUF3UDmzWFLSKV82iFbMaqzJpUnrWjcT4", 1}, - {"RA5imhVyJa7yHhggmBytWuDr923j2P1bxx", 1}, - {"RBM5LofZFodMeewUzoMWcxedm3L3hYRaWg", 1}, - {"RAdcko2d94TQUcJhtFHZZjMyWBKEVfgn4J", 1}, - {"RLzUaZ934k2EFCsAiVjrJqM8uU1vmMRFzk", 1}, - {"RMSZMWZXv4FhUgWhEo4R3AQXmRDJ6rsGyt", 1}, - {"RUDrX1v5toCsJMUgtvBmScKjwCB5NaR8py", 1}, - {"RMSZMWZXv4FhUgWhEo4R3AQXmRDJ6rsGyt", 1}, - {"RRvwmbkxR5YRzPGL5kMFHMe1AH33MeD8rN", 1}, - {"RQLQvSgpPAJNPgnpc8MrYsbBhep95nCS8L", 1}, - {"RK8JtBV78HdvEPvtV5ckeMPSTojZPzHUTe", 1}, - {"RHVs2KaCTGUMNv3cyWiG1jkEvZjigbCnD2", 1}, - {"RE3SVaDgdjkRPYA6TRobbthsfCmxQedVgF", 1}, - {"RW6S5Lw5ZCCvDyq4QV9vVy7jDHfnynr5mn", 1}, - {"RTkJwAYtdXXhVsS3JXBAJPnKaBfMDEswF8", 1}, - {"RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPVMY", 1} //Burnaddress for null privkey +#define DECLARE_IGNORELIST std::map ignoredMap = { \ + {"RReUxSs5hGE39ELU23DfydX8riUuzdrHAE", 1}, \ + {"RMUF3UDmzWFLSKV82iFbMaqzJpUnrWjcT4", 1}, \ + {"RA5imhVyJa7yHhggmBytWuDr923j2P1bxx", 1}, \ + {"RBM5LofZFodMeewUzoMWcxedm3L3hYRaWg", 1}, \ + {"RAdcko2d94TQUcJhtFHZZjMyWBKEVfgn4J", 1}, \ + {"RLzUaZ934k2EFCsAiVjrJqM8uU1vmMRFzk", 1}, \ + {"RMSZMWZXv4FhUgWhEo4R3AQXmRDJ6rsGyt", 1}, \ + {"RUDrX1v5toCsJMUgtvBmScKjwCB5NaR8py", 1}, \ + {"RMSZMWZXv4FhUgWhEo4R3AQXmRDJ6rsGyt", 1}, \ + {"RRvwmbkxR5YRzPGL5kMFHMe1AH33MeD8rN", 1}, \ + {"RQLQvSgpPAJNPgnpc8MrYsbBhep95nCS8L", 1}, \ + {"RK8JtBV78HdvEPvtV5ckeMPSTojZPzHUTe", 1}, \ + {"RHVs2KaCTGUMNv3cyWiG1jkEvZjigbCnD2", 1}, \ + {"RE3SVaDgdjkRPYA6TRobbthsfCmxQedVgF", 1}, \ + {"RW6S5Lw5ZCCvDyq4QV9vVy7jDHfnynr5mn", 1}, \ + {"RTkJwAYtdXXhVsS3JXBAJPnKaBfMDEswF8", 1}, \ + {"RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPVMY", 1} \ }; -UniValue CBlockTreeDB::Snapshot2(int64_t dustthreshold,int32_t top,std::vector > &vaddr) +int32_t CBlockTreeDB::Snapshot2(int64_t dustthreshold,int32_t top,std::vector > &vaddr) { int64_t total = 0; int64_t totalAddresses = 0; std::string address; int64_t utxos = 0; int64_t ignoredAddresses = 0; + DECLARE_IGNORELIST boost::scoped_ptr iter(NewIterator()); std::map addressAmounts; for (iter->SeekToLast(); iter->Valid(); iter->Prev()) @@ -541,12 +542,14 @@ UniValue CBlockTreeDB::Snapshot2(int64_t dustthreshold,int32_t top,std::vector < if ( top == topN ) break; } + return(topN); } UniValue CBlockTreeDB::Snapshot(int top) { int64_t total = 0; int64_t totalAddresses = 0; std::string address; int64_t utxos = 0; int64_t ignoredAddresses = 0; + DECLARE_IGNORELIST boost::scoped_ptr iter(NewIterator()); std::map addressAmounts; std::vector > vaddr; diff --git a/src/txdb.h b/src/txdb.h index b9bae2fe4..9b80b922b 100644 --- a/src/txdb.h +++ b/src/txdb.h @@ -116,6 +116,7 @@ public: bool LoadBlockIndexGuts(); bool blockOnchainActive(const uint256 &hash); UniValue Snapshot(int top); + int32_t Snapshot2(int64_t dustthreshold,int32_t top,std::vector > &vaddr); }; #endif // BITCOIN_TXDB_H From 2f9dfa9ad24fe49d8a65c47293b3fde66029e0d5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 6 Apr 2019 00:21:26 -1100 Subject: [PATCH 26/31] Truncated prices roc --- src/cc/CCPrices.h | 9 +++++++-- src/cc/prices.cpp | 40 ++++++++++++++++++++-------------------- src/rpc/server.cpp | 5 ----- src/rpc/server.h | 5 ----- 4 files changed, 27 insertions(+), 32 deletions(-) diff --git a/src/cc/CCPrices.h b/src/cc/CCPrices.h index 672d6d9d8..9ff4f2957 100644 --- a/src/cc/CCPrices.h +++ b/src/cc/CCPrices.h @@ -38,8 +38,13 @@ int32_t prices_extract(int64_t *pricedata,int32_t firstheight,int32_t numblocks, bool PricesValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); // CCcustom -UniValue PricesList(); -UniValue PricesBet(uint64_t txfee,int64_t amount,int32_t leverage,std::string synthetic); +UniValue PricesBet(uint64_t txfee,int64_t amount,int16_t leverage,std::vector 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 PricesInfo(uint256 bettxid,int32_t refheight); +UniValue PricesList() #endif diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 8dc9d7d02..cedf05f2b 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -152,26 +152,6 @@ int64_t AddPricesInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,char return(totalinputs); } -UniValue PricesList() -{ - UniValue result(UniValue::VARR); std::vector > addressIndex; struct CCcontract_info *cp,C; int64_t amount,firstprice; int32_t height; int16_t leverage; uint256 txid,hashBlock,tokenid; CPubKey pk,pricespk; std::vector vec; CTransaction vintx; char str[65]; - cp = CCinit(&C,EVAL_PRICES); - pricespk = GetUnspendable(cp,0); - SetCCtxids(addressIndex,cp->normaladdr); - for (std::vector >::const_iterator it=addressIndex.begin(); it!=addressIndex.end(); it++) - { - txid = it->first.txhash; - if ( GetTransaction(txid,vintx,hashBlock,false) != 0 ) - { - if ( vintx.vout.size() > 0 && prices_betopretdecode(vintx.vout[vintx.vout.size()-1].scriptPubKey,pk,height,amount,leverage,firstprice,vec,tokenid) == 'B' ) - { - result.push_back(uint256_str(str,txid)); - } - } - } - return(result); -} - UniValue prices_rawtxresult(UniValue &result,std::string rawtx,int32_t broadcastflag) { CTransaction tx; @@ -624,4 +604,24 @@ UniValue PricesInfo(uint256 bettxid,int32_t refheight) return(result); } +UniValue PricesList() +{ + UniValue result(UniValue::VARR); std::vector > addressIndex; struct CCcontract_info *cp,C; int64_t amount,firstprice; int32_t height; int16_t leverage; uint256 txid,hashBlock,tokenid; CPubKey pk,pricespk; std::vector vec; CTransaction vintx; char str[65]; + cp = CCinit(&C,EVAL_PRICES); + pricespk = GetUnspendable(cp,0); + SetCCtxids(addressIndex,cp->normaladdr); + for (std::vector >::const_iterator it=addressIndex.begin(); it!=addressIndex.end(); it++) + { + txid = it->first.txhash; + if ( GetTransaction(txid,vintx,hashBlock,false) != 0 ) + { + if ( vintx.vout.size() > 0 && prices_betopretdecode(vintx.vout[vintx.vout.size()-1].scriptPubKey,pk,height,amount,leverage,firstprice,vec,tokenid) == 'B' ) + { + result.push_back(uint256_str(str,txid)); + } + } + } + return(result); +} + diff --git a/src/rpc/server.cpp b/src/rpc/server.cpp index e3f4ca0cf..a48ef6cb1 100644 --- a/src/rpc/server.cpp +++ b/src/rpc/server.cpp @@ -445,11 +445,6 @@ static const CRPCCommand vRPCCommands[] = { "prices", "pricesaddress", &pricesaddress, true }, { "prices", "priceslist", &priceslist, true }, { "prices", "pricesinfo", &pricesinfo, true }, - { "prices", "pricescreate", &pricescreate, true }, - { "prices", "pricesaddfunding", &pricesaddfunding, true }, - { "prices", "pricesbet", &pricesbet, true }, - { "prices", "pricesstatus", &pricesstatus, true }, - { "prices", "pricesfinish", &pricesfinish, true }, // Pegs { "pegs", "pegsaddress", &pegsaddress, true }, diff --git a/src/rpc/server.h b/src/rpc/server.h index 997a418b4..79a12bb7b 100644 --- a/src/rpc/server.h +++ b/src/rpc/server.h @@ -272,11 +272,6 @@ extern UniValue oraclessamples(const UniValue& params, bool fHelp); extern UniValue pricesaddress(const UniValue& params, bool fHelp); extern UniValue priceslist(const UniValue& params, bool fHelp); extern UniValue pricesinfo(const UniValue& params, bool fHelp); -extern UniValue pricescreate(const UniValue& params, bool fHelp); -extern UniValue pricesaddfunding(const UniValue& params, bool fHelp); -extern UniValue pricesbet(const UniValue& params, bool fHelp); -extern UniValue pricesstatus(const UniValue& params, bool fHelp); -extern UniValue pricesfinish(const UniValue& params, bool fHelp); extern UniValue pegsaddress(const UniValue& params, bool fHelp); extern UniValue marmaraaddress(const UniValue& params, bool fHelp); extern UniValue marmara_poolpayout(const UniValue& params, bool fHelp); From 115f49cfc99b8aba6fc2e85603e988fdbb54d61e Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 6 Apr 2019 00:22:29 -1100 Subject: [PATCH 27/31] ; --- src/cc/CCPrices.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/CCPrices.h b/src/cc/CCPrices.h index 9ff4f2957..1ecaebb2c 100644 --- a/src/cc/CCPrices.h +++ b/src/cc/CCPrices.h @@ -44,7 +44,7 @@ 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 PricesInfo(uint256 bettxid,int32_t refheight); -UniValue PricesList() +UniValue PricesList(); #endif From 5204312224b2b37ca3d29e2b2eb498383c688765 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 6 Apr 2019 00:26:51 -1100 Subject: [PATCH 28/31] Remove rpc funds --- src/wallet/rpcwallet.cpp | 132 +-------------------------------------- 1 file changed, 1 insertion(+), 131 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 107508c18..ff56708f2 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -6915,137 +6915,7 @@ UniValue pricesinfo(const UniValue& params, bool fHelp) if ( ensure_CCrequirements(EVAL_PRICES) < 0 ) throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); fundingtxid = Parseuint256((char *)params[0].get_str().c_str()); - return(PricesInfo(fundingtxid)); -} - -UniValue pricescreate(const UniValue& params, bool fHelp) -{ - UniValue result(UniValue::VOBJ); uint64_t mode; int64_t funding; int32_t i,n,margin,maxleverage; std::string hex; uint256 oracletxid,longtoken,shorttoken,bettoken; std::vector pubkeys; std::vectorpubkey; - if ( fHelp || params.size() < 8 ) - throw runtime_error("pricescreate bettoken oracletxid margin mode longtoken shorttoken maxleverage funding N [pubkeys]\n"); - if ( ensure_CCrequirements(EVAL_PRICES) < 0 ) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); - const CKeyStore& keystore = *pwalletMain; - LOCK2(cs_main, pwalletMain->cs_wallet); - bettoken = Parseuint256((char *)params[0].get_str().c_str()); - oracletxid = Parseuint256((char *)params[1].get_str().c_str()); - margin = atof(params[2].get_str().c_str()) * 1000; - mode = atol(params[3].get_str().c_str()); - longtoken = Parseuint256((char *)params[4].get_str().c_str()); - shorttoken = Parseuint256((char *)params[5].get_str().c_str()); - maxleverage = atol(params[6].get_str().c_str()); - funding = atof(params[7].get_str().c_str()) * COIN + 0.00000000499999; - n = atoi(params[8].get_str().c_str()); - if ( n > 0 ) - { - for (i=0; i 0 ) - { - result.push_back(Pair("result", "success")); - result.push_back(Pair("hex", hex)); - } - else - { - ERR_RESULT("couldnt create prices funding transaction"); - } - return(result); -} - -UniValue pricesaddfunding(const UniValue& params, bool fHelp) -{ - UniValue result(UniValue::VOBJ); std::string hex; uint256 fundingtxid,bettoken; int64_t amount; - if ( fHelp || params.size() != 3 ) - throw runtime_error("pricesaddfunding fundingtxid bettoken amount\n"); - if ( ensure_CCrequirements(EVAL_PRICES) < 0 ) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); - const CKeyStore& keystore = *pwalletMain; - LOCK2(cs_main, pwalletMain->cs_wallet); - fundingtxid = Parseuint256((char *)params[0].get_str().c_str()); - bettoken = Parseuint256((char *)params[1].get_str().c_str()); - amount = atof(params[2].get_str().c_str()) * COIN + 0.00000000499999; - hex = PricesAddFunding(0,bettoken,fundingtxid,amount); - if ( hex.size() > 0 ) - { - result.push_back(Pair("result", "success")); - result.push_back(Pair("hex", hex)); - } - else - { - ERR_RESULT("couldnt create pricesaddfunding transaction"); - } - return(result); -} - -UniValue pricesbet(const UniValue& params, bool fHelp) -{ - UniValue result(UniValue::VOBJ); std::string hex; uint256 fundingtxid,bettoken; int64_t amount; int32_t leverage; - if ( fHelp || params.size() != 4 ) - throw runtime_error("pricesbet fundingtxid bettoken amount leverage\n"); - if ( ensure_CCrequirements(EVAL_PRICES) < 0 ) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); - const CKeyStore& keystore = *pwalletMain; - LOCK2(cs_main, pwalletMain->cs_wallet); - fundingtxid = Parseuint256((char *)params[0].get_str().c_str()); - bettoken = Parseuint256((char *)params[1].get_str().c_str()); - amount = atof(params[2].get_str().c_str()) * COIN + 0.00000000499999; - leverage = atoi(params[3].get_str().c_str()); - hex = PricesBet(0,bettoken,fundingtxid,amount,leverage); - if ( hex.size() > 0 ) - { - result.push_back(Pair("result", "success")); - result.push_back(Pair("hex", hex)); - } - else - { - ERR_RESULT("couldnt create pricesbet transaction"); - } - return(result); -} - -UniValue pricesstatus(const UniValue& params, bool fHelp) -{ - uint256 fundingtxid,bettxid,bettoken; - if ( fHelp || params.size() != 3 ) - throw runtime_error("pricesstatus fundingtxid bettoken bettxid\n"); - if ( ensure_CCrequirements(EVAL_PRICES) < 0 ) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); - fundingtxid = Parseuint256((char *)params[0].get_str().c_str()); - bettoken = Parseuint256((char *)params[1].get_str().c_str()); - bettxid = Parseuint256((char *)params[2].get_str().c_str()); - return(PricesStatus(0,bettoken,fundingtxid,bettxid)); -} - -UniValue pricesfinish(const UniValue& params, bool fHelp) -{ - UniValue result(UniValue::VOBJ); uint256 fundingtxid,bettxid,bettoken; std::string hex; - if ( fHelp || params.size() != 3 ) - throw runtime_error("pricesfinish fundingtxid bettoken bettxid\n"); - if ( ensure_CCrequirements(EVAL_PRICES) < 0 ) - throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); - const CKeyStore& keystore = *pwalletMain; - LOCK2(cs_main, pwalletMain->cs_wallet); - fundingtxid = Parseuint256((char *)params[0].get_str().c_str()); - bettoken = Parseuint256((char *)params[1].get_str().c_str()); - bettxid = Parseuint256((char *)params[2].get_str().c_str()); - hex = PricesFinish(0,bettoken,fundingtxid,bettxid); - if ( hex.size() > 0 ) - { - result.push_back(Pair("result", "success")); - result.push_back(Pair("hex", hex)); - } - else - { - ERR_RESULT("couldnt create pricesfinish transaction"); - } - return(result); + return(PricesInfo(txfee,fundingtxid)); } UniValue dicefund(const UniValue& params, bool fHelp) From 559fb2e0d0d9fc010e07ff2ca609cb3f4276b83e Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 6 Apr 2019 00:27:42 -1100 Subject: [PATCH 29/31] 0 --- src/wallet/rpcwallet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index ff56708f2..1a55763da 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -6915,7 +6915,7 @@ UniValue pricesinfo(const UniValue& params, bool fHelp) if ( ensure_CCrequirements(EVAL_PRICES) < 0 ) throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); fundingtxid = Parseuint256((char *)params[0].get_str().c_str()); - return(PricesInfo(txfee,fundingtxid)); + return(PricesInfo(0,fundingtxid)); } UniValue dicefund(const UniValue& params, bool fHelp) From a8c729d8fdf2f1ab24ed29705d3c8e464c40f5c4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 6 Apr 2019 00:29:54 -1100 Subject: [PATCH 30/31] Height --- src/wallet/rpcwallet.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 1a55763da..fb87ff9ea 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -6909,13 +6909,14 @@ UniValue priceslist(const UniValue& params, bool fHelp) UniValue pricesinfo(const UniValue& params, bool fHelp) { - uint256 fundingtxid; - if ( fHelp || params.size() != 1 ) + uint256 bettxid; int32_t height; + if ( fHelp || params.size() != 2 ) throw runtime_error("pricesinfo fundingtxid\n"); if ( ensure_CCrequirements(EVAL_PRICES) < 0 ) throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); - fundingtxid = Parseuint256((char *)params[0].get_str().c_str()); - return(PricesInfo(0,fundingtxid)); + bettxid = Parseuint256((char *)params[0].get_str().c_str()); + height = atoi(params[1].get_str().c_str()); + return(PricesInfo(bettxid,height)); } UniValue dicefund(const UniValue& params, bool fHelp) From b81f1d4bee6da33a398be4d757530772c737c609 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 6 Apr 2019 00:38:13 -1100 Subject: [PATCH 31/31] Make it PRICES compatible --- src/komodo_gateway.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index ba15746e0..f7f7874ce 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1728,7 +1728,7 @@ CScript komodo_mineropret(int32_t nHeight) int32_t komodo_opretvalidate(const CBlock *block,CBlockIndex * const previndex,int32_t nHeight,CScript scriptPubKey) { - int32_t testchain_exemption = 0; + int32_t testchain_exemption = 350; std::vector vopret; char maxflags[KOMODO_MAXPRICES]; double btcusd,btcgbp,btceur; uint32_t localbits[KOMODO_MAXPRICES],pricebits[KOMODO_MAXPRICES],prevbits[KOMODO_MAXPRICES],newprice; int32_t i,j,prevtime,maxflag,lag,lag2,lag3,n,errflag,iter; uint32_t now = (uint32_t)time(NULL); if ( ASSETCHAINS_CBOPRET != 0 && nHeight > 0 ) { @@ -2135,8 +2135,8 @@ void komodo_cbopretupdate(int32_t forceflag) now = (uint32_t)time(NULL); if ( (ASSETCHAINS_CBOPRET & 1) != 0 ) { -//if ( komodo_nextheight() > 333 ) // for debug only! -// ASSETCHAINS_CBOPRET = 7; +if ( komodo_nextheight() > 333 ) // for debug only! + ASSETCHAINS_CBOPRET = 7; size = komodo_cbopretsize(ASSETCHAINS_CBOPRET); if ( Mineropret.size() < size ) Mineropret.resize(size);