Browse Source

Test

etomic
jl777 8 years ago
parent
commit
51a4997f65
  1. 31
      iguana/exchanges/LP_cache.c
  2. 2
      iguana/exchanges/LP_coins.c
  3. 4
      iguana/exchanges/LP_include.h

31
iguana/exchanges/LP_cache.c

@ -87,22 +87,26 @@ cJSON *LP_create_transaction(struct iguana_info *coin,bits256 txid,uint8_t *seri
void LP_SPV_store(struct iguana_info *coin,char *coinaddr,bits256 txid,int32_t height) void LP_SPV_store(struct iguana_info *coin,char *coinaddr,bits256 txid,int32_t height)
{ {
struct LP_transaction TX; int32_t n; struct LP_transaction *tx = 0; FILE *fp; char fname[512]; struct LP_transaction TX; int32_t n; struct LP_transaction *tx = 0;
if ( coin->cachefp != 0 && (tx= LP_transactionfind(coin,txid)) != 0 && tx->serialized != 0 && tx->len > 0 ) //strcmp(coin->smartaddr,coinaddr) == 0 && if ( (tx= LP_transactionfind(coin,txid)) != 0 && tx->serialized != 0 && tx->len > 0 )
{
sprintf(fname,"%s/UNSPENTS/%s.SPV",GLOBAL_DBDIR,coin->symbol), OS_portable_path(fname);
if ( (fp= OS_appendfile(fname)) != 0 )
{ {
char str[65]; printf("store %s %s.[%d]\n",coin->symbol,bits256_str(str,txid),tx->len); char str[65]; printf("store %s %s.[%d]\n",coin->symbol,bits256_str(str,txid),tx->len);
TX = *tx; TX = *tx;
memset(&TX.hh,0,sizeof(TX.hh)); memset(&TX.hh,0,sizeof(TX.hh));
TX.serialized = 0; TX.serialized = 0;
TX.SPV = height; TX.SPV = height;
fwrite(&TX,1,sizeof(TX),coin->cachefp); fwrite(&TX,1,sizeof(TX),fp);
if ( tx->numvouts > 0 ) if ( tx->numvouts > 0 )
fwrite(TX.outpoints,tx->numvouts,sizeof(*TX.outpoints),coin->cachefp); fwrite(TX.outpoints,tx->numvouts,sizeof(*TX.outpoints),fp);
fwrite(tx->serialized,1,tx->len,coin->cachefp); fwrite(tx->serialized,1,tx->len,fp);
n = tx->len; n = tx->len;
while ( (n & 7) != 0 ) while ( (n & 7) != 0 )
fputc(0,coin->cachefp), n++; fputc(0,fp), n++;
fflush(coin->cachefp); fclose(fp);
}
} }
} }
@ -130,13 +134,11 @@ int32_t LP_cacheitem(struct iguana_info *coin,struct LP_transaction *tx,long rem
return(-1); return(-1);
} }
long LP_cacheptrs_init(FILE **wfp,struct iguana_info *coin) void LP_cacheptrs_init(struct iguana_info *coin)
{ {
char fname[1024]; FILE *fp; int32_t flag = 0; long n,fsize=0,len = 0; uint8_t *ptr = 0; char fname[1024]; FILE *fp; int32_t tflag=0,flag = 0; long n,fsize=0,len = 0; uint8_t *ptr = 0;
sprintf(fname,"%s/UNSPENTS/%s.SPV",GLOBAL_DBDIR,coin->symbol), OS_portable_path(fname); sprintf(fname,"%s/UNSPENTS/%s.SPV",GLOBAL_DBDIR,coin->symbol), OS_portable_path(fname);
fp = fopen(fname,"rb"); fp = fopen(fname,"rb");
if ( ((*wfp)= OS_appendfile(fname)) != 0 )
{
if ( fp != 0 ) if ( fp != 0 )
{ {
fseek(fp,0,SEEK_END); fseek(fp,0,SEEK_END);
@ -151,17 +153,18 @@ long LP_cacheptrs_init(FILE **wfp,struct iguana_info *coin)
if ( (n= LP_cacheitem(coin,(struct LP_transaction *)&ptr[len],fsize - len)) < 0 ) if ( (n= LP_cacheitem(coin,(struct LP_transaction *)&ptr[len],fsize - len)) < 0 )
{ {
printf("cacheitem error at %s offset.%ld when fsize.%ld\n",coin->symbol,len,fsize); printf("cacheitem error at %s offset.%ld when fsize.%ld\n",coin->symbol,len,fsize);
fseek(*wfp,len,SEEK_SET); tflag = 1;
break; break;
} }
len += n; len += n;
if ( (len & 7) != 0 ) if ( (len & 7) != 0 )
printf("odd offset at %ld\n",len); printf("odd offset at %ld\n",len);
} }
OS_releasemap(ptr,fsize);
} }
} }
} if ( tflag != 0 )
return(fsize); OS_truncate(fname,len);
} }
bits256 iguana_merkle(bits256 *tree,int32_t txn_count) bits256 iguana_merkle(bits256 *tree,int32_t txn_count)

