Browse Source

test

release/v0.1
jl777 8 years ago
parent
commit
e844111a6a
  1. 15
      basilisk/basilisk.c
  2. 2
      iguana/iguana_spendvectors.c
  3. 139
      iguana/iguana_unspents.c

15
basilisk/basilisk.c

@ -870,14 +870,17 @@ void basilisks_loop(void *arg)
basilisk_ping_send(myinfo,btcd);
}
}
HASH_ITER(hh,myinfo->allcoins,coin,tmpcoin)
if ( myinfo->expiration != 0 )
{
if ( time(NULL) > coin->lastunspentsupdate+10 )
HASH_ITER(hh,myinfo->allcoins,coin,tmpcoin)
{
//printf(">>>>>>>>>>>>> update %s\n",coin->symbol);
basilisk_unspents_update(myinfo,coin);
coin->lastunspentsupdate = (uint32_t)time(NULL);
//printf(">>>>>>>>>>>>> update %s finished\n",coin->symbol);
if ( myinfo->Cunspents == 0 || time(NULL) > coin->lastunspentsupdate+60 )
{
//printf(">>>>>>>>>>>>> update %s\n",coin->symbol);
basilisk_unspents_update(myinfo,coin);
coin->lastunspentsupdate = (uint32_t)time(NULL);
//printf(">>>>>>>>>>>>> update %s finished\n",coin->symbol);
}
}
}
if ( RELAYID < 0 && myinfo->expiration != 0 )

2
iguana/iguana_spendvectors.c

