|
|
@ -60,18 +60,72 @@ cJSON *LP_cache_transaction(struct iguana_info *coin,bits256 txid,uint8_t *seria |
|
|
|
return(txobj); |
|
|
|
} |
|
|
|
|
|
|
|
struct LP_transaction |
|
|
|
{ |
|
|
|
UT_hash_handle hh; |
|
|
|
bits256 txid; |
|
|
|
int32_t height,numvouts,numvins,len,SPV; |
|
|
|
uint8_t *serialized; |
|
|
|
struct LP_outpoint outpoints[]; |
|
|
|
}; |
|
|
|
|
|
|
|
int32_t LP_cacheitem(uint8_t *ptr,long remains) |
|
|
|
{ |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
void *LP_cacheptr(FILE **wfp,long *fsizep,struct iguana_info *coin) |
|
|
|
{ |
|
|
|
char fname[1024]; long n,len = 0; uint8_t *ptr = 0; |
|
|
|
sprintf(fname,"%s/UNSPENTS/%s.SPV",GLOBAL_DBDIR,coin->symbol), OS_portable_path(fname); |
|
|
|
if ( ((*wfp)= OS_appendfile(fname)) != 0 ) |
|
|
|
{ |
|
|
|
ptr = OS_portable_mapfile(fname,fsizep,0); |
|
|
|
while ( len < *fsizep ) |
|
|
|
{ |
|
|
|
if ( (n= LP_cacheitem(coin,&ptr[len],*fsizep - len)) < 0 ) |
|
|
|
{ |
|
|
|
printf("cacheitem error at %s offset.%ld when fsize.%ld\n",coin->symbol,len,*fsizep); |
|
|
|
fseek(*wfp,len,SEEK_SET); |
|
|
|
break; |
|
|
|
} |
|
|
|
len += n; |
|
|
|
} |
|
|
|
} |
|
|
|
return(ptr); |
|
|
|
} |
|
|
|
|
|
|
|
int32_t LP_SPV_load(struct iguana_info *coin,bits256 txid,int32_t height) |
|
|
|
{ |
|
|
|
struct LP_transaction *tp; |
|
|
|
HASH_FIND(hh,coin->SPVcache,&txid,sizeof(txid),cp) |
|
|
|
return(-1); |
|
|
|
} |
|
|
|
|
|
|
|
struct LP_transaction |
|
|
|
{ |
|
|
|
UT_hash_handle hh; |
|
|
|
bits256 txid; |
|
|
|
int32_t height,numvouts,numvins,len,SPV; |
|
|
|
uint8_t *serialized; |
|
|
|
struct LP_outpoint outpoints[]; |
|
|
|
}; |
|
|
|
|
|
|
|
void LP_SPV_store(struct iguana_info *coin,char *coinaddr,bits256 txid,int32_t height) |
|
|
|
{ |
|
|
|
struct LP_transaction *tx = 0; |
|
|
|
if ( strcmp(coin->smartaddr,coinaddr) == 0 && (tx= LP_transactionfind(coin,txid)) != 0 && tx->serialized != 0 ) |
|
|
|
struct LP_transaction TX; 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 &&
|
|
|
|
{ |
|
|
|
//char str[65]; printf("store %s %s.[%d]\n",coin->symbol,bits256_str(str,txid),tx->len);
|
|
|
|
} //else printf("skip SPV store for (%s) tx.%p\n",coinaddr,tx);
|
|
|
|
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; |
|
|
|
fwrite(&TX,1,sizeof(TX),coin->cachefp); |
|
|
|
if ( tx->numvouts > 0 ) |
|
|
|
fwrite(TX.outpoints,tx->numvouts,sizeof(*TX.outpoints),coin->cachefp); |
|
|
|
fwrite(tx->serialized,1,tx->len,coin->cachefp); |
|
|
|
fflush(coin->cachefp); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
bits256 iguana_merkle(bits256 *tree,int32_t txn_count) |
|
|
@ -144,9 +198,9 @@ bits256 LP_merkleroot(struct iguana_info *coin,struct electrum_info *ep,int32_t |
|
|
|
|
|
|
|
int32_t LP_merkleproof(struct iguana_info *coin,char *coinaddr,struct electrum_info *ep,bits256 txid,int32_t height) |
|
|
|
{ |
|
|
|
cJSON *merkobj,*merkles; bits256 roothash,merkleroot; int32_t retval,m,SPV = 0; |
|
|
|
if ( strcmp(coin->smartaddr,coinaddr) == 0 && (retval= LP_SPV_load(coin,txid,height)) > 0 ) |
|
|
|
return(retval); |
|
|
|
struct LP_transaction *tx; cJSON *merkobj,*merkles; bits256 roothash,merkleroot; int32_t retval,m,SPV = 0; |
|
|
|
if ( (tx= LP_transactionfind(coin,txid)) != 0 && tx->height == height && tx->SPV > 0 ) |
|
|
|
return(tx->SPV); |
|
|
|
if ( (merkobj= electrum_getmerkle(coin->symbol,ep,&merkobj,txid,height)) != 0 ) |
|
|
|
{ |
|
|
|
char str[65],str2[65],str3[65]; |
|
|
|