From bf3ced623c1919823368695f06aa93b2df0e560f Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 23 May 2016 14:08:31 -0500 Subject: [PATCH] test --- iguana/SuperNET.c | 15 +++++++++++++++ iguana/exchanges777.h | 2 +- iguana/iguana_instantdex.c | 4 +++- iguana/swaps/iguana_BTCswap.c | 14 +++++--------- includes/iguana_apideclares.h | 1 + 5 files changed, 25 insertions(+), 11 deletions(-) diff --git a/iguana/SuperNET.c b/iguana/SuperNET.c index 0a79c82f0..67fcee9c4 100755 --- a/iguana/SuperNET.c +++ b/iguana/SuperNET.c @@ -966,6 +966,21 @@ STRING_ARG(SuperNET,addr2rmd160,address) return(jprint(retjson,1)); } +STRING_ARG(SuperNET,rmd160conv,rmd160) +{ + uint8_t rmdbuf[20]; char coinaddr[64],p2shaddr[64]; cJSON *retjson = cJSON_CreateObject(); + if ( rmd160 != 0 && strlen(rmd160) == 40 ) + { + decode_hex(rmdbuf,20,rmd160); + bitcoin_address(coinaddr,coin->chain->pubtype,rmdbuf,20); + bitcoin_address(p2shaddr,coin->chain->p2shtype,rmdbuf,20); + jaddstr(retjson,"result","success"); + jaddstr(retjson,"address",coinaddr); + jaddstr(retjson,"p2sh",p2shaddr); + } + return(jprint(retjson,1)); +} + HASH_AND_INT(SuperNET,priv2pub,privkey,addrtype) { cJSON *retjson; bits256 pub; uint8_t pubkey[33]; char coinaddr[64],pubkeystr[67]; diff --git a/iguana/exchanges777.h b/iguana/exchanges777.h index ba7f22c25..4c29673db 100755 --- a/iguana/exchanges777.h +++ b/iguana/exchanges777.h @@ -164,7 +164,7 @@ struct bitcoin_swapinfo struct bitcoin_swapinfo *next,*prev; queue_t eventsQ; struct bitcoin_eventitem *pollevent; bits256 privkeys[INSTANTDEX_DECKSIZE+2],mypubs[2],otherpubs[2],privAm,pubAm,privBn,pubBn; - bits256 myorderhash,otherorderhash,mypubkey,othertrader; + bits256 myorderhash,otherorderhash,mypubkey,othertrader,bothorderhash; uint64_t otherdeck[INSTANTDEX_DECKSIZE][2],deck[INSTANTDEX_DECKSIZE][2]; uint64_t altsatoshis,BTCsatoshis,insurance,altinsurance; int32_t choosei,otherchoosei,cutverified,otherverifiedcut,numpubs,havestate,otherhavestate; diff --git a/iguana/iguana_instantdex.c b/iguana/iguana_instantdex.c index 3ef422b18..467923849 100755 --- a/iguana/iguana_instantdex.c +++ b/iguana/iguana_instantdex.c @@ -1140,7 +1140,7 @@ int32_t instantdex_acceptextract(struct instantdex_accept *ap,cJSON *argjson) struct bitcoin_swapinfo *bitcoin_swapinit(struct supernet_info *myinfo,struct exchange_info *exchange,struct instantdex_accept *myap,struct instantdex_accept *otherap,int32_t aminitiator,cJSON *argjson,char *statename) { - struct bitcoin_swapinfo *swap = 0; struct iguana_info *coinbtc,*altcoin; + struct bitcoin_swapinfo *swap = 0; struct iguana_info *coinbtc,*altcoin; int32_t i; swap = calloc(1,sizeof(struct bitcoin_swapinfo)); swap->state = instantdex_statefind(BTC_states,BTC_numstates,statename); swap->mine = *myap, swap->other = *otherap; @@ -1149,6 +1149,8 @@ struct bitcoin_swapinfo *bitcoin_swapinit(struct supernet_info *myinfo,struct ex strcpy(swap->status,"pending"); vcalc_sha256(0,swap->myorderhash.bytes,(void *)&swap->mine.offer,sizeof(swap->mine.offer)); vcalc_sha256(0,swap->otherorderhash.bytes,(void *)&swap->other.offer,sizeof(swap->other.offer)); + for (i=0; i<4; i++) + swap->bothorderhash.ulongs[i] = (swap->myorderhash.ulongs[i] ^ swap->otherorderhash.ulongs[i]); swap->mypubkey = myinfo->myaddr.persistent; swap->othertrader = jbits256(argjson,"traderpub"); swap->altsatoshis = myap->offer.basevolume64; diff --git a/iguana/swaps/iguana_BTCswap.c b/iguana/swaps/iguana_BTCswap.c index 3db92ebaa..6be6b916f 100755 --- a/iguana/swaps/iguana_BTCswap.c +++ b/iguana/swaps/iguana_BTCswap.c @@ -443,13 +443,12 @@ int32_t instantdex_pubkeyargs(struct supernet_info *myinfo,struct bitcoin_swapin //printf("i.%d n.%d numpubs.%d %02x vs %02x\n",i,n,numpubs,pubkey[0],firstbyte); if ( pubkey[0] != firstbyte ) continue; - if ( n < 2 && numpubs > 2 ) + if ( n < 2 ) { - sprintf(buf+1,"%d",n); - if ( jobj(newjson,buf) == 0 ) - jaddbits256(newjson,buf,pubi); + if ( bits256_nonz(swap->mypubs[n]) == 0 ) + memcpy(swap->mypubs[n].bytes,pubkey+1,sizeof(bits256)); } - else if ( swap->numpubs < INSTANTDEX_DECKSIZE ) + if ( swap->numpubs < INSTANTDEX_DECKSIZE ) { calc_rmd160_sha256(secret160,swap->privkeys[n].bytes,sizeof(swap->privkeys[n])); memcpy(&txid,secret160,sizeof(txid)); @@ -1079,7 +1078,7 @@ void instantdex_eventfree(struct bitcoin_eventitem *ptr) char *instantdex_statemachine(struct instantdex_stateinfo *states,int32_t numstates,struct supernet_info *myinfo,struct exchange_info *exchange,struct bitcoin_swapinfo *swap,char *cmdstr,cJSON *argjson,cJSON *newjson,uint8_t *serdata,int32_t serdatalen) { - uint32_t i,j; struct iguana_info *altcoin=0,*coinbtc=0; struct instantdex_stateinfo *state=0; + uint32_t i; struct iguana_info *altcoin=0,*coinbtc=0; struct instantdex_stateinfo *state=0; if ( swap == 0 || (state= swap->state) == 0 || (coinbtc= iguana_coinfind("BTC")) == 0 || (altcoin= iguana_coinfind(swap->mine.offer.base)) == 0 ) { printf("state.%s btc.%p altcoin.%p (%s)\n",state->name,coinbtc,altcoin,swap->mine.offer.base); @@ -1164,9 +1163,6 @@ char *instantdex_statemachine(struct instantdex_stateinfo *states,int32_t numsta jaddbits256(newjson,"pubBn",swap->pubBn); if ( bits256_nonz(swap->privBn) != 0 ) jaddbits256(newjson,"privn",swap->privBn); - for (j=0; j<2; j++) - if ( bits256_nonz(swap->mypubs[j]) == 0 ) - swap->mypubs[j] = rand256(0); if ( instantdex_isbob(swap) == 0 ) { if ( (swap->otherhavestate & INSTANTDEX_ORDERSTATE_HAVEALTPAYMENT) == 0 && swap->altpayment != 0 && jobj(newjson,"altpayment") == 0 ) diff --git a/includes/iguana_apideclares.h b/includes/iguana_apideclares.h index 256a07bfb..1381d30e8 100755 --- a/includes/iguana_apideclares.h +++ b/includes/iguana_apideclares.h @@ -190,6 +190,7 @@ HASH_AND_INT(SuperNET,priv2pub,privkey,addrtype); STRING_ARG(SuperNET,wif2priv,wif); STRING_ARG(SuperNET,priv2wif,priv); STRING_ARG(SuperNET,addr2rmd160,address); +STRING_ARG(SuperNET,rmd160conv,rmd160); TWOHASHES_AND_STRING(SuperNET,cipher,privkey,destpubkey,message); TWOHASHES_AND_STRING(SuperNET,decipher,privkey,srcpubkey,cipherstr);