From d6dce089f57cc7c473a4af8851ea847f51918633 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 2 Dec 2017 11:20:58 +0400 Subject: [PATCH 01/59] Test --- iguana/exchanges/LP_instantdex.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_instantdex.c b/iguana/exchanges/LP_instantdex.c index d2ee44382..c398d505b 100644 --- a/iguana/exchanges/LP_instantdex.c +++ b/iguana/exchanges/LP_instantdex.c @@ -214,7 +214,7 @@ char *LP_instantdex_claim(struct iguana_info *coin) newarray = cJSON_CreateArray(); if ( (array= LP_instantdex_txids()) != 0 ) { - //printf("claiming from.(%s)\n",jprint(array,0)); + printf("claiming from.(%s)\n",jprint(array,0)); if ( (n= cJSON_GetArraySize(array)) > 0 ) { flag = 0; From 02c12ebd2f7f72ba42ddf3ed5bc8a289e7ed51c1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 2 Dec 2017 14:35:48 +0400 Subject: [PATCH 02/59] Test --- iguana/exchanges/stats.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/stats.c b/iguana/exchanges/stats.c index 69d6435ab..abb7b785d 100644 --- a/iguana/exchanges/stats.c +++ b/iguana/exchanges/stats.c @@ -33,7 +33,7 @@ char *stats_JSON(void *ctx,char *myipaddr,int32_t mypubsock,cJSON *argjson,char char *stats_validmethods[] = { "psock", "getprices", "notify", "getpeers", // from issue_ "uitem", "listunspent", - "orderbook", "help", "getcoins", "pricearray", "balance", "tradesarray" + "orderbook", "statsdisp", "help", "getcoins", "pricearray", "balance", "tradesarray" }; int32_t LP_valid_remotemethod(cJSON *argjson) From a4bfef1b12d13738a4e764bf49b34d4bc45c9be8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 2 Dec 2017 20:17:17 +0400 Subject: [PATCH 03/59] Test --- iguana/exchanges/LP_socket.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_socket.c b/iguana/exchanges/LP_socket.c index af827b346..481a31ded 100644 --- a/iguana/exchanges/LP_socket.c +++ b/iguana/exchanges/LP_socket.c @@ -445,7 +445,7 @@ cJSON *electrum_submit(char *symbol,struct electrum_info *ep,cJSON **retjsonp,ch } return(*retjsonp); } - } else printf("couldnt find electrum server for (%s %s) or no retjsonp.%p\n",method,params,retjsonp); + } //else printf("couldnt find electrum server for (%s %s) or no retjsonp.%p\n",method,params,retjsonp); ep = ep->prev; //if ( ep != 0 ) // printf("using prev ep.%s\n",ep->symbol); From 6bf7dc3dce36348f66bb38a19d55bcd30babe918 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 2 Dec 2017 20:18:10 +0400 Subject: [PATCH 04/59] Test --- iguana/exchanges/LP_nativeDEX.c | 1 + 1 file changed, 1 insertion(+) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 4a853cd6d..7a8b48699 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -589,6 +589,7 @@ void LP_coinsloop(void *_coins) //printf("%s electrum.%p needs a keepalive: lag.%d\n",ep->symbol,ep,(int32_t)(time(NULL) - ep->keepalive)); if ( (retjson= electrum_banner(coin->symbol,ep,&retjson)) != 0 ) free_json(retjson); + ep->keepalive = (uint32_t)time(NULL); } ep = ep->prev; } From dcf8c2c797d79d298637912e8a70f8e043871853 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 2 Dec 2017 22:51:51 +0400 Subject: [PATCH 05/59] Test --- iguana/exchanges/LP_instantdex.c | 13 +++++++++---- iguana/exchanges/LP_nativeDEX.c | 3 +-- iguana/exchanges/mm.c | 1 - 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/iguana/exchanges/LP_instantdex.c b/iguana/exchanges/LP_instantdex.c index c398d505b..81c5e505a 100644 --- a/iguana/exchanges/LP_instantdex.c +++ b/iguana/exchanges/LP_instantdex.c @@ -178,8 +178,11 @@ char *LP_instantdex_deposit(struct iguana_info *coin,int32_t weeks,double amount int64_t LP_claimtx(void *ctx,struct iguana_info *coin,bits256 *claimtxidp,bits256 utxotxid,int32_t utxovout,uint64_t satoshis,char *vinaddr,uint32_t claimtime,uint8_t *redeemscript,int32_t redeemlen) { - uint8_t userdata[2]; char *signedtx; bits256 signedtxid,sendtxid; int32_t userdatalen; int64_t destamount,sum = 0; - userdata[0] = 0x51; + uint8_t userdata[2]; char *signedtx; bits256 signedtxid,sendtxid; int32_t isbots,userdatalen; int64_t destamount,sum = 0; + if ( strcmp(coin->smartaddr,BOTS_BONDADDRESS) == 0 ) + isbots = 1; + else isbots = 0; + userdata[0] = (isbots == 0) ? 0x51 : 0; userdatalen = 1; utxovout = 0; memset(claimtxidp,0,sizeof(*claimtxidp)); @@ -229,9 +232,10 @@ char *LP_instantdex_claim(struct iguana_info *coin) } flagi = 0; utxovout = 0; + // make into function, and separate calling path by txid if ( (txjson= LP_gettx(coin->symbol,utxotxid,1)) != 0 ) { - if ( (vouts= jarray(&numvouts,txjson,"vout")) != 0 && numvouts == 3 ) + if ( (vouts= jarray(&numvouts,txjson,"vout")) != 0 && numvouts >= 3 ) { vout0 = jitem(vouts,0); LP_destaddr(vinaddr,vout0); @@ -410,6 +414,7 @@ int64_t LP_dynamictrust(bits256 pubkey,int64_t kmdvalue) int64_t LP_instantdex_proofcheck(char *coinaddr,cJSON *proof,int32_t num) { uint8_t rmd160[20],addrtype; int32_t i; int64_t net = 0; char othersmartaddr[64]; struct iguana_info *coin; struct LP_address *ap = 0; + printf("proofcheck.(%s) %d %s\n",coinaddr,num,jprint(proof,0)); if ( (coin= LP_coinfind("KMD")) != 0 ) { bitcoin_addr2rmd160(0,&addrtype,rmd160,coinaddr); @@ -437,7 +442,7 @@ int64_t LP_myzcredits() zcredits = LP_instantdex_proofcheck(coin->smartaddr,proof,cJSON_GetArraySize(proof)); free_json(proof); return(zcredits); - } + } else printf("cant find my instantdex proof\n"); } return(0); } diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 7a8b48699..0e4c91e44 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -17,7 +17,7 @@ // LP_nativeDEX.c // marketmaker // -// verify claim works +// delay swap credit back until notarization, else path // big BTC swaps // https://github.com/bitcoin/bips/blob/master/bip-0143.mediawiki for signing BCH/BTG // @@ -28,7 +28,6 @@ // USD paxprice based USDvalue in portfolio // // improve critical section detection when parallel trades -// delay swap credit back until notarization // dPoW security -> 4: KMD notarized, 5: BTC notarized, after next notary elections // bigendian architectures need to use little endian for sighash calcs // diff --git a/iguana/exchanges/mm.c b/iguana/exchanges/mm.c index f4d147131..ec3aba913 100644 --- a/iguana/exchanges/mm.c +++ b/iguana/exchanges/mm.c @@ -20,7 +20,6 @@ // - void PNACL_message(char *arg,...) { From c5fae7900907090faa830d61c91ef5a0166b6415 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 2 Dec 2017 22:58:37 +0400 Subject: [PATCH 06/59] Test --- iguana/exchanges/LP_instantdex.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/iguana/exchanges/LP_instantdex.c b/iguana/exchanges/LP_instantdex.c index 81c5e505a..56f4a05d0 100644 --- a/iguana/exchanges/LP_instantdex.c +++ b/iguana/exchanges/LP_instantdex.c @@ -235,7 +235,7 @@ char *LP_instantdex_claim(struct iguana_info *coin) // make into function, and separate calling path by txid if ( (txjson= LP_gettx(coin->symbol,utxotxid,1)) != 0 ) { - if ( (vouts= jarray(&numvouts,txjson,"vout")) != 0 && numvouts >= 3 ) + if ( (vouts= jarray(&numvouts,txjson,"vout")) != 0 && numvouts == 3 ) { vout0 = jitem(vouts,0); LP_destaddr(vinaddr,vout0); @@ -414,7 +414,6 @@ int64_t LP_dynamictrust(bits256 pubkey,int64_t kmdvalue) int64_t LP_instantdex_proofcheck(char *coinaddr,cJSON *proof,int32_t num) { uint8_t rmd160[20],addrtype; int32_t i; int64_t net = 0; char othersmartaddr[64]; struct iguana_info *coin; struct LP_address *ap = 0; - printf("proofcheck.(%s) %d %s\n",coinaddr,num,jprint(proof,0)); if ( (coin= LP_coinfind("KMD")) != 0 ) { bitcoin_addr2rmd160(0,&addrtype,rmd160,coinaddr); @@ -442,7 +441,7 @@ int64_t LP_myzcredits() zcredits = LP_instantdex_proofcheck(coin->smartaddr,proof,cJSON_GetArraySize(proof)); free_json(proof); return(zcredits); - } else printf("cant find my instantdex proof\n"); + } } return(0); } From 68cea842a7cfb621a3611766e7d863f0d724f7bb Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 2 Dec 2017 23:07:56 +0400 Subject: [PATCH 07/59] Test --- iguana/exchanges/LP_instantdex.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_instantdex.c b/iguana/exchanges/LP_instantdex.c index 56f4a05d0..9fac9b6cd 100644 --- a/iguana/exchanges/LP_instantdex.c +++ b/iguana/exchanges/LP_instantdex.c @@ -403,7 +403,8 @@ int64_t LP_dynamictrust(bits256 pubkey,int64_t kmdvalue) if ( (sp= ptr->swap) != 0 && sp->finished == 0 && sp->expired == 0 ) swaps_kmdvalue += LP_kmdvalue(sp->Q.destcoin,sp->Q.destsatoshis); } - //printf("%s instantdex_credits %.8f vs (%.8f + current %.8f)\n",coinaddr,dstr(ap->instantdex_credits),dstr(swaps_kmdvalue),dstr(kmdvalue)); + if ( ap->instantdex_credits != 0 && (swaps_kmdvalue+kmdvalue) > ap->instantdex_credits ) + printf("%s instantdex_credits %.8f vs (%.8f + current %.8f)\n",coinaddr,dstr(ap->instantdex_credits),dstr(swaps_kmdvalue),dstr(kmdvalue)); //if ( ap->instantdex_credits > swaps_kmdvalue+kmdvalue ) return(ap->instantdex_credits - (swaps_kmdvalue+kmdvalue)); } From 08db8aa6bc01f9b34c379c1057c1bb69047bfabe Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 3 Dec 2017 15:41:10 +0400 Subject: [PATCH 08/59] Test --- iguana/exchanges/LP_include.h | 4 +- iguana/exchanges/LP_instantdex.c | 195 ++++++++++++++++++++----------- iguana/exchanges/LP_nativeDEX.c | 2 +- iguana/exchanges/LP_rpc.c | 8 +- iguana/exchanges/LP_socket.c | 24 ++-- iguana/exchanges/LP_stats.c | 75 +++++++++++- iguana/exchanges/LP_utxo.c | 10 +- iguana/m_notary | 49 +------- iguana/m_notary_run | 47 ++++++++ 9 files changed, 283 insertions(+), 131 deletions(-) create mode 100755 iguana/m_notary_run diff --git a/iguana/exchanges/LP_include.h b/iguana/exchanges/LP_include.h index bb7e77d73..c64827d11 100644 --- a/iguana/exchanges/LP_include.h +++ b/iguana/exchanges/LP_include.h @@ -403,7 +403,8 @@ struct LP_swapstats bits256 bobdeposit,alicepayment,bobpayment,paymentspent,Apaymentspent,depositspent; double qprice; uint64_t aliceid; - uint32_t ind,methodind,finished,expired,lasttime; + int32_t bobneeds_dPoW,aliceneeds_dPoW,bob_dPoWheight,alice_dPoWheight; + uint32_t ind,methodind,finished,expired,lasttime,dPoWfinished; char alicegui[32],bobgui[32]; }; @@ -489,6 +490,7 @@ int32_t LP_crc32find(int32_t *duplicatep,int32_t ind,uint32_t crc32); char *LP_pricepings(void *ctx,char *myipaddr,int32_t pubsock,char *base,char *rel,double price); int32_t LP_merkleproof(struct iguana_info *coin,char *coinaddr,struct electrum_info *ep,bits256 txid,int32_t height); cJSON *electrum_address_gethistory(char *symbol,struct electrum_info *ep,cJSON **retjsonp,char *addr,bits256 reftxid); +cJSON *LP_myzdebits(); int32_t _LP_utxos_remove(bits256 txid,int32_t vout); int32_t LP_utxos_remove(bits256 txid,int32_t vout); struct LP_transaction *LP_transactionadd(struct iguana_info *coin,bits256 txid,int32_t height,int32_t numvouts,int32_t numvins); diff --git a/iguana/exchanges/LP_instantdex.c b/iguana/exchanges/LP_instantdex.c index 9fac9b6cd..a8f5760c5 100644 --- a/iguana/exchanges/LP_instantdex.c +++ b/iguana/exchanges/LP_instantdex.c @@ -202,16 +202,74 @@ int64_t LP_claimtx(void *ctx,struct iguana_info *coin,bits256 *claimtxidp,bits25 return(sum); } +int32_t LP_claim_submit(void *ctx,cJSON *txids,int64_t *sump,struct iguana_info *coin,bits256 utxotxid) +{ + uint8_t redeemscript[512]; bits256 claimtxid; cJSON *txjson,*vout0,*vout1,*vout2,*vouts,*item; int32_t numvouts; char str[65],vinaddr[64],destaddr[64],checkaddr[64]; int32_t j,utxovout,flagi = 0,redeemlen,weeki; int64_t weeksatoshis,satoshis; uint32_t expiration,claimtime; + if ( (txjson= LP_gettx(coin->symbol,utxotxid,1)) != 0 ) + { + if ( (vouts= jarray(&numvouts,txjson,"vout")) != 0 && numvouts >= 3 ) + { + vout0 = jitem(vouts,0); + LP_destaddr(vinaddr,vout0); + satoshis = LP_value_extract(vout0,1); + vout2 = jitem(vouts,2); + LP_destaddr(destaddr,vout2); + if ( strcmp(destaddr,coin->smartaddr) == 0 ) + { + vout1 = jitem(vouts,1); + weeksatoshis = LP_value_extract(vout1,0); + weeki = (int32_t)(weeksatoshis % 10000); + for (j=28; j<=28; j++) + { + expiration = ((weeki * LP_WEEKMULT + j*3600) + LP_FIRSTWEEKTIME); + redeemlen = LP_deposit_addr(checkaddr,redeemscript,coin->taddr,coin->p2shtype,expiration,G.LP_pubsecp); + if ( strcmp(checkaddr,vinaddr) == 0 ) + { + claimtime = (uint32_t)time(NULL)-777; + item = cJSON_CreateObject(); + jaddbits256(item,"txid",utxotxid); + jaddnum(item,"deposit",dstr(LP_value_extract(vout0,0))); + if ( coin->electrum == 0 ) + jaddnum(item,"interest",dstr(satoshis)-dstr(LP_value_extract(vout0,0))); + else jaddnum(item,"interest",dstr(LP_komodo_interest(utxotxid,satoshis))); + if ( claimtime <= expiration ) + { + printf("claimtime.%u vs %u, wait %d seconds to %s claim %.8f\n",claimtime,expiration,(int32_t)expiration-claimtime,bits256_str(str,utxotxid),dstr(satoshis)); + jaddnum(item,"waittime",(int32_t)expiration-claimtime); + jaddi(txids,item); + break; + } + else + { + utxovout = 0; + *sump += LP_claimtx(ctx,coin,&claimtxid,utxotxid,utxovout,satoshis,vinaddr,claimtime,redeemscript,redeemlen); + if ( bits256_nonz(claimtxid) != 0 ) + { + flagi = 1; + jaddbits256(item,"claimtxid",claimtxid); + jaddi(txids,item); + } + } + } else printf("expiration.%u j.%d checkaddr.(%s) != vinaddr.%s\n",expiration,j,checkaddr,vinaddr); + if ( flagi != 0 ) + break; + } + } else printf("vout2 dest.(%s) != %s\n",destaddr,coin->smartaddr); + } else printf("numvouts %d != 3\n",numvouts); + free_json(txjson); + } else printf("cant get transaction\n"); + return(flagi); +} + char *LP_instantdex_claim(struct iguana_info *coin) { static void *ctx; - uint8_t redeemscript[512]; char vinaddr[64],checkaddr[64],destaddr[64],str[65]; uint32_t now,redeemlen,claimtime,expiration=0; int32_t i,j,n,flagi,flag,weeki,numvouts,utxovout; bits256 utxotxid,claimtxid; int64_t sum,satoshis,weeksatoshis; cJSON *array,*txids,*retjson,*newarray,*txjson,*vouts,*vout0,*vout1,*vout2,*item; + int32_t i,n; cJSON *array,*txids,*newarray,*retjson; int64_t sum; bits256 utxotxid; printf("inside instantdex claim\n"); if ( ctx == 0 ) ctx = bitcoin_ctx(); if ( strcmp(coin->symbol,"KMD") != 0 ) return(clonestr("{\"error\":\"instantdex deposit must be in KMD\"}")); - now = (uint32_t)time(NULL); sum = 0; txids = cJSON_CreateArray(); newarray = cJSON_CreateArray(); @@ -220,71 +278,11 @@ char *LP_instantdex_claim(struct iguana_info *coin) printf("claiming from.(%s)\n",jprint(array,0)); if ( (n= cJSON_GetArraySize(array)) > 0 ) { - flag = 0; for (i=0; isymbol,utxotxid,1)) != 0 ) - { - if ( (vouts= jarray(&numvouts,txjson,"vout")) != 0 && numvouts == 3 ) - { - vout0 = jitem(vouts,0); - LP_destaddr(vinaddr,vout0); - satoshis = LP_value_extract(vout0,1); - vout2 = jitem(vouts,2); - LP_destaddr(destaddr,vout2); - if ( strcmp(destaddr,coin->smartaddr) == 0 ) - { - vout1 = jitem(vouts,1); - weeksatoshis = LP_value_extract(vout1,0); - weeki = (int32_t)(weeksatoshis % 10000); - for (j=28; j<=28; j++) - { - expiration = ((weeki * LP_WEEKMULT + j*3600) + LP_FIRSTWEEKTIME); - redeemlen = LP_deposit_addr(checkaddr,redeemscript,coin->taddr,coin->p2shtype,expiration,G.LP_pubsecp); - if ( strcmp(checkaddr,vinaddr) == 0 ) - { - claimtime = (uint32_t)time(NULL)-777; - item = cJSON_CreateObject(); - jaddbits256(item,"txid",utxotxid); - jaddnum(item,"deposit",dstr(LP_value_extract(vout0,0))); - if ( coin->electrum == 0 ) - jaddnum(item,"interest",dstr(satoshis)-dstr(LP_value_extract(vout0,0))); - else jaddnum(item,"interest",dstr(LP_komodo_interest(utxotxid,satoshis))); - if ( claimtime <= expiration ) - { - printf("claimtime.%u vs %u, wait %d seconds to %s claim %.8f\n",claimtime,expiration,(int32_t)expiration-claimtime,bits256_str(str,utxotxid),dstr(satoshis)); - jaddnum(item,"waittime",(int32_t)expiration-claimtime); - jaddi(txids,item); - break; - } - else - { - flagi = 1; - sum += LP_claimtx(ctx,coin,&claimtxid,utxotxid,utxovout,satoshis,vinaddr,claimtime,redeemscript,redeemlen); - jaddbits256(item,"claimtxid",claimtxid); - jaddi(txids,item); - } - } else printf("expiration.%u j.%d checkaddr.(%s) != vinaddr.%s\n",expiration,j,checkaddr,vinaddr); - if ( flagi != 0 ) - break; - } - } else printf("vout2 dest.(%s) != %s\n",destaddr,coin->smartaddr); - } else printf("numvouts %d != 3\n",numvouts); - free_json(txjson); - } else printf("cant get transaction\n"); - if ( flagi == 0 ) + if ( LP_claim_submit(ctx,txids,&sum,coin,utxotxid) == 0 ) jaddibits256(newarray,utxotxid); - else flag++; } } free_json(array); @@ -395,12 +393,12 @@ int64_t LP_dynamictrust(bits256 pubkey,int64_t kmdvalue) { DL_FOREACH_SAFE(pubp->bobswaps,ptr,tmp) { - if ( (sp= ptr->swap) != 0 && sp->finished == 0 && sp->expired == 0 ) + if ( (sp= ptr->swap) != 0 && LP_swap_finished(sp,1) == 0 ) swaps_kmdvalue += LP_kmdvalue(sp->Q.srccoin,sp->Q.satoshis); } DL_FOREACH_SAFE(pubp->aliceswaps,ptr,tmp) { - if ( (sp= ptr->swap) != 0 && sp->finished == 0 && sp->expired == 0 ) + if ( (sp= ptr->swap) != 0 && LP_swap_finished(sp,1) == 0 ) swaps_kmdvalue += LP_kmdvalue(sp->Q.destcoin,sp->Q.destsatoshis); } if ( ap->instantdex_credits != 0 && (swaps_kmdvalue+kmdvalue) > ap->instantdex_credits ) @@ -446,3 +444,70 @@ int64_t LP_myzcredits() } return(0); } + +cJSON *LP_swapstats_item(struct LP_swapstats *sp,int32_t iambob) +{ + cJSON *item = cJSON_CreateObject(); + jaddnum(item,"iambob",iambob); + jaddnum(item,"aliceid",sp->aliceid); + jaddnum(item,"requestid",sp->Q.R.requestid); + jaddnum(item,"quoteid",sp->Q.R.quoteid); + jaddstr(item,"base",sp->Q.srccoin); + jaddnum(item,"satoshis",sp->Q.satoshis); + jaddstr(item,"rel",sp->Q.destcoin); + jaddnum(item,"destsatoshis",sp->Q.destsatoshis); + jaddnum(item,"price",sp->Q.destsatoshis/((double)sp->Q.satoshis+1)); + if ( LP_swap_finished(sp,1) == 0 ) + { + jaddnum(item,"finished",sp->finished); + if ( sp->bobneeds_dPoW != 0 ) + { + jaddnum(item,"bobneeds_dPoW",sp->bobneeds_dPoW); + jaddnum(item,"bobdPoW_height",sp->bob_dPoWheight); + } + if ( sp->aliceneeds_dPoW != 0 ) + { + jaddnum(item,"aliceneeds_dPoW",sp->aliceneeds_dPoW); + jaddnum(item,"alicedPoW_height",sp->alice_dPoWheight); + } + } + return(item); +} + +cJSON *LP_myzdebits() +{ + struct LP_pubswap *ptr,*tmp; struct LP_pubkey_info *pubp; struct LP_swapstats *sp; int64_t kmdvalue,swaps_kmdvalue = 0; struct iguana_info *coin; cJSON *retjson,*array,*item; + array = cJSON_CreateArray(); + if ( (coin= LP_coinfind("KMD")) != 0 ) + { + if ( (pubp= LP_pubkeyfind(G.LP_mypub25519)) != 0 ) + { + DL_FOREACH_SAFE(pubp->bobswaps,ptr,tmp) + { + if ( (sp= ptr->swap) != 0 && LP_swap_finished(sp,1) == 0 ) + { + kmdvalue = LP_kmdvalue(sp->Q.srccoin,sp->Q.satoshis); + item = LP_swapstats_item(sp,1); + jaddnum(item,"kmdvalue",dstr(kmdvalue)); + jaddi(array,item); + swaps_kmdvalue += kmdvalue; + } + } + DL_FOREACH_SAFE(pubp->aliceswaps,ptr,tmp) + { + if ( (sp= ptr->swap) != 0 && LP_swap_finished(sp,1) == 0 ) + { + kmdvalue = LP_kmdvalue(sp->Q.destcoin,sp->Q.destsatoshis); + item = LP_swapstats_item(sp,0); + jaddnum(item,"kmdvalue",dstr(kmdvalue)); + jaddi(array,item); + swaps_kmdvalue += kmdvalue; + } + } + } + } + retjson = cJSON_CreateObject(); + jaddstr(retjson,"result","success"); + jadd(retjson,"swaps",array); + jaddnum(retjson,"pendingswaps",dstr(swaps_kmdvalue)); +} diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 0e4c91e44..c818a1436 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -571,7 +571,7 @@ void LP_coinsloop(void *_coins) nonz++; printf("SPV failure for %s %s\n",coin->symbol,bits256_str(str,up->U.txid)); oldht = up->U.height; - LP_txheight_check(coin,ap->coinaddr,up); + LP_txheight_check(coin,ap->coinaddr,up->U.txid); if ( oldht != up->U.height ) up->SPV = LP_merkleproof(coin,coin->smartaddr,backupep,up->U.txid,up->U.height); if ( up->SPV <= 0 ) diff --git a/iguana/exchanges/LP_rpc.c b/iguana/exchanges/LP_rpc.c index b39cdc9fa..7b04045eb 100644 --- a/iguana/exchanges/LP_rpc.c +++ b/iguana/exchanges/LP_rpc.c @@ -157,7 +157,7 @@ cJSON *LP_paxprice(char *fiat) cJSON *LP_gettx(char *symbol,bits256 txid,int32_t suppress_errors) { - struct iguana_info *coin; char buf[512],str[65]; cJSON *retjson; + struct iguana_info *coin; char buf[512],str[65]; int32_t height; cJSON *retjson; //printf("LP_gettx %s %s\n",symbol,bits256_str(str,txid)); if ( symbol == 0 || symbol[0] == 0 ) return(cJSON_Parse("{\"error\":\"null symbol\"}")); @@ -174,7 +174,7 @@ cJSON *LP_gettx(char *symbol,bits256 txid,int32_t suppress_errors) } else { - if ( (retjson= electrum_transaction(symbol,coin->electrum,&retjson,txid,0)) != 0 ) + if ( (retjson= electrum_transaction(&height,symbol,coin->electrum,&retjson,txid,0)) != 0 ) return(retjson); else if ( suppress_errors == 0 ) printf("failed blockchain.transaction.get %s %s\n",coin->symbol,bits256_str(str,txid)); @@ -214,7 +214,7 @@ cJSON *LP_gettxout_json(bits256 txid,int32_t vout,int32_t height,char *coinaddr, cJSON *LP_gettxout(char *symbol,char *coinaddr,bits256 txid,int32_t vout) { - char buf[128],str[65]; cJSON *item,*array,*vouts,*txobj,*retjson=0; int32_t i,v,n; bits256 t,zero; struct iguana_info *coin; struct LP_transaction *tx; struct LP_address_utxo *up; + char buf[128],str[65]; cJSON *item,*array,*vouts,*txobj,*retjson=0; int32_t i,v,height,n; bits256 t,zero; struct iguana_info *coin; struct LP_transaction *tx; struct LP_address_utxo *up; if ( symbol == 0 || symbol[0] == 0 ) return(cJSON_Parse("{\"error\":\"null symbol\"}")); if ( (coin= LP_coinfind(symbol)) == 0 ) @@ -236,7 +236,7 @@ cJSON *LP_gettxout(char *symbol,char *coinaddr,bits256 txid,int32_t vout) } if ( coinaddr[0] == 0 ) { - if ( (txobj= electrum_transaction(symbol,coin->electrum,&txobj,txid,0)) != 0 ) + if ( (txobj= electrum_transaction(&height,symbol,coin->electrum,&txobj,txid,0)) != 0 ) { if ( (vouts= jarray(&n,txobj,"vout")) != 0 && n > 0 ) LP_destaddr(coinaddr,jitem(vouts,vout)); diff --git a/iguana/exchanges/LP_socket.c b/iguana/exchanges/LP_socket.c index 481a31ded..8cceb33b2 100644 --- a/iguana/exchanges/LP_socket.c +++ b/iguana/exchanges/LP_socket.c @@ -558,12 +558,12 @@ cJSON *electrum_address_gethistory(char *symbol,struct electrum_info *ep,cJSON * return(retjson); } -int32_t LP_txheight_check(struct iguana_info *coin,char *coinaddr,struct LP_address_utxo *up) +int32_t LP_txheight_check(struct iguana_info *coin,char *coinaddr,bits256 txid) { cJSON *retjson; if ( coin->electrum != 0 ) { - if ( (retjson= electrum_address_gethistory(coin->symbol,coin->electrum,&retjson,coinaddr,up->U.txid)) != 0 ) + if ( (retjson= electrum_address_gethistory(coin->symbol,coin->electrum,&retjson,coinaddr,txid)) != 0 ) free_json(retjson); } return(0); @@ -744,14 +744,15 @@ cJSON *_electrum_transaction(char *symbol,struct electrum_info *ep,cJSON **retjs return(*retjsonp); } -cJSON *electrum_transaction(char *symbol,struct electrum_info *ep,cJSON **retjsonp,bits256 txid,char *SPVcheck) +cJSON *electrum_transaction(int32_t *heightp,char *symbol,struct electrum_info *ep,cJSON **retjsonp,bits256 txid,char *SPVcheck) { - cJSON *retjson,*array; bits256 zero; struct LP_transaction *tx; struct iguana_info *coin; + cJSON *retjson,*array; bits256 zero; struct LP_transaction *tx=0; struct iguana_info *coin; coin = LP_coinfind(symbol); + *heightp = 0; if ( ep != 0 ) portable_mutex_lock(&ep->txmutex); retjson = _electrum_transaction(symbol,ep,retjsonp,txid); - if ( ep != 0 && coin != 0 && SPVcheck != 0 && SPVcheck[0] != 0 && (tx= LP_transactionfind(coin,txid)) != 0 ) + if ( (tx= LP_transactionfind(coin,txid)) != 0 && ep != 0 && coin != 0 && SPVcheck != 0 && SPVcheck[0] != 0 ) { if ( tx->height <= 0 ) { @@ -763,9 +764,14 @@ cJSON *electrum_transaction(char *symbol,struct electrum_info *ep,cJSON **retjso } } if ( tx->height > 0 ) - tx->SPV = LP_merkleproof(coin,SPVcheck,ep,txid,tx->height); + { + if ( tx->SPV == 0 ) + tx->SPV = LP_merkleproof(coin,SPVcheck,ep,txid,tx->height); + *heightp = tx->height; + } char str[65]; printf("%s %s %s SPV height %d SPV %d\n",coin->symbol,SPVcheck,bits256_str(str,txid),tx->height,tx->SPV); - } + } else if ( tx != 0 ) + *heightp = tx->height; if ( ep != 0 ) portable_mutex_unlock(&ep->txmutex); return(retjson); @@ -782,7 +788,7 @@ cJSON *electrum_getmerkle(char *symbol,struct electrum_info *ep,cJSON **retjsonp void electrum_test() { - cJSON *retjson; bits256 hash,zero; struct electrum_info *ep = 0; char *addr,*script,*symbol = "BTC"; + cJSON *retjson; int32_t height; bits256 hash,zero; struct electrum_info *ep = 0; char *addr,*script,*symbol = "BTC"; while ( Num_electrums == 0 ) { sleep(1); @@ -808,7 +814,7 @@ void electrum_test() decode_hex(hash.bytes,sizeof(hash),"b967a7d55889fe11e993430921574ec6379bc8ce712a652c3fcb66c6be6e925c"); if ( (retjson= electrum_getmerkle(symbol,ep,0,hash,403000)) != 0 ) printf("electrum_getmerkle %s\n",jprint(retjson,1)); - if ( (retjson= electrum_transaction(symbol,ep,0,hash,0)) != 0 ) + if ( (retjson= electrum_transaction(&height,symbol,ep,0,hash,0)) != 0 ) printf("electrum_transaction %s\n",jprint(retjson,1)); addr = "14NeevLME8UAANiTCVNgvDrynUPk1VcQKb"; if ( (retjson= electrum_address_gethistory(symbol,ep,0,addr,zero)) != 0 ) diff --git a/iguana/exchanges/LP_stats.c b/iguana/exchanges/LP_stats.c index e460c1c6c..fc33d58bc 100644 --- a/iguana/exchanges/LP_stats.c +++ b/iguana/exchanges/LP_stats.c @@ -208,10 +208,72 @@ int32_t LP_swapstats_update(struct LP_swapstats *sp,struct LP_quoteinfo *qp,cJSO return(0); } +int32_t LP_dPoWheight(struct iguana_info *coin) // get dPoW protected height +{ + +} + +int32_t LP_finished_lastheight(struct LP_swapstats *sp,int32_t iambob) +{ + int32_t ht,height = 1; struct iguana_info *coin; + if ( (coin= LP_coinfind(iambob != 0 ? sp->Q.srccoin : sp->Q.destcoin)) != 0 ) + { + if ( iambob != 0 ) + { + if ( bits256_nonz(sp->bobdeposit) != 0 && (ht= LP_txheight(coin,sp->bobdeposit)) > 1 && ht > height ) + height = ht; + if ( bits256_nonz(sp->bobpayment) != 0 && (ht= LP_txheight(coin,sp->bobpayment)) > 1 && ht > height ) + height = ht; + if ( bits256_nonz(sp->paymentspent) != 0 && (ht= LP_txheight(coin,sp->paymentspent)) > 1 && ht > height ) + height = ht; + if ( bits256_nonz(sp->depositspent) != 0 && (ht= LP_txheight(coin,sp->depositspent)) > 1 && ht > height ) + height = ht; + } + else + { + if ( bits256_nonz(sp->alicepayment) != 0 && (ht= LP_txheight(coin,sp->alicepayment)) > 1 && ht > height ) + height = ht; + if ( bits256_nonz(sp->Apaymentspent) != 0 && (ht= LP_txheight(coin,sp->Apaymentspent)) > 1 && ht > height ) + height = ht; + } + } + return(height); +} + +int32_t LP_swap_finished(struct LP_swapstats *sp,int32_t dPoWflag) +{ + struct iguana_info *bob,*alice; + bob = LP_coinfind(sp->Q.srccoin); + alice = LP_coinfind(sp->Q.destcoin); + if ( sp->finished == 0 ) + { + if ( sp->expired != 0 ) + return(1); + if ( dPoWflag != 0 ) + { + if ( sp->finished != 0 && sp->dPoWfinished != 0 ) + return(1); + else if ( sp->finished != 0 ) + { + sp->bob_dPoWheight = LP_dPoWheight(bob); + sp->alice_dPoWheight = LP_dPoWheight(alice); + if ( bob->isassetchain != 0 ) + sp->bobneeds_dPoW = LP_finished_lastheight(sp,1); + if ( alice->isassetchain != 0 ) + sp->aliceneeds_dPoW = LP_finished_lastheight(sp,0); + printf("bob needs %d @ %d, alice needs %d @ %d\n",sp->bobneeds_dPoW,sp->bob_dPoWheight,sp->aliceneeds_dPoW,sp->alice_dPoWheight); + } + if ( (sp->bobneeds_dPoW == 0 || (sp->bobneeds_dPoW > 1 && sp->bob_dPoWheight >= sp->bobneeds_dPoW)) && (sp->aliceneeds_dPoW == 0 || (sp->aliceneeds_dPoW > 1 && sp->alice_dPoWheight >= sp->aliceneeds_dPoW)) ) + return(1); + } + } + return(0); +} + int32_t LP_statslog_parsequote(char *method,cJSON *lineobj) { static uint32_t unexpected; - struct LP_swapstats *sp,*tmp; struct LP_pubkey_info *pubp; struct LP_pubswap *ptr; double qprice; uint32_t requestid,quoteid,timestamp; int32_t i,RTflag,flag,numtrades[LP_MAXPRICEINFOS],methodind,destvout,feevout,duplicate=0; char *statusstr,*gui,*base,*rel; uint64_t aliceid,txfee,satoshis,destsatoshis; bits256 desttxid,feetxid; struct LP_quoteinfo Q; uint64_t basevols[LP_MAXPRICEINFOS],relvols[LP_MAXPRICEINFOS]; + struct LP_swapstats *sp,*tmp; struct iguana_info *alice,*bob; struct LP_pubkey_info *pubp; struct LP_pubswap *ptr; double qprice; uint32_t requestid,quoteid,timestamp; int32_t i,RTflag,flag,numtrades[LP_MAXPRICEINFOS],methodind,destvout,feevout,duplicate=0; char *statusstr,*gui,*base,*rel; uint64_t aliceid,txfee,satoshis,destsatoshis; bits256 desttxid,feetxid; struct LP_quoteinfo Q; uint64_t basevols[LP_MAXPRICEINFOS],relvols[LP_MAXPRICEINFOS]; memset(numtrades,0,sizeof(numtrades)); memset(basevols,0,sizeof(basevols)); memset(relvols,0,sizeof(relvols)); @@ -314,9 +376,18 @@ int32_t LP_statslog_parsequote(char *method,cJSON *lineobj) sp->methodind = methodind; sp->ind = LP_aliceids++; sp->lasttime = (uint32_t)time(NULL); + if ( sp->lasttime > sp->Q.timestamp+LP_atomic_locktime(base,rel)*2) + sp->expired = sp->lasttime; + else + { + if ( (alice= LP_coinfind(rel)) && alice->isassetchain != 0 ) + sp->aliceneeds_dPoW = 1; + if ( (bob= LP_coinfind(rel)) && bob->isassetchain != 0 ) + sp->bobneeds_dPoW = 1; + } strcpy(sp->bobgui,"nogui"); strcpy(sp->alicegui,"nogui"); - if ( sp->finished == 0 && sp->expired == 0 ) + if ( LP_swap_finished(sp,1) == 0 ) //sp->finished == 0 && sp->expired == 0 ) { if ( (pubp= LP_pubkeyadd(sp->Q.srchash)) != 0 ) { diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index 9d48e6ba5..2770ad42b 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -620,7 +620,10 @@ cJSON *LP_address_balance(struct iguana_info *coin,char *coinaddr,int32_t electr jaddstr(retjson,"address",coinaddr); jaddnum(retjson,"balance",dstr(balance)); if ( strcmp(coin->symbol,"KMD") == 0 && strcmp(coin->smartaddr,coinaddr) == 0 ) + { jaddnum(retjson,"zcredits",dstr(LP_myzcredits())); + jadd(retjson,"zdebits",LP_myzdebits()); + } return(retjson); } @@ -763,7 +766,7 @@ cJSON *LP_transactioninit(struct iguana_info *coin,bits256 txid,int32_t iter,cJS int32_t LP_txheight(struct iguana_info *coin,bits256 txid) { - bits256 blockhash; struct LP_transaction *tx; cJSON *blockobj,*txobj; int32_t height = 0; + bits256 blockhash; struct LP_transaction *tx; cJSON *blockobj,*retjson,*txobj; int32_t height = 0; if ( coin == 0 ) return(-1); if ( coin->electrum == 0 ) @@ -788,6 +791,11 @@ int32_t LP_txheight(struct iguana_info *coin,bits256 txid) { if ( (tx= LP_transactionfind(coin,txid)) != 0 ) height = tx->height; + if ( height == 0 ) + { + if ( (retjson= electrum_transaction(&height,coin->symbol,coin->electrum,&retjson,txid,0)) != 0 ) + free_json(retjson); + } } return(height); } diff --git a/iguana/m_notary b/iguana/m_notary index c88989065..0d4d9a9c4 100755 --- a/iguana/m_notary +++ b/iguana/m_notary @@ -2,51 +2,4 @@ pkill -15 iguana rm -f ../agents/iguana *.o git pull -cd secp256k1; ./m_unix; cd .. -cd ../crypto777; ./m_LP; cd ../iguana -#gcc -g -fno-aggressive-loop-optimizations -Wno-deprecated -c -O2 -DISNOTARYNODE=1 -DLIQUIDITY_PROVIDER=1 *.c ../basilisk/basilisk.c ../gecko/gecko.c ../datachain/datachain.c -clang -g -Wno-deprecated -c -O2 -DISNOTARYNODE=1 -DLIQUIDITY_PROVIDER=1 *.c ../basilisk/basilisk.c ../gecko/gecko.c ../datachain/datachain.c -#gcc -g -fno-aggressive-loop-optimizations -Wno-deprecated -c -DISNOTARYNODE=1 -DLIQUIDITY_PROVIDER=1 main.c iguana777.c iguana_bundles.c ../basilisk/basilisk.c -clang -g -Wno-deprecated -c -DISNOTARYNODE=1 -DLIQUIDITY_PROVIDER=1 main.c iguana777.c iguana_bundles.c ../basilisk/basilisk.c -clang -g -o ../agents/iguana *.o ../agents/libcrypto777.a -lnanomsg -lcurl -lssl -lcrypto -lpthread -lz -lm - -../agents/iguana notary & #> iguana.log 2> error.log & - -myip=`curl -s4 checkip.amazonaws.com` -source pubkey.txt - -sleep 4 -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"SuperNET\",\"method\":\"myipaddr\",\"ipaddr\":\"$myip\"}" -sleep 3 -tests/addnotarys_7776 -coins/btc_7776 -coins/ltc_7776 -coins/kmd_7776 -coins/chips_7776 -./wp_7776 - -coins/revs_7776 -coins/supernet_7776 -coins/dex_7776 -coins/bet_7776 -coins/bots_7776 -coins/hodl_7776 -coins/shark_7776 -coins/mshark_7776 -coins/jumblr_7776 -coins/crypto_7776 -coins/pangea_7776 -coins/mgw_7776 -#coins/mvp_7776 -coins/coqui_7776 -coins/wlc_7776 -coins/kv_7776 -coins/ceal_7776 -coins/mesh_7776 -coins/mnz_7776 -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"passthru\",\"method\":\"paxfiats\",\"timeout\":900000}" - -#curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"addnotary\",\"ipaddr\":\"$myip\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"KMD\",\"pubkey\":\"$pubkey\"}" - -sleep 17 +./m_notary_run diff --git a/iguana/m_notary_run b/iguana/m_notary_run new file mode 100755 index 000000000..4c64de6ff --- /dev/null +++ b/iguana/m_notary_run @@ -0,0 +1,47 @@ +#!/bin/bash + +cd secp256k1; ./m_unix; cd .. +cd ../crypto777; ./m_LP; cd ../iguana +#gcc -g -fno-aggressive-loop-optimizations -Wno-deprecated -c -O2 -DISNOTARYNODE=1 -DLIQUIDITY_PROVIDER=1 *.c ../basilisk/basilisk.c ../gecko/gecko.c ../datachain/datachain.c +clang -g -Wno-deprecated -c -O2 -DISNOTARYNODE=1 -DLIQUIDITY_PROVIDER=1 *.c ../basilisk/basilisk.c ../gecko/gecko.c ../datachain/datachain.c +#gcc -g -fno-aggressive-loop-optimizations -Wno-deprecated -c -DISNOTARYNODE=1 -DLIQUIDITY_PROVIDER=1 main.c iguana777.c iguana_bundles.c ../basilisk/basilisk.c +clang -g -Wno-deprecated -c -DISNOTARYNODE=1 -DLIQUIDITY_PROVIDER=1 main.c iguana777.c iguana_bundles.c ../basilisk/basilisk.c +clang -g -o ../agents/iguana *.o ../agents/libcrypto777.a -lnanomsg -lcurl -lssl -lcrypto -lpthread -lz -lm + +../agents/iguana notary & #> iguana.log 2> error.log & + +myip=`curl -s4 checkip.amazonaws.com` +source pubkey.txt + +sleep 4 +curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"SuperNET\",\"method\":\"myipaddr\",\"ipaddr\":\"$myip\"}" +sleep 3 +tests/addnotarys_7776 +coins/btc_7776 +coins/ltc_7776 +coins/kmd_7776 +coins/chips_7776 +./wp_7776 + +coins/revs_7776 +coins/supernet_7776 +coins/dex_7776 +coins/bet_7776 +coins/bots_7776 +coins/hodl_7776 +coins/shark_7776 +coins/mshark_7776 +coins/jumblr_7776 +coins/crypto_7776 +coins/pangea_7776 +coins/mgw_7776 +coins/coqui_7776 +coins/wlc_7776 +coins/kv_7776 +coins/ceal_7776 +coins/mesh_7776 +coins/mnz_7776 +#curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"passthru\",\"method\":\"paxfiats\",\"timeout\":900000}" + +#curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"addnotary\",\"ipaddr\":\"$myip\"}" +curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"KMD\",\"pubkey\":\"$pubkey\"}" From 30828f5fc23c517bac9052106e204c9a5f496367 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 3 Dec 2017 16:04:03 +0400 Subject: [PATCH 09/59] Test --- iguana/exchanges/LP_cache.c | 13 ++++++++++--- iguana/exchanges/LP_coins.c | 6 ++++-- iguana/exchanges/LP_commands.c | 5 +++-- iguana/exchanges/LP_include.h | 4 ++-- iguana/exchanges/LP_instantdex.c | 2 +- iguana/exchanges/LP_nativeDEX.c | 31 ++++++++++++++++++++++--------- iguana/exchanges/LP_ordermatch.c | 4 ++-- iguana/exchanges/LP_privkey.c | 4 ++-- iguana/exchanges/LP_rpc.c | 4 +++- iguana/exchanges/LP_stats.c | 8 +++++--- iguana/exchanges/LP_utxo.c | 8 ++++---- 11 files changed, 58 insertions(+), 31 deletions(-) diff --git a/iguana/exchanges/LP_cache.c b/iguana/exchanges/LP_cache.c index c27fb2ecd..194ab75c0 100644 --- a/iguana/exchanges/LP_cache.c +++ b/iguana/exchanges/LP_cache.c @@ -229,17 +229,24 @@ bits256 LP_merkleroot(struct iguana_info *coin,struct electrum_info *ep,int32_t int32_t LP_merkleproof(struct iguana_info *coin,char *coinaddr,struct electrum_info *ep,bits256 txid,int32_t height) { - struct LP_transaction *tx=0; cJSON *merkobj,*merkles,*retjson; bits256 roothash,merkleroot; int32_t m,SPV = 0; + struct LP_transaction *tx=0; cJSON *merkobj,*merkles,*retjson; bits256 roothash,merkleroot; int32_t m,ht=0,SPV = 0; if ( height <= 0 ) return(0); if ( (tx= LP_transactionfind(coin,txid)) == 0 && strcmp(coinaddr,coin->smartaddr) == 0 ) { - if ( (retjson= electrum_transaction(coin->symbol,ep,&retjson,txid,0)) != 0 ) + if ( (retjson= electrum_transaction(&ht,coin->symbol,ep,&retjson,txid,0)) != 0 ) free_json(retjson); } if ( tx != 0 ) { - tx->height = height; + if ( tx->height == 0 ) + { + if ( height != 0 ) + tx->height = height; + else if ( ht != 0 ) + tx->height = ht; + height = tx->height; + } if ( tx->SPV > 0 ) return(tx->SPV); } diff --git a/iguana/exchanges/LP_coins.c b/iguana/exchanges/LP_coins.c index 0bf61e969..67312eb51 100644 --- a/iguana/exchanges/LP_coins.c +++ b/iguana/exchanges/LP_coins.c @@ -214,7 +214,7 @@ uint16_t LP_userpass(char *userpass,char *symbol,char *assetname,char *confroot, cJSON *LP_coinjson(struct iguana_info *coin,int32_t showwif) { - struct electrum_info *ep; uint64_t balance; char wifstr[128],ipaddr[64]; uint8_t tmptype; bits256 checkkey; cJSON *item = cJSON_CreateObject(); + struct electrum_info *ep; int32_t notarized; uint64_t balance; char wifstr[128],ipaddr[64]; uint8_t tmptype; bits256 checkkey; cJSON *item = cJSON_CreateObject(); jaddstr(item,"coin",coin->symbol); if ( showwif != 0 ) { @@ -227,7 +227,9 @@ cJSON *LP_coinjson(struct iguana_info *coin,int32_t showwif) jadd(item,"installed",coin->userpass[0] == 0 ? jfalse() : jtrue()); if ( coin->userpass[0] != 0 ) { - jaddnum(item,"height",LP_getheight(coin)); + jaddnum(item,"height",LP_getheight(¬arized,coin)); + if ( notarized > 0 ) + jaddnum(item,"notarized",notarized); if ( coin->electrum != 0 ) balance = LP_unspents_load(coin->symbol,coin->smartaddr); else balance = LP_RTsmartbalance(coin); diff --git a/iguana/exchanges/LP_commands.c b/iguana/exchanges/LP_commands.c index b06a66e5d..a0af02d32 100644 --- a/iguana/exchanges/LP_commands.c +++ b/iguana/exchanges/LP_commands.c @@ -124,6 +124,7 @@ swapstatus(coin, limit=10)\n\ swapstatus(base, rel, limit=10)\n\ swapstatus(requestid, quoteid)\n\ recentswaps(limit=3)\n\ +notarizations(coin)\n\ public API:\n \ getcoins()\n\ getcoin(coin)\n\ @@ -419,8 +420,8 @@ instantdex_claim()\n\ if ( LP_conflicts_find(ptr) == 0 ) { ptr->inactive = 0; - cJSON *array; - if ( LP_getheight(ptr) <= 0 ) + cJSON *array; int32_t notarized; + if ( LP_getheight(¬arized,ptr) <= 0 ) { ptr->inactive = (uint32_t)time(NULL); return(clonestr("{\"error\":\"coin cant be activated till synced\"}")); diff --git a/iguana/exchanges/LP_include.h b/iguana/exchanges/LP_include.h index c64827d11..2de68ee07 100644 --- a/iguana/exchanges/LP_include.h +++ b/iguana/exchanges/LP_include.h @@ -289,7 +289,7 @@ struct iguana_info UT_hash_handle hh; portable_mutex_t txmutex,addrmutex; struct LP_transaction *transactions; struct LP_address *addresses; uint64_t txfee; - int32_t numutxos,longestchain,firstrefht,firstscanht,lastscanht,bussock,height; uint16_t busport; + int32_t numutxos,notarized,longestchain,firstrefht,firstscanht,lastscanht,bussock,height; uint16_t busport; uint32_t loadedcache,electrumlist,lastunspent,importedprivkey,lastpushtime,lastutxosync,addr_listunspent_requested,lastutxos,updaterate,counter,inactive,lastmempool,lastgetinfo,ratetime,heighttime,lastmonitor,obooktime; uint8_t pubtype,p2shtype,isPoS,wiftype,wiftaddr,taddr,noimportprivkey_flag,userconfirms,isassetchain,maxconfirms; char symbol[128],smartaddr[64],userpass[1024],serverport[128]; @@ -483,7 +483,7 @@ void LP_aliceid(uint32_t tradeid,uint64_t aliceid,char *event,uint32_t requestid cJSON *LP_cache_transaction(struct iguana_info *coin,bits256 txid,uint8_t *serialized,int32_t len); cJSON *LP_transaction_fromdata(struct iguana_info *coin,bits256 txid,uint8_t *serialized,int32_t len); uint64_t LP_RTsmartbalance(struct iguana_info *coin); -int32_t LP_getheight(struct iguana_info *coin); +int32_t LP_getheight(int32_t *notarizedp,struct iguana_info *coin); int32_t LP_reserved_msg(int32_t priority,char *base,char *rel,bits256 pubkey,char *msg); struct iguana_info *LP_coinfind(char *symbol); int32_t LP_crc32find(int32_t *duplicatep,int32_t ind,uint32_t crc32); diff --git a/iguana/exchanges/LP_instantdex.c b/iguana/exchanges/LP_instantdex.c index a8f5760c5..b32297672 100644 --- a/iguana/exchanges/LP_instantdex.c +++ b/iguana/exchanges/LP_instantdex.c @@ -507,7 +507,7 @@ cJSON *LP_myzdebits() } } retjson = cJSON_CreateObject(); - jaddstr(retjson,"result","success"); jadd(retjson,"swaps",array); jaddnum(retjson,"pendingswaps",dstr(swaps_kmdvalue)); + return(retjson); } diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index c818a1436..4163a4511 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -483,7 +483,7 @@ void command_rpcloop(void *ctx) void LP_coinsloop(void *_coins) { - struct LP_address *ap=0,*atmp; struct LP_transaction *tx; cJSON *retjson; struct LP_address_utxo *up,*tmp; struct iguana_info *coin,*ctmp; char str[65]; struct electrum_info *ep,*backupep=0; bits256 zero; int32_t oldht,j,nonz; char *coins = _coins; + struct LP_address *ap=0,*atmp; struct LP_transaction *tx; cJSON *retjson; struct LP_address_utxo *up,*tmp; struct iguana_info *coin,*ctmp; char str[65]; struct electrum_info *ep,*backupep=0; bits256 zero; int32_t notarized,oldht,j,nonz; char *coins = _coins; if ( strcmp("BTC",coins) == 0 ) { strcpy(LP_coinsloopBTC_stats.name,"BTC coin loop"); @@ -528,7 +528,7 @@ void LP_coinsloop(void *_coins) if ( coin->inactive != 0 ) continue; if ( coin->longestchain == 1 ) // special init value - coin->longestchain = LP_getheight(coin); + coin->longestchain = LP_getheight(¬arized,coin); if ( (ep= coin->electrum) != 0 ) { /*if ( strcmp("KMD",coin->symbol) == 0 && coin->electrumzeroconf == 0 ) @@ -645,7 +645,7 @@ void LP_coinsloop(void *_coins) int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int32_t pubsock,char *pushaddr,uint16_t myport) { static uint32_t counter;//,didinstantdex; - struct iguana_info *coin,*ctmp; char *origipaddr; uint32_t now; int32_t height,nonz = 0; + struct iguana_info *coin,*ctmp; char *origipaddr; uint32_t now; int32_t notarized,height,nonz = 0; bits256 zero; cJSON *reqjson; if ( (origipaddr= myipaddr) == 0 ) origipaddr = "127.0.0.1"; if ( mypeer == 0 ) @@ -660,19 +660,32 @@ int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int didinstantdex = now; } #endif - if ( (coin->addr_listunspent_requested != 0 && now > coin->lastpushtime+LP_ORDERBOOK_DURATION*.5) || now > coin->lastpushtime+LP_ORDERBOOK_DURATION*5 ) + /*if ( (coin->addr_listunspent_requested != 0 && now > coin->lastpushtime+LP_ORDERBOOK_DURATION*.5) || now > coin->lastpushtime+LP_ORDERBOOK_DURATION*5 ) { //printf("PUSH addr_listunspent_requested %u\n",coin->addr_listunspent_requested); coin->lastpushtime = (uint32_t)now; LP_smartutxos_push(coin); coin->addr_listunspent_requested = 0; - } + }*/ if ( coin->electrum == 0 && coin->inactive == 0 && now > coin->lastgetinfo+LP_GETINFO_INCR ) { nonz++; - if ( (height= LP_getheight(coin)) > coin->longestchain ) + if ( (height= LP_getheight(¬arized,coin)) > coin->longestchain ) { coin->longestchain = height; + if ( notarized != 0 && notarized > coin->notarized ) + { + coin->notarized = notarized; + if ( IAMLP != 0 ) + { + reqjson = cJSON_CreateObject(); + jaddstr(reqjson,"method","dPoW"); + jaddstr(reqjson,"coin",coin->symbol); + jaddnum(reqjson,"notarized",coin->notarized); + memset(zero.bytes,0,sizeof(zero)); + LP_reserved_msg(0,coin->symbol,coin->symbol,zero,jprint(reqjson,1)); + } + } if ( 0 && 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); @@ -685,7 +698,7 @@ int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int void LP_initcoins(void *ctx,int32_t pubsock,cJSON *coins) { - int32_t i,n; cJSON *item; char *symbol; struct iguana_info *coin; + int32_t i,n,notarized; cJSON *item; char *symbol; struct iguana_info *coin; for (i=0; iinactive = (uint32_t)time(NULL); else { @@ -720,7 +733,7 @@ void LP_initcoins(void *ctx,int32_t pubsock,cJSON *coins) LP_priceinfoadd(jstr(item,"coin")); if ( (coin= LP_coinfind(symbol)) != 0 ) { - if ( LP_getheight(coin) <= 0 ) + if ( LP_getheight(¬arized,coin) <= 0 ) coin->inactive = (uint32_t)time(NULL); else LP_unspents_load(coin->symbol,coin->smartaddr); if ( coin->txfee == 0 && strcmp(coin->symbol,"BTC") != 0 ) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 15d8f959d..9ad350ce8 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -696,13 +696,13 @@ int32_t LP_aliceonly(char *symbol) int32_t LP_validSPV(char *symbol,char *coinaddr,bits256 txid,int32_t vout) { - struct electrum_info *ep,*backupep; cJSON *txobj; struct LP_address_utxo *up; struct iguana_info *coin; struct LP_transaction *tx; + struct electrum_info *ep,*backupep; cJSON *txobj; struct LP_address_utxo *up; struct iguana_info *coin; int32_t height; struct LP_transaction *tx; coin = LP_coinfind(symbol); if ( coin != 0 && (ep= coin->electrum) != 0 ) { if ( (up= LP_address_utxofind(coin,coinaddr,txid,vout)) == 0 ) { - if ( (txobj= electrum_transaction(symbol,ep,&txobj,txid,coinaddr)) != 0 ) + if ( (txobj= electrum_transaction(&height,symbol,ep,&txobj,txid,coinaddr)) != 0 ) free_json(txobj); if ( (tx= LP_transactionfind(coin,txid)) != 0 ) { diff --git a/iguana/exchanges/LP_privkey.c b/iguana/exchanges/LP_privkey.c index f9c533419..5c77b4c89 100644 --- a/iguana/exchanges/LP_privkey.c +++ b/iguana/exchanges/LP_privkey.c @@ -205,7 +205,7 @@ char *LP_secretaddresses(void *ctx,char *prefix,char *passphrase,int32_t n,uint8 bits256 LP_privkeycalc(void *ctx,uint8_t *pubkey33,bits256 *pubkeyp,struct iguana_info *coin,char *passphrase,char *wifstr) { //static uint32_t counter; - bits256 privkey,userpub,zero,userpass,checkkey; char tmpstr[128]; cJSON *retjson; uint8_t tmptype; + bits256 privkey,userpub,zero,userpass,checkkey; char tmpstr[128]; cJSON *retjson; uint8_t tmptype; int32_t notarized; if ( passphrase != 0 && passphrase[0] != 0 ) { calc_NXTaddr(G.LP_NXTaddr,userpub.bytes,(uint8_t *)passphrase,(int32_t)strlen(passphrase)); @@ -252,7 +252,7 @@ bits256 LP_privkeycalc(void *ctx,uint8_t *pubkey33,bits256 *pubkeyp,struct iguan printf("userpass.(%s)\n",bits256_str(G.USERPASS,userpub)); } } - if ( coin->importedprivkey == 0 && coin->electrum == 0 && coin->userpass[0] != 0 && LP_getheight(coin) > 0 ) + if ( coin->importedprivkey == 0 && coin->electrum == 0 && coin->userpass[0] != 0 && LP_getheight(¬arized,coin) > 0 ) { memset(zero.bytes,0,sizeof(zero)); LP_listunspent_issue(coin->symbol,coin->smartaddr,0,zero,zero); diff --git a/iguana/exchanges/LP_rpc.c b/iguana/exchanges/LP_rpc.c index 7b04045eb..5c60ea47e 100644 --- a/iguana/exchanges/LP_rpc.c +++ b/iguana/exchanges/LP_rpc.c @@ -86,9 +86,10 @@ void LP_unspents_mark(char *symbol,cJSON *vins) //printf("LOCK (%s)\n",jprint(vins,0)); } -int32_t LP_getheight(struct iguana_info *coin) +int32_t LP_getheight(int32_t *notarizedp,struct iguana_info *coin) { cJSON *retjson; char *retstr,*method = "getinfo"; int32_t height; + *notarizedp = 0; if ( coin == 0 ) return(-1); height = coin->height; @@ -101,6 +102,7 @@ int32_t LP_getheight(struct iguana_info *coin) { retjson = cJSON_Parse(retstr); coin->height = height = jint(retjson,"blocks"); + *notarizedp = jint(retjson,"notarized"); free_json(retjson); if ( coin->height > 0 ) coin->heighttime = (uint32_t)time(NULL); diff --git a/iguana/exchanges/LP_stats.c b/iguana/exchanges/LP_stats.c index fc33d58bc..1837fbffd 100644 --- a/iguana/exchanges/LP_stats.c +++ b/iguana/exchanges/LP_stats.c @@ -210,7 +210,9 @@ int32_t LP_swapstats_update(struct LP_swapstats *sp,struct LP_quoteinfo *qp,cJSO int32_t LP_dPoWheight(struct iguana_info *coin) // get dPoW protected height { - + int32_t notarized; + coin->height = LP_getheight(¬arized,coin); + return(notarized); } int32_t LP_finished_lastheight(struct LP_swapstats *sp,int32_t iambob) @@ -380,9 +382,9 @@ int32_t LP_statslog_parsequote(char *method,cJSON *lineobj) sp->expired = sp->lasttime; else { - if ( (alice= LP_coinfind(rel)) && alice->isassetchain != 0 ) + if ( (alice= LP_coinfind(rel)) != 0 && (alice->isassetchain != 0 || strcmp("KMD",alice->symbol) == 0) ) sp->aliceneeds_dPoW = 1; - if ( (bob= LP_coinfind(rel)) && bob->isassetchain != 0 ) + if ( (bob= LP_coinfind(rel)) != 0 && (bob->isassetchain != 0 || strcmp(bob->symbol,"KMD") == 0) ) sp->bobneeds_dPoW = 1; } strcpy(sp->bobgui,"nogui"); diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index 2770ad42b..aa11f9b3b 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -495,13 +495,13 @@ struct LP_address *LP_address_utxo_reset(struct iguana_info *coin) cJSON *LP_address_item(struct iguana_info *coin,struct LP_address_utxo *up,int32_t electrumret) { - cJSON *item = cJSON_CreateObject(); + int32_t notarized; cJSON *item = cJSON_CreateObject(); if ( electrumret == 0 ) { jaddbits256(item,"txid",up->U.txid); jaddnum(item,"vout",up->U.vout); if ( up->U.height > 0 ) - jaddnum(item,"confirmations",LP_getheight(coin) - up->U.height + 1); + jaddnum(item,"confirmations",LP_getheight(¬arized,coin) - up->U.height + 1); jaddnum(item,"amount",dstr(up->U.value)); jaddstr(item,"scriptPubKey",""); } @@ -802,7 +802,7 @@ int32_t LP_txheight(struct iguana_info *coin,bits256 txid) int32_t LP_numconfirms(char *symbol,char *coinaddr,bits256 txid,int32_t vout,int32_t mempool) { - struct iguana_info *coin; bits256 zero; int32_t ht,numconfirms = 100; + struct iguana_info *coin; bits256 zero; int32_t ht,notarized,numconfirms = 100; cJSON *txobj; if ( (coin= LP_coinfind(symbol)) == 0 || coin->inactive != 0 ) return(-1); @@ -827,7 +827,7 @@ int32_t LP_numconfirms(char *symbol,char *coinaddr,bits256 txid,int32_t vout,int memset(zero.bytes,0,sizeof(zero)); LP_listunspent_issue(symbol,coinaddr,1,txid,zero); if ( (ht= LP_txheight(coin,txid)) > 0 && ht <= coin->height ) - numconfirms = (LP_getheight(coin) - ht + 1); + numconfirms = (LP_getheight(¬arized,coin) - ht + 1); else if ( mempool != 0 ) { if ( LP_waitmempool(symbol,coinaddr,txid,vout,30) >= 0 ) From 7e43bf3f88fa1ab7de89a582e39b509e43ab057c Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 3 Dec 2017 16:14:31 +0400 Subject: [PATCH 10/59] Test --- iguana/exchanges/LP_ordermatch.c | 53 +++++++++++++++++--------------- 1 file changed, 29 insertions(+), 24 deletions(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 9ad350ce8..cebdfd947 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -421,34 +421,39 @@ struct LP_utxoinfo *LP_address_myutxopair(struct LP_utxoinfo *butxo,int32_t iamb printf("%.8f ",dstr(utxos[i]->U.value)); printf("targetval %.8f vol %.8f price %.8f txfee %.8f %s %s\n",dstr(targetval),relvolume,price,dstr(fee),coin->symbol,coinaddr); } - mini = -1; - if ( targetval != 0 && (mini= LP_nearest_utxovalue(coin,coinaddr,utxos,m,targetval+fee)) >= 0 ) + while ( 1 ) { - up = utxos[mini]; - utxos[mini] = 0; -//printf("found mini.%d %.8f for targetval %.8f -> targetval2 %.8f, ratio %.2f\n",mini,dstr(up->U.value),dstr(targetval),dstr(targetval2),(double)up->U.value/targetval); - if ( (double)up->U.value/targetval < ratio-1 ) - + mini = -1; + if ( targetval != 0 && (mini= LP_nearest_utxovalue(coin,coinaddr,utxos,m,targetval+fee)) >= 0 ) { - if ( 0 ) - { - int32_t i; - for (i=0; iU.value >= targetval2 ) - printf("%.8f ",dstr(utxos[i]->U.value)); - printf("targetval2 %.8f vol %.8f price %.8f txfee %.8f %s %s\n",dstr(targetval2),relvolume,price,dstr(fee),coin->symbol,coinaddr); - } - if ( (mini= LP_nearest_utxovalue(coin,coinaddr,utxos,m,(targetval2+2*fee) * 1.01)) >= 0 ) + up = utxos[mini]; + utxos[mini] = 0; + //printf("found mini.%d %.8f for targetval %.8f -> targetval2 %.8f, ratio %.2f\n",mini,dstr(up->U.value),dstr(targetval),dstr(targetval2),(double)up->U.value/targetval); + if ( (double)up->U.value/targetval < ratio-1 ) + { - if ( up != 0 && (up2= utxos[mini]) != 0 ) + if ( 0 ) { - LP_butxo_set(butxo,iambob,coin,up,up2,targetval); - return(butxo); - } else printf("cant find utxos[mini %d]\n",mini); - } else printf("cant find targetval2 %.8f\n",dstr(targetval2)); - } else printf("failed ratio test %.8f\n",(double)up->U.value/targetval); - } else if ( targetval != 0 && mini >= 0 ) - printf("targetval %.8f mini.%d\n",dstr(targetval),mini); + int32_t i; + for (i=0; iU.value >= targetval2 ) + printf("%.8f ",dstr(utxos[i]->U.value)); + printf("targetval2 %.8f vol %.8f price %.8f txfee %.8f %s %s\n",dstr(targetval2),relvolume,price,dstr(fee),coin->symbol,coinaddr); + } + if ( (mini= LP_nearest_utxovalue(coin,coinaddr,utxos,m,(targetval2+2*fee) * 1.01)) >= 0 ) + { + if ( up != 0 && (up2= utxos[mini]) != 0 ) + { + LP_butxo_set(butxo,iambob,coin,up,up2,targetval); + return(butxo); + } else printf("cant find utxos[mini %d]\n",mini); + } else printf("cant find targetval2 %.8f\n",dstr(targetval2)); + } else printf("failed ratio test %.8f\n",(double)up->U.value/targetval); + } else if ( targetval != 0 && mini >= 0 ) + printf("targetval %.8f mini.%d\n",dstr(targetval),mini); + if ( targetval == 0 || mini < 0 ) + break; + } } else printf("no %s utxos pass LP_address_utxo_ptrs filter\n",coinaddr); } else printf("address_myutxopair couldnt find %s %s\n",coin->symbol,coinaddr); return(0); From 2e9793f6ba61e9b14e91146fa0b42a81bcaa5d81 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 3 Dec 2017 16:22:13 +0400 Subject: [PATCH 11/59] Test --- iguana/exchanges/LP_instantdex.c | 4 ++-- iguana/exchanges/LP_ordermatch.c | 1 - iguana/exchanges/LP_stats.c | 3 ++- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/iguana/exchanges/LP_instantdex.c b/iguana/exchanges/LP_instantdex.c index b32297672..62fafbbad 100644 --- a/iguana/exchanges/LP_instantdex.c +++ b/iguana/exchanges/LP_instantdex.c @@ -463,12 +463,12 @@ cJSON *LP_swapstats_item(struct LP_swapstats *sp,int32_t iambob) if ( sp->bobneeds_dPoW != 0 ) { jaddnum(item,"bobneeds_dPoW",sp->bobneeds_dPoW); - jaddnum(item,"bobdPoW_height",sp->bob_dPoWheight); + jaddnum(item,"bob_dPoWheight",sp->bob_dPoWheight); } if ( sp->aliceneeds_dPoW != 0 ) { jaddnum(item,"aliceneeds_dPoW",sp->aliceneeds_dPoW); - jaddnum(item,"alicedPoW_height",sp->alice_dPoWheight); + jaddnum(item,"alice_dPoWheight",sp->alice_dPoWheight); } } return(item); diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index cebdfd947..fa911b330 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -1313,7 +1313,6 @@ char *LP_autobuy(void *ctx,char *myipaddr,int32_t mypubsock,char *base,char *rel memset(&A,0,sizeof(A)); LP_address_utxo_reset(relcoin); if ( (autxo= LP_address_myutxopair(&A,0,utxos,max,relcoin,relcoin->smartaddr,txfee,dstr(destsatoshis),maxprice,desttxfee)) == 0 ) - //if ( (autxo= LP_utxo_bestfit(rel,destsatoshis + 2*desttxfee)) == 0 ) return(clonestr("{\"error\":\"cant find alice utxo that is close enough in size\"}")); //printf("bestfit selected alice (%.8f %.8f) for %.8f sats %.8f\n",dstr(autxo->payment.value),dstr(autxo->fee.value),dstr(destsatoshis),dstr(autxo->swap_satoshis)); if ( destsatoshis - desttxfee < autxo->swap_satoshis ) diff --git a/iguana/exchanges/LP_stats.c b/iguana/exchanges/LP_stats.c index 1837fbffd..3d3e72981 100644 --- a/iguana/exchanges/LP_stats.c +++ b/iguana/exchanges/LP_stats.c @@ -211,7 +211,8 @@ int32_t LP_swapstats_update(struct LP_swapstats *sp,struct LP_quoteinfo *qp,cJSO int32_t LP_dPoWheight(struct iguana_info *coin) // get dPoW protected height { int32_t notarized; - coin->height = LP_getheight(¬arized,coin); + LP_getheight(¬arized,coin); + printf("dPoWheight.%s %d\n",coin->symbol,notarized); return(notarized); } From e347719541bbf0c0ad241f49f7f016e77b021ff3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 3 Dec 2017 16:28:57 +0400 Subject: [PATCH 12/59] Test --- iguana/exchanges/LP_stats.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_stats.c b/iguana/exchanges/LP_stats.c index 3d3e72981..49fbdc8cc 100644 --- a/iguana/exchanges/LP_stats.c +++ b/iguana/exchanges/LP_stats.c @@ -379,7 +379,7 @@ int32_t LP_statslog_parsequote(char *method,cJSON *lineobj) sp->methodind = methodind; sp->ind = LP_aliceids++; sp->lasttime = (uint32_t)time(NULL); - if ( sp->lasttime > sp->Q.timestamp+LP_atomic_locktime(base,rel)*2) + if ( sp->lasttime > sp->Q.timestamp+LP_atomic_locktime(base,rel)*2 ) sp->expired = sp->lasttime; else { @@ -436,6 +436,8 @@ cJSON *LP_swapstats_json(struct LP_swapstats *sp) jaddnum(item,"quoteid",sp->Q.R.quoteid); jaddnum(item,"finished",sp->finished); jaddnum(item,"expired",sp->expired); + if ( sp->finished == 0 && sp->expired == 0 ) + jaddnum(item,"expires",sp->Q.timestamp + LP_atomic_locktime(sp->Q.srccoin,sp->Q.destcoin)*2 - time(NULL)); jaddnum(item,"ind",sp->methodind); //jaddstr(item,"line",line); return(item); From 193dd3527c55f55144451c72566f770e5b107a6b Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 3 Dec 2017 16:35:50 +0400 Subject: [PATCH 13/59] Test --- iguana/exchanges/LP_rpc.c | 6 +++++- iguana/exchanges/LP_stats.c | 24 ++++++++++++++++++------ 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/iguana/exchanges/LP_rpc.c b/iguana/exchanges/LP_rpc.c index 5c60ea47e..e3b8e5d07 100644 --- a/iguana/exchanges/LP_rpc.c +++ b/iguana/exchanges/LP_rpc.c @@ -102,7 +102,11 @@ int32_t LP_getheight(int32_t *notarizedp,struct iguana_info *coin) { retjson = cJSON_Parse(retstr); coin->height = height = jint(retjson,"blocks"); - *notarizedp = jint(retjson,"notarized"); + if ( (*notarizedp= jint(retjson,"notarized")) != 0 && *notarizedp != coin->notarized ) + { + printf("new notarized %s %d -> %d\n",coin->symbol,coin->notarized,*notarizedp); + coin->notarized = *notarizedp; + } free_json(retjson); if ( coin->height > 0 ) coin->heighttime = (uint32_t)time(NULL); diff --git a/iguana/exchanges/LP_stats.c b/iguana/exchanges/LP_stats.c index 49fbdc8cc..c0bf11515 100644 --- a/iguana/exchanges/LP_stats.c +++ b/iguana/exchanges/LP_stats.c @@ -210,10 +210,19 @@ int32_t LP_swapstats_update(struct LP_swapstats *sp,struct LP_quoteinfo *qp,cJSO int32_t LP_dPoWheight(struct iguana_info *coin) // get dPoW protected height { - int32_t notarized; - LP_getheight(¬arized,coin); - printf("dPoWheight.%s %d\n",coin->symbol,notarized); - return(notarized); + int32_t notarized,oldnotarized; + if ( coin->electrum == 0 ) + { + coin->heighttime = (uint32_t)(time(NULL) - 61); + oldnotarized = coin->notarized; + LP_getheight(¬arized,coin); + if ( notarized != 0 && notarized != oldnotarized ) + { + printf("dPoWheight.%s %d <- %d\n",coin->symbol,oldnotarized,notarized); + coin->notarized = notarized; + } + } + return(coin->notarized); } int32_t LP_finished_lastheight(struct LP_swapstats *sp,int32_t iambob) @@ -248,6 +257,8 @@ int32_t LP_swap_finished(struct LP_swapstats *sp,int32_t dPoWflag) struct iguana_info *bob,*alice; bob = LP_coinfind(sp->Q.srccoin); alice = LP_coinfind(sp->Q.destcoin); + sp->bob_dPoWheight = LP_dPoWheight(bob); + sp->alice_dPoWheight = LP_dPoWheight(alice); if ( sp->finished == 0 ) { if ( sp->expired != 0 ) @@ -258,8 +269,6 @@ int32_t LP_swap_finished(struct LP_swapstats *sp,int32_t dPoWflag) return(1); else if ( sp->finished != 0 ) { - sp->bob_dPoWheight = LP_dPoWheight(bob); - sp->alice_dPoWheight = LP_dPoWheight(alice); if ( bob->isassetchain != 0 ) sp->bobneeds_dPoW = LP_finished_lastheight(sp,1); if ( alice->isassetchain != 0 ) @@ -267,7 +276,10 @@ int32_t LP_swap_finished(struct LP_swapstats *sp,int32_t dPoWflag) printf("bob needs %d @ %d, alice needs %d @ %d\n",sp->bobneeds_dPoW,sp->bob_dPoWheight,sp->aliceneeds_dPoW,sp->alice_dPoWheight); } if ( (sp->bobneeds_dPoW == 0 || (sp->bobneeds_dPoW > 1 && sp->bob_dPoWheight >= sp->bobneeds_dPoW)) && (sp->aliceneeds_dPoW == 0 || (sp->aliceneeds_dPoW > 1 && sp->alice_dPoWheight >= sp->aliceneeds_dPoW)) ) + { + sp->dPoWfinished = (uint32_t)time(NULL); return(1); + } } } return(0); From ed2214f2c10c02701c4244c17d6c28a388da5bec Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 3 Dec 2017 16:40:46 +0400 Subject: [PATCH 14/59] Test --- iguana/exchanges/LP_stats.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_stats.c b/iguana/exchanges/LP_stats.c index c0bf11515..fcc0c313b 100644 --- a/iguana/exchanges/LP_stats.c +++ b/iguana/exchanges/LP_stats.c @@ -255,8 +255,16 @@ int32_t LP_finished_lastheight(struct LP_swapstats *sp,int32_t iambob) int32_t LP_swap_finished(struct LP_swapstats *sp,int32_t dPoWflag) { struct iguana_info *bob,*alice; - bob = LP_coinfind(sp->Q.srccoin); - alice = LP_coinfind(sp->Q.destcoin); + if ( (bob= LP_coinfind(sp->Q.srccoin)) == 0 ) + { + printf("no bobcoin.%s\n",sp->Q.srccoin); + return(0); + } + if ( (alice= LP_coinfind(sp->Q.destcoin)) == 0 ) + { + printf("no alicecoin.%s\n",sp->Q.destcoin); + return(0); + } sp->bob_dPoWheight = LP_dPoWheight(bob); sp->alice_dPoWheight = LP_dPoWheight(alice); if ( sp->finished == 0 ) From 01961694f6afeb4028d581f999af7bedb8cba2ed Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 3 Dec 2017 16:42:11 +0400 Subject: [PATCH 15/59] Test --- iguana/exchanges/LP_commands.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/iguana/exchanges/LP_commands.c b/iguana/exchanges/LP_commands.c index a0af02d32..bb05f3cf3 100644 --- a/iguana/exchanges/LP_commands.c +++ b/iguana/exchanges/LP_commands.c @@ -258,15 +258,13 @@ instantdex_claim()\n\ return(jprint(LP_coinsjson(0),1)); else if ( strcmp(method,"notarizations") == 0 ) { - int32_t height,bestheight; if ( (ptr= LP_coinsearch(coin)) != 0 ) { - height = LP_notarization_latest(&bestheight,ptr); retjson = cJSON_CreateObject(); jaddstr(retjson,"result","success"); jaddstr(retjson,"coin",coin); - jaddnum(retjson,"lastnotarization",height); - jaddnum(retjson,"bestheight",bestheight); + jaddnum(retjson,"lastnotarization",ptr->notarized); + jaddnum(retjson,"bestheight",ptr->height); return(jprint(retjson,1)); } else return(clonestr("{\"error\":\"cant find coin\"}")); } From 23b582cfd1490f073e46fe9e79a5b25db8aae211 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 3 Dec 2017 16:46:32 +0400 Subject: [PATCH 16/59] Test --- iguana/exchanges/LP_bitcoin.c | 2 ++ iguana/exchanges/LP_rpc.c | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_bitcoin.c b/iguana/exchanges/LP_bitcoin.c index f9c212cd1..e4fb09e5d 100644 --- a/iguana/exchanges/LP_bitcoin.c +++ b/iguana/exchanges/LP_bitcoin.c @@ -2008,6 +2008,8 @@ int32_t bitcoin_p2shscript(uint8_t *script,int32_t n,const uint8_t *p2shscript,c char *bitcoind_passthru(char *coinstr,char *serverport,char *userpass,char *method,char *params) { + if ( userpass[0] == 0 ) + return(clonestr("{\"error\":\"no rpcusername rpcpassword in coin.conf\"}")); return(bitcoind_RPC(0,coinstr,serverport,userpass,method,params,4)); } diff --git a/iguana/exchanges/LP_rpc.c b/iguana/exchanges/LP_rpc.c index e3b8e5d07..169192f54 100644 --- a/iguana/exchanges/LP_rpc.c +++ b/iguana/exchanges/LP_rpc.c @@ -93,7 +93,7 @@ int32_t LP_getheight(int32_t *notarizedp,struct iguana_info *coin) if ( coin == 0 ) return(-1); height = coin->height; - if ( coin->electrum == 0 && time(NULL) > coin->heighttime+60 ) + if ( coin->electrum == 0 && time(NULL) > coin->heighttime+60 && coin->userpass[0] != 0 ) { if ( strcmp(coin->symbol,"BTC") == 0 ) method = "getblockchaininfo"; From 014920967138034926cd8711156845edfaeb6c7e Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 3 Dec 2017 16:50:23 +0400 Subject: [PATCH 17/59] Test --- iguana/exchanges/LP_stats.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_stats.c b/iguana/exchanges/LP_stats.c index fcc0c313b..433fc8126 100644 --- a/iguana/exchanges/LP_stats.c +++ b/iguana/exchanges/LP_stats.c @@ -265,8 +265,6 @@ int32_t LP_swap_finished(struct LP_swapstats *sp,int32_t dPoWflag) printf("no alicecoin.%s\n",sp->Q.destcoin); return(0); } - sp->bob_dPoWheight = LP_dPoWheight(bob); - sp->alice_dPoWheight = LP_dPoWheight(alice); if ( sp->finished == 0 ) { if ( sp->expired != 0 ) @@ -281,6 +279,8 @@ int32_t LP_swap_finished(struct LP_swapstats *sp,int32_t dPoWflag) sp->bobneeds_dPoW = LP_finished_lastheight(sp,1); if ( alice->isassetchain != 0 ) sp->aliceneeds_dPoW = LP_finished_lastheight(sp,0); + sp->bob_dPoWheight = LP_dPoWheight(bob); + sp->alice_dPoWheight = LP_dPoWheight(alice); printf("bob needs %d @ %d, alice needs %d @ %d\n",sp->bobneeds_dPoW,sp->bob_dPoWheight,sp->aliceneeds_dPoW,sp->alice_dPoWheight); } if ( (sp->bobneeds_dPoW == 0 || (sp->bobneeds_dPoW > 1 && sp->bob_dPoWheight >= sp->bobneeds_dPoW)) && (sp->aliceneeds_dPoW == 0 || (sp->aliceneeds_dPoW > 1 && sp->alice_dPoWheight >= sp->aliceneeds_dPoW)) ) From 402214f45ba1c4291423ec6c68ef0cade2302daf Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 3 Dec 2017 16:52:52 +0400 Subject: [PATCH 18/59] Test --- iguana/exchanges/LP_include.h | 2 +- iguana/exchanges/LP_instantdex.c | 10 +++++----- iguana/exchanges/LP_stats.c | 6 ++---- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/iguana/exchanges/LP_include.h b/iguana/exchanges/LP_include.h index 2de68ee07..a70137b68 100644 --- a/iguana/exchanges/LP_include.h +++ b/iguana/exchanges/LP_include.h @@ -403,7 +403,7 @@ struct LP_swapstats bits256 bobdeposit,alicepayment,bobpayment,paymentspent,Apaymentspent,depositspent; double qprice; uint64_t aliceid; - int32_t bobneeds_dPoW,aliceneeds_dPoW,bob_dPoWheight,alice_dPoWheight; + int32_t bobneeds_dPoW,aliceneeds_dPoW; uint32_t ind,methodind,finished,expired,lasttime,dPoWfinished; char alicegui[32],bobgui[32]; }; diff --git a/iguana/exchanges/LP_instantdex.c b/iguana/exchanges/LP_instantdex.c index 62fafbbad..0e482e6c9 100644 --- a/iguana/exchanges/LP_instantdex.c +++ b/iguana/exchanges/LP_instantdex.c @@ -447,7 +447,7 @@ int64_t LP_myzcredits() cJSON *LP_swapstats_item(struct LP_swapstats *sp,int32_t iambob) { - cJSON *item = cJSON_CreateObject(); + struct iguana_info *bob,*alice; cJSON *item = cJSON_CreateObject(); jaddnum(item,"iambob",iambob); jaddnum(item,"aliceid",sp->aliceid); jaddnum(item,"requestid",sp->Q.R.requestid); @@ -460,15 +460,15 @@ cJSON *LP_swapstats_item(struct LP_swapstats *sp,int32_t iambob) if ( LP_swap_finished(sp,1) == 0 ) { jaddnum(item,"finished",sp->finished); - if ( sp->bobneeds_dPoW != 0 ) + if ( sp->bobneeds_dPoW != 0 && (bob= LP_coinfind(sp->Q.srccoin)) != 0 ) { jaddnum(item,"bobneeds_dPoW",sp->bobneeds_dPoW); - jaddnum(item,"bob_dPoWheight",sp->bob_dPoWheight); + jaddnum(item,"bob_dPoWheight",bob->notarized); } - if ( sp->aliceneeds_dPoW != 0 ) + if ( sp->aliceneeds_dPoW != 0 && (alice= LP_coinfind(sp->Q.destcoin)) != 0 ) { jaddnum(item,"aliceneeds_dPoW",sp->aliceneeds_dPoW); - jaddnum(item,"alice_dPoWheight",sp->alice_dPoWheight); + jaddnum(item,"alice_dPoWheight",alice->notarized); } } return(item); diff --git a/iguana/exchanges/LP_stats.c b/iguana/exchanges/LP_stats.c index 433fc8126..0e3b958fe 100644 --- a/iguana/exchanges/LP_stats.c +++ b/iguana/exchanges/LP_stats.c @@ -279,11 +279,9 @@ int32_t LP_swap_finished(struct LP_swapstats *sp,int32_t dPoWflag) sp->bobneeds_dPoW = LP_finished_lastheight(sp,1); if ( alice->isassetchain != 0 ) sp->aliceneeds_dPoW = LP_finished_lastheight(sp,0); - sp->bob_dPoWheight = LP_dPoWheight(bob); - sp->alice_dPoWheight = LP_dPoWheight(alice); - printf("bob needs %d @ %d, alice needs %d @ %d\n",sp->bobneeds_dPoW,sp->bob_dPoWheight,sp->aliceneeds_dPoW,sp->alice_dPoWheight); + printf("bob needs %d @ %d, alice needs %d @ %d\n",sp->bobneeds_dPoW,bob->notarized,sp->aliceneeds_dPoW,alice->notarized); } - if ( (sp->bobneeds_dPoW == 0 || (sp->bobneeds_dPoW > 1 && sp->bob_dPoWheight >= sp->bobneeds_dPoW)) && (sp->aliceneeds_dPoW == 0 || (sp->aliceneeds_dPoW > 1 && sp->alice_dPoWheight >= sp->aliceneeds_dPoW)) ) + if ( (sp->bobneeds_dPoW == 0 || (sp->bobneeds_dPoW > 1 && bob->notarized >= sp->bobneeds_dPoW)) && (sp->aliceneeds_dPoW == 0 || (sp->aliceneeds_dPoW > 1 && alice->notarized >= sp->aliceneeds_dPoW)) ) { sp->dPoWfinished = (uint32_t)time(NULL); return(1); From a27ff3e23834f1ba6d77ea8c3d2f7ded17d7c757 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 3 Dec 2017 16:59:29 +0400 Subject: [PATCH 19/59] Test --- iguana/exchanges/LP_stats.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_stats.c b/iguana/exchanges/LP_stats.c index 0e3b958fe..3e171961a 100644 --- a/iguana/exchanges/LP_stats.c +++ b/iguana/exchanges/LP_stats.c @@ -197,7 +197,7 @@ int32_t LP_swapstats_update(struct LP_swapstats *sp,struct LP_quoteinfo *qp,cJSO } else { - if ( requestid == sp->Q.R.requestid && quoteid == sp->Q.R.quoteid ) + if ( 0 && requestid == sp->Q.R.requestid && quoteid == sp->Q.R.quoteid ) printf("mismatched tradestatus aliceid.%22llu b%s/%s r%s/%s r%u/%u q%u/%u %.8f/%.8f -> %.8f/%.8f\n",(long long)sp->aliceid,base,sp->Q.srccoin,rel,sp->Q.destcoin,requestid,sp->Q.R.requestid,quoteid,sp->Q.R.quoteid,dstr(satoshis+2*sp->Q.txfee),dstr(sp->Q.satoshis),dstr(destsatoshis+2*sp->Q.desttxfee),dstr(sp->Q.destsatoshis)); return(-1); } @@ -233,20 +233,38 @@ int32_t LP_finished_lastheight(struct LP_swapstats *sp,int32_t iambob) if ( iambob != 0 ) { if ( bits256_nonz(sp->bobdeposit) != 0 && (ht= LP_txheight(coin,sp->bobdeposit)) > 1 && ht > height ) + { height = ht; + printf("bobdeposit.%d height.%d\n",ht,height); + } if ( bits256_nonz(sp->bobpayment) != 0 && (ht= LP_txheight(coin,sp->bobpayment)) > 1 && ht > height ) + { height = ht; + printf("bobpayment.%d height.%d\n",ht,height); + } if ( bits256_nonz(sp->paymentspent) != 0 && (ht= LP_txheight(coin,sp->paymentspent)) > 1 && ht > height ) + { height = ht; + printf("paymentspent.%d height.%d\n",ht,height); + } if ( bits256_nonz(sp->depositspent) != 0 && (ht= LP_txheight(coin,sp->depositspent)) > 1 && ht > height ) + { height = ht; + printf("depositspent.%d height.%d\n",ht,height); + } } else { if ( bits256_nonz(sp->alicepayment) != 0 && (ht= LP_txheight(coin,sp->alicepayment)) > 1 && ht > height ) + { height = ht; + printf("alicepayment.%d height.%d\n",ht,height); + } if ( bits256_nonz(sp->Apaymentspent) != 0 && (ht= LP_txheight(coin,sp->Apaymentspent)) > 1 && ht > height ) + { height = ht; + printf("Apaymentspent.%d height.%d\n",ht,height); + } } } return(height); From 28f35c69daf4ad653ef74c36a69b731976d727e2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 3 Dec 2017 17:00:28 +0400 Subject: [PATCH 20/59] Test --- iguana/exchanges/LP_nativeDEX.c | 3 ++- iguana/exchanges/LP_stats.c | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 4163a4511..69e83e6d2 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -17,7 +17,7 @@ // LP_nativeDEX.c // marketmaker // -// delay swap credit back until notarization, else path +// too much stats.log // big BTC swaps // https://github.com/bitcoin/bips/blob/master/bip-0143.mediawiki for signing BCH/BTG // @@ -27,6 +27,7 @@ // portfolio value based on ask? // USD paxprice based USDvalue in portfolio // +// else claim path // improve critical section detection when parallel trades // dPoW security -> 4: KMD notarized, 5: BTC notarized, after next notary elections // bigendian architectures need to use little endian for sighash calcs diff --git a/iguana/exchanges/LP_stats.c b/iguana/exchanges/LP_stats.c index 3e171961a..c569fec67 100644 --- a/iguana/exchanges/LP_stats.c +++ b/iguana/exchanges/LP_stats.c @@ -275,12 +275,12 @@ int32_t LP_swap_finished(struct LP_swapstats *sp,int32_t dPoWflag) struct iguana_info *bob,*alice; if ( (bob= LP_coinfind(sp->Q.srccoin)) == 0 ) { - printf("no bobcoin.%s\n",sp->Q.srccoin); + //printf("no bobcoin.%s\n",sp->Q.srccoin); return(0); } if ( (alice= LP_coinfind(sp->Q.destcoin)) == 0 ) { - printf("no alicecoin.%s\n",sp->Q.destcoin); + //printf("no alicecoin.%s\n",sp->Q.destcoin); return(0); } if ( sp->finished == 0 ) From b3eeca47e1fe3c0fbf4220d8fd87d848f4d76e64 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 3 Dec 2017 17:21:07 +0400 Subject: [PATCH 21/59] Test --- iguana/exchanges/LP_include.h | 3 +- iguana/exchanges/LP_stats.c | 53 ++++++++++++++++++++++++++++++++--- 2 files changed, 51 insertions(+), 5 deletions(-) diff --git a/iguana/exchanges/LP_include.h b/iguana/exchanges/LP_include.h index a70137b68..29fe7cf4a 100644 --- a/iguana/exchanges/LP_include.h +++ b/iguana/exchanges/LP_include.h @@ -64,7 +64,8 @@ void emscripten_usleep(int32_t x); // returns immediate, no sense for sleeping // RTmetrics #define LP_RTMETRICS_TOPGROUP 1.01 -#define LP_MAXPENDING_SWAPS 13 +//#define LP_MAXPENDING_SWAPS 13 +#define LP_CLIENT_STATSPARSE (100 * 1024 * 1024) #define LP_COMMAND_SENDSOCK NN_PUSH #define LP_COMMAND_RECVSOCK NN_PULL diff --git a/iguana/exchanges/LP_stats.c b/iguana/exchanges/LP_stats.c index c569fec67..2a323e4e3 100644 --- a/iguana/exchanges/LP_stats.c +++ b/iguana/exchanges/LP_stats.c @@ -81,13 +81,14 @@ void LP_statslog_parseline(cJSON *lineobj) int32_t LP_statslog_parse() { - static long lastpos; FILE *fp; char line[8192]; cJSON *lineobj; int32_t n = 0; + static long lastpos; + FILE *fp; long fpos; char line[8192]; cJSON *lineobj; int32_t c,n = 0; if ( (fp= fopen(LP_STATSLOG_FNAME,"rb")) != 0 ) { if ( lastpos > 0 ) { fseek(fp,0,SEEK_END); - if ( ftell(fp) > lastpos ) + if ( ftell(fp) >= lastpos ) fseek(fp,lastpos,SEEK_SET); else { @@ -95,6 +96,20 @@ int32_t LP_statslog_parse() return(0); } } + else + { + if ( IAMLP == 0 ) + { + fseek(fp,0,SEEK_END); + if ( (fpos= ftell(fp)) > LP_CLIENT_STATSPARSE ) + { + fseek(fp,fpos-LP_CLIENT_STATSPARSE,SEEK_SET); + while ( (c= fgetc(fp)) >= 0 && c != '\n' ) + ; + printf("start scanning %s from %ld, found boundary %ld\n",LP_STATSLOG_FNAME,fpos-LP_CLIENT_STATSPARSE,ftell(fp)); + } + } + } while ( fgets(line,sizeof(line),fp) > 0 ) { lastpos = ftell(fp); @@ -472,6 +487,18 @@ cJSON *LP_swapstats_json(struct LP_swapstats *sp) jaddnum(item,"quoteid",sp->Q.R.quoteid); jaddnum(item,"finished",sp->finished); jaddnum(item,"expired",sp->expired); + if ( bits256_nonz(sp->bobdeposit) != 0 ) + jaddbits256(item,"bobdeposit",sp->bobdeposit); + if ( bits256_nonz(sp->alicepayment) != 0 ) + jaddbits256(item,"alicepayment",sp->alicepayment); + if ( bits256_nonz(sp->bobpayment) != 0 ) + jaddbits256(item,"bobpayment",sp->bobpayment); + if ( bits256_nonz(sp->paymentspent) != 0 ) + jaddbits256(item,"paymentspent",sp->paymentspent); + if ( bits256_nonz(sp->Apaymentspent) != 0 ) + jaddbits256(item,"Apaymentspent",sp->Apaymentspent); + if ( bits256_nonz(sp->depositspent) != 0 ) + jaddbits256(item,"depositspent",sp->depositspent); if ( sp->finished == 0 && sp->expired == 0 ) jaddnum(item,"expires",sp->Q.timestamp + LP_atomic_locktime(sp->Q.srccoin,sp->Q.destcoin)*2 - time(NULL)); jaddnum(item,"ind",sp->methodind); @@ -481,7 +508,7 @@ cJSON *LP_swapstats_json(struct LP_swapstats *sp) char *LP_swapstatus_recv(cJSON *argjson) { - struct LP_swapstats *sp; int32_t methodind; + struct LP_swapstats *sp; int32_t methodind; bits256 txid; //printf("swapstatus.(%s)\n",jprint(argjson,0)); if ( (sp= LP_swapstats_find(j64bits(argjson,"aliceid"))) != 0 ) { @@ -493,6 +520,24 @@ char *LP_swapstatus_recv(cJSON *argjson) sp->methodind = methodind; sp->finished = juint(argjson,"finished"); sp->expired = juint(argjson,"expired"); + txid = jbits256(argjson,"bobdeposit"); + if ( bits256_nonz(txid) != 0 ) + sp->bobdeposit = txid; + txid = jbits256(argjson,"alicepayment"); + if ( bits256_nonz(txid) != 0 ) + sp->alicepayment = txid; + txid = jbits256(argjson,"bobpayment"); + if ( bits256_nonz(txid) != 0 ) + sp->bobpayment = txid; + txid = jbits256(argjson,"paymentspent"); + if ( bits256_nonz(txid) != 0 ) + sp->paymentspent = txid; + txid = jbits256(argjson,"Apaymentspent"); + if ( bits256_nonz(txid) != 0 ) + sp->Apaymentspent = txid; + txid = jbits256(argjson,"depositspent"); + if ( bits256_nonz(txid) != 0 ) + sp->depositspent = txid; } } return(clonestr("{\"result\":\"success\"}")); @@ -519,7 +564,7 @@ int32_t LP_stats_dispiter(cJSON *array,struct LP_swapstats *sp,uint32_t starttim int32_t dispflag,retval = 0; if ( sp->finished == 0 && sp->expired == 0 && time(NULL) > sp->Q.timestamp+LP_atomic_locktime(sp->Q.srccoin,sp->Q.destcoin)*2 ) sp->expired = (uint32_t)time(NULL); - if ( sp->finished != 0 || sp->expired != 0 ) + if ( LP_swap_finished(sp,1) > 0 ) retval = 1; dispflag = 0; if ( starttime == 0 && endtime == 0 ) From 4c302cd2eeb63c87d34ab06b2e8905f056064086 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 3 Dec 2017 17:28:14 +0400 Subject: [PATCH 22/59] Test --- iguana/exchanges/LP_stats.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_stats.c b/iguana/exchanges/LP_stats.c index 2a323e4e3..3532472b0 100644 --- a/iguana/exchanges/LP_stats.c +++ b/iguana/exchanges/LP_stats.c @@ -96,7 +96,7 @@ int32_t LP_statslog_parse() return(0); } } - else + else if ( 0 ) { if ( IAMLP == 0 ) { From 40f61609983284adf3dcd83568acf9c33b830f7d Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 3 Dec 2017 17:32:02 +0400 Subject: [PATCH 23/59] Test --- iguana/exchanges/LP_stats.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/iguana/exchanges/LP_stats.c b/iguana/exchanges/LP_stats.c index 3532472b0..81643c224 100644 --- a/iguana/exchanges/LP_stats.c +++ b/iguana/exchanges/LP_stats.c @@ -302,23 +302,23 @@ int32_t LP_swap_finished(struct LP_swapstats *sp,int32_t dPoWflag) { if ( sp->expired != 0 ) return(1); - if ( dPoWflag != 0 ) + } + if ( dPoWflag != 0 ) + { + if ( sp->dPoWfinished != 0 ) + return(1); + else if ( sp->finished != 0 ) { - if ( sp->finished != 0 && sp->dPoWfinished != 0 ) - return(1); - else if ( sp->finished != 0 ) - { - if ( bob->isassetchain != 0 ) - sp->bobneeds_dPoW = LP_finished_lastheight(sp,1); - if ( alice->isassetchain != 0 ) - sp->aliceneeds_dPoW = LP_finished_lastheight(sp,0); - printf("bob needs %d @ %d, alice needs %d @ %d\n",sp->bobneeds_dPoW,bob->notarized,sp->aliceneeds_dPoW,alice->notarized); - } - if ( (sp->bobneeds_dPoW == 0 || (sp->bobneeds_dPoW > 1 && bob->notarized >= sp->bobneeds_dPoW)) && (sp->aliceneeds_dPoW == 0 || (sp->aliceneeds_dPoW > 1 && alice->notarized >= sp->aliceneeds_dPoW)) ) - { - sp->dPoWfinished = (uint32_t)time(NULL); - return(1); - } + if ( bob->isassetchain != 0 ) + sp->bobneeds_dPoW = LP_finished_lastheight(sp,1); + if ( alice->isassetchain != 0 ) + sp->aliceneeds_dPoW = LP_finished_lastheight(sp,0); + printf("bob needs %d @ %d, alice needs %d @ %d\n",sp->bobneeds_dPoW,bob->notarized,sp->aliceneeds_dPoW,alice->notarized); + } + if ( (sp->bobneeds_dPoW == 0 || (sp->bobneeds_dPoW > 1 && bob->notarized >= sp->bobneeds_dPoW)) && (sp->aliceneeds_dPoW == 0 || (sp->aliceneeds_dPoW > 1 && alice->notarized >= sp->aliceneeds_dPoW)) ) + { + sp->dPoWfinished = (uint32_t)time(NULL); + return(1); } } return(0); From 558edc90e4cc172603cf4b233e0b9e8b88605e29 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 3 Dec 2017 17:39:30 +0400 Subject: [PATCH 24/59] Test --- iguana/exchanges/LP_stats.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/iguana/exchanges/LP_stats.c b/iguana/exchanges/LP_stats.c index 81643c224..9024f9ef4 100644 --- a/iguana/exchanges/LP_stats.c +++ b/iguana/exchanges/LP_stats.c @@ -250,22 +250,22 @@ int32_t LP_finished_lastheight(struct LP_swapstats *sp,int32_t iambob) if ( bits256_nonz(sp->bobdeposit) != 0 && (ht= LP_txheight(coin,sp->bobdeposit)) > 1 && ht > height ) { height = ht; - printf("bobdeposit.%d height.%d\n",ht,height); + //printf("bobdeposit.%d height.%d\n",ht,height); } if ( bits256_nonz(sp->bobpayment) != 0 && (ht= LP_txheight(coin,sp->bobpayment)) > 1 && ht > height ) { height = ht; - printf("bobpayment.%d height.%d\n",ht,height); + //printf("bobpayment.%d height.%d\n",ht,height); } if ( bits256_nonz(sp->paymentspent) != 0 && (ht= LP_txheight(coin,sp->paymentspent)) > 1 && ht > height ) { height = ht; - printf("paymentspent.%d height.%d\n",ht,height); + //printf("paymentspent.%d height.%d\n",ht,height); } if ( bits256_nonz(sp->depositspent) != 0 && (ht= LP_txheight(coin,sp->depositspent)) > 1 && ht > height ) { height = ht; - printf("depositspent.%d height.%d\n",ht,height); + //printf("depositspent.%d height.%d\n",ht,height); } } else @@ -509,9 +509,9 @@ cJSON *LP_swapstats_json(struct LP_swapstats *sp) char *LP_swapstatus_recv(cJSON *argjson) { struct LP_swapstats *sp; int32_t methodind; bits256 txid; - //printf("swapstatus.(%s)\n",jprint(argjson,0)); if ( (sp= LP_swapstats_find(j64bits(argjson,"aliceid"))) != 0 ) { + printf("swapstatus.(%s)\n",jprint(argjson,0)); sp->lasttime = (uint32_t)time(NULL); if ( (methodind= jint(argjson,"ind")) > sp->methodind && methodind < sizeof(LP_stats_methods)/sizeof(*LP_stats_methods) ) { From 886a4962e513f1da1a4a7ea6f7e550d0a9d42ffb Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 3 Dec 2017 17:44:32 +0400 Subject: [PATCH 25/59] Test --- iguana/exchanges/LP_stats.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/iguana/exchanges/LP_stats.c b/iguana/exchanges/LP_stats.c index 9024f9ef4..728f2538a 100644 --- a/iguana/exchanges/LP_stats.c +++ b/iguana/exchanges/LP_stats.c @@ -309,11 +309,12 @@ int32_t LP_swap_finished(struct LP_swapstats *sp,int32_t dPoWflag) return(1); else if ( sp->finished != 0 ) { - if ( bob->isassetchain != 0 ) + if ( bob->isassetchain != 0 || strcmp(sp->Q.srccoin,"KMD") == 0 ) sp->bobneeds_dPoW = LP_finished_lastheight(sp,1); - if ( alice->isassetchain != 0 ) + if ( alice->isassetchain != 0 || strcmp(sp->Q.destcoin,"KMD") == 0 ) sp->aliceneeds_dPoW = LP_finished_lastheight(sp,0); - printf("bob needs %d @ %d, alice needs %d @ %d\n",sp->bobneeds_dPoW,bob->notarized,sp->aliceneeds_dPoW,alice->notarized); + if ( IAMLP == 0 ) + printf("bob needs %d @ %d, alice needs %d @ %d\n",sp->bobneeds_dPoW,bob->notarized,sp->aliceneeds_dPoW,alice->notarized); } if ( (sp->bobneeds_dPoW == 0 || (sp->bobneeds_dPoW > 1 && bob->notarized >= sp->bobneeds_dPoW)) && (sp->aliceneeds_dPoW == 0 || (sp->aliceneeds_dPoW > 1 && alice->notarized >= sp->aliceneeds_dPoW)) ) { @@ -511,7 +512,8 @@ char *LP_swapstatus_recv(cJSON *argjson) struct LP_swapstats *sp; int32_t methodind; bits256 txid; if ( (sp= LP_swapstats_find(j64bits(argjson,"aliceid"))) != 0 ) { - printf("swapstatus.(%s)\n",jprint(argjson,0)); + if ( IAMLP == 0 ) + printf("swapstatus.(%s)\n",jprint(argjson,0)); sp->lasttime = (uint32_t)time(NULL); if ( (methodind= jint(argjson,"ind")) > sp->methodind && methodind < sizeof(LP_stats_methods)/sizeof(*LP_stats_methods) ) { From 703a2fd0412d16f9b3de3e1e9662d0a824dfd4c5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 3 Dec 2017 17:56:08 +0400 Subject: [PATCH 26/59] Test --- iguana/exchanges/LP_include.h | 2 +- iguana/exchanges/LP_instantdex.c | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_include.h b/iguana/exchanges/LP_include.h index 29fe7cf4a..7b78ed2bf 100644 --- a/iguana/exchanges/LP_include.h +++ b/iguana/exchanges/LP_include.h @@ -27,7 +27,7 @@ #define LP_MAJOR_VERSION "0" #define LP_MINOR_VERSION "1" -#define LP_BUILD_NUMBER "17577" +#define LP_BUILD_NUMBER "17667" #define LP_BARTERDEX_VERSION 1 #define LP_MAGICBITS 1 diff --git a/iguana/exchanges/LP_instantdex.c b/iguana/exchanges/LP_instantdex.c index 0e482e6c9..6e2b9f328 100644 --- a/iguana/exchanges/LP_instantdex.c +++ b/iguana/exchanges/LP_instantdex.c @@ -447,7 +447,8 @@ int64_t LP_myzcredits() cJSON *LP_swapstats_item(struct LP_swapstats *sp,int32_t iambob) { - struct iguana_info *bob,*alice; cJSON *item = cJSON_CreateObject(); + struct iguana_info *bob,*alice; int32_t flag = 0; cJSON *item; char *retstr; + item = cJSON_CreateObject(); jaddnum(item,"iambob",iambob); jaddnum(item,"aliceid",sp->aliceid); jaddnum(item,"requestid",sp->Q.R.requestid); @@ -464,12 +465,18 @@ cJSON *LP_swapstats_item(struct LP_swapstats *sp,int32_t iambob) { jaddnum(item,"bobneeds_dPoW",sp->bobneeds_dPoW); jaddnum(item,"bob_dPoWheight",bob->notarized); + if ( sp->bobneeds_dPoW == 1 ) + flag = 1; } if ( sp->aliceneeds_dPoW != 0 && (alice= LP_coinfind(sp->Q.destcoin)) != 0 ) { jaddnum(item,"aliceneeds_dPoW",sp->aliceneeds_dPoW); jaddnum(item,"alice_dPoWheight",alice->notarized); + if ( sp->aliceneeds_dPoW == 1 ) + flag = 1; } + if ( flag != 0 && (retstr= LP_gettradestatus(sp->aliceid)) != 0 ) + free(retstr); } return(item); } From 6f6466e5f84a795f66a9f18bbe55581a70c7a6c9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 3 Dec 2017 18:03:27 +0400 Subject: [PATCH 27/59] Test --- iguana/exchanges/LP_stats.c | 38 +++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/iguana/exchanges/LP_stats.c b/iguana/exchanges/LP_stats.c index 728f2538a..52e9bbf8c 100644 --- a/iguana/exchanges/LP_stats.c +++ b/iguana/exchanges/LP_stats.c @@ -247,37 +247,43 @@ int32_t LP_finished_lastheight(struct LP_swapstats *sp,int32_t iambob) { if ( iambob != 0 ) { - if ( bits256_nonz(sp->bobdeposit) != 0 && (ht= LP_txheight(coin,sp->bobdeposit)) > 1 && ht > height ) + if ( bits256_nonz(sp->bobdeposit) != 0 && (ht= LP_txheight(coin,sp->bobdeposit)) > 1 ) { - height = ht; - //printf("bobdeposit.%d height.%d\n",ht,height); + if ( ht > height ) + height = ht; + printf("bobdeposit.%d height.%d\n",ht,height); } - if ( bits256_nonz(sp->bobpayment) != 0 && (ht= LP_txheight(coin,sp->bobpayment)) > 1 && ht > height ) + if ( bits256_nonz(sp->bobpayment) != 0 && (ht= LP_txheight(coin,sp->bobpayment)) > 1 ) { - height = ht; - //printf("bobpayment.%d height.%d\n",ht,height); + if ( ht > height ) + height = ht; + printf("bobpayment.%d height.%d\n",ht,height); } - if ( bits256_nonz(sp->paymentspent) != 0 && (ht= LP_txheight(coin,sp->paymentspent)) > 1 && ht > height ) + if ( bits256_nonz(sp->paymentspent) != 0 && (ht= LP_txheight(coin,sp->paymentspent)) > 1 ) { - height = ht; - //printf("paymentspent.%d height.%d\n",ht,height); + if ( ht > height ) + height = ht; + printf("paymentspent.%d height.%d\n",ht,height); } - if ( bits256_nonz(sp->depositspent) != 0 && (ht= LP_txheight(coin,sp->depositspent)) > 1 && ht > height ) + if ( bits256_nonz(sp->depositspent) != 0 && (ht= LP_txheight(coin,sp->depositspent)) > 1 ) { - height = ht; - //printf("depositspent.%d height.%d\n",ht,height); + if ( ht > height ) + height = ht; + printf("depositspent.%d height.%d\n",ht,height); } } else { - if ( bits256_nonz(sp->alicepayment) != 0 && (ht= LP_txheight(coin,sp->alicepayment)) > 1 && ht > height ) + if ( bits256_nonz(sp->alicepayment) != 0 && (ht= LP_txheight(coin,sp->alicepayment)) > 1 ) { - height = ht; + if ( ht > height ) + height = ht; printf("alicepayment.%d height.%d\n",ht,height); } - if ( bits256_nonz(sp->Apaymentspent) != 0 && (ht= LP_txheight(coin,sp->Apaymentspent)) > 1 && ht > height ) + if ( bits256_nonz(sp->Apaymentspent) != 0 && (ht= LP_txheight(coin,sp->Apaymentspent)) > 1 ) { - height = ht; + if ( ht > height ) + height = ht; printf("Apaymentspent.%d height.%d\n",ht,height); } } From 9ede5b54ba102cc2d91a54a7bd900dd81368ded8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 3 Dec 2017 18:09:48 +0400 Subject: [PATCH 28/59] Test --- iguana/exchanges/LP_stats.c | 63 ++++++++++++++++++------------------- 1 file changed, 30 insertions(+), 33 deletions(-) diff --git a/iguana/exchanges/LP_stats.c b/iguana/exchanges/LP_stats.c index 52e9bbf8c..20621d40c 100644 --- a/iguana/exchanges/LP_stats.c +++ b/iguana/exchanges/LP_stats.c @@ -240,51 +240,51 @@ int32_t LP_dPoWheight(struct iguana_info *coin) // get dPoW protected height return(coin->notarized); } -int32_t LP_finished_lastheight(struct LP_swapstats *sp,int32_t iambob) +int32_t LP_finished_lastheight(struct LP_swapstats *sp) { - int32_t ht,height = 1; struct iguana_info *coin; - if ( (coin= LP_coinfind(iambob != 0 ? sp->Q.srccoin : sp->Q.destcoin)) != 0 ) + int32_t ht,height = 1; struct iguana_info *bob,*alice; + if ( (bob= LP_coinfind(sp->Q.srccoin)) != 0 && (alice= LP_coinfind(sp->Q.destcoin)) != 0 ) { - if ( iambob != 0 ) + if ( sp->bobneeds_dPoW != 0 ) { - if ( bits256_nonz(sp->bobdeposit) != 0 && (ht= LP_txheight(coin,sp->bobdeposit)) > 1 ) + if ( bits256_nonz(sp->bobdeposit) != 0 && (ht= LP_txheight(bob,sp->bobdeposit)) > 1 ) { - if ( ht > height ) - height = ht; - printf("bobdeposit.%d height.%d\n",ht,height); + if ( ht > sp->bobneeds_dPoW ) + sp->bobneeds_dPoW = ht; + printf("bobdeposit.%d height.%d\n",ht,sp->bobneeds_dPoW); } - if ( bits256_nonz(sp->bobpayment) != 0 && (ht= LP_txheight(coin,sp->bobpayment)) > 1 ) + if ( bits256_nonz(sp->bobpayment) != 0 && (ht= LP_txheight(bob,sp->bobpayment)) > 1 ) { - if ( ht > height ) - height = ht; - printf("bobpayment.%d height.%d\n",ht,height); + if ( ht > sp->bobneeds_dPoW ) + sp->bobneeds_dPoW = ht; + printf("bobpayment.%d height.%d\n",ht,sp->bobneeds_dPoW); } - if ( bits256_nonz(sp->paymentspent) != 0 && (ht= LP_txheight(coin,sp->paymentspent)) > 1 ) + if ( bits256_nonz(sp->paymentspent) != 0 && (ht= LP_txheight(bob,sp->paymentspent)) > 1 ) { - if ( ht > height ) - height = ht; - printf("paymentspent.%d height.%d\n",ht,height); + if ( ht > sp->bobneeds_dPoW ) + sp->bobneeds_dPoW = ht; + printf("paymentspent.%d height.%d\n",ht,sp->bobneeds_dPoW); } - if ( bits256_nonz(sp->depositspent) != 0 && (ht= LP_txheight(coin,sp->depositspent)) > 1 ) + if ( bits256_nonz(sp->depositspent) != 0 && (ht= LP_txheight(bob,sp->depositspent)) > 1 ) { - if ( ht > height ) - height = ht; - printf("depositspent.%d height.%d\n",ht,height); + if ( ht > sp->bobneeds_dPoW ) + sp->bobneeds_dPoW = ht; + printf("depositspent.%d height.%d\n",ht,sp->bobneeds_dPoW); } } - else + if ( sp->aliceneeds_dPoW != 0 ) { - if ( bits256_nonz(sp->alicepayment) != 0 && (ht= LP_txheight(coin,sp->alicepayment)) > 1 ) + if ( bits256_nonz(sp->alicepayment) != 0 && (ht= LP_txheight(alice,sp->alicepayment)) > 1 ) { - if ( ht > height ) - height = ht; - printf("alicepayment.%d height.%d\n",ht,height); + if ( ht > sp->aliceneeds_dPoW ) + sp->aliceneeds_dPoW = ht; + printf("alicepayment.%d height.%d\n",ht,sp->aliceneeds_dPoW); } - if ( bits256_nonz(sp->Apaymentspent) != 0 && (ht= LP_txheight(coin,sp->Apaymentspent)) > 1 ) + if ( bits256_nonz(sp->Apaymentspent) != 0 && (ht= LP_txheight(alice,sp->Apaymentspent)) > 1 ) { - if ( ht > height ) - height = ht; - printf("Apaymentspent.%d height.%d\n",ht,height); + if ( ht > sp->aliceneeds_dPoW ) + sp->aliceneeds_dPoW = ht; + printf("Apaymentspent.%d height.%d\n",ht,sp->aliceneeds_dPoW); } } } @@ -315,10 +315,7 @@ int32_t LP_swap_finished(struct LP_swapstats *sp,int32_t dPoWflag) return(1); else if ( sp->finished != 0 ) { - if ( bob->isassetchain != 0 || strcmp(sp->Q.srccoin,"KMD") == 0 ) - sp->bobneeds_dPoW = LP_finished_lastheight(sp,1); - if ( alice->isassetchain != 0 || strcmp(sp->Q.destcoin,"KMD") == 0 ) - sp->aliceneeds_dPoW = LP_finished_lastheight(sp,0); + LP_finished_lastheight(sp); if ( IAMLP == 0 ) printf("bob needs %d @ %d, alice needs %d @ %d\n",sp->bobneeds_dPoW,bob->notarized,sp->aliceneeds_dPoW,alice->notarized); } From 11da38de0e83e56399611ffb1dff4fb6b68f66d3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 3 Dec 2017 18:22:09 +0400 Subject: [PATCH 29/59] Test --- iguana/exchanges/LP_stats.c | 72 +++++++++++++++++++++++-------------- 1 file changed, 45 insertions(+), 27 deletions(-) diff --git a/iguana/exchanges/LP_stats.c b/iguana/exchanges/LP_stats.c index 20621d40c..b053ea352 100644 --- a/iguana/exchanges/LP_stats.c +++ b/iguana/exchanges/LP_stats.c @@ -242,49 +242,49 @@ int32_t LP_dPoWheight(struct iguana_info *coin) // get dPoW protected height int32_t LP_finished_lastheight(struct LP_swapstats *sp) { - int32_t ht,height = 1; struct iguana_info *bob,*alice; + int32_t ht,height = 1; struct iguana_info *bob,*alice; char str[65]; if ( (bob= LP_coinfind(sp->Q.srccoin)) != 0 && (alice= LP_coinfind(sp->Q.destcoin)) != 0 ) { if ( sp->bobneeds_dPoW != 0 ) { - if ( bits256_nonz(sp->bobdeposit) != 0 && (ht= LP_txheight(bob,sp->bobdeposit)) > 1 ) + if ( bits256_nonz(sp->bobdeposit) != 0 ) { - if ( ht > sp->bobneeds_dPoW ) + if ( (ht= LP_txheight(bob,sp->bobdeposit)) > sp->bobneeds_dPoW ) sp->bobneeds_dPoW = ht; - printf("bobdeposit.%d height.%d\n",ht,sp->bobneeds_dPoW); + printf("%s bobdeposit.%d height.%d\n",bits256_str(str,sp->bobdeposit),ht,sp->bobneeds_dPoW); } - if ( bits256_nonz(sp->bobpayment) != 0 && (ht= LP_txheight(bob,sp->bobpayment)) > 1 ) + if ( bits256_nonz(sp->bobpayment) != 0 ) { - if ( ht > sp->bobneeds_dPoW ) + if ( (ht= LP_txheight(bob,sp->bobpayment)) > sp->bobneeds_dPoW ) sp->bobneeds_dPoW = ht; - printf("bobpayment.%d height.%d\n",ht,sp->bobneeds_dPoW); + printf("%s bobpayment.%d height.%d\n",bits256_str(str,sp->bobpayment),ht,sp->bobneeds_dPoW); } - if ( bits256_nonz(sp->paymentspent) != 0 && (ht= LP_txheight(bob,sp->paymentspent)) > 1 ) + if ( bits256_nonz(sp->paymentspent) != 0 ) { - if ( ht > sp->bobneeds_dPoW ) + if ( (ht= LP_txheight(bob,sp->paymentspent)) > sp->bobneeds_dPoW ) sp->bobneeds_dPoW = ht; - printf("paymentspent.%d height.%d\n",ht,sp->bobneeds_dPoW); + printf("%s paymentspent.%d height.%d\n",bits256_str(str,sp->paymentspent),ht,sp->bobneeds_dPoW); } - if ( bits256_nonz(sp->depositspent) != 0 && (ht= LP_txheight(bob,sp->depositspent)) > 1 ) + if ( bits256_nonz(sp->depositspent) != 0 ) { - if ( ht > sp->bobneeds_dPoW ) + if ( (ht= LP_txheight(bob,sp->depositspent)) > sp->bobneeds_dPoW ) sp->bobneeds_dPoW = ht; - printf("depositspent.%d height.%d\n",ht,sp->bobneeds_dPoW); + printf("%s depositspent.%d height.%d\n",bits256_str(str,sp->depositspent),ht,sp->bobneeds_dPoW); } } if ( sp->aliceneeds_dPoW != 0 ) { - if ( bits256_nonz(sp->alicepayment) != 0 && (ht= LP_txheight(alice,sp->alicepayment)) > 1 ) + if ( bits256_nonz(sp->alicepayment) != 0 ) { - if ( ht > sp->aliceneeds_dPoW ) + if ( (ht= LP_txheight(alice,sp->alicepayment)) > sp->aliceneeds_dPoW ) sp->aliceneeds_dPoW = ht; - printf("alicepayment.%d height.%d\n",ht,sp->aliceneeds_dPoW); + printf("%s alicepayment.%d height.%d\n",bits256_str(str,sp->alicepayment),ht,sp->aliceneeds_dPoW); } - if ( bits256_nonz(sp->Apaymentspent) != 0 && (ht= LP_txheight(alice,sp->Apaymentspent)) > 1 ) + if ( bits256_nonz(sp->Apaymentspent) != 0 ) { - if ( ht > sp->aliceneeds_dPoW ) + if ( (ht= LP_txheight(alice,sp->Apaymentspent)) > sp->aliceneeds_dPoW ) sp->aliceneeds_dPoW = ht; - printf("Apaymentspent.%d height.%d\n",ht,sp->aliceneeds_dPoW); + printf("%s Apaymentspent.%d height.%d\n",bits256_str(str,sp->Apaymentspent),ht,sp->aliceneeds_dPoW); } } } @@ -512,7 +512,7 @@ cJSON *LP_swapstats_json(struct LP_swapstats *sp) char *LP_swapstatus_recv(cJSON *argjson) { - struct LP_swapstats *sp; int32_t methodind; bits256 txid; + struct LP_swapstats *sp; int32_t methodind; bits256 txid; char str[65]; if ( (sp= LP_swapstats_find(j64bits(argjson,"aliceid"))) != 0 ) { if ( IAMLP == 0 ) @@ -526,23 +526,41 @@ char *LP_swapstatus_recv(cJSON *argjson) sp->finished = juint(argjson,"finished"); sp->expired = juint(argjson,"expired"); txid = jbits256(argjson,"bobdeposit"); - if ( bits256_nonz(txid) != 0 ) + if ( bits256_nonz(txid) != 0 && bits256_nonz(sp->bobdeposit) == 0 ) + { sp->bobdeposit = txid; + printf("set aliceid.%llu bobdeposit %s\n",(long long)sp->aliceid,bits256_str(str,txid)); + } txid = jbits256(argjson,"alicepayment"); - if ( bits256_nonz(txid) != 0 ) + if ( bits256_nonz(txid) != 0 && bits256_nonz(sp->alicepayment) == 0 ) + { sp->alicepayment = txid; + printf("set aliceid.%llu alicepayment %s\n",(long long)sp->aliceid,bits256_str(str,txid)); + } txid = jbits256(argjson,"bobpayment"); - if ( bits256_nonz(txid) != 0 ) + if ( bits256_nonz(txid) != 0 && bits256_nonz(sp->bobpayment) == 0 ) + { sp->bobpayment = txid; + printf("set aliceid.%llu bobpayment %s\n",(long long)sp->aliceid,bits256_str(str,txid)); + } txid = jbits256(argjson,"paymentspent"); - if ( bits256_nonz(txid) != 0 ) + if ( bits256_nonz(txid) != 0 && bits256_nonz(sp->paymentspent) == 0 ) + { sp->paymentspent = txid; + printf("set aliceid.%llu paymentspent %s\n",(long long)sp->aliceid,bits256_str(str,txid)); + } txid = jbits256(argjson,"Apaymentspent"); - if ( bits256_nonz(txid) != 0 ) - sp->Apaymentspent = txid; + if ( bits256_nonz(txid) != 0 && bits256_nonz(sp->Apaymentspent) == 0 ) + { + sp->Apaymentspent = txid; + printf("set aliceid.%llu Apaymentspent %s\n",(long long)sp->aliceid,bits256_str(str,txid)); + } txid = jbits256(argjson,"depositspent"); - if ( bits256_nonz(txid) != 0 ) + if ( bits256_nonz(txid) != 0 && bits256_nonz(sp->depositspent) == 0 ) + { sp->depositspent = txid; + printf("set aliceid.%llu depositspent %s\n",(long long)sp->aliceid,bits256_str(str,txid)); + } } } return(clonestr("{\"result\":\"success\"}")); From f00f9247b8663af78c477da4680b2620d2b14fad Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 3 Dec 2017 18:27:37 +0400 Subject: [PATCH 30/59] Test --- iguana/exchanges/LP_rpc.c | 2 +- iguana/exchanges/LP_stats.c | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/iguana/exchanges/LP_rpc.c b/iguana/exchanges/LP_rpc.c index 169192f54..d84369890 100644 --- a/iguana/exchanges/LP_rpc.c +++ b/iguana/exchanges/LP_rpc.c @@ -52,7 +52,7 @@ cJSON *bitcoin_json(struct iguana_info *coin,char *method,char *params) //printf("issue.(%s, %s, %s, %s, %s)\n",coin->symbol,coin->serverport,coin->userpass,method,params); if ( coin->electrum != 0 && (strcmp(method,"getblock") == 0 || strcmp(method,"paxprice") == 0 || strcmp(method,"getrawmempool") == 0) ) return(cJSON_Parse("{\"error\":\"illegal electrum call\"}")); - if ( coin->inactive == 0 || strcmp(method,"importprivkey") == 0 || strcmp(method,"validateaddress") == 0 ) + if ( coin->inactive == 0 || strcmp(method,"importprivkey") == 0 || strcmp(method,"validateaddress") == 0 || strcmp(method,"getrawtransaction") == 0 || strcmp(method,"getblock") == 0 || strcmp(method,"getinfo") == 0 ) { if ( coin->electrum == 0 ) { diff --git a/iguana/exchanges/LP_stats.c b/iguana/exchanges/LP_stats.c index b053ea352..5cc3fdb8a 100644 --- a/iguana/exchanges/LP_stats.c +++ b/iguana/exchanges/LP_stats.c @@ -242,7 +242,7 @@ int32_t LP_dPoWheight(struct iguana_info *coin) // get dPoW protected height int32_t LP_finished_lastheight(struct LP_swapstats *sp) { - int32_t ht,height = 1; struct iguana_info *bob,*alice; char str[65]; + int32_t ht,height = 1; struct iguana_info *bob,*alice; //char str[65]; if ( (bob= LP_coinfind(sp->Q.srccoin)) != 0 && (alice= LP_coinfind(sp->Q.destcoin)) != 0 ) { if ( sp->bobneeds_dPoW != 0 ) @@ -251,25 +251,25 @@ int32_t LP_finished_lastheight(struct LP_swapstats *sp) { if ( (ht= LP_txheight(bob,sp->bobdeposit)) > sp->bobneeds_dPoW ) sp->bobneeds_dPoW = ht; - printf("%s bobdeposit.%d height.%d\n",bits256_str(str,sp->bobdeposit),ht,sp->bobneeds_dPoW); + //printf("%s bobdeposit.%d height.%d\n",bits256_str(str,sp->bobdeposit),ht,sp->bobneeds_dPoW); } if ( bits256_nonz(sp->bobpayment) != 0 ) { if ( (ht= LP_txheight(bob,sp->bobpayment)) > sp->bobneeds_dPoW ) sp->bobneeds_dPoW = ht; - printf("%s bobpayment.%d height.%d\n",bits256_str(str,sp->bobpayment),ht,sp->bobneeds_dPoW); + //printf("%s bobpayment.%d height.%d\n",bits256_str(str,sp->bobpayment),ht,sp->bobneeds_dPoW); } if ( bits256_nonz(sp->paymentspent) != 0 ) { if ( (ht= LP_txheight(bob,sp->paymentspent)) > sp->bobneeds_dPoW ) sp->bobneeds_dPoW = ht; - printf("%s paymentspent.%d height.%d\n",bits256_str(str,sp->paymentspent),ht,sp->bobneeds_dPoW); + //printf("%s paymentspent.%d height.%d\n",bits256_str(str,sp->paymentspent),ht,sp->bobneeds_dPoW); } if ( bits256_nonz(sp->depositspent) != 0 ) { if ( (ht= LP_txheight(bob,sp->depositspent)) > sp->bobneeds_dPoW ) sp->bobneeds_dPoW = ht; - printf("%s depositspent.%d height.%d\n",bits256_str(str,sp->depositspent),ht,sp->bobneeds_dPoW); + //printf("%s depositspent.%d height.%d\n",bits256_str(str,sp->depositspent),ht,sp->bobneeds_dPoW); } } if ( sp->aliceneeds_dPoW != 0 ) @@ -278,13 +278,13 @@ int32_t LP_finished_lastheight(struct LP_swapstats *sp) { if ( (ht= LP_txheight(alice,sp->alicepayment)) > sp->aliceneeds_dPoW ) sp->aliceneeds_dPoW = ht; - printf("%s alicepayment.%d height.%d\n",bits256_str(str,sp->alicepayment),ht,sp->aliceneeds_dPoW); + //printf("%s alicepayment.%d height.%d\n",bits256_str(str,sp->alicepayment),ht,sp->aliceneeds_dPoW); } if ( bits256_nonz(sp->Apaymentspent) != 0 ) { if ( (ht= LP_txheight(alice,sp->Apaymentspent)) > sp->aliceneeds_dPoW ) sp->aliceneeds_dPoW = ht; - printf("%s Apaymentspent.%d height.%d\n",bits256_str(str,sp->Apaymentspent),ht,sp->aliceneeds_dPoW); + //printf("%s Apaymentspent.%d height.%d\n",bits256_str(str,sp->Apaymentspent),ht,sp->aliceneeds_dPoW); } } } From 96c9018ef0637fdc1a960ccd5f990be238a05ee4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 3 Dec 2017 18:31:34 +0400 Subject: [PATCH 31/59] Test --- iguana/exchanges/LP_stats.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_stats.c b/iguana/exchanges/LP_stats.c index 5cc3fdb8a..5476f8267 100644 --- a/iguana/exchanges/LP_stats.c +++ b/iguana/exchanges/LP_stats.c @@ -316,7 +316,7 @@ int32_t LP_swap_finished(struct LP_swapstats *sp,int32_t dPoWflag) else if ( sp->finished != 0 ) { LP_finished_lastheight(sp); - if ( IAMLP == 0 ) + if ( 0 && IAMLP == 0 ) printf("bob needs %d @ %d, alice needs %d @ %d\n",sp->bobneeds_dPoW,bob->notarized,sp->aliceneeds_dPoW,alice->notarized); } if ( (sp->bobneeds_dPoW == 0 || (sp->bobneeds_dPoW > 1 && bob->notarized >= sp->bobneeds_dPoW)) && (sp->aliceneeds_dPoW == 0 || (sp->aliceneeds_dPoW > 1 && alice->notarized >= sp->aliceneeds_dPoW)) ) @@ -515,7 +515,7 @@ char *LP_swapstatus_recv(cJSON *argjson) struct LP_swapstats *sp; int32_t methodind; bits256 txid; char str[65]; if ( (sp= LP_swapstats_find(j64bits(argjson,"aliceid"))) != 0 ) { - if ( IAMLP == 0 ) + if ( 0 && IAMLP == 0 ) printf("swapstatus.(%s)\n",jprint(argjson,0)); sp->lasttime = (uint32_t)time(NULL); if ( (methodind= jint(argjson,"ind")) > sp->methodind && methodind < sizeof(LP_stats_methods)/sizeof(*LP_stats_methods) ) From 1c1a622741da10c3133cde83ae5f43f4480c815d Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 3 Dec 2017 18:44:54 +0400 Subject: [PATCH 32/59] Test --- iguana/exchanges/LP_include.h | 1 + iguana/exchanges/LP_stats.c | 51 +++++++++++++++++------------------ 2 files changed, 25 insertions(+), 27 deletions(-) diff --git a/iguana/exchanges/LP_include.h b/iguana/exchanges/LP_include.h index 7b78ed2bf..0f7a17e7e 100644 --- a/iguana/exchanges/LP_include.h +++ b/iguana/exchanges/LP_include.h @@ -402,6 +402,7 @@ struct LP_swapstats UT_hash_handle hh; struct LP_quoteinfo Q; bits256 bobdeposit,alicepayment,bobpayment,paymentspent,Apaymentspent,depositspent; + int32_t bobdeposit_ht,alicepayment_ht,bobpayment_ht,paymentspent_ht,Apaymentspent_ht,depositspent_ht; double qprice; uint64_t aliceid; int32_t bobneeds_dPoW,aliceneeds_dPoW; diff --git a/iguana/exchanges/LP_stats.c b/iguana/exchanges/LP_stats.c index 5476f8267..b8cac3d38 100644 --- a/iguana/exchanges/LP_stats.c +++ b/iguana/exchanges/LP_stats.c @@ -242,48 +242,48 @@ int32_t LP_dPoWheight(struct iguana_info *coin) // get dPoW protected height int32_t LP_finished_lastheight(struct LP_swapstats *sp) { - int32_t ht,height = 1; struct iguana_info *bob,*alice; //char str[65]; + int32_t height = 1; struct iguana_info *bob,*alice; //char str[65]; if ( (bob= LP_coinfind(sp->Q.srccoin)) != 0 && (alice= LP_coinfind(sp->Q.destcoin)) != 0 ) { if ( sp->bobneeds_dPoW != 0 ) { - if ( bits256_nonz(sp->bobdeposit) != 0 ) + if ( bits256_nonz(sp->bobdeposit) != 0 && sp->bobdeposit_ht == 0 ) { - if ( (ht= LP_txheight(bob,sp->bobdeposit)) > sp->bobneeds_dPoW ) - sp->bobneeds_dPoW = ht; + if ( (sp->bobdeposit_ht= LP_txheight(bob,sp->bobdeposit)) > sp->bobneeds_dPoW ) + sp->bobneeds_dPoW = sp->bobdeposit_ht; //printf("%s bobdeposit.%d height.%d\n",bits256_str(str,sp->bobdeposit),ht,sp->bobneeds_dPoW); } - if ( bits256_nonz(sp->bobpayment) != 0 ) + if ( bits256_nonz(sp->bobpayment) != 0 && sp->bobpayment_ht == 0 ) { - if ( (ht= LP_txheight(bob,sp->bobpayment)) > sp->bobneeds_dPoW ) - sp->bobneeds_dPoW = ht; + if ( (sp->bobpayment_ht= LP_txheight(bob,sp->bobpayment)) > sp->bobneeds_dPoW ) + sp->bobneeds_dPoW = sp->bobpayment_ht; //printf("%s bobpayment.%d height.%d\n",bits256_str(str,sp->bobpayment),ht,sp->bobneeds_dPoW); } - if ( bits256_nonz(sp->paymentspent) != 0 ) + if ( bits256_nonz(sp->paymentspent) != 0 && sp->paymentspent_ht == 0 ) { - if ( (ht= LP_txheight(bob,sp->paymentspent)) > sp->bobneeds_dPoW ) - sp->bobneeds_dPoW = ht; + if ( (sp->paymentspent_ht= LP_txheight(bob,sp->paymentspent)) > sp->bobneeds_dPoW ) + sp->bobneeds_dPoW = sp->paymentspent_ht; //printf("%s paymentspent.%d height.%d\n",bits256_str(str,sp->paymentspent),ht,sp->bobneeds_dPoW); } - if ( bits256_nonz(sp->depositspent) != 0 ) + if ( bits256_nonz(sp->depositspent) != 0 && sp->depositspent_ht == 0 ) { - if ( (ht= LP_txheight(bob,sp->depositspent)) > sp->bobneeds_dPoW ) - sp->bobneeds_dPoW = ht; + if ( (sp->depositspent_ht= LP_txheight(bob,sp->depositspent)) > sp->bobneeds_dPoW ) + sp->bobneeds_dPoW = sp->depositspent_ht; //printf("%s depositspent.%d height.%d\n",bits256_str(str,sp->depositspent),ht,sp->bobneeds_dPoW); } } if ( sp->aliceneeds_dPoW != 0 ) { - if ( bits256_nonz(sp->alicepayment) != 0 ) + if ( bits256_nonz(sp->alicepayment) != 0 && sp->alicepayment_ht == 0 ) { - if ( (ht= LP_txheight(alice,sp->alicepayment)) > sp->aliceneeds_dPoW ) - sp->aliceneeds_dPoW = ht; + if ( (sp->alicepayment_ht= LP_txheight(alice,sp->alicepayment)) > sp->aliceneeds_dPoW ) + sp->aliceneeds_dPoW = sp->alicepayment_ht; //printf("%s alicepayment.%d height.%d\n",bits256_str(str,sp->alicepayment),ht,sp->aliceneeds_dPoW); } - if ( bits256_nonz(sp->Apaymentspent) != 0 ) + if ( bits256_nonz(sp->Apaymentspent) != 0 && sp->Apaymentspent_ht == 0 ) { - if ( (ht= LP_txheight(alice,sp->Apaymentspent)) > sp->aliceneeds_dPoW ) - sp->aliceneeds_dPoW = ht; + if ( (sp->Apaymentspent_ht= LP_txheight(alice,sp->Apaymentspent)) > sp->aliceneeds_dPoW ) + sp->aliceneeds_dPoW = sp->Apaymentspent_ht; //printf("%s Apaymentspent.%d height.%d\n",bits256_str(str,sp->Apaymentspent),ht,sp->aliceneeds_dPoW); } } @@ -294,6 +294,10 @@ int32_t LP_finished_lastheight(struct LP_swapstats *sp) int32_t LP_swap_finished(struct LP_swapstats *sp,int32_t dPoWflag) { struct iguana_info *bob,*alice; + if ( sp->dPoWfinished != 0 || sp->expired != 0 ) + return(1); + else if ( dPoWflag == 0 && sp->finished != 0 ) + return(1); if ( (bob= LP_coinfind(sp->Q.srccoin)) == 0 ) { //printf("no bobcoin.%s\n",sp->Q.srccoin); @@ -304,16 +308,9 @@ int32_t LP_swap_finished(struct LP_swapstats *sp,int32_t dPoWflag) //printf("no alicecoin.%s\n",sp->Q.destcoin); return(0); } - if ( sp->finished == 0 ) - { - if ( sp->expired != 0 ) - return(1); - } if ( dPoWflag != 0 ) { - if ( sp->dPoWfinished != 0 ) - return(1); - else if ( sp->finished != 0 ) + if ( sp->finished != 0 ) { LP_finished_lastheight(sp); if ( 0 && IAMLP == 0 ) From 9321ab763d72c4902a4c8d03478508d120907e32 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 3 Dec 2017 18:59:53 +0400 Subject: [PATCH 33/59] Test --- iguana/exchanges/LP_stats.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/iguana/exchanges/LP_stats.c b/iguana/exchanges/LP_stats.c index b8cac3d38..36fd25825 100644 --- a/iguana/exchanges/LP_stats.c +++ b/iguana/exchanges/LP_stats.c @@ -526,37 +526,37 @@ char *LP_swapstatus_recv(cJSON *argjson) if ( bits256_nonz(txid) != 0 && bits256_nonz(sp->bobdeposit) == 0 ) { sp->bobdeposit = txid; - printf("set aliceid.%llu bobdeposit %s\n",(long long)sp->aliceid,bits256_str(str,txid)); + //printf("set aliceid.%llu bobdeposit %s\n",(long long)sp->aliceid,bits256_str(str,txid)); } txid = jbits256(argjson,"alicepayment"); if ( bits256_nonz(txid) != 0 && bits256_nonz(sp->alicepayment) == 0 ) { sp->alicepayment = txid; - printf("set aliceid.%llu alicepayment %s\n",(long long)sp->aliceid,bits256_str(str,txid)); + //printf("set aliceid.%llu alicepayment %s\n",(long long)sp->aliceid,bits256_str(str,txid)); } txid = jbits256(argjson,"bobpayment"); if ( bits256_nonz(txid) != 0 && bits256_nonz(sp->bobpayment) == 0 ) { sp->bobpayment = txid; - printf("set aliceid.%llu bobpayment %s\n",(long long)sp->aliceid,bits256_str(str,txid)); + //printf("set aliceid.%llu bobpayment %s\n",(long long)sp->aliceid,bits256_str(str,txid)); } txid = jbits256(argjson,"paymentspent"); if ( bits256_nonz(txid) != 0 && bits256_nonz(sp->paymentspent) == 0 ) { sp->paymentspent = txid; - printf("set aliceid.%llu paymentspent %s\n",(long long)sp->aliceid,bits256_str(str,txid)); + //printf("set aliceid.%llu paymentspent %s\n",(long long)sp->aliceid,bits256_str(str,txid)); } txid = jbits256(argjson,"Apaymentspent"); if ( bits256_nonz(txid) != 0 && bits256_nonz(sp->Apaymentspent) == 0 ) { - sp->Apaymentspent = txid; - printf("set aliceid.%llu Apaymentspent %s\n",(long long)sp->aliceid,bits256_str(str,txid)); + sp->Apaymentspent = txid; + //printf("set aliceid.%llu Apaymentspent %s\n",(long long)sp->aliceid,bits256_str(str,txid)); } txid = jbits256(argjson,"depositspent"); if ( bits256_nonz(txid) != 0 && bits256_nonz(sp->depositspent) == 0 ) { sp->depositspent = txid; - printf("set aliceid.%llu depositspent %s\n",(long long)sp->aliceid,bits256_str(str,txid)); + //printf("set aliceid.%llu depositspent %s\n",(long long)sp->aliceid,bits256_str(str,txid)); } } } From 2dfd937f906006337e850d41cd86fce1a9a4cc70 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 3 Dec 2017 21:10:51 +0400 Subject: [PATCH 34/59] Test --- iguana/exchanges/LP_RTmetrics.c | 2 +- iguana/exchanges/LP_commands.c | 12 ++- iguana/exchanges/LP_include.h | 2 +- iguana/exchanges/LP_instantdex.c | 12 ++- iguana/exchanges/LP_nativeDEX.c | 4 +- iguana/exchanges/LP_ordermatch.c | 4 +- iguana/exchanges/LP_prices.c | 4 +- iguana/exchanges/LP_remember.c | 29 ++++--- iguana/exchanges/LP_stats.c | 135 ++++++++++++++++++++----------- iguana/exchanges/LP_swap.c | 4 +- iguana/exchanges/LP_tradebots.c | 2 +- 11 files changed, 131 insertions(+), 79 deletions(-) diff --git a/iguana/exchanges/LP_RTmetrics.c b/iguana/exchanges/LP_RTmetrics.c index 7bbab1c38..3d37c8a2e 100644 --- a/iguana/exchanges/LP_RTmetrics.c +++ b/iguana/exchanges/LP_RTmetrics.c @@ -132,7 +132,7 @@ void LP_RTmetrics_swapsinfo(char *refbase,char *refrel,cJSON *swaps,int32_t nums quoteid = juint(item,"quoteid"); LP_RTmetrics_pendingswap(srcpub,LP_kmdvalue(base,basesatoshis)); LP_RTmetrics_pendingswap(destpub,LP_kmdvalue(rel,relsatoshis)); - if ( 0 && (retstr= basilisk_swapentry(requestid,quoteid)) != 0 ) // no need for this + if ( 0 && (retstr= basilisk_swapentry(requestid,quoteid,0)) != 0 ) // no need for this { if ( (swapjson= cJSON_Parse(retstr)) != 0 ) { diff --git a/iguana/exchanges/LP_commands.c b/iguana/exchanges/LP_commands.c index bb05f3cf3..2c9a378d5 100644 --- a/iguana/exchanges/LP_commands.c +++ b/iguana/exchanges/LP_commands.c @@ -288,13 +288,13 @@ instantdex_claim()\n\ uint32_t requestid,quoteid; if ( (requestid= juint(argjson,"requestid")) != 0 && (quoteid= juint(argjson,"quoteid")) != 0 ) { - return(basilisk_swapentry(requestid,quoteid)); + return(basilisk_swapentry(requestid,quoteid,1)); } else if ( coin[0] != 0 ) return(basilisk_swapentries(coin,0,jint(argjson,"limit"))); else if ( base[0] != 0 && rel[0] != 0 ) return(basilisk_swapentries(base,rel,jint(argjson,"limit"))); - else return(basilisk_swaplist(0,0)); + else return(basilisk_swaplist(0,0,0)); } else if ( strcmp(method,"dynamictrust") == 0 ) { @@ -603,14 +603,10 @@ instantdex_claim()\n\ } argjson = reqjson; } - if ( strcmp(method,"gettradestatus") == 0 ) - retstr = clonestr("{\"result\":\"success\"}"); } else { - if ( strcmp(method,"gettradestatus") == 0 ) - return(LP_gettradestatus(j64bits(argjson,"aliceid"))); - else if ( strcmp(method,"tradesarray") == 0 ) + if ( strcmp(method,"tradesarray") == 0 ) { return(jprint(LP_tradesarray(base,rel,juint(argjson,"starttime"),juint(argjson,"endtime"),jint(argjson,"timescale")),1)); } @@ -618,6 +614,8 @@ instantdex_claim()\n\ // received response if ( strcmp(method,"swapstatus") == 0 ) return(LP_swapstatus_recv(argjson)); + else if ( strcmp(method,"gettradestatus") == 0 ) + return(LP_gettradestatus(j64bits(argjson,"aliceid"),juint(argjson,"requestid"),juint(argjson,"quoteid"))); else if ( strcmp(method,"postprice") == 0 ) return(LP_postprice_recv(argjson)); else if ( strcmp(method,"uitem") == 0 ) diff --git a/iguana/exchanges/LP_include.h b/iguana/exchanges/LP_include.h index 0f7a17e7e..d6b484d05 100644 --- a/iguana/exchanges/LP_include.h +++ b/iguana/exchanges/LP_include.h @@ -516,7 +516,7 @@ cJSON *LP_transactioninit(struct iguana_info *coin,bits256 txid,int32_t iter,cJS int32_t LP_mempoolscan(char *symbol,bits256 searchtxid); int32_t LP_txheight(struct iguana_info *coin,bits256 txid); int32_t LP_numpeers(); -char *basilisk_swapentry(uint32_t requestid,uint32_t quoteid); +char *basilisk_swapentry(uint32_t requestid,uint32_t quoteid,int32_t forceflag); int64_t LP_KMDvalue(struct iguana_info *coin,int64_t balance); int32_t LP_address_utxoadd(uint32_t timestamp,char *debug,struct iguana_info *coin,char *coinaddr,bits256 txid,int32_t vout,uint64_t value,int32_t height,int32_t spendheight); void LP_smartutxos_push(struct iguana_info *coin); diff --git a/iguana/exchanges/LP_instantdex.c b/iguana/exchanges/LP_instantdex.c index 6e2b9f328..176c4abd0 100644 --- a/iguana/exchanges/LP_instantdex.c +++ b/iguana/exchanges/LP_instantdex.c @@ -447,7 +447,7 @@ int64_t LP_myzcredits() cJSON *LP_swapstats_item(struct LP_swapstats *sp,int32_t iambob) { - struct iguana_info *bob,*alice; int32_t flag = 0; cJSON *item; char *retstr; + struct iguana_info *bob,*alice; int32_t flag = 0; bits256 zero; cJSON *item,*reqjson; item = cJSON_CreateObject(); jaddnum(item,"iambob",iambob); jaddnum(item,"aliceid",sp->aliceid); @@ -475,8 +475,14 @@ cJSON *LP_swapstats_item(struct LP_swapstats *sp,int32_t iambob) if ( sp->aliceneeds_dPoW == 1 ) flag = 1; } - if ( flag != 0 && (retstr= LP_gettradestatus(sp->aliceid)) != 0 ) - free(retstr); + if ( flag != 0 ) + { + reqjson = cJSON_CreateObject(); + jaddstr(reqjson,"method","gettradestatus"); + jadd64bits(reqjson,"aliceid",sp->aliceid); + memset(zero.bytes,0,sizeof(zero)); + LP_reserved_msg(0,"","",zero,jprint(reqjson,1)); + } } return(item); } diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 69e83e6d2..cf09af1b6 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -816,7 +816,7 @@ void LP_swapsloop(void *ctx) while ( 1 ) { LP_millistats_update(&LP_swapsloop_stats); - if ( (retstr= basilisk_swapentry(0,0)) != 0 ) + if ( (retstr= basilisk_swapentry(0,0,0)) != 0 ) free(retstr); sleep(600); } @@ -1319,7 +1319,7 @@ void LP_fromjs_iter() { LP_notify_pubkeys(ctx,LP_mypubsock); LP_privkey_updates(ctx,LP_mypubsock,0); - if ( (retstr= basilisk_swapentry(0,0)) != 0 ) + if ( (retstr= basilisk_swapentry(0,0,0)) != 0 ) free(retstr); } } diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index fa911b330..85e4f5088 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -85,7 +85,7 @@ uint64_t LP_txfeecalc(struct iguana_info *coin,uint64_t txfee,int32_t txlen) return(txfee); } -double LP_qprice_calc(int64_t *destsatoshisp,int64_t *satoshisp,double price,uint64_t b_satoshis,uint64_t txfee,uint64_t a_value,uint64_t maxdestsatoshis,uint64_t desttxfee) +/*double LP_qprice_calc(int64_t *destsatoshisp,int64_t *satoshisp,double price,uint64_t b_satoshis,uint64_t txfee,uint64_t a_value,uint64_t maxdestsatoshis,uint64_t desttxfee) { uint64_t destsatoshis,satoshis; a_value -= (desttxfee + 1); @@ -100,7 +100,7 @@ double LP_qprice_calc(int64_t *destsatoshisp,int64_t *satoshisp,double price,uin if ( satoshis > 0 ) return((double)destsatoshis / satoshis); else return(0.); -} +}*/ int32_t LP_quote_checkmempool(struct LP_quoteinfo *qp,struct LP_utxoinfo *autxo,struct LP_utxoinfo *butxo) { diff --git a/iguana/exchanges/LP_prices.c b/iguana/exchanges/LP_prices.c index 8c23d87fb..16efbe735 100644 --- a/iguana/exchanges/LP_prices.c +++ b/iguana/exchanges/LP_prices.c @@ -408,9 +408,9 @@ double LP_pricecache(struct LP_quoteinfo *qp,char *base,char *rel,bits256 txid,i { if ( qp != 0 ) (*qp) = ptr->Q; - if ( ptr->price == 0. && ptr->Q.satoshis != 0 ) + if ( ptr->price == 0. && ptr->Q.satoshis > ptr->Q.txfee ) { - ptr->price = (double)ptr->Q.destsatoshis / ptr->Q.satoshis; + ptr->price = (double)ptr->Q.destsatoshis / (ptr->Q.satoshis - ptr->Q.txfee); if ( LP_pricevalid(ptr->price) <= 0 ) ptr->price = 0.; printf("LP_pricecache: set %s/%s ptr->price %.8f\n",base,rel,ptr->price); diff --git a/iguana/exchanges/LP_remember.c b/iguana/exchanges/LP_remember.c index 0b8264214..b054f9fdb 100644 --- a/iguana/exchanges/LP_remember.c +++ b/iguana/exchanges/LP_remember.c @@ -529,7 +529,7 @@ cJSON *LP_swap_json(struct LP_swap_remember *rswap) return(item); } -int32_t LP_rswap_init(struct LP_swap_remember *rswap,uint32_t requestid,uint32_t quoteid) +int32_t LP_rswap_init(struct LP_swap_remember *rswap,uint32_t requestid,uint32_t quoteid,int32_t forceflag) { char fname[1024],*fstr,*secretstr,*srcstr,*deststr,*dest33,*txname; long fsize; cJSON *item,*txobj,*array; bits256 privkey; struct iguana_info *coin; uint32_t r,q; int32_t i,j,n; uint8_t other33[33]; memset(rswap,0,sizeof(*rswap)); @@ -664,6 +664,8 @@ int32_t LP_rswap_init(struct LP_swap_remember *rswap,uint32_t requestid,uint32_t } rswap->origfinishedflag = basilisk_swap_isfinished(rswap->iambob,rswap->txids,rswap->sentflags,rswap->paymentspent,rswap->Apaymentspent,rswap->depositspent); rswap->finishedflag = rswap->origfinishedflag; + if ( forceflag != 0 ) + rswap->finishedflag = rswap->origfinishedflag = 0; free(fstr); } return(rswap->iambob); @@ -694,7 +696,7 @@ int32_t LP_refht_update(char *symbol,bits256 txid) return(0); } -int32_t LP_swap_load(struct LP_swap_remember *rswap) +int32_t LP_swap_load(struct LP_swap_remember *rswap,int32_t forceflag) { 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; @@ -704,7 +706,8 @@ int32_t LP_swap_load(struct LP_swap_remember *rswap) if ( (fileobj= cJSON_Parse(fstr)) != 0 ) { rswap->finishtime = juint(fileobj,"finishtime"); - rswap->origfinishedflag = rswap->finishedflag = 1; + if ( forceflag == 0 ) + rswap->origfinishedflag = rswap->finishedflag = 1; free_json(fileobj); } free(fstr); @@ -872,16 +875,16 @@ int32_t LP_spends_set(struct LP_swap_remember *rswap) return(numspent); } -cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requestid,uint32_t quoteid) +cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requestid,uint32_t quoteid,int32_t forceflag) { 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,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 ) + if ( (rswap.iambob= LP_rswap_init(&rswap,requestid,quoteid,forceflag)) < 0 ) return(cJSON_Parse("{\"error\":\"couldnt initialize rswap, are all coins active?\"}")); decode_hex(deadtxid.bytes,32,"deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef"); - LP_swap_load(&rswap); + LP_swap_load(&rswap,forceflag); memset(zero.bytes,0,sizeof(zero)); otheraddr[0] = 0; srcAdest = srcBdest = destAdest = destBdest = 0; @@ -1185,7 +1188,7 @@ cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requesti return(item); } -char *basilisk_swaplist(uint32_t origrequestid,uint32_t origquoteid) +char *basilisk_swaplist(uint32_t origrequestid,uint32_t origquoteid,int32_t forceflag) { uint64_t ridqids[4096],ridqid; char fname[512]; FILE *fp; cJSON *item,*retjson,*array,*totalsobj; uint32_t r,q,quoteid,requestid; int64_t KMDtotals[LP_MAXPRICEINFOS],BTCtotals[LP_MAXPRICEINFOS],Btotal,Ktotal; int32_t i,j,count=0; portable_mutex_lock(&LP_swaplistmutex); @@ -1198,7 +1201,7 @@ char *basilisk_swaplist(uint32_t origrequestid,uint32_t origquoteid) if ( origrequestid != 0 && origquoteid != 0 ) { //printf("orig req.%u q.%u\n",origrequestid,origquoteid); - if ( (item= basilisk_remember(KMDtotals,BTCtotals,origrequestid,origquoteid)) != 0 ) + if ( (item= basilisk_remember(KMDtotals,BTCtotals,origrequestid,origquoteid,forceflag)) != 0 ) jaddi(array,item); //printf("got.(%s)\n",jprint(item,0)); } @@ -1237,7 +1240,7 @@ char *basilisk_swaplist(uint32_t origrequestid,uint32_t origquoteid) { if ( count < sizeof(ridqids)/sizeof(*ridqids) ) ridqids[count++] = ridqid; - if ( (item= basilisk_remember(KMDtotals,BTCtotals,requestid,quoteid)) != 0 ) + if ( (item= basilisk_remember(KMDtotals,BTCtotals,requestid,quoteid,0)) != 0 ) jaddi(array,item); } } @@ -1270,12 +1273,12 @@ char *basilisk_swaplist(uint32_t origrequestid,uint32_t origquoteid) return(jprint(retjson,1)); } -char *basilisk_swapentry(uint32_t requestid,uint32_t quoteid) +char *basilisk_swapentry(uint32_t requestid,uint32_t quoteid,int32_t forceflag) { cJSON *item; int64_t KMDtotals[LP_MAXPRICEINFOS],BTCtotals[LP_MAXPRICEINFOS]; memset(KMDtotals,0,sizeof(KMDtotals)); memset(BTCtotals,0,sizeof(BTCtotals)); - if ( (item= basilisk_remember(KMDtotals,BTCtotals,requestid,quoteid)) != 0 ) + if ( (item= basilisk_remember(KMDtotals,BTCtotals,requestid,quoteid,forceflag)) != 0 ) return(jprint(item,1)); else return(clonestr("{\"error\":\"cant find requestid-quoteid\"}")); } @@ -1365,7 +1368,7 @@ char *basilisk_swapentries(char *refbase,char *refrel,int32_t limit) limit = 10; memset(ridqids,0,sizeof(ridqids)); retarray = cJSON_CreateArray(); - if ( (liststr= basilisk_swaplist(0,0)) != 0 ) + if ( (liststr= basilisk_swaplist(0,0,0)) != 0 ) { //printf("swapentry.(%s)\n",liststr); if ( (retjson= cJSON_Parse(liststr)) != 0 ) @@ -1408,7 +1411,7 @@ char *basilisk_swapentries(char *refbase,char *refrel,int32_t limit) //printf("j.%d count.%d %u %u ridqid.%16llx\n",j,count,requestid,quoteid,(long long)ridqid); if ( j == count ) { - if ( (retstr2= basilisk_swapentry(requestid,quoteid)) != 0 ) + if ( (retstr2= basilisk_swapentry(requestid,quoteid,0)) != 0 ) { if ( (swapjson= cJSON_Parse(retstr2)) != 0 ) { diff --git a/iguana/exchanges/LP_stats.c b/iguana/exchanges/LP_stats.c index 36fd25825..7d7ee1fba 100644 --- a/iguana/exchanges/LP_stats.c +++ b/iguana/exchanges/LP_stats.c @@ -24,6 +24,7 @@ struct LP_swapstats *LP_swapstats,*LP_RTstats; int32_t LP_statslog_parsequote(char *method,cJSON *lineobj); char *LP_stats_methods[] = { "unknown", "request", "reserved", "connect", "connected", "tradestatus" }; +#define LP_TRADESTATUS_METHODIND 5 static uint32_t LP_requests,LP_reserveds,LP_connects,LP_connecteds,LP_tradestatuses,LP_parse_errors,LP_unknowns,LP_duplicates,LP_aliceids; @@ -325,10 +326,51 @@ int32_t LP_swap_finished(struct LP_swapstats *sp,int32_t dPoWflag) return(0); } +struct LP_swapstats *LP_swapstats_create(uint64_t aliceid,int32_t RTflag,struct LP_quoteinfo *qp,double qprice,int32_t methodind) +{ + struct LP_pubswap *ptr; struct iguana_info *alice,*bob; struct LP_pubkey_info *pubp; char *base,*rel; struct LP_swapstats *sp = 0; + base = qp->srccoin, rel = qp->destcoin; + if ( (sp= LP_swapstats_add(aliceid,RTflag)) != 0 ) + { + sp->Q = *qp; + sp->qprice = qprice; + sp->methodind = methodind; + sp->ind = LP_aliceids++; + sp->lasttime = (uint32_t)time(NULL); + if ( sp->lasttime > sp->Q.timestamp+LP_atomic_locktime(base,rel)*2 ) + sp->expired = sp->lasttime; + else + { + if ( (alice= LP_coinfind(rel)) != 0 && (alice->isassetchain != 0 || strcmp("KMD",alice->symbol) == 0) ) + sp->aliceneeds_dPoW = 1; + if ( (bob= LP_coinfind(rel)) != 0 && (bob->isassetchain != 0 || strcmp(bob->symbol,"KMD") == 0) ) + sp->bobneeds_dPoW = 1; + } + strcpy(sp->bobgui,"nogui"); + strcpy(sp->alicegui,"nogui"); + if ( LP_swap_finished(sp,1) == 0 ) //sp->finished == 0 && sp->expired == 0 ) + { + if ( (pubp= LP_pubkeyadd(qp->srchash)) != 0 ) + { + ptr = calloc(1,sizeof(*ptr)); + ptr->swap = sp; + DL_APPEND(pubp->bobswaps,ptr); + } + if ( (pubp= LP_pubkeyadd(qp->desthash)) != 0 ) + { + ptr = calloc(1,sizeof(*ptr)); + ptr->swap = sp; + DL_APPEND(pubp->aliceswaps,ptr); + } + } + } else printf("unexpected LP_swapstats_add failure\n"); + return(sp); +} + int32_t LP_statslog_parsequote(char *method,cJSON *lineobj) { static uint32_t unexpected; - struct LP_swapstats *sp,*tmp; struct iguana_info *alice,*bob; struct LP_pubkey_info *pubp; struct LP_pubswap *ptr; double qprice; uint32_t requestid,quoteid,timestamp; int32_t i,RTflag,flag,numtrades[LP_MAXPRICEINFOS],methodind,destvout,feevout,duplicate=0; char *statusstr,*gui,*base,*rel; uint64_t aliceid,txfee,satoshis,destsatoshis; bits256 desttxid,feetxid; struct LP_quoteinfo Q; uint64_t basevols[LP_MAXPRICEINFOS],relvols[LP_MAXPRICEINFOS]; + struct LP_swapstats *sp,*tmp; double qprice; uint32_t requestid,quoteid,timestamp; int32_t i,RTflag,flag,numtrades[LP_MAXPRICEINFOS],methodind,destvout,feevout,duplicate=0; char *statusstr,*gui,*base,*rel; uint64_t aliceid,txfee,satoshis,destsatoshis; bits256 desttxid,feetxid; struct LP_quoteinfo Q; uint64_t basevols[LP_MAXPRICEINFOS],relvols[LP_MAXPRICEINFOS]; memset(numtrades,0,sizeof(numtrades)); memset(basevols,0,sizeof(basevols)); memset(relvols,0,sizeof(relvols)); @@ -423,41 +465,8 @@ int32_t LP_statslog_parsequote(char *method,cJSON *lineobj) } else { + sp = LP_swapstats_create(aliceid,RTflag,&Q,qprice,methodind); //printf("create aliceid.%llu\n",(long long)aliceid); - if ( (sp= LP_swapstats_add(aliceid,RTflag)) != 0 ) - { - sp->Q = Q; - sp->qprice = qprice; - sp->methodind = methodind; - sp->ind = LP_aliceids++; - sp->lasttime = (uint32_t)time(NULL); - if ( sp->lasttime > sp->Q.timestamp+LP_atomic_locktime(base,rel)*2 ) - sp->expired = sp->lasttime; - else - { - if ( (alice= LP_coinfind(rel)) != 0 && (alice->isassetchain != 0 || strcmp("KMD",alice->symbol) == 0) ) - sp->aliceneeds_dPoW = 1; - if ( (bob= LP_coinfind(rel)) != 0 && (bob->isassetchain != 0 || strcmp(bob->symbol,"KMD") == 0) ) - sp->bobneeds_dPoW = 1; - } - strcpy(sp->bobgui,"nogui"); - strcpy(sp->alicegui,"nogui"); - if ( LP_swap_finished(sp,1) == 0 ) //sp->finished == 0 && sp->expired == 0 ) - { - if ( (pubp= LP_pubkeyadd(sp->Q.srchash)) != 0 ) - { - ptr = calloc(1,sizeof(*ptr)); - ptr->swap = sp; - DL_APPEND(pubp->bobswaps,ptr); - } - if ( (pubp= LP_pubkeyadd(sp->Q.desthash)) != 0 ) - { - ptr = calloc(1,sizeof(*ptr)); - ptr->swap = sp; - DL_APPEND(pubp->aliceswaps,ptr); - } - } - } else printf("unexpected LP_swapstats_add failure\n"); } if ( sp != 0 ) { @@ -509,8 +518,22 @@ cJSON *LP_swapstats_json(struct LP_swapstats *sp) char *LP_swapstatus_recv(cJSON *argjson) { - struct LP_swapstats *sp; int32_t methodind; bits256 txid; char str[65]; - if ( (sp= LP_swapstats_find(j64bits(argjson,"aliceid"))) != 0 ) + struct LP_swapstats *sp; char *statusstr; uint64_t aliceid; double qprice; struct LP_quoteinfo Q; int32_t methodind,RTflag; bits256 txid; //char str[65]; + if ( (aliceid= j64bits(argjson,"aliceid")) == 0 ) + return(clonestr("{\"error\":\"LP_swapstatus_recv null aliceid\"}")); + if ( (sp= LP_swapstats_find(aliceid)) == 0 ) + { + LP_quoteparse(&Q,argjson); + if ( Q.satoshis > Q.txfee ) + return(clonestr("{\"error\":\"LP_swapstatus_recv null satoshis\"}")); + qprice = (double)Q.destsatoshis / (Q.satoshis - Q.txfee); + if ( (statusstr= jstr(argjson,"status")) != 0 && strcmp(statusstr,"finished") == 0 ) + RTflag = 0; + else RTflag = 1; + sp = LP_swapstats_create(aliceid,RTflag,&Q,qprice,LP_TRADESTATUS_METHODIND); + printf("create swapstatus from recv\n"); + } + if ( sp != 0 ) { if ( 0 && IAMLP == 0 ) printf("swapstatus.(%s)\n",jprint(argjson,0)); @@ -563,20 +586,42 @@ char *LP_swapstatus_recv(cJSON *argjson) return(clonestr("{\"result\":\"success\"}")); } -char *LP_gettradestatus(uint64_t aliceid) +char *LP_gettradestatus(uint64_t aliceid,uint32_t requestid,uint32_t quoteid) { - struct LP_swapstats *sp; cJSON *reqjson; bits256 zero; + struct LP_swapstats *sp; char *swapstr,*statusstr; cJSON *reqjson,*swapjson; bits256 zero; //printf("gettradestatus.(%llu)\n",(long long)aliceid); - if ( (sp= LP_swapstats_find(aliceid)) != 0 && time(NULL) > sp->lasttime+60 ) + if ( IAMLP != 0 ) { - if ( (reqjson= LP_swapstats_json(sp)) != 0 ) + if ( (sp= LP_swapstats_find(aliceid)) != 0 ) { - jaddstr(reqjson,"method","swapstatus"); - memset(zero.bytes,0,sizeof(zero)); - LP_reserved_msg(0,"","",zero,jprint(reqjson,1)); + if ( time(NULL) > sp->lasttime+60 ) + { + if ( (reqjson= LP_swapstats_json(sp)) != 0 ) + { + jaddstr(reqjson,"method","swapstatus"); + memset(zero.bytes,0,sizeof(zero)); + LP_reserved_msg(0,"","",zero,jprint(reqjson,1)); + } + } + return(clonestr("{\"result\":\"success\"}")); + } + } + if ( (swapstr= basilisk_swapentry(requestid,quoteid,0)) != 0 ) + { + if ( (swapjson= cJSON_Parse(swapstr)) != 0 ) + { + if ( (statusstr= jstr(swapjson,"status")) != 0 && strcmp(statusstr,"finished") == 0 ) + { + jaddstr(swapjson,"method","swapstatus"); + memset(zero.bytes,0,sizeof(zero)); + printf("send local swapstatus\n"); + LP_reserved_msg(0,"","",zero,jprint(swapjson,0)); + } + free_json(swapjson); } + free(swapstr); } - return(clonestr("{\"error\":\"cant find aliceid\"}")); + return(clonestr("{\"result\":\"success\"}")); } int32_t LP_stats_dispiter(cJSON *array,struct LP_swapstats *sp,uint32_t starttime,uint32_t endtime,char *refbase,char *refrel,char *refgui,bits256 refpubkey) diff --git a/iguana/exchanges/LP_swap.c b/iguana/exchanges/LP_swap.c index fe905c424..d03cfa668 100644 --- a/iguana/exchanges/LP_swap.c +++ b/iguana/exchanges/LP_swap.c @@ -751,7 +751,7 @@ int32_t LP_swapwait(struct basilisk_swap *swap,uint32_t requestid,uint32_t quote // sleeptime = divisor * 60; while ( time(NULL) < expiration ) { - if ( (retstr= basilisk_swapentry(requestid,quoteid)) != 0 ) + if ( (retstr= basilisk_swapentry(requestid,quoteid,1)) != 0 ) { if ( (retjson= cJSON_Parse(retstr)) != 0 ) { @@ -775,7 +775,7 @@ int32_t LP_swapwait(struct basilisk_swap *swap,uint32_t requestid,uint32_t quote { printf("\n>>>>>>>>>>>>>>>>>>>>>>>>>\nSWAP completed! %u-%u %s\n",requestid,quoteid,jprint(retjson,0)); free_json(retjson); - if ( 0 && (retstr= basilisk_swapentry(requestid,quoteid)) != 0 ) + if ( 0 && (retstr= basilisk_swapentry(requestid,quoteid,1)) != 0 ) { printf("second call.(%s)\n",retstr); free(retstr); diff --git a/iguana/exchanges/LP_tradebots.c b/iguana/exchanges/LP_tradebots.c index 7f3742304..c5f0d7d6f 100644 --- a/iguana/exchanges/LP_tradebots.c +++ b/iguana/exchanges/LP_tradebots.c @@ -43,7 +43,7 @@ struct LP_tradebot void LP_tradebot_updatestats(struct LP_tradebot *bot,struct LP_tradebot_trade *tp) { char *swapstr,*status; int32_t flag; cJSON *swapjson; - if ( (swapstr= basilisk_swapentry(tp->requestid,tp->quoteid)) != 0 ) + if ( (swapstr= basilisk_swapentry(tp->requestid,tp->quoteid,1)) != 0 ) { flag = 0; if ( (swapjson= cJSON_Parse(swapstr)) != 0 ) From 16143707cd5cdbb30664c69f9d7cf767c6814515 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 3 Dec 2017 21:15:05 +0400 Subject: [PATCH 35/59] Test --- iguana/exchanges/LP_stats.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_stats.c b/iguana/exchanges/LP_stats.c index 7d7ee1fba..c63b08957 100644 --- a/iguana/exchanges/LP_stats.c +++ b/iguana/exchanges/LP_stats.c @@ -535,7 +535,7 @@ char *LP_swapstatus_recv(cJSON *argjson) } if ( sp != 0 ) { - if ( 0 && IAMLP == 0 ) + if ( IAMLP == 0 ) printf("swapstatus.(%s)\n",jprint(argjson,0)); sp->lasttime = (uint32_t)time(NULL); if ( (methodind= jint(argjson,"ind")) > sp->methodind && methodind < sizeof(LP_stats_methods)/sizeof(*LP_stats_methods) ) @@ -589,7 +589,7 @@ char *LP_swapstatus_recv(cJSON *argjson) char *LP_gettradestatus(uint64_t aliceid,uint32_t requestid,uint32_t quoteid) { struct LP_swapstats *sp; char *swapstr,*statusstr; cJSON *reqjson,*swapjson; bits256 zero; - //printf("gettradestatus.(%llu)\n",(long long)aliceid); + printf("gettradestatus.(%llu)\n",(long long)aliceid); if ( IAMLP != 0 ) { if ( (sp= LP_swapstats_find(aliceid)) != 0 ) From 3d01e764aad396e3648f394c5d7c63255541c57f Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 3 Dec 2017 21:22:59 +0400 Subject: [PATCH 36/59] Test --- iguana/exchanges/LP_instantdex.c | 12 +++++++++++- iguana/exchanges/LP_stats.c | 12 ++++++------ 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/iguana/exchanges/LP_instantdex.c b/iguana/exchanges/LP_instantdex.c index 176c4abd0..9cbcdca45 100644 --- a/iguana/exchanges/LP_instantdex.c +++ b/iguana/exchanges/LP_instantdex.c @@ -447,7 +447,7 @@ int64_t LP_myzcredits() cJSON *LP_swapstats_item(struct LP_swapstats *sp,int32_t iambob) { - struct iguana_info *bob,*alice; int32_t flag = 0; bits256 zero; cJSON *item,*reqjson; + struct iguana_info *bob,*alice; int32_t flag = 0; char *retstr,*swapstr; bits256 zero; cJSON *item,*reqjson,*swapjson; item = cJSON_CreateObject(); jaddnum(item,"iambob",iambob); jaddnum(item,"aliceid",sp->aliceid); @@ -482,6 +482,16 @@ cJSON *LP_swapstats_item(struct LP_swapstats *sp,int32_t iambob) jadd64bits(reqjson,"aliceid",sp->aliceid); memset(zero.bytes,0,sizeof(zero)); LP_reserved_msg(0,"","",zero,jprint(reqjson,1)); + if ( (swapstr= basilisk_swapentry(sp->Q.R.requestid,sp->Q.R.quoteid,1)) != 0 ) + { + if ( (swapjson= cJSON_Parse(swapstr)) != 0 ) + { + if ( (retstr= LP_swapstatus_recv(swapjson)) != 0 ) + free(retstr); + free_json(swapjson); + } + free(swapstr); + } } } return(item); diff --git a/iguana/exchanges/LP_stats.c b/iguana/exchanges/LP_stats.c index c63b08957..cd250dcfe 100644 --- a/iguana/exchanges/LP_stats.c +++ b/iguana/exchanges/LP_stats.c @@ -518,7 +518,7 @@ cJSON *LP_swapstats_json(struct LP_swapstats *sp) char *LP_swapstatus_recv(cJSON *argjson) { - struct LP_swapstats *sp; char *statusstr; uint64_t aliceid; double qprice; struct LP_quoteinfo Q; int32_t methodind,RTflag; bits256 txid; //char str[65]; + struct LP_swapstats *sp; char *statusstr; uint64_t aliceid; double qprice; struct LP_quoteinfo Q; int32_t methodind,RTflag; bits256 txid; char str[65]; if ( (aliceid= j64bits(argjson,"aliceid")) == 0 ) return(clonestr("{\"error\":\"LP_swapstatus_recv null aliceid\"}")); if ( (sp= LP_swapstats_find(aliceid)) == 0 ) @@ -549,31 +549,31 @@ char *LP_swapstatus_recv(cJSON *argjson) if ( bits256_nonz(txid) != 0 && bits256_nonz(sp->bobdeposit) == 0 ) { sp->bobdeposit = txid; - //printf("set aliceid.%llu bobdeposit %s\n",(long long)sp->aliceid,bits256_str(str,txid)); + printf("set aliceid.%llu bobdeposit %s\n",(long long)sp->aliceid,bits256_str(str,txid)); } txid = jbits256(argjson,"alicepayment"); if ( bits256_nonz(txid) != 0 && bits256_nonz(sp->alicepayment) == 0 ) { sp->alicepayment = txid; - //printf("set aliceid.%llu alicepayment %s\n",(long long)sp->aliceid,bits256_str(str,txid)); + printf("set aliceid.%llu alicepayment %s\n",(long long)sp->aliceid,bits256_str(str,txid)); } txid = jbits256(argjson,"bobpayment"); if ( bits256_nonz(txid) != 0 && bits256_nonz(sp->bobpayment) == 0 ) { sp->bobpayment = txid; - //printf("set aliceid.%llu bobpayment %s\n",(long long)sp->aliceid,bits256_str(str,txid)); + printf("set aliceid.%llu bobpayment %s\n",(long long)sp->aliceid,bits256_str(str,txid)); } txid = jbits256(argjson,"paymentspent"); if ( bits256_nonz(txid) != 0 && bits256_nonz(sp->paymentspent) == 0 ) { sp->paymentspent = txid; - //printf("set aliceid.%llu paymentspent %s\n",(long long)sp->aliceid,bits256_str(str,txid)); + printf("set aliceid.%llu paymentspent %s\n",(long long)sp->aliceid,bits256_str(str,txid)); } txid = jbits256(argjson,"Apaymentspent"); if ( bits256_nonz(txid) != 0 && bits256_nonz(sp->Apaymentspent) == 0 ) { sp->Apaymentspent = txid; - //printf("set aliceid.%llu Apaymentspent %s\n",(long long)sp->aliceid,bits256_str(str,txid)); + printf("set aliceid.%llu Apaymentspent %s\n",(long long)sp->aliceid,bits256_str(str,txid)); } txid = jbits256(argjson,"depositspent"); if ( bits256_nonz(txid) != 0 && bits256_nonz(sp->depositspent) == 0 ) From 20e3c0ebe67a2a981ac2515059256c70a782eff8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 3 Dec 2017 21:25:49 +0400 Subject: [PATCH 37/59] Test --- iguana/exchanges/LP_stats.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/iguana/exchanges/LP_stats.c b/iguana/exchanges/LP_stats.c index cd250dcfe..77e6500da 100644 --- a/iguana/exchanges/LP_stats.c +++ b/iguana/exchanges/LP_stats.c @@ -535,7 +535,7 @@ char *LP_swapstatus_recv(cJSON *argjson) } if ( sp != 0 ) { - if ( IAMLP == 0 ) + if ( 0 && IAMLP == 0 ) printf("swapstatus.(%s)\n",jprint(argjson,0)); sp->lasttime = (uint32_t)time(NULL); if ( (methodind= jint(argjson,"ind")) > sp->methodind && methodind < sizeof(LP_stats_methods)/sizeof(*LP_stats_methods) ) @@ -549,31 +549,31 @@ char *LP_swapstatus_recv(cJSON *argjson) if ( bits256_nonz(txid) != 0 && bits256_nonz(sp->bobdeposit) == 0 ) { sp->bobdeposit = txid; - printf("set aliceid.%llu bobdeposit %s\n",(long long)sp->aliceid,bits256_str(str,txid)); + //printf("set aliceid.%llu bobdeposit %s\n",(long long)sp->aliceid,bits256_str(str,txid)); } txid = jbits256(argjson,"alicepayment"); if ( bits256_nonz(txid) != 0 && bits256_nonz(sp->alicepayment) == 0 ) { sp->alicepayment = txid; - printf("set aliceid.%llu alicepayment %s\n",(long long)sp->aliceid,bits256_str(str,txid)); + //printf("set aliceid.%llu alicepayment %s\n",(long long)sp->aliceid,bits256_str(str,txid)); } txid = jbits256(argjson,"bobpayment"); if ( bits256_nonz(txid) != 0 && bits256_nonz(sp->bobpayment) == 0 ) { sp->bobpayment = txid; - printf("set aliceid.%llu bobpayment %s\n",(long long)sp->aliceid,bits256_str(str,txid)); + //printf("set aliceid.%llu bobpayment %s\n",(long long)sp->aliceid,bits256_str(str,txid)); } txid = jbits256(argjson,"paymentspent"); if ( bits256_nonz(txid) != 0 && bits256_nonz(sp->paymentspent) == 0 ) { sp->paymentspent = txid; - printf("set aliceid.%llu paymentspent %s\n",(long long)sp->aliceid,bits256_str(str,txid)); + //printf("set aliceid.%llu paymentspent %s\n",(long long)sp->aliceid,bits256_str(str,txid)); } txid = jbits256(argjson,"Apaymentspent"); if ( bits256_nonz(txid) != 0 && bits256_nonz(sp->Apaymentspent) == 0 ) { sp->Apaymentspent = txid; - printf("set aliceid.%llu Apaymentspent %s\n",(long long)sp->aliceid,bits256_str(str,txid)); + //printf("set aliceid.%llu Apaymentspent %s\n",(long long)sp->aliceid,bits256_str(str,txid)); } txid = jbits256(argjson,"depositspent"); if ( bits256_nonz(txid) != 0 && bits256_nonz(sp->depositspent) == 0 ) From c120c3e8d13cd65585e92965d8e4b3557b21fb42 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 3 Dec 2017 21:40:35 +0400 Subject: [PATCH 38/59] Test --- iguana/exchanges/LP_instantdex.c | 4 ++-- iguana/exchanges/LP_stats.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/iguana/exchanges/LP_instantdex.c b/iguana/exchanges/LP_instantdex.c index 9cbcdca45..e89db4ccd 100644 --- a/iguana/exchanges/LP_instantdex.c +++ b/iguana/exchanges/LP_instantdex.c @@ -319,7 +319,7 @@ int64_t LP_instantdex_credit(int32_t dispflag,char *coinaddr,int64_t satoshis,in int64_t LP_instantdex_creditcalc(struct iguana_info *coin,int32_t dispflag,bits256 txid,char *refaddr) { - cJSON *txjson,*vouts,*txobj,*item; int64_t satoshis=0,amount64; int32_t weeki,numvouts; char destaddr[64],p2shaddr[64]; + cJSON *txjson,*vouts,*txobj,*item; int64_t satoshis=0,amount64; int32_t weeki,numvouts; char destaddr[64],p2shaddr[64],str[65]; if ( (txjson= LP_gettx(coin->symbol,txid,0)) != 0 ) { // vout0 deposit, vout1 botsfee, vout2 smartaddress @@ -335,7 +335,7 @@ int64_t LP_instantdex_creditcalc(struct iguana_info *coin,int32_t dispflag,bits2 weeki = (amount64 % 10000); item = jitem(vouts,0); satoshis = LP_value_extract(item,0); - //printf("%s funded %.8f weeki.%d\n",destaddr,dstr(satoshis),weeki); + printf("%s %s funded %.8f weeki.%d (%s)\n",bits256_str(str,txid),destaddr,dstr(satoshis),weeki,jprint(item,0)); if ( LP_destaddr(p2shaddr,item) == 0 ) { if ( (txobj= LP_gettxout(coin->symbol,p2shaddr,txid,0)) != 0 ) diff --git a/iguana/exchanges/LP_stats.c b/iguana/exchanges/LP_stats.c index 77e6500da..7d7ee1fba 100644 --- a/iguana/exchanges/LP_stats.c +++ b/iguana/exchanges/LP_stats.c @@ -518,7 +518,7 @@ cJSON *LP_swapstats_json(struct LP_swapstats *sp) char *LP_swapstatus_recv(cJSON *argjson) { - struct LP_swapstats *sp; char *statusstr; uint64_t aliceid; double qprice; struct LP_quoteinfo Q; int32_t methodind,RTflag; bits256 txid; char str[65]; + struct LP_swapstats *sp; char *statusstr; uint64_t aliceid; double qprice; struct LP_quoteinfo Q; int32_t methodind,RTflag; bits256 txid; //char str[65]; if ( (aliceid= j64bits(argjson,"aliceid")) == 0 ) return(clonestr("{\"error\":\"LP_swapstatus_recv null aliceid\"}")); if ( (sp= LP_swapstats_find(aliceid)) == 0 ) @@ -589,7 +589,7 @@ char *LP_swapstatus_recv(cJSON *argjson) char *LP_gettradestatus(uint64_t aliceid,uint32_t requestid,uint32_t quoteid) { struct LP_swapstats *sp; char *swapstr,*statusstr; cJSON *reqjson,*swapjson; bits256 zero; - printf("gettradestatus.(%llu)\n",(long long)aliceid); + //printf("gettradestatus.(%llu)\n",(long long)aliceid); if ( IAMLP != 0 ) { if ( (sp= LP_swapstats_find(aliceid)) != 0 ) From 6231df35f2852999e8228dec21d3b8686676413a Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 3 Dec 2017 21:47:55 +0400 Subject: [PATCH 39/59] Test --- iguana/exchanges/LP_instantdex.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/iguana/exchanges/LP_instantdex.c b/iguana/exchanges/LP_instantdex.c index e89db4ccd..b0e24cf53 100644 --- a/iguana/exchanges/LP_instantdex.c +++ b/iguana/exchanges/LP_instantdex.c @@ -303,7 +303,7 @@ int64_t LP_instantdex_credit(int32_t dispflag,char *coinaddr,int64_t satoshis,in if ( coin != 0 ) { timestamp = LP_FIRSTWEEKTIME + weeki*LP_WEEKMULT; - if ( time(NULL) < timestamp-60*3600 && (ap= LP_address(coin,coinaddr)) != 0 ) + if ( (ap= LP_address(coin,coinaddr)) != 0 && time(NULL) < timestamp-60*3600 ) { ap->instantdex_credits += satoshis; ap->didinstantdex = 1; @@ -312,7 +312,7 @@ int64_t LP_instantdex_credit(int32_t dispflag,char *coinaddr,int64_t satoshis,in if ( dispflag != 0 ) printf("InstantDEX credit.(%s) %.8f weeki.%d (%s) -> sum %.8f\n",coinaddr,dstr(satoshis),weeki,p2shaddr,dstr(ap->instantdex_credits)); return(satoshis); - } + } else printf("null ap.%p or expired %ld\n",ap,time(NULL) - (timestamp-60*3600)); } return(0); } @@ -342,8 +342,8 @@ int64_t LP_instantdex_creditcalc(struct iguana_info *coin,int32_t dispflag,bits2 { free_json(txobj); LP_instantdex_credit(dispflag,destaddr,satoshis,weeki,p2shaddr,txid); - } - } + } else printf("already spent\n"); + } else printf("error getting p2shaddr.(%s)\n",p2shaddr); } } free_json(txjson); From 7c90d05916488a00effa5d63e253a19dca66a980 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 3 Dec 2017 21:53:57 +0400 Subject: [PATCH 40/59] Test --- iguana/exchanges/LP_include.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_include.h b/iguana/exchanges/LP_include.h index d6b484d05..1e9900d61 100644 --- a/iguana/exchanges/LP_include.h +++ b/iguana/exchanges/LP_include.h @@ -106,7 +106,7 @@ void emscripten_usleep(int32_t x); // returns immediate, no sense for sleeping #define INSTANTDEX_KMD "RThtXup6Zo7LZAi8kRWgjAyi1s4u6U9Cpf" #define BOTS_BONDADDRESS "RNdqHx26GWy9bk8MtmH1UiXjQcXE4RKK2P" #define BOTS_BONDPUBKEY33 "03e641d22e1ff5a7d45c8880537e0b0a114d7b9fee2c18a6b4a8a80b6285292990" -#define LP_WEEKMULT (7 * 24 * 2600) +#define LP_WEEKMULT (7 * 24 * 3600) #define LP_FIRSTWEEKTIME 1510790400 // must be 0 mod LP_WEEKMULT //#define BASILISK_DISABLEWAITTX From e086f6e4ac98ed114e1b65562b3fa184301f1e86 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 3 Dec 2017 21:57:59 +0400 Subject: [PATCH 41/59] Test --- iguana/exchanges/LP_include.h | 1 + iguana/exchanges/LP_instantdex.c | 10 ++++++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/iguana/exchanges/LP_include.h b/iguana/exchanges/LP_include.h index 1e9900d61..fe6637eea 100644 --- a/iguana/exchanges/LP_include.h +++ b/iguana/exchanges/LP_include.h @@ -106,6 +106,7 @@ void emscripten_usleep(int32_t x); // returns immediate, no sense for sleeping #define INSTANTDEX_KMD "RThtXup6Zo7LZAi8kRWgjAyi1s4u6U9Cpf" #define BOTS_BONDADDRESS "RNdqHx26GWy9bk8MtmH1UiXjQcXE4RKK2P" #define BOTS_BONDPUBKEY33 "03e641d22e1ff5a7d45c8880537e0b0a114d7b9fee2c18a6b4a8a80b6285292990" +#define LP_WEEKMULTBAD (7 * 24 * 2600) #define LP_WEEKMULT (7 * 24 * 3600) #define LP_FIRSTWEEKTIME 1510790400 // must be 0 mod LP_WEEKMULT diff --git a/iguana/exchanges/LP_instantdex.c b/iguana/exchanges/LP_instantdex.c index b0e24cf53..acb195e7b 100644 --- a/iguana/exchanges/LP_instantdex.c +++ b/iguana/exchanges/LP_instantdex.c @@ -219,12 +219,15 @@ int32_t LP_claim_submit(void *ctx,cJSON *txids,int64_t *sump,struct iguana_info vout1 = jitem(vouts,1); weeksatoshis = LP_value_extract(vout1,0); weeki = (int32_t)(weeksatoshis % 10000); - for (j=28; j<=28; j++) + for (j=0; j<2*168; j++) { - expiration = ((weeki * LP_WEEKMULT + j*3600) + LP_FIRSTWEEKTIME); + if ( j >= 168 ) + expiration = ((weeki * LP_WEEKMULT + (j-168)*2600) + LP_FIRSTWEEKTIME); + else expiration = ((weeki * LP_WEEKMULT + j*3600) + LP_FIRSTWEEKTIME); redeemlen = LP_deposit_addr(checkaddr,redeemscript,coin->taddr,coin->p2shtype,expiration,G.LP_pubsecp); if ( strcmp(checkaddr,vinaddr) == 0 ) { + flagi = 1; claimtime = (uint32_t)time(NULL)-777; item = cJSON_CreateObject(); jaddbits256(item,"txid",utxotxid); @@ -245,12 +248,11 @@ int32_t LP_claim_submit(void *ctx,cJSON *txids,int64_t *sump,struct iguana_info *sump += LP_claimtx(ctx,coin,&claimtxid,utxotxid,utxovout,satoshis,vinaddr,claimtime,redeemscript,redeemlen); if ( bits256_nonz(claimtxid) != 0 ) { - flagi = 1; jaddbits256(item,"claimtxid",claimtxid); jaddi(txids,item); } } - } else printf("expiration.%u j.%d checkaddr.(%s) != vinaddr.%s\n",expiration,j,checkaddr,vinaddr); + } //else printf("expiration.%u j.%d checkaddr.(%s) != vinaddr.%s\n",expiration,j,checkaddr,vinaddr); if ( flagi != 0 ) break; } From f6bc0aaedfb89413e2d7110829ecaa02d9e88c5f Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 3 Dec 2017 22:01:13 +0400 Subject: [PATCH 42/59] Test --- iguana/exchanges/LP_instantdex.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_instantdex.c b/iguana/exchanges/LP_instantdex.c index acb195e7b..87f8fbf9a 100644 --- a/iguana/exchanges/LP_instantdex.c +++ b/iguana/exchanges/LP_instantdex.c @@ -252,7 +252,7 @@ int32_t LP_claim_submit(void *ctx,cJSON *txids,int64_t *sump,struct iguana_info jaddi(txids,item); } } - } //else printf("expiration.%u j.%d checkaddr.(%s) != vinaddr.%s\n",expiration,j,checkaddr,vinaddr); + } else printf("expiration.%u j.%d checkaddr.(%s) != vinaddr.%s\n",expiration,j,checkaddr,vinaddr); if ( flagi != 0 ) break; } @@ -267,7 +267,6 @@ char *LP_instantdex_claim(struct iguana_info *coin) { static void *ctx; int32_t i,n; cJSON *array,*txids,*newarray,*retjson; int64_t sum; bits256 utxotxid; - printf("inside instantdex claim\n"); if ( ctx == 0 ) ctx = bitcoin_ctx(); if ( strcmp(coin->symbol,"KMD") != 0 ) From ad7064d4bd01153b9e894cb842d2b6cfcde1c825 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 3 Dec 2017 22:03:06 +0400 Subject: [PATCH 43/59] Test --- iguana/exchanges/LP_instantdex.c | 1 + 1 file changed, 1 insertion(+) diff --git a/iguana/exchanges/LP_instantdex.c b/iguana/exchanges/LP_instantdex.c index 87f8fbf9a..ce5762fa3 100644 --- a/iguana/exchanges/LP_instantdex.c +++ b/iguana/exchanges/LP_instantdex.c @@ -228,6 +228,7 @@ int32_t LP_claim_submit(void *ctx,cJSON *txids,int64_t *sump,struct iguana_info if ( strcmp(checkaddr,vinaddr) == 0 ) { flagi = 1; + printf("j.%d matched %s\n",j,vinaddr); claimtime = (uint32_t)time(NULL)-777; item = cJSON_CreateObject(); jaddbits256(item,"txid",utxotxid); From 363e8a80ca0102c2b6ff3845d4fd32c2fc1444e4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 3 Dec 2017 22:04:58 +0400 Subject: [PATCH 44/59] Test --- iguana/exchanges/LP_instantdex.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/iguana/exchanges/LP_instantdex.c b/iguana/exchanges/LP_instantdex.c index ce5762fa3..56e18a652 100644 --- a/iguana/exchanges/LP_instantdex.c +++ b/iguana/exchanges/LP_instantdex.c @@ -222,13 +222,12 @@ int32_t LP_claim_submit(void *ctx,cJSON *txids,int64_t *sump,struct iguana_info for (j=0; j<2*168; j++) { if ( j >= 168 ) - expiration = ((weeki * LP_WEEKMULT + (j-168)*2600) + LP_FIRSTWEEKTIME); + expiration = ((weeki * LP_WEEKMULTBAD + (j-168)*2600) + LP_FIRSTWEEKTIME); else expiration = ((weeki * LP_WEEKMULT + j*3600) + LP_FIRSTWEEKTIME); redeemlen = LP_deposit_addr(checkaddr,redeemscript,coin->taddr,coin->p2shtype,expiration,G.LP_pubsecp); if ( strcmp(checkaddr,vinaddr) == 0 ) { flagi = 1; - printf("j.%d matched %s\n",j,vinaddr); claimtime = (uint32_t)time(NULL)-777; item = cJSON_CreateObject(); jaddbits256(item,"txid",utxotxid); @@ -253,7 +252,7 @@ int32_t LP_claim_submit(void *ctx,cJSON *txids,int64_t *sump,struct iguana_info jaddi(txids,item); } } - } else printf("expiration.%u j.%d checkaddr.(%s) != vinaddr.%s\n",expiration,j,checkaddr,vinaddr); + } //else printf("expiration.%u j.%d checkaddr.(%s) != vinaddr.%s\n",expiration,j,checkaddr,vinaddr); if ( flagi != 0 ) break; } From 5026668175541934eaa1d0a18dec60976c1ae78a Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 3 Dec 2017 22:08:43 +0400 Subject: [PATCH 45/59] Test --- iguana/exchanges/LP_instantdex.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_instantdex.c b/iguana/exchanges/LP_instantdex.c index 56e18a652..725f907ec 100644 --- a/iguana/exchanges/LP_instantdex.c +++ b/iguana/exchanges/LP_instantdex.c @@ -222,7 +222,7 @@ int32_t LP_claim_submit(void *ctx,cJSON *txids,int64_t *sump,struct iguana_info for (j=0; j<2*168; j++) { if ( j >= 168 ) - expiration = ((weeki * LP_WEEKMULTBAD + (j-168)*2600) + LP_FIRSTWEEKTIME); + expiration = ((weeki * LP_WEEKMULTBAD + (j-168)*3600) + LP_FIRSTWEEKTIME); else expiration = ((weeki * LP_WEEKMULT + j*3600) + LP_FIRSTWEEKTIME); redeemlen = LP_deposit_addr(checkaddr,redeemscript,coin->taddr,coin->p2shtype,expiration,G.LP_pubsecp); if ( strcmp(checkaddr,vinaddr) == 0 ) From cb43c9c0cdca4a4b48e722fb784c5932d5c384f8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 3 Dec 2017 22:12:17 +0400 Subject: [PATCH 46/59] Test --- iguana/exchanges/LP_instantdex.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/iguana/exchanges/LP_instantdex.c b/iguana/exchanges/LP_instantdex.c index 725f907ec..21fb780a3 100644 --- a/iguana/exchanges/LP_instantdex.c +++ b/iguana/exchanges/LP_instantdex.c @@ -313,14 +313,14 @@ int64_t LP_instantdex_credit(int32_t dispflag,char *coinaddr,int64_t satoshis,in if ( dispflag != 0 ) printf("InstantDEX credit.(%s) %.8f weeki.%d (%s) -> sum %.8f\n",coinaddr,dstr(satoshis),weeki,p2shaddr,dstr(ap->instantdex_credits)); return(satoshis); - } else printf("null ap.%p or expired %ld\n",ap,time(NULL) - (timestamp-60*3600)); + } //else printf("null ap.%p or expired %ld\n",ap,time(NULL) - (timestamp-60*3600)); } return(0); } int64_t LP_instantdex_creditcalc(struct iguana_info *coin,int32_t dispflag,bits256 txid,char *refaddr) { - cJSON *txjson,*vouts,*txobj,*item; int64_t satoshis=0,amount64; int32_t weeki,numvouts; char destaddr[64],p2shaddr[64],str[65]; + cJSON *txjson,*vouts,*txobj,*item; int64_t satoshis=0,amount64; int32_t weeki,numvouts; char destaddr[64],p2shaddr[64]; if ( (txjson= LP_gettx(coin->symbol,txid,0)) != 0 ) { // vout0 deposit, vout1 botsfee, vout2 smartaddress @@ -336,7 +336,7 @@ int64_t LP_instantdex_creditcalc(struct iguana_info *coin,int32_t dispflag,bits2 weeki = (amount64 % 10000); item = jitem(vouts,0); satoshis = LP_value_extract(item,0); - printf("%s %s funded %.8f weeki.%d (%s)\n",bits256_str(str,txid),destaddr,dstr(satoshis),weeki,jprint(item,0)); + //printf("%s %s funded %.8f weeki.%d (%s)\n",bits256_str(str,txid),destaddr,dstr(satoshis),weeki,jprint(item,0)); if ( LP_destaddr(p2shaddr,item) == 0 ) { if ( (txobj= LP_gettxout(coin->symbol,p2shaddr,txid,0)) != 0 ) From 93a08f29256f2e918a388c5faefafa9a00cf2071 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 3 Dec 2017 22:28:15 +0400 Subject: [PATCH 47/59] Test --- iguana/exchanges/LP_include.h | 2 +- iguana/exchanges/LP_stats.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_include.h b/iguana/exchanges/LP_include.h index fe6637eea..79a76b055 100644 --- a/iguana/exchanges/LP_include.h +++ b/iguana/exchanges/LP_include.h @@ -65,7 +65,7 @@ void emscripten_usleep(int32_t x); // returns immediate, no sense for sleeping // RTmetrics #define LP_RTMETRICS_TOPGROUP 1.01 //#define LP_MAXPENDING_SWAPS 13 -#define LP_CLIENT_STATSPARSE (100 * 1024 * 1024) +#define LP_CLIENT_STATSPARSE (90 * 1024 * 1024) #define LP_COMMAND_SENDSOCK NN_PUSH #define LP_COMMAND_RECVSOCK NN_PULL diff --git a/iguana/exchanges/LP_stats.c b/iguana/exchanges/LP_stats.c index 7d7ee1fba..69da2fbd8 100644 --- a/iguana/exchanges/LP_stats.c +++ b/iguana/exchanges/LP_stats.c @@ -531,7 +531,7 @@ char *LP_swapstatus_recv(cJSON *argjson) RTflag = 0; else RTflag = 1; sp = LP_swapstats_create(aliceid,RTflag,&Q,qprice,LP_TRADESTATUS_METHODIND); - printf("create swapstatus from recv\n"); + //printf("create swapstatus from recv\n"); } if ( sp != 0 ) { From f0a261d8cbac07fa95671b55731ca1bb8b43bb9f Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 3 Dec 2017 22:30:44 +0400 Subject: [PATCH 48/59] Test --- iguana/exchanges/LP_stats.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_stats.c b/iguana/exchanges/LP_stats.c index 69da2fbd8..312fab0db 100644 --- a/iguana/exchanges/LP_stats.c +++ b/iguana/exchanges/LP_stats.c @@ -97,7 +97,7 @@ int32_t LP_statslog_parse() return(0); } } - else if ( 0 ) + else if ( 1 ) { if ( IAMLP == 0 ) { @@ -108,7 +108,7 @@ int32_t LP_statslog_parse() while ( (c= fgetc(fp)) >= 0 && c != '\n' ) ; printf("start scanning %s from %ld, found boundary %ld\n",LP_STATSLOG_FNAME,fpos-LP_CLIENT_STATSPARSE,ftell(fp)); - } + } else rewind(fp); } } while ( fgets(line,sizeof(line),fp) > 0 ) From cc60813494b6778fdb187cba69e54029cc6be7c3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 3 Dec 2017 23:19:51 +0400 Subject: [PATCH 49/59] Test --- iguana/exchanges/LP_commands.c | 2 + iguana/exchanges/LP_include.h | 4 +- iguana/exchanges/LP_instantdex.c | 4 +- iguana/exchanges/LP_nativeDEX.c | 6 ++- iguana/exchanges/LP_rpc.c | 69 +++++++++++++++++++++++++++++--- iguana/exchanges/LP_stats.c | 18 +++++++++ 6 files changed, 92 insertions(+), 11 deletions(-) diff --git a/iguana/exchanges/LP_commands.c b/iguana/exchanges/LP_commands.c index 2c9a378d5..980bc9a76 100644 --- a/iguana/exchanges/LP_commands.c +++ b/iguana/exchanges/LP_commands.c @@ -620,6 +620,8 @@ instantdex_claim()\n\ return(LP_postprice_recv(argjson)); else if ( strcmp(method,"uitem") == 0 ) return(LP_uitem_recv(argjson)); + else if ( strcmp(method,"dPoW") == 0 ) + return(LP_dPoW_recv(argjson)); else if ( strcmp(method,"notify") == 0 ) return(LP_notify_recv(argjson)); else if ( strcmp(method,"getpeers") == 0 ) diff --git a/iguana/exchanges/LP_include.h b/iguana/exchanges/LP_include.h index 79a76b055..55f97fe19 100644 --- a/iguana/exchanges/LP_include.h +++ b/iguana/exchanges/LP_include.h @@ -301,8 +301,8 @@ struct iguana_info uint64_t maxamount,kmd_equiv,balanceA,balanceB,valuesumA,valuesumB; uint8_t pubkey33[33],zcash; int32_t privkeydepth; - bits256 cachedtxid; uint8_t *cachedtxiddata; int32_t cachedtxidlen; - bits256 cachedmerkle; int32_t cachedmerkleheight; + bits256 cachedtxid,notarizationtxid; uint8_t *cachedtxiddata; int32_t cachedtxidlen; + bits256 cachedmerkle,notarizedhash; int32_t cachedmerkleheight; }; struct _LP_utxoinfo { bits256 txid; uint64_t value; int32_t vout,height; }; diff --git a/iguana/exchanges/LP_instantdex.c b/iguana/exchanges/LP_instantdex.c index 21fb780a3..043d6b50f 100644 --- a/iguana/exchanges/LP_instantdex.c +++ b/iguana/exchanges/LP_instantdex.c @@ -418,7 +418,7 @@ int64_t LP_instantdex_proofcheck(char *coinaddr,cJSON *proof,int32_t num) { bitcoin_addr2rmd160(0,&addrtype,rmd160,coinaddr); bitcoin_address(othersmartaddr,0,60,rmd160,20); - if ((ap= LP_address(coin,othersmartaddr)) != 0 && (coin->electrum == 0 || ap->didinstantdex == 0) ) + if ((ap= LP_address(coin,othersmartaddr)) != 0 )//&& (coin->electrum == 0 || ap->didinstantdex == 0) ) { ap->instantdex_credits = 0; for (i=0; ididinstantdex = 1; //if ( ap->instantdex_credits > 0 ) printf("validated instantdex %s.[%d] proof.(%s) credits %.8f net %.8f\n",othersmartaddr,num,jprint(proof,0),dstr(ap->instantdex_credits),dstr(net)); - } else printf("cant find ap.%p or already did %d %.8f\n",ap,ap!=0?ap->didinstantdex:-1,ap!=0?dstr(ap->instantdex_credits):-1); + } //else printf("cant find ap.%p or already did %d %.8f\n",ap,ap!=0?ap->didinstantdex:-1,ap!=0?dstr(ap->instantdex_credits):-1); } return(ap->instantdex_credits); } diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index cf09af1b6..a011ef4ec 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -17,8 +17,8 @@ // LP_nativeDEX.c // marketmaker // -// too much stats.log -// big BTC swaps +// validate notarization +// big BTC swaps, assetchain markets // https://github.com/bitcoin/bips/blob/master/bip-0143.mediawiki for signing BCH/BTG // // compress packets @@ -683,6 +683,8 @@ int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int jaddstr(reqjson,"method","dPoW"); jaddstr(reqjson,"coin",coin->symbol); jaddnum(reqjson,"notarized",coin->notarized); + jaddbits256(reqjson,"notarizedhash",coin->notarizedhash); + jaddbits256(reqjson,"notarizationtxid",coin->notarizationtxid); memset(zero.bytes,0,sizeof(zero)); LP_reserved_msg(0,coin->symbol,coin->symbol,zero,jprint(reqjson,1)); } diff --git a/iguana/exchanges/LP_rpc.c b/iguana/exchanges/LP_rpc.c index d84369890..d692b16fd 100644 --- a/iguana/exchanges/LP_rpc.c +++ b/iguana/exchanges/LP_rpc.c @@ -106,6 +106,8 @@ int32_t LP_getheight(int32_t *notarizedp,struct iguana_info *coin) { printf("new notarized %s %d -> %d\n",coin->symbol,coin->notarized,*notarizedp); coin->notarized = *notarizedp; + coin->notarizationtxid = jbits256(retjson,"notarizedtxid"); + coin->notarizedhash = jbits256(retjson,"notarizedhash"); } free_json(retjson); if ( coin->height > 0 ) @@ -965,9 +967,10 @@ const char *Notaries_elected[][2] = { "xxspot2_XX", "03d85b221ea72ebcd25373e7961f4983d12add66a92f899deaf07bab1d8b6f5573" } }; -int32_t LP_txhasnotarization(struct iguana_info *coin,bits256 txid) +int32_t LP_txhasnotarization(bits256 *notarizedhashp,struct iguana_info *coin,bits256 txid) { - cJSON *txobj,*vins,*vin,*vouts,*vout,*spentobj,*sobj; char *hexstr; uint8_t script[35]; bits256 spenttxid; uint64_t notarymask; int32_t i,j,numnotaries,len,spentvout,numvins,numvouts,hasnotarization = 0; + cJSON *txobj,*vins,*vin,*vouts,*vout,*spentobj,*sobj; char *hexstr; uint8_t script[1024]; bits256 spenttxid; uint64_t notarymask; int32_t i,j,numnotaries,len,spentvout,numvins,numvouts,hasnotarization = 0; + memset(notarizedhashp,0,sizeof(*notarizedhashp)); if ( (txobj= LP_gettx(coin->symbol,txid,0)) != 0 ) { if ( (vins= jarray(&numvins,txobj,"vin")) != 0 ) @@ -987,7 +990,7 @@ int32_t LP_txhasnotarization(struct iguana_info *coin,bits256 txid) if ( spentvout < numvouts ) { vout = jitem(vouts,spentvout); - if ( (sobj= jobj(vout,"scriptPubKey")) != 0 && (hexstr= jstr(sobj,"hex")) != 0 && (len= is_hexstr(hexstr,0)) == sizeof(script)*2 ) + if ( (sobj= jobj(vout,"scriptPubKey")) != 0 && (hexstr= jstr(sobj,"hex")) != 0 && (len= is_hexstr(hexstr,0)) == 35*2 ) { len >>= 1; decode_hex(script,len,hexstr); @@ -1021,20 +1024,76 @@ int32_t LP_txhasnotarization(struct iguana_info *coin,bits256 txid) } } } + if ( (vouts= jarray(&numvouts,txobj,"vout")) != 0 ) + { + vout = jitem(vouts,1); + if ( (sobj= jobj(vout,"scriptPubKey")) != 0 && (hexstr= jstr(sobj,"hex")) != 0 && (len= is_hexstr(hexstr,0)) >= 35 ) + { + len >>= 1; + decode_hex(script,len,hexstr); + iguana_rwbignum(0,&script[3],32,(uint8_t *)notarizedhashp); + } + } free_json(txobj); } return(hasnotarization); } +int32_t LP_notarization_validate(char *symbol,int32_t notarized,bits256 notarizedhash,bits256 notarizationtxid) +{ + struct iguana_info *coin; int32_t valid = 0; cJSON *blockjson; bits256 notarizedhash2; char str[65],str2[65]; + if ( strcmp(symbol,"KMD") == 0 ) + coin = LP_coinfind("BTC"); + else coin = LP_coinfind("KMD"); + if ( coin != 0 ) + { + if (LP_txhasnotarization(¬arizedhash2,coin,notarizationtxid) == 0 ) + { + printf("missing %s notarization txid %s\n",symbol,bits256_str(str,notarizationtxid)); + return(-1); + } + else if ( bits256_cmp(notarizedhash,notarizedhash2) != 0 ) + { + printf("mismatched %s notarizedhash %s vs %s\n",symbol,bits256_str(str,notarizedhash),bits256_str(str2,notarizedhash2)); + return(-1); + } + } + if ( (coin= LP_coinfind(symbol)) != 0 ) + { + if ( coin->electrum == 0 ) + { + if ( (blockjson= LP_getblock(coin->symbol,notarizedhash)) != 0 ) + { + if ( jint(blockjson,"height") != notarized ) + valid = 1; + free_json(blockjson); + } + } + else + { + if ( (blockjson= electrum_getheader(symbol,coin->electrum,&blockjson,notarized+1)) != 0 ) + { + notarizedhash2 = jbits256(blockjson,"prev_block_hash"); + if ( bits256_cmp(notarizedhash,notarizedhash2) == 0 ) + valid = 1; + free_json(blockjson); + } + } + } + if ( valid == 1 ) + return(0); + else return(-1); +} + int32_t LP_hasnotarization(struct iguana_info *coin,cJSON *blockjson) { - int32_t i,n,hasnotarization = 0; bits256 txid; cJSON *txarray; + int32_t i,n,hasnotarization = 0; bits256 txid,notarizedhash; cJSON *txarray; if ( (txarray= jarray(&n,blockjson,"tx")) != 0 ) { for (i=0; ielectrum != 0 ) + { + notarized = jint(argjson,"notarized"); + notarizedhash = jbits256(argjson,"notarizedhash"); + notarizationtxid = jbits256(argjson,"notarizationtxid"); + if ( notarized > coin->notarized && LP_notarization_validate(symbol,notarized,notarizedhash,notarizationtxid) == 0 ) + { + coin->notarized = notarized; + coin->notarizedhash = notarizedhash; + coin->notarizationtxid = notarizationtxid; + } + } + return(clonestr("{\"result\":\"success\"}")); +} + void LP_tradecommand_log(cJSON *argjson) { static FILE *logfp; char *jsonstr; From 16a595a9c163a57b2771f73351b0c8e8eac5aed6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 3 Dec 2017 23:27:14 +0400 Subject: [PATCH 50/59] Test --- iguana/exchanges/LP_stats.c | 2 ++ iguana/exchanges/LP_utxo.c | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/iguana/exchanges/LP_stats.c b/iguana/exchanges/LP_stats.c index cea994f07..94278f88b 100644 --- a/iguana/exchanges/LP_stats.c +++ b/iguana/exchanges/LP_stats.c @@ -36,11 +36,13 @@ char *LP_dPoW_recv(cJSON *argjson) notarized = jint(argjson,"notarized"); notarizedhash = jbits256(argjson,"notarizedhash"); notarizationtxid = jbits256(argjson,"notarizationtxid"); + printf("dPoW %s\n",jprint(argjson,0)); if ( notarized > coin->notarized && LP_notarization_validate(symbol,notarized,notarizedhash,notarizationtxid) == 0 ) { coin->notarized = notarized; coin->notarizedhash = notarizedhash; coin->notarizationtxid = notarizationtxid; + printf("VALIDATED\n"); } } return(clonestr("{\"result\":\"success\"}")); diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index aa11f9b3b..d3a32db6e 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -794,7 +794,12 @@ int32_t LP_txheight(struct iguana_info *coin,bits256 txid) if ( height == 0 ) { if ( (retjson= electrum_transaction(&height,coin->symbol,coin->electrum,&retjson,txid,0)) != 0 ) + { + printf("process %s\n",jprint(retjson,0)); free_json(retjson); + } + if ( (tx= LP_transactionfind(coin,txid)) != 0 ) + height = tx->height; } } return(height); From c4d025049566168a227b94d3f2de7f4b49b81aa8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 3 Dec 2017 23:38:10 +0400 Subject: [PATCH 51/59] Test --- iguana/exchanges/LP_nativeDEX.c | 11 +---------- iguana/exchanges/LP_stats.c | 18 +++++++++++++++++- iguana/exchanges/LP_utxo.c | 2 +- 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index a011ef4ec..639b57fb8 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -678,16 +678,7 @@ int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int { coin->notarized = notarized; if ( IAMLP != 0 ) - { - reqjson = cJSON_CreateObject(); - jaddstr(reqjson,"method","dPoW"); - jaddstr(reqjson,"coin",coin->symbol); - jaddnum(reqjson,"notarized",coin->notarized); - jaddbits256(reqjson,"notarizedhash",coin->notarizedhash); - jaddbits256(reqjson,"notarizationtxid",coin->notarizationtxid); - memset(zero.bytes,0,sizeof(zero)); - LP_reserved_msg(0,coin->symbol,coin->symbol,zero,jprint(reqjson,1)); - } + LP_dPoW_broadcast(coin); } if ( 0 && coin->firstrefht != 0 ) printf(">>>>>>>>>> set %s longestchain %d (ref.%d [%d, %d])\n",coin->symbol,height,coin->firstrefht,coin->firstscanht,coin->lastscanht); diff --git a/iguana/exchanges/LP_stats.c b/iguana/exchanges/LP_stats.c index 94278f88b..f1088c47d 100644 --- a/iguana/exchanges/LP_stats.c +++ b/iguana/exchanges/LP_stats.c @@ -28,6 +28,18 @@ char *LP_stats_methods[] = { "unknown", "request", "reserved", "connect", "conne static uint32_t LP_requests,LP_reserveds,LP_connects,LP_connecteds,LP_tradestatuses,LP_parse_errors,LP_unknowns,LP_duplicates,LP_aliceids; +void LP_dPoW_broadcast(struct iguana_info *coin) +{ + bits256 zero; cJSON *reqjson = cJSON_CreateObject(); + jaddstr(reqjson,"method","dPoW"); + jaddstr(reqjson,"coin",coin->symbol); + jaddnum(reqjson,"notarized",coin->notarized); + jaddbits256(reqjson,"notarizedhash",coin->notarizedhash); + jaddbits256(reqjson,"notarizationtxid",coin->notarizationtxid); + memset(zero.bytes,0,sizeof(zero)); + LP_reserved_msg(0,coin->symbol,coin->symbol,zero,jprint(reqjson,1)); +} + char *LP_dPoW_recv(cJSON *argjson) { int32_t notarized; bits256 notarizedhash,notarizationtxid; char *symbol; struct iguana_info *coin; @@ -608,7 +620,7 @@ char *LP_swapstatus_recv(cJSON *argjson) char *LP_gettradestatus(uint64_t aliceid,uint32_t requestid,uint32_t quoteid) { - struct LP_swapstats *sp; char *swapstr,*statusstr; cJSON *reqjson,*swapjson; bits256 zero; + struct LP_swapstats *sp; struct iguana_info *bob,*alice; char *swapstr,*statusstr; cJSON *reqjson,*swapjson; bits256 zero; //printf("gettradestatus.(%llu)\n",(long long)aliceid); if ( IAMLP != 0 ) { @@ -622,6 +634,10 @@ char *LP_gettradestatus(uint64_t aliceid,uint32_t requestid,uint32_t quoteid) memset(zero.bytes,0,sizeof(zero)); LP_reserved_msg(0,"","",zero,jprint(reqjson,1)); } + if ( (bob= LP_coinfind(sp->Q.srccoin)) != 0 ) + LP_dPoW_broadcast(bob); + if ( (alice= LP_coinfind(sp->Q.destcoin)) != 0 ) + LP_dPoW_broadcast(alice); } return(clonestr("{\"result\":\"success\"}")); } diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index d3a32db6e..890577df0 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -795,7 +795,7 @@ int32_t LP_txheight(struct iguana_info *coin,bits256 txid) { if ( (retjson= electrum_transaction(&height,coin->symbol,coin->electrum,&retjson,txid,0)) != 0 ) { - printf("process %s\n",jprint(retjson,0)); + //printf("process %s\n",jprint(retjson,0)); free_json(retjson); } if ( (tx= LP_transactionfind(coin,txid)) != 0 ) From d6fac1a5896bf8a7de04d0f477feac21e0f50d87 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 3 Dec 2017 23:39:11 +0400 Subject: [PATCH 52/59] Test --- iguana/exchanges/LP_stats.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/iguana/exchanges/LP_stats.c b/iguana/exchanges/LP_stats.c index f1088c47d..2e9169e67 100644 --- a/iguana/exchanges/LP_stats.c +++ b/iguana/exchanges/LP_stats.c @@ -30,14 +30,18 @@ static uint32_t LP_requests,LP_reserveds,LP_connects,LP_connecteds,LP_tradestatu void LP_dPoW_broadcast(struct iguana_info *coin) { - bits256 zero; cJSON *reqjson = cJSON_CreateObject(); - jaddstr(reqjson,"method","dPoW"); - jaddstr(reqjson,"coin",coin->symbol); - jaddnum(reqjson,"notarized",coin->notarized); - jaddbits256(reqjson,"notarizedhash",coin->notarizedhash); - jaddbits256(reqjson,"notarizationtxid",coin->notarizationtxid); - memset(zero.bytes,0,sizeof(zero)); - LP_reserved_msg(0,coin->symbol,coin->symbol,zero,jprint(reqjson,1)); + bits256 zero; cJSON *reqjson; + if ( coin->isassetchain != 0 || strcmp(coin->symbol,"KMD") == 0 ) + { + reqjson = cJSON_CreateObject(); + jaddstr(reqjson,"method","dPoW"); + jaddstr(reqjson,"coin",coin->symbol); + jaddnum(reqjson,"notarized",coin->notarized); + jaddbits256(reqjson,"notarizedhash",coin->notarizedhash); + jaddbits256(reqjson,"notarizationtxid",coin->notarizationtxid); + memset(zero.bytes,0,sizeof(zero)); + LP_reserved_msg(0,coin->symbol,coin->symbol,zero,jprint(reqjson,1)); + } } char *LP_dPoW_recv(cJSON *argjson) From f8edc9635240b283120c2c42b5804d262a7ee000 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 3 Dec 2017 23:50:13 +0400 Subject: [PATCH 53/59] Test --- iguana/exchanges/LP_commands.c | 10 ++++++- iguana/exchanges/LP_nativeDEX.c | 2 +- iguana/exchanges/LP_stats.c | 48 +++++++++++++++++++++------------ 3 files changed, 41 insertions(+), 19 deletions(-) diff --git a/iguana/exchanges/LP_commands.c b/iguana/exchanges/LP_commands.c index 980bc9a76..d9031b6df 100644 --- a/iguana/exchanges/LP_commands.c +++ b/iguana/exchanges/LP_commands.c @@ -603,6 +603,8 @@ instantdex_claim()\n\ } argjson = reqjson; } + else if ( strcmp(method,"getdPoW") == 0 ) + retstr = clonestr("{\"result\":\"success\"}"); } else { @@ -610,7 +612,13 @@ instantdex_claim()\n\ { return(jprint(LP_tradesarray(base,rel,juint(argjson,"starttime"),juint(argjson,"endtime"),jint(argjson,"timescale")),1)); } - } + else if ( strcmp(method,"getdPoW") == 0 ) + { + if ( (ptr= LP_coinfind(jstr(argjson,"coin"))) != 0 ) + LP_dPoW_broadcast(ptr); + retstr = clonestr("{\"result\":\"success\"}"); + } + } // received response if ( strcmp(method,"swapstatus") == 0 ) return(LP_swapstatus_recv(argjson)); diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 639b57fb8..a985e5b5f 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -646,7 +646,7 @@ void LP_coinsloop(void *_coins) int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int32_t pubsock,char *pushaddr,uint16_t myport) { static uint32_t counter;//,didinstantdex; - struct iguana_info *coin,*ctmp; char *origipaddr; uint32_t now; int32_t notarized,height,nonz = 0; bits256 zero; cJSON *reqjson; + struct iguana_info *coin,*ctmp; char *origipaddr; uint32_t now; int32_t notarized,height,nonz = 0; if ( (origipaddr= myipaddr) == 0 ) origipaddr = "127.0.0.1"; if ( mypeer == 0 ) diff --git a/iguana/exchanges/LP_stats.c b/iguana/exchanges/LP_stats.c index 2e9169e67..0db044e23 100644 --- a/iguana/exchanges/LP_stats.c +++ b/iguana/exchanges/LP_stats.c @@ -28,6 +28,17 @@ char *LP_stats_methods[] = { "unknown", "request", "reserved", "connect", "conne static uint32_t LP_requests,LP_reserveds,LP_connects,LP_connecteds,LP_tradestatuses,LP_parse_errors,LP_unknowns,LP_duplicates,LP_aliceids; +void LP_dPoW_request(struct iguana_info *coin) +{ + bits256 zero; cJSON *reqjson; + reqjson = cJSON_CreateObject(); + jaddstr(reqjson,"method","getdPoW"); + jaddstr(reqjson,"coin",coin->symbol); + memset(zero.bytes,0,sizeof(zero)); + printf("request %s\n",jprint(reqjson,0)); + LP_reserved_msg(0,coin->symbol,coin->symbol,zero,jprint(reqjson,1)); +} + void LP_dPoW_broadcast(struct iguana_info *coin) { bits256 zero; cJSON *reqjson; @@ -40,6 +51,7 @@ void LP_dPoW_broadcast(struct iguana_info *coin) jaddbits256(reqjson,"notarizedhash",coin->notarizedhash); jaddbits256(reqjson,"notarizationtxid",coin->notarizationtxid); memset(zero.bytes,0,sizeof(zero)); + printf("broadcast %s\n",jprint(reqjson,0)); LP_reserved_msg(0,coin->symbol,coin->symbol,zero,jprint(reqjson,1)); } } @@ -64,6 +76,25 @@ char *LP_dPoW_recv(cJSON *argjson) return(clonestr("{\"result\":\"success\"}")); } +int32_t LP_dPoWheight(struct iguana_info *coin) // get dPoW protected height +{ + int32_t notarized,oldnotarized; + if ( coin->electrum == 0 ) + { + coin->heighttime = (uint32_t)(time(NULL) - 61); + oldnotarized = coin->notarized; + LP_getheight(¬arized,coin); + if ( notarized != 0 && notarized != oldnotarized ) + { + printf("dPoWheight.%s %d <- %d\n",coin->symbol,oldnotarized,notarized); + coin->notarized = notarized; + } + } + else if ( coin->notarized == 0 ) + LP_dPoW_request(coin); + return(coin->notarized); +} + void LP_tradecommand_log(cJSON *argjson) { static FILE *logfp; char *jsonstr; @@ -260,23 +291,6 @@ int32_t LP_swapstats_update(struct LP_swapstats *sp,struct LP_quoteinfo *qp,cJSO return(0); } -int32_t LP_dPoWheight(struct iguana_info *coin) // get dPoW protected height -{ - int32_t notarized,oldnotarized; - if ( coin->electrum == 0 ) - { - coin->heighttime = (uint32_t)(time(NULL) - 61); - oldnotarized = coin->notarized; - LP_getheight(¬arized,coin); - if ( notarized != 0 && notarized != oldnotarized ) - { - printf("dPoWheight.%s %d <- %d\n",coin->symbol,oldnotarized,notarized); - coin->notarized = notarized; - } - } - return(coin->notarized); -} - int32_t LP_finished_lastheight(struct LP_swapstats *sp) { int32_t height = 1; struct iguana_info *bob,*alice; //char str[65]; From 702467d96658518e6968b8171545269c181be01d Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 3 Dec 2017 23:54:32 +0400 Subject: [PATCH 54/59] Test --- iguana/exchanges/LP_rpc.c | 2 +- iguana/exchanges/LP_stats.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_rpc.c b/iguana/exchanges/LP_rpc.c index d692b16fd..b3a070f83 100644 --- a/iguana/exchanges/LP_rpc.c +++ b/iguana/exchanges/LP_rpc.c @@ -1031,7 +1031,7 @@ int32_t LP_txhasnotarization(bits256 *notarizedhashp,struct iguana_info *coin,bi { len >>= 1; decode_hex(script,len,hexstr); - iguana_rwbignum(0,&script[3],32,(uint8_t *)notarizedhashp); + iguana_rwbignum(0,&script[4],32,(uint8_t *)notarizedhashp); } } free_json(txobj); diff --git a/iguana/exchanges/LP_stats.c b/iguana/exchanges/LP_stats.c index 0db044e23..5b483d6b5 100644 --- a/iguana/exchanges/LP_stats.c +++ b/iguana/exchanges/LP_stats.c @@ -70,7 +70,7 @@ char *LP_dPoW_recv(cJSON *argjson) coin->notarized = notarized; coin->notarizedhash = notarizedhash; coin->notarizationtxid = notarizationtxid; - printf("VALIDATED\n"); + printf("VALIDATED dPoW %s\n",jprint(argjson,0)); } } return(clonestr("{\"result\":\"success\"}")); From fcee4d1518b8c1dd19928d4ce6efab3db413c286 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 3 Dec 2017 23:58:34 +0400 Subject: [PATCH 55/59] Test --- iguana/exchanges/LP_include.h | 2 +- iguana/exchanges/LP_instantdex.c | 4 ++++ iguana/exchanges/LP_stats.c | 3 ++- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_include.h b/iguana/exchanges/LP_include.h index 55f97fe19..218dc7867 100644 --- a/iguana/exchanges/LP_include.h +++ b/iguana/exchanges/LP_include.h @@ -292,7 +292,7 @@ struct iguana_info portable_mutex_t txmutex,addrmutex; struct LP_transaction *transactions; struct LP_address *addresses; uint64_t txfee; int32_t numutxos,notarized,longestchain,firstrefht,firstscanht,lastscanht,bussock,height; uint16_t busport; - uint32_t loadedcache,electrumlist,lastunspent,importedprivkey,lastpushtime,lastutxosync,addr_listunspent_requested,lastutxos,updaterate,counter,inactive,lastmempool,lastgetinfo,ratetime,heighttime,lastmonitor,obooktime; + uint32_t dPoWtime,loadedcache,electrumlist,lastunspent,importedprivkey,lastpushtime,lastutxosync,addr_listunspent_requested,lastutxos,updaterate,counter,inactive,lastmempool,lastgetinfo,ratetime,heighttime,lastmonitor,obooktime; uint8_t pubtype,p2shtype,isPoS,wiftype,wiftaddr,taddr,noimportprivkey_flag,userconfirms,isassetchain,maxconfirms; char symbol[128],smartaddr[64],userpass[1024],serverport[128]; // portfolio diff --git a/iguana/exchanges/LP_instantdex.c b/iguana/exchanges/LP_instantdex.c index 043d6b50f..2737a0c9e 100644 --- a/iguana/exchanges/LP_instantdex.c +++ b/iguana/exchanges/LP_instantdex.c @@ -468,6 +468,8 @@ cJSON *LP_swapstats_item(struct LP_swapstats *sp,int32_t iambob) jaddnum(item,"bob_dPoWheight",bob->notarized); if ( sp->bobneeds_dPoW == 1 ) flag = 1; + if ( bob->notarized == 0 ) + LP_dPoW_request(bob); } if ( sp->aliceneeds_dPoW != 0 && (alice= LP_coinfind(sp->Q.destcoin)) != 0 ) { @@ -475,6 +477,8 @@ cJSON *LP_swapstats_item(struct LP_swapstats *sp,int32_t iambob) jaddnum(item,"alice_dPoWheight",alice->notarized); if ( sp->aliceneeds_dPoW == 1 ) flag = 1; + if ( alice->notarized == 0 ) + LP_dPoW_request(alice); } if ( flag != 0 ) { diff --git a/iguana/exchanges/LP_stats.c b/iguana/exchanges/LP_stats.c index 5b483d6b5..ab3744c60 100644 --- a/iguana/exchanges/LP_stats.c +++ b/iguana/exchanges/LP_stats.c @@ -42,7 +42,7 @@ void LP_dPoW_request(struct iguana_info *coin) void LP_dPoW_broadcast(struct iguana_info *coin) { bits256 zero; cJSON *reqjson; - if ( coin->isassetchain != 0 || strcmp(coin->symbol,"KMD") == 0 ) + if ( time(NULL) > coin->dPoWtime+60 && (coin->isassetchain != 0 || strcmp(coin->symbol,"KMD") == 0) ) { reqjson = cJSON_CreateObject(); jaddstr(reqjson,"method","dPoW"); @@ -53,6 +53,7 @@ void LP_dPoW_broadcast(struct iguana_info *coin) memset(zero.bytes,0,sizeof(zero)); printf("broadcast %s\n",jprint(reqjson,0)); LP_reserved_msg(0,coin->symbol,coin->symbol,zero,jprint(reqjson,1)); + coin->dPoWtime = (uint32_t)time(NULL); } } From 8c327cae8316677038ba4d3527256c1a04e05633 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 4 Dec 2017 00:01:52 +0400 Subject: [PATCH 56/59] Test --- iguana/exchanges/LP_commands.c | 4 ++-- iguana/exchanges/LP_rpc.c | 2 +- iguana/exchanges/LP_stats.c | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/iguana/exchanges/LP_commands.c b/iguana/exchanges/LP_commands.c index d9031b6df..af24bf929 100644 --- a/iguana/exchanges/LP_commands.c +++ b/iguana/exchanges/LP_commands.c @@ -603,7 +603,7 @@ instantdex_claim()\n\ } argjson = reqjson; } - else if ( strcmp(method,"getdPoW") == 0 ) + if ( strcmp(method,"getdPoW") == 0 ) retstr = clonestr("{\"result\":\"success\"}"); } else @@ -618,7 +618,7 @@ instantdex_claim()\n\ LP_dPoW_broadcast(ptr); retstr = clonestr("{\"result\":\"success\"}"); } - } + } // received response if ( strcmp(method,"swapstatus") == 0 ) return(LP_swapstatus_recv(argjson)); diff --git a/iguana/exchanges/LP_rpc.c b/iguana/exchanges/LP_rpc.c index b3a070f83..a9dcfe1e3 100644 --- a/iguana/exchanges/LP_rpc.c +++ b/iguana/exchanges/LP_rpc.c @@ -1031,7 +1031,7 @@ int32_t LP_txhasnotarization(bits256 *notarizedhashp,struct iguana_info *coin,bi { len >>= 1; decode_hex(script,len,hexstr); - iguana_rwbignum(0,&script[4],32,(uint8_t *)notarizedhashp); + iguana_rwbignum(0,&script[2],32,(uint8_t *)notarizedhashp); } } free_json(txobj); diff --git a/iguana/exchanges/LP_stats.c b/iguana/exchanges/LP_stats.c index ab3744c60..ba9486f13 100644 --- a/iguana/exchanges/LP_stats.c +++ b/iguana/exchanges/LP_stats.c @@ -77,7 +77,7 @@ char *LP_dPoW_recv(cJSON *argjson) return(clonestr("{\"result\":\"success\"}")); } -int32_t LP_dPoWheight(struct iguana_info *coin) // get dPoW protected height +/*int32_t LP_dPoWheight(struct iguana_info *coin) // get dPoW protected height { int32_t notarized,oldnotarized; if ( coin->electrum == 0 ) @@ -94,7 +94,7 @@ int32_t LP_dPoWheight(struct iguana_info *coin) // get dPoW protected height else if ( coin->notarized == 0 ) LP_dPoW_request(coin); return(coin->notarized); -} +}*/ void LP_tradecommand_log(cJSON *argjson) { From 603202b57430028d180d690376ff389596319862 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 4 Dec 2017 00:03:23 +0400 Subject: [PATCH 57/59] Test --- iguana/exchanges/LP_stats.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_stats.c b/iguana/exchanges/LP_stats.c index ba9486f13..550ccaca5 100644 --- a/iguana/exchanges/LP_stats.c +++ b/iguana/exchanges/LP_stats.c @@ -35,7 +35,7 @@ void LP_dPoW_request(struct iguana_info *coin) jaddstr(reqjson,"method","getdPoW"); jaddstr(reqjson,"coin",coin->symbol); memset(zero.bytes,0,sizeof(zero)); - printf("request %s\n",jprint(reqjson,0)); + //printf("request %s\n",jprint(reqjson,0)); LP_reserved_msg(0,coin->symbol,coin->symbol,zero,jprint(reqjson,1)); } @@ -51,7 +51,7 @@ void LP_dPoW_broadcast(struct iguana_info *coin) jaddbits256(reqjson,"notarizedhash",coin->notarizedhash); jaddbits256(reqjson,"notarizationtxid",coin->notarizationtxid); memset(zero.bytes,0,sizeof(zero)); - printf("broadcast %s\n",jprint(reqjson,0)); + //printf("broadcast %s\n",jprint(reqjson,0)); LP_reserved_msg(0,coin->symbol,coin->symbol,zero,jprint(reqjson,1)); coin->dPoWtime = (uint32_t)time(NULL); } From 46945928b4d1d2c9dc45577e66d825ab3d88d1c6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 4 Dec 2017 00:13:56 +0400 Subject: [PATCH 58/59] Test --- iguana/exchanges/LP_instantdex.c | 2 +- iguana/exchanges/LP_stats.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_instantdex.c b/iguana/exchanges/LP_instantdex.c index 2737a0c9e..cb01b37b8 100644 --- a/iguana/exchanges/LP_instantdex.c +++ b/iguana/exchanges/LP_instantdex.c @@ -487,7 +487,7 @@ cJSON *LP_swapstats_item(struct LP_swapstats *sp,int32_t iambob) jadd64bits(reqjson,"aliceid",sp->aliceid); memset(zero.bytes,0,sizeof(zero)); LP_reserved_msg(0,"","",zero,jprint(reqjson,1)); - if ( (swapstr= basilisk_swapentry(sp->Q.R.requestid,sp->Q.R.quoteid,1)) != 0 ) + if ( (swapstr= basilisk_swapentry(sp->Q.R.requestid,sp->Q.R.quoteid,0)) != 0 ) { if ( (swapjson= cJSON_Parse(swapstr)) != 0 ) { diff --git a/iguana/exchanges/LP_stats.c b/iguana/exchanges/LP_stats.c index 550ccaca5..06d072285 100644 --- a/iguana/exchanges/LP_stats.c +++ b/iguana/exchanges/LP_stats.c @@ -65,7 +65,7 @@ char *LP_dPoW_recv(cJSON *argjson) notarized = jint(argjson,"notarized"); notarizedhash = jbits256(argjson,"notarizedhash"); notarizationtxid = jbits256(argjson,"notarizationtxid"); - printf("dPoW %s\n",jprint(argjson,0)); + //printf("dPoW %s\n",jprint(argjson,0)); if ( notarized > coin->notarized && LP_notarization_validate(symbol,notarized,notarizedhash,notarizationtxid) == 0 ) { coin->notarized = notarized; From ad04965a196d8aedff68689bf43822f3f7dc3514 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 4 Dec 2017 01:48:54 +0400 Subject: [PATCH 59/59] Test --- iguana/coins/mshark_7776 | 0 iguana/exchanges/LP_nativeDEX.c | 7 ++----- 2 files changed, 2 insertions(+), 5 deletions(-) mode change 100644 => 100755 iguana/coins/mshark_7776 diff --git a/iguana/coins/mshark_7776 b/iguana/coins/mshark_7776 old mode 100644 new mode 100755 diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index a985e5b5f..19ee06ace 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -17,21 +17,18 @@ // LP_nativeDEX.c // marketmaker // -// validate notarization -// big BTC swaps, assetchain markets // https://github.com/bitcoin/bips/blob/master/bip-0143.mediawiki for signing BCH/BTG +// big BTC swaps, assetchain markets // // compress packets // cancel bid/ask // portfolio to set prices from historical // portfolio value based on ask? -// USD paxprice based USDvalue in portfolio // // else claim path -// improve critical section detection when parallel trades // dPoW security -> 4: KMD notarized, 5: BTC notarized, after next notary elections // bigendian architectures need to use little endian for sighash calcs -// +// improve critical section detection when parallel trades #include