diff --git a/iguana/exchanges/LP_include.h b/iguana/exchanges/LP_include.h index cbbd765ec..eeb6a823a 100644 --- a/iguana/exchanges/LP_include.h +++ b/iguana/exchanges/LP_include.h @@ -379,6 +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); 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_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 3f7f7ea16..6ae7a566a 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -684,6 +684,7 @@ void LP_initcoins(void *ctx,int32_t pubsock,cJSON *coins) LP_priceinfoadd(activecoins[i]); if ( (coin= LP_coinfind(activecoins[i])) != 0 && LP_getheight(coin) <= 0 ) coin->inactive = (uint32_t)time(NULL); + LP_unspents_load(coin->symbol,coin->smartaddr); } if ( (n= cJSON_GetArraySize(coins)) > 0 ) { @@ -697,6 +698,7 @@ void LP_initcoins(void *ctx,int32_t pubsock,cJSON *coins) LP_priceinfoadd(jstr(item,"coin")); if ( (coin= LP_coinfind(symbol)) != 0 && LP_getheight(coin) <= 0 ) coin->inactive = (uint32_t)time(NULL); + LP_unspents_load(coin->symbol,coin->smartaddr); } } } diff --git a/iguana/exchanges/LP_socket.c b/iguana/exchanges/LP_socket.c index 1b584ac28..19a7b5363 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; 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 height,usecache=1; if ( (coin= LP_coinfind(symbol)) == 0 ) return(0); if ( ep == 0 || ep->heightp == 0 ) @@ -565,7 +565,15 @@ cJSON *electrum_address_listunspent(char *symbol,struct electrum_info *ep,cJSON { 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))); if ( electrum_process_array(coin,ep,addr,retjson,electrumflag) != 0 ) + { LP_postutxos(coin->symbol,addr); + if ( strcmp(addr,coin->smartaddr) == 0 ) + { + retstr = jprint(retjson,0); + LP_unspents_cache(coin->symbol,coin->smartaddr,retstr); + free(retstr); + } + } if ( ap != 0 ) { ap->unspenttime = (uint32_t)time(NULL); diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index 8a7f0d0b6..ffd5d3f9e 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -981,3 +981,37 @@ int32_t LP_undospends(struct iguana_info *coin,int32_t lastheight) } return(num); } + +void LP_unspents_cache(char *symbol,char *addr,char *arraystr) +{ + 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 ) + { + fwrite(arraystr,1,strlen(arraystr),fp); + fclose(fp); + } +} + +void LP_unspents_load(char *symbol,char *addr) +{ + char fname[1024],*arraystr; long fsize; struct iguana_info *coin; cJSON *retjson; + if ( (coin= LP_coinfind(symbol)) != 0 ) + { + sprintf(fname,"%s/UNSPENTS/%s_%s",GLOBAL_DBDIR,symbol,addr), OS_portable_path(fname); + if ( (arraystr= OS_filestr(&fsize,fname)) != 0 ) + { + if ( (retjson= cJSON_Parse(arraystr)) != 0 ) + { + if ( electrum_process_array(coin,coin->electrum,coin->smartaddr,retjson,1) == 0 ) + printf("error electrum_process_array\n"); + else printf("processed %s\n",arraystr); + free_json(retjson); + } + free(arraystr); + } + } +} + + + diff --git a/iguana/exchanges/mm.c b/iguana/exchanges/mm.c index 632ab794d..b5cc4404e 100644 --- a/iguana/exchanges/mm.c +++ b/iguana/exchanges/mm.c @@ -882,6 +882,7 @@ int main(int argc, const char * argv[]) sprintf(dirname,"%s",GLOBAL_DBDIR), OS_ensure_directory(dirname); sprintf(dirname,"%s/SWAPS",GLOBAL_DBDIR), OS_ensure_directory(dirname); sprintf(dirname,"%s/PRICES",GLOBAL_DBDIR), OS_ensure_directory(dirname); + sprintf(dirname,"%s/UNSPENTS",GLOBAL_DBDIR), OS_ensure_directory(dirname); #ifdef FROM_JS argc = 2; retjson = cJSON_Parse("{\"client\":1,\"passphrase\":\"test\"}");