Browse Source

fixed history

release/v0.1
jl777 8 years ago
parent
commit
f15c6881af
  1. 11
      basilisk/basilisk.c
  2. 33
      basilisk/basilisk_bitcoin.c
  3. 2
      iguana/iguana_unspents.c
  4. 10
      iguana/iguana_wallet.c
  5. 2
      iguana/tests/history
  6. 1
      iguana/tests/history2
  7. 2
      includes/iguana_structs.h

11
basilisk/basilisk.c

@ -904,7 +904,7 @@ HASH_ARRAY_STRING(basilisk,balances,hash,vals,hexstr)
if ( jobj(vals,"addresses") == 0 ) if ( jobj(vals,"addresses") == 0 )
{ {
jadd(vals,"addresses",iguana_getaddressesbyaccount(myinfo,coin,"*")); jadd(vals,"addresses",iguana_getaddressesbyaccount(myinfo,coin,"*"));
//printf("added all addresses: %s\n",jprint(vals,0)); //printf("added all %s addresses: %s\n",coin->symbol,jprint(vals,0));
} //else printf("have addresses.(%s)\n",jprint(jobj(vals,"addresses"),0)); } //else printf("have addresses.(%s)\n",jprint(jobj(vals,"addresses"),0));
if ( (basilisktag= juint(vals,"basilisktag")) == 0 ) if ( (basilisktag= juint(vals,"basilisktag")) == 0 )
basilisktag = rand(); basilisktag = rand();
@ -939,18 +939,17 @@ HASH_ARRAY_STRING(basilisk,history,hash,vals,hexstr)
{ {
HASH_ITER(hh,wacct->waddr,waddr,tmp2) HASH_ITER(hh,wacct->waddr,waddr,tmp2)
{ {
if ( (array= waddr->unspents) != 0 ) if ( waddr->Cunspents != 0 && (array= jobj(waddr->Cunspents,coin->symbol)) != 0 )
{ {
if ( (n= cJSON_GetArraySize(array)) > 0 ) if ( (n= cJSON_GetArraySize(array)) > 0 )
{ {
for (i=0; i<n; i++) for (i=0; i<n; i++)
total += jdouble(jitem(array,i),"amount") * SATOSHIDEN; total += jdouble(jitem(array,i),"amount") * SATOSHIDEN;
} }
jaddi(unspents,jduplicate(waddr->unspents)); jaddi(unspents,jduplicate(array));
//jaddi(array,basilisk_history_item(coin,&total,waddr->coinaddr,bu->value,bu->timestamp,bu->txid,"vout",bu->vout,bu->height,"spentheight",bu->spentheight,bu->relaymask,-1));
} }
if ( waddr->spends != 0 ) if ( waddr->Cspends != 0 && (array= jobj(waddr->Cspends,coin->symbol)) != 0 )
jaddi(spends,jduplicate(waddr->spends)); jaddi(spends,jduplicate(array));
} }
} }
retjson = cJSON_CreateObject(); retjson = cJSON_CreateObject();

33
basilisk/basilisk_bitcoin.c

@ -299,7 +299,7 @@ int32_t basilisk_bitcoinavail(struct iguana_info *coin)
void *basilisk_bitcoinbalances(struct basilisk_item *Lptr,struct supernet_info *myinfo,struct iguana_info *coin,char *remoteaddr,uint32_t basilisktag,int32_t timeoutmillis,cJSON *vals) void *basilisk_bitcoinbalances(struct basilisk_item *Lptr,struct supernet_info *myinfo,struct iguana_info *coin,char *remoteaddr,uint32_t basilisktag,int32_t timeoutmillis,cJSON *vals)
{ {
int64_t balance,total = 0; int32_t i,n,hist; cJSON *spends,*unspents,*retjson,*item,*addresses,*array = cJSON_CreateArray(); int64_t balance,total = 0; int32_t i,n,hist; char *str; cJSON *spends,*unspents,*retjson,*item,*addresses,*array = cJSON_CreateArray();
spends = unspents = 0; spends = unspents = 0;
if ( (hist= juint(vals,"history")) != 0 ) if ( (hist= juint(vals,"history")) != 0 )
{ {
@ -313,12 +313,15 @@ void *basilisk_bitcoinbalances(struct basilisk_item *Lptr,struct supernet_info *
{ {
for (i=0; i<n; i++) for (i=0; i<n; i++)
{ {
balance = iguana_addressreceived(myinfo,coin,vals,remoteaddr,0,0,unspents,spends,jstri(addresses,i),juint(vals,"minconf"),juint(vals,"firstheight")); if ( (str= jstri(addresses,i)) != 0 )
item = cJSON_CreateObject(); {
jaddnum(item,jstri(addresses,i),dstr(balance)); balance = iguana_addressreceived(myinfo,coin,vals,remoteaddr,0,0,unspents,spends,str,juint(vals,"minconf"),juint(vals,"firstheight"));
jaddstr(item,"address",jstri(addresses,i)); item = cJSON_CreateObject();
jaddi(array,item); jaddnum(item,jstri(addresses,i),dstr(balance));
total += balance; jaddstr(item,"address",jstri(addresses,i));
jaddi(array,item);
total += balance;
}
//printf("%.8f ",dstr(balance)); //printf("%.8f ",dstr(balance));
} }
} }
@ -887,9 +890,11 @@ void basilisk_unspent_update(struct supernet_info *myinfo,struct iguana_info *co
item = jitem(spends,0); item = jitem(spends,0);
if ( (address= jstr(item,"address")) != 0 && (waddr= iguana_waddresssearch(myinfo,&wacct,address)) != 0 ) if ( (address= jstr(item,"address")) != 0 && (waddr= iguana_waddresssearch(myinfo,&wacct,address)) != 0 )
{ {
if ( waddr->spends != 0 ) // maybe better to merge and error check if basilisk if ( waddr->Cspends == 0 )
free_json(waddr->spends); waddr->Cspends = cJSON_CreateObject();
waddr->spends = jduplicate(spends); if ( jobj(waddr->Cspends,coin->symbol) != 0 )
jdelete(waddr->Cspends,coin->symbol); // better merge and error check if basilisk
jadd(waddr->Cspends,coin->symbol,jduplicate(spends));
} }
} }
if ( (unspents= jarray(&n,json,"unspents")) != 0 ) if ( (unspents= jarray(&n,json,"unspents")) != 0 )
@ -897,9 +902,11 @@ void basilisk_unspent_update(struct supernet_info *myinfo,struct iguana_info *co
item = jitem(unspents,0); item = jitem(unspents,0);
if ( (address= jstr(item,"address")) != 0 && (waddr= iguana_waddresssearch(myinfo,&wacct,address)) != 0 ) if ( (address= jstr(item,"address")) != 0 && (waddr= iguana_waddresssearch(myinfo,&wacct,address)) != 0 )
{ {
if ( waddr->unspents != 0 ) // maybe better to merge and error check if basilisk if ( waddr->Cunspents == 0 )
free_json(waddr->unspents); waddr->Cunspents = cJSON_CreateObject();
waddr->unspents = jduplicate(unspents); if ( jobj(waddr->Cunspents,coin->symbol) != 0 )
jdelete(waddr->Cunspents,coin->symbol); // better merge and error check if basilisk
jadd(waddr->Cunspents,coin->symbol,jduplicate(unspents));
} }
} }
} }

2
iguana/iguana_unspents.c

@ -853,7 +853,7 @@ int32_t iguana_RTunspentslists(struct supernet_info *myinfo,struct iguana_info *
{ {
if ( (waddr= iguana_waddresssearch(myinfo,&wacct,coinaddr)) != 0 ) if ( (waddr= iguana_waddresssearch(myinfo,&wacct,coinaddr)) != 0 )
{ {
if ( (array= waddr->unspents) != 0 ) if ( waddr->Cunspents != 0 && (array= jobj(waddr->Cunspents,coin->symbol)) != 0 )
{ {
if ( (n= cJSON_GetArraySize(array)) > 0 ) if ( (n= cJSON_GetArraySize(array)) > 0 )
{ {

10
iguana/iguana_wallet.c

@ -745,10 +745,10 @@ cJSON *iguana_walletiterate(struct supernet_info *myinfo,struct iguana_info *coi
if ( flag < -1 ) if ( flag < -1 )
{ {
HASH_DELETE(hh,wacct->waddr,waddr); HASH_DELETE(hh,wacct->waddr,waddr);
if ( waddr->unspents != 0 ) if ( waddr->Cunspents != 0 )
free_json(waddr->unspents), waddr->unspents = 0; free_json(waddr->Cunspents), waddr->Cunspents = 0;
if ( waddr->spends != 0 ) if ( waddr->Cspends != 0 )
free_json(waddr->spends), waddr->spends = 0; free_json(waddr->Cspends), waddr->Cspends = 0;
//printf("walletiterate: %p free %s\n",waddr,waddr->coinaddr); //printf("walletiterate: %p free %s\n",waddr,waddr->coinaddr);
myfree(waddr,sizeof(*waddr) + waddr->scriptlen); myfree(waddr,sizeof(*waddr) + waddr->scriptlen);
} }
@ -1140,7 +1140,7 @@ struct iguana_waddress *iguana_getaccountaddress(struct supernet_info *myinfo,st
wacct = iguana_waccountcreate(myinfo,account); wacct = iguana_waccountcreate(myinfo,account);
if ( wacct != 0 ) if ( wacct != 0 )
{ {
if ( (waddr= wacct->current) == 0 || waddr->unspents != 0 ) if ( (waddr= wacct->current) == 0 || (waddr->Cunspents != 0 && jobj(waddr->Cunspents,coin->symbol) != 0) )
{ {
if ( (retstr= SuperNET_login(IGUANA_CALLARGS,myinfo->handle,myinfo->secret,myinfo->permanentfile,myinfo->password)) != 0 ) if ( (retstr= SuperNET_login(IGUANA_CALLARGS,myinfo->handle,myinfo->secret,myinfo->permanentfile,myinfo->password)) != 0 )
{ {

2
iguana/tests/history

@ -1 +1 @@
curl --url "http://127.0.0.1:7778" --data "{\"timeout\":20000,\"agent\":\"basilisk\",\"method\":\"history\",\"vals\":{\"coin\":\"BTCD\"}}" curl --url "http://127.0.0.1:7778" --data "{\"timeout\":20000,\"agent\":\"basilisk\",\"method\":\"history\",\"vals\":{\"coin\":\"BTC\"}}"

1
iguana/tests/history2

@ -0,0 +1 @@
curl --url "http://127.0.0.1:7778" --data "{\"timeout\":20000,\"agent\":\"basilisk\",\"method\":\"history\",\"vals\":{\"coin\":\"BTCD\"}}"

2
includes/iguana_structs.h

@ -374,7 +374,7 @@ struct basilisk_spend { bits256 txid,spentfrom; uint64_t relaymask,value; uint32
struct basilisk_unspent { bits256 txid; uint64_t value,relaymask; uint32_t unspentind,timestamp; int32_t RTheight,height,spentheight; int16_t status,hdrsi,vout,spendlen; char symbol[16]; uint8_t script[256]; }; struct basilisk_unspent { bits256 txid; uint64_t value,relaymask; uint32_t unspentind,timestamp; int32_t RTheight,height,spentheight; int16_t status,hdrsi,vout,spendlen; char symbol[16]; uint8_t script[256]; };
struct iguana_waddress { UT_hash_handle hh; cJSON *unspents,*spends; uint64_t balance; uint16_t scriptlen; uint8_t rmd160[20],pubkey[33],wiftype,addrtype; bits256 privkey; char symbol[8],coinaddr[36],wifstr[54]; uint8_t redeemScript[]; }; struct iguana_waddress { UT_hash_handle hh; cJSON *Cunspents,*Cspends; uint64_t balance; uint16_t scriptlen; uint8_t rmd160[20],pubkey[33],wiftype,addrtype; bits256 privkey; char symbol[8],coinaddr[36],wifstr[54]; uint8_t redeemScript[]; };
struct iguana_waccount { UT_hash_handle hh; struct iguana_waddress *waddr,*current; char account[]; }; struct iguana_waccount { UT_hash_handle hh; struct iguana_waddress *waddr,*current; char account[]; };
struct iguana_wallet { UT_hash_handle hh; struct iguana_waccount *wacct; }; struct iguana_wallet { UT_hash_handle hh; struct iguana_waccount *wacct; };

Loading…
Cancel
Save