@ -679,7 +679,7 @@ int32_t iguana_volatilesinit(struct supernet_info *myinfo,struct iguana_info *co
fprintf(stderr,".");
if ( filecrc == 0 )
{
fprintf(stderr,"balancehash add [%d]\n",bp->hdrsi);
//fprintf(stderr,"balancehash add [%d]\n",bp->hdrsi);
vupdate_sha256(balancehash.bytes,&vstate,(void *)Aptr,sizeof(*Aptr) * numpkinds);
vupdate_sha256(balancehash.bytes,&vstate,(void *)Uptr,sizeof(*Uptr) * numunspents);
vupdate_sha256(allbundles.bytes,&bstate,(void *)bp->hashes,sizeof(bp->hashes[0]) * bp->n);

139
iguana/iguana_unspents.c

@ -653,7 +653,7 @@ int64_t iguana_RTunspents(struct supernet_info *myinfo,struct iguana_info *coin,
uint8_t *iguana_rmdarray(struct supernet_info *myinfo,struct iguana_info *coin,int32_t *numrmdsp,cJSON *array,int32_t firsti)
{
int32_t i,n,flag=0,j=0; char *coinaddr,rmdstr[41]; uint8_t *addrtypes,*rmdarray = 0;
int32_t i,n,flag=0,k,j=0; char *coinaddr,rmdstr[41]; uint8_t addrtype,*addrtypes,*rmdarray = 0;
*numrmdsp = 0;
if ( array == 0 || cJSON_GetArraySize(array) == 0 )
array = iguana_getaddressesbyaccount(myinfo,coin,"*");
@ -666,9 +666,19 @@ uint8_t *iguana_rmdarray(struct supernet_info *myinfo,struct iguana_info *coin,i
{
if ( (coinaddr= jstr(jitem(array,i),0)) != 0 )
{
//printf("(%s %s) ",coinaddr,rmdstr);
if ( iguana_addressvalidate(coin,&addrtype,coinaddr) < 0 )
{
printf("i.%d illegal coinaddr.(%s) longest.%d\n",i,coinaddr,coin->longestchain);
continue;
}
bitcoin_addr2rmd160(&addrtypes[j],&rmdarray[20 * j],coinaddr);
for (k=0; k<20; k++)
if ( rmdarray[20 * j + k] != 0 )
break;
if ( k == 20 )
continue;
init_hexbytes_noT(rmdstr,&rmdarray[20 * j],20);
//printf("(%s %s) ",coinaddr,rmdstr);
j++;
}
}
@ -807,10 +817,20 @@ int32_t iguana_RTunspent_check(struct supernet_info *myinfo,struct iguana_info *
int32_t iguana_RTaddr_unspents(struct supernet_info *myinfo,struct iguana_info *coin,uint64_t *sump,struct iguana_outpoint *unspents,int32_t max,char *coinaddr,char *remoteaddr,int32_t lastheight,int32_t includespent)
{
int32_t n,k,numunspents,minconf = 0; uint64_t total; uint8_t rmd160[20],pubkey[65],addrtype;
int32_t n,j,k,numunspents,minconf = 0; uint64_t total; uint8_t rmd160[20],pubkey[65],addrtype;
total = 0;
n = numunspents = 0;
if ( iguana_addressvalidate(coin,&addrtype,coinaddr) < 0 )
{
printf("illegal coinaddr.(%s) minconf.%d longest.%d diff.%d\n",coinaddr,minconf,coin->longestchain,coin->blocks.hwmchain.height - minconf);
return(0);
}
bitcoin_addr2rmd160(&addrtype,rmd160,coinaddr);
for (j=0; j<20; j++)
if ( rmd160[j] != 0 )
break;
if ( j == 20 )
return(0);
iguana_RTpkhasharray(myinfo,coin,0,minconf,coin->longestchain,&total,0,coin->bundlescount,rmd160,coinaddr,pubkey,lastheight,unspents,&n,max-1000,remoteaddr,includespent);
numunspents = n;
for (k=0; k<n; k++)
@ -818,69 +838,6 @@ int32_t iguana_RTaddr_unspents(struct supernet_info *myinfo,struct iguana_info *
return(numunspents);
}
int32_t iguana_RTunspentslists(struct supernet_info *myinfo,struct iguana_info *coin,uint64_t *totalp,struct iguana_outpoint *unspents,int32_t max,uint64_t required,int32_t minconf,cJSON *addresses,char *remoteaddr)
{
uint64_t sum = 0; int32_t i,j,n,numunspents,numaddrs; uint8_t addrtype,rmd160[20],pubkey[65]; char *coinaddr; struct iguana_outpoint outpt; cJSON *array,*item; //struct iguana_waddress *waddr; struct iguana_waccount *wacct;
*totalp = 0;
if ( (numaddrs= cJSON_GetArraySize(addresses)) == 0 )
{
printf("null addresses.(%s)\n",jprint(addresses,0));
return(0);
}
memset(pubkey,0,sizeof(pubkey));
//remains = required * 1.1 + coin->txfee;
for (i=numunspents=0; i<numaddrs; i++)
{
if ( (coinaddr= jstri(addresses,i)) != 0 )
{
if ( iguana_addressvalidate(coin,&addrtype,coinaddr) < 0 )
{
printf("i.%d illegal coinaddr.(%s) minconf.%d longest.%d diff.%d\n",i,coinaddr,minconf,coin->longestchain,coin->blocks.hwmchain.height - minconf);
continue;
}
bitcoin_addr2rmd160(&addrtype,rmd160,coinaddr);
for (j=0; j<20; j++)
if ( rmd160[j] != 0 )
break;
if ( j == 20 )
continue;
if ( coin->FULLNODE != 0 || coin->VALIDATENODE != 0 )
{
numunspents += iguana_RTaddr_unspents(myinfo,coin,&sum,&unspents[numunspents],max-numunspents,coinaddr,remoteaddr,1<<30,0);
}
else
{
portable_mutex_lock(&myinfo->bu_mutex);
//if ( (waddr= iguana_waddresssearch(myinfo,&wacct,coinaddr)) != 0 )
{
if ( myinfo->Cunspents != 0 && (array= jobj(myinfo->Cunspents,coin->symbol)) != 0 )
{
if ( (n= cJSON_GetArraySize(array)) > 0 )
{
for (i=0; i<n; i++)
{
item = jitem(array,i);
iguana_outptset(myinfo,coin,&outpt,jbits256(item,"txid"),jint(item,"vout"));
*unspents = outpt;
sum += outpt.value;
unspents++;
numunspents++;
}
}
}
}
portable_mutex_unlock(&myinfo->bu_mutex);
}
if ( numunspents > max || sum > required )
break;
//printf("n.%d max.%d total %.8f\n",n,max,dstr(total));
}
}
*totalp = sum;
printf("numunspents.%d sum %.8f\n",numunspents,dstr(sum));
return(numunspents);
}
int32_t iguana_RTuvaltxid(struct supernet_info *myinfo,bits256 *txidp,struct iguana_info *coin,struct iguana_outpoint outpt)
{
struct iguana_bundle *bp; struct iguana_unspent *U,*u; struct iguana_txid *T; struct iguana_ramchain *ramchain; struct iguana_ramchaindata *rdata; struct iguana_RTunspent *unspent; struct iguana_RTtxid *parent;
@ -992,6 +949,56 @@ cJSON *iguana_RTlistunspent(struct supernet_info *myinfo,struct iguana_info *coi
return(retjson);
}
int32_t iguana_RTunspentslists(struct supernet_info *myinfo,struct iguana_info *coin,uint64_t *totalp,struct iguana_outpoint *unspents,int32_t max,uint64_t required,int32_t minconf,cJSON *addresses,char *remoteaddr)
{
uint64_t sum = 0; int32_t i,n,numunspents,numaddrs; uint8_t pubkey[65]; char *coinaddr; struct iguana_outpoint outpt; cJSON *array,*item; //struct iguana_waddress *waddr; struct iguana_waccount *wacct;
*totalp = 0;
numunspents = 0;
if ( (numaddrs= cJSON_GetArraySize(addresses)) == 0 )
{
printf("null addresses.(%s)\n",jprint(addresses,0));
return(0);
}
memset(pubkey,0,sizeof(pubkey));
//remains = required * 1.1 + coin->txfee;
if ( coin->FULLNODE != 0 || coin->VALIDATENODE != 0 )
{
for (i=numunspents=0; i<numaddrs; i++)
{
if ( (coinaddr= jstri(addresses,i)) != 0 )
{
numunspents += iguana_RTaddr_unspents(myinfo,coin,&sum,&unspents[numunspents],max-numunspents,coinaddr,remoteaddr,1<<30,0);
}
}
}
else
{
if ( (array= iguana_RTlistunspent(myinfo,coin,addresses,minconf,1<<30,remoteaddr,0)) != 0 )
{
if ( (n= cJSON_GetArraySize(array)) > 0 )
{
for (i=0; i<n; i++)
{
item = jitem(array,i);
iguana_outptset(myinfo,coin,&outpt,jbits256(item,"txid"),jint(item,"vout"));
outpt.value = jdouble(item,"amount") * SATOSHIDEN;
*unspents = outpt;
sum += outpt.value;
printf("ITEM.(%s) %.8f\n",jprint(item,0),dstr(outpt.value));
unspents++;
numunspents++;
if ( numunspents > max || sum > required )
break;
}
}
free_json(array);
}
}
*totalp = sum;
printf("numunspents.%d max.%d sum %.8f required %.8f\n",numunspents,max,dstr(sum),dstr(required));
return(numunspents);
}
#define UTXOADDR_ITEMSIZE 32
#define iguana_utxotable_numinds(ind) (((ind) == 0xffff) ? coin->utxoaddrlastcount : (coin->utxoaddroffsets[(ind) + 1] - coin->utxoaddroffsets[ind]))

Loading…
Cancel
Save