2
iguana/exchanges/LP_coins.c

@ -353,7 +353,7 @@ uint16_t LP_coininit(struct iguana_info *coin,char *symbol,char *name,char *asse
coin->zcash = LP_IS_BITCOINCASH; coin->zcash = LP_IS_BITCOINCASH;
//printf("set coin.%s <- LP_IS_BITCOINCASH %d\n",symbol,coin->zcash); //printf("set coin.%s <- LP_IS_BITCOINCASH %d\n",symbol,coin->zcash);
} }
coin->cachesize = LP_cacheptrs_init(&coin->cachefp,coin); LP_cacheptrs_init(coin);
return(port); return(port);
} }

4
iguana/exchanges/LP_include.h

@ -268,7 +268,7 @@ struct iguana_info
char symbol[16],smartaddr[64],userpass[1024],serverport[128]; char symbol[16],smartaddr[64],userpass[1024],serverport[128];
// portfolio // portfolio
double price_kmd,force,perc,goal,goalperc,relvolume,rate; double price_kmd,force,perc,goal,goalperc,relvolume,rate;
void *electrum; void *ctx; FILE *cachefp; long cachesize; void *electrum; void *ctx;
uint64_t maxamount,kmd_equiv,balanceA,balanceB,valuesumA,valuesumB; uint64_t maxamount,kmd_equiv,balanceA,balanceB,valuesumA,valuesumB;
uint8_t pubkey33[33],zcash; uint8_t pubkey33[33],zcash;
bits256 lastprivkey; uint32_t lastprivkeytime; int32_t privkeydepth; bits256 lastprivkey; uint32_t lastprivkeytime; int32_t privkeydepth;
@ -433,7 +433,7 @@ char *basilisk_swapentry(uint32_t requestid,uint32_t quoteid);
uint64_t LP_KMDvalue(struct iguana_info *coin,uint64_t balance); uint64_t LP_KMDvalue(struct iguana_info *coin,uint64_t balance);
int32_t LP_address_utxoadd(char *debug,struct iguana_info *coin,char *coinaddr,bits256 txid,int32_t vout,uint64_t value,int32_t height,int32_t spendheight); int32_t LP_address_utxoadd(char *debug,struct iguana_info *coin,char *coinaddr,bits256 txid,int32_t vout,uint64_t value,int32_t height,int32_t spendheight);
void LP_smartutxos_push(struct iguana_info *coin); void LP_smartutxos_push(struct iguana_info *coin);
long LP_cacheptrs_init(FILE **wfp,struct iguana_info *coin); void LP_cacheptrs_init(struct iguana_info *coin);
cJSON *LP_address_utxos(struct iguana_info *coin,char *coinaddr,int32_t electrumret); cJSON *LP_address_utxos(struct iguana_info *coin,char *coinaddr,int32_t electrumret);
cJSON *LP_gettxout(char *symbol,char *coinaddr,bits256 txid,int32_t vout); cJSON *LP_gettxout(char *symbol,char *coinaddr,bits256 txid,int32_t vout);
void LP_postutxos(char *symbol,char *coinaddr); void LP_postutxos(char *symbol,char *coinaddr);

Loading…
Cancel
Save