diff --git a/iguana/exchanges777.h b/iguana/exchanges777.h index e5bda4994..b15cc375d 100755 --- a/iguana/exchanges777.h +++ b/iguana/exchanges777.h @@ -200,7 +200,7 @@ double fxcm_price(struct exchange_info *exchange,char *base,char *rel,struct exc double instaforex_price(struct exchange_info *exchange,char *base,char *rel,struct exchange_quote *bidasks,int32_t maxdepth,double commission,cJSON *argjson,int32_t invert); char *instantdex_createaccept(struct supernet_info *myinfo,struct instantdex_accept **aptrp,struct exchange_info *exchange,char *base,char *rel,double price,double basevolume,int32_t acceptdir,char *mysidestr,int32_t duration,uint64_t offerer,uint8_t minperc); -char *instantdex_sendcmd(struct supernet_info *myinfo,struct instantdex_offer *offer,cJSON *argjson,char *cmdstr,bits256 desthash,int32_t hops,void *extra,int32_t extralen,struct iguana_peer *addr); +char *instantdex_sendcmd(struct supernet_info *myinfo,struct instantdex_offer *offer,cJSON *argjson,char *cmdstr,bits256 desthash,int32_t hops,void *extra,int32_t extralen,struct iguana_peer *addr,struct bitcoin_swapinfo *swap); char *instantdex_sendoffer(struct supernet_info *myinfo,struct exchange_info *exchange,struct instantdex_accept *ap,cJSON *argjson); // Bob sending to network (Alice) struct bitcoin_swapinfo *instantdex_statemachinefind(struct supernet_info *myinfo,struct exchange_info *exchange,uint64_t orderid); char *instantdex_checkoffer(struct supernet_info *myinfo,int32_t *addedp,uint64_t *txidp,struct exchange_info *exchange,struct instantdex_accept *ap,cJSON *json); diff --git a/iguana/iguana777.c b/iguana/iguana777.c index ad869c4db..a077e8c86 100755 --- a/iguana/iguana777.c +++ b/iguana/iguana777.c @@ -561,10 +561,18 @@ int32_t iguana_utxogen(struct iguana_info *coin,int32_t helperid,int32_t convert void iguana_helper(void *arg) { + static int32_t maxhelperid; cJSON *argjson=0; int32_t iter,i,n,j,polltimeout,type,helperid=rand(),flag,allcurrent,idle=0; struct iguana_helper *ptr; struct iguana_info *coin; struct OS_memspace MEM,*MEMB; struct iguana_bundle *bp; if ( arg != 0 && (argjson= cJSON_Parse(arg)) != 0 ) helperid = juint(argjson,"helperid"); + if ( helperid > maxhelperid ) + maxhelperid = helperid; + if ( helperid < maxhelperid ) + { + printf("SKIP duplicate helper.%d\n",helperid); + return; + } if ( IGUANA_NUMHELPERS < 2 ) type = 3; else type = (1 << (helperid % 2)); diff --git a/iguana/iguana_instantdex.c b/iguana/iguana_instantdex.c index 0c5e2e8aa..9e212f35f 100755 --- a/iguana/iguana_instantdex.c +++ b/iguana/iguana_instantdex.c @@ -387,7 +387,7 @@ bits256 instantdex_rwoffer(int32_t rwflag,int32_t *lenp,uint8_t *serialized,stru return(orderhash); } -char *instantdex_sendcmd(struct supernet_info *myinfo,struct instantdex_offer *offer,cJSON *argjson,char *cmdstr,bits256 desthash,int32_t hops,void *extraser,int32_t extralen,struct iguana_peer *addr) +char *instantdex_sendcmd(struct supernet_info *myinfo,struct instantdex_offer *offer,cJSON *argjson,char *cmdstr,bits256 desthash,int32_t hops,void *extraser,int32_t extralen,struct iguana_peer *addr,struct bitcoin_swapinfo *swap) { char *reqstr,*hexstr,*retstr; struct instantdex_msghdr *msg; bits256 orderhash; struct iguana_info *coin; int32_t i,olen,slen,datalen,max=-1; uint8_t serialized[sizeof(*offer) + sizeof(struct iguana_msghdr) + 4096 + INSTANTDEX_DECKSIZE*33]; uint64_t nxt64bits; //if ( strcmp(cmdstr,"poll") == 0 ) @@ -416,15 +416,24 @@ char *instantdex_sendcmd(struct supernet_info *myinfo,struct instantdex_offer *o reqstr = jprint(argjson,0); slen = (int32_t)(strlen(reqstr) + 1); datalen = (int32_t)slen + extralen + olen; - msg = calloc(1,datalen + sizeof(*msg)); + msg = calloc(1,datalen + sizeof(*msg) + sizeof(swap->deck)); for (i=0; icmd); i++) if ( (msg->cmd[i]= cmdstr[i]) == 0 ) break; memcpy(msg->serialized,reqstr,slen); memcpy(&msg->serialized[slen],serialized,olen); //printf("extralen.%d datalen.%d slen.%d olen.%d\n",extralen,datalen,slen,olen); + extraser = (void *)swap->deck; + extralen = (int32_t)sizeof(swap->deck); if ( extralen > 0 ) + { + //if ( swap->otherchoosei < 0 ) + { + //serdata = (void *)swap->deck; + //serdatalen = (int32_t)sizeof(swap->deck); + } memcpy(&msg->serialized[slen + olen],extraser,extralen); + } free(reqstr); if ( instantdex_msgcreate(myinfo,msg,datalen) != 0 ) { @@ -1233,7 +1242,7 @@ char *instantdex_checkoffer(struct supernet_info *myinfo,int32_t *addedp,uint64_ if ( swap->pollevent != 0 ) instantdex_eventfree(swap->pollevent); swap->pollevent = instantdex_event("poll",argjson,newjson,(void *)swap->deck,sizeof(swap->deck)); - retstr = instantdex_sendcmd(myinfo,&swap->mine.offer,newjson,"BTCoffer",GENESIS_PUBKEY,INSTANTDEX_HOPS,swap->deck,sizeof(swap->deck),0); + retstr = instantdex_sendcmd(myinfo,&swap->mine.offer,newjson,"BTCoffer",GENESIS_PUBKEY,INSTANTDEX_HOPS,swap->deck,sizeof(swap->deck),0,swap); free_json(newjson); } else printf("error creating statemachine\n"); portable_mutex_unlock(&swap->mutex); @@ -1295,7 +1304,7 @@ char *instantdex_gotoffer(struct supernet_info *myinfo,struct exchange_info *exc if ( swap->pollevent != 0 ) instantdex_eventfree(swap->pollevent); swap->pollevent = instantdex_event("poll",argjson,newjson,(void *)swap->deck,sizeof(swap->deck)); - retstr = instantdex_sendcmd(myinfo,&swap->mine.offer,newjson,"BTCdeckC",traderpub,INSTANTDEX_HOPS,swap->deck,sizeof(swap->deck),0); + retstr = instantdex_sendcmd(myinfo,&swap->mine.offer,newjson,"BTCdeckC",traderpub,INSTANTDEX_HOPS,swap->deck,sizeof(swap->deck),0,swap); free_json(newjson); } } @@ -1574,7 +1583,7 @@ THREE_STRINGS(atomic,approve,myorderid,otherid,txname) strcpy(virtualevent,txname); strcat(virtualevent,"found"); newjson = cJSON_CreateObject(); - if ( (retstr= instantdex_sendcmd(myinfo,&swap->mine.offer,newjson,virtualevent,myinfo->myaddr.persistent,0,0,0,0)) != 0 ) + if ( (retstr= instantdex_sendcmd(myinfo,&swap->mine.offer,newjson,virtualevent,myinfo->myaddr.persistent,0,0,0,0,swap)) != 0 ) return(retstr); else { diff --git a/iguana/swaps/iguana_BTCswap.c b/iguana/swaps/iguana_BTCswap.c index 64f7a1a1b..920589e6a 100755 --- a/iguana/swaps/iguana_BTCswap.c +++ b/iguana/swaps/iguana_BTCswap.c @@ -730,7 +730,7 @@ char *BTC_txconfirmed(struct supernet_info *myinfo,struct iguana_info *coin,stru if ( (firstvout= iguana_unspentindfind(coin,0,0,0,0,&height,txid,0,coin->bundlescount-1)) != 0 && (confs= iguana_numconfs(coin,txid,height)) >= requiredconfs ) { *numconfirmsp = confs; - if ( (retstr= instantdex_sendcmd(myinfo,&swap->mine.offer,newjson,virtualevent,myinfo->myaddr.persistent,0,0,0,0)) != 0 ) + if ( (retstr= instantdex_sendcmd(myinfo,&swap->mine.offer,newjson,virtualevent,myinfo->myaddr.persistent,0,0,0,0,swap)) != 0 ) return(retstr); } } @@ -1262,12 +1262,7 @@ char *instantdex_statemachine(struct instantdex_stateinfo *states,int32_t numsta instantdex_newjson(myinfo,swap,newjson); printf("i.%d (%s) %s %s.%d -> %s.%d send.(%s) %p\n",i,jprint(newjson,0),cmdstr,swap->state->name,state->ind,states[state->events[i].nextstateind].name,state->events[i].nextstateind,state->events[i].sendcmd,&states[state->events[i].nextstateind]); swap->state = &states[state->events[i].nextstateind]; - if ( swap->otherchoosei < 0 ) - { - serdata = (void *)swap->deck; - serdatalen = (int32_t)sizeof(swap->deck); - } - return(instantdex_sendcmd(myinfo,&swap->mine.offer,newjson,state->events[i].sendcmd,swap->othertrader,INSTANTDEX_HOPS,serdata,serdatalen,0)); + return(instantdex_sendcmd(myinfo,&swap->mine.offer,newjson,state->events[i].sendcmd,swap->othertrader,INSTANTDEX_HOPS,serdata,serdatalen,0,swap)); } else return(clonestr("{\"error\":\"instantdex_statemachine: illegal state\"}")); } else return(clonestr("{\"result\":\"instantdex_statemachine: processed\"}")); }