Browse Source

test

release/v0.1
jl777 9 years ago
parent
commit
424474d0da
  1. 181
      deprecated/obsolete.h
  2. 3
      iguana/iguana777.h
  3. 1
      iguana/iguana_init.c
  4. 23
      iguana/iguana_ramchain.c
  5. 184
      iguana/iguana_scripts.c

181
deprecated/obsolete.h

@ -13944,4 +13944,185 @@ len = 0;
}
}*/
/*void iguana_bundlescript(struct iguana_info *coin,uint32_t offset,struct iguana_bundle *bp,uint32_t ind,uint8_t *spendscript,int32_t spendlen)
{
long size = sizeof(offset) + sizeof(ind); uint32_t *ptr;
if ( bp->numscriptsmaps >= bp->maxscriptsmaps )
{
bp->scriptsmap = realloc(bp->scriptsmap,(1000+bp->maxscriptsmaps) * (sizeof(offset) + sizeof(ind)));
bp->maxscriptsmaps += 1000;
}
ptr = (void *)((long)bp->scriptsmap + bp->numscriptsmaps*size);
ptr[0] = ind;
ptr[1] = offset;
bp->numscriptsmaps++;
}*/
uint32_t iguana_scriptstableadd(struct iguana_info *coin,int32_t spendflag,uint32_t fpos,uint8_t *script,uint16_t scriptlen)
{
struct scriptinfo *ptr;
HASH_FIND(hh,coin->scriptstable[spendflag],script,scriptlen,ptr);
if ( ptr == 0 )
{
ptr = mycalloc('w',1,sizeof(*ptr) + scriptlen);
ptr->fpos = fpos;
ptr->scriptlen = scriptlen;
memcpy(ptr->script,script,scriptlen);
HASH_ADD(hh,coin->scriptstable[spendflag],script,scriptlen,ptr);
}
return(fpos);
}
uint32_t iguana_scriptstablefind(struct iguana_info *coin,int32_t spendflag,uint8_t *script,int32_t scriptlen)
{
struct scriptinfo *ptr;
HASH_FIND(hh,coin->scriptstable[spendflag],script,scriptlen,ptr);
if ( ptr != 0 )
return(ptr->fpos);
else return(0);
}
long iguana_rwscript(struct iguana_info *coin,int32_t rwflag,void *fileptr,long offset,long filesize,FILE *fp,struct iguana_bundle *bp,uint8_t **scriptptrp,int32_t *lenp,int32_t hdrsi,uint32_t ind,int32_t spendflag)
{
long scriptpos; struct scriptdata data; uint8_t *script = *scriptptrp;
if ( spendflag == 0 && (scriptpos= iguana_scriptstablefind(coin,spendflag,script,*lenp)) != 0 )
return(scriptpos);
memset(&data,0,sizeof(data));
if ( rwflag != 0 && fp != 0 && fileptr == 0 )
{
scriptpos = ftell(fp);
data.ind = ind, data.spendflag = spendflag;
data.hdrsi = hdrsi;
data.scriptlen = *lenp;
if ( fwrite(&data,1,sizeof(data),fp) != sizeof(data) )
return(-1);
if ( fwrite(script,1,data.scriptlen,fp) != data.scriptlen )
return(-1);
offset = (uint32_t)ftell(fp);
//printf("spend.%d filesize.%ld wrote.h%d u%d len.%d [%ld,%ld) crc.%08x\n",spendflag,coin->scriptsfilesize[spendflag],hdrsi,ind,data.scriptlen,scriptpos,ftell(fp),calc_crc32(0,script,data.scriptlen));
}
else if ( rwflag == 0 && fp == 0 && fileptr != 0 )
{
scriptpos = offset;
if ( offset+sizeof(data) <= filesize )
{
memcpy(&data,(void *)((long)fileptr + offset),sizeof(data));
if ( data.scriptlen > 0 && data.scriptlen < *lenp && offset+sizeof(data)+data.scriptlen <= filesize )
{
if ( data.scriptlen > 0 )
{
*scriptptrp = script = (void *)((long)fileptr + offset);
offset += data.scriptlen + sizeof(data);
if ( data.hdrsi < coin->bundlescount )
bp = coin->bundles[data.hdrsi];
else printf("illegal hdrsi.%d/%d\n",data.hdrsi,coin->bundlescount);
} else printf("illegal scriptlen %d\n",data.scriptlen);
//printf("hdrsi.%d loaded script.%d %u s%d\n",data.hdrsi,data.scriptlen,data.ind,data.spendflag);
}
else if ( data.scriptlen > 0 )
{
printf("spendlen overflow.%d vs %d\n",data.scriptlen,*lenp);
return(-1);
}
}
else
{
printf("error reading from %ld\n",scriptpos);
return(-1);
}
//printf("hdrsi.%d scriptlen.%d\n",data.hdrsi,data.scriptlen);
*lenp = data.scriptlen;
}
if ( bp != 0 )
{
//if ( spendflag == 0 )
iguana_scriptstableadd(coin,spendflag,(uint32_t)scriptpos,script,*lenp);
}
else if ( rwflag == 0 )
{
printf("null bp for iguana_rwscript hdrsi.%d/%d\n",data.hdrsi,coin->bundlescount);
return(-1);
}
return(offset);
}
long iguana_initscripts(struct iguana_info *coin)
{
long fpos=0,offset = 0; uint8_t scriptdata[IGUANA_MAXSCRIPTSIZE],*scriptptr; int32_t spendflag,size,n=0; struct scriptdata script;
for (spendflag=0; spendflag<2; spendflag++)
{
portable_mutex_lock(&coin->scripts_mutex[spendflag]);
sprintf(coin->scriptsfname[spendflag],"tmp/%s/%sscripts",coin->symbol,spendflag==0?"":"sig"), OS_portable_path(coin->scriptsfname[spendflag]);
printf("scripts fname.(%s)\n",coin->scriptsfname[spendflag]);
if ( (coin->scriptsptr[spendflag]= OS_mapfile(coin->scriptsfname[spendflag],&coin->scriptsfilesize[spendflag],0)) == 0 )
{
coin->scriptsfp[spendflag] = fopen(coin->scriptsfname[spendflag],"wb");
memset(&script,0,sizeof(script));
fwrite(&script,1,sizeof(script),coin->scriptsfp[spendflag]);
}
else
{
while ( 1 )
{
size = sizeof(scriptdata);
scriptptr = scriptdata;
if ( (offset= iguana_rwscript(coin,0,coin->scriptsptr[spendflag],offset,coin->scriptsfilesize[spendflag],0,0,&scriptptr,&size,0,0,spendflag)) < 0 )
break;
else fpos = offset;
n++;
}
coin->scriptsfp[spendflag] = fopen(coin->scriptsfname[spendflag],"ab");
portable_mutex_unlock(&coin->scripts_mutex[spendflag]);
printf("initialized %d scripts, fpos %ld\n",n,fpos);
return(offset);
}
portable_mutex_unlock(&coin->scripts_mutex[spendflag]);
}
return(-1);
}
uint32_t iguana_scriptsave(struct iguana_info *coin,struct iguana_bundle *bp,uint32_t ind,int32_t spendflag,uint8_t *script,int32_t scriptlen)
{
FILE *fp; long fpos = 0;
if ( scriptlen > 0 && (fp= coin->scriptsfp[spendflag]) != 0 )
{
portable_mutex_lock(&coin->scripts_mutex[spendflag]);
fpos = ftell(fp);
if ( iguana_rwscript(coin,1,0,0,0,fp,bp,&script,&scriptlen,bp->hdrsi,ind,spendflag) < 0 )
{
fseek(fp,fpos,SEEK_SET);
fpos = -1;
printf("error saving script at %ld\n",fpos);
} else fflush(fp);
portable_mutex_unlock(&coin->scripts_mutex[spendflag]);
} else printf("cant scriptsave.%d to (%s).%p scriptlen.%d\n",spendflag,coin->scriptsfname[spendflag],coin->scriptsfp[spendflag],scriptlen);
return((uint32_t)fpos);
}
long iguana_scriptadd(struct iguana_info *coin,struct iguana_bundle *bp,uint32_t unspentind,int32_t type,uint8_t *spendscript,int32_t spendlen,uint8_t rmd160[20],int32_t vout)
{
static long total,saved;
int32_t scriptlen; char asmstr[IGUANA_MAXSCRIPTSIZE*2+1]; uint8_t script[IGUANA_MAXSCRIPTSIZE]; long fpos=0; struct vin_info V,*vp = &V;
if ( spendlen == 0 )
{
printf("null script?\n");
getchar();
return(0);
}
memset(vp,0,sizeof(*vp));
asmstr[0] = 0;
total++;
scriptlen = iguana_scriptgen(coin,&vp->M,&vp->N,vp->coinaddr,script,asmstr,rmd160,type,(const struct vin_info *)vp,vout);
if ( scriptlen == spendlen && memcmp(script,spendscript,scriptlen) == 0 )
return(0);
else
{
saved++;
//if ( (saved % 1000) == 0 )
printf("add type.%d scriptlen.%d fpos.%ld saved.%ld/%ld\n",type,spendlen,coin->scriptsfp!=0?ftell(coin->scriptsfp[0]):-1,saved,total);
fpos = iguana_scriptsave(coin,bp,unspentind,0,spendscript,spendlen);
}
return(fpos);
}
#endif

