Browse Source

test

release/v0.1
jl777 9 years ago
parent
commit
cf6535dade
  1. 2
      basilisk/basilisk.h
  2. 4
      basilisk/basilisk_bitcoin.c
  3. 16
      basilisk/basilisk_swap.c
  4. 103
      iguana/iguana_interpreter.c

2
basilisk/basilisk.h

@ -55,7 +55,7 @@ struct basilisk_rawtx
bits256 txid,signedtxid,actualtxid;
struct iguana_info *coin;
uint64_t amount,change,inputsum;
int32_t datalen,completed,vintype,vouttype,numconfirms,spendlen,secretstart;
int32_t datalen,completed,vintype,vouttype,numconfirms,spendlen,secretstart,suppress_pubkeys;
uint32_t locktime;
char destaddr[64]; uint8_t addrtype,pubkey33[33],rmd160[20],spendscript[512];
uint8_t *txbytes;

4
basilisk/basilisk_bitcoin.c

@ -462,8 +462,8 @@ void *basilisk_bitcoinrawtx(struct basilisk_item *Lptr,struct supernet_info *myi
addresses = iguana_getaddressesbyaccount(myinfo,coin,"*");
jadd(valsobj,"addresses",addresses);
}
printf("use addresses.(%s)\n",jprint(addresses,0));
printf("vals.(%s) change.(%s) spend.%s\n",jprint(valsobj,0),changeaddr,spendscriptstr);
//printf("use addresses.(%s)\n",jprint(addresses,0));
//printf("vals.(%s) change.(%s) spend.%s\n",jprint(valsobj,0),changeaddr,spendscriptstr);
if ( changeaddr == 0 || changeaddr[0] == 0 || spendscriptstr == 0 || spendscriptstr[0] == 0 )//|| amount == 0 || addresses == 0 )
{
Lptr->retstr = clonestr("{\"error\":\"invalid changeaddr or spendscript or addresses\"}");

16
basilisk/basilisk_swap.c

@ -121,14 +121,16 @@ int32_t basilisk_rawtx_spend(struct supernet_info *myinfo,struct basilisk_swap *
jaddistr(privkeys,wifstr);
if ( userdata != 0 && userdatalen > 0 )
{
V.suppress_pubkeys = 1;
V.suppress_pubkeys = rawtx->suppress_pubkeys;
memcpy(V.userdata,userdata,userdatalen);
V.userdatalen = userdatalen;
}
txobj = bitcoin_txcreate(rawtx->coin->chain->isPoS,0,1);
vins = cJSON_CreateArray();
item = cJSON_CreateObject();
if ( bits256_nonz(rawtx->actualtxid) != 0 )
jaddbits256(item,"txid",rawtx->actualtxid);
else jaddbits256(item,"txid",rawtx->signedtxid);
jaddnum(item,"vout",0);
sobj = cJSON_CreateObject();
init_hexbytes_noT(hexstr,rawtx->spendscript,rawtx->spendlen);
@ -140,7 +142,7 @@ int32_t basilisk_rawtx_spend(struct supernet_info *myinfo,struct basilisk_swap *
txobj = bitcoin_txoutput(txobj,dest->spendscript,dest->spendlen,dest->amount);
if ( (rawtxbytes= bitcoin_json2hex(myinfo,rawtx->coin,&dest->txid,txobj,&V)) != 0 )
{
printf("spend rawtx.(%s)\n",rawtxbytes);
printf("spend rawtx.(%s) userdatalen.%d\n",rawtxbytes,userdatalen);
if ( (signedtx= iguana_signrawtx(myinfo,rawtx->coin,&dest->signedtxid,&dest->completed,vins,rawtxbytes,privkeys,&V)) != 0 )
{
printf("rawtx spend signedtx.(%s)\n",signedtx);
@ -552,11 +554,15 @@ struct basilisk_swap *bitcoin_swapinit(struct supernet_info *myinfo,struct basil
}
basilisk_rawtx_setparms(myinfo,swap,&swap->bobdeposit,swap->bobcoin,swap->bobconfirms,0,swap->bobsatoshis*1.1,4,0);
basilisk_rawtx_setparms(myinfo,swap,&swap->bobrefund,swap->bobcoin,1,4,swap->bobsatoshis*1.1-swap->bobcoin->txfee,1,bobpub33);
swap->bobrefund.suppress_pubkeys = 1;
basilisk_rawtx_setparms(myinfo,swap,&swap->aliceclaim,swap->bobcoin,1,4,swap->bobsatoshis*1.1-swap->bobcoin->txfee,1,alicepub33);
swap->aliceclaim.suppress_pubkeys = 1;
basilisk_rawtx_setparms(myinfo,swap,&swap->bobpayment,swap->bobcoin,swap->bobconfirms,0,swap->bobsatoshis,3,0);
basilisk_rawtx_setparms(myinfo,swap,&swap->alicespend,swap->bobcoin,swap->bobconfirms,3,swap->bobsatoshis - swap->bobcoin->txfee,1,alicepub33);
swap->alicespend.suppress_pubkeys = 1;
basilisk_rawtx_setparms(myinfo,swap,&swap->bobreclaim,swap->bobcoin,swap->bobconfirms,3,swap->bobsatoshis - swap->bobcoin->txfee,1,bobpub33);
swap->bobreclaim.suppress_pubkeys = 1;
basilisk_rawtx_setparms(myinfo,swap,&swap->alicepayment,swap->alicecoin,swap->aliceconfirms,0,swap->alicesatoshis,2,0);
basilisk_rawtx_setparms(myinfo,swap,&swap->bobspend,swap->alicecoin,swap->aliceconfirms,2,swap->alicesatoshis-swap->alicecoin->txfee,1,bobpub33);
@ -991,7 +997,7 @@ void basilisk_swaploop(void *_swap)
break;
}
}
else if ( time(NULL) > swap->bobpayment.locktime )
else if ( swap->bobpayment.locktime != 0 && time(NULL) > swap->bobpayment.locktime )
{
// submit reclaim of payment
swap->sleeptime = 1;
@ -1027,11 +1033,11 @@ void basilisk_swaploop(void *_swap)
else
{
// [BLOCKING: depfound] Alice waits for deposit to confirm and sends altpayment
if ( time(NULL) > swap->bobdeposit.locktime )
if ( swap->bobdeposit.locktime != 0 && time(NULL) > swap->bobdeposit.locktime )
{
if ( basilisk_swapdata_rawtxsend(myinfo,swap,0,data,maxlen,&swap->aliceclaim,0) == 0 )
{
printf("Alice clains deposit\n");
printf("Alice claims deposit\n");
break;
}
}

103
iguana/iguana_interpreter.c

@ -967,6 +967,7 @@ int32_t bitcoin_assembler(struct iguana_info *coin,cJSON *logarray,uint8_t scrip
free(stacks);
return(-1);
}
printf("pushdata siglen.%d depth.%d\n",V->signers[i].siglen,stacks->stackdepth);
}
}
for (i=0; i<V->N; i++)
@ -975,7 +976,10 @@ int32_t bitcoin_assembler(struct iguana_info *coin,cJSON *logarray,uint8_t scrip
{
plen = bitcoin_pubkeylen(V->signers[i].pubkey);
if ( V->suppress_pubkeys == 0 && (V->spendscript[0] != plen || V->spendscript[V->spendlen - 1] != IGUANA_OP_CHECKSIG || bitcoin_pubkeylen(&V->spendscript[1]) <= 0) )
{
iguana_pushdata(stacks,0,V->signers[i].pubkey,plen);
printf("pushdata plen.%d depth.%d\n",plen,stacks->stackdepth);
} else printf("skip pubkey push %d script[0].%d spendlen.%d depth.%d\n",plen,V->spendscript[0],V->spendlen,stacks->stackdepth);
}
}
if ( V->userdatalen != 0 )
@ -1113,37 +1117,6 @@ int32_t bitcoin_assembler(struct iguana_info *coin,cJSON *logarray,uint8_t scrip
}
memset(args,0,sizeof(args));
numargs = 0;
if ( op->opcode <= IGUANA_OP_16 || ++numops <= MAX_OPS_PER_SCRIPT )
{
script[k++] = op->opcode;
if ( (op->flags & IGUANA_ALWAYSILLEGAL) != 0 )
{
printf("disabled opcode.%s at offset.%ld\n",str,(long)str-(long)asmstr);
errs++;
break;
}
else if ( op->extralen > 0 )
{
if ( is_delim(*str) != 0 )
str++;
if ( is_hexstr(str,0) != (op->extralen<<1) )
{
printf("expected extralen.%d of hex, got.(%s) at offset.%ld\n",op->extralen,str,(long)str-(long)asmstr);
errs++;
break;
}
decode_hex(&script[k],op->extralen,str), str += (op->extralen << 1);
if ( op->extralen == 1 )
iguana_pushdata(stacks,script[k],0,0);
else if ( op->extralen == 2 )
iguana_pushdata(stacks,script[k] + ((uint32_t)script[k]<<8),0,0);
k += op->extralen;
continue;
}
if ( interpret == 0 || V == 0 )
continue;
if ( (op->flags & IGUANA_NOPFLAG) != 0 )
continue;
if ( (op->flags & IGUANA_CONTROLFLAG) != 0 )
{
printf("control opcode depth.%d\n",stacks->stackdepth);
@ -1201,9 +1174,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++;
//if ( stacks->stackdepth > 0 )
// args[0] = iguana_pop(stacks);
//else errs++;
break;
case IGUANA_OP_RETURN:
iguana_pushdata(stacks,0,0,0);
@ -1214,8 +1187,48 @@ int32_t bitcoin_assembler(struct iguana_info *coin,cJSON *logarray,uint8_t scrip
break;
continue;
}
else if ( stacks->lastpath[stacks->ifdepth] >= 0 )
if ( stacks->lastpath[stacks->ifdepth] != 0 )
{
if ( stacks->lastpath[stacks->ifdepth] < 0 )
{
printf("SKIP opcode.%02x depth.%d\n",op->opcode,stacks->stackdepth);
if ( stacks->logarray )
jaddistr(stacks->logarray,"skip");
continue;
}
printf("conditional opcode.%02x stackdepth.%d\n",op->opcode,stacks->stackdepth);
}
if ( op->opcode <= IGUANA_OP_16 || ++numops <= MAX_OPS_PER_SCRIPT )
{
script[k++] = op->opcode;
if ( (op->flags & IGUANA_ALWAYSILLEGAL) != 0 )
{
printf("disabled opcode.%s at offset.%ld\n",str,(long)str-(long)asmstr);
errs++;
break;
}
else if ( op->extralen > 0 )
{
if ( is_delim(*str) != 0 )
str++;
if ( is_hexstr(str,0) != (op->extralen<<1) )
{
printf("expected extralen.%d of hex, got.(%s) at offset.%ld\n",op->extralen,str,(long)str-(long)asmstr);
errs++;
break;
}
decode_hex(&script[k],op->extralen,str), str += (op->extralen << 1);
if ( op->extralen == 1 )
iguana_pushdata(stacks,script[k],0,0);
else if ( op->extralen == 2 )
iguana_pushdata(stacks,script[k] + ((uint32_t)script[k]<<8),0,0);
k += op->extralen;
continue;
}
if ( interpret == 0 || V == 0 )
continue;
if ( (op->flags & IGUANA_NOPFLAG) != 0 )
continue;
if ( (numargs= op->stackitems) > 0 )
{
if ( stacks->stackdepth < op->stackitems )
@ -1228,7 +1241,6 @@ int32_t bitcoin_assembler(struct iguana_info *coin,cJSON *logarray,uint8_t scrip
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];
@ -1243,18 +1255,7 @@ int32_t bitcoin_assembler(struct iguana_info *coin,cJSON *logarray,uint8_t scrip
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 depth.%d\n",op->opcode,stacks->stackdepth);
if ( stacks->logarray )
jaddistr(stacks->logarray,"skip");
continue;
}
printf("conditional opcode.%02x stackdepth.%d\n",op->opcode,stacks->stackdepth);
}
else if ( (op->flags & IGUANA_EXECUTIONILLEGAL) != 0 )
if ( (op->flags & IGUANA_EXECUTIONILLEGAL) != 0 )
{
printf("opcode not allowed to run.%s at %ld\n",(char *)op->hh.key,(long)str-(long)asmstr);
errs++;
@ -1381,7 +1382,11 @@ int32_t bitcoin_assembler(struct iguana_info *coin,cJSON *logarray,uint8_t scrip
iguana_stack(stacks,args,0,"","0");
iguana_stack(stacks,args,1,"0","");
break;
case IGUANA_OP_DUP: iguana_stack(stacks,args,1,"0","0"); break;
case IGUANA_OP_DUP:
printf("before dup stackdepth.%d\n",stacks->stackdepth);
iguana_stack(stacks,args,1,"0","0");
printf("after dup stackdepth.%d\n",stacks->stackdepth);
break;
case IGUANA_OP_2DUP: iguana_stack(stacks,args,2,"01","01"); break;
case IGUANA_OP_NIP:
if ( args[0].data != 0 )

Loading…
Cancel
Save