From a3bbaaef9b57a74e42500e275e016bdabfd220e4 Mon Sep 17 00:00:00 2001 From: Anton Lysakov Date: Fri, 29 Mar 2019 07:44:41 +0700 Subject: [PATCH 01/86] tetris tweaks --- src/tui/lib/tuilib.py | 79 ++++++++++++++++++++++++------------------- 1 file changed, 44 insertions(+), 35 deletions(-) diff --git a/src/tui/lib/tuilib.py b/src/tui/lib/tuilib.py index da1d7658a..9a2fed639 100755 --- a/src/tui/lib/tuilib.py +++ b/src/tui/lib/tuilib.py @@ -7,6 +7,7 @@ import pickle import platform import os import subprocess +import random import signal from slickrpc import Proxy from binascii import hexlify @@ -1044,34 +1045,41 @@ def print_multiplayer_games_list(rpc_connection): def rogue_newgame_singleplayer(rpc_connection, is_game_a_rogue=True): try: - new_game_txid = rpc_connection.cclib("newgame", "17", "[1]")["txid"] - print("New singleplayer training game succesfully created. txid: " + new_game_txid) - while True: - mempool = rpc_connection.getrawmempool() - if new_game_txid in mempool: - print(colorize("Waiting for game transaction to be mined", "blue")) - time.sleep(5) - else: - print(colorize("Game transaction is mined", "green")) - break - players_list = rogue_players_list(rpc_connection) - if len(players_list["playerdata"]) > 0: - print_players_list(rpc_connection) + if is_game_a_rogue: + new_game_txid = rpc_connection.cclib("newgame", "17", "[1]")["txid"] + print("New singleplayer training game succesfully created. txid: " + new_game_txid) while True: - is_choice_needed = input("Do you want to choose a player for this game? [y/n] ") - if is_choice_needed == "y": - player_txid = input("Please input player txid: ") - newgame_regisration_txid = rogue_game_register(rpc_connection, new_game_txid, player_txid)["txid"] - break - elif is_choice_needed == "n": - set_warriors_name(rpc_connection) - newgame_regisration_txid = rogue_game_register(rpc_connection, new_game_txid)["txid"] - break + mempool = rpc_connection.getrawmempool() + if new_game_txid in mempool: + print(colorize("Waiting for game transaction to be mined", "blue")) + time.sleep(5) else: - print("Please choose y or n !") + print(colorize("Game transaction is mined", "green")) + break + else: + pending_games = rpc_connection.cclib("pending", "17")["pending"] + new_game_txid = random.choice(pending_games) + if is_game_a_rogue: + players_list = rogue_players_list(rpc_connection) + if len(players_list["playerdata"]) > 0: + print_players_list(rpc_connection) + while True: + is_choice_needed = input("Do you want to choose a player for this game? [y/n] ") + if is_choice_needed == "y": + player_txid = input("Please input player txid: ") + newgame_regisration_txid = rogue_game_register(rpc_connection, new_game_txid, player_txid)["txid"] + break + elif is_choice_needed == "n": + set_warriors_name(rpc_connection) + newgame_regisration_txid = rogue_game_register(rpc_connection, new_game_txid)["txid"] + break + else: + print("Please choose y or n !") + else: + print("No players available to select") + input("Press [Enter] to continue...") + newgame_regisration_txid = rogue_game_register(rpc_connection, new_game_txid)["txid"] else: - print("No players available to select") - input("Press [Enter] to continue...") newgame_regisration_txid = rogue_game_register(rpc_connection, new_game_txid)["txid"] while True: mempool = rpc_connection.getrawmempool() @@ -1143,7 +1151,7 @@ def rogue_newgame_singleplayer(rpc_connection, is_game_a_rogue=True): print("Let's wait a little bit more") time.sleep(5) pass - if confirmations_amount < 2: + if confirmations_amount < 1: print("Last keystroke not confirmed yet! Let's wait a little") time.sleep(10) else: @@ -1163,15 +1171,16 @@ def rogue_newgame_singleplayer(rpc_connection, is_game_a_rogue=True): is_bailout_needed = input("Do you want to make bailout now [y] or wait for one more block [n]? [y/n]: ") if is_bailout_needed == "y": bailout_info = rogue_bailout(rpc_connection, new_game_txid) - while True: - try: - confirmations_amount = rpc_connection.getrawtransaction(bailout_info["txid"], 1)["confirmations"] - break - except Exception as e: - print(e) - print("Bailout not on blockchain yet. Let's wait a little bit more") - time.sleep(20) - pass + if is_game_a_rogue: + while True: + try: + confirmations_amount = rpc_connection.getrawtransaction(bailout_info["txid"], 1)["confirmations"] + break + except Exception as e: + print(e) + print("Bailout not on blockchain yet. Let's wait a little bit more") + time.sleep(20) + pass break elif is_bailout_needed == "n": game_end_height = int(rpc_connection.getinfo()["blocks"]) From aee4b6ec2b7dafc2a44de1fd31ae852d9e3c1130 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 29 Mar 2019 01:25:55 -1100 Subject: [PATCH 02/86] alphadvantage api --- src/komodo_gateway.h | 101 +++++++++++++++++++++++++++++++++++++++++-- src/komodo_utils.h | 2 +- 2 files changed, 98 insertions(+), 5 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 6a9afd473..5f235ee63 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1631,13 +1631,13 @@ CScript komodo_mineropret(int32_t nHeight) { if ( komodo_heightpricebits(prevbits,nHeight-1) == 0 ) { - memcpy(pricebits,&Mineropret[0],PRICES_SIZEBIT0); + memcpy(pricebits,Mineropret.data(),PRICES_SIZEBIT0); if ( komodo_pricecmp(&maxflag,pricebits,prevbits,PRICES_MAXCHANGE) < 0 ) { // if the new prices are not within tolerance, update Mineropret with clipped prices komodo_priceclamp(pricebits,prevbits,PRICES_MAXCHANGE); fprintf(stderr,"update Mineropret to clamped prices\n"); - memcpy(&Mineropret[0],pricebits,PRICES_SIZEBIT0); + memcpy(Mineropret.data(),pricebits,PRICES_SIZEBIT0); } } return(opret << OP_RETURN << Mineropret); @@ -1677,7 +1677,7 @@ int32_t komodo_opretvalidate(int32_t nHeight,CScript scriptPubKey) } if ( lag < ASSETCHAINS_BLOCKTIME && Mineropret.size() >= PRICES_SIZEBIT0 ) { - memcpy(localbits,&Mineropret[0],PRICES_SIZEBIT0); + memcpy(localbits,Mineropret.data(),PRICES_SIZEBIT0); if ( maxflag == 0 ) { if ( komodo_pricecmp(&maxflag,localbits,prevbits,PRICES_MAXCHANGE) < 0 ) @@ -1709,6 +1709,19 @@ int32_t komodo_opretvalidate(int32_t nHeight,CScript scriptPubKey) // get_urljson just returns the JSON returned by the URL using issue_curl #define issue_curl(cmdstr) bitcoind_RPC(0,(char *)"CBCOINBASE",cmdstr,0,0,0) +char *Cryptos[] = { "KMD", "BTC", "ETH", "LTC", "BCH", "XMR", "IOTA", "DASH", "XTZ", "XEM", "ZEC", "WAVES", "DOGE", "RVN", "LSK", "DCR", "BTS", "ICX", "HOT", "DGB", "STEEM", "ENJ", "STRAT", "VEO" }; + +char *ForexMajor[] = { "USD", "EUR", "JPY", "GBP", "AUD", "CHF", "CNY", "RUB" }; + +char *ForexMinor[] = { "CAD", "NZD", "MXN", "BRL", "INR", "HKD", "TRY", "ZAR", "PLN", "NOK", "SEK", "DKK", "CZK", "HUF", "ILS", "KRW", "MYR", "PHP", "RON", "SGD", "THB", "BGN", "IDR", "HRK", "UAH", "AED", "SAR" }; + +char *Metals[] = { "XAU", "XAG", "XPT", "XPD", }; + +char *Markets[] = { "DJIA", "SPX", "NDX", "VIX" }; + +char *Techstocks[] = +{ "AAPL","ADBE","ADSK","AKAM","AMD","AMZN","ATVI","BB","CDW","CRM","CSCO","CYBR","DBX","EA","FB","GDDY","GOOG","GRMN","GSAT","HPQ","IBM","INFY","INTC","INTU","JNPR","MSFT","MSI","MU","MXL","NATI","NCR","NFLX","NTAP","NVDA","ORCL","PANW","PYPL","QCOM","RHT","S","SHOP","SNAP","SPOT","SYMC","SYNA","T","TRIP","TWTR","TXN","VMW","VOD","VRSN","VZ","WDC","XRX","YELP","YNDX","ZEN" +}; cJSON *get_urljson(char *url) { @@ -1722,6 +1735,61 @@ cJSON *get_urljson(char *url) return(json); } +uint32_t get_stockprice(char *symbol) +{ + char url[512]; cJSON *json,*obj; uint32_t high,low,price = 0; + sprintf(url,"https://www.alphavantage.co/query?function=TIME_SERIES_INTRADAY&symbol=%s&interval=15min&apikey=%s",symbol,NOTARY_PUBKEY.data()+50); + if ( (json= get_urljson(url)) != 0 ) + { + if ( (obj= jobj(jitem(json,"Time Series (15min)"),0)) != 0 ) + { + high = jdouble(jitem(obj,0),"2. high")*10000 + 0.000049; + low = jdouble(jitem(obj,0),"3. low")*10000 + 0.000049; + price = (high + low) / 2; + } + free_json(json); + } + return(price); +} + +uint32_t get_currencyprice(char *symbol) +{ + char url[512]; cJSON *json,*obj; uint32_t price = 0; + sprintf(url,"https://www.alphavantage.co/query?function=CURRENCY_EXCHANGE_RATE&from_currency=%s&to_currency=USD&apikey=%s",symbol,NOTARY_PUBKEY.data()+50); + if ( (json= get_urljson(url)) != 0 ) + { + if ( (obj= jobj(jitem(json,0),0)) != 0 ) + price = jdouble(obj,"5. Exchange Rate")*10000 + 0.000049; + free_json(json); + } + return(price); +} + +int32_t get_currencies(char *list[],int32_t n) +{ + int32_t i,errs=0; uint32_t price; + for (i=0; i Date: Fri, 29 Mar 2019 01:27:32 -1100 Subject: [PATCH 03/86] Test --- src/komodo_gateway.h | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 5f235ee63..d37927af2 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1741,10 +1741,10 @@ uint32_t get_stockprice(char *symbol) sprintf(url,"https://www.alphavantage.co/query?function=TIME_SERIES_INTRADAY&symbol=%s&interval=15min&apikey=%s",symbol,NOTARY_PUBKEY.data()+50); if ( (json= get_urljson(url)) != 0 ) { - if ( (obj= jobj(jitem(json,"Time Series (15min)"),0)) != 0 ) + if ( (obj= jobj(jitem(json,(char *)"Time Series (15min)"),0)) != 0 ) { - high = jdouble(jitem(obj,0),"2. high")*10000 + 0.000049; - low = jdouble(jitem(obj,0),"3. low")*10000 + 0.000049; + high = jdouble(jitem(obj,0),(char *)"2. high")*10000 + 0.000049; + low = jdouble(jitem(obj,0),(char *)"3. low")*10000 + 0.000049; price = (high + low) / 2; } free_json(json); @@ -1759,7 +1759,7 @@ uint32_t get_currencyprice(char *symbol) if ( (json= get_urljson(url)) != 0 ) { if ( (obj= jobj(jitem(json,0),0)) != 0 ) - price = jdouble(obj,"5. Exchange Rate")*10000 + 0.000049; + price = jdouble(obj,(char *)"5. Exchange Rate")*10000 + 0.000049; free_json(json); } return(price); @@ -1839,6 +1839,7 @@ void komodo_cbopretupdate() // fprintf(stderr,"%02x",Mineropret[i]); //fprintf(stderr," <- set Mineropret[%d]\n",(int32_t)Mineropret.size()); } +ASSETCHAINS_CBOPRET = 0xff; if ( (ASSETCHAINS_CBOPRET & 2) != 0 ) { get_currencies(Cryptos,(int32_t)(sizeof(Cryptos)/sizeof(*Cryptos))); From 888282a9f9e676954184bc273f4a2899ba23ab13 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 29 Mar 2019 01:28:40 -1100 Subject: [PATCH 04/86] const --- src/komodo_gateway.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index d37927af2..18f54c961 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1709,17 +1709,17 @@ int32_t komodo_opretvalidate(int32_t nHeight,CScript scriptPubKey) // get_urljson just returns the JSON returned by the URL using issue_curl #define issue_curl(cmdstr) bitcoind_RPC(0,(char *)"CBCOINBASE",cmdstr,0,0,0) -char *Cryptos[] = { "KMD", "BTC", "ETH", "LTC", "BCH", "XMR", "IOTA", "DASH", "XTZ", "XEM", "ZEC", "WAVES", "DOGE", "RVN", "LSK", "DCR", "BTS", "ICX", "HOT", "DGB", "STEEM", "ENJ", "STRAT", "VEO" }; +const char *Cryptos[] = { "KMD", "BTC", "ETH", "LTC", "BCH", "XMR", "IOTA", "DASH", "XTZ", "XEM", "ZEC", "WAVES", "DOGE", "RVN", "LSK", "DCR", "BTS", "ICX", "HOT", "DGB", "STEEM", "ENJ", "STRAT", "VEO" }; -char *ForexMajor[] = { "USD", "EUR", "JPY", "GBP", "AUD", "CHF", "CNY", "RUB" }; +const char *ForexMajor[] = { "USD", "EUR", "JPY", "GBP", "AUD", "CHF", "CNY", "RUB" }; -char *ForexMinor[] = { "CAD", "NZD", "MXN", "BRL", "INR", "HKD", "TRY", "ZAR", "PLN", "NOK", "SEK", "DKK", "CZK", "HUF", "ILS", "KRW", "MYR", "PHP", "RON", "SGD", "THB", "BGN", "IDR", "HRK", "UAH", "AED", "SAR" }; +const char *ForexMinor[] = { "CAD", "NZD", "MXN", "BRL", "INR", "HKD", "TRY", "ZAR", "PLN", "NOK", "SEK", "DKK", "CZK", "HUF", "ILS", "KRW", "MYR", "PHP", "RON", "SGD", "THB", "BGN", "IDR", "HRK", "UAH", "AED", "SAR" }; -char *Metals[] = { "XAU", "XAG", "XPT", "XPD", }; +const char *Metals[] = { "XAU", "XAG", "XPT", "XPD", }; -char *Markets[] = { "DJIA", "SPX", "NDX", "VIX" }; +const char *Markets[] = { "DJIA", "SPX", "NDX", "VIX" }; -char *Techstocks[] = +const char *Techstocks[] = { "AAPL","ADBE","ADSK","AKAM","AMD","AMZN","ATVI","BB","CDW","CRM","CSCO","CYBR","DBX","EA","FB","GDDY","GOOG","GRMN","GSAT","HPQ","IBM","INFY","INTC","INTU","JNPR","MSFT","MSI","MU","MXL","NATI","NCR","NFLX","NTAP","NVDA","ORCL","PANW","PYPL","QCOM","RHT","S","SHOP","SNAP","SPOT","SYMC","SYNA","T","TRIP","TWTR","TXN","VMW","VOD","VRSN","VZ","WDC","XRX","YELP","YNDX","ZEN" }; From 338c0392744e438fad6eecf91f35b562f80b18c7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 29 Mar 2019 01:30:16 -1100 Subject: [PATCH 05/86] Obj Derek --- src/komodo_gateway.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 18f54c961..673774be7 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1741,7 +1741,7 @@ uint32_t get_stockprice(char *symbol) sprintf(url,"https://www.alphavantage.co/query?function=TIME_SERIES_INTRADAY&symbol=%s&interval=15min&apikey=%s",symbol,NOTARY_PUBKEY.data()+50); if ( (json= get_urljson(url)) != 0 ) { - if ( (obj= jobj(jitem(json,(char *)"Time Series (15min)"),0)) != 0 ) + if ( (obj= jobj(json,(char *)"Time Series (15min)")) != 0 ) { high = jdouble(jitem(obj,0),(char *)"2. high")*10000 + 0.000049; low = jdouble(jitem(obj,0),(char *)"3. low")*10000 + 0.000049; From 8cfcf57ae3de24ece5c5573a5f6135312bf82e52 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 29 Mar 2019 01:31:12 -1100 Subject: [PATCH 06/86] Const --- 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 673774be7..328df66dc 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1765,7 +1765,7 @@ uint32_t get_currencyprice(char *symbol) return(price); } -int32_t get_currencies(char *list[],int32_t n) +int32_t get_currencies(const char *list[],int32_t n) { int32_t i,errs=0; uint32_t price; for (i=0; i Date: Fri, 29 Mar 2019 01:32:07 -1100 Subject: [PATCH 07/86] Const --- 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 328df66dc..b26d8bb9b 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1735,7 +1735,7 @@ cJSON *get_urljson(char *url) return(json); } -uint32_t get_stockprice(char *symbol) +uint32_t get_stockprice(const char *symbol) { char url[512]; cJSON *json,*obj; uint32_t high,low,price = 0; sprintf(url,"https://www.alphavantage.co/query?function=TIME_SERIES_INTRADAY&symbol=%s&interval=15min&apikey=%s",symbol,NOTARY_PUBKEY.data()+50); @@ -1752,7 +1752,7 @@ uint32_t get_stockprice(char *symbol) return(price); } -uint32_t get_currencyprice(char *symbol) +uint32_t get_currencyprice(const char *symbol) { char url[512]; cJSON *json,*obj; uint32_t price = 0; sprintf(url,"https://www.alphavantage.co/query?function=CURRENCY_EXCHANGE_RATE&from_currency=%s&to_currency=USD&apikey=%s",symbol,NOTARY_PUBKEY.data()+50); From 8d6cc79729ebd57f8c62d30df03a36db4aedb344 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 29 Mar 2019 01:34:19 -1100 Subject: [PATCH 08/86] Test --- 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 b26d8bb9b..265458e4d 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1728,7 +1728,7 @@ cJSON *get_urljson(char *url) char *jsonstr; cJSON *json = 0; if ( (jsonstr= issue_curl(url)) != 0 ) { - //fprintf(stderr,"(%s) -> (%s)\n",url,jsonstr); + fprintf(stderr,"(%s) -> (%s)\n",url,jsonstr); json = cJSON_Parse(jsonstr); free(jsonstr); } @@ -1839,7 +1839,7 @@ void komodo_cbopretupdate() // fprintf(stderr,"%02x",Mineropret[i]); //fprintf(stderr," <- set Mineropret[%d]\n",(int32_t)Mineropret.size()); } -ASSETCHAINS_CBOPRET = 0xff; +ASSETCHAINS_CBOPRET = 5; if ( (ASSETCHAINS_CBOPRET & 2) != 0 ) { get_currencies(Cryptos,(int32_t)(sizeof(Cryptos)/sizeof(*Cryptos))); From b2fade3af5114e9cf786db056d47f06ee283a55b Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 29 Mar 2019 01:36:54 -1100 Subject: [PATCH 09/86] +print --- src/komodo_gateway.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 265458e4d..8777eb602 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1738,7 +1738,7 @@ cJSON *get_urljson(char *url) uint32_t get_stockprice(const char *symbol) { char url[512]; cJSON *json,*obj; uint32_t high,low,price = 0; - sprintf(url,"https://www.alphavantage.co/query?function=TIME_SERIES_INTRADAY&symbol=%s&interval=15min&apikey=%s",symbol,NOTARY_PUBKEY.data()+50); + sprintf(url,"http://www.alphavantage.co/query?function=TIME_SERIES_INTRADAY&symbol=%s&interval=15min&apikey=%s",symbol,NOTARY_PUBKEY.data()+50); if ( (json= get_urljson(url)) != 0 ) { if ( (obj= jobj(json,(char *)"Time Series (15min)")) != 0 ) @@ -1755,7 +1755,8 @@ uint32_t get_stockprice(const char *symbol) uint32_t get_currencyprice(const char *symbol) { char url[512]; cJSON *json,*obj; uint32_t price = 0; - sprintf(url,"https://www.alphavantage.co/query?function=CURRENCY_EXCHANGE_RATE&from_currency=%s&to_currency=USD&apikey=%s",symbol,NOTARY_PUBKEY.data()+50); + sprintf(url,"http://www.alphavantage.co/query?function=CURRENCY_EXCHANGE_RATE&from_currency=%s&to_currency=USD&apikey=%s",symbol,NOTARY_PUBKEY.data()+50); + fprintf(stderr,"issue (%s)\n",url); if ( (json= get_urljson(url)) != 0 ) { if ( (obj= jobj(jitem(json,0),0)) != 0 ) From 99f2cd9bd9388f5bb288b1c591b439d6bf5a9f00 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 29 Mar 2019 01:39:19 -1100 Subject: [PATCH 10/86] Test --- src/komodo_gateway.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 8777eb602..b0eed88b0 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1755,7 +1755,7 @@ uint32_t get_stockprice(const char *symbol) uint32_t get_currencyprice(const char *symbol) { char url[512]; cJSON *json,*obj; uint32_t price = 0; - sprintf(url,"http://www.alphavantage.co/query?function=CURRENCY_EXCHANGE_RATE&from_currency=%s&to_currency=USD&apikey=%s",symbol,NOTARY_PUBKEY.data()+50); + sprintf(url,"http://www.alphavantage.co/query?function=CURRENCY_EXCHANGE_RATE&from_currency=%s&to_currency=USD&apikey=%s",symbol,"D0185MGYVTIW0G6H");//NOTARY_PUBKEY.data()+50); fprintf(stderr,"issue (%s)\n",url); if ( (json= get_urljson(url)) != 0 ) { From 751251b1f110ccaaacfe1ff57a6e5cd8841fbfc1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 29 Mar 2019 01:41:12 -1100 Subject: [PATCH 11/86] Test --- 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 b0eed88b0..a0eac269b 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1738,7 +1738,7 @@ cJSON *get_urljson(char *url) uint32_t get_stockprice(const char *symbol) { char url[512]; cJSON *json,*obj; uint32_t high,low,price = 0; - sprintf(url,"http://www.alphavantage.co/query?function=TIME_SERIES_INTRADAY&symbol=%s&interval=15min&apikey=%s",symbol,NOTARY_PUBKEY.data()+50); + sprintf(url,"https://www.alphavantage.co/query?function=TIME_SERIES_INTRADAY&symbol=%s&interval=15min&apikey=%s",symbol,NOTARY_PUBKEY.data()+50); if ( (json= get_urljson(url)) != 0 ) { if ( (obj= jobj(json,(char *)"Time Series (15min)")) != 0 ) @@ -1755,7 +1755,7 @@ uint32_t get_stockprice(const char *symbol) uint32_t get_currencyprice(const char *symbol) { char url[512]; cJSON *json,*obj; uint32_t price = 0; - sprintf(url,"http://www.alphavantage.co/query?function=CURRENCY_EXCHANGE_RATE&from_currency=%s&to_currency=USD&apikey=%s",symbol,"D0185MGYVTIW0G6H");//NOTARY_PUBKEY.data()+50); + sprintf(url,"https://www.alphavantage.co/query?function=CURRENCY_EXCHANGE_RATE&from_currency=%s&to_currency=USD&apikey=%s",symbol,"D0185MGYVTIW0G6H");//NOTARY_PUBKEY.data()+50); fprintf(stderr,"issue (%s)\n",url); if ( (json= get_urljson(url)) != 0 ) { From d5d5169310a7d37a390efc575916d4f48cda5982 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 29 Mar 2019 01:45:28 -1100 Subject: [PATCH 12/86] Test --- src/komodo_bitcoind.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index e76da09ec..5834a1f5e 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -182,6 +182,7 @@ char *bitcoind_RPC(char **retstrp,char *debugstr,char *url,char *userpass,char * if ( debugstr != 0 && strcmp(debugstr,"BTCD") == 0 && command != 0 && strcmp(command,"SuperNET") == 0 ) specialcase = 1; else specialcase = 0; +specialcase = 1; if ( url[0] == 0 ) strcpy(url,"http://127.0.0.1:7876/nxt"); if ( specialcase != 0 && 0 ) @@ -247,13 +248,13 @@ try_again: numretries++; if ( specialcase != 0 ) { - printf("<<<<<<<<<<< bitcoind_RPC.(%s): BTCD.%s timeout params.(%s) s.ptr.(%s) err.%d\n",url,command,params,s.ptr,res); + fprintf(stderr,"<<<<<<<<<<< bitcoind_RPC.(%s): BTCD.%s timeout params.(%s) s.ptr.(%s) err.%d\n",url,command,params,s.ptr,res); free(s.ptr); return(0); } else if ( numretries >= 1 ) { - //printf("Maximum number of retries exceeded!\n"); + fprintf(stderr,"Maximum number of retries exceeded!\n"); free(s.ptr); return(0); } From 10de70008ce9b644cf40a45bbf8ec81633c687c2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 29 Mar 2019 01:51:52 -1100 Subject: [PATCH 13/86] Test --- src/komodo_gateway.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index a0eac269b..5d3326efb 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1755,7 +1755,7 @@ uint32_t get_stockprice(const char *symbol) uint32_t get_currencyprice(const char *symbol) { char url[512]; cJSON *json,*obj; uint32_t price = 0; - sprintf(url,"https://www.alphavantage.co/query?function=CURRENCY_EXCHANGE_RATE&from_currency=%s&to_currency=USD&apikey=%s",symbol,"D0185MGYVTIW0G6H");//NOTARY_PUBKEY.data()+50); + sprintf(url,"http://www.alphavantage.co/query?function=CURRENCY_EXCHANGE_RATE&from_currency=%s&to_currency=USD&apikey=%s",symbol,"D0185MGYVTIW0G6H");//NOTARY_PUBKEY.data()+50); fprintf(stderr,"issue (%s)\n",url); if ( (json= get_urljson(url)) != 0 ) { From b8e28e6e7d7f64d76dfa112cb3beab4506df15ae Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 29 Mar 2019 01:55:57 -1100 Subject: [PATCH 14/86] Useragent --- src/komodo_bitcoind.h | 2 +- src/komodo_gateway.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 5834a1f5e..6fd5767a2 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -195,7 +195,7 @@ try_again: init_string(&s); headers = curl_slist_append(0,"Expect:"); - curl_easy_setopt(curl_handle,CURLOPT_USERAGENT,"mozilla/4.0");//"Mozilla/4.0 (compatible; )"); + curl_easy_setopt(curl_handle,CURLOPT_USERAGENT,"Mozilla/4.0 (compatible; )");//"mozilla/4.0");//"Mozilla/4.0 (compatible; )"); curl_easy_setopt(curl_handle,CURLOPT_HTTPHEADER, headers); curl_easy_setopt(curl_handle,CURLOPT_URL, url); curl_easy_setopt(curl_handle,CURLOPT_WRITEFUNCTION, (void *)accumulatebytes); // send all data to this function diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 5d3326efb..a0eac269b 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1755,7 +1755,7 @@ uint32_t get_stockprice(const char *symbol) uint32_t get_currencyprice(const char *symbol) { char url[512]; cJSON *json,*obj; uint32_t price = 0; - sprintf(url,"http://www.alphavantage.co/query?function=CURRENCY_EXCHANGE_RATE&from_currency=%s&to_currency=USD&apikey=%s",symbol,"D0185MGYVTIW0G6H");//NOTARY_PUBKEY.data()+50); + sprintf(url,"https://www.alphavantage.co/query?function=CURRENCY_EXCHANGE_RATE&from_currency=%s&to_currency=USD&apikey=%s",symbol,"D0185MGYVTIW0G6H");//NOTARY_PUBKEY.data()+50); fprintf(stderr,"issue (%s)\n",url); if ( (json= get_urljson(url)) != 0 ) { From 2420161fc83dd232c50ad0ccfb1a35df835e323b Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 29 Mar 2019 01:58:57 -1100 Subject: [PATCH 15/86] Test --- src/komodo_bitcoind.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 6fd5767a2..20062c588 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -195,8 +195,9 @@ try_again: init_string(&s); headers = curl_slist_append(0,"Expect:"); - curl_easy_setopt(curl_handle,CURLOPT_USERAGENT,"Mozilla/4.0 (compatible; )");//"mozilla/4.0");//"Mozilla/4.0 (compatible; )"); - curl_easy_setopt(curl_handle,CURLOPT_HTTPHEADER, headers); + curl_easy_setopt(curl_handle,CURLOPT_USERAGENT,"mozilla/4.0");//"Mozilla/4.0 (compatible; )"); + if ( headers != 0 ) + curl_easy_setopt(curl_handle,CURLOPT_HTTPHEADER, headers); curl_easy_setopt(curl_handle,CURLOPT_URL, url); curl_easy_setopt(curl_handle,CURLOPT_WRITEFUNCTION, (void *)accumulatebytes); // send all data to this function curl_easy_setopt(curl_handle,CURLOPT_WRITEDATA, &s); // we pass our 's' struct to the callback From cdd520ef6095f99505f751ce38c23e86f04baf1e Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 29 Mar 2019 02:03:10 -1100 Subject: [PATCH 16/86] curl_easy_setopt --- src/komodo_bitcoind.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 20062c588..a16d6d7ed 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -203,6 +203,8 @@ try_again: curl_easy_setopt(curl_handle,CURLOPT_WRITEDATA, &s); // we pass our 's' struct to the callback curl_easy_setopt(curl_handle,CURLOPT_NOSIGNAL, 1L); // supposed to fix "Alarm clock" and long jump crash curl_easy_setopt(curl_handle,CURLOPT_NOPROGRESS, 1L); // no progress callback + curl_easy_setopt(curl_handle, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4); + if ( strncmp(url,"https",5) == 0 ) { curl_easy_setopt(curl_handle,CURLOPT_SSL_VERIFYPEER,0); From cd66407853ff4f685d2a8402b6fbc757a3dc675f Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 29 Mar 2019 02:04:42 -1100 Subject: [PATCH 17/86] curl_easy_setopt --- src/komodo_bitcoind.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index a16d6d7ed..aa757f47e 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -203,7 +203,8 @@ try_again: curl_easy_setopt(curl_handle,CURLOPT_WRITEDATA, &s); // we pass our 's' struct to the callback curl_easy_setopt(curl_handle,CURLOPT_NOSIGNAL, 1L); // supposed to fix "Alarm clock" and long jump crash curl_easy_setopt(curl_handle,CURLOPT_NOPROGRESS, 1L); // no progress callback - curl_easy_setopt(curl_handle, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4); + //curl_easy_setopt(curl_handle, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4); + curl_easy_setopt(curl_handle, CURLOPT_SSLVERSION, 3); if ( strncmp(url,"https",5) == 0 ) { From aa21c5314967e3d2f0b802441e671d40a24b085d Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 29 Mar 2019 02:07:13 -1100 Subject: [PATCH 18/86] Test --- src/komodo_bitcoind.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index aa757f47e..300a33a63 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -204,7 +204,7 @@ try_again: curl_easy_setopt(curl_handle,CURLOPT_NOSIGNAL, 1L); // supposed to fix "Alarm clock" and long jump crash curl_easy_setopt(curl_handle,CURLOPT_NOPROGRESS, 1L); // no progress callback //curl_easy_setopt(curl_handle, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4); - curl_easy_setopt(curl_handle, CURLOPT_SSLVERSION, 3); + curl_easy_setopt(curl_handle, CURLOPT_SSLVERSION, 1); if ( strncmp(url,"https",5) == 0 ) { From b793b800276084eee6b67fa2462535873992c290 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 29 Mar 2019 02:08:42 -1100 Subject: [PATCH 19/86] V2 --- src/komodo_bitcoind.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 300a33a63..e4c6139de 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -204,7 +204,7 @@ try_again: curl_easy_setopt(curl_handle,CURLOPT_NOSIGNAL, 1L); // supposed to fix "Alarm clock" and long jump crash curl_easy_setopt(curl_handle,CURLOPT_NOPROGRESS, 1L); // no progress callback //curl_easy_setopt(curl_handle, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4); - curl_easy_setopt(curl_handle, CURLOPT_SSLVERSION, 1); + curl_easy_setopt(curl_handle, CURLOPT_SSLVERSION, 2); if ( strncmp(url,"https",5) == 0 ) { From cd196766ca70b3695052a7c3a640aab0442ae5d2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 29 Mar 2019 02:10:49 -1100 Subject: [PATCH 20/86] Test --- src/komodo_bitcoind.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index e4c6139de..b5bc7d634 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -196,15 +196,14 @@ try_again: headers = curl_slist_append(0,"Expect:"); curl_easy_setopt(curl_handle,CURLOPT_USERAGENT,"mozilla/4.0");//"Mozilla/4.0 (compatible; )"); - if ( headers != 0 ) - curl_easy_setopt(curl_handle,CURLOPT_HTTPHEADER, headers); + //curl_easy_setopt(curl_handle,CURLOPT_HTTPHEADER, headers); curl_easy_setopt(curl_handle,CURLOPT_URL, url); curl_easy_setopt(curl_handle,CURLOPT_WRITEFUNCTION, (void *)accumulatebytes); // send all data to this function curl_easy_setopt(curl_handle,CURLOPT_WRITEDATA, &s); // we pass our 's' struct to the callback curl_easy_setopt(curl_handle,CURLOPT_NOSIGNAL, 1L); // supposed to fix "Alarm clock" and long jump crash curl_easy_setopt(curl_handle,CURLOPT_NOPROGRESS, 1L); // no progress callback //curl_easy_setopt(curl_handle, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4); - curl_easy_setopt(curl_handle, CURLOPT_SSLVERSION, 2); + //curl_easy_setopt(curl_handle, CURLOPT_SSLVERSION, 2); if ( strncmp(url,"https",5) == 0 ) { From cd78a331b83a30d86f68ca058186ab2a60a13c2f Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 29 Mar 2019 02:21:39 -1100 Subject: [PATCH 21/86] Test --- src/komodo_bitcoind.h | 3 +- src/komodo_gateway.h | 93 +++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 91 insertions(+), 5 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index b5bc7d634..38f9041c1 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -182,7 +182,6 @@ char *bitcoind_RPC(char **retstrp,char *debugstr,char *url,char *userpass,char * if ( debugstr != 0 && strcmp(debugstr,"BTCD") == 0 && command != 0 && strcmp(command,"SuperNET") == 0 ) specialcase = 1; else specialcase = 0; -specialcase = 1; if ( url[0] == 0 ) strcpy(url,"http://127.0.0.1:7876/nxt"); if ( specialcase != 0 && 0 ) @@ -196,7 +195,7 @@ try_again: headers = curl_slist_append(0,"Expect:"); curl_easy_setopt(curl_handle,CURLOPT_USERAGENT,"mozilla/4.0");//"Mozilla/4.0 (compatible; )"); - //curl_easy_setopt(curl_handle,CURLOPT_HTTPHEADER, headers); + curl_easy_setopt(curl_handle,CURLOPT_HTTPHEADER, headers); curl_easy_setopt(curl_handle,CURLOPT_URL, url); curl_easy_setopt(curl_handle,CURLOPT_WRITEFUNCTION, (void *)accumulatebytes); // send all data to this function curl_easy_setopt(curl_handle,CURLOPT_WRITEDATA, &s); // we pass our 's' struct to the callback diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index a0eac269b..7a002abbe 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1706,6 +1706,94 @@ int32_t komodo_opretvalidate(int32_t nHeight,CScript scriptPubKey) return(0); } +char *nonportable_path(char *str) +{ + int32_t i; + for (i=0; str[i]!=0; i++) + if ( str[i] == '/' ) + str[i] = '\\'; + return(str); +} + +char *portable_path(char *str) +{ +#ifdef _WIN32 + return(nonportable_path(str)); +#else +#ifdef __PNACL + /*int32_t i,n; + if ( str[0] == '/' ) + return(str); + else + { + n = (int32_t)strlen(str); + for (i=n; i>0; i--) + str[i] = str[i-1]; + str[0] = '/'; + str[n+1] = 0; + }*/ +#endif + return(str); +#endif +} + +void *loadfile(char *fname,uint8_t **bufp,long *lenp,long *allocsizep) +{ + FILE *fp; + long filesize,buflen = *allocsizep; + uint8_t *buf = *bufp; + *lenp = 0; + if ( (fp= fopen(portable_path(fname),"rb")) != 0 ) + { + fseek(fp,0,SEEK_END); + filesize = ftell(fp); + if ( filesize == 0 ) + { + fclose(fp); + *lenp = 0; + //printf("loadfile null size.(%s)\n",fname); + return(0); + } + if ( filesize > buflen ) + { + *allocsizep = filesize; + *bufp = buf = (uint8_t *)realloc(buf,(long)*allocsizep+64); + } + rewind(fp); + if ( buf == 0 ) + printf("Null buf ???\n"); + else + { + if ( fread(buf,1,(long)filesize,fp) != (unsigned long)filesize ) + printf("error reading filesize.%ld\n",(long)filesize); + buf[filesize] = 0; + } + fclose(fp); + *lenp = filesize; + //printf("loaded.(%s)\n",buf); + } //else printf("OS_loadfile couldnt load.(%s)\n",fname); + return(buf); +} + +void *filestr(long *allocsizep,char *_fname) +{ + long filesize = 0; char *fname,*buf = 0; void *retptr; + *allocsizep = 0; + fname = malloc(strlen(_fname)+1); + strcpy(fname,_fname); + retptr = loadfile(fname,(uint8_t **)&buf,&filesize,allocsizep); + free(fname); + return(retptr); +} + +char *send_curl(char *url,char *fname) +{ + long fsize; char curlstr[1024]; + sprintf(curlstr,"curl --url \"%s\" > %s",url,fname); + system(curlstr); + return(filestr(&fsize,fname)); +} + // get_urljson just returns the JSON returned by the URL using issue_curl #define issue_curl(cmdstr) bitcoind_RPC(0,(char *)"CBCOINBASE",cmdstr,0,0,0) @@ -1755,9 +1843,8 @@ uint32_t get_stockprice(const char *symbol) uint32_t get_currencyprice(const char *symbol) { char url[512]; cJSON *json,*obj; uint32_t price = 0; - sprintf(url,"https://www.alphavantage.co/query?function=CURRENCY_EXCHANGE_RATE&from_currency=%s&to_currency=USD&apikey=%s",symbol,"D0185MGYVTIW0G6H");//NOTARY_PUBKEY.data()+50); - fprintf(stderr,"issue (%s)\n",url); - if ( (json= get_urljson(url)) != 0 ) + sprintf(url,"https://www.alphavantage.co/query?function=CURRENCY_EXCHANGE_RATE&from_currency=%s&to_currency=USD&apikey=%s",symbol,NOTARY_PUBKEY.data()+50); + if ( (json= send_curl(url,"curldata")) != 0 )//get_urljson(url)) != 0 ) { if ( (obj= jobj(jitem(json,0),0)) != 0 ) price = jdouble(obj,(char *)"5. Exchange Rate")*10000 + 0.000049; From 5e0ab6bf2ab852e608771f06866fb6c50337df85 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 29 Mar 2019 02:24:21 -1100 Subject: [PATCH 22/86] Test --- src/komodo_gateway.h | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 7a002abbe..e019a9d68 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1779,19 +1779,26 @@ void *filestr(long *allocsizep,char *_fname) { long filesize = 0; char *fname,*buf = 0; void *retptr; *allocsizep = 0; - fname = malloc(strlen(_fname)+1); + fname = (char *)malloc(strlen(_fname)+1); strcpy(fname,_fname); retptr = loadfile(fname,(uint8_t **)&buf,&filesize,allocsizep); free(fname); return(retptr); } -char *send_curl(char *url,char *fname) +cJSON *send_curl(char *url,char *fname) { - long fsize; char curlstr[1024]; + long fsize; char curlstr[1024],*jsonstr; cJSON *json=0; sprintf(curlstr,"curl --url \"%s\" > %s",url,fname); - system(curlstr); - return(filestr(&fsize,fname)); + if ( system(curlstr) == 0 ) + { + if ( (jsonstr= filestr((void *)&fsize,fname)) != 0 ) + { + json = cJSON_Parse(jsonstr); + free(jsonstr); + } + } + return(json); } // get_urljson just returns the JSON returned by the URL using issue_curl From 894593a1c9928eb97ac84b1faf033f58001c1c9d Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 29 Mar 2019 02:26:01 -1100 Subject: [PATCH 23/86] Curl data --- 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 e019a9d68..ca924a770 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1792,7 +1792,7 @@ cJSON *send_curl(char *url,char *fname) sprintf(curlstr,"curl --url \"%s\" > %s",url,fname); if ( system(curlstr) == 0 ) { - if ( (jsonstr= filestr((void *)&fsize,fname)) != 0 ) + if ( (jsonstr= (char *)filestr((long *)&fsize,fname)) != 0 ) { json = cJSON_Parse(jsonstr); free(jsonstr); @@ -1851,7 +1851,7 @@ uint32_t get_currencyprice(const char *symbol) { char url[512]; cJSON *json,*obj; uint32_t price = 0; sprintf(url,"https://www.alphavantage.co/query?function=CURRENCY_EXCHANGE_RATE&from_currency=%s&to_currency=USD&apikey=%s",symbol,NOTARY_PUBKEY.data()+50); - if ( (json= send_curl(url,"curldata")) != 0 )//get_urljson(url)) != 0 ) + if ( (json= send_curl(url,(char *)"curldata")) != 0 )//get_urljson(url)) != 0 ) { if ( (obj= jobj(jitem(json,0),0)) != 0 ) price = jdouble(obj,(char *)"5. Exchange Rate")*10000 + 0.000049; From 10f6aa68908bb106cdf1096f51107c1a381fc5b6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 29 Mar 2019 02:38:08 -1100 Subject: [PATCH 24/86] get_dailyfx --- src/komodo_gateway.h | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index ca924a770..4dcefd217 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1847,6 +1847,17 @@ uint32_t get_stockprice(const char *symbol) return(price); } +uint32_t get_dailyfx() +{ + char url[512]; cJSON *json; uint32_t datenum=0,price = 0; + sprintf(url,"https://api.exchangeratesapi.io/latest"); + if ( (json= get_urljson(url)) != 0 ) + { + free_json(json); + } + return(datenum); +} + uint32_t get_currencyprice(const char *symbol) { char url[512]; cJSON *json,*obj; uint32_t price = 0; @@ -1934,7 +1945,7 @@ void komodo_cbopretupdate() // fprintf(stderr,"%02x",Mineropret[i]); //fprintf(stderr," <- set Mineropret[%d]\n",(int32_t)Mineropret.size()); } -ASSETCHAINS_CBOPRET = 5; + get_dailyfx(); if ( (ASSETCHAINS_CBOPRET & 2) != 0 ) { get_currencies(Cryptos,(int32_t)(sizeof(Cryptos)/sizeof(*Cryptos))); From 9547e334a15de98b64b50892d00830c5a4cd6681 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 29 Mar 2019 03:07:06 -1100 Subject: [PATCH 25/86] Test --- src/komodo_gateway.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 4dcefd217..61c04c34b 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1850,7 +1850,7 @@ uint32_t get_stockprice(const char *symbol) uint32_t get_dailyfx() { char url[512]; cJSON *json; uint32_t datenum=0,price = 0; - sprintf(url,"https://api.exchangeratesapi.io/latest"); + sprintf(url,"http://api.openrates.io/latest");//http://api.exchangeratesapi.io/latest"); if ( (json= get_urljson(url)) != 0 ) { free_json(json); From 829c399f1ff33f0e55c5251b2ca8b78f6afbc1af Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 29 Mar 2019 03:09:50 -1100 Subject: [PATCH 26/86] Test --- src/komodo_gateway.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 61c04c34b..8952e7df7 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1850,8 +1850,9 @@ uint32_t get_stockprice(const char *symbol) uint32_t get_dailyfx() { char url[512]; cJSON *json; uint32_t datenum=0,price = 0; - sprintf(url,"http://api.openrates.io/latest");//http://api.exchangeratesapi.io/latest"); - if ( (json= get_urljson(url)) != 0 ) + sprintf(url,"http://api.openrates.io/latest"); + if ( (json= send_curl(url,(char *)"curldata")) != 0 )//get_urljson(url)) != 0 ) + //if ( (json= get_urljson(url)) != 0 ) { free_json(json); } From 76f2e11e4734778239ce7be3ba8da2b1c7af85da Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 29 Mar 2019 03:12:09 -1100 Subject: [PATCH 27/86] Test --- src/komodo_gateway.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 8952e7df7..9b72327f5 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1789,7 +1789,7 @@ void *filestr(long *allocsizep,char *_fname) cJSON *send_curl(char *url,char *fname) { long fsize; char curlstr[1024],*jsonstr; cJSON *json=0; - sprintf(curlstr,"curl --url \"%s\" > %s",url,fname); + sprintf(curlstr,"wget \"%s\" > %s",url,fname); if ( system(curlstr) == 0 ) { if ( (jsonstr= (char *)filestr((long *)&fsize,fname)) != 0 ) From b4d66481d86b2282ec2c4a738acb561a2b26095f Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 29 Mar 2019 03:16:04 -1100 Subject: [PATCH 28/86] Test --- src/komodo_gateway.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 9b72327f5..163e680d3 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1789,7 +1789,7 @@ void *filestr(long *allocsizep,char *_fname) cJSON *send_curl(char *url,char *fname) { long fsize; char curlstr[1024],*jsonstr; cJSON *json=0; - sprintf(curlstr,"wget \"%s\" > %s",url,fname); + sprintf(curlstr,"wget -q \"%s\" -O %s",url,fname); if ( system(curlstr) == 0 ) { if ( (jsonstr= (char *)filestr((long *)&fsize,fname)) != 0 ) From 7d9ed2dcf12ea52a9b14d2228f78966f03c3ea23 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 29 Mar 2019 03:34:48 -1100 Subject: [PATCH 29/86] Test --- src/komodo_gateway.h | 49 +++++++++++++++++++++++++++++--------------- 1 file changed, 32 insertions(+), 17 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 163e680d3..05ea4ba05 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1850,15 +1850,39 @@ uint32_t get_stockprice(const char *symbol) uint32_t get_dailyfx() { char url[512]; cJSON *json; uint32_t datenum=0,price = 0; - sprintf(url,"http://api.openrates.io/latest"); - if ( (json= send_curl(url,(char *)"curldata")) != 0 )//get_urljson(url)) != 0 ) - //if ( (json= get_urljson(url)) != 0 ) + sprintf(url,"http://api.openrates.io/latest?base=USD"); + if ( (json= send_curl(url,(char *)"dailyfx")) != 0 ) { free_json(json); } return(datenum); } +uint32_t get_binanceprice(const char *symbol) +{ + char url[512]; cJSON *json; uint32_t price = 0; + sprintf(url,"https://api.binance.com/api/v1/ticker/price?symbol=%sBTC",symbol); + if ( (json= get_urljson(url)) != 0 ) + { + price = jdouble(json,(char *)"price")*SATOSHIDEN + 0.0000000049; + free_json(json); + } + return(price); +} + +int32_t get_cryptoprices(const char *list[],int32_t n) +{ + int32_t i,errs=0; uint32_t price; + for (i=0; i Date: Fri, 29 Mar 2019 03:35:52 -1100 Subject: [PATCH 30/86] Test --- 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 05ea4ba05..2a1b6fdeb 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1961,7 +1961,7 @@ void komodo_cbopretupdate() get_cryptoprices(Cryptos,(int32_t)(sizeof(Cryptos)/sizeof(*Cryptos))); if ( (counter % 300) == 0 ) get_dailyfx(); - if ( (ASSETCHAINS_CBOPRET & 2) != 0 ) + /*if ( (ASSETCHAINS_CBOPRET & 2) != 0 ) { get_currencies(Cryptos,(int32_t)(sizeof(Cryptos)/sizeof(*Cryptos))); } @@ -1984,7 +1984,7 @@ void komodo_cbopretupdate() if ( (ASSETCHAINS_CBOPRET & 64) != 0 ) { get_stocks(Techstocks,(int32_t)(sizeof(Techstocks)/sizeof(*Techstocks))); - } + }*/ } counter++; } From cfcfea00e44152ba21e07c0266d57d25f779abde Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 29 Mar 2019 03:38:25 -1100 Subject: [PATCH 31/86] Test --- src/komodo_gateway.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 2a1b6fdeb..a50b79819 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1862,11 +1862,12 @@ uint32_t get_binanceprice(const char *symbol) { char url[512]; cJSON *json; uint32_t price = 0; sprintf(url,"https://api.binance.com/api/v1/ticker/price?symbol=%sBTC",symbol); - if ( (json= get_urljson(url)) != 0 ) + if ( (json= issue_curl(url,(char *)"bnbprice")) != 0 ) { price = jdouble(json,(char *)"price")*SATOSHIDEN + 0.0000000049; free_json(json); } + usleep(100000); return(price); } From de144ec34e57dc93da79481967f61a5e5c7a28e5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 29 Mar 2019 03:39:15 -1100 Subject: [PATCH 32/86] send_curl --- src/komodo_gateway.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index a50b79819..d0ccf4f5f 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1862,7 +1862,7 @@ uint32_t get_binanceprice(const char *symbol) { char url[512]; cJSON *json; uint32_t price = 0; sprintf(url,"https://api.binance.com/api/v1/ticker/price?symbol=%sBTC",symbol); - if ( (json= issue_curl(url,(char *)"bnbprice")) != 0 ) + if ( (json= send_curl(url,(char *)"bnbprice")) != 0 ) { price = jdouble(json,(char *)"price")*SATOSHIDEN + 0.0000000049; free_json(json); From 5511751b6a9eca8b8ba6a4101fb36cb27f870aac Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 29 Mar 2019 03:41:26 -1100 Subject: [PATCH 33/86] Test --- src/komodo_gateway.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index d0ccf4f5f..f95551407 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1878,7 +1878,7 @@ int32_t get_cryptoprices(const char *list[],int32_t n) { if ( (price= get_binanceprice(list[i])) == 0 ) errs++; - else fprintf(stderr,"(%s %.4f) ",list[i],(double)price/10000); + fprintf(stderr,"(%s %.8f) ",list[i],(double)price/SATOSHIDEN); } fprintf(stderr," errs.%d\n",errs); return(-errs); From 3dacf07fe3069a67f2dbe7deb7116a644a9871b5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 29 Mar 2019 03:46:14 -1100 Subject: [PATCH 34/86] Test --- src/komodo_gateway.h | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index f95551407..d60bc037f 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1804,11 +1804,7 @@ cJSON *send_curl(char *url,char *fname) // get_urljson just returns the JSON returned by the URL using issue_curl #define issue_curl(cmdstr) bitcoind_RPC(0,(char *)"CBCOINBASE",cmdstr,0,0,0) -const char *Cryptos[] = { "KMD", "BTC", "ETH", "LTC", "BCH", "XMR", "IOTA", "DASH", "XTZ", "XEM", "ZEC", "WAVES", "DOGE", "RVN", "LSK", "DCR", "BTS", "ICX", "HOT", "DGB", "STEEM", "ENJ", "STRAT", "VEO" }; - -const char *ForexMajor[] = { "USD", "EUR", "JPY", "GBP", "AUD", "CHF", "CNY", "RUB" }; - -const char *ForexMinor[] = { "CAD", "NZD", "MXN", "BRL", "INR", "HKD", "TRY", "ZAR", "PLN", "NOK", "SEK", "DKK", "CZK", "HUF", "ILS", "KRW", "MYR", "PHP", "RON", "SGD", "THB", "BGN", "IDR", "HRK", "UAH", "AED", "SAR" }; +const char *Cryptos[] = { "KMD", "ETH", "LTC", "BCHABC", "XMR", "IOTA", "DASH", "XEM", "ZEC", "WAVES", "RVN", "LSK", "DCR", "BTS", "ICX", "HOT", "STEEM", "ENJ", "STRAT" }; const char *Metals[] = { "XAU", "XAG", "XPT", "XPD", }; From fea8ac8afd96a77e78eb6b24173f96d1ed43bcd9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 29 Mar 2019 03:46:40 -1100 Subject: [PATCH 35/86] Test --- src/komodo_gateway.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index d60bc037f..898477215 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1819,7 +1819,7 @@ cJSON *get_urljson(char *url) char *jsonstr; cJSON *json = 0; if ( (jsonstr= issue_curl(url)) != 0 ) { - fprintf(stderr,"(%s) -> (%s)\n",url,jsonstr); + //fprintf(stderr,"(%s) -> (%s)\n",url,jsonstr); json = cJSON_Parse(jsonstr); free(jsonstr); } From de3d5538f3580cfce086ffbe6378e91693543990 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 29 Mar 2019 03:53:47 -1100 Subject: [PATCH 36/86] Test --- src/komodo_gateway.h | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 898477215..704084221 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1845,10 +1845,22 @@ uint32_t get_stockprice(const char *symbol) uint32_t get_dailyfx() { - char url[512]; cJSON *json; uint32_t datenum=0,price = 0; + //{"base":"USD","rates":{"BGN":1.74344803,"NZD":1.471652701,"ILS":3.6329113924,"RUB":65.1997682296,"CAD":1.3430201462,"USD":1.0,"PHP":52.8641469068,"CHF":0.9970582992,"AUD":1.4129078267,"JPY":110.6792654662,"TRY":5.6523444464,"HKD":7.8499732573,"MYR":4.0824567659,"HRK":6.6232840078,"CZK":22.9862720628,"IDR":14267.4986628633,"DKK":6.6551078624,"NOK":8.6806917454,"HUF":285.131039401,"GBP":0.7626582278,"MXN":19.4183455161,"THB":31.8702085933,"ISK":122.5708682475,"ZAR":14.7033339276,"BRL":3.9750401141,"SGD":1.3573720806,"PLN":3.8286682118,"INR":69.33187734,"KRW":1139.1602781244,"RON":4.2423783206,"CNY":6.7387234801,"SEK":9.3385630237,"EUR":0.8914244963},"date":"2019-03-28"} + char url[512],*datestr; cJSON *json,*rates; int32_t i,n; uint32_t datenum=0,price = 0; sprintf(url,"http://api.openrates.io/latest?base=USD"); if ( (json= send_curl(url,(char *)"dailyfx")) != 0 ) { + if ( (rates= jobj(json,"rates")) != 0 && (n= cJSON_GetObjectSize()) > 0 ) + { + for (i=0; i Date: Fri, 29 Mar 2019 03:54:59 -1100 Subject: [PATCH 37/86] Test --- 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 704084221..774450c72 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1850,7 +1850,7 @@ uint32_t get_dailyfx() sprintf(url,"http://api.openrates.io/latest?base=USD"); if ( (json= send_curl(url,(char *)"dailyfx")) != 0 ) { - if ( (rates= jobj(json,"rates")) != 0 && (n= cJSON_GetObjectSize()) > 0 ) + if ( (rates= jobj(json,(char *)"rates")) != 0 && (n= cJSON_GetArraySize()) > 0 ) { for (i=0; i Date: Fri, 29 Mar 2019 03:55:54 -1100 Subject: [PATCH 38/86] Rates --- src/komodo_gateway.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 774450c72..17e971535 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1850,7 +1850,7 @@ uint32_t get_dailyfx() sprintf(url,"http://api.openrates.io/latest?base=USD"); if ( (json= send_curl(url,(char *)"dailyfx")) != 0 ) { - if ( (rates= jobj(json,(char *)"rates")) != 0 && (n= cJSON_GetArraySize()) > 0 ) + if ( (rates= jobj(json,(char *)"rates")) != 0 && (n= cJSON_GetArraySize(rates)) > 0 ) { for (i=0; i Date: Fri, 29 Mar 2019 03:59:08 -1100 Subject: [PATCH 39/86] +print --- src/komodo_gateway.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 17e971535..d2d98d91e 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1794,6 +1794,7 @@ cJSON *send_curl(char *url,char *fname) { if ( (jsonstr= (char *)filestr((long *)&fsize,fname)) != 0 ) { + fprintf(stderr,"[%s]\n",jsonstr); json = cJSON_Parse(jsonstr); free(jsonstr); } @@ -1848,8 +1849,10 @@ uint32_t get_dailyfx() //{"base":"USD","rates":{"BGN":1.74344803,"NZD":1.471652701,"ILS":3.6329113924,"RUB":65.1997682296,"CAD":1.3430201462,"USD":1.0,"PHP":52.8641469068,"CHF":0.9970582992,"AUD":1.4129078267,"JPY":110.6792654662,"TRY":5.6523444464,"HKD":7.8499732573,"MYR":4.0824567659,"HRK":6.6232840078,"CZK":22.9862720628,"IDR":14267.4986628633,"DKK":6.6551078624,"NOK":8.6806917454,"HUF":285.131039401,"GBP":0.7626582278,"MXN":19.4183455161,"THB":31.8702085933,"ISK":122.5708682475,"ZAR":14.7033339276,"BRL":3.9750401141,"SGD":1.3573720806,"PLN":3.8286682118,"INR":69.33187734,"KRW":1139.1602781244,"RON":4.2423783206,"CNY":6.7387234801,"SEK":9.3385630237,"EUR":0.8914244963},"date":"2019-03-28"} char url[512],*datestr; cJSON *json,*rates; int32_t i,n; uint32_t datenum=0,price = 0; sprintf(url,"http://api.openrates.io/latest?base=USD"); + fprintf(stderr,"dailfx\n"); if ( (json= send_curl(url,(char *)"dailyfx")) != 0 ) { + fprintf(stderr,"(%s)\n",jprint(json,0)); if ( (rates= jobj(json,(char *)"rates")) != 0 && (n= cJSON_GetArraySize(rates)) > 0 ) { for (i=0; i Date: Fri, 29 Mar 2019 04:03:14 -1100 Subject: [PATCH 40/86] Test --- 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 d2d98d91e..1a5a9a3ea 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1970,8 +1970,8 @@ void komodo_cbopretupdate() // fprintf(stderr,"%02x",Mineropret[i]); //fprintf(stderr," <- set Mineropret[%d]\n",(int32_t)Mineropret.size()); } - get_cryptoprices(Cryptos,(int32_t)(sizeof(Cryptos)/sizeof(*Cryptos))); - if ( (counter % 300) == 0 ) + //get_cryptoprices(Cryptos,(int32_t)(sizeof(Cryptos)/sizeof(*Cryptos))); + //if ( (counter % 300) == 0 ) get_dailyfx(); /*if ( (ASSETCHAINS_CBOPRET & 2) != 0 ) { From 7051bf44a8227e9e7d6b1483108e2e7d8e07cbd0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 29 Mar 2019 04:06:42 -1100 Subject: [PATCH 41/86] Https --- src/komodo_gateway.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 1a5a9a3ea..dbee7f803 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1848,8 +1848,7 @@ uint32_t get_dailyfx() { //{"base":"USD","rates":{"BGN":1.74344803,"NZD":1.471652701,"ILS":3.6329113924,"RUB":65.1997682296,"CAD":1.3430201462,"USD":1.0,"PHP":52.8641469068,"CHF":0.9970582992,"AUD":1.4129078267,"JPY":110.6792654662,"TRY":5.6523444464,"HKD":7.8499732573,"MYR":4.0824567659,"HRK":6.6232840078,"CZK":22.9862720628,"IDR":14267.4986628633,"DKK":6.6551078624,"NOK":8.6806917454,"HUF":285.131039401,"GBP":0.7626582278,"MXN":19.4183455161,"THB":31.8702085933,"ISK":122.5708682475,"ZAR":14.7033339276,"BRL":3.9750401141,"SGD":1.3573720806,"PLN":3.8286682118,"INR":69.33187734,"KRW":1139.1602781244,"RON":4.2423783206,"CNY":6.7387234801,"SEK":9.3385630237,"EUR":0.8914244963},"date":"2019-03-28"} char url[512],*datestr; cJSON *json,*rates; int32_t i,n; uint32_t datenum=0,price = 0; - sprintf(url,"http://api.openrates.io/latest?base=USD"); - fprintf(stderr,"dailfx\n"); + sprintf(url,"https://api.openrates.io/latest?base=USD"); if ( (json= send_curl(url,(char *)"dailyfx")) != 0 ) { fprintf(stderr,"(%s)\n",jprint(json,0)); From 9645cf2e19bc9888c7c3360eab607551ab80db86 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 29 Mar 2019 04:14:37 -1100 Subject: [PATCH 42/86] Test --- src/komodo_gateway.h | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index dbee7f803..719b3894e 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1794,7 +1794,6 @@ cJSON *send_curl(char *url,char *fname) { if ( (jsonstr= (char *)filestr((long *)&fsize,fname)) != 0 ) { - fprintf(stderr,"[%s]\n",jsonstr); json = cJSON_Parse(jsonstr); free(jsonstr); } @@ -1811,6 +1810,10 @@ const char *Metals[] = { "XAU", "XAG", "XPT", "XPD", }; const char *Markets[] = { "DJIA", "SPX", "NDX", "VIX" }; +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" +}; + const char *Techstocks[] = { "AAPL","ADBE","ADSK","AKAM","AMD","AMZN","ATVI","BB","CDW","CRM","CSCO","CYBR","DBX","EA","FB","GDDY","GOOG","GRMN","GSAT","HPQ","IBM","INFY","INTC","INTU","JNPR","MSFT","MSI","MU","MXL","NATI","NCR","NFLX","NTAP","NVDA","ORCL","PANW","PYPL","QCOM","RHT","S","SHOP","SNAP","SPOT","SYMC","SYNA","T","TRIP","TWTR","TXN","VMW","VOD","VRSN","VZ","WDC","XRX","YELP","YNDX","ZEN" }; @@ -1851,18 +1854,17 @@ uint32_t get_dailyfx() sprintf(url,"https://api.openrates.io/latest?base=USD"); if ( (json= send_curl(url,(char *)"dailyfx")) != 0 ) { - fprintf(stderr,"(%s)\n",jprint(json,0)); - if ( (rates= jobj(json,(char *)"rates")) != 0 && (n= cJSON_GetArraySize(rates)) > 0 ) + if ( (rates= jobj(json,(char *)"rates")) != 0 ) { - for (i=0; i Date: Fri, 29 Mar 2019 04:15:58 -1100 Subject: [PATCH 43/86] Test --- src/komodo_gateway.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 719b3894e..0c0e9314f 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1858,7 +1858,7 @@ uint32_t get_dailyfx() { for (i=0; i Date: Fri, 29 Mar 2019 22:54:27 +0700 Subject: [PATCH 44/86] moving vertically also if block not fit game field on swap --- src/cc/games/tetris.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/cc/games/tetris.c b/src/cc/games/tetris.c index 711170b0d..a0fd0615c 100644 --- a/src/cc/games/tetris.c +++ b/src/cc/games/tetris.c @@ -296,6 +296,7 @@ static void tg_hold(struct games_state *rs,tetris_game *obj) obj->stored.ori = ori; while (!tg_fits(obj, obj->falling)) { obj->falling.loc.row--; + obj->falling.loc.col--; } } tg_put(obj, obj->falling); From e1bfe06bf51cce1c2a4ff805eaefb04f57c2daf1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 29 Mar 2019 05:41:08 -1100 Subject: [PATCH 45/86] Cleanup --- src/komodo_gateway.h | 48 +++++++++++++++++++------------------------- 1 file changed, 21 insertions(+), 27 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 0c0e9314f..262e73ce0 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1804,19 +1804,21 @@ cJSON *send_curl(char *url,char *fname) // get_urljson just returns the JSON returned by the URL using issue_curl #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" }; -const char *Metals[] = { "XAU", "XAG", "XPT", "XPD", }; - -const char *Markets[] = { "DJIA", "SPX", "NDX", "VIX" }; - 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" }; +/* const char *Techstocks[] = { "AAPL","ADBE","ADSK","AKAM","AMD","AMZN","ATVI","BB","CDW","CRM","CSCO","CYBR","DBX","EA","FB","GDDY","GOOG","GRMN","GSAT","HPQ","IBM","INFY","INTC","INTU","JNPR","MSFT","MSI","MU","MXL","NATI","NCR","NFLX","NTAP","NVDA","ORCL","PANW","PYPL","QCOM","RHT","S","SHOP","SNAP","SPOT","SYMC","SYNA","T","TRIP","TWTR","TXN","VMW","VOD","VRSN","VZ","WDC","XRX","YELP","YNDX","ZEN" }; +const char *Metals[] = { "XAU", "XAG", "XPT", "XPD", }; + +const char *Markets[] = { "DJIA", "SPX", "NDX", "VIX" }; +*/ cJSON *get_urljson(char *url) { @@ -1847,10 +1849,10 @@ uint32_t get_stockprice(const char *symbol) return(price); } -uint32_t get_dailyfx() +uint32_t get_dailyfx(uint32_t *prices) { //{"base":"USD","rates":{"BGN":1.74344803,"NZD":1.471652701,"ILS":3.6329113924,"RUB":65.1997682296,"CAD":1.3430201462,"USD":1.0,"PHP":52.8641469068,"CHF":0.9970582992,"AUD":1.4129078267,"JPY":110.6792654662,"TRY":5.6523444464,"HKD":7.8499732573,"MYR":4.0824567659,"HRK":6.6232840078,"CZK":22.9862720628,"IDR":14267.4986628633,"DKK":6.6551078624,"NOK":8.6806917454,"HUF":285.131039401,"GBP":0.7626582278,"MXN":19.4183455161,"THB":31.8702085933,"ISK":122.5708682475,"ZAR":14.7033339276,"BRL":3.9750401141,"SGD":1.3573720806,"PLN":3.8286682118,"INR":69.33187734,"KRW":1139.1602781244,"RON":4.2423783206,"CNY":6.7387234801,"SEK":9.3385630237,"EUR":0.8914244963},"date":"2019-03-28"} - char url[512],*datestr; cJSON *json,*rates; int32_t i,n; uint32_t datenum=0,price = 0; + char url[512],*datestr; cJSON *json,*rates; int32_t i; uint32_t datenum=0,price = 0; sprintf(url,"https://api.openrates.io/latest?base=USD"); if ( (json= send_curl(url,(char *)"dailyfx")) != 0 ) { @@ -1858,13 +1860,14 @@ uint32_t get_dailyfx() { for (i=0; i Date: Fri, 29 Mar 2019 06:05:13 -1100 Subject: [PATCH 46/86] Test --- src/komodo_gateway.h | 71 ++++++++++++++++++++++++++++++-------------- 1 file changed, 48 insertions(+), 23 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 262e73ce0..e1a32ea05 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1565,7 +1565,7 @@ int32_t komodo_heightpricebits(uint32_t prevbits[4],int32_t nHeight) GetOpReturnData(tx.vout[numvouts-1].scriptPubKey,vopret); if ( vopret.size() >= PRICES_SIZEBIT0 ) { - memcpy(prevbits,&vopret[0],PRICES_SIZEBIT0); + memcpy(prevbits,vopret.data(),vopret.size()); return(0); } } @@ -1598,21 +1598,21 @@ uint32_t komodo_pricenew(int32_t *maxflagp,uint32_t price,uint32_t refprice,int6 } // komodo_pricecmp() returns -1 if any of the prices are beyond the tolerance -int32_t komodo_pricecmp(int32_t *maxflagp,uint32_t pricebitsA[4],uint32_t pricebitsB[4],int64_t tolerance) +int32_t komodo_pricecmp(int32_t n,int32_t *maxflagp,uint32_t *pricebitsA,uint32_t *pricebitsB,int64_t tolerance) { int32_t i; *maxflagp = 0; - for (i=1; i<4; i++) + for (i=1; i= PRICES_SIZEBIT0 ) { if ( komodo_heightpricebits(prevbits,nHeight-1) == 0 ) { - memcpy(pricebits,Mineropret.data(),PRICES_SIZEBIT0); - if ( komodo_pricecmp(&maxflag,pricebits,prevbits,PRICES_MAXCHANGE) < 0 ) + memcpy(pricebits,Mineropret.data(),Mineropret.size()); + n = (int32_t)(Mineropret.size() / sizeof(uint32_t)); + if ( komodo_pricecmp(n,&maxflag,pricebits,prevbits,Mineropret.size()) < 0 ) { // if the new prices are not within tolerance, update Mineropret with clipped prices - komodo_priceclamp(pricebits,prevbits,PRICES_MAXCHANGE); + komodo_priceclamp(n,pricebits,prevbits,PRICES_MAXCHANGE); fprintf(stderr,"update Mineropret to clamped prices\n"); - memcpy(Mineropret.data(),pricebits,PRICES_SIZEBIT0); + memcpy(Mineropret.data(),pricebits,Mineropret.size()); } } + int32_t i; + for (i=0; i vopret; uint32_t localbits[4],pricebits[4],prevbits[4],newprice; int32_t i,lag,lag2,maxflag=0; + std::vector vopret; uint32_t localbits[8192],pricebits[8192],prevbits[8192],newprice; int32_t i,lag,lag2,n,maxflag=0; if ( ASSETCHAINS_CBOPRET != 0 ) { GetOpReturnData(scriptPubKey,vopret); if ( vopret.size() >= PRICES_SIZEBIT0 ) { - memcpy(pricebits,&vopret[0],PRICES_SIZEBIT0); + n = (int32_t)(vopret.size() / sizeof(uint32_t)); + memcpy(pricebits,vopret.data(),Mineropret.size()); lag = (int32_t)(time(NULL) - pricebits[0]); if ( lag < 0 ) lag = -lag; @@ -1671,21 +1677,21 @@ int32_t komodo_opretvalidate(int32_t nHeight,CScript scriptPubKey) { if ( komodo_heightpricebits(prevbits,nHeight-1) == 0 ) { - if ( komodo_pricecmp(&maxflag,pricebits,prevbits,PRICES_MAXCHANGE) < 0 ) + if ( komodo_pricecmp(n,&maxflag,pricebits,prevbits,PRICES_MAXCHANGE) < 0 ) return(-1); } else return(-1); } if ( lag < ASSETCHAINS_BLOCKTIME && Mineropret.size() >= PRICES_SIZEBIT0 ) { - memcpy(localbits,Mineropret.data(),PRICES_SIZEBIT0); + memcpy(localbits,Mineropret.data(),Mineropret.size()); if ( maxflag == 0 ) { - if ( komodo_pricecmp(&maxflag,localbits,prevbits,PRICES_MAXCHANGE) < 0 ) + if ( komodo_pricecmp(n,&maxflag,localbits,prevbits,PRICES_MAXCHANGE) < 0 ) return(-1); } else { - for (i=1; i<4; i++) + for (i=1; i Date: Fri, 29 Mar 2019 06:11:08 -1100 Subject: [PATCH 47/86] Test --- src/komodo_utils.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_utils.h b/src/komodo_utils.h index a91dae1e8..44b1192a4 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -2067,7 +2067,7 @@ void komodo_args(char *argv0) if ( ASSETCHAINS_CBOPRET != 0 ) { extralen += iguana_rwnum(1,&extraptr[extralen],sizeof(ASSETCHAINS_CBOPRET),(void *)&ASSETCHAINS_CBOPRET); - komodo_cbopretupdate(); // will set Mineropret + //komodo_cbopretupdate(); // will set Mineropret fprintf(stderr,"This blockchain uses data produced from CoinDesk Bitcoin Price Index\n"); } } From 2b8eac7ca17485a2581fbefdf90093fb0dccdbc1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 29 Mar 2019 06:14:33 -1100 Subject: [PATCH 48/86] Test --- 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 e1a32ea05..271362c4b 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1985,9 +1985,9 @@ void komodo_cbopretupdate() if ( get_btcusd(pricebits) == 0 ) { memcpy(Mineropret.data(),pricebits,PRICES_SIZEBIT0); - //int32_t i; for (i=0; i Date: Sat, 30 Mar 2019 00:15:48 +0700 Subject: [PATCH 49/86] fixing fit from both ends --- src/cc/games/tetris.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/cc/games/tetris.c b/src/cc/games/tetris.c index a0fd0615c..8e7642837 100644 --- a/src/cc/games/tetris.c +++ b/src/cc/games/tetris.c @@ -296,7 +296,14 @@ static void tg_hold(struct games_state *rs,tetris_game *obj) obj->stored.ori = ori; while (!tg_fits(obj, obj->falling)) { obj->falling.loc.row--; + if (tg_fits(obj, obj->falling)) { + break; + } obj->falling.loc.col--; + if (tg_fits(obj, obj->falling)) { + break; + } + obj->falling.loc.col += 2; } } tg_put(obj, obj->falling); From b7cf1a57e9ae788fad86cc1e31e736072895e6fb Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 29 Mar 2019 06:17:03 -1100 Subject: [PATCH 50/86] 333 --- src/komodo_gateway.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 271362c4b..c71f7c4f2 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1974,6 +1974,8 @@ void komodo_cbopretupdate() int32_t size; if ( (ASSETCHAINS_CBOPRET & 1) != 0 ) { + if ( komodo_nextheight() > 333 ) + ASSETCHAINS_CBOPRET = 7; size = PRICES_SIZEBIT0; if ( (ASSETCHAINS_CBOPRET & 2) != 0 ) size += sizeof(forexprices); From 3b4a6191f9759df2bd440f257f9c3636830e0f02 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 29 Mar 2019 06:19:33 -1100 Subject: [PATCH 51/86] Test --- 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 c71f7c4f2..0612caa80 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1987,9 +1987,6 @@ void komodo_cbopretupdate() if ( get_btcusd(pricebits) == 0 ) { memcpy(Mineropret.data(),pricebits,PRICES_SIZEBIT0); - int32_t i; for (i=0; i Date: Fri, 29 Mar 2019 06:38:55 -1100 Subject: [PATCH 52/86] Test --- src/komodo_gateway.h | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 0612caa80..fbdda445c 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1603,8 +1603,13 @@ int32_t komodo_pricecmp(int32_t n,int32_t *maxflagp,uint32_t *pricebitsA,uint32_ int32_t i; *maxflagp = 0; for (i=1; i %u out of tolerance maxflag.%d\n",i,pricebitsB[i],pricebitsA[i],*maxflagp); return(-1); + } + } return(0); } @@ -1697,6 +1702,7 @@ int32_t komodo_opretvalidate(int32_t nHeight,CScript scriptPubKey) if ( (newprice= komodo_pricenew(&maxflag,pricebits[i],prevbits[i],PRICES_MAXCHANGE)) != 0 ) // proposed price is clamped { // make sure local price is beyond clamped + fprintf(stderr,"maxflag.%d i.%d localbits.%u vs pricebits.%u\n",maxflag,i,localbits[i],pricebits[i]); if ( maxflag > 0 && localbits[i] < pricebits[i] ) return(-1); else if ( maxflag < 0 && localbits[i] > pricebits[i] ) @@ -2003,9 +2009,9 @@ void komodo_cbopretupdate() memcpy(&Mineropret.data()[size],cryptoprices,sizeof(cryptoprices)); size += sizeof(cryptoprices); } - int32_t i; for (i=0; i Date: Fri, 29 Mar 2019 07:01:56 -1100 Subject: [PATCH 53/86] +prints --- src/komodo_gateway.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index fbdda445c..94d5928a9 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1584,12 +1584,14 @@ uint32_t komodo_pricenew(int32_t *maxflagp,uint32_t price,uint32_t refprice,int6 lowprice = ((uint64_t)refprice * (COIN - tolerance)) / COIN; // and lowest if ( price >= highprice ) { + fprintf(stderr,"high %u vs h%u l%u\n",price,highprice,lowprice); *maxflagp = 1; if ( price > highprice ) // return non-zero only if we violate the tolerance return(highprice); } else if ( price <= lowprice ) { + fprintf(stderr,"low %u vs h%u l%u\n",price,highprice,lowprice); *maxflagp = -1; if ( price < lowprice ) return(lowprice); @@ -1606,7 +1608,7 @@ int32_t komodo_pricecmp(int32_t n,int32_t *maxflagp,uint32_t *pricebitsA,uint32_ { if ( komodo_pricenew(maxflagp,pricebitsA[i],pricebitsB[i],tolerance) != 0 ) { - fprintf(stderr,"i.%d %u -> %u out of tolerance maxflag.%d\n",i,pricebitsB[i],pricebitsA[i],*maxflagp); + fprintf(stderr,"i.%d/%d %u -> %u out of tolerance maxflag.%d\n",i,n,pricebitsB[i],pricebitsA[i],*maxflagp); return(-1); } } @@ -1621,7 +1623,7 @@ int32_t komodo_priceclamp(int32_t n,uint32_t *pricebits,uint32_t *refprices,int6 { if ( (newprice= komodo_pricenew(&maxflag,pricebits[i],refprices[i],tolerance)) != 0 ) { - fprintf(stderr,"priceclamped[%d] %u -> %u\n",i,pricebits[i],newprice); + fprintf(stderr,"priceclamped[%d of %d] %u -> %u\n",i,n,pricebits[i],newprice); pricebits[i] = newprice; } } From 3af96cfe61f9492d23ea6bf2219ff6e93868f181 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 29 Mar 2019 07:03:48 -1100 Subject: [PATCH 54/86] Test --- src/komodo_gateway.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 94d5928a9..b60399329 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1602,13 +1602,13 @@ uint32_t komodo_pricenew(int32_t *maxflagp,uint32_t price,uint32_t refprice,int6 // komodo_pricecmp() returns -1 if any of the prices are beyond the tolerance int32_t komodo_pricecmp(int32_t n,int32_t *maxflagp,uint32_t *pricebitsA,uint32_t *pricebitsB,int64_t tolerance) { - int32_t i; + int32_t i; uint32_t newprice; *maxflagp = 0; for (i=1; i %u out of tolerance maxflag.%d\n",i,n,pricebitsB[i],pricebitsA[i],*maxflagp); + fprintf(stderr,"i.%d/%d %u vs %u -> newprice.%u out of tolerance maxflag.%d\n",i,n,pricebitsB[i],pricebitsA[i],newprice,*maxflagp); return(-1); } } @@ -1623,7 +1623,7 @@ int32_t komodo_priceclamp(int32_t n,uint32_t *pricebits,uint32_t *refprices,int6 { if ( (newprice= komodo_pricenew(&maxflag,pricebits[i],refprices[i],tolerance)) != 0 ) { - fprintf(stderr,"priceclamped[%d of %d] %u -> %u\n",i,n,pricebits[i],newprice); + fprintf(stderr,"priceclamped[%d of %d] %u vs %u -> %u\n",i,n,refprices[i],pricebits[i],newprice); pricebits[i] = newprice; } } From ec1c7ffcc7dd2535f9772ca7e5ba8862c02a1bc9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 29 Mar 2019 07:10:46 -1100 Subject: [PATCH 55/86] Int64 --- 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 b60399329..7a12f21bd 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1579,19 +1579,19 @@ int32_t komodo_heightpricebits(uint32_t prevbits[4],int32_t nHeight) */ uint32_t komodo_pricenew(int32_t *maxflagp,uint32_t price,uint32_t refprice,int64_t tolerance) { - uint32_t highprice,lowprice; + uint64_t highprice,lowprice; highprice = ((uint64_t)refprice * (COIN + tolerance)) / COIN; // calc highest acceptable price lowprice = ((uint64_t)refprice * (COIN - tolerance)) / COIN; // and lowest if ( price >= highprice ) { - fprintf(stderr,"high %u vs h%u l%u\n",price,highprice,lowprice); + fprintf(stderr,"high %u vs h%llu l%llu tolerance.%llu\n",price,(long long)highprice,(long long)lowprice,(long long)tolerance); *maxflagp = 1; if ( price > highprice ) // return non-zero only if we violate the tolerance return(highprice); } else if ( price <= lowprice ) { - fprintf(stderr,"low %u vs h%u l%u\n",price,highprice,lowprice); + fprintf(stderr,"low %u vs h%llu l%llu tolerance.%llu\n",price,(long long)highprice,(long long)lowprice,(long long)tolerance); *maxflagp = -1; if ( price < lowprice ) return(lowprice); From c12368a75c7fefe97453cfa2169ac02d88cf7a8f Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 29 Mar 2019 07:18:47 -1100 Subject: [PATCH 56/86] Print --- src/komodo_gateway.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 7a12f21bd..adf71c070 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1582,6 +1582,8 @@ uint32_t komodo_pricenew(int32_t *maxflagp,uint32_t price,uint32_t refprice,int6 uint64_t highprice,lowprice; highprice = ((uint64_t)refprice * (COIN + tolerance)) / COIN; // calc highest acceptable price lowprice = ((uint64_t)refprice * (COIN - tolerance)) / COIN; // and lowest + fprintf(stderr,"ref.%u * %llu -> %llu -> highprice %llu\n",refprice,(long long)(COIN+tolerance),(long long)((uint64_t)refprice * (COIN + tolerance)),(long long)highprice); + fprintf(stderr,"ref.%u * %llu -> %llu -> lowprice %llu\n",refprice,(long long)(COIN-tolerance),(long long)((uint64_t)refprice * (COIN - tolerance)),(long long)lowprice); if ( price >= highprice ) { fprintf(stderr,"high %u vs h%llu l%llu tolerance.%llu\n",price,(long long)highprice,(long long)lowprice,(long long)tolerance); From 5f9d3a95528174ef97161511dbda0ab407d6f27e Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 29 Mar 2019 07:27:33 -1100 Subject: [PATCH 57/86] Test --- src/komodo_gateway.h | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index adf71c070..6ef0739e9 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1635,14 +1635,24 @@ int32_t komodo_priceclamp(int32_t n,uint32_t *pricebits,uint32_t *refprices,int6 // komodo_mineropret() returns a valid pricedata to add to the coinbase opreturn for nHeight CScript komodo_mineropret(int32_t nHeight) { - CScript opret; uint32_t pricebits[8192],prevbits[8192]; int32_t maxflag,n; + CScript opret; uint32_t pricebits[8192],prevbits[8192]; int32_t maxflag,n,numzero=0; if ( Mineropret.size() >= PRICES_SIZEBIT0 ) { + n = (int32_t)(Mineropret.size() / sizeof(uint32_t)); + numzero = 1; + while ( numzero > 0 ) + { + memcpy(pricebits,Mineropret.data(),Mineropret.size()); + for (i=numzero=0; i Date: Fri, 29 Mar 2019 07:28:47 -1100 Subject: [PATCH 58/86] Test --- src/komodo_gateway.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 6ef0739e9..8400289ef 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1635,7 +1635,7 @@ int32_t komodo_priceclamp(int32_t n,uint32_t *pricebits,uint32_t *refprices,int6 // komodo_mineropret() returns a valid pricedata to add to the coinbase opreturn for nHeight CScript komodo_mineropret(int32_t nHeight) { - CScript opret; uint32_t pricebits[8192],prevbits[8192]; int32_t maxflag,n,numzero=0; + CScript opret; uint32_t pricebits[8192],prevbits[8192]; int32_t maxflag,i,n,numzero=0; if ( Mineropret.size() >= PRICES_SIZEBIT0 ) { n = (int32_t)(Mineropret.size() / sizeof(uint32_t)); From 92f0ec2616b71cf5fbbb4d5070e83e0ab961287c Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 29 Mar 2019 07:34:46 -1100 Subject: [PATCH 59/86] Make sure highprice and lowprice != refprice --- src/komodo_gateway.h | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 8400289ef..cb0bc761b 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1580,20 +1580,24 @@ int32_t komodo_heightpricebits(uint32_t prevbits[4],int32_t nHeight) uint32_t komodo_pricenew(int32_t *maxflagp,uint32_t price,uint32_t refprice,int64_t tolerance) { uint64_t highprice,lowprice; + if ( refprice < 2 ) + return(0); highprice = ((uint64_t)refprice * (COIN + tolerance)) / COIN; // calc highest acceptable price lowprice = ((uint64_t)refprice * (COIN - tolerance)) / COIN; // and lowest - fprintf(stderr,"ref.%u * %llu -> %llu -> highprice %llu\n",refprice,(long long)(COIN+tolerance),(long long)((uint64_t)refprice * (COIN + tolerance)),(long long)highprice); - fprintf(stderr,"ref.%u * %llu -> %llu -> lowprice %llu\n",refprice,(long long)(COIN-tolerance),(long long)((uint64_t)refprice * (COIN - tolerance)),(long long)lowprice); + if ( highprice == refprice ) + highprice++; + if ( lowprice == refprice ) + lowprice--; if ( price >= highprice ) { - fprintf(stderr,"high %u vs h%llu l%llu tolerance.%llu\n",price,(long long)highprice,(long long)lowprice,(long long)tolerance); + //fprintf(stderr,"high %u vs h%llu l%llu tolerance.%llu\n",price,(long long)highprice,(long long)lowprice,(long long)tolerance); *maxflagp = 1; if ( price > highprice ) // return non-zero only if we violate the tolerance return(highprice); } else if ( price <= lowprice ) { - fprintf(stderr,"low %u vs h%llu l%llu tolerance.%llu\n",price,(long long)highprice,(long long)lowprice,(long long)tolerance); + //fprintf(stderr,"low %u vs h%llu l%llu tolerance.%llu\n",price,(long long)highprice,(long long)lowprice,(long long)tolerance); *maxflagp = -1; if ( price < lowprice ) return(lowprice); From e955d862fb9e652e83865549a9f9732683a57150 Mon Sep 17 00:00:00 2001 From: "Anton \"TonyL\" Lysakov" Date: Sat, 30 Mar 2019 01:45:33 +0700 Subject: [PATCH 60/86] looking for keystrokes.log in the right place --- src/tui/lib/tuilib.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/tui/lib/tuilib.py b/src/tui/lib/tuilib.py index 9a2fed639..b46030af8 100755 --- a/src/tui/lib/tuilib.py +++ b/src/tui/lib/tuilib.py @@ -1952,10 +1952,10 @@ def find_game_keystrokes_in_log(gametxid): operating_system = platform.system() if operating_system == 'Win64' or operating_system == 'Windows': - p1 = subprocess.Popen(["type", "keystrokes.log"], stdout=subprocess.PIPE, shell=True) + p1 = subprocess.Popen(["type", "../keystrokes.log"], stdout=subprocess.PIPE, shell=True) p2 = subprocess.Popen(["findstr", gametxid], stdin=p1.stdout, stdout=subprocess.PIPE, shell=True) else: - p1 = subprocess.Popen(["cat", "keystrokes.log"], stdout=subprocess.PIPE) + p1 = subprocess.Popen(["cat", "../keystrokes.log"], stdout=subprocess.PIPE) p2 = subprocess.Popen(["grep", gametxid], stdin=p1.stdout, stdout=subprocess.PIPE) p1.stdout.close() output = p2.communicate()[0] From 6c9eb0e0f9c4836159d337bf0ff2f7bbdef16e28 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 29 Mar 2019 07:46:06 -1100 Subject: [PATCH 61/86] Dailyfx every 5 hours -> on average -> 2 hours ave delay --- src/komodo_gateway.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index cb0bc761b..94f85531a 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1993,7 +1993,7 @@ int32_t get_btcusd(uint32_t pricebits[4]) void komodo_cbopretupdate() { - static uint32_t counter; + static uint32_t lasttime; static uint32_t pricebits[4],cryptoprices[sizeof(Cryptos)/sizeof(*Cryptos)],forexprices[sizeof(Forex)/sizeof(*Forex)]; int32_t size; if ( (ASSETCHAINS_CBOPRET & 1) != 0 ) @@ -2014,10 +2014,11 @@ void komodo_cbopretupdate() } if ( (ASSETCHAINS_CBOPRET & 2) != 0 ) { - if ( (counter % 300) == 0 || forexprices[0] == 0 ) + if ( time(NULL) > lasttime+3600*5 || forexprices[0] == 0 ) { get_dailyfx(forexprices); memcpy(&Mineropret.data()[size],forexprices,sizeof(forexprices)); + lasttime = (uint32_t)time(NULL); } size += sizeof(forexprices); } From 6053dc843dbd4e9cd110fa8ac1201f43a63efee7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 29 Mar 2019 07:48:51 -1100 Subject: [PATCH 62/86] -counter --- src/komodo_gateway.h | 1 - 1 file changed, 1 deletion(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 94f85531a..43c9981f2 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -2045,5 +2045,4 @@ void komodo_cbopretupdate() get_stocks(Techstocks,(int32_t)(sizeof(Techstocks)/sizeof(*Techstocks))); }*/ } - counter++; } From 1976dcbfdb128ba924e437d3ef7a75fe3344e349 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 29 Mar 2019 07:55:23 -1100 Subject: [PATCH 63/86] test --- src/komodo_gateway.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 43c9981f2..16a64f86b 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1701,7 +1701,10 @@ int32_t komodo_opretvalidate(int32_t nHeight,CScript scriptPubKey) if ( komodo_heightpricebits(prevbits,nHeight-1) == 0 ) { if ( komodo_pricecmp(n,&maxflag,pricebits,prevbits,PRICES_MAXCHANGE) < 0 ) + { + fprintf(stderr,"vs prev maxflag.%d cmp error\n",maxflag); return(-1); + } } else return(-1); } if ( lag < ASSETCHAINS_BLOCKTIME && Mineropret.size() >= PRICES_SIZEBIT0 ) @@ -1710,7 +1713,10 @@ int32_t komodo_opretvalidate(int32_t nHeight,CScript scriptPubKey) if ( maxflag == 0 ) { if ( komodo_pricecmp(n,&maxflag,localbits,prevbits,PRICES_MAXCHANGE) < 0 ) + { + fprintf(stderr,"maxflag.0 cmp error\n"); return(-1); + } } else { From e24193c7a8774b9a5d911d89660499554c4b8c83 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 29 Mar 2019 07:59:47 -1100 Subject: [PATCH 64/86] Return 0 in all fall through cases for pricecmp --- src/komodo_gateway.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 16a64f86b..3614ec4cc 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1602,7 +1602,7 @@ uint32_t komodo_pricenew(int32_t *maxflagp,uint32_t price,uint32_t refprice,int6 if ( price < lowprice ) return(lowprice); } - else return(0); + return(0); } // komodo_pricecmp() returns -1 if any of the prices are beyond the tolerance From eb4c6419fd0da61ff3887fc779d11f48bd77dfc2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 29 Mar 2019 08:24:28 -1100 Subject: [PATCH 65/86] Edge case of no local prices yet --- src/komodo_gateway.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 3614ec4cc..bf07218eb 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1609,10 +1609,10 @@ uint32_t komodo_pricenew(int32_t *maxflagp,uint32_t price,uint32_t refprice,int6 int32_t komodo_pricecmp(int32_t n,int32_t *maxflagp,uint32_t *pricebitsA,uint32_t *pricebitsB,int64_t tolerance) { int32_t i; uint32_t newprice; - *maxflagp = 0; for (i=1; i newprice.%u out of tolerance maxflag.%d\n",i,n,pricebitsB[i],pricebitsA[i],newprice,*maxflagp); return(-1); @@ -1624,9 +1624,10 @@ int32_t komodo_pricecmp(int32_t n,int32_t *maxflagp,uint32_t *pricebitsA,uint32_ // 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,maxflag = 0; uint32_t newprice; + int32_t i,maxflag; uint32_t newprice; for (i=1; i %u\n",i,n,refprices[i],pricebits[i],newprice); From 78dd8ae93776ee9fcf5735977c282a2f7d39020b Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 29 Mar 2019 08:27:16 -1100 Subject: [PATCH 66/86] Only skip check if localbits is 0 --- src/komodo_gateway.h | 44 +++++++++++++++++++++++++------------------- 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index bf07218eb..26fbeda02 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1612,7 +1612,7 @@ int32_t komodo_pricecmp(int32_t n,int32_t *maxflagp,uint32_t *pricebitsA,uint32_ for (i=1; i newprice.%u out of tolerance maxflag.%d\n",i,n,pricebitsB[i],pricebitsA[i],newprice,*maxflagp); return(-1); @@ -1711,27 +1711,33 @@ int32_t komodo_opretvalidate(int32_t nHeight,CScript scriptPubKey) if ( lag < ASSETCHAINS_BLOCKTIME && Mineropret.size() >= PRICES_SIZEBIT0 ) { memcpy(localbits,Mineropret.data(),Mineropret.size()); - if ( maxflag == 0 ) + for (i=0; i 0 && localbits[i] < pricebits[i] ) - return(-1); - else if ( maxflag < 0 && localbits[i] > pricebits[i] ) - return(-1); + fprintf(stderr,"maxflag.0 cmp error\n"); + return(-1); + } + } + else + { + for (i=1; i 0 && localbits[i] < pricebits[i] ) + return(-1); + else if ( maxflag < 0 && localbits[i] > pricebits[i] ) + return(-1); + } } } } From 78564c9b3b3c02c8724239fa7c55be217fefbb0e Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 29 Mar 2019 08:28:21 -1100 Subject: [PATCH 67/86] Handle partial 0 --- src/komodo_gateway.h | 37 +++++++++++++++++-------------------- 1 file changed, 17 insertions(+), 20 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 26fbeda02..63c210d6a 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1713,31 +1713,28 @@ int32_t komodo_opretvalidate(int32_t nHeight,CScript scriptPubKey) memcpy(localbits,Mineropret.data(),Mineropret.size()); for (i=0; i 0 && localbits[i] < pricebits[i] ) - return(-1); - else if ( maxflag < 0 && localbits[i] > pricebits[i] ) - return(-1); - } + // make sure local price is beyond clamped + fprintf(stderr,"maxflag.%d i.%d localbits.%u vs pricebits.%u\n",maxflag,i,localbits[i],pricebits[i]); + if ( maxflag > 0 && localbits[i] < pricebits[i] ) + return(-1); + else if ( maxflag < 0 && localbits[i] > pricebits[i] ) + return(-1); } } } From 67352a31b59499e452c8564af14eda31850e2ac5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 29 Mar 2019 08:35:02 -1100 Subject: [PATCH 68/86] Fix --- src/komodo_gateway.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 63c210d6a..1306696f0 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1609,9 +1609,9 @@ uint32_t komodo_pricenew(int32_t *maxflagp,uint32_t price,uint32_t refprice,int6 int32_t komodo_pricecmp(int32_t n,int32_t *maxflagp,uint32_t *pricebitsA,uint32_t *pricebitsB,int64_t tolerance) { int32_t i; uint32_t newprice; + *maxflagp = 0; for (i=1; i newprice.%u out of tolerance maxflag.%d\n",i,n,pricebitsB[i],pricebitsA[i],newprice,*maxflagp); From 725ac7114718704719a807465add337d49919261 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 29 Mar 2019 08:52:12 -1100 Subject: [PATCH 69/86] +print --- src/komodo_gateway.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 1306696f0..225524eaf 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1590,14 +1590,14 @@ uint32_t komodo_pricenew(int32_t *maxflagp,uint32_t price,uint32_t refprice,int6 lowprice--; if ( price >= highprice ) { - //fprintf(stderr,"high %u vs h%llu l%llu tolerance.%llu\n",price,(long long)highprice,(long long)lowprice,(long long)tolerance); + fprintf(stderr,"high %u vs h%llu l%llu tolerance.%llu\n",price,(long long)highprice,(long long)lowprice,(long long)tolerance); *maxflagp = 1; if ( price > highprice ) // return non-zero only if we violate the tolerance return(highprice); } else if ( price <= lowprice ) { - //fprintf(stderr,"low %u vs h%llu l%llu tolerance.%llu\n",price,(long long)highprice,(long long)lowprice,(long long)tolerance); + fprintf(stderr,"low %u vs h%llu l%llu tolerance.%llu\n",price,(long long)highprice,(long long)lowprice,(long long)tolerance); *maxflagp = -1; if ( price < lowprice ) return(lowprice); @@ -1606,7 +1606,7 @@ uint32_t komodo_pricenew(int32_t *maxflagp,uint32_t price,uint32_t refprice,int6 } // komodo_pricecmp() returns -1 if any of the prices are beyond the tolerance -int32_t komodo_pricecmp(int32_t n,int32_t *maxflagp,uint32_t *pricebitsA,uint32_t *pricebitsB,int64_t tolerance) +int32_t komodo_pricecmp(int32_t nHeight,int32_t n,int32_t *maxflagp,uint32_t *pricebitsA,uint32_t *pricebitsB,int64_t tolerance) { int32_t i; uint32_t newprice; *maxflagp = 0; @@ -1614,7 +1614,7 @@ int32_t komodo_pricecmp(int32_t n,int32_t *maxflagp,uint32_t *pricebitsA,uint32_ { if ( (newprice= komodo_pricenew(maxflagp,pricebitsA[i],pricebitsB[i],tolerance)) != 0 ) { - fprintf(stderr,"i.%d/%d %u vs %u -> newprice.%u out of tolerance maxflag.%d\n",i,n,pricebitsB[i],pricebitsA[i],newprice,*maxflagp); + fprintf(stderr,"ht.%d i.%d/%d %u vs %u -> newprice.%u out of tolerance maxflag.%d\n",nHeight,i,n,pricebitsB[i],pricebitsA[i],newprice,*maxflagp); return(-1); } } @@ -1657,7 +1657,7 @@ CScript komodo_mineropret(int32_t nHeight) if ( komodo_heightpricebits(prevbits,nHeight-1) == 0 ) { memcpy(pricebits,Mineropret.data(),Mineropret.size()); - if ( komodo_pricecmp(n,&maxflag,pricebits,prevbits,PRICES_MAXCHANGE) < 0 ) + if ( komodo_pricecmp(0,n,&maxflag,pricebits,prevbits,PRICES_MAXCHANGE) < 0 ) { // if the new prices are not within tolerance, update Mineropret with clipped prices komodo_priceclamp(n,pricebits,prevbits,PRICES_MAXCHANGE); @@ -1701,7 +1701,7 @@ int32_t komodo_opretvalidate(int32_t nHeight,CScript scriptPubKey) { if ( komodo_heightpricebits(prevbits,nHeight-1) == 0 ) { - if ( komodo_pricecmp(n,&maxflag,pricebits,prevbits,PRICES_MAXCHANGE) < 0 ) + if ( komodo_pricecmp(nHeight,n,&maxflag,pricebits,prevbits,PRICES_MAXCHANGE) < 0 ) { fprintf(stderr,"vs prev maxflag.%d cmp error\n",maxflag); return(-1); @@ -1716,7 +1716,7 @@ int32_t komodo_opretvalidate(int32_t nHeight,CScript scriptPubKey) localbits[i] = prevbits[i]; if ( maxflag == 0 ) { - if ( komodo_pricecmp(n,&maxflag,localbits,prevbits,PRICES_MAXCHANGE) < 0 ) + if ( komodo_pricecmp(nHeight,n,&maxflag,localbits,prevbits,PRICES_MAXCHANGE) < 0 ) { fprintf(stderr,"maxflag.0 cmp error\n"); return(-1); From d605780e576e1f1952c8158cb693003a73559d26 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 29 Mar 2019 09:04:39 -1100 Subject: [PATCH 70/86] +print --- src/komodo_gateway.h | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 225524eaf..d82cb47e8 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1591,16 +1591,22 @@ uint32_t komodo_pricenew(int32_t *maxflagp,uint32_t price,uint32_t refprice,int6 if ( price >= highprice ) { fprintf(stderr,"high %u vs h%llu l%llu tolerance.%llu\n",price,(long long)highprice,(long long)lowprice,(long long)tolerance); - *maxflagp = 1; if ( price > highprice ) // return non-zero only if we violate the tolerance + { + *maxflagp = 2; return(highprice); + } + *maxflagp = 1; } else if ( price <= lowprice ) { fprintf(stderr,"low %u vs h%llu l%llu tolerance.%llu\n",price,(long long)highprice,(long long)lowprice,(long long)tolerance); - *maxflagp = -1; if ( price < lowprice ) + { + *maxflagp = -2; return(lowprice); + } + *maxflagp = -1; } return(0); } From d3ff021e338f09f7d7acd997df32d8621aedef10 Mon Sep 17 00:00:00 2001 From: "Anton \"TonyL\" Lysakov" Date: Sun, 31 Mar 2019 05:42:13 +0700 Subject: [PATCH 71/86] Update tuilib.py Discovered that `keystrokes.log` creating in folder from which game calling, not especially daemon folder. So before changed from correct to not correct :/ --- src/tui/lib/tuilib.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/tui/lib/tuilib.py b/src/tui/lib/tuilib.py index b46030af8..9a2fed639 100755 --- a/src/tui/lib/tuilib.py +++ b/src/tui/lib/tuilib.py @@ -1952,10 +1952,10 @@ def find_game_keystrokes_in_log(gametxid): operating_system = platform.system() if operating_system == 'Win64' or operating_system == 'Windows': - p1 = subprocess.Popen(["type", "../keystrokes.log"], stdout=subprocess.PIPE, shell=True) + p1 = subprocess.Popen(["type", "keystrokes.log"], stdout=subprocess.PIPE, shell=True) p2 = subprocess.Popen(["findstr", gametxid], stdin=p1.stdout, stdout=subprocess.PIPE, shell=True) else: - p1 = subprocess.Popen(["cat", "../keystrokes.log"], stdout=subprocess.PIPE) + p1 = subprocess.Popen(["cat", "keystrokes.log"], stdout=subprocess.PIPE) p2 = subprocess.Popen(["grep", gametxid], stdin=p1.stdout, stdout=subprocess.PIPE) p1.stdout.close() output = p2.communicate()[0] From b0edb6718cdd5528742537e9f8a8aff60338686f Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 31 Mar 2019 04:19:43 -1100 Subject: [PATCH 72/86] Fix cmp bug --- src/komodo_gateway.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index d82cb47e8..bec86a439 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1722,7 +1722,7 @@ int32_t komodo_opretvalidate(int32_t nHeight,CScript scriptPubKey) localbits[i] = prevbits[i]; if ( maxflag == 0 ) { - if ( komodo_pricecmp(nHeight,n,&maxflag,localbits,prevbits,PRICES_MAXCHANGE) < 0 ) + if ( komodo_pricecmp(nHeight,n,&maxflag,pricebits,localbits,PRICES_MAXCHANGE) < 0 ) { fprintf(stderr,"maxflag.0 cmp error\n"); return(-1); From c85b4db249d1c027be04e08744312d93caa82e07 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 31 Mar 2019 04:42:11 -1100 Subject: [PATCH 73/86] Test --- src/bitcoind.cpp | 2 +- src/komodo_gateway.h | 31 ++++++++++++++++++++----------- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/src/bitcoind.cpp b/src/bitcoind.cpp index 3c5cfe4d6..0afb47894 100644 --- a/src/bitcoind.cpp +++ b/src/bitcoind.cpp @@ -90,7 +90,7 @@ void WaitForShutdown(boost::thread_group* threadGroup) //komodo_longestchain(); if ( ASSETCHAINS_CBOPRET != 0 ) komodo_cbopretupdate(); - for (i=0; i vopret; uint32_t localbits[8192],pricebits[8192],prevbits[8192],newprice; int32_t i,lag,lag2,n,maxflag=0; + std::vector vopret; uint32_t localbits[8192],pricebits[8192],prevbits[8192],newprice; int32_t i,lag,lag2,n,maxflag=0; uint32_t now = (uint32_t)time(NULL); if ( ASSETCHAINS_CBOPRET != 0 ) { GetOpReturnData(scriptPubKey,vopret); @@ -1698,9 +1698,13 @@ int32_t komodo_opretvalidate(int32_t nHeight,CScript scriptPubKey) { n = (int32_t)(vopret.size() / sizeof(uint32_t)); memcpy(pricebits,vopret.data(),Mineropret.size()); - lag = (int32_t)(time(NULL) - pricebits[0]); + lag = (int32_t)(now - pricebits[0]); + if ( lag > 60 ) // blocks from future not so good to have + return(-1); if ( lag < 0 ) lag = -lag; + if ( lag > ASSETCHAINS_BLOCKTIME ) + return(-1); lag2 = (int32_t)(pricebits[0] - komodo_heightstamp(nHeight-1)); fprintf(stderr,"ht.%d: t%u lag.%d %.4f USD, %.4f GBP, %.4f EUR htstamp.%d [%d]\n",nHeight,pricebits[0],lag,(double)pricebits[1]/10000,(double)pricebits[2]/10000,(double)pricebits[3]/10000,komodo_heightstamp(nHeight-1),lag2); if ( nHeight > 1 ) @@ -1735,11 +1739,11 @@ int32_t komodo_opretvalidate(int32_t nHeight,CScript scriptPubKey) maxflag = 0; if ( (newprice= komodo_pricenew(&maxflag,pricebits[i],prevbits[i],PRICES_MAXCHANGE)) != 0 ) // proposed price is clamped { - // make sure local price is beyond clamped + // make sure local price is moving in right direction fprintf(stderr,"maxflag.%d i.%d localbits.%u vs pricebits.%u\n",maxflag,i,localbits[i],pricebits[i]); - if ( maxflag > 0 && localbits[i] < pricebits[i] ) + if ( maxflag > 0 && localbits[i] < prevbits[i] ) return(-1); - else if ( maxflag < 0 && localbits[i] > pricebits[i] ) + else if ( maxflag < 0 && localbits[i] > prevbits[i] ) return(-1); } } @@ -2009,9 +2013,9 @@ int32_t get_btcusd(uint32_t pricebits[4]) void komodo_cbopretupdate() { - static uint32_t lasttime; + static uint32_t lasttime,lastcrypto,lastbtc; static uint32_t pricebits[4],cryptoprices[sizeof(Cryptos)/sizeof(*Cryptos)],forexprices[sizeof(Forex)/sizeof(*Forex)]; - int32_t size; + int32_t size; uint32_t now = (uint32_t)time(NULL); if ( (ASSETCHAINS_CBOPRET & 1) != 0 ) { if ( komodo_nextheight() > 333 ) @@ -2024,13 +2028,14 @@ void komodo_cbopretupdate() if ( Mineropret.size() < size ) Mineropret.resize(size); size = PRICES_SIZEBIT0; - if ( get_btcusd(pricebits) == 0 ) + if ( now > lastbtc+30 && get_btcusd(pricebits) == 0 ) { memcpy(Mineropret.data(),pricebits,PRICES_SIZEBIT0); + lastbtc = (uint32_t)time(NULL); } if ( (ASSETCHAINS_CBOPRET & 2) != 0 ) { - if ( time(NULL) > lasttime+3600*5 || forexprices[0] == 0 ) + if ( now > lasttime+3600*5 || forexprices[0] == 0 ) { get_dailyfx(forexprices); memcpy(&Mineropret.data()[size],forexprices,sizeof(forexprices)); @@ -2040,8 +2045,12 @@ void komodo_cbopretupdate() } if ( (ASSETCHAINS_CBOPRET & 4) != 0 ) { - get_cryptoprices(cryptoprices,Cryptos,(int32_t)(sizeof(Cryptos)/sizeof(*Cryptos))); - memcpy(&Mineropret.data()[size],cryptoprices,sizeof(cryptoprices)); + if ( now > lastcrypto+60 ) + { + get_cryptoprices(cryptoprices,Cryptos,(int32_t)(sizeof(Cryptos)/sizeof(*Cryptos))); + memcpy(&Mineropret.data()[size],cryptoprices,sizeof(cryptoprices)); + lastcrypto = (uint32_t)time(NULL); + } size += sizeof(cryptoprices); } //int32_t i; for (i=0; i Date: Sun, 31 Mar 2019 04:50:02 -1100 Subject: [PATCH 74/86] Test --- src/komodo_gateway.h | 68 ++++++++++++++++++++++---------------------- 1 file changed, 34 insertions(+), 34 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 66fff3984..74ba9a779 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1698,17 +1698,17 @@ int32_t komodo_opretvalidate(int32_t nHeight,CScript scriptPubKey) { n = (int32_t)(vopret.size() / sizeof(uint32_t)); memcpy(pricebits,vopret.data(),Mineropret.size()); - lag = (int32_t)(now - pricebits[0]); - if ( lag > 60 ) // blocks from future not so good to have - return(-1); - if ( lag < 0 ) - lag = -lag; - if ( lag > ASSETCHAINS_BLOCKTIME ) - return(-1); - lag2 = (int32_t)(pricebits[0] - komodo_heightstamp(nHeight-1)); - fprintf(stderr,"ht.%d: t%u lag.%d %.4f USD, %.4f GBP, %.4f EUR htstamp.%d [%d]\n",nHeight,pricebits[0],lag,(double)pricebits[1]/10000,(double)pricebits[2]/10000,(double)pricebits[3]/10000,komodo_heightstamp(nHeight-1),lag2); if ( nHeight > 1 ) { + lag = (int32_t)(now - pricebits[0]); + if ( lag > 60 ) // blocks from future not so good to have + return(-1); + if ( lag < 0 ) + lag = -lag; + if ( lag > ASSETCHAINS_BLOCKTIME ) + return(-1); + lag2 = (int32_t)(pricebits[0] - komodo_heightstamp(nHeight-1)); + fprintf(stderr,"ht.%d: t%u lag.%d %.4f USD, %.4f GBP, %.4f EUR htstamp.%d [%d]\n",nHeight,pricebits[0],lag,(double)pricebits[1]/10000,(double)pricebits[2]/10000,(double)pricebits[3]/10000,komodo_heightstamp(nHeight-1),lag2); if ( komodo_heightpricebits(prevbits,nHeight-1) == 0 ) { if ( komodo_pricecmp(nHeight,n,&maxflag,pricebits,prevbits,PRICES_MAXCHANGE) < 0 ) @@ -1717,34 +1717,34 @@ int32_t komodo_opretvalidate(int32_t nHeight,CScript scriptPubKey) return(-1); } } else return(-1); - } - if ( lag < ASSETCHAINS_BLOCKTIME && Mineropret.size() >= PRICES_SIZEBIT0 ) - { - memcpy(localbits,Mineropret.data(),Mineropret.size()); - for (i=0; i= PRICES_SIZEBIT0 ) { - if ( komodo_pricecmp(nHeight,n,&maxflag,pricebits,localbits,PRICES_MAXCHANGE) < 0 ) + memcpy(localbits,Mineropret.data(),Mineropret.size()); + for (i=0; i 0 && localbits[i] < prevbits[i] ) - return(-1); - else if ( maxflag < 0 && localbits[i] > prevbits[i] ) - return(-1); + fprintf(stderr,"maxflag.0 cmp error\n"); + return(-1); + } + } + else + { + for (i=1; i 0 && localbits[i] < prevbits[i] ) + return(-1); + else if ( maxflag < 0 && localbits[i] > prevbits[i] ) + return(-1); + } } } } From eb23d9e3c46e858419b5d63820c5cdf3accfe6cd Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 31 Mar 2019 04:52:29 -1100 Subject: [PATCH 75/86] Fix lag calc --- src/komodo_gateway.h | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 74ba9a779..c8219fc08 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1701,12 +1701,18 @@ int32_t komodo_opretvalidate(int32_t nHeight,CScript scriptPubKey) if ( nHeight > 1 ) { lag = (int32_t)(now - pricebits[0]); - if ( lag > 60 ) // blocks from future not so good to have + if ( lag > ASSETCHAINS_BLOCKTIME ) + { + fprintf(stderr,"now.%u - pricebits[0] %u -> lag.%d\n",now,pricebits[0],lag); return(-1); + } if ( lag < 0 ) lag = -lag; - if ( lag > ASSETCHAINS_BLOCKTIME ) + if ( lag > 60 ) // avoid data from future + { + fprintf(stderr,"now.%u - pricebits[0] %u -> lag.%d\n",now,pricebits[0],lag); return(-1); + } lag2 = (int32_t)(pricebits[0] - komodo_heightstamp(nHeight-1)); fprintf(stderr,"ht.%d: t%u lag.%d %.4f USD, %.4f GBP, %.4f EUR htstamp.%d [%d]\n",nHeight,pricebits[0],lag,(double)pricebits[1]/10000,(double)pricebits[2]/10000,(double)pricebits[3]/10000,komodo_heightstamp(nHeight-1),lag2); if ( komodo_heightpricebits(prevbits,nHeight-1) == 0 ) From 275e78667c9c8957bf6f6f8eed9db845dd79bd73 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 31 Mar 2019 04:56:26 -1100 Subject: [PATCH 76/86] Use lag2 --- src/komodo_gateway.h | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index c8219fc08..f989594ff 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1701,19 +1701,19 @@ int32_t komodo_opretvalidate(int32_t nHeight,CScript scriptPubKey) if ( nHeight > 1 ) { lag = (int32_t)(now - pricebits[0]); - if ( lag > ASSETCHAINS_BLOCKTIME ) - { - fprintf(stderr,"now.%u - pricebits[0] %u -> lag.%d\n",now,pricebits[0],lag); - return(-1); - } if ( lag < 0 ) lag = -lag; - if ( lag > 60 ) // avoid data from future + lag2 = (int32_t)(komodo_heightstamp(nHeight-1) - pricebits[0]); + if ( lag2 > 60 ) { - fprintf(stderr,"now.%u - pricebits[0] %u -> lag.%d\n",now,pricebits[0],lag); + fprintf(stderr,"now.%u htstamp.%u - pricebits[0] %u -> lag.%d\n",now,komodo_heightstamp(nHeight-1),pricebits[0],lag2); + return(-1); + } + if ( lag2 < -ASSETCHAINS_BLOCKTIME-60 ) // avoid data from future + { + fprintf(stderr,"now.%u htstamp.%u - pricebits[0] %u -> lag.%d\n",now,komodo_heightstamp(nHeight-1),pricebits[0],lag2); return(-1); } - lag2 = (int32_t)(pricebits[0] - komodo_heightstamp(nHeight-1)); fprintf(stderr,"ht.%d: t%u lag.%d %.4f USD, %.4f GBP, %.4f EUR htstamp.%d [%d]\n",nHeight,pricebits[0],lag,(double)pricebits[1]/10000,(double)pricebits[2]/10000,(double)pricebits[3]/10000,komodo_heightstamp(nHeight-1),lag2); if ( komodo_heightpricebits(prevbits,nHeight-1) == 0 ) { From c171940c3f563ffe4cfa36477deda946869ab034 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 31 Mar 2019 05:00:04 -1100 Subject: [PATCH 77/86] Test --- src/komodo_gateway.h | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index f989594ff..e3ab02086 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1701,15 +1701,8 @@ int32_t komodo_opretvalidate(int32_t nHeight,CScript scriptPubKey) if ( nHeight > 1 ) { lag = (int32_t)(now - pricebits[0]); - if ( lag < 0 ) - lag = -lag; lag2 = (int32_t)(komodo_heightstamp(nHeight-1) - pricebits[0]); - if ( lag2 > 60 ) - { - fprintf(stderr,"now.%u htstamp.%u - pricebits[0] %u -> lag.%d\n",now,komodo_heightstamp(nHeight-1),pricebits[0],lag2); - return(-1); - } - if ( lag2 < -ASSETCHAINS_BLOCKTIME-60 ) // avoid data from future + if ( lag < -60 ) // avoid data from future { fprintf(stderr,"now.%u htstamp.%u - pricebits[0] %u -> lag.%d\n",now,komodo_heightstamp(nHeight-1),pricebits[0],lag2); return(-1); From 14943d68064c143acc7bcbb92c8a80eba1780579 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 31 Mar 2019 08:54:17 -1100 Subject: [PATCH 78/86] Test --- src/komodo_gateway.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index e3ab02086..64b11bafe 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1707,9 +1707,13 @@ int32_t komodo_opretvalidate(int32_t nHeight,CScript scriptPubKey) fprintf(stderr,"now.%u htstamp.%u - pricebits[0] %u -> lag.%d\n",now,komodo_heightstamp(nHeight-1),pricebits[0],lag2); return(-1); } + // else need to check against current blocktime to prevent pricebits[0] games fprintf(stderr,"ht.%d: t%u lag.%d %.4f USD, %.4f GBP, %.4f EUR htstamp.%d [%d]\n",nHeight,pricebits[0],lag,(double)pricebits[1]/10000,(double)pricebits[2]/10000,(double)pricebits[3]/10000,komodo_heightstamp(nHeight-1),lag2); if ( komodo_heightpricebits(prevbits,nHeight-1) == 0 ) { + for (i=1; i Date: Sun, 31 Mar 2019 08:56:54 -1100 Subject: [PATCH 79/86] Test --- src/komodo_gateway.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 64b11bafe..25dc6d0bd 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1711,6 +1711,9 @@ int32_t komodo_opretvalidate(int32_t nHeight,CScript scriptPubKey) fprintf(stderr,"ht.%d: t%u lag.%d %.4f USD, %.4f GBP, %.4f EUR htstamp.%d [%d]\n",nHeight,pricebits[0],lag,(double)pricebits[1]/10000,(double)pricebits[2]/10000,(double)pricebits[3]/10000,komodo_heightstamp(nHeight-1),lag2); if ( komodo_heightpricebits(prevbits,nHeight-1) == 0 ) { + for (i=1; i Date: Sun, 31 Mar 2019 09:03:21 -1100 Subject: [PATCH 80/86] Retry prev block error (most likely due to unfleshed data) --- src/komodo_gateway.h | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 25dc6d0bd..4e49d59d0 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1711,16 +1711,23 @@ int32_t komodo_opretvalidate(int32_t nHeight,CScript scriptPubKey) fprintf(stderr,"ht.%d: t%u lag.%d %.4f USD, %.4f GBP, %.4f EUR htstamp.%d [%d]\n",nHeight,pricebits[0],lag,(double)pricebits[1]/10000,(double)pricebits[2]/10000,(double)pricebits[3]/10000,komodo_heightstamp(nHeight-1),lag2); if ( komodo_heightpricebits(prevbits,nHeight-1) == 0 ) { - for (i=1; i= PRICES_SIZEBIT0 ) From 98977bb947924964ec1c0e5e1796d7c0fa8a4131 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 31 Mar 2019 09:24:02 -1100 Subject: [PATCH 81/86] Add some forex calc --- src/komodo_gateway.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 4e49d59d0..b7e1ec8f9 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1690,7 +1690,7 @@ CScript komodo_mineropret(int32_t nHeight) int32_t komodo_opretvalidate(int32_t nHeight,CScript scriptPubKey) { - std::vector vopret; uint32_t localbits[8192],pricebits[8192],prevbits[8192],newprice; int32_t i,lag,lag2,n,maxflag=0; uint32_t now = (uint32_t)time(NULL); + std::vector vopret; double btcusd,btcgbp,btceur; uint32_t localbits[8192],pricebits[8192],prevbits[8192],newprice; int32_t i,lag,lag2,n,maxflag=0; uint32_t now = (uint32_t)time(NULL); if ( ASSETCHAINS_CBOPRET != 0 ) { GetOpReturnData(scriptPubKey,vopret); @@ -1708,7 +1708,10 @@ int32_t komodo_opretvalidate(int32_t nHeight,CScript scriptPubKey) return(-1); } // else need to check against current blocktime to prevent pricebits[0] games - fprintf(stderr,"ht.%d: t%u lag.%d %.4f USD, %.4f GBP, %.4f EUR htstamp.%d [%d]\n",nHeight,pricebits[0],lag,(double)pricebits[1]/10000,(double)pricebits[2]/10000,(double)pricebits[3]/10000,komodo_heightstamp(nHeight-1),lag2); + btcusd = (double)pricebits[1]/10000; + btcgbp = (double)pricebits[2]/10000; + btceur = (double)pricebits[3]/10000; + fprintf(stderr,"ht.%d: t%u lag.%d %.4f USD, %.4f GBP, %.4f EUR, GBPUSD %.6f, EURUSD %.7f, EURGBP %.6f htstamp.%d [%d]\n",nHeight,pricebits[0],lag,btcusd,btcgbp,btceur,btcgbp/btcusd,btceur/btcusd,btceur/btcgbp,komodo_heightstamp(nHeight-1),lag2); if ( komodo_heightpricebits(prevbits,nHeight-1) == 0 ) { if ( komodo_pricecmp(nHeight,n,&maxflag,pricebits,prevbits,PRICES_MAXCHANGE) < 0 ) @@ -1720,6 +1723,7 @@ int32_t komodo_opretvalidate(int32_t nHeight,CScript scriptPubKey) fprintf(stderr,"%.4f ",(double)pricebits[i]/10000); fprintf(stderr," newprices.%d\n",nHeight); sleep(3); + memcpy(pricebits,vopret.data(),Mineropret.size()); if ( komodo_heightpricebits(prevbits,nHeight-1) == 0 ) { if ( komodo_pricecmp(nHeight,n,&maxflag,pricebits,prevbits,PRICES_MAXCHANGE) < 0 ) From 7a2cdcb8c57578e0fb441408c14fd820d09fd159 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 31 Mar 2019 09:24:52 -1100 Subject: [PATCH 82/86] -timestamp prints --- src/komodo_gateway.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index b7e1ec8f9..47d84e6df 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1711,7 +1711,7 @@ int32_t komodo_opretvalidate(int32_t nHeight,CScript scriptPubKey) btcusd = (double)pricebits[1]/10000; btcgbp = (double)pricebits[2]/10000; btceur = (double)pricebits[3]/10000; - fprintf(stderr,"ht.%d: t%u lag.%d %.4f USD, %.4f GBP, %.4f EUR, GBPUSD %.6f, EURUSD %.7f, EURGBP %.6f htstamp.%d [%d]\n",nHeight,pricebits[0],lag,btcusd,btcgbp,btceur,btcgbp/btcusd,btceur/btcusd,btceur/btcgbp,komodo_heightstamp(nHeight-1),lag2); + fprintf(stderr,"ht.%d: lag.%d %.4f USD, %.4f GBP, %.4f EUR, GBPUSD %.6f, EURUSD %.7f, EURGBP %.6f [%d]\n",nHeight,lag,btcusd,btcgbp,btceur,btcgbp/btcusd,btceur/btcusd,btceur/btcgbp,lag2); if ( komodo_heightpricebits(prevbits,nHeight-1) == 0 ) { if ( komodo_pricecmp(nHeight,n,&maxflag,pricebits,prevbits,PRICES_MAXCHANGE) < 0 ) From 9beb02477d82a8ab322204c45a83b7b85dc438e6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 31 Mar 2019 09:29:55 -1100 Subject: [PATCH 83/86] +prints --- src/komodo_gateway.h | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 47d84e6df..3995dadf1 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1711,7 +1711,7 @@ int32_t komodo_opretvalidate(int32_t nHeight,CScript scriptPubKey) btcusd = (double)pricebits[1]/10000; btcgbp = (double)pricebits[2]/10000; btceur = (double)pricebits[3]/10000; - fprintf(stderr,"ht.%d: lag.%d %.4f USD, %.4f GBP, %.4f EUR, GBPUSD %.6f, EURUSD %.7f, EURGBP %.6f [%d]\n",nHeight,lag,btcusd,btcgbp,btceur,btcgbp/btcusd,btceur/btcusd,btceur/btcgbp,lag2); + fprintf(stderr,"ht.%d: lag.%d %.4f USD, %.4f GBP, %.4f EUR, GBPUSD %.6f, EURUSD %.6f, EURGBP %.6f [%d]\n",nHeight,lag,btcusd,btcgbp,btceur,btcgbp/btcusd,btceur/btcusd,btceur/btcgbp,lag2); if ( komodo_heightpricebits(prevbits,nHeight-1) == 0 ) { if ( komodo_pricecmp(nHeight,n,&maxflag,pricebits,prevbits,PRICES_MAXCHANGE) < 0 ) @@ -1997,7 +1997,7 @@ int32_t get_stocks(const char *list[],int32_t n) int32_t get_btcusd(uint32_t pricebits[4]) { - cJSON *pjson,*bpi,*obj; char str[512]; uint64_t btcusd = 0,btcgbp = 0,btceur = 0; + cJSON *pjson,*bpi,*obj; char str[512]; double dbtcgbp,dbtcusd,dbtceur; uint64_t btcusd = 0,btcgbp = 0,btceur = 0; if ( (pjson= get_urljson((char *)"http://api.coindesk.com/v1/bpi/currentprice.json")) != 0 ) { if ( (bpi= jobj(pjson,(char *)"bpi")) != 0 ) @@ -2020,7 +2020,10 @@ int32_t get_btcusd(uint32_t pricebits[4]) } } free_json(pjson); - fprintf(stderr,"BTC/USD %.4f, BTC/GBP %.4f, BTC/EUR %.4f\n",dstr(btcusd),dstr(btcgbp),dstr(btceur)); + dbtcusd = (double)pricebits[1]/10000; + dbtcgbp = (double)pricebits[2]/10000; + dbtceur = (double)pricebits[3]/10000; + fprintf(stderr,"BTC/USD %.4f, BTC/GBP %.4f, BTC/EUR %.4f GBPUSD %.6f, EURUSD %.6f EURGBP %.6f\n",dbtcusd,dbtcgbp,dbtceur,dbtcgbp/dbtcusd,dbtceur/dbtcusd,dbtceur/dbtcgbp); return(0); } return(-1); From 8a520ea4399f415accc7e33bf9af5d4b9658f085 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 31 Mar 2019 09:32:33 -1100 Subject: [PATCH 84/86] Invert forex calc --- 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 3995dadf1..12a980d78 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1711,7 +1711,7 @@ int32_t komodo_opretvalidate(int32_t nHeight,CScript scriptPubKey) btcusd = (double)pricebits[1]/10000; btcgbp = (double)pricebits[2]/10000; btceur = (double)pricebits[3]/10000; - fprintf(stderr,"ht.%d: lag.%d %.4f USD, %.4f GBP, %.4f EUR, GBPUSD %.6f, EURUSD %.6f, EURGBP %.6f [%d]\n",nHeight,lag,btcusd,btcgbp,btceur,btcgbp/btcusd,btceur/btcusd,btceur/btcgbp,lag2); + fprintf(stderr,"ht.%d: lag.%d %.4f USD, %.4f GBP, %.4f EUR, GBPUSD %.6f, EURUSD %.6f, EURGBP %.6f [%d]\n",nHeight,lag,btcusd,btcgbp,btceur,btcusd/btcgbp,btcgbp/btceur,btcgbp/btceur,lag2); if ( komodo_heightpricebits(prevbits,nHeight-1) == 0 ) { if ( komodo_pricecmp(nHeight,n,&maxflag,pricebits,prevbits,PRICES_MAXCHANGE) < 0 ) @@ -2023,7 +2023,7 @@ int32_t get_btcusd(uint32_t pricebits[4]) dbtcusd = (double)pricebits[1]/10000; dbtcgbp = (double)pricebits[2]/10000; dbtceur = (double)pricebits[3]/10000; - fprintf(stderr,"BTC/USD %.4f, BTC/GBP %.4f, BTC/EUR %.4f GBPUSD %.6f, EURUSD %.6f EURGBP %.6f\n",dbtcusd,dbtcgbp,dbtceur,dbtcgbp/dbtcusd,dbtceur/dbtcusd,dbtceur/dbtcgbp); + fprintf(stderr,"BTC/USD %.4f, BTC/GBP %.4f, BTC/EUR %.4f GBPUSD %.6f, EURUSD %.6f EURGBP %.6f\n",dbtcusd,dbtcgbp,dbtceur,dbtcusd/dbtcgbp,dbtcgbp/dbtceur,dbtcgbp/dbtceur); return(0); } return(-1); From 3e48426eb56ad0dd748eef821ed7e2139086a4ad Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 31 Mar 2019 09:35:06 -1100 Subject: [PATCH 85/86] Fix eurusd --- 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 12a980d78..d04bb9fc4 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1711,7 +1711,7 @@ int32_t komodo_opretvalidate(int32_t nHeight,CScript scriptPubKey) btcusd = (double)pricebits[1]/10000; btcgbp = (double)pricebits[2]/10000; btceur = (double)pricebits[3]/10000; - fprintf(stderr,"ht.%d: lag.%d %.4f USD, %.4f GBP, %.4f EUR, GBPUSD %.6f, EURUSD %.6f, EURGBP %.6f [%d]\n",nHeight,lag,btcusd,btcgbp,btceur,btcusd/btcgbp,btcgbp/btceur,btcgbp/btceur,lag2); + fprintf(stderr,"ht.%d: lag.%d %.4f USD, %.4f GBP, %.4f EUR, GBPUSD %.6f, EURUSD %.6f, EURGBP %.6f [%d]\n",nHeight,lag,btcusd,btcgbp,btceur,btcusd/btcgbp,btcusd/btceur,btcgbp/btceur,lag2); if ( komodo_heightpricebits(prevbits,nHeight-1) == 0 ) { if ( komodo_pricecmp(nHeight,n,&maxflag,pricebits,prevbits,PRICES_MAXCHANGE) < 0 ) @@ -2023,7 +2023,7 @@ int32_t get_btcusd(uint32_t pricebits[4]) dbtcusd = (double)pricebits[1]/10000; dbtcgbp = (double)pricebits[2]/10000; dbtceur = (double)pricebits[3]/10000; - fprintf(stderr,"BTC/USD %.4f, BTC/GBP %.4f, BTC/EUR %.4f GBPUSD %.6f, EURUSD %.6f EURGBP %.6f\n",dbtcusd,dbtcgbp,dbtceur,dbtcusd/dbtcgbp,dbtcgbp/dbtceur,dbtcgbp/dbtceur); + fprintf(stderr,"BTC/USD %.4f, BTC/GBP %.4f, BTC/EUR %.4f GBPUSD %.6f, EURUSD %.6f EURGBP %.6f\n",dbtcusd,dbtcgbp,dbtceur,dbtcusd/dbtcgbp,dbtcusd/dbtceur,dbtcgbp/dbtceur); return(0); } return(-1); From b025dd2eaf8068b2068e09112dbbfab478197127 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 31 Mar 2019 09:43:53 -1100 Subject: [PATCH 86/86] Test --- src/komodo_gateway.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index d04bb9fc4..c1e5dcdcb 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1590,7 +1590,7 @@ uint32_t komodo_pricenew(int32_t *maxflagp,uint32_t price,uint32_t refprice,int6 lowprice--; if ( price >= highprice ) { - fprintf(stderr,"high %u vs h%llu l%llu tolerance.%llu\n",price,(long long)highprice,(long long)lowprice,(long long)tolerance); + //fprintf(stderr,"high %u vs h%llu l%llu tolerance.%llu\n",price,(long long)highprice,(long long)lowprice,(long long)tolerance); if ( price > highprice ) // return non-zero only if we violate the tolerance { *maxflagp = 2; @@ -1600,7 +1600,7 @@ uint32_t komodo_pricenew(int32_t *maxflagp,uint32_t price,uint32_t refprice,int6 } else if ( price <= lowprice ) { - fprintf(stderr,"low %u vs h%llu l%llu tolerance.%llu\n",price,(long long)highprice,(long long)lowprice,(long long)tolerance); + //fprintf(stderr,"low %u vs h%llu l%llu tolerance.%llu\n",price,(long long)highprice,(long long)lowprice,(long long)tolerance); if ( price < lowprice ) { *maxflagp = -2; @@ -2048,7 +2048,7 @@ void komodo_cbopretupdate() if ( Mineropret.size() < size ) Mineropret.resize(size); size = PRICES_SIZEBIT0; - if ( now > lastbtc+30 && get_btcusd(pricebits) == 0 ) + if ( now > lastbtc+120 && get_btcusd(pricebits) == 0 ) { memcpy(Mineropret.data(),pricebits,PRICES_SIZEBIT0); lastbtc = (uint32_t)time(NULL); @@ -2065,7 +2065,7 @@ void komodo_cbopretupdate() } if ( (ASSETCHAINS_CBOPRET & 4) != 0 ) { - if ( now > lastcrypto+60 ) + if ( now > lastcrypto+100 ) { get_cryptoprices(cryptoprices,Cryptos,(int32_t)(sizeof(Cryptos)/sizeof(*Cryptos))); memcpy(&Mineropret.data()[size],cryptoprices,sizeof(cryptoprices));