From 451e6c21e22ad4e10fe7523fab1312d864d703b3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 22 Sep 2017 14:53:06 +0200 Subject: [PATCH] Test --- iguana/exchanges/LP_nativeDEX.c | 18 +++++++++++++++++- iguana/exchanges/LP_ordermatch.c | 2 ++ iguana/exchanges/LP_rpc.c | 1 - iguana/exchanges/LP_scan.c | 17 +++++++++++------ iguana/exchanges/LP_socket.c | 31 +++++++++++++++++++++++++++---- iguana/exchanges/LP_utxo.c | 22 +++++++++++----------- 6 files changed, 68 insertions(+), 23 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 2daa76cbf..5285f4da7 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -343,7 +343,23 @@ int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int free(retstr); peer->needping = 0; } - //sync listunspent, parse arrays in ordermatch, electrum history to prune, spv + HASH_ITER(hh,LP_coins,coin,ctmp) + { + char coinaddr[64]; cJSON *array; int32_t n; + bitcoin_address(coinaddr,coin->taddr,coin->pubtype,G.LP_myrmd160,sizeof(G.LP_myrmd160)); + if ( (array= LP_address_utxos(coin,coinaddr,1)) != 0 ) + { + if ( (n= cJSON_GetArraySize(array)) > 0 ) + { + if ( (retstr= issue_LP_listunspent(peer->ipaddr,peer->port,coin->symbol,coinaddr)) != 0 ) + { + printf("compare (%s) vs (%s)\n",jprint(array,0),retstr); + free(retstr); + } + } + free_json(array); + } + //sync listunspent,, spv } } if ( peer->diduquery == 0 ) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 379670a7c..25bb7a3e3 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -730,6 +730,8 @@ int32_t LP_listunspent_both(char *symbol,char *coinaddr) if ( coin->electrum != 0 || LP_address_ismine(symbol,coinaddr) <= 0 ) { //printf("issue path electrum.%p\n",coin->electrum); + if ( coin->electrum != 0 && (array= electrum_address_gethistory(symbol,coin->electrum,&array,coinaddr)) != 0 ) + free_json(array); n = LP_listunspent_issue(symbol,coinaddr); } else diff --git a/iguana/exchanges/LP_rpc.c b/iguana/exchanges/LP_rpc.c index 6b04e22e1..c42d5c3d7 100644 --- a/iguana/exchanges/LP_rpc.c +++ b/iguana/exchanges/LP_rpc.c @@ -468,7 +468,6 @@ int32_t LP_listunspent_issue(char *symbol,char *coinaddr) struct iguana_info *coin; int32_t n = 0; cJSON *retjson=0; char *retstr=0,destip[64]; uint16_t destport; if ( symbol == 0 || symbol[0] == 0 ) return(0); - printf("LP_listunspent_issue\n"); if ( (coin= LP_coinfind(symbol)) != 0 ) { if ( coin->electrum != 0 ) diff --git a/iguana/exchanges/LP_scan.c b/iguana/exchanges/LP_scan.c index 5cbbabf43..9f65fa7ef 100644 --- a/iguana/exchanges/LP_scan.c +++ b/iguana/exchanges/LP_scan.c @@ -21,13 +21,14 @@ int32_t LP_blockinit(struct iguana_info *coin,int32_t height) { - int32_t i,iter,numtx,checkht=-1; cJSON *blockobj,*txs; bits256 txid; struct LP_transaction *tx; + int32_t i,iter,numtx,checkht=-1; cJSON *blockobj,*txs,*txobj; bits256 txid; struct LP_transaction *tx; if ( (blockobj= LP_blockjson(&checkht,coin->symbol,0,height)) != 0 && checkht == height ) { if ( (txs= jarray(&numtx,blockobj,"tx")) != 0 ) { for (iter=0; iter<2; iter++) { + txobj = 0; for (i=0; iheight = height; } if ( iter == 1 ) - LP_transactioninit(coin,txid,iter,0); - } else LP_transactioninit(coin,txid,iter,0); + txobj = LP_transactioninit(coin,txid,iter,0); + } else txobj = LP_transactioninit(coin,txid,iter,0); + if ( txobj != 0 ) + free_json(txobj), txobj = 0; } } } @@ -409,7 +412,7 @@ int32_t LP_spendsearch(bits256 *spendtxidp,int32_t *indp,char *symbol,bits256 se int32_t LP_mempoolscan(char *symbol,bits256 searchtxid) { - int32_t i,n; cJSON *array; bits256 txid; struct iguana_info *coin; struct LP_transaction *tx; + int32_t i,n; cJSON *array,*txobj; bits256 txid; struct iguana_info *coin; struct LP_transaction *tx; if ( (coin= LP_coinfind(symbol)) == 0 || coin->inactive != 0 || coin->electrum != 0 ) return(-1); if ( (array= LP_getmempool(symbol,0)) != 0 ) @@ -421,8 +424,10 @@ int32_t LP_mempoolscan(char *symbol,bits256 searchtxid) txid = jbits256i(array,i); if ( (tx= LP_transactionfind(coin,txid)) == 0 ) { - LP_transactioninit(coin,txid,0,0); - LP_transactioninit(coin,txid,1,0); + txobj = LP_transactioninit(coin,txid,0,0); + txobj = LP_transactioninit(coin,txid,1,txobj); + if ( txobj != 0 ) + free_json(txobj); } if ( bits256_cmp(txid,searchtxid) == 0 ) { diff --git a/iguana/exchanges/LP_socket.c b/iguana/exchanges/LP_socket.c index cb37f36fe..80f1f230b 100644 --- a/iguana/exchanges/LP_socket.c +++ b/iguana/exchanges/LP_socket.c @@ -334,6 +334,7 @@ int32_t electrum_process_array(struct iguana_info *coin,struct electrum_info *ep { txobj = LP_transactioninit(coin,txid,0,0); LP_transactioninit(coin,txid,1,txobj); + free_json(txobj); tx = LP_transactionfind(coin,txid); } if ( tx != 0 ) @@ -351,7 +352,7 @@ int32_t electrum_process_array(struct iguana_info *coin,struct electrum_info *ep tx->outpoints[v].value = value; } } - if ( value != 0 && tx->height > 0 ) + if ( value != 0 || tx->height > 0 ) flag += LP_address_utxoadd(coin,coinaddr,txid,v,value,tx->height,-1); //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)); } @@ -461,10 +462,32 @@ cJSON *electrum_address_subscribe(char *symbol,struct electrum_info *ep,cJSON ** cJSON *electrum_address_gethistory(char *symbol,struct electrum_info *ep,cJSON **retjsonp,char *addr) { - cJSON *retjson; struct iguana_info *coin = LP_coinfind(symbol); + struct LP_transaction *tx; cJSON *retjson,*txobj,*item; int32_t i,n,height; bits256 txid; struct iguana_info *coin = LP_coinfind(symbol); retjson = electrum_strarg(symbol,ep,retjsonp,"blockchain.address.get_history",addr,ELECTRUM_TIMEOUT); - printf("history.(%s)\n",jprint(retjson,0)); - electrum_process_array(coin,ep,addr,retjson); + //printf("history.(%s)\n",jprint(retjson,0)); + if ( retjson != 0 && (n= cJSON_GetArraySize(retjson)) > 0 ) + { + for (i=0; i 0 ) + { + if ( (tx= LP_transactionfind(coin,txid)) != 0 ) + { + tx->height = height; + //for (j=0; jnumvouts; j++) + // LP_address_utxoadd(coin,coinaddr,txid,j,0,height,-1); + } + } + } + } return(retjson); } diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index a4d637804..6f0dc3f84 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -185,11 +185,12 @@ int32_t LP_address_utxoadd(struct iguana_info *coin,char *coinaddr,bits256 txid, { if ( vout == up->U.vout && bits256_cmp(up->U.txid,txid) == 0 ) { - if ( up->U.height <= 0 && height > 0 ) - up->U.height = height; - if ( spendheight > 0 ) - up->spendheight = spendheight; - flag = 1; + if ( up->U.height <= 0 && height > 0 && up->U.height != height ) + up->U.height = height, flag = 1; + if ( spendheight > 0 && up->spendheight != spendheight ) + up->spendheight = spendheight, flag = 1; + if ( up->U.value == 0 && up->U.value != value ) + up->U.value = value, flag = 1; break; } } @@ -492,6 +493,7 @@ cJSON *LP_transactioninit(struct iguana_info *coin,bits256 txid,int32_t iter,cJS tx->outpoints[i].value = LP_value_extract(vout,0); tx->outpoints[i].interest = SATOSHIDEN * jdouble(vout,"interest"); LP_destaddr(tx->outpoints[i].coinaddr,vout); + LP_address_utxoadd(coin,tx->outpoints[i].coinaddr,txid,i,tx->outpoints[i].value,height,-1); } //printf("numvouts.%d\n",numvouts); } @@ -523,11 +525,7 @@ cJSON *LP_transactioninit(struct iguana_info *coin,bits256 txid,int32_t iter,cJS 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); } } - if ( iter == 1 ) - { - free_json(txobj); - return(0); - } else return(txobj); + return(txobj); } //else printf("LP_transactioninit error for %s %s\n",coin->symbol,bits256_str(str,txid)); return(0); } @@ -615,7 +613,9 @@ uint64_t LP_txvalue(char *coinaddr,char *symbol,bits256 txid,int32_t vout) if ( (tx= LP_transactionfind(coin,txid)) == 0 ) { txobj = LP_transactioninit(coin,txid,0,0); - LP_transactioninit(coin,txid,1,txobj); + txobj = LP_transactioninit(coin,txid,1,txobj); + if ( txobj != 0 ) + free_json(txobj); tx = LP_transactionfind(coin,txid); } if ( tx != 0 )