3
iguana/iguana777.h

@ -778,10 +778,7 @@ uint8_t *iguana_rmdarray(struct iguana_info *coin,int32_t *numrmdsp,cJSON *array
void iguana_unspents(struct supernet_info *myinfo,struct iguana_info *coin,cJSON *array,int32_t minconf,int32_t maxconf,uint8_t *rmdarray,int32_t numrmds);
uint8_t *iguana_walletrmds(struct supernet_info *myinfo,struct iguana_info *coin,int32_t *numrmdsp);
char *iguana_bundleaddrs(struct iguana_info *coin,int32_t hdrsi);
long iguana_scriptadd(struct iguana_info *coin,struct iguana_bundle *bp,uint32_t unspentind,int32_t type,uint8_t *spendscript,int32_t spendlen,uint8_t rmd160[20],int32_t vout);
uint32_t iguana_sparseaddpk(uint8_t *bits,int32_t width,uint32_t tablesize,uint8_t rmd160[20],struct iguana_pkhash *P,uint32_t pkind);
long iguana_initscripts(struct iguana_info *coin);
uint32_t iguana_scriptsave(struct iguana_info *coin,struct iguana_bundle *bp,uint32_t ind,int32_t spendflag,uint8_t *script,int32_t scriptlen);
int32_t iguana_vinscriptparse(struct iguana_info *coin,struct vin_info *vp,uint32_t *sigsizep,uint32_t *pubkeysizep,uint32_t *p2shsizep,uint32_t *suffixp,uint8_t *vinscript,int32_t scriptlen);
void iguana_parsebuf(struct iguana_info *coin,struct iguana_peer *addr,struct iguana_msghdr *H,uint8_t *buf,int32_t len);

1
iguana/iguana_init.c

@ -304,7 +304,6 @@ void iguana_parseline(struct iguana_info *coin,int32_t iter,FILE *fp)
{
//iguana_spentsfile(coin,i);
}
iguana_initscripts(coin);
}
}

