Browse Source

tesst

release/v0.1
jl777 8 years ago
parent
commit
167496ab16
  1. 2
      iguana/iguana_blocks.c
  2. 107
      iguana/iguana_realtime.c
  3. 4
      iguana/iguana_recv.c
  4. 10
      iguana/iguana_unspents.c
  5. 13
      includes/iguana_structs.h

2
iguana/iguana_blocks.c

@ -677,7 +677,9 @@ struct iguana_block *_iguana_chainlink(struct iguana_info *coin,struct iguana_bl
process_iguanablock(block->serdata,CHAINPARMS); process_iguanablock(block->serdata,CHAINPARMS);
}*/ }*/
iguana_blockzcopy(coin->chain->zcash,(void *)&coin->blocks.hwmchain,block); iguana_blockzcopy(coin->chain->zcash,(void *)&coin->blocks.hwmchain,block);
portable_mutex_lock(&coin->RTmutex);
iguana_RTnewblock(coin,block); iguana_RTnewblock(coin,block);
portable_mutex_unlock(&coin->RTmutex);
return(block); return(block);
} }
} }

107
iguana/iguana_realtime.c

@ -464,11 +464,71 @@ int32_t iguana_realtime_update(struct supernet_info *myinfo,struct iguana_info *
return(flag); return(flag);
} }
void iguana_RTcoinaddr(struct iguana_info *coin,struct iguana_RTtxid *RTptr,struct iguana_block *block,int64_t polarity,uint8_t *rmd160,int64_t value) void iguana_RTcoinaddr(struct iguana_info *coin,struct iguana_RTtxid *RTptr,struct iguana_block *block,int64_t polarity,char *coinaddr,int32_t spendflag,int64_t value,struct iguana_RTunspent *unspent)
{ {
char coinaddr[65]; struct iguana_RTaddr *RTaddr; int32_t i,len = (int32_t)strlen(coinaddr);
bitcoin_address(coinaddr,coin->chain->pubtype,rmd160,20); HASH_FIND(hh,coin->RTaddrs,coinaddr,len,RTaddr);
printf("%lld %s %.8f\n",(long long)polarity,coinaddr,dstr(value)); if ( RTaddr == 0 )
{
RTaddr = calloc(1,sizeof(*RTaddr));
strncpy(RTaddr->coinaddr,coinaddr,len);
RTaddr->histbalance = 0; // get hist
HASH_ADD_KEYPTR(hh,coin->RTaddrs,RTaddr->coinaddr,len,RTaddr);
}
//for (i=0; i<RTaddr->numunspents; i++)
// if ( RTaddr->unspents[i] == unspent )
// break;
if ( spendflag != 0 )
{
if ( 0 && (i == RTaddr->numunspents || unspent->validflag == 0) )
{
printf("Cant find unspent for polarity %lld %.8f valid.%d\n",(long long)polarity,dstr(value),unspent->validflag);
}
else
{
if ( polarity > 0 )
{
//unspent->spentflag = 1;
RTaddr->debits += value;
}
else
{
//unspent->spentflag = 0;
RTaddr->debits -= value;
}
}
}
else
{
if ( polarity > 0 )
{
if ( 0 && (i != RTaddr->numunspents || unspent->spentflag != 0) )
{
printf("i.%d != RTaddr->numunspents.%d when +polarity %.8f spentflag.%d\n",i,RTaddr->numunspents,dstr(value),unspent->spentflag);
}
else
{
//RTaddr->unspents = realloc(RTaddr->unspents,sizeof(*RTaddr->unspents)+(1+RTaddr->numunspents));
//RTaddr->unspents[RTaddr->numunspents++] = unspent;
RTaddr->credits += value;
//unspent->validflag = 1;
}
}
else
{
if ( 0 && (i == RTaddr->numunspents || RTaddr->numunspents <= 0 || unspent->validflag == 0) )
{
printf("i.%d == RTaddr->numunspents.%d when -polarity %.8f\n",i,RTaddr->numunspents,dstr(value));
}
else
{
//RTaddr->unspents[i] = RTaddr->unspents[--RTaddr->numunspents];
RTaddr->credits -= value;
//unspent->validflag = 0;
}
}
}
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);
} }
void iguana_RTunspent(struct iguana_info *coin,struct iguana_RTtxid *RTptr,struct iguana_block *block,int64_t polarity,char *coinaddr,uint8_t *rmd160,int32_t type,uint8_t *script,int32_t scriptlen,bits256 txid,int32_t vout,int64_t value) void iguana_RTunspent(struct iguana_info *coin,struct iguana_RTtxid *RTptr,struct iguana_block *block,int64_t polarity,char *coinaddr,uint8_t *rmd160,int32_t type,uint8_t *script,int32_t scriptlen,bits256 txid,int32_t vout,int64_t value)
@ -497,7 +557,7 @@ void iguana_RTunspent(struct iguana_info *coin,struct iguana_RTtxid *RTptr,struc
return; return;
} }
} }
iguana_RTcoinaddr(coin,RTptr,block,polarity,rmd160,value); iguana_RTcoinaddr(coin,RTptr,block,polarity,coinaddr,0,value,unspent);
} else printf("iguana_RTunspent txid mismatch %llx != %llx\n",(long long)RTptr->txid.txid,(long long)txid.txid); } else printf("iguana_RTunspent txid mismatch %llx != %llx\n",(long long)RTptr->txid.txid,(long long)txid.txid);
} }
else else
@ -510,7 +570,7 @@ void iguana_RTunspent(struct iguana_info *coin,struct iguana_RTtxid *RTptr,struc
void iguana_RTspend(struct iguana_info *coin,struct iguana_RTtxid *RTptr,struct iguana_block *block,int64_t polarity,uint8_t *script,int32_t scriptlen,bits256 txid,int32_t vini,bits256 prev_hash,int32_t prev_vout) void iguana_RTspend(struct iguana_info *coin,struct iguana_RTtxid *RTptr,struct iguana_block *block,int64_t polarity,uint8_t *script,int32_t scriptlen,bits256 txid,int32_t vini,bits256 prev_hash,int32_t prev_vout)
{ {
struct iguana_RTspend *spend; struct iguana_RTtxid *spentRTptr; struct iguana_RTunspent *unspent; char str[65],str2[65]; struct iguana_RTspend *spend; struct iguana_RTtxid *spentRTptr; struct iguana_RTunspent *unspent; char str[65],str2[65],coinaddr[64];
if ( RTptr != 0 ) if ( RTptr != 0 )
{ {
if ( bits256_cmp(RTptr->txid,txid) == 0 ) if ( bits256_cmp(RTptr->txid,txid) == 0 )
@ -534,13 +594,23 @@ void iguana_RTspend(struct iguana_info *coin,struct iguana_RTtxid *RTptr,struct
return; return;
} }
} }
HASH_FIND(hh,coin->RTdataset,prev_hash.bytes,sizeof(prev_hash),spentRTptr); if ( bits256_nonz(prev_hash) != 0 && prev_vout >= 0 )
if ( spentRTptr != 0 )
{ {
if ( (unspent= spentRTptr->unspents[prev_vout]) != 0 ) HASH_FIND(hh,coin->RTdataset,prev_hash.bytes,sizeof(prev_hash),spentRTptr);
iguana_RTcoinaddr(coin,RTptr,block,polarity,unspent->rmd160,unspent->value); if ( spentRTptr != 0 )
else printf("iguana_RTspend null unspent.(%s).%d\n",bits256_str(str,prev_hash),prev_vout); {
} else printf("iguana_RTspend cant find spentRTptr.(%s)\n",bits256_str(str,prev_hash)); if ( (unspent= spentRTptr->unspents[prev_vout]) != 0 )
{
bitcoin_address(coinaddr,coin->chain->pubtype,unspent->rmd160,sizeof(unspent->rmd160));
iguana_RTcoinaddr(coin,RTptr,block,polarity,coinaddr,1,unspent->value,unspent);
unspent->spend = spend;
} else printf("iguana_RTspend null unspent.(%s).%d\n",bits256_str(str,prev_hash),prev_vout);
}
else
{
printf("iguana_RTspend cant find spentRTptr.(%s) search history\n",bits256_str(str,prev_hash));
}
}
} else printf("iguana_RTspend txid mismatch %llx != %llx\n",(long long)RTptr->txid.txid,(long long)txid.txid); } else printf("iguana_RTspend txid mismatch %llx != %llx\n",(long long)RTptr->txid.txid,(long long)txid.txid);
} 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); } 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);
} }
@ -559,12 +629,19 @@ void iguana_RTtxid_free(struct iguana_RTtxid *RTptr)
void iguana_RTdataset_free(struct iguana_info *coin) void iguana_RTdataset_free(struct iguana_info *coin)
{ {
struct iguana_RTtxid *RTptr,*tmp; struct iguana_RTtxid *RTptr,*tmp; struct iguana_RTaddr *RTaddr,*tmp2;
HASH_ITER(hh,coin->RTdataset,RTptr,tmp) HASH_ITER(hh,coin->RTdataset,RTptr,tmp)
{ {
HASH_DELETE(hh,coin->RTdataset,RTptr); HASH_DELETE(hh,coin->RTdataset,RTptr);
iguana_RTtxid_free(RTptr); iguana_RTtxid_free(RTptr);
} }
HASH_ITER(hh,coin->RTaddrs,RTaddr,tmp2)
{
HASH_DELETE(hh,coin->RTaddrs,RTaddr);
if ( RTaddr->unspents != 0 )
free(RTaddr->unspents);
free(RTaddr);
}
} }
struct iguana_RTtxid *iguana_RTtxid(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 *iguana_RTtxid(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)
@ -586,9 +663,7 @@ struct iguana_RTtxid *iguana_RTtxid(struct iguana_info *coin,struct iguana_block
RTptr->timestamp = timestamp; RTptr->timestamp = timestamp;
RTptr->unspents = (void *)&RTptr->spends[numvins]; RTptr->unspents = (void *)&RTptr->spends[numvins];
HASH_ADD_KEYPTR(hh,coin->RTdataset,RTptr->txid.bytes,sizeof(RTptr->txid),RTptr); HASH_ADD_KEYPTR(hh,coin->RTdataset,RTptr->txid.bytes,sizeof(RTptr->txid),RTptr);
// add to hashtable block <-> txids[] printf("%s txid.(%s) vouts.%d vins.%d version.%d lock.%u t.%u %lld\n",coin->symbol,bits256_str(str,txid),numvouts,numvins,version,locktime,timestamp,(long long)polarity);
if ( 0 && strcmp("BTC",coin->symbol) != 0 )
printf("%s txid.(%s) vouts.%d vins.%d version.%d lock.%u t.%u %lld\n",coin->symbol,bits256_str(str,txid),numvouts,numvins,version,locktime,timestamp,(long long)polarity);
} }
else if ( RTptr->txn_count != txn_count || RTptr->numvouts != numvouts || RTptr->numvins != numvins ) else if ( RTptr->txn_count != txn_count || RTptr->numvouts != numvouts || RTptr->numvins != numvins )
{ {

4
iguana/iguana_recv.c

@ -400,7 +400,7 @@ void iguana_gotblockM(struct iguana_info *coin,struct iguana_peer *addr,struct i
sizeAfteremit += recvlen; sizeAfteremit += recvlen;
if ( block != 0 ) if ( block != 0 )
iguana_bundletime(coin,bp,bundlei,block,1); iguana_bundletime(coin,bp,bundlei,block,1);
printf("got [%d:%d] with emitfinish.%u\n",bp->hdrsi,bundlei,bp->emitfinish); //printf("got [%d:%d] with emitfinish.%u\n",bp->hdrsi,bundlei,bp->emitfinish);
return; return;
} }
bp->dirty++; bp->dirty++;
@ -863,7 +863,7 @@ struct iguana_bundle *iguana_bundleset(struct iguana_info *coin,struct iguana_bl
} }
else if ( coin->RTheight > 0 && newheight == coin->RTheight ) else if ( coin->RTheight > 0 && newheight == coin->RTheight )
{ {
printf("newheight.%d is RTheight\n",newheight); //printf("newheight.%d is RTheight\n",newheight);
} }
} }
//if ( 0 && bits256_nonz(prevhash2) > 0 ) //if ( 0 && bits256_nonz(prevhash2) > 0 )

