|
|
@ -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) |
|
|
|
{ |
|
|
|
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 &&
|
|
|
|
FILE *fp; char fname[512]; struct LP_transaction TX; int32_t n; struct LP_transaction *tx = 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); |
|
|
|
TX = *tx; |
|
|
|
memset(&TX.hh,0,sizeof(TX.hh)); |
|
|
|
TX.serialized = 0; |
|
|
|
TX.SPV = height; |
|
|
|
fwrite(&TX,1,sizeof(TX),coin->cachefp); |
|
|
|
fwrite(&TX,1,sizeof(TX),fp); |
|
|
|
if ( tx->numvouts > 0 ) |
|
|
|
fwrite(TX.outpoints,tx->numvouts,sizeof(*TX.outpoints),coin->cachefp); |
|
|
|
fwrite(tx->serialized,1,tx->len,coin->cachefp); |
|
|
|
fwrite(TX.outpoints,tx->numvouts,sizeof(*TX.outpoints),fp); |
|
|
|
fwrite(tx->serialized,1,tx->len,fp); |
|
|
|
n = tx->len; |
|
|
|
while ( (n & 7) != 0 ) |
|
|
|
fputc(0,coin->cachefp), n++; |
|
|
|
fflush(coin->cachefp); |
|
|
|
fputc(0,fp), n++; |
|
|
|
fclose(fp); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -130,13 +134,11 @@ int32_t LP_cacheitem(struct iguana_info *coin,struct LP_transaction *tx,long rem |
|
|
|
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); |
|
|
|
fp = fopen(fname,"rb"); |
|
|
|
if ( ((*wfp)= OS_appendfile(fname)) != 0 ) |
|
|
|
{ |
|
|
|
if ( fp != 0 ) |
|
|
|
{ |
|
|
|
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 ) |
|
|
|
{ |
|
|
|
printf("cacheitem error at %s offset.%ld when fsize.%ld\n",coin->symbol,len,fsize); |
|
|
|
fseek(*wfp,len,SEEK_SET); |
|
|
|
tflag = 1; |
|
|
|
break; |
|
|
|
} |
|
|
|
len += n; |
|
|
|
if ( (len & 7) != 0 ) |
|
|
|
printf("odd offset at %ld\n",len); |
|
|
|
} |
|
|
|
OS_releasemap(ptr,fsize); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
return(fsize); |
|
|
|
if ( tflag != 0 ) |
|
|
|
OS_truncate(fname,len); |
|
|
|
} |
|
|
|
|
|
|
|
bits256 iguana_merkle(bits256 *tree,int32_t txn_count) |
|
|
|