Browse Source

test

release/v0.1
jl777 9 years ago
parent
commit
65398a42e9
  1. 2
      iguana/iguana777.h
  2. 2
      iguana/iguana_exchanges.c
  3. 13
      iguana/iguana_instantdex.c
  4. 98
      iguana/iguana_ramchain.c
  5. 4
      iguana/iguana_tx.c
  6. 4
      iguana/main.c
  7. 1
      includes/iguana_apideclares.h

2
iguana/iguana777.h

@ -688,7 +688,7 @@ void iguana_bundleiclear(struct iguana_info *coin,struct iguana_bundle *bp,int32
int32_t hcalc_bitsize(uint64_t x);
struct iguana_txid *iguana_txidfind(struct iguana_info *coin,int32_t *heightp,struct iguana_txid *tx,bits256 txid);
int32_t iguana_scriptgen(struct iguana_info *coin,int32_t *Mp,int32_t *nump,char *coinaddr,uint8_t *script,char *asmstr,uint8_t rmd160[20],uint8_t type,const struct vin_info *vp,int32_t txi);
int32_t iguana_ramchain_spendtxid(struct iguana_info *coin,bits256 *txidp,struct iguana_txid *T,int32_t numtxids,bits256 *X,int32_t numexternaltxids,struct iguana_spend *s);
int32_t iguana_ramchain_spendtxid(struct iguana_info *coin,uint32_t *unspentindp,bits256 *txidp,struct iguana_txid *T,int32_t numtxids,bits256 *X,int32_t numexternaltxids,struct iguana_spend *s);
struct iguana_info *iguana_coinselect();
void iguana_dedicatedloop(struct iguana_info *coin,struct iguana_peer *addr);
struct iguana_peer *iguana_peerslot(struct iguana_info *coin,uint64_t ipbits,int32_t forceflag);

2
iguana/iguana_exchanges.c

@ -946,7 +946,7 @@ void exchanges777_init(struct supernet_info *myinfo,cJSON *exchanges,int32_t sle
myinfo->tradingexchanges[myinfo->numexchanges++] = exchange;
}
}
if ( 0 )
if ( 1 )
{
argjson = cJSON_CreateObject();
for (i=0; i<sizeof(Exchange_funcs)/sizeof(*Exchange_funcs); i++)

13
iguana/iguana_instantdex.c

@ -1249,5 +1249,18 @@ THREE_STRINGS(atomic,claim,myorderid,otherid,txname)
}
}
THREE_STRINGS_AND_DOUBLE(tradebot,aveprice,comment,base,rel,basevolume)
{
double retvals[4],aveprice; cJSON *retjson = cJSON_CreateObject();
aveprice = instantdex_avehbla(myinfo,retvals,base,rel,basevolume);
jaddstr(retjson,"result","success");
jaddnum(retjson,"aveprice",aveprice);
jaddnum(retjson,"avebid",retvals[0]);
jaddnum(retjson,"bidvol",retvals[1]);
jaddnum(retjson,"aveask",retvals[2]);
jaddnum(retjson,"askvol",retvals[3]);
return(jprint(retjson,1));
}
#include "../includes/iguana_apiundefs.h"

98
iguana/iguana_ramchain.c

