From c33a2f8f736c8409ffe6d95cc27c51dfa38db4a3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 5 Jul 2016 11:41:22 -0300 Subject: [PATCH] test --- basilisk/basilisk.h | 2 +- basilisk/basilisk_bitcoin.c | 57 ---------------- basilisk/basilisk_swap.c | 105 +++++++++++++++++++++++++++--- iguana/exchanges/bitcoin.h | 1 + iguana/iguana_interpreter.c | 74 ++++++++++++++++++--- iguana/iguana_scripts.c | 6 +- iguana/iguana_sign.c | 34 +++++----- iguana/tests/decoderawtransaction | 2 +- includes/iguana_structs.h | 4 +- 9 files changed, 189 insertions(+), 96 deletions(-) diff --git a/basilisk/basilisk.h b/basilisk/basilisk.h index d964d85c8..483a7c7e3 100755 --- a/basilisk/basilisk.h +++ b/basilisk/basilisk.h @@ -67,7 +67,7 @@ struct basilisk_swap struct supernet_info *myinfo; bits256 myhash,otherhash; uint32_t statebits,otherstatebits,started,expiration,finished,dead,reftime,locktime; struct iguana_info *bobcoin,*alicecoin; char bobstr[64],alicestr[64]; - int32_t bobconfirms,aliceconfirms,iambob,reclaimed; + int32_t bobconfirms,aliceconfirms,iambob,reclaimed,sleeptime; uint64_t alicesatoshis,bobsatoshis,bobinsurance,aliceinsurance; bits256 privkeys[INSTANTDEX_DECKSIZE],myprivs[2],mypubs[2],otherpubs[2],pubA0,pubA1,pubB0,pubB1,privAm,pubAm,privBn,pubBn; diff --git a/basilisk/basilisk_bitcoin.c b/basilisk/basilisk_bitcoin.c index 377985183..06ff35288 100755 --- a/basilisk/basilisk_bitcoin.c +++ b/basilisk/basilisk_bitcoin.c @@ -554,63 +554,6 @@ void *basilisk_bitcoinrawtx(struct basilisk_item *Lptr,struct supernet_info *myi Alice timeout event is triggered if INSTANTDEX_LOCKTIME elapses from the start of a FSM instance. Bob timeout event is triggered after INSTANTDEX_LOCKTIME*2 */ -#define SCRIPT_OP_IF 0x63 -#define SCRIPT_OP_ELSE 0x67 -#define SCRIPT_OP_ENDIF 0x68 - -int32_t basilisk_bobscript(uint8_t *script,int32_t n,uint32_t *locktimep,int32_t *secretstartp,struct basilisk_swap *swap,int32_t depositflag) -{ - uint8_t pubkeyA[33],pubkeyB[33],*secret160; bits256 cltvpub,destpub; int32_t i; - *locktimep = swap->locktime; - if ( depositflag != 0 ) - { - *locktimep += INSTANTDEX_LOCKTIME; - cltvpub = swap->pubA0; - destpub = swap->pubB0; - secret160 = swap->secretBn; - pubkeyA[0] = 0x02; - pubkeyB[0] = 0x03; - } - else - { - cltvpub = swap->pubB1; - destpub = swap->pubA0; - secret160 = swap->secretAm; - pubkeyA[0] = 0x03; - pubkeyB[0] = 0x02; - } - if ( bits256_nonz(cltvpub) == 0 || bits256_nonz(destpub) == 0 ) - return(-1); - for (i=0; i<20; i++) - if ( secret160[i] != 0 ) - break; - if ( i == 20 ) - return(-1); - memcpy(pubkeyA+1,cltvpub.bytes,sizeof(cltvpub)); - memcpy(pubkeyB+1,destpub.bytes,sizeof(destpub)); - script[n++] = SCRIPT_OP_IF; - n = bitcoin_checklocktimeverify(script,n,*locktimep); - n = bitcoin_pubkeyspend(script,n,pubkeyA); - script[n++] = SCRIPT_OP_ELSE; - if ( secretstartp != 0 ) - *secretstartp = n + 2; - n = bitcoin_revealsecret160(script,n,secret160); - n = bitcoin_pubkeyspend(script,n,pubkeyB); - script[n++] = SCRIPT_OP_ENDIF; - return(n); -} - -int32_t basilisk_alicescript(uint8_t *script,int32_t n,char *msigaddr,uint8_t altps2h,bits256 pubAm,bits256 pubBn) -{ - uint8_t p2sh160[20]; struct vin_info V; - memset(&V,0,sizeof(V)); - memcpy(&V.signers[0].pubkey[1],pubAm.bytes,sizeof(pubAm)), V.signers[0].pubkey[0] = 0x02; - memcpy(&V.signers[1].pubkey[1],pubBn.bytes,sizeof(pubBn)), V.signers[1].pubkey[0] = 0x03; - V.M = V.N = 2; - n = bitcoin_MofNspendscript(p2sh160,script,n,&V); - bitcoin_address(msigaddr,altps2h,p2sh160,sizeof(p2sh160)); - return(n); -} #ifdef later diff --git a/basilisk/basilisk_swap.c b/basilisk/basilisk_swap.c index 7966b7f5e..c73f8dbde 100755 --- a/basilisk/basilisk_swap.c +++ b/basilisk/basilisk_swap.c @@ -14,6 +14,63 @@ ******************************************************************************/ // included from basilisk.c +#define SCRIPT_OP_IF 0x63 +#define SCRIPT_OP_ELSE 0x67 +#define SCRIPT_OP_ENDIF 0x68 + +int32_t basilisk_bobscript(uint8_t *script,int32_t n,uint32_t *locktimep,int32_t *secretstartp,struct basilisk_swap *swap,int32_t depositflag) +{ + uint8_t pubkeyA[33],pubkeyB[33],*secret160; bits256 cltvpub,destpub; int32_t i; + *locktimep = swap->locktime; + if ( depositflag != 0 ) + { + *locktimep += INSTANTDEX_LOCKTIME; + cltvpub = swap->pubA0; + destpub = swap->pubB0; + secret160 = swap->secretBn; + pubkeyA[0] = 0x02; + pubkeyB[0] = 0x03; + } + else + { + cltvpub = swap->pubB1; + destpub = swap->pubA0; + secret160 = swap->secretAm; + pubkeyA[0] = 0x03; + pubkeyB[0] = 0x02; + } + if ( bits256_nonz(cltvpub) == 0 || bits256_nonz(destpub) == 0 ) + return(-1); + for (i=0; i<20; i++) + if ( secret160[i] != 0 ) + break; + if ( i == 20 ) + return(-1); + memcpy(pubkeyA+1,cltvpub.bytes,sizeof(cltvpub)); + memcpy(pubkeyB+1,destpub.bytes,sizeof(destpub)); + script[n++] = SCRIPT_OP_IF; + n = bitcoin_checklocktimeverify(script,n,*locktimep); + n = bitcoin_pubkeyspend(script,n,pubkeyA); + script[n++] = SCRIPT_OP_ELSE; + if ( secretstartp != 0 ) + *secretstartp = n + 2; + n = bitcoin_revealsecret160(script,n,secret160); + n = bitcoin_pubkeyspend(script,n,pubkeyB); + script[n++] = SCRIPT_OP_ENDIF; + return(n); +} + +int32_t basilisk_alicescript(uint8_t *script,int32_t n,char *msigaddr,uint8_t altps2h,bits256 pubAm,bits256 pubBn) +{ + uint8_t p2sh160[20]; struct vin_info V; + memset(&V,0,sizeof(V)); + memcpy(&V.signers[0].pubkey[1],pubAm.bytes,sizeof(pubAm)), V.signers[0].pubkey[0] = 0x02; + memcpy(&V.signers[1].pubkey[1],pubBn.bytes,sizeof(pubBn)), V.signers[1].pubkey[0] = 0x03; + V.M = V.N = 2; + n = bitcoin_MofNspendscript(p2sh160,script,n,&V); + bitcoin_address(msigaddr,altps2h,p2sh160,sizeof(p2sh160)); + return(n); +} struct basilisk_rawtx *basilisk_swapdata_rawtx(struct supernet_info *myinfo,struct basilisk_swap *swap,uint8_t *data,int32_t maxlen,struct basilisk_rawtx *rawtx) { @@ -55,12 +112,12 @@ int32_t basilisk_verify_bobpaid(struct supernet_info *myinfo,struct basilisk_swa bitcoin_priv2wif(wifstr,swap->myprivs[0],swap->bobcoin->chain->wiftype); printf("wifstr.(%s)\n",wifstr); jaddistr(privkeys,wifstr); - V.suppress_p2shlen = 1; - V.p2shscript[len++] = 32; + V.suppress_pubkeys = 1; + V.userdata[len++] = 32; for (i=0; i<32; i++) - V.p2shscript[len++] = swap->privAm.bytes[i]; - V.p2shscript[len++] = 0; - V.p2shlen = len; + V.userdata[len++] = swap->privAm.bytes[i]; + V.userdata[len++] = 0; + V.userdatalen = len; txobj = bitcoin_txcreate(swap->bobcoin->chain->isPoS,0,1); vins = cJSON_CreateArray(); item = cJSON_CreateObject(); @@ -423,6 +480,7 @@ struct basilisk_swap *bitcoin_swapinit(struct supernet_info *myinfo,struct basil basilisk_rawtx_setparms(myinfo,swap,&swap->alicepayment,swap->alicecoin,swap->aliceconfirms,0,swap->alicesatoshis,2,0); basilisk_rawtx_setparms(myinfo,swap,&swap->alicereclaim,swap->alicecoin,swap->aliceconfirms,2,swap->alicesatoshis-swap->alicecoin->txfee,1,alicepub33); basilisk_rawtx_setparms(myinfo,swap,&swap->bobspend,swap->alicecoin,swap->aliceconfirms,2,swap->alicesatoshis-swap->alicecoin->txfee,1,bobpub33); + swap->sleeptime = 3 - swap->iambob; return(swap); } // end of alice/bob code @@ -787,14 +845,22 @@ void basilisk_swaploop(void *_swap) { // verify and submit otherfee swap->statebits |= 0x80; + swap->sleeptime = 1; } + else if ( swap->sleeptime < 60 ) + swap->sleeptime++; } else // both sides have setup required data and paid txfee { + if ( swap->sleeptime < 60 ) + swap->sleeptime++; if ( swap->iambob != 0 ) { if ( (swap->statebits & 0x100) == 0 ) + { swap->statebits |= basilisk_swapdata_rawtxsend(myinfo,swap,0x200,data,maxlen,&swap->bobdeposit,0x100); + swap->sleeptime = 1; + } // [BLOCKING: altfound] make sure altpayment is confirmed and send payment else if ( (swap->statebits & 0x1000) == 0 ) { @@ -803,16 +869,23 @@ void basilisk_swaploop(void *_swap) { // verify alicepayment and submit, set confirmed height swap->statebits |= 0x1000; + swap->sleeptime = 1; } } else if ( (swap->statebits & 0x2000) == 0 ) { // set bobspend if ( basilisk_numconfirms(myinfo,&swap->alicepayment) >= swap->aliceconfirms ) + { swap->statebits |= 0x2000; + swap->sleeptime = 1; + } } else if ( (swap->statebits & 0x4000) == 0 ) + { swap->statebits |= basilisk_swapdata_rawtxsend(myinfo,swap,0x8000,data,maxlen,&swap->bobpayment,0x4000); + swap->sleeptime = 1; + } // [BLOCKING: privM] Bob waits for privAm either from Alice or alice blockchain else if ( (swap->statebits & 0x40000) == 0 ) { @@ -820,6 +893,7 @@ void basilisk_swaploop(void *_swap) // set alicespend from bobpayment if ( basilisk_numconfirms(myinfo,&swap->alicespend) >= 0 || basilisk_swapget(myinfo,swap,0x40000,data,maxlen,basilisk_verify_privi) == 0 ) // divulges privAm { + swap->sleeptime = 1; if ( bits256_nonz(swap->privAm) == 0 ) swap->privAm = basilisk_privAm_extract(myinfo,swap,&swap->alicespend); swap->statebits |= 0x40000; @@ -832,6 +906,7 @@ void basilisk_swaploop(void *_swap) else if ( time(NULL) > swap->bobpayment.locktime ) { // submit reclaim of payment + swap->sleeptime = 1; swap->statebits |= (0x40000 | 0x80000); if ( basilisk_swapdata_rawtxsend(myinfo,swap,0,data,maxlen,&swap->bobreclaim,0) == 0 ) { @@ -844,6 +919,7 @@ void basilisk_swaploop(void *_swap) { if ( basilisk_numconfirms(myinfo,&swap->bobspend) >= swap->aliceconfirms ) { + swap->sleeptime = 1; swap->statebits |= 0x80000 | 0x100000; printf("Bob confirms spend of Alice's payment\n"); break; @@ -853,6 +929,7 @@ void basilisk_swaploop(void *_swap) { if ( basilisk_numconfirms(myinfo,&swap->bobreclaim) >= 1 ) { + swap->sleeptime = 1; swap->statebits |= 0x100000; printf("Bob confirms reclain of payment\n"); break; @@ -864,6 +941,7 @@ void basilisk_swaploop(void *_swap) // [BLOCKING: depfound] Alice waits for deposit to confirm and sends altpayment if ( (swap->statebits & 0x200) == 0 ) { + swap->sleeptime = 1; if ( basilisk_swapget(myinfo,swap,0x200,data,maxlen,basilisk_verify_bobdeposit) == 0 ) { // verify deposit and submit, set confirmed height @@ -873,11 +951,15 @@ void basilisk_swaploop(void *_swap) else if ( (swap->statebits & 0x400) == 0 ) { if ( basilisk_numconfirms(myinfo,&swap->bobdeposit) >= swap->bobconfirms ) + { swap->statebits |= 0x400; + swap->sleeptime = 1; + } } else if ( (swap->statebits & 0x800) == 0 ) { // set alicerefund from bobdeposit + swap->sleeptime = 1; swap->statebits |= basilisk_swapdata_rawtxsend(myinfo,swap,0x1000,data,maxlen,&swap->alicepayment,0x800); } // [BLOCKING: payfound] make sure payment is confrmed and send in claim or see bob's reclaim and reclaim @@ -886,6 +968,7 @@ void basilisk_swaploop(void *_swap) if ( basilisk_swapget(myinfo,swap,0x8000,data,maxlen,basilisk_verify_bobpaid) == 0 ) { // verify payment and submit, set confirmed height + swap->sleeptime = 1; swap->statebits |= 0x8000; } /*else if ( basilisk_numconfirms(myinfo,&swap->bobreclaim) >= 0 ) @@ -904,7 +987,10 @@ void basilisk_swaploop(void *_swap) } else */ if ( basilisk_numconfirms(myinfo,&swap->bobpayment) >= swap->bobconfirms ) - swap->statebits |= 0x10000; + { + swap->statebits |= 0x10000; + swap->sleeptime = 1; + } } else if ( (swap->statebits & 0x20000) == 0 ) { @@ -913,12 +999,14 @@ void basilisk_swaploop(void *_swap) for (j=datalen=0; j<32; j++) data[datalen++] = swap->privAm.bytes[j]; swap->statebits |= basilisk_swapsend(myinfo,swap,0x40000,data,datalen,0x20000); + swap->sleeptime = 1; } } else if ( (swap->statebits & 0x40000) == 0 ) { if ( basilisk_numconfirms(myinfo,&swap->alicespend) >= swap->bobconfirms ) { + swap->sleeptime = 1; swap->statebits |= 0x40000; printf("Alice confirms spend of Bob's payment\n"); break; @@ -926,9 +1014,8 @@ void basilisk_swaploop(void *_swap) } } } - if ( swap->iambob != 0 ) - sleep(1); - else sleep(3); + if ( swap->sleeptime > 0 ) + sleep(swap->sleeptime); } if ( swap->iambob != 0 ) { diff --git a/iguana/exchanges/bitcoin.h b/iguana/exchanges/bitcoin.h index b0152dcdf..49f623beb 100755 --- a/iguana/exchanges/bitcoin.h +++ b/iguana/exchanges/bitcoin.h @@ -25,6 +25,7 @@ #define SCRIPT_OP_TRUE 0x51 #define SCRIPT_OP_2 0x52 #define SCRIPT_OP_3 0x53 +#define SCRIPT_OP_4 0x54 #define SCRIPT_OP_IF 0x63 #define SCRIPT_OP_ELSE 0x67 #define SCRIPT_OP_RETURN 0x6a diff --git a/iguana/iguana_interpreter.c b/iguana/iguana_interpreter.c index b13d29fbb..616a1c460 100755 --- a/iguana/iguana_interpreter.c +++ b/iguana/iguana_interpreter.c @@ -810,7 +810,7 @@ int32_t iguana_checkmultisig(struct iguana_info *coin,struct iguana_interpreter int32_t iguana_checklocktimeverify(struct iguana_info *coin,int64_t nLockTime,uint32_t nSequence,struct iguana_stackdata Snum) { - int32_t num = iguana_num(Snum); + int64_t num = iguana_num(Snum); if ( num < 0 || (num >= 500000000 && nLockTime < 500000000) || (num < 500000000 && nLockTime >= 500000000) || nSequence == 0xffffffff || num > nLockTime ) return(-1); return(0); @@ -937,7 +937,7 @@ int32_t bitcoin_assembler(struct iguana_info *coin,cJSON *logarray,uint8_t scrip struct bitcoin_opcode *op; cJSON *array = 0; struct iguana_interpreter STACKS,*stacks = &STACKS; struct iguana_stackdata args[MAX_PUBKEYS_PER_MULTISIG]; uint8_t databuf[MAX_SCRIPT_ELEMENT_SIZE]; char *asmstr,*str,*hexstr; cJSON *item; - int32_t c,numops,plen,numvars,numused,numargs=0,i,j,k,n,len,val,datalen,errs=0; + int32_t c,numops,dlen,plen,numvars,numused,numargs=0,i,j,k,n,len,val,datalen,errs=0; iguana_optableinit(coin); if ( (asmstr= jstr(interpreter,"interpreter")) == 0 ) return(-1); @@ -974,10 +974,51 @@ int32_t bitcoin_assembler(struct iguana_info *coin,cJSON *logarray,uint8_t scrip if ( V->signers[i].siglen != 0 ) { plen = bitcoin_pubkeylen(V->signers[i].pubkey); - if ( V->spendscript[0] != plen || V->spendscript[V->spendlen - 1] != IGUANA_OP_CHECKSIG || bitcoin_pubkeylen(&V->spendscript[1]) <= 0 ) + 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); } } + if ( V->userdatalen != 0 ) + { + len = 0; + while ( len < V->userdatalen ) + { + dlen = V->userdata[len++]; + if ( dlen > 0 && dlen < 76 ) + iguana_pushdata(stacks,0,&V->userdata[len],dlen), len += dlen; + else if ( dlen >= IGUANA_OP_1 && dlen <= IGUANA_OP_16 ) + { + dlen -= 0x50; + iguana_pushdata(stacks,0,&V->userdata[len],dlen), len += dlen; + } + else if ( dlen == IGUANA_OP_PUSHDATA1 ) + { + iguana_pushdata(stacks,V->userdata[len++],0,0); + } + else if ( dlen == IGUANA_OP_PUSHDATA2 ) + { + iguana_pushdata(stacks,V->userdata[len] + ((int32_t)V->userdata[len+1]<<8),0,0); + len += 2; + } + else if ( dlen == IGUANA_OP_0 ) + iguana_pushdata(stacks,0,0,0); + else if ( dlen == IGUANA_OP_1NEGATE ) + iguana_pushdata(stacks,-1,0,0); + else + { + printf("invalid data opcode %d\n",dlen); + free(stacks); + return(-1); + } + printf("stackdepth.%d dlen.%d\n",stacks->stackdepth,dlen); + } + if ( len != V->userdatalen ) + { + printf("mismatched userdatalen %d vs %d\n",len,V->userdatalen); + free(stacks); + return(-1); + } + } if ( item != 0 && stacks->logarray != 0 ) { jaddstr(item,"spendasm",asmstr); @@ -1141,8 +1182,15 @@ 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; - else 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; @@ -1153,6 +1201,7 @@ int32_t bitcoin_assembler(struct iguana_info *coin,cJSON *logarray,uint8_t scrip 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 ) @@ -1161,8 +1210,10 @@ int32_t bitcoin_assembler(struct iguana_info *coin,cJSON *logarray,uint8_t scrip errs++; } stacks->ifdepth--; + printf("OP_ENDIF status.%d depth.%d\n",stacks->lastpath[stacks->ifdepth],stacks->stackdepth); + break; + case IGUANA_OP_VERIFY: break; - case IGUANA_OP_VERIFY: break; case IGUANA_OP_RETURN: iguana_pushdata(stacks,0,0,0); errs++; @@ -1172,11 +1223,16 @@ int32_t bitcoin_assembler(struct iguana_info *coin,cJSON *logarray,uint8_t scrip break; continue; } - if ( stacks->lastpath[stacks->ifdepth] < 0 ) + if ( stacks->lastpath[stacks->ifdepth] != 0 ) { - if ( stacks->logarray ) - jaddistr(stacks->logarray,"skip"); - continue; + if ( stacks->lastpath[stacks->ifdepth] < 0 ) + { + printf("SKIP opcode.%02x\n",op->opcode); + 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 ) { diff --git a/iguana/iguana_scripts.c b/iguana/iguana_scripts.c index 82f74858e..be62e5329 100755 --- a/iguana/iguana_scripts.c +++ b/iguana/iguana_scripts.c @@ -54,7 +54,11 @@ int32_t bitcoin_standardspend(uint8_t *script,int32_t n,uint8_t rmd160[20]) int32_t bitcoin_checklocktimeverify(uint8_t *script,int32_t n,uint32_t locktime) { - script[n++] = (locktime >> 24), script[n++] = (locktime >> 16), script[n++] = (locktime >> 8), script[n++] = locktime; + script[n++] = 4; + script[n++] = locktime & 0xff, locktime >>= 8; + script[n++] = locktime & 0xff, locktime >>= 8; + script[n++] = locktime & 0xff, locktime >>= 8; + script[n++] = locktime & 0xff; script[n++] = SCRIPT_OP_CHECKLOCKTIMEVERIFY; script[n++] = SCRIPT_OP_DROP; return(n); diff --git a/iguana/iguana_sign.c b/iguana/iguana_sign.c index 405d9df88..e707ff89b 100755 --- a/iguana/iguana_sign.c +++ b/iguana/iguana_sign.c @@ -618,25 +618,27 @@ int32_t iguana_msgtx_Vset(struct iguana_info *coin,uint8_t *serialized,int32_t m } } msgtx->vins[vini].scriptlen = scriptlen; + if ( vp->userdatalen != 0 ) + { + memcpy(&script[scriptlen],vp->userdata,vp->userdatalen); + scriptlen += vp->userdatalen; + } if ( (p2shlen= vp->p2shlen) > 0 ) { msgtx->vins[vini].redeemscript = &script[scriptlen]; - if ( vp->suppress_p2shlen == 0 ) + if ( p2shlen < 76 ) + script[scriptlen++] = p2shlen; + else if ( p2shlen <= 0xff ) { - if ( p2shlen < 76 ) - script[scriptlen++] = p2shlen; - else if ( p2shlen <= 0xff ) - { - script[scriptlen++] = 0x4c; - script[scriptlen++] = p2shlen; - } - else if ( p2shlen <= 0xffff ) - { - script[scriptlen++] = 0x4d; - script[scriptlen++] = (p2shlen & 0xff); - script[scriptlen++] = ((p2shlen >> 8) & 0xff); - } else return(-1); - } // else case is for custom script params + script[scriptlen++] = 0x4c; + script[scriptlen++] = p2shlen; + } + else if ( p2shlen <= 0xffff ) + { + script[scriptlen++] = 0x4d; + script[scriptlen++] = (p2shlen & 0xff); + script[scriptlen++] = ((p2shlen >> 8) & 0xff); + } else return(-1); memcpy(&script[scriptlen],vp->p2shscript,p2shlen), scriptlen += p2shlen; if ( (msgtx->vins[vini].suffixlen= vp->suffixlen) > 0 ) { @@ -706,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); } diff --git a/iguana/tests/decoderawtransaction b/iguana/tests/decoderawtransaction index e07275759..94b277fae 100755 --- a/iguana/tests/decoderawtransaction +++ b/iguana/tests/decoderawtransaction @@ -1 +1 @@ -curl --url "http://127.0.0.1:7778" --data "{\"coin\":\"BTC\",\"method\":\"decoderawtransaction\",\"params\":[\"0100000001eabdd66e8963e6fcfd190d14b8322da2241f7d5695db8e4b42dd09de96bc8026000000006a473044022061c085126ca9c59306c67c770ec878496703ba843f3f34673fc8699d4d136876022030d73ec533944b9ada33e31fbbd2905df08f175aed0168582ca7853fece991f7012102a9669e63ef1ab04913615c2f3887ea3584f81e5f08feee9535b19ab3739d8afdffffffff018ec20300000000001976a914b7128d2ee837cf03e30a2c0e3e0181f7b9669bb688ac00000000\"]}" +curl --url "http://127.0.0.1:7778" --data "{\"coin\":\"BTC\",\"method\":\"decoderawtransaction\",\"params\":[\"0100000001afa83a8601f8d86da02823fb39fac4e19f7fcdde276d7c529df94a6fe4067f6a000000008d483045022100f968fcbd1638f0004fa51ef75be60aeb300e0870c72bb85dcc99a6b097d155e30220436884335112fd84dc9837c7d979fc4a5d1220de584d987a799d8a349782ddd7012102a9669e63ef1ab04913615c2f3887ea3584f81e5f08feee9535b19ab3739d8afd204bdc874215f9a5d9793a7b7d36e3960d02d9f969a8d427e9845bc97a48ea41ad00ffffffff015dbc0300000000001976a914b7128d2ee837cf03e30a2c0e3e0181f7b9669bb688ac00000000\"]}" diff --git a/includes/iguana_structs.h b/includes/iguana_structs.h index 406573a80..a2c4c3267 100755 --- a/includes/iguana_structs.h +++ b/includes/iguana_structs.h @@ -421,9 +421,9 @@ struct vin_signer { bits256 privkey; char coinaddr[64]; uint8_t siglen,sig[80],r struct vin_info { struct iguana_msgvin vin; uint64_t amount; cJSON *extras; bits256 sigtxid; - int32_t M,N,validmask,spendlen,type,p2shlen,suffixlen,numpubkeys,numsigs,height,hashtype,suppress_p2shlen; + int32_t M,N,validmask,spendlen,type,p2shlen,suffixlen,numpubkeys,numsigs,height,hashtype,userdatalen,suppress_pubkeys; uint32_t sequence,unspentind; struct vin_signer signers[16]; char coinaddr[65]; - uint8_t rmd160[20],spendscript[IGUANA_MAXSCRIPTSIZE],p2shscript[IGUANA_MAXSCRIPTSIZE]; + uint8_t rmd160[20],spendscript[IGUANA_MAXSCRIPTSIZE],p2shscript[IGUANA_MAXSCRIPTSIZE],userdata[IGUANA_MAXSCRIPTSIZE]; }; struct bitcoin_unspent