23
iguana/iguana_ramchain.c

@ -428,12 +428,15 @@ uint32_t iguana_ramchain_addunspent20(struct iguana_info *coin,RAMCHAIN_FUNC,uin
u->scriptfpos = (uint32_t)iguana_scriptadd(coin,bp,unspentind,type,script,scriptlen,rmd160,vout);
}
}*/
if ( ramchain->H.scriptoffset == 0 )
ramchain->H.scriptoffset++;
u->scriptoffset = ramchain->H.scriptoffset;
scriptptr = &Kspace[u->scriptoffset];//malloc(scriptlen);
ramchain->H.scriptoffset += scriptlen;
memcpy(scriptptr,script,scriptlen);
if ( type != 0 ) // IGUANA_SCRIPT_NULL
{
if ( ramchain->H.scriptoffset == 0 )
ramchain->H.scriptoffset++;
u->scriptoffset = ramchain->H.scriptoffset;
scriptptr = &Kspace[u->scriptoffset];//malloc(scriptlen);
ramchain->H.scriptoffset += scriptlen;
memcpy(scriptptr,script,scriptlen);
}
} else u->scriptoffset = 0;
u->txidind = ramchain->H.txidind;
memcpy(u->rmd160,rmd160,sizeof(u->rmd160));
@ -909,10 +912,10 @@ uint32_t iguana_ramchain_addspend(struct iguana_info *coin,RAMCHAIN_FUNC,bits256
for (i=0; i<checklen; i++)
printf("%02x",_script[i]);
printf(" decoded\n");
for (i=0; i<checklen; i++)
for (i=0; i<vinscriptlen; i++)
printf("%02x",vinscript[i]);
printf(" vinscript\n");
printf("addspend: vinscript expand error (%d vs %d) %d seq.(%u %u)\n",checklen,vinscriptlen,memcmp(_script,vinscript,vinscriptlen),sequence,checksequenceid);
printf("addspend: vinscript expand error (%d vs %d) %d seq.(%x %x)\n",checklen,vinscriptlen,memcmp(_script,vinscript,vinscriptlen),sequence,checksequenceid);
}
//ramchain->H.scriptoffset += metalen;
}
@ -2038,8 +2041,8 @@ int32_t iguana_scriptspaceraw(struct iguana_info *coin,int32_t *scriptspacep,int
int32_t iguana_ramchain_scriptspace(struct iguana_info *coin,int32_t *sigspacep,int32_t *pubkeyspacep,struct iguana_ramchain *ramchain)
{
RAMCHAIN_DECLARE;
int32_t j,scriptlen;
uint32_t sequence,p2shspace,altspace,sigspace,pubkeyspace,spendind,unspentind,p2shsize,pubkeysize,sigsize,scriptspace,suffixlen; struct vin_info V; //uint8_t _script[IGUANA_MAXSCRIPTSIZE];
int32_t j,scriptlen; struct vin_info V;
uint32_t sequence,p2shspace,altspace,sigspace,pubkeyspace,spendind,unspentind,p2shsize,pubkeysize,sigsize,scriptspace,suffixlen;
struct iguana_txid *tx; struct iguana_ramchaindata *rdata; uint8_t *scriptdata;
_iguana_ramchain_setptrs(RAMCHAIN_PTRS,ramchain->H.data);
*sigspacep = *pubkeyspacep = altspace = 0;

184
iguana/iguana_scripts.c

@ -694,7 +694,8 @@ int32_t bitcoin_scriptget(struct iguana_info *coin,int32_t *hashtypep,uint32_t *
*hashtypep = vp->signers[j].sig[siglen-1];
else if ( vp->signers[j].sig[siglen-1] != *hashtypep )
{
printf("SIGHASH mismatch %d vs %d\n",vp->signers[j].sig[siglen-1],*hashtypep);
printf("SIGHASH.%d mismatch %d vs %d\n",j,vp->signers[j].sig[siglen-1],*hashtypep);
break;
}
(*sigsizep) += siglen;
//printf("sigsize %d [%02x]\n",*sigsizep,vp->signers[j].sig[siglen-1]);
@ -778,184 +779,3 @@ char *iguana_scriptget(struct iguana_info *coin,char *scriptstr,char *asmstr,int
init_hexbytes_noT(scriptstr,script,scriptlen);
return(scriptstr);
}
/*void iguana_bundlescript(struct iguana_info *coin,uint32_t offset,struct iguana_bundle *bp,uint32_t ind,uint8_t *spendscript,int32_t spendlen)
{
long size = sizeof(offset) + sizeof(ind); uint32_t *ptr;
if ( bp->numscriptsmaps >= bp->maxscriptsmaps )
{
bp->scriptsmap = realloc(bp->scriptsmap,(1000+bp->maxscriptsmaps) * (sizeof(offset) + sizeof(ind)));
bp->maxscriptsmaps += 1000;
}
ptr = (void *)((long)bp->scriptsmap + bp->numscriptsmaps*size);
ptr[0] = ind;
ptr[1] = offset;
bp->numscriptsmaps++;
}*/
uint32_t iguana_scriptstableadd(struct iguana_info *coin,int32_t spendflag,uint32_t fpos,uint8_t *script,uint16_t scriptlen)
{
struct scriptinfo *ptr;
HASH_FIND(hh,coin->scriptstable[spendflag],script,scriptlen,ptr);
if ( ptr == 0 )
{
ptr = mycalloc('w',1,sizeof(*ptr) + scriptlen);
ptr->fpos = fpos;
ptr->scriptlen = scriptlen;
memcpy(ptr->script,script,scriptlen);
HASH_ADD(hh,coin->scriptstable[spendflag],script,scriptlen,ptr);
}
return(fpos);
}
uint32_t iguana_scriptstablefind(struct iguana_info *coin,int32_t spendflag,uint8_t *script,int32_t scriptlen)
{
struct scriptinfo *ptr;
HASH_FIND(hh,coin->scriptstable[spendflag],script,scriptlen,ptr);
if ( ptr != 0 )
return(ptr->fpos);
else return(0);
}
long iguana_rwscript(struct iguana_info *coin,int32_t rwflag,void *fileptr,long offset,long filesize,FILE *fp,struct iguana_bundle *bp,uint8_t **scriptptrp,int32_t *lenp,int32_t hdrsi,uint32_t ind,int32_t spendflag)
{
long scriptpos; struct scriptdata data; uint8_t *script = *scriptptrp;
if ( spendflag == 0 && (scriptpos= iguana_scriptstablefind(coin,spendflag,script,*lenp)) != 0 )
return(scriptpos);
memset(&data,0,sizeof(data));
if ( rwflag != 0 && fp != 0 && fileptr == 0 )
{
scriptpos = ftell(fp);
data.ind = ind, data.spendflag = spendflag;
data.hdrsi = hdrsi;
data.scriptlen = *lenp;
if ( fwrite(&data,1,sizeof(data),fp) != sizeof(data) )
return(-1);
if ( fwrite(script,1,data.scriptlen,fp) != data.scriptlen )
return(-1);
offset = (uint32_t)ftell(fp);
//printf("spend.%d filesize.%ld wrote.h%d u%d len.%d [%ld,%ld) crc.%08x\n",spendflag,coin->scriptsfilesize[spendflag],hdrsi,ind,data.scriptlen,scriptpos,ftell(fp),calc_crc32(0,script,data.scriptlen));
}
else if ( rwflag == 0 && fp == 0 && fileptr != 0 )
{
scriptpos = offset;
if ( offset+sizeof(data) <= filesize )
{
memcpy(&data,(void *)((long)fileptr + offset),sizeof(data));
if ( data.scriptlen > 0 && data.scriptlen < *lenp && offset+sizeof(data)+data.scriptlen <= filesize )
{
if ( data.scriptlen > 0 )
{
*scriptptrp = script = (void *)((long)fileptr + offset);
offset += data.scriptlen + sizeof(data);
if ( data.hdrsi < coin->bundlescount )
bp = coin->bundles[data.hdrsi];
else printf("illegal hdrsi.%d/%d\n",data.hdrsi,coin->bundlescount);
} else printf("illegal scriptlen %d\n",data.scriptlen);
//printf("hdrsi.%d loaded script.%d %u s%d\n",data.hdrsi,data.scriptlen,data.ind,data.spendflag);
}
else if ( data.scriptlen > 0 )
{
printf("spendlen overflow.%d vs %d\n",data.scriptlen,*lenp);
return(-1);
}
}
else
{
printf("error reading from %ld\n",scriptpos);
return(-1);
}
//printf("hdrsi.%d scriptlen.%d\n",data.hdrsi,data.scriptlen);
*lenp = data.scriptlen;
}
if ( bp != 0 )
{
//if ( spendflag == 0 )
iguana_scriptstableadd(coin,spendflag,(uint32_t)scriptpos,script,*lenp);
}
else if ( rwflag == 0 )
{
printf("null bp for iguana_rwscript hdrsi.%d/%d\n",data.hdrsi,coin->bundlescount);
return(-1);
}
return(offset);
}
long iguana_initscripts(struct iguana_info *coin)
{
long fpos=0,offset = 0; uint8_t scriptdata[IGUANA_MAXSCRIPTSIZE],*scriptptr; int32_t spendflag,size,n=0; struct scriptdata script;
for (spendflag=0; spendflag<2; spendflag++)
{
portable_mutex_lock(&coin->scripts_mutex[spendflag]);
sprintf(coin->scriptsfname[spendflag],"tmp/%s/%sscripts",coin->symbol,spendflag==0?"":"sig"), OS_portable_path(coin->scriptsfname[spendflag]);
printf("scripts fname.(%s)\n",coin->scriptsfname[spendflag]);
if ( (coin->scriptsptr[spendflag]= OS_mapfile(coin->scriptsfname[spendflag],&coin->scriptsfilesize[spendflag],0)) == 0 )
{
coin->scriptsfp[spendflag] = fopen(coin->scriptsfname[spendflag],"wb");
memset(&script,0,sizeof(script));
fwrite(&script,1,sizeof(script),coin->scriptsfp[spendflag]);
}
else
{
while ( 1 )
{
size = sizeof(scriptdata);
scriptptr = scriptdata;
if ( (offset= iguana_rwscript(coin,0,coin->scriptsptr[spendflag],offset,coin->scriptsfilesize[spendflag],0,0,&scriptptr,&size,0,0,spendflag)) < 0 )
break;
else fpos = offset;
n++;
}
coin->scriptsfp[spendflag] = fopen(coin->scriptsfname[spendflag],"ab");
portable_mutex_unlock(&coin->scripts_mutex[spendflag]);
printf("initialized %d scripts, fpos %ld\n",n,fpos);
return(offset);
}
portable_mutex_unlock(&coin->scripts_mutex[spendflag]);
}
return(-1);
}
uint32_t iguana_scriptsave(struct iguana_info *coin,struct iguana_bundle *bp,uint32_t ind,int32_t spendflag,uint8_t *script,int32_t scriptlen)
{
FILE *fp; long fpos = 0;
if ( scriptlen > 0 && (fp= coin->scriptsfp[spendflag]) != 0 )
{
portable_mutex_lock(&coin->scripts_mutex[spendflag]);
fpos = ftell(fp);
if ( iguana_rwscript(coin,1,0,0,0,fp,bp,&script,&scriptlen,bp->hdrsi,ind,spendflag) < 0 )
{
fseek(fp,fpos,SEEK_SET);
fpos = -1;
printf("error saving script at %ld\n",fpos);
} else fflush(fp);
portable_mutex_unlock(&coin->scripts_mutex[spendflag]);
} else printf("cant scriptsave.%d to (%s).%p scriptlen.%d\n",spendflag,coin->scriptsfname[spendflag],coin->scriptsfp[spendflag],scriptlen);
return((uint32_t)fpos);
}
long iguana_scriptadd(struct iguana_info *coin,struct iguana_bundle *bp,uint32_t unspentind,int32_t type,uint8_t *spendscript,int32_t spendlen,uint8_t rmd160[20],int32_t vout)
{
static long total,saved;
int32_t scriptlen; char asmstr[IGUANA_MAXSCRIPTSIZE*2+1]; uint8_t script[IGUANA_MAXSCRIPTSIZE]; long fpos=0; struct vin_info V,*vp = &V;
if ( spendlen == 0 )
{
printf("null script?\n");
getchar();
return(0);
}
memset(vp,0,sizeof(*vp));
asmstr[0] = 0;
total++;
scriptlen = iguana_scriptgen(coin,&vp->M,&vp->N,vp->coinaddr,script,asmstr,rmd160,type,(const struct vin_info *)vp,vout);
if ( scriptlen == spendlen && memcmp(script,spendscript,scriptlen) == 0 )
return(0);
else
{
saved++;
//if ( (saved % 1000) == 0 )
printf("add type.%d scriptlen.%d fpos.%ld saved.%ld/%ld\n",type,spendlen,coin->scriptsfp!=0?ftell(coin->scriptsfp[0]):-1,saved,total);
fpos = iguana_scriptsave(coin,bp,unspentind,0,spendscript,spendlen);
}
return(fpos);
}

Loading…
Cancel
Save