From 991b58637196c1d1590125f073c46cc0d5c0ebe5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 14 Sep 2017 18:32:31 +0200 Subject: [PATCH 01/44] Test --- iguana/exchanges/LP_utxos.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/iguana/exchanges/LP_utxos.c b/iguana/exchanges/LP_utxos.c index d9cde9716..22d3db438 100644 --- a/iguana/exchanges/LP_utxos.c +++ b/iguana/exchanges/LP_utxos.c @@ -879,9 +879,9 @@ uint64_t LP_privkey_init(int32_t mypubsock,struct iguana_info *coin,bits256 mypr //printf("array.%d\n",n); while ( used < n-1 ) { - //for (i=0; i= 0 ) { item = jitem(array,i); @@ -904,7 +904,7 @@ uint64_t LP_privkey_init(int32_t mypubsock,struct iguana_info *coin,bits256 mypr else targetval = (depositval / 9) * 8 + 2*txfee; if ( targetval < txfee*2 ) targetval = txfee*2; - //printf("iambob.%d i.%d deposit %.8f min %.8f target %.8f\n",iambob,i,dstr(depositval),dstr((1+LP_MINSIZE_TXFEEMULT)*txfee),dstr(targetval)); + printf("iambob.%d i.%d deposit %.8f min %.8f target %.8f\n",iambob,i,dstr(depositval),dstr((1+LP_MINSIZE_TXFEEMULT)*txfee),dstr(targetval)); if ( depositval < (1+LP_MINSIZE_TXFEEMULT)*txfee ) continue; i = -1; From 99ddf09a5447e82353907c2f5ab6324ff76b8639 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 14 Sep 2017 18:39:51 +0200 Subject: [PATCH 02/44] Test --- iguana/exchanges/LP_utxos.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_utxos.c b/iguana/exchanges/LP_utxos.c index 22d3db438..1c7ec0ddc 100644 --- a/iguana/exchanges/LP_utxos.c +++ b/iguana/exchanges/LP_utxos.c @@ -385,7 +385,7 @@ int32_t LP_inventory_prevent(int32_t iambob,bits256 txid,int32_t vout) { //if ( utxo->T.spentflag != 0 ) { - //char str[65]; printf("prevent adding %s/v%d to inventory\n",bits256_str(str,txid),vout); + char str[65]; printf("prevent adding %s/v%d to inventory\n",bits256_str(str,txid),vout); return(1); } } From e2fccb2ee0237637bbd3660e3b83a6e545ee1ad3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 14 Sep 2017 18:45:40 +0200 Subject: [PATCH 03/44] Test --- iguana/exchanges/LP_utxos.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_utxos.c b/iguana/exchanges/LP_utxos.c index 1c7ec0ddc..c52bfc6e7 100644 --- a/iguana/exchanges/LP_utxos.c +++ b/iguana/exchanges/LP_utxos.c @@ -779,7 +779,7 @@ cJSON *LP_inventory(char *symbol,int32_t iambob) else myipaddr = "127.0.0.1"; HASH_ITER(hh,LP_utxoinfos[iambob],utxo,tmp) { - //char str[65]; printf("iambob.%d iterate %s\n",iambob,bits256_str(str,LP_mypub25519)); + char str[65]; printf("iambob.%d iterate %s\n",iambob,bits256_str(str,LP_mypub25519)); if ( LP_isunspent(utxo) != 0 && strcmp(symbol,utxo->coin) == 0 && utxo->iambob == iambob && LP_ismine(utxo) > 0 ) { u = (iambob != 0) ? utxo->deposit : utxo->fee; @@ -793,7 +793,7 @@ cJSON *LP_inventory(char *symbol,int32_t iambob) LP_utxo_clientpublish(utxo); jaddi(array,LP_inventoryjson(cJSON_CreateObject(),utxo)); } - //else printf("skip %s %d %d %d %d\n",bits256_str(str,utxo->pubkey),LP_isunspent(utxo) != 0,strcmp(symbol,utxo->coin) == 0,utxo->iambob == iambob,LP_ismine(utxo) > 0); + else printf("skip %s %d %d %d %d\n",bits256_str(str,utxo->pubkey),LP_isunspent(utxo) != 0,strcmp(symbol,utxo->coin) == 0,utxo->iambob == iambob,LP_ismine(utxo) > 0); } return(array); } From 93548b818ca1d381eba547c3f89bd6d4accfe7d7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 14 Sep 2017 18:49:39 +0200 Subject: [PATCH 04/44] Test --- iguana/exchanges/LP_utxos.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_utxos.c b/iguana/exchanges/LP_utxos.c index c52bfc6e7..83adff265 100644 --- a/iguana/exchanges/LP_utxos.c +++ b/iguana/exchanges/LP_utxos.c @@ -793,7 +793,8 @@ cJSON *LP_inventory(char *symbol,int32_t iambob) LP_utxo_clientpublish(utxo); jaddi(array,LP_inventoryjson(cJSON_CreateObject(),utxo)); } - else printf("skip %s %d %d %d %d\n",bits256_str(str,utxo->pubkey),LP_isunspent(utxo) != 0,strcmp(symbol,utxo->coin) == 0,utxo->iambob == iambob,LP_ismine(utxo) > 0); + else if ( LP_ismine(utxo) > 0 ) + printf("skip %s %s %d %d %d %d\n",utxo->coin,bits256_str(str,u.txid),LP_isunspent(utxo) != 0,strcmp(symbol,utxo->coin) == 0,utxo->iambob == iambob,LP_ismine(utxo) > 0); } return(array); } From 7113bd84508ebec6c2b959c3c2bc6606bbf626f7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 14 Sep 2017 18:51:52 +0200 Subject: [PATCH 05/44] Test --- iguana/exchanges/LP_utxos.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_utxos.c b/iguana/exchanges/LP_utxos.c index 83adff265..b33ae0bc6 100644 --- a/iguana/exchanges/LP_utxos.c +++ b/iguana/exchanges/LP_utxos.c @@ -779,7 +779,8 @@ cJSON *LP_inventory(char *symbol,int32_t iambob) else myipaddr = "127.0.0.1"; HASH_ITER(hh,LP_utxoinfos[iambob],utxo,tmp) { - char str[65]; printf("iambob.%d iterate %s\n",iambob,bits256_str(str,LP_mypub25519)); + char str[65]; + printf("iambob.%d iterate %s\n",iambob,bits256_str(str,LP_mypub25519)); if ( LP_isunspent(utxo) != 0 && strcmp(symbol,utxo->coin) == 0 && utxo->iambob == iambob && LP_ismine(utxo) > 0 ) { u = (iambob != 0) ? utxo->deposit : utxo->fee; @@ -787,6 +788,7 @@ cJSON *LP_inventory(char *symbol,int32_t iambob) { if ( utxo->T.spentflag == 0 ) utxo->T.spentflag = (uint32_t)time(NULL); + printf("ineligible %.8f %.8f\n",dstr(val),dstr(val2)); continue; } if ( iambob != 0 ) From b322b16f4c159210ab513a911f05c5d1696bb8d6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 14 Sep 2017 18:54:53 +0200 Subject: [PATCH 06/44] Test --- iguana/exchanges/LP_socket.c | 2 +- iguana/exchanges/LP_utxos.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_socket.c b/iguana/exchanges/LP_socket.c index 536700a3e..2e39663f8 100644 --- a/iguana/exchanges/LP_socket.c +++ b/iguana/exchanges/LP_socket.c @@ -447,7 +447,7 @@ cJSON *electrum_address_listunspent(char *symbol,struct electrum_info *ep,cJSON { cJSON *retjson=0; struct iguana_info *coin = LP_coinfind(symbol); //printf("electrum listunspent last.(%s lag %d)\n",coin->lastunspent,(int32_t)(time(NULL) - coin->unspenttime)); - if ( strcmp(coin->lastunspent,addr) != 0 || time(NULL) > coin->unspenttime+10 ) + //if ( strcmp(coin->lastunspent,addr) != 0 || time(NULL) > coin->unspenttime+10 ) { if ( (retjson= electrum_strarg(symbol,ep,retjsonp,"blockchain.address.listunspent",addr,ELECTRUM_TIMEOUT)) != 0 ) { diff --git a/iguana/exchanges/LP_utxos.c b/iguana/exchanges/LP_utxos.c index b33ae0bc6..7fd9845f0 100644 --- a/iguana/exchanges/LP_utxos.c +++ b/iguana/exchanges/LP_utxos.c @@ -788,7 +788,7 @@ cJSON *LP_inventory(char *symbol,int32_t iambob) { if ( utxo->T.spentflag == 0 ) utxo->T.spentflag = (uint32_t)time(NULL); - printf("ineligible %.8f %.8f\n",dstr(val),dstr(val2)); + printf("%s %s ineligible %.8f %.8f\n",utxo->coin,bits256_str(str,u.txid),dstr(val),dstr(val2)); continue; } if ( iambob != 0 ) From c941ed0b9bb1776ad5f13d9eb6814e869caf716b Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 14 Sep 2017 18:58:37 +0200 Subject: [PATCH 07/44] Test --- iguana/exchanges/LP_scan.c | 1 + iguana/exchanges/LP_utxos.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_scan.c b/iguana/exchanges/LP_scan.c index 41c7308ec..24586897f 100644 --- a/iguana/exchanges/LP_scan.c +++ b/iguana/exchanges/LP_scan.c @@ -127,6 +127,7 @@ int32_t LP_transactioninit(struct iguana_info *coin,bits256 txid,int32_t iter) vouts = jarray(&numvouts,txobj,"vout"); if ( iter == 0 && vouts != 0 && (tx= LP_transactionadd(coin,txid,height,numvouts,numvins)) != 0 ) { + printf("create txid numvouts.%d numvins.%d\n",numvouts,numvins); for (i=0; icoin) == 0 && utxo->iambob == iambob && LP_ismine(utxo) > 0 ) { u = (iambob != 0) ? utxo->deposit : utxo->fee; From e1977fc1904f40aafc7837baad23a9f4ce5e4e24 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 14 Sep 2017 19:02:44 +0200 Subject: [PATCH 08/44] Test --- iguana/exchanges/LP_utxos.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_utxos.c b/iguana/exchanges/LP_utxos.c index dbd1badbf..9b5e760e5 100644 --- a/iguana/exchanges/LP_utxos.c +++ b/iguana/exchanges/LP_utxos.c @@ -385,7 +385,7 @@ int32_t LP_inventory_prevent(int32_t iambob,bits256 txid,int32_t vout) { //if ( utxo->T.spentflag != 0 ) { - char str[65]; printf("prevent adding %s/v%d to inventory\n",bits256_str(str,txid),vout); + char str[65]; printf("prevent adding iambob.%d %s/v%d to inventory\n",iambob,bits256_str(str,txid),vout); return(1); } } @@ -875,7 +875,12 @@ uint64_t LP_privkey_init(int32_t mypubsock,struct iguana_info *coin,bits256 mypr { //printf("%s\n",jprint(item,0)); values[i] = satoshis; - } else used++; + } + else + { + printf("skip.(%s)\n",jprint(item,0)); + used++; + } } //printf("%.8f ",dstr(satoshis)); } From b2db5bbd4b07a7bbba0caf340b76f914bc6262b8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 14 Sep 2017 19:05:32 +0200 Subject: [PATCH 09/44] Test --- iguana/exchanges/LP_utxos.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_utxos.c b/iguana/exchanges/LP_utxos.c index 9b5e760e5..1fa9a1a7d 100644 --- a/iguana/exchanges/LP_utxos.c +++ b/iguana/exchanges/LP_utxos.c @@ -878,7 +878,7 @@ uint64_t LP_privkey_init(int32_t mypubsock,struct iguana_info *coin,bits256 mypr } else { - printf("skip.(%s)\n",jprint(item,0)); + printf("skip.(%s) coinht.%d\n",jprint(item,0),coin->height); used++; } } From f8dc5b24e4e617c0752f2247670c23008ed98425 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 14 Sep 2017 19:10:41 +0200 Subject: [PATCH 10/44] Test --- iguana/exchanges/LP_utxos.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/iguana/exchanges/LP_utxos.c b/iguana/exchanges/LP_utxos.c index 1fa9a1a7d..1f7a53aa6 100644 --- a/iguana/exchanges/LP_utxos.c +++ b/iguana/exchanges/LP_utxos.c @@ -786,8 +786,8 @@ cJSON *LP_inventory(char *symbol,int32_t iambob) u = (iambob != 0) ? utxo->deposit : utxo->fee; if ( LP_iseligible(&val,&val2,iambob,utxo->coin,utxo->payment.txid,utxo->payment.vout,utxo->S.satoshis,u.txid,u.vout) == 0 ) { - if ( utxo->T.spentflag == 0 ) - utxo->T.spentflag = (uint32_t)time(NULL); + //if ( utxo->T.spentflag == 0 ) + // utxo->T.spentflag = (uint32_t)time(NULL); printf("%s %s ineligible %.8f %.8f\n",utxo->coin,bits256_str(str,u.txid),dstr(val),dstr(val2)); continue; } @@ -796,7 +796,7 @@ cJSON *LP_inventory(char *symbol,int32_t iambob) jaddi(array,LP_inventoryjson(cJSON_CreateObject(),utxo)); } else if ( LP_ismine(utxo) > 0 ) - printf("skip %s %s %d %d %d %d\n",utxo->coin,bits256_str(str,u.txid),LP_isunspent(utxo) != 0,strcmp(symbol,utxo->coin) == 0,utxo->iambob == iambob,LP_ismine(utxo) > 0); + printf("skip %s %s %d %d %d %d\n",utxo->coin,bits256_str(str,utxo->payment.txid),LP_isunspent(utxo) != 0,strcmp(symbol,utxo->coin) == 0,utxo->iambob == iambob,LP_ismine(utxo) > 0); } return(array); } From 9a2d38d9f42946020e69b9e618e95e1cea5d416c Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 14 Sep 2017 19:14:50 +0200 Subject: [PATCH 11/44] Test --- iguana/exchanges/LP_utxos.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_utxos.c b/iguana/exchanges/LP_utxos.c index 1f7a53aa6..5ce06ba46 100644 --- a/iguana/exchanges/LP_utxos.c +++ b/iguana/exchanges/LP_utxos.c @@ -383,7 +383,7 @@ int32_t LP_inventory_prevent(int32_t iambob,bits256 txid,int32_t vout) struct LP_utxoinfo *utxo; if ( (utxo= LP_utxofind(iambob,txid,vout)) != 0 || (utxo= LP_utxo2find(iambob,txid,vout)) != 0 ) { - //if ( utxo->T.spentflag != 0 ) + if ( utxo->T.spentflag != 0 ) { char str[65]; printf("prevent adding iambob.%d %s/v%d to inventory\n",iambob,bits256_str(str,txid),vout); return(1); From 4c763f559080e5d97df3b5c51045d5d727e0b1d1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 14 Sep 2017 19:18:54 +0200 Subject: [PATCH 12/44] Test --- iguana/exchanges/LP_ordermatch.c | 4 ++-- iguana/exchanges/LP_utxos.c | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index b0a7bc083..52d4f418d 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -644,8 +644,8 @@ struct LP_utxoinfo *LP_bestutxo(double *ordermatchpricep,int64_t *bestsatoshisp, else { printf("ineligible.(%.8f %.8f)\n",price,dstr(butxo->S.satoshis)); - if ( butxo->T.spentflag == 0 ) - butxo->T.spentflag = (uint32_t)time(NULL); + //if ( butxo->T.spentflag == 0 ) + // butxo->T.spentflag = (uint32_t)time(NULL); } } else diff --git a/iguana/exchanges/LP_utxos.c b/iguana/exchanges/LP_utxos.c index 5ce06ba46..d0c778cd1 100644 --- a/iguana/exchanges/LP_utxos.c +++ b/iguana/exchanges/LP_utxos.c @@ -471,7 +471,7 @@ char *LP_spentcheck(cJSON *argjson) LP_mypeer->numutxos--; utxo->T.spentflag = (uint32_t)time(NULL); retval++; - //printf("indeed txid was spent\n"); + printf("indeed txid was spent\n"); } } } @@ -598,8 +598,8 @@ struct LP_utxoinfo *LP_utxoadd(int32_t iambob,int32_t mypubsock,char *symbol,bit char str[65],str2[65],str3[65],str4[65],str5[65],str6[65]; if ( utxo->T.spentflag != 0 || LP_txvalue(0,utxo->coin,utxo->payment.txid,utxo->payment.vout) < utxo->payment.value || LP_txvalue(0,utxo->coin,u.txid,u.vout) < u.value ) { - if ( utxo->T.spentflag == 0 ) - utxo->T.spentflag = (uint32_t)time(NULL); + //if ( utxo->T.spentflag == 0 ) + // utxo->T.spentflag = (uint32_t)time(NULL); printf("original utxo pair not valid\n"); if ( dispflag != 0 ) printf("error on subsequent utxo iambob.%d %.8f %.8f add.(%s %s) when.(%s %s) %d %d %d %d %d %d %d %d %d %d %d pubkeys.(%s vs %s)\n",iambob,dstr(val),dstr(val2),bits256_str(str,txid),bits256_str(str2,txid2),bits256_str(str3,utxo->payment.txid),bits256_str(str4,utxo->deposit.txid),bits256_cmp(txid,utxo->payment.txid) != 0,bits256_cmp(txid2,u.txid) != 0,vout != utxo->payment.vout,tmpsatoshis != utxo->S.satoshis,vout2 != u.vout,value2 != u.value,strcmp(symbol,utxo->coin) != 0,strcmp(spendscript,utxo->spendscript) != 0,strcmp(coinaddr,utxo->coinaddr) != 0,bits256_cmp(pubkey,utxo->pubkey) != 0,value != utxo->payment.value,bits256_str(str5,pubkey),bits256_str(str6,utxo->pubkey)); From e03fd632551a329fae73458e2cc234afd616bf6b Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 14 Sep 2017 19:53:35 +0200 Subject: [PATCH 13/44] Test --- iguana/exchanges/LP_prices.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_prices.c b/iguana/exchanges/LP_prices.c index 699e3e8b4..0d2cbf037 100644 --- a/iguana/exchanges/LP_prices.c +++ b/iguana/exchanges/LP_prices.c @@ -111,7 +111,7 @@ void LP_address_monitor(struct LP_pubkeyinfo *pubp) { if ( (retjson= electrum_address_subscribe(coin->symbol,coin->electrum,&retjson,coinaddr)) != 0 ) { - printf("%s MONITOR.(%s) -> %p\n",coin->symbol,coinaddr,retjson); + printf("%s MONITOR.(%s) -> %s\n",coin->symbol,coinaddr,jprint(retjson,0)); free_json(retjson); } } From 5f2b5f4c477bff9d24514e15229392713b9d5fa9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 14 Sep 2017 19:55:19 +0200 Subject: [PATCH 14/44] 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 2e39663f8..4cac73c10 100644 --- a/iguana/exchanges/LP_socket.c +++ b/iguana/exchanges/LP_socket.c @@ -598,7 +598,7 @@ int32_t LP_recvfunc(struct electrum_info *ep,char *str,int32_t len) if ( (strjson= cJSON_Parse(str)) != 0 ) { resultjson = jobj(strjson,"result"); - //printf("strjson.(%s)\n",jprint(strjson,0)); + printf("strjson.(%s)\n",jprint(strjson,0)); if ( (method= jstr(strjson,"method")) != 0 ) { if ( strcmp(method,"blockchain.headers.subscribe") == 0 ) From 319110dcab1a24263bf3d58b6d43e33651214eba Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 14 Sep 2017 21:22:38 +0200 Subject: [PATCH 15/44] Test --- iguana/exchanges/LP_scan.c | 2 +- iguana/exchanges/LP_utxos.c | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/iguana/exchanges/LP_scan.c b/iguana/exchanges/LP_scan.c index 24586897f..534c76548 100644 --- a/iguana/exchanges/LP_scan.c +++ b/iguana/exchanges/LP_scan.c @@ -127,7 +127,7 @@ int32_t LP_transactioninit(struct iguana_info *coin,bits256 txid,int32_t iter) vouts = jarray(&numvouts,txobj,"vout"); if ( iter == 0 && vouts != 0 && (tx= LP_transactionadd(coin,txid,height,numvouts,numvins)) != 0 ) { - printf("create txid numvouts.%d numvins.%d\n",numvouts,numvins); + //printf("create txid numvouts.%d numvins.%d\n",numvouts,numvins); for (i=0; ioutpoints[vout].spendheight > 0 ) + utxo->T.spentflag = tx->outpoints[vout].spendheight; + else utxo->T.spentflag = 0; + } if ( utxo->T.spentflag != 0 ) { char str[65]; printf("prevent adding iambob.%d %s/v%d to inventory\n",iambob,bits256_str(str,txid),vout); From b68d0806024c3ef2a9167b806652700983c316fc Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 14 Sep 2017 21:25:15 +0200 Subject: [PATCH 16/44] Test --- iguana/exchanges/LP_utxos.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_utxos.c b/iguana/exchanges/LP_utxos.c index 79b64b2ee..900c7451d 100644 --- a/iguana/exchanges/LP_utxos.c +++ b/iguana/exchanges/LP_utxos.c @@ -867,7 +867,7 @@ uint64_t LP_privkey_init(int32_t mypubsock,struct iguana_info *coin,bits256 mypr satoshis = SATOSHIDEN * jdouble(item,"amount"); if ( satoshis == 0 ) satoshis = SATOSHIDEN * jdouble(item,"value"); - if ( LP_inventory_prevent(iambob,jbits256(item,"txid"),juint(item,"vout")) == 0 && jint(item,"confirmations") > 0 ) + if ( LP_inventory_prevent(iambob,coin->symbol,jbits256(item,"txid"),juint(item,"vout")) == 0 && jint(item,"confirmations") > 0 ) { //printf("%s\n",jprint(item,0)); values[i] = satoshis; @@ -877,7 +877,7 @@ uint64_t LP_privkey_init(int32_t mypubsock,struct iguana_info *coin,bits256 mypr { //{"value":1000000,"tx_hash":"4e4f818c53486c0576693b4cd379849e5ff95538b38e4100f48884073a4e7636","tx_pos":0,"height":484877} satoshis = j64bits(item,"value"); - if ( LP_inventory_prevent(iambob,jbits256(item,"tx_hash"),juint(item,"tx_pos")) == 0 && jint(item,"height") < coin->height ) + if ( LP_inventory_prevent(iambob,coin->symbol,jbits256(item,"tx_hash"),juint(item,"tx_pos")) == 0 && jint(item,"height") < coin->height ) { //printf("%s\n",jprint(item,0)); values[i] = satoshis; From afdfc2e13188cebda9d2ac766622cfb1317eda97 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 14 Sep 2017 21:29:11 +0200 Subject: [PATCH 17/44] Test --- iguana/exchanges/LP_scan.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_scan.c b/iguana/exchanges/LP_scan.c index 534c76548..7bd375d93 100644 --- a/iguana/exchanges/LP_scan.c +++ b/iguana/exchanges/LP_scan.c @@ -597,7 +597,7 @@ uint64_t LP_txvalue(char *coinaddr,char *symbol,bits256 txid,int32_t vout) if ( coinaddr != 0 ) { if ( tx->outpoints[vout].coinaddr[0] == 0 ) - LP_txinterestvalue(&tx->outpoints[vout].interest,tx->outpoints[vout].coinaddr,coin,txid,vout); + tx->outpoints[vout].value = LP_txinterestvalue(&tx->outpoints[vout].interest,tx->outpoints[vout].coinaddr,coin,txid,vout); strcpy(coinaddr,tx->outpoints[vout].coinaddr); //printf("(%s) return value %.8f + interest %.8f\n",coinaddr,dstr(tx->outpoints[vout].value),dstr(tx->outpoints[vout].interest)); } From b441fdf0220eaf329d8987f1e69d2fc73f03c3fc Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 14 Sep 2017 21:37:03 +0200 Subject: [PATCH 18/44] Test --- iguana/exchanges/LP_scan.c | 7 ++++--- iguana/exchanges/LP_utxos.c | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/iguana/exchanges/LP_scan.c b/iguana/exchanges/LP_scan.c index 7bd375d93..bef4b3ecd 100644 --- a/iguana/exchanges/LP_scan.c +++ b/iguana/exchanges/LP_scan.c @@ -582,8 +582,9 @@ uint64_t LP_txvalue(char *coinaddr,char *symbol,bits256 txid,int32_t vout) { LP_transactioninit(coin,txid,0); LP_transactioninit(coin,txid,1); + tx = LP_transactionfind(coin,txid); } - if ( (tx= LP_transactionfind(coin,txid)) != 0 ) + if ( tx != 0 ) { if ( vout < tx->numvouts ) { @@ -596,8 +597,8 @@ uint64_t LP_txvalue(char *coinaddr,char *symbol,bits256 txid,int32_t vout) { if ( coinaddr != 0 ) { - if ( tx->outpoints[vout].coinaddr[0] == 0 ) - tx->outpoints[vout].value = LP_txinterestvalue(&tx->outpoints[vout].interest,tx->outpoints[vout].coinaddr,coin,txid,vout); + //if ( tx->outpoints[vout].coinaddr[0] == 0 ) + // tx->outpoints[vout].value = LP_txinterestvalue(&tx->outpoints[vout].interest,tx->outpoints[vout].coinaddr,coin,txid,vout); strcpy(coinaddr,tx->outpoints[vout].coinaddr); //printf("(%s) return value %.8f + interest %.8f\n",coinaddr,dstr(tx->outpoints[vout].value),dstr(tx->outpoints[vout].interest)); } diff --git a/iguana/exchanges/LP_utxos.c b/iguana/exchanges/LP_utxos.c index 900c7451d..c0763b76e 100644 --- a/iguana/exchanges/LP_utxos.c +++ b/iguana/exchanges/LP_utxos.c @@ -317,7 +317,7 @@ int32_t LP_iseligible(uint64_t *valp,uint64_t *val2p,int32_t iambob,char *symbol } } // else printf("no val2\n"); } - // char str[65],str2[65]; printf("spent.%d %s txid or value %.8f < %.8f or val2 %.8f < %.8f, %s/v%d %s/v%d or < 10x txfee %.8f\n",iambob,symbol,dstr(val),dstr(satoshis),dstr(val2),dstr(threshold),bits256_str(str,txid),vout,bits256_str(str2,txid2),vout2,dstr(txfee)); + char str[65],str2[65]; printf("spent.%d %s txid or value %.8f < %.8f or val2 %.8f < %.8f, %s/v%d %s/v%d or < 10x txfee %.8f\n",iambob,symbol,dstr(val),dstr(satoshis),dstr(val2),dstr(threshold),bits256_str(str,txid),vout,bits256_str(str2,txid2),vout2,dstr(txfee)); /*for (iter=0; iter<2; iter++) { if ( (utxo= LP_utxofind(iter,txid,vout)) != 0 ) From e8271b72f8e256e94f0694b919b11674ef513a21 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 14 Sep 2017 21:40:01 +0200 Subject: [PATCH 19/44] Test --- iguana/exchanges/LP_scan.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/iguana/exchanges/LP_scan.c b/iguana/exchanges/LP_scan.c index bef4b3ecd..4b669efa4 100644 --- a/iguana/exchanges/LP_scan.c +++ b/iguana/exchanges/LP_scan.c @@ -143,6 +143,7 @@ int32_t LP_transactioninit(struct iguana_info *coin,bits256 txid,int32_t iter) if ( (address= jstri(addresses,0)) != 0 && strlen(address) < sizeof(tx->outpoints[i].coinaddr) ) { strcpy(tx->outpoints[i].coinaddr,address); + printf("(%s %.8f) ",address,dstr(tx->outpoints[i].value)); } else if ( tx->outpoints[i].value != 0 ) printf("LP_transactioninit: unexpected address.(%s)\n",jprint(addresses,0)); } @@ -150,6 +151,7 @@ int32_t LP_transactioninit(struct iguana_info *coin,bits256 txid,int32_t iter) // printf("LP_transactioninit: pax tx ht.%d i.%d (%s) n.%d\n",height,i,jprint(vout,0),n); } } + printf("numvouts.%d\n",numvouts); } if ( iter == 1 && vins != 0 ) { From f7b059addc010997eee9e2e1bc0d281b68eadeec Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 14 Sep 2017 21:51:52 +0200 Subject: [PATCH 20/44] Test --- iguana/exchanges/LP_socket.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/iguana/exchanges/LP_socket.c b/iguana/exchanges/LP_socket.c index 4cac73c10..54116d0df 100644 --- a/iguana/exchanges/LP_socket.c +++ b/iguana/exchanges/LP_socket.c @@ -306,7 +306,7 @@ struct electrum_info *electrum_server(char *symbol,struct electrum_info *ep) void electrum_process_array(struct iguana_info *coin,cJSON *array) { - int32_t i,n; bits256 txid; cJSON *item; struct LP_transaction *tx; + int32_t i,v,n; char str[65]; uint64_t value; bits256 txid; cJSON *item; struct LP_transaction *tx; if ( array != 0 && coin != 0 && (n= cJSON_GetArraySize(array)) > 0 ) { for (i=0; iheight <= 0 ) + if ( tx != 0 ) { - tx->height = jint(item,"height"); - char str[65]; printf(">>>>>>>>>> set %s <- height %d\n",bits256_str(str,txid),tx->height); + if (tx->height <= 0 ) + { + tx->height = jint(item,"height"); + printf(">>>>>>>>>> set %s <- height %d\n",bits256_str(str,txid),tx->height); + } + if ( (v= jint(item,"tx_pos")) >= 0 && v < tx->numvouts ) + { + value = j64bits(item,"value"); + if ( value != tx->outpoints[v].value ) + { + printf(">>>>>>>>>> set %s/v%d <- %.8f vs %.8f\n",bits256_str(str,txid),v,dstr(value),dstr(tx->outpoints[v].value)); + tx->outpoints[v].value = value; + } + } } } } From f142f310c5bde3eda40ac67a50567119ca29f835 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 14 Sep 2017 21:59:11 +0200 Subject: [PATCH 21/44] Test --- iguana/exchanges/LP_socket.c | 1 + 1 file changed, 1 insertion(+) diff --git a/iguana/exchanges/LP_socket.c b/iguana/exchanges/LP_socket.c index 54116d0df..282e85b9e 100644 --- a/iguana/exchanges/LP_socket.c +++ b/iguana/exchanges/LP_socket.c @@ -335,6 +335,7 @@ void electrum_process_array(struct iguana_info *coin,cJSON *array) tx->outpoints[v].value = value; } } + printf("v.%d numvouts.%d %.8f\n",v,tx->numvouts,dstr(tx->outpoints[v].value)); } } } From a6aede751cdfb6f1f0dbfcec7005bcf7fabf5697 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 14 Sep 2017 22:01:59 +0200 Subject: [PATCH 22/44] Test --- iguana/exchanges/LP_socket.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_socket.c b/iguana/exchanges/LP_socket.c index 282e85b9e..62aa7315f 100644 --- a/iguana/exchanges/LP_socket.c +++ b/iguana/exchanges/LP_socket.c @@ -326,7 +326,7 @@ void electrum_process_array(struct iguana_info *coin,cJSON *array) tx->height = jint(item,"height"); printf(">>>>>>>>>> set %s <- height %d\n",bits256_str(str,txid),tx->height); } - if ( (v= jint(item,"tx_pos")) >= 0 && v < tx->numvouts ) + if ( jobj(item,"tx_pos") != 0 && jobj(item,"value") != 0 && (v= jint(item,"tx_pos")) >= 0 && v < tx->numvouts ) { value = j64bits(item,"value"); if ( value != tx->outpoints[v].value ) @@ -335,7 +335,6 @@ void electrum_process_array(struct iguana_info *coin,cJSON *array) tx->outpoints[v].value = value; } } - printf("v.%d numvouts.%d %.8f\n",v,tx->numvouts,dstr(tx->outpoints[v].value)); } } } From 10492ffd443366b532c9c8b7521511c17888559b Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 14 Sep 2017 22:03:38 +0200 Subject: [PATCH 23/44] Test --- iguana/exchanges/LP_scan.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_scan.c b/iguana/exchanges/LP_scan.c index 4b669efa4..12c2c6c74 100644 --- a/iguana/exchanges/LP_scan.c +++ b/iguana/exchanges/LP_scan.c @@ -143,7 +143,7 @@ int32_t LP_transactioninit(struct iguana_info *coin,bits256 txid,int32_t iter) if ( (address= jstri(addresses,0)) != 0 && strlen(address) < sizeof(tx->outpoints[i].coinaddr) ) { strcpy(tx->outpoints[i].coinaddr,address); - printf("(%s %.8f) ",address,dstr(tx->outpoints[i].value)); + //printf("(%s %.8f) ",address,dstr(tx->outpoints[i].value)); } else if ( tx->outpoints[i].value != 0 ) printf("LP_transactioninit: unexpected address.(%s)\n",jprint(addresses,0)); } @@ -151,7 +151,7 @@ int32_t LP_transactioninit(struct iguana_info *coin,bits256 txid,int32_t iter) // printf("LP_transactioninit: pax tx ht.%d i.%d (%s) n.%d\n",height,i,jprint(vout,0),n); } } - printf("numvouts.%d\n",numvouts); + //printf("numvouts.%d\n",numvouts); } if ( iter == 1 && vins != 0 ) { From 0f502937614e99443f0b8b0a2bc2b51c9159dd3f Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 14 Sep 2017 22:06:43 +0200 Subject: [PATCH 24/44] Test --- iguana/exchanges/LP_socket.c | 1 + 1 file changed, 1 insertion(+) diff --git a/iguana/exchanges/LP_socket.c b/iguana/exchanges/LP_socket.c index 62aa7315f..3357b8ea9 100644 --- a/iguana/exchanges/LP_socket.c +++ b/iguana/exchanges/LP_socket.c @@ -335,6 +335,7 @@ void electrum_process_array(struct iguana_info *coin,cJSON *array) tx->outpoints[v].value = value; } } + printf("v.%d numvouts.%d %.8f (%s)\n",jint(item,"tx_pos"),tx->numvouts,dstr(tx->outpoints[v].value),jprint(item,0)); } } } From da0c247fe65d039f08ce87201322053facbbfbf2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 14 Sep 2017 22:06:56 +0200 Subject: [PATCH 25/44] 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 3357b8ea9..789ee331e 100644 --- a/iguana/exchanges/LP_socket.c +++ b/iguana/exchanges/LP_socket.c @@ -335,7 +335,7 @@ void electrum_process_array(struct iguana_info *coin,cJSON *array) tx->outpoints[v].value = value; } } - printf("v.%d numvouts.%d %.8f (%s)\n",jint(item,"tx_pos"),tx->numvouts,dstr(tx->outpoints[v].value),jprint(item,0)); + printf("v.%d numvouts.%d %.8f (%s)\n",jint(item,"tx_pos"),tx->numvouts,dstr(tx->outpoints[jint(item,"tx_pos")].value),jprint(item,0)); } } } From 55545761ed4da36d6185e29842800c28a0ae3cba Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 14 Sep 2017 22:12:26 +0200 Subject: [PATCH 26/44] Test --- iguana/exchanges/LP_scan.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/iguana/exchanges/LP_scan.c b/iguana/exchanges/LP_scan.c index 12c2c6c74..1826c9d84 100644 --- a/iguana/exchanges/LP_scan.c +++ b/iguana/exchanges/LP_scan.c @@ -575,7 +575,7 @@ int64_t basilisk_txvalue(char *symbol,bits256 txid,int32_t vout) uint64_t LP_txvalue(char *coinaddr,char *symbol,bits256 txid,int32_t vout) { - struct LP_transaction *tx; struct iguana_info *coin; + struct LP_transaction *tx; struct iguana_info *coin; char str[65]; if ( (coin= LP_coinfind(symbol)) == 0 || coin->inactive != 0 ) return(0); if ( coinaddr != 0 ) @@ -592,7 +592,7 @@ uint64_t LP_txvalue(char *coinaddr,char *symbol,bits256 txid,int32_t vout) { if ( bits256_nonz(tx->outpoints[vout].spendtxid) != 0 ) { - //char str[65]; printf("%s/v%d is spent\n",bits256_str(str,txid),vout); + printf("LP_txvalue %s/v%d is spent\n",bits256_str(str,txid),vout); return(0); } else @@ -606,8 +606,8 @@ uint64_t LP_txvalue(char *coinaddr,char *symbol,bits256 txid,int32_t vout) } return(tx->outpoints[vout].value + tx->outpoints[vout].interest); } - } else printf("vout.%d >= tx->numvouts.%d\n",vout,tx->numvouts); - } + } else printf("LP_txvalue vout.%d >= tx->numvouts.%d\n",vout,tx->numvouts); + } else printf("LP_txvalue couldnt find tx %s\n",bits256_str(str,txid)); return(0); } From b3500342de863937ac5e144bb5c34ef6c24d557c Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 14 Sep 2017 22:23:14 +0200 Subject: [PATCH 27/44] Test --- iguana/exchanges/LP_scan.c | 4 ++-- iguana/exchanges/LP_socket.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/iguana/exchanges/LP_scan.c b/iguana/exchanges/LP_scan.c index 1826c9d84..088a85cb7 100644 --- a/iguana/exchanges/LP_scan.c +++ b/iguana/exchanges/LP_scan.c @@ -575,7 +575,7 @@ int64_t basilisk_txvalue(char *symbol,bits256 txid,int32_t vout) uint64_t LP_txvalue(char *coinaddr,char *symbol,bits256 txid,int32_t vout) { - struct LP_transaction *tx; struct iguana_info *coin; char str[65]; + struct LP_transaction *tx; struct iguana_info *coin; char str[65],str2[65]; if ( (coin= LP_coinfind(symbol)) == 0 || coin->inactive != 0 ) return(0); if ( coinaddr != 0 ) @@ -592,7 +592,7 @@ uint64_t LP_txvalue(char *coinaddr,char *symbol,bits256 txid,int32_t vout) { if ( bits256_nonz(tx->outpoints[vout].spendtxid) != 0 ) { - printf("LP_txvalue %s/v%d is spent\n",bits256_str(str,txid),vout); + printf("LP_txvalue %s/v%d is spent at %s\n",bits256_str(str,txid),vout,bits256_str(str2,tx->outpoints[vout].spendtxid)); return(0); } else diff --git a/iguana/exchanges/LP_socket.c b/iguana/exchanges/LP_socket.c index 789ee331e..698932c8e 100644 --- a/iguana/exchanges/LP_socket.c +++ b/iguana/exchanges/LP_socket.c @@ -451,7 +451,7 @@ cJSON *electrum_address_getmempool(char *symbol,struct electrum_info *ep,cJSON * { cJSON *retjson; struct iguana_info *coin = LP_coinfind(symbol); retjson = electrum_strarg(symbol,ep,retjsonp,"blockchain.address.get_mempool",addr,ELECTRUM_TIMEOUT); - //printf("MEMPOOL.(%s)\n",jprint(retjson,0)); + printf("MEMPOOL.(%s)\n",jprint(retjson,0)); electrum_process_array(coin,retjson); return(retjson); } From a0d4d80b559a4eee962f33a748c7065637858de2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 14 Sep 2017 22:52:26 +0200 Subject: [PATCH 28/44] Test --- iguana/exchanges/LP_utxos.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_utxos.c b/iguana/exchanges/LP_utxos.c index c0763b76e..43b0951f5 100644 --- a/iguana/exchanges/LP_utxos.c +++ b/iguana/exchanges/LP_utxos.c @@ -839,7 +839,7 @@ int32_t LP_nearestvalue(int32_t iambob,uint64_t *values,int32_t n,uint64_t targe uint64_t LP_privkey_init(int32_t mypubsock,struct iguana_info *coin,bits256 myprivkey,bits256 mypub) { - char *script; struct LP_utxoinfo *utxo; cJSON *array,*item; bits256 txid,deposittxid; int32_t used,i,n,cmpflag,iambob,vout,depositvout; uint64_t *values=0,satoshis,txfee,depositval,value,total = 0; int64_t targetval; + char *script,destaddr[64]; struct LP_utxoinfo *utxo; cJSON *array,*item; bits256 txid,deposittxid; int32_t used,i,n,cmpflag,iambob,vout,depositvout; uint64_t *values=0,satoshis,txfee,depositval,value,total = 0; int64_t targetval; if ( coin == 0 ) { printf("coin not active\n"); @@ -877,7 +877,8 @@ uint64_t LP_privkey_init(int32_t mypubsock,struct iguana_info *coin,bits256 mypr { //{"value":1000000,"tx_hash":"4e4f818c53486c0576693b4cd379849e5ff95538b38e4100f48884073a4e7636","tx_pos":0,"height":484877} satoshis = j64bits(item,"value"); - if ( LP_inventory_prevent(iambob,coin->symbol,jbits256(item,"tx_hash"),juint(item,"tx_pos")) == 0 && jint(item,"height") < coin->height ) + satoshis = LP_txvalue(destaddr,coin->symbol,jbits256(item,"tx_hash"),juint(item,"tx_pos")); + if ( satoshis > 0 && LP_inventory_prevent(iambob,coin->symbol,jbits256(item,"tx_hash"),juint(item,"tx_pos")) == 0 && jint(item,"height") < coin->height ) { //printf("%s\n",jprint(item,0)); values[i] = satoshis; From 67e7280a1c0f8cacd38ccae387b103587c41868b Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 14 Sep 2017 22:55:24 +0200 Subject: [PATCH 29/44] Test --- iguana/exchanges/LP_utxos.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/iguana/exchanges/LP_utxos.c b/iguana/exchanges/LP_utxos.c index 43b0951f5..c0763b76e 100644 --- a/iguana/exchanges/LP_utxos.c +++ b/iguana/exchanges/LP_utxos.c @@ -839,7 +839,7 @@ int32_t LP_nearestvalue(int32_t iambob,uint64_t *values,int32_t n,uint64_t targe uint64_t LP_privkey_init(int32_t mypubsock,struct iguana_info *coin,bits256 myprivkey,bits256 mypub) { - char *script,destaddr[64]; struct LP_utxoinfo *utxo; cJSON *array,*item; bits256 txid,deposittxid; int32_t used,i,n,cmpflag,iambob,vout,depositvout; uint64_t *values=0,satoshis,txfee,depositval,value,total = 0; int64_t targetval; + char *script; struct LP_utxoinfo *utxo; cJSON *array,*item; bits256 txid,deposittxid; int32_t used,i,n,cmpflag,iambob,vout,depositvout; uint64_t *values=0,satoshis,txfee,depositval,value,total = 0; int64_t targetval; if ( coin == 0 ) { printf("coin not active\n"); @@ -877,8 +877,7 @@ uint64_t LP_privkey_init(int32_t mypubsock,struct iguana_info *coin,bits256 mypr { //{"value":1000000,"tx_hash":"4e4f818c53486c0576693b4cd379849e5ff95538b38e4100f48884073a4e7636","tx_pos":0,"height":484877} satoshis = j64bits(item,"value"); - satoshis = LP_txvalue(destaddr,coin->symbol,jbits256(item,"tx_hash"),juint(item,"tx_pos")); - if ( satoshis > 0 && LP_inventory_prevent(iambob,coin->symbol,jbits256(item,"tx_hash"),juint(item,"tx_pos")) == 0 && jint(item,"height") < coin->height ) + if ( LP_inventory_prevent(iambob,coin->symbol,jbits256(item,"tx_hash"),juint(item,"tx_pos")) == 0 && jint(item,"height") < coin->height ) { //printf("%s\n",jprint(item,0)); values[i] = satoshis; From f87d2afe48e2bdf5b67ea8d6a64410e747e72dd7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 14 Sep 2017 23:07:53 +0200 Subject: [PATCH 30/44] 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 698932c8e..9753d588d 100644 --- a/iguana/exchanges/LP_socket.c +++ b/iguana/exchanges/LP_socket.c @@ -462,7 +462,7 @@ cJSON *electrum_address_listunspent(char *symbol,struct electrum_info *ep,cJSON //printf("electrum listunspent last.(%s lag %d)\n",coin->lastunspent,(int32_t)(time(NULL) - coin->unspenttime)); //if ( strcmp(coin->lastunspent,addr) != 0 || time(NULL) > coin->unspenttime+10 ) { - if ( (retjson= electrum_strarg(symbol,ep,retjsonp,"blockchain.address.listunspent",addr,ELECTRUM_TIMEOUT)) != 0 ) + if ( (retjson= electrum_strarg(symbol,ep,retjsonp,"blockchain.address.get_history",addr,ELECTRUM_TIMEOUT)) != 0 ) { printf("LISTUNSPENT.(%s)\n",jprint(retjson,0)); electrum_process_array(coin,retjson); From 97b8163dc6edf600087655f8c4ce3d18d92a510b Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 14 Sep 2017 23:09:46 +0200 Subject: [PATCH 31/44] Test --- iguana/exchanges/LP_prices.c | 1 + iguana/exchanges/LP_socket.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_prices.c b/iguana/exchanges/LP_prices.c index 0d2cbf037..57ee9c54a 100644 --- a/iguana/exchanges/LP_prices.c +++ b/iguana/exchanges/LP_prices.c @@ -98,6 +98,7 @@ void LP_address_utxoadd(struct iguana_info *coin,char *coinaddr,bits256 txid,int void LP_address_monitor(struct LP_pubkeyinfo *pubp) { struct iguana_info *coin,*tmp; char coinaddr[64]; cJSON *retjson; struct LP_address *ap; + return; HASH_ITER(hh,LP_coins,coin,tmp) { bitcoin_address(coinaddr,coin->taddr,coin->pubtype,pubp->rmd160,sizeof(pubp->rmd160)); diff --git a/iguana/exchanges/LP_socket.c b/iguana/exchanges/LP_socket.c index 9753d588d..0eeb4f0eb 100644 --- a/iguana/exchanges/LP_socket.c +++ b/iguana/exchanges/LP_socket.c @@ -462,7 +462,7 @@ cJSON *electrum_address_listunspent(char *symbol,struct electrum_info *ep,cJSON //printf("electrum listunspent last.(%s lag %d)\n",coin->lastunspent,(int32_t)(time(NULL) - coin->unspenttime)); //if ( strcmp(coin->lastunspent,addr) != 0 || time(NULL) > coin->unspenttime+10 ) { - if ( (retjson= electrum_strarg(symbol,ep,retjsonp,"blockchain.address.get_history",addr,ELECTRUM_TIMEOUT)) != 0 ) + if ( (retjson= electrum_strarg(symbol,ep,retjsonp,"blockchain.address.history",addr,ELECTRUM_TIMEOUT)) != 0 ) { printf("LISTUNSPENT.(%s)\n",jprint(retjson,0)); electrum_process_array(coin,retjson); From 632b27629b261fe2b11341e94ea3d3debb0da6f4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 14 Sep 2017 23:12:48 +0200 Subject: [PATCH 32/44] Test --- iguana/exchanges/LP_socket.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_socket.c b/iguana/exchanges/LP_socket.c index 0eeb4f0eb..44f108277 100644 --- a/iguana/exchanges/LP_socket.c +++ b/iguana/exchanges/LP_socket.c @@ -488,7 +488,9 @@ cJSON *electrum_getchunk(char *symbol,struct electrum_info *ep,cJSON **retjsonp, cJSON *electrum_transaction(char *symbol,struct electrum_info *ep,cJSON **retjsonp,bits256 txid) { char str[65]; printf("%s TRANSACTION.(%s)\n",symbol,bits256_str(str,txid)); - return(electrum_hasharg(symbol,ep,retjsonp,"blockchain.transaction.get",txid,ELECTRUM_TIMEOUT)); + if ( bits256_nonz(txid) != 0 ) + return(electrum_hasharg(symbol,ep,retjsonp,"blockchain.transaction.get",txid,ELECTRUM_TIMEOUT)); + else return(cJSON_Parse("{\"error\":\"null txid\"}")); } cJSON *electrum_getmerkle(char *symbol,struct electrum_info *ep,cJSON **retjsonp,bits256 txid,int32_t height) From b925ad362a141cf957000973be2350ea3a8ca7f3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 14 Sep 2017 23:15:44 +0200 Subject: [PATCH 33/44] 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 44f108277..d5c44ff59 100644 --- a/iguana/exchanges/LP_socket.c +++ b/iguana/exchanges/LP_socket.c @@ -462,7 +462,7 @@ cJSON *electrum_address_listunspent(char *symbol,struct electrum_info *ep,cJSON //printf("electrum listunspent last.(%s lag %d)\n",coin->lastunspent,(int32_t)(time(NULL) - coin->unspenttime)); //if ( strcmp(coin->lastunspent,addr) != 0 || time(NULL) > coin->unspenttime+10 ) { - if ( (retjson= electrum_strarg(symbol,ep,retjsonp,"blockchain.address.history",addr,ELECTRUM_TIMEOUT)) != 0 ) + if ( (retjson= electrum_strarg(symbol,ep,retjsonp,"blockchain.address.listunspent",addr,ELECTRUM_TIMEOUT)) != 0 ) { printf("LISTUNSPENT.(%s)\n",jprint(retjson,0)); electrum_process_array(coin,retjson); From 9ea27975b3c164fe202cc714ae4faff3eb61a434 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 14 Sep 2017 23:21:17 +0200 Subject: [PATCH 34/44] Test --- iguana/exchanges/LP_utxos.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_utxos.c b/iguana/exchanges/LP_utxos.c index c0763b76e..e24ebc77f 100644 --- a/iguana/exchanges/LP_utxos.c +++ b/iguana/exchanges/LP_utxos.c @@ -839,7 +839,7 @@ int32_t LP_nearestvalue(int32_t iambob,uint64_t *values,int32_t n,uint64_t targe uint64_t LP_privkey_init(int32_t mypubsock,struct iguana_info *coin,bits256 myprivkey,bits256 mypub) { - char *script; struct LP_utxoinfo *utxo; cJSON *array,*item; bits256 txid,deposittxid; int32_t used,i,n,cmpflag,iambob,vout,depositvout; uint64_t *values=0,satoshis,txfee,depositval,value,total = 0; int64_t targetval; + char *script,destaddr[64]; struct LP_utxoinfo *utxo; cJSON *array,*item; bits256 txid,deposittxid; int32_t used,i,n,cmpflag,iambob,vout,depositvout; uint64_t *values=0,satoshis,txfee,depositval,value,total = 0; int64_t targetval; if ( coin == 0 ) { printf("coin not active\n"); @@ -877,6 +877,7 @@ uint64_t LP_privkey_init(int32_t mypubsock,struct iguana_info *coin,bits256 mypr { //{"value":1000000,"tx_hash":"4e4f818c53486c0576693b4cd379849e5ff95538b38e4100f48884073a4e7636","tx_pos":0,"height":484877} satoshis = j64bits(item,"value"); + satoshis = LP_txvalue(destaddr,coin->symbol,jbits256(item,"tx_hash"),juint(item,"tx_pos")); if ( LP_inventory_prevent(iambob,coin->symbol,jbits256(item,"tx_hash"),juint(item,"tx_pos")) == 0 && jint(item,"height") < coin->height ) { //printf("%s\n",jprint(item,0)); From 02171bc3ea4389ae792b9b2f8d9b6a78225a99d2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 15 Sep 2017 00:18:18 +0200 Subject: [PATCH 35/44] Test --- iguana/exchanges/LP_peers.c | 1 + 1 file changed, 1 insertion(+) diff --git a/iguana/exchanges/LP_peers.c b/iguana/exchanges/LP_peers.c index 5e7a26cc3..0a6de49a6 100644 --- a/iguana/exchanges/LP_peers.c +++ b/iguana/exchanges/LP_peers.c @@ -57,6 +57,7 @@ char *LP_peers() struct LP_peerinfo *LP_addpeer(struct LP_peerinfo *mypeer,int32_t mypubsock,char *ipaddr,uint16_t port,uint16_t pushport,uint16_t subport,int32_t numpeers,int32_t numutxos,uint32_t sessionid) { uint32_t ipbits; int32_t pushsock,subsock,timeout; char checkip[64],pushaddr[64],subaddr[64]; struct LP_peerinfo *peer = 0; + printf("addpeer (%s:%u)\n",ipaddr,port); #ifdef LP_STRICTPEERS if ( strncmp("5.9.253",ipaddr,strlen("5.9.253")) != 0 ) return(0); From fa5f451d640964c6db55bdddef9fea3521568c0a Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 15 Sep 2017 00:19:33 +0200 Subject: [PATCH 36/44] Test --- iguana/exchanges/LP_peers.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/iguana/exchanges/LP_peers.c b/iguana/exchanges/LP_peers.c index 0a6de49a6..806572415 100644 --- a/iguana/exchanges/LP_peers.c +++ b/iguana/exchanges/LP_peers.c @@ -58,6 +58,8 @@ struct LP_peerinfo *LP_addpeer(struct LP_peerinfo *mypeer,int32_t mypubsock,char { uint32_t ipbits; int32_t pushsock,subsock,timeout; char checkip[64],pushaddr[64],subaddr[64]; struct LP_peerinfo *peer = 0; printf("addpeer (%s:%u)\n",ipaddr,port); + if ( port > 10000 ) + return(0); #ifdef LP_STRICTPEERS if ( strncmp("5.9.253",ipaddr,strlen("5.9.253")) != 0 ) return(0); From 10fead0ad6c8f098d8594d0395bd268784d2cee9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 15 Sep 2017 00:29:56 +0200 Subject: [PATCH 37/44] Test --- iguana/exchanges/LP_utxos.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/iguana/exchanges/LP_utxos.c b/iguana/exchanges/LP_utxos.c index e24ebc77f..8d9118e25 100644 --- a/iguana/exchanges/LP_utxos.c +++ b/iguana/exchanges/LP_utxos.c @@ -864,9 +864,10 @@ uint64_t LP_privkey_init(int32_t mypubsock,struct iguana_info *coin,bits256 mypr item = jitem(array,i); if ( coin->electrum == 0 ) { - satoshis = SATOSHIDEN * jdouble(item,"amount"); - if ( satoshis == 0 ) - satoshis = SATOSHIDEN * jdouble(item,"value"); + //satoshis = SATOSHIDEN * jdouble(item,"amount"); + //if ( satoshis == 0 ) + // satoshis = SATOSHIDEN * jdouble(item,"value"); + satoshis = LP_txvalue(destaddr,coin->symbol,jbits256(item,"hash"),juint(item,"vout")); if ( LP_inventory_prevent(iambob,coin->symbol,jbits256(item,"txid"),juint(item,"vout")) == 0 && jint(item,"confirmations") > 0 ) { //printf("%s\n",jprint(item,0)); From 65898972c1a6fd278c81d37e2e7932b0fd2c7969 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 15 Sep 2017 09:10:43 +0200 Subject: [PATCH 38/44] Test --- iguana/exchanges/LP_socket.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_socket.c b/iguana/exchanges/LP_socket.c index d5c44ff59..cbc6821d7 100644 --- a/iguana/exchanges/LP_socket.c +++ b/iguana/exchanges/LP_socket.c @@ -647,6 +647,8 @@ int32_t LP_recvfunc(struct electrum_info *ep,char *str,int32_t len) DL_FOREACH(ep->pendingQ.list,item) { stritem = (struct stritem *)item; + if ( *stritem->retptrp != 0 ) + continue; if ( item->type == idnum ) { //printf("matched idnum.%d result.%p\n",idnum,resultjson); @@ -658,13 +660,13 @@ int32_t LP_recvfunc(struct electrum_info *ep,char *str,int32_t len) } if ( stritem->expiration < ep->lasttime ) { - DL_DELETE(ep->pendingQ.list,item); + //DL_DELETE(ep->pendingQ.list,item); printf("expired (%s)\n",stritem->str); errjson = cJSON_CreateObject(); jaddnum(errjson,"id",item->type); jaddstr(errjson,"error","timeout"); *((cJSON **)stritem->retptrp) = errjson; - free(item); + //free(item); } } } From f916d963cbf9186fb5b9c9328e8a949ce38db903 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 15 Sep 2017 10:53:58 +0200 Subject: [PATCH 39/44] Test --- iguana/exchanges/LP_nativeDEX.c | 4 ++-- iguana/exchanges/LP_scan.c | 2 ++ iguana/exchanges/LP_utxos.c | 7 ++++++- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 0dcb86446..1d107e0b0 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -423,7 +423,7 @@ int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int //printf("%s ref.%d scan.%d to %d, longest.%d\n",coin->symbol,coin->firstrefht,coin->firstscanht,coin->lastscanht,coin->longestchain); if ( coin->inactive != 0 || coin->electrum != 0 ) continue; - if ( time(NULL) > coin->lastmonitor+60 ) + /*if ( time(NULL) > coin->lastmonitor+60 ) { portable_mutex_lock(&coin->txmutex); HASH_ITER(hh,coin->addresses,ap,atmp) @@ -442,7 +442,7 @@ int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int } portable_mutex_unlock(&coin->txmutex); coin->lastmonitor = (uint32_t)time(NULL); - } + }*/ memset(zero.bytes,0,sizeof(zero)); if ( time(NULL) > coin->lastgetinfo+LP_GETINFO_INCR ) { diff --git a/iguana/exchanges/LP_scan.c b/iguana/exchanges/LP_scan.c index 088a85cb7..b48d17b09 100644 --- a/iguana/exchanges/LP_scan.c +++ b/iguana/exchanges/LP_scan.c @@ -576,6 +576,8 @@ int64_t basilisk_txvalue(char *symbol,bits256 txid,int32_t vout) uint64_t LP_txvalue(char *coinaddr,char *symbol,bits256 txid,int32_t vout) { struct LP_transaction *tx; struct iguana_info *coin; char str[65],str2[65]; + if ( bits256_nonz(txid) == 0 ) + return(0); if ( (coin= LP_coinfind(symbol)) == 0 || coin->inactive != 0 ) return(0); if ( coinaddr != 0 ) diff --git a/iguana/exchanges/LP_utxos.c b/iguana/exchanges/LP_utxos.c index 8d9118e25..33aaca9bb 100644 --- a/iguana/exchanges/LP_utxos.c +++ b/iguana/exchanges/LP_utxos.c @@ -290,6 +290,11 @@ int32_t LP_iseligible(uint64_t *valp,uint64_t *val2p,int32_t iambob,char *symbol { //struct LP_utxoinfo *utxo; uint64_t val,val2=0,txfee,threshold=0; int32_t bypass = 0; char destaddr[64],destaddr2[64]; struct iguana_info *coin = LP_coinfind(symbol); + if ( bits256_nonz(txid) == 0 || bits256_nonz(txid2) == 0 ) + { + printf("null txid not eligible\n"); + return(-1); + } destaddr[0] = destaddr2[0] = 0; if ( coin != 0 && IAMLP != 0 && coin->inactive != 0 ) bypass = 1; @@ -867,7 +872,7 @@ uint64_t LP_privkey_init(int32_t mypubsock,struct iguana_info *coin,bits256 mypr //satoshis = SATOSHIDEN * jdouble(item,"amount"); //if ( satoshis == 0 ) // satoshis = SATOSHIDEN * jdouble(item,"value"); - satoshis = LP_txvalue(destaddr,coin->symbol,jbits256(item,"hash"),juint(item,"vout")); + satoshis = LP_txvalue(destaddr,coin->symbol,jbits256(item,"txid"),juint(item,"vout")); if ( LP_inventory_prevent(iambob,coin->symbol,jbits256(item,"txid"),juint(item,"vout")) == 0 && jint(item,"confirmations") > 0 ) { //printf("%s\n",jprint(item,0)); From f3a1c2224c2fef7a38bfa226e0d61c4165e74a47 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 15 Sep 2017 10:54:13 +0200 Subject: [PATCH 40/44] Test --- iguana/exchanges/LP_nativeDEX.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 1d107e0b0..9a095a3e6 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -419,7 +419,7 @@ int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int } HASH_ITER(hh,LP_coins,coin,ctmp) // firstrefht,firstscanht,lastscanht { - int32_t height; bits256 zero; struct LP_address *ap,*atmp; struct LP_address_utxo *up; + int32_t height; bits256 zero; //struct LP_address *ap,*atmp; struct LP_address_utxo *up; //printf("%s ref.%d scan.%d to %d, longest.%d\n",coin->symbol,coin->firstrefht,coin->firstscanht,coin->lastscanht,coin->longestchain); if ( coin->inactive != 0 || coin->electrum != 0 ) continue; From b5eefcfafb2c2166f0f07834c0fad5ca2aa1ca9b Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 15 Sep 2017 11:00:59 +0200 Subject: [PATCH 41/44] Test --- iguana/exchanges/LP_scan.c | 2 +- iguana/exchanges/LP_utxos.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_scan.c b/iguana/exchanges/LP_scan.c index b48d17b09..c791f2ae1 100644 --- a/iguana/exchanges/LP_scan.c +++ b/iguana/exchanges/LP_scan.c @@ -609,7 +609,7 @@ uint64_t LP_txvalue(char *coinaddr,char *symbol,bits256 txid,int32_t vout) return(tx->outpoints[vout].value + tx->outpoints[vout].interest); } } else printf("LP_txvalue vout.%d >= tx->numvouts.%d\n",vout,tx->numvouts); - } else printf("LP_txvalue couldnt find tx %s\n",bits256_str(str,txid)); + } else printf("LP_txvalue couldnt find %s tx %s\n",coin->symbol,bits256_str(str,txid)); return(0); } diff --git a/iguana/exchanges/LP_utxos.c b/iguana/exchanges/LP_utxos.c index 33aaca9bb..ecdbb9bf8 100644 --- a/iguana/exchanges/LP_utxos.c +++ b/iguana/exchanges/LP_utxos.c @@ -806,7 +806,7 @@ cJSON *LP_inventory(char *symbol,int32_t iambob) LP_utxo_clientpublish(utxo); jaddi(array,LP_inventoryjson(cJSON_CreateObject(),utxo)); } - else if ( LP_ismine(utxo) > 0 ) + else if ( LP_ismine(utxo) > 0 && strcmp(symbol,utxo->coin) == 0 ) printf("skip %s %s %d %d %d %d\n",utxo->coin,bits256_str(str,utxo->payment.txid),LP_isunspent(utxo) != 0,strcmp(symbol,utxo->coin) == 0,utxo->iambob == iambob,LP_ismine(utxo) > 0); } return(array); From 62ee99ce15dde626924f183959379e7747fb64da Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 15 Sep 2017 11:26:26 +0200 Subject: [PATCH 42/44] Test --- iguana/exchanges/LP_scan.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_scan.c b/iguana/exchanges/LP_scan.c index c791f2ae1..f070f874d 100644 --- a/iguana/exchanges/LP_scan.c +++ b/iguana/exchanges/LP_scan.c @@ -575,7 +575,7 @@ int64_t basilisk_txvalue(char *symbol,bits256 txid,int32_t vout) uint64_t LP_txvalue(char *coinaddr,char *symbol,bits256 txid,int32_t vout) { - struct LP_transaction *tx; struct iguana_info *coin; char str[65],str2[65]; + struct LP_transaction *tx; cJSON *txobj; uint64_t value; struct iguana_info *coin; char str[65],str2[65]; if ( bits256_nonz(txid) == 0 ) return(0); if ( (coin= LP_coinfind(symbol)) == 0 || coin->inactive != 0 ) @@ -609,7 +609,17 @@ uint64_t LP_txvalue(char *coinaddr,char *symbol,bits256 txid,int32_t vout) return(tx->outpoints[vout].value + tx->outpoints[vout].interest); } } else printf("LP_txvalue vout.%d >= tx->numvouts.%d\n",vout,tx->numvouts); - } else printf("LP_txvalue couldnt find %s tx %s\n",coin->symbol,bits256_str(str,txid)); + } + else + { + printf("pruned node? LP_txvalue couldnt find %s tx %s\n",coin->symbol,bits256_str(str,txid)); + if ( (txobj= LP_gettxout(coin->symbol,txid,vout)) != 0 ) + { + value = SATOSHIDEN * jdouble(txobj,"value"); + free_json(txobj); + return(value); + } + } return(0); } From bd9ded4ea34fe5509a7fd9181546644b357fff85 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 15 Sep 2017 11:39:10 +0200 Subject: [PATCH 43/44] Test --- iguana/exchanges/LP_include.h | 1 + iguana/exchanges/LP_prices.c | 6 +- iguana/exchanges/LP_rpc.c | 60 --------- iguana/exchanges/LP_scan.c | 231 +++++++++++++++++++++------------- 4 files changed, 150 insertions(+), 148 deletions(-) diff --git a/iguana/exchanges/LP_include.h b/iguana/exchanges/LP_include.h index 1e74e9507..2a113134d 100644 --- a/iguana/exchanges/LP_include.h +++ b/iguana/exchanges/LP_include.h @@ -302,6 +302,7 @@ int32_t LP_waitmempool(char *symbol,char *coinaddr,bits256 txid,int32_t duration struct LP_transaction *LP_transactionfind(struct iguana_info *coin,bits256 txid); int32_t LP_transactioninit(struct iguana_info *coin,bits256 txid,int32_t iter); int32_t LP_mempoolscan(char *symbol,bits256 searchtxid); +int32_t LP_txheight(struct iguana_info *coin,bits256 txid); #endif diff --git a/iguana/exchanges/LP_prices.c b/iguana/exchanges/LP_prices.c index 57ee9c54a..c4e011a15 100644 --- a/iguana/exchanges/LP_prices.c +++ b/iguana/exchanges/LP_prices.c @@ -80,7 +80,7 @@ struct LP_address *_LP_address(struct iguana_info *coin,char *coinaddr) return(ap); } -void LP_address_utxoadd(struct iguana_info *coin,char *coinaddr,bits256 txid,int32_t vout,uint64_t value) +/*void LP_address_utxoadd(struct iguana_info *coin,char *coinaddr,bits256 txid,int32_t vout,uint64_t value) { struct LP_address *ap; struct LP_address_utxo *up; portable_mutex_lock(&coin->txmutex); @@ -117,7 +117,7 @@ void LP_address_monitor(struct LP_pubkeyinfo *pubp) } } } -} +}*/ int32_t LP_pricevalid(double price) { @@ -293,7 +293,7 @@ void LP_prices_parse(cJSON *obj) printf("%02x",pubp->rmd160[i]); char str[65]; printf(" -> rmd160.(%s) for %s\n",hexstr,bits256_str(str,pubkey)); memcpy(pubp->rmd160,rmd160,sizeof(pubp->rmd160)); - LP_address_monitor(pubp); + //LP_address_monitor(pubp); } } if ( (timestamp= juint(obj,"timestamp")) > pubp->timestamp && (asks= jarray(&n,obj,"asks")) != 0 ) diff --git a/iguana/exchanges/LP_rpc.c b/iguana/exchanges/LP_rpc.c index 16901dae3..641d547ab 100644 --- a/iguana/exchanges/LP_rpc.c +++ b/iguana/exchanges/LP_rpc.c @@ -617,66 +617,6 @@ cJSON *LP_getblock(char *symbol,bits256 txid) return(bitcoin_json(coin,"getblock",buf)); } -int32_t LP_txheight(struct iguana_info *coin,bits256 txid) -{ - bits256 blockhash; struct LP_transaction *tx; cJSON *blockobj,*txobj; int32_t height = 0; - if ( coin == 0 ) - return(-1); - if ( coin->electrum == 0 ) - { - if ( (txobj= LP_gettx(coin->symbol,txid)) != 0 ) - { - //*timestampp = juint(txobj,"locktime"); - //*blocktimep = juint(txobj,"blocktime"); - blockhash = jbits256(txobj,"blockhash"); - if ( bits256_nonz(blockhash) != 0 && (blockobj= LP_getblock(coin->symbol,blockhash)) != 0 ) - { - height = jint(blockobj,"height"); - //printf("%s LP_txheight.%d\n",coin->symbol,height); - free_json(blockobj); - } //else printf("%s LP_txheight error (%s)\n",coin->symbol,jprint(txobj,0)); - free_json(txobj); - } - } - else - { - if ( (tx= LP_transactionfind(coin,txid)) != 0 ) - height = tx->height; - } - return(height); -} - -int32_t LP_numconfirms(char *symbol,char *coinaddr,bits256 txid,int32_t mempool) -{ - struct iguana_info *coin; int32_t ht,numconfirms = 100; - //#ifndef BASILISK_DISABLEWAITTX - cJSON *txobj; - if ( (coin= LP_coinfind(symbol)) == 0 || coin->inactive != 0 ) - return(-1); - if ( coin->electrum == 0 ) - { - numconfirms = -1; - if ( (txobj= LP_gettx(symbol,txid)) != 0 ) - { - if ( coin->electrum == 0 ) - numconfirms = jint(txobj,"confirmations"); - else numconfirms = coin->height - jint(txobj,"height"); - free_json(txobj); - } - else if ( mempool != 0 && LP_mempoolscan(symbol,txid) >= 0 ) - numconfirms = 0; - } - else - { - if ( (ht= LP_txheight(coin,txid)) > 0 && ht <= coin->height ) - numconfirms = (coin->height - ht); - else if ( mempool != 0 && LP_waitmempool(symbol,coinaddr,txid,-1) >= 0 ) - numconfirms = 0; - } - //#endif - return(numconfirms); -} - // not in electrum path uint64_t LP_txfee(char *symbol) { diff --git a/iguana/exchanges/LP_scan.c b/iguana/exchanges/LP_scan.c index f070f874d..d5ae10c80 100644 --- a/iguana/exchanges/LP_scan.c +++ b/iguana/exchanges/LP_scan.c @@ -51,31 +51,6 @@ struct LP_transaction *LP_transactionadd(struct iguana_info *coin,bits256 txid,i return(tx); } -int32_t LP_undospends(struct iguana_info *coin,int32_t lastheight) -{ - int32_t i,ht,num = 0; struct LP_transaction *tx,*tmp; - HASH_ITER(hh,coin->transactions,tx,tmp) - { - for (i=0; inumvouts; i++) - { - if ( bits256_nonz(tx->outpoints[i].spendtxid) == 0 ) - continue; - if ( (ht= tx->outpoints[i].spendheight) == 0 ) - { - tx->outpoints[i].spendheight = LP_txheight(coin,tx->outpoints[i].spendtxid); - } - if ( (ht= tx->outpoints[i].spendheight) != 0 && ht > lastheight ) - { - char str[65]; printf("clear spend %s/v%d at ht.%d > lastheight.%d\n",bits256_str(str,tx->txid),i,ht,lastheight); - tx->outpoints[i].spendheight = 0; - tx->outpoints[i].spendvini = -1; - memset(tx->outpoints[i].spendtxid.bytes,0,sizeof(bits256)); - } - } - } - return(num); -} - uint64_t LP_txinterestvalue(uint64_t *interestp,char *destaddr,struct iguana_info *coin,bits256 txid,int32_t vout) { uint64_t interest,value = 0; double val; cJSON *txobj,*sobj,*array; int32_t n=0; @@ -182,6 +157,152 @@ int32_t LP_transactioninit(struct iguana_info *coin,bits256 txid,int32_t iter) return(-1); } +int32_t LP_txheight(struct iguana_info *coin,bits256 txid) +{ + bits256 blockhash; struct LP_transaction *tx; cJSON *blockobj,*txobj; int32_t height = 0; + if ( coin == 0 ) + return(-1); + if ( coin->electrum == 0 ) + { + if ( (txobj= LP_gettx(coin->symbol,txid)) != 0 ) + { + //*timestampp = juint(txobj,"locktime"); + //*blocktimep = juint(txobj,"blocktime"); + blockhash = jbits256(txobj,"blockhash"); + if ( bits256_nonz(blockhash) != 0 && (blockobj= LP_getblock(coin->symbol,blockhash)) != 0 ) + { + height = jint(blockobj,"height"); + //printf("%s LP_txheight.%d\n",coin->symbol,height); + free_json(blockobj); + } //else printf("%s LP_txheight error (%s)\n",coin->symbol,jprint(txobj,0)); + free_json(txobj); + } + } + else + { + if ( (tx= LP_transactionfind(coin,txid)) != 0 ) + height = tx->height; + } + return(height); +} + +int32_t LP_numconfirms(char *symbol,char *coinaddr,bits256 txid,int32_t mempool) +{ + struct iguana_info *coin; int32_t ht,numconfirms = 100; + //#ifndef BASILISK_DISABLEWAITTX + cJSON *txobj; + if ( (coin= LP_coinfind(symbol)) == 0 || coin->inactive != 0 ) + return(-1); + if ( coin->electrum == 0 ) + { + numconfirms = -1; + if ( (txobj= LP_gettx(symbol,txid)) != 0 ) + { + if ( coin->electrum == 0 ) + numconfirms = jint(txobj,"confirmations"); + else numconfirms = coin->height - jint(txobj,"height"); + free_json(txobj); + } + else if ( mempool != 0 && LP_mempoolscan(symbol,txid) >= 0 ) + numconfirms = 0; + } + else + { + if ( (ht= LP_txheight(coin,txid)) > 0 && ht <= coin->height ) + numconfirms = (coin->height - ht); + else if ( mempool != 0 && LP_waitmempool(symbol,coinaddr,txid,-1) >= 0 ) + numconfirms = 0; + } + //#endif + return(numconfirms); +} + +int64_t basilisk_txvalue(char *symbol,bits256 txid,int32_t vout) +{ + char destaddr[64]; uint64_t value,interest = 0; struct iguana_info *coin; + if ( (coin= LP_coinfind(symbol)) == 0 || coin->inactive != 0 ) + return(0); + //char str[65]; printf("%s txvalue.(%s)\n",symbol,bits256_str(str,txid)); + value = LP_txinterestvalue(&interest,destaddr,coin,txid,vout); + return(value + interest); +} + +uint64_t LP_txvalue(char *coinaddr,char *symbol,bits256 txid,int32_t vout) +{ + struct LP_transaction *tx; cJSON *txobj; uint64_t value; struct iguana_info *coin; char str[65],str2[65]; + if ( bits256_nonz(txid) == 0 ) + return(0); + if ( (coin= LP_coinfind(symbol)) == 0 || coin->inactive != 0 ) + return(0); + if ( coinaddr != 0 ) + coinaddr[0] = 0; + if ( (tx= LP_transactionfind(coin,txid)) == 0 ) + { + LP_transactioninit(coin,txid,0); + LP_transactioninit(coin,txid,1); + tx = LP_transactionfind(coin,txid); + } + if ( tx != 0 ) + { + if ( vout < tx->numvouts ) + { + if ( bits256_nonz(tx->outpoints[vout].spendtxid) != 0 ) + { + printf("LP_txvalue %s/v%d is spent at %s\n",bits256_str(str,txid),vout,bits256_str(str2,tx->outpoints[vout].spendtxid)); + return(0); + } + else + { + if ( coinaddr != 0 ) + { + //if ( tx->outpoints[vout].coinaddr[0] == 0 ) + // tx->outpoints[vout].value = LP_txinterestvalue(&tx->outpoints[vout].interest,tx->outpoints[vout].coinaddr,coin,txid,vout); + strcpy(coinaddr,tx->outpoints[vout].coinaddr); + //printf("(%s) return value %.8f + interest %.8f\n",coinaddr,dstr(tx->outpoints[vout].value),dstr(tx->outpoints[vout].interest)); + } + return(tx->outpoints[vout].value + tx->outpoints[vout].interest); + } + } else printf("LP_txvalue vout.%d >= tx->numvouts.%d\n",vout,tx->numvouts); + } + else + { + if ( (txobj= LP_gettxout(coin->symbol,txid,vout)) != 0 ) + { + value = SATOSHIDEN * jdouble(txobj,"value"); + free_json(txobj); + printf("pruned node? LP_txvalue couldnt find %s tx %s, but gettxout %.8f\n",coin->symbol,bits256_str(str,txid),dstr(value)); + return(value); + } + printf("pruned node? LP_txvalue couldnt find %s tx %s\n",coin->symbol,bits256_str(str,txid)); + } + return(0); +} + +int32_t LP_undospends(struct iguana_info *coin,int32_t lastheight) +{ + int32_t i,ht,num = 0; struct LP_transaction *tx,*tmp; + HASH_ITER(hh,coin->transactions,tx,tmp) + { + for (i=0; inumvouts; i++) + { + if ( bits256_nonz(tx->outpoints[i].spendtxid) == 0 ) + continue; + if ( (ht= tx->outpoints[i].spendheight) == 0 ) + { + tx->outpoints[i].spendheight = LP_txheight(coin,tx->outpoints[i].spendtxid); + } + if ( (ht= tx->outpoints[i].spendheight) != 0 && ht > lastheight ) + { + char str[65]; printf("clear spend %s/v%d at ht.%d > lastheight.%d\n",bits256_str(str,tx->txid),i,ht,lastheight); + tx->outpoints[i].spendheight = 0; + tx->outpoints[i].spendvini = -1; + memset(tx->outpoints[i].spendtxid.bytes,0,sizeof(bits256)); + } + } + } + return(num); +} + int32_t LP_blockinit(struct iguana_info *coin,int32_t height) { int32_t i,j,iter,numtx,checkht=-1; cJSON *blockobj,*txs; bits256 txid; struct LP_transaction *tx; @@ -563,66 +684,6 @@ char *LP_dividends(struct iguana_info *coin,int32_t height,cJSON *argjson) return(clonestr("{\"error\":\"symbol not found\"}")); } -int64_t basilisk_txvalue(char *symbol,bits256 txid,int32_t vout) -{ - char destaddr[64]; uint64_t value,interest = 0; struct iguana_info *coin; - if ( (coin= LP_coinfind(symbol)) == 0 || coin->inactive != 0 ) - return(0); - //char str[65]; printf("%s txvalue.(%s)\n",symbol,bits256_str(str,txid)); - value = LP_txinterestvalue(&interest,destaddr,coin,txid,vout); - return(value + interest); -} - -uint64_t LP_txvalue(char *coinaddr,char *symbol,bits256 txid,int32_t vout) -{ - struct LP_transaction *tx; cJSON *txobj; uint64_t value; struct iguana_info *coin; char str[65],str2[65]; - if ( bits256_nonz(txid) == 0 ) - return(0); - if ( (coin= LP_coinfind(symbol)) == 0 || coin->inactive != 0 ) - return(0); - if ( coinaddr != 0 ) - coinaddr[0] = 0; - if ( (tx= LP_transactionfind(coin,txid)) == 0 ) - { - LP_transactioninit(coin,txid,0); - LP_transactioninit(coin,txid,1); - tx = LP_transactionfind(coin,txid); - } - if ( tx != 0 ) - { - if ( vout < tx->numvouts ) - { - if ( bits256_nonz(tx->outpoints[vout].spendtxid) != 0 ) - { - printf("LP_txvalue %s/v%d is spent at %s\n",bits256_str(str,txid),vout,bits256_str(str2,tx->outpoints[vout].spendtxid)); - return(0); - } - else - { - if ( coinaddr != 0 ) - { - //if ( tx->outpoints[vout].coinaddr[0] == 0 ) - // tx->outpoints[vout].value = LP_txinterestvalue(&tx->outpoints[vout].interest,tx->outpoints[vout].coinaddr,coin,txid,vout); - strcpy(coinaddr,tx->outpoints[vout].coinaddr); - //printf("(%s) return value %.8f + interest %.8f\n",coinaddr,dstr(tx->outpoints[vout].value),dstr(tx->outpoints[vout].interest)); - } - return(tx->outpoints[vout].value + tx->outpoints[vout].interest); - } - } else printf("LP_txvalue vout.%d >= tx->numvouts.%d\n",vout,tx->numvouts); - } - else - { - printf("pruned node? LP_txvalue couldnt find %s tx %s\n",coin->symbol,bits256_str(str,txid)); - if ( (txobj= LP_gettxout(coin->symbol,txid,vout)) != 0 ) - { - value = SATOSHIDEN * jdouble(txobj,"value"); - free_json(txobj); - return(value); - } - } - return(0); -} - int32_t LP_spendsearch(bits256 *spendtxidp,int32_t *indp,char *symbol,bits256 searchtxid,int32_t searchvout) { struct LP_transaction *tx; struct iguana_info *coin; From b8898f875cd11718607488edf183deb827b595ac Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 15 Sep 2017 11:53:29 +0200 Subject: [PATCH 44/44] Test --- iguana/exchanges/LP_nativeDEX.c | 1 + iguana/exchanges/LP_portfolio.c | 4 +- iguana/exchanges/LP_remember.c | 4 +- iguana/exchanges/LP_scan.c | 284 ------------------- iguana/exchanges/LP_socket.c | 2 +- iguana/exchanges/LP_transaction.c | 10 +- iguana/exchanges/LP_utxo.c | 436 ++++++++++++++++++++++++++++++ iguana/exchanges/LP_utxos.c | 133 +-------- 8 files changed, 444 insertions(+), 430 deletions(-) create mode 100644 iguana/exchanges/LP_utxo.c diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 9a095a3e6..15296bcd6 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -85,6 +85,7 @@ char *blocktrail_listtransactions(char *symbol,char *coinaddr,int32_t num,int32_ #include "LP_coins.c" #include "LP_rpc.c" #include "LP_prices.c" +#include "LP_utxo.c" #include "LP_scan.c" #include "LP_transaction.c" #include "LP_remember.c" diff --git a/iguana/exchanges/LP_portfolio.c b/iguana/exchanges/LP_portfolio.c index a5982444d..a3e656e70 100644 --- a/iguana/exchanges/LP_portfolio.c +++ b/iguana/exchanges/LP_portfolio.c @@ -57,9 +57,7 @@ uint64_t LP_balance(uint64_t *valuep,int32_t iambob,char *symbol,char *coinaddr) for (i=0; i>= 1; decode_hex(Dredeemscript,Dredeemlen,rstr); } - if ( (value= jdouble(txobj,"amount") * SATOSHIDEN) == 0 ) - value = jdouble(txobj,"value") * SATOSHIDEN; - values[i] = value; + values[i] = value = LP_value_extract(txobj); if ( (symbol= jstr(txobj,"coin")) != 0 ) { if ( i == BASILISK_ALICESPEND || i == BASILISK_BOBPAYMENT || i == BASILISK_BOBDEPOSIT || i == BASILISK_BOBREFUND || i == BASILISK_BOBRECLAIM || i == BASILISK_ALICECLAIM ) diff --git a/iguana/exchanges/LP_scan.c b/iguana/exchanges/LP_scan.c index d5ae10c80..ddd95f458 100644 --- a/iguana/exchanges/LP_scan.c +++ b/iguana/exchanges/LP_scan.c @@ -19,290 +19,6 @@ // -struct LP_transaction *LP_transactionfind(struct iguana_info *coin,bits256 txid) -{ - struct LP_transaction *tx; - portable_mutex_lock(&coin->txmutex); - HASH_FIND(hh,coin->transactions,txid.bytes,sizeof(txid),tx); - portable_mutex_unlock(&coin->txmutex); - return(tx); -} - -struct LP_transaction *LP_transactionadd(struct iguana_info *coin,bits256 txid,int32_t height,int32_t numvouts,int32_t numvins) -{ - struct LP_transaction *tx; int32_t i; - if ( (tx= LP_transactionfind(coin,txid)) == 0 ) - { - //char str[65]; printf("%s ht.%d u.%u NEW TXID.(%s) vouts.[%d]\n",coin->symbol,height,timestamp,bits256_str(str,txid),numvouts); - //if ( bits256_nonz(txid) == 0 && tx->height == 0 ) - // getchar(); - tx = calloc(1,sizeof(*tx) + (sizeof(*tx->outpoints) * numvouts)); - for (i=0; ioutpoints[i].spendvini = -1; - tx->height = height; - tx->numvouts = numvouts; - tx->numvins = numvins; - //tx->timestamp = timestamp; - tx->txid = txid; - portable_mutex_lock(&coin->txmutex); - HASH_ADD_KEYPTR(hh,coin->transactions,tx->txid.bytes,sizeof(tx->txid),tx); - portable_mutex_unlock(&coin->txmutex); - } // else printf("warning adding already existing txid %s\n",bits256_str(str,tx->txid)); - return(tx); -} - -uint64_t LP_txinterestvalue(uint64_t *interestp,char *destaddr,struct iguana_info *coin,bits256 txid,int32_t vout) -{ - uint64_t interest,value = 0; double val; cJSON *txobj,*sobj,*array; int32_t n=0; - *interestp = 0; - destaddr[0] = 0; - if ( (txobj= LP_gettxout(coin->symbol,txid,vout)) != 0 ) - { - // GETTXOUT.({"value":0.01200000,"txid":"6f5adfefad102e39f62a6bacb222ebace6ce5c084116c08a62cac1182729dd46","vout":1,"scriptPubkey":{"reqSigs":1,"type":"pubkey","addresses":["19Cq6MBaD8LY7trqs99ypqKAms3GcLs6J9"]}}) - if ( (val= jdouble(txobj,"amount")) < SMALLVAL ) - val = jdouble(txobj,"value"); - if ( val > SMALLVAL ) - value = (val * SATOSHIDEN + 0.0000000049); - else value = 0; - if ( value == 0 ) - { - char str[65]; printf("%s LP_txvalue.%s strange utxo.(%s) vout.%d\n",coin->symbol,bits256_str(str,txid),jprint(txobj,0),vout); - } - else if ( strcmp(coin->symbol,"KMD") == 0 ) - { - if ( (interest= jdouble(txobj,"interest")) != 0. ) - { - //printf("add interest of %.8f to %.8f\n",interest,dstr(value)); - *interestp = SATOSHIDEN * interest; - } - } - if ( (sobj= jobj(txobj,"scriptPubKey")) != 0 && (array= jarray(&n,sobj,"addresses")) != 0 ) - { - strcpy(destaddr,jstri(array,0)); - //printf("set destaddr.(%s)\n",destaddr); - if ( n > 1 ) - printf("LP_txinterestvalue warning: violation of 1 output assumption n.%d\n",n); - } else printf("LP_txinterestvalue no addresses found?\n"); - //char str[65]; printf("dest.(%s) %.8f <- %s.(%s) txobj.(%s)\n",destaddr,dstr(value),coin->symbol,bits256_str(str,txid),jprint(txobj,0)); - free_json(txobj); - } //else { char str[65]; printf("null gettxout return %s/v%d\n",bits256_str(str,txid),vout); } - return(value); -} - -int32_t LP_transactioninit(struct iguana_info *coin,bits256 txid,int32_t iter) -{ - struct LP_transaction *tx; char *address; int32_t i,n,height,numvouts,numvins,spentvout; cJSON *txobj,*vins,*vouts,*vout,*vin,*sobj,*addresses; bits256 spenttxid; char str[65]; - if ( (txobj= LP_gettx(coin->symbol,txid)) != 0 ) - { - //printf("TX.(%s)\n",jprint(txobj,0)); - if ( coin->electrum == 0 ) - height = LP_txheight(coin,txid); - else height = -1; - vins = jarray(&numvins,txobj,"vin"); - vouts = jarray(&numvouts,txobj,"vout"); - if ( iter == 0 && vouts != 0 && (tx= LP_transactionadd(coin,txid,height,numvouts,numvins)) != 0 ) - { - //printf("create txid numvouts.%d numvins.%d\n",numvouts,numvins); - for (i=0; ioutpoints[i].value= SATOSHIDEN * jdouble(vout,"value")) == 0 ) - tx->outpoints[i].value = SATOSHIDEN * jdouble(vout,"amount"); - tx->outpoints[i].interest = SATOSHIDEN * jdouble(vout,"interest"); - if ( (sobj= jobj(vout,"scriptPubKey")) != 0 ) - { - if ( (addresses= jarray(&n,sobj,"addresses")) != 0 && n > 0 ) - { - if ( n > 1 ) - printf("LP_transactioninit: txid.(%s) multiple addresses.[%s]\n",bits256_str(str,txid),jprint(addresses,0)); - if ( (address= jstri(addresses,0)) != 0 && strlen(address) < sizeof(tx->outpoints[i].coinaddr) ) - { - strcpy(tx->outpoints[i].coinaddr,address); - //printf("(%s %.8f) ",address,dstr(tx->outpoints[i].value)); - } else if ( tx->outpoints[i].value != 0 ) - printf("LP_transactioninit: unexpected address.(%s)\n",jprint(addresses,0)); - } - //else if ( tx->outpoints[i].value != 0 ) - // printf("LP_transactioninit: pax tx ht.%d i.%d (%s) n.%d\n",height,i,jprint(vout,0),n); - } - } - //printf("numvouts.%d\n",numvouts); - } - if ( iter == 1 && vins != 0 ) - { - for (i=0; inumvouts ) - { - tx->outpoints[spentvout].spendtxid = txid; - tx->outpoints[spentvout].spendvini = i; - tx->outpoints[spentvout].spendheight = height; - //printf("spend %s %s/v%d at ht.%d\n",coin->symbol,bits256_str(str,tx->txid),spentvout,height); - } else printf("LP_transactioninit: %s spentvout.%d < numvouts.%d\n",bits256_str(str,spenttxid),spentvout,tx->numvouts); - } //else printf("LP_transactioninit: couldnt find (%s) ht.%d %s\n",bits256_str(str,spenttxid),height,jprint(vin,0)); - if ( bits256_cmp(spenttxid,txid) == 0 ) - printf("spending same tx's %p vout ht.%d %s.[%d] s%d\n",tx,height,bits256_str(str,txid),tx!=0?tx->numvouts:0,spentvout); - } - } - free_json(txobj); - return(0); - } //else printf("LP_transactioninit error for %s %s\n",coin->symbol,bits256_str(str,txid)); - return(-1); -} - -int32_t LP_txheight(struct iguana_info *coin,bits256 txid) -{ - bits256 blockhash; struct LP_transaction *tx; cJSON *blockobj,*txobj; int32_t height = 0; - if ( coin == 0 ) - return(-1); - if ( coin->electrum == 0 ) - { - if ( (txobj= LP_gettx(coin->symbol,txid)) != 0 ) - { - //*timestampp = juint(txobj,"locktime"); - //*blocktimep = juint(txobj,"blocktime"); - blockhash = jbits256(txobj,"blockhash"); - if ( bits256_nonz(blockhash) != 0 && (blockobj= LP_getblock(coin->symbol,blockhash)) != 0 ) - { - height = jint(blockobj,"height"); - //printf("%s LP_txheight.%d\n",coin->symbol,height); - free_json(blockobj); - } //else printf("%s LP_txheight error (%s)\n",coin->symbol,jprint(txobj,0)); - free_json(txobj); - } - } - else - { - if ( (tx= LP_transactionfind(coin,txid)) != 0 ) - height = tx->height; - } - return(height); -} - -int32_t LP_numconfirms(char *symbol,char *coinaddr,bits256 txid,int32_t mempool) -{ - struct iguana_info *coin; int32_t ht,numconfirms = 100; - //#ifndef BASILISK_DISABLEWAITTX - cJSON *txobj; - if ( (coin= LP_coinfind(symbol)) == 0 || coin->inactive != 0 ) - return(-1); - if ( coin->electrum == 0 ) - { - numconfirms = -1; - if ( (txobj= LP_gettx(symbol,txid)) != 0 ) - { - if ( coin->electrum == 0 ) - numconfirms = jint(txobj,"confirmations"); - else numconfirms = coin->height - jint(txobj,"height"); - free_json(txobj); - } - else if ( mempool != 0 && LP_mempoolscan(symbol,txid) >= 0 ) - numconfirms = 0; - } - else - { - if ( (ht= LP_txheight(coin,txid)) > 0 && ht <= coin->height ) - numconfirms = (coin->height - ht); - else if ( mempool != 0 && LP_waitmempool(symbol,coinaddr,txid,-1) >= 0 ) - numconfirms = 0; - } - //#endif - return(numconfirms); -} - -int64_t basilisk_txvalue(char *symbol,bits256 txid,int32_t vout) -{ - char destaddr[64]; uint64_t value,interest = 0; struct iguana_info *coin; - if ( (coin= LP_coinfind(symbol)) == 0 || coin->inactive != 0 ) - return(0); - //char str[65]; printf("%s txvalue.(%s)\n",symbol,bits256_str(str,txid)); - value = LP_txinterestvalue(&interest,destaddr,coin,txid,vout); - return(value + interest); -} - -uint64_t LP_txvalue(char *coinaddr,char *symbol,bits256 txid,int32_t vout) -{ - struct LP_transaction *tx; cJSON *txobj; uint64_t value; struct iguana_info *coin; char str[65],str2[65]; - if ( bits256_nonz(txid) == 0 ) - return(0); - if ( (coin= LP_coinfind(symbol)) == 0 || coin->inactive != 0 ) - return(0); - if ( coinaddr != 0 ) - coinaddr[0] = 0; - if ( (tx= LP_transactionfind(coin,txid)) == 0 ) - { - LP_transactioninit(coin,txid,0); - LP_transactioninit(coin,txid,1); - tx = LP_transactionfind(coin,txid); - } - if ( tx != 0 ) - { - if ( vout < tx->numvouts ) - { - if ( bits256_nonz(tx->outpoints[vout].spendtxid) != 0 ) - { - printf("LP_txvalue %s/v%d is spent at %s\n",bits256_str(str,txid),vout,bits256_str(str2,tx->outpoints[vout].spendtxid)); - return(0); - } - else - { - if ( coinaddr != 0 ) - { - //if ( tx->outpoints[vout].coinaddr[0] == 0 ) - // tx->outpoints[vout].value = LP_txinterestvalue(&tx->outpoints[vout].interest,tx->outpoints[vout].coinaddr,coin,txid,vout); - strcpy(coinaddr,tx->outpoints[vout].coinaddr); - //printf("(%s) return value %.8f + interest %.8f\n",coinaddr,dstr(tx->outpoints[vout].value),dstr(tx->outpoints[vout].interest)); - } - return(tx->outpoints[vout].value + tx->outpoints[vout].interest); - } - } else printf("LP_txvalue vout.%d >= tx->numvouts.%d\n",vout,tx->numvouts); - } - else - { - if ( (txobj= LP_gettxout(coin->symbol,txid,vout)) != 0 ) - { - value = SATOSHIDEN * jdouble(txobj,"value"); - free_json(txobj); - printf("pruned node? LP_txvalue couldnt find %s tx %s, but gettxout %.8f\n",coin->symbol,bits256_str(str,txid),dstr(value)); - return(value); - } - printf("pruned node? LP_txvalue couldnt find %s tx %s\n",coin->symbol,bits256_str(str,txid)); - } - return(0); -} - -int32_t LP_undospends(struct iguana_info *coin,int32_t lastheight) -{ - int32_t i,ht,num = 0; struct LP_transaction *tx,*tmp; - HASH_ITER(hh,coin->transactions,tx,tmp) - { - for (i=0; inumvouts; i++) - { - if ( bits256_nonz(tx->outpoints[i].spendtxid) == 0 ) - continue; - if ( (ht= tx->outpoints[i].spendheight) == 0 ) - { - tx->outpoints[i].spendheight = LP_txheight(coin,tx->outpoints[i].spendtxid); - } - if ( (ht= tx->outpoints[i].spendheight) != 0 && ht > lastheight ) - { - char str[65]; printf("clear spend %s/v%d at ht.%d > lastheight.%d\n",bits256_str(str,tx->txid),i,ht,lastheight); - tx->outpoints[i].spendheight = 0; - tx->outpoints[i].spendvini = -1; - memset(tx->outpoints[i].spendtxid.bytes,0,sizeof(bits256)); - } - } - } - return(num); -} - int32_t LP_blockinit(struct iguana_info *coin,int32_t height) { int32_t i,j,iter,numtx,checkht=-1; cJSON *blockobj,*txs; bits256 txid; struct LP_transaction *tx; diff --git a/iguana/exchanges/LP_socket.c b/iguana/exchanges/LP_socket.c index cbc6821d7..2866205a8 100644 --- a/iguana/exchanges/LP_socket.c +++ b/iguana/exchanges/LP_socket.c @@ -329,7 +329,7 @@ void electrum_process_array(struct iguana_info *coin,cJSON *array) if ( jobj(item,"tx_pos") != 0 && jobj(item,"value") != 0 && (v= jint(item,"tx_pos")) >= 0 && v < tx->numvouts ) { value = j64bits(item,"value"); - if ( value != tx->outpoints[v].value ) + if ( tx->outpoints[v].value == 0 && value != tx->outpoints[v].value ) { printf(">>>>>>>>>> set %s/v%d <- %.8f vs %.8f\n",bits256_str(str,txid),v,dstr(value),dstr(tx->outpoints[v].value)); tx->outpoints[v].value = value; diff --git a/iguana/exchanges/LP_transaction.c b/iguana/exchanges/LP_transaction.c index 3cdafe59b..71bde88e4 100644 --- a/iguana/exchanges/LP_transaction.c +++ b/iguana/exchanges/LP_transaction.c @@ -1073,7 +1073,7 @@ int32_t basilisk_bobdeposit_refund(struct basilisk_swap *swap,int32_t delay) void LP_swap_coinaddr(struct iguana_info *coin,char *coinaddr,uint64_t *valuep,uint8_t *data,int32_t datalen,int32_t v) { - cJSON *txobj,*vouts,*vout,*addresses,*item,*skey; uint8_t extraspace[32768]; bits256 signedtxid; struct iguana_msgtx msgtx; char *addr; double val; int32_t n,m,suppress_pubkeys = 0; + cJSON *txobj,*vouts,*vout,*addresses,*item,*skey; uint8_t extraspace[32768]; bits256 signedtxid; struct iguana_msgtx msgtx; char *addr; int32_t n,m,suppress_pubkeys = 0; if ( valuep != 0 ) *valuep = 0; if ( (txobj= bitcoin_data2json(coin->taddr,coin->pubtype,coin->p2shtype,coin->isPoS,coin->longestchain,&signedtxid,&msgtx,extraspace,sizeof(extraspace),data,datalen,0,suppress_pubkeys)) != 0 ) @@ -1083,13 +1083,7 @@ void LP_swap_coinaddr(struct iguana_info *coin,char *coinaddr,uint64_t *valuep,u { vout = jitem(vouts,v); if ( valuep != 0 ) - { - *valuep = 0; - if ( (val= jdouble(vout,"value")) < SMALLVAL ) - val = jdouble(vout,"amount"); - if ( val > SMALLVAL ) - *valuep = (val * SATOSHIDEN + 0.0000000049); - } + *valuep = LP_value_extract(vout); //printf("VOUT.(%s)\n",jprint(vout,0)); if ( (skey= jobj(vout,"scriptPubKey")) != 0 && (addresses= jarray(&m,skey,"addresses")) != 0 ) { diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c new file mode 100644 index 000000000..5c327dc99 --- /dev/null +++ b/iguana/exchanges/LP_utxo.c @@ -0,0 +1,436 @@ + +/****************************************************************************** + * Copyright © 2014-2017 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ +// +// LP_utxo.c +// marketmaker +// + +uint64_t LP_value_extract(cJSON *obj) +{ + double val = 0.; uint64_t value; + if ( (val= jdouble(obj,"amount")) < SMALLVAL ) + val = jdouble(obj,"value"); + if ( val > SMALLVAL ) + value = (val * SATOSHIDEN + 0.0000000049); + else value = 0; + return(value); +} + +void LP_utxosetkey(uint8_t *key,bits256 txid,int32_t vout) +{ + memcpy(key,txid.bytes,sizeof(txid)); + memcpy(&key[sizeof(txid)],&vout,sizeof(vout)); +} + +struct LP_utxoinfo *_LP_utxofind(int32_t iambob,bits256 txid,int32_t vout) +{ + struct LP_utxoinfo *utxo=0; uint8_t key[sizeof(txid) + sizeof(vout)]; + LP_utxosetkey(key,txid,vout); + HASH_FIND(hh,LP_utxoinfos[iambob],key,sizeof(key),utxo); + return(utxo); +} + +struct LP_utxoinfo *_LP_utxo2find(int32_t iambob,bits256 txid2,int32_t vout2) +{ + struct LP_utxoinfo *utxo=0; uint8_t key2[sizeof(txid2) + sizeof(vout2)]; + LP_utxosetkey(key2,txid2,vout2); + HASH_FIND(hh2,LP_utxoinfos2[iambob],key2,sizeof(key2),utxo); + return(utxo); +} + +struct LP_utxoinfo *LP_utxofind(int32_t iambob,bits256 txid,int32_t vout) +{ + struct LP_utxoinfo *utxo=0; + portable_mutex_lock(&LP_utxomutex); + utxo = _LP_utxofind(iambob,txid,vout); + portable_mutex_unlock(&LP_utxomutex); + return(utxo); +} + +struct LP_utxoinfo *LP_utxo2find(int32_t iambob,bits256 txid2,int32_t vout2) +{ + struct LP_utxoinfo *utxo=0; + portable_mutex_lock(&LP_utxomutex); + utxo = _LP_utxo2find(iambob,txid2,vout2); + portable_mutex_unlock(&LP_utxomutex); + return(utxo); +} + +struct LP_transaction *LP_transactionfind(struct iguana_info *coin,bits256 txid) +{ + struct LP_transaction *tx; + portable_mutex_lock(&coin->txmutex); + HASH_FIND(hh,coin->transactions,txid.bytes,sizeof(txid),tx); + portable_mutex_unlock(&coin->txmutex); + return(tx); +} + +struct LP_transaction *LP_transactionadd(struct iguana_info *coin,bits256 txid,int32_t height,int32_t numvouts,int32_t numvins) +{ + struct LP_transaction *tx; int32_t i; + if ( (tx= LP_transactionfind(coin,txid)) == 0 ) + { + //char str[65]; printf("%s ht.%d u.%u NEW TXID.(%s) vouts.[%d]\n",coin->symbol,height,timestamp,bits256_str(str,txid),numvouts); + //if ( bits256_nonz(txid) == 0 && tx->height == 0 ) + // getchar(); + tx = calloc(1,sizeof(*tx) + (sizeof(*tx->outpoints) * numvouts)); + for (i=0; ioutpoints[i].spendvini = -1; + tx->height = height; + tx->numvouts = numvouts; + tx->numvins = numvins; + //tx->timestamp = timestamp; + tx->txid = txid; + portable_mutex_lock(&coin->txmutex); + HASH_ADD_KEYPTR(hh,coin->transactions,tx->txid.bytes,sizeof(tx->txid),tx); + portable_mutex_unlock(&coin->txmutex); + } // else printf("warning adding already existing txid %s\n",bits256_str(str,tx->txid)); + return(tx); +} + +uint64_t LP_txinterestvalue(uint64_t *interestp,char *destaddr,struct iguana_info *coin,bits256 txid,int32_t vout) +{ + uint64_t interest,value = 0; cJSON *txobj,*sobj,*array; int32_t n=0; + *interestp = 0; + destaddr[0] = 0; + if ( (txobj= LP_gettxout(coin->symbol,txid,vout)) != 0 ) + { + if ( (value= LP_value_extract(txobj)) == 0 ) + { + char str[65]; printf("%s LP_txvalue.%s strange utxo.(%s) vout.%d\n",coin->symbol,bits256_str(str,txid),jprint(txobj,0),vout); + } + else if ( strcmp(coin->symbol,"KMD") == 0 ) + { + if ( (interest= jdouble(txobj,"interest")) != 0. ) + { + //printf("add interest of %.8f to %.8f\n",interest,dstr(value)); + *interestp = SATOSHIDEN * interest; + } + } + if ( (sobj= jobj(txobj,"scriptPubKey")) != 0 && (array= jarray(&n,sobj,"addresses")) != 0 ) + { + strcpy(destaddr,jstri(array,0)); + //printf("set destaddr.(%s)\n",destaddr); + if ( n > 1 ) + printf("LP_txinterestvalue warning: violation of 1 output assumption n.%d\n",n); + } else printf("LP_txinterestvalue no addresses found?\n"); + //char str[65]; printf("dest.(%s) %.8f <- %s.(%s) txobj.(%s)\n",destaddr,dstr(value),coin->symbol,bits256_str(str,txid),jprint(txobj,0)); + free_json(txobj); + } //else { char str[65]; printf("null gettxout return %s/v%d\n",bits256_str(str,txid),vout); } + return(value); +} + +int32_t LP_transactioninit(struct iguana_info *coin,bits256 txid,int32_t iter) +{ + struct LP_transaction *tx; char *address; int32_t i,n,height,numvouts,numvins,spentvout; cJSON *txobj,*vins,*vouts,*vout,*vin,*sobj,*addresses; bits256 spenttxid; char str[65]; + if ( (txobj= LP_gettx(coin->symbol,txid)) != 0 ) + { + //printf("TX.(%s)\n",jprint(txobj,0)); + if ( coin->electrum == 0 ) + height = LP_txheight(coin,txid); + else height = -1; + vins = jarray(&numvins,txobj,"vin"); + vouts = jarray(&numvouts,txobj,"vout"); + if ( iter == 0 && vouts != 0 && (tx= LP_transactionadd(coin,txid,height,numvouts,numvins)) != 0 ) + { + //printf("create txid numvouts.%d numvins.%d\n",numvouts,numvins); + for (i=0; ioutpoints[i].value = LP_value_extract(vout); + tx->outpoints[i].interest = SATOSHIDEN * jdouble(vout,"interest"); + if ( (sobj= jobj(vout,"scriptPubKey")) != 0 ) + { + if ( (addresses= jarray(&n,sobj,"addresses")) != 0 && n > 0 ) + { + if ( n > 1 ) + printf("LP_transactioninit: txid.(%s) multiple addresses.[%s]\n",bits256_str(str,txid),jprint(addresses,0)); + if ( (address= jstri(addresses,0)) != 0 && strlen(address) < sizeof(tx->outpoints[i].coinaddr) ) + { + strcpy(tx->outpoints[i].coinaddr,address); + //printf("(%s %.8f) ",address,dstr(tx->outpoints[i].value)); + } else if ( tx->outpoints[i].value != 0 ) + printf("LP_transactioninit: unexpected address.(%s)\n",jprint(addresses,0)); + } + //else if ( tx->outpoints[i].value != 0 ) + // printf("LP_transactioninit: pax tx ht.%d i.%d (%s) n.%d\n",height,i,jprint(vout,0),n); + } + } + //printf("numvouts.%d\n",numvouts); + } + if ( iter == 1 && vins != 0 ) + { + for (i=0; inumvouts ) + { + tx->outpoints[spentvout].spendtxid = txid; + tx->outpoints[spentvout].spendvini = i; + tx->outpoints[spentvout].spendheight = height; + //printf("spend %s %s/v%d at ht.%d\n",coin->symbol,bits256_str(str,tx->txid),spentvout,height); + } else printf("LP_transactioninit: %s spentvout.%d < numvouts.%d\n",bits256_str(str,spenttxid),spentvout,tx->numvouts); + } //else printf("LP_transactioninit: couldnt find (%s) ht.%d %s\n",bits256_str(str,spenttxid),height,jprint(vin,0)); + if ( bits256_cmp(spenttxid,txid) == 0 ) + printf("spending same tx's %p vout ht.%d %s.[%d] s%d\n",tx,height,bits256_str(str,txid),tx!=0?tx->numvouts:0,spentvout); + } + } + free_json(txobj); + return(0); + } //else printf("LP_transactioninit error for %s %s\n",coin->symbol,bits256_str(str,txid)); + return(-1); +} + +int32_t LP_txheight(struct iguana_info *coin,bits256 txid) +{ + bits256 blockhash; struct LP_transaction *tx; cJSON *blockobj,*txobj; int32_t height = 0; + if ( coin == 0 ) + return(-1); + if ( coin->electrum == 0 ) + { + if ( (txobj= LP_gettx(coin->symbol,txid)) != 0 ) + { + //*timestampp = juint(txobj,"locktime"); + //*blocktimep = juint(txobj,"blocktime"); + blockhash = jbits256(txobj,"blockhash"); + if ( bits256_nonz(blockhash) != 0 && (blockobj= LP_getblock(coin->symbol,blockhash)) != 0 ) + { + height = jint(blockobj,"height"); + //printf("%s LP_txheight.%d\n",coin->symbol,height); + free_json(blockobj); + } //else printf("%s LP_txheight error (%s)\n",coin->symbol,jprint(txobj,0)); + free_json(txobj); + } + } + else + { + if ( (tx= LP_transactionfind(coin,txid)) != 0 ) + height = tx->height; + } + return(height); +} + +int32_t LP_numconfirms(char *symbol,char *coinaddr,bits256 txid,int32_t mempool) +{ + struct iguana_info *coin; int32_t ht,numconfirms = 100; + //#ifndef BASILISK_DISABLEWAITTX + cJSON *txobj; + if ( (coin= LP_coinfind(symbol)) == 0 || coin->inactive != 0 ) + return(-1); + if ( coin->electrum == 0 ) + { + numconfirms = -1; + if ( (txobj= LP_gettx(symbol,txid)) != 0 ) + { + if ( coin->electrum == 0 ) + numconfirms = jint(txobj,"confirmations"); + else numconfirms = coin->height - jint(txobj,"height"); + free_json(txobj); + } + else if ( mempool != 0 && LP_mempoolscan(symbol,txid) >= 0 ) + numconfirms = 0; + } + else + { + if ( (ht= LP_txheight(coin,txid)) > 0 && ht <= coin->height ) + numconfirms = (coin->height - ht); + else if ( mempool != 0 && LP_waitmempool(symbol,coinaddr,txid,-1) >= 0 ) + numconfirms = 0; + } + //#endif + return(numconfirms); +} + +int64_t basilisk_txvalue(char *symbol,bits256 txid,int32_t vout) +{ + char destaddr[64]; uint64_t value,interest = 0; struct iguana_info *coin; + if ( (coin= LP_coinfind(symbol)) == 0 || coin->inactive != 0 ) + return(0); + //char str[65]; printf("%s txvalue.(%s)\n",symbol,bits256_str(str,txid)); + value = LP_txinterestvalue(&interest,destaddr,coin,txid,vout); + return(value + interest); +} + +uint64_t LP_txvalue(char *coinaddr,char *symbol,bits256 txid,int32_t vout) +{ + struct LP_transaction *tx; cJSON *txobj; uint64_t value; struct iguana_info *coin; char str[65],str2[65]; + if ( bits256_nonz(txid) == 0 ) + return(0); + if ( (coin= LP_coinfind(symbol)) == 0 || coin->inactive != 0 ) + return(0); + if ( coinaddr != 0 ) + coinaddr[0] = 0; + if ( (tx= LP_transactionfind(coin,txid)) == 0 ) + { + LP_transactioninit(coin,txid,0); + LP_transactioninit(coin,txid,1); + tx = LP_transactionfind(coin,txid); + } + if ( tx != 0 ) + { + if ( vout < tx->numvouts ) + { + if ( bits256_nonz(tx->outpoints[vout].spendtxid) != 0 ) + { + printf("LP_txvalue %s/v%d is spent at %s\n",bits256_str(str,txid),vout,bits256_str(str2,tx->outpoints[vout].spendtxid)); + return(0); + } + else + { + if ( coinaddr != 0 ) + { + //if ( tx->outpoints[vout].coinaddr[0] == 0 ) + // tx->outpoints[vout].value = LP_txinterestvalue(&tx->outpoints[vout].interest,tx->outpoints[vout].coinaddr,coin,txid,vout); + strcpy(coinaddr,tx->outpoints[vout].coinaddr); + //printf("(%s) return value %.8f + interest %.8f\n",coinaddr,dstr(tx->outpoints[vout].value),dstr(tx->outpoints[vout].interest)); + } + return(tx->outpoints[vout].value + tx->outpoints[vout].interest); + } + } else printf("LP_txvalue vout.%d >= tx->numvouts.%d\n",vout,tx->numvouts); + } + else + { + if ( (txobj= LP_gettxout(coin->symbol,txid,vout)) != 0 ) + { + value = SATOSHIDEN * jdouble(txobj,"value"); + free_json(txobj); + printf("pruned node? LP_txvalue couldnt find %s tx %s, but gettxout %.8f\n",coin->symbol,bits256_str(str,txid),dstr(value)); + return(value); + } + printf("pruned node? LP_txvalue couldnt find %s tx %s\n",coin->symbol,bits256_str(str,txid)); + } + return(0); +} + +int32_t LP_iseligible(uint64_t *valp,uint64_t *val2p,int32_t iambob,char *symbol,bits256 txid,int32_t vout,uint64_t satoshis,bits256 txid2,int32_t vout2) +{ + //struct LP_utxoinfo *utxo; + uint64_t val,val2=0,txfee,threshold=0; int32_t bypass = 0; char destaddr[64],destaddr2[64]; struct iguana_info *coin = LP_coinfind(symbol); + if ( bits256_nonz(txid) == 0 || bits256_nonz(txid2) == 0 ) + { + printf("null txid not eligible\n"); + return(-1); + } + destaddr[0] = destaddr2[0] = 0; + if ( coin != 0 && IAMLP != 0 && coin->inactive != 0 ) + bypass = 1; + if ( bypass != 0 ) + val = satoshis; + else val = LP_txvalue(destaddr,symbol,txid,vout); + txfee = LP_txfeecalc(LP_coinfind(symbol),0); + if ( val >= satoshis && val > (1+LP_MINSIZE_TXFEEMULT)*txfee ) + { + threshold = (iambob != 0) ? LP_DEPOSITSATOSHIS(satoshis) : (LP_DEXFEE(satoshis) + txfee); + if ( bypass != 0 ) + val2 = threshold; + else val2 = LP_txvalue(destaddr2,symbol,txid2,vout2); + if ( val2 >= threshold ) + { + if ( bypass == 0 && strcmp(destaddr,destaddr2) != 0 ) + printf("mismatched %s destaddr (%s) vs (%s)\n",symbol,destaddr,destaddr2); + else if ( bypass == 0 && ((iambob == 0 && val2 > val) || (iambob != 0 && val2 <= satoshis)) ) + printf("iambob.%d ineligible due to offsides: val %.8f and val2 %.8f vs %.8f diff %lld\n",iambob,dstr(val),dstr(val2),dstr(satoshis),(long long)(val2 - val)); + else + { + *valp = val; + *val2p = val2; + return(1); + } + } // else printf("no val2\n"); + } + char str[65],str2[65]; printf("spent.%d %s txid or value %.8f < %.8f or val2 %.8f < %.8f, %s/v%d %s/v%d or < 10x txfee %.8f\n",iambob,symbol,dstr(val),dstr(satoshis),dstr(val2),dstr(threshold),bits256_str(str,txid),vout,bits256_str(str2,txid2),vout2,dstr(txfee)); + /*for (iter=0; iter<2; iter++) + { + if ( (utxo= LP_utxofind(iter,txid,vout)) != 0 ) + { + //printf("iambob.%d case 00\n",iter); + if ( utxo->T.spentflag == 0 ) + utxo->T.spentflag = (uint32_t)time(NULL); + } + if ( (utxo= LP_utxo2find(iter,txid,vout)) != 0 ) + { + //printf("iambob.%d case 01\n",iter); + if ( utxo->T.spentflag == 0 ) + utxo->T.spentflag = (uint32_t)time(NULL); + } + if ( (utxo= LP_utxofind(iter,txid2,vout2)) != 0 ) + { + //printf("iambob.%d case 10\n",iter); + if ( utxo->T.spentflag == 0 ) + utxo->T.spentflag = (uint32_t)time(NULL); + } + if ( (utxo= LP_utxo2find(iter,txid2,vout2)) != 0 ) + { + //printf("iambob.%d case 11\n",iter); + if ( utxo->T.spentflag == 0 ) + utxo->T.spentflag = (uint32_t)time(NULL); + } + }*/ + *valp = val; + *val2p = val2; + return(0); +} + +int32_t LP_inventory_prevent(int32_t iambob,char *symbol,bits256 txid,int32_t vout) +{ + struct LP_utxoinfo *utxo; struct LP_transaction *tx; struct iguana_info *coin; + if ( (utxo= LP_utxofind(iambob,txid,vout)) != 0 || (utxo= LP_utxo2find(iambob,txid,vout)) != 0 ) + { + if ( (coin= LP_coinfind(symbol)) != 0 && (tx= LP_transactionfind(coin,txid)) != 0 ) + { + if ( tx->outpoints[vout].spendheight > 0 ) + utxo->T.spentflag = tx->outpoints[vout].spendheight; + else utxo->T.spentflag = 0; + } + if ( utxo->T.spentflag != 0 ) + { + char str[65]; printf("prevent adding iambob.%d %s/v%d to inventory\n",iambob,bits256_str(str,txid),vout); + return(1); + } + } + return(0); +} + +int32_t LP_undospends(struct iguana_info *coin,int32_t lastheight) +{ + int32_t i,ht,num = 0; struct LP_transaction *tx,*tmp; + HASH_ITER(hh,coin->transactions,tx,tmp) + { + for (i=0; inumvouts; i++) + { + if ( bits256_nonz(tx->outpoints[i].spendtxid) == 0 ) + continue; + if ( (ht= tx->outpoints[i].spendheight) == 0 ) + { + tx->outpoints[i].spendheight = LP_txheight(coin,tx->outpoints[i].spendtxid); + } + if ( (ht= tx->outpoints[i].spendheight) != 0 && ht > lastheight ) + { + char str[65]; printf("clear spend %s/v%d at ht.%d > lastheight.%d\n",bits256_str(str,tx->txid),i,ht,lastheight); + tx->outpoints[i].spendheight = 0; + tx->outpoints[i].spendvini = -1; + memset(tx->outpoints[i].spendtxid.bytes,0,sizeof(bits256)); + } + } + } + return(num); +} diff --git a/iguana/exchanges/LP_utxos.c b/iguana/exchanges/LP_utxos.c index ecdbb9bf8..bf985cae1 100644 --- a/iguana/exchanges/LP_utxos.c +++ b/iguana/exchanges/LP_utxos.c @@ -41,37 +41,6 @@ int32_t LP_isunspent(struct LP_utxoinfo *utxo) else return(0); } -void LP_utxosetkey(uint8_t *key,bits256 txid,int32_t vout) -{ - memcpy(key,txid.bytes,sizeof(txid)); - memcpy(&key[sizeof(txid)],&vout,sizeof(vout)); -} - -struct LP_utxoinfo *_LP_utxofind(int32_t iambob,bits256 txid,int32_t vout) -{ - struct LP_utxoinfo *utxo=0; uint8_t key[sizeof(txid) + sizeof(vout)]; - LP_utxosetkey(key,txid,vout); - HASH_FIND(hh,LP_utxoinfos[iambob],key,sizeof(key),utxo); - return(utxo); -} - -struct LP_utxoinfo *_LP_utxo2find(int32_t iambob,bits256 txid2,int32_t vout2) -{ - struct LP_utxoinfo *utxo=0; uint8_t key2[sizeof(txid2) + sizeof(vout2)]; - LP_utxosetkey(key2,txid2,vout2); - HASH_FIND(hh2,LP_utxoinfos2[iambob],key2,sizeof(key2),utxo); - return(utxo); -} - -struct LP_utxoinfo *LP_utxofind(int32_t iambob,bits256 txid,int32_t vout) -{ - struct LP_utxoinfo *utxo=0; - portable_mutex_lock(&LP_utxomutex); - utxo = _LP_utxofind(iambob,txid,vout); - portable_mutex_unlock(&LP_utxomutex); - return(utxo); -} - struct LP_utxoinfo *LP_utxopairfind(int32_t iambob,bits256 txid,int32_t vout,bits256 txid2,int32_t vout2) { struct LP_utxoinfo *utxo=0; struct _LP_utxoinfo u; @@ -84,15 +53,6 @@ struct LP_utxoinfo *LP_utxopairfind(int32_t iambob,bits256 txid,int32_t vout,bit return(0); } -struct LP_utxoinfo *LP_utxo2find(int32_t iambob,bits256 txid2,int32_t vout2) -{ - struct LP_utxoinfo *utxo=0; - portable_mutex_lock(&LP_utxomutex); - utxo = _LP_utxo2find(iambob,txid2,vout2); - portable_mutex_unlock(&LP_utxomutex); - return(utxo); -} - struct LP_utxoinfo *LP_utxofinds(int32_t iambob,bits256 txid,int32_t vout,bits256 txid2,int32_t vout2) { struct LP_utxoinfo *utxo; @@ -286,75 +246,6 @@ cJSON *LP_utxojson(struct LP_utxoinfo *utxo) return(item); } -int32_t LP_iseligible(uint64_t *valp,uint64_t *val2p,int32_t iambob,char *symbol,bits256 txid,int32_t vout,uint64_t satoshis,bits256 txid2,int32_t vout2) -{ - //struct LP_utxoinfo *utxo; - uint64_t val,val2=0,txfee,threshold=0; int32_t bypass = 0; char destaddr[64],destaddr2[64]; struct iguana_info *coin = LP_coinfind(symbol); - if ( bits256_nonz(txid) == 0 || bits256_nonz(txid2) == 0 ) - { - printf("null txid not eligible\n"); - return(-1); - } - destaddr[0] = destaddr2[0] = 0; - if ( coin != 0 && IAMLP != 0 && coin->inactive != 0 ) - bypass = 1; - if ( bypass != 0 ) - val = satoshis; - else val = LP_txvalue(destaddr,symbol,txid,vout); - txfee = LP_txfeecalc(LP_coinfind(symbol),0); - if ( val >= satoshis && val > (1+LP_MINSIZE_TXFEEMULT)*txfee ) - { - threshold = (iambob != 0) ? LP_DEPOSITSATOSHIS(satoshis) : (LP_DEXFEE(satoshis) + txfee); - if ( bypass != 0 ) - val2 = threshold; - else val2 = LP_txvalue(destaddr2,symbol,txid2,vout2); - if ( val2 >= threshold ) - { - if ( bypass == 0 && strcmp(destaddr,destaddr2) != 0 ) - printf("mismatched %s destaddr (%s) vs (%s)\n",symbol,destaddr,destaddr2); - else if ( bypass == 0 && ((iambob == 0 && val2 > val) || (iambob != 0 && val2 <= satoshis)) ) - printf("iambob.%d ineligible due to offsides: val %.8f and val2 %.8f vs %.8f diff %lld\n",iambob,dstr(val),dstr(val2),dstr(satoshis),(long long)(val2 - val)); - else - { - *valp = val; - *val2p = val2; - return(1); - } - } // else printf("no val2\n"); - } - char str[65],str2[65]; printf("spent.%d %s txid or value %.8f < %.8f or val2 %.8f < %.8f, %s/v%d %s/v%d or < 10x txfee %.8f\n",iambob,symbol,dstr(val),dstr(satoshis),dstr(val2),dstr(threshold),bits256_str(str,txid),vout,bits256_str(str2,txid2),vout2,dstr(txfee)); - /*for (iter=0; iter<2; iter++) - { - if ( (utxo= LP_utxofind(iter,txid,vout)) != 0 ) - { - //printf("iambob.%d case 00\n",iter); - if ( utxo->T.spentflag == 0 ) - utxo->T.spentflag = (uint32_t)time(NULL); - } - if ( (utxo= LP_utxo2find(iter,txid,vout)) != 0 ) - { - //printf("iambob.%d case 01\n",iter); - if ( utxo->T.spentflag == 0 ) - utxo->T.spentflag = (uint32_t)time(NULL); - } - if ( (utxo= LP_utxofind(iter,txid2,vout2)) != 0 ) - { - //printf("iambob.%d case 10\n",iter); - if ( utxo->T.spentflag == 0 ) - utxo->T.spentflag = (uint32_t)time(NULL); - } - if ( (utxo= LP_utxo2find(iter,txid2,vout2)) != 0 ) - { - //printf("iambob.%d case 11\n",iter); - if ( utxo->T.spentflag == 0 ) - utxo->T.spentflag = (uint32_t)time(NULL); - } - }*/ - *valp = val; - *val2p = val2; - return(0); -} - char *LP_utxos(int32_t iambob,struct LP_peerinfo *mypeer,char *symbol,int32_t lastn) { int32_t i,n,m; uint64_t val,val2; struct _LP_utxoinfo u; struct LP_utxoinfo *utxo,*tmp; cJSON *utxosjson = cJSON_CreateArray(); @@ -383,26 +274,6 @@ char *LP_utxos(int32_t iambob,struct LP_peerinfo *mypeer,char *symbol,int32_t la return(jprint(utxosjson,1)); } -int32_t LP_inventory_prevent(int32_t iambob,char *symbol,bits256 txid,int32_t vout) -{ - struct LP_utxoinfo *utxo; struct LP_transaction *tx; struct iguana_info *coin; - if ( (utxo= LP_utxofind(iambob,txid,vout)) != 0 || (utxo= LP_utxo2find(iambob,txid,vout)) != 0 ) - { - if ( (coin= LP_coinfind(symbol)) != 0 && (tx= LP_transactionfind(coin,txid)) != 0 ) - { - if ( tx->outpoints[vout].spendheight > 0 ) - utxo->T.spentflag = tx->outpoints[vout].spendheight; - else utxo->T.spentflag = 0; - } - if ( utxo->T.spentflag != 0 ) - { - char str[65]; printf("prevent adding iambob.%d %s/v%d to inventory\n",iambob,bits256_str(str,txid),vout); - return(1); - } - } - return(0); -} - struct LP_utxoinfo *LP_utxo_bestfit(char *symbol,uint64_t destsatoshis) { uint64_t srcvalue,srcvalue2; struct LP_utxoinfo *utxo,*tmp,*bestutxo = 0; @@ -666,11 +537,11 @@ struct LP_utxoinfo *LP_utxoadd(int32_t iambob,int32_t mypubsock,char *symbol,bit if ( _LP_utxo2find(iambob,txid2,vout2) == 0 ) HASH_ADD_KEYPTR(hh2,LP_utxoinfos2[iambob],utxo->key2,sizeof(utxo->key2),utxo); portable_mutex_unlock(&LP_utxomutex); - if ( 0 && coin->electrum == 0 ) + /*if ( 0 && coin->electrum == 0 ) { LP_address_utxoadd(coin,coinaddr,txid,vout,value); LP_address_utxoadd(coin,coinaddr,txid2,vout2,value2); - } + }*/ if ( iambob != 0 ) { if ( LP_mypeer != 0 )