diff --git a/iguana/exchanges/LP_include.h b/iguana/exchanges/LP_include.h index eeb6a823a..870628dc9 100644 --- a/iguana/exchanges/LP_include.h +++ b/iguana/exchanges/LP_include.h @@ -379,7 +379,7 @@ int64_t LP_komodo_interest(bits256 txid,int64_t value); void LP_availableset(struct LP_utxoinfo *utxo); 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); int32_t LP_pullsock_check(void *ctx,char **retstrp,char *myipaddr,int32_t pubsock,int32_t pullsock); -void LP_unspents_cache(char *symbol,char *addr,char *arraystr); +void LP_unspents_cache(char *symbol,char *addr,char *arraystr,int32_t updatedflag); uint16_t LP_psock_get(char *connectaddr,char *publicaddr,int32_t ispaired); //void LP_utxo_clientpublish(struct LP_utxoinfo *utxo); int32_t LP_coinbus(uint16_t coin_busport); diff --git a/iguana/exchanges/LP_socket.c b/iguana/exchanges/LP_socket.c index f2e91f2a8..87bb1560e 100644 --- a/iguana/exchanges/LP_socket.c +++ b/iguana/exchanges/LP_socket.c @@ -543,7 +543,7 @@ cJSON *electrum_address_getmempool(char *symbol,struct electrum_info *ep,cJSON * cJSON *electrum_address_listunspent(char *symbol,struct electrum_info *ep,cJSON **retjsonp,char *addr,int32_t electrumflag) { - cJSON *retjson=0; char *retstr; struct LP_address *ap; struct iguana_info *coin; int32_t height,usecache=1; + cJSON *retjson=0; char *retstr; struct LP_address *ap; struct iguana_info *coin; int32_t updatedflag,height,usecache=1; if ( (coin= LP_coinfind(symbol)) == 0 ) return(0); if ( ep == 0 || ep->heightp == 0 ) @@ -564,12 +564,13 @@ cJSON *electrum_address_listunspent(char *symbol,struct electrum_info *ep,cJSON if ( (retjson= electrum_strarg(symbol,ep,retjsonp,"blockchain.address.listunspent",addr,ELECTRUM_TIMEOUT)) != 0 ) { printf("%s.%d u.%u/%d t.%ld %s LISTUNSPENT.(%d)\n",coin->symbol,height,ap->unspenttime,ap->unspentheight,time(NULL),addr,(int32_t)strlen(jprint(retjson,0))); + updatedflag = 0; if ( electrum_process_array(coin,ep,addr,retjson,electrumflag) != 0 ) - LP_postutxos(coin->symbol,addr); + LP_postutxos(coin->symbol,addr), updatedflag = 1; if ( strcmp(addr,coin->smartaddr) == 0 ) { retstr = jprint(retjson,0); - LP_unspents_cache(coin->symbol,coin->smartaddr,retstr); + LP_unspents_cache(coin->symbol,coin->smartaddr,retstr,updatedflag); free(retstr); } if ( ap != 0 ) diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index ffd5d3f9e..39e414aff 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -982,11 +982,14 @@ int32_t LP_undospends(struct iguana_info *coin,int32_t lastheight) return(num); } -void LP_unspents_cache(char *symbol,char *addr,char *arraystr) +void LP_unspents_cache(char *symbol,char *addr,char *arraystr,int32_t updatedflag) { char fname[1024]; FILE *fp; sprintf(fname,"%s/UNSPENTS/%s_%s",GLOBAL_DBDIR,symbol,addr), OS_portable_path(fname); - if ( (fp= fopen(fname,"wb")) != 0 ) + if ( updatedflag == 0 && (fp= fopen(fname,"rb")) == 0 ) + updatedflag = 1; + else fclose(fp); + if ( updatedflag != 0 && (fp= fopen(fname,"wb")) != 0 ) { fwrite(arraystr,1,strlen(arraystr),fp); fclose(fp);