From 4ade6b63d023b0d81a7108a828bef10093983bd9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 7 Jul 2016 07:09:24 -0300 Subject: [PATCH] test --- basilisk/basilisk_swap.c | 22 +++++++++++++++++++--- iguana/iguana_interpreter.c | 4 ++-- iguana/iguana_payments.c | 11 ++++++++--- iguana/iguana_realtime.c | 2 +- iguana/iguana_volatiles.c | 4 ---- iguana/iguana_wallet.c | 2 ++ iguana/tests/walletpassphrase | 2 +- 7 files changed, 33 insertions(+), 14 deletions(-) diff --git a/basilisk/basilisk_swap.c b/basilisk/basilisk_swap.c index fa2976db3..7b3f93474 100755 --- a/basilisk/basilisk_swap.c +++ b/basilisk/basilisk_swap.c @@ -78,6 +78,7 @@ int32_t basilisk_bobscript(uint8_t *script,int32_t n,uint32_t *locktimep,int32_t pubkeyA[0] = 0x03; pubkeyB[0] = 0x02; } + char str[65]; printf("bobtx dflag.%d %s\n",depositflag,bits256_str(str,cltvpub)); if ( bits256_nonz(cltvpub) == 0 || bits256_nonz(destpub) == 0 ) return(-1); for (i=0; i<20; i++) @@ -113,19 +114,27 @@ 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,bits256 *privkey2,uint8_t *userdata,int32_t userdatalen) { - char *rawtxbytes,*signedtx,hexstr[999],wifstr[128]; cJSON *txobj,*vins,*item,*sobj,*privkeys; int32_t retval = -1; 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; uint32_t locktime=0; memset(&V,0,sizeof(V)); + if ( dest == &swap->aliceclaim ) + locktime = swap->locktime + INSTANTDEX_LOCKTIME; V.signers[0].privkey = privkey; privkeys = cJSON_CreateArray(); bitcoin_priv2wif(wifstr,privkey,rawtx->coin->chain->wiftype); jaddistr(privkeys,wifstr); + if ( privkey2 != 0 ) + { + V.signers[1].privkey = *privkey2; + bitcoin_priv2wif(wifstr,*privkey2,rawtx->coin->chain->wiftype); + jaddistr(privkeys,wifstr); + } if ( userdata != 0 && userdatalen > 0 ) { V.suppress_pubkeys = rawtx->suppress_pubkeys; memcpy(V.userdata,userdata,userdatalen); V.userdatalen = userdatalen; } - txobj = bitcoin_txcreate(rawtx->coin->chain->isPoS,0,1); + txobj = bitcoin_txcreate(rawtx->coin->chain->isPoS,locktime,rawtx->coin->chain->locktime_txversion); vins = cJSON_CreateArray(); item = cJSON_CreateObject(); if ( bits256_nonz(rawtx->actualtxid) != 0 ) @@ -136,10 +145,12 @@ int32_t basilisk_rawtx_spend(struct supernet_info *myinfo,struct basilisk_swap * init_hexbytes_noT(hexstr,rawtx->spendscript,rawtx->spendlen); jaddstr(sobj,"hex",hexstr); jadd(item,"scriptPubKey",sobj); + if ( locktime != 0 ) + jaddnum(item,"sequence",0); jaddi(vins,item); jdelete(txobj,"vin"); jadd(txobj,"vin",vins); - printf("basilisk_rawtx_spend for %s spendscript.%s -> %s\n",rawtx->name,hexstr,dest->name); + printf("basilisk_rawtx_spend locktime.%u/%u for %s spendscript.%s -> %s\n",rawtx->locktime,dest->locktime,rawtx->name,hexstr,dest->name); txobj = bitcoin_txoutput(txobj,dest->spendscript,dest->spendlen,dest->amount); if ( (rawtxbytes= bitcoin_json2hex(myinfo,rawtx->coin,&dest->txid,txobj,&V)) != 0 ) { @@ -195,6 +206,7 @@ int32_t basilisk_rawtx_spendscript(struct supernet_info *myinfo,struct basilisk_ } if ( (txobj= bitcoin_data2json(rawtx->coin,&rawtx->signedtxid,&rawtx->msgtx,rawtx->extraspace,sizeof(rawtx->extraspace),rawtx->txbytes,rawtx->datalen)) != 0 ) { + rawtx->locktime = rawtx->msgtx.lock_time; if ( (vouts= jarray(&n,txobj,"vout")) != 0 && v < n ) { vout = jitem(vouts,v); @@ -418,6 +430,8 @@ int32_t basilisk_rawtx_gen(char *str,struct supernet_info *myinfo,struct basilis jaddnum(valsobj,"minconf",minconf); jaddnum(valsobj,"locktime",locktime); jaddnum(valsobj,"timeout",30000); + rawtx->locktime = locktime; + printf("%s locktime.%u\n",rawtx->name,locktime); if ( (retstr= basilisk_rawtx(myinfo,rawtx->coin,0,0,myinfo->myaddr.persistent,valsobj,"")) != 0 ) { //printf("%s got.(%s)\n",str,retstr); @@ -664,6 +678,7 @@ int32_t basilisk_verify_choosei(struct supernet_info *myinfo,struct basilisk_swa swap->pubA0.bytes[i] = data[len++]; for (i=0; i<32; i++) swap->pubA1.bytes[i] = data[len++]; + char str[65]; printf("GOT pubA0/1 %s\n",bits256_str(str,swap->pubA0)); } else { @@ -844,6 +859,7 @@ void basilisk_swaploop(void *_swap) data[datalen++] = swap->pubA0.bytes[i]; for (i=0; i<32; i++) data[datalen++] = swap->pubA1.bytes[i]; + char str[65]; printf("SEND pubA0/1 %s\n",bits256_str(str,swap->pubA0)); } swap->statebits |= basilisk_swapsend(myinfo,swap,0x08,data,datalen,0x04); } diff --git a/iguana/iguana_interpreter.c b/iguana/iguana_interpreter.c index bdcafe188..2ed1b6cc4 100755 --- a/iguana/iguana_interpreter.c +++ b/iguana/iguana_interpreter.c @@ -498,7 +498,7 @@ static int32_t iguana_pushdata(struct iguana_interpreter *stacks,int64_t num64,u struct iguana_stackdata Snum; cJSON *item = 0; char tmpstr[2048]; int32_t num = (int32_t)num64; if ( stacks->lastpath[stacks->ifdepth] < 0 ) return(0); - printf("PUSH.(%lld %p %d\n",(long long)num64,numbuf,numlen); + printf("PUSH.(%lld %p %d)\n",(long long)num64,numbuf,numlen); if ( stacks->maxstackdepth > 0 ) { /*if ( numbuf != 0 ) @@ -817,7 +817,7 @@ int32_t iguana_checkmultisig(struct iguana_info *coin,struct iguana_interpreter int32_t iguana_checklocktimeverify(struct iguana_info *coin,int64_t tx_lockval,uint32_t nSequence,struct iguana_stackdata Snum) { int64_t nLockTime = iguana_num(Snum); - if ( nLockTime < 0 ) + if ( nLockTime < 0 || tx_lockval < 0 ) return(-1); else if ( ((tx_lockval < LOCKTIME_THRESHOLD && nLockTime < LOCKTIME_THRESHOLD) || (tx_lockval >= LOCKTIME_THRESHOLD && nLockTime >= LOCKTIME_THRESHOLD)) == 0 ) diff --git a/iguana/iguana_payments.c b/iguana/iguana_payments.c index fe4275137..24c29fe42 100755 --- a/iguana/iguana_payments.c +++ b/iguana/iguana_payments.c @@ -1023,9 +1023,14 @@ cJSON *iguana_createvins(struct supernet_info *myinfo,struct iguana_info *coin,c init_hexbytes_noT(scriptstr,redeemscript,p2shlen); jaddstr(newvin,"redeemScript",scriptstr); } - if ( jobj(item,"sequence") != 0 ) - sequenceid = juint(item,"sequence"); - else sequenceid = 0xffffffff; + if ( jint(txobj,"locktime") > 0 ) + sequenceid = (uint32_t)time(NULL); // any value < 0xfffffffe should be fine + else + { + if ( jobj(item,"sequence") != 0 ) + sequenceid = juint(item,"sequence"); + else sequenceid = 0xffffffff; + } jaddnum(newvin,"sequence",sequenceid); bitcoin_txinput(coin,txobj,txid,vout,sequenceid,spendscript,spendlen,redeemscript,p2shlen,0,0); jadd(newvin,"pubkeys",pubkeys); diff --git a/iguana/iguana_realtime.c b/iguana/iguana_realtime.c index 6d053e0e6..07bbc4aa6 100755 --- a/iguana/iguana_realtime.c +++ b/iguana/iguana_realtime.c @@ -29,7 +29,6 @@ void iguana_RTramchainfree(struct iguana_info *coin,struct iguana_bundle *bp) bp->ramchain = coin->RTramchain; iguana_mempurge(&coin->RTmem); iguana_mempurge(&coin->RThashmem); - coin->RTdatabad = 0; for (hdrsi=coin->bundlescount-1; hdrsi>0; hdrsi--) if ( (bp= coin->bundles[hdrsi]) == 0 && bp != coin->current ) { @@ -37,6 +36,7 @@ void iguana_RTramchainfree(struct iguana_info *coin,struct iguana_bundle *bp) if ( iguana_volatilesmap(coin,&bp->ramchain) != 0 ) printf("error mapping bundle.[%d]\n",hdrsi); } + coin->RTdatabad = 0; printf("done RTramchain\n"); } } diff --git a/iguana/iguana_volatiles.c b/iguana/iguana_volatiles.c index 2b0ec1a8b..9bd5c70fa 100755 --- a/iguana/iguana_volatiles.c +++ b/iguana/iguana_volatiles.c @@ -221,10 +221,6 @@ int32_t iguana_volatileupdate(struct iguana_info *coin,int32_t incremental,struc coin->spendvectorsaved = 0; coin->started = 0; coin->active = 0; - int32_t i; struct iguana_bundle *bp; - for (i=0; ibundlescount; i++) - if ( (bp= coin->bundles[i]) != 0 ) - iguana_RTramchainfree(coin,bp); } else printf("volatileupdate error null rdata [%d]\n",spentchain->height/coin->current->bundleheight); return(-1); } diff --git a/iguana/iguana_wallet.c b/iguana/iguana_wallet.c index c4b10c933..24c7faa25 100755 --- a/iguana/iguana_wallet.c +++ b/iguana/iguana_wallet.c @@ -1069,8 +1069,10 @@ TWOSTRINGS_AND_INT(bitcoinrpc,walletpassphrase,password,permanentfile,timeout) return(clonestr("{\"error\":\"no remote\"}")); if ( timeout <= 0 ) return(clonestr("{\"error\":\"timeout must be positive\"}")); + printf("timeout.%d\n",timeout); myinfo->expiration = (uint32_t)time(NULL) + timeout; retstr = SuperNET_login(IGUANA_CALLARGS,myinfo->handle,password,permanentfile,0); + myinfo->expiration = (uint32_t)time(NULL) + timeout; iguana_walletinitcheck(myinfo,coin); return(retstr); } diff --git a/iguana/tests/walletpassphrase b/iguana/tests/walletpassphrase index 16c6669bf..d5c8f0fcb 100755 --- a/iguana/tests/walletpassphrase +++ b/iguana/tests/walletpassphrase @@ -1,2 +1,2 @@ #curl --url "http://127.0.0.1:7778" --data "{\"method\":\"walletpassphrase\",\"params\":[\"test\", 600]}" -curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"bitcoinrpc\",\"method\":\"walletpassphrase\",\"password\":\"test\",\"timeout\":300}" +curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"bitcoinrpc\",\"method\":\"walletpassphrase\",\"password\":\"test\",\"timeout\":86444}"