Browse Source

test

release/v0.1
jl777 9 years ago
parent
commit
55f392e487
  1. 23
      basilisk/basilisk.c
  2. 32
      basilisk/basilisk_bitcoin.c

23
basilisk/basilisk.c

@ -984,7 +984,7 @@ HASH_ARRAY_STRING(basilisk,value,hash,vals,hexstr)
HASH_ARRAY_STRING(basilisk,rawtx,hash,vals,hexstr)
{
char *retstr=0,*symbol; uint32_t basilisktag; struct basilisk_item *ptr,Lptr; int32_t timeoutmillis; uint64_t amount,txfee;
char *retstr=0,*symbol; uint32_t basilisktag; struct basilisk_item *ptr,Lptr; int32_t timeoutmillis,i,retval = -1; uint64_t amount,txfee; cJSON *retarray;
if ( coin == 0 )
{
if ( (symbol= jstr(vals,"symbol")) != 0 || (symbol= jstr(vals,"coin")) != 0 )
@ -1008,10 +1008,25 @@ HASH_ARRAY_STRING(basilisk,rawtx,hash,vals,hexstr)
txfee = coin->chain->txfee;
if ( txfee == 0 )
txfee = 10000;
if ( basilisk_vins_validate(myinfo,coin,retstr,amount,txfee) < 0 )
retval = -1;
if ( (retarray= cJSON_Parse(retstr)) != 0 )
{
free(retstr);
retstr = clonestr("{\"error\":\"invalid vin in rawtx\"}");
if ( is_cJSON_Array(retarray) != 0 )
{
for (i=0; i<cJSON_GetArraySize(retarray); i++)
{
if ( basilisk_vins_validate(myinfo,coin,jitem(retarray,i),amount,txfee) == 0 )
{
retval = 0;
break;
}
}
} else retval = basilisk_vins_validate(myinfo,coin,retarray,amount,txfee);
if ( retval < 0 )
{
free(retstr);
retstr = clonestr("{\"error\":\"invalid vin in rawtx\"}");
}
}
ptr->retstr = 0;
ptr->finished = (uint32_t)time(NULL);

32
basilisk/basilisk_bitcoin.c

@ -335,19 +335,19 @@ double basilisk_bitcoin_valuemetric(struct supernet_info *myinfo,struct basilisk
void *basilisk_bitcoinvalue(struct basilisk_item *Lptr,struct supernet_info *myinfo,struct iguana_info *coin,char *remoteaddr,uint32_t basilisktag,int32_t timeoutmillis,cJSON *valsobj)
{
int32_t i,height,vout,numsent; struct basilisk_item *ptr; char coinaddr[64]; struct basilisk_value *v; uint64_t value = 0; bits256 txid;
int32_t i,height,vout,numsent; struct basilisk_item *ptr; char coinaddr[64],str[64]; struct basilisk_value *v; uint64_t value = 0; bits256 txid;
txid = jbits256(valsobj,"txid");
vout = jint(valsobj,"vout");
if ( coin != 0 && basilisk_bitcoinavail(coin) != 0 )
{
if ( (coin->VALIDATENODE != 0 || coin->RELAYNODE != 0) && coinaddr != 0 && coinaddr[0] != 0 )
if ( (coin->VALIDATENODE != 0 || coin->RELAYNODE != 0) )//&& coinaddr != 0 && coinaddr[0] != 0 )
{
if ( iguana_unspentindfind(coin,coinaddr,0,0,&value,&height,txid,vout,coin->bundlescount,0) > 0 )
{
printf("bitcoinvalue found iguana\n");
Lptr->retstr = basilisk_valuestr(coin,coinaddr,value,height,txid,vout);
return(Lptr);
}
} else printf("unspentind couldnt find %s vout.%d\n",bits256_str(str,txid),vout);
} //else return(bitcoin_value(coin,txid,vout,coinaddr));
Lptr->retstr = clonestr("{\"error\":\"basilisk value missing address\"}");
return(Lptr);
@ -580,11 +580,10 @@ int32_t basilisk_voutvin_validate(struct iguana_info *coin,char *rawtx,uint64_t
return(-1);
}
int32_t basilisk_vins_validate(struct supernet_info *myinfo,struct iguana_info *coin,char *rawtx_retstr,uint64_t amount,uint64_t txfee)
int32_t basilisk_vins_validate(struct supernet_info *myinfo,struct iguana_info *coin,cJSON *retjson,uint64_t amount,uint64_t txfee)
{
cJSON *vins,*item,*argjson,*valobj,*retjson; uint64_t value,inputsum=0; int32_t i=-1,vout,retval=-1,numvins=0; bits256 txid; char *valstr;
printf("validate.(%s)\n",rawtx_retstr);
if ( (retjson= cJSON_Parse(rawtx_retstr)) != 0 )
cJSON *vins,*item,*argjson,*valobj; uint64_t value,inputsum=0; int32_t i=-1,vout,retval=-1,numvins=0; bits256 txid; char *valstr;
if ( retjson != 0 )
{
if ( (vins= jarray(&numvins,retjson,"vins")) != 0 )
{
@ -596,31 +595,38 @@ int32_t basilisk_vins_validate(struct supernet_info *myinfo,struct iguana_info *
argjson = cJSON_CreateObject();
jaddbits256(argjson,"txid",txid);
jaddnum(argjson,"vout",vout);
retval = -1;
if ( (valstr= basilisk_value(myinfo,coin,0,0,myinfo->myaddr.persistent,argjson,0)) != 0 )
{
printf("valstr.[%d] %s\n",i,valstr);
if ( (valobj= cJSON_Parse(valstr)) != 0 )
{
value = j64bits(retjson,"satoshis");
inputsum += value;
if ( jobj(valobj,"error") == 0 )
{
if ( (value= j64bits(retjson,"satoshis")) != 0 )
{
inputsum += value;
retval = 0;
}
}
free_json(valobj);
}
free(valstr);
}
if ( retval < 0 )
break;
}
}
if ( i != numvins || basilisk_voutvin_validate(coin,jstr(retjson,"rawtx"),inputsum,amount,txfee) < 0 )
{
retval = -1;
} else retval = 0;
free_json(retjson);
else retval = 0;
}
return(retval);
}
void *basilisk_bitcoinrawtx(struct basilisk_item *Lptr,struct supernet_info *myinfo,struct iguana_info *coin,char *remoteaddr,uint32_t basilisktag,int32_t timeoutmillis,cJSON *valsobj)
{
uint8_t buf[IGUANA_MAXSCRIPTSIZE]; int32_t oplen,offset,numsent,minconf,spendlen; cJSON *vins,*addresses,*txobj = 0; uint32_t locktime; char *retstr=0,*opreturn,*spendscriptstr,*changeaddr,*rawtx = 0; int64_t amount,txfee,burnamount; struct basilisk_item *ptr;
uint8_t buf[IGUANA_MAXSCRIPTSIZE]; int32_t oplen,offset,numsent,minconf,spendlen; cJSON *vins,*addresses,*txobj = 0; uint32_t locktime; char *opreturn,*spendscriptstr,*changeaddr,*rawtx = 0; int64_t amount,txfee,burnamount;
vins = 0;
changeaddr = jstr(valsobj,"changeaddr");
if ( (amount= j64bits(valsobj,"satoshis")) == 0 )

Loading…
Cancel
Save