Browse Source

test

release/v0.1
jl777 9 years ago
parent
commit
7d0891a9c6
  1. 4
      basilisk/basilisk_bitcoin.c
  2. 103
      iguana/iguana_realtime.c

4
basilisk/basilisk_bitcoin.c

@ -944,7 +944,7 @@ struct basilisk_spend *basilisk_addspend(struct supernet_info *myinfo,char *symb
s->txid = txid;
s->vout = vout;
strcpy(s->symbol,symbol);
char str[65]; printf("ADDSPEND.%s %s/v%d\n",symbol,bits256_str(str,txid),vout);
//char str[65]; printf("ADDSPEND.%s %s/v%d\n",symbol,bits256_str(str,txid),vout);
// mutex
return(s);
}
@ -976,7 +976,7 @@ void basilisk_unspent_update(struct supernet_info *myinfo,struct iguana_info *co
bu.unspentind = juint(item,"checkind");
bu.timestamp = juint(item,"timestamp");
decode_hex(bu.script,bu.spendlen,script);
printf("unspentupdate.(%s)\n",jprint(item,0));
//printf("unspentupdate.(%s)\n",jprint(item,0));
n = waddr->numunspents;
for (i=0; i<n; i++)
{

103
iguana/iguana_realtime.c

@ -473,6 +473,51 @@ int32_t iguana_realtime_update(struct supernet_info *myinfo,struct iguana_info *
#define uthash_malloc(size) ((coin->RTHASHMEM.ptr == 0) ? mycalloc('u',1,size) : iguana_memalloc(&coin->RTHASHMEM,size,1))
#define uthash_free(mem,size) ((coin->RTHASHMEM.ptr == 0) ? myfree(mem,size) : 0)
void iguana_RTtxid_free(struct iguana_RTtxid *RTptr)
{
int32_t i;
if ( 0 )
{
for (i=0; i<RTptr->numvouts; i++)
if ( RTptr->unspents[i] != 0 )
free(RTptr->unspents[i]);
for (i=0; i<RTptr->numvins; i++)
if ( RTptr->spends[i] != 0 )
free(RTptr->spends[i]);
free(RTptr);
}
}
void iguana_RTdataset_free(struct iguana_info *coin)
{
struct iguana_RTtxid *RTptr,*tmp; struct iguana_RTaddr *RTaddr,*tmp2;
HASH_ITER(hh,coin->RTdataset,RTptr,tmp)
{
HASH_DELETE(hh,coin->RTdataset,RTptr);
iguana_RTtxid_free(RTptr);
}
HASH_ITER(hh,coin->RTaddrs,RTaddr,tmp2)
{
HASH_DELETE(hh,coin->RTaddrs,RTaddr);
//free(RTaddr);
}
iguana_hhutxo_purge(coin);
iguana_memreset(&coin->RTHASHMEM);
}
void iguana_RTreset(struct iguana_info *coin)
{
iguana_utxoaddrs_purge(coin);
//iguana_utxoupdate(coin,-1,0,0,0,0,-1,0); // free hashtables
coin->lastRTheight = 0;
coin->RTheight = coin->firstRTheight;
iguana_RTdataset_free(coin);
if ( coin->RTHASHMEM.ptr == 0 )
iguana_meminit(&coin->RTHASHMEM,"RTHASHMEM",0,1024*1024*1024 + ((strcmp(coin->symbol,"BTC") == 0) ? 2*1024*1024*1024 : 0),0);
iguana_memreset(&coin->RTHASHMEM);
printf("%s RTreset %d\n",coin->symbol,coin->RTheight);
}
struct iguana_RTaddr *iguana_RTaddrfind(struct iguana_info *coin,uint8_t *rmd160,char *coinaddr)
{
struct iguana_RTaddr *RTaddr; int32_t len; char _coinaddr[64];
@ -506,7 +551,7 @@ void iguana_RTcoinaddr(struct iguana_info *coin,struct iguana_RTtxid *RTptr,stru
HASH_FIND(hh,coin->RTaddrs,coinaddr,len,RTaddr);
if ( RTaddr == 0 )
{
RTaddr = calloc(1,sizeof(*RTaddr));
RTaddr = uthash_malloc(sizeof(*RTaddr));//calloc(1,sizeof(*RTaddr));
strncpy(RTaddr->coinaddr,coinaddr,len);
RTaddr->histbalance = iguana_utxoaddrtablefind(coin,-1,-1,rmd160);
HASH_ADD_KEYPTR(hh,coin->RTaddrs,RTaddr->coinaddr,len,RTaddr);
@ -532,7 +577,7 @@ void iguana_RTcoinaddr(struct iguana_info *coin,struct iguana_RTtxid *RTptr,stru
if ( RTaddr->lastunspent == unspent )
{
RTaddr->lastunspent = unspent->prevunspent;
free(unspent);
//free(unspent);
} else printf("lastunspent.%p != %p\n",RTaddr->lastunspent,unspent);
//RTaddr->unspents[i] = RTaddr->unspents[--RTaddr->numunspents];
}
@ -541,10 +586,10 @@ void iguana_RTcoinaddr(struct iguana_info *coin,struct iguana_RTtxid *RTptr,stru
printf("%lld %s %.8f h %.8f, cr %.8f deb %.8f [%.8f] numunspents.%d %p\n",(long long)polarity,coinaddr,dstr(value),dstr(RTaddr->histbalance),dstr(RTaddr->credits),dstr(RTaddr->debits),dstr(RTaddr->credits)-dstr(RTaddr->debits)+dstr(RTaddr->histbalance),RTaddr->numunspents,unspent);
}
struct iguana_RTunspent *iguana_RTunspent_create(uint8_t *rmd160,int64_t value,uint8_t *script,int32_t scriptlen,struct iguana_RTtxid *parent,int32_t vout)
struct iguana_RTunspent *iguana_RTunspent_create(struct iguana_info *coin,uint8_t *rmd160,int64_t value,uint8_t *script,int32_t scriptlen,struct iguana_RTtxid *parent,int32_t vout)
{
struct iguana_RTunspent *unspent;
unspent = calloc(1,sizeof(*unspent) + scriptlen);
unspent = uthash_malloc(sizeof(*unspent) + scriptlen);//calloc(1,sizeof(*unspent) + scriptlen);
unspent->value = value;
if ( (unspent->parent= parent) != 0 )
unspent->height = parent->height;
@ -568,7 +613,7 @@ void iguana_RTunspent(struct iguana_info *coin,struct iguana_RTtxid *RTptr,struc
{
if ( polarity > 0 )
{
unspent = iguana_RTunspent_create(rmd160,value,script,scriptlen>0?scriptlen:0,RTptr,vout);
unspent = iguana_RTunspent_create(coin,rmd160,value,script,scriptlen>0?scriptlen:0,RTptr,vout);
RTptr->unspents[vout] = unspent;
} else printf("iguana_RTunspent missing vout.%d ptr\n",vout);
}
@ -609,7 +654,7 @@ void iguana_RTspend(struct supernet_info *myinfo,struct iguana_info *coin,struct
{
if ( polarity > 0 )
{
spend = calloc(1,sizeof(*spend) + scriptlen);
spend = uthash_malloc(sizeof(*spend) + scriptlen);//calloc(1,sizeof(*spend) + scriptlen);
spend->prev_hash = prev_hash;
spend->prev_vout = prev_vout;
spend->scriptlen = scriptlen;
@ -644,7 +689,7 @@ void iguana_RTspend(struct supernet_info *myinfo,struct iguana_info *coin,struct
int32_t spentheight,lockedflag,RTspentflag;
bitcoin_addr2rmd160(&addrtype,rmd160,coinaddr);
//printf("found unspentind (%s %.8f).%d spendlen.%d\n",coinaddr,dstr(value),addrtype,spendlen);
unspent = iguana_RTunspent_create(rmd160,value,spendscript,spendlen>0?spendlen:0,0,prev_vout);
unspent = iguana_RTunspent_create(coin,rmd160,value,spendscript,spendlen>0?spendlen:0,0,prev_vout);
memset(&spentpt,0,sizeof(spentpt));
spentpt.unspentind = unspentind;
spentpt.hdrsi = height / coin->chain->bundlesize;
@ -664,35 +709,6 @@ void iguana_RTspend(struct supernet_info *myinfo,struct iguana_info *coin,struct
} else printf("null rtptr? %s vini.%d spend.(%s/v%d) %lld\n",bits256_str(str,txid),vini,bits256_str(str2,prev_hash),prev_vout,(long long)polarity);
}
void iguana_RTtxid_free(struct iguana_RTtxid *RTptr)
{
int32_t i;
for (i=0; i<RTptr->numvouts; i++)
if ( RTptr->unspents[i] != 0 )
free(RTptr->unspents[i]);
for (i=0; i<RTptr->numvins; i++)
if ( RTptr->spends[i] != 0 )
free(RTptr->spends[i]);
free(RTptr);
}
void iguana_RTdataset_free(struct iguana_info *coin)
{
struct iguana_RTtxid *RTptr,*tmp; struct iguana_RTaddr *RTaddr,*tmp2; struct iguana_hhutxo *hhutxo;
HASH_ITER(hh,coin->RTdataset,RTptr,tmp)
{
HASH_DELETE(hh,coin->RTdataset,RTptr);
iguana_RTtxid_free(RTptr);
}
HASH_ITER(hh,coin->RTaddrs,RTaddr,tmp2)
{
HASH_DELETE(hh,coin->RTaddrs,RTaddr);
free(RTaddr);
}
iguana_hhutxo_purge(coin);
iguana_memreset(&coin->RTHASHMEM);
}
struct iguana_RTtxid *iguana_RTtxid_create(struct iguana_info *coin,struct iguana_block *block,int64_t polarity,int32_t txi,int32_t txn_count,bits256 txid,int32_t numvouts,int32_t numvins,uint32_t locktime,uint32_t version,uint32_t timestamp)
{
struct iguana_RTtxid *RTptr; char str[65];
@ -704,7 +720,7 @@ struct iguana_RTtxid *iguana_RTtxid_create(struct iguana_info *coin,struct iguan
HASH_FIND(hh,coin->RTdataset,txid.bytes,sizeof(txid),RTptr);
if ( RTptr == 0 )
{
RTptr = calloc(1,sizeof(*RTptr) + sizeof(void *)*numvins + sizeof(void *)*numvouts);
RTptr = uthash_malloc(sizeof(*RTptr) + sizeof(void *)*numvins + sizeof(void *)*numvouts);//calloc(1,sizeof(*RTptr) + sizeof(void *)*numvins + sizeof(void *)*numvouts);
RTptr->txi = txi, RTptr->txn_count = txn_count;
RTptr->coin = coin;
RTptr->block = block;
@ -777,19 +793,6 @@ int32_t _iguana_RTunspentfind(struct supernet_info *myinfo,struct iguana_info *c
return(spendlen);
}
void iguana_RTreset(struct iguana_info *coin)
{
iguana_utxoaddrs_purge(coin);
//iguana_utxoupdate(coin,-1,0,0,0,0,-1,0); // free hashtables
coin->lastRTheight = 0;
coin->RTheight = coin->firstRTheight;
iguana_RTdataset_free(coin);
if ( coin->RTHASHMEM.ptr == 0 )
iguana_meminit(&coin->RTHASHMEM,"RTHASHMEM",0,1024*1024*1024,0);
iguana_memreset(&coin->RTHASHMEM);
printf("%s RTreset %d\n",coin->symbol,coin->RTheight);
}
void iguana_RTunmap(uint8_t *ptr,uint32_t len)
{
OS_releasemap(&ptr[-2*sizeof(len)],len+2*sizeof(len));

Loading…
Cancel
Save