From 41f13442c288e0b51eaa475e2f179f69c9399675 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 27 Sep 2016 15:03:49 -0300 Subject: [PATCH] test --- iguana/iguana_unspents.c | 34 ++++++++++++++++++++++++++++++++-- includes/iguana_structs.h | 1 + 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/iguana/iguana_unspents.c b/iguana/iguana_unspents.c index 4c7af34c6..3891d903c 100755 --- a/iguana/iguana_unspents.c +++ b/iguana/iguana_unspents.c @@ -872,7 +872,7 @@ int32_t iguana_markedunspents_find(struct iguana_info *coin,int32_t *firstslotp, void iguana_unspents_mark(struct supernet_info *myinfo,struct iguana_info *coin,cJSON *vins) { - int32_t i,n,firstslot; int16_t vout; cJSON *item; bits256 txid; char str[65]; + int32_t i,n,firstslot; int16_t vout; cJSON *item; bits256 txid; char str[65],fname[1024]; if ( (n= cJSON_GetArraySize(vins)) > 0 ) { for (i=0; imarkedunspents[firstslot] = txid; coin->markedunspents[firstslot].ushorts[15] = vout; + if ( coin->utxofp == 0 ) + { + sprintf(fname,"%s/%s/utxo.dat",GLOBAL_DBDIR,coin->symbol), OS_compatible_path(fname); + if ( (coin->utxofp= fopen(fname,"rb+")) == 0 ) + coin->utxofp = fopen(fname,"wb"); + else fseek(coin->utxofp,0,SEEK_END); + if ( coin->utxofp != 0 ) + { + fwrite(txid.bytes,1,sizeof(txid),coin->utxofp); + fwrite(&vout,1,sizeof(vout),coin->utxofp); + fflush(coin->utxofp); + } + } } } else printf("error firstslot.[%d] <- %s/v%d\n",firstslot,bits256_str(str,txid),vout); } @@ -898,7 +911,24 @@ void iguana_unspents_mark(struct supernet_info *myinfo,struct iguana_info *coin, void iguana_unspents_markinit(struct supernet_info *myinfo,struct iguana_info *coin) { - char *filestr,fname[1024]; long filesize; bits256 filetxid; cJSON *array,*item; int32_t i,filevout,n,firstslot; + char *filestr,fname[1024]; FILE *fp; long filesize; bits256 filetxid; cJSON *array,*item; int32_t i,filevout,n,firstslot; + sprintf(fname,"%s/%s/utxo.dat",GLOBAL_DBDIR,coin->symbol), OS_compatible_path(fname); + if ( (fp= fopen(fname,"rb")) != 0 ) + { + while ( fread(&filetxid,1,sizeof(filetxid),fp) == sizeof(filetxid) && fread(&filevout,1,sizeof(filevout),fp) == sizeof(filevout) ) + { + if ( iguana_markedunspents_find(coin,&firstslot,filetxid,filevout) < 0 ) + { + if ( firstslot >= 0 ) + { + char str[65]; printf("slot.[%d] <- %s/v%d\n",firstslot,bits256_str(str,filetxid),filevout); + coin->markedunspents[firstslot] = filetxid; + coin->markedunspents[firstslot].ushorts[15] = filevout; + } + } + } + fclose(fp); + } sprintf(fname,"%s/%s/utxo.json",GLOBAL_DBDIR,coin->symbol), OS_compatible_path(fname); if ( (filestr= OS_filestr(&filesize,fname)) != 0 ) { diff --git a/includes/iguana_structs.h b/includes/iguana_structs.h index ba2d49dd4..bbe312de2 100755 --- a/includes/iguana_structs.h +++ b/includes/iguana_structs.h @@ -506,6 +506,7 @@ struct iguana_info uint64_t histbalance,RTcredits,RTdebits; void *utxoaddrfileptr; long utxoaddrfilesize; uint32_t utxoaddrlastcount,*utxoaddroffsets,lastunspentsupdate; uint8_t *utxoaddrtable; bits256 utxoaddrhash; + FILE *utxofp; bits256 markedunspents[1024]; struct iguana_block *RTblocks[65536]; uint8_t *RTrawdata[65536]; int32_t RTrecvlens[65536],RTnumtx[65536]; struct iguana_RTtxid *RTdataset; struct iguana_RTaddr *RTaddrs;