10
iguana/iguana_unspents.c

@ -1173,7 +1173,7 @@ int32_t iguana_utxoaddr_validate(struct supernet_info *myinfo,struct iguana_info
int64_t iguana_utxoaddr_gen(struct supernet_info *myinfo,struct iguana_info *coin,int32_t maxheight) int64_t iguana_utxoaddr_gen(struct supernet_info *myinfo,struct iguana_info *coin,int32_t maxheight)
{ {
char fname[1024],fname2[1024],coinaddr[64],str[65],checkaddr[64]; struct iguana_utxoaddr *utxoaddr,UA,*tmp,*last=0; uint16_t hdrsi; uint8_t *table,item[UTXOADDR_ITEMSIZE]; uint32_t *counts,*offsets,offset,n; int32_t errs=0,height=0,j,k,ind,tablesize=0; struct iguana_bundle *bp; struct iguana_block *block; struct iguana_ramchaindata *rdata=0; int64_t checkbalance=0,balance = 0; char fname[1024],fname2[1024],coinaddr[64],str[65],checkaddr[64]; struct iguana_utxoaddr *utxoaddr,UA,*tmp,*last=0; uint16_t hdrsi; uint8_t *table,item[UTXOADDR_ITEMSIZE]; uint32_t *counts,*offsets,offset,n; int32_t errs=0,height=0,j,k,ind,tablesize=0; struct iguana_bundle *bp; struct iguana_ramchaindata *rdata=0; int64_t checkbalance=0,balance = 0;
for (hdrsi=0; hdrsi<coin->bundlescount-1; hdrsi++) for (hdrsi=0; hdrsi<coin->bundlescount-1; hdrsi++)
{ {
if ( (bp= coin->bundles[hdrsi]) != 0 && bp->bundleheight < maxheight ) if ( (bp= coin->bundles[hdrsi]) != 0 && bp->bundleheight < maxheight )
@ -1190,8 +1190,8 @@ int64_t iguana_utxoaddr_gen(struct supernet_info *myinfo,struct iguana_info *coi
coin->firstRTheight = coin->RTheight = height; coin->firstRTheight = coin->RTheight = height;
iguana_RTreset(coin); iguana_RTreset(coin);
iguana_RTpurge(coin,coin->firstRTheight); iguana_RTpurge(coin,coin->firstRTheight);
if ( (block= iguana_blockfind("utxogen",coin,coin->blocks.hwmchain.RO.hash2)) != 0 ) //if ( (block= iguana_blockfind("utxogen",coin,coin->blocks.hwmchain.RO.hash2)) != 0 )
iguana_RTnewblock(coin,block); // iguana_RTnewblock(coin,block);
return(coin->histbalance); return(coin->histbalance);
} }
} }
@ -1319,8 +1319,8 @@ continue;
coin->firstRTheight = coin->RTheight = height; coin->firstRTheight = coin->RTheight = height;
iguana_RTreset(coin); iguana_RTreset(coin);
iguana_RTpurge(coin,coin->firstRTheight); iguana_RTpurge(coin,coin->firstRTheight);
if ( (block= iguana_blockfind("utxogen",coin,coin->blocks.hwmchain.RO.hash2)) != 0 ) //if ( (block= iguana_blockfind("utxogen",coin,coin->blocks.hwmchain.RO.hash2)) != 0 )
iguana_RTnewblock(coin,block); // iguana_RTnewblock(coin,block);
return(coin->histbalance); return(coin->histbalance);
} }
} }

