From 89d73e90e0366a12ed2c82b9654ed8aaf810c56e Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 23 Nov 2017 20:06:40 +0400 Subject: [PATCH 01/14] Test --- iguana/exchanges/LP_nativeDEX.c | 2 -- iguana/exchanges/LP_remember.c | 5 +++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index d320b2e67..409adee31 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -18,7 +18,6 @@ // marketmaker // // feature requests: -// electrum memleak? // alice waiting for bestprice // USD paxprice based USDvalue in portfolio // cancel bid/ask @@ -27,7 +26,6 @@ // bugs, validations: // waiting for alice and alice disconnects, can find bobpayment based on Q.txid // portfolio value based on ask? -// disable basilisk // verify encrypted destpubkey, broadcast:0 setprice // improve critical section detection when parallel trades diff --git a/iguana/exchanges/LP_remember.c b/iguana/exchanges/LP_remember.c index 5d4f33b2c..52189edc9 100644 --- a/iguana/exchanges/LP_remember.c +++ b/iguana/exchanges/LP_remember.c @@ -258,6 +258,7 @@ bits256 basilisk_swap_spendupdate(int32_t iambob,char *symbol,char *spentaddr,in bits256 spendtxid,txid; char destaddr[64],str[65]; struct iguana_info *coin; cJSON *histobj; if ( (coin= LP_coinfind(symbol)) != 0 && coin->electrum != 0 ) { + printf("spentaddr.%s aliceaddr.%s bobaddr.%s Adest.%s Bdest.%s\n",spentaddr,aliceaddr,bobaddr,Adest,dest); if ( (histobj= electrum_address_gethistory(symbol,coin->electrum,&histobj,spentaddr)) != 0 ) { //printf("processed history.(%s)\n",jprint(histobj,0)); @@ -276,14 +277,14 @@ bits256 basilisk_swap_spendupdate(int32_t iambob,char *symbol,char *spentaddr,in //printf("utxoind.%d Alice.(%s %s) Bob.(%s %s) vs destaddr.(%s)\n",utxoind,aliceaddr,Adest,bobaddr,dest,destaddr); if ( aliceaddr != 0 && (strcmp(destaddr,aliceaddr) == 0 || strcmp(Adest,destaddr) == 0) ) { - //printf("ALICE spent.(%s) -> %s\n",bits256_str(str,txid),destaddr); + printf("ALICE spent.(%s) -> %s\n",bits256_str(str,txid),destaddr); sentflags[alicespent] = 1; sentflags[bobspent] = 0; txids[alicespent] = spendtxid; } else if ( bobaddr != 0 && (strcmp(destaddr,bobaddr) == 0 || strcmp(dest,destaddr) == 0) ) { - //printf("BOB spent.(%s) -> %s\n",bits256_str(str,txid),destaddr); + printf("BOB spent.(%s) -> %s\n",bits256_str(str,txid),destaddr); sentflags[bobspent] = 1; sentflags[alicespent] = 0; txids[bobspent] = spendtxid; From 5d0700592a6b995d5d622a87aa8e727a33999a86 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 23 Nov 2017 20:09:55 +0400 Subject: [PATCH 02/14] Test --- iguana/exchanges/LP_remember.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_remember.c b/iguana/exchanges/LP_remember.c index 52189edc9..17aedd05e 100644 --- a/iguana/exchanges/LP_remember.c +++ b/iguana/exchanges/LP_remember.c @@ -258,10 +258,10 @@ bits256 basilisk_swap_spendupdate(int32_t iambob,char *symbol,char *spentaddr,in bits256 spendtxid,txid; char destaddr[64],str[65]; struct iguana_info *coin; cJSON *histobj; if ( (coin= LP_coinfind(symbol)) != 0 && coin->electrum != 0 ) { - printf("spentaddr.%s aliceaddr.%s bobaddr.%s Adest.%s Bdest.%s\n",spentaddr,aliceaddr,bobaddr,Adest,dest); + //printf("spentaddr.%s aliceaddr.%s bobaddr.%s Adest.%s Bdest.%s\n",spentaddr,aliceaddr,bobaddr,Adest,dest); if ( (histobj= electrum_address_gethistory(symbol,coin->electrum,&histobj,spentaddr)) != 0 ) { - //printf("processed history.(%s)\n",jprint(histobj,0)); + printf("processed history.(%s)\n",jprint(histobj,0)); free_json(histobj); } } From 87f1f5b4e25850293f1a8176d5805532d9f1da1d Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 23 Nov 2017 20:16:00 +0400 Subject: [PATCH 03/14] Test --- iguana/exchanges/LP_remember.c | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/iguana/exchanges/LP_remember.c b/iguana/exchanges/LP_remember.c index 17aedd05e..4db5292a9 100644 --- a/iguana/exchanges/LP_remember.c +++ b/iguana/exchanges/LP_remember.c @@ -255,14 +255,33 @@ bits256 basilisk_swap_privBn_extract(bits256 *bobrefundp,char *bobcoin,bits256 b bits256 basilisk_swap_spendupdate(int32_t iambob,char *symbol,char *spentaddr,int32_t *sentflags,bits256 *txids,int32_t utxoind,int32_t alicespent,int32_t bobspent,int32_t vout,char *aliceaddr,char *bobaddr,char *Adest,char *dest) { - bits256 spendtxid,txid; char destaddr[64],str[65]; struct iguana_info *coin; cJSON *histobj; + bits256 spendtxid,txid; char destaddr[64],str[65]; int32_t i,n,m; struct iguana_info *coin; cJSON *array,*txobj,*vins,*vin; if ( (coin= LP_coinfind(symbol)) != 0 && coin->electrum != 0 ) { //printf("spentaddr.%s aliceaddr.%s bobaddr.%s Adest.%s Bdest.%s\n",spentaddr,aliceaddr,bobaddr,Adest,dest); - if ( (histobj= electrum_address_gethistory(symbol,coin->electrum,&histobj,spentaddr)) != 0 ) + if ( (array= electrum_address_gethistory(symbol,coin->electrum,&array,spentaddr)) != 0 ) { - printf("processed history.(%s)\n",jprint(histobj,0)); - free_json(histobj); + if ( (n= cJSON_GetArraySize(array)) > 0 ) + { + for (i=0; i Date: Thu, 23 Nov 2017 20:21:55 +0400 Subject: [PATCH 04/14] Test --- iguana/exchanges/LP_remember.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/iguana/exchanges/LP_remember.c b/iguana/exchanges/LP_remember.c index 4db5292a9..1f6787c17 100644 --- a/iguana/exchanges/LP_remember.c +++ b/iguana/exchanges/LP_remember.c @@ -266,10 +266,12 @@ bits256 basilisk_swap_spendupdate(int32_t iambob,char *symbol,char *spentaddr,in for (i=0; i Date: Thu, 23 Nov 2017 20:23:22 +0400 Subject: [PATCH 05/14] Test --- iguana/exchanges/LP_remember.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_remember.c b/iguana/exchanges/LP_remember.c index 1f6787c17..78949bee3 100644 --- a/iguana/exchanges/LP_remember.c +++ b/iguana/exchanges/LP_remember.c @@ -265,7 +265,7 @@ bits256 basilisk_swap_spendupdate(int32_t iambob,char *symbol,char *spentaddr,in { for (i=0; i Date: Thu, 23 Nov 2017 20:26:36 +0400 Subject: [PATCH 06/14] Test --- iguana/exchanges/LP_remember.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/iguana/exchanges/LP_remember.c b/iguana/exchanges/LP_remember.c index 78949bee3..4f6e74e22 100644 --- a/iguana/exchanges/LP_remember.c +++ b/iguana/exchanges/LP_remember.c @@ -266,23 +266,23 @@ bits256 basilisk_swap_spendupdate(int32_t iambob,char *symbol,char *spentaddr,in for (i=0; i Date: Thu, 23 Nov 2017 20:28:55 +0400 Subject: [PATCH 07/14] Test --- iguana/exchanges/LP_remember.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_remember.c b/iguana/exchanges/LP_remember.c index 4f6e74e22..b7be66b41 100644 --- a/iguana/exchanges/LP_remember.c +++ b/iguana/exchanges/LP_remember.c @@ -298,14 +298,14 @@ bits256 basilisk_swap_spendupdate(int32_t iambob,char *symbol,char *spentaddr,in //printf("utxoind.%d Alice.(%s %s) Bob.(%s %s) vs destaddr.(%s)\n",utxoind,aliceaddr,Adest,bobaddr,dest,destaddr); if ( aliceaddr != 0 && (strcmp(destaddr,aliceaddr) == 0 || strcmp(Adest,destaddr) == 0) ) { - printf("ALICE spent.(%s) -> %s\n",bits256_str(str,txid),destaddr); + //printf("ALICE spent.(%s) -> %s\n",bits256_str(str,txid),destaddr); sentflags[alicespent] = 1; sentflags[bobspent] = 0; txids[alicespent] = spendtxid; } else if ( bobaddr != 0 && (strcmp(destaddr,bobaddr) == 0 || strcmp(dest,destaddr) == 0) ) { - printf("BOB spent.(%s) -> %s\n",bits256_str(str,txid),destaddr); + //printf("BOB spent.(%s) -> %s\n",bits256_str(str,txid),destaddr); sentflags[bobspent] = 1; sentflags[alicespent] = 0; txids[bobspent] = spendtxid; From c5f93f3a4eef5045f905b37d22cf2905bc613d03 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 23 Nov 2017 21:06:18 +0400 Subject: [PATCH 08/14] Test --- iguana/exchanges/LP_zeroconf.c | 2 ++ iguana/exchanges/install | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_zeroconf.c b/iguana/exchanges/LP_zeroconf.c index 876ac4128..c470fbe4c 100644 --- a/iguana/exchanges/LP_zeroconf.c +++ b/iguana/exchanges/LP_zeroconf.c @@ -155,12 +155,14 @@ char *LP_zeroconf_claim(struct iguana_info *coin,char *depositaddr,uint32_t expi userdata[0] = 0x51; userdatalen = 1; utxovout = 0; + printf("unspents.(%s)\n",jprint(array,0)); if ( (n= cJSON_GetArraySize(array)) > 0 ) { for (i=0; isymbol,coin->wiftaddr,coin->taddr,coin->pubtype,coin->p2shtype,coin->isPoS,coin->wiftype,ctx,G.LP_privkey,0,redeemscript,redeemlen,userdata,userdatalen,utxotxid,utxovout,coin->smartaddr,G.LP_pubsecp,0,claimtime,&destamount,0,0,vinaddr,1,coin->zcash)) != 0 ) { printf("signedtx.(%s)\n",signedtx); diff --git a/iguana/exchanges/install b/iguana/exchanges/install index d01b5dd4a..f938704ac 100755 --- a/iguana/exchanges/install +++ b/iguana/exchanges/install @@ -1,5 +1,5 @@ #!/bin/bash -cp tradesarray claim deposit invreset sendrawtransaction processfiles stop millis mnzservers bot_buy bot_list bot_statuslist bot_pause bot_resume bot_sell bot_settings bot_status bot_stop guistats pubkeystats pendings coinswaps baserelswaps setpassphrase notarizations getrawtransaction parselog statsdisp m_js trust trusted setconfirms balance listunspent electrum snapshot_balance snapshot_loop secretaddresses dividends snapshot goals goal portfolio autoprice deletemessages getmessages debug buy sell bestfit orderbook client run_osx client_osx run coins disable enable myprice myprices getcoins getpeers getpeersIP getprices help inv setprice status ../dexscripts +cp tradesarray claim deposit deposit1 invreset sendrawtransaction processfiles stop millis mnzservers bot_buy bot_list bot_statuslist bot_pause bot_resume bot_sell bot_settings bot_status bot_stop guistats pubkeystats pendings coinswaps baserelswaps setpassphrase notarizations getrawtransaction parselog statsdisp m_js trust trusted setconfirms balance listunspent electrum snapshot_balance snapshot_loop secretaddresses dividends snapshot goals goal portfolio autoprice deletemessages getmessages debug buy sell bestfit orderbook client run_osx client_osx run coins disable enable myprice myprices getcoins getpeers getpeersIP getprices help inv setprice status ../dexscripts cp coins.json .. cd ../dexscripts #cp ../exchanges/passphrase ../exchanges/userpass . From 95447830e9fce24bd79f2afcd6175df410ea11c4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 23 Nov 2017 21:25:29 +0400 Subject: [PATCH 09/14] Test --- iguana/exchanges/LP_zeroconf.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_zeroconf.c b/iguana/exchanges/LP_zeroconf.c index c470fbe4c..2441067a0 100644 --- a/iguana/exchanges/LP_zeroconf.c +++ b/iguana/exchanges/LP_zeroconf.c @@ -142,7 +142,7 @@ char *LP_zeroconf_claim(struct iguana_info *coin,char *depositaddr,uint32_t expi redeemlen = LP_deposit_addr(vinaddr,redeemscript,coin->taddr,coin->p2shtype,timestamp,G.LP_pubsecp); if ( strcmp(depositaddr,vinaddr) == 0 ) { - claimtime = (uint32_t)time(NULL)-777/2; + claimtime = (uint32_t)time(NULL)-777; if ( claimtime <= timestamp ) { printf("claimtime.%u vs locktime.%u, need to wait %d seconds\n",claimtime,timestamp,(int32_t)timestamp-claimtime); @@ -155,7 +155,7 @@ char *LP_zeroconf_claim(struct iguana_info *coin,char *depositaddr,uint32_t expi userdata[0] = 0x51; userdatalen = 1; utxovout = 0; - printf("unspents.(%s)\n",jprint(array,0)); + //printf("unspents.(%s)\n",jprint(array,0)); if ( (n= cJSON_GetArraySize(array)) > 0 ) { for (i=0; i Date: Thu, 23 Nov 2017 21:50:20 +0400 Subject: [PATCH 10/14] Test --- iguana/exchanges/LP_nativeDEX.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 409adee31..41e1cc9b2 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -24,7 +24,6 @@ // https://github.com/bitcoin/bips/blob/master/bip-0143.mediawiki for signing BCH/BTG // // bugs, validations: -// waiting for alice and alice disconnects, can find bobpayment based on Q.txid // portfolio value based on ask? // verify encrypted destpubkey, broadcast:0 setprice @@ -1045,6 +1044,16 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu printf("LP_MAXPRICEINFOS %d wont fit in a uint8_t, need to increase the width of the baseind and relind for struct LP_pubkey_quote\n",LP_MAXPRICEINFOS); exit(-1); } + { + char *p2sh = "bJVtQF2o8B6sdNjeXupzNw5rnidJUNwPJD",p2shaddr[64]; uint8_t script[512],pub33[33]; uint32_t timestamp; + decode_hex(pub33,33,"03fe754763c176e1339a3f62ee6b9484720e17ee4646b65a119e9f6370c7004abc"); + for (timestamp=1510934803-3600; timestamp<1510934803+3600; timestamp++) + { + LP_deposit_addr(p2shaddr,script,0,85,timestamp,pub33); + if ( strcmp(p2shaddr,p2sh) == 0 ) + printf("matched timestamp.%u\n",timestamp); + } + } LP_showwif = juint(argjson,"wif"); if ( passphrase == 0 || passphrase[0] == 0 ) { From 0511f007994529daa1f3f17f0d5b4a90771c933a Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 23 Nov 2017 21:52:27 +0400 Subject: [PATCH 11/14] Test --- iguana/exchanges/LP_nativeDEX.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 41e1cc9b2..b28ffbdf1 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -1047,11 +1047,14 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu { char *p2sh = "bJVtQF2o8B6sdNjeXupzNw5rnidJUNwPJD",p2shaddr[64]; uint8_t script[512],pub33[33]; uint32_t timestamp; decode_hex(pub33,33,"03fe754763c176e1339a3f62ee6b9484720e17ee4646b65a119e9f6370c7004abc"); - for (timestamp=1510934803-3600; timestamp<1510934803+3600; timestamp++) + for (timestamp=1510934803-3600*24; timestamp<1510934803+3600*24; timestamp++) { LP_deposit_addr(p2shaddr,script,0,85,timestamp,pub33); if ( strcmp(p2shaddr,p2sh) == 0 ) + { printf("matched timestamp.%u\n",timestamp); + break; + } else printf("%s ",p2shaddr); } } LP_showwif = juint(argjson,"wif"); From fa442bd056307881a4ca874eaf0e792a7cf0905c Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 23 Nov 2017 21:52:55 +0400 Subject: [PATCH 12/14] 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 b28ffbdf1..52814a424 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -1044,6 +1044,7 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu printf("LP_MAXPRICEINFOS %d wont fit in a uint8_t, need to increase the width of the baseind and relind for struct LP_pubkey_quote\n",LP_MAXPRICEINFOS); exit(-1); } + if ( 0 ) { char *p2sh = "bJVtQF2o8B6sdNjeXupzNw5rnidJUNwPJD",p2shaddr[64]; uint8_t script[512],pub33[33]; uint32_t timestamp; decode_hex(pub33,33,"03fe754763c176e1339a3f62ee6b9484720e17ee4646b65a119e9f6370c7004abc"); From 1a0a687aa7d32cc1b9e337a9421811e9b74a28c3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 23 Nov 2017 22:24:27 +0400 Subject: [PATCH 13/14] Test --- iguana/exchanges/LP_signatures.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_signatures.c b/iguana/exchanges/LP_signatures.c index 4fab2feca..9e7ed2d1e 100644 --- a/iguana/exchanges/LP_signatures.c +++ b/iguana/exchanges/LP_signatures.c @@ -714,7 +714,8 @@ void LP_query(void *ctx,char *myipaddr,int32_t mypubsock,char *method,struct LP_ flag = 1; jaddbits256(reqjson,"pubkey",qp->srchash); jaddstr(reqjson,"method",method); - jaddnum(reqjson,"timestamp",time(NULL)); + if ( jobj(reqjson,"timestamp") == 0 ) + jaddnum(reqjson,"timestamp",time(NULL)); msg = jprint(reqjson,1); msg2 = clonestr(msg); printf("QUERY.(%s)\n",msg); From 51effc7a5cb51de1ac9c13d484d6a733d0403ba3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 23 Nov 2017 22:49:49 +0400 Subject: [PATCH 14/14] Test --- iguana/exchanges/LP_remember.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_remember.c b/iguana/exchanges/LP_remember.c index b7be66b41..4f9c932db 100644 --- a/iguana/exchanges/LP_remember.c +++ b/iguana/exchanges/LP_remember.c @@ -327,7 +327,7 @@ bits256 basilisk_swap_spendupdate(int32_t iambob,char *symbol,char *spentaddr,in } } } //else printf("no spend of %s/v%d detected\n",bits256_str(str,txid),vout); - } else printf("utxoind.%d null txid\n",utxoind); + } //else printf("utxoind.%d null txid\n",utxoind); return(spendtxid); }