Browse Source

basilisk listunspent, balances, history

release/v0.1
jl777 8 years ago
committed by Christopher Valerio
parent
commit
54056bc131
  1. 6
      basilisk/basilisk.c
  2. 76
      basilisk/basilisk_bitcoin.c
  3. 44
      iguana/iguana_unspents.c
  4. 27
      iguana/iguana_wallet.c
  5. 2
      iguana/tests/listunspent
  6. 4
      includes/iguana_funcs.h

6
basilisk/basilisk.c

@ -956,7 +956,11 @@ HASH_ARRAY_STRING(basilisk,balances,hash,vals,hexstr)
return(clonestr("{\"error\":\"no result\"}"));
}
} else printf("no coin\n");
return(basilisk_standardservice("BAL",myinfo,0,hash,vals,hexstr,1));
if ( (retstr= basilisk_standardservice("BAL",myinfo,0,hash,vals,hexstr,1)) != 0 )
{
basilisk_unspents_process(myinfo,coin,retstr);
}
return(retstr);
}
HASH_ARRAY_STRING(basilisk,history,hash,vals,hexstr)

76
basilisk/basilisk_bitcoin.c

@ -914,65 +914,91 @@ int32_t basilisk_unspentfind(struct supernet_info *myinfo,struct iguana_info *co
return(-1);
}
void basilisk_jsonmerge(cJSON *json,char *symbol,cJSON *array)
cJSON *basilisk_jsonmerge(char *symbol,cJSON *array)
{
int32_t i,j,n,m; cJSON *jobj,*iobj,*dest;
if ( (dest= jarray(&m,json,symbol)) == 0 )
dest = cJSON_CreateArray();
int32_t i,j,n,m; cJSON *jobj,*iobj,*dest = cJSON_CreateArray();
if ( dest != 0 && (n= cJSON_GetArraySize(array)) > 0 )
{
m = cJSON_GetArraySize(dest);
for (i=0; i<n; i++)
{
m = cJSON_GetArraySize(dest);
iobj = jitem(array,i);
for (j=0; j<m; j++)
{
jobj = jitem(dest,j);
if ( bits256_cmp(jbits256(jobj,"txid"),jbits256(iobj,"txid")) == 0 && jint(jobj,"vout") == jint(iobj,"vout") )
{
//printf("(%s) == (%s)\n",jprint(iobj,0),jprint(jobj,0));
break;
}
}
if ( j == m )
{
jaddi(dest,jduplicate(iobj));
//printf("add.(%s) ",jprint(iobj,0));
} //else printf("j.%d != m.%d\n",j,m);
}
}
return(dest);
}
void basilisk_unspent_update(struct supernet_info *myinfo,struct iguana_info *coin,cJSON *json)
{
cJSON *unspents,*spends,*item; int32_t n; char *address; struct iguana_waccount *wacct; struct iguana_waddress *waddr=0;
if ( (spends= jarray(&n,json,"spends")) != 0 )
cJSON *unspents,*spends,*item; int32_t n; char *address; //struct iguana_waccount *wacct; struct iguana_waddress *waddr=0;
if ( (spends= jarray(&n,json,"spends")) != 0 && n > 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 ( myinfo->Cspends == 0 )
{
myinfo->Cspends = cJSON_CreateObject();
jadd(myinfo->Cspends,coin->symbol,jduplicate(spends));
} else basilisk_jsonmerge(myinfo->Cspends,coin->symbol,spends);
if ( jobj(myinfo->Cspends,coin->symbol) != 0 )
jdelete(myinfo->Cspends,coin->symbol);
jadd(myinfo->Cspends,coin->symbol,basilisk_jsonmerge(coin->symbol,spends));
//printf("S.(%s)\n",jprint(waddr->Cspends,0));
}
//printf("merge spends.(%s)\n",jprint(spends,0));
}
if ( (unspents= jarray(&n,json,"unspents")) != 0 )
if ( (unspents= jarray(&n,json,"unspents")) != 0 && n > 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 ( myinfo->Cunspents == 0 )
{
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));
if ( jobj(myinfo->Cunspents,coin->symbol) != 0 )
jdelete(myinfo->Cunspents,coin->symbol);
jadd(myinfo->Cunspents,coin->symbol,basilisk_jsonmerge(coin->symbol,unspents));
//printf("U.(%s)\n",jprint(myinfo->Cunspents,0));
}
//printf("merge unspents.(%s)\n",jprint(unspents,0));
}
}
void basilisk_unspents_process(struct supernet_info *myinfo,struct iguana_info *coin,char *retstr)
{
cJSON *retarray; int32_t i,n;
portable_mutex_lock(&myinfo->bu_mutex);
if ( myinfo->Cspends != 0 )
free_json(myinfo->Cspends), myinfo->Cspends = 0;
if ( myinfo->Cunspents != 0 )
free_json(myinfo->Cunspents), myinfo->Cunspents = 0;
if ( (retarray= cJSON_Parse(retstr)) != 0 )
{
if ( is_cJSON_Array(retarray) != 0 )
{
n = cJSON_GetArraySize(retarray);
for (i=0; i<n; i++)
basilisk_unspent_update(myinfo,coin,jitem(retarray,i));
} else basilisk_unspent_update(myinfo,coin,retarray);
free_json(retarray);
}
portable_mutex_unlock(&myinfo->bu_mutex);
}
void basilisk_unspents_update(struct supernet_info *myinfo,struct iguana_info *coin)
{
char *retstr; cJSON *vals; int32_t oldest,i,RTheight; cJSON *retarray;
char *retstr; cJSON *vals; int32_t oldest,i,RTheight;
vals = cJSON_CreateObject();
for (i=oldest=0; i<BASILISK_MAXRELAYS; i++)
if ( (RTheight= coin->relay_RTheights[i]) != 0 && (oldest == 0 || RTheight < oldest) )
@ -982,19 +1008,7 @@ void basilisk_unspents_update(struct supernet_info *myinfo,struct iguana_info *c
jaddstr(vals,"coin",coin->symbol);
if ( (retstr= basilisk_balances(myinfo,coin,0,0,GENESIS_PUBKEY,vals,"")) != 0 )
{
//printf("basilisk_balances.(%s)\n",retstr);
if ( (retarray= cJSON_Parse(retstr)) != 0 )
{
portable_mutex_lock(&myinfo->bu_mutex);
iguana_wallet_Cclear(myinfo,coin->symbol);
if ( is_cJSON_Array(retarray) != 0 )
{
for (i=0; i<cJSON_GetArraySize(retarray); i++)
basilisk_unspent_update(myinfo,coin,jitem(retarray,i));
} else basilisk_unspent_update(myinfo,coin,retarray);
free_json(retarray);
portable_mutex_unlock(&myinfo->bu_mutex);
}
basilisk_unspents_process(myinfo,coin,retstr);
free(retstr);
}
free_json(vals);

44
iguana/iguana_unspents.c

@ -941,11 +941,44 @@ uint64_t iguana_unspentavail(struct supernet_info *myinfo,struct iguana_info *co
cJSON *iguana_RTlistunspent(struct supernet_info *myinfo,struct iguana_info *coin,cJSON *argarray,int32_t minconf,int32_t maxconf,char *remoteaddr,int32_t includespends)
{
int32_t numrmds,numunspents=0; uint8_t *rmdarray; cJSON *retjson = cJSON_CreateArray();
rmdarray = iguana_rmdarray(myinfo,coin,&numrmds,argarray,0);
iguana_RTunspents(myinfo,coin,retjson,minconf,maxconf,rmdarray,numrmds,(1 << 30),0,&numunspents,remoteaddr,includespends);
if ( rmdarray != 0 )
free(rmdarray);
int32_t i,j,m,n,numrmds,numunspents=0; char *coinaddr; uint8_t *rmdarray; cJSON *unspents,*item,*array,*retjson;
if ( coin->FULLNODE != 0 || coin->VALIDATENODE != 0 )
{
retjson = cJSON_CreateArray();
rmdarray = iguana_rmdarray(myinfo,coin,&numrmds,argarray,0);
iguana_RTunspents(myinfo,coin,retjson,minconf,maxconf,rmdarray,numrmds,(1 << 30),0,&numunspents,remoteaddr,includespends);
if ( rmdarray != 0 )
free(rmdarray);
}
else
{
portable_mutex_lock(&myinfo->bu_mutex);
if ( (unspents= myinfo->Cunspents) != 0 && (array= jobj(unspents,coin->symbol)) != 0 )
unspents = jduplicate(array);
portable_mutex_unlock(&myinfo->bu_mutex);
retjson = cJSON_CreateArray();
if ( unspents != 0 )
{
if ( (n= cJSON_GetArraySize(unspents)) > 0 && (m= cJSON_GetArraySize(argarray)) > 0 )
{
for (i=0; i<n; i++)
{
item = jitem(unspents,i);
if ( (coinaddr= jstr(item,"address")) != 0 )
{
for (j=0; j<m; j++)
if ( strcmp(coinaddr,jstri(argarray,j)) == 0 )
{
jaddi(retjson,jduplicate(item));
break;
}
}
}
}
//printf("RET.(%s)\n",jprint(retjson,0));
free_json(unspents);
}
}
/*{
"txid" : "d54994ece1d11b19785c7248868696250ab195605b469632b7bd68130e880c9a",
"vout" : 1,
@ -956,7 +989,6 @@ cJSON *iguana_RTlistunspent(struct supernet_info *myinfo,struct iguana_info *coi
"confirmations" : 6210,
"spendable" : true
},*/
return(retjson);
}

27
iguana/iguana_wallet.c

@ -307,6 +307,8 @@ uint8_t *iguana_walletrmds(struct supernet_info *myinfo,struct iguana_info *coin
cJSON *iguana_getaddressesbyaccount(struct supernet_info *myinfo,struct iguana_info *coin,char *account)
{
struct iguana_waccount *subset,*tmp; char refaddr[64],coinaddr[64]; struct iguana_waddress *waddr,*tmp2; cJSON *retjson,*array;
if ( coin == 0 )
return(0);
retjson = cJSON_CreateObject();
array = cJSON_CreateArray();
if ( account == 0 || account[0] == 0 )
@ -342,27 +344,6 @@ cJSON *iguana_getaddressesbyaccount(struct supernet_info *myinfo,struct iguana_i
return(array);
}
void iguana_wallet_Cclear(struct supernet_info *myinfo,char *symbol)
{
/*struct iguana_waccount *subset,*tmp; struct iguana_waddress *waddr,*tmp2;
HASH_ITER(hh,myinfo->wallet,subset,tmp)
{
HASH_ITER(hh,subset->waddr,waddr,tmp2)
{
if ( waddr->Cspends != 0 )
free_json(waddr->Cspends), waddr->Cspends = 0;
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])
{
struct iguana_waccount *wacct; struct iguana_waddress *waddr = 0;
@ -936,10 +917,6 @@ void iguana_walletlock(struct supernet_info *myinfo,struct iguana_info *coin)
memset(myinfo->myaddr.NXTADDR,0,sizeof(myinfo->myaddr.NXTADDR));
myinfo->myaddr.nxt64bits = 0;
myinfo->expiration = 0;
portable_mutex_lock(&myinfo->bu_mutex);
if ( myinfo->spends != 0 )
/*free(myinfo->spends),*/ myinfo->numspends = 0;
portable_mutex_unlock(&myinfo->bu_mutex);
iguana_walletiterate(myinfo,coin,-2,0,0,0,0);
}

2
iguana/tests/listunspent

@ -1 +1 @@
curl --url "http://127.0.0.1:7778" --data "{\"coin\":\"BTCD\",\"method\":\"listunspent\",\"params\":[1, 9999999, [\"RFMEYcxuBL8S7UPdUbzXunPtS4p82HRcKs\"]]}"
curl --url "http://127.0.0.1:7778" --data "{\"coin\":\"BTCD\",\"method\":\"listunspent\",\"params\":[1, 9999999, []]}"

4
includes/iguana_funcs.h

@ -245,7 +245,7 @@ int32_t blockhash_sha256(uint8_t *blockhashp,uint8_t *serialized,int32_t len);
void iguana_nameset(char name[64],char *symbol,cJSON *json);
cJSON *iguana_getinfo(struct supernet_info *myinfo,struct iguana_info *coin);
void *basilisk_getinfo(struct basilisk_item *Lptr,struct supernet_info *myinfo,struct iguana_info *coin,char *remoteaddr,uint32_t basilisktag,int32_t timeoutmillis,cJSON *valsobj);
void basilisk_unspents_process(struct supernet_info *myinfo,struct iguana_info *coin,char *retstr);
char *busdata_sync(uint32_t *noncep,char *jsonstr,char *broadcastmode,char *destNXTaddr);
void peggy();
int32_t opreturns_init(uint32_t blocknum,uint32_t blocktimestamp,char *path);
@ -430,7 +430,7 @@ struct iguana_waddress *iguana_waddresssearch(struct supernet_info *myinfo,struc
cJSON *iguana_RTlistunspent(struct supernet_info *myinfo,struct iguana_info *coin,cJSON *argarray,int32_t minconf,int32_t maxconf,char *remoteaddr,int32_t includespends);
void calc_shares(struct supernet_info *myinfo,uint8_t *shares,uint8_t *secret,int32_t size,int32_t width,int32_t M,int32_t N,uint8_t *sharenrs,uint8_t *space,int32_t spacesize);
//struct basilisk_spend *basilisk_addspend(struct supernet_info *myinfo,char *symbol,bits256 txid,uint16_t vout,int32_t addflag);
void iguana_wallet_Cclear(struct supernet_info *myinfo,char *symbol);
//void iguana_wallet_Cclear(struct supernet_info *myinfo,char *symbol);
int64_t _RTgettxout(struct iguana_info *coin,struct iguana_RTtxid **ptrp,int32_t *heightp,int32_t *scriptlenp,uint8_t *script,uint8_t *rmd160,char *coinaddr,bits256 txid,int32_t vout,int32_t mempool);
int32_t _iguana_RTunspentfind(struct supernet_info *myinfo,struct iguana_info *coin,bits256 *txidp,int32_t *voutp,uint8_t *spendscript,struct iguana_outpoint outpt,int64_t value);
int32_t basilisk_unspentfind(struct supernet_info *myinfo,struct iguana_info *coin,bits256 *txidp,int32_t *voutp,uint8_t *spendscript,struct iguana_outpoint outpt,int64_t value);

Loading…
Cancel
Save