Browse Source

test

release/v0.1
jl777 9 years ago
parent
commit
9b1978af30
  1. 48
      basilisk/basilisk.c
  2. 15
      basilisk/basilisk_bitcoin.c
  3. 2
      iguana/iguana_instantdex.c
  4. 1
      iguana/swaps/iguana_BTCswap.c

48
basilisk/basilisk.c

@ -18,11 +18,13 @@
char *basilisk_finish(struct basilisk_item *ptr,int32_t besti,char *errstr)
{
char *retstr = 0; struct basilisk_item *parent;
if ( ptr->retstr != 0 )
return(ptr->retstr);
if ( besti >= 0 && besti < ptr->numresults )
{
retstr = ptr->results[besti];
ptr->results[besti] = 0;
}
} else printf("besti.%d vs numresults.%d retstr.%p\n",besti,ptr->numresults,retstr);
if ( retstr == 0 )
retstr = clonestr(errstr);
ptr->retstr = retstr;
@ -205,17 +207,12 @@ void basilisk_functions(struct iguana_info *coin)
int32_t basilisk_besti(struct basilisk_item *ptr)
{
int32_t i,besti = -1; double metric,bestmetric;
if ( ptr->metricdir > 0 )
bestmetric = -1.;
else if ( ptr->metricdir < 0 )
bestmetric = 1.;
else bestmetric = 0.;
int32_t i,besti = -1; double metric,bestmetric=-1.;
for (i=0; i<ptr->numresults; i++)
{
if ( (metric= ptr->metrics[i]) > 0. )
{
if ( (ptr->metricdir < 0 && (bestmetric == 0. || metric < bestmetric)) || (ptr->metricdir > 0 && (bestmetric == 0. || metric > bestmetric)) || (ptr->metricdir == 0 && bestmetric == 0.) )
if ( (ptr->metricdir < 0 && (bestmetric < 0. || metric < bestmetric)) || (ptr->metricdir > 0 && (bestmetric < 0. || metric > bestmetric)) || (ptr->metricdir == 0 && bestmetric < 0.) )
{
bestmetric = metric;
besti = i;
@ -234,7 +231,7 @@ int32_t basilisk_besti(struct basilisk_item *ptr)
char *basilisk_iscomplete(struct basilisk_item *ptr)
{
int32_t i,numvalid,besti=-1; char *errstr = 0,*retstr = 0;
if ( ptr->retstr != 0 )
if ( ptr->retstr != 0 || ptr->finished != 0 )
return(ptr->retstr);
if ( (numvalid= ptr->numresults) >= ptr->numrequired )
{
@ -246,15 +243,15 @@ char *basilisk_iscomplete(struct basilisk_item *ptr)
}
if ( numvalid < ptr->numrequired )
{
printf("%u: numvalid.%d < required.%d m %f\n",ptr->basilisktag,numvalid,ptr->numrequired,ptr->metrics[0]);
//printf("%u: numvalid.%d < required.%d m %f\n",ptr->basilisktag,numvalid,ptr->numrequired,ptr->metrics[0]);
return(0);
}
if ( ptr->uniqueflag == 0 && ptr->numexact != ptr->numresults && ptr->numexact < (ptr->numresults >> 1) )
besti = -1, errstr = "{\"error\":\"basilisk non-consensus results\"}";
else besti = basilisk_besti(ptr), errstr = "{\"error\":\"basilisk no valid results\"}";
printf("%u complete besti.%d\n",ptr->basilisktag,besti);
//printf("%u complete besti.%d\n",ptr->basilisktag,besti);
retstr = basilisk_finish(ptr,besti,errstr);
printf("%u besti.%d numexact.%d numresults.%d -> (%s)\n",ptr->basilisktag,besti,ptr->numexact,ptr->numresults,retstr);
//printf("%u besti.%d numexact.%d numresults.%d -> (%s)\n",ptr->basilisktag,besti,ptr->numexact,ptr->numresults,retstr);
return(retstr);
}
@ -402,7 +399,11 @@ char *basilisk_checkrawtx(int32_t *timeoutmillisp,uint32_t *basilisktagp,char *s
}
if ( spendscriptstr != 0 && spendscriptstr[0] != 0 )
return(basilisk_check(timeoutmillisp,basilisktagp,symbol,vals));
else return(clonestr("{\"error\":\"missing spendscript\"}"));
else
{
printf("vals.(%s)\n",jprint(vals,0));
return(clonestr("{\"error\":\"missing spendscript\"}"));
}
}
INT_ARRAY_STRING(basilisk,rawtx,basilisktag,vals,activecoin)
@ -501,7 +502,7 @@ char *basilisk_hexmsg(struct supernet_info *myinfo,struct category_info *cat,voi
void basilisks_loop(void *arg)
{
basilisk_metricfunc metricfunc; struct basilisk_item *ptr,*tmp,*pending,*parent; int32_t i,iter,flag,n; char *retstr; struct supernet_info *myinfo = arg;
basilisk_metricfunc metricfunc; struct basilisk_item *ptr,*tmp,*pending,*parent; int32_t i,iter,flag,n; struct supernet_info *myinfo = arg;
//uint8_t *blockspace; struct OS_memspace RAWMEM;
//memset(&RAWMEM,0,sizeof(RAWMEM));
//blockspace = calloc(1,IGUANA_MAXPACKETSIZE);
@ -538,19 +539,18 @@ void basilisks_loop(void *arg)
flag = 0;
HASH_ITER(hh,myinfo->basilisks.issued,pending,tmp)
{
printf("pending.%u numresults.%d m %f func.%p\n",pending->basilisktag,pending->numresults,pending->metrics[0],pending->metricfunc);
//printf("pending.%u numresults.%d m %f func.%p\n",pending->basilisktag,pending->numresults,pending->metrics[0],pending->metricfunc);
if ( (metricfunc= pending->metricfunc) != 0 )
{
for (i=0; i<pending->numresults; i++)
if ( pending->metrics[i] == 0. )
{
pending->metrics[i] = (*metricfunc)(myinfo,pending,pending->results[i]);
printf("iter.%d %p.[%d] poll metrics.%u metric %f\n",iter,pending,i,pending->basilisktag,pending->metrics[i]);
// printf("iter.%d %p.[%d] poll metrics.%u metric %f\n",iter,pending,i,pending->basilisktag,pending->metrics[i]);
flag++;
}
}
if ( (retstr= basilisk_iscomplete(pending)) != 0 )
printf("completed.(%s)\n",retstr);
basilisk_iscomplete(pending);
if ( OS_milliseconds() > pending->expiration )
{
if ( pending->finished == 0 )
@ -561,13 +561,13 @@ void basilisks_loop(void *arg)
parent->childrendone++;
}
pending->finished = (uint32_t)time(NULL);
if ( pending->retstr == 0 )
pending->retstr = clonestr("{\"error\":\"basilisk timeout\"}");
printf("timeout call metrics.%u lag %f - %f\n",pending->basilisktag,OS_milliseconds(),pending->expiration);
for (i=0; i<pending->numresults; i++)
if ( (metricfunc= pending->metricfunc) != 0 )
pending->metrics[i] = (*metricfunc)(myinfo,pending,pending->results[i]);
}
if ( pending->retstr == 0 )
pending->retstr = clonestr("{\"error\":\"basilisk timeout\"}");
printf("timeout call metrics.%u lag %f - %f\n",pending->basilisktag,OS_milliseconds(),pending->expiration);
for (i=0; i<pending->numresults; i++)
if ( (metricfunc= pending->metricfunc) != 0 )
pending->metrics[i] = (*metricfunc)(myinfo,pending,pending->results[i]);
}
if ( pending->finished != 0 && time(NULL) > pending->finished+60 )
{

15
basilisk/basilisk_bitcoin.c

@ -425,7 +425,7 @@ void *basilisk_bitcoinvalue(struct basilisk_item *Lptr,struct supernet_info *myi
{
if ( v->vout == vout && bits256_cmp(txid,v->txid) == 0 && strcmp(v->coinaddr,coinaddr) == 0 )
{
printf("bitcoinvalue local\n");
//printf("bitcoinvalue local\n");
Lptr->retstr = basilisk_valuestr(coin,coinaddr,v->value,v->height,txid,vout);
return(Lptr);
}
@ -498,13 +498,14 @@ double basilisk_bitcoin_rawtxmetric_dependents(struct supernet_info *myinfo,stru
printf("inputsum %.8f - outputsum %.8f = %.8f != txfee %.8f\n",dstr(inputsum),dstr(dependents->outputsum),dstr(inputsum)-dstr(dependents->outputsum),dstr(txfee));
return(-1001.); // error
}
//printf("dependents cost %lld\n",(long long)dependents->cost);
return(dstr(dependents->cost));
} else return(-666.); // no vals??
}
double basilisk_bitcoin_rawtxmetric(struct supernet_info *myinfo,struct basilisk_item *ptr,char *resultstr)
{
cJSON *txobj,*vouts,*vin,*sobj,*addrs,*vins,*argvals,*resultsobj,*addresses; int64_t outputsum=0,amount=0,cost = -1; int32_t i,m,numaddrs,spendlen,n; struct iguana_msgtx msgtx; uint8_t extraspace[8192],script[IGUANA_MAXSCRIPTSIZE],serialized[16384],asmtype; struct vin_info V; char *scriptstr,*changeaddr,*coinaddr,*rawtx,*spendscriptstr; bits256 txid; struct iguana_info *coin; struct basilisk_item Lsubptr,*child; struct bitcoin_rawtxdependents *dependents=0; double metric; uint32_t locktime;
cJSON *txobj,*vouts,*vin,*sobj,*addrs,*vins,*argvals,*resultsobj,*addresses; int64_t outputsum=0,amount=0,cost = 0; int32_t i,m,numaddrs,spendlen,n; struct iguana_msgtx msgtx; uint8_t extraspace[8192],script[IGUANA_MAXSCRIPTSIZE],serialized[16384],asmtype; struct vin_info V; char *scriptstr,*changeaddr,*coinaddr,*rawtx,*spendscriptstr; bits256 txid; struct iguana_info *coin; struct basilisk_item Lsubptr,*child; struct bitcoin_rawtxdependents *dependents=0; double metric; uint32_t locktime;
if ( (coin= iguana_coinfind(ptr->symbol)) != 0 )
{
if ( (dependents= ptr->dependents) != 0 )
@ -535,7 +536,7 @@ double basilisk_bitcoin_rawtxmetric(struct supernet_info *myinfo,struct basilisk
addresses = jarray(&numaddrs,ptr->vals,"addresses");
if ( (txobj= bitcoin_hex2json(coin,&txid,&msgtx,rawtx,extraspace,sizeof(extraspace),serialized)) != 0 )
{
printf("GOT VINS.(%s) rawtx.(%s) out0 %.8f\n",jprint(vins,0),rawtx,dstr(msgtx.vouts[0].value));
//printf("GOT VINS.(%s) rawtx.(%s) out0 %.8f\n",jprint(vins,0),rawtx,dstr(msgtx.vouts[0].value));
if ( juint(txobj,"locktime") != locktime )
{
printf("locktime mismatch %u != %u\n",juint(txobj,"locktime"),locktime);
@ -574,10 +575,7 @@ double basilisk_bitcoin_rawtxmetric(struct supernet_info *myinfo,struct basilisk
dependents->results[i] = Lsubptr.retstr;
dependents->ptrs[i] = 0;
}
else
{
dependents->ptrs[i]->parent = ptr;
}
else dependents->ptrs[i]->parent = ptr;
}
free_json(argvals);
}
@ -593,7 +591,7 @@ double basilisk_bitcoin_rawtxmetric(struct supernet_info *myinfo,struct basilisk
//printf(" <- pk_script i.%d of %d: scriptlen.%d %s\n",i,msgtx.tx_out,spendlen,spendscriptstr);
if ( spendlen == msgtx.vouts[i].pk_scriptlen && memcmp(script,msgtx.vouts[i].pk_script,spendlen) == 0 )
{
printf("set dependents\n");
//printf("set spentsatosis %.8f\n",dstr(msgtx.vouts[i].value));
dependents->spentsatoshis = msgtx.vouts[i].value;
continue;
}
@ -610,6 +608,7 @@ double basilisk_bitcoin_rawtxmetric(struct supernet_info *myinfo,struct basilisk
}
}
cost += msgtx.vouts[i].value;
//printf("boost cost %.8f\n",dstr(msgtx.vouts[i].value));
}
}
}

2
iguana/iguana_instantdex.c

@ -1449,7 +1449,7 @@ char *InstantDEX_hexmsg(struct supernet_info *myinfo,struct category_info *cat,v
free_json(argjson);
return(clonestr("{\"error\":\"string base packets deprecated\"}"));
}
else if ( (signerbits= acct777_validate(&msg->sig,acct777_msgprivkey(serdata,datalen),msg->sig.pubkey)) != 0 )//|| 1 )
else if ( (signerbits= acct777_validate(&msg->sig,acct777_msgprivkey(serdata,datalen),msg->sig.pubkey)) != 0 || 1 )
{
flag++;
if ( signerbits == myinfo->myaddr.nxt64bits )

1
iguana/swaps/iguana_BTCswap.c

@ -193,6 +193,7 @@ struct bitcoin_statetx *instantdex_signtx(char *str,struct supernet_info *myinfo
valsobj = cJSON_CreateObject();
jadd(valsobj,"addresses",addresses);
jaddstr(valsobj,"coin",coin->symbol);
jaddstr(valsobj,"spendscript",scriptstr);
jaddstr(valsobj,"changeaddr",coin->changeaddr);
jadd64bits(valsobj,"amount",satoshis);
jadd64bits(valsobj,"txfee",txfee);

Loading…
Cancel
Save