|
|
@ -113,7 +113,16 @@ cJSON *ramchain_unspentjson(struct iguana_unspent *up,uint32_t unspentind) |
|
|
|
return(item); |
|
|
|
} |
|
|
|
|
|
|
|
cJSON *iguana_unspentjson(struct supernet_info *myinfo,struct iguana_info *coin,int32_t hdrsi,uint32_t unspentind,struct iguana_txid *T,struct iguana_unspent *up,uint8_t rmd160[20],char *coinaddr,uint8_t *pubkey33) |
|
|
|
cJSON *ramchain_spentjson(struct iguana_info *coin,int32_t spentheight,int32_t hdrsi,int32_t unspentind) |
|
|
|
{ |
|
|
|
char coinaddr[64]; int64_t total = 0; cJSON *item = cJSON_CreateObject(); |
|
|
|
coinaddr[0] = 0; |
|
|
|
jaddstr(item,"destaddr",coinaddr); |
|
|
|
jaddnum(item,"total",dstr(total)); |
|
|
|
return(item); |
|
|
|
} |
|
|
|
|
|
|
|
cJSON *iguana_unspentjson(struct supernet_info *myinfo,struct iguana_info *coin,int32_t hdrsi,uint32_t unspentind,struct iguana_txid *T,struct iguana_unspent *up,uint8_t rmd160[20],char *coinaddr,uint8_t *pubkey33,int32_t spentheight,char *remoteaddr) |
|
|
|
{ |
|
|
|
/*{
|
|
|
|
"txid" : "d54994ece1d11b19785c7248868696250ab195605b469632b7bd68130e880c9a", |
|
|
@ -134,17 +143,26 @@ cJSON *iguana_unspentjson(struct supernet_info *myinfo,struct iguana_info *coin, |
|
|
|
if ( iguana_scriptget(coin,scriptstr,asmstr,sizeof(scriptstr),hdrsi,unspentind,T[up->txidind].txid,up->vout,rmd160,up->type,pubkey33) != 0 ) |
|
|
|
jaddstr(item,"scriptPubKey",scriptstr); |
|
|
|
jaddnum(item,"amount",dstr(up->value)); |
|
|
|
jaddnum(item,"timestamp",T[up->txidind].timestamp); |
|
|
|
if ( (checkind= iguana_unspentindfind(coin,0,0,0,0,&height,T[up->txidind].txid,up->vout,coin->bundlescount-1,0)) != 0 ) |
|
|
|
{ |
|
|
|
jaddnum(item,"height",height); |
|
|
|
jaddnum(item,"confirmations",coin->blocks.hwmchain.height - height + 1); |
|
|
|
jaddnum(item,"checkind",checkind); |
|
|
|
} |
|
|
|
if ( remoteaddr == 0 || remoteaddr[0] == 0 ) |
|
|
|
{ |
|
|
|
if ( (waddr= iguana_waddresssearch(myinfo,&wacct,coinaddr)) != 0 ) |
|
|
|
{ |
|
|
|
jaddstr(item,"account",wacct->account); |
|
|
|
jadd(item,"spendable",jtrue()); |
|
|
|
} else jadd(item,"spendable",jfalse()); |
|
|
|
jadd(item,"unspent",ramchain_unspentjson(up,unspentind)); |
|
|
|
} |
|
|
|
if ( spentheight > 0 ) |
|
|
|
{ |
|
|
|
jadd(item,"spent",ramchain_unspentjson(up,unspentind)); |
|
|
|
jaddnum(item,"spentheight",spentheight); |
|
|
|
} else jadd(item,"unspent",ramchain_unspentjson(up,unspentind)); |
|
|
|
return(item); |
|
|
|
} |
|
|
|
|
|
|
@ -233,7 +251,7 @@ int32_t iguana_datachain_scan(struct supernet_info *myinfo,struct iguana_info *c |
|
|
|
return(num); |
|
|
|
} |
|
|
|
|
|
|
|
int64_t iguana_pkhashbalance(struct supernet_info *myinfo,struct iguana_info *coin,cJSON *array,int64_t *spentp,int64_t *unspents,int32_t *nump,struct iguana_ramchain *ramchain,struct iguana_pkhash *p,uint32_t lastunspentind,uint8_t rmd160[20],char *coinaddr,uint8_t *pubkey33,int32_t hdrsi,int32_t lastheight,int32_t minconf,int32_t maxconf) |
|
|
|
int64_t iguana_pkhashbalance(struct supernet_info *myinfo,struct iguana_info *coin,cJSON *array,int64_t *spentp,int64_t *unspents,int32_t *nump,struct iguana_ramchain *ramchain,struct iguana_pkhash *p,uint32_t lastunspentind,uint8_t rmd160[20],char *coinaddr,uint8_t *pubkey33,int32_t hdrsi,int32_t lastheight,int32_t minconf,int32_t maxconf,char *remoteaddr) |
|
|
|
{ |
|
|
|
struct iguana_unspent *U; struct iguana_utxo *U2; struct iguana_spend *S; int32_t max,uheight,spentheight; uint32_t pkind=0,unspentind; int64_t spent = 0,checkval,deposits = 0; struct iguana_txid *T; struct iguana_account *A2; struct iguana_ramchaindata *rdata = 0; int64_t RTspend = 0; |
|
|
|
max = *nump; |
|
|
@ -269,14 +287,14 @@ int64_t iguana_pkhashbalance(struct supernet_info *myinfo,struct iguana_info *co |
|
|
|
} |
|
|
|
//printf("%.8f ",dstr(U[unspentind].value));
|
|
|
|
(*nump)++; |
|
|
|
if ( array != 0 ) |
|
|
|
jaddi(array,iguana_unspentjson(myinfo,coin,hdrsi,unspentind,T,&U[unspentind],rmd160,coinaddr,pubkey33)); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
//printf("-%.8f ",dstr(U[unspentind].value));
|
|
|
|
spent += U[unspentind].value; |
|
|
|
} |
|
|
|
if ( array != 0 ) |
|
|
|
jaddi(array,iguana_unspentjson(myinfo,coin,hdrsi,unspentind,T,&U[unspentind],rmd160,coinaddr,pubkey33,spentheight,remoteaddr)); |
|
|
|
if ( p->pkind != U[unspentind].pkind ) |
|
|
|
printf("warning: [%d] p->pkind.%u vs U->pkind.%u for u%d\n",hdrsi,p->pkind,U[unspentind].pkind,unspentind); |
|
|
|
} |
|
|
@ -307,7 +325,7 @@ int64_t iguana_pkhashbalance(struct supernet_info *myinfo,struct iguana_info *co |
|
|
|
return(deposits - spent); |
|
|
|
} |
|
|
|
|
|
|
|
int32_t iguana_pkhasharray(struct supernet_info *myinfo,struct iguana_info *coin,cJSON *array,int32_t minconf,int32_t maxconf,int64_t *totalp,struct iguana_pkhash *P,int32_t max,uint8_t rmd160[20],char *coinaddr,uint8_t *pubkey33,int32_t lastheight,int64_t *unspents,int32_t *numunspentsp,int32_t maxunspents) |
|
|
|
int32_t iguana_pkhasharray(struct supernet_info *myinfo,struct iguana_info *coin,cJSON *array,int32_t minconf,int32_t maxconf,int64_t *totalp,struct iguana_pkhash *P,int32_t max,uint8_t rmd160[20],char *coinaddr,uint8_t *pubkey33,int32_t lastheight,int64_t *unspents,int32_t *numunspentsp,int32_t maxunspents,char *remoteaddr) |
|
|
|
{ |
|
|
|
int32_t i,n,m,numunspents; int64_t spent,deposits,netbalance,total; uint32_t lastunspentind; struct iguana_pkhash *p,_p; struct iguana_ramchain *ramchain; struct iguana_bundle *bp; |
|
|
|
if ( 0 && coin->RTramchain_busy != 0 ) |
|
|
@ -344,7 +362,7 @@ int32_t iguana_pkhasharray(struct supernet_info *myinfo,struct iguana_info *coin |
|
|
|
{ |
|
|
|
m = maxunspents >> 1; |
|
|
|
p = (P == 0) ? &_p : &P[n]; |
|
|
|
if ( (netbalance= iguana_pkhashbalance(myinfo,coin,array,&spent,unspents != 0 ? &unspents[numunspents << 1] : 0,&m,ramchain,p,lastunspentind,rmd160,coinaddr,pubkey33,i,lastheight,minconf,maxconf)) != deposits-spent && lastheight == IGUANA_MAXHEIGHT && minconf == 1 && maxconf > coin->blocks.hwmchain.height ) |
|
|
|
if ( (netbalance= iguana_pkhashbalance(myinfo,coin,array,&spent,unspents != 0 ? &unspents[numunspents << 1] : 0,&m,ramchain,p,lastunspentind,rmd160,coinaddr,pubkey33,i,lastheight,minconf,maxconf,remoteaddr)) != deposits-spent && lastheight == IGUANA_MAXHEIGHT && minconf == 1 && maxconf > coin->blocks.hwmchain.height ) |
|
|
|
{ |
|
|
|
printf("pkhash balance mismatch from m.%d check %.8f vs %.8f spent %.8f [%.8f]\n",m,dstr(netbalance),dstr(deposits),dstr(spent),dstr(deposits)-dstr(spent)); |
|
|
|
} |
|
|
@ -371,7 +389,7 @@ int32_t iguana_pkhasharray(struct supernet_info *myinfo,struct iguana_info *coin |
|
|
|
return(n); |
|
|
|
} |
|
|
|
|
|
|
|
int64_t iguana_unspents(struct supernet_info *myinfo,struct iguana_info *coin,cJSON *array,int32_t minconf,int32_t maxconf,uint8_t *rmdarray,int32_t numrmds,int32_t lastheight,int64_t *unspents,int32_t *numunspentsp) |
|
|
|
int64_t iguana_unspents(struct supernet_info *myinfo,struct iguana_info *coin,cJSON *array,int32_t minconf,int32_t maxconf,uint8_t *rmdarray,int32_t numrmds,int32_t lastheight,int64_t *unspents,int32_t *numunspentsp,char *remoteaddr) |
|
|
|
{ |
|
|
|
int64_t total=0,sum=0; struct iguana_pkhash *P; uint8_t *addrtypes,*pubkeys; int32_t i,numunspents,maxunspents,flag = 0; char coinaddr[64]; |
|
|
|
if ( 0 && coin->RTramchain_busy != 0 ) |
|
|
@ -391,7 +409,7 @@ int64_t iguana_unspents(struct supernet_info *myinfo,struct iguana_info *coin,cJ |
|
|
|
{ |
|
|
|
bitcoin_address(coinaddr,addrtypes[i],&rmdarray[i * 20],20); |
|
|
|
*numunspentsp = 0; |
|
|
|
iguana_pkhasharray(myinfo,coin,array,minconf,maxconf,&total,P,coin->bundlescount,&rmdarray[i * 20],coinaddr,&pubkeys[33*i],lastheight,&unspents[numunspents << 1],numunspentsp,maxunspents); |
|
|
|
iguana_pkhasharray(myinfo,coin,array,minconf,maxconf,&total,P,coin->bundlescount,&rmdarray[i * 20],coinaddr,&pubkeys[33*i],lastheight,&unspents[numunspents << 1],numunspentsp,maxunspents,remoteaddr); |
|
|
|
//printf("iguana_unspents: i.%d of %d: %s %.8f numunspents.%d\n",i,numrmds,coinaddr,dstr(total),*numunspentsp);
|
|
|
|
maxunspents -= *numunspentsp; |
|
|
|
numunspents += *numunspentsp; |
|
|
@ -434,7 +452,7 @@ uint8_t *iguana_rmdarray(struct supernet_info *myinfo,struct iguana_info *coin,i |
|
|
|
return(rmdarray); |
|
|
|
} |
|
|
|
|
|
|
|
int32_t iguana_unspentslists(struct supernet_info *myinfo,struct iguana_info *coin,int64_t *totalp,int64_t *unspents,int32_t max,int64_t required,int32_t minconf,cJSON *addresses) |
|
|
|
int32_t iguana_unspentslists(struct supernet_info *myinfo,struct iguana_info *coin,int64_t *totalp,int64_t *unspents,int32_t max,int64_t required,int32_t minconf,cJSON *addresses,char *remoteaddr) |
|
|
|
{ |
|
|
|
int64_t remains,total,sum = 0; int32_t i,n,numunspents,numaddrs; uint8_t addrtype,pubkey[65],rmd160[20]; char *coinaddr; |
|
|
|
*totalp = 0; |
|
|
@ -453,7 +471,7 @@ int32_t iguana_unspentslists(struct supernet_info *myinfo,struct iguana_info *co |
|
|
|
total = 0; |
|
|
|
n = 0; |
|
|
|
bitcoin_addr2rmd160(&addrtype,rmd160,coinaddr); |
|
|
|
iguana_pkhasharray(myinfo,coin,0,minconf,coin->longestchain,&total,0,coin->bundlescount,rmd160,coinaddr,pubkey,coin->blocks.hwmchain.height - minconf,unspents,&n,max-1000); |
|
|
|
iguana_pkhasharray(myinfo,coin,0,minconf,coin->longestchain,&total,0,coin->bundlescount,rmd160,coinaddr,pubkey,coin->blocks.hwmchain.height - minconf,unspents,&n,max-1000,remoteaddr); |
|
|
|
//printf("n.%d max.%d total %.8f\n",n,max,dstr(total));
|
|
|
|
if ( n > 0 ) |
|
|
|
{ |
|
|
|