Browse Source

unspents cache

etomic
jl777 7 years ago
parent
commit
a3b84b2e2b
  1. 1
      iguana/exchanges/LP_include.h
  2. 2
      iguana/exchanges/LP_nativeDEX.c
  3. 10
      iguana/exchanges/LP_socket.c
  4. 34
      iguana/exchanges/LP_utxo.c
  5. 1
      iguana/exchanges/mm.c

1
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); 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_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); 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); uint16_t LP_psock_get(char *connectaddr,char *publicaddr,int32_t ispaired);
//void LP_utxo_clientpublish(struct LP_utxoinfo *utxo); //void LP_utxo_clientpublish(struct LP_utxoinfo *utxo);
int32_t LP_coinbus(uint16_t coin_busport); int32_t LP_coinbus(uint16_t coin_busport);

2
iguana/exchanges/LP_nativeDEX.c

@ -684,6 +684,7 @@ void LP_initcoins(void *ctx,int32_t pubsock,cJSON *coins)
LP_priceinfoadd(activecoins[i]); LP_priceinfoadd(activecoins[i]);
if ( (coin= LP_coinfind(activecoins[i])) != 0 && LP_getheight(coin) <= 0 ) if ( (coin= LP_coinfind(activecoins[i])) != 0 && LP_getheight(coin) <= 0 )
coin->inactive = (uint32_t)time(NULL); coin->inactive = (uint32_t)time(NULL);
LP_unspents_load(coin->symbol,coin->smartaddr);
} }
if ( (n= cJSON_GetArraySize(coins)) > 0 ) 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")); LP_priceinfoadd(jstr(item,"coin"));
if ( (coin= LP_coinfind(symbol)) != 0 && LP_getheight(coin) <= 0 ) if ( (coin= LP_coinfind(symbol)) != 0 && LP_getheight(coin) <= 0 )
coin->inactive = (uint32_t)time(NULL); coin->inactive = (uint32_t)time(NULL);
LP_unspents_load(coin->symbol,coin->smartaddr);
} }
} }
} }

10
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 *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 ) if ( (coin= LP_coinfind(symbol)) == 0 )
return(0); return(0);
if ( ep == 0 || ep->heightp == 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))); 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 ) if ( electrum_process_array(coin,ep,addr,retjson,electrumflag) != 0 )
{
LP_postutxos(coin->symbol,addr); 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 ) if ( ap != 0 )
{ {
ap->unspenttime = (uint32_t)time(NULL); ap->unspenttime = (uint32_t)time(NULL);

34
iguana/exchanges/LP_utxo.c

@ -981,3 +981,37 @@ int32_t LP_undospends(struct iguana_info *coin,int32_t lastheight)
} }
return(num); 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);
}
}
}

1
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",GLOBAL_DBDIR), OS_ensure_directory(dirname);
sprintf(dirname,"%s/SWAPS",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/PRICES",GLOBAL_DBDIR), OS_ensure_directory(dirname);
sprintf(dirname,"%s/UNSPENTS",GLOBAL_DBDIR), OS_ensure_directory(dirname);
#ifdef FROM_JS #ifdef FROM_JS
argc = 2; argc = 2;
retjson = cJSON_Parse("{\"client\":1,\"passphrase\":\"test\"}"); retjson = cJSON_Parse("{\"client\":1,\"passphrase\":\"test\"}");

Loading…
Cancel
Save