From d27ffaf556acbded1f8eb4737ee51399bac552ad Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 16 Nov 2017 07:19:06 +0200 Subject: [PATCH] Test --- iguana/exchanges/LP_commands.c | 11 +--------- iguana/exchanges/LP_nativeDEX.c | 34 ++++++++---------------------- iguana/exchanges/LP_ordermatch.c | 1 + iguana/exchanges/LP_prices.c | 1 + iguana/exchanges/LP_rpc.c | 9 -------- iguana/exchanges/LP_signatures.c | 3 --- iguana/exchanges/LP_statemachine.c | 10 +++++++++ iguana/exchanges/LP_utxo.c | 6 +++--- iguana/exchanges/LP_utxos.c | 8 ++----- 9 files changed, 27 insertions(+), 56 deletions(-) diff --git a/iguana/exchanges/LP_commands.c b/iguana/exchanges/LP_commands.c index 72734536e..72c64d04b 100644 --- a/iguana/exchanges/LP_commands.c +++ b/iguana/exchanges/LP_commands.c @@ -35,13 +35,7 @@ char *LP_numutxos() char *stats_JSON(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson,char *remoteaddr,uint16_t port) // from rpc port { char *method,*userpass,*base,*rel,*coin,*retstr = 0; int32_t changed,flag = 0; cJSON *retjson,*reqjson = 0; struct iguana_info *ptr; - printf("stats_JSON.0 %ld\n",LP_cjson_allocated); method = jstr(argjson,"method"); -/*if ( //strcmp(method,"uitem") == 0 || strcmp(method,"postutxos") == 0 || - strcmp(method,"notify") == 0 - || strcmp(method,"postprice") == 0 - ) - return(clonestr("{}"));*/ /*if ( (ipaddr= jstr(argjson,"ipaddr")) != 0 && (argport= juint(argjson,"port")) != 0 && (method == 0 || strcmp(method,"electrum") != 0) ) { if ( strcmp(ipaddr,"127.0.0.1") != 0 && argport >= 1000 ) @@ -159,7 +153,6 @@ bot_resume(botid)\n\ rel = ""; if ( (coin= jstr(argjson,"coin")) == 0 ) coin = ""; - printf("stats_JSON.1 %ld %s\n",LP_cjson_allocated,method); if ( G.USERPASS[0] != 0 && strcmp(remoteaddr,"127.0.0.1") == 0 && port != 0 ) // protected localhost { if ( G.USERPASS_COUNTER == 0 ) @@ -437,7 +430,7 @@ bot_resume(botid)\n\ } else if ( strcmp(method,"getrawtransaction") == 0 ) { - return(jprint(LP_gettx(coin,jbits256(argjson,"txid")),0)); + return(jprint(LP_gettx(coin,jbits256(argjson,"txid")),1)); } else if ( strcmp(method,"withdraw") == 0 ) { @@ -642,10 +635,8 @@ bot_resume(botid)\n\ } if ( retstr == 0 ) printf("ERROR.(%s)\n",jprint(argjson,0)); - printf("stats_JSON.2 %ld reqjson.%p\n",LP_cjson_allocated,reqjson); if ( reqjson != 0 ) free_json(reqjson); - printf("stats_JSON.3 %ld retstr.%p\n",LP_cjson_allocated,retstr); if ( retstr != 0 ) { free(retstr); diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 7fcdd92ed..9c260bdaa 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -183,19 +183,12 @@ char *LP_command_process(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson return(0); if ( LP_tradecommand(ctx,myipaddr,pubsock,argjson,data,datalen) <= 0 ) { - long startval = LP_cjson_allocated; if ( (retstr= stats_JSON(ctx,myipaddr,pubsock,argjson,"127.0.0.1",0)) != 0 ) { //printf("%s PULL.[%d]-> (%s)\n",myipaddr != 0 ? myipaddr : "127.0.0.1",datalen,retstr); //if ( pubsock >= 0 ) //strncmp("{\"error\":",retstr,strlen("{\"error\":")) != 0 && //LP_send(pubsock,retstr,(int32_t)strlen(retstr)+1,0); } - if ( LP_cjson_allocated > startval ) - { - char *leakstr = jprint(argjson,0); - printf("stats_JSON leaked.%ld (%s)\n",LP_cjson_allocated - startval,leakstr); - free(leakstr); - } } //else printf("finished tradecommand (%s)\n",jprint(argjson,0)); return(retstr); } @@ -316,16 +309,9 @@ char *LP_process_message(void *ctx,char *typestr,char *myipaddr,int32_t pubsock, } else { - long startval = LP_cjson_allocated; if ( (retstr= LP_command_process(ctx,myipaddr,pubsock,argjson,&((uint8_t *)ptr)[len],recvlen - len)) != 0 ) { } - if ( LP_cjson_allocated > startval ) - { - char *leakstr = jprint(argjson,0); - printf("LP_command_process leaked.%ld (%s)\n",LP_cjson_allocated - startval,leakstr); - free(leakstr); - } } } if ( argjson != 0 ) @@ -383,11 +369,8 @@ int32_t LP_sock_check(char *typestr,void *ctx,char *myipaddr,int32_t pubsock,int } if ( validreq != 0 ) { - long startval = LP_cjson_allocated; if ( (retstr= LP_process_message(ctx,typestr,myipaddr,pubsock,ptr,recvlen,sock)) != 0 ) free(retstr); - if ( LP_cjson_allocated > startval ) - printf("leaked.%ld (%s)\n",LP_cjson_allocated - startval,(char *)ptr); if ( Broadcaststr != 0 ) { //printf("self broadcast.(%s)\n",Broadcaststr); @@ -1222,10 +1205,10 @@ int32_t zeroval() { return(0); } void *LP_alloc(uint64_t len) { + return(calloc(1,len)); LP_cjson_allocated += len; LP_cjson_total += len; LP_cjson_count++; - //return(calloc(1,len)); struct LP_memory_list *mp; mp = calloc(1,sizeof(*mp) + len); mp->ptr = calloc(1,len); @@ -1238,16 +1221,11 @@ void *LP_alloc(uint64_t len) return(mp->ptr); } -void *LP_realloc(void *ptr,uint64_t len) -{ - return(realloc(ptr,len)); -} - void LP_free(void *ptr) { static uint32_t lasttime,unknown; - //free(ptr); - //return; + free(ptr); + return; uint32_t now; char str[65]; int32_t n,lagging; uint64_t total = 0; struct LP_memory_list *mp,*tmp; if ( (now= (uint32_t)time(NULL)) > lasttime+60 ) { @@ -1297,3 +1275,9 @@ char *LP_clonestr(char *str) return(retstr); } +void *LP_realloc(void *ptr,uint64_t len) +{ + return(realloc(ptr,len)); +} + + diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 04faf3715..b541200a1 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -718,6 +718,7 @@ int32_t LP_listunspent_both(char *symbol,char *coinaddr,int32_t fullflag) LP_address_utxoadd(now,"LP_listunspent_both",coin,coinaddr,txid,v,value,height,-1); } } + free_json(array); } } } //else printf("%s coin.%p inactive.%d\n",symbol,coin,coin!=0?coin->inactive:-1); diff --git a/iguana/exchanges/LP_prices.c b/iguana/exchanges/LP_prices.c index 7313c733b..d299b8368 100644 --- a/iguana/exchanges/LP_prices.c +++ b/iguana/exchanges/LP_prices.c @@ -265,6 +265,7 @@ uint64_t LP_unspents_metric(struct iguana_info *coin,char *coinaddr) } } metric = _LP_unspents_metric(total,n); + free_json(array); } return(metric); } diff --git a/iguana/exchanges/LP_rpc.c b/iguana/exchanges/LP_rpc.c index 2a66c9b94..320eec701 100644 --- a/iguana/exchanges/LP_rpc.c +++ b/iguana/exchanges/LP_rpc.c @@ -682,15 +682,6 @@ int32_t LP_listunspent_issue(char *symbol,char *coinaddr,int32_t fullflag) { //printf("LP_listunspent_query.(%s %s)\n",symbol,coinaddr); LP_listunspent_query(coin->symbol,coin->smartaddr); - /*if ( fullflag != 0 ) - { - if ( (destport= LP_randpeer(destip)) > 0 ) - { - retstr = issue_LP_listunspent(destip,destport,symbol,coinaddr); - //printf("issue %s %s %s -> (%s)\n",coin->symbol,coinaddr,destip,retstr); - retjson = cJSON_Parse(retstr); - } else printf("LP_listunspent_issue couldnt get a random peer?\n"); - }*/ } if ( retjson != 0 ) { diff --git a/iguana/exchanges/LP_signatures.c b/iguana/exchanges/LP_signatures.c index 0742f49d5..fee4a1189 100644 --- a/iguana/exchanges/LP_signatures.c +++ b/iguana/exchanges/LP_signatures.c @@ -649,7 +649,6 @@ void LP_smartutxos_push(struct iguana_info *coin) char *LP_uitem_recv(cJSON *argjson) { bits256 txid; int32_t vout,height; uint64_t value; struct iguana_info *coin; char *coinaddr,*symbol; - printf("LP_uitem_recv.0 %ld\n",LP_cjson_allocated); txid = jbits256(argjson,"txid"); vout = jint(argjson,"vout"); height = jint(argjson,"ht"); @@ -661,9 +660,7 @@ char *LP_uitem_recv(cJSON *argjson) if ( strcmp(coin->smartaddr,coinaddr) != 0 ) LP_address_utxoadd((uint32_t)time(NULL),"LP_uitem_recv",coin,coinaddr,txid,vout,value,height,-1); //else printf("ignore external uitem %s %s\n",symbol,coin->smartaddr); - printf("LP_uitem_recv.1 %ld\n",LP_cjson_allocated); } - printf("LP_uitem_recv.2 %ld\n",LP_cjson_allocated); return(clonestr("{\"result\":\"success\"}")); } diff --git a/iguana/exchanges/LP_statemachine.c b/iguana/exchanges/LP_statemachine.c index 3c32b8cad..86997fcd5 100644 --- a/iguana/exchanges/LP_statemachine.c +++ b/iguana/exchanges/LP_statemachine.c @@ -355,6 +355,16 @@ char *issue_LP_getprices(char *destip,uint16_t destport) return(LP_issue_curl("getprices",destip,destport,url)); //return(issue_curlt(url,LP_HTTP_TIMEOUT)); } +/*if ( fullflag != 0 ) + { + if ( (destport= LP_randpeer(destip)) > 0 ) + { + retstr = issue_LP_listunspent(destip,destport,symbol,coinaddr); + //printf("issue %s %s %s -> (%s)\n",coin->symbol,coinaddr,destip,retstr); + retjson = cJSON_Parse(retstr); + } else printf("LP_listunspent_issue couldnt get a random peer?\n"); + }*/ + void issue_LP_listunspent(char *destip,uint16_t destport,char *symbol,char *coinaddr) { cJSON *reqjson = cJSON_CreateObject(); diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index 1ebb7039e..c93f5e0fc 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -423,7 +423,6 @@ void LP_mark_spent(char *symbol,bits256 txid,int32_t vout) int32_t LP_address_utxoadd(uint32_t timestamp,char *debug,struct iguana_info *coin,char *coinaddr,bits256 txid,int32_t vout,uint64_t value,int32_t height,int32_t spendheight) { struct LP_address *ap; cJSON *txobj; struct LP_transaction *tx; struct LP_address_utxo *up,*tmp; int32_t flag,retval = 0; //char str[65]; - printf("LP_address_utxoadd.0 %ld\n",LP_cjson_allocated); if ( coin == 0 ) return(0); if ( spendheight > 0 ) // dont autocreate entries for spends we dont care about @@ -480,7 +479,6 @@ int32_t LP_address_utxoadd(uint32_t timestamp,char *debug,struct iguana_info *co } } // else printf("cant get ap %s %s\n",coin->symbol,coinaddr); //printf("done %s add addr.%s ht.%d\n",coin->symbol,coinaddr,height); - printf("LP_address_utxoadd.1 %ld\n",LP_cjson_allocated); return(retval); } @@ -505,7 +503,7 @@ struct LP_address *LP_address_utxo_reset(struct iguana_info *coin) up->spendheight = (int32_t)time(NULL); DL_APPEND(LP_garbage_collector2,up); portable_mutex_unlock(&LP_gcmutex); - } + } now = (uint32_t)time(NULL); if ( (n= cJSON_GetArraySize(array)) > 0 ) { @@ -636,6 +634,7 @@ cJSON *LP_address_balance(struct iguana_info *coin,char *coinaddr,int32_t electr balance += LP_value_extract(item,1); } } + free_json(array); } } else @@ -654,6 +653,7 @@ cJSON *LP_address_balance(struct iguana_info *coin,char *coinaddr,int32_t electr balance += j64bits(item,"value"); } } + free_json(array); } } } diff --git a/iguana/exchanges/LP_utxos.c b/iguana/exchanges/LP_utxos.c index 497760624..2498d4da4 100644 --- a/iguana/exchanges/LP_utxos.c +++ b/iguana/exchanges/LP_utxos.c @@ -570,15 +570,11 @@ int32_t LP_privkey_init(int32_t mypubsock,struct iguana_info *coin,bits256 mypri } if ( coin->privkeydepth > 0 ) return(0); - printf("LP_privkey_init.0 %ld\n",LP_cjson_allocated); coin->privkeydepth++; LP_address(coin,coin->smartaddr); - printf("LP_privkey_init.1 %ld\n",LP_cjson_allocated); if ( coin->inactive == 0 ) LP_listunspent_issue(coin->symbol,coin->smartaddr,0); - printf("LP_privkey_init.2 %ld\n",LP_cjson_allocated); array = LP_listunspent(coin->symbol,coin->smartaddr); - printf("LP_privkey_init.3 %ld\n",LP_cjson_allocated); if ( array != 0 ) { txfee = LP_txfeecalc(coin,0,0); @@ -707,7 +703,6 @@ int32_t LP_privkey_init(int32_t mypubsock,struct iguana_info *coin,bits256 mypri if ( flag != 0 ) LP_postutxos(coin->symbol,coin->smartaddr); } - printf("LP_privkey_init.4 %ld\n",LP_cjson_allocated); if ( values != 0 ) free(values); if ( coin->privkeydepth > 0 ) @@ -819,7 +814,8 @@ bits256 LP_privkeycalc(void *ctx,uint8_t *pubkey33,bits256 *pubkeyp,struct iguan printf("cant importprivkey.%s -> (%s), abort session\n",coin->symbol,jprint(retjson,1)); exit(-1); } - } else free_json(retjson); + free_json(retjson); + } coin->importedprivkey = (uint32_t)time(NULL); } vcalc_sha256(0,checkkey.bytes,privkey.bytes,sizeof(privkey));