13
includes/iguana_structs.h

@ -391,9 +391,20 @@ struct iguana_RTunspent
uint8_t rmd160[20]; uint8_t rmd160[20];
int64_t value; int64_t value;
int16_t scriptlen; int16_t scriptlen;
struct iguana_RTspend *spend;
uint8_t spentflag,validflag;
uint8_t script[]; uint8_t script[];
}; };
struct iguana_RTaddr
{
UT_hash_handle hh;
char coinaddr[64];
int64_t histbalance,debits,credits;
int32_t numunspents;
struct iguana_RTunspent **unspents;
};
struct iguana_RTtxid struct iguana_RTtxid
{ {
UT_hash_handle hh; struct iguana_info *coin; struct iguana_block *block; UT_hash_handle hh; struct iguana_info *coin; struct iguana_block *block;
@ -453,7 +464,7 @@ struct iguana_info
void *utxoaddrfileptr; long utxoaddrfilesize; void *utxoaddrfileptr; long utxoaddrfilesize;
uint32_t utxoaddrlastcount,*utxoaddroffsets; uint8_t *utxoaddrtable; bits256 utxoaddrhash; uint32_t utxoaddrlastcount,*utxoaddroffsets; uint8_t *utxoaddrtable; bits256 utxoaddrhash;
struct iguana_block *RTblocks[65536]; uint8_t *RTrawdata[65536]; int32_t RTrecvlens[65536],RTnumtx[65536]; struct iguana_block *RTblocks[65536]; uint8_t *RTrawdata[65536]; int32_t RTrecvlens[65536],RTnumtx[65536];
struct iguana_RTtxid *RTdataset; struct iguana_RTtxid *RTdataset; struct iguana_RTaddr *RTaddrs;
}; };
struct vin_signer { bits256 privkey; char coinaddr[64]; uint8_t siglen,sig[80],rmd160[20],pubkey[66]; }; struct vin_signer { bits256 privkey; char coinaddr[64]; uint8_t siglen,sig[80],rmd160[20],pubkey[66]; };

Loading…
Cancel
Save