Browse Source

test

release/v0.1
jl777 9 years ago
parent
commit
455b0be2a2
  1. 20
      basilisk/basilisk_swap.c
  2. 29
      iguana/iguana_interpreter.c
  3. 2
      iguana/iguana_sign.c

20
basilisk/basilisk_swap.c

@ -142,10 +142,10 @@ 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) userdatalen.%d\n",rawtxbytes,userdatalen);
//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);
//printf("rawtx spend signedtx.(%s)\n",signedtx);
dest->datalen = (int32_t)strlen(signedtx) >> 1;
dest->txbytes = calloc(1,dest->datalen);
decode_hex(dest->txbytes,dest->datalen,signedtx);
@ -185,7 +185,7 @@ int32_t basilisk_verify_bobdeposit(struct supernet_info *myinfo,struct basilisk_
swap->bobdeposit.txbytes = calloc(1,datalen);
memcpy(swap->bobdeposit.txbytes,data,datalen);
swap->bobdeposit.signedtxid = bits256_doublesha256(0,data,datalen);
userdata[len++] = 1; // true -> if path
userdata[len++] = 0x51; // true -> if path
return(basilisk_rawtx_spend(myinfo,swap,&swap->aliceclaim,&swap->bobdeposit,swap->myprivs[0],0,userdata,len));
}
@ -194,7 +194,7 @@ int32_t basilisk_bobdeposit_refund(struct supernet_info *myinfo,struct basilisk_
uint8_t userdata[512]; int32_t i,len = 0;
userdata[len++] = sizeof(swap->privBn);
for (i=0; i<sizeof(swap->privBn); i++)
userdata[len++] = swap->privBn.bytes[i];
userdata[len++] = swap->privBn.bytes[sizeof(swap->privBn) - 1 - i];
userdata[len++] = 0; // false -> else path
return(basilisk_rawtx_spend(myinfo,swap,&swap->bobrefund,&swap->bobdeposit,swap->myprivs[0],0,userdata,len));
}
@ -202,7 +202,7 @@ int32_t basilisk_bobdeposit_refund(struct supernet_info *myinfo,struct basilisk_
int32_t basilisk_bobpayment_reclaim(struct supernet_info *myinfo,struct basilisk_swap *swap)
{
uint8_t userdata[512]; int32_t len = 0;
userdata[len++] = 1; // true -> if path
userdata[len++] = 0x51; // true -> if path
return(basilisk_rawtx_spend(myinfo,swap,&swap->bobreclaim,&swap->bobpayment,swap->myprivs[1],0,userdata,len));
}
@ -216,8 +216,9 @@ int32_t basilisk_verify_bobpaid(struct supernet_info *myinfo,struct basilisk_swa
// OP_HASH160 <hash(alice_privM)> OP_EQUALVERIFY <alice_pubA0> OP_CHECKSIG
userdata[len++] = sizeof(swap->privAm);
for (i=0; i<sizeof(swap->privAm); i++)
userdata[len++] = swap->privAm.bytes[i];
userdata[len++] = swap->privAm.bytes[sizeof(swap->privAm) - 1 - i];
userdata[len++] = 0; // false -> else path
char str[65]; printf("bobpaid.(%s)\n",bits256_str(str,swap->privAm));
return(basilisk_rawtx_spend(myinfo,swap,&swap->alicespend,&swap->bobpayment,swap->myprivs[0],0,userdata,len));
}
@ -347,7 +348,7 @@ int32_t basilisk_rawtx_return(struct supernet_info *myinfo,struct basilisk_rawtx
rawtx->datalen = (int32_t)strlen(signedtx) >> 1;
rawtx->txbytes = calloc(1,rawtx->datalen);
decode_hex(rawtx->txbytes,rawtx->datalen,signedtx);
printf("SIGNEDTX.(%s)\n",signedtx);
//printf("SIGNEDTX.(%s)\n",signedtx);
free(signedtx);
retval = 0;
} else printf("error signrawtx\n"); //do a very short timeout so it finishes via local poll
@ -819,13 +820,14 @@ void basilisk_swaploop(void *_swap)
{
if ( basilisk_swapget(myinfo,swap,0x08,data,maxlen,basilisk_verify_choosei) == 0 )
{
char str[65];
if ( swap->iambob != 0 )
{
swap->privBn = swap->privkeys[swap->otherchoosei];
memset(&swap->privkeys[swap->otherchoosei],0,sizeof(swap->privkeys[swap->otherchoosei]));
calc_rmd160_sha256(swap->secretBn,swap->privBn.bytes,sizeof(swap->privBn));
swap->pubBn = bitcoin_pubkey33(myinfo->ctx,pubkey33,swap->privBn);
printf("set secretBn.%02x\n",pubkey33[0]);
printf("set privBn.%s\n",bits256_str(str,swap->privBn));
}
else
{
@ -833,7 +835,7 @@ void basilisk_swaploop(void *_swap)
memset(&swap->privkeys[swap->otherchoosei],0,sizeof(swap->privkeys[swap->otherchoosei]));
calc_rmd160_sha256(swap->secretAm,swap->privAm.bytes,sizeof(swap->privAm));
swap->pubAm = bitcoin_pubkey33(myinfo->ctx,pubkey33,swap->privAm);
printf("set secretAm.%02x\n",pubkey33[0]);
printf("set privAm.%s\n",bits256_str(str,swap->privAm));
}
swap->statebits |= 0x08;
}

29
iguana/iguana_interpreter.c

@ -494,6 +494,8 @@ static int32_t iguana_num(struct iguana_stackdata Snum)
static int32_t iguana_pushdata(struct iguana_interpreter *stacks,int64_t num64,uint8_t *numbuf,int32_t numlen)
{
struct iguana_stackdata Snum; cJSON *item = 0; char tmpstr[2048]; int32_t num = (int32_t)num64;
if ( stacks->lastpath[stacks->ifdepth] < 0 )
return(0);
if ( stacks->maxstackdepth > 0 )
{
/*if ( numbuf != 0 )
@ -993,7 +995,7 @@ int32_t bitcoin_assembler(struct iguana_info *coin,cJSON *logarray,uint8_t scrip
else if ( dlen >= IGUANA_OP_1 && dlen <= IGUANA_OP_16 )
{
dlen -= 0x50;
iguana_pushdata(stacks,0,&V->userdata[len],dlen), len += dlen;
iguana_pushdata(stacks,dlen,0,0);
}
else if ( dlen == IGUANA_OP_PUSHDATA1 )
{
@ -1010,7 +1012,7 @@ int32_t bitcoin_assembler(struct iguana_info *coin,cJSON *logarray,uint8_t scrip
iguana_pushdata(stacks,-1,0,0);
else
{
printf("invalid data opcode %d\n",dlen);
printf("invalid data opcode %02x\n",dlen);
free(stacks);
return(-1);
}
@ -1154,7 +1156,6 @@ int32_t bitcoin_assembler(struct iguana_info *coin,cJSON *logarray,uint8_t scrip
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);
@ -1174,9 +1175,6 @@ 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);
@ -1265,7 +1263,17 @@ int32_t bitcoin_assembler(struct iguana_info *coin,cJSON *logarray,uint8_t scrip
{
if ( iguana_cmp(&args[0],&args[1]) == 0 )
iguana_pushdata(stacks,1,0,0);
else iguana_pushdata(stacks,0,0,0);
else
{
for (i=0; i<args[0].size; i++)
printf("%02x",args[0].U.pubkey[i]);
printf(" <- args[0]\n");
for (i=0; i<args[1].size; i++)
printf("%02x",args[1].U.pubkey[i]);
printf(" <- args[1]\n");
printf("OP_EQUAL compare error %d vs %d\n",args[0].size,args[1].size);
iguana_pushdata(stacks,0,0,0);
}
}
else if ( (op->flags & IGUANA_CRYPTOFLAG) != 0 )
{
@ -1382,11 +1390,7 @@ 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:
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_DUP: iguana_stack(stacks,args,1,"0","0"); break;
case IGUANA_OP_2DUP: iguana_stack(stacks,args,2,"01","01"); break;
case IGUANA_OP_NIP:
if ( args[0].data != 0 )
@ -1501,6 +1505,7 @@ int32_t bitcoin_assembler(struct iguana_info *coin,cJSON *logarray,uint8_t scrip
jadd(interpreter,"result",jtrue());
else jadd(interpreter,"result",jfalse());
}
else printf("Evaluate FALSE, depth.%d errs.%d\n",stacks->stackdepth,errs);
//if ( stacks->logarray != 0 )
// printf("LOG.(%s)\n",jprint(stacks->logarray,0));
if ( numargs > 0 )

2
iguana/iguana_sign.c

@ -708,7 +708,7 @@ int32_t bitcoin_verifyvins(struct iguana_info *coin,bits256 *signedtxidp,char **
iguana_msgtx_Vset(coin,serialized,maxlen,msgtx,V);
cJSON *txobj = cJSON_CreateObject();
*signedtx = iguana_rawtxbytes(coin,txobj,msgtx);
printf("SIGNEDTX.(%s)\n",jprint(txobj,1));
//printf("SIGNEDTX.(%s)\n",jprint(txobj,1));
*signedtxidp = msgtx->txid;
return(complete);
}

Loading…
Cancel
Save