Browse Source

test

release/v0.1
jl777 9 years ago
parent
commit
55ecce6695
  1. 13
      basilisk/basilisk_swap.c
  2. 100
      iguana/iguana_interpreter.c

13
basilisk/basilisk_swap.c

@ -113,7 +113,7 @@ int32_t basilisk_alicescript(uint8_t *script,int32_t n,char *msigaddr,uint8_t al
int32_t basilisk_rawtx_spend(struct supernet_info *myinfo,struct basilisk_swap *swap,struct basilisk_rawtx *dest,struct basilisk_rawtx *rawtx,bits256 privkey,uint8_t *userdata,int32_t userdatalen)
{
char *rawtxbytes,*signedtx,hexstr[999],wifstr[128]; cJSON *txobj,*vins,*item,*sobj,*privkeys; int32_t retval = -1,len=0; struct vin_info V;
char *rawtxbytes,*signedtx,hexstr[999],wifstr[128]; cJSON *txobj,*vins,*item,*sobj,*privkeys; int32_t retval = -1; struct vin_info V;
memset(&V,0,sizeof(V));
V.signers[0].privkey = privkey;
privkeys = cJSON_CreateArray();
@ -123,7 +123,7 @@ int32_t basilisk_rawtx_spend(struct supernet_info *myinfo,struct basilisk_swap *
{
V.suppress_pubkeys = 1;
memcpy(V.userdata,userdata,userdatalen);
V.userdatalen = len;
V.userdatalen = userdatalen;
}
txobj = bitcoin_txcreate(rawtx->coin->chain->isPoS,0,1);
vins = cJSON_CreateArray();
@ -1059,8 +1059,13 @@ void basilisk_swaploop(void *_swap)
}
}
}
if ( swap->sleeptime > 0 )
sleep(swap->sleeptime);
if ( myinfo->RELAYID >= 0 )
usleep(100000);
else
{
if ( swap->sleeptime > 0 )
sleep(swap->sleeptime);
}
}
if ( swap->iambob != 0 )
{

100
iguana/iguana_interpreter.c

@ -1010,7 +1010,7 @@ int32_t bitcoin_assembler(struct iguana_info *coin,cJSON *logarray,uint8_t scrip
free(stacks);
return(-1);
}
printf("stackdepth.%d dlen.%d\n",stacks->stackdepth,dlen);
printf("user data stackdepth.%d dlen.%d\n",stacks->stackdepth,dlen);
}
if ( len != V->userdatalen )
{
@ -1142,35 +1142,11 @@ int32_t bitcoin_assembler(struct iguana_info *coin,cJSON *logarray,uint8_t scrip
}
if ( interpret == 0 || V == 0 )
continue;
if ( (numargs= op->stackitems) > 0 )
{
if ( stacks->stackdepth < op->stackitems )
{
printf("stackdepth.%d needed.%d (%s) at offset.%ld\n",stacks->stackdepth,op->stackitems,str,(long)str-(long)asmstr);
errs++;
break;
}
for (i=0; i<numargs; i++)
args[numargs - 1 - i] = iguana_pop(stacks);
}
if ( stacks->logarray != 0 )
{
char tmpstr[1096];
item = cJSON_CreateObject();
array = cJSON_CreateArray();
for (i=0; i<numargs; i++)
{
datalen = iguana_databuf(databuf,args[i]);
init_hexbytes_noT(tmpstr,databuf,datalen);
jaddistr(array,tmpstr);
}
jadd(item,(char *)op->hh.key,array);
jaddi(stacks->logarray,item);
}
if ( (op->flags & IGUANA_NOPFLAG) != 0 )
continue;
if ( (op->flags & IGUANA_CONTROLFLAG) != 0 )
{
printf("control opcode depth.%d\n",stacks->stackdepth);
switch ( op->opcode )
{
case IGUANA_OP_IF: case IGUANA_OP_NOTIF:
@ -1181,27 +1157,39 @@ int32_t bitcoin_assembler(struct iguana_info *coin,cJSON *logarray,uint8_t scrip
}
else
{
if ( iguana_isnonz(args[0]) == (op->opcode == IGUANA_OP_IF) )
{
val = 1;
printf("OP_IF enabled depth.%d\n",stacks->stackdepth);
}
if ( stacks->stackdepth <= 0 )
errs++;
else
{
val = -1;
printf("OP_IF disabled depth.%d\n",stacks->stackdepth);
args[0] = iguana_pop(stacks);
if ( iguana_isnonz(args[0]) == (op->opcode == IGUANA_OP_IF) )
{
val = 1;
printf("OP_IF enabled depth.%d\n",stacks->stackdepth);
}
else
{
val = -1;
printf("OP_IF disabled depth.%d\n",stacks->stackdepth);
}
stacks->lastpath[++stacks->ifdepth] = val;
}
stacks->lastpath[++stacks->ifdepth] = val;
}
break;
case IGUANA_OP_ELSE:
if ( stacks->ifdepth <= stacks->elsedepth )
{
printf("unhandled opcode.%02x stacks->ifdepth %d <= %d stacks->elsedepth\n",op->opcode,stacks->ifdepth,stacks->elsedepth);
if ( stacks->stackdepth <= 0 )
errs++;
else
{
args[0] = iguana_pop(stacks);
if ( stacks->ifdepth <= stacks->elsedepth )
{
printf("unhandled opcode.%02x stacks->ifdepth %d <= %d stacks->elsedepth\n",op->opcode,stacks->ifdepth,stacks->elsedepth);
errs++;
}
stacks->lastpath[stacks->ifdepth] *= -1;
printf("OP_ELSE status.%d depth.%d\n",stacks->lastpath[stacks->ifdepth],stacks->stackdepth);
}
stacks->lastpath[stacks->ifdepth] *= -1;
printf("OP_ELSE status.%d depth.%d\n",stacks->lastpath[stacks->ifdepth],stacks->stackdepth);
break;
case IGUANA_OP_ENDIF:
if ( stacks->ifdepth <= 0 )
@ -1213,6 +1201,9 @@ int32_t bitcoin_assembler(struct iguana_info *coin,cJSON *logarray,uint8_t scrip
printf("OP_ENDIF status.%d depth.%d\n",stacks->lastpath[stacks->ifdepth],stacks->stackdepth);
break;
case IGUANA_OP_VERIFY:
if ( stacks->stackdepth > 0 )
args[0] = iguana_pop(stacks);
else errs++;
break;
case IGUANA_OP_RETURN:
iguana_pushdata(stacks,0,0,0);
@ -1223,11 +1214,40 @@ int32_t bitcoin_assembler(struct iguana_info *coin,cJSON *logarray,uint8_t scrip
break;
continue;
}
else if ( stacks->lastpath[stacks->ifdepth] >= 0 )
{
if ( (numargs= op->stackitems) > 0 )
{
if ( stacks->stackdepth < op->stackitems )
{
printf("stackdepth.%d needed.%d (%s) at offset.%ld\n",stacks->stackdepth,op->stackitems,str,(long)str-(long)asmstr);
errs++;
break;
}
for (i=0; i<numargs; i++)
args[numargs - 1 - i] = iguana_pop(stacks);
}
printf("%02x: numargs.%d depth.%d\n",op->opcode,numargs,stacks->stackdepth);
}
if ( stacks->logarray != 0 )
{
char tmpstr[1096];
item = cJSON_CreateObject();
array = cJSON_CreateArray();
for (i=0; i<numargs; i++)
{
datalen = iguana_databuf(databuf,args[i]);
init_hexbytes_noT(tmpstr,databuf,datalen);
jaddistr(array,tmpstr);
}
jadd(item,(char *)op->hh.key,array);
jaddi(stacks->logarray,item);
}
if ( stacks->lastpath[stacks->ifdepth] != 0 )
{
if ( stacks->lastpath[stacks->ifdepth] < 0 )
{
printf("SKIP opcode.%02x\n",op->opcode);
printf("SKIP opcode.%02x depth.%d\n",op->opcode,stacks->stackdepth);
if ( stacks->logarray )
jaddistr(stacks->logarray,"skip");
continue;

Loading…
Cancel
Save