From cf26246774c2747057cbc30c90066126ec949e10 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Oct 2017 21:07:33 +0300 Subject: [PATCH 01/37] Test --- iguana/exchanges/LP_nativeDEX.c | 4 ++-- iguana/exchanges/LP_remember.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 7bb32a06a..d5b5b47f7 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -19,13 +19,13 @@ // marketmaker // // process stats.log local file -> map of realtime activity! +// sign price +// select oldest utxo first // handles <-> pubkeys, deal with offline pubkeys, reputations, bonds etc. // // verify portfolio, pricearray, interest to KMD withdraw, reliable networking - // dPoW security -> 4: KMD notarized, 5: BTC notarized, after next notary elections - #include #include "LP_include.h" portable_mutex_t LP_peermutex,LP_UTXOmutex,LP_utxomutex,LP_commandmutex,LP_cachemutex,LP_swaplistmutex,LP_forwardmutex,LP_pubkeymutex,LP_networkmutex,LP_psockmutex,LP_coinmutex,LP_messagemutex,LP_portfoliomutex,LP_electrummutex,LP_butxomutex,LP_reservedmutex,LP_nanorecvsmutex; diff --git a/iguana/exchanges/LP_remember.c b/iguana/exchanges/LP_remember.c index 208216537..3e9af4ac9 100644 --- a/iguana/exchanges/LP_remember.c +++ b/iguana/exchanges/LP_remember.c @@ -814,7 +814,7 @@ int32_t LP_rswap_checktx(struct LP_swap_remember *rswap,char *symbol,int32_t txi rswap->sentflags[txi] = 1; _LP_refht_update(coin,rswap->txids[txi],tx->height); } else LP_refht_update(symbol,rswap->txids[txi]); - } + } else printf("sent.%d %s txi.%d\n",rswap->sentflags[txi],bits256_str(str,rswap->txids[txi]),txi); return(0); } From ab76528e246b113f778f1d570510df31fa36323d Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Oct 2017 21:17:24 +0300 Subject: [PATCH 02/37] Test --- iguana/exchanges/LP_remember.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/iguana/exchanges/LP_remember.c b/iguana/exchanges/LP_remember.c index 3e9af4ac9..f70ba6cc5 100644 --- a/iguana/exchanges/LP_remember.c +++ b/iguana/exchanges/LP_remember.c @@ -804,16 +804,19 @@ void LP_txbytes_update(char *name,char *symbol,char *txbytes,bits256 *txidp,bits int32_t LP_rswap_checktx(struct LP_swap_remember *rswap,char *symbol,int32_t txi) { - struct LP_transaction *tx; struct iguana_info *coin; char str[65]; + struct LP_transaction *tx=0; struct iguana_info *coin; char str[65]; if ( rswap->sentflags[txi] == 0 && bits256_nonz(rswap->txids[txi]) != 0 ) { coin = LP_coinfind(symbol); - printf("[%s] %s txbytes.%p %s\n",txnames[txi],txnames[txi],rswap->txbytes[txi],bits256_str(str,rswap->txids[txi])); - if ( coin != 0 && (tx= LP_transactionfind(coin,rswap->txids[txi])) != 0 && tx->height > 0 ) + if ( coin != 0 && (tx= LP_transactionfind(coin,rswap->txids[txi])) != 0 ) { rswap->sentflags[txi] = 1; - _LP_refht_update(coin,rswap->txids[txi],tx->height); + if ( tx->height <= 0 ) + tx->height = LP_txheight(coin,rswap->txids[txi]); + if ( tx->height > 0 ) + _LP_refht_update(coin,rswap->txids[txi],tx->height); } else LP_refht_update(symbol,rswap->txids[txi]); + printf("[%s] %s txbytes.%p %s ht.%d\n",txnames[txi],txnames[txi],rswap->txbytes[txi],bits256_str(str,rswap->txids[txi]),tx!=0?tx->height:-1); } else printf("sent.%d %s txi.%d\n",rswap->sentflags[txi],bits256_str(str,rswap->txids[txi]),txi); return(0); } From 54dd52559b8b102d5d2660bdb805403dea744846 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Oct 2017 21:22:32 +0300 Subject: [PATCH 03/37] Test --- iguana/exchanges/LP_remember.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/iguana/exchanges/LP_remember.c b/iguana/exchanges/LP_remember.c index f70ba6cc5..1ae21c336 100644 --- a/iguana/exchanges/LP_remember.c +++ b/iguana/exchanges/LP_remember.c @@ -804,19 +804,18 @@ void LP_txbytes_update(char *name,char *symbol,char *txbytes,bits256 *txidp,bits int32_t LP_rswap_checktx(struct LP_swap_remember *rswap,char *symbol,int32_t txi) { - struct LP_transaction *tx=0; struct iguana_info *coin; char str[65]; + int32_t ht; struct LP_transaction *tx=0; struct iguana_info *coin; char str[65]; if ( rswap->sentflags[txi] == 0 && bits256_nonz(rswap->txids[txi]) != 0 ) { - coin = LP_coinfind(symbol); - if ( coin != 0 && (tx= LP_transactionfind(coin,rswap->txids[txi])) != 0 ) + if ( (coin= LP_coinfind(symbol)) != 0 ) { - rswap->sentflags[txi] = 1; - if ( tx->height <= 0 ) - tx->height = LP_txheight(coin,rswap->txids[txi]); - if ( tx->height > 0 ) + if ( (ht= LP_txheight(coin,rswap->txids[txi])) > 0 ) + { + rswap->sentflags[txi] = 1; _LP_refht_update(coin,rswap->txids[txi],tx->height); - } else LP_refht_update(symbol,rswap->txids[txi]); - printf("[%s] %s txbytes.%p %s ht.%d\n",txnames[txi],txnames[txi],rswap->txbytes[txi],bits256_str(str,rswap->txids[txi]),tx!=0?tx->height:-1); + } else LP_refht_update(symbol,rswap->txids[txi]); + printf("[%s] %s txbytes.%p %s ht.%d\n",txnames[txi],txnames[txi],rswap->txbytes[txi],bits256_str(str,rswap->txids[txi]),tx!=0?tx->height:-1); + } } else printf("sent.%d %s txi.%d\n",rswap->sentflags[txi],bits256_str(str,rswap->txids[txi]),txi); return(0); } From 4aa13ba3e626f151cecbafd5547b87b1b668ad5d Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Oct 2017 21:28:00 +0300 Subject: [PATCH 04/37] Test --- iguana/exchanges/LP_remember.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/iguana/exchanges/LP_remember.c b/iguana/exchanges/LP_remember.c index 1ae21c336..00590c8c8 100644 --- a/iguana/exchanges/LP_remember.c +++ b/iguana/exchanges/LP_remember.c @@ -260,7 +260,7 @@ bits256 basilisk_swap_spendupdate(int32_t iambob,char *symbol,char *spentaddr,in } txid = txids[utxoind]; memset(&spendtxid,0,sizeof(spendtxid)); - if ( bits256_nonz(txid) != 0 ) + if ( bits256_nonz(txid) != 0 && sentflags[utxoind] != 0 ) { destaddr[0] = 0; spendtxid = LP_swap_spendtxid(symbol,destaddr,txid,vout); @@ -804,7 +804,7 @@ void LP_txbytes_update(char *name,char *symbol,char *txbytes,bits256 *txidp,bits int32_t LP_rswap_checktx(struct LP_swap_remember *rswap,char *symbol,int32_t txi) { - int32_t ht; struct LP_transaction *tx=0; struct iguana_info *coin; char str[65]; + int32_t ht; struct iguana_info *coin; char str[65]; if ( rswap->sentflags[txi] == 0 && bits256_nonz(rswap->txids[txi]) != 0 ) { if ( (coin= LP_coinfind(symbol)) != 0 ) @@ -812,9 +812,9 @@ int32_t LP_rswap_checktx(struct LP_swap_remember *rswap,char *symbol,int32_t txi if ( (ht= LP_txheight(coin,rswap->txids[txi])) > 0 ) { rswap->sentflags[txi] = 1; - _LP_refht_update(coin,rswap->txids[txi],tx->height); + _LP_refht_update(coin,rswap->txids[txi],ht); } else LP_refht_update(symbol,rswap->txids[txi]); - printf("[%s] %s txbytes.%p %s ht.%d\n",txnames[txi],txnames[txi],rswap->txbytes[txi],bits256_str(str,rswap->txids[txi]),tx!=0?tx->height:-1); + printf("[%s] %s txbytes.%p %s ht.%d\n",txnames[txi],txnames[txi],rswap->txbytes[txi],bits256_str(str,rswap->txids[txi]),ht); } } else printf("sent.%d %s txi.%d\n",rswap->sentflags[txi],bits256_str(str,rswap->txids[txi]),txi); return(0); From 6c16c8d83f1337a0a202806cfafe2d87f817147a Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Oct 2017 21:37:56 +0300 Subject: [PATCH 05/37] Test --- iguana/exchanges/LP_utxo.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index fc5857199..97c40c7b0 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -628,6 +628,8 @@ cJSON *LP_transactioninit(struct iguana_info *coin,bits256 txid,int32_t iter,cJS spentvout = jint(vin,"vout"); if ( i == 0 && bits256_nonz(spenttxid) == 0 ) continue; + if ( strcmp("REVS",coin->symbol) == 0 ) + printf("ht.%d vini.%d %s/v%d spent\n",height,i,bits256_str(str,spenttxid),spentvout); if ( (tx= LP_transactionfind(coin,spenttxid)) != 0 ) { if ( spentvout < tx->numvouts ) From 75d48167dfef88f29b9ebd56fc526419a7f760bf Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Oct 2017 21:43:18 +0300 Subject: [PATCH 06/37] 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 d5b5b47f7..0f640624a 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -606,10 +606,11 @@ int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int coin->lastscanht = coin->firstscanht; continue; } - if ( (coin->lastscanht % 1000) == 0 ) - printf("%s ref.%d scan.%d to %d, longest.%d\n",coin->symbol,coin->firstrefht,coin->firstscanht,coin->lastscanht,coin->longestchain); + //if ( (coin->lastscanht % 1000) == 0 ) for (j=0; j<100; j++) { + if ( strcmp("REVS",coin->symbol) == 0 ) + printf("%s ref.%d scan.%d to %d, longest.%d\n",coin->symbol,coin->firstrefht,coin->firstscanht,coin->lastscanht,coin->longestchain); if ( LP_blockinit(coin,coin->lastscanht) < 0 ) { printf("blockinit.%s %d error\n",coin->symbol,coin->lastscanht); @@ -619,9 +620,9 @@ int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int if ( coin->lastscanht == coin->longestchain+1 ) break; } + nonz++; if ( j < 100 ) continue; - nonz++; //LP_getestimatedrate(coin); break; } From 6db5b63484ae5d57c1f75da3665c2c64e4f67387 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Oct 2017 21:52:38 +0300 Subject: [PATCH 07/37] Test --- iguana/exchanges/LP_nativeDEX.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 0f640624a..d2ccdc896 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -586,7 +586,10 @@ int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int coin->lastgetinfo = (uint32_t)time(NULL); } if ( coin->firstrefht == 0 ) + { + printf("%s no firstrefht\n",coin->symbol); continue; + } else if ( coin->firstscanht == 0 ) coin->lastscanht = coin->firstscanht = coin->firstrefht; else if ( coin->firstrefht < coin->firstscanht ) @@ -595,7 +598,10 @@ int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int coin->lastscanht = coin->firstscanht = coin->firstrefht; } if ( coin->lastscanht == coin->longestchain+1 ) + { + printf("%s lastscanht.%d is longest.%d + 1\n",coin->synbol,coin->lastscanht,coin->longestchain) continue; + } else if ( coin->lastscanht > coin->longestchain+1 ) { printf("detected chain rewind lastscanht.%d vs longestchain.%d, first.%d ref.%d\n",coin->lastscanht,coin->longestchain,coin->firstscanht,coin->firstrefht); @@ -609,7 +615,7 @@ int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int //if ( (coin->lastscanht % 1000) == 0 ) for (j=0; j<100; j++) { - if ( strcmp("REVS",coin->symbol) == 0 ) + //if ( strcmp("REVS",coin->symbol) == 0 ) printf("%s ref.%d scan.%d to %d, longest.%d\n",coin->symbol,coin->firstrefht,coin->firstscanht,coin->lastscanht,coin->longestchain); if ( LP_blockinit(coin,coin->lastscanht) < 0 ) { @@ -623,6 +629,7 @@ int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int nonz++; if ( j < 100 ) continue; + printf("break out of coins iters\n"); //LP_getestimatedrate(coin); break; } From 95af33379d5350e05953bd315156be2f84527541 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Oct 2017 21:55:30 +0300 Subject: [PATCH 08/37] Test --- iguana/exchanges/LP_nativeDEX.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index d2ccdc896..0a7d33402 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -561,6 +561,7 @@ int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int } HASH_ITER(hh,LP_coins,coin,ctmp) // firstrefht,firstscanht,lastscanht { + fprintf(stderr,"%s ",coin->symbol); memset(&zero,0,sizeof(zero)); if ( coin->addr_listunspent_requested != 0 ) { @@ -599,7 +600,7 @@ int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int } if ( coin->lastscanht == coin->longestchain+1 ) { - printf("%s lastscanht.%d is longest.%d + 1\n",coin->synbol,coin->lastscanht,coin->longestchain) + printf("%s lastscanht.%d is longest.%d + 1\n",coin->symbol,coin->lastscanht,coin->longestchain); continue; } else if ( coin->lastscanht > coin->longestchain+1 ) From 2aa5bbe4fcf250b4fe4747d60cd67f126d7489c9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Oct 2017 22:01:20 +0300 Subject: [PATCH 09/37] Test --- iguana/exchanges/LP_nativeDEX.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 0a7d33402..0634a25ac 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -511,6 +511,7 @@ int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int myipaddr = "127.0.0.1"; numpeers = LP_numpeers(); needpings = 0; + fprintf(stderr,"P"); HASH_ITER(hh,LP_peerinfos,peer,tmp) { if ( peer->errors >= LP_MAXPEER_ERRORS ) @@ -529,9 +530,12 @@ int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int if ( strcmp(peer->ipaddr,myipaddr) != 0 ) { nonz++; + fprintf(stderr,"q"); LP_peersquery(mypeer,pubsock,peer->ipaddr,peer->port,myipaddr,myport); peer->diduquery = 0; + fprintf(stderr,"p"); LP_peer_pricesquery(peer); + fprintf(stderr,"u"); LP_utxos_sync(peer); needpings++; } @@ -539,9 +543,11 @@ int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int } if ( peer->needping != 0 ) { + fprintf(stderr,"u"); LP_utxos_sync(peer); peer->diduquery = now; nonz++; + fprintf(stderr,"n"); if ( (retstr= issue_LP_notify(peer->ipaddr,peer->port,"127.0.0.1",0,numpeers,G.LP_sessionid,G.LP_myrmd160str,G.LP_mypub25519)) != 0 ) free(retstr); peer->needping = 0; @@ -552,13 +558,16 @@ int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int { nonz++; //printf("needpings.%d send notify\n",needpings); + fprintf(stderr,"p"); LP_notify_pubkeys(ctx,pubsock); } if ( (counter % 6000) == 10 ) { + fprintf(stderr,"K"); nonz++; LP_privkey_updates(ctx,pubsock,0); } + fprintf(stderr,"C"); HASH_ITER(hh,LP_coins,coin,ctmp) // firstrefht,firstscanht,lastscanht { fprintf(stderr,"%s ",coin->symbol); @@ -634,6 +643,7 @@ int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int //LP_getestimatedrate(coin); break; } + fprintf(stderr,"S"); if ( (counter % 100000) == 90000 ) { if ( (retstr= basilisk_swapentry(0,0)) != 0 ) @@ -929,6 +939,7 @@ 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++; + fprintf(stderr," nonz.%d\n",nonz); if ( nonz == 0 ) usleep(1000); else if ( IAMLP == 0 ) From f3b5158fdb564b65441913711a00db554e934293 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Oct 2017 22:06:20 +0300 Subject: [PATCH 10/37] 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 0634a25ac..2eeec8ef7 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -536,7 +536,7 @@ int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int fprintf(stderr,"p"); LP_peer_pricesquery(peer); fprintf(stderr,"u"); - LP_utxos_sync(peer); + //LP_utxos_sync(peer); needpings++; } peer->lastpeers = now; @@ -575,6 +575,7 @@ int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int if ( coin->addr_listunspent_requested != 0 ) { //printf("PUSH addr_listunspent_requested %u\n",coin->addr_listunspent_requested); + fprintf(stderr,">"); LP_smartutxos_push(coin); coin->addr_listunspent_requested = 0; } @@ -587,12 +588,13 @@ int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int if ( time(NULL) > coin->lastgetinfo+LP_GETINFO_INCR ) { nonz++; + fprintf(stderr,"X"); if ( (height= LP_getheight(coin)) > coin->longestchain ) { coin->longestchain = height; if ( coin->firstrefht != 0 ) printf(">>>>>>>>>> set %s longestchain %d (ref.%d [%d, %d])\n",coin->symbol,height,coin->firstrefht,coin->firstscanht,coin->lastscanht); - } else LP_mempoolscan(coin->symbol,zero); + } //else LP_mempoolscan(coin->symbol,zero); coin->lastgetinfo = (uint32_t)time(NULL); } if ( coin->firstrefht == 0 ) From e62afd4a9be4a1d6ba75af7017da0a01c2cd472a Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Oct 2017 22:17:11 +0300 Subject: [PATCH 11/37] Test --- iguana/exchanges/LP_nativeDEX.c | 129 +++++++++++++++++--------------- iguana/exchanges/coins | 2 +- 2 files changed, 71 insertions(+), 60 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 2eeec8ef7..457e3d9c6 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -500,10 +500,69 @@ int32_t LP_utxos_sync(struct LP_peerinfo *peer) return(posted); } +void LP_coinsloop(void *myipaddr) +{ + struct iguana_info *coin,*ctmp; bits256 zero; int32_t j,nonz; + while ( 1 ) + { + nonz = 0; + HASH_ITER(hh,LP_coins,coin,ctmp) // firstrefht,firstscanht,lastscanht + { + memset(&zero,0,sizeof(zero)); + if ( coin->inactive != 0 ) + continue; + if ( coin->electrum != 0 ) + continue; + if ( coin->firstrefht == 0 ) + continue; + else if ( coin->firstscanht == 0 ) + coin->lastscanht = coin->firstscanht = coin->firstrefht; + else if ( coin->firstrefht < coin->firstscanht ) + { + printf("detected %s firstrefht.%d < firstscanht.%d\n",coin->symbol,coin->firstrefht,coin->firstscanht); + coin->lastscanht = coin->firstscanht = coin->firstrefht; + } + if ( coin->lastscanht == coin->longestchain+1 ) + { + printf("%s lastscanht.%d is longest.%d + 1\n",coin->symbol,coin->lastscanht,coin->longestchain); + continue; + } + else if ( coin->lastscanht > coin->longestchain+1 ) + { + printf("detected chain rewind lastscanht.%d vs longestchain.%d, first.%d ref.%d\n",coin->lastscanht,coin->longestchain,coin->firstscanht,coin->firstrefht); + LP_undospends(coin,coin->longestchain-1); + //LP_mempoolscan(coin->symbol,zero); + coin->lastscanht = coin->longestchain - 1; + if ( coin->firstscanht < coin->lastscanht ) + coin->lastscanht = coin->firstscanht; + continue; + } + //if ( (coin->lastscanht % 1000) == 0 ) + for (j=0; j<100; j++) + { + //if ( strcmp("REVS",coin->symbol) == 0 ) + printf("%s ref.%d scan.%d to %d, longest.%d\n",coin->symbol,coin->firstrefht,coin->firstscanht,coin->lastscanht,coin->longestchain); + if ( LP_blockinit(coin,coin->lastscanht) < 0 ) + { + printf("blockinit.%s %d error\n",coin->symbol,coin->lastscanht); + break; + } + coin->lastscanht++; + if ( coin->lastscanht == coin->longestchain+1 ) + break; + } + nonz++; + continue; + } + if ( nonz == 0 ) + usleep(1000); + } +} + int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int32_t pubsock,char *pushaddr,uint16_t myport) { static uint32_t counter,numpeers; - struct iguana_info *coin,*ctmp; char *retstr,*origipaddr; struct LP_peerinfo *peer,*tmp; uint32_t now; bits256 zero; int32_t needpings,j,height,nonz = 0; + struct iguana_info *coin,*ctmp; char *retstr,*origipaddr; struct LP_peerinfo *peer,*tmp; uint32_t now; int32_t needpings,height,nonz = 0; now = (uint32_t)time(NULL); if ( (origipaddr= myipaddr) == 0 ) origipaddr = "127.0.0.1"; @@ -571,7 +630,6 @@ int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int HASH_ITER(hh,LP_coins,coin,ctmp) // firstrefht,firstscanht,lastscanht { fprintf(stderr,"%s ",coin->symbol); - memset(&zero,0,sizeof(zero)); if ( coin->addr_listunspent_requested != 0 ) { //printf("PUSH addr_listunspent_requested %u\n",coin->addr_listunspent_requested); @@ -579,12 +637,6 @@ int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int LP_smartutxos_push(coin); coin->addr_listunspent_requested = 0; } - if ( coin->inactive != 0 ) - continue; - if ( coin->electrum != 0 ) - continue; - //if ( coin->obooktime == 0 ) - // continue; if ( time(NULL) > coin->lastgetinfo+LP_GETINFO_INCR ) { nonz++; @@ -597,57 +649,10 @@ int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int } //else LP_mempoolscan(coin->symbol,zero); coin->lastgetinfo = (uint32_t)time(NULL); } - if ( coin->firstrefht == 0 ) - { - printf("%s no firstrefht\n",coin->symbol); - continue; - } - else if ( coin->firstscanht == 0 ) - coin->lastscanht = coin->firstscanht = coin->firstrefht; - else if ( coin->firstrefht < coin->firstscanht ) - { - printf("detected %s firstrefht.%d < firstscanht.%d\n",coin->symbol,coin->firstrefht,coin->firstscanht); - coin->lastscanht = coin->firstscanht = coin->firstrefht; - } - if ( coin->lastscanht == coin->longestchain+1 ) - { - printf("%s lastscanht.%d is longest.%d + 1\n",coin->symbol,coin->lastscanht,coin->longestchain); - continue; - } - else if ( coin->lastscanht > coin->longestchain+1 ) - { - printf("detected chain rewind lastscanht.%d vs longestchain.%d, first.%d ref.%d\n",coin->lastscanht,coin->longestchain,coin->firstscanht,coin->firstrefht); - LP_undospends(coin,coin->longestchain-1); - LP_mempoolscan(coin->symbol,zero); - coin->lastscanht = coin->longestchain - 1; - if ( coin->firstscanht < coin->lastscanht ) - coin->lastscanht = coin->firstscanht; - continue; - } - //if ( (coin->lastscanht % 1000) == 0 ) - for (j=0; j<100; j++) - { - //if ( strcmp("REVS",coin->symbol) == 0 ) - printf("%s ref.%d scan.%d to %d, longest.%d\n",coin->symbol,coin->firstrefht,coin->firstscanht,coin->lastscanht,coin->longestchain); - if ( LP_blockinit(coin,coin->lastscanht) < 0 ) - { - printf("blockinit.%s %d error\n",coin->symbol,coin->lastscanht); - break; - } - coin->lastscanht++; - if ( coin->lastscanht == coin->longestchain+1 ) - break; - } - nonz++; - if ( j < 100 ) - continue; - printf("break out of coins iters\n"); - //LP_getestimatedrate(coin); - break; } - fprintf(stderr,"S"); if ( (counter % 100000) == 90000 ) { + fprintf(stderr,"S"); if ( (retstr= basilisk_swapentry(0,0)) != 0 ) { //printf("SWAPS.(%s)\n",retstr); @@ -655,6 +660,7 @@ int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int free(retstr); } } + fprintf(stderr,"."); counter++; return(nonz); } @@ -913,17 +919,22 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu } if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)command_rpcloop,(void *)&myipaddr) != 0 ) { - printf("error launching stats rpcloop for port.%u\n",myport); + printf("error launching command_rpcloop for port.%u\n",myport); exit(-1); } if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)queue_loop,(void *)&myipaddr) != 0 ) { - printf("error launching stats rpcloop for port.%u\n",myport); + printf("error launching queue_loop for port.%u\n",myport); exit(-1); } if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)prices_loop,(void *)&myipaddr) != 0 ) { - printf("error launching stats rpcloop for port.%u\n",myport); + printf("error launching prices_loop for port.%u\n",myport); + exit(-1); + } + if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_coinsloop,(void *)&myipaddr) != 0 ) + { + printf("error launching LP_coinsloop for port.%u\n",myport); exit(-1); } //if ( (retstr= basilisk_swapentry(0,0)) != 0 ) diff --git a/iguana/exchanges/coins b/iguana/exchanges/coins index e6da494a4..60511920f 100644 --- a/iguana/exchanges/coins +++ b/iguana/exchanges/coins @@ -1,4 +1,4 @@ -export coins="[{\"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\":\"CRW\",\"name\":\"crown\",\"rpcport\":9341,\"pubtype\":0,\"p2shtype\":5,\"wiftype\":128,\"txfee\":10000}, {\"coin\":\"HUC\",\"name\":\"huntercoin\",\"rpcport\":8399,\"pubtype\":40,\"p2shtype\":13,\"wiftype\":168,\"txfee\":100000}, {\"coin\":\"PIVX\",\"name\":\"pivx\",\"rpcport\":51473,\"pubtype\":30,\"p2shtype\":13,\"wiftype\":212,\"txfee\":10000}, {\"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\":\"MOON\",\"name\":\"Mooncoin\",\"rpcport\":44663,\"pubtype\":3,\"p2shtype\":22,\"wiftype\":131,\"txfee\":100000}, {\"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\":1000}, {\"coin\":\"I0C\",\"name\":\"i0coin\",\"rpcport\":7332,\"pubtype\":105,\"p2shtype\":5,\"wiftype\":128,\"txfee\":1000}, {\"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\":50000}, {\"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\":1000}, {\"coin\":\"LBC\",\"name\":\"lbrycrd\",\"rpcport\":9245,\"pubtype\":85,\"p2shtype\":122,\"wiftype\":28,\"txfee\":1000}, {\"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\":\"SHARK\",\"asset\":\"SHARK\",\"rpcport\":10114}, {\"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\":\"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\":\"CRW\",\"name\":\"crown\",\"rpcport\":9341,\"pubtype\":0,\"p2shtype\":5,\"wiftype\":128,\"txfee\":10000}, {\"coin\":\"HUC\",\"name\":\"huntercoin\",\"rpcport\":8399,\"pubtype\":40,\"p2shtype\":13,\"wiftype\":168,\"txfee\":100000}, {\"coin\":\"PIVX\",\"name\":\"pivx\",\"rpcport\":51473,\"pubtype\":30,\"p2shtype\":13,\"wiftype\":212,\"txfee\":10000}, {\"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\":\"MOON\",\"name\":\"Mooncoin\",\"rpcport\":44663,\"pubtype\":3,\"p2shtype\":22,\"wiftype\":131,\"txfee\":100000}, {\"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\":1000}, {\"coin\":\"I0C\",\"name\":\"i0coin\",\"rpcport\":7332,\"pubtype\":105,\"p2shtype\":5,\"wiftype\":128,\"txfee\":1000}, {\"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\":50000}, {\"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\":1000}, {\"coin\":\"LBC\",\"name\":\"lbrycrd\",\"rpcport\":9245,\"pubtype\":85,\"p2shtype\":122,\"wiftype\":28,\"txfee\":1000}, {\"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\":\"SHARK\",\"asset\":\"SHARK\",\"rpcport\":10114}, {\"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\":\"ZEN\",\"name\":\"zen\",\"rpcport\":8231,\"pubtype\":137,\"taddr\":32,\"p2shtype\":150,\"wiftype\":128,\"txfee\":10000}, #{\"coin\":\"BLK\",\"name\":\"blackcoin\",\"rpcport\":15715,\"pubtype\":25,\"p2shtype\":85,\"wiftype\":153,\"txfee\":10000}, From fdeee4a33b41759e62e7493fae2307f98890e615 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Oct 2017 22:18:41 +0300 Subject: [PATCH 12/37] Test --- iguana/exchanges/LP_nativeDEX.c | 1 - 1 file changed, 1 deletion(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 457e3d9c6..9d7718cc6 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -629,7 +629,6 @@ int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int fprintf(stderr,"C"); HASH_ITER(hh,LP_coins,coin,ctmp) // firstrefht,firstscanht,lastscanht { - fprintf(stderr,"%s ",coin->symbol); if ( coin->addr_listunspent_requested != 0 ) { //printf("PUSH addr_listunspent_requested %u\n",coin->addr_listunspent_requested); From 4a42ad4cc2bd0f588360032b2a6ed37e952a6053 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Oct 2017 22:27:56 +0300 Subject: [PATCH 13/37] Test --- iguana/exchanges/LP_include.h | 1 - iguana/exchanges/LP_nativeDEX.c | 46 +++++++++++++++++---------------- iguana/exchanges/LP_network.c | 1 - iguana/exchanges/LP_portfolio.c | 8 +----- 4 files changed, 25 insertions(+), 31 deletions(-) diff --git a/iguana/exchanges/LP_include.h b/iguana/exchanges/LP_include.h index 4766854ee..cb5f54bd0 100644 --- a/iguana/exchanges/LP_include.h +++ b/iguana/exchanges/LP_include.h @@ -311,7 +311,6 @@ 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_nanomsg_recvs(void *ctx); -int32_t LP_reserved_msgs(); uint64_t LP_smartbalance(struct iguana_info *coin); int32_t LP_getheight(struct iguana_info *coin); int32_t LP_reserved_msg(char *base,char *rel,bits256 pubkey,char *msg); diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 9d7718cc6..83da086eb 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -380,6 +380,15 @@ void command_rpcloop(void *myipaddr) } } +void utxosQ_loop(void *myipaddr) +{ + while ( 1 ) + { + if ( LP_utxosQ_process() == 0 ) + usleep(10000); + } +} + int32_t LP_utxos_sync(struct LP_peerinfo *peer) { int32_t i,j,n=0,m,v,posted=0; bits256 txid; cJSON *array,*item,*item2,*array2,*array3; uint64_t total,total2,metric; struct iguana_info *coin,*ctmp; struct LP_address *ap; char *retstr,*retstr2,*coinaddr; @@ -570,7 +579,6 @@ int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int myipaddr = "127.0.0.1"; numpeers = LP_numpeers(); needpings = 0; - fprintf(stderr,"P"); HASH_ITER(hh,LP_peerinfos,peer,tmp) { if ( peer->errors >= LP_MAXPEER_ERRORS ) @@ -589,12 +597,9 @@ int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int if ( strcmp(peer->ipaddr,myipaddr) != 0 ) { nonz++; - fprintf(stderr,"q"); LP_peersquery(mypeer,pubsock,peer->ipaddr,peer->port,myipaddr,myport); peer->diduquery = 0; - fprintf(stderr,"p"); LP_peer_pricesquery(peer); - fprintf(stderr,"u"); //LP_utxos_sync(peer); needpings++; } @@ -602,11 +607,9 @@ int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int } if ( peer->needping != 0 ) { - fprintf(stderr,"u"); LP_utxos_sync(peer); peer->diduquery = now; nonz++; - fprintf(stderr,"n"); if ( (retstr= issue_LP_notify(peer->ipaddr,peer->port,"127.0.0.1",0,numpeers,G.LP_sessionid,G.LP_myrmd160str,G.LP_mypub25519)) != 0 ) free(retstr); peer->needping = 0; @@ -617,29 +620,24 @@ int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int { nonz++; //printf("needpings.%d send notify\n",needpings); - fprintf(stderr,"p"); LP_notify_pubkeys(ctx,pubsock); } if ( (counter % 6000) == 10 ) { - fprintf(stderr,"K"); nonz++; LP_privkey_updates(ctx,pubsock,0); } - fprintf(stderr,"C"); HASH_ITER(hh,LP_coins,coin,ctmp) // firstrefht,firstscanht,lastscanht { if ( coin->addr_listunspent_requested != 0 ) { //printf("PUSH addr_listunspent_requested %u\n",coin->addr_listunspent_requested); - fprintf(stderr,">"); LP_smartutxos_push(coin); coin->addr_listunspent_requested = 0; } if ( time(NULL) > coin->lastgetinfo+LP_GETINFO_INCR ) { nonz++; - fprintf(stderr,"X"); if ( (height= LP_getheight(coin)) > coin->longestchain ) { coin->longestchain = height; @@ -651,7 +649,6 @@ int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int } if ( (counter % 100000) == 90000 ) { - fprintf(stderr,"S"); if ( (retstr= basilisk_swapentry(0,0)) != 0 ) { //printf("SWAPS.(%s)\n",retstr); @@ -659,7 +656,6 @@ int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int free(retstr); } } - fprintf(stderr,"."); counter++; return(nonz); } @@ -726,9 +722,9 @@ void LP_initpeers(int32_t pubsock,struct LP_peerinfo *mypeer,char *myipaddr,uint } } -int32_t LP_reserved_msgs() +void LP_reserved_msgs(void *ignore) { - bits256 zero; int32_t flag,n = 0; struct nn_pollfd pfd; + bits256 zero; int32_t flag; struct nn_pollfd pfd; memset(zero.bytes,0,sizeof(zero)); while ( 1 ) { @@ -751,13 +747,10 @@ int32_t LP_reserved_msgs() LP_broadcast_message(LP_mypubsock,"","",zero,Reserved_msgs[num_Reserved_msgs]); Reserved_msgs[num_Reserved_msgs] = 0; portable_mutex_unlock(&LP_reservedmutex); - usleep(3000); - } else break; - } else break; - if ( ++n > 1 ) - break; + } + } + usleep(3000); } - return(n); } int32_t LP_reserved_msg(char *base,char *rel,bits256 pubkey,char *msg) @@ -911,6 +904,16 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu printf("error launching LP_psockloop for (%s)\n",myipaddr); exit(-1); } + if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_reserved_msgs,(void *)myipaddr) != 0 ) + { + printf("error launching LP_reserved_msgs for (%s)\n",myipaddr); + exit(-1); + } + if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)utxosQ_loop,(void *)myipaddr) != 0 ) + { + printf("error launching utxosQ_loop for (%s)\n",myipaddr); + exit(-1); + } if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)stats_rpcloop,(void *)&myport) != 0 ) { printf("error launching stats rpcloop for port.%u\n",myport); @@ -951,7 +954,6 @@ 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++; - fprintf(stderr," nonz.%d\n",nonz); if ( nonz == 0 ) usleep(1000); else if ( IAMLP == 0 ) diff --git a/iguana/exchanges/LP_network.c b/iguana/exchanges/LP_network.c index 1419c8b6e..f947b9f03 100644 --- a/iguana/exchanges/LP_network.c +++ b/iguana/exchanges/LP_network.c @@ -144,7 +144,6 @@ void queue_loop(void *ignore) struct LP_queue *ptr,*tmp; int32_t sentbytes,nonz,flag,duplicate,n=0; while ( 1 ) { - LP_reserved_msgs(); nonz = 0; //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); n = 0; diff --git a/iguana/exchanges/LP_portfolio.c b/iguana/exchanges/LP_portfolio.c index 9bb176b00..99644a956 100644 --- a/iguana/exchanges/LP_portfolio.c +++ b/iguana/exchanges/LP_portfolio.c @@ -596,7 +596,7 @@ int32_t LP_portfolio_order(struct LP_portfoliotrade *trades,int32_t max,cJSON *a void prices_loop(void *ignore) { - char *retstr; cJSON *retjson,*array; char *buycoin,*sellcoin; struct iguana_info *buy,*sell; uint32_t requestid,quoteid; uint32_t expiration; int32_t i,n,m; struct LP_portfoliotrade trades[256]; struct LP_priceinfo *btcpp; void *ctx = bitcoin_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; void *ctx = bitcoin_ctx(); while ( 1 ) { if ( (btcpp= LP_priceinfofind("BTC")) == 0 ) @@ -634,12 +634,6 @@ void prices_loop(void *ignore) } free(retstr); } - expiration = (uint32_t)time(NULL) + 60; - while ( time(NULL) < expiration ) - { - if ( LP_utxosQ_process() == 0 ) - usleep(10000); - } } } From bbcf8414a7278bb7ad39ee025508fcba426a8046 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Oct 2017 22:38:05 +0300 Subject: [PATCH 14/37] Test --- iguana/exchanges/LP_nativeDEX.c | 69 +++++++++++++++++++++++---------- 1 file changed, 48 insertions(+), 21 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 83da086eb..0e0f53128 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -616,17 +616,6 @@ int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int needpings++; } } - if ( needpings != 0 || (counter % 10000) == 5 ) - { - nonz++; - //printf("needpings.%d send notify\n",needpings); - LP_notify_pubkeys(ctx,pubsock); - } - if ( (counter % 6000) == 10 ) - { - nonz++; - LP_privkey_updates(ctx,pubsock,0); - } HASH_ITER(hh,LP_coins,coin,ctmp) // firstrefht,firstscanht,lastscanht { if ( coin->addr_listunspent_requested != 0 ) @@ -647,15 +636,6 @@ int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int coin->lastgetinfo = (uint32_t)time(NULL); } } - if ( (counter % 100000) == 90000 ) - { - if ( (retstr= basilisk_swapentry(0,0)) != 0 ) - { - //printf("SWAPS.(%s)\n",retstr); - nonz++; - free(retstr); - } - } counter++; return(nonz); } @@ -722,6 +702,38 @@ void LP_initpeers(int32_t pubsock,struct LP_peerinfo *mypeer,char *myipaddr,uint } } +void LP_pubkeysloop(void *ctx) +{ + sleep(10); + while ( 1 ) + { + LP_notify_pubkeys(ctx,LP_mypubsock); + sleep(60); + } +} + +void LP_privkeysloop(void *ctx) +{ + sleep(20); + while ( 1 ) + { + LP_privkey_updates(ctx,LP_mypubsock,0); + sleep(60); + } +} + +void LP_swapsloop(void *ignore) +{ + char *retstr; + sleep(50); + while ( 1 ) + { + if ( (retstr= basilisk_swapentry(0,0)) != 0 ) + free(retstr); + sleep(600); + } +} + void LP_reserved_msgs(void *ignore) { bits256 zero; int32_t flag; struct nn_pollfd pfd; @@ -939,7 +951,22 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu printf("error launching LP_coinsloop for port.%u\n",myport); exit(-1); } - //if ( (retstr= basilisk_swapentry(0,0)) != 0 ) + if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_pubkeysloop,(void *)&myipaddr) != 0 ) + { + printf("error launching LP_pubkeysloop for ctx.%p\n",ctx); + exit(-1); + } + if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_privkeysloop,(void *)&myipaddr) != 0 ) + { + printf("error launching LP_privkeysloop for ctx.%p\n",ctx); + exit(-1); + } + if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_swapsloop,(void *)&myipaddr) != 0 ) + { + printf("error launching LP_swapsloop for port.%u\n",myport); + exit(-1); + } + //if ( (retstr= basilisk_swapentry(0,0)) != 0 ) // free(retstr); int32_t nonz; printf("start mainloop\n"); From 20f0a60e12f776aba42ec97ccfe2ff9d8f37266d Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Oct 2017 22:41:01 +0300 Subject: [PATCH 15/37] Test --- iguana/exchanges/LP_nativeDEX.c | 2 +- iguana/exchanges/LP_utxo.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 0e0f53128..7267f2d3f 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -547,7 +547,7 @@ void LP_coinsloop(void *myipaddr) continue; } //if ( (coin->lastscanht % 1000) == 0 ) - for (j=0; j<100; j++) + for (j=0; j<1; j++) { //if ( strcmp("REVS",coin->symbol) == 0 ) printf("%s ref.%d scan.%d to %d, longest.%d\n",coin->symbol,coin->firstrefht,coin->firstscanht,coin->lastscanht,coin->longestchain); diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index 97c40c7b0..0dab4f3a9 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -628,8 +628,8 @@ cJSON *LP_transactioninit(struct iguana_info *coin,bits256 txid,int32_t iter,cJS spentvout = jint(vin,"vout"); if ( i == 0 && bits256_nonz(spenttxid) == 0 ) continue; - if ( strcmp("REVS",coin->symbol) == 0 ) - printf("ht.%d vini.%d %s/v%d spent\n",height,i,bits256_str(str,spenttxid),spentvout); + //if ( strcmp("REVS",coin->symbol) == 0 ) + // printf("ht.%d vini.%d %s/v%d spent\n",height,i,bits256_str(str,spenttxid),spentvout); if ( (tx= LP_transactionfind(coin,spenttxid)) != 0 ) { if ( spentvout < tx->numvouts ) From 701f753fa3c0a023371d23342dde11e26ec6a561 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Oct 2017 22:49:43 +0300 Subject: [PATCH 16/37] 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 00590c8c8..2d1795fbd 100644 --- a/iguana/exchanges/LP_remember.c +++ b/iguana/exchanges/LP_remember.c @@ -353,7 +353,7 @@ int32_t basilisk_swap_isfinished(int32_t iambob,bits256 *txids,int32_t *sentflag { if ( bits256_nonz(txids[BASILISK_BOBDEPOSIT]) == 0 && sentflags[BASILISK_BOBDEPOSIT] == 0 ) return(1); - else if ( bits256_nonz(txids[BASILISK_BOBPAYMENT]) == 0 && sentflags[BASILISK_BOBPAYMENT] == 0 ) + else if ( bits256_nonz(txids[BASILISK_BOBPAYMENT]) == 0 || sentflags[BASILISK_BOBPAYMENT] == 0 ) { if ( bits256_nonz(depositspent) != 0 ) return(1); From a71351a87c93d7e3ab6f622c4bcc77a6b28ff0da Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Oct 2017 22:50:56 +0300 Subject: [PATCH 17/37] Test --- iguana/exchanges/LP_nativeDEX.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 7267f2d3f..d62d4ba41 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -546,11 +546,10 @@ void LP_coinsloop(void *myipaddr) coin->lastscanht = coin->firstscanht; continue; } - //if ( (coin->lastscanht % 1000) == 0 ) + if ( (coin->lastscanht % 1000) == 0 ) + printf("%s ref.%d scan.%d to %d, longest.%d\n",coin->symbol,coin->firstrefht,coin->firstscanht,coin->lastscanht,coin->longestchain); for (j=0; j<1; j++) { - //if ( strcmp("REVS",coin->symbol) == 0 ) - printf("%s ref.%d scan.%d to %d, longest.%d\n",coin->symbol,coin->firstrefht,coin->firstscanht,coin->lastscanht,coin->longestchain); if ( LP_blockinit(coin,coin->lastscanht) < 0 ) { printf("blockinit.%s %d error\n",coin->symbol,coin->lastscanht); From 5fcb9ee98d62ff649efc1fea8a87d19d35fc12c0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Oct 2017 22:51:11 +0300 Subject: [PATCH 18/37] 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 d62d4ba41..b4da4c940 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -533,7 +533,7 @@ void LP_coinsloop(void *myipaddr) } if ( coin->lastscanht == coin->longestchain+1 ) { - printf("%s lastscanht.%d is longest.%d + 1\n",coin->symbol,coin->lastscanht,coin->longestchain); + //printf("%s lastscanht.%d is longest.%d + 1\n",coin->symbol,coin->lastscanht,coin->longestchain); continue; } else if ( coin->lastscanht > coin->longestchain+1 ) From d275f9333320a811eb8bb1ca90ae6172311a47f7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Oct 2017 23:11:49 +0300 Subject: [PATCH 19/37] test --- iguana/exchanges/LP_remember.c | 46 ++++++++++++++++++++++++---------- 1 file changed, 33 insertions(+), 13 deletions(-) diff --git a/iguana/exchanges/LP_remember.c b/iguana/exchanges/LP_remember.c index 2d1795fbd..fec9242a4 100644 --- a/iguana/exchanges/LP_remember.c +++ b/iguana/exchanges/LP_remember.c @@ -847,7 +847,7 @@ int32_t LP_spends_set(struct LP_swap_remember *rswap) cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requestid,uint32_t quoteid) { static void *ctx; - struct LP_swap_remember rswap; int32_t i,j,numspent,len,secretstart,redeemlen; char str[65],*srcAdest,*srcBdest,*destAdest,*destBdest,otheraddr[64]; cJSON *item; bits256 rev,signedtxid,zero; struct iguana_info *bob=0,*alice=0; uint8_t redeemscript[1024],userdata[1024]; + struct LP_swap_remember rswap; int32_t i,j,flag,numspent,len,secretstart,redeemlen; char str[65],*srcAdest,*srcBdest,*destAdest,*destBdest,otheraddr[64]; cJSON *item,*txoutobj; bits256 rev,signedtxid,zero; struct iguana_info *bob=0,*alice=0; uint8_t redeemscript[1024],userdata[1024]; if ( ctx == 0 ) ctx = bitcoin_ctx(); if ( (rswap.iambob= LP_rswap_init(&rswap,requestid,quoteid)) < 0 ) @@ -927,7 +927,10 @@ cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requesti { if ( rswap.sentflags[BASILISK_BOBPAYMENT] != 0 && bits256_nonz(rswap.paymentspent) == 0 ) { - //if ( txbytes[BASILISK_ALICESPEND] == 0 ) + if ( (txoutobj= LP_gettxout(rswap.bobcoin,rswap.bobpaymentaddr,rswap.txids[BASILISK_BOBPAYMENT],0)) != 0 ) + free_json(txoutobj), flag = 0; + else flag = -1; + if ( flag == 0 ) { if ( bits256_nonz(rswap.txids[BASILISK_BOBPAYMENT]) != 0 ) { @@ -952,15 +955,18 @@ cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requesti if ( (rswap.txbytes[BASILISK_ALICESPEND]= basilisk_swap_bobtxspend(&signedtxid,rswap.Btxfee,"alicespend",rswap.bobcoin,bob->wiftaddr,bob->taddr,bob->pubtype,bob->p2shtype,bob->isPoS,bob->wiftype,ctx,rswap.myprivs[0],0,redeemscript,redeemlen,userdata,len,rswap.txids[BASILISK_BOBPAYMENT],0,0,rswap.pubkey33,1,rswap.expiration,&rswap.values[BASILISK_ALICESPEND],0,0,rswap.bobpaymentaddr,1)) != 0 ) printf("alicespend.(%s)\n",rswap.txbytes[BASILISK_ALICESPEND]); } + LP_txbytes_update("alicespend",rswap.bobcoin,rswap.txbytes[BASILISK_ALICESPEND],&rswap.txids[BASILISK_ALICESPEND],&rswap.paymentspent,&rswap.sentflags[BASILISK_ALICESPEND]); } - LP_txbytes_update("alicespend",rswap.bobcoin,rswap.txbytes[BASILISK_ALICESPEND],&rswap.txids[BASILISK_ALICESPEND],&rswap.paymentspent,&rswap.sentflags[BASILISK_ALICESPEND]); } } if ( rswap.sentflags[BASILISK_ALICECLAIM] == 0 && rswap.sentflags[BASILISK_BOBDEPOSIT] != 0 && bits256_nonz(rswap.txids[BASILISK_BOBDEPOSIT]) != 0 && bits256_nonz(rswap.depositspent) == 0 ) { if ( time(NULL) > rswap.expiration ) { - //if ( txbytes[BASILISK_ALICECLAIM] == 0 ) + if ( (txoutobj= LP_gettxout(rswap.bobcoin,rswap.bobdepositaddr,rswap.txids[BASILISK_BOBDEPOSIT],0)) != 0 ) + free_json(txoutobj), flag = 0; + else flag = -1; + if ( flag == 0 ) { if ( rswap.Dredeemlen != 0 ) redeemlen = rswap.Dredeemlen, memcpy(redeemscript,rswap.Dredeemscript,rswap.Dredeemlen); @@ -976,13 +982,16 @@ cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requesti printf("privBn.(%s) aliceclaim.(%s)\n",bits256_str(str,rswap.privBn),rswap.txbytes[BASILISK_ALICECLAIM]); } } + LP_txbytes_update("aliceclaim",rswap.bobcoin,rswap.txbytes[BASILISK_ALICECLAIM],&rswap.txids[BASILISK_ALICECLAIM],&rswap.depositspent,&rswap.sentflags[BASILISK_ALICECLAIM]); } - LP_txbytes_update("aliceclaim",rswap.bobcoin,rswap.txbytes[BASILISK_ALICECLAIM],&rswap.txids[BASILISK_ALICECLAIM],&rswap.depositspent,&rswap.sentflags[BASILISK_ALICECLAIM]); } else printf("now %u before expiration %u\n",(uint32_t)time(NULL),rswap.expiration); } if ( rswap.sentflags[BASILISK_ALICEPAYMENT] != 0 && bits256_nonz(rswap.Apaymentspent) == 0 && rswap.sentflags[BASILISK_ALICECLAIM] == 0 ) { - //if ( txbytes[BASILISK_ALICERECLAIM] == 0 ) + if ( (txoutobj= LP_gettxout(rswap.alicecoin,rswap.alicepaymentaddr,rswap.txids[BASILISK_ALICEPAYMENT],0)) != 0 ) + free_json(txoutobj), flag = 0; + else flag = -1; + if ( flag == 0 ) { rswap.privBn = basilisk_swap_privBn_extract(&rswap.txids[BASILISK_BOBREFUND],rswap.bobcoin,rswap.txids[BASILISK_BOBDEPOSIT],rswap.privBn); if ( bits256_nonz(rswap.txids[BASILISK_ALICEPAYMENT]) != 0 && bits256_nonz(rswap.privAm) != 0 && bits256_nonz(rswap.privBn) != 0 ) @@ -990,8 +999,8 @@ cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requesti if ( (rswap.txbytes[BASILISK_ALICERECLAIM]= basilisk_swap_Aspend("alicereclaim",rswap.alicecoin,rswap.Atxfee,alice->wiftaddr,alice->taddr,alice->pubtype,alice->p2shtype,alice->isPoS,alice->wiftype,ctx,rswap.privAm,rswap.privBn,rswap.txids[BASILISK_ALICEPAYMENT],0,rswap.pubkey33,rswap.expiration,&rswap.values[BASILISK_ALICERECLAIM],rswap.alicepaymentaddr)) != 0 ) printf("privBn.(%s) alicereclaim.(%s)\n",bits256_str(str,rswap.privBn),rswap.txbytes[BASILISK_ALICERECLAIM]); } + LP_txbytes_update("alicereclaim",rswap.alicecoin,rswap.txbytes[BASILISK_ALICERECLAIM],&rswap.txids[BASILISK_ALICERECLAIM],&rswap.Apaymentspent,&rswap.sentflags[BASILISK_ALICERECLAIM]); } - LP_txbytes_update("alicereclaim",rswap.alicecoin,rswap.txbytes[BASILISK_ALICERECLAIM],&rswap.txids[BASILISK_ALICERECLAIM],&rswap.Apaymentspent,&rswap.sentflags[BASILISK_ALICERECLAIM]); } } else if ( rswap.iambob == 1 ) @@ -1001,7 +1010,10 @@ cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requesti printf("try to bobspend aspend.%s have privAm.%d\n",bits256_str(str,rswap.txids[BASILISK_ALICESPEND]),bits256_nonz(rswap.privAm)); if ( bits256_nonz(rswap.txids[BASILISK_ALICESPEND]) != 0 || bits256_nonz(rswap.privAm) != 0 ) { - //if ( txbytes[BASILISK_BOBSPEND] == 0 ) + if ( (txoutobj= LP_gettxout(rswap.alicecoin,rswap.alicepaymentaddr,rswap.txids[BASILISK_ALICEPAYMENT],0)) != 0 ) + free_json(txoutobj), flag = 0; + else flag = -1; + if ( flag == 0 ) { if ( bits256_nonz(rswap.privAm) == 0 ) { @@ -1013,13 +1025,16 @@ cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requesti if ( (rswap.txbytes[BASILISK_BOBSPEND]= basilisk_swap_Aspend("bobspend",rswap.alicecoin,rswap.Atxfee,alice->wiftaddr,alice->taddr,alice->pubtype,alice->p2shtype,alice->isPoS,alice->wiftype,ctx,rswap.privAm,rswap.privBn,rswap.txids[BASILISK_ALICEPAYMENT],0,rswap.pubkey33,rswap.expiration,&rswap.values[BASILISK_BOBSPEND],rswap.alicepaymentaddr)) != 0 ) printf("bobspend.(%s)\n",rswap.txbytes[BASILISK_BOBSPEND]); } + LP_txbytes_update("bobspend",rswap.alicecoin,rswap.txbytes[BASILISK_BOBSPEND],&rswap.txids[BASILISK_BOBSPEND],&rswap.Apaymentspent,&rswap.sentflags[BASILISK_BOBSPEND]); } - LP_txbytes_update("bobspend",rswap.alicecoin,rswap.txbytes[BASILISK_BOBSPEND],&rswap.txids[BASILISK_BOBSPEND],&rswap.Apaymentspent,&rswap.sentflags[BASILISK_BOBSPEND]); } } if ( rswap.sentflags[BASILISK_BOBRECLAIM] == 0 && rswap.sentflags[BASILISK_BOBPAYMENT] != 0 && bits256_nonz(rswap.txids[BASILISK_BOBPAYMENT]) != 0 && time(NULL) > rswap.expiration && bits256_nonz(rswap.paymentspent) == 0 ) { - //if ( txbytes[BASILISK_BOBRECLAIM] == 0 ) + if ( (txoutobj= LP_gettxout(rswap.bobcoin,rswap.bobpaymentaddr,rswap.txids[BASILISK_BOBPAYMENT],0)) != 0 ) + free_json(txoutobj), flag = 0; + else flag = -1; + if ( flag == 0 ) { // 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); @@ -1034,12 +1049,15 @@ cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requesti printf(" secretAm, myprivs[1].(%s) bobreclaim.(%s)\n",bits256_str(str,rswap.myprivs[1]),rswap.txbytes[BASILISK_BOBRECLAIM]); } } + LP_txbytes_update("bobreclaim",rswap.bobcoin,rswap.txbytes[BASILISK_BOBRECLAIM],&rswap.txids[BASILISK_BOBRECLAIM],&rswap.paymentspent,&rswap.sentflags[BASILISK_BOBRECLAIM]); } - LP_txbytes_update("bobreclaim",rswap.bobcoin,rswap.txbytes[BASILISK_BOBRECLAIM],&rswap.txids[BASILISK_BOBRECLAIM],&rswap.paymentspent,&rswap.sentflags[BASILISK_BOBRECLAIM]); } if ( rswap.sentflags[BASILISK_BOBREFUND] == 0 && rswap.sentflags[BASILISK_BOBDEPOSIT] != 0 && bits256_nonz(rswap.txids[BASILISK_BOBDEPOSIT]) != 0 && bits256_nonz(rswap.depositspent) == 0 ) { - if ( bits256_nonz(rswap.Apaymentspent) != 0 || time(NULL) > rswap.expiration ) + if ( (txoutobj= LP_gettxout(rswap.bobcoin,rswap.bobdepositaddr,rswap.txids[BASILISK_BOBDEPOSIT],0)) != 0 ) + free_json(txoutobj), flag = 0; + else flag = -1; + if ( flag == 0 && (bits256_nonz(rswap.Apaymentspent) != 0 || time(NULL) > rswap.expiration) ) { 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 ) @@ -1052,7 +1070,9 @@ cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requesti printf("pubB1.(%s) bobrefund.(%s)\n",bits256_str(str,rswap.pubB1),rswap.txbytes[BASILISK_BOBREFUND]); } LP_txbytes_update("bobrefund",rswap.bobcoin,rswap.txbytes[BASILISK_BOBREFUND],&rswap.txids[BASILISK_BOBREFUND],&rswap.depositspent,&rswap.sentflags[BASILISK_BOBREFUND]); - } else printf("bobrefund's time %u vs expiration %u\n",(uint32_t)time(NULL),rswap.expiration); + } + else if ( flag == 0 ) + printf("bobrefund's time %u vs expiration %u\n",(uint32_t)time(NULL),rswap.expiration); } } } From 367016a8d1e2ee1ef6797122bf44cb70c5817812 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Oct 2017 23:19:26 +0300 Subject: [PATCH 20/37] Test --- iguana/exchanges/LP_remember.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/iguana/exchanges/LP_remember.c b/iguana/exchanges/LP_remember.c index fec9242a4..062b78886 100644 --- a/iguana/exchanges/LP_remember.c +++ b/iguana/exchanges/LP_remember.c @@ -847,11 +847,12 @@ int32_t LP_spends_set(struct LP_swap_remember *rswap) cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requestid,uint32_t quoteid) { static void *ctx; - struct LP_swap_remember rswap; int32_t i,j,flag,numspent,len,secretstart,redeemlen; char str[65],*srcAdest,*srcBdest,*destAdest,*destBdest,otheraddr[64]; cJSON *item,*txoutobj; bits256 rev,signedtxid,zero; struct iguana_info *bob=0,*alice=0; uint8_t redeemscript[1024],userdata[1024]; + struct LP_swap_remember rswap; int32_t i,j,flag,numspent,len,secretstart,redeemlen; char str[65],*srcAdest,*srcBdest,*destAdest,*destBdest,otheraddr[64]; cJSON *item,*txoutobj; bits256 rev,signedtxid,zero,deadtxid; struct iguana_info *bob=0,*alice=0; uint8_t redeemscript[1024],userdata[1024]; if ( ctx == 0 ) ctx = bitcoin_ctx(); if ( (rswap.iambob= LP_rswap_init(&rswap,requestid,quoteid)) < 0 ) return(cJSON_Parse("{\"error\":\"couldnt initialize rswap, are all coins active?\"}")); + decode_hex(deadtxid.bytes,32,"dead0000000000000000000000000000"); LP_swap_load(&rswap); memset(zero.bytes,0,sizeof(zero)); otheraddr[0] = 0; @@ -929,7 +930,7 @@ cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requesti { if ( (txoutobj= LP_gettxout(rswap.bobcoin,rswap.bobpaymentaddr,rswap.txids[BASILISK_BOBPAYMENT],0)) != 0 ) free_json(txoutobj), flag = 0; - else flag = -1; + else flag = -1, rswap.paymentspent = deadtxid; if ( flag == 0 ) { if ( bits256_nonz(rswap.txids[BASILISK_BOBPAYMENT]) != 0 ) @@ -965,7 +966,7 @@ cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requesti { if ( (txoutobj= LP_gettxout(rswap.bobcoin,rswap.bobdepositaddr,rswap.txids[BASILISK_BOBDEPOSIT],0)) != 0 ) free_json(txoutobj), flag = 0; - else flag = -1; + else flag = -1, rswap.depositspent = deadtxid; if ( flag == 0 ) { if ( rswap.Dredeemlen != 0 ) @@ -990,7 +991,7 @@ cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requesti { if ( (txoutobj= LP_gettxout(rswap.alicecoin,rswap.alicepaymentaddr,rswap.txids[BASILISK_ALICEPAYMENT],0)) != 0 ) free_json(txoutobj), flag = 0; - else flag = -1; + else flag = -1, rswap.Apaymentspent = deadtxid; if ( flag == 0 ) { rswap.privBn = basilisk_swap_privBn_extract(&rswap.txids[BASILISK_BOBREFUND],rswap.bobcoin,rswap.txids[BASILISK_BOBDEPOSIT],rswap.privBn); @@ -1012,7 +1013,7 @@ cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requesti { if ( (txoutobj= LP_gettxout(rswap.alicecoin,rswap.alicepaymentaddr,rswap.txids[BASILISK_ALICEPAYMENT],0)) != 0 ) free_json(txoutobj), flag = 0; - else flag = -1; + else flag = -1, rswap.Apaymentspent = deadtxid; if ( flag == 0 ) { if ( bits256_nonz(rswap.privAm) == 0 ) @@ -1033,7 +1034,7 @@ cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requesti { if ( (txoutobj= LP_gettxout(rswap.bobcoin,rswap.bobpaymentaddr,rswap.txids[BASILISK_BOBPAYMENT],0)) != 0 ) free_json(txoutobj), flag = 0; - else flag = -1; + else flag = -1, rswap.paymentspent = deadtxid; if ( flag == 0 ) { // bobreclaim @@ -1056,7 +1057,7 @@ cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requesti { if ( (txoutobj= LP_gettxout(rswap.bobcoin,rswap.bobdepositaddr,rswap.txids[BASILISK_BOBDEPOSIT],0)) != 0 ) free_json(txoutobj), flag = 0; - else flag = -1; + else flag = -1, rswap.depositspent = deadtxid; if ( flag == 0 && (bits256_nonz(rswap.Apaymentspent) != 0 || time(NULL) > rswap.expiration) ) { printf("do the refund! paymentspent.%s now.%u vs expiration.%u\n",bits256_str(str,rswap.paymentspent),(uint32_t)time(NULL),rswap.expiration); From 8ab979fc2c0bd30913c1b50149088392daecc1a6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Oct 2017 23:28:43 +0300 Subject: [PATCH 21/37] Test --- iguana/exchanges/LP_remember.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/iguana/exchanges/LP_remember.c b/iguana/exchanges/LP_remember.c index 062b78886..30893c288 100644 --- a/iguana/exchanges/LP_remember.c +++ b/iguana/exchanges/LP_remember.c @@ -852,7 +852,7 @@ cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requesti ctx = bitcoin_ctx(); if ( (rswap.iambob= LP_rswap_init(&rswap,requestid,quoteid)) < 0 ) return(cJSON_Parse("{\"error\":\"couldnt initialize rswap, are all coins active?\"}")); - decode_hex(deadtxid.bytes,32,"dead0000000000000000000000000000"); + decode_hex(deadtxid.bytes,32,"dead000000000000000000000000000000000000000000000000000000000000"); LP_swap_load(&rswap); memset(zero.bytes,0,sizeof(zero)); otheraddr[0] = 0; @@ -1030,12 +1030,12 @@ cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requesti } } } - if ( rswap.sentflags[BASILISK_BOBRECLAIM] == 0 && rswap.sentflags[BASILISK_BOBPAYMENT] != 0 && bits256_nonz(rswap.txids[BASILISK_BOBPAYMENT]) != 0 && time(NULL) > rswap.expiration && bits256_nonz(rswap.paymentspent) == 0 ) + if ( rswap.sentflags[BASILISK_BOBRECLAIM] == 0 && rswap.sentflags[BASILISK_BOBPAYMENT] != 0 && bits256_nonz(rswap.txids[BASILISK_BOBPAYMENT]) != 0 && bits256_nonz(rswap.paymentspent) == 0 ) { if ( (txoutobj= LP_gettxout(rswap.bobcoin,rswap.bobpaymentaddr,rswap.txids[BASILISK_BOBPAYMENT],0)) != 0 ) free_json(txoutobj), flag = 0; else flag = -1, rswap.paymentspent = deadtxid; - if ( flag == 0 ) + if ( flag == 0 && time(NULL) > rswap.expiration ) { // 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); @@ -1051,7 +1051,7 @@ cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requesti } } LP_txbytes_update("bobreclaim",rswap.bobcoin,rswap.txbytes[BASILISK_BOBRECLAIM],&rswap.txids[BASILISK_BOBRECLAIM],&rswap.paymentspent,&rswap.sentflags[BASILISK_BOBRECLAIM]); - } + } else printf("bobpayment spent.%d or now.%u < expiration %u\n",flag,(uint32_t)time(NULL),rswap.expiration); } if ( rswap.sentflags[BASILISK_BOBREFUND] == 0 && rswap.sentflags[BASILISK_BOBDEPOSIT] != 0 && bits256_nonz(rswap.txids[BASILISK_BOBDEPOSIT]) != 0 && bits256_nonz(rswap.depositspent) == 0 ) { From 2d05eb383d789e41a15e90daf8a5d3a98d25e728 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Oct 2017 23:30:41 +0300 Subject: [PATCH 22/37] 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 30893c288..eb3340d89 100644 --- a/iguana/exchanges/LP_remember.c +++ b/iguana/exchanges/LP_remember.c @@ -852,7 +852,7 @@ cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requesti ctx = bitcoin_ctx(); if ( (rswap.iambob= LP_rswap_init(&rswap,requestid,quoteid)) < 0 ) return(cJSON_Parse("{\"error\":\"couldnt initialize rswap, are all coins active?\"}")); - decode_hex(deadtxid.bytes,32,"dead000000000000000000000000000000000000000000000000000000000000"); + decode_hex(deadtxid.bytes,32,"deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef"); LP_swap_load(&rswap); memset(zero.bytes,0,sizeof(zero)); otheraddr[0] = 0; From 12ca02ad7d0ca73e7ab458f6a4e8520907e19186 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 Oct 2017 23:35:49 +0300 Subject: [PATCH 23/37] 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 eb3340d89..062c01997 100644 --- a/iguana/exchanges/LP_remember.c +++ b/iguana/exchanges/LP_remember.c @@ -260,7 +260,7 @@ bits256 basilisk_swap_spendupdate(int32_t iambob,char *symbol,char *spentaddr,in } txid = txids[utxoind]; memset(&spendtxid,0,sizeof(spendtxid)); - if ( bits256_nonz(txid) != 0 && sentflags[utxoind] != 0 ) + if ( bits256_nonz(txid) != 0 )//&& sentflags[utxoind] != 0 ) { destaddr[0] = 0; spendtxid = LP_swap_spendtxid(symbol,destaddr,txid,vout); From 1a353a7be7137835989eb5c9f10ffea57e6a1cae Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 23 Oct 2017 04:38:32 +0300 Subject: [PATCH 24/37] Test --- iguana/exchanges/LP_include.h | 2 +- iguana/exchanges/LP_ordermatch.c | 2 +- iguana/exchanges/LP_utxo.c | 4 +--- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/iguana/exchanges/LP_include.h b/iguana/exchanges/LP_include.h index cb5f54bd0..93421deae 100644 --- a/iguana/exchanges/LP_include.h +++ b/iguana/exchanges/LP_include.h @@ -44,7 +44,7 @@ #define LP_PEERGOOD_ERRORDECAY 0.9 #define LP_SWAPSTEP_TIMEOUT 30 -#define LP_AUTOTRADE_TIMEOUT 30 +#define LP_AUTOTRADE_TIMEOUT 15 #define LP_MIN_TXFEE 10000 #define LP_MINVOL 20 #define LP_MINCLIENTVOL 50 diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 5baf980a9..0aad4f785 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -81,7 +81,7 @@ double LP_quote_validate(struct LP_utxoinfo *autxo,struct LP_utxoinfo *butxo,str printf(">>>>>>> quote satoshis.(%.8f %.8f) %s %.8f -> %s %.8f\n",dstr(qp->satoshis),dstr(qp->destsatoshis),qp->srccoin,dstr(qp->satoshis),qp->destcoin,dstr(qp->destsatoshis)); if ( butxo != 0 ) { - if (LP_iseligible(&srcvalue,&srcvalue2,1,qp->srccoin,qp->txid,qp->vout,qp->satoshis,qp->txid2,qp->vout2) == 0 ) + if ( LP_iseligible(&srcvalue,&srcvalue2,1,qp->srccoin,qp->txid,qp->vout,qp->satoshis,qp->txid2,qp->vout2) == 0 ) { printf("bob not eligible %s\n",jprint(LP_quotejson(qp),1)); return(-2); diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index 0dab4f3a9..572faff33 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -628,8 +628,6 @@ cJSON *LP_transactioninit(struct iguana_info *coin,bits256 txid,int32_t iter,cJS spentvout = jint(vin,"vout"); if ( i == 0 && bits256_nonz(spenttxid) == 0 ) continue; - //if ( strcmp("REVS",coin->symbol) == 0 ) - // printf("ht.%d vini.%d %s/v%d spent\n",height,i,bits256_str(str,spenttxid),spentvout); if ( (tx= LP_transactionfind(coin,spenttxid)) != 0 ) { if ( spentvout < tx->numvouts ) @@ -640,7 +638,7 @@ cJSON *LP_transactioninit(struct iguana_info *coin,bits256 txid,int32_t iter,cJS tx->outpoints[spentvout].spendvini = i; tx->outpoints[spentvout].spendheight = height > 0 ? height : 1; LP_address_utxoadd(coin,tx->outpoints[spentvout].coinaddr,spenttxid,spentvout,tx->outpoints[spentvout].value,-1,height>0?height:1); - if ( 0 && strcmp(coin->symbol,"BTC") != 0 ) + if ( strcmp(coin->symbol,"REVS") == 0 ) printf("spend %s %s/v%d at ht.%d\n",coin->symbol,bits256_str(str,tx->txid),spentvout,height); } } else printf("LP_transactioninit: %s spentvout.%d < numvouts.%d spendheight.%d\n",bits256_str(str,spenttxid),spentvout,tx->numvouts,tx->outpoints[spentvout].spendheight); From d369178681e2fe8f337d931ae28b10a205c8edf7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 23 Oct 2017 04:45:05 +0300 Subject: [PATCH 25/37] 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 b4da4c940..3a4837243 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -548,7 +548,7 @@ void LP_coinsloop(void *myipaddr) } if ( (coin->lastscanht % 1000) == 0 ) printf("%s ref.%d scan.%d to %d, longest.%d\n",coin->symbol,coin->firstrefht,coin->firstscanht,coin->lastscanht,coin->longestchain); - for (j=0; j<1; j++) + for (j=0; j<100; j++) { if ( LP_blockinit(coin,coin->lastscanht) < 0 ) { From 6258ad1f0bbb8a12723b26df13d6aecb8c2fa195 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 23 Oct 2017 04:48:15 +0300 Subject: [PATCH 26/37] 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 3a4837243..b4da4c940 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -548,7 +548,7 @@ void LP_coinsloop(void *myipaddr) } if ( (coin->lastscanht % 1000) == 0 ) printf("%s ref.%d scan.%d to %d, longest.%d\n",coin->symbol,coin->firstrefht,coin->firstscanht,coin->lastscanht,coin->longestchain); - for (j=0; j<100; j++) + for (j=0; j<1; j++) { if ( LP_blockinit(coin,coin->lastscanht) < 0 ) { From 434072eaaff09da226aaa0e3842129715628df3b Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 23 Oct 2017 04:54:51 +0300 Subject: [PATCH 27/37] Test --- iguana/exchanges/LP_nativeDEX.c | 2 +- iguana/exchanges/LP_utxo.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index b4da4c940..114c7c204 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -546,7 +546,7 @@ void LP_coinsloop(void *myipaddr) coin->lastscanht = coin->firstscanht; continue; } - if ( (coin->lastscanht % 1000) == 0 ) + //if ( (coin->lastscanht % 1000) == 0 ) printf("%s ref.%d scan.%d to %d, longest.%d\n",coin->symbol,coin->firstrefht,coin->firstscanht,coin->lastscanht,coin->longestchain); for (j=0; j<1; j++) { diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index 572faff33..999c9ec4e 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -638,7 +638,7 @@ cJSON *LP_transactioninit(struct iguana_info *coin,bits256 txid,int32_t iter,cJS tx->outpoints[spentvout].spendvini = i; tx->outpoints[spentvout].spendheight = height > 0 ? height : 1; LP_address_utxoadd(coin,tx->outpoints[spentvout].coinaddr,spenttxid,spentvout,tx->outpoints[spentvout].value,-1,height>0?height:1); - if ( strcmp(coin->symbol,"REVS") == 0 ) + if ( 0 && strcmp(coin->symbol,"REVS") == 0 ) printf("spend %s %s/v%d at ht.%d\n",coin->symbol,bits256_str(str,tx->txid),spentvout,height); } } else printf("LP_transactioninit: %s spentvout.%d < numvouts.%d spendheight.%d\n",bits256_str(str,spenttxid),spentvout,tx->numvouts,tx->outpoints[spentvout].spendheight); From 2643edd11e372255d928cfcb18c5be06edfd2158 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 23 Oct 2017 05:01:48 +0300 Subject: [PATCH 28/37] Test --- iguana/exchanges/LP_nativeDEX.c | 2 +- iguana/exchanges/LP_remember.c | 18 +++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 114c7c204..75ff5541c 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -533,7 +533,7 @@ void LP_coinsloop(void *myipaddr) } if ( coin->lastscanht == coin->longestchain+1 ) { - //printf("%s lastscanht.%d is longest.%d + 1\n",coin->symbol,coin->lastscanht,coin->longestchain); + printf("%s lastscanht.%d is longest.%d + 1\n",coin->symbol,coin->lastscanht,coin->longestchain); continue; } else if ( coin->lastscanht > coin->longestchain+1 ) diff --git a/iguana/exchanges/LP_remember.c b/iguana/exchanges/LP_remember.c index 062c01997..34c3229bd 100644 --- a/iguana/exchanges/LP_remember.c +++ b/iguana/exchanges/LP_remember.c @@ -267,17 +267,17 @@ bits256 basilisk_swap_spendupdate(int32_t iambob,char *symbol,char *spentaddr,in if ( bits256_nonz(spendtxid) != 0 ) { sentflags[utxoind] = 1; - printf("utxoind.%d Alice.(%s %s) Bob.(%s %s) vs destaddr.(%s)\n",utxoind,aliceaddr,Adest,bobaddr,dest,destaddr); + //printf("utxoind.%d Alice.(%s %s) Bob.(%s %s) vs destaddr.(%s)\n",utxoind,aliceaddr,Adest,bobaddr,dest,destaddr); if ( aliceaddr != 0 && (strcmp(destaddr,aliceaddr) == 0 || strcmp(Adest,destaddr) == 0) ) { - printf("ALICE spent.(%s) -> %s\n",bits256_str(str,txid),destaddr); + //printf("ALICE spent.(%s) -> %s\n",bits256_str(str,txid),destaddr); sentflags[alicespent] = 1; sentflags[bobspent] = 0; txids[alicespent] = spendtxid; } else if ( bobaddr != 0 && (strcmp(destaddr,bobaddr) == 0 || strcmp(dest,destaddr) == 0) ) { - printf("BOB spent.(%s) -> %s\n",bits256_str(str,txid),destaddr); + //printf("BOB spent.(%s) -> %s\n",bits256_str(str,txid),destaddr); sentflags[bobspent] = 1; sentflags[alicespent] = 0; txids[bobspent] = spendtxid; @@ -298,7 +298,7 @@ bits256 basilisk_swap_spendupdate(int32_t iambob,char *symbol,char *spentaddr,in txids[alicespent] = spendtxid; } } - } else printf("no spend of %s/v%d detected\n",bits256_str(str,txid),vout); + } //else printf("no spend of %s/v%d detected\n",bits256_str(str,txid),vout); } else printf("utxoind.%d null txid\n",utxoind); return(spendtxid); } @@ -804,7 +804,7 @@ void LP_txbytes_update(char *name,char *symbol,char *txbytes,bits256 *txidp,bits int32_t LP_rswap_checktx(struct LP_swap_remember *rswap,char *symbol,int32_t txi) { - int32_t ht; struct iguana_info *coin; char str[65]; + int32_t ht; struct iguana_info *coin; //char str[65]; if ( rswap->sentflags[txi] == 0 && bits256_nonz(rswap->txids[txi]) != 0 ) { if ( (coin= LP_coinfind(symbol)) != 0 ) @@ -814,9 +814,9 @@ int32_t LP_rswap_checktx(struct LP_swap_remember *rswap,char *symbol,int32_t txi rswap->sentflags[txi] = 1; _LP_refht_update(coin,rswap->txids[txi],ht); } else LP_refht_update(symbol,rswap->txids[txi]); - printf("[%s] %s txbytes.%p %s ht.%d\n",txnames[txi],txnames[txi],rswap->txbytes[txi],bits256_str(str,rswap->txids[txi]),ht); + //printf("[%s] %s txbytes.%p %s ht.%d\n",txnames[txi],txnames[txi],rswap->txbytes[txi],bits256_str(str,rswap->txids[txi]),ht); } - } else printf("sent.%d %s txi.%d\n",rswap->sentflags[txi],bits256_str(str,rswap->txids[txi]),txi); + } //else printf("sent.%d %s txi.%d\n",rswap->sentflags[txi],bits256_str(str,rswap->txids[txi]),txi); return(0); } @@ -1008,7 +1008,7 @@ cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requesti { if ( rswap.sentflags[BASILISK_BOBSPEND] == 0 && bits256_nonz(rswap.Apaymentspent) == 0 ) { - printf("try to bobspend aspend.%s have privAm.%d\n",bits256_str(str,rswap.txids[BASILISK_ALICESPEND]),bits256_nonz(rswap.privAm)); + //printf("try to bobspend aspend.%s have privAm.%d\n",bits256_str(str,rswap.txids[BASILISK_ALICESPEND]),bits256_nonz(rswap.privAm)); if ( bits256_nonz(rswap.txids[BASILISK_ALICESPEND]) != 0 || bits256_nonz(rswap.privAm) != 0 ) { if ( (txoutobj= LP_gettxout(rswap.alicecoin,rswap.alicepaymentaddr,rswap.txids[BASILISK_ALICEPAYMENT],0)) != 0 ) @@ -1019,7 +1019,7 @@ cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requesti if ( bits256_nonz(rswap.privAm) == 0 ) { rswap.privAm = basilisk_swap_privbob_extract(rswap.bobcoin,rswap.txids[BASILISK_ALICESPEND],0,1); - printf("try to bobspend aspend.%s have privAm.%d\n",bits256_str(str,rswap.txids[BASILISK_ALICESPEND]),bits256_nonz(rswap.privAm)); + //printf("try to bobspend aspend.%s have privAm.%d\n",bits256_str(str,rswap.txids[BASILISK_ALICESPEND]),bits256_nonz(rswap.privAm)); } if ( bits256_nonz(rswap.privAm) != 0 && bits256_nonz(rswap.privBn) != 0 ) { From 5093e8771a79a1de66e8bd87c0e113306b63e71b Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 23 Oct 2017 05:12:27 +0300 Subject: [PATCH 29/37] Test --- iguana/exchanges/LP_nativeDEX.c | 27 ++++++++++++++++++--------- iguana/exchanges/LP_remember.c | 4 +++- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 75ff5541c..769fece73 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -509,14 +509,18 @@ int32_t LP_utxos_sync(struct LP_peerinfo *peer) return(posted); } -void LP_coinsloop(void *myipaddr) +void LP_coinsloop(void *_coins) { - struct iguana_info *coin,*ctmp; bits256 zero; int32_t j,nonz; + struct iguana_info *coin,*ctmp; bits256 zero; int32_t j,nonz; char *coins = _coins; while ( 1 ) { nonz = 0; HASH_ITER(hh,LP_coins,coin,ctmp) // firstrefht,firstscanht,lastscanht { + if ( coins[0] != 0 && strcmp(coins,coin->symbol) != 0 ) + continue; + else if ( strcmp("BTC",coin->symbol) == 0 ) + continue; memset(&zero,0,sizeof(zero)); if ( coin->inactive != 0 ) continue; @@ -547,7 +551,7 @@ void LP_coinsloop(void *myipaddr) continue; } //if ( (coin->lastscanht % 1000) == 0 ) - printf("%s ref.%d scan.%d to %d, longest.%d\n",coin->symbol,coin->firstrefht,coin->firstscanht,coin->lastscanht,coin->longestchain); + printf("[%s]: %s ref.%d scan.%d to %d, longest.%d\n",coins,coin->symbol,coin->firstrefht,coin->firstscanht,coin->lastscanht,coin->longestchain); for (j=0; j<1; j++) { if ( LP_blockinit(coin,coin->lastscanht) < 0 ) @@ -910,7 +914,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")); - if ( IAMLP != 0 && OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_psockloop,(void *)&myipaddr) != 0 ) + if ( IAMLP != 0 && OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_psockloop,(void *)myipaddr) != 0 ) { printf("error launching LP_psockloop for (%s)\n",myipaddr); exit(-1); @@ -930,27 +934,32 @@ 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); } - if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)command_rpcloop,(void *)&myipaddr) != 0 ) + if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)command_rpcloop,(void *)myipaddr) != 0 ) { printf("error launching command_rpcloop for port.%u\n",myport); exit(-1); } - if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)queue_loop,(void *)&myipaddr) != 0 ) + if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)queue_loop,(void *)myipaddr) != 0 ) { printf("error launching queue_loop for port.%u\n",myport); exit(-1); } - if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)prices_loop,(void *)&myipaddr) != 0 ) + if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)prices_loop,(void *)myipaddr) != 0 ) { printf("error launching prices_loop for port.%u\n",myport); exit(-1); } - if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_coinsloop,(void *)&myipaddr) != 0 ) + if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_coinsloop,(void *)"") != 0 ) { printf("error launching LP_coinsloop for port.%u\n",myport); exit(-1); } - if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_pubkeysloop,(void *)&myipaddr) != 0 ) + if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_coinsloop,(void *)"BTC") != 0 ) + { + printf("error launching BTC LP_coinsloop for port.%u\n",myport); + exit(-1); + } + if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_pubkeysloop,(void *)myipaddr) != 0 ) { printf("error launching LP_pubkeysloop for ctx.%p\n",ctx); exit(-1); diff --git a/iguana/exchanges/LP_remember.c b/iguana/exchanges/LP_remember.c index 34c3229bd..979e44a35 100644 --- a/iguana/exchanges/LP_remember.c +++ b/iguana/exchanges/LP_remember.c @@ -1051,7 +1051,9 @@ cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requesti } } LP_txbytes_update("bobreclaim",rswap.bobcoin,rswap.txbytes[BASILISK_BOBRECLAIM],&rswap.txids[BASILISK_BOBRECLAIM],&rswap.paymentspent,&rswap.sentflags[BASILISK_BOBRECLAIM]); - } else printf("bobpayment spent.%d or now.%u < expiration %u\n",flag,(uint32_t)time(NULL),rswap.expiration); + } + else if ( flag == 0 ) + printf("bobpayment: now.%u < expiration %u\n",(uint32_t)time(NULL),rswap.expiration); } if ( rswap.sentflags[BASILISK_BOBREFUND] == 0 && rswap.sentflags[BASILISK_BOBDEPOSIT] != 0 && bits256_nonz(rswap.txids[BASILISK_BOBDEPOSIT]) != 0 && bits256_nonz(rswap.depositspent) == 0 ) { From e3ff8f66f8b891af41a54bc344f2fe174382955b Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 23 Oct 2017 05:14:17 +0300 Subject: [PATCH 30/37] 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 769fece73..05463498c 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -552,7 +552,7 @@ void LP_coinsloop(void *_coins) } //if ( (coin->lastscanht % 1000) == 0 ) printf("[%s]: %s ref.%d scan.%d to %d, longest.%d\n",coins,coin->symbol,coin->firstrefht,coin->firstscanht,coin->lastscanht,coin->longestchain); - for (j=0; j<1; j++) + for (j=0; j<100; j++) { if ( LP_blockinit(coin,coin->lastscanht) < 0 ) { From b865f27975039d4442df47d7e464cc17de82e39b Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 23 Oct 2017 05:19:52 +0300 Subject: [PATCH 31/37] Test --- iguana/exchanges/LP_nativeDEX.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 05463498c..37176a928 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -519,7 +519,7 @@ void LP_coinsloop(void *_coins) { if ( coins[0] != 0 && strcmp(coins,coin->symbol) != 0 ) continue; - else if ( strcmp("BTC",coin->symbol) == 0 ) + else if ( strcmp("BTC",coin->symbol) == 0 || strcmp("KMD",coin->symbol) == 0 ) continue; memset(&zero,0,sizeof(zero)); if ( coin->inactive != 0 ) @@ -537,7 +537,7 @@ void LP_coinsloop(void *_coins) } if ( coin->lastscanht == coin->longestchain+1 ) { - printf("%s lastscanht.%d is longest.%d + 1\n",coin->symbol,coin->lastscanht,coin->longestchain); + //printf("%s lastscanht.%d is longest.%d + 1\n",coin->symbol,coin->lastscanht,coin->longestchain); continue; } else if ( coin->lastscanht > coin->longestchain+1 ) @@ -959,6 +959,11 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu printf("error launching BTC LP_coinsloop for port.%u\n",myport); exit(-1); } + if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_coinsloop,(void *)"KMD") != 0 ) + { + printf("error launching KMD LP_coinsloop for port.%u\n",myport); + exit(-1); + } if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_pubkeysloop,(void *)myipaddr) != 0 ) { printf("error launching LP_pubkeysloop for ctx.%p\n",ctx); From 718b7a146314d6c19702c382170d6c29aff04e51 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 23 Oct 2017 05:25:13 +0300 Subject: [PATCH 32/37] Test --- iguana/exchanges/LP_nativeDEX.c | 2 ++ iguana/exchanges/LP_remember.c | 6 +++--- iguana/exchanges/LP_transaction.c | 4 +++- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 37176a928..fcf10404b 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -521,6 +521,8 @@ void LP_coinsloop(void *_coins) continue; else if ( strcmp("BTC",coin->symbol) == 0 || strcmp("KMD",coin->symbol) == 0 ) continue; + if ( coins[0] != 0 ) + printf("%s loop\n",coins); memset(&zero,0,sizeof(zero)); if ( coin->inactive != 0 ) continue; diff --git a/iguana/exchanges/LP_remember.c b/iguana/exchanges/LP_remember.c index 979e44a35..778da68f4 100644 --- a/iguana/exchanges/LP_remember.c +++ b/iguana/exchanges/LP_remember.c @@ -670,7 +670,7 @@ int32_t LP_refht_update(char *symbol,bits256 txid) int32_t LP_swap_load(struct LP_swap_remember *rswap) { - int32_t i,needflag,addflag; long fsize; char fname[1024],str[65],*fstr,*symbol,*rstr; cJSON *txobj,*sentobj,*fileobj; bits256 txid,checktxid; uint64_t value; + int32_t i,needflag,addflag; long fsize; char fname[1024],*fstr,*symbol,*rstr; cJSON *txobj,*sentobj,*fileobj; bits256 txid,checktxid; uint64_t value; rswap->iambob = -1; sprintf(fname,"%s/SWAPS/%u-%u.finished",GLOBAL_DBDIR,rswap->requestid,rswap->quoteid), OS_compatible_path(fname); if ( (fstr= OS_filestr(&fsize,fname)) != 0 ) @@ -767,7 +767,7 @@ int32_t LP_swap_load(struct LP_swap_remember *rswap) } free_json(sentobj); } - printf("%s %s %.8f\n",txnames[i],bits256_str(str,txid),dstr(value)); + //printf("%s %s %.8f\n",txnames[i],bits256_str(str,txid),dstr(value)); } } } //else printf("no symbol\n"); @@ -1089,7 +1089,7 @@ cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requesti for (i=0; i 0 ) - printf("spend of %s/v%d detected\n",bits256_str(str,utxotxid),vout); + { + //printf("spend of %s/v%d detected\n",bits256_str(str,utxotxid),vout); + } else if ( 0 && (coin= LP_coinfind(symbol)) != 0 && coin->electrum == 0 ) { if ( (retjson= LP_gettxout(symbol,coinaddr,utxotxid,vout)) == 0 ) From 2db98761d42d157fffe2593629546b25e8cb3864 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 23 Oct 2017 05:28:58 +0300 Subject: [PATCH 33/37] Test --- iguana/exchanges/LP_nativeDEX.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index fcf10404b..4f930281d 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -517,10 +517,16 @@ void LP_coinsloop(void *_coins) nonz = 0; HASH_ITER(hh,LP_coins,coin,ctmp) // firstrefht,firstscanht,lastscanht { - if ( coins[0] != 0 && strcmp(coins,coin->symbol) != 0 ) - continue; - else if ( strcmp("BTC",coin->symbol) == 0 || strcmp("KMD",coin->symbol) == 0 ) - continue; + if ( coins[0] != 0 ) + { + if ( strcmp(coins,coin->symbol) != 0 ) + continue; + } + else // avoid hardcode special case LP_coinsloop + { + if ( strcmp("BTC",coin->symbol) == 0 || strcmp("KMD",coin->symbol) == 0 ) + continue; + } if ( coins[0] != 0 ) printf("%s loop\n",coins); memset(&zero,0,sizeof(zero)); From 8ebc7e51d02858682e5d4df7a42d768a8485dbb9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 23 Oct 2017 05:29:40 +0300 Subject: [PATCH 34/37] Test --- iguana/exchanges/LP_nativeDEX.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 4f930281d..df9a0d6eb 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -527,8 +527,6 @@ void LP_coinsloop(void *_coins) if ( strcmp("BTC",coin->symbol) == 0 || strcmp("KMD",coin->symbol) == 0 ) continue; } - if ( coins[0] != 0 ) - printf("%s loop\n",coins); memset(&zero,0,sizeof(zero)); if ( coin->inactive != 0 ) continue; From 02fcf328ac8333dbecbc9bed9576c0d50e6a9ba9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 23 Oct 2017 06:35:41 +0300 Subject: [PATCH 35/37] Test --- iguana/exchanges/LP_include.h | 2 +- iguana/exchanges/LP_nativeDEX.c | 2 +- iguana/exchanges/LP_signatures.c | 230 +++++++++++++++++++++++-------- 3 files changed, 176 insertions(+), 58 deletions(-) diff --git a/iguana/exchanges/LP_include.h b/iguana/exchanges/LP_include.h index 93421deae..5ec7f2350 100644 --- a/iguana/exchanges/LP_include.h +++ b/iguana/exchanges/LP_include.h @@ -286,7 +286,7 @@ struct LP_pubkeyinfo }; int32_t LP_pubkey_sigcheck(struct LP_pubkeyinfo *pubp,cJSON *item); -int32_t LP_pubkey_sigadd(cJSON *item,bits256 priv,bits256 pub,uint8_t *rmd160,uint8_t *pubsecp); +int32_t LP_pubkey_sigadd(cJSON *item,uint32_t timestamp,bits256 priv,bits256 pub,uint8_t *rmd160,uint8_t *pubsecp); void LP_swap_coinaddr(struct iguana_info *coin,char *coinaddr,uint64_t *valuep,uint8_t *data,int32_t datalen,int32_t vout); void basilisk_dontforget_update(struct basilisk_swap *swap,struct basilisk_rawtx *rawtx); uint32_t basilisk_requestid(struct basilisk_request *rp); diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index df9a0d6eb..05bef27d5 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -19,7 +19,7 @@ // marketmaker // // process stats.log local file -> map of realtime activity! -// sign price +// serialize sighash functions // select oldest utxo first // handles <-> pubkeys, deal with offline pubkeys, reputations, bonds etc. // diff --git a/iguana/exchanges/LP_signatures.c b/iguana/exchanges/LP_signatures.c index 9626aba6b..b38c5028f 100644 --- a/iguana/exchanges/LP_signatures.c +++ b/iguana/exchanges/LP_signatures.c @@ -181,9 +181,106 @@ char *LP_quotereceived(cJSON *argjson) } else return(clonestr("{\"error\":\"nullptr\"}")); } +int32_t LP_bitcoinsig_add(cJSON *item,bits256 priv,uint8_t *pubsecp,bits256 sighash) +{ + static void *ctx; int32_t i,j,siglen; uint8_t pub33[33],sig[65]; char sigstr[128]; + if ( ctx == 0 ) + ctx = bitcoin_ctx(); + for (j=0; j<100; j++) + { + if ( (siglen= bitcoin_sign(ctx,"sigadd",sig,sighash,priv,1)) > 0 && siglen == 65 ) + { + memset(pub33,0,33); + if ( bitcoin_recoververify(ctx,"test",sig,sighash,pub33,0) == 0 && memcmp(pub33,pubsecp,33) == 0 ) + { + init_hexbytes_noT(sigstr,sig,siglen); + jaddstr(item,"sig",sigstr); + return(siglen); + } + if ( 0 ) + { + for (i=0; i<33; i++) + printf("%02x",pubsecp[i]); + printf(" pubsecp -> "); + for (i=0; i<33; i++) + printf("%02x",pub33[i]); + printf(" mismatched recovered pubkey.%d of %d\n",j,100); + } + } + } + return(-1); +} + +bits256 LP_price_sighash(uint32_t timestamp,uint8_t *pubsecp,bits256 pubkey,char *base,char *rel,uint64_t price64) +{ + uint8_t buf[sizeof(pubkey) + 33 + sizeof(uint64_t)*3 + sizeof(timestamp)]; uint64_t basebits,relbits; bits256 sighash; + basebits = stringbits(base); + relbits = stringbits(rel); + memcpy(buf,pubkey.bytes,sizeof(pubkey)); + memcpy(&buf[sizeof(pubkey)],pubsecp,33); + memcpy(&buf[sizeof(pubkey)+33],&price64,sizeof(price64)); + memcpy(&buf[sizeof(pubkey)+33+sizeof(price64)],&basebits,sizeof(basebits)); + memcpy(&buf[sizeof(pubkey)+33+sizeof(price64)+sizeof(basebits)],&relbits,sizeof(relbits)); + memcpy(&buf[sizeof(pubkey)+33+sizeof(price64)+sizeof(basebits)+sizeof(relbits)],×tamp,sizeof(timestamp)); + vcalc_sha256(0,sighash.bytes,buf,sizeof(buf)); + return(sighash); +} + +bits256 LP_pubkey_sighash(uint32_t timestamp,bits256 pubkey,uint8_t *rmd160,uint8_t *pubsecp) +{ + uint8_t buf[sizeof(pubkey) + 20 + 33 + sizeof(timestamp)]; bits256 sighash; + memcpy(buf,pubkey.bytes,sizeof(pubkey)); + memcpy(&buf[sizeof(pubkey)],rmd160,20); + memcpy(&buf[sizeof(pubkey)+20],pubsecp,33); + memcpy(&buf[sizeof(pubkey)+20+33],×tamp,sizeof(timestamp)); + vcalc_sha256(0,sighash.bytes,buf,sizeof(buf)); + return(sighash); +} + +bits256 LP_utxos_sighash(uint32_t timestamp,uint8_t *pubsecp,bits256 pubkey,char *msg) +{ + uint8_t *buf; bits256 sighash; int32_t len; + len = (int32_t)strlen(msg) + sizeof(pubkey)+33+sizeof(timestamp); + buf = malloc(len+1); + memcpy(buf,pubkey.bytes,sizeof(pubkey)); + memcpy(&buf[sizeof(pubkey)],pubsecp,33); + memcpy(&buf[sizeof(pubkey)+33],×tamp,sizeof(timestamp)); + strcpy((char *)&buf[sizeof(pubkey)+33+sizeof(timestamp)],msg); + vcalc_sha256(0,sighash.bytes,buf,len); + free(buf); + return(sighash); +} + +int32_t LP_utxos_sigcheck(uint32_t timestamp,char *sigstr,char *pubsecpstr,bits256 pubkey,char *msg) +{ + static void *ctx; int32_t retval=-1; uint8_t pub33[33],pubsecp[33],sig[65]; bits256 sighash; + if ( ctx == 0 ) + ctx = bitcoin_ctx(); + if ( sigstr != 0 && pubsecpstr != 0 && strlen(sigstr) == 65*2 && strlen(pubsecpstr) == 33 *2 ) + { + decode_hex(sig,65,sigstr); + decode_hex(pubsecp,33,pubsecpstr); + sighash = LP_utxos_sighash(timestamp,pubsecp,pubkey,msg); + retval = bitcoin_recoververify(ctx,"price",sig,sighash,pub33,0); + if ( memcmp(pub33,pubsecp,33) != 0 || retval != 0 ) + { + printf("LP_utxos_sigcheck failure\n"); + retval = -1; + } else retval = 0; + } + return(retval); +} + +int32_t LP_utxos_sigadd(cJSON *item,uint32_t timestamp,bits256 priv,uint8_t *pubsecp,bits256 pubkey,char *msg) +{ + bits256 sighash; + sighash = LP_utxos_sighash(timestamp,pubsecp,pubkey,msg); + return(LP_bitcoinsig_add(item,priv,pubsecp,sighash)); +} + void LP_postutxos(char *symbol,char *coinaddr) { - bits256 zero; struct iguana_info *coin; cJSON *array,*reqjson = cJSON_CreateObject(); + bits256 zero; uint32_t timestamp; char *msg,pubsecpstr[67]; struct iguana_info *coin; cJSON *array,*reqjson = cJSON_CreateObject(); if ( (coin= LP_coinfind(symbol)) != 0 && (array= LP_address_utxos(coin,coinaddr,1)) != 0 ) { //printf("LP_postutxos pubsock.%d %s %s\n",pubsock,symbol,coin->smartaddr); @@ -196,6 +293,14 @@ void LP_postutxos(char *symbol,char *coinaddr) jaddstr(reqjson,"coin",symbol); jaddstr(reqjson,"coinaddr",coinaddr); jadd(reqjson,"utxos",array); + timestamp = (uint32_t)time(NULL); + jaddnum(reqjson,"timetamp",timestamp); + init_hexbytes_noT(pubsecpstr,G.LP_pubsecp,33); + jaddstr(reqjson,"pubsecp",pubsecpstr); + jaddbits256(reqjson,"pubkey",G.LP_mypub25519); + msg = jprint(array,0); + LP_utxos_sigadd(reqjson,timestamp,G.LP_privkey,G.LP_pubsecp,G.LP_mypub25519,msg); + free(msg); //printf("post (%s) -> %d\n",msg,LP_mypubsock); LP_reserved_msg(symbol,symbol,zero,jprint(reqjson,1)); } @@ -207,11 +312,21 @@ struct LP_utxos_qitem { struct queueitem DL; cJSON *argjson; }; char *LP_postutxos_recv(cJSON *argjson) { - struct LP_utxos_qitem *uitem; - uitem = calloc(1,sizeof(*uitem)); - uitem->argjson = jduplicate(argjson); - queue_enqueue("utxosQ",&utxosQ,&uitem->DL); - return(clonestr("{\"result\":\"success\"}")); + struct LP_utxos_qitem *uitem; char *msg; cJSON *obj; + if ( (obj= jobj(argjson,"utxos")) != 0 ) + { + msg = jprint(obj,0); + if ( LP_utxos_sigcheck(juint(argjson,"timestamp"),jstr(argjson,"sig"),jstr(argjson,"pubsecp"),jbits256(argjson,"pubkey"),msg) == 0 ) + { + free(msg); + uitem = calloc(1,sizeof(*uitem)); + uitem->argjson = jduplicate(argjson); + queue_enqueue("utxosQ",&utxosQ,&uitem->DL); + return(clonestr("{\"result\":\"success\"}")); + } + free(msg); + } + return(clonestr("{\"error\":\"sig failure\"}")); } int32_t LP_utxosQ_process() @@ -237,9 +352,36 @@ int32_t LP_utxosQ_process() return(0); } +int32_t LP_price_sigcheck(uint32_t timestamp,char *sigstr,char *pubsecpstr,bits256 pubkey,char *base,char *rel,uint64_t price64) +{ + static void *ctx; int32_t retval=-1; uint8_t pub33[33],pubsecp[33],sig[65]; bits256 sighash; + if ( ctx == 0 ) + ctx = bitcoin_ctx(); + if ( sigstr != 0 && pubsecpstr != 0 && strlen(sigstr) == 65*2 && strlen(pubsecpstr) == 33 *2 ) + { + decode_hex(sig,65,sigstr); + decode_hex(pubsecp,33,pubsecpstr); + sighash = LP_price_sighash(timestamp,pubsecp,pubkey,base,rel,price64); + retval = bitcoin_recoververify(ctx,"price",sig,sighash,pub33,0); + if ( memcmp(pub33,pubsecp,33) != 0 || retval != 0 ) + { + printf("LP_price_sigcheck failure\n"); + retval = -1; + } else retval = 0; + } + return(retval); +} + +int32_t LP_price_sigadd(cJSON *item,uint32_t timestamp,bits256 priv,uint8_t *pubsecp,bits256 pubkey,char *base,char *rel,uint64_t price64) +{ + bits256 sighash; + sighash = LP_price_sighash(timestamp,pubsecp,pubkey,base,rel,price64); + return(LP_bitcoinsig_add(item,priv,pubsecp,sighash)); +} + char *LP_pricepings(void *ctx,char *myipaddr,int32_t pubsock,char *base,char *rel,double price) { - struct iguana_info *basecoin,*relcoin; bits256 zero; cJSON *reqjson = cJSON_CreateObject(); + struct iguana_info *basecoin,*relcoin; char pubsecpstr[67]; uint32_t timestamp; uint64_t price64; bits256 zero; cJSON *reqjson = cJSON_CreateObject(); // LP_addsig if ( (basecoin= LP_coinfind(base)) != 0 && (relcoin= LP_coinfind(rel)) != 0 && basecoin->electrum == 0 && relcoin->electrum == 0 ) { @@ -247,8 +389,15 @@ char *LP_pricepings(void *ctx,char *myipaddr,int32_t pubsock,char *base,char *re jaddbits256(reqjson,"pubkey",G.LP_mypub25519); jaddstr(reqjson,"base",base); jaddstr(reqjson,"rel",rel); + price64 = price * SATOSHIDEN + 0.0000000049; jaddnum(reqjson,"price",price); + jadd64bits(reqjson,"price64",price64); jaddstr(reqjson,"method","postprice"); + timestamp = (uint32_t)time(NULL); + jaddnum(reqjson,"timestamp",timestamp); + init_hexbytes_noT(pubsecpstr,G.LP_pubsecp,33); + jaddstr(reqjson,"pubsecp",pubsecpstr); + LP_price_sigadd(reqjson,timestamp,G.LP_privkey,G.LP_pubsecp,G.LP_mypub25519,base,rel,price64); LP_reserved_msg(base,rel,zero,jprint(reqjson,1)); return(clonestr("{\"result\":\"success\"}")); } else return(clonestr("{\"error\":\"electrum node cant post bob asks\"}")); @@ -263,62 +412,30 @@ char *LP_postprice_recv(cJSON *argjson) pubkey = jbits256(argjson,"pubkey"); if ( bits256_nonz(pubkey) != 0 ) { - LP_pricefeedupdate(pubkey,base,rel,price); - return(clonestr("{\"result\":\"success\"}")); + if ( LP_price_sigcheck(juint(argjson,"timestamp"),jstr(argjson,"sig"),jstr(argjson,"pubsecp"),pubkey,base,rel,j64bits(argjson,"price64")) == 0 ) + { + LP_pricefeedupdate(pubkey,base,rel,price); + return(clonestr("{\"result\":\"success\"}")); + } else return(clonestr("{\"error\":\"sig failure\"}")); } } return(clonestr("{\"error\":\"missing fields in posted price\"}")); } -bits256 LP_pubkey_sighash(bits256 pub,uint8_t *rmd160,uint8_t *pubsecp) -{ - uint8_t buf[sizeof(pub) + 20 + 33]; bits256 sighash; - memcpy(buf,pub.bytes,sizeof(pub)); - memcpy(&buf[sizeof(pub)],rmd160,20); - memcpy(&buf[sizeof(pub)+20],pubsecp,33); - vcalc_sha256(0,sighash.bytes,buf,sizeof(buf)); - return(sighash); -} - -int32_t _LP_pubkey_sigcheck(uint8_t *sig,int32_t siglen,bits256 pub,uint8_t *rmd160,uint8_t *pubsecp) +int32_t _LP_pubkey_sigcheck(uint8_t *sig,int32_t siglen,uint32_t timestamp,bits256 pub,uint8_t *rmd160,uint8_t *pubsecp) { - static void *ctx; - uint8_t pub33[33]; bits256 sighash = LP_pubkey_sighash(pub,rmd160,pubsecp); + static void *ctx; uint8_t pub33[33]; bits256 sighash; if ( ctx == 0 ) ctx = bitcoin_ctx(); - return(bitcoin_recoververify(ctx,"sigcheck",sig,sighash,pub33,0)); + sighash = LP_pubkey_sighash(timestamp,pub,rmd160,pubsecp); + return(bitcoin_recoververify(ctx,"pubkey",sig,sighash,pub33,0)); } -int32_t LP_pubkey_sigadd(cJSON *item,bits256 priv,bits256 pub,uint8_t *rmd160,uint8_t *pubsecp) +int32_t LP_pubkey_sigadd(cJSON *item,uint32_t timestamp,bits256 priv,bits256 pub,uint8_t *rmd160,uint8_t *pubsecp) { - static void *ctx; - uint8_t sig[128],pub33[33]; int32_t i,j,siglen=0; bits256 sighash; char sigstr[256]; - sighash = LP_pubkey_sighash(pub,rmd160,pubsecp); - if ( ctx == 0 ) - ctx = bitcoin_ctx(); - for (j=0; j<100; j++) - { - if ( (siglen= bitcoin_sign(ctx,"sigadd",sig,sighash,priv,1)) > 0 && siglen == 65 ) - { - memset(pub33,0,33); - if ( bitcoin_recoververify(ctx,"test",sig,sighash,pub33,0) == 0 && memcmp(pub33,pubsecp,33) == 0 ) - { - init_hexbytes_noT(sigstr,sig,siglen); - jaddstr(item,"sig",sigstr); - return(siglen); - } - if ( 0 ) - { - for (i=0; i<33; i++) - printf("%02x",pubsecp[i]); - printf(" pubsecp -> "); - for (i=0; i<33; i++) - printf("%02x",pub33[i]); - printf(" mismatched recovered pubkey.%d of %d\n",j,100); - } - } - } - return(0); + bits256 sighash; + sighash = LP_pubkey_sighash(timestamp,pub,rmd160,pubsecp); + return(LP_bitcoinsig_add(item,priv,pubsecp,sighash)); } int32_t LP_pubkey_sigcheck(struct LP_pubkeyinfo *pubp,cJSON *item) @@ -342,7 +459,7 @@ int32_t LP_pubkey_sigcheck(struct LP_pubkeyinfo *pubp,cJSON *item) { siglen = len >> 1; decode_hex(sig,siglen,sigstr); - if ( _LP_pubkey_sigcheck(sig,siglen,pubp->pubkey,rmd160,pubsecp) == 0 ) + if ( _LP_pubkey_sigcheck(sig,siglen,juint(item,"timestamp"),pubp->pubkey,rmd160,pubsecp) == 0 ) { for (i=0; i<20; i++) printf("%02x",pubp->rmd160[i]); @@ -374,15 +491,16 @@ int32_t LP_pubkey_sigcheck(struct LP_pubkeyinfo *pubp,cJSON *item) void LP_notify_pubkeys(void *ctx,int32_t pubsock) { - bits256 zero; char secpstr[67]; cJSON *reqjson = cJSON_CreateObject(); - // LP_addsig + bits256 zero; uint32_t timestamp; char secpstr[67]; cJSON *reqjson = cJSON_CreateObject(); memset(zero.bytes,0,sizeof(zero)); jaddstr(reqjson,"method","notify"); jaddstr(reqjson,"rmd160",G.LP_myrmd160str); jaddbits256(reqjson,"pub",G.LP_mypub25519); init_hexbytes_noT(secpstr,G.LP_pubsecp,33); jaddstr(reqjson,"pubsecp",secpstr); - LP_pubkey_sigadd(reqjson,G.LP_privkey,G.LP_mypub25519,G.LP_myrmd160,G.LP_pubsecp); + timestamp = (uint32_t)time(NULL); + jaddnum(reqjson,"timestamp",timestamp); + LP_pubkey_sigadd(reqjson,timestamp,G.LP_privkey,G.LP_mypub25519,G.LP_myrmd160,G.LP_pubsecp); LP_reserved_msg("","",zero,jprint(reqjson,1)); } From f668e9a1f03b42ac53b7b4480b2bfdcc7407d706 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 23 Oct 2017 06:51:46 +0300 Subject: [PATCH 36/37] Test --- iguana/exchanges/LP_signatures.c | 63 +++++++++++++++++++++----------- 1 file changed, 41 insertions(+), 22 deletions(-) diff --git a/iguana/exchanges/LP_signatures.c b/iguana/exchanges/LP_signatures.c index b38c5028f..8d461a450 100644 --- a/iguana/exchanges/LP_signatures.c +++ b/iguana/exchanges/LP_signatures.c @@ -237,21 +237,18 @@ bits256 LP_pubkey_sighash(uint32_t timestamp,bits256 pubkey,uint8_t *rmd160,uint return(sighash); } -bits256 LP_utxos_sighash(uint32_t timestamp,uint8_t *pubsecp,bits256 pubkey,char *msg) +bits256 LP_utxos_sighash(uint32_t timestamp,uint8_t *pubsecp,bits256 pubkey,bits256 utxoshash) { - uint8_t *buf; bits256 sighash; int32_t len; - len = (int32_t)strlen(msg) + sizeof(pubkey)+33+sizeof(timestamp); - buf = malloc(len+1); + uint8_t buf[sizeof(pubkey)+sizeof(utxoshash)+33+sizeof(timestamp)]; bits256 sighash; memcpy(buf,pubkey.bytes,sizeof(pubkey)); memcpy(&buf[sizeof(pubkey)],pubsecp,33); memcpy(&buf[sizeof(pubkey)+33],×tamp,sizeof(timestamp)); - strcpy((char *)&buf[sizeof(pubkey)+33+sizeof(timestamp)],msg); - vcalc_sha256(0,sighash.bytes,buf,len); - free(buf); + memcpy(&buf[sizeof(pubkey)+33+sizeof(timestamp)],utxoshash.bytes,sizeof(utxoshash)); + vcalc_sha256(0,sighash.bytes,buf,sizeof(buf)); return(sighash); } -int32_t LP_utxos_sigcheck(uint32_t timestamp,char *sigstr,char *pubsecpstr,bits256 pubkey,char *msg) +int32_t LP_utxos_sigcheck(uint32_t timestamp,char *sigstr,char *pubsecpstr,bits256 pubkey,bits256 utxoshash) { static void *ctx; int32_t retval=-1; uint8_t pub33[33],pubsecp[33],sig[65]; bits256 sighash; if ( ctx == 0 ) @@ -260,8 +257,8 @@ int32_t LP_utxos_sigcheck(uint32_t timestamp,char *sigstr,char *pubsecpstr,bits2 { decode_hex(sig,65,sigstr); decode_hex(pubsecp,33,pubsecpstr); - sighash = LP_utxos_sighash(timestamp,pubsecp,pubkey,msg); - retval = bitcoin_recoververify(ctx,"price",sig,sighash,pub33,0); + sighash = LP_utxos_sighash(timestamp,pubsecp,pubkey,utxoshash); + retval = bitcoin_recoververify(ctx,"utxos",sig,sighash,pub33,0); if ( memcmp(pub33,pubsecp,33) != 0 || retval != 0 ) { printf("LP_utxos_sigcheck failure\n"); @@ -271,16 +268,34 @@ int32_t LP_utxos_sigcheck(uint32_t timestamp,char *sigstr,char *pubsecpstr,bits2 return(retval); } -int32_t LP_utxos_sigadd(cJSON *item,uint32_t timestamp,bits256 priv,uint8_t *pubsecp,bits256 pubkey,char *msg) +bits256 LP_utxoshash_calc(cJSON *array) +{ + int32_t i,j,n; bits256 utxoshash,txid; cJSON *item; + memset(utxoshash.bytes,0,sizeof(utxoshash)); + if ( (n= cJSON_GetArraySize(array)) > 0 ) + { + for (i=0; ismartaddr); @@ -298,9 +313,9 @@ void LP_postutxos(char *symbol,char *coinaddr) init_hexbytes_noT(pubsecpstr,G.LP_pubsecp,33); jaddstr(reqjson,"pubsecp",pubsecpstr); jaddbits256(reqjson,"pubkey",G.LP_mypub25519); - msg = jprint(array,0); - LP_utxos_sigadd(reqjson,timestamp,G.LP_privkey,G.LP_pubsecp,G.LP_mypub25519,msg); - free(msg); + utxoshash = LP_utxoshash_calc(array); + char str[65]; printf("utxoshash add %s\n",bits256_str(str,utxoshash)); + LP_utxos_sigadd(reqjson,timestamp,G.LP_privkey,G.LP_pubsecp,G.LP_mypub25519,utxoshash); //printf("post (%s) -> %d\n",msg,LP_mypubsock); LP_reserved_msg(symbol,symbol,zero,jprint(reqjson,1)); } @@ -312,19 +327,18 @@ struct LP_utxos_qitem { struct queueitem DL; cJSON *argjson; }; char *LP_postutxos_recv(cJSON *argjson) { - struct LP_utxos_qitem *uitem; char *msg; cJSON *obj; + struct LP_utxos_qitem *uitem; bits256 utxoshash; cJSON *obj; if ( (obj= jobj(argjson,"utxos")) != 0 ) { - msg = jprint(obj,0); - if ( LP_utxos_sigcheck(juint(argjson,"timestamp"),jstr(argjson,"sig"),jstr(argjson,"pubsecp"),jbits256(argjson,"pubkey"),msg) == 0 ) + utxoshash = LP_utxoshash_calc(obj); + char str[65]; printf("got utxoshash %s\n",bits256_str(str,utxoshash)); + if ( LP_utxos_sigcheck(juint(argjson,"timestamp"),jstr(argjson,"sig"),jstr(argjson,"pubsecp"),jbits256(argjson,"pubkey"),utxoshash) == 0 ) { - free(msg); uitem = calloc(1,sizeof(*uitem)); uitem->argjson = jduplicate(argjson); queue_enqueue("utxosQ",&utxosQ,&uitem->DL); return(clonestr("{\"result\":\"success\"}")); } - free(msg); } return(clonestr("{\"error\":\"sig failure\"}")); } @@ -367,7 +381,12 @@ int32_t LP_price_sigcheck(uint32_t timestamp,char *sigstr,char *pubsecpstr,bits2 { printf("LP_price_sigcheck failure\n"); retval = -1; - } else retval = 0; + } + else + { + retval = 0; + printf("valid price sig %s/%s %.8f\n",base,rel,dstr(price64)); + } } return(retval); } From 77c947733bdc29ee32109fa74c05ef503145f2b9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 23 Oct 2017 06:56:06 +0300 Subject: [PATCH 37/37] Test --- iguana/exchanges/LP_signatures.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/iguana/exchanges/LP_signatures.c b/iguana/exchanges/LP_signatures.c index 8d461a450..830dae61b 100644 --- a/iguana/exchanges/LP_signatures.c +++ b/iguana/exchanges/LP_signatures.c @@ -261,7 +261,7 @@ int32_t LP_utxos_sigcheck(uint32_t timestamp,char *sigstr,char *pubsecpstr,bits2 retval = bitcoin_recoververify(ctx,"utxos",sig,sighash,pub33,0); if ( memcmp(pub33,pubsecp,33) != 0 || retval != 0 ) { - printf("LP_utxos_sigcheck failure\n"); + printf("LP_utxos_sigcheck failure, probably from node with older version\n"); retval = -1; } else retval = 0; } @@ -314,7 +314,7 @@ void LP_postutxos(char *symbol,char *coinaddr) jaddstr(reqjson,"pubsecp",pubsecpstr); jaddbits256(reqjson,"pubkey",G.LP_mypub25519); utxoshash = LP_utxoshash_calc(array); - char str[65]; printf("utxoshash add %s\n",bits256_str(str,utxoshash)); + //char str[65]; printf("utxoshash add %s\n",bits256_str(str,utxoshash)); LP_utxos_sigadd(reqjson,timestamp,G.LP_privkey,G.LP_pubsecp,G.LP_mypub25519,utxoshash); //printf("post (%s) -> %d\n",msg,LP_mypubsock); LP_reserved_msg(symbol,symbol,zero,jprint(reqjson,1)); @@ -331,7 +331,7 @@ char *LP_postutxos_recv(cJSON *argjson) if ( (obj= jobj(argjson,"utxos")) != 0 ) { utxoshash = LP_utxoshash_calc(obj); - char str[65]; printf("got utxoshash %s\n",bits256_str(str,utxoshash)); + //char str[65]; printf("got utxoshash %s\n",bits256_str(str,utxoshash)); if ( LP_utxos_sigcheck(juint(argjson,"timestamp"),jstr(argjson,"sig"),jstr(argjson,"pubsecp"),jbits256(argjson,"pubkey"),utxoshash) == 0 ) { uitem = calloc(1,sizeof(*uitem)); @@ -385,7 +385,7 @@ int32_t LP_price_sigcheck(uint32_t timestamp,char *sigstr,char *pubsecpstr,bits2 else { retval = 0; - printf("valid price sig %s/%s %.8f\n",base,rel,dstr(price64)); + //printf("valid price sig %s/%s %.8f\n",base,rel,dstr(price64)); } } return(retval);