From 26506f8c3596f86a65b8ca5c46101187d1268f41 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 16 Feb 2016 06:13:19 -0300 Subject: [PATCH] test --- iguana/iguana_instantdex.c | 43 +++++++++++++++++++++++++------------- iguana/main.c | 4 +++- 2 files changed, 32 insertions(+), 15 deletions(-) diff --git a/iguana/iguana_instantdex.c b/iguana/iguana_instantdex.c index 8c019404c..b22a5de3b 100755 --- a/iguana/iguana_instantdex.c +++ b/iguana/iguana_instantdex.c @@ -109,27 +109,39 @@ struct instantdex_stateinfo *instantdex_statefind(struct instantdex_stateinfo *s return(0); } +void instantdex_stateinit(struct instantdex_stateinfo *states,int32_t numstates,struct instantdex_stateinfo *state,char *name,char *errorstr,char *timeoutstr,void *process_func,void *timeout_func) +{ + struct instantdex_stateinfo *timeoutstate,*errorstate; + memset(state,0,sizeof(*state)); + strcpy(state->name,name); + if ( (errorstate= instantdex_statefind(states,numstates,errorstr)) == 0 ) + errorstate = &instantdex_errorstate; + state->errorevent = errorstate; + if ( (timeoutstate= instantdex_statefind(states,numstates,timeoutstr)) == 0 ) + timeoutstate = &instantdex_timeoutstate; + state->timeoutevent = timeoutstate; + if ( (state->process= process_func) == 0 ) + state->process = instantdex_defaultprocess; + if ( (state->timeout= timeout_func) == 0 ) + state->timeout = instantdex_defaulttimeout; +} + struct instantdex_stateinfo *instantdex_statecreate(struct instantdex_stateinfo *states,int32_t *numstatesp,char *name,cJSON *(*process_func)(struct supernet_info *myinfo,struct exchange_info *exchange,struct instantdex_accept *A,cJSON *argjson,cJSON *newjson,uint8_t **serdatap,int32_t *serdatalenp),cJSON *(*timeout_func)(struct supernet_info *myinfo,struct exchange_info *exchange,struct instantdex_accept *A,cJSON *argjson,cJSON *newjson,uint8_t **serdatap,int32_t *serdatalenp),char *timeoutstr,char *errorstr) { - struct instantdex_stateinfo *timeoutstate,*errorstate,*state = 0; + struct instantdex_stateinfo S,*state = 0; if ( (state= instantdex_statefind(states,*numstatesp,name)) == 0 ) { states = realloc(states,sizeof(*states) * (*numstatesp + 1)); state = &states[*numstatesp]; - memset(state,0,sizeof(*state)); - strcpy(state->name,name); - if ( (errorstate= instantdex_statefind(states,*numstatesp,errorstr)) == 0 ) - errorstate = &instantdex_errorstate; - state->errorevent = errorstate; - if ( (timeoutstate= instantdex_statefind(states,*numstatesp,timeoutstr)) == 0 ) - timeoutstate = &instantdex_timeoutstate; - state->timeoutevent = timeoutstate; - if ( (state->process= process_func) == 0 ) - state->process = instantdex_defaultprocess; - if ( (state->timeout= timeout_func) == 0 ) - state->timeout = instantdex_defaulttimeout; + instantdex_stateinit(states,*numstatesp,state,name,errorstr,timeoutstr,process_func,timeout_func); (*numstatesp)++; - } else printf("statecreate error!!! (%s) already exists\n",name); + } + else + { + instantdex_stateinit(states,*numstatesp,&S,name,errorstr,timeoutstr,process_func,timeout_func); + if ( memcmp(&S,state,sizeof(S)) != 0 ) + printf("statecreate error!!! (%s) already exists\n",name); + } return(states); } @@ -786,7 +798,10 @@ char *instantdex_selectqueue(struct exchange_info *exchange,struct instantdex_ac free_json(retjson); } if ( flag == 0 ) + { + printf("add orderid.%llu to statemachine\n",(long long)ap->orderid); queue_enqueue("statemachineQ",&exchange->statemachineQ,&ap->DL,0); + } return(retstr); } diff --git a/iguana/main.c b/iguana/main.c index e8dd00b3c..b60a7db62 100644 --- a/iguana/main.c +++ b/iguana/main.c @@ -1107,7 +1107,7 @@ void iguana_main(void *arg) sleep(1); char *str; strcpy(MYINFO.rpcsymbol,"BTC"); - iguana_launchcoin(MYINFO.rpcsymbol,cJSON_Parse("{}")); + //iguana_launchcoin(MYINFO.rpcsymbol,cJSON_Parse("{}")); if ( 1 && (str= SuperNET_JSON(&MYINFO,cJSON_Parse("{\"agent\":\"iguana\",\"method\":\"addcoin\",\"services\":128,\"maxpeers\":3,\"newcoin\":\"BTC\",\"active\":0}"),0)) != 0 ) { free(str); @@ -1121,6 +1121,8 @@ void iguana_main(void *arg) free(str); } } + printf("BTC active.%d BTCD active.%d\n",iguana_coinfind("BTC")->active,iguana_coinfind("BTCD")->active); + iguana_coinfind("BTC")->active = iguana_coinfind("BTCD")->active = 0; } sleep(1); #endif