@ -254,22 +254,77 @@ struct iguana_pkhash *iguana_pkhashfind(struct iguana_info *coin,struct iguana_r
int32_t iguana_spentsinit(struct iguana_info *coin,struct iguana_Uextra *spents,struct iguana_bundle *bp,struct iguana_ramchain *ramchain)
{
//struct iguana_Uextra { uint32_t spendind; uint16_t hdrsi; } __attribute__((packed)); // unspentind
//struct iguana_spend { uint32_t spendtxidind; int16_t prevout; uint16_t tbd:14,external:1,diffsequence:1; } __attribute__((packed));
//struct iguana_unspent { uint64_t value; uint32_t txidind,pkind,prevunspentind; uint16_t hdrsi:12,type:4,vout; } __attribute__((packed));
int32_t i,n,max; struct iguana_spend *S;
int32_t spendind,n,max,m,prev_vout,height,hdrsi,errs,flag; uint32_t sequenceid,unspentind;
struct iguana_bundle *spentbp; char str[65];
struct iguana_spend *S,*s; struct iguana_txid *T,TX,*tp,*nextT; bits256 *X; bits256 prev_hash;
S = (void *)(long)((long)ramchain->H.data + ramchain->H.data->Soffset);
max = ramchain->H.unspentind;
n = ramchain->H.spendind;
for (i=0; i<n; i++)
{
X = (void *)(long)((long)ramchain->H.data + ramchain->H.data->Xoffset);
T = (void *)(long)((long)ramchain->H.data + ramchain->H.data->Toffset);
max = ramchain->H.data->numunspents;
n = ramchain->H.data->numspends;
nextT = &T[1];
for (spendind=1,errs=m=0; spendind<n; spendind++)
{
flag = 0;
hdrsi = bp->hdrsi;
s = &S[spendind];
if ( s->diffsequence == 0 )
sequenceid = 0xffffffff;
if ( s->prevout < 0 )
{
//printf("n.%d coinbase at spendind.%d firstvin.%d -> firstvout.%d -> unspentind\n",m,spendind,nextT->firstvin,nextT->firstvout);
nextT++;
m++;
continue;
unspentind = nextT->firstvout;
prev_vout = -1;
}
else
{
prev_vout = s->prevout;
iguana_ramchain_spendtxid(coin,&unspentind,&prev_hash,T,ramchain->H.data->numtxids,X,ramchain->H.data->numexternaltxids,s);
if ( unspentind == 0 )
{
if ( (tp= iguana_txidfind(coin,&height,&TX,prev_hash)) != 0 )
{
unspentind = TX.firstvout + ((prev_vout > 0) ? prev_vout : 0);
hdrsi = height / coin->chain->bundlesize;
//printf("height.%d firstvout.%d prev.%d ->U%d\n",height,TX.firstvout,prev_vout,unspentind);
}
else
{
printf("cant find prev_hash.(%s) for bp.[%d] spendind.%d\n",bits256_str(str,prev_hash),bp->hdrsi,spendind);
}
} else hdrsi = bp->hdrsi;
}
if ( hdrsi > bp->hdrsi || (spentbp= coin->bundles[hdrsi]) == 0 )
printf("illegal hdrsi.%d when [%d] spentbp.%p\n",hdrsi,bp->hdrsi,spentbp), getchar();
else if ( spentbp->ramchain.spents[unspentind].spendind != 0 || hdrsi < 0 )
printf("DOUBLE SPEND? U%d %p bp.[%d] unspentind.%u already has %u, no room for %u\n",unspentind,&spentbp->ramchain.spents[unspentind],hdrsi,unspentind,spentbp->ramchain.spents[unspentind].spendind,spendind), getchar();
else if ( unspentind == 0 || unspentind >= spentbp->ramchain.H.data->numunspents )
printf("illegal unspentind.%d vs max.%d spentbp.%p[%d]\n",unspentind,spentbp->ramchain.H.data->numunspents,spentbp,hdrsi), getchar();
else
{
spentbp->ramchain.spents[unspentind].spendind = spendind;
spentbp->ramchain.spents[unspentind].hdrsi = bp->hdrsi;
//printf("%p bp.[%d] U%d <- S%d.[%d] [%p %p %p]\n",&spentbp->ramchain.spents[unspentind],hdrsi,unspentind,spendind,bp->hdrsi,coin->bundles[0],coin->bundles[1],coin->bundles[2]);
flag = 1;
}
if ( flag == 0 )
errs++;
}
return(0);
printf("processed %d spendinds for bp.[%d] -> errs.%d\n",spendind,bp->hdrsi,errs);
return(-errs);
}
// if file exists and is valid, load and then process only the incremental
long iguana_spentsfile(struct iguana_info *coin,int32_t n)
{
int32_t i,iter,allocated = 0; long filesize,total,count; struct iguana_Uextra *spents = 0; struct iguana_ramchain *ramchain; char fname[1024]; struct iguana_bundle *bp;
int32_t i,iter,allocated = 0; long filesize,total,count; struct iguana_Uextra *spents = 0; struct iguana_ramchain *ramchain; char fname[1024]; struct iguana_bundle *bp; FILE *fp;
fname[0] = 0;
for (total=iter=0; iter<2; iter++)
{
for (count=i=0; i<n; i++)
@ -280,13 +335,14 @@ long iguana_spentsfile(struct iguana_info *coin,int32_t n)
if ( iter == 1 )
{
ramchain->spents = &spents[count];
//printf("bp.[%d] count.%ld %p\n",i,count,ramchain->spents);
if ( allocated != 0 && iguana_spentsinit(coin,spents,bp,ramchain) < 0 )
{
printf("error initializing spents bp.%d\n",i);
exit(-1);
}
}
count += ramchain->H.unspentind;
count += ramchain->H.data->numunspents;
} else return(-1);
}
sprintf(fname,"DB/%s/spents_%d.%ld",coin->symbol,n,count);
@ -300,6 +356,11 @@ long iguana_spentsfile(struct iguana_info *coin,int32_t n)
else if ( total != count )
printf("%s total.%ld != count.%ld\n",fname,total,count);
}
if ( allocated != 0 && fname[0] != 0 && (fp= fopen(fname,"wb")) != 0 )
{
fwrite(spents,total,sizeof(*spents),fp);
fclose(fp);
}
return(total);
}
@ -337,6 +398,7 @@ int32_t iguana_pkhasharray(struct iguana_info *coin,int64_t *totalp,struct iguan
P[n].firstunspentind = lastunspentind;
P[n].flags = m;
total += balance;
// use spents to find ! intersections(unspendinds & spents)
n++;
}
}
@ -561,16 +623,17 @@ uint32_t iguana_ramchain_addspend256(struct iguana_info *coin,RAMCHAIN_FUNC,bits
return(spendind);
}
int32_t iguana_ramchain_spendtxid(struct iguana_info *coin,bits256 *txidp,struct iguana_txid *T,int32_t numtxids,bits256 *X,int32_t numexternaltxids,struct iguana_spend *s)
int32_t iguana_ramchain_spendtxid(struct iguana_info *coin,uint32_t *unspentindp,bits256 *txidp,struct iguana_txid *T,int32_t numtxids,bits256 *X,int32_t numexternaltxids,struct iguana_spend *s)
{
uint32_t ind,external;
*unspentindp = 0;
memset(txidp,0,sizeof(*txidp));
//printf("s.%p ramchaintxid vout.%x spendtxidind.%d numexternals.%d isext.%d numspendinds.%d\n",s,s->vout,s->spendtxidind,ramchain->numexternaltxids,s->external,ramchain->numspends);
if ( s->prevout < 0 )
return(-1);
ind = s->spendtxidind;
external = (ind >> 31) & 1;
ind &= ~(1 << 31);
//printf("s.%p ramchaintxid vout.%x spendtxidind.%d isext.%d ext.%d ind.%d\n",s,s->prevout,s->spendtxidind,s->external,external,ind);
if ( s->prevout < 0 )
return(-1);
if ( s->external != 0 && s->external == external && ind < numexternaltxids )
{
//printf("ind.%d externalind.%d X[%d]\n",ind,ramchain->externalind,ramchain->H.data->numexternaltxids);
@ -580,6 +643,7 @@ int32_t iguana_ramchain_spendtxid(struct iguana_info *coin,bits256 *txidp,struct
else if ( s->external == 0 && s->external == external && ind < numtxids )
{
*txidp = T[ind].txid;
*unspentindp = T[ind].firstvout + s->prevout;
return(s->prevout);
}
return(-2);
@ -680,14 +744,6 @@ uint32_t iguana_ramchain_addspend(struct iguana_info *coin,RAMCHAIN_FUNC,bits256
//if ( P2[pkind].firstspendind == 0 )
// P2[pkind].firstspendind = spendind;
}
/*if ( unspentind != 0 )
{
if ( coin->U2[hdris][unspentind].spendind == 0 )
{
coin->U2[hdris][unspentind].spendind = spendind;
coin->U2[hdris][unspentind].hdris = hdrsi;
}
}*/
return(spendind);
}

4
iguana/iguana_tx.c

@ -24,7 +24,7 @@
void iguana_vinset(struct iguana_info *coin,int32_t height,struct iguana_msgvin *vin,struct iguana_txid *tx,int32_t i)
{
struct iguana_spend *s,*S; uint32_t spendind; struct iguana_bundle *bp;
struct iguana_spend *s,*S; uint32_t spendind,unspentind; struct iguana_bundle *bp;
struct iguana_ramchaindata *rdata; struct iguana_txid *T; bits256 *X;
memset(vin,0,sizeof(*vin));
if ( height >= 0 && height < coin->chain->bundlesize*coin->bundlescount && (bp= coin->bundles[height / coin->chain->bundlesize]) != 0 && (rdata= bp->ramchain.H.data) != 0 )
@ -37,7 +37,7 @@ void iguana_vinset(struct iguana_info *coin,int32_t height,struct iguana_msgvin
if ( s->diffsequence == 0 )
vin->sequence = 0xffffffff;
vin->prev_vout = s->prevout;
iguana_ramchain_spendtxid(coin,&vin->prev_hash,T,rdata->numtxids,X,rdata->numexternaltxids,s);
iguana_ramchain_spendtxid(coin,&unspentind,&vin->prev_hash,T,rdata->numtxids,X,rdata->numexternaltxids,s);
}
}

4
iguana/main.c

@ -1139,14 +1139,14 @@ void iguana_main(void *arg)
{
int32_t i,n; int64_t total; char *coinaddr; struct iguana_pkhash *P; struct iguana_info *coin; uint8_t rmd160[20],addrtype;
coin = iguana_coinfind("BTCD");
if ( 0 && coin != 0 )
if ( 1 && coin != 0 )
{
getchar();
for (i=0; i<coin->bundlescount; i++)
if ( coin->bundles[i] == 0 )
break;
if ( i > 0 )
iguana_spentsfile(coin,i);
getchar();
coinaddr = "RUZ9AKxy6J2okcBd1PZm4YH6atmPwqV4bo";
bitcoin_addr2rmd160(&addrtype,rmd160,coinaddr);
P = calloc(coin->bundlescount,sizeof(*P));

1
includes/iguana_apideclares.h

@ -60,6 +60,7 @@ THREE_STRINGS(atomic,claim,myorderid,otherid,txname);
//TWOSTRINGS_AND_TWOHASHES_AND_TWOINTS(InstantDEX,accept,reference,message,basetxid,reltxid,duration,flags);
//TWOSTRINGS_AND_TWOHASHES_AND_TWOINTS(InstantDEX,confirm,reference,message,basetxid,reltxid,baseheight,relheight);
THREE_STRINGS_AND_DOUBLE(tradebot,aveprice,comment,base,rel,basevolume);
THREE_STRINGS_AND_DOUBLE(tradebot,monitor,exchange,base,rel,commission);
STRING_AND_DOUBLE(tradebot,monitorall,exchange,commission);
THREE_STRINGS(tradebot,unmonitor,exchange,base,rel);

Loading…
Cancel
Save