From 1e159b40bd2a4a1fd2bda9ed57d15e9a6921cfbd Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 22 May 2016 00:36:38 -0500 Subject: [PATCH] test --- iguana/iguana_instantdex.c | 24 ++++++++++++++++-------- iguana/swaps/iguana_BTCswap.c | 8 ++++---- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/iguana/iguana_instantdex.c b/iguana/iguana_instantdex.c index 2d577ed58..c742f8527 100755 --- a/iguana/iguana_instantdex.c +++ b/iguana/iguana_instantdex.c @@ -455,11 +455,11 @@ char *instantdex_sendcmd(struct supernet_info *myinfo,struct instantdex_offer *o } } free(msg); - return(jprint(argjson,1)); + return(jprint(argjson,0)); } else { - free_json(argjson), free(msg); + free(msg); printf("cant msgcreate datalen.%d\n",datalen); return(clonestr("{\"error\":\"couldnt create instantdex message\"}")); } @@ -1177,7 +1177,7 @@ struct bitcoin_swapinfo *bitcoin_swapinit(struct supernet_info *myinfo,struct ex char *instantdex_checkoffer(struct supernet_info *myinfo,int32_t *addedp,uint64_t *txidp,struct exchange_info *exchange,struct instantdex_accept *ap,cJSON *argjson) { - struct instantdex_accept *otherap,*tmp; struct bitcoin_swapinfo *swap; cJSON *newjson; int32_t isbob = 0; + struct instantdex_accept *otherap,*tmp; struct bitcoin_swapinfo *swap; cJSON *newjson; int32_t isbob = 0; char *retstr = 0; *addedp = 0; if ( exchange == 0 ) { @@ -1229,10 +1229,11 @@ char *instantdex_checkoffer(struct supernet_info *myinfo,int32_t *addedp,uint64_ if ( (newjson= instantdex_parseargjson(myinfo,exchange,swap,argjson,1)) == 0 ) return(clonestr("{\"error\":\"instantdex_checkoffer null newjson\"}")); instantdex_statemachineadd(exchange,swap); - return(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); + free_json(newjson); } else printf("error creating statemachine\n"); } - return(0); + return(retstr); } char *instantdex_gotoffer(struct supernet_info *myinfo,struct exchange_info *exchange,struct instantdex_accept *myap,struct instantdex_accept *otherap,struct instantdex_msghdr *msg,cJSON *argjson,char *remoteaddr,uint64_t signerbits,uint8_t *serdata,int32_t serdatalen) // receiving side @@ -1276,10 +1277,14 @@ char *instantdex_gotoffer(struct supernet_info *myinfo,struct exchange_info *exc //queue_enqueue("acceptableQ",&exchange->acceptableQ,&swap->DL,0); instantdex_statemachineadd(exchange,swap); if ( (retstr= instantdex_choosei(swap,newjson,argjson,serdata,serdatalen)) != 0 ) + { + free_json(newjson); return(retstr); + } else { - return(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); + free_json(newjson); } } return(retstr); @@ -1336,7 +1341,6 @@ char *instantdex_parse(struct supernet_info *myinfo,struct instantdex_msghdr *ms queue_enqueue("eventQ",&swap->eventsQ,&ptr->DL,0); free_json(newjson); return(clonestr("{\"result\":\"updated statemachine\"}")); - //return(instantdex_statemachine(BTC_states,BTC_numstates,myinfo,exchange,swap,cmdstr,argjson,newjson,serdata,serdatalen)); } else if ( strcmp(cmdstr,"BTCoffer") == 0 ) // incoming { @@ -1567,7 +1571,11 @@ THREE_STRINGS(atomic,approve,myorderid,otherid,txname) newjson = cJSON_CreateObject(); if ( (retstr= instantdex_sendcmd(myinfo,&swap->mine.offer,newjson,virtualevent,myinfo->myaddr.persistent,0,0,0,0)) != 0 ) return(retstr); - else return(clonestr("{\"result\":\"statemachine sent found event\"}")); + else + { + free_json(newjson); + return(clonestr("{\"result\":\"statemachine sent found event\"}")); + } } } diff --git a/iguana/swaps/iguana_BTCswap.c b/iguana/swaps/iguana_BTCswap.c index 2dc6a0fa6..e2f9f55b1 100755 --- a/iguana/swaps/iguana_BTCswap.c +++ b/iguana/swaps/iguana_BTCswap.c @@ -611,7 +611,7 @@ double iguana_numconfs(struct iguana_info *coin,bits256 txid,int32_t height) char *BTC_txconfirmed(struct supernet_info *myinfo,struct iguana_info *coin,struct bitcoin_swapinfo *swap,cJSON *newjson,bits256 txid,double *numconfirmsp,char *virtualevent,double requiredconfs) { - int32_t height,firstvout; char *retstr; double confs; + int32_t height,firstvout; char *retstr = 0; double confs; *numconfirmsp = -1.; if ( coin != 0 && *numconfirmsp < 0 ) { @@ -1025,7 +1025,7 @@ char *instantdex_statemachine(struct instantdex_stateinfo *states,int32_t numsta swap->state = &states[state->timeoutind]; if ( (newjson= (*state->timeout)(myinfo,exchange,swap,argjson,newjson,&serdata,&serdatalen)) == 0 ) return(clonestr("{\"error\":\"instantdex_BTCswap null return from timeoutfunc\"}")); - else return(jprint(newjson,1)); + else return(jprint(newjson,0)); } for (i=0; inumevents; i++) { @@ -1077,7 +1077,7 @@ void instantdex_statemachine_iter(struct supernet_info *myinfo,struct exchange_i while ( (ptr= queue_dequeue(&swap->eventsQ,0)) != 0 ) { printf("dequeued (%s)\n",ptr->cmd); - if ( (str= instantdex_statemachine(BTC_states,BTC_numstates,myinfo,exchange,swap,ptr->cmd,ptr->argjson,jduplicate(ptr->newjson),ptr->serdata,ptr->serdatalen)) != 0 ) + if ( (str= instantdex_statemachine(BTC_states,BTC_numstates,myinfo,exchange,swap,ptr->cmd,ptr->argjson,ptr->newjson,ptr->serdata,ptr->serdatalen)) != 0 ) free(str); instantdex_eventfree(ptr); flag++; @@ -1085,7 +1085,7 @@ void instantdex_statemachine_iter(struct supernet_info *myinfo,struct exchange_i if ( flag == 0 && swap->pollevent != 0 ) { printf("send poll event\n"); - if ( (str= instantdex_statemachine(BTC_states,BTC_numstates,myinfo,exchange,swap,"poll",swap->pollevent->argjson,jduplicate(swap->pollevent->newjson),swap->pollevent->serdata,swap->pollevent->serdatalen)) != 0 ) + if ( (str= instantdex_statemachine(BTC_states,BTC_numstates,myinfo,exchange,swap,"poll",swap->pollevent->argjson,swap->pollevent->newjson,swap->pollevent->serdata,swap->pollevent->serdatalen)) != 0 ) free(str); } }