Browse Source

test

release/v0.1
jl777 9 years ago
parent
commit
477d4b1c41
  1. 1
      iguana/iguana777.c
  2. 4
      iguana/iguana_recv.c
  3. 72
      iguana/iguana_unspents.c
  4. 1
      includes/iguana_funcs.h
  5. 3
      includes/iguana_structs.h

1
iguana/iguana777.c

@ -444,6 +444,7 @@ void iguana_update_balances(struct iguana_info *coin)
coin->balanceflush = max+1;
while ( coin->balanceflush != 0 )
sleep(3);
iguana_utxoaddr_gen(coin,1);
} else printf("skip flush when max.%d and orig.%d\n",max,coin->origbalanceswritten);
}
}

4
iguana/iguana_recv.c

@ -921,13 +921,15 @@ struct iguana_bundlereq *iguana_recvblockhashes(struct iguana_info *coin,struct
else
{
for (i=1; i<num; i++)
{
if ( (block= iguana_blockfind("prev",coin,blockhashes[i])) != 0 && block->height+1 > coin->longestchain )
{
iguana_blockQ("recvhash",coin,0,-1,blockhashes[i],1);
coin->longestchain = block->height+1;
if ( bp != 0 && bp->speculative != 0 && i < bp->n )
bp->speculative[i] = blockhashes[i];
}
iguana_blockQ("recvhash",coin,0,-1,blockhashes[i],1);
}
}
if ( bp != 0 )
{

72
iguana/iguana_unspents.c

@ -842,3 +842,75 @@ int64_t iguana_unspentavail(struct supernet_info *myinfo,struct iguana_info *coi
}
else return(0);
}
struct iguana_utxoaddr *iguana_utxoaddrfind(int32_t createflag,struct iguana_info *coin,uint8_t rmd160[20])
{
struct iguana_utxoaddr *utxoaddr;
HASH_FIND(hh,coin->utxoaddrs,rmd160,sizeof(utxoaddr),utxoaddr);
if ( utxoaddr == 0 && createflag != 0 )
{
if ( coin->utxoaddrind < coin->utxodatasize )
{
utxoaddr = &coin->UTXOADDRDATA[++coin->utxoaddrind];
memcpy(utxoaddr->rmd160,rmd160,sizeof(utxoaddr->rmd160));
HASH_ADD_KEYPTR(hh,coin->utxoaddrs,utxoaddr->rmd160,sizeof(utxoaddr->rmd160),utxoaddr);
} else printf("UTXOTABLE overflow?? %d vs %d\n",coin->utxoaddrind,coin->utxodatasize);
}
return(utxoaddr);
}
int64_t iguana_bundle_unspents(struct iguana_info *coin,struct iguana_bundle *bp,int32_t maketable)
{
struct iguana_utxoaddr *utxoaddr; int32_t unspentind; struct iguana_ramchaindata *rdata=0; struct iguana_pkhash *P; struct iguana_unspent *U; struct iguana_utxo *U2=0; int64_t value,balance = 0;
if ( bp == 0 || (rdata= bp->ramchain.H.data) == 0 || (U2= bp->ramchain.Uextras) == 0 )
{
printf("missing ptr bp.%p rdata.%p U2.%p\n",bp,rdata,U2);
return(0);
}
U = RAMCHAIN_PTR(rdata,Uoffset);
P = RAMCHAIN_PTR(rdata,Poffset);
for (unspentind=1; unspentind<rdata->numunspents; unspentind++)
{
if ( U2[unspentind].spentflag == 0 && (value= U[unspentind].value) != 0 )
{
balance += value;
if ( maketable != 0 )
{
if ( (utxoaddr= iguana_utxoaddrfind(1,coin,P[U[unspentind].pkind].rmd160)) != 0 )
utxoaddr->balance += value;
}
}
}
return(balance);
}
int64_t iguana_utxoaddr_gen(struct iguana_info *coin,int32_t maketable)
{
struct iguana_utxoaddr *utxoaddr,*tmp; int32_t hdrsi,tablesize=0; struct iguana_bundle *bp; struct iguana_ramchaindata *rdata=0; int64_t balance = 0;
if ( maketable != 0 )
{
if ( coin->utxoaddrs != 0 && coin->UTXOADDRDATA != 0 )
{
HASH_ITER(hh,coin->utxoaddrs,utxoaddr,tmp);
{
HASH_DELETE(hh,coin->utxoaddrs,utxoaddr);
}
free(coin->UTXOADDRDATA);
coin->UTXOADDRDATA = 0;
coin->utxoaddrs = 0;
}
for (hdrsi=0; hdrsi<coin->bundlescount; hdrsi++)
if ( (bp= coin->bundles[hdrsi]) != 0 && (rdata= bp->ramchain.H.data) != 0 )
tablesize += rdata->numpkinds;
coin->UTXOADDRDATA = calloc(sizeof(*coin->UTXOADDRDATA),tablesize);
coin->utxodatasize = tablesize;
coin->utxoaddrind = 0;
}
for (hdrsi=0; hdrsi<coin->bundlescount; hdrsi++)
{
balance += iguana_bundle_unspents(coin,coin->bundles[hdrsi],maketable);
fprintf(stderr,"%.8f ",dstr(balance));
}
fprintf(stderr,"%d bundles for iguana_utxoaddr_gen\n",hdrsi);
return(balance);
}

1
includes/iguana_funcs.h

@ -518,6 +518,7 @@ int32_t iguana_headerget(struct iguana_info *coin,uint8_t *serialized,int32_t ma
int32_t iguana_bundlefinalize(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_bundle *bp,struct OS_memspace *mem,struct OS_memspace *memB);
bits256 iguana_parsetxobj(struct supernet_info *myinfo,struct iguana_info *coin,int32_t *txstartp,uint8_t *serialized,int32_t maxsize,struct iguana_msgtx *msg,cJSON *txobj,struct vin_info *V);
int32_t iguana_ROallocsize(struct iguana_info *virt);
int64_t iguana_utxoaddr_gen(struct iguana_info *coin,int32_t maketable);
long iguana_bundlesload(struct supernet_info *myinfo,struct iguana_info *coin);
void basilisk_wait(struct supernet_info *myinfo,struct iguana_info *coin);
int32_t bitcoin_pubkey_combine(void *ctx,uint8_t *combined_pub,uint8_t *skipkey,bits256 *evenkeys,int32_t n,bits256 *oddkeys,int32_t m);

3
includes/iguana_structs.h

@ -253,6 +253,8 @@ struct iguana_utxo { uint32_t fromheight:31,lockedflag:1,prevunspentind:31,spent
struct iguana_hhaccount { UT_hash_handle hh; uint64_t pval; struct iguana_account a; } __attribute__((packed));
struct iguana_hhutxo { UT_hash_handle hh; uint64_t uval; struct iguana_utxo u; } __attribute__((packed));
struct iguana_utxoaddr { UT_hash_handle hh; int64_t balance; uint8_t rmd160[20]; } __attribute__((packed));
// GLOBAL one zero to non-zero write (unless reorg)
struct iguana_spendvector { uint64_t value; uint32_t pkind,unspentind; int32_t fromheight; uint16_t hdrsi:15,tmpflag:1; } __attribute__((packed)); // unspentind
//struct iguana_pkextra { uint32_t firstspendind; } __attribute__((packed)); // pkind
@ -420,6 +422,7 @@ struct iguana_info
struct iguana_zblock newblock; char *newblockstr;
int32_t relay_RTheights[BASILISK_MAXRELAYS];
struct iguana_blocks blocks; void *mempool; void *mempools[BASILISK_MAXRELAYS];
struct iguana_utxoaddr *utxoaddrs,*UTXOADDRDATA; uint32_t utxodatasize,utxoaddrind;
};
struct vin_signer { bits256 privkey; char coinaddr[64]; uint8_t siglen,sig[80],rmd160[20],pubkey[66]; };

Loading…
Cancel
Save