|
|
@ -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); |
|
|
|
} |
|
|
|