From da7b45d806d73f2de473547d75c72be9c01e36c2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 20 Jan 2018 21:00:39 +0200 Subject: [PATCH 001/183] New JUMBLR and REVS pricing --- iguana/exchanges/prices/autoprice | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/iguana/exchanges/prices/autoprice b/iguana/exchanges/prices/autoprice index 4536e16e9..1a82532f6 100755 --- a/iguana/exchanges/prices/autoprice +++ b/iguana/exchanges/prices/autoprice @@ -15,8 +15,8 @@ curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\ source crypto source trackbtc -source jumblr -source trackbtc +#source jumblr +#source trackbtc source pangea source trackbtc @@ -24,8 +24,8 @@ source trackbtc source bet source trackbtc -source revs -source trackbtc +#source revs +#source trackbtc sharkholdings="{\"coin\":\"iota\",\"balance\":1500000}, {\"coin\":\"bitcoin-cash\",\"balance\":1200}, {\"coin\":\"bitcoin\",\"balance\":145}" curl --url "http://127.0.0.1:7783" --data "{\"base\":\"MSHARK\",\"rel\":\"KMD\",\"fundvalue_bid\":\"NAV_KMD\",\"fundvalue_ask\":\"assetNAV_KMD\",\"userpass\":\"$userpass\",\"method\":\"autoprice\",\"margin\":$margin,\"address\":\"RTu3JZZKLJTcfNwBa19dWRagEfQq49STqC\",\"holdings\":[$sharkholdings],\"divisor\":1400000}" @@ -40,4 +40,8 @@ curl --url "http://127.0.0.1:7783" --data "{\"base\":\"DEX\",\"rel\":\"KMD\",\"m curl --url "http://127.0.0.1:7783" --data "{\"base\":\"BOTS\",\"rel\":\"KMD\",\"margin\":$margin,\"fundvalue_bid\":\"assetNAV_KMD\",\"fundvalue_ask\":\"assetNAV_KMD\",\"userpass\":\"$userpass\",\"method\":\"autoprice\",\"address\":\"RNdqHx26GWy9bk8MtmH1UiXjQcXE4RKK2P\",\"holdings\":[$dexholdings],\"divisor\":3333333}" -curl --url "http://127.0.0.1:7783" --data "{\"base\":\"MGW\",\"rel\":\"KMD\",\"margin\":$margin,\"fundvalue_bid\":\"assetNAV_KMD\",\"fundvalue_ask\":\"assetNAV_KMD\",\"userpass\":\"$userpass\",\"method\":\"autoprice\",\"holdings\":[$dexholdings],\"divisor\":10000000}" +curl --url "http://127.0.0.1:7783" --data "{\"base\":\"JUMBLR\",\"rel\":\"KMD\",\"margin\":$margin,\"fundvalue_bid\":\"assetNAV_KMD\",\"fundvalue_ask\":\"assetNAV_KMD\",\"userpass\":\"$userpass\",\"method\":\"autoprice\",\"address\":\"RGhxXpXSSBTBm9EvNsXnTQczthMCxHX91t\",\"holdings\":[$dexholdings],\"divisor\":3333333}" + +curl --url "http://127.0.0.1:7783" --data "{\"base\":\"MGW\",\"rel\":\"KMD\",\"margin\":$margin,\"fundvalue_bid\":\"assetNAV_KMD\",\"fundvalue_ask\":\"assetNAV_KMD\",\"userpass\":\"$userpass\",\"method\":\"autoprice\",\"holdings\":[$dexholdings],\"divisor\":13000000}" + +curl --url "http://127.0.0.1:7783" --data "{\"base\":\"REVS\",\"rel\":\"KMD\",\"margin\":$margin,\"fundvalue_bid\":\"assetNAV_KMD\",\"fundvalue_ask\":\"assetNAV_KMD\",\"userpass\":\"$userpass\",\"method\":\"autoprice\",\"holdings\":[$dexholdings],\"divisor\":9000000}" From 69dc26ab2ff55a11c15cf248c3247d6ac85280db Mon Sep 17 00:00:00 2001 From: DeckerSU Date: Sun, 21 Jan 2018 04:01:19 +0300 Subject: [PATCH 002/183] Fix Windows build. Add groestl.c to MSVC project. --- marketmaker.vcxproj | 1 + marketmaker.vcxproj.filters | 3 +++ 2 files changed, 4 insertions(+) diff --git a/marketmaker.vcxproj b/marketmaker.vcxproj index 26e11409a..fbe023dc8 100644 --- a/marketmaker.vcxproj +++ b/marketmaker.vcxproj @@ -248,6 +248,7 @@ + diff --git a/marketmaker.vcxproj.filters b/marketmaker.vcxproj.filters index 59cf37d99..36d2bdfe0 100644 --- a/marketmaker.vcxproj.filters +++ b/marketmaker.vcxproj.filters @@ -293,6 +293,9 @@ Source Files + + Source Files + From 35a43c3a37f85632a92b1ce17744554dc739be54 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 21 Jan 2018 11:53:02 +0200 Subject: [PATCH 003/183] Test --- iguana/exchanges/LP_bitcoin.c | 1 + 1 file changed, 1 insertion(+) diff --git a/iguana/exchanges/LP_bitcoin.c b/iguana/exchanges/LP_bitcoin.c index 4ddcda058..4b380cd4b 100644 --- a/iguana/exchanges/LP_bitcoin.c +++ b/iguana/exchanges/LP_bitcoin.c @@ -2093,6 +2093,7 @@ int32_t bitcoin_addr2rmd160(char *symbol,uint8_t taddr,uint8_t *addrtypep,uint8_ for (i=0; i Date: Sun, 21 Jan 2018 11:53:28 +0200 Subject: [PATCH 004/183] Test --- iguana/exchanges/LP_bitcoin.c | 1 - 1 file changed, 1 deletion(-) diff --git a/iguana/exchanges/LP_bitcoin.c b/iguana/exchanges/LP_bitcoin.c index 4b380cd4b..4ddcda058 100644 --- a/iguana/exchanges/LP_bitcoin.c +++ b/iguana/exchanges/LP_bitcoin.c @@ -2093,7 +2093,6 @@ int32_t bitcoin_addr2rmd160(char *symbol,uint8_t taddr,uint8_t *addrtypep,uint8_ for (i=0; i Date: Sun, 21 Jan 2018 11:56:10 +0200 Subject: [PATCH 005/183] Test --- iguana/exchanges/LP_bitcoin.c | 1 + 1 file changed, 1 insertion(+) diff --git a/iguana/exchanges/LP_bitcoin.c b/iguana/exchanges/LP_bitcoin.c index 4ddcda058..4b380cd4b 100644 --- a/iguana/exchanges/LP_bitcoin.c +++ b/iguana/exchanges/LP_bitcoin.c @@ -2093,6 +2093,7 @@ int32_t bitcoin_addr2rmd160(char *symbol,uint8_t taddr,uint8_t *addrtypep,uint8_ for (i=0; i Date: Sun, 21 Jan 2018 11:56:28 +0200 Subject: [PATCH 006/183] Test --- iguana/exchanges/LP_bitcoin.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_bitcoin.c b/iguana/exchanges/LP_bitcoin.c index 4b380cd4b..192556e04 100644 --- a/iguana/exchanges/LP_bitcoin.c +++ b/iguana/exchanges/LP_bitcoin.c @@ -2093,7 +2093,7 @@ int32_t bitcoin_addr2rmd160(char *symbol,uint8_t taddr,uint8_t *addrtypep,uint8_ for (i=0; i Date: Sun, 21 Jan 2018 12:02:20 +0200 Subject: [PATCH 007/183] Test --- iguana/exchanges/LP_bitcoin.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_bitcoin.c b/iguana/exchanges/LP_bitcoin.c index 192556e04..4b380cd4b 100644 --- a/iguana/exchanges/LP_bitcoin.c +++ b/iguana/exchanges/LP_bitcoin.c @@ -2093,7 +2093,7 @@ int32_t bitcoin_addr2rmd160(char *symbol,uint8_t taddr,uint8_t *addrtypep,uint8_ for (i=0; i Date: Sun, 21 Jan 2018 12:12:06 +0200 Subject: [PATCH 008/183] Test --- iguana/exchanges/LP_utxo.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index 3cb2dcbb5..1bf47ebc2 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -635,7 +635,7 @@ cJSON *LP_balances(char *coinaddr) strcpy(address,coin->smartaddr); else { - bitcoin_addr2rmd160(coin->symbol,taddr,&addrtype,rmd160,coinaddr); + bitcoin_addr2rmd160("KMD",taddr,&addrtype,rmd160,coinaddr); bitcoin_address(coin->symbol,address,coin->taddr,coin->pubtype,rmd160,20); //printf("%s taddr.%d addrtype.%u %s -> %s [%c %c].%d\n",coin->symbol,taddr,addrtype,coinaddr,address,coinaddr[0],coinaddr[1],coinaddr[0] == 't' && (coinaddr[1] == '1' || coinaddr[1] == '3')); } From 0840857f3be7a2257597fa821e2e235dbaeaba7a Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 21 Jan 2018 12:15:51 +0200 Subject: [PATCH 009/183] Test --- iguana/exchanges/LP_bitcoin.c | 2 +- iguana/mini-gmp.c | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_bitcoin.c b/iguana/exchanges/LP_bitcoin.c index 4b380cd4b..db44549d0 100644 --- a/iguana/exchanges/LP_bitcoin.c +++ b/iguana/exchanges/LP_bitcoin.c @@ -2052,7 +2052,7 @@ bits256 bits256_calcaddrhash(char *symbol,uint8_t *serialized,int32_t len) int32_t bitcoin_addr2rmd160(char *symbol,uint8_t taddr,uint8_t *addrtypep,uint8_t rmd160[20],char *coinaddr) { bits256 hash; uint8_t *buf,_buf[26],data5[128],rmd21[21]; char prefixaddr[64],hrp[64]; int32_t len,len5,offset; - if ( strcmp(symbol,"BCH") == 0 && strlen(coinaddr) == 42 ) + if ( strcmp(symbol,"BCH") == 0 )//&& strlen(coinaddr) == 42 ) { strcpy(prefixaddr,"bitcoincash:"); strcat(prefixaddr,coinaddr); diff --git a/iguana/mini-gmp.c b/iguana/mini-gmp.c index f39c66f69..036b3abff 100644 --- a/iguana/mini-gmp.c +++ b/iguana/mini-gmp.c @@ -4386,6 +4386,8 @@ bits256 mpz_to_bits256(mpz_t bn) return(x); } +extern int32_t zeroval(); + int32_t bitcoin_base58decode(uint8_t *data,char *coinaddr) { uint32_t zeroes,be_sz=0; size_t count; const char *p,*p1; mpz_t bn58,bn; int32_t nonz=0; @@ -4404,6 +4406,7 @@ int32_t bitcoin_base58decode(uint8_t *data,char *coinaddr) { printf("bitcoin_base58decode error: p %02x != 0x00\n",*p); mpz_clear(bn), mpz_clear(bn58); + printf("death.%d\n",1/zeroval()); return(-1); } break; From 68bc05e007cc2ef9ead4c09e1ba84b29a9dc5da0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 21 Jan 2018 12:23:20 +0200 Subject: [PATCH 010/183] Test --- iguana/exchanges/LP_bitcoin.c | 1 - 1 file changed, 1 deletion(-) diff --git a/iguana/exchanges/LP_bitcoin.c b/iguana/exchanges/LP_bitcoin.c index db44549d0..ccebaf252 100644 --- a/iguana/exchanges/LP_bitcoin.c +++ b/iguana/exchanges/LP_bitcoin.c @@ -2093,7 +2093,6 @@ int32_t bitcoin_addr2rmd160(char *symbol,uint8_t taddr,uint8_t *addrtypep,uint8_ for (i=0; i Date: Sun, 21 Jan 2018 12:41:00 +0200 Subject: [PATCH 011/183] Test --- iguana/exchanges/LP_nativeDEX.c | 3 ++- iguana/mini-gmp.c | 3 --- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 8c6782259..cb4d80128 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -736,8 +736,9 @@ void bech32_tests() { //char *test = "an83characterlonghumanreadablepartthatcontainsthenumber1andtheexcludedcharactersbio1tt5tgs"; //char *test = "bitcoincash:qpm2qsznhks23z7629mms6s4cwef74vcwvy22gdx6a"; - char *test = "bitcoincash:qr95sy3j9xwd2ap32xkykttr4cvcu7as4y0qverfuy"; + //char *test = "bitcoincash:qr95sy3j9xwd2ap32xkykttr4cvcu7as4y0qverfuy"; //char *test = "prefix:x64nx6hz"; + char *test = "bitcoincash:pq4p38fll9uuh2mzkesqhmgt66du4u0zzy92jchqqa"; uint8_t data[82],data2[64],rmd160[21],addrtype; char rebuild[92],hrp[84]; int32_t data_len,data_len2; int32_t i; if ( bech32_decode(hrp,data,&data_len,test) == 0 ) { diff --git a/iguana/mini-gmp.c b/iguana/mini-gmp.c index 036b3abff..f39c66f69 100644 --- a/iguana/mini-gmp.c +++ b/iguana/mini-gmp.c @@ -4386,8 +4386,6 @@ bits256 mpz_to_bits256(mpz_t bn) return(x); } -extern int32_t zeroval(); - int32_t bitcoin_base58decode(uint8_t *data,char *coinaddr) { uint32_t zeroes,be_sz=0; size_t count; const char *p,*p1; mpz_t bn58,bn; int32_t nonz=0; @@ -4406,7 +4404,6 @@ int32_t bitcoin_base58decode(uint8_t *data,char *coinaddr) { printf("bitcoin_base58decode error: p %02x != 0x00\n",*p); mpz_clear(bn), mpz_clear(bn58); - printf("death.%d\n",1/zeroval()); return(-1); } break; From c9efb61e99b47deaac0f953f8da00a8217768de4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 21 Jan 2018 12:41:18 +0200 Subject: [PATCH 012/183] Test --- iguana/exchanges/LP_nativeDEX.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index cb4d80128..ad93b3be4 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -825,7 +825,7 @@ void LP_initcoins(void *ctx,int32_t pubsock,cJSON *coins) else LP_unspents_load(coin->symbol,coin->smartaddr); if ( coin->txfee == 0 && strcmp(coin->symbol,"BTC") != 0 ) coin->txfee = LP_MIN_TXFEE; - if ( 0 && strcmp(coin->symbol,"BCH") == 0 ) + if ( strcmp(coin->symbol,"BCH") == 0 ) { bech32_tests(); } From 89e8347f8097e11d21b2873a18bb90a36a50d0a6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 21 Jan 2018 12:44:33 +0200 Subject: [PATCH 013/183] Test --- iguana/exchanges/LP_nativeDEX.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index ad93b3be4..c768f0919 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -746,10 +746,12 @@ void bech32_tests() } else { - bitcoin_addr2rmd160("BCH",0,&addrtype,rmd160,"qr95sy3j9xwd2ap32xkykttr4cvcu7as4y0qverfuy"); + bitcoin_addr2rmd160("BCH",0,&addrtype,rmd160,"pq4p38fll9uuh2mzkesqhmgt66du4u0zzy92jchqqa"); + bitcoin_address("BTC",rebuild,0,5,rmd160,20); for (i=0; i<20; i++) printf("%02x",rmd160[i]); - printf("addr2rmd160 %d\n",addrtype); + printf("addr2rmd160 %d -> %s\n",addrtype,rebuild); + data_len2 = 0; if ( bech32_convert_bits(data2,&data_len2,8,data,data_len,5,0) == 0 ) printf("error converting data5\n"); From 6039944bc5f4eaa6c66f328a3eda8d40884a1e88 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 21 Jan 2018 12:46:43 +0200 Subject: [PATCH 014/183] Test --- iguana/exchanges/LP_bitcoin.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/iguana/exchanges/LP_bitcoin.c b/iguana/exchanges/LP_bitcoin.c index ccebaf252..79ea96189 100644 --- a/iguana/exchanges/LP_bitcoin.c +++ b/iguana/exchanges/LP_bitcoin.c @@ -2054,11 +2054,15 @@ int32_t bitcoin_addr2rmd160(char *symbol,uint8_t taddr,uint8_t *addrtypep,uint8_ bits256 hash; uint8_t *buf,_buf[26],data5[128],rmd21[21]; char prefixaddr[64],hrp[64]; int32_t len,len5,offset; if ( strcmp(symbol,"BCH") == 0 )//&& strlen(coinaddr) == 42 ) { - strcpy(prefixaddr,"bitcoincash:"); - strcat(prefixaddr,coinaddr); + char *bchprefix = "bitcoincash:"; + if ( strncmp(coinaddr,bchprefix,strlen(bchprefix)) != 0 ) + { + strcpy(prefixaddr,bchprefix); + strcat(prefixaddr,coinaddr); + } else strcpy(prefixaddr,coinaddr); if ( bech32_decode(hrp,data5,&len5,prefixaddr) == 0 ) { - printf("bitcoin_addr2rmd160 bech32_decode error.(%s)\n",coinaddr); + printf("bitcoin_addr2rmd160 bech32_decode error.(%s)\n",prefixaddr); return(0); } len = 0; From cb8c60e024e4eaed192006905cfe7994839d64bd Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 21 Jan 2018 12:49:10 +0200 Subject: [PATCH 015/183] Test --- iguana/exchanges/LP_nativeDEX.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index c768f0919..f8dd093ab 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -738,7 +738,7 @@ void bech32_tests() //char *test = "bitcoincash:qpm2qsznhks23z7629mms6s4cwef74vcwvy22gdx6a"; //char *test = "bitcoincash:qr95sy3j9xwd2ap32xkykttr4cvcu7as4y0qverfuy"; //char *test = "prefix:x64nx6hz"; - char *test = "bitcoincash:pq4p38fll9uuh2mzkesqhmgt66du4u0zzy92jchqqa"; + char *test = "bitcoincash:pq4p38fll9uuh2mzkesqhmgt66du4u0zzy92jchqqa"; // 35Xbnq3kLoNsjN67knFewiRc9fqewrCzMW uint8_t data[82],data2[64],rmd160[21],addrtype; char rebuild[92],hrp[84]; int32_t data_len,data_len2; int32_t i; if ( bech32_decode(hrp,data,&data_len,test) == 0 ) { @@ -758,10 +758,10 @@ void bech32_tests() for (i=0; i %d\n",data_len2); - bitcoin_addr2rmd160("BTC",0,&addrtype,rmd160+1,"1KXrWXciRDZUpQwQmuM1DbwsKDLYAYsVLR"); + bitcoin_addr2rmd160("BTC",0,&addrtype,rmd160+1,"35Xbnq3kLoNsjN67knFewiRc9fqewrCzMW"); for (i=0; i ",(int32_t)data_len,test,"1KXrWXciRDZUpQwQmuM1DbwsKDLYAYsVLR"); + printf(" datalen.%d <- %s (%s) -> ",(int32_t)data_len,test,"35Xbnq3kLoNsjN67knFewiRc9fqewrCzMW"); for (i=0; i<20; i++) printf("%02x",rmd160[i+1]); printf("\n"); From 6f45f448423531d7aa92f6580626f57491ce28f8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 21 Jan 2018 12:51:01 +0200 Subject: [PATCH 016/183] Test --- iguana/exchanges/LP_nativeDEX.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index f8dd093ab..e9c675955 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -767,7 +767,7 @@ void bech32_tests() printf("\n"); } data_len2 = 0; - rmd160[0] = (0 << 3); + rmd160[0] = (1 << 3); bech32_convert_bits(data2,&data_len2,5,rmd160,21,8,1); for (i=0; i Date: Sun, 21 Jan 2018 18:07:17 +0200 Subject: [PATCH 017/183] Test --- iguana/exchanges/LP_nativeDEX.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index e9c675955..995b3f91f 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -139,7 +139,7 @@ char LP_gui[16] = { "cli" }; char *default_LPnodes[] = { "5.9.253.195", "5.9.253.196", "5.9.253.197", "5.9.253.198", "5.9.253.199", "5.9.253.200", "5.9.253.201", "5.9.253.202", "5.9.253.203", //"24.54.206.138", "107.72.162.127", "72.50.16.86", "51.15.202.191", "173.228.198.88", - "51.15.203.171", "51.15.86.136", "51.15.94.249", "51.15.80.18", "51.15.91.40", "51.15.54.2", "51.15.86.31", "51.15.82.29", "51.15.89.155", "173.212.225.176", "136.243.45.140" + //"51.15.203.171", "51.15.86.136", "51.15.94.249", "51.15.80.18", "51.15.91.40", "51.15.54.2", "51.15.86.31", "51.15.82.29", "51.15.89.155", "173.212.225.176", "136.243.45.140" }; // stubs @@ -827,7 +827,7 @@ void LP_initcoins(void *ctx,int32_t pubsock,cJSON *coins) else LP_unspents_load(coin->symbol,coin->smartaddr); if ( coin->txfee == 0 && strcmp(coin->symbol,"BTC") != 0 ) coin->txfee = LP_MIN_TXFEE; - if ( strcmp(coin->symbol,"BCH") == 0 ) + if ( 0 && strcmp(coin->symbol,"BCH") == 0 ) { bech32_tests(); } From de1e497f20029e24b2c7cd57622b66ddee8bcfee Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 21 Jan 2018 18:14:37 +0200 Subject: [PATCH 018/183] Test --- iguana/exchanges/LP_peers.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_peers.c b/iguana/exchanges/LP_peers.c index 593046706..fc740832e 100644 --- a/iguana/exchanges/LP_peers.c +++ b/iguana/exchanges/LP_peers.c @@ -143,7 +143,7 @@ struct LP_peerinfo *LP_addpeer(struct LP_peerinfo *mypeer,int32_t mypubsock,char } else printf("%s pushport.%u subport.%u pushsock.%d\n",ipaddr,pushport,subport,pushsock); if ( peer->pushsock >= 0 && peer->subsock >= 0 ) { - //printf("add peer %s\n",peer->ipaddr); + printf("add peer %s isLP.%d\n",peer->ipaddr,peer->isLP); portable_mutex_lock(&LP_peermutex); HASH_ADD(hh,LP_peerinfos,ip_port,sizeof(peer->ip_port),peer); if ( mypeer != 0 ) From 04b1226fd28b9d5f743cbff45309b753911237c8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 21 Jan 2018 18:15:49 +0200 Subject: [PATCH 019/183] Test --- iguana/exchanges/LP_nativeDEX.c | 4 ++-- iguana/exchanges/LP_peers.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 995b3f91f..e379e7f25 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -860,7 +860,7 @@ void LP_initpeers(int32_t pubsock,struct LP_peerinfo *mypeer,char *myipaddr,uint { LP_addpeer(mypeer,pubsock,default_LPnodes[i],myport,pushport,subport,0,G.LP_sessionid); } - } else LP_addpeer(mypeer,pubsock,seednode,myport,pushport,subport,0,G.LP_sessionid); + } else LP_addpeer(mypeer,pubsock,seednode,myport,pushport,subport,1,G.LP_sessionid); } else { @@ -881,7 +881,7 @@ void LP_initpeers(int32_t pubsock,struct LP_peerinfo *mypeer,char *myipaddr,uint //issue_LP_getpeers(default_LPnodes[i],myport); //LP_peersquery(mypeer,pubsock,default_LPnodes[i],myport,"127.0.0.1",myport); } - } else LP_addpeer(mypeer,pubsock,seednode,myport,pushport,subport,0,G.LP_sessionid); + } else LP_addpeer(mypeer,pubsock,seednode,myport,pushport,subport,1,G.LP_sessionid); } } diff --git a/iguana/exchanges/LP_peers.c b/iguana/exchanges/LP_peers.c index fc740832e..a7d960c97 100644 --- a/iguana/exchanges/LP_peers.c +++ b/iguana/exchanges/LP_peers.c @@ -140,10 +140,10 @@ struct LP_peerinfo *LP_addpeer(struct LP_peerinfo *mypeer,int32_t mypubsock,char pushsock = -1; printf("error connecting to push.(%s)\n",pushaddr); } - } else printf("%s pushport.%u subport.%u pushsock.%d\n",ipaddr,pushport,subport,pushsock); + } else printf("%s pushport.%u subport.%u pushsock.%d isLP.%d\n",ipaddr,pushport,subport,pushsock,isLP); if ( peer->pushsock >= 0 && peer->subsock >= 0 ) { - printf("add peer %s isLP.%d\n",peer->ipaddr,peer->isLP); + //printf("add peer %s isLP.%d\n",peer->ipaddr,peer->isLP); portable_mutex_lock(&LP_peermutex); HASH_ADD(hh,LP_peerinfos,ip_port,sizeof(peer->ip_port),peer); if ( mypeer != 0 ) From 1c7308632c86df047964529d92f740a0335a8ed7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 21 Jan 2018 18:52:25 +0200 Subject: [PATCH 020/183] Test --- iguana/exchanges/LP_nativeDEX.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index e379e7f25..fb0827277 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -387,7 +387,7 @@ int32_t LP_sock_check(char *typestr,void *ctx,char *myipaddr,int32_t pubsock,int } else printf("couldnt decode linebuf[%d]\n",recvlen); } methodstr[0] = 0; - //printf("%s.(%s)\n",typestr,(char *)ptr); +printf("%s.(%s)\n",typestr,(char *)ptr); if ( recvjson != 0 ) { safecopy(LP_methodstr,jstr(recvjson,"method"),sizeof(LP_methodstr)); @@ -1095,7 +1095,7 @@ void LP_reserved_msgs(void *ignore) else if ( num_Reserved_msgs[0] > 0 ) { num_Reserved_msgs[0]--; -//printf("BROADCAST.(%s)\n",Reserved_msgs[0][num_Reserved_msgs[0]]); +printf("BROADCAST.(%s)\n",Reserved_msgs[0][num_Reserved_msgs[0]]); LP_broadcast_message(LP_mypubsock,"","",zero,Reserved_msgs[0][num_Reserved_msgs[0]]); Reserved_msgs[0][num_Reserved_msgs[0]] = 0; } From a678fa057ddbcf3ffa08190392833978e569131e Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 21 Jan 2018 18:57:03 +0200 Subject: [PATCH 021/183] Test --- iguana/exchanges/LP_nativeDEX.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index fb0827277..7427ca7f6 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -383,11 +383,10 @@ int32_t LP_sock_check(char *typestr,void *ctx,char *myipaddr,int32_t pubsock,int msg = decodestr; msglen = (int32_t)strlen(decodestr) + 1; } - //printf("decoded.(%s)\n",decodestr); + printf("decoded.(%s)\n",decodestr); } else printf("couldnt decode linebuf[%d]\n",recvlen); } methodstr[0] = 0; -printf("%s.(%s)\n",typestr,(char *)ptr); if ( recvjson != 0 ) { safecopy(LP_methodstr,jstr(recvjson,"method"),sizeof(LP_methodstr)); From 05fdc77e2bea10036a29cb58b35a01aec703030b Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 21 Jan 2018 19:05:46 +0200 Subject: [PATCH 022/183] Test --- iguana/exchanges/LP_nativeDEX.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 7427ca7f6..1ff5fa9d6 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -365,6 +365,7 @@ int32_t LP_sock_check(char *typestr,void *ctx,char *myipaddr,int32_t pubsock,int ptr = 0; if ( (recvlen= nn_recv(sock,&ptr,NN_MSG,0)) > 0 ) { + printf("nn_recv.%d\n",recvlen); decodestr = 0; if ( recvlen > 32768 ) { @@ -383,7 +384,7 @@ int32_t LP_sock_check(char *typestr,void *ctx,char *myipaddr,int32_t pubsock,int msg = decodestr; msglen = (int32_t)strlen(decodestr) + 1; } - printf("decoded.(%s)\n",decodestr); + //printf("decoded.(%s)\n",decodestr); } else printf("couldnt decode linebuf[%d]\n",recvlen); } methodstr[0] = 0; @@ -440,13 +441,13 @@ int32_t LP_sock_check(char *typestr,void *ctx,char *myipaddr,int32_t pubsock,int int32_t LP_nanomsg_recvs(void *ctx) { - int32_t nonz = 0; char *origipaddr; struct LP_peerinfo *peer,*tmp; + int32_t n=0,nonz = 0; char *origipaddr; struct LP_peerinfo *peer,*tmp; if ( (origipaddr= LP_myipaddr) == 0 ) origipaddr = "127.0.0.1"; //portable_mutex_lock(&LP_nanorecvsmutex); HASH_ITER(hh,LP_peerinfos,peer,tmp) { - if ( peer->errors >= LP_MAXPEER_ERRORS ) + if ( n++ > 0 && peer->errors >= LP_MAXPEER_ERRORS ) { if ( (LP_rand() % 10000) == 0 ) peer->errors--; From 06a3ed790d7feca5c669663ba9ec46df0dd98769 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 21 Jan 2018 19:13:42 +0200 Subject: [PATCH 023/183] Test --- iguana/exchanges/LP_nativeDEX.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 1ff5fa9d6..497007a34 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -998,11 +998,13 @@ void queue_loop(void *ctx) printf("%d LP_send mmjson sent %d instead of %d\n",n,sentbytes,k); else flag++; } + printf("k.%d SEND.(%s)\n",k,(char *)ptr->msg); } free_json(json); } if ( flag == 0 ) { + printf("len.%d SEND.(%s)\n",ptr->msglen,(char *)ptr->msg); if ( (sentbytes= nn_send(ptr->sock,ptr->msg,ptr->msglen,0)) != ptr->msglen ) printf("%d LP_send sent %d instead of %d\n",n,sentbytes,ptr->msglen); else flag++; From bceee0e274d226651a6400bebcd389deb503d6e8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 21 Jan 2018 19:24:47 +0200 Subject: [PATCH 024/183] Test --- iguana/exchanges/LP_nativeDEX.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 497007a34..9868bf7cd 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -457,8 +457,8 @@ int32_t LP_nanomsg_recvs(void *ctx) continue; } } - //printf("check %s pubsock.%d\n",peer->ipaddr,peer->subsock); - nonz += LP_sock_check("PULL",ctx,origipaddr,LP_mypubsock,peer->subsock,peer->ipaddr,1); + printf("check %s subsock.%d\n",peer->ipaddr,peer->subsock); + nonz += LP_sock_check("SUB",ctx,origipaddr,LP_mypubsock,peer->subsock,peer->ipaddr,1); } /*HASH_ITER(hh,LP_coins,coin,ctmp) // firstrefht,firstscanht,lastscanht { @@ -469,7 +469,8 @@ int32_t LP_nanomsg_recvs(void *ctx) }*/ if ( LP_mypullsock >= 0 ) { - nonz += LP_sock_check("SUB",ctx,origipaddr,-1,LP_mypullsock,"127.0.0.1",1); + printf("check %s pullsock.%d\n",peer->ipaddr,LP_mypullsock); + nonz += LP_sock_check("PULL",ctx,origipaddr,-1,LP_mypullsock,"127.0.0.1",1); } //portable_mutex_unlock(&LP_nanorecvsmutex); return(nonz); @@ -998,13 +999,13 @@ void queue_loop(void *ctx) printf("%d LP_send mmjson sent %d instead of %d\n",n,sentbytes,k); else flag++; } - printf("k.%d SEND.(%s)\n",k,(char *)ptr->msg); + printf("k.%d SEND.(%s) sock.%d\n",k,(char *)ptr->msg,ptr->sock); } free_json(json); } if ( flag == 0 ) { - printf("len.%d SEND.(%s)\n",ptr->msglen,(char *)ptr->msg); + printf("len.%d SEND.(%s) sock.%d\n",ptr->msglen,(char *)ptr->msg,ptr->sock); if ( (sentbytes= nn_send(ptr->sock,ptr->msg,ptr->msglen,0)) != ptr->msglen ) printf("%d LP_send sent %d instead of %d\n",n,sentbytes,ptr->msglen); else flag++; @@ -1256,7 +1257,7 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu nn_close(pubsock), pubsock = -1; } } else printf("error getting pubsock %d\n",pubsock); - printf(">>>>>>>>> myipaddr.(%s) (%s) pullsock.%d valid.%d\n",bindaddr,subaddr,pubsock,valid); + printf(">>>>>>>>> myipaddr.(%s) (%s) pullsock.%d valid.%d pubbindaddr.%s\n",bindaddr,subaddr,pubsock,valid,bindaddr); LP_mypubsock = pubsock; } printf("got %s, initpeers\n",myipaddr); From 52aa975540e7bc65e524c8080c1407ca4364c5ee Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 21 Jan 2018 19:47:18 +0200 Subject: [PATCH 025/183] Test --- iguana/exchanges/LP_nativeDEX.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 9868bf7cd..a2efcf95b 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -365,7 +365,7 @@ int32_t LP_sock_check(char *typestr,void *ctx,char *myipaddr,int32_t pubsock,int ptr = 0; if ( (recvlen= nn_recv(sock,&ptr,NN_MSG,0)) > 0 ) { - printf("nn_recv.%d\n",recvlen); + printf("%s nn_recv.%d\n",typestr,recvlen); decodestr = 0; if ( recvlen > 32768 ) { @@ -457,7 +457,6 @@ int32_t LP_nanomsg_recvs(void *ctx) continue; } } - printf("check %s subsock.%d\n",peer->ipaddr,peer->subsock); nonz += LP_sock_check("SUB",ctx,origipaddr,LP_mypubsock,peer->subsock,peer->ipaddr,1); } /*HASH_ITER(hh,LP_coins,coin,ctmp) // firstrefht,firstscanht,lastscanht @@ -469,7 +468,6 @@ int32_t LP_nanomsg_recvs(void *ctx) }*/ if ( LP_mypullsock >= 0 ) { - printf("check %s pullsock.%d\n",peer->ipaddr,LP_mypullsock); nonz += LP_sock_check("PULL",ctx,origipaddr,-1,LP_mypullsock,"127.0.0.1",1); } //portable_mutex_unlock(&LP_nanorecvsmutex); From 8b914a7ad5f986d8cf4dcc2d350fdc8f81d0d4f6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 21 Jan 2018 19:55:55 +0200 Subject: [PATCH 026/183] Test --- iguana/exchanges/LP_nativeDEX.c | 4 ++-- iguana/exchanges/LP_network.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index a2efcf95b..79d331e9d 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -1096,7 +1096,7 @@ void LP_reserved_msgs(void *ignore) else if ( num_Reserved_msgs[0] > 0 ) { num_Reserved_msgs[0]--; -printf("BROADCAST.(%s)\n",Reserved_msgs[0][num_Reserved_msgs[0]]); +//printf("BROADCAST.(%s)\n",Reserved_msgs[0][num_Reserved_msgs[0]]); LP_broadcast_message(LP_mypubsock,"","",zero,Reserved_msgs[0][num_Reserved_msgs[0]]); Reserved_msgs[0][num_Reserved_msgs[0]] = 0; } @@ -1255,7 +1255,7 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu nn_close(pubsock), pubsock = -1; } } else printf("error getting pubsock %d\n",pubsock); - printf(">>>>>>>>> myipaddr.(%s) (%s) pullsock.%d valid.%d pubbindaddr.%s\n",bindaddr,subaddr,pubsock,valid,bindaddr); + printf(">>>>>>>>> myipaddr.(%s) (%s) pullsock.%d valid.%d pubbindaddr.%s pubsock.%d\n",bindaddr,subaddr,pubsock,valid,bindaddr,pubsock); LP_mypubsock = pubsock; } printf("got %s, initpeers\n",myipaddr); diff --git a/iguana/exchanges/LP_network.c b/iguana/exchanges/LP_network.c index e3755aae6..049d7a59f 100644 --- a/iguana/exchanges/LP_network.c +++ b/iguana/exchanges/LP_network.c @@ -156,7 +156,7 @@ void _LP_sendqueueadd(uint32_t crc32,int32_t sock,uint8_t *msg,int32_t msglen,in memcpy(ptr->msg,msg,msglen); // sizeof(bits256) at the end all zeroes DL_APPEND(LP_Q,ptr); LP_Qenqueued++; - //printf("Q.%p: peerind.%d msglen.%d\n",ptr,peerind,msglen); + printf("Q.%p: peerind.%d msglen.%d sock.%d\n",ptr,peerind,msglen,sock); } uint32_t _LP_magic_check(bits256 hash,bits256 magic) @@ -307,7 +307,7 @@ void LP_broadcast_finish(int32_t pubsock,char *base,char *rel,uint8_t *msg,cJSON #ifdef FROM_MARKETMAKER if ( G.LP_IAMLP == 0 ) #else - if ( IAMLP == 0 ) + if ( IAMLP == 0 || pubsock < 0 ) #endif { free(msg); From 12e808f45ebee480c2218274e757604bea9cce68 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 21 Jan 2018 19:59:40 +0200 Subject: [PATCH 027/183] Test --- iguana/exchanges/LP_nativeDEX.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 79d331e9d..f0a6fcedd 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -1255,7 +1255,7 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu nn_close(pubsock), pubsock = -1; } } else printf("error getting pubsock %d\n",pubsock); - printf(">>>>>>>>> myipaddr.(%s) (%s) pullsock.%d valid.%d pubbindaddr.%s pubsock.%d\n",bindaddr,subaddr,pubsock,valid,bindaddr,pubsock); + printf(">>>>>>>>> myipaddr.(%s) (%s) valid.%d pubbindaddr.%s pubsock.%d\n",bindaddr,subaddr,valid,bindaddr,pubsock); LP_mypubsock = pubsock; } printf("got %s, initpeers\n",myipaddr); From cd178ab406037d561d99299c13484e4cd4c20aaa Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 21 Jan 2018 20:04:33 +0200 Subject: [PATCH 028/183] Test --- iguana/exchanges/LP_nativeDEX.c | 3 +-- iguana/exchanges/LP_network.c | 1 + 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index f0a6fcedd..e423be2ac 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -1258,10 +1258,9 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu printf(">>>>>>>>> myipaddr.(%s) (%s) valid.%d pubbindaddr.%s pubsock.%d\n",bindaddr,subaddr,valid,bindaddr,pubsock); LP_mypubsock = pubsock; } - printf("got %s, initpeers\n",myipaddr); + printf("got %s, initpeers. LP_mypubsock.%d\n",myipaddr,LP_mypubsock); LP_initpeers(pubsock,mypeer,myipaddr,myport,jstr(argjson,"seednode"),mypullport,mypubport); RPC_port = myport; - printf("get public socket\n"); LP_mypullsock = LP_initpublicaddr(ctx,&mypullport,pushaddr,myipaddr,mypullport,0); strcpy(LP_publicaddr,pushaddr); LP_publicport = mypullport; diff --git a/iguana/exchanges/LP_network.c b/iguana/exchanges/LP_network.c index 049d7a59f..6d11dbdc7 100644 --- a/iguana/exchanges/LP_network.c +++ b/iguana/exchanges/LP_network.c @@ -304,6 +304,7 @@ void LP_broadcast_finish(int32_t pubsock,char *base,char *rel,uint8_t *msg,cJSON msglen = (int32_t)strlen((char *)msg) + 1; if ( crc32 == 0 ) crc32 = calc_crc32(0,&msg[2],msglen - 2); + printf("crc32.%x IAMLP.%d pubsock.%d\n",crc32,G.LP_IAMLP,pubsock); #ifdef FROM_MARKETMAKER if ( G.LP_IAMLP == 0 ) #else From 148b0a1bfce33e49c6ab1f3f2287e5d19d4c539e Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 21 Jan 2018 20:09:28 +0200 Subject: [PATCH 029/183] Test --- iguana/exchanges/LP_network.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_network.c b/iguana/exchanges/LP_network.c index 6d11dbdc7..b531d506e 100644 --- a/iguana/exchanges/LP_network.c +++ b/iguana/exchanges/LP_network.c @@ -306,7 +306,7 @@ void LP_broadcast_finish(int32_t pubsock,char *base,char *rel,uint8_t *msg,cJSON crc32 = calc_crc32(0,&msg[2],msglen - 2); printf("crc32.%x IAMLP.%d pubsock.%d\n",crc32,G.LP_IAMLP,pubsock); #ifdef FROM_MARKETMAKER - if ( G.LP_IAMLP == 0 ) + if ( (G.LP_IAMLP == 0 && IAMLP == 0) || pubsock < 0 ) #else if ( IAMLP == 0 || pubsock < 0 ) #endif @@ -321,7 +321,11 @@ void LP_broadcast_finish(int32_t pubsock,char *base,char *rel,uint8_t *msg,cJSON msg = (void *)jprint(argjson,0); msglen = (int32_t)strlen((char *)msg) + 1; LP_queuesend(crc32,-1,base,rel,msg,msglen); - } else LP_queuesend(crc32,pubsock,base,rel,msg,msglen); + } + else + { + LP_queuesend(crc32,pubsock,base,rel,msg,msglen); + } free(msg); } From 0ad0e1dd816f47e7376214fe7b165a46f2c356b7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 21 Jan 2018 20:11:31 +0200 Subject: [PATCH 030/183] Test --- iguana/exchanges/LP_nativeDEX.c | 6 +++--- iguana/exchanges/LP_network.c | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index e423be2ac..8ae6e08ae 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -365,7 +365,7 @@ int32_t LP_sock_check(char *typestr,void *ctx,char *myipaddr,int32_t pubsock,int ptr = 0; if ( (recvlen= nn_recv(sock,&ptr,NN_MSG,0)) > 0 ) { - printf("%s nn_recv.%d\n",typestr,recvlen); + //printf("%s nn_recv.%d\n",typestr,recvlen); decodestr = 0; if ( recvlen > 32768 ) { @@ -997,13 +997,13 @@ void queue_loop(void *ctx) printf("%d LP_send mmjson sent %d instead of %d\n",n,sentbytes,k); else flag++; } - printf("k.%d SEND.(%s) sock.%d\n",k,(char *)ptr->msg,ptr->sock); + //printf("k.%d SEND.(%s) sock.%d\n",k,(char *)ptr->msg,ptr->sock); } free_json(json); } if ( flag == 0 ) { - printf("len.%d SEND.(%s) sock.%d\n",ptr->msglen,(char *)ptr->msg,ptr->sock); + //printf("len.%d SEND.(%s) sock.%d\n",ptr->msglen,(char *)ptr->msg,ptr->sock); if ( (sentbytes= nn_send(ptr->sock,ptr->msg,ptr->msglen,0)) != ptr->msglen ) printf("%d LP_send sent %d instead of %d\n",n,sentbytes,ptr->msglen); else flag++; diff --git a/iguana/exchanges/LP_network.c b/iguana/exchanges/LP_network.c index b531d506e..f5619a39d 100644 --- a/iguana/exchanges/LP_network.c +++ b/iguana/exchanges/LP_network.c @@ -156,7 +156,7 @@ void _LP_sendqueueadd(uint32_t crc32,int32_t sock,uint8_t *msg,int32_t msglen,in memcpy(ptr->msg,msg,msglen); // sizeof(bits256) at the end all zeroes DL_APPEND(LP_Q,ptr); LP_Qenqueued++; - printf("Q.%p: peerind.%d msglen.%d sock.%d\n",ptr,peerind,msglen,sock); + //printf("Q.%p: peerind.%d msglen.%d sock.%d\n",ptr,peerind,msglen,sock); } uint32_t _LP_magic_check(bits256 hash,bits256 magic) @@ -304,7 +304,7 @@ void LP_broadcast_finish(int32_t pubsock,char *base,char *rel,uint8_t *msg,cJSON msglen = (int32_t)strlen((char *)msg) + 1; if ( crc32 == 0 ) crc32 = calc_crc32(0,&msg[2],msglen - 2); - printf("crc32.%x IAMLP.%d pubsock.%d\n",crc32,G.LP_IAMLP,pubsock); + //printf("crc32.%x IAMLP.%d pubsock.%d\n",crc32,G.LP_IAMLP,pubsock); #ifdef FROM_MARKETMAKER if ( (G.LP_IAMLP == 0 && IAMLP == 0) || pubsock < 0 ) #else From 323f6ab688c2d73eb58255dd7b75bc2398930cea Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 22 Jan 2018 21:06:48 +0400 Subject: [PATCH 031/183] Patch lp ip --- iguana/exchanges/LP_nativeDEX.c | 1 + 1 file changed, 1 insertion(+) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 8ae6e08ae..dc6e1d912 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -138,6 +138,7 @@ char LP_myipaddr[64],LP_publicaddr[64],USERHOME[512] = { "/root" }; char LP_gui[16] = { "cli" }; char *default_LPnodes[] = { "5.9.253.195", "5.9.253.196", "5.9.253.197", "5.9.253.198", "5.9.253.199", "5.9.253.200", "5.9.253.201", "5.9.253.202", "5.9.253.203", + "173.212.225.176", "136.243.45.140", "88.99.227.213", "78.47.108.168","188.166.105.227" //"24.54.206.138", "107.72.162.127", "72.50.16.86", "51.15.202.191", "173.228.198.88", //"51.15.203.171", "51.15.86.136", "51.15.94.249", "51.15.80.18", "51.15.91.40", "51.15.54.2", "51.15.86.31", "51.15.82.29", "51.15.89.155", "173.212.225.176", "136.243.45.140" }; From 14b71de5c14c07a3a90b359ec5e0e13ca0f7ecef Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 22 Jan 2018 21:08:26 +0400 Subject: [PATCH 032/183] Test --- iguana/exchanges/LP_nativeDEX.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index dc6e1d912..bc00eecc7 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -138,7 +138,7 @@ char LP_myipaddr[64],LP_publicaddr[64],USERHOME[512] = { "/root" }; char LP_gui[16] = { "cli" }; char *default_LPnodes[] = { "5.9.253.195", "5.9.253.196", "5.9.253.197", "5.9.253.198", "5.9.253.199", "5.9.253.200", "5.9.253.201", "5.9.253.202", "5.9.253.203", - "173.212.225.176", "136.243.45.140", "88.99.227.213", "78.47.108.168","188.166.105.227" + "173.212.225.176", "136.243.45.140", "88.99.227.213", "78.47.108.168","188.166.105.227", "23.254.202.142", "45.32.19.196" //"24.54.206.138", "107.72.162.127", "72.50.16.86", "51.15.202.191", "173.228.198.88", //"51.15.203.171", "51.15.86.136", "51.15.94.249", "51.15.80.18", "51.15.91.40", "51.15.54.2", "51.15.86.31", "51.15.82.29", "51.15.89.155", "173.212.225.176", "136.243.45.140" }; From 11b63d1bf37d2aad330bc1c53806ad908c18380c Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 23 Jan 2018 18:46:05 +0400 Subject: [PATCH 033/183] Sane stop, reduce redundancy --- iguana/exchanges/LP_commands.c | 3 ++- iguana/exchanges/LP_nativeDEX.c | 22 ++++++++++++---------- iguana/exchanges/LP_network.c | 4 ++-- iguana/exchanges/LP_ordermatch.c | 14 ++++++-------- iguana/exchanges/LP_peers.c | 14 +++++++++----- iguana/exchanges/LP_portfolio.c | 2 +- iguana/exchanges/LP_remember.c | 2 +- iguana/exchanges/LP_scan.c | 2 +- iguana/exchanges/LP_signatures.c | 1 + iguana/exchanges/stats.c | 6 +++--- 10 files changed, 38 insertions(+), 32 deletions(-) diff --git a/iguana/exchanges/LP_commands.c b/iguana/exchanges/LP_commands.c index a3e508e67..a4d6521e4 100644 --- a/iguana/exchanges/LP_commands.c +++ b/iguana/exchanges/LP_commands.c @@ -268,7 +268,8 @@ jpg(srcfile, destfile, power2=7, passphrase, data="", required)\n\ else if ( strcmp(method,"stop") == 0 ) { printf("DEBUG stop\n"); - exit(0); + LP_STOP_RECEIVED = 1; + return(clonestr("{\"result\":\"success\"}")); } else if ( strcmp(method,"millis") == 0 ) { diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index bc00eecc7..4df11579d 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -100,7 +100,7 @@ struct LP_trade *LP_trades,*LP_tradesQ; //uint32_t LP_deadman_switch; uint16_t LP_fixed_pairport,LP_publicport; uint32_t LP_lastnonce,LP_swap_endcritical,LP_swap_critical,LP_RTcount,LP_swapscount; -int32_t LP_mybussock = -1; +int32_t LP_STOP_RECEIVED,LP_numactive_LP,LP_mybussock = -1; int32_t LP_mypubsock = -1; int32_t LP_mypullsock = -1; int32_t LP_numfinished,LP_showwif,IAMLP = 0; @@ -480,7 +480,7 @@ void command_rpcloop(void *ctx) int32_t nonz = 0; strcpy(command_rpcloop_stats.name,"command_rpcloop"); command_rpcloop_stats.threshold = 2500.; - while ( 1 ) + while ( LP_STOP_RECEIVED == 0 ) { LP_millistats_update(&command_rpcloop_stats); nonz = LP_nanomsg_recvs(ctx); @@ -515,7 +515,7 @@ void LP_coinsloop(void *_coins) strcpy(LP_coinsloop_stats.name,"other coins loop"); LP_coinsloop_stats.threshold = 5000.; } - while ( 1 ) + while ( LP_STOP_RECEIVED == 0 ) { if ( strcmp("BTC",coins) == 0 ) LP_millistats_update(&LP_coinsloopBTC_stats); @@ -874,7 +874,7 @@ void LP_initpeers(int32_t pubsock,struct LP_peerinfo *mypeer,char *myipaddr,uint //LP_addpeer(mypeer,pubsock,"51.15.86.136",myport,pushport,subport,0,G.LP_sessionid); OS_randombytes((void *)&r,sizeof(r)); //r = 0; - for (j=0; j lasttime+LP_ORDERBOOK_DURATION*0.5 ) @@ -910,7 +910,7 @@ void LP_swapsloop(void *ctx) strcpy(LP_swapsloop_stats.name,"LP_swapsloop"); LP_swapsloop_stats.threshold = 605000.; sleep(50); - while ( 1 ) + while ( LP_STOP_RECEIVED == 0 ) { LP_millistats_update(&LP_swapsloop_stats); if ( (retstr= basilisk_swapentry(0,0,0)) != 0 ) @@ -924,7 +924,7 @@ void gc_loop(void *ctx) uint32_t now; struct LP_address_utxo *up,*utmp; struct rpcrequest_info *req,*rtmp; int32_t flag = 0; strcpy(LP_gcloop_stats.name,"gc_loop"); LP_gcloop_stats.threshold = 11000.; - while ( 1 ) + while ( LP_STOP_RECEIVED == 0 ) { flag = 0; LP_millistats_update(&LP_gcloop_stats); @@ -959,7 +959,7 @@ void queue_loop(void *ctx) struct LP_queue *ptr,*tmp; cJSON *json; uint8_t linebuf[32768]; int32_t k,sentbytes,nonz,flag,duplicate,n=0; strcpy(queue_loop_stats.name,"queue_loop"); queue_loop_stats.threshold = 1000.; - while ( 1 ) + while ( LP_STOP_RECEIVED == 0 ) { LP_millistats_update(&queue_loop_stats); //printf("LP_Q.%p next.%p prev.%p\n",LP_Q,LP_Q!=0?LP_Q->next:0,LP_Q!=0?LP_Q->prev:0); @@ -1068,7 +1068,7 @@ void LP_reserved_msgs(void *ignore) memset(zero.bytes,0,sizeof(zero)); strcpy(LP_reserved_msgs_stats.name,"LP_reserved_msgs"); LP_reserved_msgs_stats.threshold = 150.; - while ( 1 ) + while ( LP_STOP_RECEIVED == 0 ) { nonz = 0; LP_millistats_update(&LP_reserved_msgs_stats); @@ -1362,7 +1362,7 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu int32_t nonz; LP_statslog_parse(); bitcoind_RPC_inittime = 0; - while ( 1 ) + while ( LP_STOP_RECEIVED == 0 ) { nonz = 0; G.waiting = 1; @@ -1379,6 +1379,8 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu usleep(1000); } #endif + sleep(5); + printf("marketmaker exiting in 5 seconds\n"); } #ifdef FROM_JS diff --git a/iguana/exchanges/LP_network.c b/iguana/exchanges/LP_network.c index f5619a39d..1a7fefeb3 100644 --- a/iguana/exchanges/LP_network.c +++ b/iguana/exchanges/LP_network.c @@ -213,7 +213,7 @@ int32_t LP_magic_check(uint8_t *msg,int32_t recvlen,char *remoteaddr) int32_t LP_crc32find(int32_t *duplicatep,int32_t ind,uint32_t crc32) { - static uint32_t crcs[4096]; static unsigned long dup,total; + static uint32_t crcs[16384]; static unsigned long dup,total; int32_t i; *duplicatep = 0; if ( ind < 0 ) @@ -416,7 +416,7 @@ void LP_psockloop(void *_ptr) // printouts seem to be needed for forwarding to w int32_t i,n,nonz,iter,retval,sentbytes,size=0,sendsock = -1; uint32_t now; struct psock *ptr=0; void *buf=0; char keepalive[512]; strcpy(LP_psockloop_stats.name,"LP_psockloop"); LP_psockloop_stats.threshold = 200.; - while ( 1 ) + while ( LP_STOP_RECEIVED == 0 ) { LP_millistats_update(&LP_psockloop_stats); now = (uint32_t)time(NULL); diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 810abb632..bb22c383d 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -481,11 +481,9 @@ int32_t LP_connectstartbob(void *ctx,int32_t pubsock,char *base,char *rel,double bits256 zero; memset(zero.bytes,0,sizeof(zero)); LP_reserved_msg(1,base,rel,zero,jprint(reqjson,0)); - //if ( IAMLP == 0 ) - { - sleep(1); - LP_reserved_msg(1,qp->srccoin,qp->destcoin,qp->desthash,jprint(reqjson,0)); - } + sleep(1); + LP_reserved_msg(1,qp->srccoin,qp->destcoin,qp->desthash,jprint(reqjson,0)); + sleep(1); LP_reserved_msg(0,base,rel,zero,jprint(reqjson,0)); free_json(reqjson); LP_importaddress(qp->destcoin,qp->destaddr); @@ -910,12 +908,12 @@ struct LP_quoteinfo *LP_trades_gotrequest(void *ctx,struct LP_quoteinfo *qp,stru bits256 zero; memset(zero.bytes,0,sizeof(zero)); LP_reserved_msg(1,qp->srccoin,qp->destcoin,zero,jprint(reqjson,0)); - //if ( IAMLP == 0 ) + if ( 0 )//if ( IAMLP == 0 ) { sleep(1); LP_reserved_msg(1,qp->srccoin,qp->destcoin,qp->desthash,jprint(reqjson,0)); } - LP_reserved_msg(0,qp->srccoin,qp->destcoin,zero,jprint(reqjson,0)); + //LP_reserved_msg(0,qp->srccoin,qp->destcoin,zero,jprint(reqjson,0)); free_json(reqjson); return(qp); } else printf("request processing selected ineligible utxos?\n"); @@ -1016,7 +1014,7 @@ void LP_tradesloop(void *ctx) strcpy(LP_tradesloop_stats.name,"LP_tradesloop"); LP_tradesloop_stats.threshold = 10000; sleep(5); - while ( 1 ) + while ( LP_STOP_RECEIVED == 0 ) { LP_millistats_update(&LP_tradesloop_stats); nonz = 0; diff --git a/iguana/exchanges/LP_peers.c b/iguana/exchanges/LP_peers.c index a7d960c97..782bf90ed 100644 --- a/iguana/exchanges/LP_peers.c +++ b/iguana/exchanges/LP_peers.c @@ -68,8 +68,11 @@ struct LP_peerinfo *LP_addpeer(struct LP_peerinfo *mypeer,int32_t mypubsock,char { if ( (peer= LP_peerfind(ipbits,port)) != 0 ) { - if ( isLP != 0 ) - peer->isLP = isLP; + if ( isLP != 0 && peer->isLP == 0 ) + { + if ( (peer->isLP= isLP) != 0 ) + LP_numactive_LP++; + } /*if ( numpeers > peer->numpeers ) peer->numpeers = numpeers; if ( numutxos > peer->numutxos ) @@ -77,7 +80,7 @@ struct LP_peerinfo *LP_addpeer(struct LP_peerinfo *mypeer,int32_t mypubsock,char if ( peer->sessionid == 0 ) peer->sessionid = sessionid;*/ } - else + else if ( IAMLP != 0 || LP_numactive_LP < 3 ) { //printf("addpeer (%s:%u) pushport.%u subport.%u\n",ipaddr,port,pushport,subport); peer = calloc(1,sizeof(*peer)); @@ -88,7 +91,8 @@ struct LP_peerinfo *LP_addpeer(struct LP_peerinfo *mypeer,int32_t mypubsock,char strcpy(peer->ipaddr,ipaddr); //peer->profitmargin = profitmargin; peer->ipbits = ipbits; - peer->isLP = isLP; + if ( (peer->isLP= isLP) != 0 ) + LP_numactive_LP++; peer->port = port; peer->ip_port = ((uint64_t)port << 32) | ipbits; if ( pushport != 0 && subport != 0 && (pushsock= nn_socket(AF_SP,NN_PUSH)) >= 0 ) @@ -124,7 +128,7 @@ struct LP_peerinfo *LP_addpeer(struct LP_peerinfo *mypeer,int32_t mypubsock,char if ( valid > 0 ) { peer->subsock = subsock; - printf("connected to sub.(%s) subsock.%d valid.%d\n",subaddr,peer->subsock,valid); + printf("connected to sub.(%s) subsock.%d valid.%d numactive.%d\n",subaddr,peer->subsock,valid,LP_numactive_LP); } else { diff --git a/iguana/exchanges/LP_portfolio.c b/iguana/exchanges/LP_portfolio.c index 3476f53c8..068997c9f 100644 --- a/iguana/exchanges/LP_portfolio.c +++ b/iguana/exchanges/LP_portfolio.c @@ -869,7 +869,7 @@ void prices_loop(void *ctx) char *retstr; cJSON *retjson,*array; char *buycoin,*sellcoin; struct iguana_info *buy,*sell; uint32_t requestid,quoteid; int32_t i,n,m; struct LP_portfoliotrade trades[256]; struct LP_priceinfo *btcpp; strcpy(prices_loop_stats.name,"prices_loop"); prices_loop_stats.threshold = 191000.; - while ( 1 ) + while ( LP_STOP_RECEIVED == 0 ) { //printf("prices loop autoprices.%d autorefs.%d\n",LP_autoprices,num_LP_autorefs); LP_millistats_update(&prices_loop_stats); diff --git a/iguana/exchanges/LP_remember.c b/iguana/exchanges/LP_remember.c index 6abf336b5..693eb9093 100644 --- a/iguana/exchanges/LP_remember.c +++ b/iguana/exchanges/LP_remember.c @@ -489,7 +489,7 @@ cJSON *LP_swap_json(struct LP_swap_remember *rswap) item = cJSON_CreateObject(); if ( LP_swap_endcritical < LP_swap_critical ) { - jaddstr(item,"warning","swaps in critical section"); + jaddstr(item,"warning","swaps in critical section, dont exit now"); jaddnum(item,"critical",LP_swap_critical); jaddnum(item,"endcritical",LP_swap_endcritical); } diff --git a/iguana/exchanges/LP_scan.c b/iguana/exchanges/LP_scan.c index defc1b0cd..fdb3801cd 100644 --- a/iguana/exchanges/LP_scan.c +++ b/iguana/exchanges/LP_scan.c @@ -453,7 +453,7 @@ int32_t LP_waitmempool(char *symbol,char *coinaddr,bits256 txid,int32_t vout,int return(-1); } expiration = (uint32_t)time(NULL) + duration; - while ( 1 ) + while ( LP_STOP_RECEIVED == 0 ) { if ( LP_gettx_presence(symbol,txid) != 0 ) numconfirms = 0; diff --git a/iguana/exchanges/LP_signatures.c b/iguana/exchanges/LP_signatures.c index e251daabc..22be5ffd2 100644 --- a/iguana/exchanges/LP_signatures.c +++ b/iguana/exchanges/LP_signatures.c @@ -676,6 +676,7 @@ void LP_query(void *ctx,char *myipaddr,int32_t mypubsock,char *method,struct LP_ memset(&zero,0,sizeof(zero)); LP_reserved_msg(1,qp->srccoin,qp->destcoin,zero,clonestr(msg)); //if ( strcmp(method,"request") == 0 ) + if ( 0 ) { sleep(1); LP_reserved_msg(1,qp->srccoin,qp->destcoin,zero,clonestr(msg)); diff --git a/iguana/exchanges/stats.c b/iguana/exchanges/stats.c index e20bfa284..8d03d26c6 100644 --- a/iguana/exchanges/stats.c +++ b/iguana/exchanges/stats.c @@ -771,7 +771,7 @@ void LP_rpc_processreq(void *_ptr) spawned--; } -extern int32_t IAMLP; +extern int32_t IAMLP,LP_STOP_RECEIVED; //int32_t LP_bindsock_reset,LP_bindsock = -1; void stats_rpcloop(void *args) @@ -782,7 +782,7 @@ void stats_rpcloop(void *args) printf("Start stats_rpcloop.%u\n",port); localhostbits = (uint32_t)calc_ipbits("127.0.0.1"); //initial_bindsock_reset = LP_bindsock_reset; - while ( 1 )//LP_bindsock_reset == initial_bindsock_reset ) + while ( LP_STOP_RECEIVED == 0 )//LP_bindsock_reset == initial_bindsock_reset ) { //printf("LP_bindsock.%d\n",LP_bindsock); if ( bindsock < 0 ) @@ -1196,7 +1196,7 @@ int main(int argc, const char * argv[]) exit(-1); } printf("DEX stats running\n"); - while ( 1 ) + while ( LP_STOP_RECEIVED == 0 ) { if ( (filestr= stats_update(logfp,STATS_DEST,statefname,komodofile)) != 0 ) { From 6bda64b65139fccf69b83d4199e5a94f1f095a91 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 23 Jan 2018 18:50:59 +0400 Subject: [PATCH 034/183] Test --- iguana/exchanges/LP_nativeDEX.c | 2 +- iguana/exchanges/mm.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 4df11579d..ff83ff8d5 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -1379,8 +1379,8 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu usleep(1000); } #endif - sleep(5); printf("marketmaker exiting in 5 seconds\n"); + sleep(5); } #ifdef FROM_JS diff --git a/iguana/exchanges/mm.c b/iguana/exchanges/mm.c index cdef05e37..8c1e99b9d 100644 --- a/iguana/exchanges/mm.c +++ b/iguana/exchanges/mm.c @@ -211,7 +211,7 @@ int main(int argc, const char * argv[]) exit(-1); } //else printf("(%s) launched.(%s)\n",argv[1],passphrase); incr = 100.; - while ( (1) ) + while ( LP_STOP_RECEIVED == 0 ) sleep(100000); } #endif From b010405a422fa3c9eb70a5e5deb7bf14f764ba7f Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 23 Jan 2018 18:53:08 +0400 Subject: [PATCH 035/183] Test --- iguana/exchanges/LP_nativeDEX.c | 1 + 1 file changed, 1 insertion(+) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index ff83ff8d5..ea66301d7 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -1381,6 +1381,7 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu #endif printf("marketmaker exiting in 5 seconds\n"); sleep(5); + exit(0); } #ifdef FROM_JS From 9e5d0963cf057ac8dc1ef5c0c789ce62e223428b Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 23 Jan 2018 20:46:05 +0400 Subject: [PATCH 036/183] Netid/seednode to passphrase hooks, and fix dancing chicken duplicate Gui field --- iguana/exchanges/LP_commands.c | 8 ++++---- iguana/exchanges/LP_nativeDEX.c | 5 +++-- iguana/exchanges/LP_privkey.c | 4 +++- iguana/exchanges/LP_remember.c | 3 ++- iguana/exchanges/LP_signatures.c | 3 ++- iguana/exchanges/LP_stats.c | 6 ++++++ 6 files changed, 20 insertions(+), 9 deletions(-) diff --git a/iguana/exchanges/LP_commands.c b/iguana/exchanges/LP_commands.c index a4d6521e4..0427210b4 100644 --- a/iguana/exchanges/LP_commands.c +++ b/iguana/exchanges/LP_commands.c @@ -123,7 +123,7 @@ sendrawtransaction(coin, signedtx)\n\ swapstatus(pending=0)\n\ swapstatus(coin, limit=10)\n\ swapstatus(base, rel, limit=10)\n\ -swapstatus(requestid, quoteid)\n\ +swapstatus(requestid, quoteid, pending=0)\n\ recentswaps(limit=3)\n\ notarizations(coin)\n\ public API:\n \ @@ -131,7 +131,7 @@ getcoins()\n\ getcoin(coin)\n\ portfolio()\n\ getpeers()\n\ -passphrase(passphrase, gui)\n\ +passphrase(passphrase, gui, netid=0, seednode="")\n\ listunspent(coin, address)\n\ setconfirms(coin, numconfirms, maxconfirms=6)\n\ trust(pubkey, trust) # positive to trust, 0 for normal, negative to blacklist\n\ @@ -202,7 +202,7 @@ jpg(srcfile, destfile, power2=7, passphrase, data="", required)\n\ { char coinaddr[64],pub33str[67]; G.USERPASS_COUNTER = 1; - if ( LP_passphrase_init(jstr(argjson,"passphrase"),jstr(argjson,"gui")) < 0 ) + if ( LP_passphrase_init(jstr(argjson,"passphrase"),jstr(argjson,"gui"),juint(argjson,"netid"),jstr(argjson,"seednode")) < 0 ) return(clonestr("{\"error\":\"couldnt change passphrase\"}")); { retjson = cJSON_CreateObject(); @@ -571,7 +571,7 @@ jpg(srcfile, destfile, power2=7, passphrase, data="", required)\n\ { ptr->privkeydepth = 0; LP_address_utxo_reset(ptr); - LP_passphrase_init(jstr(argjson,"passphrase"),G.gui); + LP_passphrase_init(jstr(argjson,"passphrase"),G.gui,G.netid,G.seednode); } if ( bits256_nonz(G.LP_privkey) != 0 ) LP_privkey_init(-1,ptr,G.LP_privkey,G.LP_mypub25519); diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index ea66301d7..acd61b932 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -113,10 +113,11 @@ struct LP_globals //struct LP_utxoinfo *LP_utxoinfos[2],*LP_utxoinfos2[2]; bits256 LP_mypub25519,LP_privkey,LP_mypriv25519,LP_passhash; uint64_t LP_skipstatus[10000]; + uint16_t netid; uint8_t LP_myrmd160[20],LP_pubsecp[33]; uint32_t LP_sessionid,counter; int32_t LP_IAMLP,LP_pendingswaps,USERPASS_COUNTER,LP_numprivkeys,initializing,waiting,LP_numskips; - char USERPASS[65],USERPASS_WIFSTR[64],LP_myrmd160str[41],gui[16],LP_NXTaddr[64]; + char seednode[64],USERPASS[65],USERPASS_WIFSTR[64],LP_myrmd160str[41],gui[16],LP_NXTaddr[64]; struct LP_privkey LP_privkeys[100]; } G; @@ -1286,7 +1287,7 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu } LP_initcoins(ctx,pubsock,coinsjson); G.waiting = 1; - LP_passphrase_init(passphrase,jstr(argjson,"gui")); + LP_passphrase_init(passphrase,jstr(argjson,"gui"),juint(argjson,"netid"),jstr(argjson,"seednode")); #ifndef FROM_JS if ( IAMLP != 0 && OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_psockloop,(void *)myipaddr) != 0 ) { diff --git a/iguana/exchanges/LP_privkey.c b/iguana/exchanges/LP_privkey.c index ece651338..0c75d4425 100644 --- a/iguana/exchanges/LP_privkey.c +++ b/iguana/exchanges/LP_privkey.c @@ -345,7 +345,7 @@ void LP_privkey_updates(void *ctx,int32_t pubsock,char *passphrase) } } -int32_t LP_passphrase_init(char *passphrase,char *gui) +int32_t LP_passphrase_init(char *passphrase,char *gui,uint16_t netid,char *seednode) { static void *ctx; int32_t counter; //iambob,; struct LP_utxoinfo *utxo,*tmp; if ( ctx == 0 ) @@ -362,6 +362,8 @@ int32_t LP_passphrase_init(char *passphrase,char *gui) sleep(5); } memset(&G,0,sizeof(G)); + G.netid = netid; + safecopy(G.seednode,seednode,sizeof(G.seednode)); vcalc_sha256(0,G.LP_passhash.bytes,(uint8_t *)passphrase,(int32_t)strlen(passphrase)); LP_privkey_updates(ctx,LP_mypubsock,passphrase); init_hexbytes_noT(G.LP_myrmd160str,G.LP_myrmd160,20); diff --git a/iguana/exchanges/LP_remember.c b/iguana/exchanges/LP_remember.c index 693eb9093..8c50de4fe 100644 --- a/iguana/exchanges/LP_remember.c +++ b/iguana/exchanges/LP_remember.c @@ -1202,7 +1202,8 @@ cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requesti { jaddstr(item,"method","tradestatus"); jaddnum(item,"finishtime",rswap.finishtime); - jaddstr(item,"gui",G.gui); + if ( jobj(item,"gui") == 0 ) + jaddstr(item,"gui",G.gui); //jaddbits256(item,"srchash",rswap.Q.srchash); //jaddbits256(item,"desthash",rswap.desthash); itemstr = jprint(item,0); diff --git a/iguana/exchanges/LP_signatures.c b/iguana/exchanges/LP_signatures.c index 22be5ffd2..6318a96a7 100644 --- a/iguana/exchanges/LP_signatures.c +++ b/iguana/exchanges/LP_signatures.c @@ -42,7 +42,8 @@ struct basilisk_request *LP_requestinit(struct basilisk_request *rp,bits256 srch cJSON *LP_quotejson(struct LP_quoteinfo *qp) { double price; cJSON *retjson = cJSON_CreateObject(); - jaddstr(retjson,"gui",qp->gui[0] != 0 ? qp->gui : LP_gui); + if ( jobj(retjson,"gui") == 0 ) + jaddstr(retjson,"gui",qp->gui[0] != 0 ? qp->gui : LP_gui); jadd64bits(retjson,"aliceid",qp->aliceid); jaddnum(retjson,"tradeid",qp->tradeid); jaddstr(retjson,"base",qp->srccoin); diff --git a/iguana/exchanges/LP_stats.c b/iguana/exchanges/LP_stats.c index 31eacdd9f..1bce64fde 100644 --- a/iguana/exchanges/LP_stats.c +++ b/iguana/exchanges/LP_stats.c @@ -201,9 +201,11 @@ int32_t LP_statslog_parse() struct LP_swapstats *LP_swapstats_find(uint64_t aliceid) { struct LP_swapstats *sp; + portable_mutex_lock(&LP_statslogmutex); HASH_FIND(hh,LP_RTstats,&aliceid,sizeof(aliceid),sp); if ( sp == 0 ) HASH_FIND(hh,LP_swapstats,&aliceid,sizeof(aliceid),sp); + portable_mutex_unlock(&LP_statslogmutex); return(sp); } @@ -214,9 +216,11 @@ struct LP_swapstats *LP_swapstats_add(uint64_t aliceid,int32_t RTflag) { sp = calloc(1,sizeof(*sp)); sp->aliceid = aliceid; + portable_mutex_lock(&LP_statslogmutex); if ( RTflag != 0 ) HASH_ADD(hh,LP_RTstats,aliceid,sizeof(aliceid),sp); else HASH_ADD(hh,LP_swapstats,aliceid,sizeof(aliceid),sp); + portable_mutex_unlock(&LP_statslogmutex); } return(LP_swapstats_find(aliceid)); } @@ -742,8 +746,10 @@ cJSON *LP_statslog_disp(uint32_t starttime,uint32_t endtime,char *refgui,bits256 { if ( LP_stats_dispiter(array,sp,starttime,endtime,refbase,refrel,refgui,refpubkey) > 0 ) { + portable_mutex_lock(&LP_statslogmutex); HASH_DELETE(hh,LP_RTstats,sp); HASH_ADD(hh,LP_swapstats,aliceid,sizeof(sp->aliceid),sp); + portable_mutex_unlock(&LP_statslogmutex); } else { From 9e2a36b5ee7e76a4e9900f84cba0d9fc51b86d56 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 23 Jan 2018 23:48:35 +0400 Subject: [PATCH 037/183] Coinmarketprice margin fix? --- iguana/exchanges/LP_portfolio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_portfolio.c b/iguana/exchanges/LP_portfolio.c index 068997c9f..4277b93a0 100644 --- a/iguana/exchanges/LP_portfolio.c +++ b/iguana/exchanges/LP_portfolio.c @@ -604,7 +604,7 @@ void LP_autoprice_iter(void *ctx,struct LP_priceinfo *btcpp) LP_mypriceset(&changed,rel,base,newprice); LP_pricepings(ctx,LP_myipaddr,LP_mypubsock,rel,base,newprice); //printf("%s/%s price %.8f margin %.8f/%.8f newprice %.8f %.8f\n",base,rel,price,buymargin,sellmargin,newprice,(1. / newprice) * (1. + sellmargin)); - newprice = (1. / newprice) * (1. + sellmargin); + newprice = (1. / (newprice * (1. + sellmargin))); if ( LP_autorefs[i].lastask < SMALLVAL ) LP_autorefs[i].lastask = newprice; else LP_autorefs[i].lastask = (LP_autorefs[i].lastask * 0.9) + (0.1 *newprice); From 2b78b47f9e5800bb063f906d182cbeee04073145 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 24 Jan 2018 00:08:50 +0400 Subject: [PATCH 038/183] Test --- iguana/exchanges/LP_portfolio.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_portfolio.c b/iguana/exchanges/LP_portfolio.c index 4277b93a0..eff98e472 100644 --- a/iguana/exchanges/LP_portfolio.c +++ b/iguana/exchanges/LP_portfolio.c @@ -596,7 +596,7 @@ void LP_autoprice_iter(void *ctx,struct LP_priceinfo *btcpp) else continue; if ( factor > 0. ) price = (price * factor) + offset; - newprice = (price * (1. - buymargin)); + newprice = (price * (1. + buymargin)); if ( LP_autorefs[i].lastbid < SMALLVAL ) LP_autorefs[i].lastbid = newprice; else LP_autorefs[i].lastbid = (LP_autorefs[i].lastbid * 0.9) + (0.1 *newprice); @@ -604,7 +604,7 @@ void LP_autoprice_iter(void *ctx,struct LP_priceinfo *btcpp) LP_mypriceset(&changed,rel,base,newprice); LP_pricepings(ctx,LP_myipaddr,LP_mypubsock,rel,base,newprice); //printf("%s/%s price %.8f margin %.8f/%.8f newprice %.8f %.8f\n",base,rel,price,buymargin,sellmargin,newprice,(1. / newprice) * (1. + sellmargin)); - newprice = (1. / (newprice * (1. + sellmargin))); + newprice = (1. / newprice) * (1. + sellmargin); if ( LP_autorefs[i].lastask < SMALLVAL ) LP_autorefs[i].lastask = newprice; else LP_autorefs[i].lastask = (LP_autorefs[i].lastask * 0.9) + (0.1 *newprice); From 705ce5cae475e42818c311dea1148df67c5860bc Mon Sep 17 00:00:00 2001 From: cipig <32116761+cipig@users.noreply.github.com> Date: Tue, 23 Jan 2018 22:14:11 +0000 Subject: [PATCH 039/183] fix cmc autoprice margin --- iguana/exchanges/LP_portfolio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_portfolio.c b/iguana/exchanges/LP_portfolio.c index eff98e472..7601761fa 100644 --- a/iguana/exchanges/LP_portfolio.c +++ b/iguana/exchanges/LP_portfolio.c @@ -604,7 +604,7 @@ void LP_autoprice_iter(void *ctx,struct LP_priceinfo *btcpp) LP_mypriceset(&changed,rel,base,newprice); LP_pricepings(ctx,LP_myipaddr,LP_mypubsock,rel,base,newprice); //printf("%s/%s price %.8f margin %.8f/%.8f newprice %.8f %.8f\n",base,rel,price,buymargin,sellmargin,newprice,(1. / newprice) * (1. + sellmargin)); - newprice = (1. / newprice) * (1. + sellmargin); + newprice = (1. / price) * (1. + sellmargin); if ( LP_autorefs[i].lastask < SMALLVAL ) LP_autorefs[i].lastask = newprice; else LP_autorefs[i].lastask = (LP_autorefs[i].lastask * 0.9) + (0.1 *newprice); From 785e77d9870c15e5a8cc785ed2f500074160f07a Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 24 Jan 2018 10:59:22 +0400 Subject: [PATCH 040/183] Better wif detector --- iguana/exchanges/LP_privkey.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_privkey.c b/iguana/exchanges/LP_privkey.c index 0c75d4425..133b62d0b 100644 --- a/iguana/exchanges/LP_privkey.c +++ b/iguana/exchanges/LP_privkey.c @@ -206,12 +206,26 @@ static const char base58_chars[] = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijk int32_t LP_wifstr_valid(char *symbol,char *wifstr) { - bits256 privkey,cmpkey; uint8_t wiftype; char cmpstr[128],cmpstr2[128]; int32_t i; + bits256 privkey,cmpkey; uint8_t wiftype; char cmpstr[128],cmpstr2[128]; int32_t i,len,n,a,A; + if ( (len= (int32_t)strlen(wifstr)) < 50 || len > 54 ) + return(0); memset(privkey.bytes,0,sizeof(privkey)); memset(cmpkey.bytes,0,sizeof(cmpkey)); - for (i=0; wifstr[i]!=0; i++) + for (i=n=a=A=0; wifstr[i]!=0; i++) + { if ( strchr(base58_chars,wifstr[i]) == 0 ) return(0); + if ( wifstr[i] >= '1' && wifstr[i] <= '9' ) + n++; + else if ( wifstr[i] >= 'A' && wifstr[i] <= 'Z' ) + A++; + else if ( wifstr[i] >= 'a' && wifstr[i] <= 'z' ) + a++; + } + if ( n == 0 || A == 0 || a == 0 ) + return(0); + if ( A > 10*a || a < 10*A || n < 20*a || n < 20*A ) // unlikely it is a real wif + return(0); bitcoin_wif2priv(symbol,0,&wiftype,&privkey,wifstr); bitcoin_priv2wif(symbol,0,cmpstr,privkey,wiftype); if ( strcmp(cmpstr,wifstr) == 0 ) From 86f85cb5858de0c42a89e66d4d5c2848181d1c6f Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 24 Jan 2018 11:54:04 +0400 Subject: [PATCH 041/183] Test --- iguana/exchanges/LP_nativeDEX.c | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index acd61b932..8d189f74f 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -1236,15 +1236,12 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu pubsock = -1; nanomsg_transportname(0,subaddr,myipaddr,mypubport); nanomsg_transportname(1,bindaddr,myipaddr,mypubport); - //nanomsg_transportname2(1,bindaddr2,myipaddr,mypubport); valid = 0; if ( (pubsock= nn_socket(AF_SP,NN_PUB)) >= 0 ) { valid = 0; if ( nn_bind(pubsock,bindaddr) >= 0 ) valid++; - //if ( nn_bind(pubsock,bindaddr2) >= 0 ) - // valid++; if ( valid > 0 ) { timeout = 1; @@ -1260,15 +1257,6 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu printf(">>>>>>>>> myipaddr.(%s) (%s) valid.%d pubbindaddr.%s pubsock.%d\n",bindaddr,subaddr,valid,bindaddr,pubsock); LP_mypubsock = pubsock; } - printf("got %s, initpeers. LP_mypubsock.%d\n",myipaddr,LP_mypubsock); - LP_initpeers(pubsock,mypeer,myipaddr,myport,jstr(argjson,"seednode"),mypullport,mypubport); - RPC_port = myport; - LP_mypullsock = LP_initpublicaddr(ctx,&mypullport,pushaddr,myipaddr,mypullport,0); - strcpy(LP_publicaddr,pushaddr); - LP_publicport = mypullport; - LP_mybussock = LP_coinbus(mybusport); - //LP_deadman_switch = (uint32_t)time(NULL); - printf("canbind.%d my command address is (%s) pullsock.%d pullport.%u\n",LP_canbind,pushaddr,LP_mypullsock,mypullport); if ( (coinsjson= jobj(argjson,"coins")) == 0 ) { if ( (coins_str= OS_filestr(&filesize,"coins.json")) != 0 || (coins_str= OS_filestr(&filesize,"exchanges/coins.json")) != 0 ) @@ -1287,6 +1275,15 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu } LP_initcoins(ctx,pubsock,coinsjson); G.waiting = 1; + printf("got %s, initpeers. LP_mypubsock.%d\n",myipaddr,LP_mypubsock); + LP_initpeers(pubsock,mypeer,myipaddr,myport,jstr(argjson,"seednode"),mypullport,mypubport); + RPC_port = myport; + LP_mypullsock = LP_initpublicaddr(ctx,&mypullport,pushaddr,myipaddr,mypullport,0); + strcpy(LP_publicaddr,pushaddr); + LP_publicport = mypullport; + LP_mybussock = LP_coinbus(mybusport); + //LP_deadman_switch = (uint32_t)time(NULL); + printf("canbind.%d my command address is (%s) pullsock.%d pullport.%u\n",LP_canbind,pushaddr,LP_mypullsock,mypullport); LP_passphrase_init(passphrase,jstr(argjson,"gui"),juint(argjson,"netid"),jstr(argjson,"seednode")); #ifndef FROM_JS if ( IAMLP != 0 && OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_psockloop,(void *)myipaddr) != 0 ) From 6c39a536d8c4d913ec7c949d08deacb49605ac69 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 24 Jan 2018 11:58:00 +0400 Subject: [PATCH 042/183] Test --- iguana/exchanges/LP_privkey.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/iguana/exchanges/LP_privkey.c b/iguana/exchanges/LP_privkey.c index 133b62d0b..660c79290 100644 --- a/iguana/exchanges/LP_privkey.c +++ b/iguana/exchanges/LP_privkey.c @@ -208,7 +208,10 @@ int32_t LP_wifstr_valid(char *symbol,char *wifstr) { bits256 privkey,cmpkey; uint8_t wiftype; char cmpstr[128],cmpstr2[128]; int32_t i,len,n,a,A; if ( (len= (int32_t)strlen(wifstr)) < 50 || len > 54 ) + { + printf("len.%d is wrong for wif %s\n",len,wifstr); return(0); + } memset(privkey.bytes,0,sizeof(privkey)); memset(cmpkey.bytes,0,sizeof(cmpkey)); for (i=n=a=A=0; wifstr[i]!=0; i++) @@ -225,7 +228,10 @@ int32_t LP_wifstr_valid(char *symbol,char *wifstr) if ( n == 0 || A == 0 || a == 0 ) return(0); if ( A > 10*a || a < 10*A || n < 20*a || n < 20*A ) // unlikely it is a real wif + { + printf("reject wif %s due to n.%d a.%d A.%d\n",wifstr,n,a,A); return(0); + } bitcoin_wif2priv(symbol,0,&wiftype,&privkey,wifstr); bitcoin_priv2wif(symbol,0,cmpstr,privkey,wiftype); if ( strcmp(cmpstr,wifstr) == 0 ) @@ -241,6 +247,7 @@ int32_t LP_wifstr_valid(char *symbol,char *wifstr) if ( bits256_cmp(privkey,cmpkey) == 0 ) return(1); } + char str[65]; printf("%s is not a wif, privkey.%s\n",wifstr,bits256_str(str,privkey)); return(0); } From 565d6608cfc3fb32a0346bd9d5972364943a0fce Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 24 Jan 2018 11:59:57 +0400 Subject: [PATCH 043/183] Test --- iguana/exchanges/LP_privkey.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_privkey.c b/iguana/exchanges/LP_privkey.c index 660c79290..077b880f2 100644 --- a/iguana/exchanges/LP_privkey.c +++ b/iguana/exchanges/LP_privkey.c @@ -227,7 +227,7 @@ int32_t LP_wifstr_valid(char *symbol,char *wifstr) } if ( n == 0 || A == 0 || a == 0 ) return(0); - if ( A > 10*a || a < 10*A || n < 20*a || n < 20*A ) // unlikely it is a real wif + if ( A > 5*a || a < 5*A || n < a/20 || n < A/20 ) // unlikely it is a real wif { printf("reject wif %s due to n.%d a.%d A.%d\n",wifstr,n,a,A); return(0); From c4d8e6a5fda846bef2b87c2eaa58e49118e7dddd Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 24 Jan 2018 12:02:52 +0400 Subject: [PATCH 044/183] Test --- iguana/exchanges/LP_privkey.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_privkey.c b/iguana/exchanges/LP_privkey.c index 077b880f2..e5731545d 100644 --- a/iguana/exchanges/LP_privkey.c +++ b/iguana/exchanges/LP_privkey.c @@ -227,9 +227,9 @@ int32_t LP_wifstr_valid(char *symbol,char *wifstr) } if ( n == 0 || A == 0 || a == 0 ) return(0); - if ( A > 5*a || a < 5*A || n < a/20 || n < A/20 ) // unlikely it is a real wif + if ( A > 5*a || a < 5*A || a > n*20 || A > n*20 ) // unlikely it is a real wif { - printf("reject wif %s due to n.%d a.%d A.%d\n",wifstr,n,a,A); + printf("reject wif %s due to n.%d a.%d A.%d (%d %d %d %d)\n",wifstr,n,a,A,A > 5*a,a < 5*A,a > n*20,A > n*20); return(0); } bitcoin_wif2priv(symbol,0,&wiftype,&privkey,wifstr); From f69335e9b93479aba2cb39cca6b9d92e3b748923 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 24 Jan 2018 12:03:55 +0400 Subject: [PATCH 045/183] Test --- iguana/exchanges/LP_privkey.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_privkey.c b/iguana/exchanges/LP_privkey.c index e5731545d..f74a5a45a 100644 --- a/iguana/exchanges/LP_privkey.c +++ b/iguana/exchanges/LP_privkey.c @@ -227,7 +227,7 @@ int32_t LP_wifstr_valid(char *symbol,char *wifstr) } if ( n == 0 || A == 0 || a == 0 ) return(0); - if ( A > 5*a || a < 5*A || a > n*20 || A > n*20 ) // unlikely it is a real wif + if ( A > 5*a || a > 5*A || a > n*20 || A > n*20 ) // unlikely it is a real wif { printf("reject wif %s due to n.%d a.%d A.%d (%d %d %d %d)\n",wifstr,n,a,A,A > 5*a,a < 5*A,a > n*20,A > n*20); return(0); From 4ab470f4c2780781259d40f1748f16fc7d08d216 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 24 Jan 2018 12:18:21 +0400 Subject: [PATCH 046/183] Test --- iguana/exchanges/LP_privkey.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_privkey.c b/iguana/exchanges/LP_privkey.c index f74a5a45a..3b72a5142 100644 --- a/iguana/exchanges/LP_privkey.c +++ b/iguana/exchanges/LP_privkey.c @@ -282,7 +282,7 @@ bits256 LP_privkeycalc(void *ctx,uint8_t *pubkey33,bits256 *pubkeyp,struct iguan bitcoin_priv2wif(coin->symbol,coin->wiftaddr,tmpstr,privkey,tmptype); if ( strcmp(tmpstr,wifstr) != 0 ) { - printf("error reproducing the wifstr, likely edge case like non-supported uncompressed pubkey\n"); + char str[65]; printf("error reproducing the wifstr, likely edge case like non-supported uncompressed pubkey privkey.%s\n",bits256_str(str,privkey)); exit(1); } tmpkey = privkey; From f190e18699f87368b28088c7cd951f9715b0b353 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 24 Jan 2018 12:27:27 +0400 Subject: [PATCH 047/183] Test --- iguana/exchanges/LP_bitcoin.c | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/iguana/exchanges/LP_bitcoin.c b/iguana/exchanges/LP_bitcoin.c index 79ea96189..9d3e1dff8 100644 --- a/iguana/exchanges/LP_bitcoin.c +++ b/iguana/exchanges/LP_bitcoin.c @@ -2217,24 +2217,17 @@ int32_t bitcoin_wif2priv(char *symbol,uint8_t wiftaddr,uint8_t *addrtypep,bits25 if ( (len= bitcoin_base58decode(buf,wifstr)) >= 4 ) { if ( len >= 32+offset ) + { memcpy(privkeyp,buf+offset,32); + if ( len > 32+offset ) + printf("wif: extra byte %d len.%d vs %d\n",buf[32+offset],len,32+offset); + } else { //printf("wif %s -> buf too short len.%d\n",wifstr,len); return(-1); } ptr = buf; - /*if ( len < 38 ) - { - memset(pbuf,0,sizeof(pbuf)); - memcpy(pbuf,buf,len-4); - memcpy(&pbuf[34],&buf[len-4],4); - ptr = pbuf; - int32_t i; for (i=0; i<38; i++) - printf("%02x ",pbuf[i]); - printf("pbuf from %d\n",len); - len = 38; - }*/ hash = bits256_calcaddrhash(symbol,ptr,len - 4); *addrtypep = (wiftaddr == 0) ? *ptr : ptr[1]; if ( strcmp(symbol,"GRS") != 0 && (ptr[len - 4]&0xff) == hash.bytes[31] && (ptr[len - 3]&0xff) == hash.bytes[30] &&(ptr[len - 2]&0xff) == hash.bytes[29] && (ptr[len - 1]&0xff) == hash.bytes[28] ) From 5dc3ed29a5f17c7b658c2f1aa9b3847ce343cb2c Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 24 Jan 2018 12:30:33 +0400 Subject: [PATCH 048/183] Test --- iguana/exchanges/LP_bitcoin.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_bitcoin.c b/iguana/exchanges/LP_bitcoin.c index 9d3e1dff8..4b4580902 100644 --- a/iguana/exchanges/LP_bitcoin.c +++ b/iguana/exchanges/LP_bitcoin.c @@ -2220,7 +2220,7 @@ int32_t bitcoin_wif2priv(char *symbol,uint8_t wiftaddr,uint8_t *addrtypep,bits25 { memcpy(privkeyp,buf+offset,32); if ( len > 32+offset ) - printf("wif: extra byte %d len.%d vs %d\n",buf[32+offset],len,32+offset); + printf("wif: extra byte %d len.%d vs %d addrtype.%d\n",buf[32+offset],len,32+offset,(wiftaddr == 0) ? buf[0] : buf[1]); } else { From 7b7153156e1ad387e540ec5a2dbfa93cfedb0d0b Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 24 Jan 2018 12:33:53 +0400 Subject: [PATCH 049/183] Test --- iguana/exchanges/LP_privkey.c | 1 + 1 file changed, 1 insertion(+) diff --git a/iguana/exchanges/LP_privkey.c b/iguana/exchanges/LP_privkey.c index 3b72a5142..4e897bcea 100644 --- a/iguana/exchanges/LP_privkey.c +++ b/iguana/exchanges/LP_privkey.c @@ -282,6 +282,7 @@ bits256 LP_privkeycalc(void *ctx,uint8_t *pubkey33,bits256 *pubkeyp,struct iguan bitcoin_priv2wif(coin->symbol,coin->wiftaddr,tmpstr,privkey,tmptype); if ( strcmp(tmpstr,wifstr) != 0 ) { + bitcoin_wif2priv(coin->symbol,coin->wiftaddr,&tmptype,&privkey,tmpstr); char str[65]; printf("error reproducing the wifstr, likely edge case like non-supported uncompressed pubkey privkey.%s\n",bits256_str(str,privkey)); exit(1); } From fc01c80acc1cfc6a32dfabf2ce83af7b277f2761 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 24 Jan 2018 12:37:54 +0400 Subject: [PATCH 050/183] Test --- iguana/exchanges/LP_privkey.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_privkey.c b/iguana/exchanges/LP_privkey.c index 4e897bcea..54eb78e69 100644 --- a/iguana/exchanges/LP_privkey.c +++ b/iguana/exchanges/LP_privkey.c @@ -278,7 +278,7 @@ bits256 LP_privkeycalc(void *ctx,uint8_t *pubkey33,bits256 *pubkeyp,struct iguan } else { - bitcoin_wif2priv(coin->symbol,coin->wiftaddr,&tmptype,&privkey,wifstr); + bitcoin_wif2priv(coin->symbol,0,&tmptype,&privkey,wifstr); bitcoin_priv2wif(coin->symbol,coin->wiftaddr,tmpstr,privkey,tmptype); if ( strcmp(tmpstr,wifstr) != 0 ) { From 9d4a47b5f052fbe8749b42d0a2c9d9237a9d39ec Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 24 Jan 2018 12:42:51 +0400 Subject: [PATCH 051/183] Test --- iguana/exchanges/LP_bitcoin.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_bitcoin.c b/iguana/exchanges/LP_bitcoin.c index 4b4580902..e89772438 100644 --- a/iguana/exchanges/LP_bitcoin.c +++ b/iguana/exchanges/LP_bitcoin.c @@ -2220,11 +2220,12 @@ int32_t bitcoin_wif2priv(char *symbol,uint8_t wiftaddr,uint8_t *addrtypep,bits25 { memcpy(privkeyp,buf+offset,32); if ( len > 32+offset ) - printf("wif: extra byte %d len.%d vs %d addrtype.%d\n",buf[32+offset],len,32+offset,(wiftaddr == 0) ? buf[0] : buf[1]); + printf("wif %s: extra byte %d len.%d vs %d addrtype.%d\n",wifstr,buf[32+offset],len,32+offset,(wiftaddr == 0) ? buf[0] : buf[1]); + else printf("%s is for uncompressed\n",wifstr); } else { - //printf("wif %s -> buf too short len.%d\n",wifstr,len); + printf("wif %s -> buf too short len.%d\n",wifstr,len); return(-1); } ptr = buf; From 42b7b5c02a1f263929f51290b2b3c4df805d912d Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 24 Jan 2018 12:49:53 +0400 Subject: [PATCH 052/183] Test --- iguana/exchanges/LP_bitcoin.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_bitcoin.c b/iguana/exchanges/LP_bitcoin.c index e89772438..87085839c 100644 --- a/iguana/exchanges/LP_bitcoin.c +++ b/iguana/exchanges/LP_bitcoin.c @@ -2281,7 +2281,7 @@ int32_t bitcoin_priv2wif(char *symbol,uint8_t wiftaddr,char *wifstr,bits256 priv memcpy(data+offset,privkey.bytes,len); data[offset + len++] = 1; len = base58encode_checkbuf(symbol,wiftaddr,addrtype,data,len); - if ( bitcoin_base58encode(wifstr,data,len) == 0 ) + if ( bitcoin_base58encode(wifstr,data,len+offset) == 0 ) { char str[65]; printf("error making wif from %s\n",bits256_str(str,privkey)); return(-1); From d2de491155f78aea256275a3a247e80507821df3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 24 Jan 2018 12:52:11 +0400 Subject: [PATCH 053/183] Test --- iguana/exchanges/LP_bitcoin.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_bitcoin.c b/iguana/exchanges/LP_bitcoin.c index 87085839c..2c141bb70 100644 --- a/iguana/exchanges/LP_bitcoin.c +++ b/iguana/exchanges/LP_bitcoin.c @@ -2281,12 +2281,12 @@ int32_t bitcoin_priv2wif(char *symbol,uint8_t wiftaddr,char *wifstr,bits256 priv memcpy(data+offset,privkey.bytes,len); data[offset + len++] = 1; len = base58encode_checkbuf(symbol,wiftaddr,addrtype,data,len); - if ( bitcoin_base58encode(wifstr,data,len+offset) == 0 ) + if ( bitcoin_base58encode(wifstr,data,len) == 0 ) // skips last byte? { char str[65]; printf("error making wif from %s\n",bits256_str(str,privkey)); return(-1); } - if ( 0 ) + if ( 1 ) { uint8_t checktype; bits256 checkpriv; char str[65],str2[65]; if ( bitcoin_wif2priv(symbol,wiftaddr,&checktype,&checkpriv,wifstr) == sizeof(bits256) ) From ccaf4273d75ce2b1460950e8fd67cdb57e563fa3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 24 Jan 2018 12:55:26 +0400 Subject: [PATCH 054/183] Test --- iguana/exchanges/LP_privkey.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_privkey.c b/iguana/exchanges/LP_privkey.c index 54eb78e69..8465045b1 100644 --- a/iguana/exchanges/LP_privkey.c +++ b/iguana/exchanges/LP_privkey.c @@ -283,7 +283,7 @@ bits256 LP_privkeycalc(void *ctx,uint8_t *pubkey33,bits256 *pubkeyp,struct iguan if ( strcmp(tmpstr,wifstr) != 0 ) { bitcoin_wif2priv(coin->symbol,coin->wiftaddr,&tmptype,&privkey,tmpstr); - char str[65]; printf("error reproducing the wifstr, likely edge case like non-supported uncompressed pubkey privkey.%s\n",bits256_str(str,privkey)); + char str[65]; printf("%s error reproducing the wifstr, likely edge case like non-supported uncompressed pubkey privkey.%s\n",coin->symbol,bits256_str(str,privkey)); exit(1); } tmpkey = privkey; From ab3d29a39cc0de0e868e51121bd1620c7f0b883e Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 24 Jan 2018 12:58:52 +0400 Subject: [PATCH 055/183] Test --- iguana/exchanges/LP_bitcoin.c | 2 +- iguana/exchanges/LP_privkey.c | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/iguana/exchanges/LP_bitcoin.c b/iguana/exchanges/LP_bitcoin.c index 2c141bb70..b26d2c0fa 100644 --- a/iguana/exchanges/LP_bitcoin.c +++ b/iguana/exchanges/LP_bitcoin.c @@ -2286,7 +2286,7 @@ int32_t bitcoin_priv2wif(char *symbol,uint8_t wiftaddr,char *wifstr,bits256 priv char str[65]; printf("error making wif from %s\n",bits256_str(str,privkey)); return(-1); } - if ( 1 ) + if ( 0 ) { uint8_t checktype; bits256 checkpriv; char str[65],str2[65]; if ( bitcoin_wif2priv(symbol,wiftaddr,&checktype,&checkpriv,wifstr) == sizeof(bits256) ) diff --git a/iguana/exchanges/LP_privkey.c b/iguana/exchanges/LP_privkey.c index 8465045b1..c86edfde9 100644 --- a/iguana/exchanges/LP_privkey.c +++ b/iguana/exchanges/LP_privkey.c @@ -278,13 +278,16 @@ bits256 LP_privkeycalc(void *ctx,uint8_t *pubkey33,bits256 *pubkeyp,struct iguan } else { - bitcoin_wif2priv(coin->symbol,0,&tmptype,&privkey,wifstr); + bitcoin_wif2priv(coin->symbol,coin->wiftaddr,&tmptype,&privkey,wifstr); bitcoin_priv2wif(coin->symbol,coin->wiftaddr,tmpstr,privkey,tmptype); if ( strcmp(tmpstr,wifstr) != 0 ) { - bitcoin_wif2priv(coin->symbol,coin->wiftaddr,&tmptype,&privkey,tmpstr); - char str[65]; printf("%s error reproducing the wifstr, likely edge case like non-supported uncompressed pubkey privkey.%s\n",coin->symbol,bits256_str(str,privkey)); - exit(1); + bitcoin_wif2priv(coin->symbol,coin->wiftaddr,&tmptype,&tmpkey,tmpstr); + if ( bits256_cmp(tmpkey,privkey) != 0 ) + { + char str[65]; printf("%s error reproducing the wifstr, likely edge case like non-supported uncompressed pubkey privkey.%s\n",coin->symbol,bits256_str(str,privkey)); + exit(1); + } } tmpkey = privkey; nxtaddr = conv_NXTpassword(tmpkey.bytes,pubkeyp->bytes,0,0); From b17d0bac7db6707e05ee3e4db6e15559dade3064 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 24 Jan 2018 12:59:58 +0400 Subject: [PATCH 056/183] Test --- iguana/exchanges/LP_bitcoin.c | 4 ++-- iguana/exchanges/LP_privkey.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/iguana/exchanges/LP_bitcoin.c b/iguana/exchanges/LP_bitcoin.c index b26d2c0fa..fadd13779 100644 --- a/iguana/exchanges/LP_bitcoin.c +++ b/iguana/exchanges/LP_bitcoin.c @@ -2219,9 +2219,9 @@ int32_t bitcoin_wif2priv(char *symbol,uint8_t wiftaddr,uint8_t *addrtypep,bits25 if ( len >= 32+offset ) { memcpy(privkeyp,buf+offset,32); - if ( len > 32+offset ) + /*if ( len > 32+offset ) printf("wif %s: extra byte %d len.%d vs %d addrtype.%d\n",wifstr,buf[32+offset],len,32+offset,(wiftaddr == 0) ? buf[0] : buf[1]); - else printf("%s is for uncompressed\n",wifstr); + else printf("%s is for uncompressed\n",wifstr);*/ } else { diff --git a/iguana/exchanges/LP_privkey.c b/iguana/exchanges/LP_privkey.c index c86edfde9..9beebd8c4 100644 --- a/iguana/exchanges/LP_privkey.c +++ b/iguana/exchanges/LP_privkey.c @@ -236,7 +236,7 @@ int32_t LP_wifstr_valid(char *symbol,char *wifstr) bitcoin_priv2wif(symbol,0,cmpstr,privkey,wiftype); if ( strcmp(cmpstr,wifstr) == 0 ) { - printf("%s is valid wif\n",wifstr); + //printf("%s is valid wif\n",wifstr); return(1); } else if ( bits256_nonz(privkey) != 0 ) From 4b4612848c27ecf1374b99cb6df10b346e71022c Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 24 Jan 2018 13:02:22 +0400 Subject: [PATCH 057/183] Test --- iguana/exchanges/LP_privkey.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_privkey.c b/iguana/exchanges/LP_privkey.c index 9beebd8c4..33aa2f1d6 100644 --- a/iguana/exchanges/LP_privkey.c +++ b/iguana/exchanges/LP_privkey.c @@ -243,9 +243,9 @@ int32_t LP_wifstr_valid(char *symbol,char *wifstr) { bitcoin_wif2priv(symbol,0,&wiftype,&cmpkey,cmpstr); bitcoin_priv2wiflong(symbol,0,cmpstr2,privkey,wiftype); - char str[65],str2[65]; printf("mismatched wifstr %s -> %s -> %s %s %s\n",wifstr,bits256_str(str,privkey),cmpstr,bits256_str(str2,cmpkey),cmpstr2); if ( bits256_cmp(privkey,cmpkey) == 0 ) return(1); + char str[65],str2[65]; printf("%s mismatched wifstr %s -> %s -> %s %s %s\n",symbol,wifstr,bits256_str(str,privkey),cmpstr,bits256_str(str2,cmpkey),cmpstr2); } char str[65]; printf("%s is not a wif, privkey.%s\n",wifstr,bits256_str(str,privkey)); return(0); From 8bda82c57d71288bbd93b7082fe77994c5c713ff Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 24 Jan 2018 13:14:14 +0400 Subject: [PATCH 058/183] Test --- iguana/exchanges/LP_coins.c | 2 +- iguana/exchanges/LP_include.h | 4 ++-- iguana/exchanges/LP_nativeDEX.c | 9 ++++----- iguana/exchanges/LP_peers.c | 10 +++++----- 4 files changed, 12 insertions(+), 13 deletions(-) diff --git a/iguana/exchanges/LP_coins.c b/iguana/exchanges/LP_coins.c index 07be2166b..4134936bf 100644 --- a/iguana/exchanges/LP_coins.c +++ b/iguana/exchanges/LP_coins.c @@ -368,7 +368,7 @@ uint16_t LP_coininit(struct iguana_info *coin,char *symbol,char *name,char *asse coin->p2shtype = p2shtype; coin->wiftype = wiftype; coin->inactive = (uint32_t)time(NULL); - coin->bussock = LP_coinbus(busport); + //coin->bussock = LP_coinbus(busport); if ( ctx == 0 ) ctx = bitcoin_ctx(); coin->ctx = ctx; diff --git a/iguana/exchanges/LP_include.h b/iguana/exchanges/LP_include.h index 6705e8e6d..2cae0f44c 100644 --- a/iguana/exchanges/LP_include.h +++ b/iguana/exchanges/LP_include.h @@ -299,7 +299,7 @@ struct iguana_info UT_hash_handle hh; portable_mutex_t txmutex,addrmutex; struct LP_transaction *transactions; struct LP_address *addresses; uint64_t txfee; - int32_t numutxos,notarized,longestchain,firstrefht,firstscanht,lastscanht,bussock,height; uint16_t busport; + int32_t numutxos,notarized,longestchain,firstrefht,firstscanht,lastscanht,height; uint16_t busport; uint32_t txversion,dPoWtime,loadedcache,electrumlist,lastunspent,importedprivkey,lastpushtime,lastutxosync,addr_listunspent_requested,lastutxos,updaterate,counter,inactive,lastmempool,lastgetinfo,ratetime,heighttime,lastmonitor,obooktime; uint8_t pubtype,p2shtype,isPoS,wiftype,wiftaddr,taddr,noimportprivkey_flag,userconfirms,isassetchain,maxconfirms; char symbol[128],smartaddr[64],userpass[1024],serverport[128],instantdex_address[64]; @@ -487,7 +487,7 @@ int64_t LP_listunspent_parseitem(struct iguana_info *coin,bits256 *txidp,int32_t void LP_unspents_cache(char *symbol,char *addr,char *arraystr,int32_t updatedflag); uint16_t LP_psock_get(char *connectaddr,char *publicaddr,int32_t ispaired); //void LP_utxo_clientpublish(struct LP_utxoinfo *utxo); -int32_t LP_coinbus(uint16_t coin_busport); +//int32_t LP_coinbus(uint16_t coin_busport); int32_t LP_nanomsg_recvs(void *ctx); int32_t LP_numconfirms(char *symbol,char *coinaddr,bits256 txid,int32_t vout,int32_t mempool); void LP_aliceid(uint32_t tradeid,uint64_t aliceid,char *event,uint32_t requestid,uint32_t quoteid); diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 8d189f74f..8cbdad5de 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -100,7 +100,7 @@ struct LP_trade *LP_trades,*LP_tradesQ; //uint32_t LP_deadman_switch; uint16_t LP_fixed_pairport,LP_publicport; uint32_t LP_lastnonce,LP_swap_endcritical,LP_swap_critical,LP_RTcount,LP_swapscount; -int32_t LP_STOP_RECEIVED,LP_numactive_LP,LP_mybussock = -1; +int32_t LP_STOP_RECEIVED,LP_numactive_LP;//,LP_mybussock = -1; int32_t LP_mypubsock = -1; int32_t LP_mypullsock = -1; int32_t LP_numfinished,LP_showwif,IAMLP = 0; @@ -1274,15 +1274,14 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu exit(-1); } LP_initcoins(ctx,pubsock,coinsjson); + RPC_port = myport; G.waiting = 1; - printf("got %s, initpeers. LP_mypubsock.%d\n",myipaddr,LP_mypubsock); + printf("got %s, initpeers. LP_mypubsock.%d/%d myport.%u mypullport.%d mypubport.%d pushaddr.%s\n",myipaddr,LP_mypubsock,pubsock,myport,mypullport,mypubport,pushaddr); LP_initpeers(pubsock,mypeer,myipaddr,myport,jstr(argjson,"seednode"),mypullport,mypubport); - RPC_port = myport; LP_mypullsock = LP_initpublicaddr(ctx,&mypullport,pushaddr,myipaddr,mypullport,0); strcpy(LP_publicaddr,pushaddr); LP_publicport = mypullport; - LP_mybussock = LP_coinbus(mybusport); - //LP_deadman_switch = (uint32_t)time(NULL); + //LP_mybussock = LP_coinbus(mybusport); printf("canbind.%d my command address is (%s) pullsock.%d pullport.%u\n",LP_canbind,pushaddr,LP_mypullsock,mypullport); LP_passphrase_init(passphrase,jstr(argjson,"gui"),juint(argjson,"netid"),jstr(argjson,"seednode")); #ifndef FROM_JS diff --git a/iguana/exchanges/LP_peers.c b/iguana/exchanges/LP_peers.c index 782bf90ed..193dfac6f 100644 --- a/iguana/exchanges/LP_peers.c +++ b/iguana/exchanges/LP_peers.c @@ -156,9 +156,9 @@ struct LP_peerinfo *LP_addpeer(struct LP_peerinfo *mypeer,int32_t mypubsock,char printf("_LPaddpeer %s -> numpeers.%d mypubsock.%d other.(%d)\n",ipaddr,mypeer->numpeers,mypubsock,isLP); } else peer->numpeers = 1; // will become mypeer portable_mutex_unlock(&LP_peermutex); - if ( IAMLP != 0 && mypubsock >= 0 ) + /*if ( IAMLP != 0 && mypubsock >= 0 ) { - struct iguana_info *coin,*ctmp; char busaddr[64]; // + //struct iguana_info *coin,*ctmp; char busaddr[64]; // //memset(zero.bytes,0,sizeof(zero)); //LP_send(mypubsock,msg,(int32_t)strlen(msg)+1,1); //LP_reserved_msg(0,"","",zero,jprint(LP_peerjson(peer),1)); @@ -173,14 +173,14 @@ struct LP_peerinfo *LP_addpeer(struct LP_peerinfo *mypeer,int32_t mypubsock,char } } } - } + }*/ } else printf("%s invalid pushsock.%d or subsock.%d\n",peer->ipaddr,peer->pushsock,peer->subsock); } } else printf("LP_addpeer: checkip.(%s) vs (%s)\n",checkip,ipaddr); return(peer); } -int32_t LP_coinbus(uint16_t coin_busport) +/*int32_t LP_coinbus(uint16_t coin_busport) { struct LP_peerinfo *peer,*tmp; char busaddr[64]; int32_t timeout,bussock = -1; return(-1); @@ -208,7 +208,7 @@ int32_t LP_coinbus(uint16_t coin_busport) } } return(bussock); -} +}*/ void LP_peer_recv(char *ipaddr,int32_t ismine) { From 42e6b36b52d05010f9712a284455af239a25cad5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 24 Jan 2018 13:16:34 +0400 Subject: [PATCH 059/183] Test --- iguana/exchanges/LP_nativeDEX.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 8cbdad5de..3df46b912 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -1276,13 +1276,12 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu LP_initcoins(ctx,pubsock,coinsjson); RPC_port = myport; G.waiting = 1; - printf("got %s, initpeers. LP_mypubsock.%d/%d myport.%u mypullport.%d mypubport.%d pushaddr.%s\n",myipaddr,LP_mypubsock,pubsock,myport,mypullport,mypubport,pushaddr); LP_initpeers(pubsock,mypeer,myipaddr,myport,jstr(argjson,"seednode"),mypullport,mypubport); LP_mypullsock = LP_initpublicaddr(ctx,&mypullport,pushaddr,myipaddr,mypullport,0); strcpy(LP_publicaddr,pushaddr); LP_publicport = mypullport; //LP_mybussock = LP_coinbus(mybusport); - printf("canbind.%d my command address is (%s) pullsock.%d pullport.%u\n",LP_canbind,pushaddr,LP_mypullsock,mypullport); + printf("got %s, initpeers. LP_mypubsock.%d/%d myport.%u mypullport.%d mypubport.%d pushaddr.%s\n",myipaddr,LP_mypubsock,pubsock,myport,mypullport,mypubport,pushaddr); LP_passphrase_init(passphrase,jstr(argjson,"gui"),juint(argjson,"netid"),jstr(argjson,"seednode")); #ifndef FROM_JS if ( IAMLP != 0 && OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_psockloop,(void *)myipaddr) != 0 ) From bb815b2d410446a8b8b5049e9f3b650192f6da8c Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 24 Jan 2018 13:31:17 +0400 Subject: [PATCH 060/183] Test --- iguana/exchanges/LP_nativeDEX.c | 8 ++++---- iguana/exchanges/LP_network.c | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 3df46b912..8faa32253 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -98,7 +98,7 @@ struct LP_address_utxo *LP_garbage_collector2; struct LP_trade *LP_trades,*LP_tradesQ; //uint32_t LP_deadman_switch; -uint16_t LP_fixed_pairport,LP_publicport; +uint16_t LP_fixed_pairport;//,LP_publicport; uint32_t LP_lastnonce,LP_swap_endcritical,LP_swap_critical,LP_RTcount,LP_swapscount; int32_t LP_STOP_RECEIVED,LP_numactive_LP;//,LP_mybussock = -1; int32_t LP_mypubsock = -1; @@ -252,7 +252,7 @@ char *LP_process_message(void *ctx,char *typestr,char *myipaddr,int32_t pubsock, dup++; else uniq++; portable_mutex_lock(&LP_commandmutex); - if ( (LP_rand() % 10000) == 0 ) + if ( (LP_rand() % 100000) == 0 ) printf("%s dup.%d (%u / %u) %.1f%% encrypted.%d recv.%u [%02x %02x] vs %02x %02x\n",typestr,duplicate,dup,dup+uniq,(double)100*dup/(dup+uniq),encrypted,crc32,ptr[0],ptr[1],crc32&0xff,(crc32>>8)&0xff); if ( duplicate == 0 ) { @@ -1279,9 +1279,9 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu LP_initpeers(pubsock,mypeer,myipaddr,myport,jstr(argjson,"seednode"),mypullport,mypubport); LP_mypullsock = LP_initpublicaddr(ctx,&mypullport,pushaddr,myipaddr,mypullport,0); strcpy(LP_publicaddr,pushaddr); - LP_publicport = mypullport; + //LP_publicport = mypullport; //LP_mybussock = LP_coinbus(mybusport); - printf("got %s, initpeers. LP_mypubsock.%d/%d myport.%u mypullport.%d mypubport.%d pushaddr.%s\n",myipaddr,LP_mypubsock,pubsock,myport,mypullport,mypubport,pushaddr); + printf("got %s, initpeers. LP_mypubsock.%d/%d pullsock.%d myport.%u mypullport.%d mypubport.%d pushaddr.%s\n",myipaddr,LP_mypubsock,pubsock,LP_mypullsock,myport,mypullport,mypubport,pushaddr); LP_passphrase_init(passphrase,jstr(argjson,"gui"),juint(argjson,"netid"),jstr(argjson,"seednode")); #ifndef FROM_JS if ( IAMLP != 0 && OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_psockloop,(void *)myipaddr) != 0 ) diff --git a/iguana/exchanges/LP_network.c b/iguana/exchanges/LP_network.c index 1a7fefeb3..ee6b847ed 100644 --- a/iguana/exchanges/LP_network.c +++ b/iguana/exchanges/LP_network.c @@ -738,7 +738,7 @@ int32_t LP_initpublicaddr(void *ctx,uint16_t *mypullportp,char *publicaddr,char *mypullportp = 0; if ( ispaired == 0 ) { - strcpy(publicaddr,"127.0.0.1"); + sprintf(publicaddr,"127.0.0.1:%u",mypullport); return(-1); } while ( *mypullportp == 0 ) From c201e31b95ec9eab7b58cad5d64e77cd8afec0ae Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 24 Jan 2018 13:37:43 +0400 Subject: [PATCH 061/183] Test --- iguana/exchanges/jpg | 2 ++ 1 file changed, 2 insertions(+) create mode 100755 iguana/exchanges/jpg diff --git a/iguana/exchanges/jpg b/iguana/exchanges/jpg new file mode 100755 index 000000000..fd5685554 --- /dev/null +++ b/iguana/exchanges/jpg @@ -0,0 +1,2 @@ +source userpass +curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"jpg\",\"srcfile\":\"utxos.jpg\",\"destfile\":\"utxosdest.jpg\",\"power2\":3,\"passphrase\":\"default\",\"data\":\"68656c6c6f20776f726c64\",\"required\":\"required\"}" From ca758828494476ebf8fafbfb8af72c7f17a75217 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 24 Jan 2018 13:39:19 +0400 Subject: [PATCH 062/183] Test --- iguana/exchanges/LP_privkey.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_privkey.c b/iguana/exchanges/LP_privkey.c index 33aa2f1d6..96ae28272 100644 --- a/iguana/exchanges/LP_privkey.c +++ b/iguana/exchanges/LP_privkey.c @@ -209,7 +209,7 @@ int32_t LP_wifstr_valid(char *symbol,char *wifstr) bits256 privkey,cmpkey; uint8_t wiftype; char cmpstr[128],cmpstr2[128]; int32_t i,len,n,a,A; if ( (len= (int32_t)strlen(wifstr)) < 50 || len > 54 ) { - printf("len.%d is wrong for wif %s\n",len,wifstr); + //printf("len.%d is wrong for wif %s\n",len,wifstr); return(0); } memset(privkey.bytes,0,sizeof(privkey)); From 8ae065141ab60768fff5c9bffdea3a078af17df0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 24 Jan 2018 13:42:12 +0400 Subject: [PATCH 063/183] Test --- iguana/exchanges/LP_privkey.c | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/iguana/exchanges/LP_privkey.c b/iguana/exchanges/LP_privkey.c index 96ae28272..246d961b3 100644 --- a/iguana/exchanges/LP_privkey.c +++ b/iguana/exchanges/LP_privkey.c @@ -443,9 +443,11 @@ int32_t LP_jpg_process(int32_t *capacityp,char *inputfname,char *outputfname,uin limit <<= 1; power2--; } - if ((input_file = fopen(inputfname, READ_BINARY)) == NULL) { + if ((input_file = fopen(inputfname, READ_BINARY)) == NULL) + { fprintf(stderr, "Can't open %s\n", inputfname); - exit(EXIT_FAILURE); + //exit(EXIT_FAILURE); + return(-1); } // Initialize the JPEG compression and decompression objects with default error handling inputinfo.err = jpeg_std_error(&jerr); @@ -569,7 +571,6 @@ char *LP_jpg(char *srcfile,char *destfile,int32_t power2,char *passphrase,char * if ( srcfile != 0 && srcfile[0] != 0 ) { retjson = cJSON_CreateObject(); - jaddstr(retjson,"result","success"); if ( datastr != 0 && datastr[0] != 0 ) { if ( (len= is_hexstr(datastr,0)) > 0 ) @@ -581,14 +582,19 @@ char *LP_jpg(char *srcfile,char *destfile,int32_t power2,char *passphrase,char * } } if ( required > 0 ) - decoded = calloc(1,len); - modified = LP_jpg_process(&capacity,srcfile,destfile,decoded,data,required,power2,passphrase); - jaddnum(retjson,"modifiedrows",modified); - if ( modified != 0 ) - jaddstr(retjson,"outputfile",destfile); - jaddnum(retjson,"power2",power2); - jaddnum(retjson,"capacity",capacity); - jaddnum(retjson,"required",required); + decoded = calloc(1,len+required); + if ( (modified= LP_jpg_process(&capacity,srcfile,destfile,decoded,data,required,power2,passphrase)) < 0 ) + jaddstr(retjson,"error","file not found"); + else + { + jaddstr(retjson,"result","success"); + jaddnum(retjson,"modifiedrows",modified); + if ( modified != 0 ) + jaddstr(retjson,"outputfile",destfile); + jaddnum(retjson,"power2",power2); + jaddnum(retjson,"capacity",capacity); + jaddnum(retjson,"required",required); + } if ( decoded != 0 ) { decodedstr = calloc(1,len*2+1); From ce321e887061341c7eabb63e0e0835b5fe25656b Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 24 Jan 2018 13:48:04 +0400 Subject: [PATCH 064/183] Test --- crypto777/jpeg/unix/jmemname.c | 2 +- iguana/exchanges/LP_privkey.c | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/crypto777/jpeg/unix/jmemname.c b/crypto777/jpeg/unix/jmemname.c index fd09935aa..e6a89ea11 100755 --- a/crypto777/jpeg/unix/jmemname.c +++ b/crypto777/jpeg/unix/jmemname.c @@ -70,7 +70,7 @@ extern void free JPP((void *ptr)); */ #ifndef TEMP_DIRECTORY /* can override from jconfig.h or Makefile */ -#define TEMP_DIRECTORY "/usr/tmp/" /* recommended setting for Unix */ +#define TEMP_DIRECTORY "/tmp/" /* recommended setting for Unix */ #endif static int next_file_num; /* to distinguish among several temp files */ diff --git a/iguana/exchanges/LP_privkey.c b/iguana/exchanges/LP_privkey.c index 246d961b3..95595ef05 100644 --- a/iguana/exchanges/LP_privkey.c +++ b/iguana/exchanges/LP_privkey.c @@ -597,10 +597,13 @@ char *LP_jpg(char *srcfile,char *destfile,int32_t power2,char *passphrase,char * } if ( decoded != 0 ) { - decodedstr = calloc(1,len*2+1); - init_hexbytes_noT(decodedstr,decoded,len); - jaddstr(retjson,"decoded",decodedstr); - free(decodedstr); + if ( capacity > 0 ) + { + decodedstr = calloc(1,len*2+1); + init_hexbytes_noT(decodedstr,decoded,len); + jaddstr(retjson,"decoded",decodedstr); + free(decodedstr); + } free(decoded); } if ( data != 0 ) From 123e588ab39b2829d2b0b0f8f97fc24e635eaf46 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 24 Jan 2018 13:52:07 +0400 Subject: [PATCH 065/183] Test --- crypto777/jpeg/unix/jmemname.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/crypto777/jpeg/unix/jmemname.c b/crypto777/jpeg/unix/jmemname.c index e6a89ea11..b738d4f21 100755 --- a/crypto777/jpeg/unix/jmemname.c +++ b/crypto777/jpeg/unix/jmemname.c @@ -70,8 +70,12 @@ extern void free JPP((void *ptr)); */ #ifndef TEMP_DIRECTORY /* can override from jconfig.h or Makefile */ +#ifdef _WIN32 +#define TEMP_DIRECTORY "" /* recommended setting for Unix */ +#else #define TEMP_DIRECTORY "/tmp/" /* recommended setting for Unix */ #endif +#endif static int next_file_num; /* to distinguish among several temp files */ From d7146093ac2aa16e1b181670888bfda125939295 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 24 Jan 2018 13:54:59 +0400 Subject: [PATCH 066/183] Test --- iguana/exchanges/LP_privkey.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_privkey.c b/iguana/exchanges/LP_privkey.c index 95595ef05..d56f759a5 100644 --- a/iguana/exchanges/LP_privkey.c +++ b/iguana/exchanges/LP_privkey.c @@ -599,8 +599,8 @@ char *LP_jpg(char *srcfile,char *destfile,int32_t power2,char *passphrase,char * { if ( capacity > 0 ) { - decodedstr = calloc(1,len*2+1); - init_hexbytes_noT(decodedstr,decoded,len); + decodedstr = calloc(1,required/8+1); + init_hexbytes_noT(decodedstr,decoded,required/8+1); jaddstr(retjson,"decoded",decodedstr); free(decodedstr); } From bdf75bcc81f64810deeb7b5bc7397beafd19143a Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 24 Jan 2018 13:57:02 +0400 Subject: [PATCH 067/183] Test --- iguana/exchanges/LP_privkey.c | 3 ++- iguana/exchanges/jpg | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_privkey.c b/iguana/exchanges/LP_privkey.c index d56f759a5..6f186e0f9 100644 --- a/iguana/exchanges/LP_privkey.c +++ b/iguana/exchanges/LP_privkey.c @@ -599,7 +599,8 @@ char *LP_jpg(char *srcfile,char *destfile,int32_t power2,char *passphrase,char * { if ( capacity > 0 ) { - decodedstr = calloc(1,required/8+1); + printf("len.%d required.%d capacity.%d\n",len,required,capacity); + decodedstr = calloc(1,(len+required)*2+1); init_hexbytes_noT(decodedstr,decoded,required/8+1); jaddstr(retjson,"decoded",decodedstr); free(decodedstr); diff --git a/iguana/exchanges/jpg b/iguana/exchanges/jpg index fd5685554..b84c7bd56 100755 --- a/iguana/exchanges/jpg +++ b/iguana/exchanges/jpg @@ -1,2 +1,3 @@ source userpass -curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"jpg\",\"srcfile\":\"utxos.jpg\",\"destfile\":\"utxosdest.jpg\",\"power2\":3,\"passphrase\":\"default\",\"data\":\"68656c6c6f20776f726c64\",\"required\":\"required\"}" +curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"jpg\",\"srcfile\":\"/root/boost_1_64_0/libs/gil/doc/doxygen/images/monkey_steps.jpg\",\"destfile\":\"dest.jpg\",\"power2\":3,\"passphrase\":\"default\",\"data\":\"68656c6c6f20776f726c64\",\"required\":11}" +curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"jpg\",\"srcfile\":\"dest.jpg\",\"power2\":3,\"passphrase\":\"default\",\"required\":11}" From dd85f65cebbced94168da4ddab6812a860e8f967 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 24 Jan 2018 13:58:22 +0400 Subject: [PATCH 068/183] Test --- iguana/exchanges/jpg | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/jpg b/iguana/exchanges/jpg index b84c7bd56..69cb6a894 100755 --- a/iguana/exchanges/jpg +++ b/iguana/exchanges/jpg @@ -1,3 +1,3 @@ source userpass -curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"jpg\",\"srcfile\":\"/root/boost_1_64_0/libs/gil/doc/doxygen/images/monkey_steps.jpg\",\"destfile\":\"dest.jpg\",\"power2\":3,\"passphrase\":\"default\",\"data\":\"68656c6c6f20776f726c64\",\"required\":11}" -curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"jpg\",\"srcfile\":\"dest.jpg\",\"power2\":3,\"passphrase\":\"default\",\"required\":11}" +curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"jpg\",\"srcfile\":\"/root/boost_1_64_0/libs/gil/doc/doxygen/images/monkey_steps.jpg\",\"destfile\":\"dest.jpg\",\"power2\":3,\"passphrase\":\"default\",\"data\":\"68656c6c6f20776f726c64\",\"required\":88}" +curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"jpg\",\"srcfile\":\"dest.jpg\",\"power2\":3,\"passphrase\":\"default\",\"required\":88}" From 6b8b50c890a6eff4f05465ddf92ffde959376588 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 24 Jan 2018 14:00:35 +0400 Subject: [PATCH 069/183] Test --- iguana/exchanges/LP_privkey.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/iguana/exchanges/LP_privkey.c b/iguana/exchanges/LP_privkey.c index 6f186e0f9..2b251174b 100644 --- a/iguana/exchanges/LP_privkey.c +++ b/iguana/exchanges/LP_privkey.c @@ -482,7 +482,7 @@ int32_t LP_jpg_process(int32_t *capacityp,char *inputfname,char *outputfname,uin for (i=0; i power2 ) + if ( val < -limit || val > limit ) { if ( decoded != 0 && (val & 1) != 0 && *capacityp < required ) decoded[*capacityp >> 3] |= (1 << (*capacityp & 7)); @@ -493,7 +493,7 @@ int32_t LP_jpg_process(int32_t *capacityp,char *inputfname,char *outputfname,uin } } } - printf("capacity %d required.%d\n",*capacityp,required); + printf("capacity %d required.%d power2.%d limit.%d\n",*capacityp,required,power2,limit); if ( *capacityp > required && outputfname != 0 && outputfname[0] != 0 ) { if ((output_file = fopen(outputfname, WRITE_BINARY)) == NULL) { @@ -515,7 +515,7 @@ int32_t LP_jpg_process(int32_t *capacityp,char *inputfname,char *outputfname,uin for (i=0; i power2 ) + if ( val < -limit || val > limit ) { val &= ~1; if ( (data[emit >> 3] & (1 << (emit&7))) != 0 ) From 2543a0ef3c9dbf1f14f5c4d41292a6559bc4b25d Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 24 Jan 2018 14:07:54 +0400 Subject: [PATCH 070/183] Test --- iguana/exchanges/LP_commands.c | 4 ++-- iguana/exchanges/LP_privkey.c | 14 +++++++++----- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/iguana/exchanges/LP_commands.c b/iguana/exchanges/LP_commands.c index 0427210b4..c9140dea9 100644 --- a/iguana/exchanges/LP_commands.c +++ b/iguana/exchanges/LP_commands.c @@ -161,7 +161,7 @@ bot_stop(botid)\n\ bot_pause(botid)\n\ instantdex_deposit(weeks, amount, broadcast=1)\n\ instantdex_claim()\n\ -jpg(srcfile, destfile, power2=7, passphrase, data="", required)\n\ +jpg(srcfile, destfile, power2=7, password, data="", required)\n\ \"}")); //sell(base, rel, price, basevolume, timeout=10, duration=3600)\n\ @@ -240,7 +240,7 @@ jpg(srcfile, destfile, power2=7, passphrase, data="", required)\n\ } else if ( strcmp(method,"jpg") == 0 ) { - return(LP_jpg(jstr(argjson,"srcfile"),jstr(argjson,"destfile"),jint(argjson,"power2"),jstr(argjson,"passphrase"),jstr(argjson,"data"),jint(argjson,"required"))); + return(LP_jpg(jstr(argjson,"srcfile"),jstr(argjson,"destfile"),jint(argjson,"power2"),jstr(argjson,"password"),jstr(argjson,"data"),jint(argjson,"required"))); } /*else if ( strcmp(method,"sendmessage") == 0 ) { diff --git a/iguana/exchanges/LP_privkey.c b/iguana/exchanges/LP_privkey.c index 2b251174b..b546fbc55 100644 --- a/iguana/exchanges/LP_privkey.c +++ b/iguana/exchanges/LP_privkey.c @@ -482,10 +482,14 @@ int32_t LP_jpg_process(int32_t *capacityp,char *inputfname,char *outputfname,uin for (i=0; i limit ) + if ( val < -8 || val > 8 ) { - if ( decoded != 0 && (val & 1) != 0 && *capacityp < required ) - decoded[*capacityp >> 3] |= (1 << (*capacityp & 7)); + if ( *capacityp < required ) + { + if ( (val & 1) != 0 ) + decoded[*capacityp >> 3] |= (1 << (*capacityp&7)); + else decoded[(*capacityp) >> 3] &= ~(1 << (*capacityp&7)); + } (*capacityp)++; } coef_buffers[compnum][rownum][blocknum][i] = val; @@ -515,10 +519,10 @@ int32_t LP_jpg_process(int32_t *capacityp,char *inputfname,char *outputfname,uin for (i=0; i limit ) + if ( val < -8 || val > 8 ) { val &= ~1; - if ( (data[emit >> 3] & (1 << (emit&7))) != 0 ) + if ( (emit < required && (data[emit >> 3] & (1 << (emit&7))) != 0) || (rand() & 1) != 0 ) val |= 1; emit++; } From 0afaf4c94b5aa3abf35322ee5fd44565f2625395 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 24 Jan 2018 14:12:27 +0400 Subject: [PATCH 071/183] Test --- iguana/exchanges/LP_privkey.c | 1 - 1 file changed, 1 deletion(-) diff --git a/iguana/exchanges/LP_privkey.c b/iguana/exchanges/LP_privkey.c index b546fbc55..df94f78e1 100644 --- a/iguana/exchanges/LP_privkey.c +++ b/iguana/exchanges/LP_privkey.c @@ -488,7 +488,6 @@ int32_t LP_jpg_process(int32_t *capacityp,char *inputfname,char *outputfname,uin { if ( (val & 1) != 0 ) decoded[*capacityp >> 3] |= (1 << (*capacityp&7)); - else decoded[(*capacityp) >> 3] &= ~(1 << (*capacityp&7)); } (*capacityp)++; } From 0594f8cb517db16eb7f828b0fc8ba4f678c5ff9f Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 24 Jan 2018 14:14:29 +0400 Subject: [PATCH 072/183] Test --- iguana/exchanges/LP_privkey.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_privkey.c b/iguana/exchanges/LP_privkey.c index df94f78e1..fc7684df6 100644 --- a/iguana/exchanges/LP_privkey.c +++ b/iguana/exchanges/LP_privkey.c @@ -484,10 +484,10 @@ int32_t LP_jpg_process(int32_t *capacityp,char *inputfname,char *outputfname,uin val = row_ptrs[compnum][0][blocknum][i]; if ( val < -8 || val > 8 ) { - if ( *capacityp < required ) + if ( (*capacityp) < required ) { if ( (val & 1) != 0 ) - decoded[*capacityp >> 3] |= (1 << (*capacityp&7)); + decoded[(*capacityp) >> 3] |= (1 << ((*capacityp)&7)); } (*capacityp)++; } From 286a8de8c2db8452c60814db466bd21b5b67d1ec Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 24 Jan 2018 20:07:24 +0400 Subject: [PATCH 073/183] Test --- iguana/exchanges/LP_privkey.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_privkey.c b/iguana/exchanges/LP_privkey.c index fc7684df6..e7d100e80 100644 --- a/iguana/exchanges/LP_privkey.c +++ b/iguana/exchanges/LP_privkey.c @@ -482,7 +482,8 @@ int32_t LP_jpg_process(int32_t *capacityp,char *inputfname,char *outputfname,uin for (i=0; i 8 ) + //if ( val < -8 || val > 8 ) + if ( val >= 0 && val < 2 ) { if ( (*capacityp) < required ) { @@ -518,7 +519,8 @@ int32_t LP_jpg_process(int32_t *capacityp,char *inputfname,char *outputfname,uin for (i=0; i 8 ) + //if ( val < -8 || val > 8 ) + if ( val >= 0 && val < 2 ) { val &= ~1; if ( (emit < required && (data[emit >> 3] & (1 << (emit&7))) != 0) || (rand() & 1) != 0 ) From bb74a0b6dcf974175b0b9b00e3bce449b3017b15 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 24 Jan 2018 20:09:34 +0400 Subject: [PATCH 074/183] Test --- iguana/exchanges/coins | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/coins b/iguana/exchanges/coins index 937f9a103..3b5a2e820 100644 --- a/iguana/exchanges/coins +++ b/iguana/exchanges/coins @@ -1,3 +1,3 @@ -export coins="[{\"coin\":\"GRS\",\"name\":\"groestlcoin\",\"rpcport\":1441,\"pubtype\":36,\"p2shtype\":5,\"wiftype\":128,\"txfee\":10000}, {\"coin\":\"XMCC\",\"name\":\"monoeci\",\"confpath\":\"${HOME#}/.monoeciCore/monoeci.conf\",\"rpcport\":24156,\"pubtype\":50,\"p2shtype\":73,\"wiftype\":77,\"txfee\":10000}, {\"coin\":\"BTCH\",\"asset\":\"BTCH\",\"rpcport\":8800},{\"coin\":\"ETOMIC\",\"asset\":\"ETOMIC\",\"rpcport\":10271},{\"coin\":\"AXO\",\"asset\":\"AXO\",\"rpcport\":12927},{\"coin\":\"CRC\",\"name\":\"crowdcoin\",\"confpath\":\"${HOME#}/.crowdcoincore/crowdcoin.conf\",\"rpcport\":9998,\"pubtype\":28,\"p2shtype\":88,\"wiftype\":0,\"txfee\":10000}, {\"coin\":\"VOT\",\"name\":\"votecoin\",\"rpcport\":8232,\"taddr\":28,\"pubtype\":184,\"p2shtype\":189,\"wiftype\":128,\"txfee\":10000}, {\"coin\":\"INN\",\"name\":\"innova\",\"confpath\":\"${HOME#}/.innovacore/innova.conf\",\"rpcport\":8818,\"pubtype\":102,\"p2shtype\":20,\"wiftype\":195,\"txfee\":10000}, {\"coin\":\"MOON\",\"name\":\"mooncoin\",\"rpcport\":44663,\"pubtype\":3,\"p2shtype\":22,\"wiftype\":131,\"txfee\":100000}, {\"coin\":\"CRW\",\"name\":\"crown\",\"rpcport\":9341,\"pubtype\":0,\"p2shtype\":28,\"wiftype\":128,\"txfee\":10000}, {\"coin\":\"EFL\",\"name\":\"egulden\",\"confpath\":\"${HOME#}/.egulden/coin.conf\",\"rpcport\":21015,\"pubtype\":48,\"p2shtype\":5,\"wiftype\":176,\"txfee\":100000}, {\"coin\":\"GBX\",\"name\":\"gobyte\",\"confpath\":\"${HOME#}/.gobytecore/gobyte.conf\",\"rpcport\":12454,\"pubtype\":38,\"p2shtype\":10,\"wiftype\":198,\"txfee\":10000}, {\"coin\":\"BCO\",\"name\":\"bridgecoin\",\"rpcport\":6332,\"pubtype\":27,\"p2shtype\":5,\"wiftype\":176,\"txfee\":100000}, {\"coin\":\"BLK\",\"name\":\"blackcoin\",\"confpath\":\"${HOME#}/.lore/blackcoin.conf\",\"isPoS\":1,\"rpcport\":15715,\"pubtype\":25,\"p2shtype\":85,\"wiftype\":153,\"txfee\":100000}, {\"coin\":\"BTG\",\"name\":\"bitcoingold\",\"rpcport\":8332,\"pubtype\":38,\"p2shtype\":23,\"wiftype\":128,\"txfee\":10000}, {\"coin\":\"BCH\",\"name\":\"bch\",\"rpcport\":33333,\"pubtype\":0,\"p2shtype\":5,\"wiftype\":128,\"txfee\":10000}, {\"coin\":\"ABY\",\"name\":\"applebyte\",\"rpcport\":8607,\"pubtype\":23,\"p2shtype\":5,\"wiftype\":151,\"txfee\":100000}, {\"coin\":\"STAK\",\"name\":\"straks\",\"rpcport\":7574,\"pubtype\":63,\"p2shtype\":5,\"wiftype\":204,\"txfee\":10000}, {\"coin\":\"XZC\",\"name\":\"zcoin\",\"rpcport\":8888,\"pubtype\":82,\"p2shtype\":7,\"wiftype\":210,\"txfee\":10000}, {\"coin\":\"QTUM\",\"name\":\"qtum\",\"rpcport\":3889,\"pubtype\":58,\"p2shtype\":50,\"wiftype\":128,\"txfee\":400000}, {\"coin\":\"PURA\",\"name\":\"pura\",\"rpcport\":55555,\"pubtype\":55,\"p2shtype\":16,\"wiftype\":150,\"txfee\":10000}, {\"coin\":\"DSR\",\"name\":\"desire\",\"confpath\":\"${HOME#}/.desirecore/desire.conf\",\"rpcport\":9918,\"pubtype\":30,\"p2shtype\":16,\"wiftype\":204,\"txfee\":10000}, {\"coin\":\"MNZ\",\"asset\":\"MNZ\",\"rpcport\":14337},{\"coin\":\"BTCZ\",\"name\":\"bitcoinz\",\"rpcport\":1979,\"taddr\":28,\"pubtype\":184,\"p2shtype\":189,\"wiftype\":128,\"txfee\":10000}, {\"coin\":\"MAGA\",\"name\":\"magacoin\",\"rpcport\":5332,\"pubtype\":23,\"p2shtype\":50,\"wiftype\":176,\"txfee\":100000}, {\"coin\":\"BSD\",\"name\":\"bitsend\",\"rpcport\":8800,\"pubtype\":102,\"p2shtype\":5,\"wiftype\":204,\"txfee\":10000}, {\"coin\":\"IOP\",\"name\":\"IoP\",\"rpcport\":8337,\"pubtype\":117,\"p2shtype\":174,\"wiftype\":49,\"txfee\":10000}, {\"coin\":\"BLOCK\",\"name\":\"blocknetdx\",\"rpcport\":41414,\"pubtype\":26,\"p2shtype\":28,\"wiftype\":154,\"txfee\":10000}, {\"coin\":\"CHIPS\", \"name\": \"chips\", \"rpcport\":57776,\"pubtype\":60, \"p2shtype\":85, \"wiftype\":188, \"txfee\":10000}, {\"coin\":\"888\",\"name\":\"octocoin\",\"rpcport\":22888,\"pubtype\":18,\"p2shtype\":5,\"wiftype\":176,\"txfee\":2000000}, {\"coin\":\"ARG\",\"name\":\"argentum\",\"rpcport\":13581,\"pubtype\":23,\"p2shtype\":5,\"wiftype\":151,\"txfee\":50000}, {\"coin\":\"GLT\",\"name\":\"globaltoken\",\"rpcport\":9320,\"pubtype\":38,\"p2shtype\":5,\"wiftype\":166,\"txfee\":10000}, {\"coin\":\"ZER\",\"name\":\"zero\",\"rpcport\":23801,\"taddr\":28,\"pubtype\":184,\"p2shtype\":189,\"wiftype\":128,\"txfee\":1000}, {\"coin\":\"HODLC\",\"name\":\"hodlcoin\",\"rpcport\":11989,\"pubtype\":40,\"p2shtype\":5,\"wiftype\":168,\"txfee\":5000}, {\"coin\":\"UIS\",\"name\":\"unitus\",\"rpcport\":50604,\"pubtype\":68,\"p2shtype\":10,\"wiftype\":132,\"txfee\":2000000}, {\"coin\":\"HUC\",\"name\":\"huntercoin\",\"rpcport\":8399,\"pubtype\":40,\"p2shtype\":13,\"wiftype\":168,\"txfee\":100000}, {\"coin\":\"BDL\",\"name\":\"bitdeal\",\"rpcport\":9332,\"pubtype\":38,\"p2shtype\":5,\"wiftype\":176,\"txfee\":100000}, {\"coin\":\"ARC\",\"name\":\"arcticcoin\",\"confpath\":\"${HOME#}/.arcticcore/arcticcoin.conf\",\"rpcport\":7208,\"pubtype\":23,\"p2shtype\":8,\"wiftype\":176,\"txfee\":10000}, {\"coin\":\"ZCL\",\"name\":\"zclassic\",\"rpcport\":8023,\"taddr\":28,\"pubtype\":184,\"p2shtype\":189,\"wiftype\":128,\"txfee\":1000}, {\"coin\":\"VIA\",\"name\":\"viacoin\",\"rpcport\":5222,\"pubtype\":71,\"p2shtype\":33,\"wiftype\":199,\"txfee\":100000}, {\"coin\":\"ERC\",\"name\":\"europecoin\",\"rpcport\":11989,\"pubtype\":33,\"p2shtype\":5,\"wiftype\":168,\"txfee\":10000},{\"coin\":\"FAIR\",\"name\":\"faircoin\",\"confpath\":\"${HOME#}/.faircoin2/faircoin.conf\",\"rpcport\":40405,\"pubtype\":95,\"p2shtype\":36,\"wiftype\":223,\"txfee\":1000000}, {\"coin\":\"FLO\",\"name\":\"florincoin\",\"rpcport\":7313,\"pubtype\":35,\"p2shtype\":8,\"wiftype\":176,\"txfee\":100000}, {\"coin\":\"SXC\",\"name\":\"sexcoin\",\"rpcport\":9561,\"pubtype\":62,\"p2shtype\":5,\"wiftype\":190,\"txfee\":100000}, {\"coin\":\"CREA\",\"name\":\"creativecoin\",\"rpcport\":17711,\"pubtype\":28,\"p2shtype\":5,\"wiftype\":176,\"txfee\":100000}, {\"coin\":\"TRC\",\"name\":\"terracoin\",\"confpath\":\"${HOME#}/.terracoincore/terracoin.conf\",\"rpcport\":13332,\"pubtype\":0,\"p2shtype\":5,\"wiftype\":128,\"txfee\":10000}, {\"coin\":\"BTA\",\"name\":\"bata\",\"rpcport\":5493,\"pubtype\":25,\"p2shtype\":5,\"wiftype\":188,\"txfee\":100000}, {\"coin\":\"SMC\",\"name\":\"smartcoin\",\"rpcport\":58583,\"pubtype\":63,\"p2shtype\":5,\"wiftype\":191,\"txfee\":1000000}, {\"coin\":\"NMC\",\"name\":\"namecoin\",\"rpcport\":8336,\"pubtype\":52,\"p2shtype\":13,\"wiftype\":180,\"txfee\":100000}, {\"coin\":\"NAV\",\"name\":\"navcoin\",\"isPoS\":1,\"confpath\":\"${HOME#}/.navcoin4/navcoin.conf\",\"rpcport\":44444,\"pubtype\":53,\"p2shtype\":85,\"wiftype\":150,\"txfee\":10000}, {\"coin\":\"EMC2\",\"name\":\"einsteinium\",\"rpcport\":41879,\"pubtype\":33,\"p2shtype\":5,\"wiftype\":176,\"txfee\":100000},{\"coin\":\"SYS\",\"name\":\"syscoin\",\"rpcport\":8370,\"pubtype\":0,\"p2shtype\":5,\"wiftype\":128,\"txfee\":10000}, {\"coin\":\"I0C\",\"name\":\"i0coin\",\"rpcport\":7332,\"pubtype\":105,\"p2shtype\":5,\"wiftype\":128,\"txfee\":10000}, {\"coin\":\"DASH\",\"confpath\":\"${HOME#}/.dashcore/dash.conf\",\"name\":\"dashcore\",\"rpcport\":9998,\"pubtype\":76,\"p2shtype\":16,\"wiftype\":204,\"txfee\":10000}, {\"coin\":\"STRAT\", \"name\": \"stratis\", \"active\":0, \"rpcport\":16174,\"pubtype\":63, \"p2shtype\":125, \"wiftype\":191, \"txfee\":10000}, {\"confpath\":\"${HOME#}/.muecore/mue.conf\",\"coin\":\"MUE\",\"name\":\"muecore\",\"rpcport\":29683,\"pubtype\":16,\"p2shtype\":76,\"wiftype\":126,\"txfee\":10000}, {\"coin\":\"MONA\",\"name\":\"monacoin\",\"rpcport\":9402,\"pubtype\":50,\"p2shtype\":5,\"wiftype\":176,\"txfee\":100000},{\"coin\":\"XMY\",\"name\":\"myriadcoin\",\"rpcport\":10889,\"pubtype\":50,\"p2shtype\":9,\"wiftype\":178,\"txfee\":5000}, {\"coin\":\"MAC\",\"name\":\"machinecoin\",\"rpcport\":40332,\"pubtype\":50,\"p2shtype\":5,\"wiftype\":178,\"txfee\":100000}, {\"coin\":\"BTX\",\"name\":\"bitcore\",\"rpcport\":8556,\"pubtype\":0,\"p2shtype\":5,\"wiftype\":128,\"txfee\":50000}, {\"coin\":\"XRE\",\"name\":\"revolvercoin\",\"rpcport\":8775,\"pubtype\":0,\"p2shtype\":5,\"wiftype\":128,\"txfee\":10000}, {\"coin\":\"LBC\",\"name\":\"lbrycrd\",\"rpcport\":9245,\"pubtype\":85,\"p2shtype\":122,\"wiftype\":28,\"txfee\":10000}, {\"coin\":\"SIB\",\"name\":\"sibcoin\",\"rpcport\":1944,\"pubtype\":63,\"p2shtype\":40,\"wiftype\":128,\"txfee\":10000}, {\"coin\":\"VTC\", \"name\":\"vertcoin\", \"rpcport\":5888, \"pubtype\":71, \"p2shtype\":5, \"wiftype\":128, \"txfee\":100000 }, {\"coin\":\"REVS\",\"active\":0, \"asset\":\"REVS\",\"rpcport\":10196}, {\"coin\":\"JUMBLR\",\"active\":0, \"asset\":\"JUMBLR\",\"rpcport\":15106}, {\"coin\":\"DOGE\",\"name\":\"dogecoin\",\"rpcport\":22555,\"pubtype\":30,\"p2shtype\":22,\"wiftype\":158,\"txfee\":100000000}, {\"coin\":\"HUSH\",\"name\":\"hush\",\"rpcport\":8822,\"taddr\":28,\"pubtype\":184,\"p2shtype\":189,\"wiftype\":128,\"txfee\":1000 }, {\"active\":0,\"coin\":\"ZEC\",\"name\":\"zcash\",\"rpcport\":8232,\"taddr\":28,\"pubtype\":184,\"p2shtype\":189,\"wiftype\":128,\"txfee\":10000 }, {\"coin\":\"DGB\",\"name\":\"digibyte\",\"rpcport\":14022,\"pubtype\":30,\"p2shtype\":5,\"wiftype\":128,\"txfee\":100000}, {\"coin\":\"ZET\", \"name\":\"zetacoin\", \"pubtype\":80, \"p2shtype\":9,\"rpcport\":8332, \"wiftype\":224, \"txfee\":10000}, {\"coin\":\"GAME\", \"rpcport\":40001, \"name\":\"gamecredits\", \"pubtype\":38, \"p2shtype\":5, \"wiftype\":166, \"txfee\":100000}, {\"coin\":\"LTC\", \"name\":\"litecoin\", \"rpcport\":9332, \"pubtype\":48, \"p2shtype\":5, \"wiftype\":176, \"txfee\":100000 }, {\"coin\":\"SUPERNET\",\"asset\":\"SUPERNET\",\"rpcport\":11341}, {\"coin\":\"WLC\",\"asset\":\"WLC\",\"rpcport\":12167}, {\"coin\":\"PANGEA\",\"asset\":\"PANGEA\",\"rpcport\":14068}, {\"coin\":\"DEX\",\"asset\":\"DEX\",\"rpcport\":11890}, {\"coin\":\"BET\",\"asset\":\"BET\",\"rpcport\":14250}, {\"coin\":\"CRYPTO\",\"asset\":\"CRYPTO\",\"rpcport\":8516}, {\"coin\":\"HODL\",\"asset\":\"HODL\",\"rpcport\":14431}, {\"coin\":\"MSHARK\",\"asset\":\"MSHARK\",\"rpcport\":8846}, {\"coin\":\"BOTS\",\"asset\":\"BOTS\",\"rpcport\":11964}, {\"coin\":\"MGW\",\"asset\":\"MGW\",\"rpcport\":12386}, {\"coin\":\"COQUI\",\"asset\":\"COQUI\",\"rpcport\":14276}, {\"coin\":\"KV\",\"asset\":\"KV\",\"rpcport\":8299}, {\"coin\":\"CEAL\",\"asset\":\"CEAL\",\"rpcport\":11116}, {\"coin\":\"MESH\",\"asset\":\"MESH\",\"rpcport\":9455}]" +export coins="[{\"coin\": \"PIZZA\",\"asset\": \"PIZZA\",\"rpcport\": 11116},{\"coin\": \"BEER\",\"asset\": \"BEER\",\"rpcport\": 8923}, {\"coin\":\"GRS\",\"name\":\"groestlcoin\",\"rpcport\":1441,\"pubtype\":36,\"p2shtype\":5,\"wiftype\":128,\"txfee\":10000}, {\"coin\":\"XMCC\",\"name\":\"monoeci\",\"confpath\":\"${HOME#}/.monoeciCore/monoeci.conf\",\"rpcport\":24156,\"pubtype\":50,\"p2shtype\":73,\"wiftype\":77,\"txfee\":10000}, {\"coin\":\"BTCH\",\"asset\":\"BTCH\",\"rpcport\":8800},{\"coin\":\"ETOMIC\",\"asset\":\"ETOMIC\",\"rpcport\":10271},{\"coin\":\"AXO\",\"asset\":\"AXO\",\"rpcport\":12927},{\"coin\":\"CRC\",\"name\":\"crowdcoin\",\"confpath\":\"${HOME#}/.crowdcoincore/crowdcoin.conf\",\"rpcport\":9998,\"pubtype\":28,\"p2shtype\":88,\"wiftype\":0,\"txfee\":10000}, {\"coin\":\"VOT\",\"name\":\"votecoin\",\"rpcport\":8232,\"taddr\":28,\"pubtype\":184,\"p2shtype\":189,\"wiftype\":128,\"txfee\":10000}, {\"coin\":\"INN\",\"name\":\"innova\",\"confpath\":\"${HOME#}/.innovacore/innova.conf\",\"rpcport\":8818,\"pubtype\":102,\"p2shtype\":20,\"wiftype\":195,\"txfee\":10000}, {\"coin\":\"MOON\",\"name\":\"mooncoin\",\"rpcport\":44663,\"pubtype\":3,\"p2shtype\":22,\"wiftype\":131,\"txfee\":100000}, {\"coin\":\"CRW\",\"name\":\"crown\",\"rpcport\":9341,\"pubtype\":0,\"p2shtype\":28,\"wiftype\":128,\"txfee\":10000}, {\"coin\":\"EFL\",\"name\":\"egulden\",\"confpath\":\"${HOME#}/.egulden/coin.conf\",\"rpcport\":21015,\"pubtype\":48,\"p2shtype\":5,\"wiftype\":176,\"txfee\":100000}, {\"coin\":\"GBX\",\"name\":\"gobyte\",\"confpath\":\"${HOME#}/.gobytecore/gobyte.conf\",\"rpcport\":12454,\"pubtype\":38,\"p2shtype\":10,\"wiftype\":198,\"txfee\":10000}, {\"coin\":\"BCO\",\"name\":\"bridgecoin\",\"rpcport\":6332,\"pubtype\":27,\"p2shtype\":5,\"wiftype\":176,\"txfee\":100000}, {\"coin\":\"BLK\",\"name\":\"blackcoin\",\"confpath\":\"${HOME#}/.lore/blackcoin.conf\",\"isPoS\":1,\"rpcport\":15715,\"pubtype\":25,\"p2shtype\":85,\"wiftype\":153,\"txfee\":100000}, {\"coin\":\"BTG\",\"name\":\"bitcoingold\",\"rpcport\":8332,\"pubtype\":38,\"p2shtype\":23,\"wiftype\":128,\"txfee\":10000}, {\"coin\":\"BCH\",\"name\":\"bch\",\"rpcport\":33333,\"pubtype\":0,\"p2shtype\":5,\"wiftype\":128,\"txfee\":10000}, {\"coin\":\"ABY\",\"name\":\"applebyte\",\"rpcport\":8607,\"pubtype\":23,\"p2shtype\":5,\"wiftype\":151,\"txfee\":100000}, {\"coin\":\"STAK\",\"name\":\"straks\",\"rpcport\":7574,\"pubtype\":63,\"p2shtype\":5,\"wiftype\":204,\"txfee\":10000}, {\"coin\":\"XZC\",\"name\":\"zcoin\",\"rpcport\":8888,\"pubtype\":82,\"p2shtype\":7,\"wiftype\":210,\"txfee\":10000}, {\"coin\":\"QTUM\",\"name\":\"qtum\",\"rpcport\":3889,\"pubtype\":58,\"p2shtype\":50,\"wiftype\":128,\"txfee\":400000}, {\"coin\":\"PURA\",\"name\":\"pura\",\"rpcport\":55555,\"pubtype\":55,\"p2shtype\":16,\"wiftype\":150,\"txfee\":10000}, {\"coin\":\"DSR\",\"name\":\"desire\",\"confpath\":\"${HOME#}/.desirecore/desire.conf\",\"rpcport\":9918,\"pubtype\":30,\"p2shtype\":16,\"wiftype\":204,\"txfee\":10000}, {\"coin\":\"MNZ\",\"asset\":\"MNZ\",\"rpcport\":14337},{\"coin\":\"BTCZ\",\"name\":\"bitcoinz\",\"rpcport\":1979,\"taddr\":28,\"pubtype\":184,\"p2shtype\":189,\"wiftype\":128,\"txfee\":10000}, {\"coin\":\"MAGA\",\"name\":\"magacoin\",\"rpcport\":5332,\"pubtype\":23,\"p2shtype\":50,\"wiftype\":176,\"txfee\":100000}, {\"coin\":\"BSD\",\"name\":\"bitsend\",\"rpcport\":8800,\"pubtype\":102,\"p2shtype\":5,\"wiftype\":204,\"txfee\":10000}, {\"coin\":\"IOP\",\"name\":\"IoP\",\"rpcport\":8337,\"pubtype\":117,\"p2shtype\":174,\"wiftype\":49,\"txfee\":10000}, {\"coin\":\"BLOCK\",\"name\":\"blocknetdx\",\"rpcport\":41414,\"pubtype\":26,\"p2shtype\":28,\"wiftype\":154,\"txfee\":10000}, {\"coin\":\"CHIPS\", \"name\": \"chips\", \"rpcport\":57776,\"pubtype\":60, \"p2shtype\":85, \"wiftype\":188, \"txfee\":10000}, {\"coin\":\"888\",\"name\":\"octocoin\",\"rpcport\":22888,\"pubtype\":18,\"p2shtype\":5,\"wiftype\":176,\"txfee\":2000000}, {\"coin\":\"ARG\",\"name\":\"argentum\",\"rpcport\":13581,\"pubtype\":23,\"p2shtype\":5,\"wiftype\":151,\"txfee\":50000}, {\"coin\":\"GLT\",\"name\":\"globaltoken\",\"rpcport\":9320,\"pubtype\":38,\"p2shtype\":5,\"wiftype\":166,\"txfee\":10000}, {\"coin\":\"ZER\",\"name\":\"zero\",\"rpcport\":23801,\"taddr\":28,\"pubtype\":184,\"p2shtype\":189,\"wiftype\":128,\"txfee\":1000}, {\"coin\":\"HODLC\",\"name\":\"hodlcoin\",\"rpcport\":11989,\"pubtype\":40,\"p2shtype\":5,\"wiftype\":168,\"txfee\":5000}, {\"coin\":\"UIS\",\"name\":\"unitus\",\"rpcport\":50604,\"pubtype\":68,\"p2shtype\":10,\"wiftype\":132,\"txfee\":2000000}, {\"coin\":\"HUC\",\"name\":\"huntercoin\",\"rpcport\":8399,\"pubtype\":40,\"p2shtype\":13,\"wiftype\":168,\"txfee\":100000}, {\"coin\":\"BDL\",\"name\":\"bitdeal\",\"rpcport\":9332,\"pubtype\":38,\"p2shtype\":5,\"wiftype\":176,\"txfee\":100000}, {\"coin\":\"ARC\",\"name\":\"arcticcoin\",\"confpath\":\"${HOME#}/.arcticcore/arcticcoin.conf\",\"rpcport\":7208,\"pubtype\":23,\"p2shtype\":8,\"wiftype\":176,\"txfee\":10000}, {\"coin\":\"ZCL\",\"name\":\"zclassic\",\"rpcport\":8023,\"taddr\":28,\"pubtype\":184,\"p2shtype\":189,\"wiftype\":128,\"txfee\":1000}, {\"coin\":\"VIA\",\"name\":\"viacoin\",\"rpcport\":5222,\"pubtype\":71,\"p2shtype\":33,\"wiftype\":199,\"txfee\":100000}, {\"coin\":\"ERC\",\"name\":\"europecoin\",\"rpcport\":11989,\"pubtype\":33,\"p2shtype\":5,\"wiftype\":168,\"txfee\":10000},{\"coin\":\"FAIR\",\"name\":\"faircoin\",\"confpath\":\"${HOME#}/.faircoin2/faircoin.conf\",\"rpcport\":40405,\"pubtype\":95,\"p2shtype\":36,\"wiftype\":223,\"txfee\":1000000}, {\"coin\":\"FLO\",\"name\":\"florincoin\",\"rpcport\":7313,\"pubtype\":35,\"p2shtype\":8,\"wiftype\":176,\"txfee\":100000}, {\"coin\":\"SXC\",\"name\":\"sexcoin\",\"rpcport\":9561,\"pubtype\":62,\"p2shtype\":5,\"wiftype\":190,\"txfee\":100000}, {\"coin\":\"CREA\",\"name\":\"creativecoin\",\"rpcport\":17711,\"pubtype\":28,\"p2shtype\":5,\"wiftype\":176,\"txfee\":100000}, {\"coin\":\"TRC\",\"name\":\"terracoin\",\"confpath\":\"${HOME#}/.terracoincore/terracoin.conf\",\"rpcport\":13332,\"pubtype\":0,\"p2shtype\":5,\"wiftype\":128,\"txfee\":10000}, {\"coin\":\"BTA\",\"name\":\"bata\",\"rpcport\":5493,\"pubtype\":25,\"p2shtype\":5,\"wiftype\":188,\"txfee\":100000}, {\"coin\":\"SMC\",\"name\":\"smartcoin\",\"rpcport\":58583,\"pubtype\":63,\"p2shtype\":5,\"wiftype\":191,\"txfee\":1000000}, {\"coin\":\"NMC\",\"name\":\"namecoin\",\"rpcport\":8336,\"pubtype\":52,\"p2shtype\":13,\"wiftype\":180,\"txfee\":100000}, {\"coin\":\"NAV\",\"name\":\"navcoin\",\"isPoS\":1,\"confpath\":\"${HOME#}/.navcoin4/navcoin.conf\",\"rpcport\":44444,\"pubtype\":53,\"p2shtype\":85,\"wiftype\":150,\"txfee\":10000}, {\"coin\":\"EMC2\",\"name\":\"einsteinium\",\"rpcport\":41879,\"pubtype\":33,\"p2shtype\":5,\"wiftype\":176,\"txfee\":100000},{\"coin\":\"SYS\",\"name\":\"syscoin\",\"rpcport\":8370,\"pubtype\":0,\"p2shtype\":5,\"wiftype\":128,\"txfee\":10000}, {\"coin\":\"I0C\",\"name\":\"i0coin\",\"rpcport\":7332,\"pubtype\":105,\"p2shtype\":5,\"wiftype\":128,\"txfee\":10000}, {\"coin\":\"DASH\",\"confpath\":\"${HOME#}/.dashcore/dash.conf\",\"name\":\"dashcore\",\"rpcport\":9998,\"pubtype\":76,\"p2shtype\":16,\"wiftype\":204,\"txfee\":10000}, {\"coin\":\"STRAT\", \"name\": \"stratis\", \"active\":0, \"rpcport\":16174,\"pubtype\":63, \"p2shtype\":125, \"wiftype\":191, \"txfee\":10000}, {\"confpath\":\"${HOME#}/.muecore/mue.conf\",\"coin\":\"MUE\",\"name\":\"muecore\",\"rpcport\":29683,\"pubtype\":16,\"p2shtype\":76,\"wiftype\":126,\"txfee\":10000}, {\"coin\":\"MONA\",\"name\":\"monacoin\",\"rpcport\":9402,\"pubtype\":50,\"p2shtype\":5,\"wiftype\":176,\"txfee\":100000},{\"coin\":\"XMY\",\"name\":\"myriadcoin\",\"rpcport\":10889,\"pubtype\":50,\"p2shtype\":9,\"wiftype\":178,\"txfee\":5000}, {\"coin\":\"MAC\",\"name\":\"machinecoin\",\"rpcport\":40332,\"pubtype\":50,\"p2shtype\":5,\"wiftype\":178,\"txfee\":100000}, {\"coin\":\"BTX\",\"name\":\"bitcore\",\"rpcport\":8556,\"pubtype\":0,\"p2shtype\":5,\"wiftype\":128,\"txfee\":50000}, {\"coin\":\"XRE\",\"name\":\"revolvercoin\",\"rpcport\":8775,\"pubtype\":0,\"p2shtype\":5,\"wiftype\":128,\"txfee\":10000}, {\"coin\":\"LBC\",\"name\":\"lbrycrd\",\"rpcport\":9245,\"pubtype\":85,\"p2shtype\":122,\"wiftype\":28,\"txfee\":10000}, {\"coin\":\"SIB\",\"name\":\"sibcoin\",\"rpcport\":1944,\"pubtype\":63,\"p2shtype\":40,\"wiftype\":128,\"txfee\":10000}, {\"coin\":\"VTC\", \"name\":\"vertcoin\", \"rpcport\":5888, \"pubtype\":71, \"p2shtype\":5, \"wiftype\":128, \"txfee\":100000 }, {\"coin\":\"REVS\",\"active\":0, \"asset\":\"REVS\",\"rpcport\":10196}, {\"coin\":\"JUMBLR\",\"active\":0, \"asset\":\"JUMBLR\",\"rpcport\":15106}, {\"coin\":\"DOGE\",\"name\":\"dogecoin\",\"rpcport\":22555,\"pubtype\":30,\"p2shtype\":22,\"wiftype\":158,\"txfee\":100000000}, {\"coin\":\"HUSH\",\"name\":\"hush\",\"rpcport\":8822,\"taddr\":28,\"pubtype\":184,\"p2shtype\":189,\"wiftype\":128,\"txfee\":1000 }, {\"active\":0,\"coin\":\"ZEC\",\"name\":\"zcash\",\"rpcport\":8232,\"taddr\":28,\"pubtype\":184,\"p2shtype\":189,\"wiftype\":128,\"txfee\":10000 }, {\"coin\":\"DGB\",\"name\":\"digibyte\",\"rpcport\":14022,\"pubtype\":30,\"p2shtype\":5,\"wiftype\":128,\"txfee\":100000}, {\"coin\":\"ZET\", \"name\":\"zetacoin\", \"pubtype\":80, \"p2shtype\":9,\"rpcport\":8332, \"wiftype\":224, \"txfee\":10000}, {\"coin\":\"GAME\", \"rpcport\":40001, \"name\":\"gamecredits\", \"pubtype\":38, \"p2shtype\":5, \"wiftype\":166, \"txfee\":100000}, {\"coin\":\"LTC\", \"name\":\"litecoin\", \"rpcport\":9332, \"pubtype\":48, \"p2shtype\":5, \"wiftype\":176, \"txfee\":100000 }, {\"coin\":\"SUPERNET\",\"asset\":\"SUPERNET\",\"rpcport\":11341}, {\"coin\":\"WLC\",\"asset\":\"WLC\",\"rpcport\":12167}, {\"coin\":\"PANGEA\",\"asset\":\"PANGEA\",\"rpcport\":14068}, {\"coin\":\"DEX\",\"asset\":\"DEX\",\"rpcport\":11890}, {\"coin\":\"BET\",\"asset\":\"BET\",\"rpcport\":14250}, {\"coin\":\"CRYPTO\",\"asset\":\"CRYPTO\",\"rpcport\":8516}, {\"coin\":\"HODL\",\"asset\":\"HODL\",\"rpcport\":14431}, {\"coin\":\"MSHARK\",\"asset\":\"MSHARK\",\"rpcport\":8846}, {\"coin\":\"BOTS\",\"asset\":\"BOTS\",\"rpcport\":11964}, {\"coin\":\"MGW\",\"asset\":\"MGW\",\"rpcport\":12386}, {\"coin\":\"COQUI\",\"asset\":\"COQUI\",\"rpcport\":14276}, {\"coin\":\"KV\",\"asset\":\"KV\",\"rpcport\":8299}, {\"coin\":\"CEAL\",\"asset\":\"CEAL\",\"rpcport\":11116}, {\"coin\":\"MESH\",\"asset\":\"MESH\",\"rpcport\":9455}]" #, {\"coin\":\"AUD\",\"asset\":\"AUD\",\"rpcport\":8045}, {\"coin\":\"BGN\",\"asset\":\"BGN\",\"rpcport\":9110}, {\"coin\":\"CAD\",\"asset\":\"CAD\",\"rpcport\":8720}, {\"coin\":\"CHF\",\"asset\":\"CHF\",\"rpcport\":15312}, {\"coin\":\"CNY\",\"asset\":\"CNY\",\"rpcport\":10384}, {\"coin\":\"CZK\",\"asset\":\"CZK\",\"rpcport\":9482}, {\"coin\":\"DKK\",\"asset\":\"DKK\",\"rpcport\":13830}, {\"coin\":\"EUR\",\"asset\":\"EUR\",\"rpcport\":8065}, {\"coin\":\"GBP\",\"asset\":\"GBP\",\"rpcport\":11505}, {\"coin\":\"HKD\",\"asset\":\"HKD\",\"rpcport\":15409}, {\"coin\":\"HRK\",\"asset\":\"HRK\",\"rpcport\":12617}, {\"coin\":\"HUF\",\"asset\":\"HUF\",\"rpcport\":13699}, {\"coin\":\"IDR\",\"asset\":\"IDR\",\"rpcport\":14459}, {\"coin\":\"ILS\",\"asset\":\"ILS\",\"rpcport\":14638}, {\"coin\":\"INR\",\"asset\":\"INR\",\"rpcport\":10536}, {\"coin\":\"JPY\",\"asset\":\"JPY\",\"rpcport\":13145}, {\"coin\":\"KRW\",\"asset\":\"KRW\",\"rpcport\":14020}, {\"coin\":\"MXN\",\"asset\":\"MXN\",\"rpcport\":13970}, {\"coin\":\"MYR\",\"asset\":\"MYR\",\"rpcport\":10688}, {\"coin\":\"NOK\",\"asset\":\"NOK\",\"rpcport\":11588}, {\"coin\":\"NZD\",\"asset\":\"NZD\",\"rpcport\":10915}, {\"coin\":\"PHP\",\"asset\":\"PHP\",\"rpcport\":11181}, {\"coin\":\"PLN\",\"asset\":\"PLN\",\"rpcport\":13493}, {\"coin\":\"BRL\",\"asset\":\"BRL\",\"rpcport\":9914}, {\"coin\":\"RON\",\"asset\":\"RON\",\"rpcport\":8675}, {\"coin\":\"RUB\",\"asset\":\"RUB\",\"rpcport\":8199}, {\"coin\":\"SEK\",\"asset\":\"SEK\",\"rpcport\":11447}, {\"coin\":\"SGD\",\"asset\":\"SGD\",\"rpcport\":14475}, {\"coin\":\"THB\",\"asset\":\"THB\",\"rpcport\":11847}, {\"coin\":\"TRY\",\"asset\":\"TRY\",\"rpcport\":13924}, {\"coin\":\"USD\",\"asset\":\"USD\",\"rpcport\":13967}, {\"coin\":\"ZAR\",\"asset\":\"ZAR\",\"rpcport\":15160}]" #{\"coin\":\"PIVX\",\"name\":\"pivx\",\"rpcport\":51473,\"pubtype\":30,\"p2shtype\":13,\"wiftype\":212,\"txfee\":10000}, From 79176ef6ccd9b4ec86e00bff6391cbe87b2e5455 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 24 Jan 2018 20:34:38 +0400 Subject: [PATCH 075/183] Test --- iguana/exchanges/LP_privkey.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/iguana/exchanges/LP_privkey.c b/iguana/exchanges/LP_privkey.c index e7d100e80..872105b64 100644 --- a/iguana/exchanges/LP_privkey.c +++ b/iguana/exchanges/LP_privkey.c @@ -483,12 +483,13 @@ int32_t LP_jpg_process(int32_t *capacityp,char *inputfname,char *outputfname,uin { val = row_ptrs[compnum][0][blocknum][i]; //if ( val < -8 || val > 8 ) - if ( val >= 0 && val < 2 ) + if ( val == 0 || val == 1 ) { if ( (*capacityp) < required ) { if ( (val & 1) != 0 ) decoded[(*capacityp) >> 3] |= (1 << ((*capacityp)&7)); + printf("%c",(val&1)!=0?'1':'0'); } (*capacityp)++; } @@ -497,7 +498,7 @@ int32_t LP_jpg_process(int32_t *capacityp,char *inputfname,char *outputfname,uin } } } - printf("capacity %d required.%d power2.%d limit.%d\n",*capacityp,required,power2,limit); + printf(" capacity %d required.%d power2.%d limit.%d\n",*capacityp,required,power2,limit); if ( *capacityp > required && outputfname != 0 && outputfname[0] != 0 ) { if ((output_file = fopen(outputfname, WRITE_BINARY)) == NULL) { @@ -520,12 +521,13 @@ int32_t LP_jpg_process(int32_t *capacityp,char *inputfname,char *outputfname,uin { val = coef_buffers[compnum][rownum][blocknum][i]; //if ( val < -8 || val > 8 ) - if ( val >= 0 && val < 2 ) + if ( val == 0 || val == 1 ) { val &= ~1; if ( (emit < required && (data[emit >> 3] & (1 << (emit&7))) != 0) || (rand() & 1) != 0 ) val |= 1; emit++; + printf("%c",(val&1)!=0?'1':'0'); } coef_buffers[compnum][rownum][blocknum][i] = val; //printf("%i,", coef_buffers[compnum][rownum][blocknum][i]); @@ -533,9 +535,8 @@ int32_t LP_jpg_process(int32_t *capacityp,char *inputfname,char *outputfname,uin } } } - //printf("\n\n"); - - /* Output the new DCT coeffs to a JPEG file */ + printf(" emit.%d\n",emit); + // Output the new DCT coeffs to a JPEG file modified = 0; for (compnum=0; compnum Date: Wed, 24 Jan 2018 20:37:14 +0400 Subject: [PATCH 076/183] Test --- iguana/exchanges/LP_privkey.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_privkey.c b/iguana/exchanges/LP_privkey.c index 872105b64..40b5fa701 100644 --- a/iguana/exchanges/LP_privkey.c +++ b/iguana/exchanges/LP_privkey.c @@ -526,8 +526,9 @@ int32_t LP_jpg_process(int32_t *capacityp,char *inputfname,char *outputfname,uin val &= ~1; if ( (emit < required && (data[emit >> 3] & (1 << (emit&7))) != 0) || (rand() & 1) != 0 ) val |= 1; + if ( emit < required ) + printf("%c",(val&1)!=0?'1':'0'); emit++; - printf("%c",(val&1)!=0?'1':'0'); } coef_buffers[compnum][rownum][blocknum][i] = val; //printf("%i,", coef_buffers[compnum][rownum][blocknum][i]); From be73cffb2f456634bfecea1c33c74557431605a7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 24 Jan 2018 20:42:41 +0400 Subject: [PATCH 077/183] Test --- iguana/exchanges/LP_privkey.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/iguana/exchanges/LP_privkey.c b/iguana/exchanges/LP_privkey.c index 40b5fa701..c944c430d 100644 --- a/iguana/exchanges/LP_privkey.c +++ b/iguana/exchanges/LP_privkey.c @@ -488,7 +488,8 @@ int32_t LP_jpg_process(int32_t *capacityp,char *inputfname,char *outputfname,uin if ( (*capacityp) < required ) { if ( (val & 1) != 0 ) - decoded[(*capacityp) >> 3] |= (1 << ((*capacityp)&7)); + SETBIT(decoded,(*capacityp)); + //decoded[(*capacityp) >> 3] |= (1 << ((*capacityp)&7)); printf("%c",(val&1)!=0?'1':'0'); } (*capacityp)++; @@ -524,7 +525,7 @@ int32_t LP_jpg_process(int32_t *capacityp,char *inputfname,char *outputfname,uin if ( val == 0 || val == 1 ) { val &= ~1; - if ( (emit < required && (data[emit >> 3] & (1 << (emit&7))) != 0) || (rand() & 1) != 0 ) + if ( (emit < required && GETBIT(data,emit) != 0) || (rand() & 1) != 0 ) val |= 1; if ( emit < required ) printf("%c",(val&1)!=0?'1':'0'); @@ -574,7 +575,7 @@ int32_t LP_jpg_process(int32_t *capacityp,char *inputfname,char *outputfname,uin char *LP_jpg(char *srcfile,char *destfile,int32_t power2,char *passphrase,char *datastr,int32_t required) { - cJSON *retjson; int32_t len=0,modified,capacity; char *decodedstr; uint8_t *data=0,*decoded=0; + cJSON *retjson; int32_t i,len=0,modified,capacity; char *decodedstr; uint8_t *data=0,*decoded=0; if ( srcfile != 0 && srcfile[0] != 0 ) { retjson = cJSON_CreateObject(); @@ -586,6 +587,9 @@ char *LP_jpg(char *srcfile,char *destfile,int32_t power2,char *passphrase,char * data = calloc(1,len); decode_hex(data,len,datastr); required = len * 8; + for (i=0; i 0 ) From 6486aced0f849b2bde7483c25f002dd50cb7e3bd Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 24 Jan 2018 20:44:46 +0400 Subject: [PATCH 078/183] Test --- iguana/exchanges/LP_privkey.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_privkey.c b/iguana/exchanges/LP_privkey.c index c944c430d..52ca61ff4 100644 --- a/iguana/exchanges/LP_privkey.c +++ b/iguana/exchanges/LP_privkey.c @@ -588,7 +588,7 @@ char *LP_jpg(char *srcfile,char *destfile,int32_t power2,char *passphrase,char * decode_hex(data,len,datastr); required = len * 8; for (i=0; i Date: Wed, 24 Jan 2018 20:50:13 +0400 Subject: [PATCH 079/183] Test --- iguana/exchanges/LP_nativeDEX.c | 2 +- iguana/exchanges/LP_privkey.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 8faa32253..38685d97b 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -1068,7 +1068,7 @@ void LP_reserved_msgs(void *ignore) bits256 zero; int32_t flag,nonz; struct nn_pollfd pfd; memset(zero.bytes,0,sizeof(zero)); strcpy(LP_reserved_msgs_stats.name,"LP_reserved_msgs"); - LP_reserved_msgs_stats.threshold = 150.; + LP_reserved_msgs_stats.threshold = 1000.; while ( LP_STOP_RECEIVED == 0 ) { nonz = 0; diff --git a/iguana/exchanges/LP_privkey.c b/iguana/exchanges/LP_privkey.c index 52ca61ff4..c73706b5d 100644 --- a/iguana/exchanges/LP_privkey.c +++ b/iguana/exchanges/LP_privkey.c @@ -525,10 +525,10 @@ int32_t LP_jpg_process(int32_t *capacityp,char *inputfname,char *outputfname,uin if ( val == 0 || val == 1 ) { val &= ~1; - if ( (emit < required && GETBIT(data,emit) != 0) || (rand() & 1) != 0 ) + if ( (emit < required && GETBIT(data,emit) != 0) || (emit >= required && (rand() & 1) != 0) ) val |= 1; if ( emit < required ) - printf("%c",(val&1)!=0?'1':'0'); + printf("%d",val-'0'); emit++; } coef_buffers[compnum][rownum][blocknum][i] = val; From 564a91c16b6ff1f5576bc98bb2c9804e8d4b1e4a Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 24 Jan 2018 20:53:22 +0400 Subject: [PATCH 080/183] Test --- iguana/exchanges/LP_privkey.c | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/iguana/exchanges/LP_privkey.c b/iguana/exchanges/LP_privkey.c index c73706b5d..89ec7516e 100644 --- a/iguana/exchanges/LP_privkey.c +++ b/iguana/exchanges/LP_privkey.c @@ -482,15 +482,14 @@ int32_t LP_jpg_process(int32_t *capacityp,char *inputfname,char *outputfname,uin for (i=0; i 8 ) - if ( val == 0 || val == 1 ) + if ( val < -limit || val > limit ) { if ( (*capacityp) < required ) { if ( (val & 1) != 0 ) SETBIT(decoded,(*capacityp)); //decoded[(*capacityp) >> 3] |= (1 << ((*capacityp)&7)); - printf("%c",(val&1)!=0?'1':'0'); + //printf("%c",(val&1)!=0?'1':'0'); } (*capacityp)++; } @@ -521,14 +520,11 @@ int32_t LP_jpg_process(int32_t *capacityp,char *inputfname,char *outputfname,uin for (i=0; i 8 ) - if ( val == 0 || val == 1 ) + if ( val < -limit || val > limit ) { val &= ~1; if ( (emit < required && GETBIT(data,emit) != 0) || (emit >= required && (rand() & 1) != 0) ) val |= 1; - if ( emit < required ) - printf("%d",val-'0'); emit++; } coef_buffers[compnum][rownum][blocknum][i] = val; @@ -537,7 +533,6 @@ int32_t LP_jpg_process(int32_t *capacityp,char *inputfname,char *outputfname,uin } } } - printf(" emit.%d\n",emit); // Output the new DCT coeffs to a JPEG file modified = 0; for (compnum=0; compnum 0 ) @@ -612,7 +607,7 @@ char *LP_jpg(char *srcfile,char *destfile,int32_t power2,char *passphrase,char * { printf("len.%d required.%d capacity.%d\n",len,required,capacity); decodedstr = calloc(1,(len+required)*2+1); - init_hexbytes_noT(decodedstr,decoded,required/8+1); + init_hexbytes_noT(decodedstr,decoded,required/8); jaddstr(retjson,"decoded",decodedstr); free(decodedstr); } From 6c74b42c09688936ed0c7b1fb683e4824ba908ce Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 24 Jan 2018 20:56:25 +0400 Subject: [PATCH 081/183] Test --- iguana/exchanges/LP_privkey.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/iguana/exchanges/LP_privkey.c b/iguana/exchanges/LP_privkey.c index 89ec7516e..7afcb0c4d 100644 --- a/iguana/exchanges/LP_privkey.c +++ b/iguana/exchanges/LP_privkey.c @@ -482,7 +482,8 @@ int32_t LP_jpg_process(int32_t *capacityp,char *inputfname,char *outputfname,uin for (i=0; i limit ) + if ( val == 0 || val == 1 ) + //if ( val < -limit || val > limit ) { if ( (*capacityp) < required ) { @@ -498,7 +499,7 @@ int32_t LP_jpg_process(int32_t *capacityp,char *inputfname,char *outputfname,uin } } } - printf(" capacity %d required.%d power2.%d limit.%d\n",*capacityp,required,power2,limit); + //printf(" capacity %d required.%d power2.%d limit.%d\n",*capacityp,required,power2,limit); if ( *capacityp > required && outputfname != 0 && outputfname[0] != 0 ) { if ((output_file = fopen(outputfname, WRITE_BINARY)) == NULL) { @@ -520,7 +521,8 @@ int32_t LP_jpg_process(int32_t *capacityp,char *inputfname,char *outputfname,uin for (i=0; i limit ) + // if ( val < -limit || val > limit ) + if ( val == 0 || val == 1 ) { val &= ~1; if ( (emit < required && GETBIT(data,emit) != 0) || (emit >= required && (rand() & 1) != 0) ) From 3a3796b8ca911f389b06beffc02a5090d7027424 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 24 Jan 2018 21:19:42 +0400 Subject: [PATCH 082/183] Test --- iguana/exchanges/LP_privkey.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/iguana/exchanges/LP_privkey.c b/iguana/exchanges/LP_privkey.c index 7afcb0c4d..fdf9ed454 100644 --- a/iguana/exchanges/LP_privkey.c +++ b/iguana/exchanges/LP_privkey.c @@ -482,8 +482,8 @@ int32_t LP_jpg_process(int32_t *capacityp,char *inputfname,char *outputfname,uin for (i=0; i limit ) + //if ( val == 0 || val == 1 ) + if ( val < -8 || val > 8 ) { if ( (*capacityp) < required ) { @@ -518,18 +518,17 @@ int32_t LP_jpg_process(int32_t *capacityp,char *inputfname,char *outputfname,uin for (blocknum=0; blocknum limit ) - if ( val == 0 || val == 1 ) + if ( val < -8 || val > 8 ) { val &= ~1; - if ( (emit < required && GETBIT(data,emit) != 0) || (emit >= required && (rand() & 1) != 0) ) + if (GETBIT(data,emit) != 0 )//|| (emit >= required && (rand() & 1) != 0) ) val |= 1; + coef_buffers[compnum][rownum][blocknum][i] = val; emit++; } - coef_buffers[compnum][rownum][blocknum][i] = val; //printf("%i,", coef_buffers[compnum][rownum][blocknum][i]); } } From c43406d4ee32ada89a87405158dbc9028d5d2d8e Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 24 Jan 2018 21:23:27 +0400 Subject: [PATCH 083/183] Test --- iguana/exchanges/LP_privkey.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/iguana/exchanges/LP_privkey.c b/iguana/exchanges/LP_privkey.c index fdf9ed454..5903d286d 100644 --- a/iguana/exchanges/LP_privkey.c +++ b/iguana/exchanges/LP_privkey.c @@ -482,15 +482,14 @@ int32_t LP_jpg_process(int32_t *capacityp,char *inputfname,char *outputfname,uin for (i=0; i 8 ) + if ( val > 8 ) { if ( (*capacityp) < required ) { if ( (val & 1) != 0 ) SETBIT(decoded,(*capacityp)); //decoded[(*capacityp) >> 3] |= (1 << ((*capacityp)&7)); - //printf("%c",(val&1)!=0?'1':'0'); + printf("%c",(val&1)!=0?'1':'0'); } (*capacityp)++; } @@ -499,7 +498,7 @@ int32_t LP_jpg_process(int32_t *capacityp,char *inputfname,char *outputfname,uin } } } - //printf(" capacity %d required.%d power2.%d limit.%d\n",*capacityp,required,power2,limit); + printf(" capacity %d required.%d power2.%d limit.%d\n",*capacityp,required,power2,limit); if ( *capacityp > required && outputfname != 0 && outputfname[0] != 0 ) { if ((output_file = fopen(outputfname, WRITE_BINARY)) == NULL) { @@ -521,11 +520,12 @@ int32_t LP_jpg_process(int32_t *capacityp,char *inputfname,char *outputfname,uin for (i=0; i 8 ) + if ( val > 8 ) { val &= ~1; if (GETBIT(data,emit) != 0 )//|| (emit >= required && (rand() & 1) != 0) ) val |= 1; + printf("%c",(val&1)!=0?'1':'0'); coef_buffers[compnum][rownum][blocknum][i] = val; emit++; } @@ -534,6 +534,7 @@ int32_t LP_jpg_process(int32_t *capacityp,char *inputfname,char *outputfname,uin } } } + printf(" emit.%d\n",emit); // Output the new DCT coeffs to a JPEG file modified = 0; for (compnum=0; compnum 0 ) From b6895e0dd64ab1206b1d9ecbea593e62b95ec5b0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 24 Jan 2018 21:27:44 +0400 Subject: [PATCH 084/183] Test --- iguana/exchanges/LP_privkey.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_privkey.c b/iguana/exchanges/LP_privkey.c index 5903d286d..0378d35e3 100644 --- a/iguana/exchanges/LP_privkey.c +++ b/iguana/exchanges/LP_privkey.c @@ -482,7 +482,7 @@ int32_t LP_jpg_process(int32_t *capacityp,char *inputfname,char *outputfname,uin for (i=0; i 8 ) + if ( val >= 8 ) { if ( (*capacityp) < required ) { @@ -520,7 +520,7 @@ int32_t LP_jpg_process(int32_t *capacityp,char *inputfname,char *outputfname,uin for (i=0; i 8 ) + if ( val >= 8 ) { val &= ~1; if (GETBIT(data,emit) != 0 )//|| (emit >= required && (rand() & 1) != 0) ) From df3ec005e0abe7b2ff145a82be60603a26655eb2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 24 Jan 2018 21:29:51 +0400 Subject: [PATCH 085/183] Test --- iguana/exchanges/LP_privkey.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_privkey.c b/iguana/exchanges/LP_privkey.c index 0378d35e3..c490df13a 100644 --- a/iguana/exchanges/LP_privkey.c +++ b/iguana/exchanges/LP_privkey.c @@ -482,7 +482,7 @@ int32_t LP_jpg_process(int32_t *capacityp,char *inputfname,char *outputfname,uin for (i=0; i= 8 ) + if ( val <= -8 && val >= 8 ) { if ( (*capacityp) < required ) { @@ -520,7 +520,7 @@ int32_t LP_jpg_process(int32_t *capacityp,char *inputfname,char *outputfname,uin for (i=0; i= 8 ) + if ( val <= -8 && val >= 8 ) { val &= ~1; if (GETBIT(data,emit) != 0 )//|| (emit >= required && (rand() & 1) != 0) ) From 34866b48f753065650517f2fe2683cc5921451a2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 24 Jan 2018 21:32:08 +0400 Subject: [PATCH 086/183] Test --- iguana/exchanges/LP_privkey.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_privkey.c b/iguana/exchanges/LP_privkey.c index c490df13a..62b98e3d1 100644 --- a/iguana/exchanges/LP_privkey.c +++ b/iguana/exchanges/LP_privkey.c @@ -482,7 +482,7 @@ int32_t LP_jpg_process(int32_t *capacityp,char *inputfname,char *outputfname,uin for (i=0; i= 8 ) + if ( val <= -8 || val >= 8 ) { if ( (*capacityp) < required ) { @@ -520,7 +520,7 @@ int32_t LP_jpg_process(int32_t *capacityp,char *inputfname,char *outputfname,uin for (i=0; i= 8 ) + if ( val <= -8 || val >= 8 ) { val &= ~1; if (GETBIT(data,emit) != 0 )//|| (emit >= required && (rand() & 1) != 0) ) From aad8ad120d1d051fc6ff2c6e35366682997353f9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 24 Jan 2018 21:33:46 +0400 Subject: [PATCH 087/183] Test --- iguana/exchanges/LP_privkey.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_privkey.c b/iguana/exchanges/LP_privkey.c index 62b98e3d1..96d86bb92 100644 --- a/iguana/exchanges/LP_privkey.c +++ b/iguana/exchanges/LP_privkey.c @@ -482,7 +482,7 @@ int32_t LP_jpg_process(int32_t *capacityp,char *inputfname,char *outputfname,uin for (i=0; i= 8 ) + if ( val < -8 || val >= 8 ) { if ( (*capacityp) < required ) { @@ -520,7 +520,7 @@ int32_t LP_jpg_process(int32_t *capacityp,char *inputfname,char *outputfname,uin for (i=0; i= 8 ) + if ( val < -8 || val >= 8 ) { val &= ~1; if (GETBIT(data,emit) != 0 )//|| (emit >= required && (rand() & 1) != 0) ) From 9b9e375b21d32b648905aefec61ce4472121063d Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 24 Jan 2018 21:35:16 +0400 Subject: [PATCH 088/183] Test --- iguana/exchanges/LP_privkey.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_privkey.c b/iguana/exchanges/LP_privkey.c index 96d86bb92..136b2cb04 100644 --- a/iguana/exchanges/LP_privkey.c +++ b/iguana/exchanges/LP_privkey.c @@ -482,7 +482,7 @@ int32_t LP_jpg_process(int32_t *capacityp,char *inputfname,char *outputfname,uin for (i=0; i= 8 ) + if ( val < -limit || val >= limit ) { if ( (*capacityp) < required ) { @@ -520,7 +520,7 @@ int32_t LP_jpg_process(int32_t *capacityp,char *inputfname,char *outputfname,uin for (i=0; i= 8 ) + if ( val < -limit || val >= limit ) { val &= ~1; if (GETBIT(data,emit) != 0 )//|| (emit >= required && (rand() & 1) != 0) ) From d1248a70ec608ead419ca898b3e426b7d36776c9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 24 Jan 2018 21:38:03 +0400 Subject: [PATCH 089/183] Test --- iguana/exchanges/LP_privkey.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/iguana/exchanges/LP_privkey.c b/iguana/exchanges/LP_privkey.c index 136b2cb04..8b142aa12 100644 --- a/iguana/exchanges/LP_privkey.c +++ b/iguana/exchanges/LP_privkey.c @@ -489,7 +489,7 @@ int32_t LP_jpg_process(int32_t *capacityp,char *inputfname,char *outputfname,uin if ( (val & 1) != 0 ) SETBIT(decoded,(*capacityp)); //decoded[(*capacityp) >> 3] |= (1 << ((*capacityp)&7)); - printf("%c",(val&1)!=0?'1':'0'); + //printf("%c",(val&1)!=0?'1':'0'); } (*capacityp)++; } @@ -498,7 +498,7 @@ int32_t LP_jpg_process(int32_t *capacityp,char *inputfname,char *outputfname,uin } } } - printf(" capacity %d required.%d power2.%d limit.%d\n",*capacityp,required,power2,limit); + //printf(" capacity %d required.%d power2.%d limit.%d\n",*capacityp,required,power2,limit); if ( *capacityp > required && outputfname != 0 && outputfname[0] != 0 ) { if ((output_file = fopen(outputfname, WRITE_BINARY)) == NULL) { @@ -525,7 +525,7 @@ int32_t LP_jpg_process(int32_t *capacityp,char *inputfname,char *outputfname,uin val &= ~1; if (GETBIT(data,emit) != 0 )//|| (emit >= required && (rand() & 1) != 0) ) val |= 1; - printf("%c",(val&1)!=0?'1':'0'); + //printf("%c",(val&1)!=0?'1':'0'); coef_buffers[compnum][rownum][blocknum][i] = val; emit++; } @@ -534,7 +534,7 @@ int32_t LP_jpg_process(int32_t *capacityp,char *inputfname,char *outputfname,uin } } } - printf(" emit.%d\n",emit); + //printf(" emit.%d\n",emit); // Output the new DCT coeffs to a JPEG file modified = 0; for (compnum=0; compnum 0 ) From d3b8710651a4a4bf8ca20398c1ba4b4544598a8d Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 24 Jan 2018 22:11:11 +0400 Subject: [PATCH 090/183] Test --- iguana/exchanges/LP_privkey.c | 89 ++++++++++++++++++++++++++++++----- 1 file changed, 78 insertions(+), 11 deletions(-) diff --git a/iguana/exchanges/LP_privkey.c b/iguana/exchanges/LP_privkey.c index 8b142aa12..6a300363c 100644 --- a/iguana/exchanges/LP_privkey.c +++ b/iguana/exchanges/LP_privkey.c @@ -422,10 +422,61 @@ void LP_privkey_tests() } +#define JPG_ENCRYPTED_MAXSIZE 32768 + +int32_t JPG_encrypt(uint16_t ind,uint8_t encoded[JPG_ENCRYPTED_MAXSIZE],uint8_t *msg,int32_t msglen,bits256 privkey) +{ + bits256 pubkey; int32_t len = 2; uint8_t space[JPG_ENCRYPTED_MAXSIZE],*nonce,*cipher; uint32_t crc32=0; + pubkey = acct777_pubkey(privkey); + encoded[len++] = msglen & 0xff; + encoded[len++] = (msglen >> 8) & 0xff; + encoded[len++] = ind & 0xff; + encoded[len++] = (ind >> 8) & 0xff; + nonce = &encoded[len]; + OS_randombytes(nonce,crypto_box_NONCEBYTES); + cipher = &encoded[len + crypto_box_NONCEBYTES]; + msglen = _SuperNET_cipher(nonce,&encoded[len + crypto_box_NONCEBYTES],msg,msglen,pubkey,privkey,space); + msglen += crypto_box_NONCEBYTES; + crc32 = calc_crc32(0,&encoded[2],msglen + len - 2); + encoded[0] = crc32 & 0xff; + encoded[1] = (crc32 >> 8) & 0xff; + msg = encoded; + msglen += len; + return(msglen); +} + +uint8_t *JPG_decrypt(int32_t *indp,int32_t *recvlenp,uint8_t space[JPG_ENCRYPTED_MAXSIZE + crypto_box_ZEROBYTES],uint8_t *encoded,bits256 privkey) +{ + bits256 pubkey; uint8_t *extracted=0,*nonce,*cipher; uint32_t crc32; uint16_t msglen,ind,crc16; int32_t cipherlen,len = 6; + *recvlenp = 0; + *indp = -1; + pubkey = acct777_pubkey(privkey); + crc16 = ((int32_t)encoded[1] << 8) | encoded[0]; + msglen = ((int32_t)encoded[3] << 8) | encoded[2]; + ind = ((int32_t)encoded[5] << 8) | encoded[4]; + crc32 = calc_crc32(0,&encoded[2],msglen + len - 2); + if ( (uint16_t)crc32 == crc16 ) + { + nonce = &encoded[len]; + cipher = &encoded[len + crypto_box_NONCEBYTES]; + cipherlen = msglen - (len + crypto_box_NONCEBYTES); + if ( cipherlen > 0 && cipherlen <= JPG_ENCRYPTED_MAXSIZE + crypto_box_ZEROBYTES ) + { + if ( (extracted= _SuperNET_decipher(nonce,cipher,space,cipherlen,pubkey,privkey)) != 0 ) + { + msglen = (cipherlen - crypto_box_ZEROBYTES); + *recvlenp = msglen; + *indp = ind; + } + } else printf("cipher.%d too big for %d\n",cipherlen,JPG_ENCRYPTED_MAXSIZE + crypto_box_ZEROBYTES); + } else printf("JPG_decrypt crc16 mismatch %08x vs %04x\n",crc32,crc16); + return(extracted); +} + // from https://github.com/owencm/C-Steganography-Framework #include "../../crypto777/jpeg/cdjpeg.h" // Common decls for compressing and decompressing jpegs -int32_t LP_jpg_process(int32_t *capacityp,char *inputfname,char *outputfname,uint8_t *decoded,uint8_t *data,int32_t required,int32_t power2,char *passphrase) +int32_t LP_jpg_process(int32_t *capacityp,char *inputfname,char *outputfname,uint8_t *decoded,uint8_t *origdata,int32_t required,int32_t power2,char *password) { struct jpeg_decompress_struct inputinfo; struct jpeg_compress_struct outputinfo; @@ -434,7 +485,27 @@ int32_t LP_jpg_process(int32_t *capacityp,char *inputfname,char *outputfname,uin JDIMENSION i,compnum,rownum,blocknum; JBLOCKARRAY coef_buffers[MAX_COMPONENTS]; JBLOCKARRAY row_ptrs[MAX_COMPONENTS]; - FILE *input_file,*output_file; int32_t val,modified,emit,totalrows,limit; + bits256 privkey; FILE *input_file,*output_file; int32_t checkind,recvlen,msglen,val,modified,emit,totalrows,limit,ind=0; uint8_t *decrypted,*space,*data=0; + if ((input_file = fopen(inputfname, READ_BINARY)) == NULL) + { + fprintf(stderr, "Can't open %s\n", inputfname); + //exit(EXIT_FAILURE); + return(-1); + } + if ( 0 && origdata != 0 && password != 0 && password[0] != 0 ) + { + if ( required/8 > JPG_ENCRYPTED_MAXSIZE-60 ) + return(-1); + data = calloc(1,required/8+512); + vcalc_sha256(0,privkey.bytes,(uint8_t *)password,(int32_t)strlen(password)); + msglen = JPG_encrypt(ind,data,origdata,required/8,privkey); + { + space = calloc(1,required/8+512); + if ( (decrypted= JPG_decrypt(&checkind,&recvlen,space,data,privkey)) == 0 || recvlen != required/8 || checkind != ind || memcmp(decrypted,origdata,required/8) != 0 ) + printf("decryption error: checkind.%d vs %d, recvlen.%d vs %d, decrypted.%p\n",checkind,ind,recvlen,required/8,decrypted); + free(space); + } + } else data = origdata; if ( power2 < 0 || power2 > 16 ) power2 = 4; limit = 1; @@ -443,12 +514,6 @@ int32_t LP_jpg_process(int32_t *capacityp,char *inputfname,char *outputfname,uin limit <<= 1; power2--; } - if ((input_file = fopen(inputfname, READ_BINARY)) == NULL) - { - fprintf(stderr, "Can't open %s\n", inputfname); - //exit(EXIT_FAILURE); - return(-1); - } // Initialize the JPEG compression and decompression objects with default error handling inputinfo.err = jpeg_std_error(&jerr); jpeg_create_decompress(&inputinfo); @@ -482,7 +547,7 @@ int32_t LP_jpg_process(int32_t *capacityp,char *inputfname,char *outputfname,uin for (i=0; i= limit ) + if ( val >= limit ) //val < -limit || { if ( (*capacityp) < required ) { @@ -503,7 +568,9 @@ int32_t LP_jpg_process(int32_t *capacityp,char *inputfname,char *outputfname,uin { if ((output_file = fopen(outputfname, WRITE_BINARY)) == NULL) { fprintf(stderr, "Can't open %s\n", outputfname); - exit(EXIT_FAILURE); + if ( data != origdata ) + free(data); + return(-1); } outputinfo.err = jpeg_std_error(&jerr); jpeg_create_compress(&outputinfo); @@ -520,7 +587,7 @@ int32_t LP_jpg_process(int32_t *capacityp,char *inputfname,char *outputfname,uin for (i=0; i= limit ) + if ( val >= limit ) //val < -limit || { val &= ~1; if (GETBIT(data,emit) != 0 )//|| (emit >= required && (rand() & 1) != 0) ) From baa026a29a6d4166cec083cd87de45edaf499c5c Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 24 Jan 2018 22:16:28 +0400 Subject: [PATCH 091/183] Test --- iguana/exchanges/LP_privkey.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/iguana/exchanges/LP_privkey.c b/iguana/exchanges/LP_privkey.c index 6a300363c..d2035cf54 100644 --- a/iguana/exchanges/LP_privkey.c +++ b/iguana/exchanges/LP_privkey.c @@ -492,7 +492,7 @@ int32_t LP_jpg_process(int32_t *capacityp,char *inputfname,char *outputfname,uin //exit(EXIT_FAILURE); return(-1); } - if ( 0 && origdata != 0 && password != 0 && password[0] != 0 ) + if ( origdata != 0 && password != 0 && password[0] != 0 ) { if ( required/8 > JPG_ENCRYPTED_MAXSIZE-60 ) return(-1); @@ -547,13 +547,12 @@ int32_t LP_jpg_process(int32_t *capacityp,char *inputfname,char *outputfname,uin for (i=0; i= limit ) //val < -limit || + if ( val < -limit || val >= limit ) { if ( (*capacityp) < required ) { if ( (val & 1) != 0 ) SETBIT(decoded,(*capacityp)); - //decoded[(*capacityp) >> 3] |= (1 << ((*capacityp)&7)); //printf("%c",(val&1)!=0?'1':'0'); } (*capacityp)++; @@ -587,7 +586,7 @@ int32_t LP_jpg_process(int32_t *capacityp,char *inputfname,char *outputfname,uin for (i=0; i= limit ) //val < -limit || + if ( val < -limit || val >= limit ) { val &= ~1; if (GETBIT(data,emit) != 0 )//|| (emit >= required && (rand() & 1) != 0) ) From 753736d33e892d18ce95b1cad98739275f63a565 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 24 Jan 2018 22:21:58 +0400 Subject: [PATCH 092/183] Test --- iguana/exchanges/LP_privkey.c | 40 ++++++++++++++--------------------- 1 file changed, 16 insertions(+), 24 deletions(-) diff --git a/iguana/exchanges/LP_privkey.c b/iguana/exchanges/LP_privkey.c index d2035cf54..fe0d11826 100644 --- a/iguana/exchanges/LP_privkey.c +++ b/iguana/exchanges/LP_privkey.c @@ -426,7 +426,7 @@ void LP_privkey_tests() int32_t JPG_encrypt(uint16_t ind,uint8_t encoded[JPG_ENCRYPTED_MAXSIZE],uint8_t *msg,int32_t msglen,bits256 privkey) { - bits256 pubkey; int32_t len = 2; uint8_t space[JPG_ENCRYPTED_MAXSIZE],*nonce,*cipher; uint32_t crc32=0; + bits256 pubkey; int32_t len = 0; uint8_t space[JPG_ENCRYPTED_MAXSIZE],*nonce,*cipher; pubkey = acct777_pubkey(privkey); encoded[len++] = msglen & 0xff; encoded[len++] = (msglen >> 8) & 0xff; @@ -437,9 +437,6 @@ int32_t JPG_encrypt(uint16_t ind,uint8_t encoded[JPG_ENCRYPTED_MAXSIZE],uint8_t cipher = &encoded[len + crypto_box_NONCEBYTES]; msglen = _SuperNET_cipher(nonce,&encoded[len + crypto_box_NONCEBYTES],msg,msglen,pubkey,privkey,space); msglen += crypto_box_NONCEBYTES; - crc32 = calc_crc32(0,&encoded[2],msglen + len - 2); - encoded[0] = crc32 & 0xff; - encoded[1] = (crc32 >> 8) & 0xff; msg = encoded; msglen += len; return(msglen); @@ -447,29 +444,24 @@ int32_t JPG_encrypt(uint16_t ind,uint8_t encoded[JPG_ENCRYPTED_MAXSIZE],uint8_t uint8_t *JPG_decrypt(int32_t *indp,int32_t *recvlenp,uint8_t space[JPG_ENCRYPTED_MAXSIZE + crypto_box_ZEROBYTES],uint8_t *encoded,bits256 privkey) { - bits256 pubkey; uint8_t *extracted=0,*nonce,*cipher; uint32_t crc32; uint16_t msglen,ind,crc16; int32_t cipherlen,len = 6; + bits256 pubkey; uint8_t *extracted=0,*nonce,*cipher; uint16_t msglen,ind; int32_t cipherlen,len = 4; *recvlenp = 0; *indp = -1; pubkey = acct777_pubkey(privkey); - crc16 = ((int32_t)encoded[1] << 8) | encoded[0]; - msglen = ((int32_t)encoded[3] << 8) | encoded[2]; - ind = ((int32_t)encoded[5] << 8) | encoded[4]; - crc32 = calc_crc32(0,&encoded[2],msglen + len - 2); - if ( (uint16_t)crc32 == crc16 ) + msglen = ((int32_t)encoded[1] << 8) | encoded[0]; + ind = ((int32_t)encoded[3] << 8) | encoded[2]; + nonce = &encoded[len]; + cipher = &encoded[len + crypto_box_NONCEBYTES]; + cipherlen = msglen - (len + crypto_box_NONCEBYTES); + if ( cipherlen > 0 && cipherlen <= JPG_ENCRYPTED_MAXSIZE + crypto_box_ZEROBYTES ) { - nonce = &encoded[len]; - cipher = &encoded[len + crypto_box_NONCEBYTES]; - cipherlen = msglen - (len + crypto_box_NONCEBYTES); - if ( cipherlen > 0 && cipherlen <= JPG_ENCRYPTED_MAXSIZE + crypto_box_ZEROBYTES ) + if ( (extracted= _SuperNET_decipher(nonce,cipher,space,cipherlen,pubkey,privkey)) != 0 ) { - if ( (extracted= _SuperNET_decipher(nonce,cipher,space,cipherlen,pubkey,privkey)) != 0 ) - { - msglen = (cipherlen - crypto_box_ZEROBYTES); - *recvlenp = msglen; - *indp = ind; - } - } else printf("cipher.%d too big for %d\n",cipherlen,JPG_ENCRYPTED_MAXSIZE + crypto_box_ZEROBYTES); - } else printf("JPG_decrypt crc16 mismatch %08x vs %04x\n",crc32,crc16); + msglen = (cipherlen - crypto_box_ZEROBYTES); + *recvlenp = msglen; + *indp = ind; + } + } else printf("cipher.%d too big for %d\n",cipherlen,JPG_ENCRYPTED_MAXSIZE + crypto_box_ZEROBYTES); return(extracted); } @@ -506,8 +498,8 @@ int32_t LP_jpg_process(int32_t *capacityp,char *inputfname,char *outputfname,uin free(space); } } else data = origdata; - if ( power2 < 0 || power2 > 16 ) - power2 = 4; + if ( power2 < 0 || power2 > 30 ) + power2 = 7; limit = 1; while ( power2 > 0 ) { From 7c274c8c19068a79f7eda9b6da8fe00a5e265c91 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 24 Jan 2018 22:30:25 +0400 Subject: [PATCH 093/183] Test --- iguana/exchanges/LP_privkey.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/iguana/exchanges/LP_privkey.c b/iguana/exchanges/LP_privkey.c index fe0d11826..6e9e3fe53 100644 --- a/iguana/exchanges/LP_privkey.c +++ b/iguana/exchanges/LP_privkey.c @@ -432,6 +432,7 @@ int32_t JPG_encrypt(uint16_t ind,uint8_t encoded[JPG_ENCRYPTED_MAXSIZE],uint8_t encoded[len++] = (msglen >> 8) & 0xff; encoded[len++] = ind & 0xff; encoded[len++] = (ind >> 8) & 0xff; + printf("msglen.%d ind.%d -> %d %d %d %d\n",msglen,ind,encoded[0],encoded[1],encoded[2],encoded[3]); nonce = &encoded[len]; OS_randombytes(nonce,crypto_box_NONCEBYTES); cipher = &encoded[len + crypto_box_NONCEBYTES]; @@ -439,6 +440,9 @@ int32_t JPG_encrypt(uint16_t ind,uint8_t encoded[JPG_ENCRYPTED_MAXSIZE],uint8_t msglen += crypto_box_NONCEBYTES; msg = encoded; msglen += len; + int32_t i; for (i=0; i Date: Wed, 24 Jan 2018 22:36:22 +0400 Subject: [PATCH 094/183] Test --- iguana/exchanges/LP_privkey.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/iguana/exchanges/LP_privkey.c b/iguana/exchanges/LP_privkey.c index 6e9e3fe53..6d48f98a5 100644 --- a/iguana/exchanges/LP_privkey.c +++ b/iguana/exchanges/LP_privkey.c @@ -440,6 +440,8 @@ int32_t JPG_encrypt(uint16_t ind,uint8_t encoded[JPG_ENCRYPTED_MAXSIZE],uint8_t msglen += crypto_box_NONCEBYTES; msg = encoded; msglen += len; + encoded[0] = msglen & 0xff; + encoded[1] = (msglen >> 8) & 0xff; int32_t i; for (i=0; i Date: Wed, 24 Jan 2018 22:40:03 +0400 Subject: [PATCH 095/183] Test --- iguana/exchanges/LP_privkey.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/iguana/exchanges/LP_privkey.c b/iguana/exchanges/LP_privkey.c index 6d48f98a5..34af3c370 100644 --- a/iguana/exchanges/LP_privkey.c +++ b/iguana/exchanges/LP_privkey.c @@ -426,13 +426,10 @@ void LP_privkey_tests() int32_t JPG_encrypt(uint16_t ind,uint8_t encoded[JPG_ENCRYPTED_MAXSIZE],uint8_t *msg,int32_t msglen,bits256 privkey) { - bits256 pubkey; int32_t len = 0; uint8_t space[JPG_ENCRYPTED_MAXSIZE],*nonce,*cipher; + bits256 pubkey; int32_t len = 2; uint8_t space[JPG_ENCRYPTED_MAXSIZE],*nonce,*cipher; pubkey = acct777_pubkey(privkey); - encoded[len++] = msglen & 0xff; - encoded[len++] = (msglen >> 8) & 0xff; encoded[len++] = ind & 0xff; encoded[len++] = (ind >> 8) & 0xff; - printf("msglen.%d ind.%d -> %d %d %d %d\n",msglen,ind,encoded[0],encoded[1],encoded[2],encoded[3]); nonce = &encoded[len]; OS_randombytes(nonce,crypto_box_NONCEBYTES); cipher = &encoded[len + crypto_box_NONCEBYTES]; @@ -442,9 +439,6 @@ int32_t JPG_encrypt(uint16_t ind,uint8_t encoded[JPG_ENCRYPTED_MAXSIZE],uint8_t msglen += len; encoded[0] = msglen & 0xff; encoded[1] = (msglen >> 8) & 0xff; - int32_t i; for (i=0; i Date: Wed, 24 Jan 2018 22:46:50 +0400 Subject: [PATCH 096/183] Test --- iguana/exchanges/LP_privkey.c | 47 +++++++++++++++++++++++++---------- 1 file changed, 34 insertions(+), 13 deletions(-) diff --git a/iguana/exchanges/LP_privkey.c b/iguana/exchanges/LP_privkey.c index 34af3c370..6b047b492 100644 --- a/iguana/exchanges/LP_privkey.c +++ b/iguana/exchanges/LP_privkey.c @@ -468,7 +468,7 @@ uint8_t *JPG_decrypt(int32_t *indp,int32_t *recvlenp,uint8_t space[JPG_ENCRYPTED // from https://github.com/owencm/C-Steganography-Framework #include "../../crypto777/jpeg/cdjpeg.h" // Common decls for compressing and decompressing jpegs -int32_t LP_jpg_process(int32_t *capacityp,char *inputfname,char *outputfname,uint8_t *decoded,uint8_t *origdata,int32_t required,int32_t power2,char *password) +int32_t LP_jpg_process(int32_t *capacityp,char *inputfname,char *outputfname,uint8_t *decoded,uint8_t *origdata,int32_t origrequired,int32_t power2,char *password) { struct jpeg_decompress_struct inputinfo; struct jpeg_compress_struct outputinfo; @@ -477,31 +477,37 @@ int32_t LP_jpg_process(int32_t *capacityp,char *inputfname,char *outputfname,uin JDIMENSION i,compnum,rownum,blocknum; JBLOCKARRAY coef_buffers[MAX_COMPONENTS]; JBLOCKARRAY row_ptrs[MAX_COMPONENTS]; - bits256 privkey; FILE *input_file,*output_file; int32_t checkind,recvlen,msglen,val,modified,emit,totalrows,limit,ind=0; uint8_t *decrypted,*space,*data=0; + bits256 privkey; FILE *input_file,*output_file; int32_t checkind,recvlen,msglen,val,modified,emit,totalrows,limit,required,ind=0; uint8_t *decrypted,*space,*data=0; if ((input_file = fopen(inputfname, READ_BINARY)) == NULL) { fprintf(stderr, "Can't open %s\n", inputfname); //exit(EXIT_FAILURE); return(-1); } - if ( origdata != 0 && password != 0 && password[0] != 0 ) + required = origrequired; + memset(privkey.bytes,0,sizeof(privkey)); + if ( password != 0 && password[0] != 0 ) { if ( required/8 > JPG_ENCRYPTED_MAXSIZE-60 ) return(-1); data = calloc(1,required/8+512); vcalc_sha256(0,privkey.bytes,(uint8_t *)password,(int32_t)strlen(password)); - msglen = JPG_encrypt(ind,data,origdata,required/8,privkey); + if ( origdata != 0 ) { - space = calloc(1,required/8+512); - if ( (decrypted= JPG_decrypt(&checkind,&recvlen,space,data,privkey)) == 0 || recvlen != required/8 || checkind != ind || memcmp(decrypted,origdata,required/8) != 0 ) - printf("decryption error: checkind.%d vs %d, recvlen.%d vs %d, decrypted.%p\n",checkind,ind,recvlen,required/8,decrypted); - else + msglen = JPG_encrypt(ind,data,origdata,required/8,privkey); + required = msglen * 8; { - for (i=0; i 30 ) @@ -560,7 +566,20 @@ int32_t LP_jpg_process(int32_t *capacityp,char *inputfname,char *outputfname,uin } } } - //printf(" capacity %d required.%d power2.%d limit.%d\n",*capacityp,required,power2,limit); + if ( password != 0 && password[0] != 0 ) + { + space = calloc(1,JPG_ENCRYPTED_MAXSIZE); + if ( (decrypted= JPG_decrypt(&checkind,&recvlen,space,decoded,privkey)) == 0 || recvlen != required/8 || checkind != ind || memcmp(decrypted,origdata,required/8) != 0 ) + printf("decryption error: checkind.%d vs %d, recvlen.%d vs %d, decrypted.%p\n",checkind,ind,recvlen,required/8,decrypted); + else + { + for (i=0; i required && outputfname != 0 && outputfname[0] != 0 ) { if ((output_file = fopen(outputfname, WRITE_BINARY)) == NULL) { @@ -631,6 +650,8 @@ int32_t LP_jpg_process(int32_t *capacityp,char *inputfname,char *outputfname,uin free(block_row_size); free(width_in_blocks); free(height_in_blocks); + if ( data != origdata ) + free(data); return(modified); } From cf46d0d8df3fce3cdb16ee3d33bea9a6395d306d Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 24 Jan 2018 22:55:37 +0400 Subject: [PATCH 097/183] Test --- iguana/exchanges/LP_commands.c | 4 ++-- iguana/exchanges/LP_privkey.c | 25 +++++++++++++------------ 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/iguana/exchanges/LP_commands.c b/iguana/exchanges/LP_commands.c index c9140dea9..f85c41e5e 100644 --- a/iguana/exchanges/LP_commands.c +++ b/iguana/exchanges/LP_commands.c @@ -161,7 +161,7 @@ bot_stop(botid)\n\ bot_pause(botid)\n\ instantdex_deposit(weeks, amount, broadcast=1)\n\ instantdex_claim()\n\ -jpg(srcfile, destfile, power2=7, password, data="", required)\n\ +jpg(srcfile, destfile, power2=7, password, data="", required, ind=0)\n\ \"}")); //sell(base, rel, price, basevolume, timeout=10, duration=3600)\n\ @@ -240,7 +240,7 @@ jpg(srcfile, destfile, power2=7, password, data="", required)\n\ } else if ( strcmp(method,"jpg") == 0 ) { - return(LP_jpg(jstr(argjson,"srcfile"),jstr(argjson,"destfile"),jint(argjson,"power2"),jstr(argjson,"password"),jstr(argjson,"data"),jint(argjson,"required"))); + return(LP_jpg(jstr(argjson,"srcfile"),jstr(argjson,"destfile"),jint(argjson,"power2"),jstr(argjson,"password"),jstr(argjson,"data"),jint(argjson,"required"),juint(argjson,"ind"))); } /*else if ( strcmp(method,"sendmessage") == 0 ) { diff --git a/iguana/exchanges/LP_privkey.c b/iguana/exchanges/LP_privkey.c index 6b047b492..7464faf00 100644 --- a/iguana/exchanges/LP_privkey.c +++ b/iguana/exchanges/LP_privkey.c @@ -442,7 +442,7 @@ int32_t JPG_encrypt(uint16_t ind,uint8_t encoded[JPG_ENCRYPTED_MAXSIZE],uint8_t return(msglen); } -uint8_t *JPG_decrypt(int32_t *indp,int32_t *recvlenp,uint8_t space[JPG_ENCRYPTED_MAXSIZE + crypto_box_ZEROBYTES],uint8_t *encoded,bits256 privkey) +uint8_t *JPG_decrypt(uint16_t *indp,int32_t *recvlenp,uint8_t space[JPG_ENCRYPTED_MAXSIZE + crypto_box_ZEROBYTES],uint8_t *encoded,bits256 privkey) { bits256 pubkey; uint8_t *extracted=0,*nonce,*cipher; uint16_t msglen,ind; int32_t cipherlen,len = 4; *recvlenp = 0; @@ -468,7 +468,7 @@ uint8_t *JPG_decrypt(int32_t *indp,int32_t *recvlenp,uint8_t space[JPG_ENCRYPTED // from https://github.com/owencm/C-Steganography-Framework #include "../../crypto777/jpeg/cdjpeg.h" // Common decls for compressing and decompressing jpegs -int32_t LP_jpg_process(int32_t *capacityp,char *inputfname,char *outputfname,uint8_t *decoded,uint8_t *origdata,int32_t origrequired,int32_t power2,char *password) +int32_t LP_jpg_process(int32_t *capacityp,char *inputfname,char *outputfname,uint8_t *decoded,uint8_t *origdata,int32_t origrequired,int32_t power2,char *password,uint16_t *indp) { struct jpeg_decompress_struct inputinfo; struct jpeg_compress_struct outputinfo; @@ -477,7 +477,7 @@ int32_t LP_jpg_process(int32_t *capacityp,char *inputfname,char *outputfname,uin JDIMENSION i,compnum,rownum,blocknum; JBLOCKARRAY coef_buffers[MAX_COMPONENTS]; JBLOCKARRAY row_ptrs[MAX_COMPONENTS]; - bits256 privkey; FILE *input_file,*output_file; int32_t checkind,recvlen,msglen,val,modified,emit,totalrows,limit,required,ind=0; uint8_t *decrypted,*space,*data=0; + bits256 privkey; FILE *input_file,*output_file; int32_t recvlen,msglen,val,modified,emit,totalrows,limit,required; uint16_t checkind; uint8_t *decrypted,*space,*data=0; if ((input_file = fopen(inputfname, READ_BINARY)) == NULL) { fprintf(stderr, "Can't open %s\n", inputfname); @@ -494,17 +494,17 @@ int32_t LP_jpg_process(int32_t *capacityp,char *inputfname,char *outputfname,uin vcalc_sha256(0,privkey.bytes,(uint8_t *)password,(int32_t)strlen(password)); if ( origdata != 0 ) { - msglen = JPG_encrypt(ind,data,origdata,required/8,privkey); + msglen = JPG_encrypt(*indp,data,origdata,required/8,privkey); required = msglen * 8; { space = calloc(1,JPG_ENCRYPTED_MAXSIZE); - if ( (decrypted= JPG_decrypt(&checkind,&recvlen,space,data,privkey)) == 0 || recvlen != required/8 || checkind != ind || memcmp(decrypted,origdata,required/8) != 0 ) - printf("decryption error: checkind.%d vs %d, recvlen.%d vs %d, decrypted.%p\n",checkind,ind,recvlen,required/8,decrypted); + if ( (decrypted= JPG_decrypt(&checkind,&recvlen,space,data,privkey)) == 0 || recvlen != origrequired/8 || checkind != *indp || memcmp(decrypted,origdata,origrequired/8) != 0 ) + printf("decryption error: checkind.%d vs %d, recvlen.%d vs %d, decrypted.%p\n",checkind,*indp,recvlen,origrequired/8,decrypted); else { for (i=0; i 0 ) decoded = calloc(1,len+required); - if ( (modified= LP_jpg_process(&capacity,srcfile,destfile,decoded,data,required,power2,passphrase)) < 0 ) + if ( (modified= LP_jpg_process(&capacity,srcfile,destfile,decoded,data,required,power2,passphrase,&ind)) < 0 ) jaddstr(retjson,"error","file not found"); else { @@ -687,6 +687,7 @@ char *LP_jpg(char *srcfile,char *destfile,int32_t power2,char *passphrase,char * jaddnum(retjson,"power2",power2); jaddnum(retjson,"capacity",capacity); jaddnum(retjson,"required",required); + jaddnum(retjson,"ind",ind); } if ( decoded != 0 ) { From 024d65d98ff1f3fbf89e299cc5c528672fa041d2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 24 Jan 2018 23:01:30 +0400 Subject: [PATCH 098/183] Test --- iguana/exchanges/LP_privkey.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/iguana/exchanges/LP_privkey.c b/iguana/exchanges/LP_privkey.c index 7464faf00..0c5756963 100644 --- a/iguana/exchanges/LP_privkey.c +++ b/iguana/exchanges/LP_privkey.c @@ -439,7 +439,10 @@ int32_t JPG_encrypt(uint16_t ind,uint8_t encoded[JPG_ENCRYPTED_MAXSIZE],uint8_t msglen += len; encoded[0] = msglen & 0xff; encoded[1] = (msglen >> 8) & 0xff; - return(msglen); + int32_t i; for (i=0; i Date: Wed, 24 Jan 2018 23:04:32 +0400 Subject: [PATCH 099/183] Test --- iguana/exchanges/LP_privkey.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_privkey.c b/iguana/exchanges/LP_privkey.c index 0c5756963..4255ee142 100644 --- a/iguana/exchanges/LP_privkey.c +++ b/iguana/exchanges/LP_privkey.c @@ -514,7 +514,7 @@ int32_t LP_jpg_process(int32_t *capacityp,char *inputfname,char *outputfname,uin } free(space); } - } + } else required += 60 * 8; } else data = origdata; if ( power2 < 0 || power2 > 30 ) power2 = 7; From 800f69b8094f116786063e9acd914e5ca4ce64a4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 24 Jan 2018 23:08:08 +0400 Subject: [PATCH 100/183] Test --- iguana/exchanges/LP_privkey.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/iguana/exchanges/LP_privkey.c b/iguana/exchanges/LP_privkey.c index 4255ee142..5610825bb 100644 --- a/iguana/exchanges/LP_privkey.c +++ b/iguana/exchanges/LP_privkey.c @@ -453,9 +453,6 @@ uint8_t *JPG_decrypt(uint16_t *indp,int32_t *recvlenp,uint8_t space[JPG_ENCRYPTE pubkey = acct777_pubkey(privkey); msglen = ((int32_t)encoded[1] << 8) | encoded[0]; ind = ((int32_t)encoded[3] << 8) | encoded[2]; - int32_t i; for (i=0; i<64; i++) - printf("%02x",encoded[i]); - printf(" encoded\n"); nonce = &encoded[len]; cipher = &encoded[len + crypto_box_NONCEBYTES]; cipherlen = msglen - (len + crypto_box_NONCEBYTES); @@ -463,6 +460,9 @@ uint8_t *JPG_decrypt(uint16_t *indp,int32_t *recvlenp,uint8_t space[JPG_ENCRYPTE { if ( (extracted= _SuperNET_decipher(nonce,cipher,space,cipherlen,pubkey,privkey)) != 0 ) { + int32_t i; for (i=0; i Date: Wed, 24 Jan 2018 23:13:47 +0400 Subject: [PATCH 101/183] Test --- iguana/exchanges/LP_privkey.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_privkey.c b/iguana/exchanges/LP_privkey.c index 5610825bb..558c413a0 100644 --- a/iguana/exchanges/LP_privkey.c +++ b/iguana/exchanges/LP_privkey.c @@ -467,7 +467,7 @@ uint8_t *JPG_decrypt(uint16_t *indp,int32_t *recvlenp,uint8_t space[JPG_ENCRYPTE *recvlenp = msglen; *indp = ind; } - } else printf("cipher.%d too big for %d\n",cipherlen,JPG_ENCRYPTED_MAXSIZE + crypto_box_ZEROBYTES); + } //else printf("cipher.%d too big for %d\n",cipherlen,JPG_ENCRYPTED_MAXSIZE + crypto_box_ZEROBYTES); return(extracted); } @@ -700,7 +700,7 @@ char *LP_jpg(char *srcfile,char *destfile,int32_t power2,char *passphrase,char * { if ( capacity > 0 ) { - printf("len.%d required.%d capacity.%d\n",len,required,capacity); + //printf("len.%d required.%d capacity.%d\n",len,required,capacity); decodedstr = calloc(1,(len+required)*2+1); init_hexbytes_noT(decodedstr,decoded,required/8); jaddstr(retjson,"decoded",decodedstr); From bf22122b41092e03c342bcde08ab2a2483d776f0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 24 Jan 2018 23:15:57 +0400 Subject: [PATCH 102/183] Test --- iguana/exchanges/LP_privkey.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/iguana/exchanges/LP_privkey.c b/iguana/exchanges/LP_privkey.c index 558c413a0..453a6cb91 100644 --- a/iguana/exchanges/LP_privkey.c +++ b/iguana/exchanges/LP_privkey.c @@ -510,7 +510,7 @@ int32_t LP_jpg_process(int32_t *capacityp,char *inputfname,char *outputfname,uin { for (i=0; i Date: Wed, 24 Jan 2018 23:26:23 +0400 Subject: [PATCH 103/183] Test --- iguana/exchanges/jpg | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/jpg b/iguana/exchanges/jpg index 69cb6a894..7cdd04446 100755 --- a/iguana/exchanges/jpg +++ b/iguana/exchanges/jpg @@ -1,3 +1,3 @@ source userpass -curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"jpg\",\"srcfile\":\"/root/boost_1_64_0/libs/gil/doc/doxygen/images/monkey_steps.jpg\",\"destfile\":\"dest.jpg\",\"power2\":3,\"passphrase\":\"default\",\"data\":\"68656c6c6f20776f726c64\",\"required\":88}" -curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"jpg\",\"srcfile\":\"dest.jpg\",\"power2\":3,\"passphrase\":\"default\",\"required\":88}" +curl --url "http://127.0.0.1:7783" --data "{\"password\":\"123\",\"ind\":3453,\"userpass\":\"$userpass\",\"method\":\"jpg\",\"srcfile\":\"/root/boost_1_64_0/libs/gil/doc/doxygen/images/monkey_steps.jpg\",\"destfile\":\"dest.jpg\",\"power2\":3,\"data\":\"68656c6c6f20776f726c64\",\"required\":88}" +curl --url "http://127.0.0.1:7783" --data "{\\"password\":\"123\","userpass\":\"$userpass\",\"method\":\"jpg\",\"srcfile\":\"dest.jpg\",\"power2\":3,\"required\":88}" From 080c7d7c5350ad6f67bf8c618b6f1b2ece7dd7d5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 24 Jan 2018 23:27:27 +0400 Subject: [PATCH 104/183] Test --- iguana/exchanges/jpg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/jpg b/iguana/exchanges/jpg index 7cdd04446..595fbdbb2 100755 --- a/iguana/exchanges/jpg +++ b/iguana/exchanges/jpg @@ -1,3 +1,3 @@ source userpass curl --url "http://127.0.0.1:7783" --data "{\"password\":\"123\",\"ind\":3453,\"userpass\":\"$userpass\",\"method\":\"jpg\",\"srcfile\":\"/root/boost_1_64_0/libs/gil/doc/doxygen/images/monkey_steps.jpg\",\"destfile\":\"dest.jpg\",\"power2\":3,\"data\":\"68656c6c6f20776f726c64\",\"required\":88}" -curl --url "http://127.0.0.1:7783" --data "{\\"password\":\"123\","userpass\":\"$userpass\",\"method\":\"jpg\",\"srcfile\":\"dest.jpg\",\"power2\":3,\"required\":88}" +curl --url "http://127.0.0.1:7783" --data "{\"password\":\"123\","userpass\":\"$userpass\",\"method\":\"jpg\",\"srcfile\":\"dest.jpg\",\"power2\":3,\"required\":88}" From 5c964934e978c49be076cfd244769a1848b4bd6f Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 24 Jan 2018 23:29:33 +0400 Subject: [PATCH 105/183] Fix jpg --- iguana/exchanges/jpg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/jpg b/iguana/exchanges/jpg index 595fbdbb2..1809d9aa0 100755 --- a/iguana/exchanges/jpg +++ b/iguana/exchanges/jpg @@ -1,3 +1,3 @@ source userpass curl --url "http://127.0.0.1:7783" --data "{\"password\":\"123\",\"ind\":3453,\"userpass\":\"$userpass\",\"method\":\"jpg\",\"srcfile\":\"/root/boost_1_64_0/libs/gil/doc/doxygen/images/monkey_steps.jpg\",\"destfile\":\"dest.jpg\",\"power2\":3,\"data\":\"68656c6c6f20776f726c64\",\"required\":88}" -curl --url "http://127.0.0.1:7783" --data "{\"password\":\"123\","userpass\":\"$userpass\",\"method\":\"jpg\",\"srcfile\":\"dest.jpg\",\"power2\":3,\"required\":88}" +curl --url "http://127.0.0.1:7783" --data "{\"password\":\"123\",\"userpass\":\"$userpass\",\"method\":\"jpg\",\"srcfile\":\"dest.jpg\",\"power2\":3,\"required\":88}" From 3378bacce7c76236c4f372c412ef7b67bea678d7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 24 Jan 2018 23:41:21 +0400 Subject: [PATCH 106/183] Fix getpeersIP --- iguana/exchanges/getpeersIP | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/iguana/exchanges/getpeersIP b/iguana/exchanges/getpeersIP index 7c532e609..8fd44da30 100755 --- a/iguana/exchanges/getpeersIP +++ b/iguana/exchanges/getpeersIP @@ -1,11 +1,11 @@ #!/bin/bash -curl --url "http://5.9.253.195:7783" --data "{\"method\":\"getpeers\"}" -curl --url "http://5.9.253.196:7783" --data "{\"method\":\"getpeers\"}" -curl --url "http://5.9.253.197:7783" --data "{\"method\":\"getpeers\"}" -curl --url "http://5.9.253.198:7783" --data "{\"method\":\"getpeers\"}" -curl --url "http://5.9.253.199:7783" --data "{\"method\":\"getpeers\"}" -curl --url "http://5.9.253.200:7783" --data "{\"method\":\"getpeers\"}" -curl --url "http://5.9.253.201:7783" --data "{\"method\":\"getpeers\"}" -curl --url "http://5.9.253.202:7783" --data "{\"method\":\"getpeers\"}" -curl --url "http://5.9.253.203:7783" --data "{\"method\":\"getpeers\"}" -curl --url "http://5.9.253.204:7783" --data "{\"method\":\"getpeers\"}" +curl --url "http://5.9.253.195:7782" --data "{\"method\":\"getpeers\"}" +curl --url "http://5.9.253.196:7782" --data "{\"method\":\"getpeers\"}" +curl --url "http://5.9.253.197:7782" --data "{\"method\":\"getpeers\"}" +curl --url "http://5.9.253.198:7782" --data "{\"method\":\"getpeers\"}" +curl --url "http://5.9.253.199:7782" --data "{\"method\":\"getpeers\"}" +curl --url "http://5.9.253.200:7782" --data "{\"method\":\"getpeers\"}" +curl --url "http://5.9.253.201:7782" --data "{\"method\":\"getpeers\"}" +curl --url "http://5.9.253.202:7782" --data "{\"method\":\"getpeers\"}" +curl --url "http://5.9.253.203:7782" --data "{\"method\":\"getpeers\"}" +curl --url "http://5.9.253.204:7782" --data "{\"method\":\"getpeers\"}" From 1086fabbdfdeccd51e47e0c213200be361b4367f Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 25 Jan 2018 08:57:28 +0400 Subject: [PATCH 107/183] Test --- iguana/exchanges/stats.c | 1 + 1 file changed, 1 insertion(+) diff --git a/iguana/exchanges/stats.c b/iguana/exchanges/stats.c index 8d03d26c6..c9d21deb3 100644 --- a/iguana/exchanges/stats.c +++ b/iguana/exchanges/stats.c @@ -29,6 +29,7 @@ #define STATS_DEST "/var/www/html/DEXstats.json" #include "DEXstats.h" char *stats_JSON(void *ctx,char *myipaddr,int32_t mypubsock,cJSON *argjson,char *remoteaddr,uint16_t port); +extern uint32_t DOCKERFLAG; char *stats_validmethods[] = { From 406700acb8253d02ccc5a51e296002bb2512aa53 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 25 Jan 2018 09:20:15 +0400 Subject: [PATCH 108/183] Force usage of default as initial passphrase --- iguana/exchanges/coins | 2 +- iguana/exchanges/mm.c | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/coins b/iguana/exchanges/coins index 3b5a2e820..87b472712 100644 --- a/iguana/exchanges/coins +++ b/iguana/exchanges/coins @@ -1,3 +1,3 @@ -export coins="[{\"coin\": \"PIZZA\",\"asset\": \"PIZZA\",\"rpcport\": 11116},{\"coin\": \"BEER\",\"asset\": \"BEER\",\"rpcport\": 8923}, {\"coin\":\"GRS\",\"name\":\"groestlcoin\",\"rpcport\":1441,\"pubtype\":36,\"p2shtype\":5,\"wiftype\":128,\"txfee\":10000}, {\"coin\":\"XMCC\",\"name\":\"monoeci\",\"confpath\":\"${HOME#}/.monoeciCore/monoeci.conf\",\"rpcport\":24156,\"pubtype\":50,\"p2shtype\":73,\"wiftype\":77,\"txfee\":10000}, {\"coin\":\"BTCH\",\"asset\":\"BTCH\",\"rpcport\":8800},{\"coin\":\"ETOMIC\",\"asset\":\"ETOMIC\",\"rpcport\":10271},{\"coin\":\"AXO\",\"asset\":\"AXO\",\"rpcport\":12927},{\"coin\":\"CRC\",\"name\":\"crowdcoin\",\"confpath\":\"${HOME#}/.crowdcoincore/crowdcoin.conf\",\"rpcport\":9998,\"pubtype\":28,\"p2shtype\":88,\"wiftype\":0,\"txfee\":10000}, {\"coin\":\"VOT\",\"name\":\"votecoin\",\"rpcport\":8232,\"taddr\":28,\"pubtype\":184,\"p2shtype\":189,\"wiftype\":128,\"txfee\":10000}, {\"coin\":\"INN\",\"name\":\"innova\",\"confpath\":\"${HOME#}/.innovacore/innova.conf\",\"rpcport\":8818,\"pubtype\":102,\"p2shtype\":20,\"wiftype\":195,\"txfee\":10000}, {\"coin\":\"MOON\",\"name\":\"mooncoin\",\"rpcport\":44663,\"pubtype\":3,\"p2shtype\":22,\"wiftype\":131,\"txfee\":100000}, {\"coin\":\"CRW\",\"name\":\"crown\",\"rpcport\":9341,\"pubtype\":0,\"p2shtype\":28,\"wiftype\":128,\"txfee\":10000}, {\"coin\":\"EFL\",\"name\":\"egulden\",\"confpath\":\"${HOME#}/.egulden/coin.conf\",\"rpcport\":21015,\"pubtype\":48,\"p2shtype\":5,\"wiftype\":176,\"txfee\":100000}, {\"coin\":\"GBX\",\"name\":\"gobyte\",\"confpath\":\"${HOME#}/.gobytecore/gobyte.conf\",\"rpcport\":12454,\"pubtype\":38,\"p2shtype\":10,\"wiftype\":198,\"txfee\":10000}, {\"coin\":\"BCO\",\"name\":\"bridgecoin\",\"rpcport\":6332,\"pubtype\":27,\"p2shtype\":5,\"wiftype\":176,\"txfee\":100000}, {\"coin\":\"BLK\",\"name\":\"blackcoin\",\"confpath\":\"${HOME#}/.lore/blackcoin.conf\",\"isPoS\":1,\"rpcport\":15715,\"pubtype\":25,\"p2shtype\":85,\"wiftype\":153,\"txfee\":100000}, {\"coin\":\"BTG\",\"name\":\"bitcoingold\",\"rpcport\":8332,\"pubtype\":38,\"p2shtype\":23,\"wiftype\":128,\"txfee\":10000}, {\"coin\":\"BCH\",\"name\":\"bch\",\"rpcport\":33333,\"pubtype\":0,\"p2shtype\":5,\"wiftype\":128,\"txfee\":10000}, {\"coin\":\"ABY\",\"name\":\"applebyte\",\"rpcport\":8607,\"pubtype\":23,\"p2shtype\":5,\"wiftype\":151,\"txfee\":100000}, {\"coin\":\"STAK\",\"name\":\"straks\",\"rpcport\":7574,\"pubtype\":63,\"p2shtype\":5,\"wiftype\":204,\"txfee\":10000}, {\"coin\":\"XZC\",\"name\":\"zcoin\",\"rpcport\":8888,\"pubtype\":82,\"p2shtype\":7,\"wiftype\":210,\"txfee\":10000}, {\"coin\":\"QTUM\",\"name\":\"qtum\",\"rpcport\":3889,\"pubtype\":58,\"p2shtype\":50,\"wiftype\":128,\"txfee\":400000}, {\"coin\":\"PURA\",\"name\":\"pura\",\"rpcport\":55555,\"pubtype\":55,\"p2shtype\":16,\"wiftype\":150,\"txfee\":10000}, {\"coin\":\"DSR\",\"name\":\"desire\",\"confpath\":\"${HOME#}/.desirecore/desire.conf\",\"rpcport\":9918,\"pubtype\":30,\"p2shtype\":16,\"wiftype\":204,\"txfee\":10000}, {\"coin\":\"MNZ\",\"asset\":\"MNZ\",\"rpcport\":14337},{\"coin\":\"BTCZ\",\"name\":\"bitcoinz\",\"rpcport\":1979,\"taddr\":28,\"pubtype\":184,\"p2shtype\":189,\"wiftype\":128,\"txfee\":10000}, {\"coin\":\"MAGA\",\"name\":\"magacoin\",\"rpcport\":5332,\"pubtype\":23,\"p2shtype\":50,\"wiftype\":176,\"txfee\":100000}, {\"coin\":\"BSD\",\"name\":\"bitsend\",\"rpcport\":8800,\"pubtype\":102,\"p2shtype\":5,\"wiftype\":204,\"txfee\":10000}, {\"coin\":\"IOP\",\"name\":\"IoP\",\"rpcport\":8337,\"pubtype\":117,\"p2shtype\":174,\"wiftype\":49,\"txfee\":10000}, {\"coin\":\"BLOCK\",\"name\":\"blocknetdx\",\"rpcport\":41414,\"pubtype\":26,\"p2shtype\":28,\"wiftype\":154,\"txfee\":10000}, {\"coin\":\"CHIPS\", \"name\": \"chips\", \"rpcport\":57776,\"pubtype\":60, \"p2shtype\":85, \"wiftype\":188, \"txfee\":10000}, {\"coin\":\"888\",\"name\":\"octocoin\",\"rpcport\":22888,\"pubtype\":18,\"p2shtype\":5,\"wiftype\":176,\"txfee\":2000000}, {\"coin\":\"ARG\",\"name\":\"argentum\",\"rpcport\":13581,\"pubtype\":23,\"p2shtype\":5,\"wiftype\":151,\"txfee\":50000}, {\"coin\":\"GLT\",\"name\":\"globaltoken\",\"rpcport\":9320,\"pubtype\":38,\"p2shtype\":5,\"wiftype\":166,\"txfee\":10000}, {\"coin\":\"ZER\",\"name\":\"zero\",\"rpcport\":23801,\"taddr\":28,\"pubtype\":184,\"p2shtype\":189,\"wiftype\":128,\"txfee\":1000}, {\"coin\":\"HODLC\",\"name\":\"hodlcoin\",\"rpcport\":11989,\"pubtype\":40,\"p2shtype\":5,\"wiftype\":168,\"txfee\":5000}, {\"coin\":\"UIS\",\"name\":\"unitus\",\"rpcport\":50604,\"pubtype\":68,\"p2shtype\":10,\"wiftype\":132,\"txfee\":2000000}, {\"coin\":\"HUC\",\"name\":\"huntercoin\",\"rpcport\":8399,\"pubtype\":40,\"p2shtype\":13,\"wiftype\":168,\"txfee\":100000}, {\"coin\":\"BDL\",\"name\":\"bitdeal\",\"rpcport\":9332,\"pubtype\":38,\"p2shtype\":5,\"wiftype\":176,\"txfee\":100000}, {\"coin\":\"ARC\",\"name\":\"arcticcoin\",\"confpath\":\"${HOME#}/.arcticcore/arcticcoin.conf\",\"rpcport\":7208,\"pubtype\":23,\"p2shtype\":8,\"wiftype\":176,\"txfee\":10000}, {\"coin\":\"ZCL\",\"name\":\"zclassic\",\"rpcport\":8023,\"taddr\":28,\"pubtype\":184,\"p2shtype\":189,\"wiftype\":128,\"txfee\":1000}, {\"coin\":\"VIA\",\"name\":\"viacoin\",\"rpcport\":5222,\"pubtype\":71,\"p2shtype\":33,\"wiftype\":199,\"txfee\":100000}, {\"coin\":\"ERC\",\"name\":\"europecoin\",\"rpcport\":11989,\"pubtype\":33,\"p2shtype\":5,\"wiftype\":168,\"txfee\":10000},{\"coin\":\"FAIR\",\"name\":\"faircoin\",\"confpath\":\"${HOME#}/.faircoin2/faircoin.conf\",\"rpcport\":40405,\"pubtype\":95,\"p2shtype\":36,\"wiftype\":223,\"txfee\":1000000}, {\"coin\":\"FLO\",\"name\":\"florincoin\",\"rpcport\":7313,\"pubtype\":35,\"p2shtype\":8,\"wiftype\":176,\"txfee\":100000}, {\"coin\":\"SXC\",\"name\":\"sexcoin\",\"rpcport\":9561,\"pubtype\":62,\"p2shtype\":5,\"wiftype\":190,\"txfee\":100000}, {\"coin\":\"CREA\",\"name\":\"creativecoin\",\"rpcport\":17711,\"pubtype\":28,\"p2shtype\":5,\"wiftype\":176,\"txfee\":100000}, {\"coin\":\"TRC\",\"name\":\"terracoin\",\"confpath\":\"${HOME#}/.terracoincore/terracoin.conf\",\"rpcport\":13332,\"pubtype\":0,\"p2shtype\":5,\"wiftype\":128,\"txfee\":10000}, {\"coin\":\"BTA\",\"name\":\"bata\",\"rpcport\":5493,\"pubtype\":25,\"p2shtype\":5,\"wiftype\":188,\"txfee\":100000}, {\"coin\":\"SMC\",\"name\":\"smartcoin\",\"rpcport\":58583,\"pubtype\":63,\"p2shtype\":5,\"wiftype\":191,\"txfee\":1000000}, {\"coin\":\"NMC\",\"name\":\"namecoin\",\"rpcport\":8336,\"pubtype\":52,\"p2shtype\":13,\"wiftype\":180,\"txfee\":100000}, {\"coin\":\"NAV\",\"name\":\"navcoin\",\"isPoS\":1,\"confpath\":\"${HOME#}/.navcoin4/navcoin.conf\",\"rpcport\":44444,\"pubtype\":53,\"p2shtype\":85,\"wiftype\":150,\"txfee\":10000}, {\"coin\":\"EMC2\",\"name\":\"einsteinium\",\"rpcport\":41879,\"pubtype\":33,\"p2shtype\":5,\"wiftype\":176,\"txfee\":100000},{\"coin\":\"SYS\",\"name\":\"syscoin\",\"rpcport\":8370,\"pubtype\":0,\"p2shtype\":5,\"wiftype\":128,\"txfee\":10000}, {\"coin\":\"I0C\",\"name\":\"i0coin\",\"rpcport\":7332,\"pubtype\":105,\"p2shtype\":5,\"wiftype\":128,\"txfee\":10000}, {\"coin\":\"DASH\",\"confpath\":\"${HOME#}/.dashcore/dash.conf\",\"name\":\"dashcore\",\"rpcport\":9998,\"pubtype\":76,\"p2shtype\":16,\"wiftype\":204,\"txfee\":10000}, {\"coin\":\"STRAT\", \"name\": \"stratis\", \"active\":0, \"rpcport\":16174,\"pubtype\":63, \"p2shtype\":125, \"wiftype\":191, \"txfee\":10000}, {\"confpath\":\"${HOME#}/.muecore/mue.conf\",\"coin\":\"MUE\",\"name\":\"muecore\",\"rpcport\":29683,\"pubtype\":16,\"p2shtype\":76,\"wiftype\":126,\"txfee\":10000}, {\"coin\":\"MONA\",\"name\":\"monacoin\",\"rpcport\":9402,\"pubtype\":50,\"p2shtype\":5,\"wiftype\":176,\"txfee\":100000},{\"coin\":\"XMY\",\"name\":\"myriadcoin\",\"rpcport\":10889,\"pubtype\":50,\"p2shtype\":9,\"wiftype\":178,\"txfee\":5000}, {\"coin\":\"MAC\",\"name\":\"machinecoin\",\"rpcport\":40332,\"pubtype\":50,\"p2shtype\":5,\"wiftype\":178,\"txfee\":100000}, {\"coin\":\"BTX\",\"name\":\"bitcore\",\"rpcport\":8556,\"pubtype\":0,\"p2shtype\":5,\"wiftype\":128,\"txfee\":50000}, {\"coin\":\"XRE\",\"name\":\"revolvercoin\",\"rpcport\":8775,\"pubtype\":0,\"p2shtype\":5,\"wiftype\":128,\"txfee\":10000}, {\"coin\":\"LBC\",\"name\":\"lbrycrd\",\"rpcport\":9245,\"pubtype\":85,\"p2shtype\":122,\"wiftype\":28,\"txfee\":10000}, {\"coin\":\"SIB\",\"name\":\"sibcoin\",\"rpcport\":1944,\"pubtype\":63,\"p2shtype\":40,\"wiftype\":128,\"txfee\":10000}, {\"coin\":\"VTC\", \"name\":\"vertcoin\", \"rpcport\":5888, \"pubtype\":71, \"p2shtype\":5, \"wiftype\":128, \"txfee\":100000 }, {\"coin\":\"REVS\",\"active\":0, \"asset\":\"REVS\",\"rpcport\":10196}, {\"coin\":\"JUMBLR\",\"active\":0, \"asset\":\"JUMBLR\",\"rpcport\":15106}, {\"coin\":\"DOGE\",\"name\":\"dogecoin\",\"rpcport\":22555,\"pubtype\":30,\"p2shtype\":22,\"wiftype\":158,\"txfee\":100000000}, {\"coin\":\"HUSH\",\"name\":\"hush\",\"rpcport\":8822,\"taddr\":28,\"pubtype\":184,\"p2shtype\":189,\"wiftype\":128,\"txfee\":1000 }, {\"active\":0,\"coin\":\"ZEC\",\"name\":\"zcash\",\"rpcport\":8232,\"taddr\":28,\"pubtype\":184,\"p2shtype\":189,\"wiftype\":128,\"txfee\":10000 }, {\"coin\":\"DGB\",\"name\":\"digibyte\",\"rpcport\":14022,\"pubtype\":30,\"p2shtype\":5,\"wiftype\":128,\"txfee\":100000}, {\"coin\":\"ZET\", \"name\":\"zetacoin\", \"pubtype\":80, \"p2shtype\":9,\"rpcport\":8332, \"wiftype\":224, \"txfee\":10000}, {\"coin\":\"GAME\", \"rpcport\":40001, \"name\":\"gamecredits\", \"pubtype\":38, \"p2shtype\":5, \"wiftype\":166, \"txfee\":100000}, {\"coin\":\"LTC\", \"name\":\"litecoin\", \"rpcport\":9332, \"pubtype\":48, \"p2shtype\":5, \"wiftype\":176, \"txfee\":100000 }, {\"coin\":\"SUPERNET\",\"asset\":\"SUPERNET\",\"rpcport\":11341}, {\"coin\":\"WLC\",\"asset\":\"WLC\",\"rpcport\":12167}, {\"coin\":\"PANGEA\",\"asset\":\"PANGEA\",\"rpcport\":14068}, {\"coin\":\"DEX\",\"asset\":\"DEX\",\"rpcport\":11890}, {\"coin\":\"BET\",\"asset\":\"BET\",\"rpcport\":14250}, {\"coin\":\"CRYPTO\",\"asset\":\"CRYPTO\",\"rpcport\":8516}, {\"coin\":\"HODL\",\"asset\":\"HODL\",\"rpcport\":14431}, {\"coin\":\"MSHARK\",\"asset\":\"MSHARK\",\"rpcport\":8846}, {\"coin\":\"BOTS\",\"asset\":\"BOTS\",\"rpcport\":11964}, {\"coin\":\"MGW\",\"asset\":\"MGW\",\"rpcport\":12386}, {\"coin\":\"COQUI\",\"asset\":\"COQUI\",\"rpcport\":14276}, {\"coin\":\"KV\",\"asset\":\"KV\",\"rpcport\":8299}, {\"coin\":\"CEAL\",\"asset\":\"CEAL\",\"rpcport\":11116}, {\"coin\":\"MESH\",\"asset\":\"MESH\",\"rpcport\":9455}]" +export coins="[{\"coin\":\"ZOI\",\"name\":\"zoin\",\"rpcport\":8255,\"pubtype\":80,\"p2shtype\":7,\"wiftype\":208,\"txfee\":1000}, {\"coin\": \"PIZZA\",\"asset\": \"PIZZA\",\"rpcport\": 11116},{\"coin\": \"BEER\",\"asset\": \"BEER\",\"rpcport\": 8923}, {\"coin\":\"GRS\",\"name\":\"groestlcoin\",\"rpcport\":1441,\"pubtype\":36,\"p2shtype\":5,\"wiftype\":128,\"txfee\":10000}, {\"coin\":\"XMCC\",\"name\":\"monoeci\",\"confpath\":\"${HOME#}/.monoeciCore/monoeci.conf\",\"rpcport\":24156,\"pubtype\":50,\"p2shtype\":73,\"wiftype\":77,\"txfee\":10000}, {\"coin\":\"BTCH\",\"asset\":\"BTCH\",\"rpcport\":8800},{\"coin\":\"ETOMIC\",\"asset\":\"ETOMIC\",\"rpcport\":10271},{\"coin\":\"AXO\",\"asset\":\"AXO\",\"rpcport\":12927},{\"coin\":\"CRC\",\"name\":\"crowdcoin\",\"confpath\":\"${HOME#}/.crowdcoincore/crowdcoin.conf\",\"rpcport\":9998,\"pubtype\":28,\"p2shtype\":88,\"wiftype\":0,\"txfee\":10000}, {\"coin\":\"VOT\",\"name\":\"votecoin\",\"rpcport\":8232,\"taddr\":28,\"pubtype\":184,\"p2shtype\":189,\"wiftype\":128,\"txfee\":10000}, {\"coin\":\"INN\",\"name\":\"innova\",\"confpath\":\"${HOME#}/.innovacore/innova.conf\",\"rpcport\":8818,\"pubtype\":102,\"p2shtype\":20,\"wiftype\":195,\"txfee\":10000}, {\"coin\":\"MOON\",\"name\":\"mooncoin\",\"rpcport\":44663,\"pubtype\":3,\"p2shtype\":22,\"wiftype\":131,\"txfee\":100000}, {\"coin\":\"CRW\",\"name\":\"crown\",\"rpcport\":9341,\"pubtype\":0,\"p2shtype\":28,\"wiftype\":128,\"txfee\":10000}, {\"coin\":\"EFL\",\"name\":\"egulden\",\"confpath\":\"${HOME#}/.egulden/coin.conf\",\"rpcport\":21015,\"pubtype\":48,\"p2shtype\":5,\"wiftype\":176,\"txfee\":100000}, {\"coin\":\"GBX\",\"name\":\"gobyte\",\"confpath\":\"${HOME#}/.gobytecore/gobyte.conf\",\"rpcport\":12454,\"pubtype\":38,\"p2shtype\":10,\"wiftype\":198,\"txfee\":10000}, {\"coin\":\"BCO\",\"name\":\"bridgecoin\",\"rpcport\":6332,\"pubtype\":27,\"p2shtype\":5,\"wiftype\":176,\"txfee\":100000}, {\"coin\":\"BLK\",\"name\":\"blackcoin\",\"confpath\":\"${HOME#}/.lore/blackcoin.conf\",\"isPoS\":1,\"rpcport\":15715,\"pubtype\":25,\"p2shtype\":85,\"wiftype\":153,\"txfee\":100000}, {\"coin\":\"BTG\",\"name\":\"bitcoingold\",\"rpcport\":8332,\"pubtype\":38,\"p2shtype\":23,\"wiftype\":128,\"txfee\":10000}, {\"coin\":\"BCH\",\"name\":\"bch\",\"rpcport\":33333,\"pubtype\":0,\"p2shtype\":5,\"wiftype\":128,\"txfee\":10000}, {\"coin\":\"ABY\",\"name\":\"applebyte\",\"rpcport\":8607,\"pubtype\":23,\"p2shtype\":5,\"wiftype\":151,\"txfee\":100000}, {\"coin\":\"STAK\",\"name\":\"straks\",\"rpcport\":7574,\"pubtype\":63,\"p2shtype\":5,\"wiftype\":204,\"txfee\":10000}, {\"coin\":\"XZC\",\"name\":\"zcoin\",\"rpcport\":8888,\"pubtype\":82,\"p2shtype\":7,\"wiftype\":210,\"txfee\":10000}, {\"coin\":\"QTUM\",\"name\":\"qtum\",\"rpcport\":3889,\"pubtype\":58,\"p2shtype\":50,\"wiftype\":128,\"txfee\":400000}, {\"coin\":\"PURA\",\"name\":\"pura\",\"rpcport\":55555,\"pubtype\":55,\"p2shtype\":16,\"wiftype\":150,\"txfee\":10000}, {\"coin\":\"DSR\",\"name\":\"desire\",\"confpath\":\"${HOME#}/.desirecore/desire.conf\",\"rpcport\":9918,\"pubtype\":30,\"p2shtype\":16,\"wiftype\":204,\"txfee\":10000}, {\"coin\":\"MNZ\",\"asset\":\"MNZ\",\"rpcport\":14337},{\"coin\":\"BTCZ\",\"name\":\"bitcoinz\",\"rpcport\":1979,\"taddr\":28,\"pubtype\":184,\"p2shtype\":189,\"wiftype\":128,\"txfee\":10000}, {\"coin\":\"MAGA\",\"name\":\"magacoin\",\"rpcport\":5332,\"pubtype\":23,\"p2shtype\":50,\"wiftype\":176,\"txfee\":100000}, {\"coin\":\"BSD\",\"name\":\"bitsend\",\"rpcport\":8800,\"pubtype\":102,\"p2shtype\":5,\"wiftype\":204,\"txfee\":10000}, {\"coin\":\"IOP\",\"name\":\"IoP\",\"rpcport\":8337,\"pubtype\":117,\"p2shtype\":174,\"wiftype\":49,\"txfee\":10000}, {\"coin\":\"BLOCK\",\"name\":\"blocknetdx\",\"rpcport\":41414,\"pubtype\":26,\"p2shtype\":28,\"wiftype\":154,\"txfee\":10000}, {\"coin\":\"CHIPS\", \"name\": \"chips\", \"rpcport\":57776,\"pubtype\":60, \"p2shtype\":85, \"wiftype\":188, \"txfee\":10000}, {\"coin\":\"888\",\"name\":\"octocoin\",\"rpcport\":22888,\"pubtype\":18,\"p2shtype\":5,\"wiftype\":176,\"txfee\":2000000}, {\"coin\":\"ARG\",\"name\":\"argentum\",\"rpcport\":13581,\"pubtype\":23,\"p2shtype\":5,\"wiftype\":151,\"txfee\":50000}, {\"coin\":\"GLT\",\"name\":\"globaltoken\",\"rpcport\":9320,\"pubtype\":38,\"p2shtype\":5,\"wiftype\":166,\"txfee\":10000}, {\"coin\":\"ZER\",\"name\":\"zero\",\"rpcport\":23801,\"taddr\":28,\"pubtype\":184,\"p2shtype\":189,\"wiftype\":128,\"txfee\":1000}, {\"coin\":\"HODLC\",\"name\":\"hodlcoin\",\"rpcport\":11989,\"pubtype\":40,\"p2shtype\":5,\"wiftype\":168,\"txfee\":5000}, {\"coin\":\"UIS\",\"name\":\"unitus\",\"rpcport\":50604,\"pubtype\":68,\"p2shtype\":10,\"wiftype\":132,\"txfee\":2000000}, {\"coin\":\"HUC\",\"name\":\"huntercoin\",\"rpcport\":8399,\"pubtype\":40,\"p2shtype\":13,\"wiftype\":168,\"txfee\":100000}, {\"coin\":\"BDL\",\"name\":\"bitdeal\",\"rpcport\":9332,\"pubtype\":38,\"p2shtype\":5,\"wiftype\":176,\"txfee\":100000}, {\"coin\":\"ARC\",\"name\":\"arcticcoin\",\"confpath\":\"${HOME#}/.arcticcore/arcticcoin.conf\",\"rpcport\":7208,\"pubtype\":23,\"p2shtype\":8,\"wiftype\":176,\"txfee\":10000}, {\"coin\":\"ZCL\",\"name\":\"zclassic\",\"rpcport\":8023,\"taddr\":28,\"pubtype\":184,\"p2shtype\":189,\"wiftype\":128,\"txfee\":1000}, {\"coin\":\"VIA\",\"name\":\"viacoin\",\"rpcport\":5222,\"pubtype\":71,\"p2shtype\":33,\"wiftype\":199,\"txfee\":100000}, {\"coin\":\"ERC\",\"name\":\"europecoin\",\"rpcport\":11989,\"pubtype\":33,\"p2shtype\":5,\"wiftype\":168,\"txfee\":10000},{\"coin\":\"FAIR\",\"name\":\"faircoin\",\"confpath\":\"${HOME#}/.faircoin2/faircoin.conf\",\"rpcport\":40405,\"pubtype\":95,\"p2shtype\":36,\"wiftype\":223,\"txfee\":1000000}, {\"coin\":\"FLO\",\"name\":\"florincoin\",\"rpcport\":7313,\"pubtype\":35,\"p2shtype\":8,\"wiftype\":176,\"txfee\":100000}, {\"coin\":\"SXC\",\"name\":\"sexcoin\",\"rpcport\":9561,\"pubtype\":62,\"p2shtype\":5,\"wiftype\":190,\"txfee\":100000}, {\"coin\":\"CREA\",\"name\":\"creativecoin\",\"rpcport\":17711,\"pubtype\":28,\"p2shtype\":5,\"wiftype\":176,\"txfee\":100000}, {\"coin\":\"TRC\",\"name\":\"terracoin\",\"confpath\":\"${HOME#}/.terracoincore/terracoin.conf\",\"rpcport\":13332,\"pubtype\":0,\"p2shtype\":5,\"wiftype\":128,\"txfee\":10000}, {\"coin\":\"BTA\",\"name\":\"bata\",\"rpcport\":5493,\"pubtype\":25,\"p2shtype\":5,\"wiftype\":188,\"txfee\":100000}, {\"coin\":\"SMC\",\"name\":\"smartcoin\",\"rpcport\":58583,\"pubtype\":63,\"p2shtype\":5,\"wiftype\":191,\"txfee\":1000000}, {\"coin\":\"NMC\",\"name\":\"namecoin\",\"rpcport\":8336,\"pubtype\":52,\"p2shtype\":13,\"wiftype\":180,\"txfee\":100000}, {\"coin\":\"NAV\",\"name\":\"navcoin\",\"isPoS\":1,\"confpath\":\"${HOME#}/.navcoin4/navcoin.conf\",\"rpcport\":44444,\"pubtype\":53,\"p2shtype\":85,\"wiftype\":150,\"txfee\":10000}, {\"coin\":\"EMC2\",\"name\":\"einsteinium\",\"rpcport\":41879,\"pubtype\":33,\"p2shtype\":5,\"wiftype\":176,\"txfee\":100000},{\"coin\":\"SYS\",\"name\":\"syscoin\",\"rpcport\":8370,\"pubtype\":0,\"p2shtype\":5,\"wiftype\":128,\"txfee\":10000}, {\"coin\":\"I0C\",\"name\":\"i0coin\",\"rpcport\":7332,\"pubtype\":105,\"p2shtype\":5,\"wiftype\":128,\"txfee\":10000}, {\"coin\":\"DASH\",\"confpath\":\"${HOME#}/.dashcore/dash.conf\",\"name\":\"dashcore\",\"rpcport\":9998,\"pubtype\":76,\"p2shtype\":16,\"wiftype\":204,\"txfee\":10000}, {\"coin\":\"STRAT\", \"name\": \"stratis\", \"active\":0, \"rpcport\":16174,\"pubtype\":63, \"p2shtype\":125, \"wiftype\":191, \"txfee\":10000}, {\"confpath\":\"${HOME#}/.muecore/mue.conf\",\"coin\":\"MUE\",\"name\":\"muecore\",\"rpcport\":29683,\"pubtype\":16,\"p2shtype\":76,\"wiftype\":126,\"txfee\":10000}, {\"coin\":\"MONA\",\"name\":\"monacoin\",\"rpcport\":9402,\"pubtype\":50,\"p2shtype\":5,\"wiftype\":176,\"txfee\":100000},{\"coin\":\"XMY\",\"name\":\"myriadcoin\",\"rpcport\":10889,\"pubtype\":50,\"p2shtype\":9,\"wiftype\":178,\"txfee\":5000}, {\"coin\":\"MAC\",\"name\":\"machinecoin\",\"rpcport\":40332,\"pubtype\":50,\"p2shtype\":5,\"wiftype\":178,\"txfee\":100000}, {\"coin\":\"BTX\",\"name\":\"bitcore\",\"rpcport\":8556,\"pubtype\":0,\"p2shtype\":5,\"wiftype\":128,\"txfee\":50000}, {\"coin\":\"XRE\",\"name\":\"revolvercoin\",\"rpcport\":8775,\"pubtype\":0,\"p2shtype\":5,\"wiftype\":128,\"txfee\":10000}, {\"coin\":\"LBC\",\"name\":\"lbrycrd\",\"rpcport\":9245,\"pubtype\":85,\"p2shtype\":122,\"wiftype\":28,\"txfee\":10000}, {\"coin\":\"SIB\",\"name\":\"sibcoin\",\"rpcport\":1944,\"pubtype\":63,\"p2shtype\":40,\"wiftype\":128,\"txfee\":10000}, {\"coin\":\"VTC\", \"name\":\"vertcoin\", \"rpcport\":5888, \"pubtype\":71, \"p2shtype\":5, \"wiftype\":128, \"txfee\":100000 }, {\"coin\":\"REVS\",\"active\":0, \"asset\":\"REVS\",\"rpcport\":10196}, {\"coin\":\"JUMBLR\",\"active\":0, \"asset\":\"JUMBLR\",\"rpcport\":15106}, {\"coin\":\"DOGE\",\"name\":\"dogecoin\",\"rpcport\":22555,\"pubtype\":30,\"p2shtype\":22,\"wiftype\":158,\"txfee\":100000000}, {\"coin\":\"HUSH\",\"name\":\"hush\",\"rpcport\":8822,\"taddr\":28,\"pubtype\":184,\"p2shtype\":189,\"wiftype\":128,\"txfee\":1000 }, {\"active\":0,\"coin\":\"ZEC\",\"name\":\"zcash\",\"rpcport\":8232,\"taddr\":28,\"pubtype\":184,\"p2shtype\":189,\"wiftype\":128,\"txfee\":10000 }, {\"coin\":\"DGB\",\"name\":\"digibyte\",\"rpcport\":14022,\"pubtype\":30,\"p2shtype\":5,\"wiftype\":128,\"txfee\":100000}, {\"coin\":\"ZET\", \"name\":\"zetacoin\", \"pubtype\":80, \"p2shtype\":9,\"rpcport\":8332, \"wiftype\":224, \"txfee\":10000}, {\"coin\":\"GAME\", \"rpcport\":40001, \"name\":\"gamecredits\", \"pubtype\":38, \"p2shtype\":5, \"wiftype\":166, \"txfee\":100000}, {\"coin\":\"LTC\", \"name\":\"litecoin\", \"rpcport\":9332, \"pubtype\":48, \"p2shtype\":5, \"wiftype\":176, \"txfee\":100000 }, {\"coin\":\"SUPERNET\",\"asset\":\"SUPERNET\",\"rpcport\":11341}, {\"coin\":\"WLC\",\"asset\":\"WLC\",\"rpcport\":12167}, {\"coin\":\"PANGEA\",\"asset\":\"PANGEA\",\"rpcport\":14068}, {\"coin\":\"DEX\",\"asset\":\"DEX\",\"rpcport\":11890}, {\"coin\":\"BET\",\"asset\":\"BET\",\"rpcport\":14250}, {\"coin\":\"CRYPTO\",\"asset\":\"CRYPTO\",\"rpcport\":8516}, {\"coin\":\"HODL\",\"asset\":\"HODL\",\"rpcport\":14431}, {\"coin\":\"MSHARK\",\"asset\":\"MSHARK\",\"rpcport\":8846}, {\"coin\":\"BOTS\",\"asset\":\"BOTS\",\"rpcport\":11964}, {\"coin\":\"MGW\",\"asset\":\"MGW\",\"rpcport\":12386}, {\"coin\":\"COQUI\",\"asset\":\"COQUI\",\"rpcport\":14276}, {\"coin\":\"KV\",\"asset\":\"KV\",\"rpcport\":8299}, {\"coin\":\"CEAL\",\"asset\":\"CEAL\",\"rpcport\":11116}, {\"coin\":\"MESH\",\"asset\":\"MESH\",\"rpcport\":9455}]" #, {\"coin\":\"AUD\",\"asset\":\"AUD\",\"rpcport\":8045}, {\"coin\":\"BGN\",\"asset\":\"BGN\",\"rpcport\":9110}, {\"coin\":\"CAD\",\"asset\":\"CAD\",\"rpcport\":8720}, {\"coin\":\"CHF\",\"asset\":\"CHF\",\"rpcport\":15312}, {\"coin\":\"CNY\",\"asset\":\"CNY\",\"rpcport\":10384}, {\"coin\":\"CZK\",\"asset\":\"CZK\",\"rpcport\":9482}, {\"coin\":\"DKK\",\"asset\":\"DKK\",\"rpcport\":13830}, {\"coin\":\"EUR\",\"asset\":\"EUR\",\"rpcport\":8065}, {\"coin\":\"GBP\",\"asset\":\"GBP\",\"rpcport\":11505}, {\"coin\":\"HKD\",\"asset\":\"HKD\",\"rpcport\":15409}, {\"coin\":\"HRK\",\"asset\":\"HRK\",\"rpcport\":12617}, {\"coin\":\"HUF\",\"asset\":\"HUF\",\"rpcport\":13699}, {\"coin\":\"IDR\",\"asset\":\"IDR\",\"rpcport\":14459}, {\"coin\":\"ILS\",\"asset\":\"ILS\",\"rpcport\":14638}, {\"coin\":\"INR\",\"asset\":\"INR\",\"rpcport\":10536}, {\"coin\":\"JPY\",\"asset\":\"JPY\",\"rpcport\":13145}, {\"coin\":\"KRW\",\"asset\":\"KRW\",\"rpcport\":14020}, {\"coin\":\"MXN\",\"asset\":\"MXN\",\"rpcport\":13970}, {\"coin\":\"MYR\",\"asset\":\"MYR\",\"rpcport\":10688}, {\"coin\":\"NOK\",\"asset\":\"NOK\",\"rpcport\":11588}, {\"coin\":\"NZD\",\"asset\":\"NZD\",\"rpcport\":10915}, {\"coin\":\"PHP\",\"asset\":\"PHP\",\"rpcport\":11181}, {\"coin\":\"PLN\",\"asset\":\"PLN\",\"rpcport\":13493}, {\"coin\":\"BRL\",\"asset\":\"BRL\",\"rpcport\":9914}, {\"coin\":\"RON\",\"asset\":\"RON\",\"rpcport\":8675}, {\"coin\":\"RUB\",\"asset\":\"RUB\",\"rpcport\":8199}, {\"coin\":\"SEK\",\"asset\":\"SEK\",\"rpcport\":11447}, {\"coin\":\"SGD\",\"asset\":\"SGD\",\"rpcport\":14475}, {\"coin\":\"THB\",\"asset\":\"THB\",\"rpcport\":11847}, {\"coin\":\"TRY\",\"asset\":\"TRY\",\"rpcport\":13924}, {\"coin\":\"USD\",\"asset\":\"USD\",\"rpcport\":13967}, {\"coin\":\"ZAR\",\"asset\":\"ZAR\",\"rpcport\":15160}]" #{\"coin\":\"PIVX\",\"name\":\"pivx\",\"rpcport\":51473,\"pubtype\":30,\"p2shtype\":13,\"wiftype\":212,\"txfee\":10000}, diff --git a/iguana/exchanges/mm.c b/iguana/exchanges/mm.c index 8c1e99b9d..379fb763d 100644 --- a/iguana/exchanges/mm.c +++ b/iguana/exchanges/mm.c @@ -203,8 +203,10 @@ int main(int argc, const char * argv[]) DOCKERFLAG = 1; else if ( jstr(retjson,"docker") != 0 ) DOCKERFLAG = (uint32_t)calc_ipbits(jstr(retjson,"docker")); + if ( jobj(retjson,"passphrase") != 0 ) + jdelete(retjson,"passphrase"); if ( (passphrase= jstr(retjson,"passphrase")) == 0 ) - jaddstr(retjson,"passphrase","test"); + jaddstr(retjson,"passphrase","default"); if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_main,(void *)retjson) != 0 ) { printf("error launching LP_main (%s)\n",jprint(retjson,0)); From f8f6b15b9ba74d4c523ce10c84fbe4fd322867a4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 25 Jan 2018 09:22:00 +0400 Subject: [PATCH 109/183] Setpassphrase using default's user pass --- iguana/exchanges/setpassphrase | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/setpassphrase b/iguana/exchanges/setpassphrase index eec8bc5b1..422418b82 100755 --- a/iguana/exchanges/setpassphrase +++ b/iguana/exchanges/setpassphrase @@ -1,3 +1,3 @@ #!/bin/bash source userpass -curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"passphrase\",\"passphrase\":\"put the passphrase here\",\"gui\":\"buildog\"}" +curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"1d8b27b21efabcd96571cd56f91a40fb9aa4cc623d273c63bf9223dc6f8cd81f\",\"method\":\"passphrase\",\"passphrase\":\"put the passphrase here\",\"gui\":\"nogui\"}" From 9ee579f784515926ec0a0eb6185562f9b01a2eed Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 25 Jan 2018 10:39:30 +0400 Subject: [PATCH 110/183] Test --- iguana/exchanges/LP_portfolio.c | 32 ++------------------------------ iguana/exchanges/LP_prices.c | 15 ++++++++++++++- iguana/exchanges/auto_chipskmd | 2 +- 3 files changed, 17 insertions(+), 32 deletions(-) diff --git a/iguana/exchanges/LP_portfolio.c b/iguana/exchanges/LP_portfolio.c index 7601761fa..f53e89939 100644 --- a/iguana/exchanges/LP_portfolio.c +++ b/iguana/exchanges/LP_portfolio.c @@ -547,36 +547,6 @@ void LP_autoprice_iter(void *ctx,struct LP_priceinfo *btcpp) LP_pricepings(ctx,LP_myipaddr,LP_mypubsock,base,rel,askprice); //printf("price %.8f -> %.8f %.8f\n",price,bidprice,askprice); } - /*if ( LP_autorefs[i].fundbid[0] != 0 && (price= jdouble(fundjson,LP_autorefs[i].fundbid)) > SMALLVAL ) - { - printf("%s/%s %s %.8f -> %.8f or %.8f",base,rel,LP_autorefs[i].fundbid,price,(1. / (price * (1. + buymargin))),(1. / (price * (1. - buymargin)))); - if ( tickerjson != 0 && LP_autorefs[i].count == 0 ) - price = LP_tickered_price(0,base,rel,price,tickerjson); - newprice = (1. / (price * (1. + buymargin))); - //if ( LP_autorefs[i].lastbid < SMALLVAL ) - LP_autorefs[i].lastbid = newprice; - //else LP_autorefs[i].lastbid = (LP_autorefs[i].lastbid * 0.9) + (0.1 *newprice); - newprice = LP_autorefs[i].lastbid; - LP_mypriceset(&changed,rel,base,newprice); - LP_pricepings(ctx,LP_myipaddr,LP_mypubsock,rel,base,newprice); - printf("fundbid %.8f margin %.8f newprice %.8f\n",price,buymargin,newprice); - } - if ( LP_autorefs[i].fundask[0] != 0 && (price= jdouble(fundjson,LP_autorefs[i].fundask)) > SMALLVAL ) - { - printf("%s/%s %s %.8f -> ",base,rel,LP_autorefs[i].fundask,price); - if ( tickerjson != 0 && LP_autorefs[i].count == 0 ) - price = LP_tickered_price(1,base,rel,price,tickerjson); - newprice = (price * (1. + sellmargin)); - //if ( LP_autorefs[i].lastask < SMALLVAL ) - LP_autorefs[i].lastask = newprice; - //else LP_autorefs[i].lastask = (LP_autorefs[i].lastask * 0.9) + (0.1 *newprice); - if ( LP_autorefs[i].lastbid < SMALLVAL || LP_autorefs[i].lastask >= LP_autorefs[i].lastbid/(1. + sellmargin) ) - newprice = LP_autorefs[i].lastask; - else newprice = LP_autorefs[i].lastbid * (1. + sellmargin); - LP_mypriceset(&changed,base,rel,newprice); - LP_pricepings(ctx,LP_myipaddr,LP_mypubsock,base,rel,newprice); - printf("fundask %.8f margin %.8f newprice %.8f\n",price,sellmargin,newprice); - }*/ LP_autorefs[i].count++; } free_json(fundjson); @@ -681,6 +651,8 @@ int32_t LP_autoprice(void *ctx,char *base,char *rel,cJSON *argjson) fixedprice = jdouble(argjson,"fixed"); basepp->fixedprices[relpp->ind] = fixedprice; basepp->minprices[relpp->ind] = minprice; + if ( jobj(argjson,"maxprice") != 0 ) + relpp->minprices[basepp->ind] = 1. / jdouble(argjson,"maxprice"); basepp->buymargins[relpp->ind] = buymargin; basepp->sellmargins[relpp->ind] = sellmargin; basepp->offsets[relpp->ind] = offset; diff --git a/iguana/exchanges/LP_prices.c b/iguana/exchanges/LP_prices.c index 7807f8eaf..bbfa42f36 100644 --- a/iguana/exchanges/LP_prices.c +++ b/iguana/exchanges/LP_prices.c @@ -511,7 +511,7 @@ char *LP_myprices() int32_t LP_mypriceset(int32_t *changedp,char *base,char *rel,double price) { - struct LP_priceinfo *basepp,*relpp; struct LP_pubkey_info *pubp; + struct LP_priceinfo *basepp,*relpp; struct LP_pubkey_info *pubp; double minprice,maxprice; *changedp = 0; //if ( strcmp("DEX",base) == 0 || strcmp("DEX",rel) == 0 ) // printf("%s/%s setprice %.8f\n",base,rel,price); @@ -529,6 +529,19 @@ int32_t LP_mypriceset(int32_t *changedp,char *base,char *rel,double price) relpp->offsets[basepp->ind] = 0.; relpp->factors[basepp->ind] = 0.; } + else if ( (minprice= basepp->minprices[relpp->ind]) > SMALLVAL && price < minprice ) + { + printf("%s/%s price %.8f less than minprice %.8f\n",base,rel,price,minprice); + price = minprice; + } + else if ( (maxprice= relpp->minprices[basepp->ind]) > SMALLVAL ) + { + if ( price < (1. / maxprice) ) + { + printf("%s/%s price %.8f more than maxprice %.8f, less than %.8f\n",base,rel,price,maxprice,1./maxprice); + price = maxprice; + } + } /*else if ( basepp->myprices[relpp->ind] > SMALLVAL ) { price = (basepp->myprices[relpp->ind] * 0.9) + (0.1 * price); diff --git a/iguana/exchanges/auto_chipskmd b/iguana/exchanges/auto_chipskmd index aee6c0548..c259a8cff 100755 --- a/iguana/exchanges/auto_chipskmd +++ b/iguana/exchanges/auto_chipskmd @@ -1,2 +1,2 @@ source userpass -curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"autoprice\",\"base\":\"CHIPS\",\"rel\":\"KMD\",\"margin\":0.05,\"refbase\":\"chips\",\"refrel\":\"coinmarketcap\"}" +curl --url "http://127.0.0.1:7783" --data "{\"minprice\":0.04,\"maxprice\":0.1,\"userpass\":\"$userpass\",\"method\":\"autoprice\",\"base\":\"CHIPS\",\"rel\":\"KMD\",\"margin\":0.05,\"refbase\":\"chips\",\"refrel\":\"coinmarketcap\"}" From 1673c4c12b42bae73a70f6cad1d34c5f467c4e38 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 25 Jan 2018 10:57:43 +0400 Subject: [PATCH 111/183] test --- iguana/exchanges/LP_prices.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_prices.c b/iguana/exchanges/LP_prices.c index bbfa42f36..771fdbc85 100644 --- a/iguana/exchanges/LP_prices.c +++ b/iguana/exchanges/LP_prices.c @@ -536,9 +536,9 @@ int32_t LP_mypriceset(int32_t *changedp,char *base,char *rel,double price) } else if ( (maxprice= relpp->minprices[basepp->ind]) > SMALLVAL ) { - if ( price < (1. / maxprice) ) + if ( price > (1. / maxprice) ) { - printf("%s/%s price %.8f more than maxprice %.8f, less than %.8f\n",base,rel,price,maxprice,1./maxprice); + printf("%s/%s price %.8f less than maxprice %.8f, more than %.8f\n",base,rel,price,maxprice,1./maxprice); price = maxprice; } } From 3afa16fa59f9c66dbc42cbb7e85a0f2b6448adbb Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 25 Jan 2018 10:59:09 +0400 Subject: [PATCH 112/183] Test --- iguana/exchanges/LP_portfolio.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/iguana/exchanges/LP_portfolio.c b/iguana/exchanges/LP_portfolio.c index f53e89939..ead40b27c 100644 --- a/iguana/exchanges/LP_portfolio.c +++ b/iguana/exchanges/LP_portfolio.c @@ -300,7 +300,7 @@ void LP_autopriceset(int32_t ind,void *ctx,int32_t dir,struct LP_priceinfo *base { if ( LP_autorefs[ind].lastask < SMALLVAL ) LP_autorefs[ind].lastask = newprice; - else LP_autorefs[ind].lastask = (LP_autorefs[ind].lastask * 0.9) + (0.1 *newprice); + else LP_autorefs[ind].lastask = (LP_autorefs[ind].lastask * 0.99) + (0.01 *newprice); newprice = LP_autorefs[ind].lastask; //printf("autopriceset %s/%s <- %.8f %.8f (%.8f %.8f)\n",basepp->symbol,relpp->symbol,price,newprice,LP_autorefs[ind].lastbid,LP_autorefs[ind].lastask); } @@ -569,7 +569,7 @@ void LP_autoprice_iter(void *ctx,struct LP_priceinfo *btcpp) newprice = (price * (1. + buymargin)); if ( LP_autorefs[i].lastbid < SMALLVAL ) LP_autorefs[i].lastbid = newprice; - else LP_autorefs[i].lastbid = (LP_autorefs[i].lastbid * 0.9) + (0.1 *newprice); + else LP_autorefs[i].lastbid = (LP_autorefs[i].lastbid * 0.99) + (0.01 * newprice); newprice = LP_autorefs[i].lastbid; LP_mypriceset(&changed,rel,base,newprice); LP_pricepings(ctx,LP_myipaddr,LP_mypubsock,rel,base,newprice); @@ -577,7 +577,7 @@ void LP_autoprice_iter(void *ctx,struct LP_priceinfo *btcpp) newprice = (1. / price) * (1. + sellmargin); if ( LP_autorefs[i].lastask < SMALLVAL ) LP_autorefs[i].lastask = newprice; - else LP_autorefs[i].lastask = (LP_autorefs[i].lastask * 0.9) + (0.1 *newprice); + else LP_autorefs[i].lastask = (LP_autorefs[i].lastask * 0.99) + (0.01 * newprice); newprice = LP_autorefs[i].lastask; LP_mypriceset(&changed,base,rel,newprice); LP_pricepings(ctx,LP_myipaddr,LP_mypubsock,base,rel,newprice); From afb09723fe6bcaed6443e3cfdb26179e5d53295d Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 25 Jan 2018 11:05:12 +0400 Subject: [PATCH 113/183] Test --- iguana/exchanges/LP_prices.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_prices.c b/iguana/exchanges/LP_prices.c index 771fdbc85..4dbf53495 100644 --- a/iguana/exchanges/LP_prices.c +++ b/iguana/exchanges/LP_prices.c @@ -539,7 +539,7 @@ int32_t LP_mypriceset(int32_t *changedp,char *base,char *rel,double price) if ( price > (1. / maxprice) ) { printf("%s/%s price %.8f less than maxprice %.8f, more than %.8f\n",base,rel,price,maxprice,1./maxprice); - price = maxprice; + price = (1. / maxprice); } } /*else if ( basepp->myprices[relpp->ind] > SMALLVAL ) From 1d71ab6a36086dad15eb91a849f4ffae1834c99e Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 25 Jan 2018 11:13:27 +0400 Subject: [PATCH 114/183] Test --- iguana/exchanges/LP_commands.c | 2 +- iguana/exchanges/stats.c | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_commands.c b/iguana/exchanges/LP_commands.c index f85c41e5e..23b8f79ff 100644 --- a/iguana/exchanges/LP_commands.c +++ b/iguana/exchanges/LP_commands.c @@ -103,7 +103,7 @@ char *stats_JSON(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson,char *r return(clonestr("{\"result\":\" \ available localhost RPC commands: \n \ setprice(base, rel, price, broadcast=1)\n\ -autoprice(base, rel, fixed, minprice, margin, refbase, refrel, factor, offset)*\n\ +autoprice(base, rel, fixed, minprice, maxprice, margin, refbase, refrel, factor, offset)*\n\ goal(coin=*, val=)\n\ myprice(base, rel)\n\ enable(coin)\n\ diff --git a/iguana/exchanges/stats.c b/iguana/exchanges/stats.c index c9d21deb3..87f14e05d 100644 --- a/iguana/exchanges/stats.c +++ b/iguana/exchanges/stats.c @@ -47,6 +47,7 @@ int32_t LP_valid_remotemethod(cJSON *argjson) for (i=0; i Date: Thu, 25 Jan 2018 11:17:35 +0400 Subject: [PATCH 115/183] Test --- iguana/exchanges/auto_chipsbtc | 2 +- iguana/exchanges/auto_grskmd | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/auto_chipsbtc b/iguana/exchanges/auto_chipsbtc index e4b2490cc..06c5282e9 100755 --- a/iguana/exchanges/auto_chipsbtc +++ b/iguana/exchanges/auto_chipsbtc @@ -1,2 +1,2 @@ source userpass -curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"autoprice\",\"base\":\"CHIPS\",\"rel\":\"BTC\",\"margin\":0.05,\"refbase\":\"chips\",\"refrel\":\"coinmarketcap\"}" +curl --url "http://127.0.0.1:7783" --data "{\"minprice\":0.00002,\"maxprice\":0.0001,\"userpass\":\"$userpass\",\"method\":\"autoprice\",\"base\":\"CHIPS\",\"rel\":\"BTC\",\"margin\":0.05,\"refbase\":\"chips\",\"refrel\":\"coinmarketcap\"}" diff --git a/iguana/exchanges/auto_grskmd b/iguana/exchanges/auto_grskmd index 5e4bc927e..59ad21afa 100755 --- a/iguana/exchanges/auto_grskmd +++ b/iguana/exchanges/auto_grskmd @@ -1,2 +1,2 @@ source userpass -curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"autoprice\",\"base\":\"GRS\",\"rel\":\"KMD\",\"margin\":0.05,\"refbase\":\"groestlcoin\",\"refrel\":\"coinmarketcap\"}" +curl --url "http://127.0.0.1:7783" --data "{\"minprice\":0.05,\"maxprice\":0.2,\"userpass\":\"$userpass\",\"method\":\"autoprice\",\"base\":\"GRS\",\"rel\":\"KMD\",\"margin\":0.05,\"refbase\":\"groestlcoin\",\"refrel\":\"coinmarketcap\"}" From 90d5ef4c5b9858c683633a297877936466a156ef Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 25 Jan 2018 11:19:02 +0400 Subject: [PATCH 116/183] Test --- iguana/exchanges/setpassphrase | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/setpassphrase b/iguana/exchanges/setpassphrase index 422418b82..9df8de637 100755 --- a/iguana/exchanges/setpassphrase +++ b/iguana/exchanges/setpassphrase @@ -1,3 +1,3 @@ #!/bin/bash source userpass -curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"1d8b27b21efabcd96571cd56f91a40fb9aa4cc623d273c63bf9223dc6f8cd81f\",\"method\":\"passphrase\",\"passphrase\":\"put the passphrase here\",\"gui\":\"nogui\"}" +curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"1d8b27b21efabcd96571cd56f91a40fb9aa4cc623d273c63bf9223dc6f8cd81f\",\"method\":\"passphrase\",\"passphrase\":\"$passphrase\",\"gui\":\"nogui\"}" From be533c69adbcafedeadbdb8d2218464a1c1298af Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 25 Jan 2018 11:23:35 +0400 Subject: [PATCH 117/183] Test --- iguana/exchanges/client | 3 ++- iguana/exchanges/run | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/client b/iguana/exchanges/client index a36758376..3b33a363a 100755 --- a/iguana/exchanges/client +++ b/iguana/exchanges/client @@ -1,9 +1,10 @@ #!/bin/bash source passphrase source coins -pkill -15 marketmaker; +./stop git pull; cd ..; ./m_mm; +pkill -15 marketmaker; ./marketmaker "{\"gui\":\"nogui\",\"client\":1, \"userhome\":\"/${HOME#"/"}\", \"passphrase\":\"$passphrase\", \"coins\":$coins}" & diff --git a/iguana/exchanges/run b/iguana/exchanges/run index ec549c0c7..0954a5c1a 100755 --- a/iguana/exchanges/run +++ b/iguana/exchanges/run @@ -1,8 +1,9 @@ #!/bin/bash source passphrase source coins -pkill -15 marketmaker; +./stop git pull; cd ..; ./m_mm; +pkill -15 marketmaker; $1 ./marketmaker "{\"gui\":\"nogui\", \"profitmargin\":0.01, \"userhome\":\"/${HOME#"/"}\", \"passphrase\":\"$passphrase\", \"coins\":$coins}" & From 0e5df0cd4644c3fe9a98958a490fa11bba03f500 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 25 Jan 2018 11:29:49 +0400 Subject: [PATCH 118/183] Test --- iguana/exchanges/LP_bitcoin.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_bitcoin.c b/iguana/exchanges/LP_bitcoin.c index fadd13779..2fb98a48d 100644 --- a/iguana/exchanges/LP_bitcoin.c +++ b/iguana/exchanges/LP_bitcoin.c @@ -2173,7 +2173,7 @@ int32_t bitcoin_validaddress(char *symbol,uint8_t taddr,uint8_t pubtype,uint8_t return(-1); else if ( bitcoin_address(symbol,checkaddr,addrtype,taddr,rmd160,sizeof(rmd160)) != checkaddr || strcmp(checkaddr,coinaddr) != 0 ) { - printf("bitcoin_validaddress checkaddr.%s != %s\n",checkaddr,coinaddr); + printf("%s pubtype.%d bitcoin_validaddress checkaddr.%s != %s\n",symbol,pubtype,checkaddr,coinaddr); return(-1); } return(0); From 14d277df58d74a60db96a2fb370c82cff45cc2dd Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 25 Jan 2018 11:34:08 +0400 Subject: [PATCH 119/183] Test --- iguana/exchanges/stats.c | 1 + 1 file changed, 1 insertion(+) diff --git a/iguana/exchanges/stats.c b/iguana/exchanges/stats.c index 87f14e05d..7db807a8a 100644 --- a/iguana/exchanges/stats.c +++ b/iguana/exchanges/stats.c @@ -819,6 +819,7 @@ void stats_rpcloop(void *args) } #endif*/ memcpy(&ipbits,&cli_addr.sin_addr.s_addr,sizeof(ipbits)); +printf("port.%u got incoming from %x\n",port,ipbits); if ( DOCKERFLAG != 0 && (DOCKERFLAG == 1 || ipbits == DOCKERFLAG) ) ipbits = localhostbits; if ( port == RPC_port && ipbits != localhostbits ) From c7531b8fbc4540fcf05f1cd722863e2c2d94ac15 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 25 Jan 2018 11:40:40 +0400 Subject: [PATCH 120/183] Test --- iguana/exchanges/LP_commands.c | 3 ++- iguana/exchanges/LP_include.h | 2 +- iguana/exchanges/LP_nativeDEX.c | 20 ++++++++++++-------- iguana/exchanges/LP_peers.c | 1 + iguana/exchanges/stats.c | 2 +- 5 files changed, 17 insertions(+), 11 deletions(-) diff --git a/iguana/exchanges/LP_commands.c b/iguana/exchanges/LP_commands.c index 23b8f79ff..700e50d13 100644 --- a/iguana/exchanges/LP_commands.c +++ b/iguana/exchanges/LP_commands.c @@ -198,6 +198,7 @@ jpg(srcfile, destfile, power2=7, password, data="", required, ind=0)\n\ return(clonestr("{\"error\":\"authentication error you need to make sure userpass is set\"}")); if ( jobj(argjson,"userpass") != 0 ) jdelete(argjson,"userpass"); + LP_cmdcount++; if ( strcmp(method,"passphrase") == 0 ) { char coinaddr[64],pub33str[67]; @@ -651,7 +652,7 @@ jpg(srcfile, destfile, power2=7, password, data="", required, ind=0)\n\ else if ( strcmp(method,"notify") == 0 ) return(LP_notify_recv(argjson)); else if ( strcmp(method,"getpeers") == 0 ) - retstr = clonestr("{\"error\":\"deprecated\"}"); + return(LP_peers()); else if ( strcmp(method,"balances") == 0 ) return(jprint(LP_balances(jstr(argjson,"address")),1)); else if ( strcmp(method,"fundvalue") == 0 ) diff --git a/iguana/exchanges/LP_include.h b/iguana/exchanges/LP_include.h index 2cae0f44c..f3fd53d92 100644 --- a/iguana/exchanges/LP_include.h +++ b/iguana/exchanges/LP_include.h @@ -363,7 +363,7 @@ struct LP_peerinfo uint64_t ip_port; uint32_t recvtime,numrecv,ipbits,errortime,errors,numpeers,needping,lasttime,connected,lastutxos,lastpeers,diduquery,good,sessionid; int32_t pushsock,subsock,isLP; - uint16_t port; + uint16_t port,netid; char ipaddr[64]; }; diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 38685d97b..5d0372b17 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -102,7 +102,7 @@ uint16_t LP_fixed_pairport;//,LP_publicport; uint32_t LP_lastnonce,LP_swap_endcritical,LP_swap_critical,LP_RTcount,LP_swapscount; int32_t LP_STOP_RECEIVED,LP_numactive_LP;//,LP_mybussock = -1; int32_t LP_mypubsock = -1; -int32_t LP_mypullsock = -1; +int32_t LP_cmdcount,LP_mypullsock = -1; int32_t LP_numfinished,LP_showwif,IAMLP = 0; double LP_profitratio = 1.; @@ -1299,12 +1299,6 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu printf("error launching stats rpcloop for port.%u\n",myport); exit(-1); } - uint16_t myport2 = myport-1; - if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)stats_rpcloop,(void *)&myport2) != 0 ) - { - printf("error launching stats rpcloop for port.%u\n",myport); - exit(-1); - } if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)command_rpcloop,ctx) != 0 ) { printf("error launching command_rpcloop for ctx.%p\n",ctx); @@ -1355,7 +1349,7 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu printf("error launching LP_swapsloop for ctx.%p\n",ctx); exit(-1); } - int32_t nonz; + int32_t nonz,didremote=0; LP_statslog_parse(); bitcoind_RPC_inittime = 0; while ( LP_STOP_RECEIVED == 0 ) @@ -1369,6 +1363,16 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu } if ( LP_mainloop_iter(ctx,myipaddr,mypeer,pubsock,pushaddr,myport) != 0 ) nonz++; + if ( didremote == 0 && LP_cmdcount > 0 ) + { + didremote = 1; + uint16_t myport2 = myport-1; + if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)stats_rpcloop,(void *)&myport2) != 0 ) + { + printf("error launching stats rpcloop for port.%u\n",myport); + exit(-1); + } + } if ( nonz == 0 ) usleep(1000); else if ( IAMLP == 0 ) diff --git a/iguana/exchanges/LP_peers.c b/iguana/exchanges/LP_peers.c index 193dfac6f..3c6a4fb32 100644 --- a/iguana/exchanges/LP_peers.c +++ b/iguana/exchanges/LP_peers.c @@ -33,6 +33,7 @@ cJSON *LP_peerjson(struct LP_peerinfo *peer) cJSON *item = cJSON_CreateObject(); jaddstr(item,"isLP",peer->ipaddr); jaddnum(item,"port",peer->port); + jaddnum(item,"netid",peer->netid); if ( strcmp(peer->ipaddr,LP_myipaddr) == 0 ) { jaddnum(item,"session",G.LP_sessionid); diff --git a/iguana/exchanges/stats.c b/iguana/exchanges/stats.c index 7db807a8a..6625d3f75 100644 --- a/iguana/exchanges/stats.c +++ b/iguana/exchanges/stats.c @@ -819,7 +819,7 @@ void stats_rpcloop(void *args) } #endif*/ memcpy(&ipbits,&cli_addr.sin_addr.s_addr,sizeof(ipbits)); -printf("port.%u got incoming from %x\n",port,ipbits); +//printf("port.%u got incoming from %x\n",port,ipbits); if ( DOCKERFLAG != 0 && (DOCKERFLAG == 1 || ipbits == DOCKERFLAG) ) ipbits = localhostbits; if ( port == RPC_port && ipbits != localhostbits ) From 500cc084edc691680b85c508607d2b7f6c9f5742 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 25 Jan 2018 11:43:53 +0400 Subject: [PATCH 121/183] Test --- iguana/exchanges/LP_commands.c | 3 ++- iguana/exchanges/LP_nativeDEX.c | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_commands.c b/iguana/exchanges/LP_commands.c index 700e50d13..0d1eb9972 100644 --- a/iguana/exchanges/LP_commands.c +++ b/iguana/exchanges/LP_commands.c @@ -198,7 +198,8 @@ jpg(srcfile, destfile, power2=7, password, data="", required, ind=0)\n\ return(clonestr("{\"error\":\"authentication error you need to make sure userpass is set\"}")); if ( jobj(argjson,"userpass") != 0 ) jdelete(argjson,"userpass"); - LP_cmdcount++; + if ( LP_cmdcount++ == 0 ) + printf("got first rpc command\n"); if ( strcmp(method,"passphrase") == 0 ) { char coinaddr[64],pub33str[67]; diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 5d0372b17..d0a47a5a9 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -1367,6 +1367,7 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu { didremote = 1; uint16_t myport2 = myport-1; + printf("start remote port\n"); if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)stats_rpcloop,(void *)&myport2) != 0 ) { printf("error launching stats rpcloop for port.%u\n",myport); From 8735b3939bad77226c27340b3d6b4f69246982fe Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 25 Jan 2018 11:48:12 +0400 Subject: [PATCH 122/183] Test --- iguana/exchanges/LP_commands.c | 4 ++-- iguana/exchanges/LP_peers.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/iguana/exchanges/LP_commands.c b/iguana/exchanges/LP_commands.c index 0d1eb9972..94186c659 100644 --- a/iguana/exchanges/LP_commands.c +++ b/iguana/exchanges/LP_commands.c @@ -183,6 +183,7 @@ jpg(srcfile, destfile, power2=7, password, data="", required, ind=0)\n\ init_hexbytes_noT(pub33str,G.LP_pubsecp,33); jaddstr(retjson,"pubsecp",pub33str); jadd(retjson,"coins",LP_coinsjson(LP_showwif)); + LP_cmdcount++; return(jprint(retjson,1)); } // if passphrase api and passphrase is right, ignore userpass, use hass of passphrase @@ -198,8 +199,7 @@ jpg(srcfile, destfile, power2=7, password, data="", required, ind=0)\n\ return(clonestr("{\"error\":\"authentication error you need to make sure userpass is set\"}")); if ( jobj(argjson,"userpass") != 0 ) jdelete(argjson,"userpass"); - if ( LP_cmdcount++ == 0 ) - printf("got first rpc command\n"); + LP_cmdcount++; if ( strcmp(method,"passphrase") == 0 ) { char coinaddr[64],pub33str[67]; diff --git a/iguana/exchanges/LP_peers.c b/iguana/exchanges/LP_peers.c index 3c6a4fb32..81674b0de 100644 --- a/iguana/exchanges/LP_peers.c +++ b/iguana/exchanges/LP_peers.c @@ -32,7 +32,7 @@ cJSON *LP_peerjson(struct LP_peerinfo *peer) { cJSON *item = cJSON_CreateObject(); jaddstr(item,"isLP",peer->ipaddr); - jaddnum(item,"port",peer->port); + jaddnum(item,"remoteport",peer->port-1); jaddnum(item,"netid",peer->netid); if ( strcmp(peer->ipaddr,LP_myipaddr) == 0 ) { From 782317a448ed355f7e1bc11edfe9814725255e4d Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 25 Jan 2018 12:02:36 +0400 Subject: [PATCH 123/183] Test --- iguana/exchanges/LP_commands.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_commands.c b/iguana/exchanges/LP_commands.c index 94186c659..5fc6a0dac 100644 --- a/iguana/exchanges/LP_commands.c +++ b/iguana/exchanges/LP_commands.c @@ -193,7 +193,7 @@ jpg(srcfile, destfile, power2=7, password, data="", required, ind=0)\n\ vcalc_sha256(0,passhash.bytes,(uint8_t *)passphrase,(int32_t)strlen(passphrase)); if ( bits256_cmp(passhash,G.LP_passhash) == 0 ) authenticated = 1; - else printf("passhash %s != G %s\n",bits256_str(str,passhash),bits256_str(str2,G.LP_passhash)); + else printf("(%s) passhash %s != G %s\n",passphrase,bits256_str(str,passhash),bits256_str(str2,G.LP_passhash)); } if ( authenticated == 0 && ((userpass= jstr(argjson,"userpass")) == 0 || strcmp(userpass,G.USERPASS) != 0) ) return(clonestr("{\"error\":\"authentication error you need to make sure userpass is set\"}")); From f5a6402b2f498362cc84b2da1d5ff75f5829fd5d Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 25 Jan 2018 12:06:13 +0400 Subject: [PATCH 124/183] Fix setpassphrase --- iguana/exchanges/setpassphrase | 1 + 1 file changed, 1 insertion(+) diff --git a/iguana/exchanges/setpassphrase b/iguana/exchanges/setpassphrase index 9df8de637..ad170a572 100755 --- a/iguana/exchanges/setpassphrase +++ b/iguana/exchanges/setpassphrase @@ -1,3 +1,4 @@ #!/bin/bash source userpass +source passphrase curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"1d8b27b21efabcd96571cd56f91a40fb9aa4cc623d273c63bf9223dc6f8cd81f\",\"method\":\"passphrase\",\"passphrase\":\"$passphrase\",\"gui\":\"nogui\"}" From b4736afb3640d96b1ec45e0ceea5bf384605c5d3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 25 Jan 2018 12:16:36 +0400 Subject: [PATCH 125/183] Prevent default processing --- iguana/exchanges/LP_nativeDEX.c | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index d0a47a5a9..fedceb60e 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -518,6 +518,11 @@ void LP_coinsloop(void *_coins) } while ( LP_STOP_RECEIVED == 0 ) { + if ( strcmp(G.USERPASS,"1d8b27b21efabcd96571cd56f91a40fb9aa4cc623d273c63bf9223dc6f8cd81f") == 0 ) + { + sleep(10); + continue; + } if ( strcmp("BTC",coins) == 0 ) LP_millistats_update(&LP_coinsloopBTC_stats); else if ( strcmp("KMD",coins) == 0 ) @@ -894,12 +899,15 @@ void LP_pubkeysloop(void *ctx) sleep(10); while ( LP_STOP_RECEIVED == 0 ) { - LP_millistats_update(&LP_pubkeysloop_stats); - if ( time(NULL) > lasttime+LP_ORDERBOOK_DURATION*0.5 ) + if ( strcmp(G.USERPASS,"1d8b27b21efabcd96571cd56f91a40fb9aa4cc623d273c63bf9223dc6f8cd81f") != 0 ) { -//printf("LP_pubkeysloop %u\n",(uint32_t)time(NULL)); - LP_notify_pubkeys(ctx,LP_mypubsock); - lasttime = (uint32_t)time(NULL); + LP_millistats_update(&LP_pubkeysloop_stats); + if ( time(NULL) > lasttime+LP_ORDERBOOK_DURATION*0.5 ) + { + //printf("LP_pubkeysloop %u\n",(uint32_t)time(NULL)); + LP_notify_pubkeys(ctx,LP_mypubsock); + lasttime = (uint32_t)time(NULL); + } } sleep(3); } @@ -913,10 +921,13 @@ void LP_swapsloop(void *ctx) sleep(50); while ( LP_STOP_RECEIVED == 0 ) { - LP_millistats_update(&LP_swapsloop_stats); - if ( (retstr= basilisk_swapentry(0,0,0)) != 0 ) - free(retstr); - sleep(600); + if ( strcmp(G.USERPASS,"1d8b27b21efabcd96571cd56f91a40fb9aa4cc623d273c63bf9223dc6f8cd81f") != 0 ) + { + LP_millistats_update(&LP_swapsloop_stats); + if ( (retstr= basilisk_swapentry(0,0,0)) != 0 ) + free(retstr); + sleep(600); + } else sleep(10); } } @@ -1116,6 +1127,8 @@ void LP_reserved_msgs(void *ignore) int32_t LP_reserved_msg(int32_t priority,char *base,char *rel,bits256 pubkey,char *msg) { int32_t n = 0; + if ( strcmp(G.USERPASS,"1d8b27b21efabcd96571cd56f91a40fb9aa4cc623d273c63bf9223dc6f8cd81f") == 0 ) + return(-1); portable_mutex_lock(&LP_reservedmutex); if ( num_Reserved_msgs[priority] < sizeof(Reserved_msgs[priority])/sizeof(*Reserved_msgs[priority]) ) { @@ -1356,7 +1369,7 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu { nonz = 0; G.waiting = 1; - while ( G.initializing != 0 ) + while ( G.initializing != 0 && strcmp(G.USERPASS,"1d8b27b21efabcd96571cd56f91a40fb9aa4cc623d273c63bf9223dc6f8cd81f") == 0 ) { //fprintf(stderr,"."); sleep(3); From ee3c92f8b8ab66b3e58ee88cc3c486bf8832780f Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 25 Jan 2018 13:04:42 +0400 Subject: [PATCH 126/183] Test --- iguana/exchanges/LP_include.h | 1 + iguana/exchanges/LP_nativeDEX.c | 47 +++++++++++++++++---------------- iguana/exchanges/mm.c | 43 +++++++++++++++++++----------- iguana/exchanges/stats.c | 2 +- 4 files changed, 53 insertions(+), 40 deletions(-) diff --git a/iguana/exchanges/LP_include.h b/iguana/exchanges/LP_include.h index f3fd53d92..07271aa55 100644 --- a/iguana/exchanges/LP_include.h +++ b/iguana/exchanges/LP_include.h @@ -518,6 +518,7 @@ int64_t LP_myzcredits(); void test_validate(struct iguana_info *coin,char *signedtx); void LP_instantdex_depositadd(char *coinaddr,bits256 txid); int64_t LP_instantdex_creditcalc(struct iguana_info *coin,int32_t dispflag,bits256 txid,char *refaddr); +void LP_ports(uint16_t *pullportp,uint16_t *pubportp,uint16_t *busportp,uint16_t netid); int32_t LP_destaddr(char *destaddr,cJSON *item); int32_t LP_waitmempool(char *symbol,char *coinaddr,bits256 txid,int32_t vout,int32_t duration); cJSON *LP_statslog_disp(uint32_t starttime,uint32_t endtime,char *refgui,bits256 refpubkey,char *refbase,char *refrel); diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index fedceb60e..673b0ba66 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -135,7 +135,7 @@ uint32_t LP_rand() char *activecoins[] = { "BTC", "KMD" }; char GLOBAL_DBDIR[] = { "DB" }; -char LP_myipaddr[64],LP_publicaddr[64],USERHOME[512] = { "/root" }; +char LP_myipaddr[64],USERHOME[512] = { "/root" }; char LP_gui[16] = { "cli" }; char *default_LPnodes[] = { "5.9.253.195", "5.9.253.196", "5.9.253.197", "5.9.253.198", "5.9.253.199", "5.9.253.200", "5.9.253.201", "5.9.253.202", "5.9.253.203", @@ -669,7 +669,7 @@ void LP_coinsloop(void *_coins) } } -int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int32_t pubsock,char *pushaddr,uint16_t myport) +int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int32_t pubsock) { static uint32_t counter;//,didinstantdex; struct iguana_info *coin,*ctmp; char *origipaddr; uint32_t now; int32_t notarized,height,nonz = 0; @@ -849,9 +849,10 @@ void LP_initcoins(void *ctx,int32_t pubsock,cJSON *coins) printf("privkey updates\n"); } -void LP_initpeers(int32_t pubsock,struct LP_peerinfo *mypeer,char *myipaddr,uint16_t myport,char *seednode,uint16_t pushport,uint16_t subport) +void LP_initpeers(int32_t pubsock,struct LP_peerinfo *mypeer,char *myipaddr,uint16_t myport,uint16_t netid,char *seednode) { - int32_t i,j; uint32_t r; + int32_t i,j; uint32_t r; uint16_t pushport,subport,busport; + LP_ports(&pushport,&subport,&busport,netid); if ( IAMLP != 0 ) { LP_mypeer = mypeer = LP_addpeer(mypeer,pubsock,myipaddr,myport,pushport,subport,1,G.LP_sessionid); @@ -1149,7 +1150,7 @@ extern int32_t bitcoind_RPC_inittime; void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybusport,char *passphrase,int32_t amclient,char *userhome,cJSON *argjson) { - char *myipaddr=0,version[64]; long filesize,n; int32_t valid,timeout,pubsock=-1; struct LP_peerinfo *mypeer=0; char pushaddr[128],subaddr[128],bindaddr[128],*coins_str=0; cJSON *coinsjson=0; void *ctx = bitcoin_ctx(); + char *myipaddr=0,version[64]; long filesize,n; int32_t valid,timeout; struct LP_peerinfo *mypeer=0; char pushaddr[128],subaddr[128],bindaddr[128],*coins_str=0; cJSON *coinsjson=0; void *ctx = bitcoin_ctx(); sprintf(version,"Marketmaker %s.%s %s rsize.%ld",LP_MAJOR_VERSION,LP_MINOR_VERSION,LP_BUILD_NUMBER,sizeof(struct basilisk_request)); bitcoind_RPC_inittime = 1; printf("%s %u\n",version,calc_crc32(0,version,(int32_t)strlen(version))); @@ -1246,29 +1247,29 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu #endif if ( IAMLP != 0 ) { - pubsock = -1; + LP_mypubsock = -1; nanomsg_transportname(0,subaddr,myipaddr,mypubport); nanomsg_transportname(1,bindaddr,myipaddr,mypubport); valid = 0; - if ( (pubsock= nn_socket(AF_SP,NN_PUB)) >= 0 ) + if ( (LP_mypubsock= nn_socket(AF_SP,NN_PUB)) >= 0 ) { valid = 0; - if ( nn_bind(pubsock,bindaddr) >= 0 ) + if ( nn_bind(LP_mypubsock,bindaddr) >= 0 ) valid++; if ( valid > 0 ) { timeout = 1; - nn_setsockopt(pubsock,NN_SOL_SOCKET,NN_SNDTIMEO,&timeout,sizeof(timeout)); + nn_setsockopt(LP_mypubsock,NN_SOL_SOCKET,NN_SNDTIMEO,&timeout,sizeof(timeout)); } else { - printf("error binding to (%s).%d\n",subaddr,pubsock); - if ( pubsock >= 0 ) - nn_close(pubsock), pubsock = -1; + printf("error binding to (%s).%d\n",subaddr,LP_mypubsock); + if ( LP_mypubsock >= 0 ) + nn_close(LP_mypubsock), LP_mypubsock = -1; } - } else printf("error getting pubsock %d\n",pubsock); - printf(">>>>>>>>> myipaddr.(%s) (%s) valid.%d pubbindaddr.%s pubsock.%d\n",bindaddr,subaddr,valid,bindaddr,pubsock); - LP_mypubsock = pubsock; + } else printf("error getting pubsock %d\n",LP_mypubsock); + printf(">>>>>>>>> myipaddr.(%s) (%s) valid.%d pubbindaddr.%s pubsock.%d\n",bindaddr,subaddr,valid,bindaddr,LP_mypubsock); + LP_mypullsock = LP_initpublicaddr(ctx,&mypullport,pushaddr,myipaddr,mypullport,0); } if ( (coinsjson= jobj(argjson,"coins")) == 0 ) { @@ -1286,15 +1287,15 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu printf("no coins object or coins.json file, must abort\n"); exit(-1); } - LP_initcoins(ctx,pubsock,coinsjson); + LP_initcoins(ctx,LP_mypubsock,coinsjson); RPC_port = myport; G.waiting = 1; - LP_initpeers(pubsock,mypeer,myipaddr,myport,jstr(argjson,"seednode"),mypullport,mypubport); - LP_mypullsock = LP_initpublicaddr(ctx,&mypullport,pushaddr,myipaddr,mypullport,0); - strcpy(LP_publicaddr,pushaddr); + LP_initpeers(LP_mypubsock,LP_mypeer,LP_myipaddr,RPC_port,juint(argjson,"netid"),jstr(argjson,"seednode")); + //LP_mypullsock = LP_initpublicaddr(ctx,&mypullport,pushaddr,myipaddr,mypullport,0); + //strcpy(LP_publicaddr,pushaddr); //LP_publicport = mypullport; //LP_mybussock = LP_coinbus(mybusport); - printf("got %s, initpeers. LP_mypubsock.%d/%d pullsock.%d myport.%u mypullport.%d mypubport.%d pushaddr.%s\n",myipaddr,LP_mypubsock,pubsock,LP_mypullsock,myport,mypullport,mypubport,pushaddr); + printf("got %s, initpeers. LP_mypubsock.%d pullsock.%d RPC_port.%u mypullport.%d mypubport.%d pushaddr.%s\n",myipaddr,LP_mypubsock,LP_mypullsock,RPC_port,mypullport,mypubport,pushaddr); LP_passphrase_init(passphrase,jstr(argjson,"gui"),juint(argjson,"netid"),jstr(argjson,"seednode")); #ifndef FROM_JS if ( IAMLP != 0 && OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_psockloop,(void *)myipaddr) != 0 ) @@ -1374,12 +1375,12 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu //fprintf(stderr,"."); sleep(3); } - if ( LP_mainloop_iter(ctx,myipaddr,mypeer,pubsock,pushaddr,myport) != 0 ) + if ( LP_mainloop_iter(ctx,myipaddr,mypeer,LP_mypubsock) != 0 ) nonz++; if ( didremote == 0 && LP_cmdcount > 0 ) { didremote = 1; - uint16_t myport2 = myport-1; + uint16_t myport2 = RPC_port-1; printf("start remote port\n"); if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)stats_rpcloop,(void *)&myport2) != 0 ) { @@ -1450,7 +1451,7 @@ void LP_fromjs_iter() //LP_pubkeys_query(); //LP_utxosQ_process(); //LP_nanomsg_recvs(ctx); - LP_mainloop_iter(ctx,LP_myipaddr,0,LP_mypubsock,LP_publicaddr,LP_RPCPORT); + LP_mainloop_iter(ctx,LP_myipaddr,0,LP_mypubsock); //queue_loop(0); if ( 0 ) // 10 seconds { diff --git a/iguana/exchanges/mm.c b/iguana/exchanges/mm.c index 379fb763d..db8bc57b7 100644 --- a/iguana/exchanges/mm.c +++ b/iguana/exchanges/mm.c @@ -69,11 +69,35 @@ void LP_priceupdate(char *base,char *rel,double price,double avebid,double aveas #endif #endif + #include "LP_nativeDEX.c" +void LP_ports(uint16_t *pullportp,uint16_t *pubportp,uint16_t *busportp,uint16_t netid) +{ + int32_t netmod,netdiv; uint16_t otherports; + *pullportp = *pubportp = *busportp = 0; + if ( netid < 0 ) + netid = 0; + else if ( netid > (65535-40-LP_RPCPORT)/4 ) + { + printf("netid.%d overflow vs max netid.%d 14420?\n",netid,(65535-40-LP_RPCPORT)/4); + exit(-1); + } + if ( netid != 0 ) + { + netmod = (netid % 10); + netdiv = (netid / 10); + otherports = (netdiv * 40) + (LP_RPCPORT + netmod); + } else otherports = LP_RPCPORT; + *pullportp = otherports + 10; + *pubportp = otherports + 20; + *busportp = otherports + 30; + printf("RPCport.%d remoteport.%d, nanoports %d %d %d\n",RPC_port,RPC_port-1,*pullportp,*pubportp,*busportp); +} + void LP_main(void *ptr) { - char *passphrase; double profitmargin; int32_t netmod,netdiv,netid=0; uint16_t port,otherports; cJSON *argjson = ptr; + char *passphrase; double profitmargin; uint16_t netid=0,port,pullport,pubport,busport; cJSON *argjson = ptr; if ( (passphrase= jstr(argjson,"passphrase")) != 0 ) { profitmargin = jdouble(argjson,"profitmargin"); @@ -82,21 +106,8 @@ void LP_main(void *ptr) port = LP_RPCPORT; if ( jobj(argjson,"netid") != 0 ) netid = juint(argjson,"netid"); - if ( netid < 0 ) - netid = 0; - else if ( netid > (65535-40-LP_RPCPORT)/4 ) - { - printf("netid.%d overflow vs max netid.%d 14420?\n",netid,(65535-40-LP_RPCPORT)/4); - exit(-1); - } - if ( netid != 0 ) - { - netmod = (netid % 10); - netdiv = (netid / 10); - otherports = (netdiv * 40) + (LP_RPCPORT + netmod); - } else otherports = LP_RPCPORT; - printf("RPCport.%d remoteport.%d, nanoports %d %d %d\n",port,port-1,otherports+10,otherports+20,otherports+30); - LPinit(port,otherports+10,otherports+20,otherports+30,passphrase,jint(argjson,"client"),jstr(argjson,"userhome"),argjson); + LP_ports(&pullport,&pubport,&busport,netid); + LPinit(port,pullport,pubport,busport,passphrase,jint(argjson,"client"),jstr(argjson,"userhome"),argjson); } } diff --git a/iguana/exchanges/stats.c b/iguana/exchanges/stats.c index 6625d3f75..c1fdbe2ff 100644 --- a/iguana/exchanges/stats.c +++ b/iguana/exchanges/stats.c @@ -861,7 +861,7 @@ continue; #ifndef FROM_MARKETMAKER portable_mutex_t LP_commandmutex; -uint16_t LP_RPCPORT; +uint16_t LP_RPCPORT = 7763; void stats_kvjson(FILE *logfp,int32_t height,int32_t savedheight,uint32_t timestamp,char *key,cJSON *kvjson,bits256 pubkey,bits256 sigprev) { From 5919e9a01dccc2cee5cee83ea3fe44ac69fa0076 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 25 Jan 2018 13:09:58 +0400 Subject: [PATCH 127/183] Test --- iguana/exchanges/LP_include.h | 1 + iguana/exchanges/LP_nativeDEX.c | 2 +- iguana/exchanges/LP_privkey.c | 7 +++++++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_include.h b/iguana/exchanges/LP_include.h index 07271aa55..a9eb886cf 100644 --- a/iguana/exchanges/LP_include.h +++ b/iguana/exchanges/LP_include.h @@ -557,6 +557,7 @@ struct LP_utxoinfo *_LP_utxo2find(int32_t iambob,bits256 txid,int32_t vout); int64_t LP_dynamictrust(int64_t credits,bits256 pubkey,int64_t kmdvalue); struct LP_address *LP_addressfind(struct iguana_info *coin,char *coinaddr); int64_t LP_outpoint_amount(char *symbol,bits256 txid,int32_t vout); +void LP_initpeers(int32_t pubsock,struct LP_peerinfo *mypeer,char *myipaddr,uint16_t myport,uint16_t netid,char *seednode); void LP_listunspent_query(char *symbol,char *coinaddr); int32_t bitcoin_priv2wif(char *symbol,uint8_t wiftaddr,char *wifstr,bits256 privkey,uint8_t addrtype); diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 673b0ba66..899c918c2 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -1290,7 +1290,7 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu LP_initcoins(ctx,LP_mypubsock,coinsjson); RPC_port = myport; G.waiting = 1; - LP_initpeers(LP_mypubsock,LP_mypeer,LP_myipaddr,RPC_port,juint(argjson,"netid"),jstr(argjson,"seednode")); + LP_initpeers(LP_mypubsock,LP_mypeer,LP_myipaddr,RPC_port,juint(argjson,"netid"),jstr(argjson,"seednode")); //LP_mypullsock = LP_initpublicaddr(ctx,&mypullport,pushaddr,myipaddr,mypullport,0); //strcpy(LP_publicaddr,pushaddr); //LP_publicport = mypullport; diff --git a/iguana/exchanges/LP_privkey.c b/iguana/exchanges/LP_privkey.c index 453a6cb91..a028869ef 100644 --- a/iguana/exchanges/LP_privkey.c +++ b/iguana/exchanges/LP_privkey.c @@ -377,6 +377,11 @@ int32_t LP_passphrase_init(char *passphrase,char *gui,uint16_t netid,char *seedn ctx = bitcoin_ctx(); if ( G.LP_pendingswaps != 0 ) return(-1); + if ( IAMLP != 0 && netid != G.netid ) + { + printf("sorry, LP nodes can only set netid during startup\n"); + return(-1); + } G.initializing = 1; if ( gui == 0 ) gui = "cli"; @@ -387,6 +392,8 @@ int32_t LP_passphrase_init(char *passphrase,char *gui,uint16_t netid,char *seedn sleep(5); } memset(&G,0,sizeof(G)); + if ( IAMLP == 0 ) + LP_initpeers(LP_mypubsock,LP_mypeer,LP_myipaddr,RPC_port,netid,seednode); G.netid = netid; safecopy(G.seednode,seednode,sizeof(G.seednode)); vcalc_sha256(0,G.LP_passhash.bytes,(uint8_t *)passphrase,(int32_t)strlen(passphrase)); From 7a187951d66b4ea5deccefa14a0401b0df5ece46 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 25 Jan 2018 15:42:02 +0400 Subject: [PATCH 128/183] Test --- iguana/exchanges/LP_peers.c | 21 +++++++++++++++++++++ iguana/exchanges/LP_privkey.c | 7 +++++-- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_peers.c b/iguana/exchanges/LP_peers.c index 81674b0de..3695db113 100644 --- a/iguana/exchanges/LP_peers.c +++ b/iguana/exchanges/LP_peers.c @@ -181,6 +181,27 @@ struct LP_peerinfo *LP_addpeer(struct LP_peerinfo *mypeer,int32_t mypubsock,char return(peer); } +uint64_t ip_port; +uint32_t recvtime,numrecv,ipbits,errortime,errors,numpeers,needping,lasttime,connected,lastutxos,lastpeers,diduquery,good,sessionid; +uint16_t port,netid; + + +void LP_closepeers() +{ + struct LP_peerinfo *peer,*tmp; + HASH_ITER(hh,LP_peerinfos,peer,tmp) + { + portable_mutex_lock(&LP_peermutex); + HASH_DELETE(hh,LP_peerinfos,peer); + portable_mutex_unlock(&LP_peermutex); + if ( peer->pushsock >= 0 ) + nn_close(peer->pushsock), peer->pushsock = -1; + if ( peer->subsock >= 0 ) + nn_close(peer->subsock), peer->subsock = -1; + // free(peer); a small memleak to avoid freein inflight requests + } +} + /*int32_t LP_coinbus(uint16_t coin_busport) { struct LP_peerinfo *peer,*tmp; char busaddr[64]; int32_t timeout,bussock = -1; diff --git a/iguana/exchanges/LP_privkey.c b/iguana/exchanges/LP_privkey.c index a028869ef..c66ec1192 100644 --- a/iguana/exchanges/LP_privkey.c +++ b/iguana/exchanges/LP_privkey.c @@ -382,6 +382,11 @@ int32_t LP_passphrase_init(char *passphrase,char *gui,uint16_t netid,char *seedn printf("sorry, LP nodes can only set netid during startup\n"); return(-1); } + else if ( IAMLP == 0 && netid != G.netid ) + { + LP_closepeers(); + LP_initpeers(LP_mypubsock,LP_mypeer,LP_myipaddr,RPC_port,netid,seednode); + } G.initializing = 1; if ( gui == 0 ) gui = "cli"; @@ -392,8 +397,6 @@ int32_t LP_passphrase_init(char *passphrase,char *gui,uint16_t netid,char *seedn sleep(5); } memset(&G,0,sizeof(G)); - if ( IAMLP == 0 ) - LP_initpeers(LP_mypubsock,LP_mypeer,LP_myipaddr,RPC_port,netid,seednode); G.netid = netid; safecopy(G.seednode,seednode,sizeof(G.seednode)); vcalc_sha256(0,G.LP_passhash.bytes,(uint8_t *)passphrase,(int32_t)strlen(passphrase)); From fac19d587135d2ebaf6d75b728ea604e4318fa32 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 25 Jan 2018 15:46:46 +0400 Subject: [PATCH 129/183] Test --- iguana/exchanges/LP_privkey.c | 1 + 1 file changed, 1 insertion(+) diff --git a/iguana/exchanges/LP_privkey.c b/iguana/exchanges/LP_privkey.c index c66ec1192..6e26711b2 100644 --- a/iguana/exchanges/LP_privkey.c +++ b/iguana/exchanges/LP_privkey.c @@ -384,6 +384,7 @@ int32_t LP_passphrase_init(char *passphrase,char *gui,uint16_t netid,char *seedn } else if ( IAMLP == 0 && netid != G.netid ) { + printf("netid.%d vs G.netid %d\n",netid,G.netid); LP_closepeers(); LP_initpeers(LP_mypubsock,LP_mypeer,LP_myipaddr,RPC_port,netid,seednode); } From b8beb480a906821701830f6429b6fbb6e7c7d143 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 25 Jan 2018 15:49:36 +0400 Subject: [PATCH 130/183] Test --- iguana/exchanges/LP_prices.c | 1 + 1 file changed, 1 insertion(+) diff --git a/iguana/exchanges/LP_prices.c b/iguana/exchanges/LP_prices.c index 4dbf53495..cee20a5d2 100644 --- a/iguana/exchanges/LP_prices.c +++ b/iguana/exchanges/LP_prices.c @@ -949,6 +949,7 @@ char *LP_orderbook(char *base,char *rel,int32_t duration) jaddstr(retjson,"base",base); jaddstr(retjson,"rel",rel); jaddnum(retjson,"timestamp",now); + jaddnum(retjson,"netid",G.netid); if ( bids != 0 ) free(bids); if ( asks != 0 ) From 78ccf2ba1bd817aef2a451dbd749a8e7ba1dd8e0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 25 Jan 2018 15:59:33 +0400 Subject: [PATCH 131/183] Test --- iguana/exchanges/LP_nativeDEX.c | 29 ++++++++++++++++------------- iguana/exchanges/LP_peers.c | 13 +++++++------ iguana/exchanges/LP_signatures.c | 2 +- 3 files changed, 24 insertions(+), 20 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 899c918c2..91dac1f81 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -138,8 +138,7 @@ char GLOBAL_DBDIR[] = { "DB" }; char LP_myipaddr[64],USERHOME[512] = { "/root" }; char LP_gui[16] = { "cli" }; -char *default_LPnodes[] = { "5.9.253.195", "5.9.253.196", "5.9.253.197", "5.9.253.198", "5.9.253.199", "5.9.253.200", "5.9.253.201", "5.9.253.202", "5.9.253.203", - "173.212.225.176", "136.243.45.140", "88.99.227.213", "78.47.108.168","188.166.105.227", "23.254.202.142", "45.32.19.196" +char *default_LPnodes[] = { "5.9.253.195", "173.212.225.176", "136.243.45.140", "23.254.202.142", "45.32.19.196" //"24.54.206.138", "107.72.162.127", "72.50.16.86", "51.15.202.191", "173.228.198.88", //"51.15.203.171", "51.15.86.136", "51.15.94.249", "51.15.80.18", "51.15.91.40", "51.15.54.2", "51.15.86.31", "51.15.82.29", "51.15.89.155", "173.212.225.176", "136.243.45.140" }; @@ -851,11 +850,11 @@ void LP_initcoins(void *ctx,int32_t pubsock,cJSON *coins) void LP_initpeers(int32_t pubsock,struct LP_peerinfo *mypeer,char *myipaddr,uint16_t myport,uint16_t netid,char *seednode) { - int32_t i,j; uint32_t r; uint16_t pushport,subport,busport; + int32_t i,j; uint32_t r; uint16_t pushport,subport,busport; char fixedseed[64]; LP_ports(&pushport,&subport,&busport,netid); if ( IAMLP != 0 ) { - LP_mypeer = mypeer = LP_addpeer(mypeer,pubsock,myipaddr,myport,pushport,subport,1,G.LP_sessionid); + LP_mypeer = mypeer = LP_addpeer(mypeer,pubsock,myipaddr,myport,pushport,subport,1,G.LP_sessionid,netid); if ( myipaddr == 0 || mypeer == 0 ) { printf("couldnt get myipaddr or null mypeer.%p\n",mypeer); @@ -863,11 +862,14 @@ void LP_initpeers(int32_t pubsock,struct LP_peerinfo *mypeer,char *myipaddr,uint } if ( seednode == 0 || seednode[0] == 0 ) { - for (i=0; i 0 && netid < 9) && (seednode == 0 || seednode[0] == 0) ) + { + sprintf(fixedseed,"5.9.253.%d",195 + netid); + seednode = fixedseed; + } if ( seednode == 0 || seednode[0] == 0 ) { - //LP_addpeer(mypeer,pubsock,"51.15.86.136",myport,pushport,subport,0,G.LP_sessionid); OS_randombytes((void *)&r,sizeof(r)); - //r = 0; for (j=0; jnetid != netid ) + { + printf("netid mismatch for %s? %d vs %d\n",peer->ipaddr,peer->netid,G.netid); + return(0); + } if ( isLP != 0 && peer->isLP == 0 ) { if ( (peer->isLP= isLP) != 0 ) @@ -90,6 +95,7 @@ struct LP_peerinfo *LP_addpeer(struct LP_peerinfo *mypeer,int32_t mypubsock,char else peer->sessionid = sessionid; peer->pushsock = peer->subsock = pushsock = subsock = -1; strcpy(peer->ipaddr,ipaddr); + peer->netid = netid; //peer->profitmargin = profitmargin; peer->ipbits = ipbits; if ( (peer->isLP= isLP) != 0 ) @@ -181,11 +187,6 @@ struct LP_peerinfo *LP_addpeer(struct LP_peerinfo *mypeer,int32_t mypubsock,char return(peer); } -uint64_t ip_port; -uint32_t recvtime,numrecv,ipbits,errortime,errors,numpeers,needping,lasttime,connected,lastutxos,lastpeers,diduquery,good,sessionid; -uint16_t port,netid; - - void LP_closepeers() { struct LP_peerinfo *peer,*tmp; diff --git a/iguana/exchanges/LP_signatures.c b/iguana/exchanges/LP_signatures.c index 6318a96a7..31870fad2 100644 --- a/iguana/exchanges/LP_signatures.c +++ b/iguana/exchanges/LP_signatures.c @@ -570,7 +570,7 @@ char *LP_notify_recv(cJSON *argjson) G.LP_IAMLP = 1; } } - LP_addpeer(LP_mypeer,LP_mypubsock,ipaddr,RPC_port,RPC_port+10,RPC_port+20,1,juint(argjson,"session")); + LP_addpeer(LP_mypeer,LP_mypubsock,ipaddr,RPC_port,RPC_port+10,RPC_port+20,1,juint(argjson,"session"),G.netid); } //char str[65]; printf("%.3f NOTIFIED pub %s rmd160 %s\n",OS_milliseconds()-millis,bits256_str(str,pub),rmd160str); } From 6eb4ab4a6fdddef4254ce01452986da464c5ecf4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 25 Jan 2018 16:19:05 +0400 Subject: [PATCH 132/183] Test --- iguana/exchanges/LP_nativeDEX.c | 4 ++++ iguana/exchanges/LP_privkey.c | 21 ++++++++++++--------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 91dac1f81..9d7619e70 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -544,7 +544,10 @@ void LP_coinsloop(void *_coins) } } if ( coin->smartaddr[0] == 0 ) + { printf("%s has no smartaddress??\n",coin->symbol); + continue; + } memset(&zero,0,sizeof(zero)); if ( coin->inactive != 0 ) continue; @@ -1250,6 +1253,7 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu #endif if ( IAMLP != 0 ) { + G.netid = juint(argjson,"netid"); LP_mypubsock = -1; nanomsg_transportname(0,subaddr,myipaddr,mypubport); nanomsg_transportname(1,bindaddr,myipaddr,mypubport); diff --git a/iguana/exchanges/LP_privkey.c b/iguana/exchanges/LP_privkey.c index 6e26711b2..65821b0b4 100644 --- a/iguana/exchanges/LP_privkey.c +++ b/iguana/exchanges/LP_privkey.c @@ -377,16 +377,19 @@ int32_t LP_passphrase_init(char *passphrase,char *gui,uint16_t netid,char *seedn ctx = bitcoin_ctx(); if ( G.LP_pendingswaps != 0 ) return(-1); - if ( IAMLP != 0 && netid != G.netid ) + if ( netid != G.netid ) { - printf("sorry, LP nodes can only set netid during startup\n"); - return(-1); - } - else if ( IAMLP == 0 && netid != G.netid ) - { - printf("netid.%d vs G.netid %d\n",netid,G.netid); - LP_closepeers(); - LP_initpeers(LP_mypubsock,LP_mypeer,LP_myipaddr,RPC_port,netid,seednode); + if ( IAMLP != 0 ) + { + printf("sorry, LP nodes can only set netid during startup\n"); + return(-1); + } + else + { + printf(">>>>>>>>>>>>> netid.%d vs G.netid %d\n",netid,G.netid); + LP_closepeers(); + LP_initpeers(LP_mypubsock,LP_mypeer,LP_myipaddr,RPC_port,netid,seednode); + } } G.initializing = 1; if ( gui == 0 ) From dea5ef4866ba4f57a65923719ccac80885156ca1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 25 Jan 2018 18:01:04 +0400 Subject: [PATCH 133/183] Test --- iguana/exchanges/LP_network.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_network.c b/iguana/exchanges/LP_network.c index ee6b847ed..3fc9561c8 100644 --- a/iguana/exchanges/LP_network.c +++ b/iguana/exchanges/LP_network.c @@ -415,7 +415,7 @@ void LP_psockloop(void *_ptr) // printouts seem to be needed for forwarding to w static struct nn_pollfd *pfds; int32_t i,n,nonz,iter,retval,sentbytes,size=0,sendsock = -1; uint32_t now; struct psock *ptr=0; void *buf=0; char keepalive[512]; strcpy(LP_psockloop_stats.name,"LP_psockloop"); - LP_psockloop_stats.threshold = 200.; + LP_psockloop_stats.threshold = 1000.; while ( LP_STOP_RECEIVED == 0 ) { LP_millistats_update(&LP_psockloop_stats); From bbd8ad64e29c24852ab04596f90770e4f0a0d5d5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 25 Jan 2018 18:04:54 +0400 Subject: [PATCH 134/183] Test --- iguana/exchanges/LP_nativeDEX.c | 1 + 1 file changed, 1 insertion(+) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 9d7619e70..c816d6793 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -867,6 +867,7 @@ void LP_initpeers(int32_t pubsock,struct LP_peerinfo *mypeer,char *myipaddr,uint { if ( netid == 0 ) { + printf("load default seednodes\n"); for (i=0; i Date: Thu, 25 Jan 2018 18:06:08 +0400 Subject: [PATCH 135/183] Test --- iguana/exchanges/LP_nativeDEX.c | 1 + 1 file changed, 1 insertion(+) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index c816d6793..8383c5a9f 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -889,6 +889,7 @@ void LP_initpeers(int32_t pubsock,struct LP_peerinfo *mypeer,char *myipaddr,uint } if ( seednode == 0 || seednode[0] == 0 ) { + printf("default seed nodes for netid.%d\n",netid); OS_randombytes((void *)&r,sizeof(r)); for (j=0; j Date: Thu, 25 Jan 2018 18:20:10 +0400 Subject: [PATCH 136/183] Remove print --- iguana/exchanges/LP_commands.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_commands.c b/iguana/exchanges/LP_commands.c index 5fc6a0dac..94186c659 100644 --- a/iguana/exchanges/LP_commands.c +++ b/iguana/exchanges/LP_commands.c @@ -193,7 +193,7 @@ jpg(srcfile, destfile, power2=7, password, data="", required, ind=0)\n\ vcalc_sha256(0,passhash.bytes,(uint8_t *)passphrase,(int32_t)strlen(passphrase)); if ( bits256_cmp(passhash,G.LP_passhash) == 0 ) authenticated = 1; - else printf("(%s) passhash %s != G %s\n",passphrase,bits256_str(str,passhash),bits256_str(str2,G.LP_passhash)); + else printf("passhash %s != G %s\n",bits256_str(str,passhash),bits256_str(str2,G.LP_passhash)); } if ( authenticated == 0 && ((userpass= jstr(argjson,"userpass")) == 0 || strcmp(userpass,G.USERPASS) != 0) ) return(clonestr("{\"error\":\"authentication error you need to make sure userpass is set\"}")); From 951d224388cd1ef617d9c52510c439c6e15825a8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 25 Jan 2018 18:58:41 +0400 Subject: [PATCH 137/183] Test --- iguana/exchanges/LP_rpc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_rpc.c b/iguana/exchanges/LP_rpc.c index c7918cc71..76a4f820d 100644 --- a/iguana/exchanges/LP_rpc.c +++ b/iguana/exchanges/LP_rpc.c @@ -104,7 +104,7 @@ int32_t LP_getheight(int32_t *notarizedp,struct iguana_info *coin) coin->height = height = jint(retjson,"blocks"); if ( (*notarizedp= jint(retjson,"notarized")) != 0 && *notarizedp != coin->notarized ) { - printf("new notarized %s %d -> %d\n",coin->symbol,coin->notarized,*notarizedp); + //printf("new notarized %s %d -> %d\n",coin->symbol,coin->notarized,*notarizedp); coin->notarized = *notarizedp; coin->notarizationtxid = jbits256(retjson,"notarizedtxid"); coin->notarizedhash = jbits256(retjson,"notarizedhash"); From 95d3e696729169b0e3f2eae91f32d3db3885155b Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 25 Jan 2018 19:14:11 +0400 Subject: [PATCH 138/183] Test --- iguana/exchanges/prices/autoprice | 2 ++ 1 file changed, 2 insertions(+) diff --git a/iguana/exchanges/prices/autoprice b/iguana/exchanges/prices/autoprice index 1a82532f6..75bb33aff 100755 --- a/iguana/exchanges/prices/autoprice +++ b/iguana/exchanges/prices/autoprice @@ -12,6 +12,8 @@ curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\ curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"autoprice\",\"base\":\"KMD\",\"rel\":\"BTCH\",\"offset\":0.0,\"refbase\":\"KMD\",\"refrel\":\"HUSH\",\"factor\":1.44,\"buymargin\":0.05,\"sellmargin\":0.05}" curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"autoprice\",\"base\":\"BTCH\",\"rel\":\"KMD\",\"offset\":0.0,\"refbase\":\"HUSH\",\"refrel\":\"KMD\",\"factor\":0.7,\"buymargin\":0.05,\"sellmargin\":0.05}" +curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"autoprice\",\"base\":\"BEER\",\"rel\":\"PIZZA\",\"fixed\":9999,\"margin\":0.0001}" + source crypto source trackbtc From cae830dcf579e2f7adc42777699ace998061a072 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 25 Jan 2018 19:16:39 +0400 Subject: [PATCH 139/183] Test --- iguana/exchanges/enable | 2 ++ 1 file changed, 2 insertions(+) diff --git a/iguana/exchanges/enable b/iguana/exchanges/enable index 86166f790..dd4fd5380 100755 --- a/iguana/exchanges/enable +++ b/iguana/exchanges/enable @@ -1,5 +1,7 @@ #!/bin/bash source userpass +curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"enable\",\"coin\":\"BEER\"}" +curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"enable\",\"coin\":\"PIZZA\"}" curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"enable\",\"coin\":\"REVS\"}" curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"enable\",\"coin\":\"KMD\"}" curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"enable\",\"coin\":\"BTC\"}" From 98d31f668a4836963df7f80ec483bdfb0384497a Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 25 Jan 2018 19:18:51 +0400 Subject: [PATCH 140/183] Test --- iguana/exchanges/prices/autoprice | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/prices/autoprice b/iguana/exchanges/prices/autoprice index 75bb33aff..941fc382a 100755 --- a/iguana/exchanges/prices/autoprice +++ b/iguana/exchanges/prices/autoprice @@ -12,7 +12,7 @@ curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\ curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"autoprice\",\"base\":\"KMD\",\"rel\":\"BTCH\",\"offset\":0.0,\"refbase\":\"KMD\",\"refrel\":\"HUSH\",\"factor\":1.44,\"buymargin\":0.05,\"sellmargin\":0.05}" curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"autoprice\",\"base\":\"BTCH\",\"rel\":\"KMD\",\"offset\":0.0,\"refbase\":\"HUSH\",\"refrel\":\"KMD\",\"factor\":0.7,\"buymargin\":0.05,\"sellmargin\":0.05}" -curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"autoprice\",\"base\":\"BEER\",\"rel\":\"PIZZA\",\"fixed\":9999,\"margin\":0.0001}" +curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"autoprice\",\"base\":\"BEER\",\"rel\":\"PIZZA\",\"fixed\":0.00009999,\"margin\":0.0001}" source crypto source trackbtc From 6a8c2a44a8a02f2c1a7c4e81d38adb59836dc97c Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 25 Jan 2018 19:36:43 +0400 Subject: [PATCH 141/183] Test --- iguana/exchanges/prices/autoprice | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/prices/autoprice b/iguana/exchanges/prices/autoprice index 941fc382a..eb3b53851 100755 --- a/iguana/exchanges/prices/autoprice +++ b/iguana/exchanges/prices/autoprice @@ -12,7 +12,7 @@ curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\ curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"autoprice\",\"base\":\"KMD\",\"rel\":\"BTCH\",\"offset\":0.0,\"refbase\":\"KMD\",\"refrel\":\"HUSH\",\"factor\":1.44,\"buymargin\":0.05,\"sellmargin\":0.05}" curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"autoprice\",\"base\":\"BTCH\",\"rel\":\"KMD\",\"offset\":0.0,\"refbase\":\"HUSH\",\"refrel\":\"KMD\",\"factor\":0.7,\"buymargin\":0.05,\"sellmargin\":0.05}" -curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"autoprice\",\"base\":\"BEER\",\"rel\":\"PIZZA\",\"fixed\":0.00009999,\"margin\":0.0001}" +curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"autoprice\",\"base\":\"BEER\",\"rel\":\"PIZZA\",\"fixed\":0.0001,\"margin\":0.00001}" source crypto source trackbtc From dd34d43d8889bede4c1c3be605c84fca3cc4504b Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 25 Jan 2018 21:32:35 +0400 Subject: [PATCH 142/183] Test --- iguana/exchanges/LP_privkey.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_privkey.c b/iguana/exchanges/LP_privkey.c index 65821b0b4..191c5fde1 100644 --- a/iguana/exchanges/LP_privkey.c +++ b/iguana/exchanges/LP_privkey.c @@ -372,7 +372,7 @@ void LP_privkey_updates(void *ctx,int32_t pubsock,char *passphrase) int32_t LP_passphrase_init(char *passphrase,char *gui,uint16_t netid,char *seednode) { - static void *ctx; int32_t counter; //iambob,; struct LP_utxoinfo *utxo,*tmp; + static void *ctx; struct iguana_info *coin,*tmp; int32_t counter; if ( ctx == 0 ) ctx = bitcoin_ctx(); if ( G.LP_pendingswaps != 0 ) @@ -395,6 +395,10 @@ int32_t LP_passphrase_init(char *passphrase,char *gui,uint16_t netid,char *seedn if ( gui == 0 ) gui = "cli"; counter = G.USERPASS_COUNTER; + HASH_ITER(hh,LP_coins,coin,tmp) + { + coin->importedprivkey = 0; + } while ( G.waiting == 0 ) { printf("waiting for G.waiting\n"); From afbc4247741f0efb3158cd15230efa2bf3a73cc1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 26 Jan 2018 10:24:57 +0400 Subject: [PATCH 143/183] BCH three to 1000 --- iguana/exchanges/coins | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/coins b/iguana/exchanges/coins index 87b472712..ed72c6d97 100644 --- a/iguana/exchanges/coins +++ b/iguana/exchanges/coins @@ -1,3 +1,3 @@ -export coins="[{\"coin\":\"ZOI\",\"name\":\"zoin\",\"rpcport\":8255,\"pubtype\":80,\"p2shtype\":7,\"wiftype\":208,\"txfee\":1000}, {\"coin\": \"PIZZA\",\"asset\": \"PIZZA\",\"rpcport\": 11116},{\"coin\": \"BEER\",\"asset\": \"BEER\",\"rpcport\": 8923}, {\"coin\":\"GRS\",\"name\":\"groestlcoin\",\"rpcport\":1441,\"pubtype\":36,\"p2shtype\":5,\"wiftype\":128,\"txfee\":10000}, {\"coin\":\"XMCC\",\"name\":\"monoeci\",\"confpath\":\"${HOME#}/.monoeciCore/monoeci.conf\",\"rpcport\":24156,\"pubtype\":50,\"p2shtype\":73,\"wiftype\":77,\"txfee\":10000}, {\"coin\":\"BTCH\",\"asset\":\"BTCH\",\"rpcport\":8800},{\"coin\":\"ETOMIC\",\"asset\":\"ETOMIC\",\"rpcport\":10271},{\"coin\":\"AXO\",\"asset\":\"AXO\",\"rpcport\":12927},{\"coin\":\"CRC\",\"name\":\"crowdcoin\",\"confpath\":\"${HOME#}/.crowdcoincore/crowdcoin.conf\",\"rpcport\":9998,\"pubtype\":28,\"p2shtype\":88,\"wiftype\":0,\"txfee\":10000}, {\"coin\":\"VOT\",\"name\":\"votecoin\",\"rpcport\":8232,\"taddr\":28,\"pubtype\":184,\"p2shtype\":189,\"wiftype\":128,\"txfee\":10000}, {\"coin\":\"INN\",\"name\":\"innova\",\"confpath\":\"${HOME#}/.innovacore/innova.conf\",\"rpcport\":8818,\"pubtype\":102,\"p2shtype\":20,\"wiftype\":195,\"txfee\":10000}, {\"coin\":\"MOON\",\"name\":\"mooncoin\",\"rpcport\":44663,\"pubtype\":3,\"p2shtype\":22,\"wiftype\":131,\"txfee\":100000}, {\"coin\":\"CRW\",\"name\":\"crown\",\"rpcport\":9341,\"pubtype\":0,\"p2shtype\":28,\"wiftype\":128,\"txfee\":10000}, {\"coin\":\"EFL\",\"name\":\"egulden\",\"confpath\":\"${HOME#}/.egulden/coin.conf\",\"rpcport\":21015,\"pubtype\":48,\"p2shtype\":5,\"wiftype\":176,\"txfee\":100000}, {\"coin\":\"GBX\",\"name\":\"gobyte\",\"confpath\":\"${HOME#}/.gobytecore/gobyte.conf\",\"rpcport\":12454,\"pubtype\":38,\"p2shtype\":10,\"wiftype\":198,\"txfee\":10000}, {\"coin\":\"BCO\",\"name\":\"bridgecoin\",\"rpcport\":6332,\"pubtype\":27,\"p2shtype\":5,\"wiftype\":176,\"txfee\":100000}, {\"coin\":\"BLK\",\"name\":\"blackcoin\",\"confpath\":\"${HOME#}/.lore/blackcoin.conf\",\"isPoS\":1,\"rpcport\":15715,\"pubtype\":25,\"p2shtype\":85,\"wiftype\":153,\"txfee\":100000}, {\"coin\":\"BTG\",\"name\":\"bitcoingold\",\"rpcport\":8332,\"pubtype\":38,\"p2shtype\":23,\"wiftype\":128,\"txfee\":10000}, {\"coin\":\"BCH\",\"name\":\"bch\",\"rpcport\":33333,\"pubtype\":0,\"p2shtype\":5,\"wiftype\":128,\"txfee\":10000}, {\"coin\":\"ABY\",\"name\":\"applebyte\",\"rpcport\":8607,\"pubtype\":23,\"p2shtype\":5,\"wiftype\":151,\"txfee\":100000}, {\"coin\":\"STAK\",\"name\":\"straks\",\"rpcport\":7574,\"pubtype\":63,\"p2shtype\":5,\"wiftype\":204,\"txfee\":10000}, {\"coin\":\"XZC\",\"name\":\"zcoin\",\"rpcport\":8888,\"pubtype\":82,\"p2shtype\":7,\"wiftype\":210,\"txfee\":10000}, {\"coin\":\"QTUM\",\"name\":\"qtum\",\"rpcport\":3889,\"pubtype\":58,\"p2shtype\":50,\"wiftype\":128,\"txfee\":400000}, {\"coin\":\"PURA\",\"name\":\"pura\",\"rpcport\":55555,\"pubtype\":55,\"p2shtype\":16,\"wiftype\":150,\"txfee\":10000}, {\"coin\":\"DSR\",\"name\":\"desire\",\"confpath\":\"${HOME#}/.desirecore/desire.conf\",\"rpcport\":9918,\"pubtype\":30,\"p2shtype\":16,\"wiftype\":204,\"txfee\":10000}, {\"coin\":\"MNZ\",\"asset\":\"MNZ\",\"rpcport\":14337},{\"coin\":\"BTCZ\",\"name\":\"bitcoinz\",\"rpcport\":1979,\"taddr\":28,\"pubtype\":184,\"p2shtype\":189,\"wiftype\":128,\"txfee\":10000}, {\"coin\":\"MAGA\",\"name\":\"magacoin\",\"rpcport\":5332,\"pubtype\":23,\"p2shtype\":50,\"wiftype\":176,\"txfee\":100000}, {\"coin\":\"BSD\",\"name\":\"bitsend\",\"rpcport\":8800,\"pubtype\":102,\"p2shtype\":5,\"wiftype\":204,\"txfee\":10000}, {\"coin\":\"IOP\",\"name\":\"IoP\",\"rpcport\":8337,\"pubtype\":117,\"p2shtype\":174,\"wiftype\":49,\"txfee\":10000}, {\"coin\":\"BLOCK\",\"name\":\"blocknetdx\",\"rpcport\":41414,\"pubtype\":26,\"p2shtype\":28,\"wiftype\":154,\"txfee\":10000}, {\"coin\":\"CHIPS\", \"name\": \"chips\", \"rpcport\":57776,\"pubtype\":60, \"p2shtype\":85, \"wiftype\":188, \"txfee\":10000}, {\"coin\":\"888\",\"name\":\"octocoin\",\"rpcport\":22888,\"pubtype\":18,\"p2shtype\":5,\"wiftype\":176,\"txfee\":2000000}, {\"coin\":\"ARG\",\"name\":\"argentum\",\"rpcport\":13581,\"pubtype\":23,\"p2shtype\":5,\"wiftype\":151,\"txfee\":50000}, {\"coin\":\"GLT\",\"name\":\"globaltoken\",\"rpcport\":9320,\"pubtype\":38,\"p2shtype\":5,\"wiftype\":166,\"txfee\":10000}, {\"coin\":\"ZER\",\"name\":\"zero\",\"rpcport\":23801,\"taddr\":28,\"pubtype\":184,\"p2shtype\":189,\"wiftype\":128,\"txfee\":1000}, {\"coin\":\"HODLC\",\"name\":\"hodlcoin\",\"rpcport\":11989,\"pubtype\":40,\"p2shtype\":5,\"wiftype\":168,\"txfee\":5000}, {\"coin\":\"UIS\",\"name\":\"unitus\",\"rpcport\":50604,\"pubtype\":68,\"p2shtype\":10,\"wiftype\":132,\"txfee\":2000000}, {\"coin\":\"HUC\",\"name\":\"huntercoin\",\"rpcport\":8399,\"pubtype\":40,\"p2shtype\":13,\"wiftype\":168,\"txfee\":100000}, {\"coin\":\"BDL\",\"name\":\"bitdeal\",\"rpcport\":9332,\"pubtype\":38,\"p2shtype\":5,\"wiftype\":176,\"txfee\":100000}, {\"coin\":\"ARC\",\"name\":\"arcticcoin\",\"confpath\":\"${HOME#}/.arcticcore/arcticcoin.conf\",\"rpcport\":7208,\"pubtype\":23,\"p2shtype\":8,\"wiftype\":176,\"txfee\":10000}, {\"coin\":\"ZCL\",\"name\":\"zclassic\",\"rpcport\":8023,\"taddr\":28,\"pubtype\":184,\"p2shtype\":189,\"wiftype\":128,\"txfee\":1000}, {\"coin\":\"VIA\",\"name\":\"viacoin\",\"rpcport\":5222,\"pubtype\":71,\"p2shtype\":33,\"wiftype\":199,\"txfee\":100000}, {\"coin\":\"ERC\",\"name\":\"europecoin\",\"rpcport\":11989,\"pubtype\":33,\"p2shtype\":5,\"wiftype\":168,\"txfee\":10000},{\"coin\":\"FAIR\",\"name\":\"faircoin\",\"confpath\":\"${HOME#}/.faircoin2/faircoin.conf\",\"rpcport\":40405,\"pubtype\":95,\"p2shtype\":36,\"wiftype\":223,\"txfee\":1000000}, {\"coin\":\"FLO\",\"name\":\"florincoin\",\"rpcport\":7313,\"pubtype\":35,\"p2shtype\":8,\"wiftype\":176,\"txfee\":100000}, {\"coin\":\"SXC\",\"name\":\"sexcoin\",\"rpcport\":9561,\"pubtype\":62,\"p2shtype\":5,\"wiftype\":190,\"txfee\":100000}, {\"coin\":\"CREA\",\"name\":\"creativecoin\",\"rpcport\":17711,\"pubtype\":28,\"p2shtype\":5,\"wiftype\":176,\"txfee\":100000}, {\"coin\":\"TRC\",\"name\":\"terracoin\",\"confpath\":\"${HOME#}/.terracoincore/terracoin.conf\",\"rpcport\":13332,\"pubtype\":0,\"p2shtype\":5,\"wiftype\":128,\"txfee\":10000}, {\"coin\":\"BTA\",\"name\":\"bata\",\"rpcport\":5493,\"pubtype\":25,\"p2shtype\":5,\"wiftype\":188,\"txfee\":100000}, {\"coin\":\"SMC\",\"name\":\"smartcoin\",\"rpcport\":58583,\"pubtype\":63,\"p2shtype\":5,\"wiftype\":191,\"txfee\":1000000}, {\"coin\":\"NMC\",\"name\":\"namecoin\",\"rpcport\":8336,\"pubtype\":52,\"p2shtype\":13,\"wiftype\":180,\"txfee\":100000}, {\"coin\":\"NAV\",\"name\":\"navcoin\",\"isPoS\":1,\"confpath\":\"${HOME#}/.navcoin4/navcoin.conf\",\"rpcport\":44444,\"pubtype\":53,\"p2shtype\":85,\"wiftype\":150,\"txfee\":10000}, {\"coin\":\"EMC2\",\"name\":\"einsteinium\",\"rpcport\":41879,\"pubtype\":33,\"p2shtype\":5,\"wiftype\":176,\"txfee\":100000},{\"coin\":\"SYS\",\"name\":\"syscoin\",\"rpcport\":8370,\"pubtype\":0,\"p2shtype\":5,\"wiftype\":128,\"txfee\":10000}, {\"coin\":\"I0C\",\"name\":\"i0coin\",\"rpcport\":7332,\"pubtype\":105,\"p2shtype\":5,\"wiftype\":128,\"txfee\":10000}, {\"coin\":\"DASH\",\"confpath\":\"${HOME#}/.dashcore/dash.conf\",\"name\":\"dashcore\",\"rpcport\":9998,\"pubtype\":76,\"p2shtype\":16,\"wiftype\":204,\"txfee\":10000}, {\"coin\":\"STRAT\", \"name\": \"stratis\", \"active\":0, \"rpcport\":16174,\"pubtype\":63, \"p2shtype\":125, \"wiftype\":191, \"txfee\":10000}, {\"confpath\":\"${HOME#}/.muecore/mue.conf\",\"coin\":\"MUE\",\"name\":\"muecore\",\"rpcport\":29683,\"pubtype\":16,\"p2shtype\":76,\"wiftype\":126,\"txfee\":10000}, {\"coin\":\"MONA\",\"name\":\"monacoin\",\"rpcport\":9402,\"pubtype\":50,\"p2shtype\":5,\"wiftype\":176,\"txfee\":100000},{\"coin\":\"XMY\",\"name\":\"myriadcoin\",\"rpcport\":10889,\"pubtype\":50,\"p2shtype\":9,\"wiftype\":178,\"txfee\":5000}, {\"coin\":\"MAC\",\"name\":\"machinecoin\",\"rpcport\":40332,\"pubtype\":50,\"p2shtype\":5,\"wiftype\":178,\"txfee\":100000}, {\"coin\":\"BTX\",\"name\":\"bitcore\",\"rpcport\":8556,\"pubtype\":0,\"p2shtype\":5,\"wiftype\":128,\"txfee\":50000}, {\"coin\":\"XRE\",\"name\":\"revolvercoin\",\"rpcport\":8775,\"pubtype\":0,\"p2shtype\":5,\"wiftype\":128,\"txfee\":10000}, {\"coin\":\"LBC\",\"name\":\"lbrycrd\",\"rpcport\":9245,\"pubtype\":85,\"p2shtype\":122,\"wiftype\":28,\"txfee\":10000}, {\"coin\":\"SIB\",\"name\":\"sibcoin\",\"rpcport\":1944,\"pubtype\":63,\"p2shtype\":40,\"wiftype\":128,\"txfee\":10000}, {\"coin\":\"VTC\", \"name\":\"vertcoin\", \"rpcport\":5888, \"pubtype\":71, \"p2shtype\":5, \"wiftype\":128, \"txfee\":100000 }, {\"coin\":\"REVS\",\"active\":0, \"asset\":\"REVS\",\"rpcport\":10196}, {\"coin\":\"JUMBLR\",\"active\":0, \"asset\":\"JUMBLR\",\"rpcport\":15106}, {\"coin\":\"DOGE\",\"name\":\"dogecoin\",\"rpcport\":22555,\"pubtype\":30,\"p2shtype\":22,\"wiftype\":158,\"txfee\":100000000}, {\"coin\":\"HUSH\",\"name\":\"hush\",\"rpcport\":8822,\"taddr\":28,\"pubtype\":184,\"p2shtype\":189,\"wiftype\":128,\"txfee\":1000 }, {\"active\":0,\"coin\":\"ZEC\",\"name\":\"zcash\",\"rpcport\":8232,\"taddr\":28,\"pubtype\":184,\"p2shtype\":189,\"wiftype\":128,\"txfee\":10000 }, {\"coin\":\"DGB\",\"name\":\"digibyte\",\"rpcport\":14022,\"pubtype\":30,\"p2shtype\":5,\"wiftype\":128,\"txfee\":100000}, {\"coin\":\"ZET\", \"name\":\"zetacoin\", \"pubtype\":80, \"p2shtype\":9,\"rpcport\":8332, \"wiftype\":224, \"txfee\":10000}, {\"coin\":\"GAME\", \"rpcport\":40001, \"name\":\"gamecredits\", \"pubtype\":38, \"p2shtype\":5, \"wiftype\":166, \"txfee\":100000}, {\"coin\":\"LTC\", \"name\":\"litecoin\", \"rpcport\":9332, \"pubtype\":48, \"p2shtype\":5, \"wiftype\":176, \"txfee\":100000 }, {\"coin\":\"SUPERNET\",\"asset\":\"SUPERNET\",\"rpcport\":11341}, {\"coin\":\"WLC\",\"asset\":\"WLC\",\"rpcport\":12167}, {\"coin\":\"PANGEA\",\"asset\":\"PANGEA\",\"rpcport\":14068}, {\"coin\":\"DEX\",\"asset\":\"DEX\",\"rpcport\":11890}, {\"coin\":\"BET\",\"asset\":\"BET\",\"rpcport\":14250}, {\"coin\":\"CRYPTO\",\"asset\":\"CRYPTO\",\"rpcport\":8516}, {\"coin\":\"HODL\",\"asset\":\"HODL\",\"rpcport\":14431}, {\"coin\":\"MSHARK\",\"asset\":\"MSHARK\",\"rpcport\":8846}, {\"coin\":\"BOTS\",\"asset\":\"BOTS\",\"rpcport\":11964}, {\"coin\":\"MGW\",\"asset\":\"MGW\",\"rpcport\":12386}, {\"coin\":\"COQUI\",\"asset\":\"COQUI\",\"rpcport\":14276}, {\"coin\":\"KV\",\"asset\":\"KV\",\"rpcport\":8299}, {\"coin\":\"CEAL\",\"asset\":\"CEAL\",\"rpcport\":11116}, {\"coin\":\"MESH\",\"asset\":\"MESH\",\"rpcport\":9455}]" +export coins="[{\"coin\":\"ZOI\",\"name\":\"zoin\",\"rpcport\":8255,\"pubtype\":80,\"p2shtype\":7,\"wiftype\":208,\"txfee\":1000}, {\"coin\": \"PIZZA\",\"asset\": \"PIZZA\",\"rpcport\": 11116},{\"coin\": \"BEER\",\"asset\": \"BEER\",\"rpcport\": 8923}, {\"coin\":\"GRS\",\"name\":\"groestlcoin\",\"rpcport\":1441,\"pubtype\":36,\"p2shtype\":5,\"wiftype\":128,\"txfee\":10000}, {\"coin\":\"XMCC\",\"name\":\"monoeci\",\"confpath\":\"${HOME#}/.monoeciCore/monoeci.conf\",\"rpcport\":24156,\"pubtype\":50,\"p2shtype\":73,\"wiftype\":77,\"txfee\":10000}, {\"coin\":\"BTCH\",\"asset\":\"BTCH\",\"rpcport\":8800},{\"coin\":\"ETOMIC\",\"asset\":\"ETOMIC\",\"rpcport\":10271},{\"coin\":\"AXO\",\"asset\":\"AXO\",\"rpcport\":12927},{\"coin\":\"CRC\",\"name\":\"crowdcoin\",\"confpath\":\"${HOME#}/.crowdcoincore/crowdcoin.conf\",\"rpcport\":9998,\"pubtype\":28,\"p2shtype\":88,\"wiftype\":0,\"txfee\":10000}, {\"coin\":\"VOT\",\"name\":\"votecoin\",\"rpcport\":8232,\"taddr\":28,\"pubtype\":184,\"p2shtype\":189,\"wiftype\":128,\"txfee\":10000}, {\"coin\":\"INN\",\"name\":\"innova\",\"confpath\":\"${HOME#}/.innovacore/innova.conf\",\"rpcport\":8818,\"pubtype\":102,\"p2shtype\":20,\"wiftype\":195,\"txfee\":10000}, {\"coin\":\"MOON\",\"name\":\"mooncoin\",\"rpcport\":44663,\"pubtype\":3,\"p2shtype\":22,\"wiftype\":131,\"txfee\":100000}, {\"coin\":\"CRW\",\"name\":\"crown\",\"rpcport\":9341,\"pubtype\":0,\"p2shtype\":28,\"wiftype\":128,\"txfee\":10000}, {\"coin\":\"EFL\",\"name\":\"egulden\",\"confpath\":\"${HOME#}/.egulden/coin.conf\",\"rpcport\":21015,\"pubtype\":48,\"p2shtype\":5,\"wiftype\":176,\"txfee\":100000}, {\"coin\":\"GBX\",\"name\":\"gobyte\",\"confpath\":\"${HOME#}/.gobytecore/gobyte.conf\",\"rpcport\":12454,\"pubtype\":38,\"p2shtype\":10,\"wiftype\":198,\"txfee\":10000}, {\"coin\":\"BCO\",\"name\":\"bridgecoin\",\"rpcport\":6332,\"pubtype\":27,\"p2shtype\":5,\"wiftype\":176,\"txfee\":100000}, {\"coin\":\"BLK\",\"name\":\"blackcoin\",\"confpath\":\"${HOME#}/.lore/blackcoin.conf\",\"isPoS\":1,\"rpcport\":15715,\"pubtype\":25,\"p2shtype\":85,\"wiftype\":153,\"txfee\":100000}, {\"coin\":\"BTG\",\"name\":\"bitcoingold\",\"rpcport\":8332,\"pubtype\":38,\"p2shtype\":23,\"wiftype\":128,\"txfee\":10000}, {\"coin\":\"BCH\",\"name\":\"bch\",\"rpcport\":33333,\"pubtype\":0,\"p2shtype\":5,\"wiftype\":128,\"txfee\":1000}, {\"coin\":\"ABY\",\"name\":\"applebyte\",\"rpcport\":8607,\"pubtype\":23,\"p2shtype\":5,\"wiftype\":151,\"txfee\":100000}, {\"coin\":\"STAK\",\"name\":\"straks\",\"rpcport\":7574,\"pubtype\":63,\"p2shtype\":5,\"wiftype\":204,\"txfee\":10000}, {\"coin\":\"XZC\",\"name\":\"zcoin\",\"rpcport\":8888,\"pubtype\":82,\"p2shtype\":7,\"wiftype\":210,\"txfee\":10000}, {\"coin\":\"QTUM\",\"name\":\"qtum\",\"rpcport\":3889,\"pubtype\":58,\"p2shtype\":50,\"wiftype\":128,\"txfee\":400000}, {\"coin\":\"PURA\",\"name\":\"pura\",\"rpcport\":55555,\"pubtype\":55,\"p2shtype\":16,\"wiftype\":150,\"txfee\":10000}, {\"coin\":\"DSR\",\"name\":\"desire\",\"confpath\":\"${HOME#}/.desirecore/desire.conf\",\"rpcport\":9918,\"pubtype\":30,\"p2shtype\":16,\"wiftype\":204,\"txfee\":10000}, {\"coin\":\"MNZ\",\"asset\":\"MNZ\",\"rpcport\":14337},{\"coin\":\"BTCZ\",\"name\":\"bitcoinz\",\"rpcport\":1979,\"taddr\":28,\"pubtype\":184,\"p2shtype\":189,\"wiftype\":128,\"txfee\":10000}, {\"coin\":\"MAGA\",\"name\":\"magacoin\",\"rpcport\":5332,\"pubtype\":23,\"p2shtype\":50,\"wiftype\":176,\"txfee\":100000}, {\"coin\":\"BSD\",\"name\":\"bitsend\",\"rpcport\":8800,\"pubtype\":102,\"p2shtype\":5,\"wiftype\":204,\"txfee\":10000}, {\"coin\":\"IOP\",\"name\":\"IoP\",\"rpcport\":8337,\"pubtype\":117,\"p2shtype\":174,\"wiftype\":49,\"txfee\":10000}, {\"coin\":\"BLOCK\",\"name\":\"blocknetdx\",\"rpcport\":41414,\"pubtype\":26,\"p2shtype\":28,\"wiftype\":154,\"txfee\":10000}, {\"coin\":\"CHIPS\", \"name\": \"chips\", \"rpcport\":57776,\"pubtype\":60, \"p2shtype\":85, \"wiftype\":188, \"txfee\":10000}, {\"coin\":\"888\",\"name\":\"octocoin\",\"rpcport\":22888,\"pubtype\":18,\"p2shtype\":5,\"wiftype\":176,\"txfee\":2000000}, {\"coin\":\"ARG\",\"name\":\"argentum\",\"rpcport\":13581,\"pubtype\":23,\"p2shtype\":5,\"wiftype\":151,\"txfee\":50000}, {\"coin\":\"GLT\",\"name\":\"globaltoken\",\"rpcport\":9320,\"pubtype\":38,\"p2shtype\":5,\"wiftype\":166,\"txfee\":10000}, {\"coin\":\"ZER\",\"name\":\"zero\",\"rpcport\":23801,\"taddr\":28,\"pubtype\":184,\"p2shtype\":189,\"wiftype\":128,\"txfee\":1000}, {\"coin\":\"HODLC\",\"name\":\"hodlcoin\",\"rpcport\":11989,\"pubtype\":40,\"p2shtype\":5,\"wiftype\":168,\"txfee\":5000}, {\"coin\":\"UIS\",\"name\":\"unitus\",\"rpcport\":50604,\"pubtype\":68,\"p2shtype\":10,\"wiftype\":132,\"txfee\":2000000}, {\"coin\":\"HUC\",\"name\":\"huntercoin\",\"rpcport\":8399,\"pubtype\":40,\"p2shtype\":13,\"wiftype\":168,\"txfee\":100000}, {\"coin\":\"BDL\",\"name\":\"bitdeal\",\"rpcport\":9332,\"pubtype\":38,\"p2shtype\":5,\"wiftype\":176,\"txfee\":100000}, {\"coin\":\"ARC\",\"name\":\"arcticcoin\",\"confpath\":\"${HOME#}/.arcticcore/arcticcoin.conf\",\"rpcport\":7208,\"pubtype\":23,\"p2shtype\":8,\"wiftype\":176,\"txfee\":10000}, {\"coin\":\"ZCL\",\"name\":\"zclassic\",\"rpcport\":8023,\"taddr\":28,\"pubtype\":184,\"p2shtype\":189,\"wiftype\":128,\"txfee\":1000}, {\"coin\":\"VIA\",\"name\":\"viacoin\",\"rpcport\":5222,\"pubtype\":71,\"p2shtype\":33,\"wiftype\":199,\"txfee\":100000}, {\"coin\":\"ERC\",\"name\":\"europecoin\",\"rpcport\":11989,\"pubtype\":33,\"p2shtype\":5,\"wiftype\":168,\"txfee\":10000},{\"coin\":\"FAIR\",\"name\":\"faircoin\",\"confpath\":\"${HOME#}/.faircoin2/faircoin.conf\",\"rpcport\":40405,\"pubtype\":95,\"p2shtype\":36,\"wiftype\":223,\"txfee\":1000000}, {\"coin\":\"FLO\",\"name\":\"florincoin\",\"rpcport\":7313,\"pubtype\":35,\"p2shtype\":8,\"wiftype\":176,\"txfee\":100000}, {\"coin\":\"SXC\",\"name\":\"sexcoin\",\"rpcport\":9561,\"pubtype\":62,\"p2shtype\":5,\"wiftype\":190,\"txfee\":100000}, {\"coin\":\"CREA\",\"name\":\"creativecoin\",\"rpcport\":17711,\"pubtype\":28,\"p2shtype\":5,\"wiftype\":176,\"txfee\":100000}, {\"coin\":\"TRC\",\"name\":\"terracoin\",\"confpath\":\"${HOME#}/.terracoincore/terracoin.conf\",\"rpcport\":13332,\"pubtype\":0,\"p2shtype\":5,\"wiftype\":128,\"txfee\":10000}, {\"coin\":\"BTA\",\"name\":\"bata\",\"rpcport\":5493,\"pubtype\":25,\"p2shtype\":5,\"wiftype\":188,\"txfee\":100000}, {\"coin\":\"SMC\",\"name\":\"smartcoin\",\"rpcport\":58583,\"pubtype\":63,\"p2shtype\":5,\"wiftype\":191,\"txfee\":1000000}, {\"coin\":\"NMC\",\"name\":\"namecoin\",\"rpcport\":8336,\"pubtype\":52,\"p2shtype\":13,\"wiftype\":180,\"txfee\":100000}, {\"coin\":\"NAV\",\"name\":\"navcoin\",\"isPoS\":1,\"confpath\":\"${HOME#}/.navcoin4/navcoin.conf\",\"rpcport\":44444,\"pubtype\":53,\"p2shtype\":85,\"wiftype\":150,\"txfee\":10000}, {\"coin\":\"EMC2\",\"name\":\"einsteinium\",\"rpcport\":41879,\"pubtype\":33,\"p2shtype\":5,\"wiftype\":176,\"txfee\":100000},{\"coin\":\"SYS\",\"name\":\"syscoin\",\"rpcport\":8370,\"pubtype\":0,\"p2shtype\":5,\"wiftype\":128,\"txfee\":10000}, {\"coin\":\"I0C\",\"name\":\"i0coin\",\"rpcport\":7332,\"pubtype\":105,\"p2shtype\":5,\"wiftype\":128,\"txfee\":10000}, {\"coin\":\"DASH\",\"confpath\":\"${HOME#}/.dashcore/dash.conf\",\"name\":\"dashcore\",\"rpcport\":9998,\"pubtype\":76,\"p2shtype\":16,\"wiftype\":204,\"txfee\":10000}, {\"coin\":\"STRAT\", \"name\": \"stratis\", \"active\":0, \"rpcport\":16174,\"pubtype\":63, \"p2shtype\":125, \"wiftype\":191, \"txfee\":10000}, {\"confpath\":\"${HOME#}/.muecore/mue.conf\",\"coin\":\"MUE\",\"name\":\"muecore\",\"rpcport\":29683,\"pubtype\":16,\"p2shtype\":76,\"wiftype\":126,\"txfee\":10000}, {\"coin\":\"MONA\",\"name\":\"monacoin\",\"rpcport\":9402,\"pubtype\":50,\"p2shtype\":5,\"wiftype\":176,\"txfee\":100000},{\"coin\":\"XMY\",\"name\":\"myriadcoin\",\"rpcport\":10889,\"pubtype\":50,\"p2shtype\":9,\"wiftype\":178,\"txfee\":5000}, {\"coin\":\"MAC\",\"name\":\"machinecoin\",\"rpcport\":40332,\"pubtype\":50,\"p2shtype\":5,\"wiftype\":178,\"txfee\":100000}, {\"coin\":\"BTX\",\"name\":\"bitcore\",\"rpcport\":8556,\"pubtype\":0,\"p2shtype\":5,\"wiftype\":128,\"txfee\":50000}, {\"coin\":\"XRE\",\"name\":\"revolvercoin\",\"rpcport\":8775,\"pubtype\":0,\"p2shtype\":5,\"wiftype\":128,\"txfee\":10000}, {\"coin\":\"LBC\",\"name\":\"lbrycrd\",\"rpcport\":9245,\"pubtype\":85,\"p2shtype\":122,\"wiftype\":28,\"txfee\":10000}, {\"coin\":\"SIB\",\"name\":\"sibcoin\",\"rpcport\":1944,\"pubtype\":63,\"p2shtype\":40,\"wiftype\":128,\"txfee\":10000}, {\"coin\":\"VTC\", \"name\":\"vertcoin\", \"rpcport\":5888, \"pubtype\":71, \"p2shtype\":5, \"wiftype\":128, \"txfee\":100000 }, {\"coin\":\"REVS\",\"active\":0, \"asset\":\"REVS\",\"rpcport\":10196}, {\"coin\":\"JUMBLR\",\"active\":0, \"asset\":\"JUMBLR\",\"rpcport\":15106}, {\"coin\":\"DOGE\",\"name\":\"dogecoin\",\"rpcport\":22555,\"pubtype\":30,\"p2shtype\":22,\"wiftype\":158,\"txfee\":100000000}, {\"coin\":\"HUSH\",\"name\":\"hush\",\"rpcport\":8822,\"taddr\":28,\"pubtype\":184,\"p2shtype\":189,\"wiftype\":128,\"txfee\":1000 }, {\"active\":0,\"coin\":\"ZEC\",\"name\":\"zcash\",\"rpcport\":8232,\"taddr\":28,\"pubtype\":184,\"p2shtype\":189,\"wiftype\":128,\"txfee\":10000 }, {\"coin\":\"DGB\",\"name\":\"digibyte\",\"rpcport\":14022,\"pubtype\":30,\"p2shtype\":5,\"wiftype\":128,\"txfee\":100000}, {\"coin\":\"ZET\", \"name\":\"zetacoin\", \"pubtype\":80, \"p2shtype\":9,\"rpcport\":8332, \"wiftype\":224, \"txfee\":10000}, {\"coin\":\"GAME\", \"rpcport\":40001, \"name\":\"gamecredits\", \"pubtype\":38, \"p2shtype\":5, \"wiftype\":166, \"txfee\":100000}, {\"coin\":\"LTC\", \"name\":\"litecoin\", \"rpcport\":9332, \"pubtype\":48, \"p2shtype\":5, \"wiftype\":176, \"txfee\":100000 }, {\"coin\":\"SUPERNET\",\"asset\":\"SUPERNET\",\"rpcport\":11341}, {\"coin\":\"WLC\",\"asset\":\"WLC\",\"rpcport\":12167}, {\"coin\":\"PANGEA\",\"asset\":\"PANGEA\",\"rpcport\":14068}, {\"coin\":\"DEX\",\"asset\":\"DEX\",\"rpcport\":11890}, {\"coin\":\"BET\",\"asset\":\"BET\",\"rpcport\":14250}, {\"coin\":\"CRYPTO\",\"asset\":\"CRYPTO\",\"rpcport\":8516}, {\"coin\":\"HODL\",\"asset\":\"HODL\",\"rpcport\":14431}, {\"coin\":\"MSHARK\",\"asset\":\"MSHARK\",\"rpcport\":8846}, {\"coin\":\"BOTS\",\"asset\":\"BOTS\",\"rpcport\":11964}, {\"coin\":\"MGW\",\"asset\":\"MGW\",\"rpcport\":12386}, {\"coin\":\"COQUI\",\"asset\":\"COQUI\",\"rpcport\":14276}, {\"coin\":\"KV\",\"asset\":\"KV\",\"rpcport\":8299}, {\"coin\":\"CEAL\",\"asset\":\"CEAL\",\"rpcport\":11116}, {\"coin\":\"MESH\",\"asset\":\"MESH\",\"rpcport\":9455}]" #, {\"coin\":\"AUD\",\"asset\":\"AUD\",\"rpcport\":8045}, {\"coin\":\"BGN\",\"asset\":\"BGN\",\"rpcport\":9110}, {\"coin\":\"CAD\",\"asset\":\"CAD\",\"rpcport\":8720}, {\"coin\":\"CHF\",\"asset\":\"CHF\",\"rpcport\":15312}, {\"coin\":\"CNY\",\"asset\":\"CNY\",\"rpcport\":10384}, {\"coin\":\"CZK\",\"asset\":\"CZK\",\"rpcport\":9482}, {\"coin\":\"DKK\",\"asset\":\"DKK\",\"rpcport\":13830}, {\"coin\":\"EUR\",\"asset\":\"EUR\",\"rpcport\":8065}, {\"coin\":\"GBP\",\"asset\":\"GBP\",\"rpcport\":11505}, {\"coin\":\"HKD\",\"asset\":\"HKD\",\"rpcport\":15409}, {\"coin\":\"HRK\",\"asset\":\"HRK\",\"rpcport\":12617}, {\"coin\":\"HUF\",\"asset\":\"HUF\",\"rpcport\":13699}, {\"coin\":\"IDR\",\"asset\":\"IDR\",\"rpcport\":14459}, {\"coin\":\"ILS\",\"asset\":\"ILS\",\"rpcport\":14638}, {\"coin\":\"INR\",\"asset\":\"INR\",\"rpcport\":10536}, {\"coin\":\"JPY\",\"asset\":\"JPY\",\"rpcport\":13145}, {\"coin\":\"KRW\",\"asset\":\"KRW\",\"rpcport\":14020}, {\"coin\":\"MXN\",\"asset\":\"MXN\",\"rpcport\":13970}, {\"coin\":\"MYR\",\"asset\":\"MYR\",\"rpcport\":10688}, {\"coin\":\"NOK\",\"asset\":\"NOK\",\"rpcport\":11588}, {\"coin\":\"NZD\",\"asset\":\"NZD\",\"rpcport\":10915}, {\"coin\":\"PHP\",\"asset\":\"PHP\",\"rpcport\":11181}, {\"coin\":\"PLN\",\"asset\":\"PLN\",\"rpcport\":13493}, {\"coin\":\"BRL\",\"asset\":\"BRL\",\"rpcport\":9914}, {\"coin\":\"RON\",\"asset\":\"RON\",\"rpcport\":8675}, {\"coin\":\"RUB\",\"asset\":\"RUB\",\"rpcport\":8199}, {\"coin\":\"SEK\",\"asset\":\"SEK\",\"rpcport\":11447}, {\"coin\":\"SGD\",\"asset\":\"SGD\",\"rpcport\":14475}, {\"coin\":\"THB\",\"asset\":\"THB\",\"rpcport\":11847}, {\"coin\":\"TRY\",\"asset\":\"TRY\",\"rpcport\":13924}, {\"coin\":\"USD\",\"asset\":\"USD\",\"rpcport\":13967}, {\"coin\":\"ZAR\",\"asset\":\"ZAR\",\"rpcport\":15160}]" #{\"coin\":\"PIVX\",\"name\":\"pivx\",\"rpcport\":51473,\"pubtype\":30,\"p2shtype\":13,\"wiftype\":212,\"txfee\":10000}, From 3be0bc4a8ff6713581cfdf0f9b47453abc80b7b4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 27 Jan 2018 19:36:30 +0400 Subject: [PATCH 144/183] New CRC port --- iguana/exchanges/coins | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/coins b/iguana/exchanges/coins index ed72c6d97..b41a8b96f 100644 --- a/iguana/exchanges/coins +++ b/iguana/exchanges/coins @@ -1,3 +1,3 @@ -export coins="[{\"coin\":\"ZOI\",\"name\":\"zoin\",\"rpcport\":8255,\"pubtype\":80,\"p2shtype\":7,\"wiftype\":208,\"txfee\":1000}, {\"coin\": \"PIZZA\",\"asset\": \"PIZZA\",\"rpcport\": 11116},{\"coin\": \"BEER\",\"asset\": \"BEER\",\"rpcport\": 8923}, {\"coin\":\"GRS\",\"name\":\"groestlcoin\",\"rpcport\":1441,\"pubtype\":36,\"p2shtype\":5,\"wiftype\":128,\"txfee\":10000}, {\"coin\":\"XMCC\",\"name\":\"monoeci\",\"confpath\":\"${HOME#}/.monoeciCore/monoeci.conf\",\"rpcport\":24156,\"pubtype\":50,\"p2shtype\":73,\"wiftype\":77,\"txfee\":10000}, {\"coin\":\"BTCH\",\"asset\":\"BTCH\",\"rpcport\":8800},{\"coin\":\"ETOMIC\",\"asset\":\"ETOMIC\",\"rpcport\":10271},{\"coin\":\"AXO\",\"asset\":\"AXO\",\"rpcport\":12927},{\"coin\":\"CRC\",\"name\":\"crowdcoin\",\"confpath\":\"${HOME#}/.crowdcoincore/crowdcoin.conf\",\"rpcport\":9998,\"pubtype\":28,\"p2shtype\":88,\"wiftype\":0,\"txfee\":10000}, {\"coin\":\"VOT\",\"name\":\"votecoin\",\"rpcport\":8232,\"taddr\":28,\"pubtype\":184,\"p2shtype\":189,\"wiftype\":128,\"txfee\":10000}, {\"coin\":\"INN\",\"name\":\"innova\",\"confpath\":\"${HOME#}/.innovacore/innova.conf\",\"rpcport\":8818,\"pubtype\":102,\"p2shtype\":20,\"wiftype\":195,\"txfee\":10000}, {\"coin\":\"MOON\",\"name\":\"mooncoin\",\"rpcport\":44663,\"pubtype\":3,\"p2shtype\":22,\"wiftype\":131,\"txfee\":100000}, {\"coin\":\"CRW\",\"name\":\"crown\",\"rpcport\":9341,\"pubtype\":0,\"p2shtype\":28,\"wiftype\":128,\"txfee\":10000}, {\"coin\":\"EFL\",\"name\":\"egulden\",\"confpath\":\"${HOME#}/.egulden/coin.conf\",\"rpcport\":21015,\"pubtype\":48,\"p2shtype\":5,\"wiftype\":176,\"txfee\":100000}, {\"coin\":\"GBX\",\"name\":\"gobyte\",\"confpath\":\"${HOME#}/.gobytecore/gobyte.conf\",\"rpcport\":12454,\"pubtype\":38,\"p2shtype\":10,\"wiftype\":198,\"txfee\":10000}, {\"coin\":\"BCO\",\"name\":\"bridgecoin\",\"rpcport\":6332,\"pubtype\":27,\"p2shtype\":5,\"wiftype\":176,\"txfee\":100000}, {\"coin\":\"BLK\",\"name\":\"blackcoin\",\"confpath\":\"${HOME#}/.lore/blackcoin.conf\",\"isPoS\":1,\"rpcport\":15715,\"pubtype\":25,\"p2shtype\":85,\"wiftype\":153,\"txfee\":100000}, {\"coin\":\"BTG\",\"name\":\"bitcoingold\",\"rpcport\":8332,\"pubtype\":38,\"p2shtype\":23,\"wiftype\":128,\"txfee\":10000}, {\"coin\":\"BCH\",\"name\":\"bch\",\"rpcport\":33333,\"pubtype\":0,\"p2shtype\":5,\"wiftype\":128,\"txfee\":1000}, {\"coin\":\"ABY\",\"name\":\"applebyte\",\"rpcport\":8607,\"pubtype\":23,\"p2shtype\":5,\"wiftype\":151,\"txfee\":100000}, {\"coin\":\"STAK\",\"name\":\"straks\",\"rpcport\":7574,\"pubtype\":63,\"p2shtype\":5,\"wiftype\":204,\"txfee\":10000}, {\"coin\":\"XZC\",\"name\":\"zcoin\",\"rpcport\":8888,\"pubtype\":82,\"p2shtype\":7,\"wiftype\":210,\"txfee\":10000}, {\"coin\":\"QTUM\",\"name\":\"qtum\",\"rpcport\":3889,\"pubtype\":58,\"p2shtype\":50,\"wiftype\":128,\"txfee\":400000}, {\"coin\":\"PURA\",\"name\":\"pura\",\"rpcport\":55555,\"pubtype\":55,\"p2shtype\":16,\"wiftype\":150,\"txfee\":10000}, {\"coin\":\"DSR\",\"name\":\"desire\",\"confpath\":\"${HOME#}/.desirecore/desire.conf\",\"rpcport\":9918,\"pubtype\":30,\"p2shtype\":16,\"wiftype\":204,\"txfee\":10000}, {\"coin\":\"MNZ\",\"asset\":\"MNZ\",\"rpcport\":14337},{\"coin\":\"BTCZ\",\"name\":\"bitcoinz\",\"rpcport\":1979,\"taddr\":28,\"pubtype\":184,\"p2shtype\":189,\"wiftype\":128,\"txfee\":10000}, {\"coin\":\"MAGA\",\"name\":\"magacoin\",\"rpcport\":5332,\"pubtype\":23,\"p2shtype\":50,\"wiftype\":176,\"txfee\":100000}, {\"coin\":\"BSD\",\"name\":\"bitsend\",\"rpcport\":8800,\"pubtype\":102,\"p2shtype\":5,\"wiftype\":204,\"txfee\":10000}, {\"coin\":\"IOP\",\"name\":\"IoP\",\"rpcport\":8337,\"pubtype\":117,\"p2shtype\":174,\"wiftype\":49,\"txfee\":10000}, {\"coin\":\"BLOCK\",\"name\":\"blocknetdx\",\"rpcport\":41414,\"pubtype\":26,\"p2shtype\":28,\"wiftype\":154,\"txfee\":10000}, {\"coin\":\"CHIPS\", \"name\": \"chips\", \"rpcport\":57776,\"pubtype\":60, \"p2shtype\":85, \"wiftype\":188, \"txfee\":10000}, {\"coin\":\"888\",\"name\":\"octocoin\",\"rpcport\":22888,\"pubtype\":18,\"p2shtype\":5,\"wiftype\":176,\"txfee\":2000000}, {\"coin\":\"ARG\",\"name\":\"argentum\",\"rpcport\":13581,\"pubtype\":23,\"p2shtype\":5,\"wiftype\":151,\"txfee\":50000}, {\"coin\":\"GLT\",\"name\":\"globaltoken\",\"rpcport\":9320,\"pubtype\":38,\"p2shtype\":5,\"wiftype\":166,\"txfee\":10000}, {\"coin\":\"ZER\",\"name\":\"zero\",\"rpcport\":23801,\"taddr\":28,\"pubtype\":184,\"p2shtype\":189,\"wiftype\":128,\"txfee\":1000}, {\"coin\":\"HODLC\",\"name\":\"hodlcoin\",\"rpcport\":11989,\"pubtype\":40,\"p2shtype\":5,\"wiftype\":168,\"txfee\":5000}, {\"coin\":\"UIS\",\"name\":\"unitus\",\"rpcport\":50604,\"pubtype\":68,\"p2shtype\":10,\"wiftype\":132,\"txfee\":2000000}, {\"coin\":\"HUC\",\"name\":\"huntercoin\",\"rpcport\":8399,\"pubtype\":40,\"p2shtype\":13,\"wiftype\":168,\"txfee\":100000}, {\"coin\":\"BDL\",\"name\":\"bitdeal\",\"rpcport\":9332,\"pubtype\":38,\"p2shtype\":5,\"wiftype\":176,\"txfee\":100000}, {\"coin\":\"ARC\",\"name\":\"arcticcoin\",\"confpath\":\"${HOME#}/.arcticcore/arcticcoin.conf\",\"rpcport\":7208,\"pubtype\":23,\"p2shtype\":8,\"wiftype\":176,\"txfee\":10000}, {\"coin\":\"ZCL\",\"name\":\"zclassic\",\"rpcport\":8023,\"taddr\":28,\"pubtype\":184,\"p2shtype\":189,\"wiftype\":128,\"txfee\":1000}, {\"coin\":\"VIA\",\"name\":\"viacoin\",\"rpcport\":5222,\"pubtype\":71,\"p2shtype\":33,\"wiftype\":199,\"txfee\":100000}, {\"coin\":\"ERC\",\"name\":\"europecoin\",\"rpcport\":11989,\"pubtype\":33,\"p2shtype\":5,\"wiftype\":168,\"txfee\":10000},{\"coin\":\"FAIR\",\"name\":\"faircoin\",\"confpath\":\"${HOME#}/.faircoin2/faircoin.conf\",\"rpcport\":40405,\"pubtype\":95,\"p2shtype\":36,\"wiftype\":223,\"txfee\":1000000}, {\"coin\":\"FLO\",\"name\":\"florincoin\",\"rpcport\":7313,\"pubtype\":35,\"p2shtype\":8,\"wiftype\":176,\"txfee\":100000}, {\"coin\":\"SXC\",\"name\":\"sexcoin\",\"rpcport\":9561,\"pubtype\":62,\"p2shtype\":5,\"wiftype\":190,\"txfee\":100000}, {\"coin\":\"CREA\",\"name\":\"creativecoin\",\"rpcport\":17711,\"pubtype\":28,\"p2shtype\":5,\"wiftype\":176,\"txfee\":100000}, {\"coin\":\"TRC\",\"name\":\"terracoin\",\"confpath\":\"${HOME#}/.terracoincore/terracoin.conf\",\"rpcport\":13332,\"pubtype\":0,\"p2shtype\":5,\"wiftype\":128,\"txfee\":10000}, {\"coin\":\"BTA\",\"name\":\"bata\",\"rpcport\":5493,\"pubtype\":25,\"p2shtype\":5,\"wiftype\":188,\"txfee\":100000}, {\"coin\":\"SMC\",\"name\":\"smartcoin\",\"rpcport\":58583,\"pubtype\":63,\"p2shtype\":5,\"wiftype\":191,\"txfee\":1000000}, {\"coin\":\"NMC\",\"name\":\"namecoin\",\"rpcport\":8336,\"pubtype\":52,\"p2shtype\":13,\"wiftype\":180,\"txfee\":100000}, {\"coin\":\"NAV\",\"name\":\"navcoin\",\"isPoS\":1,\"confpath\":\"${HOME#}/.navcoin4/navcoin.conf\",\"rpcport\":44444,\"pubtype\":53,\"p2shtype\":85,\"wiftype\":150,\"txfee\":10000}, {\"coin\":\"EMC2\",\"name\":\"einsteinium\",\"rpcport\":41879,\"pubtype\":33,\"p2shtype\":5,\"wiftype\":176,\"txfee\":100000},{\"coin\":\"SYS\",\"name\":\"syscoin\",\"rpcport\":8370,\"pubtype\":0,\"p2shtype\":5,\"wiftype\":128,\"txfee\":10000}, {\"coin\":\"I0C\",\"name\":\"i0coin\",\"rpcport\":7332,\"pubtype\":105,\"p2shtype\":5,\"wiftype\":128,\"txfee\":10000}, {\"coin\":\"DASH\",\"confpath\":\"${HOME#}/.dashcore/dash.conf\",\"name\":\"dashcore\",\"rpcport\":9998,\"pubtype\":76,\"p2shtype\":16,\"wiftype\":204,\"txfee\":10000}, {\"coin\":\"STRAT\", \"name\": \"stratis\", \"active\":0, \"rpcport\":16174,\"pubtype\":63, \"p2shtype\":125, \"wiftype\":191, \"txfee\":10000}, {\"confpath\":\"${HOME#}/.muecore/mue.conf\",\"coin\":\"MUE\",\"name\":\"muecore\",\"rpcport\":29683,\"pubtype\":16,\"p2shtype\":76,\"wiftype\":126,\"txfee\":10000}, {\"coin\":\"MONA\",\"name\":\"monacoin\",\"rpcport\":9402,\"pubtype\":50,\"p2shtype\":5,\"wiftype\":176,\"txfee\":100000},{\"coin\":\"XMY\",\"name\":\"myriadcoin\",\"rpcport\":10889,\"pubtype\":50,\"p2shtype\":9,\"wiftype\":178,\"txfee\":5000}, {\"coin\":\"MAC\",\"name\":\"machinecoin\",\"rpcport\":40332,\"pubtype\":50,\"p2shtype\":5,\"wiftype\":178,\"txfee\":100000}, {\"coin\":\"BTX\",\"name\":\"bitcore\",\"rpcport\":8556,\"pubtype\":0,\"p2shtype\":5,\"wiftype\":128,\"txfee\":50000}, {\"coin\":\"XRE\",\"name\":\"revolvercoin\",\"rpcport\":8775,\"pubtype\":0,\"p2shtype\":5,\"wiftype\":128,\"txfee\":10000}, {\"coin\":\"LBC\",\"name\":\"lbrycrd\",\"rpcport\":9245,\"pubtype\":85,\"p2shtype\":122,\"wiftype\":28,\"txfee\":10000}, {\"coin\":\"SIB\",\"name\":\"sibcoin\",\"rpcport\":1944,\"pubtype\":63,\"p2shtype\":40,\"wiftype\":128,\"txfee\":10000}, {\"coin\":\"VTC\", \"name\":\"vertcoin\", \"rpcport\":5888, \"pubtype\":71, \"p2shtype\":5, \"wiftype\":128, \"txfee\":100000 }, {\"coin\":\"REVS\",\"active\":0, \"asset\":\"REVS\",\"rpcport\":10196}, {\"coin\":\"JUMBLR\",\"active\":0, \"asset\":\"JUMBLR\",\"rpcport\":15106}, {\"coin\":\"DOGE\",\"name\":\"dogecoin\",\"rpcport\":22555,\"pubtype\":30,\"p2shtype\":22,\"wiftype\":158,\"txfee\":100000000}, {\"coin\":\"HUSH\",\"name\":\"hush\",\"rpcport\":8822,\"taddr\":28,\"pubtype\":184,\"p2shtype\":189,\"wiftype\":128,\"txfee\":1000 }, {\"active\":0,\"coin\":\"ZEC\",\"name\":\"zcash\",\"rpcport\":8232,\"taddr\":28,\"pubtype\":184,\"p2shtype\":189,\"wiftype\":128,\"txfee\":10000 }, {\"coin\":\"DGB\",\"name\":\"digibyte\",\"rpcport\":14022,\"pubtype\":30,\"p2shtype\":5,\"wiftype\":128,\"txfee\":100000}, {\"coin\":\"ZET\", \"name\":\"zetacoin\", \"pubtype\":80, \"p2shtype\":9,\"rpcport\":8332, \"wiftype\":224, \"txfee\":10000}, {\"coin\":\"GAME\", \"rpcport\":40001, \"name\":\"gamecredits\", \"pubtype\":38, \"p2shtype\":5, \"wiftype\":166, \"txfee\":100000}, {\"coin\":\"LTC\", \"name\":\"litecoin\", \"rpcport\":9332, \"pubtype\":48, \"p2shtype\":5, \"wiftype\":176, \"txfee\":100000 }, {\"coin\":\"SUPERNET\",\"asset\":\"SUPERNET\",\"rpcport\":11341}, {\"coin\":\"WLC\",\"asset\":\"WLC\",\"rpcport\":12167}, {\"coin\":\"PANGEA\",\"asset\":\"PANGEA\",\"rpcport\":14068}, {\"coin\":\"DEX\",\"asset\":\"DEX\",\"rpcport\":11890}, {\"coin\":\"BET\",\"asset\":\"BET\",\"rpcport\":14250}, {\"coin\":\"CRYPTO\",\"asset\":\"CRYPTO\",\"rpcport\":8516}, {\"coin\":\"HODL\",\"asset\":\"HODL\",\"rpcport\":14431}, {\"coin\":\"MSHARK\",\"asset\":\"MSHARK\",\"rpcport\":8846}, {\"coin\":\"BOTS\",\"asset\":\"BOTS\",\"rpcport\":11964}, {\"coin\":\"MGW\",\"asset\":\"MGW\",\"rpcport\":12386}, {\"coin\":\"COQUI\",\"asset\":\"COQUI\",\"rpcport\":14276}, {\"coin\":\"KV\",\"asset\":\"KV\",\"rpcport\":8299}, {\"coin\":\"CEAL\",\"asset\":\"CEAL\",\"rpcport\":11116}, {\"coin\":\"MESH\",\"asset\":\"MESH\",\"rpcport\":9455}]" +export coins="[{\"coin\":\"ZOI\",\"name\":\"zoin\",\"rpcport\":8255,\"pubtype\":80,\"p2shtype\":7,\"wiftype\":208,\"txfee\":1000}, {\"coin\": \"PIZZA\",\"asset\": \"PIZZA\",\"rpcport\": 11116},{\"coin\": \"BEER\",\"asset\": \"BEER\",\"rpcport\": 8923}, {\"coin\":\"GRS\",\"name\":\"groestlcoin\",\"rpcport\":1441,\"pubtype\":36,\"p2shtype\":5,\"wiftype\":128,\"txfee\":10000}, {\"coin\":\"XMCC\",\"name\":\"monoeci\",\"confpath\":\"${HOME#}/.monoeciCore/monoeci.conf\",\"rpcport\":24156,\"pubtype\":50,\"p2shtype\":73,\"wiftype\":77,\"txfee\":10000}, {\"coin\":\"BTCH\",\"asset\":\"BTCH\",\"rpcport\":8800},{\"coin\":\"ETOMIC\",\"asset\":\"ETOMIC\",\"rpcport\":10271},{\"coin\":\"AXO\",\"asset\":\"AXO\",\"rpcport\":12927},{\"coin\":\"CRC\",\"name\":\"crowdcoin\",\"confpath\":\"${HOME#}/.crowdcoincore/crowdcoin.conf\",\"rpcport\":11998,\"pubtype\":28,\"p2shtype\":88,\"wiftype\":0,\"txfee\":10000}, {\"coin\":\"VOT\",\"name\":\"votecoin\",\"rpcport\":8232,\"taddr\":28,\"pubtype\":184,\"p2shtype\":189,\"wiftype\":128,\"txfee\":10000}, {\"coin\":\"INN\",\"name\":\"innova\",\"confpath\":\"${HOME#}/.innovacore/innova.conf\",\"rpcport\":8818,\"pubtype\":102,\"p2shtype\":20,\"wiftype\":195,\"txfee\":10000}, {\"coin\":\"MOON\",\"name\":\"mooncoin\",\"rpcport\":44663,\"pubtype\":3,\"p2shtype\":22,\"wiftype\":131,\"txfee\":100000}, {\"coin\":\"CRW\",\"name\":\"crown\",\"rpcport\":9341,\"pubtype\":0,\"p2shtype\":28,\"wiftype\":128,\"txfee\":10000}, {\"coin\":\"EFL\",\"name\":\"egulden\",\"confpath\":\"${HOME#}/.egulden/coin.conf\",\"rpcport\":21015,\"pubtype\":48,\"p2shtype\":5,\"wiftype\":176,\"txfee\":100000}, {\"coin\":\"GBX\",\"name\":\"gobyte\",\"confpath\":\"${HOME#}/.gobytecore/gobyte.conf\",\"rpcport\":12454,\"pubtype\":38,\"p2shtype\":10,\"wiftype\":198,\"txfee\":10000}, {\"coin\":\"BCO\",\"name\":\"bridgecoin\",\"rpcport\":6332,\"pubtype\":27,\"p2shtype\":5,\"wiftype\":176,\"txfee\":100000}, {\"coin\":\"BLK\",\"name\":\"blackcoin\",\"confpath\":\"${HOME#}/.lore/blackcoin.conf\",\"isPoS\":1,\"rpcport\":15715,\"pubtype\":25,\"p2shtype\":85,\"wiftype\":153,\"txfee\":100000}, {\"coin\":\"BTG\",\"name\":\"bitcoingold\",\"rpcport\":8332,\"pubtype\":38,\"p2shtype\":23,\"wiftype\":128,\"txfee\":10000}, {\"coin\":\"BCH\",\"name\":\"bch\",\"rpcport\":33333,\"pubtype\":0,\"p2shtype\":5,\"wiftype\":128,\"txfee\":1000}, {\"coin\":\"ABY\",\"name\":\"applebyte\",\"rpcport\":8607,\"pubtype\":23,\"p2shtype\":5,\"wiftype\":151,\"txfee\":100000}, {\"coin\":\"STAK\",\"name\":\"straks\",\"rpcport\":7574,\"pubtype\":63,\"p2shtype\":5,\"wiftype\":204,\"txfee\":10000}, {\"coin\":\"XZC\",\"name\":\"zcoin\",\"rpcport\":8888,\"pubtype\":82,\"p2shtype\":7,\"wiftype\":210,\"txfee\":10000}, {\"coin\":\"QTUM\",\"name\":\"qtum\",\"rpcport\":3889,\"pubtype\":58,\"p2shtype\":50,\"wiftype\":128,\"txfee\":400000}, {\"coin\":\"PURA\",\"name\":\"pura\",\"rpcport\":55555,\"pubtype\":55,\"p2shtype\":16,\"wiftype\":150,\"txfee\":10000}, {\"coin\":\"DSR\",\"name\":\"desire\",\"confpath\":\"${HOME#}/.desirecore/desire.conf\",\"rpcport\":9918,\"pubtype\":30,\"p2shtype\":16,\"wiftype\":204,\"txfee\":10000}, {\"coin\":\"MNZ\",\"asset\":\"MNZ\",\"rpcport\":14337},{\"coin\":\"BTCZ\",\"name\":\"bitcoinz\",\"rpcport\":1979,\"taddr\":28,\"pubtype\":184,\"p2shtype\":189,\"wiftype\":128,\"txfee\":10000}, {\"coin\":\"MAGA\",\"name\":\"magacoin\",\"rpcport\":5332,\"pubtype\":23,\"p2shtype\":50,\"wiftype\":176,\"txfee\":100000}, {\"coin\":\"BSD\",\"name\":\"bitsend\",\"rpcport\":8800,\"pubtype\":102,\"p2shtype\":5,\"wiftype\":204,\"txfee\":10000}, {\"coin\":\"IOP\",\"name\":\"IoP\",\"rpcport\":8337,\"pubtype\":117,\"p2shtype\":174,\"wiftype\":49,\"txfee\":10000}, {\"coin\":\"BLOCK\",\"name\":\"blocknetdx\",\"rpcport\":41414,\"pubtype\":26,\"p2shtype\":28,\"wiftype\":154,\"txfee\":10000}, {\"coin\":\"CHIPS\", \"name\": \"chips\", \"rpcport\":57776,\"pubtype\":60, \"p2shtype\":85, \"wiftype\":188, \"txfee\":10000}, {\"coin\":\"888\",\"name\":\"octocoin\",\"rpcport\":22888,\"pubtype\":18,\"p2shtype\":5,\"wiftype\":176,\"txfee\":2000000}, {\"coin\":\"ARG\",\"name\":\"argentum\",\"rpcport\":13581,\"pubtype\":23,\"p2shtype\":5,\"wiftype\":151,\"txfee\":50000}, {\"coin\":\"GLT\",\"name\":\"globaltoken\",\"rpcport\":9320,\"pubtype\":38,\"p2shtype\":5,\"wiftype\":166,\"txfee\":10000}, {\"coin\":\"ZER\",\"name\":\"zero\",\"rpcport\":23801,\"taddr\":28,\"pubtype\":184,\"p2shtype\":189,\"wiftype\":128,\"txfee\":1000}, {\"coin\":\"HODLC\",\"name\":\"hodlcoin\",\"rpcport\":11989,\"pubtype\":40,\"p2shtype\":5,\"wiftype\":168,\"txfee\":5000}, {\"coin\":\"UIS\",\"name\":\"unitus\",\"rpcport\":50604,\"pubtype\":68,\"p2shtype\":10,\"wiftype\":132,\"txfee\":2000000}, {\"coin\":\"HUC\",\"name\":\"huntercoin\",\"rpcport\":8399,\"pubtype\":40,\"p2shtype\":13,\"wiftype\":168,\"txfee\":100000}, {\"coin\":\"BDL\",\"name\":\"bitdeal\",\"rpcport\":9332,\"pubtype\":38,\"p2shtype\":5,\"wiftype\":176,\"txfee\":100000}, {\"coin\":\"ARC\",\"name\":\"arcticcoin\",\"confpath\":\"${HOME#}/.arcticcore/arcticcoin.conf\",\"rpcport\":7208,\"pubtype\":23,\"p2shtype\":8,\"wiftype\":176,\"txfee\":10000}, {\"coin\":\"ZCL\",\"name\":\"zclassic\",\"rpcport\":8023,\"taddr\":28,\"pubtype\":184,\"p2shtype\":189,\"wiftype\":128,\"txfee\":1000}, {\"coin\":\"VIA\",\"name\":\"viacoin\",\"rpcport\":5222,\"pubtype\":71,\"p2shtype\":33,\"wiftype\":199,\"txfee\":100000}, {\"coin\":\"ERC\",\"name\":\"europecoin\",\"rpcport\":11989,\"pubtype\":33,\"p2shtype\":5,\"wiftype\":168,\"txfee\":10000},{\"coin\":\"FAIR\",\"name\":\"faircoin\",\"confpath\":\"${HOME#}/.faircoin2/faircoin.conf\",\"rpcport\":40405,\"pubtype\":95,\"p2shtype\":36,\"wiftype\":223,\"txfee\":1000000}, {\"coin\":\"FLO\",\"name\":\"florincoin\",\"rpcport\":7313,\"pubtype\":35,\"p2shtype\":8,\"wiftype\":176,\"txfee\":100000}, {\"coin\":\"SXC\",\"name\":\"sexcoin\",\"rpcport\":9561,\"pubtype\":62,\"p2shtype\":5,\"wiftype\":190,\"txfee\":100000}, {\"coin\":\"CREA\",\"name\":\"creativecoin\",\"rpcport\":17711,\"pubtype\":28,\"p2shtype\":5,\"wiftype\":176,\"txfee\":100000}, {\"coin\":\"TRC\",\"name\":\"terracoin\",\"confpath\":\"${HOME#}/.terracoincore/terracoin.conf\",\"rpcport\":13332,\"pubtype\":0,\"p2shtype\":5,\"wiftype\":128,\"txfee\":10000}, {\"coin\":\"BTA\",\"name\":\"bata\",\"rpcport\":5493,\"pubtype\":25,\"p2shtype\":5,\"wiftype\":188,\"txfee\":100000}, {\"coin\":\"SMC\",\"name\":\"smartcoin\",\"rpcport\":58583,\"pubtype\":63,\"p2shtype\":5,\"wiftype\":191,\"txfee\":1000000}, {\"coin\":\"NMC\",\"name\":\"namecoin\",\"rpcport\":8336,\"pubtype\":52,\"p2shtype\":13,\"wiftype\":180,\"txfee\":100000}, {\"coin\":\"NAV\",\"name\":\"navcoin\",\"isPoS\":1,\"confpath\":\"${HOME#}/.navcoin4/navcoin.conf\",\"rpcport\":44444,\"pubtype\":53,\"p2shtype\":85,\"wiftype\":150,\"txfee\":10000}, {\"coin\":\"EMC2\",\"name\":\"einsteinium\",\"rpcport\":41879,\"pubtype\":33,\"p2shtype\":5,\"wiftype\":176,\"txfee\":100000},{\"coin\":\"SYS\",\"name\":\"syscoin\",\"rpcport\":8370,\"pubtype\":0,\"p2shtype\":5,\"wiftype\":128,\"txfee\":10000}, {\"coin\":\"I0C\",\"name\":\"i0coin\",\"rpcport\":7332,\"pubtype\":105,\"p2shtype\":5,\"wiftype\":128,\"txfee\":10000}, {\"coin\":\"DASH\",\"confpath\":\"${HOME#}/.dashcore/dash.conf\",\"name\":\"dashcore\",\"rpcport\":9998,\"pubtype\":76,\"p2shtype\":16,\"wiftype\":204,\"txfee\":10000}, {\"coin\":\"STRAT\", \"name\": \"stratis\", \"active\":0, \"rpcport\":16174,\"pubtype\":63, \"p2shtype\":125, \"wiftype\":191, \"txfee\":10000}, {\"confpath\":\"${HOME#}/.muecore/mue.conf\",\"coin\":\"MUE\",\"name\":\"muecore\",\"rpcport\":29683,\"pubtype\":16,\"p2shtype\":76,\"wiftype\":126,\"txfee\":10000}, {\"coin\":\"MONA\",\"name\":\"monacoin\",\"rpcport\":9402,\"pubtype\":50,\"p2shtype\":5,\"wiftype\":176,\"txfee\":100000},{\"coin\":\"XMY\",\"name\":\"myriadcoin\",\"rpcport\":10889,\"pubtype\":50,\"p2shtype\":9,\"wiftype\":178,\"txfee\":5000}, {\"coin\":\"MAC\",\"name\":\"machinecoin\",\"rpcport\":40332,\"pubtype\":50,\"p2shtype\":5,\"wiftype\":178,\"txfee\":100000}, {\"coin\":\"BTX\",\"name\":\"bitcore\",\"rpcport\":8556,\"pubtype\":0,\"p2shtype\":5,\"wiftype\":128,\"txfee\":50000}, {\"coin\":\"XRE\",\"name\":\"revolvercoin\",\"rpcport\":8775,\"pubtype\":0,\"p2shtype\":5,\"wiftype\":128,\"txfee\":10000}, {\"coin\":\"LBC\",\"name\":\"lbrycrd\",\"rpcport\":9245,\"pubtype\":85,\"p2shtype\":122,\"wiftype\":28,\"txfee\":10000}, {\"coin\":\"SIB\",\"name\":\"sibcoin\",\"rpcport\":1944,\"pubtype\":63,\"p2shtype\":40,\"wiftype\":128,\"txfee\":10000}, {\"coin\":\"VTC\", \"name\":\"vertcoin\", \"rpcport\":5888, \"pubtype\":71, \"p2shtype\":5, \"wiftype\":128, \"txfee\":100000 }, {\"coin\":\"REVS\",\"active\":0, \"asset\":\"REVS\",\"rpcport\":10196}, {\"coin\":\"JUMBLR\",\"active\":0, \"asset\":\"JUMBLR\",\"rpcport\":15106}, {\"coin\":\"DOGE\",\"name\":\"dogecoin\",\"rpcport\":22555,\"pubtype\":30,\"p2shtype\":22,\"wiftype\":158,\"txfee\":100000000}, {\"coin\":\"HUSH\",\"name\":\"hush\",\"rpcport\":8822,\"taddr\":28,\"pubtype\":184,\"p2shtype\":189,\"wiftype\":128,\"txfee\":1000 }, {\"active\":0,\"coin\":\"ZEC\",\"name\":\"zcash\",\"rpcport\":8232,\"taddr\":28,\"pubtype\":184,\"p2shtype\":189,\"wiftype\":128,\"txfee\":10000 }, {\"coin\":\"DGB\",\"name\":\"digibyte\",\"rpcport\":14022,\"pubtype\":30,\"p2shtype\":5,\"wiftype\":128,\"txfee\":100000}, {\"coin\":\"ZET\", \"name\":\"zetacoin\", \"pubtype\":80, \"p2shtype\":9,\"rpcport\":8332, \"wiftype\":224, \"txfee\":10000}, {\"coin\":\"GAME\", \"rpcport\":40001, \"name\":\"gamecredits\", \"pubtype\":38, \"p2shtype\":5, \"wiftype\":166, \"txfee\":100000}, {\"coin\":\"LTC\", \"name\":\"litecoin\", \"rpcport\":9332, \"pubtype\":48, \"p2shtype\":5, \"wiftype\":176, \"txfee\":100000 }, {\"coin\":\"SUPERNET\",\"asset\":\"SUPERNET\",\"rpcport\":11341}, {\"coin\":\"WLC\",\"asset\":\"WLC\",\"rpcport\":12167}, {\"coin\":\"PANGEA\",\"asset\":\"PANGEA\",\"rpcport\":14068}, {\"coin\":\"DEX\",\"asset\":\"DEX\",\"rpcport\":11890}, {\"coin\":\"BET\",\"asset\":\"BET\",\"rpcport\":14250}, {\"coin\":\"CRYPTO\",\"asset\":\"CRYPTO\",\"rpcport\":8516}, {\"coin\":\"HODL\",\"asset\":\"HODL\",\"rpcport\":14431}, {\"coin\":\"MSHARK\",\"asset\":\"MSHARK\",\"rpcport\":8846}, {\"coin\":\"BOTS\",\"asset\":\"BOTS\",\"rpcport\":11964}, {\"coin\":\"MGW\",\"asset\":\"MGW\",\"rpcport\":12386}, {\"coin\":\"COQUI\",\"asset\":\"COQUI\",\"rpcport\":14276}, {\"coin\":\"KV\",\"asset\":\"KV\",\"rpcport\":8299}, {\"coin\":\"CEAL\",\"asset\":\"CEAL\",\"rpcport\":11116}, {\"coin\":\"MESH\",\"asset\":\"MESH\",\"rpcport\":9455}]" #, {\"coin\":\"AUD\",\"asset\":\"AUD\",\"rpcport\":8045}, {\"coin\":\"BGN\",\"asset\":\"BGN\",\"rpcport\":9110}, {\"coin\":\"CAD\",\"asset\":\"CAD\",\"rpcport\":8720}, {\"coin\":\"CHF\",\"asset\":\"CHF\",\"rpcport\":15312}, {\"coin\":\"CNY\",\"asset\":\"CNY\",\"rpcport\":10384}, {\"coin\":\"CZK\",\"asset\":\"CZK\",\"rpcport\":9482}, {\"coin\":\"DKK\",\"asset\":\"DKK\",\"rpcport\":13830}, {\"coin\":\"EUR\",\"asset\":\"EUR\",\"rpcport\":8065}, {\"coin\":\"GBP\",\"asset\":\"GBP\",\"rpcport\":11505}, {\"coin\":\"HKD\",\"asset\":\"HKD\",\"rpcport\":15409}, {\"coin\":\"HRK\",\"asset\":\"HRK\",\"rpcport\":12617}, {\"coin\":\"HUF\",\"asset\":\"HUF\",\"rpcport\":13699}, {\"coin\":\"IDR\",\"asset\":\"IDR\",\"rpcport\":14459}, {\"coin\":\"ILS\",\"asset\":\"ILS\",\"rpcport\":14638}, {\"coin\":\"INR\",\"asset\":\"INR\",\"rpcport\":10536}, {\"coin\":\"JPY\",\"asset\":\"JPY\",\"rpcport\":13145}, {\"coin\":\"KRW\",\"asset\":\"KRW\",\"rpcport\":14020}, {\"coin\":\"MXN\",\"asset\":\"MXN\",\"rpcport\":13970}, {\"coin\":\"MYR\",\"asset\":\"MYR\",\"rpcport\":10688}, {\"coin\":\"NOK\",\"asset\":\"NOK\",\"rpcport\":11588}, {\"coin\":\"NZD\",\"asset\":\"NZD\",\"rpcport\":10915}, {\"coin\":\"PHP\",\"asset\":\"PHP\",\"rpcport\":11181}, {\"coin\":\"PLN\",\"asset\":\"PLN\",\"rpcport\":13493}, {\"coin\":\"BRL\",\"asset\":\"BRL\",\"rpcport\":9914}, {\"coin\":\"RON\",\"asset\":\"RON\",\"rpcport\":8675}, {\"coin\":\"RUB\",\"asset\":\"RUB\",\"rpcport\":8199}, {\"coin\":\"SEK\",\"asset\":\"SEK\",\"rpcport\":11447}, {\"coin\":\"SGD\",\"asset\":\"SGD\",\"rpcport\":14475}, {\"coin\":\"THB\",\"asset\":\"THB\",\"rpcport\":11847}, {\"coin\":\"TRY\",\"asset\":\"TRY\",\"rpcport\":13924}, {\"coin\":\"USD\",\"asset\":\"USD\",\"rpcport\":13967}, {\"coin\":\"ZAR\",\"asset\":\"ZAR\",\"rpcport\":15160}]" #{\"coin\":\"PIVX\",\"name\":\"pivx\",\"rpcport\":51473,\"pubtype\":30,\"p2shtype\":13,\"wiftype\":212,\"txfee\":10000}, From 32252a0d7b987e0afbe2c18a67d06615c621811d Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 28 Jan 2018 00:39:35 +0400 Subject: [PATCH 145/183] Test without command mutex --- iguana/exchanges/LP_nativeDEX.c | 8 ++++---- iguana/exchanges/stats.c | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 8383c5a9f..580527519 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -250,7 +250,7 @@ char *LP_process_message(void *ctx,char *typestr,char *myipaddr,int32_t pubsock, if ( duplicate != 0 ) dup++; else uniq++; - portable_mutex_lock(&LP_commandmutex); + //portable_mutex_lock(&LP_commandmutex); if ( (LP_rand() % 100000) == 0 ) printf("%s dup.%d (%u / %u) %.1f%% encrypted.%d recv.%u [%02x %02x] vs %02x %02x\n",typestr,duplicate,dup,dup+uniq,(double)100*dup/(dup+uniq),encrypted,crc32,ptr[0],ptr[1],crc32&0xff,(crc32>>8)&0xff); if ( duplicate == 0 ) @@ -340,7 +340,7 @@ char *LP_process_message(void *ctx,char *typestr,char *myipaddr,int32_t pubsock, free_json(argjson); } } //else printf("DUPLICATE.(%s)\n",(char *)ptr); - portable_mutex_unlock(&LP_commandmutex); + //portable_mutex_unlock(&LP_commandmutex); if ( jsonstr != 0 && (void *)jsonstr != (void *)ptr && encrypted == 0 ) free(jsonstr); return(retstr); @@ -414,13 +414,13 @@ int32_t LP_sock_check(char *typestr,void *ctx,char *myipaddr,int32_t pubsock,int Broadcaststr = 0; if ( (argjson= cJSON_Parse(str)) != 0 ) { - portable_mutex_lock(&LP_commandmutex); + //portable_mutex_lock(&LP_commandmutex); if ( LP_tradecommand(ctx,myipaddr,pubsock,argjson,0,0) <= 0 ) { if ( (retstr= stats_JSON(ctx,myipaddr,pubsock,argjson,remoteaddr,0)) != 0 ) free(retstr); } - portable_mutex_unlock(&LP_commandmutex); + //portable_mutex_unlock(&LP_commandmutex); free_json(argjson); } free(str); diff --git a/iguana/exchanges/stats.c b/iguana/exchanges/stats.c index c1fdbe2ff..922e4606e 100644 --- a/iguana/exchanges/stats.c +++ b/iguana/exchanges/stats.c @@ -683,9 +683,9 @@ void LP_rpc_processreq(void *_ptr) if ( recvlen > 0 ) { jsonflag = postflag = 0; - portable_mutex_lock(&LP_commandmutex); + //portable_mutex_lock(&LP_commandmutex); retstr = stats_rpcparse(space,size,&jsonflag,&postflag,jsonbuf,remoteaddr,filetype,req->port); - portable_mutex_unlock(&LP_commandmutex); + //portable_mutex_unlock(&LP_commandmutex); if ( filetype[0] != 0 ) { static cJSON *mimejson; char *tmp,*typestr=0; long tmpsize; From 905fbc636af41b6e1a8578e5577566a1c533b211 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 28 Jan 2018 13:27:49 +0400 Subject: [PATCH 146/183] Test --- iguana/exchanges/LP_NXT.c | 4 ++-- iguana/exchanges/LP_include.h | 2 +- iguana/exchanges/LP_nativeDEX.c | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/iguana/exchanges/LP_NXT.c b/iguana/exchanges/LP_NXT.c index 81ab96131..3813df1b7 100644 --- a/iguana/exchanges/LP_NXT.c +++ b/iguana/exchanges/LP_NXT.c @@ -210,7 +210,7 @@ cJSON *LP_NXT_redeems() char *account = "NXT-MRBN-8DFH-PFMK-A4DBM"; memset(totals,0,sizeof(totals)); sprintf(url,"http://127.0.0.1:7876/nxt?requestType=getBlockchainTransactions&account=%s",account); - //printf("calling (%s)\n",url); + printf("calling (%s)\n",url); if ( (retstr= issue_curlt(url,LP_HTTP_TIMEOUT)) != 0 ) { if ( (retjson= cJSON_Parse(retstr)) != 0 ) @@ -226,7 +226,7 @@ cJSON *LP_NXT_redeems() txnum = j64bits(item,"transaction"); if ( txnum == txnum_marker ) past_marker = 1; - //printf("%d: %s\n",i,jprint(item,0)); + printf("%d: %s\n",i,jprint(item,0)); if ( (recv= jstr(item,"recipientRS")) != 0 && strcmp(recv,"NXT-MRBN-8DFH-PFMK-A4DBM") == 0 ) { if ( (attach= jobj(item,"attachment")) != 0 && jint(attach,"version.AssetTransfer") == 1 ) diff --git a/iguana/exchanges/LP_include.h b/iguana/exchanges/LP_include.h index a9eb886cf..eeff1ee7a 100644 --- a/iguana/exchanges/LP_include.h +++ b/iguana/exchanges/LP_include.h @@ -416,7 +416,7 @@ struct LP_swapstats uint64_t aliceid; int32_t bobneeds_dPoW,aliceneeds_dPoW; uint32_t ind,methodind,finished,expired,lasttime,dPoWfinished; - char alicegui[32],bobgui[32]; + char alicegui[65],bobgui[65]; }; struct LP_pubswap { struct LP_pubswap *next,*prev; struct LP_swapstats *swap; }; diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 580527519..bbd63c7a4 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -117,7 +117,7 @@ struct LP_globals uint8_t LP_myrmd160[20],LP_pubsecp[33]; uint32_t LP_sessionid,counter; int32_t LP_IAMLP,LP_pendingswaps,USERPASS_COUNTER,LP_numprivkeys,initializing,waiting,LP_numskips; - char seednode[64],USERPASS[65],USERPASS_WIFSTR[64],LP_myrmd160str[41],gui[16],LP_NXTaddr[64]; + char seednode[64],USERPASS[65],USERPASS_WIFSTR[64],LP_myrmd160str[41],gui[65],LP_NXTaddr[64]; struct LP_privkey LP_privkeys[100]; } G; @@ -136,7 +136,7 @@ uint32_t LP_rand() char *activecoins[] = { "BTC", "KMD" }; char GLOBAL_DBDIR[] = { "DB" }; char LP_myipaddr[64],USERHOME[512] = { "/root" }; -char LP_gui[16] = { "cli" }; +char LP_gui[65] = { "cli" }; char *default_LPnodes[] = { "5.9.253.195", "173.212.225.176", "136.243.45.140", "23.254.202.142", "45.32.19.196" //"24.54.206.138", "107.72.162.127", "72.50.16.86", "51.15.202.191", "173.228.198.88", From 72f5757560a2c3e5017df82f99d3659999ce7b7b Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 28 Jan 2018 13:29:44 +0400 Subject: [PATCH 147/183] Test --- iguana/exchanges/LP_NXT.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_NXT.c b/iguana/exchanges/LP_NXT.c index 3813df1b7..d981a9fc1 100644 --- a/iguana/exchanges/LP_NXT.c +++ b/iguana/exchanges/LP_NXT.c @@ -213,6 +213,7 @@ cJSON *LP_NXT_redeems() printf("calling (%s)\n",url); if ( (retstr= issue_curlt(url,LP_HTTP_TIMEOUT)) != 0 ) { + printf("got.(%s)\n",retstr); if ( (retjson= cJSON_Parse(retstr)) != 0 ) { if ( (array= jarray(&numtx,retjson,"transactions")) != 0 ) @@ -226,7 +227,7 @@ cJSON *LP_NXT_redeems() txnum = j64bits(item,"transaction"); if ( txnum == txnum_marker ) past_marker = 1; - printf("%d: %s\n",i,jprint(item,0)); + //printf("%d: %s\n",i,jprint(item,0)); if ( (recv= jstr(item,"recipientRS")) != 0 && strcmp(recv,"NXT-MRBN-8DFH-PFMK-A4DBM") == 0 ) { if ( (attach= jobj(item,"attachment")) != 0 && jint(attach,"version.AssetTransfer") == 1 ) @@ -298,7 +299,7 @@ cJSON *LP_NXT_redeems() //free_json(retjson); } free(retstr); - } + } else printf("null return from NXT api call\n"); printf("\nTotal redeemed.%d\n",numtx); for (past_marker=0; past_marker<2; past_marker++) { From 6f8bc26ce09ec76579c93516738b885340d09ff2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 28 Jan 2018 15:38:03 +0400 Subject: [PATCH 148/183] Merged latest cJSON --- crypto777/cJSON.c | 3384 +++++++++++++++++++++++++++++++++++++-------- includes/cJSON.h | 283 ++-- 2 files changed, 3033 insertions(+), 634 deletions(-) diff --git a/crypto777/cJSON.c b/crypto777/cJSON.c index 54df964f5..b78c290cd 100755 --- a/crypto777/cJSON.c +++ b/crypto777/cJSON.c @@ -1,17 +1,14 @@ /* - Copyright (c) 2009 Dave Gamble - + Copyright (c) 2009-2017 Dave Gamble and cJSON contributors Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -23,15 +20,51 @@ /* cJSON */ /* JSON parser in C. */ + +/* disable warnings about old C89 functions in MSVC */ +#if !defined(_CRT_SECURE_NO_DEPRECATE) && defined(_MSC_VER) +#define _CRT_SECURE_NO_DEPRECATE +#endif + +#ifdef __GNUC__ +#pragma GCC visibility push(default) +#endif +#if defined(_MSC_VER) +#pragma warning (push) +/* disable warning about single line comments in system headers */ +#pragma warning (disable : 4001) +#endif + +#include +#include #include +#include +#include +#include +#include -#include "../includes/cJSON.h" +#ifdef ENABLE_LOCALES +#include +#endif -#ifndef DBL_EPSILON -#define DBL_EPSILON 2.2204460492503131E-16 +#if defined(_MSC_VER) +#pragma warning (pop) +#endif +#ifdef __GNUC__ +#pragma GCC visibility pop #endif -static const char *ep; +#include "cJSON.h" + +/* define our own boolean type */ +#define true ((cJSON_bool)1) +#define false ((cJSON_bool)0) + +typedef struct { + const unsigned char *json; + size_t position; +} error; +static error global_error = { NULL, 0 }; long stripquotes(char *str) { @@ -45,626 +78,2867 @@ long stripquotes(char *str) return(offset); } -const char *cJSON_GetErrorPtr(void) {return ep;} - -static int32_t cJSON_strcasecmp(const char *s1,const char *s2) +CJSON_PUBLIC(const char *) cJSON_GetErrorPtr(void) +{ + return (const char*) (global_error.json + global_error.position); +} + +CJSON_PUBLIC(char *) cJSON_GetStringValue(cJSON *item) { + if (!cJSON_IsString(item)) { + return NULL; + } + + return item->valuestring; +} + +/* This is a safeguard to prevent copy-pasters from using incompatible C and header files */ +#if (CJSON_VERSION_MAJOR != 1) || (CJSON_VERSION_MINOR != 7) || (CJSON_VERSION_PATCH != 1) +#error cJSON.h and cJSON.c have different versions. Make sure that both have the same. +#endif + +CJSON_PUBLIC(const char*) cJSON_Version(void) +{ + static char version[15]; + sprintf(version, "%i.%i.%i", CJSON_VERSION_MAJOR, CJSON_VERSION_MINOR, CJSON_VERSION_PATCH); + + return version; +} + +/* Case insensitive string comparison, doesn't consider two NULL pointers equal though */ +static int case_insensitive_strcmp(const unsigned char *string1, const unsigned char *string2) +{ + if ((string1 == NULL) || (string2 == NULL)) + { + return 1; + } + + if (string1 == string2) + { + return 0; + } + + for(; tolower(*string1) == tolower(*string2); (void)string1++, string2++) + { + if (*string1 == '\0') + { + return 0; + } + } + + return tolower(*string1) - tolower(*string2); +} + +typedef struct internal_hooks +{ + void *(*allocate)(size_t size); + void (*deallocate)(void *pointer); + void *(*reallocate)(void *pointer, size_t size); +} internal_hooks; + +#if defined(_MSC_VER) +/* work around MSVC error C2322: '...' address of dillimport '...' is not static */ +static void *internal_malloc(size_t size) +{ + return malloc(size); +} +static void internal_free(void *pointer) +{ + free(pointer); +} +static void *internal_realloc(void *pointer, size_t size) +{ + return realloc(pointer, size); +} +#else +#define internal_malloc malloc +#define internal_free free +#define internal_realloc realloc +#endif + +static internal_hooks global_hooks = { internal_malloc, internal_free, internal_realloc }; + +static unsigned char* cJSON_strdup(const unsigned char* string, const internal_hooks * const hooks) +{ + size_t length = 0; + unsigned char *copy = NULL; + + if (string == NULL) + { + return NULL; + } + + length = strlen((const char*)string) + sizeof(""); + copy = (unsigned char*)hooks->allocate(length); + if (copy == NULL) + { + return NULL; + } + memcpy(copy, string, length); + + return copy; +} + +CJSON_PUBLIC(void) cJSON_InitHooks(cJSON_Hooks* hooks) +{ + if (hooks == NULL) + { + /* Reset hooks */ + global_hooks.allocate = malloc; + global_hooks.deallocate = free; + global_hooks.reallocate = realloc; + return; + } + + global_hooks.allocate = malloc; + if (hooks->malloc_fn != NULL) + { + global_hooks.allocate = hooks->malloc_fn; + } + + global_hooks.deallocate = free; + if (hooks->free_fn != NULL) + { + global_hooks.deallocate = hooks->free_fn; + } + + /* use realloc only if both free and malloc are used */ + global_hooks.reallocate = NULL; + if ((global_hooks.allocate == malloc) && (global_hooks.deallocate == free)) + { + global_hooks.reallocate = realloc; + } +} + +/* Internal constructor. */ +static cJSON *cJSON_New_Item(const internal_hooks * const hooks) +{ + cJSON* node = (cJSON*)hooks->allocate(sizeof(cJSON)); + if (node) + { + memset(node, '\0', sizeof(cJSON)); + } + + return node; +} + +/* Delete a cJSON structure. */ +CJSON_PUBLIC(void) cJSON_Delete(cJSON *item) +{ + cJSON *next = NULL; + while (item != NULL) + { + next = item->next; + if (!(item->type & cJSON_IsReference) && (item->child != NULL)) + { + cJSON_Delete(item->child); + } + if (!(item->type & cJSON_IsReference) && (item->valuestring != NULL)) + { + global_hooks.deallocate(item->valuestring); + } + if (!(item->type & cJSON_StringIsConst) && (item->string != NULL)) + { + global_hooks.deallocate(item->string); + } + global_hooks.deallocate(item); + item = next; + } +} + +/* get the decimal point character of the current locale */ +static unsigned char get_decimal_point(void) +{ +#ifdef ENABLE_LOCALES + struct lconv *lconv = localeconv(); + return (unsigned char) lconv->decimal_point[0]; +#else + return '.'; +#endif +} + +typedef struct +{ + const unsigned char *content; + size_t length; + size_t offset; + size_t depth; /* How deeply nested (in arrays/objects) is the input at the current offset. */ + internal_hooks hooks; +} parse_buffer; + +/* check if the given size is left to read in a given parse buffer (starting with 1) */ +#define can_read(buffer, size) ((buffer != NULL) && (((buffer)->offset + size) <= (buffer)->length)) +/* check if the buffer can be accessed at the given index (starting with 0) */ +#define can_access_at_index(buffer, index) ((buffer != NULL) && (((buffer)->offset + index) < (buffer)->length)) +#define cannot_access_at_index(buffer, index) (!can_access_at_index(buffer, index)) +/* get a pointer to the buffer at the position */ +#define buffer_at_offset(buffer) ((buffer)->content + (buffer)->offset) + +/* Parse the input text to generate a number, and populate the result into item. */ +static cJSON_bool parse_number(cJSON * const item, parse_buffer * const input_buffer) +{ + double number = 0; + unsigned char *after_end = NULL; + unsigned char number_c_string[64]; + unsigned char decimal_point = get_decimal_point(); + size_t i = 0; + + if ((input_buffer == NULL) || (input_buffer->content == NULL)) + { + return false; + } + + /* copy the number into a temporary buffer and replace '.' with the decimal point + * of the current locale (for strtod) + * This also takes care of '\0' not necessarily being available for marking the end of the input */ + for (i = 0; (i < (sizeof(number_c_string) - 1)) && can_access_at_index(input_buffer, i); i++) + { + switch (buffer_at_offset(input_buffer)[i]) + { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + case '+': + case '-': + case 'e': + case 'E': + number_c_string[i] = buffer_at_offset(input_buffer)[i]; + break; + + case '.': + number_c_string[i] = decimal_point; + break; + + default: + goto loop_end; + } + } +loop_end: + number_c_string[i] = '\0'; + + number = strtod((const char*)number_c_string, (char**)&after_end); + if (number_c_string == after_end) + { + return false; /* parse_error */ + } + + item->valuedouble = number; + + /* use saturation in case of overflow */ + if (number >= INT_MAX) + { + item->valueint = INT_MAX; + } + else if (number <= INT_MIN) + { + item->valueint = INT_MIN; + } + else + { + item->valueint = (int)number; + } + + item->type = cJSON_Number; + + input_buffer->offset += (size_t)(after_end - number_c_string); + return true; +} + +/* don't ask me, but the original cJSON_SetNumberValue returns an integer or double */ +CJSON_PUBLIC(double) cJSON_SetNumberHelper(cJSON *object, double number) +{ + if (number >= INT_MAX) + { + object->valueint = INT_MAX; + } + else if (number <= INT_MIN) + { + object->valueint = INT_MIN; + } + else + { + object->valueint = (int)number; + } + + return object->valuedouble = number; +} + +typedef struct +{ + unsigned char *buffer; + size_t length; + size_t offset; + size_t depth; /* current nesting depth (for formatted printing) */ + cJSON_bool noalloc; + cJSON_bool format; /* is this print a formatted print */ + internal_hooks hooks; +} printbuffer; + +/* realloc printbuffer if necessary to have at least "needed" bytes more */ +static unsigned char* ensure(printbuffer * const p, size_t needed) +{ + unsigned char *newbuffer = NULL; + size_t newsize = 0; + + if ((p == NULL) || (p->buffer == NULL)) + { + return NULL; + } + + if ((p->length > 0) && (p->offset >= p->length)) + { + /* make sure that offset is valid */ + return NULL; + } + + if (needed > INT_MAX) + { + /* sizes bigger than INT_MAX are currently not supported */ + return NULL; + } + + needed += p->offset + 1; + if (needed <= p->length) + { + return p->buffer + p->offset; + } + + if (p->noalloc) { + return NULL; + } + + /* calculate new buffer size */ + if (needed > (INT_MAX / 2)) + { + /* overflow of int, use INT_MAX if possible */ + if (needed <= INT_MAX) + { + newsize = INT_MAX; + } + else + { + return NULL; + } + } + else + { + newsize = needed * 2; + } + + if (p->hooks.reallocate != NULL) + { + /* reallocate with realloc if available */ + newbuffer = (unsigned char*)p->hooks.reallocate(p->buffer, newsize); + if (newbuffer == NULL) + { + p->hooks.deallocate(p->buffer); + p->length = 0; + p->buffer = NULL; + + return NULL; + } + } + else + { + /* otherwise reallocate manually */ + newbuffer = (unsigned char*)p->hooks.allocate(newsize); + if (!newbuffer) + { + p->hooks.deallocate(p->buffer); + p->length = 0; + p->buffer = NULL; + + return NULL; + } + if (newbuffer) + { + memcpy(newbuffer, p->buffer, p->offset + 1); + } + p->hooks.deallocate(p->buffer); + } + p->length = newsize; + p->buffer = newbuffer; + + return newbuffer + p->offset; +} + +/* calculate the new length of the string in a printbuffer and update the offset */ +static void update_offset(printbuffer * const buffer) +{ + const unsigned char *buffer_pointer = NULL; + if ((buffer == NULL) || (buffer->buffer == NULL)) + { + return; + } + buffer_pointer = buffer->buffer + buffer->offset; + + buffer->offset += strlen((const char*)buffer_pointer); +} + +/* Render the number nicely from the given item into a string. */ +static cJSON_bool print_number(const cJSON * const item, printbuffer * const output_buffer) +{ + unsigned char *output_pointer = NULL; + double d = item->valuedouble; + int length = 0; + size_t i = 0; + unsigned char number_buffer[26]; /* temporary buffer to print the number into */ + unsigned char decimal_point = get_decimal_point(); + double test; + + if (output_buffer == NULL) + { + return false; + } + + /* This checks for NaN and Infinity */ + if ((d * 0) != 0) + { + length = sprintf((char*)number_buffer, "null"); + } + else + { + /* Try 15 decimal places of precision to avoid nonsignificant nonzero digits */ + length = sprintf((char*)number_buffer, "%1.15g", d); + + /* Check whether the original double can be recovered */ + if ((sscanf((char*)number_buffer, "%lg", &test) != 1) || ((double)test != d)) + { + /* If not, print with 17 decimal places of precision */ + length = sprintf((char*)number_buffer, "%1.17g", d); + } + } + + /* sprintf failed or buffer overrun occured */ + if ((length < 0) || (length > (int)(sizeof(number_buffer) - 1))) + { + return false; + } + + /* reserve appropriate space in the output */ + output_pointer = ensure(output_buffer, (size_t)length + sizeof("")); + if (output_pointer == NULL) + { + return false; + } + + /* copy the printed number to the output and replace locale + * dependent decimal point with '.' */ + for (i = 0; i < ((size_t)length); i++) + { + if (number_buffer[i] == decimal_point) + { + output_pointer[i] = '.'; + continue; + } + + output_pointer[i] = number_buffer[i]; + } + output_pointer[i] = '\0'; + + output_buffer->offset += (size_t)length; + + return true; +} + +/* parse 4 digit hexadecimal number */ +static unsigned parse_hex4(const unsigned char * const input) +{ + unsigned int h = 0; + size_t i = 0; + + for (i = 0; i < 4; i++) + { + /* parse digit */ + if ((input[i] >= '0') && (input[i] <= '9')) + { + h += (unsigned int) input[i] - '0'; + } + else if ((input[i] >= 'A') && (input[i] <= 'F')) + { + h += (unsigned int) 10 + input[i] - 'A'; + } + else if ((input[i] >= 'a') && (input[i] <= 'f')) + { + h += (unsigned int) 10 + input[i] - 'a'; + } + else /* invalid */ + { + return 0; + } + + if (i < 3) + { + /* shift left to make place for the next nibble */ + h = h << 4; + } + } + + return h; +} + +/* converts a UTF-16 literal to UTF-8 + * A literal can be one or two sequences of the form \uXXXX */ +static unsigned char utf16_literal_to_utf8(const unsigned char * const input_pointer, const unsigned char * const input_end, unsigned char **output_pointer) +{ + long unsigned int codepoint = 0; + unsigned int first_code = 0; + const unsigned char *first_sequence = input_pointer; + unsigned char utf8_length = 0; + unsigned char utf8_position = 0; + unsigned char sequence_length = 0; + unsigned char first_byte_mark = 0; + + if ((input_end - first_sequence) < 6) + { + /* input ends unexpectedly */ + goto fail; + } + + /* get the first utf16 sequence */ + first_code = parse_hex4(first_sequence + 2); + + /* check that the code is valid */ + if (((first_code >= 0xDC00) && (first_code <= 0xDFFF))) + { + goto fail; + } + + /* UTF16 surrogate pair */ + if ((first_code >= 0xD800) && (first_code <= 0xDBFF)) + { + const unsigned char *second_sequence = first_sequence + 6; + unsigned int second_code = 0; + sequence_length = 12; /* \uXXXX\uXXXX */ + + if ((input_end - second_sequence) < 6) + { + /* input ends unexpectedly */ + goto fail; + } + + if ((second_sequence[0] != '\\') || (second_sequence[1] != 'u')) + { + /* missing second half of the surrogate pair */ + goto fail; + } + + /* get the second utf16 sequence */ + second_code = parse_hex4(second_sequence + 2); + /* check that the code is valid */ + if ((second_code < 0xDC00) || (second_code > 0xDFFF)) + { + /* invalid second half of the surrogate pair */ + goto fail; + } + + + /* calculate the unicode codepoint from the surrogate pair */ + codepoint = 0x10000 + (((first_code & 0x3FF) << 10) | (second_code & 0x3FF)); + } + else + { + sequence_length = 6; /* \uXXXX */ + codepoint = first_code; + } + + /* encode as UTF-8 + * takes at maximum 4 bytes to encode: + * 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx */ + if (codepoint < 0x80) + { + /* normal ascii, encoding 0xxxxxxx */ + utf8_length = 1; + } + else if (codepoint < 0x800) + { + /* two bytes, encoding 110xxxxx 10xxxxxx */ + utf8_length = 2; + first_byte_mark = 0xC0; /* 11000000 */ + } + else if (codepoint < 0x10000) + { + /* three bytes, encoding 1110xxxx 10xxxxxx 10xxxxxx */ + utf8_length = 3; + first_byte_mark = 0xE0; /* 11100000 */ + } + else if (codepoint <= 0x10FFFF) + { + /* four bytes, encoding 1110xxxx 10xxxxxx 10xxxxxx 10xxxxxx */ + utf8_length = 4; + first_byte_mark = 0xF0; /* 11110000 */ + } + else + { + /* invalid unicode codepoint */ + goto fail; + } + + /* encode as utf8 */ + for (utf8_position = (unsigned char)(utf8_length - 1); utf8_position > 0; utf8_position--) + { + /* 10xxxxxx */ + (*output_pointer)[utf8_position] = (unsigned char)((codepoint | 0x80) & 0xBF); + codepoint >>= 6; + } + /* encode first byte */ + if (utf8_length > 1) + { + (*output_pointer)[0] = (unsigned char)((codepoint | first_byte_mark) & 0xFF); + } + else + { + (*output_pointer)[0] = (unsigned char)(codepoint & 0x7F); + } + + *output_pointer += utf8_length; + + return sequence_length; + +fail: + return 0; +} + +/* Parse the input text into an unescaped cinput, and populate item. */ +static cJSON_bool parse_string(cJSON * const item, parse_buffer * const input_buffer) +{ + const unsigned char *input_pointer = buffer_at_offset(input_buffer) + 1; + const unsigned char *input_end = buffer_at_offset(input_buffer) + 1; + unsigned char *output_pointer = NULL; + unsigned char *output = NULL; + + /* not a string */ + if (buffer_at_offset(input_buffer)[0] != '\"') + { + goto fail; + } + + { + /* calculate approximate size of the output (overestimate) */ + size_t allocation_length = 0; + size_t skipped_bytes = 0; + while (((size_t)(input_end - input_buffer->content) < input_buffer->length) && (*input_end != '\"')) + { + /* is escape sequence */ + if (input_end[0] == '\\') + { + if ((size_t)(input_end + 1 - input_buffer->content) >= input_buffer->length) + { + /* prevent buffer overflow when last input character is a backslash */ + goto fail; + } + skipped_bytes++; + input_end++; + } + input_end++; + } + if (((size_t)(input_end - input_buffer->content) >= input_buffer->length) || (*input_end != '\"')) + { + goto fail; /* string ended unexpectedly */ + } + + /* This is at most how much we need for the output */ + allocation_length = (size_t) (input_end - buffer_at_offset(input_buffer)) - skipped_bytes; + output = (unsigned char*)input_buffer->hooks.allocate(allocation_length + sizeof("")); + if (output == NULL) + { + goto fail; /* allocation failure */ + } + } + + output_pointer = output; + /* loop through the string literal */ + while (input_pointer < input_end) + { + if (*input_pointer != '\\') + { + *output_pointer++ = *input_pointer++; + } + /* escape sequence */ + else + { + unsigned char sequence_length = 2; + if ((input_end - input_pointer) < 1) + { + goto fail; + } + + switch (input_pointer[1]) + { + case 'b': + *output_pointer++ = '\b'; + break; + case 'f': + *output_pointer++ = '\f'; + break; + case 'n': + *output_pointer++ = '\n'; + break; + case 'r': + *output_pointer++ = '\r'; + break; + case 't': + *output_pointer++ = '\t'; + break; + case '\"': + case '\\': + case '/': + *output_pointer++ = input_pointer[1]; + break; + + /* UTF-16 literal */ + case 'u': + sequence_length = utf16_literal_to_utf8(input_pointer, input_end, &output_pointer); + if (sequence_length == 0) + { + /* failed to convert UTF16-literal to UTF-8 */ + goto fail; + } + break; + + default: + goto fail; + } + input_pointer += sequence_length; + } + } + + /* zero terminate the output */ + *output_pointer = '\0'; + + item->type = cJSON_String; + item->valuestring = (char*)output; + + input_buffer->offset = (size_t) (input_end - input_buffer->content); + input_buffer->offset++; + + return true; + +fail: + if (output != NULL) + { + input_buffer->hooks.deallocate(output); + } + + if (input_pointer != NULL) + { + input_buffer->offset = (size_t)(input_pointer - input_buffer->content); + } + + return false; +} + +/* Render the cstring provided to an escaped version that can be printed. */ +static cJSON_bool print_string_ptr(const unsigned char * const input, printbuffer * const output_buffer) +{ + const unsigned char *input_pointer = NULL; + unsigned char *output = NULL; + unsigned char *output_pointer = NULL; + size_t output_length = 0; + /* numbers of additional characters needed for escaping */ + size_t escape_characters = 0; + + if (output_buffer == NULL) + { + return false; + } + + /* empty string */ + if (input == NULL) + { + output = ensure(output_buffer, sizeof("\"\"")); + if (output == NULL) + { + return false; + } + strcpy((char*)output, "\"\""); + + return true; + } + + /* set "flag" to 1 if something needs to be escaped */ + for (input_pointer = input; *input_pointer; input_pointer++) + { + switch (*input_pointer) + { + case '\"': + case '\\': + case '\b': + case '\f': + case '\n': + case '\r': + case '\t': + /* one character escape sequence */ + escape_characters++; + break; + default: + if (*input_pointer < 32) + { + /* UTF-16 escape sequence uXXXX */ + escape_characters += 5; + } + break; + } + } + output_length = (size_t)(input_pointer - input) + escape_characters; + + output = ensure(output_buffer, output_length + sizeof("\"\"")); + if (output == NULL) + { + return false; + } + + /* no characters have to be escaped */ + if (escape_characters == 0) + { + output[0] = '\"'; + memcpy(output + 1, input, output_length); + output[output_length + 1] = '\"'; + output[output_length + 2] = '\0'; + + return true; + } + + output[0] = '\"'; + output_pointer = output + 1; + /* copy the string */ + for (input_pointer = input; *input_pointer != '\0'; (void)input_pointer++, output_pointer++) + { + if ((*input_pointer > 31) && (*input_pointer != '\"') && (*input_pointer != '\\')) + { + /* normal character, copy */ + *output_pointer = *input_pointer; + } + else + { + /* character needs to be escaped */ + *output_pointer++ = '\\'; + switch (*input_pointer) + { + case '\\': + *output_pointer = '\\'; + break; + case '\"': + *output_pointer = '\"'; + break; + case '\b': + *output_pointer = 'b'; + break; + case '\f': + *output_pointer = 'f'; + break; + case '\n': + *output_pointer = 'n'; + break; + case '\r': + *output_pointer = 'r'; + break; + case '\t': + *output_pointer = 't'; + break; + default: + /* escape and print as unicode codepoint */ + sprintf((char*)output_pointer, "u%04x", *input_pointer); + output_pointer += 4; + break; + } + } + } + output[output_length + 1] = '\"'; + output[output_length + 2] = '\0'; + + return true; +} + +/* Invoke print_string_ptr (which is useful) on an item. */ +static cJSON_bool print_string(const cJSON * const item, printbuffer * const p) +{ + return print_string_ptr((unsigned char*)item->valuestring, p); +} + +/* Predeclare these prototypes. */ +static cJSON_bool parse_value(cJSON * const item, parse_buffer * const input_buffer); +static cJSON_bool print_value(const cJSON * const item, printbuffer * const output_buffer); +static cJSON_bool parse_array(cJSON * const item, parse_buffer * const input_buffer); +static cJSON_bool print_array(const cJSON * const item, printbuffer * const output_buffer); +static cJSON_bool parse_object(cJSON * const item, parse_buffer * const input_buffer); +static cJSON_bool print_object(const cJSON * const item, printbuffer * const output_buffer); + +/* Utility to jump whitespace and cr/lf */ +static parse_buffer *buffer_skip_whitespace(parse_buffer * const buffer) +{ + if ((buffer == NULL) || (buffer->content == NULL)) + { + return NULL; + } + + while (can_access_at_index(buffer, 0) && (buffer_at_offset(buffer)[0] <= 32)) + { + buffer->offset++; + } + + if (buffer->offset == buffer->length) + { + buffer->offset--; + } + + return buffer; +} + +/* skip the UTF-8 BOM (byte order mark) if it is at the beginning of a buffer */ +static parse_buffer *skip_utf8_bom(parse_buffer * const buffer) +{ + if ((buffer == NULL) || (buffer->content == NULL) || (buffer->offset != 0)) + { + return NULL; + } + + if (can_access_at_index(buffer, 4) && (strncmp((const char*)buffer_at_offset(buffer), "\xEF\xBB\xBF", 3) == 0)) + { + buffer->offset += 3; + } + + return buffer; +} + +/* Parse an object - create a new root, and populate. */ +CJSON_PUBLIC(cJSON *) cJSON_ParseWithOpts(const char *value, const char **return_parse_end, cJSON_bool require_null_terminated) +{ + parse_buffer buffer = { 0, 0, 0, 0, { 0, 0, 0 } }; + cJSON *item = NULL; + + /* reset error position */ + global_error.json = NULL; + global_error.position = 0; + + if (value == NULL) + { + goto fail; + } + + buffer.content = (const unsigned char*)value; + buffer.length = strlen((const char*)value) + sizeof(""); + buffer.offset = 0; + buffer.hooks = global_hooks; + + item = cJSON_New_Item(&global_hooks); + if (item == NULL) /* memory fail */ + { + goto fail; + } + + if (!parse_value(item, buffer_skip_whitespace(skip_utf8_bom(&buffer)))) + { + /* parse failure. ep is set. */ + goto fail; + } + + /* if we require null-terminated JSON without appended garbage, skip and then check for a null terminator */ + if (require_null_terminated) + { + buffer_skip_whitespace(&buffer); + if ((buffer.offset >= buffer.length) || buffer_at_offset(&buffer)[0] != '\0') + { + goto fail; + } + } + if (return_parse_end) + { + *return_parse_end = (const char*)buffer_at_offset(&buffer); + } + + return item; + +fail: + if (item != NULL) + { + cJSON_Delete(item); + } + + if (value != NULL) + { + error local_error; + local_error.json = (const unsigned char*)value; + local_error.position = 0; + + if (buffer.offset < buffer.length) + { + local_error.position = buffer.offset; + } + else if (buffer.length > 0) + { + local_error.position = buffer.length - 1; + } + + if (return_parse_end != NULL) + { + *return_parse_end = (const char*)local_error.json + local_error.position; + } + + global_error = local_error; + } + + return NULL; +} + +/* Default options for cJSON_Parse */ +CJSON_PUBLIC(cJSON *) cJSON_Parse(const char *value) +{ + return cJSON_ParseWithOpts(value, 0, 0); +} + +#define cjson_min(a, b) ((a < b) ? a : b) + +static unsigned char *print(const cJSON * const item, cJSON_bool format, const internal_hooks * const hooks) +{ + static const size_t default_buffer_size = 256; + printbuffer buffer[1]; + unsigned char *printed = NULL; + + memset(buffer, 0, sizeof(buffer)); + + /* create buffer */ + buffer->buffer = (unsigned char*) hooks->allocate(default_buffer_size); + buffer->length = default_buffer_size; + buffer->format = format; + buffer->hooks = *hooks; + if (buffer->buffer == NULL) + { + goto fail; + } + + /* print the value */ + if (!print_value(item, buffer)) + { + goto fail; + } + update_offset(buffer); + + /* check if reallocate is available */ + if (hooks->reallocate != NULL) + { + printed = (unsigned char*) hooks->reallocate(buffer->buffer, buffer->offset + 1); + buffer->buffer = NULL; + if (printed == NULL) { + goto fail; + } + } + else /* otherwise copy the JSON over to a new buffer */ + { + printed = (unsigned char*) hooks->allocate(buffer->offset + 1); + if (printed == NULL) + { + goto fail; + } + memcpy(printed, buffer->buffer, cjson_min(buffer->length, buffer->offset + 1)); + printed[buffer->offset] = '\0'; /* just to be sure */ + + /* free the buffer */ + hooks->deallocate(buffer->buffer); + } + + return printed; + +fail: + if (buffer->buffer != NULL) + { + hooks->deallocate(buffer->buffer); + } + + if (printed != NULL) + { + hooks->deallocate(printed); + } + + return NULL; +} + +/* Render a cJSON item/entity/structure to text. */ +CJSON_PUBLIC(char *) cJSON_Print(const cJSON *item) +{ + return (char*)print(item, true, &global_hooks); +} + +CJSON_PUBLIC(char *) cJSON_PrintUnformatted(const cJSON *item) +{ + return (char*)print(item, false, &global_hooks); +} + +CJSON_PUBLIC(char *) cJSON_PrintBuffered(const cJSON *item, int prebuffer, cJSON_bool fmt) +{ + printbuffer p = { 0, 0, 0, 0, 0, 0, { 0, 0, 0 } }; + + if (prebuffer < 0) + { + return NULL; + } + + p.buffer = (unsigned char*)global_hooks.allocate((size_t)prebuffer); + if (!p.buffer) + { + return NULL; + } + + p.length = (size_t)prebuffer; + p.offset = 0; + p.noalloc = false; + p.format = fmt; + p.hooks = global_hooks; + + if (!print_value(item, &p)) + { + global_hooks.deallocate(p.buffer); + return NULL; + } + + return (char*)p.buffer; +} + +CJSON_PUBLIC(cJSON_bool) cJSON_PrintPreallocated(cJSON *item, char *buf, const int len, const cJSON_bool fmt) +{ + printbuffer p = { 0, 0, 0, 0, 0, 0, { 0, 0, 0 } }; + + if ((len < 0) || (buf == NULL)) + { + return false; + } + + p.buffer = (unsigned char*)buf; + p.length = (size_t)len; + p.offset = 0; + p.noalloc = true; + p.format = fmt; + p.hooks = global_hooks; + + return print_value(item, &p); +} + +/* Parser core - when encountering text, process appropriately. */ +static cJSON_bool parse_value(cJSON * const item, parse_buffer * const input_buffer) +{ + if ((input_buffer == NULL) || (input_buffer->content == NULL)) + { + return false; /* no input */ + } + + /* parse the different types of values */ + /* null */ + if (can_read(input_buffer, 4) && (strncmp((const char*)buffer_at_offset(input_buffer), "null", 4) == 0)) + { + item->type = cJSON_NULL; + input_buffer->offset += 4; + return true; + } + /* false */ + if (can_read(input_buffer, 5) && (strncmp((const char*)buffer_at_offset(input_buffer), "false", 5) == 0)) + { + item->type = cJSON_False; + input_buffer->offset += 5; + return true; + } + /* true */ + if (can_read(input_buffer, 4) && (strncmp((const char*)buffer_at_offset(input_buffer), "true", 4) == 0)) + { + item->type = cJSON_True; + item->valueint = 1; + input_buffer->offset += 4; + return true; + } + /* string */ + if (can_access_at_index(input_buffer, 0) && (buffer_at_offset(input_buffer)[0] == '\"')) + { + return parse_string(item, input_buffer); + } + /* number */ + if (can_access_at_index(input_buffer, 0) && ((buffer_at_offset(input_buffer)[0] == '-') || ((buffer_at_offset(input_buffer)[0] >= '0') && (buffer_at_offset(input_buffer)[0] <= '9')))) + { + return parse_number(item, input_buffer); + } + /* array */ + if (can_access_at_index(input_buffer, 0) && (buffer_at_offset(input_buffer)[0] == '[')) + { + return parse_array(item, input_buffer); + } + /* object */ + if (can_access_at_index(input_buffer, 0) && (buffer_at_offset(input_buffer)[0] == '{')) + { + return parse_object(item, input_buffer); + } + + return false; +} + +/* Render a value to text. */ +static cJSON_bool print_value(const cJSON * const item, printbuffer * const output_buffer) +{ + unsigned char *output = NULL; + + if ((item == NULL) || (output_buffer == NULL)) + { + return false; + } + + switch ((item->type) & 0xFF) + { + case cJSON_NULL: + output = ensure(output_buffer, 5); + if (output == NULL) + { + return false; + } + strcpy((char*)output, "null"); + return true; + + case cJSON_False: + output = ensure(output_buffer, 6); + if (output == NULL) + { + return false; + } + strcpy((char*)output, "false"); + return true; + + case cJSON_True: + output = ensure(output_buffer, 5); + if (output == NULL) + { + return false; + } + strcpy((char*)output, "true"); + return true; + + case cJSON_Number: + return print_number(item, output_buffer); + + case cJSON_Raw: + { + size_t raw_length = 0; + if (item->valuestring == NULL) + { + if (!output_buffer->noalloc) + { + output_buffer->hooks.deallocate(output_buffer->buffer); + } + return false; + } + + raw_length = strlen(item->valuestring) + sizeof(""); + output = ensure(output_buffer, raw_length); + if (output == NULL) + { + return false; + } + memcpy(output, item->valuestring, raw_length); + return true; + } + + case cJSON_String: + return print_string(item, output_buffer); + + case cJSON_Array: + return print_array(item, output_buffer); + + case cJSON_Object: + return print_object(item, output_buffer); + + default: + return false; + } +} + +/* Build an array from input text. */ +static cJSON_bool parse_array(cJSON * const item, parse_buffer * const input_buffer) +{ + cJSON *head = NULL; /* head of the linked list */ + cJSON *current_item = NULL; + + if (input_buffer->depth >= CJSON_NESTING_LIMIT) + { + return false; /* to deeply nested */ + } + input_buffer->depth++; + + if (buffer_at_offset(input_buffer)[0] != '[') + { + /* not an array */ + goto fail; + } + + input_buffer->offset++; + buffer_skip_whitespace(input_buffer); + if (can_access_at_index(input_buffer, 0) && (buffer_at_offset(input_buffer)[0] == ']')) + { + /* empty array */ + goto success; + } + + /* check if we skipped to the end of the buffer */ + if (cannot_access_at_index(input_buffer, 0)) + { + input_buffer->offset--; + goto fail; + } + + /* step back to character in front of the first element */ + input_buffer->offset--; + /* loop through the comma separated array elements */ + do + { + /* allocate next item */ + cJSON *new_item = cJSON_New_Item(&(input_buffer->hooks)); + if (new_item == NULL) + { + goto fail; /* allocation failure */ + } + + /* attach next item to list */ + if (head == NULL) + { + /* start the linked list */ + current_item = head = new_item; + } + else + { + /* add to the end and advance */ + current_item->next = new_item; + new_item->prev = current_item; + current_item = new_item; + } + + /* parse next value */ + input_buffer->offset++; + buffer_skip_whitespace(input_buffer); + if (!parse_value(current_item, input_buffer)) + { + goto fail; /* failed to parse value */ + } + buffer_skip_whitespace(input_buffer); + } + while (can_access_at_index(input_buffer, 0) && (buffer_at_offset(input_buffer)[0] == ',')); + + if (cannot_access_at_index(input_buffer, 0) || buffer_at_offset(input_buffer)[0] != ']') + { + goto fail; /* expected end of array */ + } + +success: + input_buffer->depth--; + + item->type = cJSON_Array; + item->child = head; + + input_buffer->offset++; + + return true; + +fail: + if (head != NULL) + { + cJSON_Delete(head); + } + + return false; +} + +/* Render an array to text */ +static cJSON_bool print_array(const cJSON * const item, printbuffer * const output_buffer) +{ + unsigned char *output_pointer = NULL; + size_t length = 0; + cJSON *current_element = item->child; + + if (output_buffer == NULL) + { + return false; + } + + /* Compose the output array. */ + /* opening square bracket */ + output_pointer = ensure(output_buffer, 1); + if (output_pointer == NULL) + { + return false; + } + + *output_pointer = '['; + output_buffer->offset++; + output_buffer->depth++; + + while (current_element != NULL) + { + if (!print_value(current_element, output_buffer)) + { + return false; + } + update_offset(output_buffer); + if (current_element->next) + { + length = (size_t) (output_buffer->format ? 2 : 1); + output_pointer = ensure(output_buffer, length + 1); + if (output_pointer == NULL) + { + return false; + } + *output_pointer++ = ','; + if(output_buffer->format) + { + *output_pointer++ = ' '; + } + *output_pointer = '\0'; + output_buffer->offset += length; + } + current_element = current_element->next; + } + + output_pointer = ensure(output_buffer, 2); + if (output_pointer == NULL) + { + return false; + } + *output_pointer++ = ']'; + *output_pointer = '\0'; + output_buffer->depth--; + + return true; +} + +/* Build an object from the text. */ +static cJSON_bool parse_object(cJSON * const item, parse_buffer * const input_buffer) +{ + cJSON *head = NULL; /* linked list head */ + cJSON *current_item = NULL; + + if (input_buffer->depth >= CJSON_NESTING_LIMIT) + { + return false; /* to deeply nested */ + } + input_buffer->depth++; + + if (cannot_access_at_index(input_buffer, 0) || (buffer_at_offset(input_buffer)[0] != '{')) + { + goto fail; /* not an object */ + } + + input_buffer->offset++; + buffer_skip_whitespace(input_buffer); + if (can_access_at_index(input_buffer, 0) && (buffer_at_offset(input_buffer)[0] == '}')) + { + goto success; /* empty object */ + } + + /* check if we skipped to the end of the buffer */ + if (cannot_access_at_index(input_buffer, 0)) + { + input_buffer->offset--; + goto fail; + } + + /* step back to character in front of the first element */ + input_buffer->offset--; + /* loop through the comma separated array elements */ + do + { + /* allocate next item */ + cJSON *new_item = cJSON_New_Item(&(input_buffer->hooks)); + if (new_item == NULL) + { + goto fail; /* allocation failure */ + } + + /* attach next item to list */ + if (head == NULL) + { + /* start the linked list */ + current_item = head = new_item; + } + else + { + /* add to the end and advance */ + current_item->next = new_item; + new_item->prev = current_item; + current_item = new_item; + } + + /* parse the name of the child */ + input_buffer->offset++; + buffer_skip_whitespace(input_buffer); + if (!parse_string(current_item, input_buffer)) + { + goto fail; /* faile to parse name */ + } + buffer_skip_whitespace(input_buffer); + + /* swap valuestring and string, because we parsed the name */ + current_item->string = current_item->valuestring; + current_item->valuestring = NULL; + + if (cannot_access_at_index(input_buffer, 0) || (buffer_at_offset(input_buffer)[0] != ':')) + { + goto fail; /* invalid object */ + } + + /* parse the value */ + input_buffer->offset++; + buffer_skip_whitespace(input_buffer); + if (!parse_value(current_item, input_buffer)) + { + goto fail; /* failed to parse value */ + } + buffer_skip_whitespace(input_buffer); + } + while (can_access_at_index(input_buffer, 0) && (buffer_at_offset(input_buffer)[0] == ',')); + + if (cannot_access_at_index(input_buffer, 0) || (buffer_at_offset(input_buffer)[0] != '}')) + { + goto fail; /* expected end of object */ + } + +success: + input_buffer->depth--; + + item->type = cJSON_Object; + item->child = head; + + input_buffer->offset++; + return true; + +fail: + if (head != NULL) + { + cJSON_Delete(head); + } + + return false; +} + +/* Render an object to text. */ +static cJSON_bool print_object(const cJSON * const item, printbuffer * const output_buffer) +{ + unsigned char *output_pointer = NULL; + size_t length = 0; + cJSON *current_item = item->child; + + if (output_buffer == NULL) + { + return false; + } + + /* Compose the output: */ + length = (size_t) (output_buffer->format ? 2 : 1); /* fmt: {\n */ + output_pointer = ensure(output_buffer, length + 1); + if (output_pointer == NULL) + { + return false; + } + + *output_pointer++ = '{'; + output_buffer->depth++; + if (output_buffer->format) + { + *output_pointer++ = '\n'; + } + output_buffer->offset += length; + + while (current_item) + { + if (output_buffer->format) + { + size_t i; + output_pointer = ensure(output_buffer, output_buffer->depth); + if (output_pointer == NULL) + { + return false; + } + for (i = 0; i < output_buffer->depth; i++) + { + *output_pointer++ = '\t'; + } + output_buffer->offset += output_buffer->depth; + } + + /* print key */ + if (!print_string_ptr((unsigned char*)current_item->string, output_buffer)) + { + return false; + } + update_offset(output_buffer); + + length = (size_t) (output_buffer->format ? 2 : 1); + output_pointer = ensure(output_buffer, length); + if (output_pointer == NULL) + { + return false; + } + *output_pointer++ = ':'; + if (output_buffer->format) + { + *output_pointer++ = '\t'; + } + output_buffer->offset += length; + + /* print value */ + if (!print_value(current_item, output_buffer)) + { + return false; + } + update_offset(output_buffer); + + /* print comma if not last */ + length = (size_t) ((output_buffer->format ? 1 : 0) + (current_item->next ? 1 : 0)); + output_pointer = ensure(output_buffer, length + 1); + if (output_pointer == NULL) + { + return false; + } + if (current_item->next) + { + *output_pointer++ = ','; + } + + if (output_buffer->format) + { + *output_pointer++ = '\n'; + } + *output_pointer = '\0'; + output_buffer->offset += length; + + current_item = current_item->next; + } + + output_pointer = ensure(output_buffer, output_buffer->format ? (output_buffer->depth + 1) : 2); + if (output_pointer == NULL) + { + return false; + } + if (output_buffer->format) + { + size_t i; + for (i = 0; i < (output_buffer->depth - 1); i++) + { + *output_pointer++ = '\t'; + } + } + *output_pointer++ = '}'; + *output_pointer = '\0'; + output_buffer->depth--; + + return true; +} + +/* Get Array size/item / object item. */ +CJSON_PUBLIC(int) cJSON_GetArraySize(const cJSON *array) +{ + cJSON *child = NULL; + size_t size = 0; + + if (array == NULL) + { + return 0; + } + + child = array->child; + + while(child != NULL) + { + size++; + child = child->next; + } + + /* FIXME: Can overflow here. Cannot be fixed without breaking the API */ + + return (int)size; +} + +static cJSON* get_array_item(const cJSON *array, size_t index) +{ + cJSON *current_child = NULL; + + if (array == NULL) + { + return NULL; + } + + current_child = array->child; + while ((current_child != NULL) && (index > 0)) + { + index--; + current_child = current_child->next; + } + + return current_child; +} + +CJSON_PUBLIC(cJSON *) cJSON_GetArrayItem(const cJSON *array, int index) +{ + if (index < 0) + { + return NULL; + } + + return get_array_item(array, (size_t)index); +} + +static cJSON *get_object_item(const cJSON * const object, const char * const name, const cJSON_bool case_sensitive) +{ + cJSON *current_element = NULL; + + if ((object == NULL) || (name == NULL)) + { + return NULL; + } + + current_element = object->child; + if (case_sensitive) + { + while ((current_element != NULL) && (strcmp(name, current_element->string) != 0)) + { + current_element = current_element->next; + } + } + else + { + while ((current_element != NULL) && (case_insensitive_strcmp((const unsigned char*)name, (const unsigned char*)(current_element->string)) != 0)) + { + current_element = current_element->next; + } + } + + return current_element; +} + +CJSON_PUBLIC(cJSON *) cJSON_GetObjectItem(const cJSON * const object, const char * const string) +{ + return get_object_item(object, string, false); +} + +CJSON_PUBLIC(cJSON *) cJSON_GetObjectItemCaseSensitive(const cJSON * const object, const char * const string) +{ + return get_object_item(object, string, true); +} + +CJSON_PUBLIC(cJSON_bool) cJSON_HasObjectItem(const cJSON *object, const char *string) +{ + return cJSON_GetObjectItem(object, string) ? 1 : 0; +} + +/* Utility for array list handling. */ +static void suffix_object(cJSON *prev, cJSON *item) +{ + prev->next = item; + item->prev = prev; +} + +/* Utility for handling references. */ +static cJSON *create_reference(const cJSON *item, const internal_hooks * const hooks) +{ + cJSON *reference = NULL; + if (item == NULL) + { + return NULL; + } + + reference = cJSON_New_Item(hooks); + if (reference == NULL) + { + return NULL; + } + + memcpy(reference, item, sizeof(cJSON)); + reference->string = NULL; + reference->type |= cJSON_IsReference; + reference->next = reference->prev = NULL; + return reference; +} + +static cJSON_bool add_item_to_array(cJSON *array, cJSON *item) +{ + cJSON *child = NULL; + + if ((item == NULL) || (array == NULL)) + { + return false; + } + + child = array->child; + + if (child == NULL) + { + /* list is empty, start new one */ + array->child = item; + } + else + { + /* append to the end */ + while (child->next) + { + child = child->next; + } + suffix_object(child, item); + } + + return true; +} + +/* Add item to array/object. */ +CJSON_PUBLIC(void) cJSON_AddItemToArray(cJSON *array, cJSON *item) +{ + add_item_to_array(array, item); +} + +#if defined(__clang__) || (defined(__GNUC__) && ((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ > 5)))) +#pragma GCC diagnostic push +#endif +#ifdef __GNUC__ +#pragma GCC diagnostic ignored "-Wcast-qual" +#endif +/* helper function to cast away const */ +static void* cast_away_const(const void* string) +{ + return (void*)string; +} +#if defined(__clang__) || (defined(__GNUC__) && ((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ > 5)))) +#pragma GCC diagnostic pop +#endif + + +static cJSON_bool add_item_to_object(cJSON * const object, const char * const string, cJSON * const item, const internal_hooks * const hooks, const cJSON_bool constant_key) +{ + if ((object == NULL) || (string == NULL) || (item == NULL)) + { + return false; + } + + if (!(item->type & cJSON_StringIsConst) && (item->string != NULL)) + { + hooks->deallocate(item->string); + } + + if (constant_key) + { + item->string = (char*)cast_away_const(string); + item->type |= cJSON_StringIsConst; + } + else + { + char *key = (char*)cJSON_strdup((const unsigned char*)string, hooks); + if (key == NULL) + { + return false; + } + + item->string = key; + item->type &= ~cJSON_StringIsConst; + } + + return add_item_to_array(object, item); +} + +CJSON_PUBLIC(void) cJSON_AddItemToObject(cJSON *object, const char *string, cJSON *item) +{ + add_item_to_object(object, string, item, &global_hooks, false); +} + +/* Add an item to an object with constant string as key */ +CJSON_PUBLIC(void) cJSON_AddItemToObjectCS(cJSON *object, const char *string, cJSON *item) +{ + add_item_to_object(object, string, item, &global_hooks, true); +} + +CJSON_PUBLIC(void) cJSON_AddItemReferenceToArray(cJSON *array, cJSON *item) +{ + if (array == NULL) + { + return; + } + + add_item_to_array(array, create_reference(item, &global_hooks)); +} + +CJSON_PUBLIC(void) cJSON_AddItemReferenceToObject(cJSON *object, const char *string, cJSON *item) +{ + if ((object == NULL) || (string == NULL)) + { + return; + } + + add_item_to_object(object, string, create_reference(item, &global_hooks), &global_hooks, false); +} + +CJSON_PUBLIC(cJSON*) cJSON_AddNullToObject(cJSON * const object, const char * const name) +{ + cJSON *null = cJSON_CreateNull(); + if (add_item_to_object(object, name, null, &global_hooks, false)) + { + return null; + } + + cJSON_Delete(null); + return NULL; +} + +CJSON_PUBLIC(cJSON*) cJSON_AddTrueToObject(cJSON * const object, const char * const name) +{ + cJSON *true_item = cJSON_CreateTrue(); + if (add_item_to_object(object, name, true_item, &global_hooks, false)) + { + return true_item; + } + + cJSON_Delete(true_item); + return NULL; +} + +CJSON_PUBLIC(cJSON*) cJSON_AddFalseToObject(cJSON * const object, const char * const name) +{ + cJSON *false_item = cJSON_CreateFalse(); + if (add_item_to_object(object, name, false_item, &global_hooks, false)) + { + return false_item; + } + + cJSON_Delete(false_item); + return NULL; +} + +CJSON_PUBLIC(cJSON*) cJSON_AddBoolToObject(cJSON * const object, const char * const name, const cJSON_bool boolean) +{ + cJSON *bool_item = cJSON_CreateBool(boolean); + if (add_item_to_object(object, name, bool_item, &global_hooks, false)) + { + return bool_item; + } + + cJSON_Delete(bool_item); + return NULL; +} + +CJSON_PUBLIC(cJSON*) cJSON_AddNumberToObject(cJSON * const object, const char * const name, const double number) +{ + cJSON *number_item = cJSON_CreateNumber(number); + if (add_item_to_object(object, name, number_item, &global_hooks, false)) + { + return number_item; + } + + cJSON_Delete(number_item); + return NULL; +} + +CJSON_PUBLIC(cJSON*) cJSON_AddStringToObject(cJSON * const object, const char * const name, const char * const string) +{ + cJSON *string_item = cJSON_CreateString(string); + if (add_item_to_object(object, name, string_item, &global_hooks, false)) + { + return string_item; + } + + cJSON_Delete(string_item); + return NULL; +} + +CJSON_PUBLIC(cJSON*) cJSON_AddRawToObject(cJSON * const object, const char * const name, const char * const raw) +{ + cJSON *raw_item = cJSON_CreateRaw(raw); + if (add_item_to_object(object, name, raw_item, &global_hooks, false)) + { + return raw_item; + } + + cJSON_Delete(raw_item); + return NULL; +} + +CJSON_PUBLIC(cJSON*) cJSON_AddObjectToObject(cJSON * const object, const char * const name) +{ + cJSON *object_item = cJSON_CreateObject(); + if (add_item_to_object(object, name, object_item, &global_hooks, false)) + { + return object_item; + } + + cJSON_Delete(object_item); + return NULL; +} + +CJSON_PUBLIC(cJSON*) cJSON_AddArrayToObject(cJSON * const object, const char * const name) +{ + cJSON *array = cJSON_CreateArray(); + if (add_item_to_object(object, name, array, &global_hooks, false)) + { + return array; + } + + cJSON_Delete(array); + return NULL; +} + +CJSON_PUBLIC(cJSON *) cJSON_DetachItemViaPointer(cJSON *parent, cJSON * const item) +{ + if ((parent == NULL) || (item == NULL)) + { + return NULL; + } + + if (item->prev != NULL) + { + /* not the first element */ + item->prev->next = item->next; + } + if (item->next != NULL) + { + /* not the last element */ + item->next->prev = item->prev; + } + + if (item == parent->child) + { + /* first element */ + parent->child = item->next; + } + /* make sure the detached item doesn't point anywhere anymore */ + item->prev = NULL; + item->next = NULL; + + return item; +} + +CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromArray(cJSON *array, int which) +{ + if (which < 0) + { + return NULL; + } + + return cJSON_DetachItemViaPointer(array, get_array_item(array, (size_t)which)); +} + +CJSON_PUBLIC(void) cJSON_DeleteItemFromArray(cJSON *array, int which) +{ + cJSON_Delete(cJSON_DetachItemFromArray(array, which)); +} + +CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromObject(cJSON *object, const char *string) +{ + cJSON *to_detach = cJSON_GetObjectItem(object, string); + + return cJSON_DetachItemViaPointer(object, to_detach); +} + +CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromObjectCaseSensitive(cJSON *object, const char *string) +{ + cJSON *to_detach = cJSON_GetObjectItemCaseSensitive(object, string); + + return cJSON_DetachItemViaPointer(object, to_detach); +} + +CJSON_PUBLIC(void) cJSON_DeleteItemFromObject(cJSON *object, const char *string) +{ + cJSON_Delete(cJSON_DetachItemFromObject(object, string)); +} + +CJSON_PUBLIC(void) cJSON_DeleteItemFromObjectCaseSensitive(cJSON *object, const char *string) +{ + cJSON_Delete(cJSON_DetachItemFromObjectCaseSensitive(object, string)); +} + +/* Replace array/object items with new ones. */ +CJSON_PUBLIC(void) cJSON_InsertItemInArray(cJSON *array, int which, cJSON *newitem) +{ + cJSON *after_inserted = NULL; + + if (which < 0) + { + return; + } + + after_inserted = get_array_item(array, (size_t)which); + if (after_inserted == NULL) + { + add_item_to_array(array, newitem); + return; + } + + newitem->next = after_inserted; + newitem->prev = after_inserted->prev; + after_inserted->prev = newitem; + if (after_inserted == array->child) + { + array->child = newitem; + } + else + { + newitem->prev->next = newitem; + } +} + +CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemViaPointer(cJSON * const parent, cJSON * const item, cJSON * replacement) +{ + if ((parent == NULL) || (replacement == NULL) || (item == NULL)) + { + return false; + } + + if (replacement == item) + { + return true; + } + + replacement->next = item->next; + replacement->prev = item->prev; + + if (replacement->next != NULL) + { + replacement->next->prev = replacement; + } + if (replacement->prev != NULL) + { + replacement->prev->next = replacement; + } + if (parent->child == item) + { + parent->child = replacement; + } + + item->next = NULL; + item->prev = NULL; + cJSON_Delete(item); + + return true; +} + +CJSON_PUBLIC(void) cJSON_ReplaceItemInArray(cJSON *array, int which, cJSON *newitem) +{ + if (which < 0) + { + return; + } + + cJSON_ReplaceItemViaPointer(array, get_array_item(array, (size_t)which), newitem); +} + +static cJSON_bool replace_item_in_object(cJSON *object, const char *string, cJSON *replacement, cJSON_bool case_sensitive) +{ + if ((replacement == NULL) || (string == NULL)) + { + return false; + } + + /* replace the name in the replacement */ + if (!(replacement->type & cJSON_StringIsConst) && (replacement->string != NULL)) + { + cJSON_free(replacement->string); + } + replacement->string = (char*)cJSON_strdup((const unsigned char*)string, &global_hooks); + replacement->type &= ~cJSON_StringIsConst; + + cJSON_ReplaceItemViaPointer(object, get_object_item(object, string, case_sensitive), replacement); + + return true; +} + +CJSON_PUBLIC(void) cJSON_ReplaceItemInObject(cJSON *object, const char *string, cJSON *newitem) +{ + replace_item_in_object(object, string, newitem, false); +} + +CJSON_PUBLIC(void) cJSON_ReplaceItemInObjectCaseSensitive(cJSON *object, const char *string, cJSON *newitem) +{ + replace_item_in_object(object, string, newitem, true); +} + +/* Create basic types: */ +CJSON_PUBLIC(cJSON *) cJSON_CreateNull(void) +{ + cJSON *item = cJSON_New_Item(&global_hooks); + if(item) + { + item->type = cJSON_NULL; + } + + return item; +} + +CJSON_PUBLIC(cJSON *) cJSON_CreateTrue(void) +{ + cJSON *item = cJSON_New_Item(&global_hooks); + if(item) + { + item->type = cJSON_True; + } + + return item; +} + +CJSON_PUBLIC(cJSON *) cJSON_CreateFalse(void) +{ + cJSON *item = cJSON_New_Item(&global_hooks); + if(item) + { + item->type = cJSON_False; + } + + return item; +} + +CJSON_PUBLIC(cJSON *) cJSON_CreateBool(cJSON_bool b) +{ + cJSON *item = cJSON_New_Item(&global_hooks); + if(item) + { + item->type = b ? cJSON_True : cJSON_False; + } + + return item; +} + +CJSON_PUBLIC(cJSON *) cJSON_CreateNumber(double num) +{ + cJSON *item = cJSON_New_Item(&global_hooks); + if(item) + { + item->type = cJSON_Number; + item->valuedouble = num; + + /* use saturation in case of overflow */ + if (num >= INT_MAX) + { + item->valueint = INT_MAX; + } + else if (num <= INT_MIN) + { + item->valueint = INT_MIN; + } + else + { + item->valueint = (int)num; + } + } + + return item; +} + +CJSON_PUBLIC(cJSON *) cJSON_CreateString(const char *string) { - if (!s1) return (s1==s2)?0:1;if (!s2) return 1; - for(; tolower((int32_t)(*s1)) == tolower((int32_t)(*s2)); ++s1, ++s2) if(*s1 == 0) return 0; - return tolower((int32_t)(*(const unsigned char *)s1)) - tolower((int32_t)(*(const unsigned char *)s2)); + cJSON *item = cJSON_New_Item(&global_hooks); + if(item) + { + item->type = cJSON_String; + item->valuestring = (char*)cJSON_strdup((const unsigned char*)string, &global_hooks); + if(!item->valuestring) + { + cJSON_Delete(item); + return NULL; + } + } + + return item; } -void *LP_alloc(uint64_t len); -void LP_free(void *ptr); -static void *(*cJSON_malloc)(size_t sz) = (void *)malloc;//LP_alloc; -static void (*cJSON_free)(void *ptr) = free;//LP_free; - -static void *cJSON_mallocstr(int32_t len) +CJSON_PUBLIC(cJSON *) cJSON_CreateStringReference(const char *string) { - return(cJSON_malloc(len)); + cJSON *item = cJSON_New_Item(&global_hooks); + if (item != NULL) + { + item->type = cJSON_String | cJSON_IsReference; + item->valuestring = (char*)cast_away_const(string); + } + + return item; } -static char **cJSON_mallocptrs(int32_t num,char **space,int32_t max) +CJSON_PUBLIC(cJSON *) cJSON_CreateObjectReference(const cJSON *child) { - if ( num < max ) - return(space); - else return(cJSON_malloc(num * sizeof(char *))); + cJSON *item = cJSON_New_Item(&global_hooks); + if (item != NULL) { + item->type = cJSON_Object | cJSON_IsReference; + item->child = (cJSON*)cast_away_const(child); + } + + return item; +} + +CJSON_PUBLIC(cJSON *) cJSON_CreateArrayReference(const cJSON *child) { + cJSON *item = cJSON_New_Item(&global_hooks); + if (item != NULL) { + item->type = cJSON_Array | cJSON_IsReference; + item->child = (cJSON*)cast_away_const(child); + } + + return item; } -static void *cJSON_mallocnode() +CJSON_PUBLIC(cJSON *) cJSON_CreateRaw(const char *raw) { - return(cJSON_malloc(sizeof(cJSON))); + cJSON *item = cJSON_New_Item(&global_hooks); + if(item) + { + item->type = cJSON_Raw; + item->valuestring = (char*)cJSON_strdup((const unsigned char*)raw, &global_hooks); + if(!item->valuestring) + { + cJSON_Delete(item); + return NULL; + } + } + + return item; } -static void cJSON_freeptrs(char **ptrs,int32_t num,char **space) +CJSON_PUBLIC(cJSON *) cJSON_CreateArray(void) { - if ( ptrs != space ) - cJSON_free(ptrs); + cJSON *item = cJSON_New_Item(&global_hooks); + if(item) + { + item->type=cJSON_Array; + } + + return item; } -static void cJSON_freestr(char *str) +CJSON_PUBLIC(cJSON *) cJSON_CreateObject(void) { - cJSON_free(str); + cJSON *item = cJSON_New_Item(&global_hooks); + if (item) + { + item->type = cJSON_Object; + } + + return item; } -static void cJSON_freenode(cJSON *item) +/* Create Arrays: */ +CJSON_PUBLIC(cJSON *) cJSON_CreateIntArray(const int *numbers, int count) { - cJSON_free(item); + size_t i = 0; + cJSON *n = NULL; + cJSON *p = NULL; + cJSON *a = NULL; + + if ((count < 0) || (numbers == NULL)) + { + return NULL; + } + + a = cJSON_CreateArray(); + for(i = 0; a && (i < (size_t)count); i++) + { + n = cJSON_CreateNumber(numbers[i]); + if (!n) + { + cJSON_Delete(a); + return NULL; + } + if(!i) + { + a->child = n; + } + else + { + suffix_object(p, n); + } + p = n; + } + + return a; } -static char* cJSON_strdup(const char* str) +CJSON_PUBLIC(cJSON *) cJSON_CreateFloatArray(const float *numbers, int count) { - size_t len; - char* copy; + size_t i = 0; + cJSON *n = NULL; + cJSON *p = NULL; + cJSON *a = NULL; - len = strlen(str) + 1; - if (!(copy = (char*)cJSON_mallocstr((int32_t)len+1))) return 0; - memcpy(copy,str,len); - return copy; + if ((count < 0) || (numbers == NULL)) + { + return NULL; + } + + a = cJSON_CreateArray(); + + for(i = 0; a && (i < (size_t)count); i++) + { + n = cJSON_CreateNumber((double)numbers[i]); + if(!n) + { + cJSON_Delete(a); + return NULL; + } + if(!i) + { + a->child = n; + } + else + { + suffix_object(p, n); + } + p = n; + } + + return a; } -void cJSON_InitHooks(cJSON_Hooks* hooks) +CJSON_PUBLIC(cJSON *) cJSON_CreateDoubleArray(const double *numbers, int count) { - if (!hooks) { /* Reset hooks */ - cJSON_malloc = malloc; - cJSON_free = free; - return; + size_t i = 0; + cJSON *n = NULL; + cJSON *p = NULL; + cJSON *a = NULL; + + if ((count < 0) || (numbers == NULL)) + { + return NULL; + } + + a = cJSON_CreateArray(); + + for(i = 0;a && (i < (size_t)count); i++) + { + n = cJSON_CreateNumber(numbers[i]); + if(!n) + { + cJSON_Delete(a); + return NULL; + } + if(!i) + { + a->child = n; + } + else + { + suffix_object(p, n); + } + p = n; } - cJSON_malloc = (hooks->malloc_fn)?hooks->malloc_fn:malloc; - cJSON_free = (hooks->free_fn)?hooks->free_fn:free; + return a; } -/* Internal constructor. */ -static cJSON *cJSON_New_Item(void) +CJSON_PUBLIC(cJSON *) cJSON_CreateStringArray(const char **strings, int count) { - cJSON* node = (cJSON*)cJSON_mallocnode(); - if (node) memset(node,0,sizeof(cJSON)); - return node; + size_t i = 0; + cJSON *n = NULL; + cJSON *p = NULL; + cJSON *a = NULL; + + if ((count < 0) || (strings == NULL)) + { + return NULL; + } + + a = cJSON_CreateArray(); + + for (i = 0; a && (i < (size_t)count); i++) + { + n = cJSON_CreateString(strings[i]); + if(!n) + { + cJSON_Delete(a); + return NULL; + } + if(!i) + { + a->child = n; + } + else + { + suffix_object(p,n); + } + p = n; + } + + return a; } -/* Delete a cJSON structure. */ -void cJSON_Delete(cJSON *c) +/* Duplication */ +CJSON_PUBLIC(cJSON *) cJSON_Duplicate(const cJSON *item, cJSON_bool recurse) { - cJSON *next; - while (c) - { - next=c->next; - if (!(c->type&cJSON_IsReference) && c->child) cJSON_Delete(c->child); - if (!(c->type&cJSON_IsReference) && c->valuestring) cJSON_freestr(c->valuestring); - if (c->string) cJSON_freestr(c->string); - cJSON_freenode(c); - c=next; - } + cJSON *newitem = NULL; + cJSON *child = NULL; + cJSON *next = NULL; + cJSON *newchild = NULL; + + /* Bail on bad ptr */ + if (!item) + { + goto fail; + } + /* Create new item */ + newitem = cJSON_New_Item(&global_hooks); + if (!newitem) + { + goto fail; + } + /* Copy over all vars */ + newitem->type = item->type & (~cJSON_IsReference); + newitem->valueint = item->valueint; + newitem->valuedouble = item->valuedouble; + if (item->valuestring) + { + newitem->valuestring = (char*)cJSON_strdup((unsigned char*)item->valuestring, &global_hooks); + if (!newitem->valuestring) + { + goto fail; + } + } + if (item->string) + { + newitem->string = (item->type&cJSON_StringIsConst) ? item->string : (char*)cJSON_strdup((unsigned char*)item->string, &global_hooks); + if (!newitem->string) + { + goto fail; + } + } + /* If non-recursive, then we're done! */ + if (!recurse) + { + return newitem; + } + /* Walk the ->next chain for the child. */ + child = item->child; + while (child != NULL) + { + newchild = cJSON_Duplicate(child, true); /* Duplicate (with recurse) each item in the ->next chain */ + if (!newchild) + { + goto fail; + } + if (next != NULL) + { + /* If newitem->child already set, then crosswire ->prev and ->next and move on */ + next->next = newchild; + newchild->prev = next; + next = newchild; + } + else + { + /* Set newitem->child and move to it */ + newitem->child = newchild; + next = newchild; + } + child = child->next; + } + + return newitem; + +fail: + if (newitem != NULL) + { + cJSON_Delete(newitem); + } + + return NULL; } -/* Parse the input text to generate a number, and populate the result into item. */ -static const char *parse_number(cJSON *item,const char *num) +CJSON_PUBLIC(void) cJSON_Minify(char *json) { - double n=0,sign=1,scale=0;int32_t subscale=0,signsubscale=1; + unsigned char *into = (unsigned char*)json; + + if (json == NULL) + { + return; + } - if (*num=='-') sign=-1,num++; /* Has sign? */ - if (*num=='0') num++; /* is zero */ - if (*num>='1' && *num<='9') do n=(n*10.0)+(*num++ -'0'); while (*num>='0' && *num<='9'); /* Number? */ - if (*num=='.' && num[1]>='0' && num[1]<='9') {num++; do n=(n*10.0)+(*num++ -'0'),scale--; while (*num>='0' && *num<='9');} /* Fractional part? */ - if (*num=='e' || *num=='E') /* Exponent? */ - { num++;if (*num=='+') num++; else if (*num=='-') signsubscale=-1,num++; /* With sign? */ - while (*num>='0' && *num<='9') subscale=(subscale*10)+(*num++ - '0'); /* Number? */ - } + while (*json) + { + if (*json == ' ') + { + json++; + } + else if (*json == '\t') + { + /* Whitespace characters. */ + json++; + } + else if (*json == '\r') + { + json++; + } + else if (*json=='\n') + { + json++; + } + else if ((*json == '/') && (json[1] == '/')) + { + /* double-slash comments, to end of line. */ + while (*json && (*json != '\n')) + { + json++; + } + } + else if ((*json == '/') && (json[1] == '*')) + { + /* multiline comments. */ + while (*json && !((*json == '*') && (json[1] == '/'))) + { + json++; + } + json += 2; + } + else if (*json == '\"') + { + /* string literals, which are \" sensitive. */ + *into++ = (unsigned char)*json++; + while (*json && (*json != '\"')) + { + if (*json == '\\') + { + *into++ = (unsigned char)*json++; + } + *into++ = (unsigned char)*json++; + } + *into++ = (unsigned char)*json++; + } + else + { + /* All other characters. */ + *into++ = (unsigned char)*json++; + } + } - n=sign*n*pow(10.0,(scale+subscale*signsubscale)); /* number = +/- number.fraction * 10^+/- exponent */ - - item->valuedouble=n; - item->valueint=(int64_t)n; - item->type=cJSON_Number; - return num; + /* and null-terminate. */ + *into = '\0'; } -/* Render the number nicely from the given item into a string. */ -static char *print_number(cJSON *item) -{ - char *str; - double d = item->valuedouble; - if ( fabs(((double)item->valueint) - d) <= DBL_EPSILON && d >= (1. - DBL_EPSILON) && d < (1LL << 62) )//d <= INT_MAX && d >= INT_MIN ) - { - str = (char *)cJSON_mallocstr(24); /* 2^64+1 can be represented in 21 chars + sign. */ - if ( str != 0 ) - sprintf(str,"%lld",(long long)item->valueint); - } - else - { - str = (char *)cJSON_mallocstr(66); /* This is a nice tradeoff. */ - if ( str != 0 ) - { - if ( fabs(floor(d) - d) <= DBL_EPSILON && fabs(d) < 1.0e60 ) - sprintf(str,"%.0f",d); - //else if (fabs(d)<1.0e-6 || fabs(d)>1.0e9) sprintf(str,"%e",d); - else - sprintf(str,"%.8f",d); - } - } - return str; -} - -static unsigned parse_hex4(const char *str) -{ - unsigned h=0; - if (*str>='0' && *str<='9') h+=(*str)-'0'; else if (*str>='A' && *str<='F') h+=10+(*str)-'A'; else if (*str>='a' && *str<='f') h+=10+(*str)-'a'; else return 0; - h=h<<4;str++; - if (*str>='0' && *str<='9') h+=(*str)-'0'; else if (*str>='A' && *str<='F') h+=10+(*str)-'A'; else if (*str>='a' && *str<='f') h+=10+(*str)-'a'; else return 0; - h=h<<4;str++; - if (*str>='0' && *str<='9') h+=(*str)-'0'; else if (*str>='A' && *str<='F') h+=10+(*str)-'A'; else if (*str>='a' && *str<='f') h+=10+(*str)-'a'; else return 0; - h=h<<4;str++; - if (*str>='0' && *str<='9') h+=(*str)-'0'; else if (*str>='A' && *str<='F') h+=10+(*str)-'A'; else if (*str>='a' && *str<='f') h+=10+(*str)-'a'; else return 0; - return h; -} - -/* Parse the input text into an unescaped cstring, and populate item. */ -static const unsigned char firstByteMark[7] = { 0x00, 0x00, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC }; -static const char *parse_string(cJSON *item,const char *str) -{ - const char *ptr=str+1;char *ptr2;char *out;int32_t len=0;unsigned uc,uc2; - if (*str!='\"') {ep=str;return 0;} /* not a string! */ - - while (*ptr!='\"' && *ptr && ++len) if (*ptr++ == '\\') ptr++; // Skip escaped quotes - - out=(char*)cJSON_mallocstr(len+2); /* This is how long we need for the string, roughly. */ - if (!out) return 0; - - ptr=str+1;ptr2=out; - while (*ptr!='\"' && *ptr) - { - if (*ptr!='\\') - { - if ( *ptr == '%' && is_hexstr((char *)&ptr[1],2) && isprint(_decode_hex((char *)&ptr[1])) != 0 ) - *ptr2++ = _decode_hex((char *)&ptr[1]), ptr += 3; - else *ptr2++ = *ptr++; - } - else - { - ptr++; - switch (*ptr) - { - case 'b': *ptr2++='\b'; break; - case 'f': *ptr2++='\f'; break; - case 'n': *ptr2++='\n'; break; - case 'r': *ptr2++='\r'; break; - case 't': *ptr2++='\t'; break; - case 'u': // transcode utf16 to utf8 - uc=parse_hex4(ptr+1);ptr+=4; // get the unicode char - - if ((uc>=0xDC00 && uc<=0xDFFF) || uc==0) break; // check for invalid - - if (uc>=0xD800 && uc<=0xDBFF) // UTF16 surrogate pairs - { - if (ptr[1]!='\\' || ptr[2]!='u') break; // missing second-half of surrogate. - uc2=parse_hex4(ptr+3);ptr+=6; - if (uc2<0xDC00 || uc2>0xDFFF) break; // invalid second-half of surrogate - uc=0x10000 + (((uc&0x3FF)<<10) | (uc2&0x3FF)); - } - - len=4;if (uc<0x80) len=1;else if (uc<0x800) len=2;else if (uc<0x10000) len=3; ptr2+=len; - - switch (len) { - case 4: *--ptr2 =((uc | 0x80) & 0xBF); uc >>= 6; - case 3: *--ptr2 =((uc | 0x80) & 0xBF); uc >>= 6; - case 2: *--ptr2 =((uc | 0x80) & 0xBF); uc >>= 6; - case 1: *--ptr2 =(uc | firstByteMark[len]); - } - ptr2+=len; - break; - default: *ptr2++=*ptr; break; - } - ptr++; - } - } - *ptr2=0; - if (*ptr=='\"') ptr++; - item->valuestring=out; - item->type=cJSON_String; - return ptr; +CJSON_PUBLIC(cJSON_bool) cJSON_IsInvalid(const cJSON * const item) +{ + if (item == NULL) + { + return false; + } + + return (item->type & 0xFF) == cJSON_Invalid; } -/* Render the cstring provided to an escaped version that can be printed. */ -static char *print_string_ptr(const char *str) -{ - const char *ptr;char *ptr2,*out;int32_t len=0;unsigned char token; - - if (!str) return cJSON_strdup(""); - ptr=str;while ((token=*ptr) && ++len) {if (strchr("\"\\\b\f\n\r\t",token)) len++; else if (token<32) len+=5;ptr++;} - - out=(char*)cJSON_mallocstr(len+3+1); - if (!out) return 0; - - ptr2=out;ptr=str; - *ptr2++='\"'; - while (*ptr) - { - if ((unsigned char)*ptr>31 && *ptr!='\"' && *ptr!='\\') *ptr2++=*ptr++; - else - { - *ptr2++='\\'; - switch (token=*ptr++) - { - case '\\': *ptr2++='\\'; break; - case '\"': *ptr2++='\"'; break; - case '\b': *ptr2++='b'; break; - case '\f': *ptr2++='f'; break; - case '\n': *ptr2++='n'; break; - case '\r': *ptr2++='r'; break; - case '\t': *ptr2++='t'; break; - default: sprintf(ptr2,"u%04x",token);ptr2+=5; break; /* escape and print */ - } - } - } - *ptr2++='\"';*ptr2++=0; - return out; -} -/* Invote print_string_ptr (which is useful) on an item. */ -static char *print_string(cJSON *item) {return print_string_ptr(item->valuestring);} +CJSON_PUBLIC(cJSON_bool) cJSON_IsFalse(const cJSON * const item) +{ + if (item == NULL) + { + return false; + } + + return (item->type & 0xFF) == cJSON_False; +} -/* Predeclare these prototypes. */ -static const char *parse_value(cJSON *item,const char *value); -static char *print_value(cJSON *item,int32_t depth,int32_t fmt); -static const char *parse_array(cJSON *item,const char *value); -static char *print_array(cJSON *item,int32_t depth,int32_t fmt); -static const char *parse_object(cJSON *item,const char *value); -static char *print_object(cJSON *item,int32_t depth,int32_t fmt); +CJSON_PUBLIC(cJSON_bool) cJSON_IsTrue(const cJSON * const item) +{ + if (item == NULL) + { + return false; + } + + return (item->type & 0xff) == cJSON_True; +} -/* Utility to jump whitespace and cr/lf */ -static const char *skip(const char *in) {while (in && *in && (unsigned char)*in<=32) in++; return in;} -/* Parse an object - create a new root, and populate. */ -cJSON *cJSON_ParseWithOpts(const char *value,const char **return_parse_end,int32_t require_null_terminated) +CJSON_PUBLIC(cJSON_bool) cJSON_IsBool(const cJSON * const item) { - const char *end=0; - cJSON *c=cJSON_New_Item(); - ep=0; - if (!c) return 0; /* memory fail */ - - end=parse_value(c,skip(value)); - if (!end) {cJSON_Delete(c);return 0;} /* parse failure. ep is set. */ + if (item == NULL) + { + return false; + } - /* if we require null-terminated JSON without appended garbage, skip and then check for a null terminator */ - if (require_null_terminated) {end=skip(end);if (*end) {cJSON_Delete(c);ep=end;return 0;}} - if (return_parse_end) *return_parse_end=end; - return c; + return (item->type & (cJSON_True | cJSON_False)) != 0; } -/* Default options for cJSON_Parse */ -cJSON *cJSON_Parse(const char *value) +CJSON_PUBLIC(cJSON_bool) cJSON_IsNull(const cJSON * const item) { - return(cJSON_ParseWithOpts(value,0,0)); + if (item == NULL) + { + return false; + } + + return (item->type & 0xFF) == cJSON_NULL; } -/* Render a cJSON item/entity/structure to text. */ -char *cJSON_Print(cJSON *item) +CJSON_PUBLIC(cJSON_bool) cJSON_IsNumber(const cJSON * const item) { - return(print_value(item,0,1)); + if (item == NULL) + { + return false; + } + + return (item->type & 0xFF) == cJSON_Number; } -char *cJSON_PrintUnformatted(cJSON *item) {return print_value(item,0,0);} -/* Parser core - when encountering text, process appropriately. */ -static const char *parse_value(cJSON *item,const char *value) +CJSON_PUBLIC(cJSON_bool) cJSON_IsString(const cJSON * const item) { - if (!value) return 0; /* Fail on null. */ - if (!strncmp(value,"null",4)) { item->type=cJSON_NULL; return value+4; } - if (!strncmp(value,"false",5)) { item->type=cJSON_False; return value+5; } - if (!strncmp(value,"true",4)) { item->type=cJSON_True; item->valueint=1; return value+4; } - if (*value=='\"') { return parse_string(item,value); } - if (*value=='-' || (*value>='0' && *value<='9')) { return parse_number(item,value); } - if (*value=='[') { return parse_array(item,value); } - if (*value=='{') { return parse_object(item,value); } + if (item == NULL) + { + return false; + } - ep=value;return 0; /* failure. */ -} - -/* Render a value to text. */ -static char *print_value(cJSON *item,int32_t depth,int32_t fmt) -{ - char *out=0; - if (!item) return 0; - switch ((item->type)&255) - { - case cJSON_NULL: out=cJSON_strdup("null"); break; - case cJSON_False: out=cJSON_strdup("false");break; - case cJSON_True: out=cJSON_strdup("true"); break; - case cJSON_Number: out=print_number(item);break; - case cJSON_String: out=print_string(item);break; - case cJSON_Array: out=print_array(item,depth,fmt);break; - case cJSON_Object: out=print_object(item,depth,fmt);break; - } - return out; + return (item->type & 0xFF) == cJSON_String; } -/* Build an array from input text. */ -static const char *parse_array(cJSON *item,const char *value) +CJSON_PUBLIC(cJSON_bool) cJSON_IsArray(const cJSON * const item) { - cJSON *child; - if (*value!='[') {ep=value;return 0;} /* not an array! */ - - item->type=cJSON_Array; - value=skip(value+1); - if (*value==']') return value+1; /* empty array. */ - - item->child=child=cJSON_New_Item(); - if (!item->child) return 0; /* memory fail */ - value=skip(parse_value(child,skip(value))); /* skip any spacing, get the value. */ - if (!value) return 0; - - while (*value==',') - { - cJSON *new_item; - if (!(new_item=cJSON_New_Item())) return 0; /* memory fail */ - child->next=new_item;new_item->prev=child;child=new_item; - value=skip(parse_value(child,skip(value+1))); - if (!value) return 0; /* memory fail */ - } + if (item == NULL) + { + return false; + } - if (*value==']') return value+1; /* end of array */ - ep=value;return 0; /* malformed. */ + return (item->type & 0xFF) == cJSON_Array; } -/* Render an array to text */ -static char *print_array(cJSON *item,int32_t depth,int32_t fmt) -{ - char **entries,*space_entries[512]; - char *out=0,*ptr,*ret;int32_t len=5; - cJSON *child=item->child; - int32_t numentries=0,i=0,fail=0; - - /* How many entries in the array? */ - while (child) numentries++,child=child->next; - /* Explicitly handle numentries==0 */ - if (!numentries) - { - out=(char*)cJSON_mallocstr(3+1); - if (out) strcpy(out,"[]"); - return out; - } - /* Allocate an array to hold the values for each */ - entries=cJSON_mallocptrs(1+numentries,space_entries,sizeof(space_entries)/sizeof(*space_entries)); - if (!entries) return 0; - memset(entries,0,numentries*sizeof(char*)); - /* Retrieve all the results: */ - child=item->child; - while (child && !fail) - { - ret=print_value(child,depth+1,fmt); - entries[i++]=ret; - if (ret) len+=strlen(ret)+2+(fmt?1:0); else fail=1; - child=child->next; - } - - /* If we didn't fail, try to malloc the output string */ - if (!fail) out=(char*)cJSON_mallocstr(len+1); - /* If that fails, we fail. */ - if (!out) fail=1; - - /* Handle failure. */ - if (fail) - { - for (i=0;itype & 0xFF) == cJSON_Object; } -/* Build an object from the text. */ -static const char *parse_object(cJSON *item,const char *value) -{ - cJSON *child; - if (*value!='{') {ep=value;return 0;} /* not an object! */ - - item->type=cJSON_Object; - value=skip(value+1); - if (*value=='}') return value+1; /* empty array. */ - - item->child=child=cJSON_New_Item(); - if (!item->child) return 0; - value=skip(parse_string(child,skip(value))); - if (!value) return 0; - child->string=child->valuestring;child->valuestring=0; - if (*value!=':') {ep=value;return 0;} /* fail! */ - value=skip(parse_value(child,skip(value+1))); /* skip any spacing, get the value. */ - if (!value) return 0; - - while (*value==',') - { - cJSON *new_item; - if (!(new_item=cJSON_New_Item())) return 0; /* memory fail */ - child->next=new_item;new_item->prev=child;child=new_item; - value=skip(parse_string(child,skip(value+1))); - if (!value) return 0; - child->string=child->valuestring;child->valuestring=0; - if (*value!=':') {ep=value;return 0;} /* fail! */ - value=skip(parse_value(child,skip(value+1))); /* skip any spacing, get the value. */ - if (!value) return 0; - } - - if (*value=='}') return value+1; /* end of array */ - ep=value;return 0; /* malformed. */ +CJSON_PUBLIC(cJSON_bool) cJSON_IsRaw(const cJSON * const item) +{ + if (item == NULL) + { + return false; + } + + return (item->type & 0xFF) == cJSON_Raw; } -/* Render an object to text. */ -static char *print_object(cJSON *item,int32_t depth,int32_t fmt) +CJSON_PUBLIC(cJSON_bool) cJSON_Compare(const cJSON * const a, const cJSON * const b, const cJSON_bool case_sensitive) { - char **entries=0,**names=0,*space_entries[512],*space_names[512]; - char *out=0,*ptr,*ret,*str;int32_t len=7,i=0,j; - cJSON *child=item->child,*firstchild; - int32_t numentries=0,fail=0; - // Count the number of entries - firstchild = child; - while ( child ) + if ((a == NULL) || (b == NULL) || ((a->type & 0xFF) != (b->type & 0xFF)) || cJSON_IsInvalid(a)) { - numentries++; - child = child->next; - if ( child == firstchild ) - { - printf("cJSON infinite loop detected\n"); + return false; + } + + /* check if type is valid */ + switch (a->type & 0xFF) + { + case cJSON_False: + case cJSON_True: + case cJSON_NULL: + case cJSON_Number: + case cJSON_String: + case cJSON_Raw: + case cJSON_Array: + case cJSON_Object: break; + + default: + return false; + } + + /* identical objects are equal */ + if (a == b) + { + return true; + } + + switch (a->type & 0xFF) + { + /* in these cases and equal type is enough */ + case cJSON_False: + case cJSON_True: + case cJSON_NULL: + return true; + + case cJSON_Number: + if (a->valuedouble == b->valuedouble) + { + return true; + } + return false; + + case cJSON_String: + case cJSON_Raw: + if ((a->valuestring == NULL) || (b->valuestring == NULL)) + { + return false; + } + if (strcmp(a->valuestring, b->valuestring) == 0) + { + return true; + } + + return false; + + case cJSON_Array: + { + cJSON *a_element = a->child; + cJSON *b_element = b->child; + + for (; (a_element != NULL) && (b_element != NULL);) + { + if (!cJSON_Compare(a_element, b_element, case_sensitive)) + { + return false; + } + + a_element = a_element->next; + b_element = b_element->next; + } + + /* one of the arrays is longer than the other */ + if (a_element != b_element) { + return false; + } + + return true; + } + + case cJSON_Object: + { + cJSON *a_element = NULL; + cJSON *b_element = NULL; + cJSON_ArrayForEach(a_element, a) + { + /* TODO This has O(n^2) runtime, which is horrible! */ + b_element = get_object_item(b, a_element->string, case_sensitive); + if (b_element == NULL) + { + return false; + } + + if (!cJSON_Compare(a_element, b_element, case_sensitive)) + { + return false; + } + } + + /* doing this twice, once on a and b to prevent true comparison if a subset of b + * TODO: Do this the proper way, this is just a fix for now */ + cJSON_ArrayForEach(b_element, b) + { + a_element = get_object_item(a, b_element->string, case_sensitive); + if (a_element == NULL) + { + return false; + } + + if (!cJSON_Compare(b_element, a_element, case_sensitive)) + { + return false; + } + } + + return true; } + + default: + return false; } - /* Explicitly handle empty object case */ - if (!numentries) - { - out=(char*)cJSON_mallocstr(fmt?depth+4+1:3+1); - if (!out) return 0; - ptr=out;*ptr++='{'; - if (fmt) {*ptr++='\n';for (i=0;ichild;depth++;if (fmt) len+=depth; - while ( child ) - { - names[i]=str=print_string_ptr(child->string); - entries[i++]=ret=print_value(child,depth,fmt); - if (str && ret) len+=strlen(ret)+strlen(str)+2+(fmt?2+depth:0); else fail=1; - child=child->next; - if ( child == firstchild ) - break; - } - - /* Try to allocate the output string */ - if (!fail) out=(char*)cJSON_mallocstr(len+1); - if (!out) fail=1; - - /* Handle failure */ - if (fail) - { - for (i=0;ichild;int32_t i=0;while(c)i++,c=c->next;return i;} -cJSON *cJSON_GetArrayItem(cJSON *array,int32_t item) {cJSON *c=array->child; while (c && item>0) item--,c=c->next; return c;} -cJSON *cJSON_GetObjectItem(cJSON *object,const char *string) { if ( object == 0 ) return(0); cJSON *c=object->child; while (c && cJSON_strcasecmp(c->string,string)) c=c->next; return c;} - -/* Utility for array list handling. */ -static void suffix_object(cJSON *prev,cJSON *item) {prev->next=item;item->prev=prev;} -/* Utility for handling references. */ -static cJSON *create_reference(cJSON *item) {cJSON *ref=cJSON_New_Item();if (!ref) return 0;memcpy(ref,item,sizeof(cJSON));ref->string=0;ref->type|=cJSON_IsReference;ref->next=ref->prev=0;return ref;} - -/* Add item to array/object. */ -void cJSON_AddItemToArray(cJSON *array, cJSON *item) {cJSON *c=array->child;if (!item) return; if (!c) {array->child=item;} else {while (c && c->next) c=c->next; suffix_object(c,item);}} -void cJSON_AddItemToObject(cJSON *object,const char *string,cJSON *item) {if (!item) return; if (item->string) cJSON_free(item->string);item->string=cJSON_strdup(string);cJSON_AddItemToArray(object,item);} -void cJSON_AddItemReferenceToArray(cJSON *array, cJSON *item) {cJSON_AddItemToArray(array,create_reference(item));} -void cJSON_AddItemReferenceToObject(cJSON *object,const char *string,cJSON *item) {cJSON_AddItemToObject(object,string,create_reference(item));} - -cJSON *cJSON_DetachItemFromArray(cJSON *array,int32_t which) {cJSON *c=array->child;while (c && which>0) c=c->next,which--;if (!c) return 0; - if (c->prev) c->prev->next=c->next;if (c->next) c->next->prev=c->prev;if (c==array->child) array->child=c->next;c->prev=c->next=0;return c;} -void cJSON_DeleteItemFromArray(cJSON *array,int32_t which) {cJSON_Delete(cJSON_DetachItemFromArray(array,which));} -cJSON *cJSON_DetachItemFromObject(cJSON *object,const char *string) {int32_t i=0;cJSON *c=object->child;while (c && cJSON_strcasecmp(c->string,string)) i++,c=c->next;if (c) return cJSON_DetachItemFromArray(object,i);return 0;} -void cJSON_DeleteItemFromObject(cJSON *object,const char *string) {cJSON_Delete(cJSON_DetachItemFromObject(object,string));} - -/* Replace array/object items with new ones. */ -void cJSON_ReplaceItemInArray(cJSON *array,int32_t which,cJSON *newitem) {cJSON *c=array->child;while (c && which>0) c=c->next,which--;if (!c) return; - newitem->next=c->next;newitem->prev=c->prev;if (newitem->next) newitem->next->prev=newitem; - if (c==array->child) array->child=newitem; else newitem->prev->next=newitem;c->next=c->prev=0;cJSON_Delete(c);} -void cJSON_ReplaceItemInObject(cJSON *object,const char *string,cJSON *newitem){int32_t i=0;cJSON *c=object->child;while(c && cJSON_strcasecmp(c->string,string))i++,c=c->next;if(c){newitem->string=cJSON_strdup(string);cJSON_ReplaceItemInArray(object,i,newitem);}} - -/* Create basic types: */ -cJSON *cJSON_CreateNull(void) {cJSON *item=cJSON_New_Item();if(item)item->type=cJSON_NULL;return item;} -cJSON *cJSON_CreateTrue(void) {cJSON *item=cJSON_New_Item();if(item)item->type=cJSON_True;return item;} -cJSON *cJSON_CreateFalse(void) {cJSON *item=cJSON_New_Item();if(item)item->type=cJSON_False;return item;} -cJSON *cJSON_CreateBool(int32_t b) {cJSON *item=cJSON_New_Item();if(item)item->type=b?cJSON_True:cJSON_False;return item;} -cJSON *cJSON_CreateNumber(double num) {cJSON *item=cJSON_New_Item();if(item){item->type=cJSON_Number;item->valuedouble=num;item->valueint=(int64_t)num;}return item;} -cJSON *cJSON_CreateString(const char *string) {cJSON *item=cJSON_New_Item();if(item){item->type=cJSON_String;item->valuestring=cJSON_strdup(string);}return item;} - -/* Create Arrays: */ -cJSON *cJSON_CreateIntArray(int64_t *numbers,int32_t count) {int32_t i;cJSON *n=0,*p=0,*a=cJSON_CreateArray();for(i=0;a && ichild=n;else suffix_object(p,n);p=n;}return a;} -cJSON *cJSON_CreateFloatArray(float *numbers,int32_t count) {int32_t i;cJSON *n=0,*p=0,*a=cJSON_CreateArray();for(i=0;a && ichild=n;else suffix_object(p,n);p=n;}return a;} -cJSON *cJSON_CreateDoubleArray(double *numbers,int32_t count) {int32_t i;cJSON *n=0,*p=0,*a=cJSON_CreateArray();for(i=0;a && ichild=n;else suffix_object(p,n);p=n;}return a;} -cJSON *cJSON_CreateStringArray(char **strings,int32_t count) {int32_t i;cJSON *n=0,*p=0,*a=cJSON_CreateArray();for(i=0;a && ichild=n;else suffix_object(p,n);p=n;}return a;} +CJSON_PUBLIC(void *) cJSON_malloc(size_t size) +{ + return global_hooks.allocate(size); +} -/* Duplication */ -cJSON *cJSON_Duplicate(cJSON *item,int32_t recurse) -{ - cJSON *newitem,*cptr,*nptr=0,*newchild; - /* Bail on bad ptr */ - if (!item) return 0; - /* Create new item */ - newitem=cJSON_New_Item(); - if (!newitem) return 0; - /* Copy over all vars */ - newitem->type=item->type&(~cJSON_IsReference),newitem->valueint=item->valueint,newitem->valuedouble=item->valuedouble; - if (item->valuestring) {newitem->valuestring=cJSON_strdup(item->valuestring); if (!newitem->valuestring) {cJSON_Delete(newitem);return 0;}} - if (item->string) {newitem->string=cJSON_strdup(item->string); if (!newitem->string) {cJSON_Delete(newitem);return 0;}} - /* If non-recursive, then we're done! */ - if (!recurse) return newitem; - /* Walk the ->next chain for the child. */ - cptr=item->child; - while (cptr) - { - newchild=cJSON_Duplicate(cptr,1); /* Duplicate (with recurse) each item in the ->next chain */ - if (!newchild) {cJSON_Delete(newitem);return 0;} - if (nptr) {nptr->next=newchild,newchild->prev=nptr;nptr=newchild;} /* If newitem->child already set, then crosswire ->prev and ->next and move on */ - else {newitem->child=newchild;nptr=newchild;} /* Set newitem->child and move to it */ - cptr=cptr->next; - } - return newitem; -} - -void cJSON_Minify(char *json) -{ - char *into=json; - while (*json) - { - if (*json==' ') json++; - else if (*json=='\t') json++; // Whitespace characters. - else if (*json=='\r') json++; - else if (*json=='\n') json++; - else if (*json=='/' && json[1]=='/') while (*json && *json!='\n') json++; // double-slash comments, to end of line. - else if (*json=='/' && json[1]=='*') {while (*json && !(*json=='*' && json[1]=='/')) json++;json+=2;} // multiline comments. - else if (*json=='\"'){*into++=*json++;while (*json && *json!='\"'){if (*json=='\\') *into++=*json++;*into++=*json++;}*into++=*json++;} // string literals, which are \" sensitive. - else *into++=*json++; // All other characters. - } - *into=0; // and null-terminate. +CJSON_PUBLIC(void) cJSON_free(void *object) +{ + global_hooks.deallocate(object); } // the following written by jl777 @@ -1164,7 +3438,7 @@ cJSON *addrs_jsonarray(uint64_t *addrs,int32_t num) return(array); } -cJSON *cJSON_CreateArray(void) +/*cJSON *cJSON_CreateArray(void) { cJSON *item = cJSON_New_Item(); if ( item ) @@ -1184,7 +3458,7 @@ cJSON *cJSON_CreateObject(void) // cJSON_register(item); //#endif return item; -} +}*/ void free_json(cJSON *item) { diff --git a/includes/cJSON.h b/includes/cJSON.h index 3ecdadc69..db9b2fc72 100755 --- a/includes/cJSON.h +++ b/includes/cJSON.h @@ -1,16 +1,13 @@ /* - Copyright (c) 2009 Dave Gamble - + Copyright (c) 2009-2017 Dave Gamble and cJSON contributors Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -42,15 +39,24 @@ extern "C" { #endif + /* project version */ +#define CJSON_VERSION_MAJOR 1 +#define CJSON_VERSION_MINOR 7 +#define CJSON_VERSION_PATCH 1 + +#include + /* cJSON Types: */ -#define cJSON_False 0 -#define cJSON_True 1 -#define cJSON_NULL 2 -#define cJSON_Number 3 -#define cJSON_String 4 -#define cJSON_Array 5 -#define cJSON_Object 6 - +#define cJSON_Invalid (0) +#define cJSON_False (1 << 0) +#define cJSON_True (1 << 1) +#define cJSON_NULL (1 << 2) +#define cJSON_Number (1 << 3) +#define cJSON_String (1 << 4) +#define cJSON_Array (1 << 5) +#define cJSON_Object (1 << 6) +#define cJSON_Raw (1 << 7) /* raw json */ + #define is_cJSON_Null(json) ((json) != 0 && ((json)->type & 0xff) == cJSON_NULL) #define is_cJSON_Array(json) ((json) != 0 && ((json)->type & 0xff) == cJSON_Array) #define is_cJSON_String(json) ((json) != 0 && ((json)->type & 0xff) == cJSON_String) @@ -60,108 +66,232 @@ extern "C" #define is_cJSON_False(json) ((json) != 0 && ((json)->type & 0xff) == cJSON_False) #define cJSON_IsReference 256 +#define cJSON_StringIsConst 512 /* The cJSON structure: */ - typedef struct cJSON { - struct cJSON *next,*prev; /* next/prev allow you to walk array/object chains. Alternatively, use GetArraySize/GetArrayItem/GetObjectItem */ - struct cJSON *child; /* An array or object item will have a child pointer pointing to a chain of the items in the array/object. */ + typedef struct cJSON + { + /* next/prev allow you to walk array/object chains. Alternatively, use GetArraySize/GetArrayItem/GetObjectItem */ + struct cJSON *next; + struct cJSON *prev; + /* An array or object item will have a child pointer pointing to a chain of the items in the array/object. */ + struct cJSON *child; - int32_t type; /* The type of the item, as above. */ + /* The type of the item, as above. */ + int type; - char *valuestring; /* The item's string, if type==cJSON_String */ - int64_t valueint; /* The item's number, if type==cJSON_Number */ - double valuedouble; /* The item's number, if type==cJSON_Number */ + /* The item's string, if type==cJSON_String and type == cJSON_Raw */ + char *valuestring; + /* writing to valueint is DEPRECATED, use cJSON_SetNumberValue instead */ + int valueint; + /* The item's number, if type==cJSON_Number */ + double valuedouble; - char *string; /* The item's name string, if this item is the child of, or is in the list of subitems of an object. */ - uint32_t cjsonid; + /* The item's name string, if this item is the child of, or is in the list of subitems of an object. */ + char *string; } cJSON; - typedef struct cJSON_Hooks { + typedef struct cJSON_Hooks + { void *(*malloc_fn)(size_t sz); void (*free_fn)(void *ptr); } cJSON_Hooks; + typedef int cJSON_bool; + +#if !defined(__WINDOWS__) && (defined(WIN32) || defined(WIN64) || defined(_MSC_VER) || defined(_WIN32)) +#define __WINDOWS__ +#endif +#ifdef __WINDOWS__ + + /* When compiling for windows, we specify a specific calling convention to avoid issues where we are being called from a project with a different default calling convention. For windows you have 2 define options: + CJSON_HIDE_SYMBOLS - Define this in the case where you don't want to ever dllexport symbols + CJSON_EXPORT_SYMBOLS - Define this on library build when you want to dllexport symbols (default) + CJSON_IMPORT_SYMBOLS - Define this if you want to dllimport symbol + For *nix builds that support visibility attribute, you can define similar behavior by + setting default visibility to hidden by adding + -fvisibility=hidden (for gcc) + or + -xldscope=hidden (for sun cc) + to CFLAGS + then using the CJSON_API_VISIBILITY flag to "export" the same symbols the way CJSON_EXPORT_SYMBOLS does + */ + + /* export symbols by default, this is necessary for copy pasting the C and header file */ +#if !defined(CJSON_HIDE_SYMBOLS) && !defined(CJSON_IMPORT_SYMBOLS) && !defined(CJSON_EXPORT_SYMBOLS) +#define CJSON_EXPORT_SYMBOLS +#endif + +#if defined(CJSON_HIDE_SYMBOLS) +#define CJSON_PUBLIC(type) type __stdcall +#elif defined(CJSON_EXPORT_SYMBOLS) +#define CJSON_PUBLIC(type) __declspec(dllexport) type __stdcall +#elif defined(CJSON_IMPORT_SYMBOLS) +#define CJSON_PUBLIC(type) __declspec(dllimport) type __stdcall +#endif +#else /* !WIN32 */ +#if (defined(__GNUC__) || defined(__SUNPRO_CC) || defined (__SUNPRO_C)) && defined(CJSON_API_VISIBILITY) +#define CJSON_PUBLIC(type) __attribute__((visibility("default"))) type +#else +#define CJSON_PUBLIC(type) type +#endif +#endif + + /* Limits how deeply nested arrays/objects can be before cJSON rejects to parse them. + * This is to prevent stack overflows. */ +#ifndef CJSON_NESTING_LIMIT +#define CJSON_NESTING_LIMIT 1000 +#endif + + /* returns the version of cJSON as a string */ + CJSON_PUBLIC(const char*) cJSON_Version(void); + /* Supply malloc, realloc and free functions to cJSON */ - extern void cJSON_InitHooks(cJSON_Hooks* hooks); + CJSON_PUBLIC(void) cJSON_InitHooks(cJSON_Hooks* hooks); + /* Memory Management: the caller is always responsible to free the results from all variants of cJSON_Parse (with cJSON_Delete) and cJSON_Print (with stdlib free, cJSON_Hooks.free_fn, or cJSON_free as appropriate). The exception is cJSON_PrintPreallocated, where the caller has full responsibility of the buffer. */ + /* Supply a block of JSON, and this returns a cJSON object you can interrogate. */ + CJSON_PUBLIC(cJSON *) cJSON_Parse(const char *value); + /* ParseWithOpts allows you to require (and check) that the JSON is null terminated, and to retrieve the pointer to the final byte parsed. */ + /* If you supply a ptr in return_parse_end and parsing fails, then return_parse_end will contain a pointer to the error so will match cJSON_GetErrorPtr(). */ + CJSON_PUBLIC(cJSON *) cJSON_ParseWithOpts(const char *value, const char **return_parse_end, cJSON_bool require_null_terminated); - /* Supply a block of JSON, and this returns a cJSON object you can interrogate. Call cJSON_Delete when finished. */ - extern cJSON *cJSON_Parse(const char *value); - /* Render a cJSON entity to text for transfer/storage. Free the char* when finished. */ - extern char *cJSON_Print(cJSON *item); - /* Render a cJSON entity to text for transfer/storage without any formatting. Free the char* when finished. */ - extern char *cJSON_PrintUnformatted(cJSON *item); + /* Render a cJSON entity to text for transfer/storage. */ + CJSON_PUBLIC(char *) cJSON_Print(const cJSON *item); + /* Render a cJSON entity to text for transfer/storage without any formatting. */ + CJSON_PUBLIC(char *) cJSON_PrintUnformatted(const cJSON *item); + /* Render a cJSON entity to text using a buffered strategy. prebuffer is a guess at the final size. guessing well reduces reallocation. fmt=0 gives unformatted, =1 gives formatted */ + CJSON_PUBLIC(char *) cJSON_PrintBuffered(const cJSON *item, int prebuffer, cJSON_bool fmt); + /* Render a cJSON entity to text using a buffer already allocated in memory with given length. Returns 1 on success and 0 on failure. */ + /* NOTE: cJSON is not always 100% accurate in estimating how much memory it will use, so to be safe allocate 5 bytes more than you actually need */ + CJSON_PUBLIC(cJSON_bool) cJSON_PrintPreallocated(cJSON *item, char *buffer, const int length, const cJSON_bool format); /* Delete a cJSON entity and all subentities. */ - extern void cJSON_Delete(cJSON *c); + CJSON_PUBLIC(void) cJSON_Delete(cJSON *c); /* Returns the number of items in an array (or object). */ - extern int cJSON_GetArraySize(cJSON *array); + CJSON_PUBLIC(int) cJSON_GetArraySize(const cJSON *array); /* Retrieve item number "item" from array "array". Returns NULL if unsuccessful. */ - extern cJSON *cJSON_GetArrayItem(cJSON *array,int32_t item); + CJSON_PUBLIC(cJSON *) cJSON_GetArrayItem(const cJSON *array, int index); /* Get item "string" from object. Case insensitive. */ - extern cJSON *cJSON_GetObjectItem(cJSON *object,const char *string); - + CJSON_PUBLIC(cJSON *) cJSON_GetObjectItem(const cJSON * const object, const char * const string); + CJSON_PUBLIC(cJSON *) cJSON_GetObjectItemCaseSensitive(const cJSON * const object, const char * const string); + CJSON_PUBLIC(cJSON_bool) cJSON_HasObjectItem(const cJSON *object, const char *string); /* For analysing failed parses. This returns a pointer to the parse error. You'll probably need to look a few chars back to make sense of it. Defined when cJSON_Parse() returns 0. 0 when cJSON_Parse() succeeds. */ - extern const char *cJSON_GetErrorPtr(void); - + CJSON_PUBLIC(const char *) cJSON_GetErrorPtr(void); + + /* Check if the item is a string and return its valuestring */ + CJSON_PUBLIC(char *) cJSON_GetStringValue(cJSON *item); + + /* These functions check the type of an item */ + CJSON_PUBLIC(cJSON_bool) cJSON_IsInvalid(const cJSON * const item); + CJSON_PUBLIC(cJSON_bool) cJSON_IsFalse(const cJSON * const item); + CJSON_PUBLIC(cJSON_bool) cJSON_IsTrue(const cJSON * const item); + CJSON_PUBLIC(cJSON_bool) cJSON_IsBool(const cJSON * const item); + CJSON_PUBLIC(cJSON_bool) cJSON_IsNull(const cJSON * const item); + CJSON_PUBLIC(cJSON_bool) cJSON_IsNumber(const cJSON * const item); + CJSON_PUBLIC(cJSON_bool) cJSON_IsString(const cJSON * const item); + CJSON_PUBLIC(cJSON_bool) cJSON_IsArray(const cJSON * const item); + CJSON_PUBLIC(cJSON_bool) cJSON_IsObject(const cJSON * const item); + CJSON_PUBLIC(cJSON_bool) cJSON_IsRaw(const cJSON * const item); + /* These calls create a cJSON item of the appropriate type. */ - extern cJSON *cJSON_CreateNull(void); - extern cJSON *cJSON_CreateTrue(void); - extern cJSON *cJSON_CreateFalse(void); - extern cJSON *cJSON_CreateBool(int32_t b); - extern cJSON *cJSON_CreateNumber(double num); - extern cJSON *cJSON_CreateString(const char *string); - extern cJSON *cJSON_CreateArray(void); - extern cJSON *cJSON_CreateObject(void); + CJSON_PUBLIC(cJSON *) cJSON_CreateNull(void); + CJSON_PUBLIC(cJSON *) cJSON_CreateTrue(void); + CJSON_PUBLIC(cJSON *) cJSON_CreateFalse(void); + CJSON_PUBLIC(cJSON *) cJSON_CreateBool(cJSON_bool boolean); + CJSON_PUBLIC(cJSON *) cJSON_CreateNumber(double num); + CJSON_PUBLIC(cJSON *) cJSON_CreateString(const char *string); + /* raw json */ + CJSON_PUBLIC(cJSON *) cJSON_CreateRaw(const char *raw); + CJSON_PUBLIC(cJSON *) cJSON_CreateArray(void); + CJSON_PUBLIC(cJSON *) cJSON_CreateObject(void); + + /* Create a string where valuestring references a string so + * it will not be freed by cJSON_Delete */ + CJSON_PUBLIC(cJSON *) cJSON_CreateStringReference(const char *string); + /* Create an object/arrray that only references it's elements so + * they will not be freed by cJSON_Delete */ + CJSON_PUBLIC(cJSON *) cJSON_CreateObjectReference(const cJSON *child); + CJSON_PUBLIC(cJSON *) cJSON_CreateArrayReference(const cJSON *child); /* These utilities create an Array of count items. */ - extern cJSON *cJSON_CreateIntArray(int64_t *numbers,int32_t count); - extern cJSON *cJSON_CreateFloatArray(float *numbers,int32_t count); - extern cJSON *cJSON_CreateDoubleArray(double *numbers,int32_t count); - extern cJSON *cJSON_CreateStringArray(char **strings,int32_t count); + CJSON_PUBLIC(cJSON *) cJSON_CreateIntArray(const int *numbers, int count); + CJSON_PUBLIC(cJSON *) cJSON_CreateFloatArray(const float *numbers, int count); + CJSON_PUBLIC(cJSON *) cJSON_CreateDoubleArray(const double *numbers, int count); + CJSON_PUBLIC(cJSON *) cJSON_CreateStringArray(const char **strings, int count); /* Append item to the specified array/object. */ - extern void cJSON_AddItemToArray(cJSON *array, cJSON *item); - extern void cJSON_AddItemToObject(cJSON *object,const char *string,cJSON *item); + CJSON_PUBLIC(void) cJSON_AddItemToArray(cJSON *array, cJSON *item); + CJSON_PUBLIC(void) cJSON_AddItemToObject(cJSON *object, const char *string, cJSON *item); + /* Use this when string is definitely const (i.e. a literal, or as good as), and will definitely survive the cJSON object. + * WARNING: When this function was used, make sure to always check that (item->type & cJSON_StringIsConst) is zero before + * writing to `item->string` */ + CJSON_PUBLIC(void) cJSON_AddItemToObjectCS(cJSON *object, const char *string, cJSON *item); /* Append reference to item to the specified array/object. Use this when you want to add an existing cJSON to a new cJSON, but don't want to corrupt your existing cJSON. */ - extern void cJSON_AddItemReferenceToArray(cJSON *array, cJSON *item); - extern void cJSON_AddItemReferenceToObject(cJSON *object,const char *string,cJSON *item); + CJSON_PUBLIC(void) cJSON_AddItemReferenceToArray(cJSON *array, cJSON *item); + CJSON_PUBLIC(void) cJSON_AddItemReferenceToObject(cJSON *object, const char *string, cJSON *item); /* Remove/Detatch items from Arrays/Objects. */ - extern cJSON *cJSON_DetachItemFromArray(cJSON *array,int32_t which); - extern void cJSON_DeleteItemFromArray(cJSON *array,int32_t which); - extern cJSON *cJSON_DetachItemFromObject(cJSON *object,const char *string); - extern void cJSON_DeleteItemFromObject(cJSON *object,const char *string); - + CJSON_PUBLIC(cJSON *) cJSON_DetachItemViaPointer(cJSON *parent, cJSON * const item); + CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromArray(cJSON *array, int which); + CJSON_PUBLIC(void) cJSON_DeleteItemFromArray(cJSON *array, int which); + CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromObject(cJSON *object, const char *string); + CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromObjectCaseSensitive(cJSON *object, const char *string); + CJSON_PUBLIC(void) cJSON_DeleteItemFromObject(cJSON *object, const char *string); + CJSON_PUBLIC(void) cJSON_DeleteItemFromObjectCaseSensitive(cJSON *object, const char *string); + /* Update array items. */ - extern void cJSON_ReplaceItemInArray(cJSON *array,int32_t which,cJSON *newitem); - extern void cJSON_ReplaceItemInObject(cJSON *object,const char *string,cJSON *newitem); + CJSON_PUBLIC(void) cJSON_InsertItemInArray(cJSON *array, int which, cJSON *newitem); /* Shifts pre-existing items to the right. */ + CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemViaPointer(cJSON * const parent, cJSON * const item, cJSON * replacement); + CJSON_PUBLIC(void) cJSON_ReplaceItemInArray(cJSON *array, int which, cJSON *newitem); + CJSON_PUBLIC(void) cJSON_ReplaceItemInObject(cJSON *object,const char *string,cJSON *newitem); + CJSON_PUBLIC(void) cJSON_ReplaceItemInObjectCaseSensitive(cJSON *object,const char *string,cJSON *newitem); /* Duplicate a cJSON item */ - extern cJSON *cJSON_Duplicate(cJSON *item,int32_t recurse); + CJSON_PUBLIC(cJSON *) cJSON_Duplicate(const cJSON *item, cJSON_bool recurse); /* Duplicate will create a new, identical cJSON item to the one you pass, in new memory that will need to be released. With recurse!=0, it will duplicate any children connected to the item. The item->next and ->prev pointers are always zero on return from Duplicate. */ + /* Recursively compare two cJSON items for equality. If either a or b is NULL or invalid, they will be considered unequal. + * case_sensitive determines if object keys are treated case sensitive (1) or case insensitive (0) */ + CJSON_PUBLIC(cJSON_bool) cJSON_Compare(const cJSON * const a, const cJSON * const b, const cJSON_bool case_sensitive); - /* ParseWithOpts allows you to require (and check) that the JSON is null terminated, and to retrieve the pointer to the final byte parsed. */ - extern cJSON *cJSON_ParseWithOpts(const char *value,const char **return_parse_end,int32_t require_null_terminated); - extern void cJSON_Minify(char *json); + CJSON_PUBLIC(void) cJSON_Minify(char *json); - /* Macros for creating things quickly. */ -#define cJSON_AddNullToObject(object,name) cJSON_AddItemToObject(object, name, cJSON_CreateNull()) -#define cJSON_AddTrueToObject(object,name) cJSON_AddItemToObject(object, name, cJSON_CreateTrue()) -#define cJSON_AddFalseToObject(object,name) cJSON_AddItemToObject(object, name, cJSON_CreateFalse()) -#define cJSON_AddBoolToObject(object,name,b) cJSON_AddItemToObject(object, name, cJSON_CreateBool(b)) -#define cJSON_AddNumberToObject(object,name,n) cJSON_AddItemToObject(object, name, cJSON_CreateNumber(n)) -#define cJSON_AddStringToObject(object,name,s) cJSON_AddItemToObject(object, name, cJSON_CreateString(s)) - - struct destbuf { char buf[MAX_JSON_FIELD]; }; + /* Helper functions for creating and adding items to an object at the same time. + * They return the added item or NULL on failure. */ + CJSON_PUBLIC(cJSON*) cJSON_AddNullToObject(cJSON * const object, const char * const name); + CJSON_PUBLIC(cJSON*) cJSON_AddTrueToObject(cJSON * const object, const char * const name); + CJSON_PUBLIC(cJSON*) cJSON_AddFalseToObject(cJSON * const object, const char * const name); + CJSON_PUBLIC(cJSON*) cJSON_AddBoolToObject(cJSON * const object, const char * const name, const cJSON_bool boolean); + CJSON_PUBLIC(cJSON*) cJSON_AddNumberToObject(cJSON * const object, const char * const name, const double number); + CJSON_PUBLIC(cJSON*) cJSON_AddStringToObject(cJSON * const object, const char * const name, const char * const string); + CJSON_PUBLIC(cJSON*) cJSON_AddRawToObject(cJSON * const object, const char * const name, const char * const raw); + CJSON_PUBLIC(cJSON*) cJSON_AddObjectToObject(cJSON * const object, const char * const name); + CJSON_PUBLIC(cJSON*) cJSON_AddArrayToObject(cJSON * const object, const char * const name); /* When assigning an integer value, it needs to be propagated to valuedouble too. */ -#define cJSON_SetIntValue(object,val) ((object)?(object)->valueint=(object)->valuedouble=(val):(val)) -#define jfieldstr get_cJSON_fieldname +#define cJSON_SetIntValue(object, number) ((object) ? (object)->valueint = (object)->valuedouble = (number) : (number)) + /* helper for the cJSON_SetNumberValue macro */ + CJSON_PUBLIC(double) cJSON_SetNumberHelper(cJSON *object, double number); +#define cJSON_SetNumberValue(object, number) ((object != NULL) ? cJSON_SetNumberHelper(object, (double)number) : (number)) + + /* Macro for iterating over an array or object */ +#define cJSON_ArrayForEach(element, array) for(element = (array != NULL) ? (array)->child : NULL; element != NULL; element = element->next) + + /* malloc/free objects using the malloc/free functions that have been set with cJSON_InitHooks */ + CJSON_PUBLIC(void *) cJSON_malloc(size_t size); + CJSON_PUBLIC(void) cJSON_free(void *object); + +#define jfieldname get_cJSON_fieldname +#ifdef __cplusplus +} +#endif + +struct destbuf { char buf[MAX_JSON_FIELD]; }; + char *cJSON_str(cJSON *json); char *jstr(cJSON *json,char *field); char *jprint(cJSON *json,int32_t freeflag); @@ -228,10 +358,5 @@ extern "C" #define jtrue cJSON_CreateTrue #define jfalse cJSON_CreateFalse -#define jfieldname get_cJSON_fieldname - -#ifdef __cplusplus -} -#endif #endif From 52a5e489c18e66447c6cae22d9259c0ee67a2933 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 28 Jan 2018 15:38:45 +0400 Subject: [PATCH 149/183] Fix --- crypto777/cJSON.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crypto777/cJSON.c b/crypto777/cJSON.c index b78c290cd..b21cc3e4f 100755 --- a/crypto777/cJSON.c +++ b/crypto777/cJSON.c @@ -54,7 +54,7 @@ #pragma GCC visibility pop #endif -#include "cJSON.h" +#include "../includes/cJSON.h" /* define our own boolean type */ #define true ((cJSON_bool)1) From 7b4d0ee8bfded1eebb66ac89692d87e750b2cda2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 28 Jan 2018 16:05:18 +0400 Subject: [PATCH 150/183] Check for null address in addr2rmd160 --- iguana/exchanges/LP_bitcoin.c | 6 ++++++ iguana/exchanges/LP_instantdex.c | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_bitcoin.c b/iguana/exchanges/LP_bitcoin.c index 2fb98a48d..3ca110483 100644 --- a/iguana/exchanges/LP_bitcoin.c +++ b/iguana/exchanges/LP_bitcoin.c @@ -2052,6 +2052,12 @@ bits256 bits256_calcaddrhash(char *symbol,uint8_t *serialized,int32_t len) int32_t bitcoin_addr2rmd160(char *symbol,uint8_t taddr,uint8_t *addrtypep,uint8_t rmd160[20],char *coinaddr) { bits256 hash; uint8_t *buf,_buf[26],data5[128],rmd21[21]; char prefixaddr[64],hrp[64]; int32_t len,len5,offset; + if ( coinaddr == 0 || coinaddr[0] == 0 ) + { + *addrtypep = 0; + memset(rmd160,0,20); + return(0); + } if ( strcmp(symbol,"BCH") == 0 )//&& strlen(coinaddr) == 42 ) { char *bchprefix = "bitcoincash:"; diff --git a/iguana/exchanges/LP_instantdex.c b/iguana/exchanges/LP_instantdex.c index 372024655..41496ba52 100644 --- a/iguana/exchanges/LP_instantdex.c +++ b/iguana/exchanges/LP_instantdex.c @@ -435,7 +435,7 @@ int64_t LP_instantdex_creditcalc(struct iguana_info *coin,int32_t dispflag,bits2 } #ifdef bruteforce -void LP_instantdex_deposits(struct iguana_info *coin) +/*void LP_instantdex_deposits(struct iguana_info *coin) { static int dispflag = 1; cJSON *array,*item; int32_t i,n,height,vout; bits256 txid; struct LP_address *ap,*tmp; @@ -463,7 +463,7 @@ void LP_instantdex_deposits(struct iguana_info *coin) free_json(array); } dispflag = 0; -} +}*/ #endif int64_t LP_dynamictrust(int64_t credits,bits256 pubkey,int64_t kmdvalue) From 77b4fa70b8427ff5c775a7697a7e1a5d9f1ba218 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 28 Jan 2018 16:09:54 +0400 Subject: [PATCH 151/183] Print orig coinaddr in 0conf deposit error --- iguana/exchanges/LP_include.h | 2 +- iguana/exchanges/LP_instantdex.c | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/iguana/exchanges/LP_include.h b/iguana/exchanges/LP_include.h index eeff1ee7a..63f565233 100644 --- a/iguana/exchanges/LP_include.h +++ b/iguana/exchanges/LP_include.h @@ -517,7 +517,7 @@ struct LP_address_utxo *LP_address_utxofind(struct iguana_info *coin,char *coina int64_t LP_myzcredits(); void test_validate(struct iguana_info *coin,char *signedtx); void LP_instantdex_depositadd(char *coinaddr,bits256 txid); -int64_t LP_instantdex_creditcalc(struct iguana_info *coin,int32_t dispflag,bits256 txid,char *refaddr); +int64_t LP_instantdex_creditcalc(struct iguana_info *coin,int32_t dispflag,bits256 txid,char *refaddr,char *origcoinaddr); void LP_ports(uint16_t *pullportp,uint16_t *pubportp,uint16_t *busportp,uint16_t netid); int32_t LP_destaddr(char *destaddr,cJSON *item); int32_t LP_waitmempool(char *symbol,char *coinaddr,bits256 txid,int32_t vout,int32_t duration); diff --git a/iguana/exchanges/LP_instantdex.c b/iguana/exchanges/LP_instantdex.c index 41496ba52..f0b6aa50a 100644 --- a/iguana/exchanges/LP_instantdex.c +++ b/iguana/exchanges/LP_instantdex.c @@ -133,7 +133,7 @@ void LP_instantdex_depositadd(char *coinaddr,bits256 txid) { prevtxid = jbits256i(array,i); //char str[65]; printf("instantdex iter.%d i.%d check %s\n",iter,i,bits256_str(str,prevtxid)); - if ( LP_instantdex_creditcalc(coin,0,prevtxid,coinaddr) > 0 ) + if ( LP_instantdex_creditcalc(coin,0,prevtxid,coinaddr,coinaddr) > 0 ) { LP_instantdex_deposituniq(fp,prevtxid); fflush(fp); @@ -400,7 +400,7 @@ int64_t LP_instantdex_credit(int32_t dispflag,char *coinaddr,int64_t satoshis,in return(0); } -int64_t LP_instantdex_creditcalc(struct iguana_info *coin,int32_t dispflag,bits256 txid,char *refaddr) +int64_t LP_instantdex_creditcalc(struct iguana_info *coin,int32_t dispflag,bits256 txid,char *refaddr,char *origcoinaddr) { cJSON *txjson,*vouts,*txobj,*item; int64_t satoshis=0,amount64; int32_t weeki,numvouts; char destaddr[64],p2shaddr[64]; if ( (txjson= LP_gettx(coin->symbol,txid,0)) != 0 ) @@ -410,7 +410,7 @@ int64_t LP_instantdex_creditcalc(struct iguana_info *coin,int32_t dispflag,bits2 { if ( refaddr != 0 && strcmp(refaddr,destaddr) != 0 ) { - printf("LP_instantdex_creditcalc for (%s) but deposit sent for (%s)\n",refaddr,destaddr); + printf("LP_instantdex_creditcalc for (%s) but deposit sent for orig.(%s) (%s)\n",refaddr,origcoinaddr,destaddr); } else { @@ -529,7 +529,7 @@ int64_t LP_instantdex_proofcheck(char *symbol,char *coinaddr,cJSON *proof,int32_ break; } if ( j == i ) - LP_instantdex_creditcalc(coin,1,txid,othersmartaddr); + LP_instantdex_creditcalc(coin,1,txid,othersmartaddr,coinaddr); } credits = ap->instantdex_credits; ap->didinstantdex = 1; From 76536ed013a7e3e8d7e8b8b0f66e8bec7e990380 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 28 Jan 2018 16:16:16 +0400 Subject: [PATCH 152/183] Test --- iguana/exchanges/LP_include.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_include.h b/iguana/exchanges/LP_include.h index 63f565233..3ddbb4a7b 100644 --- a/iguana/exchanges/LP_include.h +++ b/iguana/exchanges/LP_include.h @@ -55,7 +55,7 @@ void emscripten_usleep(int32_t x); // returns immediate, no sense for sleeping #define LP_MAXVINS 64 #define LP_HTTP_TIMEOUT 3 // 1 is too small due to edge cases of time(NULL) -#define LP_AUTOTRADE_TIMEOUT 60 +#define LP_AUTOTRADE_TIMEOUT 30 #define LP_RESERVETIME 600 //(LP_AUTOTRADE_TIMEOUT * 2) #define ELECTRUM_TIMEOUT 13 #define LP_ELECTRUM_KEEPALIVE 60 From 6a70aeb6c06d7453a261e45481937c9629fad513 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 28 Jan 2018 16:49:07 +0400 Subject: [PATCH 153/183] Test --- crypto777/OS_portable.h | 2 +- iguana/exchanges/LP_commands.c | 2 +- iguana/exchanges/LP_instantdex.c | 2 +- iguana/exchanges/LP_portfolio.c | 2 +- iguana/exchanges/LP_prices.c | 2 +- iguana/exchanges/LP_remember.c | 2 +- iguana/exchanges/LP_signatures.c | 4 ++-- iguana/exchanges/LP_stats.c | 4 ++-- iguana/exchanges/LP_tradebots.c | 4 ++-- includes/cJSON.h | 2 +- 10 files changed, 13 insertions(+), 13 deletions(-) diff --git a/crypto777/OS_portable.h b/crypto777/OS_portable.h index 8c109e5d0..07b9d5f67 100755 --- a/crypto777/OS_portable.h +++ b/crypto777/OS_portable.h @@ -115,7 +115,7 @@ int32_t hseek(HUFF *hp,int32_t offset,int32_t mode); #define GENESIS_SECRET "It was a bright cold day in April, and the clocks were striking thirteen." #define SATOSHIDEN ((uint64_t)100000000L) -#define dstr(x) ((double)(x) / SATOSHIDEN) +#define dstr(x) ((double)((uint64_t)(x)) / SATOSHIDEN) #define SMALLVAL 0.000000000000001 diff --git a/iguana/exchanges/LP_commands.c b/iguana/exchanges/LP_commands.c index 94186c659..72a71e648 100644 --- a/iguana/exchanges/LP_commands.c +++ b/iguana/exchanges/LP_commands.c @@ -681,7 +681,7 @@ jpg(srcfile, destfile, power2=7, password, data="", required, ind=0)\n\ jaddnum(retjson,"timestamp",time(NULL)); jaddnum(retjson,"bid",bid); jaddnum(retjson,"ask",ask); - jaddnum(retjson,"price",price); + jaddnum(retjson,"price",dstr(SATOSHIDEN * price)); return(jprint(retjson,1)); } /*else if ( strcmp(method,"getpeers") == 0 ) diff --git a/iguana/exchanges/LP_instantdex.c b/iguana/exchanges/LP_instantdex.c index f0b6aa50a..f06cd9cbc 100644 --- a/iguana/exchanges/LP_instantdex.c +++ b/iguana/exchanges/LP_instantdex.c @@ -567,7 +567,7 @@ cJSON *LP_swapstats_item(struct LP_swapstats *sp,int32_t iambob) jaddnum(item,"satoshis",sp->Q.satoshis); jaddstr(item,"rel",sp->Q.destcoin); jaddnum(item,"destsatoshis",sp->Q.destsatoshis); - jaddnum(item,"price",sp->Q.destsatoshis/((double)sp->Q.satoshis+1)); + jaddnum(item,"price",dstr(SATOSHIDEN * (sp->Q.destsatoshis/((double)sp->Q.satoshis+1)))); if ( LP_swap_finished(sp,1) == 0 ) { jaddnum(item,"finished",sp->finished); diff --git a/iguana/exchanges/LP_portfolio.c b/iguana/exchanges/LP_portfolio.c index ead40b27c..49db78608 100644 --- a/iguana/exchanges/LP_portfolio.c +++ b/iguana/exchanges/LP_portfolio.c @@ -71,7 +71,7 @@ cJSON *LP_portfolio_entry(struct iguana_info *coin) jaddstr(item,"coin",coin->symbol); jaddstr(item,"address",coin->smartaddr); jaddnum(item,"amount",dstr(coin->maxamount)); - jaddnum(item,"price",coin->price_kmd); + jaddnum(item,"price",dstr(SATOSHIDEN * coin->price_kmd)); jaddnum(item,"kmd_equiv",dstr(coin->kmd_equiv)); jaddnum(item,"perc",coin->perc); jaddnum(item,"goal",coin->goal); diff --git a/iguana/exchanges/LP_prices.c b/iguana/exchanges/LP_prices.c index cee20a5d2..f67bffd8c 100644 --- a/iguana/exchanges/LP_prices.c +++ b/iguana/exchanges/LP_prices.c @@ -741,7 +741,7 @@ cJSON *LP_orderbookjson(char *symbol,struct LP_orderbookentry *op) { jaddstr(item,"coin",symbol); jaddstr(item,"address",op->coinaddr); - jaddnum(item,"price",op->price); + jaddnum(item,"price",dstr(SATOSHIDEN * op->price)); jaddnum(item,"numutxos",op->numutxos); jaddnum(item,"avevolume",dstr(op->avesatoshis)*0.8); jaddnum(item,"maxvolume",dstr(op->maxsatoshis)*0.8); diff --git a/iguana/exchanges/LP_remember.c b/iguana/exchanges/LP_remember.c index 8c50de4fe..b88128dbb 100644 --- a/iguana/exchanges/LP_remember.c +++ b/iguana/exchanges/LP_remember.c @@ -1399,7 +1399,7 @@ char *LP_recent_swaps(int32_t limit) subitem = cJSON_CreateObject(); jaddnum(subitem,base,srcamount); jaddnum(subitem,rel,destamount); - jaddnum(subitem,"price",-destamount/srcamount); + jaddnum(subitem,"price",dstr(SATOSHIDEN * -destamount/srcamount)); jaddi(item,subitem); } } else printf("base.%p rel.%p statusstr.%p baseind.%d relind.%d\n",base,rel,statusstr,baseind,relind); diff --git a/iguana/exchanges/LP_signatures.c b/iguana/exchanges/LP_signatures.c index 31870fad2..1daae27b6 100644 --- a/iguana/exchanges/LP_signatures.c +++ b/iguana/exchanges/LP_signatures.c @@ -92,7 +92,7 @@ cJSON *LP_quotejson(struct LP_quoteinfo *qp) if ( qp->satoshis != 0 ) { price = (double)qp->destsatoshis / (qp->satoshis - qp->txfee); - jaddnum(retjson,"price",price); + jaddnum(retjson,"price",dstr(SATOSHIDEN * price)); } } if ( qp->R.requestid != 0 ) @@ -405,7 +405,7 @@ char *LP_pricepings(void *ctx,char *myipaddr,int32_t pubsock,char *base,char *re jaddstr(reqjson,"base",base); jaddstr(reqjson,"rel",rel); price64 = price * SATOSHIDEN + 0.0000000049; - jaddnum(reqjson,"price",price); + jaddnum(reqjson,"price",dstr(price64)); jadd64bits(reqjson,"price64",price64); jaddstr(reqjson,"method","postprice"); timestamp = (uint32_t)time(NULL); diff --git a/iguana/exchanges/LP_stats.c b/iguana/exchanges/LP_stats.c index 1bce64fde..54bd0c918 100644 --- a/iguana/exchanges/LP_stats.c +++ b/iguana/exchanges/LP_stats.c @@ -556,7 +556,7 @@ cJSON *LP_swapstats_json(struct LP_swapstats *sp) jaddbits256(item,"dest",sp->Q.desthash); jaddstr(item,"rel",sp->Q.destcoin); jaddnum(item,"relvol",dstr(sp->Q.destsatoshis)); - jaddnum(item,"price",sp->qprice); + jaddnum(item,"price",dstr(SATOSHIDEN * sp->qprice)); jaddnum(item,"requestid",sp->Q.R.requestid); jaddnum(item,"quoteid",sp->Q.R.quoteid); jaddnum(item,"finished",sp->finished); @@ -823,7 +823,7 @@ char *LP_ticker(char *refbase,char *refrel) jaddnum(retitem,"timestamp",juint(item,"timestamp")); jaddnum(retitem,base,basevol); jaddnum(retitem,rel,relvol); - jaddnum(retitem,"price",relvol/basevol); + jaddnum(retitem,"price",dstr(SATOSHIDEN * (relvol/basevol))); } jaddi(retjson,retitem); } diff --git a/iguana/exchanges/LP_tradebots.c b/iguana/exchanges/LP_tradebots.c index 39526c2be..6e1bb749a 100644 --- a/iguana/exchanges/LP_tradebots.c +++ b/iguana/exchanges/LP_tradebots.c @@ -142,13 +142,13 @@ cJSON *LP_tradebot_tradejson(struct LP_tradebot_trade *tp,int32_t dispflag) { if ( dispflag > 0 ) { - jaddnum(item,"price",tp->relvol/tp->basevol); + jaddnum(item,"price",dstr(SATOSHIDEN * (tp->relvol/tp->basevol))); jaddnum(item,"volume",tp->relvol); } else { price = LP_pricevol_invert(&basevol,tp->relvol / tp->basevol,tp->relvol); - jaddnum(item,"price",price); + jaddnum(item,"price",dstr(SATOSHIDEN * price)); jaddnum(item,"volume",basevol); } } diff --git a/includes/cJSON.h b/includes/cJSON.h index db9b2fc72..47e39f07d 100755 --- a/includes/cJSON.h +++ b/includes/cJSON.h @@ -31,7 +31,7 @@ #include "../crypto777/OS_portable.h" #define SATOSHIDEN ((uint64_t)100000000L) -#define dstr(x) ((double)(x) / SATOSHIDEN) +#define dstr(x) ((double)((uint64_t)(x)) / SATOSHIDEN) #define MAX_JSON_FIELD 4096 // on the big side #ifdef __cplusplus From d34fcaf9713e5a3e8aad3e726a98b5ffbbd9dd31 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 28 Jan 2018 16:50:56 +0400 Subject: [PATCH 154/183] Test --- crypto777/OS_portable.h | 2 +- includes/cJSON.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/crypto777/OS_portable.h b/crypto777/OS_portable.h index 07b9d5f67..4d3823942 100755 --- a/crypto777/OS_portable.h +++ b/crypto777/OS_portable.h @@ -115,7 +115,7 @@ int32_t hseek(HUFF *hp,int32_t offset,int32_t mode); #define GENESIS_SECRET "It was a bright cold day in April, and the clocks were striking thirteen." #define SATOSHIDEN ((uint64_t)100000000L) -#define dstr(x) ((double)((uint64_t)(x)) / SATOSHIDEN) +#define dstr(x) ((double)((uint64_t)(x)) / SATOSHIDEN + 0.0000000049) #define SMALLVAL 0.000000000000001 diff --git a/includes/cJSON.h b/includes/cJSON.h index 47e39f07d..9dfd88e5a 100755 --- a/includes/cJSON.h +++ b/includes/cJSON.h @@ -31,7 +31,7 @@ #include "../crypto777/OS_portable.h" #define SATOSHIDEN ((uint64_t)100000000L) -#define dstr(x) ((double)((uint64_t)(x)) / SATOSHIDEN) +#define dstr(x) ((double)((uint64_t)(x)) / SATOSHIDEN + 0.0000000049) #define MAX_JSON_FIELD 4096 // on the big side #ifdef __cplusplus From 98d04bf25a9a5da86ce57ce76ae49a3d676738e1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 28 Jan 2018 16:54:34 +0400 Subject: [PATCH 155/183] Test --- crypto777/OS_portable.h | 2 +- iguana/exchanges/LP_ordermatch.c | 6 +++--- includes/cJSON.h | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/crypto777/OS_portable.h b/crypto777/OS_portable.h index 4d3823942..07b9d5f67 100755 --- a/crypto777/OS_portable.h +++ b/crypto777/OS_portable.h @@ -115,7 +115,7 @@ int32_t hseek(HUFF *hp,int32_t offset,int32_t mode); #define GENESIS_SECRET "It was a bright cold day in April, and the clocks were striking thirteen." #define SATOSHIDEN ((uint64_t)100000000L) -#define dstr(x) ((double)((uint64_t)(x)) / SATOSHIDEN + 0.0000000049) +#define dstr(x) ((double)((uint64_t)(x)) / SATOSHIDEN) #define SMALLVAL 0.000000000000001 diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index bb22c383d..615cb1057 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -181,7 +181,7 @@ double LP_quote_validate(struct LP_utxoinfo *autxo,struct LP_utxoinfo *butxo,str return(-33); } if ( qp->satoshis != 0 ) - qprice = ((double)qp->destsatoshis / (qp->satoshis-qp->txfee)); + qprice = ((double)qp->destsatoshis / (qp->satoshis-qp->txfee)) + 0.000000049; LP_txfees(&txfee,&desttxfee,qp->srccoin,qp->destcoin); if ( txfee < qp->txfee ) txfee = qp->txfee; @@ -846,7 +846,7 @@ struct LP_quoteinfo *LP_trades_gotrequest(void *ctx,struct LP_quoteinfo *qp,stru LP_abutxo_set(autxo,butxo,qp); if ( bits256_nonz(qp->srchash) == 0 || bits256_cmp(qp->srchash,G.LP_mypub25519) == 0 ) { - qprice = (double)qp->destsatoshis / (qp->satoshis - qp->txfee); + qprice = (double)qp->destsatoshis / (qp->satoshis - qp->txfee) + 0.000000049; strcpy(qp->gui,G.gui); strcpy(qp->coinaddr,coin->smartaddr); strcpy(butxo->coinaddr,coin->smartaddr); @@ -980,7 +980,7 @@ int32_t LP_trades_bestpricecheck(void *ctx,struct LP_trade *tp) //printf("check bestprice %.8f vs new price %.8f\n",tp->bestprice,(double)Q.destsatoshis/Q.satoshis); if ( Q.satoshis != 0 && (pubp= LP_pubkeyadd(Q.srchash)) != 0 )//(qprice= LP_trades_alicevalidate(ctx,&Q)) > 0. ) { - qprice = (double)Q.destsatoshis / (Q.satoshis - Q.txfee); + qprice = (double)Q.destsatoshis / (Q.satoshis - Q.txfee) + 0.000000049; LP_aliceid(Q.tradeid,tp->aliceid,"reserved",0,0); if ( (retstr= LP_quotereceived(&Q)) != 0 ) free(retstr); diff --git a/includes/cJSON.h b/includes/cJSON.h index 9dfd88e5a..47e39f07d 100755 --- a/includes/cJSON.h +++ b/includes/cJSON.h @@ -31,7 +31,7 @@ #include "../crypto777/OS_portable.h" #define SATOSHIDEN ((uint64_t)100000000L) -#define dstr(x) ((double)((uint64_t)(x)) / SATOSHIDEN + 0.0000000049) +#define dstr(x) ((double)((uint64_t)(x)) / SATOSHIDEN) #define MAX_JSON_FIELD 4096 // on the big side #ifdef __cplusplus From 5ff6eb12f03ce11e755445d65a4f759b37130660 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 28 Jan 2018 17:01:04 +0400 Subject: [PATCH 156/183] Fix --- crypto777/OS_portable.h | 2 +- includes/cJSON.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/crypto777/OS_portable.h b/crypto777/OS_portable.h index 07b9d5f67..a7ee523cf 100755 --- a/crypto777/OS_portable.h +++ b/crypto777/OS_portable.h @@ -115,7 +115,7 @@ int32_t hseek(HUFF *hp,int32_t offset,int32_t mode); #define GENESIS_SECRET "It was a bright cold day in April, and the clocks were striking thirteen." #define SATOSHIDEN ((uint64_t)100000000L) -#define dstr(x) ((double)((uint64_t)(x)) / SATOSHIDEN) +#define dstr(x) ((double)((int64_t)(x)) / SATOSHIDEN) #define SMALLVAL 0.000000000000001 diff --git a/includes/cJSON.h b/includes/cJSON.h index 47e39f07d..d8f1831e0 100755 --- a/includes/cJSON.h +++ b/includes/cJSON.h @@ -31,7 +31,7 @@ #include "../crypto777/OS_portable.h" #define SATOSHIDEN ((uint64_t)100000000L) -#define dstr(x) ((double)((uint64_t)(x)) / SATOSHIDEN) +#define dstr(x) ((double)((int64_t)(x)) / SATOSHIDEN) #define MAX_JSON_FIELD 4096 // on the big side #ifdef __cplusplus From 42831a345c099f12970fd01a7ced6f9b24e545ff Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 28 Jan 2018 17:03:45 +0400 Subject: [PATCH 157/183] Test --- crypto777/OS_portable.h | 2 +- crypto777/cJSON.c | 8 ++++---- includes/cJSON.h | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/crypto777/OS_portable.h b/crypto777/OS_portable.h index a7ee523cf..362432e8d 100755 --- a/crypto777/OS_portable.h +++ b/crypto777/OS_portable.h @@ -115,7 +115,7 @@ int32_t hseek(HUFF *hp,int32_t offset,int32_t mode); #define GENESIS_SECRET "It was a bright cold day in April, and the clocks were striking thirteen." #define SATOSHIDEN ((uint64_t)100000000L) -#define dstr(x) ((double)((int64_t)(x)) / SATOSHIDEN) +#define dstr(x) ((double)((x)) / SATOSHIDEN) #define SMALLVAL 0.000000000000001 diff --git a/crypto777/cJSON.c b/crypto777/cJSON.c index b21cc3e4f..d48798c74 100755 --- a/crypto777/cJSON.c +++ b/crypto777/cJSON.c @@ -504,14 +504,14 @@ static cJSON_bool print_number(const cJSON * const item, printbuffer * const out } else { - /* Try 15 decimal places of precision to avoid nonsignificant nonzero digits */ - length = sprintf((char*)number_buffer, "%1.15g", d); + /* Try 8 decimal places of precision to avoid nonsignificant nonzero digits */ + length = sprintf((char*)number_buffer, "%1.8g", d); /* Check whether the original double can be recovered */ if ((sscanf((char*)number_buffer, "%lg", &test) != 1) || ((double)test != d)) { - /* If not, print with 17 decimal places of precision */ - length = sprintf((char*)number_buffer, "%1.17g", d); + /* If not, print with 8 decimal places of precision */ + length = sprintf((char*)number_buffer, "%1.8g", d); } } diff --git a/includes/cJSON.h b/includes/cJSON.h index d8f1831e0..999f5ce21 100755 --- a/includes/cJSON.h +++ b/includes/cJSON.h @@ -31,7 +31,7 @@ #include "../crypto777/OS_portable.h" #define SATOSHIDEN ((uint64_t)100000000L) -#define dstr(x) ((double)((int64_t)(x)) / SATOSHIDEN) +#define dstr(x) ((double)((x)) / SATOSHIDEN) #define MAX_JSON_FIELD 4096 // on the big side #ifdef __cplusplus From 0c9a957a043c13308c0ed759dffa1838064c6d1b Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 28 Jan 2018 17:07:35 +0400 Subject: [PATCH 158/183] Revert --- iguana/exchanges/LP_commands.c | 2 +- iguana/exchanges/LP_instantdex.c | 2 +- iguana/exchanges/LP_ordermatch.c | 6 +++--- iguana/exchanges/LP_portfolio.c | 2 +- iguana/exchanges/LP_prices.c | 2 +- iguana/exchanges/LP_remember.c | 2 +- iguana/exchanges/LP_signatures.c | 4 ++-- iguana/exchanges/LP_stats.c | 4 ++-- iguana/exchanges/LP_tradebots.c | 4 ++-- 9 files changed, 14 insertions(+), 14 deletions(-) diff --git a/iguana/exchanges/LP_commands.c b/iguana/exchanges/LP_commands.c index 72a71e648..94186c659 100644 --- a/iguana/exchanges/LP_commands.c +++ b/iguana/exchanges/LP_commands.c @@ -681,7 +681,7 @@ jpg(srcfile, destfile, power2=7, password, data="", required, ind=0)\n\ jaddnum(retjson,"timestamp",time(NULL)); jaddnum(retjson,"bid",bid); jaddnum(retjson,"ask",ask); - jaddnum(retjson,"price",dstr(SATOSHIDEN * price)); + jaddnum(retjson,"price",price); return(jprint(retjson,1)); } /*else if ( strcmp(method,"getpeers") == 0 ) diff --git a/iguana/exchanges/LP_instantdex.c b/iguana/exchanges/LP_instantdex.c index f06cd9cbc..f0b6aa50a 100644 --- a/iguana/exchanges/LP_instantdex.c +++ b/iguana/exchanges/LP_instantdex.c @@ -567,7 +567,7 @@ cJSON *LP_swapstats_item(struct LP_swapstats *sp,int32_t iambob) jaddnum(item,"satoshis",sp->Q.satoshis); jaddstr(item,"rel",sp->Q.destcoin); jaddnum(item,"destsatoshis",sp->Q.destsatoshis); - jaddnum(item,"price",dstr(SATOSHIDEN * (sp->Q.destsatoshis/((double)sp->Q.satoshis+1)))); + jaddnum(item,"price",sp->Q.destsatoshis/((double)sp->Q.satoshis+1)); if ( LP_swap_finished(sp,1) == 0 ) { jaddnum(item,"finished",sp->finished); diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 615cb1057..bb22c383d 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -181,7 +181,7 @@ double LP_quote_validate(struct LP_utxoinfo *autxo,struct LP_utxoinfo *butxo,str return(-33); } if ( qp->satoshis != 0 ) - qprice = ((double)qp->destsatoshis / (qp->satoshis-qp->txfee)) + 0.000000049; + qprice = ((double)qp->destsatoshis / (qp->satoshis-qp->txfee)); LP_txfees(&txfee,&desttxfee,qp->srccoin,qp->destcoin); if ( txfee < qp->txfee ) txfee = qp->txfee; @@ -846,7 +846,7 @@ struct LP_quoteinfo *LP_trades_gotrequest(void *ctx,struct LP_quoteinfo *qp,stru LP_abutxo_set(autxo,butxo,qp); if ( bits256_nonz(qp->srchash) == 0 || bits256_cmp(qp->srchash,G.LP_mypub25519) == 0 ) { - qprice = (double)qp->destsatoshis / (qp->satoshis - qp->txfee) + 0.000000049; + qprice = (double)qp->destsatoshis / (qp->satoshis - qp->txfee); strcpy(qp->gui,G.gui); strcpy(qp->coinaddr,coin->smartaddr); strcpy(butxo->coinaddr,coin->smartaddr); @@ -980,7 +980,7 @@ int32_t LP_trades_bestpricecheck(void *ctx,struct LP_trade *tp) //printf("check bestprice %.8f vs new price %.8f\n",tp->bestprice,(double)Q.destsatoshis/Q.satoshis); if ( Q.satoshis != 0 && (pubp= LP_pubkeyadd(Q.srchash)) != 0 )//(qprice= LP_trades_alicevalidate(ctx,&Q)) > 0. ) { - qprice = (double)Q.destsatoshis / (Q.satoshis - Q.txfee) + 0.000000049; + qprice = (double)Q.destsatoshis / (Q.satoshis - Q.txfee); LP_aliceid(Q.tradeid,tp->aliceid,"reserved",0,0); if ( (retstr= LP_quotereceived(&Q)) != 0 ) free(retstr); diff --git a/iguana/exchanges/LP_portfolio.c b/iguana/exchanges/LP_portfolio.c index 49db78608..ead40b27c 100644 --- a/iguana/exchanges/LP_portfolio.c +++ b/iguana/exchanges/LP_portfolio.c @@ -71,7 +71,7 @@ cJSON *LP_portfolio_entry(struct iguana_info *coin) jaddstr(item,"coin",coin->symbol); jaddstr(item,"address",coin->smartaddr); jaddnum(item,"amount",dstr(coin->maxamount)); - jaddnum(item,"price",dstr(SATOSHIDEN * coin->price_kmd)); + jaddnum(item,"price",coin->price_kmd); jaddnum(item,"kmd_equiv",dstr(coin->kmd_equiv)); jaddnum(item,"perc",coin->perc); jaddnum(item,"goal",coin->goal); diff --git a/iguana/exchanges/LP_prices.c b/iguana/exchanges/LP_prices.c index f67bffd8c..cee20a5d2 100644 --- a/iguana/exchanges/LP_prices.c +++ b/iguana/exchanges/LP_prices.c @@ -741,7 +741,7 @@ cJSON *LP_orderbookjson(char *symbol,struct LP_orderbookentry *op) { jaddstr(item,"coin",symbol); jaddstr(item,"address",op->coinaddr); - jaddnum(item,"price",dstr(SATOSHIDEN * op->price)); + jaddnum(item,"price",op->price); jaddnum(item,"numutxos",op->numutxos); jaddnum(item,"avevolume",dstr(op->avesatoshis)*0.8); jaddnum(item,"maxvolume",dstr(op->maxsatoshis)*0.8); diff --git a/iguana/exchanges/LP_remember.c b/iguana/exchanges/LP_remember.c index b88128dbb..8c50de4fe 100644 --- a/iguana/exchanges/LP_remember.c +++ b/iguana/exchanges/LP_remember.c @@ -1399,7 +1399,7 @@ char *LP_recent_swaps(int32_t limit) subitem = cJSON_CreateObject(); jaddnum(subitem,base,srcamount); jaddnum(subitem,rel,destamount); - jaddnum(subitem,"price",dstr(SATOSHIDEN * -destamount/srcamount)); + jaddnum(subitem,"price",-destamount/srcamount); jaddi(item,subitem); } } else printf("base.%p rel.%p statusstr.%p baseind.%d relind.%d\n",base,rel,statusstr,baseind,relind); diff --git a/iguana/exchanges/LP_signatures.c b/iguana/exchanges/LP_signatures.c index 1daae27b6..31870fad2 100644 --- a/iguana/exchanges/LP_signatures.c +++ b/iguana/exchanges/LP_signatures.c @@ -92,7 +92,7 @@ cJSON *LP_quotejson(struct LP_quoteinfo *qp) if ( qp->satoshis != 0 ) { price = (double)qp->destsatoshis / (qp->satoshis - qp->txfee); - jaddnum(retjson,"price",dstr(SATOSHIDEN * price)); + jaddnum(retjson,"price",price); } } if ( qp->R.requestid != 0 ) @@ -405,7 +405,7 @@ char *LP_pricepings(void *ctx,char *myipaddr,int32_t pubsock,char *base,char *re jaddstr(reqjson,"base",base); jaddstr(reqjson,"rel",rel); price64 = price * SATOSHIDEN + 0.0000000049; - jaddnum(reqjson,"price",dstr(price64)); + jaddnum(reqjson,"price",price); jadd64bits(reqjson,"price64",price64); jaddstr(reqjson,"method","postprice"); timestamp = (uint32_t)time(NULL); diff --git a/iguana/exchanges/LP_stats.c b/iguana/exchanges/LP_stats.c index 54bd0c918..1bce64fde 100644 --- a/iguana/exchanges/LP_stats.c +++ b/iguana/exchanges/LP_stats.c @@ -556,7 +556,7 @@ cJSON *LP_swapstats_json(struct LP_swapstats *sp) jaddbits256(item,"dest",sp->Q.desthash); jaddstr(item,"rel",sp->Q.destcoin); jaddnum(item,"relvol",dstr(sp->Q.destsatoshis)); - jaddnum(item,"price",dstr(SATOSHIDEN * sp->qprice)); + jaddnum(item,"price",sp->qprice); jaddnum(item,"requestid",sp->Q.R.requestid); jaddnum(item,"quoteid",sp->Q.R.quoteid); jaddnum(item,"finished",sp->finished); @@ -823,7 +823,7 @@ char *LP_ticker(char *refbase,char *refrel) jaddnum(retitem,"timestamp",juint(item,"timestamp")); jaddnum(retitem,base,basevol); jaddnum(retitem,rel,relvol); - jaddnum(retitem,"price",dstr(SATOSHIDEN * (relvol/basevol))); + jaddnum(retitem,"price",relvol/basevol); } jaddi(retjson,retitem); } diff --git a/iguana/exchanges/LP_tradebots.c b/iguana/exchanges/LP_tradebots.c index 6e1bb749a..39526c2be 100644 --- a/iguana/exchanges/LP_tradebots.c +++ b/iguana/exchanges/LP_tradebots.c @@ -142,13 +142,13 @@ cJSON *LP_tradebot_tradejson(struct LP_tradebot_trade *tp,int32_t dispflag) { if ( dispflag > 0 ) { - jaddnum(item,"price",dstr(SATOSHIDEN * (tp->relvol/tp->basevol))); + jaddnum(item,"price",tp->relvol/tp->basevol); jaddnum(item,"volume",tp->relvol); } else { price = LP_pricevol_invert(&basevol,tp->relvol / tp->basevol,tp->relvol); - jaddnum(item,"price",dstr(SATOSHIDEN * price)); + jaddnum(item,"price",price); jaddnum(item,"volume",basevol); } } From f5a6d664c7c8f0f1158ef9f3f4878e74ef6aedfe Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 28 Jan 2018 17:13:52 +0400 Subject: [PATCH 159/183] Test --- crypto777/cJSON.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/crypto777/cJSON.c b/crypto777/cJSON.c index d48798c74..071c09e83 100755 --- a/crypto777/cJSON.c +++ b/crypto777/cJSON.c @@ -504,14 +504,18 @@ static cJSON_bool print_number(const cJSON * const item, printbuffer * const out } else { + if ( fabs(d - (int64_t)d) < 0.0000001 ) + length = sprintf((char*)number_buffer, "%llu", (long long)d); /* Try 8 decimal places of precision to avoid nonsignificant nonzero digits */ - length = sprintf((char*)number_buffer, "%1.8g", d); + else length = sprintf((char*)number_buffer, "%0.8f", d); /* Check whether the original double can be recovered */ if ((sscanf((char*)number_buffer, "%lg", &test) != 1) || ((double)test != d)) { + if ( fabs(d - (int64_t)d) < 0.0000001 ) + length = sprintf((char*)number_buffer, "%llu", (long long)d); /* If not, print with 8 decimal places of precision */ - length = sprintf((char*)number_buffer, "%1.8g", d); + else length = sprintf((char*)number_buffer, "%0.8f", d); } } From 9d9bb0657112bf9d7f3d32b78681efd483230550 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 28 Jan 2018 17:23:39 +0400 Subject: [PATCH 160/183] Test --- crypto777/OS_portable.h | 2 +- iguana/exchanges/mm.c | 5 +++++ includes/cJSON.h | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/crypto777/OS_portable.h b/crypto777/OS_portable.h index 362432e8d..8c109e5d0 100755 --- a/crypto777/OS_portable.h +++ b/crypto777/OS_portable.h @@ -115,7 +115,7 @@ int32_t hseek(HUFF *hp,int32_t offset,int32_t mode); #define GENESIS_SECRET "It was a bright cold day in April, and the clocks were striking thirteen." #define SATOSHIDEN ((uint64_t)100000000L) -#define dstr(x) ((double)((x)) / SATOSHIDEN) +#define dstr(x) ((double)(x) / SATOSHIDEN) #define SMALLVAL 0.000000000000001 diff --git a/iguana/exchanges/mm.c b/iguana/exchanges/mm.c index db8bc57b7..a0641f839 100644 --- a/iguana/exchanges/mm.c +++ b/iguana/exchanges/mm.c @@ -115,6 +115,11 @@ int main(int argc, const char * argv[]) { char dirname[512],*passphrase; double incr; cJSON *retjson; OS_init(); + { + cJSON *test = cJSON_CreateObject(); + jaddnum(test,"test",-5); + printf("test (%s)\n",jprint(test,0)); + } if ( strstr(argv[0],"btc2kmd") != 0 && argv[1] != 0 ) { uint8_t addrtype,rmd160[20],rmd160b[20]; char coinaddr[64],coinaddr2[64]; diff --git a/includes/cJSON.h b/includes/cJSON.h index 999f5ce21..db9b2fc72 100755 --- a/includes/cJSON.h +++ b/includes/cJSON.h @@ -31,7 +31,7 @@ #include "../crypto777/OS_portable.h" #define SATOSHIDEN ((uint64_t)100000000L) -#define dstr(x) ((double)((x)) / SATOSHIDEN) +#define dstr(x) ((double)(x) / SATOSHIDEN) #define MAX_JSON_FIELD 4096 // on the big side #ifdef __cplusplus From d649267c1565af0cfa2d6b9aeaeae7f9c6247a7f Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 28 Jan 2018 17:26:36 +0400 Subject: [PATCH 161/183] Test --- crypto777/cJSON.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/crypto777/cJSON.c b/crypto777/cJSON.c index 071c09e83..11cae1bc4 100755 --- a/crypto777/cJSON.c +++ b/crypto777/cJSON.c @@ -505,17 +505,19 @@ static cJSON_bool print_number(const cJSON * const item, printbuffer * const out else { if ( fabs(d - (int64_t)d) < 0.0000001 ) - length = sprintf((char*)number_buffer, "%llu", (long long)d); + length = sprintf((char *)number_buffer, "%llu", (long long)d); /* Try 8 decimal places of precision to avoid nonsignificant nonzero digits */ - else length = sprintf((char*)number_buffer, "%0.8f", d); - + else length = sprintf((char *)number_buffer, "%0.8f", d); + printf("d A -> (%s)\n",number_buffer); + /* Check whether the original double can be recovered */ - if ((sscanf((char*)number_buffer, "%lg", &test) != 1) || ((double)test != d)) + if ((sscanf((char *)number_buffer, "%lg", &test) != 1) || ((double)test != d)) { if ( fabs(d - (int64_t)d) < 0.0000001 ) - length = sprintf((char*)number_buffer, "%llu", (long long)d); + length = sprintf((char *)number_buffer, "%llu", (long long)d); /* If not, print with 8 decimal places of precision */ - else length = sprintf((char*)number_buffer, "%0.8f", d); + else length = sprintf((char *)number_buffer, "%0.8f", d); + printf("d B -> (%s)\n",number_buffer); } } From e0df441f30b1e89d58dbde109c352e98b3892c25 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 28 Jan 2018 17:29:36 +0400 Subject: [PATCH 162/183] Test --- crypto777/cJSON.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crypto777/cJSON.c b/crypto777/cJSON.c index 11cae1bc4..ce6fcb4d1 100755 --- a/crypto777/cJSON.c +++ b/crypto777/cJSON.c @@ -343,7 +343,7 @@ loop_end: { item->valueint = (int)number; } - + printf("number %f -> %f %llu\n",number,item->valuedouble,(long long)item->valueint); item->type = cJSON_Number; input_buffer->offset += (size_t)(after_end - number_c_string); From 21337a79efa3d89b2fb186ab3f58bdc2b14384c7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 28 Jan 2018 17:33:44 +0400 Subject: [PATCH 163/183] Test --- crypto777/cJSON.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/crypto777/cJSON.c b/crypto777/cJSON.c index ce6fcb4d1..6603c04bc 100755 --- a/crypto777/cJSON.c +++ b/crypto777/cJSON.c @@ -343,7 +343,7 @@ loop_end: { item->valueint = (int)number; } - printf("number %f -> %f %llu\n",number,item->valuedouble,(long long)item->valueint); + //printf("number %f -> %f %llu\n",number,item->valuedouble,(long long)item->valueint); item->type = cJSON_Number; input_buffer->offset += (size_t)(after_end - number_c_string); @@ -505,7 +505,7 @@ static cJSON_bool print_number(const cJSON * const item, printbuffer * const out else { if ( fabs(d - (int64_t)d) < 0.0000001 ) - length = sprintf((char *)number_buffer, "%llu", (long long)d); + length = sprintf((char *)number_buffer, "%llu", (long long)item->valueint); /* Try 8 decimal places of precision to avoid nonsignificant nonzero digits */ else length = sprintf((char *)number_buffer, "%0.8f", d); printf("d A -> (%s)\n",number_buffer); @@ -514,7 +514,7 @@ static cJSON_bool print_number(const cJSON * const item, printbuffer * const out if ((sscanf((char *)number_buffer, "%lg", &test) != 1) || ((double)test != d)) { if ( fabs(d - (int64_t)d) < 0.0000001 ) - length = sprintf((char *)number_buffer, "%llu", (long long)d); + length = sprintf((char *)number_buffer, "%llu", (long long)item->valueint); /* If not, print with 8 decimal places of precision */ else length = sprintf((char *)number_buffer, "%0.8f", d); printf("d B -> (%s)\n",number_buffer); From d33f77fc4b5f7606786861c231ee6487baefeaf2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 28 Jan 2018 17:35:29 +0400 Subject: [PATCH 164/183] Revert cJSON --- crypto777/cJSON.c | 3414 ++++++++------------------------------------- includes/cJSON.h | 283 ++-- 2 files changed, 646 insertions(+), 3051 deletions(-) diff --git a/crypto777/cJSON.c b/crypto777/cJSON.c index 6603c04bc..54df964f5 100755 --- a/crypto777/cJSON.c +++ b/crypto777/cJSON.c @@ -1,14 +1,17 @@ /* - Copyright (c) 2009-2017 Dave Gamble and cJSON contributors + Copyright (c) 2009 Dave Gamble + Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -20,2931 +23,648 @@ /* cJSON */ /* JSON parser in C. */ - -/* disable warnings about old C89 functions in MSVC */ -#if !defined(_CRT_SECURE_NO_DEPRECATE) && defined(_MSC_VER) -#define _CRT_SECURE_NO_DEPRECATE -#endif - -#ifdef __GNUC__ -#pragma GCC visibility push(default) -#endif -#if defined(_MSC_VER) -#pragma warning (push) -/* disable warning about single line comments in system headers */ -#pragma warning (disable : 4001) -#endif - -#include -#include #include -#include -#include -#include -#include - -#ifdef ENABLE_LOCALES -#include -#endif - -#if defined(_MSC_VER) -#pragma warning (pop) -#endif -#ifdef __GNUC__ -#pragma GCC visibility pop -#endif #include "../includes/cJSON.h" -/* define our own boolean type */ -#define true ((cJSON_bool)1) -#define false ((cJSON_bool)0) - -typedef struct { - const unsigned char *json; - size_t position; -} error; -static error global_error = { NULL, 0 }; - -long stripquotes(char *str) -{ - long len,offset; - if ( str == 0 ) - return(0); - len = strlen(str); - if ( str[0] == '"' && str[len-1] == '"' ) - str[len-1] = 0, offset = 1; - else offset = 0; - return(offset); -} - -CJSON_PUBLIC(const char *) cJSON_GetErrorPtr(void) -{ - return (const char*) (global_error.json + global_error.position); -} - -CJSON_PUBLIC(char *) cJSON_GetStringValue(cJSON *item) { - if (!cJSON_IsString(item)) { - return NULL; - } - - return item->valuestring; -} - -/* This is a safeguard to prevent copy-pasters from using incompatible C and header files */ -#if (CJSON_VERSION_MAJOR != 1) || (CJSON_VERSION_MINOR != 7) || (CJSON_VERSION_PATCH != 1) -#error cJSON.h and cJSON.c have different versions. Make sure that both have the same. -#endif - -CJSON_PUBLIC(const char*) cJSON_Version(void) -{ - static char version[15]; - sprintf(version, "%i.%i.%i", CJSON_VERSION_MAJOR, CJSON_VERSION_MINOR, CJSON_VERSION_PATCH); - - return version; -} - -/* Case insensitive string comparison, doesn't consider two NULL pointers equal though */ -static int case_insensitive_strcmp(const unsigned char *string1, const unsigned char *string2) -{ - if ((string1 == NULL) || (string2 == NULL)) - { - return 1; - } - - if (string1 == string2) - { - return 0; - } - - for(; tolower(*string1) == tolower(*string2); (void)string1++, string2++) - { - if (*string1 == '\0') - { - return 0; - } - } - - return tolower(*string1) - tolower(*string2); -} - -typedef struct internal_hooks -{ - void *(*allocate)(size_t size); - void (*deallocate)(void *pointer); - void *(*reallocate)(void *pointer, size_t size); -} internal_hooks; - -#if defined(_MSC_VER) -/* work around MSVC error C2322: '...' address of dillimport '...' is not static */ -static void *internal_malloc(size_t size) -{ - return malloc(size); -} -static void internal_free(void *pointer) -{ - free(pointer); -} -static void *internal_realloc(void *pointer, size_t size) -{ - return realloc(pointer, size); -} -#else -#define internal_malloc malloc -#define internal_free free -#define internal_realloc realloc -#endif - -static internal_hooks global_hooks = { internal_malloc, internal_free, internal_realloc }; - -static unsigned char* cJSON_strdup(const unsigned char* string, const internal_hooks * const hooks) -{ - size_t length = 0; - unsigned char *copy = NULL; - - if (string == NULL) - { - return NULL; - } - - length = strlen((const char*)string) + sizeof(""); - copy = (unsigned char*)hooks->allocate(length); - if (copy == NULL) - { - return NULL; - } - memcpy(copy, string, length); - - return copy; -} - -CJSON_PUBLIC(void) cJSON_InitHooks(cJSON_Hooks* hooks) -{ - if (hooks == NULL) - { - /* Reset hooks */ - global_hooks.allocate = malloc; - global_hooks.deallocate = free; - global_hooks.reallocate = realloc; - return; - } - - global_hooks.allocate = malloc; - if (hooks->malloc_fn != NULL) - { - global_hooks.allocate = hooks->malloc_fn; - } - - global_hooks.deallocate = free; - if (hooks->free_fn != NULL) - { - global_hooks.deallocate = hooks->free_fn; - } - - /* use realloc only if both free and malloc are used */ - global_hooks.reallocate = NULL; - if ((global_hooks.allocate == malloc) && (global_hooks.deallocate == free)) - { - global_hooks.reallocate = realloc; - } -} - -/* Internal constructor. */ -static cJSON *cJSON_New_Item(const internal_hooks * const hooks) -{ - cJSON* node = (cJSON*)hooks->allocate(sizeof(cJSON)); - if (node) - { - memset(node, '\0', sizeof(cJSON)); - } - - return node; -} - -/* Delete a cJSON structure. */ -CJSON_PUBLIC(void) cJSON_Delete(cJSON *item) -{ - cJSON *next = NULL; - while (item != NULL) - { - next = item->next; - if (!(item->type & cJSON_IsReference) && (item->child != NULL)) - { - cJSON_Delete(item->child); - } - if (!(item->type & cJSON_IsReference) && (item->valuestring != NULL)) - { - global_hooks.deallocate(item->valuestring); - } - if (!(item->type & cJSON_StringIsConst) && (item->string != NULL)) - { - global_hooks.deallocate(item->string); - } - global_hooks.deallocate(item); - item = next; - } -} - -/* get the decimal point character of the current locale */ -static unsigned char get_decimal_point(void) -{ -#ifdef ENABLE_LOCALES - struct lconv *lconv = localeconv(); - return (unsigned char) lconv->decimal_point[0]; -#else - return '.'; -#endif -} - -typedef struct -{ - const unsigned char *content; - size_t length; - size_t offset; - size_t depth; /* How deeply nested (in arrays/objects) is the input at the current offset. */ - internal_hooks hooks; -} parse_buffer; - -/* check if the given size is left to read in a given parse buffer (starting with 1) */ -#define can_read(buffer, size) ((buffer != NULL) && (((buffer)->offset + size) <= (buffer)->length)) -/* check if the buffer can be accessed at the given index (starting with 0) */ -#define can_access_at_index(buffer, index) ((buffer != NULL) && (((buffer)->offset + index) < (buffer)->length)) -#define cannot_access_at_index(buffer, index) (!can_access_at_index(buffer, index)) -/* get a pointer to the buffer at the position */ -#define buffer_at_offset(buffer) ((buffer)->content + (buffer)->offset) - -/* Parse the input text to generate a number, and populate the result into item. */ -static cJSON_bool parse_number(cJSON * const item, parse_buffer * const input_buffer) -{ - double number = 0; - unsigned char *after_end = NULL; - unsigned char number_c_string[64]; - unsigned char decimal_point = get_decimal_point(); - size_t i = 0; - - if ((input_buffer == NULL) || (input_buffer->content == NULL)) - { - return false; - } - - /* copy the number into a temporary buffer and replace '.' with the decimal point - * of the current locale (for strtod) - * This also takes care of '\0' not necessarily being available for marking the end of the input */ - for (i = 0; (i < (sizeof(number_c_string) - 1)) && can_access_at_index(input_buffer, i); i++) - { - switch (buffer_at_offset(input_buffer)[i]) - { - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - case '+': - case '-': - case 'e': - case 'E': - number_c_string[i] = buffer_at_offset(input_buffer)[i]; - break; - - case '.': - number_c_string[i] = decimal_point; - break; - - default: - goto loop_end; - } - } -loop_end: - number_c_string[i] = '\0'; - - number = strtod((const char*)number_c_string, (char**)&after_end); - if (number_c_string == after_end) - { - return false; /* parse_error */ - } - - item->valuedouble = number; - - /* use saturation in case of overflow */ - if (number >= INT_MAX) - { - item->valueint = INT_MAX; - } - else if (number <= INT_MIN) - { - item->valueint = INT_MIN; - } - else - { - item->valueint = (int)number; - } - //printf("number %f -> %f %llu\n",number,item->valuedouble,(long long)item->valueint); - item->type = cJSON_Number; - - input_buffer->offset += (size_t)(after_end - number_c_string); - return true; -} - -/* don't ask me, but the original cJSON_SetNumberValue returns an integer or double */ -CJSON_PUBLIC(double) cJSON_SetNumberHelper(cJSON *object, double number) -{ - if (number >= INT_MAX) - { - object->valueint = INT_MAX; - } - else if (number <= INT_MIN) - { - object->valueint = INT_MIN; - } - else - { - object->valueint = (int)number; - } - - return object->valuedouble = number; -} - -typedef struct -{ - unsigned char *buffer; - size_t length; - size_t offset; - size_t depth; /* current nesting depth (for formatted printing) */ - cJSON_bool noalloc; - cJSON_bool format; /* is this print a formatted print */ - internal_hooks hooks; -} printbuffer; - -/* realloc printbuffer if necessary to have at least "needed" bytes more */ -static unsigned char* ensure(printbuffer * const p, size_t needed) -{ - unsigned char *newbuffer = NULL; - size_t newsize = 0; - - if ((p == NULL) || (p->buffer == NULL)) - { - return NULL; - } - - if ((p->length > 0) && (p->offset >= p->length)) - { - /* make sure that offset is valid */ - return NULL; - } - - if (needed > INT_MAX) - { - /* sizes bigger than INT_MAX are currently not supported */ - return NULL; - } - - needed += p->offset + 1; - if (needed <= p->length) - { - return p->buffer + p->offset; - } - - if (p->noalloc) { - return NULL; - } - - /* calculate new buffer size */ - if (needed > (INT_MAX / 2)) - { - /* overflow of int, use INT_MAX if possible */ - if (needed <= INT_MAX) - { - newsize = INT_MAX; - } - else - { - return NULL; - } - } - else - { - newsize = needed * 2; - } - - if (p->hooks.reallocate != NULL) - { - /* reallocate with realloc if available */ - newbuffer = (unsigned char*)p->hooks.reallocate(p->buffer, newsize); - if (newbuffer == NULL) - { - p->hooks.deallocate(p->buffer); - p->length = 0; - p->buffer = NULL; - - return NULL; - } - } - else - { - /* otherwise reallocate manually */ - newbuffer = (unsigned char*)p->hooks.allocate(newsize); - if (!newbuffer) - { - p->hooks.deallocate(p->buffer); - p->length = 0; - p->buffer = NULL; - - return NULL; - } - if (newbuffer) - { - memcpy(newbuffer, p->buffer, p->offset + 1); - } - p->hooks.deallocate(p->buffer); - } - p->length = newsize; - p->buffer = newbuffer; - - return newbuffer + p->offset; -} - -/* calculate the new length of the string in a printbuffer and update the offset */ -static void update_offset(printbuffer * const buffer) -{ - const unsigned char *buffer_pointer = NULL; - if ((buffer == NULL) || (buffer->buffer == NULL)) - { - return; - } - buffer_pointer = buffer->buffer + buffer->offset; - - buffer->offset += strlen((const char*)buffer_pointer); -} - -/* Render the number nicely from the given item into a string. */ -static cJSON_bool print_number(const cJSON * const item, printbuffer * const output_buffer) -{ - unsigned char *output_pointer = NULL; - double d = item->valuedouble; - int length = 0; - size_t i = 0; - unsigned char number_buffer[26]; /* temporary buffer to print the number into */ - unsigned char decimal_point = get_decimal_point(); - double test; - - if (output_buffer == NULL) - { - return false; - } - - /* This checks for NaN and Infinity */ - if ((d * 0) != 0) - { - length = sprintf((char*)number_buffer, "null"); - } - else - { - if ( fabs(d - (int64_t)d) < 0.0000001 ) - length = sprintf((char *)number_buffer, "%llu", (long long)item->valueint); - /* Try 8 decimal places of precision to avoid nonsignificant nonzero digits */ - else length = sprintf((char *)number_buffer, "%0.8f", d); - printf("d A -> (%s)\n",number_buffer); - - /* Check whether the original double can be recovered */ - if ((sscanf((char *)number_buffer, "%lg", &test) != 1) || ((double)test != d)) - { - if ( fabs(d - (int64_t)d) < 0.0000001 ) - length = sprintf((char *)number_buffer, "%llu", (long long)item->valueint); - /* If not, print with 8 decimal places of precision */ - else length = sprintf((char *)number_buffer, "%0.8f", d); - printf("d B -> (%s)\n",number_buffer); - } - } - - /* sprintf failed or buffer overrun occured */ - if ((length < 0) || (length > (int)(sizeof(number_buffer) - 1))) - { - return false; - } - - /* reserve appropriate space in the output */ - output_pointer = ensure(output_buffer, (size_t)length + sizeof("")); - if (output_pointer == NULL) - { - return false; - } - - /* copy the printed number to the output and replace locale - * dependent decimal point with '.' */ - for (i = 0; i < ((size_t)length); i++) - { - if (number_buffer[i] == decimal_point) - { - output_pointer[i] = '.'; - continue; - } - - output_pointer[i] = number_buffer[i]; - } - output_pointer[i] = '\0'; - - output_buffer->offset += (size_t)length; - - return true; -} - -/* parse 4 digit hexadecimal number */ -static unsigned parse_hex4(const unsigned char * const input) -{ - unsigned int h = 0; - size_t i = 0; - - for (i = 0; i < 4; i++) - { - /* parse digit */ - if ((input[i] >= '0') && (input[i] <= '9')) - { - h += (unsigned int) input[i] - '0'; - } - else if ((input[i] >= 'A') && (input[i] <= 'F')) - { - h += (unsigned int) 10 + input[i] - 'A'; - } - else if ((input[i] >= 'a') && (input[i] <= 'f')) - { - h += (unsigned int) 10 + input[i] - 'a'; - } - else /* invalid */ - { - return 0; - } - - if (i < 3) - { - /* shift left to make place for the next nibble */ - h = h << 4; - } - } - - return h; -} - -/* converts a UTF-16 literal to UTF-8 - * A literal can be one or two sequences of the form \uXXXX */ -static unsigned char utf16_literal_to_utf8(const unsigned char * const input_pointer, const unsigned char * const input_end, unsigned char **output_pointer) -{ - long unsigned int codepoint = 0; - unsigned int first_code = 0; - const unsigned char *first_sequence = input_pointer; - unsigned char utf8_length = 0; - unsigned char utf8_position = 0; - unsigned char sequence_length = 0; - unsigned char first_byte_mark = 0; - - if ((input_end - first_sequence) < 6) - { - /* input ends unexpectedly */ - goto fail; - } - - /* get the first utf16 sequence */ - first_code = parse_hex4(first_sequence + 2); - - /* check that the code is valid */ - if (((first_code >= 0xDC00) && (first_code <= 0xDFFF))) - { - goto fail; - } - - /* UTF16 surrogate pair */ - if ((first_code >= 0xD800) && (first_code <= 0xDBFF)) - { - const unsigned char *second_sequence = first_sequence + 6; - unsigned int second_code = 0; - sequence_length = 12; /* \uXXXX\uXXXX */ - - if ((input_end - second_sequence) < 6) - { - /* input ends unexpectedly */ - goto fail; - } - - if ((second_sequence[0] != '\\') || (second_sequence[1] != 'u')) - { - /* missing second half of the surrogate pair */ - goto fail; - } - - /* get the second utf16 sequence */ - second_code = parse_hex4(second_sequence + 2); - /* check that the code is valid */ - if ((second_code < 0xDC00) || (second_code > 0xDFFF)) - { - /* invalid second half of the surrogate pair */ - goto fail; - } - - - /* calculate the unicode codepoint from the surrogate pair */ - codepoint = 0x10000 + (((first_code & 0x3FF) << 10) | (second_code & 0x3FF)); - } - else - { - sequence_length = 6; /* \uXXXX */ - codepoint = first_code; - } - - /* encode as UTF-8 - * takes at maximum 4 bytes to encode: - * 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx */ - if (codepoint < 0x80) - { - /* normal ascii, encoding 0xxxxxxx */ - utf8_length = 1; - } - else if (codepoint < 0x800) - { - /* two bytes, encoding 110xxxxx 10xxxxxx */ - utf8_length = 2; - first_byte_mark = 0xC0; /* 11000000 */ - } - else if (codepoint < 0x10000) - { - /* three bytes, encoding 1110xxxx 10xxxxxx 10xxxxxx */ - utf8_length = 3; - first_byte_mark = 0xE0; /* 11100000 */ - } - else if (codepoint <= 0x10FFFF) - { - /* four bytes, encoding 1110xxxx 10xxxxxx 10xxxxxx 10xxxxxx */ - utf8_length = 4; - first_byte_mark = 0xF0; /* 11110000 */ - } - else - { - /* invalid unicode codepoint */ - goto fail; - } - - /* encode as utf8 */ - for (utf8_position = (unsigned char)(utf8_length - 1); utf8_position > 0; utf8_position--) - { - /* 10xxxxxx */ - (*output_pointer)[utf8_position] = (unsigned char)((codepoint | 0x80) & 0xBF); - codepoint >>= 6; - } - /* encode first byte */ - if (utf8_length > 1) - { - (*output_pointer)[0] = (unsigned char)((codepoint | first_byte_mark) & 0xFF); - } - else - { - (*output_pointer)[0] = (unsigned char)(codepoint & 0x7F); - } - - *output_pointer += utf8_length; - - return sequence_length; - -fail: - return 0; -} - -/* Parse the input text into an unescaped cinput, and populate item. */ -static cJSON_bool parse_string(cJSON * const item, parse_buffer * const input_buffer) -{ - const unsigned char *input_pointer = buffer_at_offset(input_buffer) + 1; - const unsigned char *input_end = buffer_at_offset(input_buffer) + 1; - unsigned char *output_pointer = NULL; - unsigned char *output = NULL; - - /* not a string */ - if (buffer_at_offset(input_buffer)[0] != '\"') - { - goto fail; - } - - { - /* calculate approximate size of the output (overestimate) */ - size_t allocation_length = 0; - size_t skipped_bytes = 0; - while (((size_t)(input_end - input_buffer->content) < input_buffer->length) && (*input_end != '\"')) - { - /* is escape sequence */ - if (input_end[0] == '\\') - { - if ((size_t)(input_end + 1 - input_buffer->content) >= input_buffer->length) - { - /* prevent buffer overflow when last input character is a backslash */ - goto fail; - } - skipped_bytes++; - input_end++; - } - input_end++; - } - if (((size_t)(input_end - input_buffer->content) >= input_buffer->length) || (*input_end != '\"')) - { - goto fail; /* string ended unexpectedly */ - } - - /* This is at most how much we need for the output */ - allocation_length = (size_t) (input_end - buffer_at_offset(input_buffer)) - skipped_bytes; - output = (unsigned char*)input_buffer->hooks.allocate(allocation_length + sizeof("")); - if (output == NULL) - { - goto fail; /* allocation failure */ - } - } - - output_pointer = output; - /* loop through the string literal */ - while (input_pointer < input_end) - { - if (*input_pointer != '\\') - { - *output_pointer++ = *input_pointer++; - } - /* escape sequence */ - else - { - unsigned char sequence_length = 2; - if ((input_end - input_pointer) < 1) - { - goto fail; - } - - switch (input_pointer[1]) - { - case 'b': - *output_pointer++ = '\b'; - break; - case 'f': - *output_pointer++ = '\f'; - break; - case 'n': - *output_pointer++ = '\n'; - break; - case 'r': - *output_pointer++ = '\r'; - break; - case 't': - *output_pointer++ = '\t'; - break; - case '\"': - case '\\': - case '/': - *output_pointer++ = input_pointer[1]; - break; - - /* UTF-16 literal */ - case 'u': - sequence_length = utf16_literal_to_utf8(input_pointer, input_end, &output_pointer); - if (sequence_length == 0) - { - /* failed to convert UTF16-literal to UTF-8 */ - goto fail; - } - break; - - default: - goto fail; - } - input_pointer += sequence_length; - } - } - - /* zero terminate the output */ - *output_pointer = '\0'; - - item->type = cJSON_String; - item->valuestring = (char*)output; - - input_buffer->offset = (size_t) (input_end - input_buffer->content); - input_buffer->offset++; - - return true; - -fail: - if (output != NULL) - { - input_buffer->hooks.deallocate(output); - } - - if (input_pointer != NULL) - { - input_buffer->offset = (size_t)(input_pointer - input_buffer->content); - } - - return false; -} - -/* Render the cstring provided to an escaped version that can be printed. */ -static cJSON_bool print_string_ptr(const unsigned char * const input, printbuffer * const output_buffer) -{ - const unsigned char *input_pointer = NULL; - unsigned char *output = NULL; - unsigned char *output_pointer = NULL; - size_t output_length = 0; - /* numbers of additional characters needed for escaping */ - size_t escape_characters = 0; - - if (output_buffer == NULL) - { - return false; - } - - /* empty string */ - if (input == NULL) - { - output = ensure(output_buffer, sizeof("\"\"")); - if (output == NULL) - { - return false; - } - strcpy((char*)output, "\"\""); - - return true; - } - - /* set "flag" to 1 if something needs to be escaped */ - for (input_pointer = input; *input_pointer; input_pointer++) - { - switch (*input_pointer) - { - case '\"': - case '\\': - case '\b': - case '\f': - case '\n': - case '\r': - case '\t': - /* one character escape sequence */ - escape_characters++; - break; - default: - if (*input_pointer < 32) - { - /* UTF-16 escape sequence uXXXX */ - escape_characters += 5; - } - break; - } - } - output_length = (size_t)(input_pointer - input) + escape_characters; - - output = ensure(output_buffer, output_length + sizeof("\"\"")); - if (output == NULL) - { - return false; - } - - /* no characters have to be escaped */ - if (escape_characters == 0) - { - output[0] = '\"'; - memcpy(output + 1, input, output_length); - output[output_length + 1] = '\"'; - output[output_length + 2] = '\0'; - - return true; - } - - output[0] = '\"'; - output_pointer = output + 1; - /* copy the string */ - for (input_pointer = input; *input_pointer != '\0'; (void)input_pointer++, output_pointer++) - { - if ((*input_pointer > 31) && (*input_pointer != '\"') && (*input_pointer != '\\')) - { - /* normal character, copy */ - *output_pointer = *input_pointer; - } - else - { - /* character needs to be escaped */ - *output_pointer++ = '\\'; - switch (*input_pointer) - { - case '\\': - *output_pointer = '\\'; - break; - case '\"': - *output_pointer = '\"'; - break; - case '\b': - *output_pointer = 'b'; - break; - case '\f': - *output_pointer = 'f'; - break; - case '\n': - *output_pointer = 'n'; - break; - case '\r': - *output_pointer = 'r'; - break; - case '\t': - *output_pointer = 't'; - break; - default: - /* escape and print as unicode codepoint */ - sprintf((char*)output_pointer, "u%04x", *input_pointer); - output_pointer += 4; - break; - } - } - } - output[output_length + 1] = '\"'; - output[output_length + 2] = '\0'; - - return true; -} - -/* Invoke print_string_ptr (which is useful) on an item. */ -static cJSON_bool print_string(const cJSON * const item, printbuffer * const p) -{ - return print_string_ptr((unsigned char*)item->valuestring, p); -} - -/* Predeclare these prototypes. */ -static cJSON_bool parse_value(cJSON * const item, parse_buffer * const input_buffer); -static cJSON_bool print_value(const cJSON * const item, printbuffer * const output_buffer); -static cJSON_bool parse_array(cJSON * const item, parse_buffer * const input_buffer); -static cJSON_bool print_array(const cJSON * const item, printbuffer * const output_buffer); -static cJSON_bool parse_object(cJSON * const item, parse_buffer * const input_buffer); -static cJSON_bool print_object(const cJSON * const item, printbuffer * const output_buffer); - -/* Utility to jump whitespace and cr/lf */ -static parse_buffer *buffer_skip_whitespace(parse_buffer * const buffer) -{ - if ((buffer == NULL) || (buffer->content == NULL)) - { - return NULL; - } - - while (can_access_at_index(buffer, 0) && (buffer_at_offset(buffer)[0] <= 32)) - { - buffer->offset++; - } - - if (buffer->offset == buffer->length) - { - buffer->offset--; - } - - return buffer; -} - -/* skip the UTF-8 BOM (byte order mark) if it is at the beginning of a buffer */ -static parse_buffer *skip_utf8_bom(parse_buffer * const buffer) -{ - if ((buffer == NULL) || (buffer->content == NULL) || (buffer->offset != 0)) - { - return NULL; - } - - if (can_access_at_index(buffer, 4) && (strncmp((const char*)buffer_at_offset(buffer), "\xEF\xBB\xBF", 3) == 0)) - { - buffer->offset += 3; - } - - return buffer; -} - -/* Parse an object - create a new root, and populate. */ -CJSON_PUBLIC(cJSON *) cJSON_ParseWithOpts(const char *value, const char **return_parse_end, cJSON_bool require_null_terminated) -{ - parse_buffer buffer = { 0, 0, 0, 0, { 0, 0, 0 } }; - cJSON *item = NULL; - - /* reset error position */ - global_error.json = NULL; - global_error.position = 0; - - if (value == NULL) - { - goto fail; - } - - buffer.content = (const unsigned char*)value; - buffer.length = strlen((const char*)value) + sizeof(""); - buffer.offset = 0; - buffer.hooks = global_hooks; - - item = cJSON_New_Item(&global_hooks); - if (item == NULL) /* memory fail */ - { - goto fail; - } - - if (!parse_value(item, buffer_skip_whitespace(skip_utf8_bom(&buffer)))) - { - /* parse failure. ep is set. */ - goto fail; - } - - /* if we require null-terminated JSON without appended garbage, skip and then check for a null terminator */ - if (require_null_terminated) - { - buffer_skip_whitespace(&buffer); - if ((buffer.offset >= buffer.length) || buffer_at_offset(&buffer)[0] != '\0') - { - goto fail; - } - } - if (return_parse_end) - { - *return_parse_end = (const char*)buffer_at_offset(&buffer); - } - - return item; - -fail: - if (item != NULL) - { - cJSON_Delete(item); - } - - if (value != NULL) - { - error local_error; - local_error.json = (const unsigned char*)value; - local_error.position = 0; - - if (buffer.offset < buffer.length) - { - local_error.position = buffer.offset; - } - else if (buffer.length > 0) - { - local_error.position = buffer.length - 1; - } - - if (return_parse_end != NULL) - { - *return_parse_end = (const char*)local_error.json + local_error.position; - } - - global_error = local_error; - } - - return NULL; -} - -/* Default options for cJSON_Parse */ -CJSON_PUBLIC(cJSON *) cJSON_Parse(const char *value) -{ - return cJSON_ParseWithOpts(value, 0, 0); -} - -#define cjson_min(a, b) ((a < b) ? a : b) - -static unsigned char *print(const cJSON * const item, cJSON_bool format, const internal_hooks * const hooks) -{ - static const size_t default_buffer_size = 256; - printbuffer buffer[1]; - unsigned char *printed = NULL; - - memset(buffer, 0, sizeof(buffer)); - - /* create buffer */ - buffer->buffer = (unsigned char*) hooks->allocate(default_buffer_size); - buffer->length = default_buffer_size; - buffer->format = format; - buffer->hooks = *hooks; - if (buffer->buffer == NULL) - { - goto fail; - } - - /* print the value */ - if (!print_value(item, buffer)) - { - goto fail; - } - update_offset(buffer); - - /* check if reallocate is available */ - if (hooks->reallocate != NULL) - { - printed = (unsigned char*) hooks->reallocate(buffer->buffer, buffer->offset + 1); - buffer->buffer = NULL; - if (printed == NULL) { - goto fail; - } - } - else /* otherwise copy the JSON over to a new buffer */ - { - printed = (unsigned char*) hooks->allocate(buffer->offset + 1); - if (printed == NULL) - { - goto fail; - } - memcpy(printed, buffer->buffer, cjson_min(buffer->length, buffer->offset + 1)); - printed[buffer->offset] = '\0'; /* just to be sure */ - - /* free the buffer */ - hooks->deallocate(buffer->buffer); - } - - return printed; - -fail: - if (buffer->buffer != NULL) - { - hooks->deallocate(buffer->buffer); - } - - if (printed != NULL) - { - hooks->deallocate(printed); - } - - return NULL; -} - -/* Render a cJSON item/entity/structure to text. */ -CJSON_PUBLIC(char *) cJSON_Print(const cJSON *item) -{ - return (char*)print(item, true, &global_hooks); -} - -CJSON_PUBLIC(char *) cJSON_PrintUnformatted(const cJSON *item) -{ - return (char*)print(item, false, &global_hooks); -} - -CJSON_PUBLIC(char *) cJSON_PrintBuffered(const cJSON *item, int prebuffer, cJSON_bool fmt) -{ - printbuffer p = { 0, 0, 0, 0, 0, 0, { 0, 0, 0 } }; - - if (prebuffer < 0) - { - return NULL; - } - - p.buffer = (unsigned char*)global_hooks.allocate((size_t)prebuffer); - if (!p.buffer) - { - return NULL; - } - - p.length = (size_t)prebuffer; - p.offset = 0; - p.noalloc = false; - p.format = fmt; - p.hooks = global_hooks; - - if (!print_value(item, &p)) - { - global_hooks.deallocate(p.buffer); - return NULL; - } - - return (char*)p.buffer; -} - -CJSON_PUBLIC(cJSON_bool) cJSON_PrintPreallocated(cJSON *item, char *buf, const int len, const cJSON_bool fmt) -{ - printbuffer p = { 0, 0, 0, 0, 0, 0, { 0, 0, 0 } }; - - if ((len < 0) || (buf == NULL)) - { - return false; - } - - p.buffer = (unsigned char*)buf; - p.length = (size_t)len; - p.offset = 0; - p.noalloc = true; - p.format = fmt; - p.hooks = global_hooks; - - return print_value(item, &p); -} - -/* Parser core - when encountering text, process appropriately. */ -static cJSON_bool parse_value(cJSON * const item, parse_buffer * const input_buffer) -{ - if ((input_buffer == NULL) || (input_buffer->content == NULL)) - { - return false; /* no input */ - } - - /* parse the different types of values */ - /* null */ - if (can_read(input_buffer, 4) && (strncmp((const char*)buffer_at_offset(input_buffer), "null", 4) == 0)) - { - item->type = cJSON_NULL; - input_buffer->offset += 4; - return true; - } - /* false */ - if (can_read(input_buffer, 5) && (strncmp((const char*)buffer_at_offset(input_buffer), "false", 5) == 0)) - { - item->type = cJSON_False; - input_buffer->offset += 5; - return true; - } - /* true */ - if (can_read(input_buffer, 4) && (strncmp((const char*)buffer_at_offset(input_buffer), "true", 4) == 0)) - { - item->type = cJSON_True; - item->valueint = 1; - input_buffer->offset += 4; - return true; - } - /* string */ - if (can_access_at_index(input_buffer, 0) && (buffer_at_offset(input_buffer)[0] == '\"')) - { - return parse_string(item, input_buffer); - } - /* number */ - if (can_access_at_index(input_buffer, 0) && ((buffer_at_offset(input_buffer)[0] == '-') || ((buffer_at_offset(input_buffer)[0] >= '0') && (buffer_at_offset(input_buffer)[0] <= '9')))) - { - return parse_number(item, input_buffer); - } - /* array */ - if (can_access_at_index(input_buffer, 0) && (buffer_at_offset(input_buffer)[0] == '[')) - { - return parse_array(item, input_buffer); - } - /* object */ - if (can_access_at_index(input_buffer, 0) && (buffer_at_offset(input_buffer)[0] == '{')) - { - return parse_object(item, input_buffer); - } - - return false; -} - -/* Render a value to text. */ -static cJSON_bool print_value(const cJSON * const item, printbuffer * const output_buffer) -{ - unsigned char *output = NULL; - - if ((item == NULL) || (output_buffer == NULL)) - { - return false; - } - - switch ((item->type) & 0xFF) - { - case cJSON_NULL: - output = ensure(output_buffer, 5); - if (output == NULL) - { - return false; - } - strcpy((char*)output, "null"); - return true; - - case cJSON_False: - output = ensure(output_buffer, 6); - if (output == NULL) - { - return false; - } - strcpy((char*)output, "false"); - return true; - - case cJSON_True: - output = ensure(output_buffer, 5); - if (output == NULL) - { - return false; - } - strcpy((char*)output, "true"); - return true; - - case cJSON_Number: - return print_number(item, output_buffer); - - case cJSON_Raw: - { - size_t raw_length = 0; - if (item->valuestring == NULL) - { - if (!output_buffer->noalloc) - { - output_buffer->hooks.deallocate(output_buffer->buffer); - } - return false; - } - - raw_length = strlen(item->valuestring) + sizeof(""); - output = ensure(output_buffer, raw_length); - if (output == NULL) - { - return false; - } - memcpy(output, item->valuestring, raw_length); - return true; - } - - case cJSON_String: - return print_string(item, output_buffer); - - case cJSON_Array: - return print_array(item, output_buffer); - - case cJSON_Object: - return print_object(item, output_buffer); - - default: - return false; - } -} - -/* Build an array from input text. */ -static cJSON_bool parse_array(cJSON * const item, parse_buffer * const input_buffer) -{ - cJSON *head = NULL; /* head of the linked list */ - cJSON *current_item = NULL; - - if (input_buffer->depth >= CJSON_NESTING_LIMIT) - { - return false; /* to deeply nested */ - } - input_buffer->depth++; - - if (buffer_at_offset(input_buffer)[0] != '[') - { - /* not an array */ - goto fail; - } - - input_buffer->offset++; - buffer_skip_whitespace(input_buffer); - if (can_access_at_index(input_buffer, 0) && (buffer_at_offset(input_buffer)[0] == ']')) - { - /* empty array */ - goto success; - } - - /* check if we skipped to the end of the buffer */ - if (cannot_access_at_index(input_buffer, 0)) - { - input_buffer->offset--; - goto fail; - } - - /* step back to character in front of the first element */ - input_buffer->offset--; - /* loop through the comma separated array elements */ - do - { - /* allocate next item */ - cJSON *new_item = cJSON_New_Item(&(input_buffer->hooks)); - if (new_item == NULL) - { - goto fail; /* allocation failure */ - } - - /* attach next item to list */ - if (head == NULL) - { - /* start the linked list */ - current_item = head = new_item; - } - else - { - /* add to the end and advance */ - current_item->next = new_item; - new_item->prev = current_item; - current_item = new_item; - } - - /* parse next value */ - input_buffer->offset++; - buffer_skip_whitespace(input_buffer); - if (!parse_value(current_item, input_buffer)) - { - goto fail; /* failed to parse value */ - } - buffer_skip_whitespace(input_buffer); - } - while (can_access_at_index(input_buffer, 0) && (buffer_at_offset(input_buffer)[0] == ',')); - - if (cannot_access_at_index(input_buffer, 0) || buffer_at_offset(input_buffer)[0] != ']') - { - goto fail; /* expected end of array */ - } - -success: - input_buffer->depth--; - - item->type = cJSON_Array; - item->child = head; - - input_buffer->offset++; - - return true; - -fail: - if (head != NULL) - { - cJSON_Delete(head); - } - - return false; -} - -/* Render an array to text */ -static cJSON_bool print_array(const cJSON * const item, printbuffer * const output_buffer) -{ - unsigned char *output_pointer = NULL; - size_t length = 0; - cJSON *current_element = item->child; - - if (output_buffer == NULL) - { - return false; - } - - /* Compose the output array. */ - /* opening square bracket */ - output_pointer = ensure(output_buffer, 1); - if (output_pointer == NULL) - { - return false; - } - - *output_pointer = '['; - output_buffer->offset++; - output_buffer->depth++; - - while (current_element != NULL) - { - if (!print_value(current_element, output_buffer)) - { - return false; - } - update_offset(output_buffer); - if (current_element->next) - { - length = (size_t) (output_buffer->format ? 2 : 1); - output_pointer = ensure(output_buffer, length + 1); - if (output_pointer == NULL) - { - return false; - } - *output_pointer++ = ','; - if(output_buffer->format) - { - *output_pointer++ = ' '; - } - *output_pointer = '\0'; - output_buffer->offset += length; - } - current_element = current_element->next; - } - - output_pointer = ensure(output_buffer, 2); - if (output_pointer == NULL) - { - return false; - } - *output_pointer++ = ']'; - *output_pointer = '\0'; - output_buffer->depth--; - - return true; -} - -/* Build an object from the text. */ -static cJSON_bool parse_object(cJSON * const item, parse_buffer * const input_buffer) -{ - cJSON *head = NULL; /* linked list head */ - cJSON *current_item = NULL; - - if (input_buffer->depth >= CJSON_NESTING_LIMIT) - { - return false; /* to deeply nested */ - } - input_buffer->depth++; - - if (cannot_access_at_index(input_buffer, 0) || (buffer_at_offset(input_buffer)[0] != '{')) - { - goto fail; /* not an object */ - } - - input_buffer->offset++; - buffer_skip_whitespace(input_buffer); - if (can_access_at_index(input_buffer, 0) && (buffer_at_offset(input_buffer)[0] == '}')) - { - goto success; /* empty object */ - } - - /* check if we skipped to the end of the buffer */ - if (cannot_access_at_index(input_buffer, 0)) - { - input_buffer->offset--; - goto fail; - } - - /* step back to character in front of the first element */ - input_buffer->offset--; - /* loop through the comma separated array elements */ - do - { - /* allocate next item */ - cJSON *new_item = cJSON_New_Item(&(input_buffer->hooks)); - if (new_item == NULL) - { - goto fail; /* allocation failure */ - } - - /* attach next item to list */ - if (head == NULL) - { - /* start the linked list */ - current_item = head = new_item; - } - else - { - /* add to the end and advance */ - current_item->next = new_item; - new_item->prev = current_item; - current_item = new_item; - } - - /* parse the name of the child */ - input_buffer->offset++; - buffer_skip_whitespace(input_buffer); - if (!parse_string(current_item, input_buffer)) - { - goto fail; /* faile to parse name */ - } - buffer_skip_whitespace(input_buffer); - - /* swap valuestring and string, because we parsed the name */ - current_item->string = current_item->valuestring; - current_item->valuestring = NULL; - - if (cannot_access_at_index(input_buffer, 0) || (buffer_at_offset(input_buffer)[0] != ':')) - { - goto fail; /* invalid object */ - } - - /* parse the value */ - input_buffer->offset++; - buffer_skip_whitespace(input_buffer); - if (!parse_value(current_item, input_buffer)) - { - goto fail; /* failed to parse value */ - } - buffer_skip_whitespace(input_buffer); - } - while (can_access_at_index(input_buffer, 0) && (buffer_at_offset(input_buffer)[0] == ',')); - - if (cannot_access_at_index(input_buffer, 0) || (buffer_at_offset(input_buffer)[0] != '}')) - { - goto fail; /* expected end of object */ - } - -success: - input_buffer->depth--; - - item->type = cJSON_Object; - item->child = head; - - input_buffer->offset++; - return true; - -fail: - if (head != NULL) - { - cJSON_Delete(head); - } - - return false; -} - -/* Render an object to text. */ -static cJSON_bool print_object(const cJSON * const item, printbuffer * const output_buffer) -{ - unsigned char *output_pointer = NULL; - size_t length = 0; - cJSON *current_item = item->child; - - if (output_buffer == NULL) - { - return false; - } - - /* Compose the output: */ - length = (size_t) (output_buffer->format ? 2 : 1); /* fmt: {\n */ - output_pointer = ensure(output_buffer, length + 1); - if (output_pointer == NULL) - { - return false; - } - - *output_pointer++ = '{'; - output_buffer->depth++; - if (output_buffer->format) - { - *output_pointer++ = '\n'; - } - output_buffer->offset += length; - - while (current_item) - { - if (output_buffer->format) - { - size_t i; - output_pointer = ensure(output_buffer, output_buffer->depth); - if (output_pointer == NULL) - { - return false; - } - for (i = 0; i < output_buffer->depth; i++) - { - *output_pointer++ = '\t'; - } - output_buffer->offset += output_buffer->depth; - } - - /* print key */ - if (!print_string_ptr((unsigned char*)current_item->string, output_buffer)) - { - return false; - } - update_offset(output_buffer); - - length = (size_t) (output_buffer->format ? 2 : 1); - output_pointer = ensure(output_buffer, length); - if (output_pointer == NULL) - { - return false; - } - *output_pointer++ = ':'; - if (output_buffer->format) - { - *output_pointer++ = '\t'; - } - output_buffer->offset += length; - - /* print value */ - if (!print_value(current_item, output_buffer)) - { - return false; - } - update_offset(output_buffer); - - /* print comma if not last */ - length = (size_t) ((output_buffer->format ? 1 : 0) + (current_item->next ? 1 : 0)); - output_pointer = ensure(output_buffer, length + 1); - if (output_pointer == NULL) - { - return false; - } - if (current_item->next) - { - *output_pointer++ = ','; - } - - if (output_buffer->format) - { - *output_pointer++ = '\n'; - } - *output_pointer = '\0'; - output_buffer->offset += length; - - current_item = current_item->next; - } - - output_pointer = ensure(output_buffer, output_buffer->format ? (output_buffer->depth + 1) : 2); - if (output_pointer == NULL) - { - return false; - } - if (output_buffer->format) - { - size_t i; - for (i = 0; i < (output_buffer->depth - 1); i++) - { - *output_pointer++ = '\t'; - } - } - *output_pointer++ = '}'; - *output_pointer = '\0'; - output_buffer->depth--; - - return true; -} - -/* Get Array size/item / object item. */ -CJSON_PUBLIC(int) cJSON_GetArraySize(const cJSON *array) -{ - cJSON *child = NULL; - size_t size = 0; - - if (array == NULL) - { - return 0; - } - - child = array->child; - - while(child != NULL) - { - size++; - child = child->next; - } - - /* FIXME: Can overflow here. Cannot be fixed without breaking the API */ - - return (int)size; -} - -static cJSON* get_array_item(const cJSON *array, size_t index) -{ - cJSON *current_child = NULL; - - if (array == NULL) - { - return NULL; - } - - current_child = array->child; - while ((current_child != NULL) && (index > 0)) - { - index--; - current_child = current_child->next; - } - - return current_child; -} - -CJSON_PUBLIC(cJSON *) cJSON_GetArrayItem(const cJSON *array, int index) -{ - if (index < 0) - { - return NULL; - } - - return get_array_item(array, (size_t)index); -} - -static cJSON *get_object_item(const cJSON * const object, const char * const name, const cJSON_bool case_sensitive) -{ - cJSON *current_element = NULL; - - if ((object == NULL) || (name == NULL)) - { - return NULL; - } - - current_element = object->child; - if (case_sensitive) - { - while ((current_element != NULL) && (strcmp(name, current_element->string) != 0)) - { - current_element = current_element->next; - } - } - else - { - while ((current_element != NULL) && (case_insensitive_strcmp((const unsigned char*)name, (const unsigned char*)(current_element->string)) != 0)) - { - current_element = current_element->next; - } - } - - return current_element; -} - -CJSON_PUBLIC(cJSON *) cJSON_GetObjectItem(const cJSON * const object, const char * const string) -{ - return get_object_item(object, string, false); -} - -CJSON_PUBLIC(cJSON *) cJSON_GetObjectItemCaseSensitive(const cJSON * const object, const char * const string) -{ - return get_object_item(object, string, true); -} - -CJSON_PUBLIC(cJSON_bool) cJSON_HasObjectItem(const cJSON *object, const char *string) -{ - return cJSON_GetObjectItem(object, string) ? 1 : 0; -} - -/* Utility for array list handling. */ -static void suffix_object(cJSON *prev, cJSON *item) -{ - prev->next = item; - item->prev = prev; -} - -/* Utility for handling references. */ -static cJSON *create_reference(const cJSON *item, const internal_hooks * const hooks) -{ - cJSON *reference = NULL; - if (item == NULL) - { - return NULL; - } - - reference = cJSON_New_Item(hooks); - if (reference == NULL) - { - return NULL; - } - - memcpy(reference, item, sizeof(cJSON)); - reference->string = NULL; - reference->type |= cJSON_IsReference; - reference->next = reference->prev = NULL; - return reference; -} - -static cJSON_bool add_item_to_array(cJSON *array, cJSON *item) -{ - cJSON *child = NULL; - - if ((item == NULL) || (array == NULL)) - { - return false; - } - - child = array->child; - - if (child == NULL) - { - /* list is empty, start new one */ - array->child = item; - } - else - { - /* append to the end */ - while (child->next) - { - child = child->next; - } - suffix_object(child, item); - } - - return true; -} - -/* Add item to array/object. */ -CJSON_PUBLIC(void) cJSON_AddItemToArray(cJSON *array, cJSON *item) -{ - add_item_to_array(array, item); -} - -#if defined(__clang__) || (defined(__GNUC__) && ((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ > 5)))) -#pragma GCC diagnostic push -#endif -#ifdef __GNUC__ -#pragma GCC diagnostic ignored "-Wcast-qual" -#endif -/* helper function to cast away const */ -static void* cast_away_const(const void* string) -{ - return (void*)string; -} -#if defined(__clang__) || (defined(__GNUC__) && ((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ > 5)))) -#pragma GCC diagnostic pop -#endif - - -static cJSON_bool add_item_to_object(cJSON * const object, const char * const string, cJSON * const item, const internal_hooks * const hooks, const cJSON_bool constant_key) -{ - if ((object == NULL) || (string == NULL) || (item == NULL)) - { - return false; - } - - if (!(item->type & cJSON_StringIsConst) && (item->string != NULL)) - { - hooks->deallocate(item->string); - } - - if (constant_key) - { - item->string = (char*)cast_away_const(string); - item->type |= cJSON_StringIsConst; - } - else - { - char *key = (char*)cJSON_strdup((const unsigned char*)string, hooks); - if (key == NULL) - { - return false; - } - - item->string = key; - item->type &= ~cJSON_StringIsConst; - } - - return add_item_to_array(object, item); -} - -CJSON_PUBLIC(void) cJSON_AddItemToObject(cJSON *object, const char *string, cJSON *item) -{ - add_item_to_object(object, string, item, &global_hooks, false); -} - -/* Add an item to an object with constant string as key */ -CJSON_PUBLIC(void) cJSON_AddItemToObjectCS(cJSON *object, const char *string, cJSON *item) -{ - add_item_to_object(object, string, item, &global_hooks, true); -} - -CJSON_PUBLIC(void) cJSON_AddItemReferenceToArray(cJSON *array, cJSON *item) -{ - if (array == NULL) - { - return; - } - - add_item_to_array(array, create_reference(item, &global_hooks)); -} - -CJSON_PUBLIC(void) cJSON_AddItemReferenceToObject(cJSON *object, const char *string, cJSON *item) -{ - if ((object == NULL) || (string == NULL)) - { - return; - } - - add_item_to_object(object, string, create_reference(item, &global_hooks), &global_hooks, false); -} - -CJSON_PUBLIC(cJSON*) cJSON_AddNullToObject(cJSON * const object, const char * const name) -{ - cJSON *null = cJSON_CreateNull(); - if (add_item_to_object(object, name, null, &global_hooks, false)) - { - return null; - } - - cJSON_Delete(null); - return NULL; -} - -CJSON_PUBLIC(cJSON*) cJSON_AddTrueToObject(cJSON * const object, const char * const name) -{ - cJSON *true_item = cJSON_CreateTrue(); - if (add_item_to_object(object, name, true_item, &global_hooks, false)) - { - return true_item; - } - - cJSON_Delete(true_item); - return NULL; -} - -CJSON_PUBLIC(cJSON*) cJSON_AddFalseToObject(cJSON * const object, const char * const name) -{ - cJSON *false_item = cJSON_CreateFalse(); - if (add_item_to_object(object, name, false_item, &global_hooks, false)) - { - return false_item; - } - - cJSON_Delete(false_item); - return NULL; -} - -CJSON_PUBLIC(cJSON*) cJSON_AddBoolToObject(cJSON * const object, const char * const name, const cJSON_bool boolean) -{ - cJSON *bool_item = cJSON_CreateBool(boolean); - if (add_item_to_object(object, name, bool_item, &global_hooks, false)) - { - return bool_item; - } - - cJSON_Delete(bool_item); - return NULL; -} - -CJSON_PUBLIC(cJSON*) cJSON_AddNumberToObject(cJSON * const object, const char * const name, const double number) -{ - cJSON *number_item = cJSON_CreateNumber(number); - if (add_item_to_object(object, name, number_item, &global_hooks, false)) - { - return number_item; - } - - cJSON_Delete(number_item); - return NULL; -} - -CJSON_PUBLIC(cJSON*) cJSON_AddStringToObject(cJSON * const object, const char * const name, const char * const string) -{ - cJSON *string_item = cJSON_CreateString(string); - if (add_item_to_object(object, name, string_item, &global_hooks, false)) - { - return string_item; - } - - cJSON_Delete(string_item); - return NULL; -} - -CJSON_PUBLIC(cJSON*) cJSON_AddRawToObject(cJSON * const object, const char * const name, const char * const raw) -{ - cJSON *raw_item = cJSON_CreateRaw(raw); - if (add_item_to_object(object, name, raw_item, &global_hooks, false)) - { - return raw_item; - } - - cJSON_Delete(raw_item); - return NULL; -} - -CJSON_PUBLIC(cJSON*) cJSON_AddObjectToObject(cJSON * const object, const char * const name) -{ - cJSON *object_item = cJSON_CreateObject(); - if (add_item_to_object(object, name, object_item, &global_hooks, false)) - { - return object_item; - } - - cJSON_Delete(object_item); - return NULL; -} - -CJSON_PUBLIC(cJSON*) cJSON_AddArrayToObject(cJSON * const object, const char * const name) -{ - cJSON *array = cJSON_CreateArray(); - if (add_item_to_object(object, name, array, &global_hooks, false)) - { - return array; - } - - cJSON_Delete(array); - return NULL; -} - -CJSON_PUBLIC(cJSON *) cJSON_DetachItemViaPointer(cJSON *parent, cJSON * const item) -{ - if ((parent == NULL) || (item == NULL)) - { - return NULL; - } - - if (item->prev != NULL) - { - /* not the first element */ - item->prev->next = item->next; - } - if (item->next != NULL) - { - /* not the last element */ - item->next->prev = item->prev; - } - - if (item == parent->child) - { - /* first element */ - parent->child = item->next; - } - /* make sure the detached item doesn't point anywhere anymore */ - item->prev = NULL; - item->next = NULL; - - return item; -} - -CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromArray(cJSON *array, int which) -{ - if (which < 0) - { - return NULL; - } - - return cJSON_DetachItemViaPointer(array, get_array_item(array, (size_t)which)); -} - -CJSON_PUBLIC(void) cJSON_DeleteItemFromArray(cJSON *array, int which) -{ - cJSON_Delete(cJSON_DetachItemFromArray(array, which)); -} - -CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromObject(cJSON *object, const char *string) -{ - cJSON *to_detach = cJSON_GetObjectItem(object, string); - - return cJSON_DetachItemViaPointer(object, to_detach); -} - -CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromObjectCaseSensitive(cJSON *object, const char *string) -{ - cJSON *to_detach = cJSON_GetObjectItemCaseSensitive(object, string); - - return cJSON_DetachItemViaPointer(object, to_detach); -} - -CJSON_PUBLIC(void) cJSON_DeleteItemFromObject(cJSON *object, const char *string) -{ - cJSON_Delete(cJSON_DetachItemFromObject(object, string)); -} - -CJSON_PUBLIC(void) cJSON_DeleteItemFromObjectCaseSensitive(cJSON *object, const char *string) -{ - cJSON_Delete(cJSON_DetachItemFromObjectCaseSensitive(object, string)); -} - -/* Replace array/object items with new ones. */ -CJSON_PUBLIC(void) cJSON_InsertItemInArray(cJSON *array, int which, cJSON *newitem) -{ - cJSON *after_inserted = NULL; - - if (which < 0) - { - return; - } - - after_inserted = get_array_item(array, (size_t)which); - if (after_inserted == NULL) - { - add_item_to_array(array, newitem); - return; - } - - newitem->next = after_inserted; - newitem->prev = after_inserted->prev; - after_inserted->prev = newitem; - if (after_inserted == array->child) - { - array->child = newitem; - } - else - { - newitem->prev->next = newitem; - } -} - -CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemViaPointer(cJSON * const parent, cJSON * const item, cJSON * replacement) -{ - if ((parent == NULL) || (replacement == NULL) || (item == NULL)) - { - return false; - } - - if (replacement == item) - { - return true; - } - - replacement->next = item->next; - replacement->prev = item->prev; - - if (replacement->next != NULL) - { - replacement->next->prev = replacement; - } - if (replacement->prev != NULL) - { - replacement->prev->next = replacement; - } - if (parent->child == item) - { - parent->child = replacement; - } - - item->next = NULL; - item->prev = NULL; - cJSON_Delete(item); - - return true; -} - -CJSON_PUBLIC(void) cJSON_ReplaceItemInArray(cJSON *array, int which, cJSON *newitem) -{ - if (which < 0) - { - return; - } - - cJSON_ReplaceItemViaPointer(array, get_array_item(array, (size_t)which), newitem); -} - -static cJSON_bool replace_item_in_object(cJSON *object, const char *string, cJSON *replacement, cJSON_bool case_sensitive) -{ - if ((replacement == NULL) || (string == NULL)) - { - return false; - } - - /* replace the name in the replacement */ - if (!(replacement->type & cJSON_StringIsConst) && (replacement->string != NULL)) - { - cJSON_free(replacement->string); - } - replacement->string = (char*)cJSON_strdup((const unsigned char*)string, &global_hooks); - replacement->type &= ~cJSON_StringIsConst; - - cJSON_ReplaceItemViaPointer(object, get_object_item(object, string, case_sensitive), replacement); - - return true; -} - -CJSON_PUBLIC(void) cJSON_ReplaceItemInObject(cJSON *object, const char *string, cJSON *newitem) -{ - replace_item_in_object(object, string, newitem, false); -} - -CJSON_PUBLIC(void) cJSON_ReplaceItemInObjectCaseSensitive(cJSON *object, const char *string, cJSON *newitem) -{ - replace_item_in_object(object, string, newitem, true); -} - -/* Create basic types: */ -CJSON_PUBLIC(cJSON *) cJSON_CreateNull(void) -{ - cJSON *item = cJSON_New_Item(&global_hooks); - if(item) - { - item->type = cJSON_NULL; - } - - return item; -} - -CJSON_PUBLIC(cJSON *) cJSON_CreateTrue(void) -{ - cJSON *item = cJSON_New_Item(&global_hooks); - if(item) - { - item->type = cJSON_True; - } - - return item; -} - -CJSON_PUBLIC(cJSON *) cJSON_CreateFalse(void) -{ - cJSON *item = cJSON_New_Item(&global_hooks); - if(item) - { - item->type = cJSON_False; - } - - return item; -} - -CJSON_PUBLIC(cJSON *) cJSON_CreateBool(cJSON_bool b) -{ - cJSON *item = cJSON_New_Item(&global_hooks); - if(item) - { - item->type = b ? cJSON_True : cJSON_False; - } - - return item; -} - -CJSON_PUBLIC(cJSON *) cJSON_CreateNumber(double num) -{ - cJSON *item = cJSON_New_Item(&global_hooks); - if(item) - { - item->type = cJSON_Number; - item->valuedouble = num; - - /* use saturation in case of overflow */ - if (num >= INT_MAX) - { - item->valueint = INT_MAX; - } - else if (num <= INT_MIN) - { - item->valueint = INT_MIN; - } - else - { - item->valueint = (int)num; - } - } - - return item; -} - -CJSON_PUBLIC(cJSON *) cJSON_CreateString(const char *string) -{ - cJSON *item = cJSON_New_Item(&global_hooks); - if(item) - { - item->type = cJSON_String; - item->valuestring = (char*)cJSON_strdup((const unsigned char*)string, &global_hooks); - if(!item->valuestring) - { - cJSON_Delete(item); - return NULL; - } - } - - return item; -} +#ifndef DBL_EPSILON +#define DBL_EPSILON 2.2204460492503131E-16 +#endif -CJSON_PUBLIC(cJSON *) cJSON_CreateStringReference(const char *string) -{ - cJSON *item = cJSON_New_Item(&global_hooks); - if (item != NULL) - { - item->type = cJSON_String | cJSON_IsReference; - item->valuestring = (char*)cast_away_const(string); - } - - return item; -} +static const char *ep; -CJSON_PUBLIC(cJSON *) cJSON_CreateObjectReference(const cJSON *child) +long stripquotes(char *str) { - cJSON *item = cJSON_New_Item(&global_hooks); - if (item != NULL) { - item->type = cJSON_Object | cJSON_IsReference; - item->child = (cJSON*)cast_away_const(child); - } - - return item; + long len,offset; + if ( str == 0 ) + return(0); + len = strlen(str); + if ( str[0] == '"' && str[len-1] == '"' ) + str[len-1] = 0, offset = 1; + else offset = 0; + return(offset); } -CJSON_PUBLIC(cJSON *) cJSON_CreateArrayReference(const cJSON *child) { - cJSON *item = cJSON_New_Item(&global_hooks); - if (item != NULL) { - item->type = cJSON_Array | cJSON_IsReference; - item->child = (cJSON*)cast_away_const(child); - } - - return item; -} +const char *cJSON_GetErrorPtr(void) {return ep;} -CJSON_PUBLIC(cJSON *) cJSON_CreateRaw(const char *raw) +static int32_t cJSON_strcasecmp(const char *s1,const char *s2) { - cJSON *item = cJSON_New_Item(&global_hooks); - if(item) - { - item->type = cJSON_Raw; - item->valuestring = (char*)cJSON_strdup((const unsigned char*)raw, &global_hooks); - if(!item->valuestring) - { - cJSON_Delete(item); - return NULL; - } - } - - return item; + if (!s1) return (s1==s2)?0:1;if (!s2) return 1; + for(; tolower((int32_t)(*s1)) == tolower((int32_t)(*s2)); ++s1, ++s2) if(*s1 == 0) return 0; + return tolower((int32_t)(*(const unsigned char *)s1)) - tolower((int32_t)(*(const unsigned char *)s2)); } -CJSON_PUBLIC(cJSON *) cJSON_CreateArray(void) +void *LP_alloc(uint64_t len); +void LP_free(void *ptr); +static void *(*cJSON_malloc)(size_t sz) = (void *)malloc;//LP_alloc; +static void (*cJSON_free)(void *ptr) = free;//LP_free; + +static void *cJSON_mallocstr(int32_t len) { - cJSON *item = cJSON_New_Item(&global_hooks); - if(item) - { - item->type=cJSON_Array; - } - - return item; + return(cJSON_malloc(len)); } -CJSON_PUBLIC(cJSON *) cJSON_CreateObject(void) +static char **cJSON_mallocptrs(int32_t num,char **space,int32_t max) { - cJSON *item = cJSON_New_Item(&global_hooks); - if (item) - { - item->type = cJSON_Object; - } - - return item; + if ( num < max ) + return(space); + else return(cJSON_malloc(num * sizeof(char *))); } -/* Create Arrays: */ -CJSON_PUBLIC(cJSON *) cJSON_CreateIntArray(const int *numbers, int count) +static void *cJSON_mallocnode() { - size_t i = 0; - cJSON *n = NULL; - cJSON *p = NULL; - cJSON *a = NULL; - - if ((count < 0) || (numbers == NULL)) - { - return NULL; - } - - a = cJSON_CreateArray(); - for(i = 0; a && (i < (size_t)count); i++) - { - n = cJSON_CreateNumber(numbers[i]); - if (!n) - { - cJSON_Delete(a); - return NULL; - } - if(!i) - { - a->child = n; - } - else - { - suffix_object(p, n); - } - p = n; - } - - return a; + return(cJSON_malloc(sizeof(cJSON))); } -CJSON_PUBLIC(cJSON *) cJSON_CreateFloatArray(const float *numbers, int count) +static void cJSON_freeptrs(char **ptrs,int32_t num,char **space) { - size_t i = 0; - cJSON *n = NULL; - cJSON *p = NULL; - cJSON *a = NULL; - - if ((count < 0) || (numbers == NULL)) - { - return NULL; - } - - a = cJSON_CreateArray(); - - for(i = 0; a && (i < (size_t)count); i++) - { - n = cJSON_CreateNumber((double)numbers[i]); - if(!n) - { - cJSON_Delete(a); - return NULL; - } - if(!i) - { - a->child = n; - } - else - { - suffix_object(p, n); - } - p = n; - } - - return a; + if ( ptrs != space ) + cJSON_free(ptrs); } -CJSON_PUBLIC(cJSON *) cJSON_CreateDoubleArray(const double *numbers, int count) +static void cJSON_freestr(char *str) { - size_t i = 0; - cJSON *n = NULL; - cJSON *p = NULL; - cJSON *a = NULL; - - if ((count < 0) || (numbers == NULL)) - { - return NULL; - } - - a = cJSON_CreateArray(); - - for(i = 0;a && (i < (size_t)count); i++) - { - n = cJSON_CreateNumber(numbers[i]); - if(!n) - { - cJSON_Delete(a); - return NULL; - } - if(!i) - { - a->child = n; - } - else - { - suffix_object(p, n); - } - p = n; - } - - return a; + cJSON_free(str); } -CJSON_PUBLIC(cJSON *) cJSON_CreateStringArray(const char **strings, int count) +static void cJSON_freenode(cJSON *item) { - size_t i = 0; - cJSON *n = NULL; - cJSON *p = NULL; - cJSON *a = NULL; - - if ((count < 0) || (strings == NULL)) - { - return NULL; - } - - a = cJSON_CreateArray(); - - for (i = 0; a && (i < (size_t)count); i++) - { - n = cJSON_CreateString(strings[i]); - if(!n) - { - cJSON_Delete(a); - return NULL; - } - if(!i) - { - a->child = n; - } - else - { - suffix_object(p,n); - } - p = n; - } - - return a; + cJSON_free(item); } -/* Duplication */ -CJSON_PUBLIC(cJSON *) cJSON_Duplicate(const cJSON *item, cJSON_bool recurse) +static char* cJSON_strdup(const char* str) { - cJSON *newitem = NULL; - cJSON *child = NULL; - cJSON *next = NULL; - cJSON *newchild = NULL; + size_t len; + char* copy; - /* Bail on bad ptr */ - if (!item) - { - goto fail; - } - /* Create new item */ - newitem = cJSON_New_Item(&global_hooks); - if (!newitem) - { - goto fail; - } - /* Copy over all vars */ - newitem->type = item->type & (~cJSON_IsReference); - newitem->valueint = item->valueint; - newitem->valuedouble = item->valuedouble; - if (item->valuestring) - { - newitem->valuestring = (char*)cJSON_strdup((unsigned char*)item->valuestring, &global_hooks); - if (!newitem->valuestring) - { - goto fail; - } - } - if (item->string) - { - newitem->string = (item->type&cJSON_StringIsConst) ? item->string : (char*)cJSON_strdup((unsigned char*)item->string, &global_hooks); - if (!newitem->string) - { - goto fail; - } - } - /* If non-recursive, then we're done! */ - if (!recurse) - { - return newitem; - } - /* Walk the ->next chain for the child. */ - child = item->child; - while (child != NULL) - { - newchild = cJSON_Duplicate(child, true); /* Duplicate (with recurse) each item in the ->next chain */ - if (!newchild) - { - goto fail; - } - if (next != NULL) - { - /* If newitem->child already set, then crosswire ->prev and ->next and move on */ - next->next = newchild; - newchild->prev = next; - next = newchild; - } - else - { - /* Set newitem->child and move to it */ - newitem->child = newchild; - next = newchild; - } - child = child->next; - } - - return newitem; - -fail: - if (newitem != NULL) - { - cJSON_Delete(newitem); - } - - return NULL; + len = strlen(str) + 1; + if (!(copy = (char*)cJSON_mallocstr((int32_t)len+1))) return 0; + memcpy(copy,str,len); + return copy; } -CJSON_PUBLIC(void) cJSON_Minify(char *json) +void cJSON_InitHooks(cJSON_Hooks* hooks) { - unsigned char *into = (unsigned char*)json; - - if (json == NULL) - { + if (!hooks) { /* Reset hooks */ + cJSON_malloc = malloc; + cJSON_free = free; return; } - while (*json) - { - if (*json == ' ') - { - json++; - } - else if (*json == '\t') - { - /* Whitespace characters. */ - json++; - } - else if (*json == '\r') - { - json++; - } - else if (*json=='\n') - { - json++; - } - else if ((*json == '/') && (json[1] == '/')) - { - /* double-slash comments, to end of line. */ - while (*json && (*json != '\n')) - { - json++; - } - } - else if ((*json == '/') && (json[1] == '*')) - { - /* multiline comments. */ - while (*json && !((*json == '*') && (json[1] == '/'))) - { - json++; - } - json += 2; - } - else if (*json == '\"') - { - /* string literals, which are \" sensitive. */ - *into++ = (unsigned char)*json++; - while (*json && (*json != '\"')) - { - if (*json == '\\') - { - *into++ = (unsigned char)*json++; - } - *into++ = (unsigned char)*json++; - } - *into++ = (unsigned char)*json++; - } - else - { - /* All other characters. */ - *into++ = (unsigned char)*json++; - } - } - - /* and null-terminate. */ - *into = '\0'; + cJSON_malloc = (hooks->malloc_fn)?hooks->malloc_fn:malloc; + cJSON_free = (hooks->free_fn)?hooks->free_fn:free; } -CJSON_PUBLIC(cJSON_bool) cJSON_IsInvalid(const cJSON * const item) +/* Internal constructor. */ +static cJSON *cJSON_New_Item(void) { - if (item == NULL) - { - return false; - } - - return (item->type & 0xFF) == cJSON_Invalid; + cJSON* node = (cJSON*)cJSON_mallocnode(); + if (node) memset(node,0,sizeof(cJSON)); + return node; } -CJSON_PUBLIC(cJSON_bool) cJSON_IsFalse(const cJSON * const item) +/* Delete a cJSON structure. */ +void cJSON_Delete(cJSON *c) { - if (item == NULL) - { - return false; - } - - return (item->type & 0xFF) == cJSON_False; + cJSON *next; + while (c) + { + next=c->next; + if (!(c->type&cJSON_IsReference) && c->child) cJSON_Delete(c->child); + if (!(c->type&cJSON_IsReference) && c->valuestring) cJSON_freestr(c->valuestring); + if (c->string) cJSON_freestr(c->string); + cJSON_freenode(c); + c=next; + } } -CJSON_PUBLIC(cJSON_bool) cJSON_IsTrue(const cJSON * const item) +/* Parse the input text to generate a number, and populate the result into item. */ +static const char *parse_number(cJSON *item,const char *num) { - if (item == NULL) - { - return false; - } + double n=0,sign=1,scale=0;int32_t subscale=0,signsubscale=1; + + if (*num=='-') sign=-1,num++; /* Has sign? */ + if (*num=='0') num++; /* is zero */ + if (*num>='1' && *num<='9') do n=(n*10.0)+(*num++ -'0'); while (*num>='0' && *num<='9'); /* Number? */ + if (*num=='.' && num[1]>='0' && num[1]<='9') {num++; do n=(n*10.0)+(*num++ -'0'),scale--; while (*num>='0' && *num<='9');} /* Fractional part? */ + if (*num=='e' || *num=='E') /* Exponent? */ + { num++;if (*num=='+') num++; else if (*num=='-') signsubscale=-1,num++; /* With sign? */ + while (*num>='0' && *num<='9') subscale=(subscale*10)+(*num++ - '0'); /* Number? */ + } - return (item->type & 0xff) == cJSON_True; + n=sign*n*pow(10.0,(scale+subscale*signsubscale)); /* number = +/- number.fraction * 10^+/- exponent */ + + item->valuedouble=n; + item->valueint=(int64_t)n; + item->type=cJSON_Number; + return num; +} + +/* Render the number nicely from the given item into a string. */ +static char *print_number(cJSON *item) +{ + char *str; + double d = item->valuedouble; + if ( fabs(((double)item->valueint) - d) <= DBL_EPSILON && d >= (1. - DBL_EPSILON) && d < (1LL << 62) )//d <= INT_MAX && d >= INT_MIN ) + { + str = (char *)cJSON_mallocstr(24); /* 2^64+1 can be represented in 21 chars + sign. */ + if ( str != 0 ) + sprintf(str,"%lld",(long long)item->valueint); + } + else + { + str = (char *)cJSON_mallocstr(66); /* This is a nice tradeoff. */ + if ( str != 0 ) + { + if ( fabs(floor(d) - d) <= DBL_EPSILON && fabs(d) < 1.0e60 ) + sprintf(str,"%.0f",d); + //else if (fabs(d)<1.0e-6 || fabs(d)>1.0e9) sprintf(str,"%e",d); + else + sprintf(str,"%.8f",d); + } + } + return str; +} + +static unsigned parse_hex4(const char *str) +{ + unsigned h=0; + if (*str>='0' && *str<='9') h+=(*str)-'0'; else if (*str>='A' && *str<='F') h+=10+(*str)-'A'; else if (*str>='a' && *str<='f') h+=10+(*str)-'a'; else return 0; + h=h<<4;str++; + if (*str>='0' && *str<='9') h+=(*str)-'0'; else if (*str>='A' && *str<='F') h+=10+(*str)-'A'; else if (*str>='a' && *str<='f') h+=10+(*str)-'a'; else return 0; + h=h<<4;str++; + if (*str>='0' && *str<='9') h+=(*str)-'0'; else if (*str>='A' && *str<='F') h+=10+(*str)-'A'; else if (*str>='a' && *str<='f') h+=10+(*str)-'a'; else return 0; + h=h<<4;str++; + if (*str>='0' && *str<='9') h+=(*str)-'0'; else if (*str>='A' && *str<='F') h+=10+(*str)-'A'; else if (*str>='a' && *str<='f') h+=10+(*str)-'a'; else return 0; + return h; +} + +/* Parse the input text into an unescaped cstring, and populate item. */ +static const unsigned char firstByteMark[7] = { 0x00, 0x00, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC }; +static const char *parse_string(cJSON *item,const char *str) +{ + const char *ptr=str+1;char *ptr2;char *out;int32_t len=0;unsigned uc,uc2; + if (*str!='\"') {ep=str;return 0;} /* not a string! */ + + while (*ptr!='\"' && *ptr && ++len) if (*ptr++ == '\\') ptr++; // Skip escaped quotes + + out=(char*)cJSON_mallocstr(len+2); /* This is how long we need for the string, roughly. */ + if (!out) return 0; + + ptr=str+1;ptr2=out; + while (*ptr!='\"' && *ptr) + { + if (*ptr!='\\') + { + if ( *ptr == '%' && is_hexstr((char *)&ptr[1],2) && isprint(_decode_hex((char *)&ptr[1])) != 0 ) + *ptr2++ = _decode_hex((char *)&ptr[1]), ptr += 3; + else *ptr2++ = *ptr++; + } + else + { + ptr++; + switch (*ptr) + { + case 'b': *ptr2++='\b'; break; + case 'f': *ptr2++='\f'; break; + case 'n': *ptr2++='\n'; break; + case 'r': *ptr2++='\r'; break; + case 't': *ptr2++='\t'; break; + case 'u': // transcode utf16 to utf8 + uc=parse_hex4(ptr+1);ptr+=4; // get the unicode char + + if ((uc>=0xDC00 && uc<=0xDFFF) || uc==0) break; // check for invalid + + if (uc>=0xD800 && uc<=0xDBFF) // UTF16 surrogate pairs + { + if (ptr[1]!='\\' || ptr[2]!='u') break; // missing second-half of surrogate. + uc2=parse_hex4(ptr+3);ptr+=6; + if (uc2<0xDC00 || uc2>0xDFFF) break; // invalid second-half of surrogate + uc=0x10000 + (((uc&0x3FF)<<10) | (uc2&0x3FF)); + } + + len=4;if (uc<0x80) len=1;else if (uc<0x800) len=2;else if (uc<0x10000) len=3; ptr2+=len; + + switch (len) { + case 4: *--ptr2 =((uc | 0x80) & 0xBF); uc >>= 6; + case 3: *--ptr2 =((uc | 0x80) & 0xBF); uc >>= 6; + case 2: *--ptr2 =((uc | 0x80) & 0xBF); uc >>= 6; + case 1: *--ptr2 =(uc | firstByteMark[len]); + } + ptr2+=len; + break; + default: *ptr2++=*ptr; break; + } + ptr++; + } + } + *ptr2=0; + if (*ptr=='\"') ptr++; + item->valuestring=out; + item->type=cJSON_String; + return ptr; } +/* Render the cstring provided to an escaped version that can be printed. */ +static char *print_string_ptr(const char *str) +{ + const char *ptr;char *ptr2,*out;int32_t len=0;unsigned char token; + + if (!str) return cJSON_strdup(""); + ptr=str;while ((token=*ptr) && ++len) {if (strchr("\"\\\b\f\n\r\t",token)) len++; else if (token<32) len+=5;ptr++;} + + out=(char*)cJSON_mallocstr(len+3+1); + if (!out) return 0; + + ptr2=out;ptr=str; + *ptr2++='\"'; + while (*ptr) + { + if ((unsigned char)*ptr>31 && *ptr!='\"' && *ptr!='\\') *ptr2++=*ptr++; + else + { + *ptr2++='\\'; + switch (token=*ptr++) + { + case '\\': *ptr2++='\\'; break; + case '\"': *ptr2++='\"'; break; + case '\b': *ptr2++='b'; break; + case '\f': *ptr2++='f'; break; + case '\n': *ptr2++='n'; break; + case '\r': *ptr2++='r'; break; + case '\t': *ptr2++='t'; break; + default: sprintf(ptr2,"u%04x",token);ptr2+=5; break; /* escape and print */ + } + } + } + *ptr2++='\"';*ptr2++=0; + return out; +} +/* Invote print_string_ptr (which is useful) on an item. */ +static char *print_string(cJSON *item) {return print_string_ptr(item->valuestring);} + +/* Predeclare these prototypes. */ +static const char *parse_value(cJSON *item,const char *value); +static char *print_value(cJSON *item,int32_t depth,int32_t fmt); +static const char *parse_array(cJSON *item,const char *value); +static char *print_array(cJSON *item,int32_t depth,int32_t fmt); +static const char *parse_object(cJSON *item,const char *value); +static char *print_object(cJSON *item,int32_t depth,int32_t fmt); + +/* Utility to jump whitespace and cr/lf */ +static const char *skip(const char *in) {while (in && *in && (unsigned char)*in<=32) in++; return in;} -CJSON_PUBLIC(cJSON_bool) cJSON_IsBool(const cJSON * const item) +/* Parse an object - create a new root, and populate. */ +cJSON *cJSON_ParseWithOpts(const char *value,const char **return_parse_end,int32_t require_null_terminated) { - if (item == NULL) - { - return false; - } + const char *end=0; + cJSON *c=cJSON_New_Item(); + ep=0; + if (!c) return 0; /* memory fail */ - return (item->type & (cJSON_True | cJSON_False)) != 0; + end=parse_value(c,skip(value)); + if (!end) {cJSON_Delete(c);return 0;} /* parse failure. ep is set. */ + + /* if we require null-terminated JSON without appended garbage, skip and then check for a null terminator */ + if (require_null_terminated) {end=skip(end);if (*end) {cJSON_Delete(c);ep=end;return 0;}} + if (return_parse_end) *return_parse_end=end; + return c; } -CJSON_PUBLIC(cJSON_bool) cJSON_IsNull(const cJSON * const item) +/* Default options for cJSON_Parse */ +cJSON *cJSON_Parse(const char *value) { - if (item == NULL) - { - return false; - } - - return (item->type & 0xFF) == cJSON_NULL; + return(cJSON_ParseWithOpts(value,0,0)); } -CJSON_PUBLIC(cJSON_bool) cJSON_IsNumber(const cJSON * const item) +/* Render a cJSON item/entity/structure to text. */ +char *cJSON_Print(cJSON *item) { - if (item == NULL) - { - return false; - } - - return (item->type & 0xFF) == cJSON_Number; + return(print_value(item,0,1)); } +char *cJSON_PrintUnformatted(cJSON *item) {return print_value(item,0,0);} -CJSON_PUBLIC(cJSON_bool) cJSON_IsString(const cJSON * const item) +/* Parser core - when encountering text, process appropriately. */ +static const char *parse_value(cJSON *item,const char *value) { - if (item == NULL) - { - return false; - } + if (!value) return 0; /* Fail on null. */ + if (!strncmp(value,"null",4)) { item->type=cJSON_NULL; return value+4; } + if (!strncmp(value,"false",5)) { item->type=cJSON_False; return value+5; } + if (!strncmp(value,"true",4)) { item->type=cJSON_True; item->valueint=1; return value+4; } + if (*value=='\"') { return parse_string(item,value); } + if (*value=='-' || (*value>='0' && *value<='9')) { return parse_number(item,value); } + if (*value=='[') { return parse_array(item,value); } + if (*value=='{') { return parse_object(item,value); } - return (item->type & 0xFF) == cJSON_String; + ep=value;return 0; /* failure. */ } -CJSON_PUBLIC(cJSON_bool) cJSON_IsArray(const cJSON * const item) -{ - if (item == NULL) - { - return false; - } - - return (item->type & 0xFF) == cJSON_Array; +/* Render a value to text. */ +static char *print_value(cJSON *item,int32_t depth,int32_t fmt) +{ + char *out=0; + if (!item) return 0; + switch ((item->type)&255) + { + case cJSON_NULL: out=cJSON_strdup("null"); break; + case cJSON_False: out=cJSON_strdup("false");break; + case cJSON_True: out=cJSON_strdup("true"); break; + case cJSON_Number: out=print_number(item);break; + case cJSON_String: out=print_string(item);break; + case cJSON_Array: out=print_array(item,depth,fmt);break; + case cJSON_Object: out=print_object(item,depth,fmt);break; + } + return out; } -CJSON_PUBLIC(cJSON_bool) cJSON_IsObject(const cJSON * const item) +/* Build an array from input text. */ +static const char *parse_array(cJSON *item,const char *value) { - if (item == NULL) - { - return false; - } + cJSON *child; + if (*value!='[') {ep=value;return 0;} /* not an array! */ + + item->type=cJSON_Array; + value=skip(value+1); + if (*value==']') return value+1; /* empty array. */ + + item->child=child=cJSON_New_Item(); + if (!item->child) return 0; /* memory fail */ + value=skip(parse_value(child,skip(value))); /* skip any spacing, get the value. */ + if (!value) return 0; - return (item->type & 0xFF) == cJSON_Object; + while (*value==',') + { + cJSON *new_item; + if (!(new_item=cJSON_New_Item())) return 0; /* memory fail */ + child->next=new_item;new_item->prev=child;child=new_item; + value=skip(parse_value(child,skip(value+1))); + if (!value) return 0; /* memory fail */ + } + + if (*value==']') return value+1; /* end of array */ + ep=value;return 0; /* malformed. */ } -CJSON_PUBLIC(cJSON_bool) cJSON_IsRaw(const cJSON * const item) -{ - if (item == NULL) - { - return false; - } - - return (item->type & 0xFF) == cJSON_Raw; +/* Render an array to text */ +static char *print_array(cJSON *item,int32_t depth,int32_t fmt) +{ + char **entries,*space_entries[512]; + char *out=0,*ptr,*ret;int32_t len=5; + cJSON *child=item->child; + int32_t numentries=0,i=0,fail=0; + + /* How many entries in the array? */ + while (child) numentries++,child=child->next; + /* Explicitly handle numentries==0 */ + if (!numentries) + { + out=(char*)cJSON_mallocstr(3+1); + if (out) strcpy(out,"[]"); + return out; + } + /* Allocate an array to hold the values for each */ + entries=cJSON_mallocptrs(1+numentries,space_entries,sizeof(space_entries)/sizeof(*space_entries)); + if (!entries) return 0; + memset(entries,0,numentries*sizeof(char*)); + /* Retrieve all the results: */ + child=item->child; + while (child && !fail) + { + ret=print_value(child,depth+1,fmt); + entries[i++]=ret; + if (ret) len+=strlen(ret)+2+(fmt?1:0); else fail=1; + child=child->next; + } + + /* If we didn't fail, try to malloc the output string */ + if (!fail) out=(char*)cJSON_mallocstr(len+1); + /* If that fails, we fail. */ + if (!out) fail=1; + + /* Handle failure. */ + if (fail) + { + for (i=0;itype=cJSON_Object; + value=skip(value+1); + if (*value=='}') return value+1; /* empty array. */ + + item->child=child=cJSON_New_Item(); + if (!item->child) return 0; + value=skip(parse_string(child,skip(value))); + if (!value) return 0; + child->string=child->valuestring;child->valuestring=0; + if (*value!=':') {ep=value;return 0;} /* fail! */ + value=skip(parse_value(child,skip(value+1))); /* skip any spacing, get the value. */ + if (!value) return 0; + + while (*value==',') + { + cJSON *new_item; + if (!(new_item=cJSON_New_Item())) return 0; /* memory fail */ + child->next=new_item;new_item->prev=child;child=new_item; + value=skip(parse_string(child,skip(value+1))); + if (!value) return 0; + child->string=child->valuestring;child->valuestring=0; + if (*value!=':') {ep=value;return 0;} /* fail! */ + value=skip(parse_value(child,skip(value+1))); /* skip any spacing, get the value. */ + if (!value) return 0; + } + + if (*value=='}') return value+1; /* end of array */ + ep=value;return 0; /* malformed. */ } -CJSON_PUBLIC(cJSON_bool) cJSON_Compare(const cJSON * const a, const cJSON * const b, const cJSON_bool case_sensitive) +/* Render an object to text. */ +static char *print_object(cJSON *item,int32_t depth,int32_t fmt) { - if ((a == NULL) || (b == NULL) || ((a->type & 0xFF) != (b->type & 0xFF)) || cJSON_IsInvalid(a)) - { - return false; - } - - /* check if type is valid */ - switch (a->type & 0xFF) - { - case cJSON_False: - case cJSON_True: - case cJSON_NULL: - case cJSON_Number: - case cJSON_String: - case cJSON_Raw: - case cJSON_Array: - case cJSON_Object: - break; - - default: - return false; - } - - /* identical objects are equal */ - if (a == b) - { - return true; - } - - switch (a->type & 0xFF) + char **entries=0,**names=0,*space_entries[512],*space_names[512]; + char *out=0,*ptr,*ret,*str;int32_t len=7,i=0,j; + cJSON *child=item->child,*firstchild; + int32_t numentries=0,fail=0; + // Count the number of entries + firstchild = child; + while ( child ) { - /* in these cases and equal type is enough */ - case cJSON_False: - case cJSON_True: - case cJSON_NULL: - return true; - - case cJSON_Number: - if (a->valuedouble == b->valuedouble) - { - return true; - } - return false; - - case cJSON_String: - case cJSON_Raw: - if ((a->valuestring == NULL) || (b->valuestring == NULL)) - { - return false; - } - if (strcmp(a->valuestring, b->valuestring) == 0) - { - return true; - } - - return false; - - case cJSON_Array: - { - cJSON *a_element = a->child; - cJSON *b_element = b->child; - - for (; (a_element != NULL) && (b_element != NULL);) - { - if (!cJSON_Compare(a_element, b_element, case_sensitive)) - { - return false; - } - - a_element = a_element->next; - b_element = b_element->next; - } - - /* one of the arrays is longer than the other */ - if (a_element != b_element) { - return false; - } - - return true; - } - - case cJSON_Object: + numentries++; + child = child->next; + if ( child == firstchild ) { - cJSON *a_element = NULL; - cJSON *b_element = NULL; - cJSON_ArrayForEach(a_element, a) - { - /* TODO This has O(n^2) runtime, which is horrible! */ - b_element = get_object_item(b, a_element->string, case_sensitive); - if (b_element == NULL) - { - return false; - } - - if (!cJSON_Compare(a_element, b_element, case_sensitive)) - { - return false; - } - } - - /* doing this twice, once on a and b to prevent true comparison if a subset of b - * TODO: Do this the proper way, this is just a fix for now */ - cJSON_ArrayForEach(b_element, b) - { - a_element = get_object_item(a, b_element->string, case_sensitive); - if (a_element == NULL) - { - return false; - } - - if (!cJSON_Compare(b_element, a_element, case_sensitive)) - { - return false; - } - } - - return true; + printf("cJSON infinite loop detected\n"); + break; } - - default: - return false; } + /* Explicitly handle empty object case */ + if (!numentries) + { + out=(char*)cJSON_mallocstr(fmt?depth+4+1:3+1); + if (!out) return 0; + ptr=out;*ptr++='{'; + if (fmt) {*ptr++='\n';for (i=0;ichild;depth++;if (fmt) len+=depth; + while ( child ) + { + names[i]=str=print_string_ptr(child->string); + entries[i++]=ret=print_value(child,depth,fmt); + if (str && ret) len+=strlen(ret)+strlen(str)+2+(fmt?2+depth:0); else fail=1; + child=child->next; + if ( child == firstchild ) + break; + } + + /* Try to allocate the output string */ + if (!fail) out=(char*)cJSON_mallocstr(len+1); + if (!out) fail=1; + + /* Handle failure */ + if (fail) + { + for (i=0;ichild;int32_t i=0;while(c)i++,c=c->next;return i;} +cJSON *cJSON_GetArrayItem(cJSON *array,int32_t item) {cJSON *c=array->child; while (c && item>0) item--,c=c->next; return c;} +cJSON *cJSON_GetObjectItem(cJSON *object,const char *string) { if ( object == 0 ) return(0); cJSON *c=object->child; while (c && cJSON_strcasecmp(c->string,string)) c=c->next; return c;} -CJSON_PUBLIC(void) cJSON_free(void *object) -{ - global_hooks.deallocate(object); +/* Utility for array list handling. */ +static void suffix_object(cJSON *prev,cJSON *item) {prev->next=item;item->prev=prev;} +/* Utility for handling references. */ +static cJSON *create_reference(cJSON *item) {cJSON *ref=cJSON_New_Item();if (!ref) return 0;memcpy(ref,item,sizeof(cJSON));ref->string=0;ref->type|=cJSON_IsReference;ref->next=ref->prev=0;return ref;} + +/* Add item to array/object. */ +void cJSON_AddItemToArray(cJSON *array, cJSON *item) {cJSON *c=array->child;if (!item) return; if (!c) {array->child=item;} else {while (c && c->next) c=c->next; suffix_object(c,item);}} +void cJSON_AddItemToObject(cJSON *object,const char *string,cJSON *item) {if (!item) return; if (item->string) cJSON_free(item->string);item->string=cJSON_strdup(string);cJSON_AddItemToArray(object,item);} +void cJSON_AddItemReferenceToArray(cJSON *array, cJSON *item) {cJSON_AddItemToArray(array,create_reference(item));} +void cJSON_AddItemReferenceToObject(cJSON *object,const char *string,cJSON *item) {cJSON_AddItemToObject(object,string,create_reference(item));} + +cJSON *cJSON_DetachItemFromArray(cJSON *array,int32_t which) {cJSON *c=array->child;while (c && which>0) c=c->next,which--;if (!c) return 0; + if (c->prev) c->prev->next=c->next;if (c->next) c->next->prev=c->prev;if (c==array->child) array->child=c->next;c->prev=c->next=0;return c;} +void cJSON_DeleteItemFromArray(cJSON *array,int32_t which) {cJSON_Delete(cJSON_DetachItemFromArray(array,which));} +cJSON *cJSON_DetachItemFromObject(cJSON *object,const char *string) {int32_t i=0;cJSON *c=object->child;while (c && cJSON_strcasecmp(c->string,string)) i++,c=c->next;if (c) return cJSON_DetachItemFromArray(object,i);return 0;} +void cJSON_DeleteItemFromObject(cJSON *object,const char *string) {cJSON_Delete(cJSON_DetachItemFromObject(object,string));} + +/* Replace array/object items with new ones. */ +void cJSON_ReplaceItemInArray(cJSON *array,int32_t which,cJSON *newitem) {cJSON *c=array->child;while (c && which>0) c=c->next,which--;if (!c) return; + newitem->next=c->next;newitem->prev=c->prev;if (newitem->next) newitem->next->prev=newitem; + if (c==array->child) array->child=newitem; else newitem->prev->next=newitem;c->next=c->prev=0;cJSON_Delete(c);} +void cJSON_ReplaceItemInObject(cJSON *object,const char *string,cJSON *newitem){int32_t i=0;cJSON *c=object->child;while(c && cJSON_strcasecmp(c->string,string))i++,c=c->next;if(c){newitem->string=cJSON_strdup(string);cJSON_ReplaceItemInArray(object,i,newitem);}} + +/* Create basic types: */ +cJSON *cJSON_CreateNull(void) {cJSON *item=cJSON_New_Item();if(item)item->type=cJSON_NULL;return item;} +cJSON *cJSON_CreateTrue(void) {cJSON *item=cJSON_New_Item();if(item)item->type=cJSON_True;return item;} +cJSON *cJSON_CreateFalse(void) {cJSON *item=cJSON_New_Item();if(item)item->type=cJSON_False;return item;} +cJSON *cJSON_CreateBool(int32_t b) {cJSON *item=cJSON_New_Item();if(item)item->type=b?cJSON_True:cJSON_False;return item;} +cJSON *cJSON_CreateNumber(double num) {cJSON *item=cJSON_New_Item();if(item){item->type=cJSON_Number;item->valuedouble=num;item->valueint=(int64_t)num;}return item;} +cJSON *cJSON_CreateString(const char *string) {cJSON *item=cJSON_New_Item();if(item){item->type=cJSON_String;item->valuestring=cJSON_strdup(string);}return item;} + +/* Create Arrays: */ +cJSON *cJSON_CreateIntArray(int64_t *numbers,int32_t count) {int32_t i;cJSON *n=0,*p=0,*a=cJSON_CreateArray();for(i=0;a && ichild=n;else suffix_object(p,n);p=n;}return a;} +cJSON *cJSON_CreateFloatArray(float *numbers,int32_t count) {int32_t i;cJSON *n=0,*p=0,*a=cJSON_CreateArray();for(i=0;a && ichild=n;else suffix_object(p,n);p=n;}return a;} +cJSON *cJSON_CreateDoubleArray(double *numbers,int32_t count) {int32_t i;cJSON *n=0,*p=0,*a=cJSON_CreateArray();for(i=0;a && ichild=n;else suffix_object(p,n);p=n;}return a;} +cJSON *cJSON_CreateStringArray(char **strings,int32_t count) {int32_t i;cJSON *n=0,*p=0,*a=cJSON_CreateArray();for(i=0;a && ichild=n;else suffix_object(p,n);p=n;}return a;} + +/* Duplication */ +cJSON *cJSON_Duplicate(cJSON *item,int32_t recurse) +{ + cJSON *newitem,*cptr,*nptr=0,*newchild; + /* Bail on bad ptr */ + if (!item) return 0; + /* Create new item */ + newitem=cJSON_New_Item(); + if (!newitem) return 0; + /* Copy over all vars */ + newitem->type=item->type&(~cJSON_IsReference),newitem->valueint=item->valueint,newitem->valuedouble=item->valuedouble; + if (item->valuestring) {newitem->valuestring=cJSON_strdup(item->valuestring); if (!newitem->valuestring) {cJSON_Delete(newitem);return 0;}} + if (item->string) {newitem->string=cJSON_strdup(item->string); if (!newitem->string) {cJSON_Delete(newitem);return 0;}} + /* If non-recursive, then we're done! */ + if (!recurse) return newitem; + /* Walk the ->next chain for the child. */ + cptr=item->child; + while (cptr) + { + newchild=cJSON_Duplicate(cptr,1); /* Duplicate (with recurse) each item in the ->next chain */ + if (!newchild) {cJSON_Delete(newitem);return 0;} + if (nptr) {nptr->next=newchild,newchild->prev=nptr;nptr=newchild;} /* If newitem->child already set, then crosswire ->prev and ->next and move on */ + else {newitem->child=newchild;nptr=newchild;} /* Set newitem->child and move to it */ + cptr=cptr->next; + } + return newitem; +} + +void cJSON_Minify(char *json) +{ + char *into=json; + while (*json) + { + if (*json==' ') json++; + else if (*json=='\t') json++; // Whitespace characters. + else if (*json=='\r') json++; + else if (*json=='\n') json++; + else if (*json=='/' && json[1]=='/') while (*json && *json!='\n') json++; // double-slash comments, to end of line. + else if (*json=='/' && json[1]=='*') {while (*json && !(*json=='*' && json[1]=='/')) json++;json+=2;} // multiline comments. + else if (*json=='\"'){*into++=*json++;while (*json && *json!='\"'){if (*json=='\\') *into++=*json++;*into++=*json++;}*into++=*json++;} // string literals, which are \" sensitive. + else *into++=*json++; // All other characters. + } + *into=0; // and null-terminate. } // the following written by jl777 @@ -3444,7 +1164,7 @@ cJSON *addrs_jsonarray(uint64_t *addrs,int32_t num) return(array); } -/*cJSON *cJSON_CreateArray(void) +cJSON *cJSON_CreateArray(void) { cJSON *item = cJSON_New_Item(); if ( item ) @@ -3464,7 +1184,7 @@ cJSON *cJSON_CreateObject(void) // cJSON_register(item); //#endif return item; -}*/ +} void free_json(cJSON *item) { diff --git a/includes/cJSON.h b/includes/cJSON.h index db9b2fc72..3ecdadc69 100755 --- a/includes/cJSON.h +++ b/includes/cJSON.h @@ -1,13 +1,16 @@ /* - Copyright (c) 2009-2017 Dave Gamble and cJSON contributors + Copyright (c) 2009 Dave Gamble + Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -39,24 +42,15 @@ extern "C" { #endif - /* project version */ -#define CJSON_VERSION_MAJOR 1 -#define CJSON_VERSION_MINOR 7 -#define CJSON_VERSION_PATCH 1 - -#include - /* cJSON Types: */ -#define cJSON_Invalid (0) -#define cJSON_False (1 << 0) -#define cJSON_True (1 << 1) -#define cJSON_NULL (1 << 2) -#define cJSON_Number (1 << 3) -#define cJSON_String (1 << 4) -#define cJSON_Array (1 << 5) -#define cJSON_Object (1 << 6) -#define cJSON_Raw (1 << 7) /* raw json */ - +#define cJSON_False 0 +#define cJSON_True 1 +#define cJSON_NULL 2 +#define cJSON_Number 3 +#define cJSON_String 4 +#define cJSON_Array 5 +#define cJSON_Object 6 + #define is_cJSON_Null(json) ((json) != 0 && ((json)->type & 0xff) == cJSON_NULL) #define is_cJSON_Array(json) ((json) != 0 && ((json)->type & 0xff) == cJSON_Array) #define is_cJSON_String(json) ((json) != 0 && ((json)->type & 0xff) == cJSON_String) @@ -66,232 +60,108 @@ extern "C" #define is_cJSON_False(json) ((json) != 0 && ((json)->type & 0xff) == cJSON_False) #define cJSON_IsReference 256 -#define cJSON_StringIsConst 512 /* The cJSON structure: */ - typedef struct cJSON - { - /* next/prev allow you to walk array/object chains. Alternatively, use GetArraySize/GetArrayItem/GetObjectItem */ - struct cJSON *next; - struct cJSON *prev; - /* An array or object item will have a child pointer pointing to a chain of the items in the array/object. */ - struct cJSON *child; + typedef struct cJSON { + struct cJSON *next,*prev; /* next/prev allow you to walk array/object chains. Alternatively, use GetArraySize/GetArrayItem/GetObjectItem */ + struct cJSON *child; /* An array or object item will have a child pointer pointing to a chain of the items in the array/object. */ - /* The type of the item, as above. */ - int type; + int32_t type; /* The type of the item, as above. */ - /* The item's string, if type==cJSON_String and type == cJSON_Raw */ - char *valuestring; - /* writing to valueint is DEPRECATED, use cJSON_SetNumberValue instead */ - int valueint; - /* The item's number, if type==cJSON_Number */ - double valuedouble; + char *valuestring; /* The item's string, if type==cJSON_String */ + int64_t valueint; /* The item's number, if type==cJSON_Number */ + double valuedouble; /* The item's number, if type==cJSON_Number */ - /* The item's name string, if this item is the child of, or is in the list of subitems of an object. */ - char *string; + char *string; /* The item's name string, if this item is the child of, or is in the list of subitems of an object. */ + uint32_t cjsonid; } cJSON; - typedef struct cJSON_Hooks - { + typedef struct cJSON_Hooks { void *(*malloc_fn)(size_t sz); void (*free_fn)(void *ptr); } cJSON_Hooks; - typedef int cJSON_bool; - -#if !defined(__WINDOWS__) && (defined(WIN32) || defined(WIN64) || defined(_MSC_VER) || defined(_WIN32)) -#define __WINDOWS__ -#endif -#ifdef __WINDOWS__ - - /* When compiling for windows, we specify a specific calling convention to avoid issues where we are being called from a project with a different default calling convention. For windows you have 2 define options: - CJSON_HIDE_SYMBOLS - Define this in the case where you don't want to ever dllexport symbols - CJSON_EXPORT_SYMBOLS - Define this on library build when you want to dllexport symbols (default) - CJSON_IMPORT_SYMBOLS - Define this if you want to dllimport symbol - For *nix builds that support visibility attribute, you can define similar behavior by - setting default visibility to hidden by adding - -fvisibility=hidden (for gcc) - or - -xldscope=hidden (for sun cc) - to CFLAGS - then using the CJSON_API_VISIBILITY flag to "export" the same symbols the way CJSON_EXPORT_SYMBOLS does - */ - - /* export symbols by default, this is necessary for copy pasting the C and header file */ -#if !defined(CJSON_HIDE_SYMBOLS) && !defined(CJSON_IMPORT_SYMBOLS) && !defined(CJSON_EXPORT_SYMBOLS) -#define CJSON_EXPORT_SYMBOLS -#endif - -#if defined(CJSON_HIDE_SYMBOLS) -#define CJSON_PUBLIC(type) type __stdcall -#elif defined(CJSON_EXPORT_SYMBOLS) -#define CJSON_PUBLIC(type) __declspec(dllexport) type __stdcall -#elif defined(CJSON_IMPORT_SYMBOLS) -#define CJSON_PUBLIC(type) __declspec(dllimport) type __stdcall -#endif -#else /* !WIN32 */ -#if (defined(__GNUC__) || defined(__SUNPRO_CC) || defined (__SUNPRO_C)) && defined(CJSON_API_VISIBILITY) -#define CJSON_PUBLIC(type) __attribute__((visibility("default"))) type -#else -#define CJSON_PUBLIC(type) type -#endif -#endif - - /* Limits how deeply nested arrays/objects can be before cJSON rejects to parse them. - * This is to prevent stack overflows. */ -#ifndef CJSON_NESTING_LIMIT -#define CJSON_NESTING_LIMIT 1000 -#endif - - /* returns the version of cJSON as a string */ - CJSON_PUBLIC(const char*) cJSON_Version(void); - /* Supply malloc, realloc and free functions to cJSON */ - CJSON_PUBLIC(void) cJSON_InitHooks(cJSON_Hooks* hooks); + extern void cJSON_InitHooks(cJSON_Hooks* hooks); - /* Memory Management: the caller is always responsible to free the results from all variants of cJSON_Parse (with cJSON_Delete) and cJSON_Print (with stdlib free, cJSON_Hooks.free_fn, or cJSON_free as appropriate). The exception is cJSON_PrintPreallocated, where the caller has full responsibility of the buffer. */ - /* Supply a block of JSON, and this returns a cJSON object you can interrogate. */ - CJSON_PUBLIC(cJSON *) cJSON_Parse(const char *value); - /* ParseWithOpts allows you to require (and check) that the JSON is null terminated, and to retrieve the pointer to the final byte parsed. */ - /* If you supply a ptr in return_parse_end and parsing fails, then return_parse_end will contain a pointer to the error so will match cJSON_GetErrorPtr(). */ - CJSON_PUBLIC(cJSON *) cJSON_ParseWithOpts(const char *value, const char **return_parse_end, cJSON_bool require_null_terminated); - /* Render a cJSON entity to text for transfer/storage. */ - CJSON_PUBLIC(char *) cJSON_Print(const cJSON *item); - /* Render a cJSON entity to text for transfer/storage without any formatting. */ - CJSON_PUBLIC(char *) cJSON_PrintUnformatted(const cJSON *item); - /* Render a cJSON entity to text using a buffered strategy. prebuffer is a guess at the final size. guessing well reduces reallocation. fmt=0 gives unformatted, =1 gives formatted */ - CJSON_PUBLIC(char *) cJSON_PrintBuffered(const cJSON *item, int prebuffer, cJSON_bool fmt); - /* Render a cJSON entity to text using a buffer already allocated in memory with given length. Returns 1 on success and 0 on failure. */ - /* NOTE: cJSON is not always 100% accurate in estimating how much memory it will use, so to be safe allocate 5 bytes more than you actually need */ - CJSON_PUBLIC(cJSON_bool) cJSON_PrintPreallocated(cJSON *item, char *buffer, const int length, const cJSON_bool format); + /* Supply a block of JSON, and this returns a cJSON object you can interrogate. Call cJSON_Delete when finished. */ + extern cJSON *cJSON_Parse(const char *value); + /* Render a cJSON entity to text for transfer/storage. Free the char* when finished. */ + extern char *cJSON_Print(cJSON *item); + /* Render a cJSON entity to text for transfer/storage without any formatting. Free the char* when finished. */ + extern char *cJSON_PrintUnformatted(cJSON *item); /* Delete a cJSON entity and all subentities. */ - CJSON_PUBLIC(void) cJSON_Delete(cJSON *c); + extern void cJSON_Delete(cJSON *c); /* Returns the number of items in an array (or object). */ - CJSON_PUBLIC(int) cJSON_GetArraySize(const cJSON *array); + extern int cJSON_GetArraySize(cJSON *array); /* Retrieve item number "item" from array "array". Returns NULL if unsuccessful. */ - CJSON_PUBLIC(cJSON *) cJSON_GetArrayItem(const cJSON *array, int index); + extern cJSON *cJSON_GetArrayItem(cJSON *array,int32_t item); /* Get item "string" from object. Case insensitive. */ - CJSON_PUBLIC(cJSON *) cJSON_GetObjectItem(const cJSON * const object, const char * const string); - CJSON_PUBLIC(cJSON *) cJSON_GetObjectItemCaseSensitive(const cJSON * const object, const char * const string); - CJSON_PUBLIC(cJSON_bool) cJSON_HasObjectItem(const cJSON *object, const char *string); - /* For analysing failed parses. This returns a pointer to the parse error. You'll probably need to look a few chars back to make sense of it. Defined when cJSON_Parse() returns 0. 0 when cJSON_Parse() succeeds. */ - CJSON_PUBLIC(const char *) cJSON_GetErrorPtr(void); - - /* Check if the item is a string and return its valuestring */ - CJSON_PUBLIC(char *) cJSON_GetStringValue(cJSON *item); - - /* These functions check the type of an item */ - CJSON_PUBLIC(cJSON_bool) cJSON_IsInvalid(const cJSON * const item); - CJSON_PUBLIC(cJSON_bool) cJSON_IsFalse(const cJSON * const item); - CJSON_PUBLIC(cJSON_bool) cJSON_IsTrue(const cJSON * const item); - CJSON_PUBLIC(cJSON_bool) cJSON_IsBool(const cJSON * const item); - CJSON_PUBLIC(cJSON_bool) cJSON_IsNull(const cJSON * const item); - CJSON_PUBLIC(cJSON_bool) cJSON_IsNumber(const cJSON * const item); - CJSON_PUBLIC(cJSON_bool) cJSON_IsString(const cJSON * const item); - CJSON_PUBLIC(cJSON_bool) cJSON_IsArray(const cJSON * const item); - CJSON_PUBLIC(cJSON_bool) cJSON_IsObject(const cJSON * const item); - CJSON_PUBLIC(cJSON_bool) cJSON_IsRaw(const cJSON * const item); + extern cJSON *cJSON_GetObjectItem(cJSON *object,const char *string); + /* For analysing failed parses. This returns a pointer to the parse error. You'll probably need to look a few chars back to make sense of it. Defined when cJSON_Parse() returns 0. 0 when cJSON_Parse() succeeds. */ + extern const char *cJSON_GetErrorPtr(void); + /* These calls create a cJSON item of the appropriate type. */ - CJSON_PUBLIC(cJSON *) cJSON_CreateNull(void); - CJSON_PUBLIC(cJSON *) cJSON_CreateTrue(void); - CJSON_PUBLIC(cJSON *) cJSON_CreateFalse(void); - CJSON_PUBLIC(cJSON *) cJSON_CreateBool(cJSON_bool boolean); - CJSON_PUBLIC(cJSON *) cJSON_CreateNumber(double num); - CJSON_PUBLIC(cJSON *) cJSON_CreateString(const char *string); - /* raw json */ - CJSON_PUBLIC(cJSON *) cJSON_CreateRaw(const char *raw); - CJSON_PUBLIC(cJSON *) cJSON_CreateArray(void); - CJSON_PUBLIC(cJSON *) cJSON_CreateObject(void); - - /* Create a string where valuestring references a string so - * it will not be freed by cJSON_Delete */ - CJSON_PUBLIC(cJSON *) cJSON_CreateStringReference(const char *string); - /* Create an object/arrray that only references it's elements so - * they will not be freed by cJSON_Delete */ - CJSON_PUBLIC(cJSON *) cJSON_CreateObjectReference(const cJSON *child); - CJSON_PUBLIC(cJSON *) cJSON_CreateArrayReference(const cJSON *child); + extern cJSON *cJSON_CreateNull(void); + extern cJSON *cJSON_CreateTrue(void); + extern cJSON *cJSON_CreateFalse(void); + extern cJSON *cJSON_CreateBool(int32_t b); + extern cJSON *cJSON_CreateNumber(double num); + extern cJSON *cJSON_CreateString(const char *string); + extern cJSON *cJSON_CreateArray(void); + extern cJSON *cJSON_CreateObject(void); /* These utilities create an Array of count items. */ - CJSON_PUBLIC(cJSON *) cJSON_CreateIntArray(const int *numbers, int count); - CJSON_PUBLIC(cJSON *) cJSON_CreateFloatArray(const float *numbers, int count); - CJSON_PUBLIC(cJSON *) cJSON_CreateDoubleArray(const double *numbers, int count); - CJSON_PUBLIC(cJSON *) cJSON_CreateStringArray(const char **strings, int count); + extern cJSON *cJSON_CreateIntArray(int64_t *numbers,int32_t count); + extern cJSON *cJSON_CreateFloatArray(float *numbers,int32_t count); + extern cJSON *cJSON_CreateDoubleArray(double *numbers,int32_t count); + extern cJSON *cJSON_CreateStringArray(char **strings,int32_t count); /* Append item to the specified array/object. */ - CJSON_PUBLIC(void) cJSON_AddItemToArray(cJSON *array, cJSON *item); - CJSON_PUBLIC(void) cJSON_AddItemToObject(cJSON *object, const char *string, cJSON *item); - /* Use this when string is definitely const (i.e. a literal, or as good as), and will definitely survive the cJSON object. - * WARNING: When this function was used, make sure to always check that (item->type & cJSON_StringIsConst) is zero before - * writing to `item->string` */ - CJSON_PUBLIC(void) cJSON_AddItemToObjectCS(cJSON *object, const char *string, cJSON *item); + extern void cJSON_AddItemToArray(cJSON *array, cJSON *item); + extern void cJSON_AddItemToObject(cJSON *object,const char *string,cJSON *item); /* Append reference to item to the specified array/object. Use this when you want to add an existing cJSON to a new cJSON, but don't want to corrupt your existing cJSON. */ - CJSON_PUBLIC(void) cJSON_AddItemReferenceToArray(cJSON *array, cJSON *item); - CJSON_PUBLIC(void) cJSON_AddItemReferenceToObject(cJSON *object, const char *string, cJSON *item); + extern void cJSON_AddItemReferenceToArray(cJSON *array, cJSON *item); + extern void cJSON_AddItemReferenceToObject(cJSON *object,const char *string,cJSON *item); /* Remove/Detatch items from Arrays/Objects. */ - CJSON_PUBLIC(cJSON *) cJSON_DetachItemViaPointer(cJSON *parent, cJSON * const item); - CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromArray(cJSON *array, int which); - CJSON_PUBLIC(void) cJSON_DeleteItemFromArray(cJSON *array, int which); - CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromObject(cJSON *object, const char *string); - CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromObjectCaseSensitive(cJSON *object, const char *string); - CJSON_PUBLIC(void) cJSON_DeleteItemFromObject(cJSON *object, const char *string); - CJSON_PUBLIC(void) cJSON_DeleteItemFromObjectCaseSensitive(cJSON *object, const char *string); - + extern cJSON *cJSON_DetachItemFromArray(cJSON *array,int32_t which); + extern void cJSON_DeleteItemFromArray(cJSON *array,int32_t which); + extern cJSON *cJSON_DetachItemFromObject(cJSON *object,const char *string); + extern void cJSON_DeleteItemFromObject(cJSON *object,const char *string); + /* Update array items. */ - CJSON_PUBLIC(void) cJSON_InsertItemInArray(cJSON *array, int which, cJSON *newitem); /* Shifts pre-existing items to the right. */ - CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemViaPointer(cJSON * const parent, cJSON * const item, cJSON * replacement); - CJSON_PUBLIC(void) cJSON_ReplaceItemInArray(cJSON *array, int which, cJSON *newitem); - CJSON_PUBLIC(void) cJSON_ReplaceItemInObject(cJSON *object,const char *string,cJSON *newitem); - CJSON_PUBLIC(void) cJSON_ReplaceItemInObjectCaseSensitive(cJSON *object,const char *string,cJSON *newitem); + extern void cJSON_ReplaceItemInArray(cJSON *array,int32_t which,cJSON *newitem); + extern void cJSON_ReplaceItemInObject(cJSON *object,const char *string,cJSON *newitem); /* Duplicate a cJSON item */ - CJSON_PUBLIC(cJSON *) cJSON_Duplicate(const cJSON *item, cJSON_bool recurse); + extern cJSON *cJSON_Duplicate(cJSON *item,int32_t recurse); /* Duplicate will create a new, identical cJSON item to the one you pass, in new memory that will need to be released. With recurse!=0, it will duplicate any children connected to the item. The item->next and ->prev pointers are always zero on return from Duplicate. */ - /* Recursively compare two cJSON items for equality. If either a or b is NULL or invalid, they will be considered unequal. - * case_sensitive determines if object keys are treated case sensitive (1) or case insensitive (0) */ - CJSON_PUBLIC(cJSON_bool) cJSON_Compare(const cJSON * const a, const cJSON * const b, const cJSON_bool case_sensitive); - - CJSON_PUBLIC(void) cJSON_Minify(char *json); - - /* Helper functions for creating and adding items to an object at the same time. - * They return the added item or NULL on failure. */ - CJSON_PUBLIC(cJSON*) cJSON_AddNullToObject(cJSON * const object, const char * const name); - CJSON_PUBLIC(cJSON*) cJSON_AddTrueToObject(cJSON * const object, const char * const name); - CJSON_PUBLIC(cJSON*) cJSON_AddFalseToObject(cJSON * const object, const char * const name); - CJSON_PUBLIC(cJSON*) cJSON_AddBoolToObject(cJSON * const object, const char * const name, const cJSON_bool boolean); - CJSON_PUBLIC(cJSON*) cJSON_AddNumberToObject(cJSON * const object, const char * const name, const double number); - CJSON_PUBLIC(cJSON*) cJSON_AddStringToObject(cJSON * const object, const char * const name, const char * const string); - CJSON_PUBLIC(cJSON*) cJSON_AddRawToObject(cJSON * const object, const char * const name, const char * const raw); - CJSON_PUBLIC(cJSON*) cJSON_AddObjectToObject(cJSON * const object, const char * const name); - CJSON_PUBLIC(cJSON*) cJSON_AddArrayToObject(cJSON * const object, const char * const name); + /* ParseWithOpts allows you to require (and check) that the JSON is null terminated, and to retrieve the pointer to the final byte parsed. */ + extern cJSON *cJSON_ParseWithOpts(const char *value,const char **return_parse_end,int32_t require_null_terminated); - /* When assigning an integer value, it needs to be propagated to valuedouble too. */ -#define cJSON_SetIntValue(object, number) ((object) ? (object)->valueint = (object)->valuedouble = (number) : (number)) - /* helper for the cJSON_SetNumberValue macro */ - CJSON_PUBLIC(double) cJSON_SetNumberHelper(cJSON *object, double number); -#define cJSON_SetNumberValue(object, number) ((object != NULL) ? cJSON_SetNumberHelper(object, (double)number) : (number)) + extern void cJSON_Minify(char *json); - /* Macro for iterating over an array or object */ -#define cJSON_ArrayForEach(element, array) for(element = (array != NULL) ? (array)->child : NULL; element != NULL; element = element->next) + /* Macros for creating things quickly. */ +#define cJSON_AddNullToObject(object,name) cJSON_AddItemToObject(object, name, cJSON_CreateNull()) +#define cJSON_AddTrueToObject(object,name) cJSON_AddItemToObject(object, name, cJSON_CreateTrue()) +#define cJSON_AddFalseToObject(object,name) cJSON_AddItemToObject(object, name, cJSON_CreateFalse()) +#define cJSON_AddBoolToObject(object,name,b) cJSON_AddItemToObject(object, name, cJSON_CreateBool(b)) +#define cJSON_AddNumberToObject(object,name,n) cJSON_AddItemToObject(object, name, cJSON_CreateNumber(n)) +#define cJSON_AddStringToObject(object,name,s) cJSON_AddItemToObject(object, name, cJSON_CreateString(s)) - /* malloc/free objects using the malloc/free functions that have been set with cJSON_InitHooks */ - CJSON_PUBLIC(void *) cJSON_malloc(size_t size); - CJSON_PUBLIC(void) cJSON_free(void *object); + struct destbuf { char buf[MAX_JSON_FIELD]; }; -#define jfieldname get_cJSON_fieldname + /* When assigning an integer value, it needs to be propagated to valuedouble too. */ +#define cJSON_SetIntValue(object,val) ((object)?(object)->valueint=(object)->valuedouble=(val):(val)) +#define jfieldstr get_cJSON_fieldname -#ifdef __cplusplus -} -#endif - -struct destbuf { char buf[MAX_JSON_FIELD]; }; - char *cJSON_str(cJSON *json); char *jstr(cJSON *json,char *field); char *jprint(cJSON *json,int32_t freeflag); @@ -358,5 +228,10 @@ struct destbuf { char buf[MAX_JSON_FIELD]; }; #define jtrue cJSON_CreateTrue #define jfalse cJSON_CreateFalse +#define jfieldname get_cJSON_fieldname + +#ifdef __cplusplus +} +#endif #endif From 6e20b69b9c262e733875a61f8b2f556f3c83de0d Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 28 Jan 2018 17:36:21 +0400 Subject: [PATCH 165/183] Remove test --- iguana/exchanges/mm.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/iguana/exchanges/mm.c b/iguana/exchanges/mm.c index a0641f839..db8bc57b7 100644 --- a/iguana/exchanges/mm.c +++ b/iguana/exchanges/mm.c @@ -115,11 +115,6 @@ int main(int argc, const char * argv[]) { char dirname[512],*passphrase; double incr; cJSON *retjson; OS_init(); - { - cJSON *test = cJSON_CreateObject(); - jaddnum(test,"test",-5); - printf("test (%s)\n",jprint(test,0)); - } if ( strstr(argv[0],"btc2kmd") != 0 && argv[1] != 0 ) { uint8_t addrtype,rmd160[20],rmd160b[20]; char coinaddr[64],coinaddr2[64]; From dabd824dc6bb4d8a096d877b88b3b40918fdeabb Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 28 Jan 2018 18:25:08 +0400 Subject: [PATCH 166/183] Test --- crypto777/bitcoind_RPC.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crypto777/bitcoind_RPC.c b/crypto777/bitcoind_RPC.c index d6c6f69f4..cd73f5560 100755 --- a/crypto777/bitcoind_RPC.c +++ b/crypto777/bitcoind_RPC.c @@ -74,7 +74,7 @@ char *post_process_bitcoind_RPC(char *debugstr,char *command,char *rpcstr,char * char *retstr = 0; cJSON *json,*result,*error; #ifdef FROM_MARKETMAKER - //usleep(3000); + usleep(500); #endif //printf("<<<<<<<<<<< bitcoind_RPC: %s post_process_bitcoind_RPC.%s.[%s]\n",debugstr,command,rpcstr); if ( command == 0 || rpcstr == 0 || rpcstr[0] == 0 ) From 3dfb36d2967a9c3f50587219a6e241de8149c25f Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 28 Jan 2018 18:32:16 +0400 Subject: [PATCH 167/183] cache instantdex credit calc --- crypto777/bitcoind_RPC.c | 2 +- iguana/exchanges/LP_include.h | 2 +- iguana/exchanges/LP_instantdex.c | 4 ++++ 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/crypto777/bitcoind_RPC.c b/crypto777/bitcoind_RPC.c index cd73f5560..698f4491d 100755 --- a/crypto777/bitcoind_RPC.c +++ b/crypto777/bitcoind_RPC.c @@ -74,7 +74,7 @@ char *post_process_bitcoind_RPC(char *debugstr,char *command,char *rpcstr,char * char *retstr = 0; cJSON *json,*result,*error; #ifdef FROM_MARKETMAKER - usleep(500); + //usleep(500); #endif //printf("<<<<<<<<<<< bitcoind_RPC: %s post_process_bitcoind_RPC.%s.[%s]\n",debugstr,command,rpcstr); if ( command == 0 || rpcstr == 0 || rpcstr[0] == 0 ) diff --git a/iguana/exchanges/LP_include.h b/iguana/exchanges/LP_include.h index 3ddbb4a7b..96a94c08d 100644 --- a/iguana/exchanges/LP_include.h +++ b/iguana/exchanges/LP_include.h @@ -351,7 +351,7 @@ struct LP_address struct LP_address_utxo *utxos; bits256 pubkey; int64_t balance,total,instantdex_credits; - uint32_t timestamp,n,unspenttime; + uint32_t timestamp,n,unspenttime,instantdextime; int32_t unspentheight; char coinaddr[64]; uint8_t pubsecp[33],didinstantdex; diff --git a/iguana/exchanges/LP_instantdex.c b/iguana/exchanges/LP_instantdex.c index f0b6aa50a..7463accaf 100644 --- a/iguana/exchanges/LP_instantdex.c +++ b/iguana/exchanges/LP_instantdex.c @@ -518,6 +518,9 @@ int64_t LP_instantdex_proofcheck(char *symbol,char *coinaddr,cJSON *proof,int32_ //printf("proofcheck addrtype.%d (%s) -> %s\n",addrtype,coinaddr,othersmartaddr); if ((ap= LP_address(coin,othersmartaddr)) != 0 ) { + if ( time(NULL) < ap->instantdextime+300 ) + return(ap->instantdex_credits); + ap->instantdextime = (uint32_t)time(NULL); ap->instantdex_credits = 0; for (i=0; iinstantdex_credits; ap->didinstantdex = 1; + ap->instantdextime = (uint32_t)time(NULL); if ( 0 && ap->instantdex_credits > 0 ) printf("validated instantdex %s.[%d] proof.(%s) credits %.8f\n",othersmartaddr,num,jprint(proof,0),dstr(ap->instantdex_credits)); } //else printf("cant find ap.%p or already did %d %.8f\n",ap,ap!=0?ap->didinstantdex:-1,ap!=0?dstr(ap->instantdex_credits):-1); From 124cdd778cc23ded52e51f678107a4cbbd3b9da8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 28 Jan 2018 18:40:34 +0400 Subject: [PATCH 168/183] Test --- crypto777/bitcoind_RPC.c | 1 + 1 file changed, 1 insertion(+) diff --git a/crypto777/bitcoind_RPC.c b/crypto777/bitcoind_RPC.c index 698f4491d..47ec2e9f1 100755 --- a/crypto777/bitcoind_RPC.c +++ b/crypto777/bitcoind_RPC.c @@ -280,6 +280,7 @@ try_again: *retstrp = retstr; return(retstr); } +printf("%s <- %s\n",url,command); return(post_process_bitcoind_RPC(debugstr,command,retstr,params)); } else From d5e84d150e79e298c7167d7165d8985a7ccb9e13 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 28 Jan 2018 18:52:12 +0400 Subject: [PATCH 169/183] Test --- crypto777/bitcoind_RPC.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crypto777/bitcoind_RPC.c b/crypto777/bitcoind_RPC.c index 47ec2e9f1..775ec5f66 100755 --- a/crypto777/bitcoind_RPC.c +++ b/crypto777/bitcoind_RPC.c @@ -280,7 +280,7 @@ try_again: *retstrp = retstr; return(retstr); } -printf("%s <- %s\n",url,command); +//printf("%s <- %s\n",url,command); return(post_process_bitcoind_RPC(debugstr,command,retstr,params)); } else From ee789e237973a86282255fe6176c2dfeaff1bb9f Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 28 Jan 2018 19:09:51 +0400 Subject: [PATCH 170/183] Test --- iguana/exchanges/LP_remember.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_remember.c b/iguana/exchanges/LP_remember.c index 8c50de4fe..8556ae259 100644 --- a/iguana/exchanges/LP_remember.c +++ b/iguana/exchanges/LP_remember.c @@ -1402,7 +1402,7 @@ char *LP_recent_swaps(int32_t limit) jaddnum(subitem,"price",-destamount/srcamount); jaddi(item,subitem); } - } else printf("base.%p rel.%p statusstr.%p baseind.%d relind.%d\n",base,rel,statusstr,baseind,relind); + } //else printf("base.%p rel.%p statusstr.%p baseind.%d relind.%d\n",base,rel,statusstr,baseind,relind); free_json(swapjson); } else printf("error parsing.(%s)\n",retstr); free(retstr); From c176e35c539014a708dc5251ab28a476c98cd382 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 29 Jan 2018 12:15:08 +0400 Subject: [PATCH 171/183] Trigger redeems and reclaims based on only time --- iguana/exchanges/LP_NXT.c | 4 ++-- iguana/exchanges/LP_remember.c | 6 +++--- iguana/exchanges/status | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/iguana/exchanges/LP_NXT.c b/iguana/exchanges/LP_NXT.c index d981a9fc1..6bc320925 100644 --- a/iguana/exchanges/LP_NXT.c +++ b/iguana/exchanges/LP_NXT.c @@ -210,10 +210,10 @@ cJSON *LP_NXT_redeems() char *account = "NXT-MRBN-8DFH-PFMK-A4DBM"; memset(totals,0,sizeof(totals)); sprintf(url,"http://127.0.0.1:7876/nxt?requestType=getBlockchainTransactions&account=%s",account); - printf("calling (%s)\n",url); + //printf("calling (%s)\n",url); if ( (retstr= issue_curlt(url,LP_HTTP_TIMEOUT)) != 0 ) { - printf("got.(%s)\n",retstr); + //printf("got.(%s)\n",retstr); if ( (retjson= cJSON_Parse(retstr)) != 0 ) { if ( (array= jarray(&numtx,retjson,"transactions")) != 0 ) diff --git a/iguana/exchanges/LP_remember.c b/iguana/exchanges/LP_remember.c index 8556ae259..995964069 100644 --- a/iguana/exchanges/LP_remember.c +++ b/iguana/exchanges/LP_remember.c @@ -1044,7 +1044,7 @@ cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requesti free_json(txoutobj), flag = 0; else flag = -1, rswap.depositspent = deadtxid; } - if ( flag == 0 ) + //if ( flag == 0 ) { if ( rswap.Dredeemlen != 0 ) redeemlen = rswap.Dredeemlen, memcpy(redeemscript,rswap.Dredeemscript,rswap.Dredeemlen); @@ -1119,7 +1119,7 @@ cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requesti free_json(txoutobj), flag = 0; else flag = -1, rswap.paymentspent = deadtxid; } - if ( flag == 0 && time(NULL) > rswap.expiration+777 ) + if ( time(NULL) > rswap.expiration+777 ) { // bobreclaim redeemlen = basilisk_swap_bobredeemscript(0,&secretstart,redeemscript,rswap.plocktime,rswap.pubA0,rswap.pubB0,rswap.pubB1,zero,rswap.privBn,rswap.secretAm,rswap.secretAm256,rswap.secretBn,rswap.secretBn256); @@ -1148,7 +1148,7 @@ cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requesti free_json(txoutobj), flag = 0; else flag = -1, rswap.depositspent = deadtxid; } - if ( flag == 0 && (bits256_nonz(rswap.Apaymentspent) != 0 || time(NULL) > rswap.expiration+777) ) + if ( bits256_nonz(rswap.Apaymentspent) != 0 || time(NULL) > rswap.expiration+777 ) { printf("do the refund! paymentspent.%s now.%u vs expiration.%u\n",bits256_str(str,rswap.paymentspent),(uint32_t)time(NULL),rswap.expiration); //if ( txbytes[BASILISK_BOBREFUND] == 0 ) diff --git a/iguana/exchanges/status b/iguana/exchanges/status index 0499bba6b..9f89cb314 100755 --- a/iguana/exchanges/status +++ b/iguana/exchanges/status @@ -1,3 +1,3 @@ #!/bin/bash source userpass -curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"swapstatus\"}" +curl --url "http://127.0.0.1:7783" --data "{\"pending\":1,\"userpass\":\"$userpass\",\"method\":\"swapstatus\"}" From b4192d7a8f615e8391a2a9bd445657d78fe025cf Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 29 Jan 2018 16:34:30 +0400 Subject: [PATCH 172/183] Test --- iguana/exchanges/LP_nativeDEX.c | 4 ++-- iguana/exchanges/LP_signatures.c | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index bbd63c7a4..5d515ac03 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -911,9 +911,9 @@ void LP_pubkeysloop(void *ctx) if ( strcmp(G.USERPASS,"1d8b27b21efabcd96571cd56f91a40fb9aa4cc623d273c63bf9223dc6f8cd81f") != 0 ) { LP_millistats_update(&LP_pubkeysloop_stats); - if ( time(NULL) > lasttime+LP_ORDERBOOK_DURATION*0.5 ) + if ( time(NULL) > lasttime+60 ) { - //printf("LP_pubkeysloop %u\n",(uint32_t)time(NULL)); + printf("LP_pubkeysloop %u\n",(uint32_t)time(NULL)); LP_notify_pubkeys(ctx,LP_mypubsock); lasttime = (uint32_t)time(NULL); } diff --git a/iguana/exchanges/LP_signatures.c b/iguana/exchanges/LP_signatures.c index 31870fad2..0ce54ee33 100644 --- a/iguana/exchanges/LP_signatures.c +++ b/iguana/exchanges/LP_signatures.c @@ -543,8 +543,8 @@ void LP_notify_pubkeys(void *ctx,int32_t pubsock) jaddstr(reqjson,"isLP",LPipaddr); if ( strcmp(LPipaddr,LP_myipaddr) == 0 ) jaddnum(reqjson,"ismine",1); - } - else printf("no LPipaddr\n"); + printf("notify send isLP.%s ismine.%d\n",LPipaddr,strcmp(LPipaddr,LP_myipaddr) == 0); + } else printf("no LPipaddr\n"); } jaddnum(reqjson,"session",G.LP_sessionid); LP_reserved_msg(0,"","",zero,jprint(reqjson,1)); @@ -560,7 +560,7 @@ char *LP_notify_recv(cJSON *argjson) LP_pubkey_sigcheck(pubp,argjson); if ( (ipaddr= jstr(argjson,"isLP")) != 0 ) { - //printf("notify got isLP %s %d\n",ipaddr,jint(argjson,"ismine")); + printf("notify got isLP %s %d\n",ipaddr,jint(argjson,"ismine")); LP_peer_recv(ipaddr,jint(argjson,"ismine")); if ( IAMLP != 0 && G.LP_IAMLP == 0 && strcmp(ipaddr,LP_myipaddr) == 0 ) { From ff93a1c1d1f50e227ea2db16acee4406a4905a06 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 29 Jan 2018 16:45:44 +0400 Subject: [PATCH 173/183] Test --- iguana/exchanges/LP_network.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_network.c b/iguana/exchanges/LP_network.c index 3fc9561c8..891cdd975 100644 --- a/iguana/exchanges/LP_network.c +++ b/iguana/exchanges/LP_network.c @@ -306,7 +306,7 @@ void LP_broadcast_finish(int32_t pubsock,char *base,char *rel,uint8_t *msg,cJSON crc32 = calc_crc32(0,&msg[2],msglen - 2); //printf("crc32.%x IAMLP.%d pubsock.%d\n",crc32,G.LP_IAMLP,pubsock); #ifdef FROM_MARKETMAKER - if ( (G.LP_IAMLP == 0 && IAMLP == 0) || pubsock < 0 ) + if ( G.LP_IAMLP == 0 || pubsock < 0 ) #else if ( IAMLP == 0 || pubsock < 0 ) #endif @@ -321,6 +321,8 @@ void LP_broadcast_finish(int32_t pubsock,char *base,char *rel,uint8_t *msg,cJSON msg = (void *)jprint(argjson,0); msglen = (int32_t)strlen((char *)msg) + 1; LP_queuesend(crc32,-1,base,rel,msg,msglen); + if ( pubsock >= 0 ) + LP_queuesend(crc32,pubsock,base,rel,msg,msglen); } else { From 8dc68d3716df68a479876724a442f648cd8fe903 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 29 Jan 2018 16:52:11 +0400 Subject: [PATCH 174/183] Fix LP propagation --- iguana/exchanges/LP_nativeDEX.c | 4 ++-- iguana/exchanges/LP_signatures.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 5d515ac03..1fe39f0b9 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -911,9 +911,9 @@ void LP_pubkeysloop(void *ctx) if ( strcmp(G.USERPASS,"1d8b27b21efabcd96571cd56f91a40fb9aa4cc623d273c63bf9223dc6f8cd81f") != 0 ) { LP_millistats_update(&LP_pubkeysloop_stats); - if ( time(NULL) > lasttime+60 ) + if ( time(NULL) > lasttime+100 ) { - printf("LP_pubkeysloop %u\n",(uint32_t)time(NULL)); + //printf("LP_pubkeysloop %u\n",(uint32_t)time(NULL)); LP_notify_pubkeys(ctx,LP_mypubsock); lasttime = (uint32_t)time(NULL); } diff --git a/iguana/exchanges/LP_signatures.c b/iguana/exchanges/LP_signatures.c index 0ce54ee33..00c92a8d8 100644 --- a/iguana/exchanges/LP_signatures.c +++ b/iguana/exchanges/LP_signatures.c @@ -543,7 +543,7 @@ void LP_notify_pubkeys(void *ctx,int32_t pubsock) jaddstr(reqjson,"isLP",LPipaddr); if ( strcmp(LPipaddr,LP_myipaddr) == 0 ) jaddnum(reqjson,"ismine",1); - printf("notify send isLP.%s ismine.%d\n",LPipaddr,strcmp(LPipaddr,LP_myipaddr) == 0); + //printf("notify send isLP.%s ismine.%d\n",LPipaddr,strcmp(LPipaddr,LP_myipaddr) == 0); } else printf("no LPipaddr\n"); } jaddnum(reqjson,"session",G.LP_sessionid); @@ -560,7 +560,7 @@ char *LP_notify_recv(cJSON *argjson) LP_pubkey_sigcheck(pubp,argjson); if ( (ipaddr= jstr(argjson,"isLP")) != 0 ) { - printf("notify got isLP %s %d\n",ipaddr,jint(argjson,"ismine")); + //printf("notify got isLP %s %d\n",ipaddr,jint(argjson,"ismine")); LP_peer_recv(ipaddr,jint(argjson,"ismine")); if ( IAMLP != 0 && G.LP_IAMLP == 0 && strcmp(ipaddr,LP_myipaddr) == 0 ) { From 09d951ca8d3891937738379bba68632fe826c420 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 29 Jan 2018 17:20:48 +0400 Subject: [PATCH 175/183] Test tcmalloc --- iguana/m_mm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/m_mm b/iguana/m_mm index b5c033488..8e5ac7e1e 100755 --- a/iguana/m_mm +++ b/iguana/m_mm @@ -1,3 +1,3 @@ cd secp256k1; ./m_unix; cd .. cd ../crypto777; ./m_LP; cd ../iguana -gcc -g -o marketmaker -I../crypto777 exchanges/mm.c ../crypto777/cJSON.c mini-gmp.c groestl.c segwit_addr.c secp256k1.o ../agents/libcrypto777.a -lnanomsg -lcurl -lpthread -lm +gcc -g -o marketmaker -I../crypto777 exchanges/mm.c ../crypto777/cJSON.c mini-gmp.c groestl.c segwit_addr.c secp256k1.o ../agents/libcrypto777.a -lnanomsg -lcurl -lpthread -ltcmalloc -lm From 7807fc9882da170792eb45915ffd634b718003b3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 29 Jan 2018 17:25:07 +0400 Subject: [PATCH 176/183] Use actual trader for instandex calc instead of 0 --- iguana/exchanges/LP_instantdex.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/iguana/exchanges/LP_instantdex.c b/iguana/exchanges/LP_instantdex.c index 7463accaf..e10f991ea 100644 --- a/iguana/exchanges/LP_instantdex.c +++ b/iguana/exchanges/LP_instantdex.c @@ -510,11 +510,13 @@ int64_t LP_dynamictrust(int64_t credits,bits256 pubkey,int64_t kmdvalue) int64_t LP_instantdex_proofcheck(char *symbol,char *coinaddr,cJSON *proof,int32_t num) { - uint8_t rmd160[20],addrtype; int64_t credits=0; int32_t i,j; bits256 prevtxid,txid; char othersmartaddr[64]; struct iguana_info *coin; struct LP_address *ap = 0; + uint8_t rmd160[20],addrtype,taddr=0; int64_t credits=0; int32_t i,j; bits256 prevtxid,txid; char othersmartaddr[64]; struct iguana_info *coin,*origcoin; struct LP_address *ap = 0; if ( (coin= LP_coinfind("KMD")) != 0 ) { - bitcoin_addr2rmd160(symbol,0,&addrtype,rmd160,coinaddr); - bitcoin_address("KMD",othersmartaddr,0,60,rmd160,20); + if ( (origcoin= LP_coinfind(symbol)) != 0 ) + taddr = origcoin->taddr; + bitcoin_addr2rmd160(symbol,taddr,&addrtype,rmd160,coinaddr); + bitcoin_address("KMD",othersmartaddr,coin->taddr,coin->pubtype,rmd160,20); //printf("proofcheck addrtype.%d (%s) -> %s\n",addrtype,coinaddr,othersmartaddr); if ((ap= LP_address(coin,othersmartaddr)) != 0 ) { From 8f7fcf0ac8ca38343611b444d686125b48c23027 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 29 Jan 2018 19:38:42 +0400 Subject: [PATCH 177/183] Revert tcmalloc --- iguana/m_mm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/m_mm b/iguana/m_mm index 8e5ac7e1e..5a227a69a 100755 --- a/iguana/m_mm +++ b/iguana/m_mm @@ -1,3 +1,3 @@ cd secp256k1; ./m_unix; cd .. cd ../crypto777; ./m_LP; cd ../iguana -gcc -g -o marketmaker -I../crypto777 exchanges/mm.c ../crypto777/cJSON.c mini-gmp.c groestl.c segwit_addr.c secp256k1.o ../agents/libcrypto777.a -lnanomsg -lcurl -lpthread -ltcmalloc -lm +gcc -g -o marketmaker -I../crypto777 exchanges/mm.c ../crypto777/cJSON.c mini-gmp.c groestl.c segwit_addr.c secp256k1.o ../agents/libcrypto777.a -lnanomsg -lcurl -lpthread -lm From 3ca1df9232bd69de5222c3ad9d9cda67dd2e79c1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 30 Jan 2018 18:17:54 +0400 Subject: [PATCH 178/183] Enable tweaks --- iguana/exchanges/enable | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/enable b/iguana/exchanges/enable index dd4fd5380..8dda8b9ea 100755 --- a/iguana/exchanges/enable +++ b/iguana/exchanges/enable @@ -4,7 +4,8 @@ curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\ curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"enable\",\"coin\":\"PIZZA\"}" curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"enable\",\"coin\":\"REVS\"}" curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"enable\",\"coin\":\"KMD\"}" -curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"enable\",\"coin\":\"BTC\"}" +#curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"enable\",\"coin\":\"BTC\"}" +curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"enable\",\"coin\":\"CHIPS\"}" curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"enable\",\"coin\":\"SUPERNET\"}" curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"enable\",\"coin\":\"CRYPTO\"}" curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"enable\",\"coin\":\"DEX\"}" @@ -17,6 +18,6 @@ curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\ curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"enable\",\"coin\":\"JUMBLR\"}" curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"enable\",\"coin\":\"HUSH\"}" curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"enable\",\"coin\":\"BTCH\"}" -#curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"electrum\",\"coin\":\"HUSH\",\"ipaddr\":\"173.212.225.176\",\"port\":50013}" +curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"electrum\",\"coin\":\"HUSH\",\"ipaddr\":\"173.212.225.176\",\"port\":50013}" #curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"electrum\",\"coin\":\"BTCH\",\"ipaddr\":\"electrum1.cipig.net\",\"port\":10020}" From badb68aae40e6fd14b1f81b73822a34bdae1b0d1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 30 Jan 2018 18:42:45 +0400 Subject: [PATCH 179/183] Test --- iguana/exchanges/enable | 1 + 1 file changed, 1 insertion(+) diff --git a/iguana/exchanges/enable b/iguana/exchanges/enable index 8dda8b9ea..e5121918a 100755 --- a/iguana/exchanges/enable +++ b/iguana/exchanges/enable @@ -20,4 +20,5 @@ curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\ curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"enable\",\"coin\":\"BTCH\"}" curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"electrum\",\"coin\":\"HUSH\",\"ipaddr\":\"173.212.225.176\",\"port\":50013}" #curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"electrum\",\"coin\":\"BTCH\",\"ipaddr\":\"electrum1.cipig.net\",\"port\":10020}" +curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"electrum\",\"coin\":\"BTC\",\"ipaddr\":\"node1.komodo.rocks\",\"port\":50001}" From 76c3f5cd73bc8862bd9ce9585c630720032668b9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 30 Jan 2018 22:37:06 +0400 Subject: [PATCH 180/183] Test --- iguana/exchanges/LP_ordermatch.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index bb22c383d..3ec680e96 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -1167,7 +1167,7 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, LP_quoteparse(&Q,argjson); LP_requestinit(&Q.R,Q.srchash,Q.desthash,Q.srccoin,Q.satoshis-Q.txfee,Q.destcoin,Q.destsatoshis-Q.desttxfee,Q.timestamp,Q.quotetime,DEXselector); LP_tradecommand_log(argjson); - printf("%-4d (%-10u %10u) %12s id.%22llu %5s/%-5s %12.8f -> %11.8f price %11.8f | RT.%d %d\n",(uint32_t)time(NULL) % 3600,Q.R.requestid,Q.R.quoteid,method,(long long)Q.aliceid,Q.srccoin,Q.destcoin,dstr(Q.satoshis),dstr(Q.destsatoshis),(double)Q.destsatoshis/Q.satoshis,LP_RTcount,LP_swapscount); + printf("%-4d (%-10u %10u) %12s id.%-20llu %5s/%-5s %12.8f -> %12.8f (%11.8f) | RT.%d %d n%d\n",(uint32_t)time(NULL) % 3600,Q.R.requestid,Q.R.quoteid,method,(long long)Q.aliceid,Q.srccoin,Q.destcoin,dstr(Q.satoshis),dstr(Q.destsatoshis),(double)Q.destsatoshis/Q.satoshis,LP_RTcount,LP_swapscount,G.netid); //LP_autoprices_update(method,Q.srccoin,dstr(Q.satoshis),Q.destcoin,dstr(Q.destsatoshis)); retval = 1; aliceid = j64bits(argjson,"aliceid"); From 9078e332d6a2ec66da2e72ac35fa07951c77d609 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 30 Jan 2018 23:20:13 +0400 Subject: [PATCH 181/183] Disable electrum error overflow kickstarting --- iguana/exchanges/LP_socket.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_socket.c b/iguana/exchanges/LP_socket.c index 4544ed0dc..c754e6bc2 100644 --- a/iguana/exchanges/LP_socket.c +++ b/iguana/exchanges/LP_socket.c @@ -433,7 +433,9 @@ cJSON *electrum_submit(char *symbol,struct electrum_info *ep,cJSON **retjsonp,ch if ( *retjsonp == 0 || jobj(*retjsonp,"error") != 0 ) { if ( ++ep->numerrors >= LP_ELECTRUM_MAXERRORS ) - electrum_kickstart(ep); + { + // electrum_kickstart(ep); seems to hurt more than help + } } else if ( ep->numerrors > 0 ) ep->numerrors--; if ( ep->prev == 0 ) From fdc7a0468dd58b66191c84b1d21a612791ab3fcc Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 31 Jan 2018 00:02:06 +0400 Subject: [PATCH 182/183] Test --- iguana/exchanges/LP_bitcoin.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_bitcoin.c b/iguana/exchanges/LP_bitcoin.c index 3ca110483..0343acc0b 100644 --- a/iguana/exchanges/LP_bitcoin.c +++ b/iguana/exchanges/LP_bitcoin.c @@ -2167,7 +2167,7 @@ void bitcoin_priv2pub(void *ctx,char *symbol,uint8_t *pubkey33,char *coinaddr,bi int32_t bitcoin_validaddress(char *symbol,uint8_t taddr,uint8_t pubtype,uint8_t p2shtype,char *coinaddr) { - uint8_t rmd160[20],addrtype; char checkaddr[128]; + uint8_t rmd160[20],addrtype; char checkaddr[64],checkaddr2[64]; if ( coinaddr == 0 || coinaddr[0] == 0 ) return(-1); else if ( bitcoin_addr2rmd160(symbol,taddr,&addrtype,rmd160,coinaddr) < 0 ) @@ -2179,7 +2179,9 @@ int32_t bitcoin_validaddress(char *symbol,uint8_t taddr,uint8_t pubtype,uint8_t return(-1); else if ( bitcoin_address(symbol,checkaddr,addrtype,taddr,rmd160,sizeof(rmd160)) != checkaddr || strcmp(checkaddr,coinaddr) != 0 ) { - printf("%s pubtype.%d bitcoin_validaddress checkaddr.%s != %s\n",symbol,pubtype,checkaddr,coinaddr); + bitcoin_addr2rmd160(symbol,taddr,&addrtype,rmd160,coinaddr); + bitcoin_address(symbol,checkaddr2,addrtype,taddr,rmd160,sizeof(rmd160)); + printf("%s pubtype.%d taddr.%d bitcoin_validaddress checkaddr.%s != %s, checkaddr2.(%s)\n",symbol,pubtype,taddr,checkaddr,coinaddr,checkaddr2); return(-1); } return(0); From 6afd83aae88758c6b3392240a8bdf866fe408747 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 31 Jan 2018 01:08:10 +0400 Subject: [PATCH 183/183] Test --- iguana/m_mm_StaticNanoMsg | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/iguana/m_mm_StaticNanoMsg b/iguana/m_mm_StaticNanoMsg index cab8ae51b..2c224b764 100755 --- a/iguana/m_mm_StaticNanoMsg +++ b/iguana/m_mm_StaticNanoMsg @@ -19,10 +19,9 @@ all: +$(MAKE) -C secp256k1 -f m_unix_Makefile all +$(MAKE) -C ../crypto777 -f m_LP_StaticNanoMsg all +$(MAKE) -C ../crypto777 -f m_LP_StaticNanoMsg clean - $(CC) -o ../agents/marketmaker -I../crypto777 exchanges/mm.c ../crypto777/cJSON.c mini-gmp.c secp256k1.o ../agents/libcrypto777.a ../OSlibs/linux/$(shell uname -m)/libnanomsg-static.a -lcurl -lpthread -lm -lanl + $(CC) -o ../agents/marketmaker -I../crypto777 exchanges/mm.c ../crypto777/cJSON.c mini-gmp.c groestl.c segwit_addr.c secp256k1.o ../agents/libcrypto777.a ../OSlibs/linux/$(shell uname -m)/libnanomsg-static.a -lcurl -lpthread -lm -lanl @echo "===========================" @echo " marketmaker -> `pwd`/../agents/marketmaker" @echo "===========================" -