From cf6535dade54341444ad50090c5c5ab103ec8515 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 5 Jul 2016 15:50:25 -0300 Subject: [PATCH] test --- basilisk/basilisk.h | 2 +- basilisk/basilisk_bitcoin.c | 4 +- basilisk/basilisk_swap.c | 22 +++-- iguana/iguana_interpreter.c | 191 ++++++++++++++++++------------------ 4 files changed, 115 insertions(+), 104 deletions(-) diff --git a/basilisk/basilisk.h b/basilisk/basilisk.h index 44d4bf7c3..a7c06d658 100755 --- a/basilisk/basilisk.h +++ b/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; diff --git a/basilisk/basilisk_bitcoin.c b/basilisk/basilisk_bitcoin.c index 06ff35288..d3a18f5cf 100755 --- a/basilisk/basilisk_bitcoin.c +++ b/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\"}"); diff --git a/basilisk/basilisk_swap.c b/basilisk/basilisk_swap.c index ae96b529f..44d7b3e83 100755 --- a/basilisk/basilisk_swap.c +++ b/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(); - jaddbits256(item,"txid",rawtx->actualtxid); + 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,12 +554,16 @@ 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); basilisk_rawtx_setparms(myinfo,swap,&swap->alicereclaim,swap->alicecoin,swap->aliceconfirms,2,swap->alicesatoshis-swap->alicecoin->txfee,1,alicepub33); @@ -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; } } diff --git a/iguana/iguana_interpreter.c b/iguana/iguana_interpreter.c index 0d9d090ce..b1906ff07 100755 --- a/iguana/iguana_interpreter.c +++ b/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; iN; 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,6 +1117,87 @@ int32_t bitcoin_assembler(struct iguana_info *coin,cJSON *logarray,uint8_t scrip } memset(args,0,sizeof(args)); numargs = 0; + 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: + if ( stacks->ifdepth >= IGUANA_MAXSTACKDEPTH ) + { + printf("ifdepth.%d >= MAXSTACKDEPTH.%d\n",stacks->ifdepth,IGUANA_MAXSTACKDEPTH); + errs++; + } + else + { + if ( stacks->stackdepth <= 0 ) + errs++; + else + { + 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; + } + } + break; + case IGUANA_OP_ELSE: + 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); + } + break; + case IGUANA_OP_ENDIF: + if ( stacks->ifdepth <= 0 ) + { + printf("endif without if offset.%ld\n",(long)str-(long)asmstr); + errs++; + } + stacks->ifdepth--; + 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); + errs++; + break; + } + if ( errs != 0 ) + break; + continue; + } + 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; @@ -1144,91 +1229,18 @@ int32_t bitcoin_assembler(struct iguana_info *coin,cJSON *logarray,uint8_t scrip continue; if ( (op->flags & IGUANA_NOPFLAG) != 0 ) continue; - if ( (op->flags & IGUANA_CONTROLFLAG) != 0 ) + if ( (numargs= op->stackitems) > 0 ) { - printf("control opcode depth.%d\n",stacks->stackdepth); - switch ( op->opcode ) + if ( stacks->stackdepth < op->stackitems ) { - case IGUANA_OP_IF: case IGUANA_OP_NOTIF: - if ( stacks->ifdepth >= IGUANA_MAXSTACKDEPTH ) - { - printf("ifdepth.%d >= MAXSTACKDEPTH.%d\n",stacks->ifdepth,IGUANA_MAXSTACKDEPTH); - errs++; - } - else - { - if ( stacks->stackdepth <= 0 ) - errs++; - else - { - 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; - } - } - break; - case IGUANA_OP_ELSE: - 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); - } - break; - case IGUANA_OP_ENDIF: - if ( stacks->ifdepth <= 0 ) - { - printf("endif without if offset.%ld\n",(long)str-(long)asmstr); - errs++; - } - stacks->ifdepth--; - 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); - errs++; - break; - } - if ( errs != 0 ) + printf("stackdepth.%d needed.%d (%s) at offset.%ld\n",stacks->stackdepth,op->stackitems,str,(long)str-(long)asmstr); + errs++; 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; iopcode,numargs,stacks->stackdepth); + for (i=0; iopcode,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 )