Browse Source

test

release/v0.1
jl777 8 years ago
parent
commit
0bd5fcb676
  1. 40
      basilisk/basilisk.c
  2. 2
      basilisk/basilisk.h
  3. 18
      basilisk/basilisk_bitcoin.c
  4. 2
      iguana/iguana777.h
  5. 10
      iguana/iguana_unspents.c
  6. 42
      iguana/iguana_wallet.c
  7. 2
      includes/iguana_structs.h

40
basilisk/basilisk.c

@ -427,7 +427,7 @@ char *basilisk_standardservice(char *CMD,struct supernet_info *myinfo,void *_add
if ( RELAYID >= 0 && basilisk_specialcmd(CMD) == 0 )
return(clonestr("{\"error\":\"unsupported special relay command\"}"));
data = get_dataptr(BASILISK_HDROFFSET,&allocptr,&datalen,space,sizeof(space),hexstr);
//printf("request.(%s)\n",jprint(valsobj,0));
//printf("request.(%s)\n",jprint(valsobj,0));
ptr = basilisk_requestservice(myinfo,_addr,CMD,blockflag,valsobj,hash,data,datalen,nBits);
if ( allocptr != 0 )
free(allocptr);
@ -573,8 +573,8 @@ void basilisk_result(struct supernet_info *myinfo,char *remoteaddr,uint32_t basi
{
retstr = jprint(vals,0);
safecopy(CMD,jstr(vals,"origcmd"),sizeof(CMD));
if ( 0 && strcmp("RID",CMD) != 0 )
printf("(%s) -> Q.%u results vals.(%d)\n",CMD,basilisktag,(int32_t)strlen(retstr));
//if ( 0 && strcmp("RID",CMD) != 0 )
//printf("(%s) -> Q.%u results vals.(%s)\n",CMD,basilisktag,retstr);//(int32_t)strlen(retstr));
if ( strcmp(CMD,"GET") == 0 )
basilisk_geckoresult(myinfo,remoteaddr,retstr,data,datalen);
else
@ -593,7 +593,7 @@ void basilisk_result(struct supernet_info *myinfo,char *remoteaddr,uint32_t basi
jaddi(pending->retarray,item);
if ( jobj(item,"error") == 0 )
{
printf("numresults.%d:%d\n",pending->numresults,cJSON_GetArraySize(pending->retarray));
//printf("numresults.%d:%d\n",pending->numresults,cJSON_GetArraySize(pending->retarray));
pending->numresults++;
}
} else printf("couldnt parse.(%s)\n",retstr);
@ -932,17 +932,17 @@ HASH_ARRAY_STRING(basilisk,balances,hash,vals,hexstr)
jaddnum(vals,"fanout",MAX(5,(int32_t)sqrt(NUMRELAYS)+1));
if ( jobj(vals,"numrequired") == 0 )
jaddnum(vals,"numrequired",juint(vals,"fanout"));
if ( jobj(vals,"addresses") == 0 )
{
jadd(vals,"addresses",iguana_getaddressesbyaccount(myinfo,coin,"*"));
//printf("added all %s addresses: %s\n",coin->symbol,jprint(vals,0));
} //else printf("have addresses.(%s)\n",jprint(jobj(vals,"addresses"),0));
if ( (basilisktag= juint(vals,"basilisktag")) == 0 )
basilisktag = rand();
if ( (timeoutmillis= juint(vals,"timeout")) <= 0 )
timeoutmillis = 3000;
if ( coin != 0 )
{
if ( jobj(vals,"addresses") == 0 )
{
jadd(vals,"addresses",iguana_getaddressesbyaccount(myinfo,coin,"*"));
//printf("added all %s addresses: %s\n",coin->symbol,jprint(vals,0));
} //else printf("have addresses.(%s)\n",jprint(jobj(vals,"addresses"),0));
if ( (basilisktag= juint(vals,"basilisktag")) == 0 )
basilisktag = rand();
if ( (timeoutmillis= juint(vals,"timeout")) <= 0 )
timeoutmillis = BASILISK_TIMEOUT;
if ( coin->FULLNODE != 0 || coin->VALIDATENODE != 0 )
{
if ( (ptr= basilisk_bitcoinbalances(&Lptr,myinfo,coin,remoteaddr,basilisktag,timeoutmillis,vals)) != 0 )
@ -959,7 +959,7 @@ HASH_ARRAY_STRING(basilisk,balances,hash,vals,hexstr)
HASH_ARRAY_STRING(basilisk,history,hash,vals,hexstr)
{
int64_t total = 0; int32_t i,n; struct iguana_waccount *wacct,*tmp; struct iguana_waddress *waddr,*tmp2; char *symbol; cJSON *retjson,*unspents,*spends,*array; //struct basilisk_spend *s; struct basilisk_unspent *bu; int32_t i;
int64_t total = 0; int32_t i,n; char *symbol; cJSON *retjson,*unspents,*spends,*array; //struct basilisk_spend *s; struct basilisk_unspent *bu; int32_t i; struct iguana_waccount *wacct,*tmp; struct iguana_waddress *waddr,*tmp2;
if ( vals == 0 )
return(clonestr("{\"error\":\"need vals object\"}"));
//if ( coin == 0 )
@ -972,14 +972,14 @@ HASH_ARRAY_STRING(basilisk,history,hash,vals,hexstr)
unspents = cJSON_CreateArray();
spends = cJSON_CreateArray();
portable_mutex_lock(&myinfo->bu_mutex);
HASH_ITER(hh,myinfo->wallet,wacct,tmp)
//HASH_ITER(hh,myinfo->wallet,wacct,tmp)
{
HASH_ITER(hh,wacct->waddr,waddr,tmp2)
//HASH_ITER(hh,wacct->waddr,waddr,tmp2)
{
if ( waddr->Cunspents != 0 )
if ( myinfo->Cunspents != 0 )
{
//printf("Cunspents.(%s)\n",jprint(waddr->Cunspents,0));
if ( (array= jobj(waddr->Cunspents,coin->symbol)) != 0 )
if ( (array= jobj(myinfo->Cunspents,coin->symbol)) != 0 )
{
if ( (n= cJSON_GetArraySize(array)) > 0 )
{
@ -989,10 +989,10 @@ HASH_ARRAY_STRING(basilisk,history,hash,vals,hexstr)
jaddi(unspents,jduplicate(array));
}
}
if ( waddr->Cspends != 0 )
if ( myinfo->Cspends != 0 )
{
//printf("Cspends.(%s)\n",jprint(waddr->Cspends,0));
if ( (array= jobj(waddr->Cspends,coin->symbol)) != 0 )
if ( (array= jobj(myinfo->Cspends,coin->symbol)) != 0 )
jaddi(spends,jduplicate(array));
}
}

2
basilisk/basilisk.h

@ -20,7 +20,7 @@
#include "../iguana/iguana777.h"
#define BASILISK_TIMEOUT 30000
#define BASILISK_TIMEOUT 5000
#define BASILISK_MINFANOUT 8
#define BASILISK_MAXFANOUT 64
#define BASILISK_DEFAULTDIFF 0x1effffff

18
basilisk/basilisk_bitcoin.c

@ -945,11 +945,12 @@ void basilisk_unspent_update(struct supernet_info *myinfo,struct iguana_info *co
item = jitem(spends,0);
if ( (address= jstr(item,"address")) != 0 && (waddr= iguana_waddresssearch(myinfo,&wacct,address)) != 0 )
{
if ( waddr->Cspends == 0 )
if ( myinfo->Cspends == 0 )
{
waddr->Cspends = cJSON_CreateObject();
jadd(waddr->Cspends,coin->symbol,jduplicate(spends));
} else basilisk_jsonmerge(waddr->Cspends,coin->symbol,spends);
myinfo->Cspends = cJSON_CreateObject();
jadd(myinfo->Cspends,coin->symbol,jduplicate(spends));
} else basilisk_jsonmerge(myinfo->Cspends,coin->symbol,spends);
//printf("S.(%s)\n",jprint(waddr->Cspends,0));
}
//printf("merge spends.(%s)\n",jprint(spends,0));
}
@ -958,11 +959,12 @@ void basilisk_unspent_update(struct supernet_info *myinfo,struct iguana_info *co
item = jitem(unspents,0);
if ( (address= jstr(item,"address")) != 0 && (waddr= iguana_waddresssearch(myinfo,&wacct,address)) != 0 )
{
if ( waddr->Cunspents == 0 )
if ( myinfo->Cunspents == 0 )
{
waddr->Cunspents = cJSON_CreateObject();
jadd(waddr->Cunspents,coin->symbol,jduplicate(unspents));
} else basilisk_jsonmerge(waddr->Cunspents,coin->symbol,unspents);
myinfo->Cunspents = cJSON_CreateObject();
jadd(myinfo->Cunspents,coin->symbol,jduplicate(unspents));
} else basilisk_jsonmerge(myinfo->Cunspents,coin->symbol,unspents);
printf("U.(%s)\n",jprint(myinfo->Cunspents,0));
}
//printf("merge unspents.(%s)\n",jprint(unspents,0));
}

2
iguana/iguana777.h

@ -78,7 +78,7 @@ struct supernet_info
struct iguana_waccount *wallet;
struct iguana_info *allcoins; int32_t allcoins_being_added,allcoins_numvirts;
portable_mutex_t bu_mutex,allcoins_mutex,gecko_mutex,basilisk_mutex,DEX_mutex,DEX_reqmutex,DEX_swapmutex;
struct queueitem *DEX_quotes;
struct queueitem *DEX_quotes; cJSON *Cunspents,*Cspends;
struct basilisk_swap *swaps[256]; int32_t numswaps;
struct basilisk_message *messagetable; portable_mutex_t messagemutex; queue_t msgQ;
void *ctx;

10
iguana/iguana_unspents.c

@ -636,12 +636,12 @@ int64_t iguana_RTunspents(struct supernet_info *myinfo,struct iguana_info *coin,
bitcoin_address(coinaddr,addrtypes[i],&rmdarray[i * 20],20);
*numunspentsp = 0;
iguana_RTpkhasharray(myinfo,coin,array,minconf,maxconf,&total,P,coin->bundlescount,&rmdarray[i * 20],coinaddr,&pubkeys[33*i],lastheight,unspents != 0 ? &unspents[numunspents] : 0,numunspentsp,maxunspents,remoteaddr,includespent);
//printf("iguana_unspents: i.%d of %d: %s %.8f numunspents.%d\n",i,numrmds,coinaddr,dstr(total),*numunspentsp);
printf("iguana_unspents: i.%d of %d: %s %.8f numunspents.%d\n",i,numrmds,coinaddr,dstr(total),*numunspentsp);
maxunspents -= *numunspentsp;
numunspents += *numunspentsp;
sum += total;
}
//printf("sum %.8f\n",dstr(sum));
printf("sum %.8f\n",dstr(sum));
free(P);
}
*numunspentsp = numunspents;
@ -820,7 +820,7 @@ int32_t iguana_RTaddr_unspents(struct supernet_info *myinfo,struct iguana_info *
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_waddress *waddr; struct iguana_waccount *wacct; struct iguana_outpoint outpt; cJSON *array,*item;
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 )
{
@ -851,9 +851,9 @@ int32_t iguana_RTunspentslists(struct supernet_info *myinfo,struct iguana_info *
else
{
portable_mutex_lock(&myinfo->bu_mutex);
if ( (waddr= iguana_waddresssearch(myinfo,&wacct,coinaddr)) != 0 )
//if ( (waddr= iguana_waddresssearch(myinfo,&wacct,coinaddr)) != 0 )
{
if ( waddr->Cunspents != 0 && (array= jobj(waddr->Cunspents,coin->symbol)) != 0 )
if ( myinfo->Cunspents != 0 && (array= jobj(myinfo->Cunspents,coin->symbol)) != 0 )
{
if ( (n= cJSON_GetArraySize(array)) > 0 )
{

42
iguana/iguana_wallet.c

@ -344,7 +344,7 @@ cJSON *iguana_getaddressesbyaccount(struct supernet_info *myinfo,struct iguana_i
void iguana_wallet_Cclear(struct supernet_info *myinfo,char *symbol)
{
struct iguana_waccount *subset,*tmp; struct iguana_waddress *waddr,*tmp2;
/*struct iguana_waccount *subset,*tmp; struct iguana_waddress *waddr,*tmp2;
HASH_ITER(hh,myinfo->wallet,subset,tmp)
{
HASH_ITER(hh,subset->waddr,waddr,tmp2)
@ -354,7 +354,13 @@ void iguana_wallet_Cclear(struct supernet_info *myinfo,char *symbol)
if ( waddr->Cunspents != 0 )
free_json(waddr->Cunspents), waddr->Cunspents = 0;
}
}
}*/
portable_mutex_lock(&myinfo->bu_mutex);
if ( myinfo->Cspends != 0 )
free_json(myinfo->Cspends);
if ( myinfo->Cunspents != 0 )
free_json(myinfo->Cunspents);
portable_mutex_unlock(&myinfo->bu_mutex);
}
struct iguana_waddress *iguana_ismine(struct supernet_info *myinfo,struct iguana_info *coin,char *coinaddr,uint8_t addrtype,uint8_t pubkey[65],uint8_t rmd160[20])
@ -775,10 +781,11 @@ cJSON *iguana_walletiterate(struct supernet_info *myinfo,struct iguana_info *coi
if ( flag < -1 )
{
HASH_DELETE(hh,wacct->waddr,waddr);
if ( waddr->Cunspents != 0 )
/*if ( waddr->Cunspents != 0 )
free_json(waddr->Cunspents), waddr->Cunspents = 0;
if ( waddr->Cspends != 0 )
free_json(waddr->Cspends), waddr->Cspends = 0;
*/
//printf("walletiterate: %p free %s\n",waddr,waddr->coinaddr);
myfree(waddr,sizeof(*waddr) + waddr->scriptlen);
}
@ -1001,7 +1008,7 @@ int64_t iguana_addressreceived(struct supernet_info *myinfo,struct iguana_info *
int64_t balance = 0; cJSON *unspentsjson,*balancejson,*item; int32_t i,n; char *balancestr;
if ( (balancestr= iguana_balance(IGUANA_CALLARGS,coin->symbol,coinaddr,1<<30,minconf)) != 0 )
{
//printf("balancestr.(%s) (%s)\n",balancestr,coinaddr);
printf("balancestr.(%s) (%s)\n",balancestr,coinaddr);
if ( (balancejson= cJSON_Parse(balancestr)) != 0 )
{
balance = jdouble(balancejson,"balance") * SATOSHIDEN;
@ -1155,11 +1162,11 @@ ZERO_ARGS(bitcoinrpc,getinfo)
if ( is_cJSON_Array(array) != 0 )
{
getinfoobj = jduplicate(jitem(array,0));
longest = juint(getinfoobj,"longestchain");
longest = 0;
if ( coin->FULLNODE == 0 && coin->VALIDATENODE == 0 && (n= cJSON_GetArraySize(array)) > 1 )
{
jdelete(getinfoobj,"longestchain");
for (i=1; i<n; i++)
for (i=0; i<n; i++)
{
item = jitem(array,i);
if ( juint(getinfoobj,"longestchain") > longest )
@ -1230,13 +1237,32 @@ STRING_ARG(bitcoinrpc,getnewaddress,account)
struct iguana_waddress *iguana_getaccountaddress(struct supernet_info *myinfo,struct iguana_info *coin,cJSON *json,char *remoteaddr,char *coinaddr,char *account)
{
char *newstr,*retstr; struct iguana_waccount *wacct; struct iguana_waddress *waddr=0;
char *newstr,*retstr; int32_t i,n,flag=0; struct iguana_waccount *wacct; struct iguana_waddress *waddr=0; cJSON *unspents,*item;
coinaddr[0] = 0;
if ( (wacct= iguana_waccountfind(myinfo,account)) == 0 )
wacct = iguana_waccountcreate(myinfo,account);
if ( wacct != 0 )
{
if ( (waddr= wacct->current) == 0 || (waddr->Cunspents != 0 && jobj(waddr->Cunspents,coin->symbol) != 0) )
portable_mutex_lock(&myinfo->bu_mutex);
if ( myinfo->Cunspents != 0 && (unspents= jobj(myinfo->Cunspents,coin->symbol)) != 0 )
{
flag = 0;
if ( (n= cJSON_GetArraySize(unspents)) > 0 )
{
for (i=0; i<n; i++)
{
item = jitem(unspents,i);
if ( jstr(item,"address") != 0 && strcmp(jstr(item,"address"),coinaddr) == 0 )
{
flag = 1;
printf("found unspent for.(%s)\n",coinaddr);
break;
}
}
}
}
portable_mutex_unlock(&myinfo->bu_mutex);
if ( flag != 0 || (waddr= wacct->current) == 0 )
{
if ( (retstr= SuperNET_login(IGUANA_CALLARGS,myinfo->handle,myinfo->secret,myinfo->permanentfile,myinfo->password)) != 0 )
{

2
includes/iguana_structs.h

@ -380,7 +380,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 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_waddress { UT_hash_handle hh; 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_wallet { UT_hash_handle hh; struct iguana_waccount *wacct; };

Loading…
Cancel
Save