From fd1799a6318b7f2524837c3e2b8d6252f9d5c4cb Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 25 Oct 2016 14:54:51 -0300 Subject: [PATCH] test --- src/komodo.h | 1 + src/komodo_bitcoind.h | 8 ++--- src/komodo_utils.h | 69 ++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 73 insertions(+), 5 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index 4e679d37a..3dc33977a 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -31,6 +31,7 @@ int32_t komodo_notarizeddata(int32_t nHeight,uint256 *notarized_hashp,uint256 *n int32_t NOTARIZED_HEIGHT,Num_nutxos; uint256 NOTARIZED_HASH,NOTARIZED_DESTTXID; pthread_mutex_t komodo_mutex; +char USERPASS[1024]; uint16_t BITCOIND_PORT = 7771; #include "komodo_bitcoind.h" #include "komodo_interest.h" diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 9fa0db9f8..84904d451 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -88,17 +88,17 @@ char *curl_post(CURL **cHandlep,char *url,char *userpass,char *postfields,char * return(chunk.memory); } -char *komodo_issuemethod(char *method,char *params,char *userpass) +char *komodo_issuemethod(char *method,char *params) { - static void *cHandle; + static void *cHandle; extern char USERPASS[]; extern uint16_t BITCOIND_PORT; char url[512],*retstr=0,postdata[8192]; if ( strlen(params) < sizeof(postdata)-128 ) { if ( params == 0 ) params = (char *)"[]"; - sprintf(url,(char *)"http://127.0.0.1:7771"); + sprintf(url,(char *)"http://127.0.0.1:%u",port); sprintf(postdata,"{\"method\":\"%s\",\"params\":%s}",method,params); - retstr = curl_post(&cHandle,url,userpass,postdata,0,0,0,0); + retstr = curl_post(&cHandle,url,USERPASS,postdata,0,0,0,0); } return(retstr); } diff --git a/src/komodo_utils.h b/src/komodo_utils.h index aae909d42..380be4687 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -907,11 +907,40 @@ int32_t komodo_opreturnscript(uint8_t *script,uint8_t type,uint8_t *opret,int32_ return(opretlen + offset); } +long _stripwhite(char *buf,int accept) +{ + int32_t i,j,c; + if ( buf == 0 || buf[0] == 0 ) + return(0); + for (i=j=0; buf[i]!=0; i++) + { + buf[j] = c = buf[i]; + if ( c == accept || (c != ' ' && c != '\n' && c != '\r' && c != '\t' && c != '\b') ) + j++; + } + buf[j] = 0; + return(j); +} + +char *parse_conf_line(char *line,char *field) +{ + line += strlen(field); + for (; *line!='='&&*line!=0; line++) + break; + if ( *line == 0 ) + return(0); + if ( *line == '=' ) + line++; + _stripwhite(line,0); + return(clonestr(line)); +} + void komodo_configfile(char *symbol,uint16_t port) { - FILE *fp; char fname[512],buf[128]; + FILE *fp; char fname[512],buf[128],line[4096],*rpcuser,*rpcpassword,*rpcport,*retstr; srand((uint32_t)time(NULL)); sprintf(buf,"%s.conf",symbol); + BITCOIND_PORT = port; #ifdef WIN32 sprintf(fname,"%s\\%s",GetDataDir(false).string().c_str(),buf); #else @@ -926,4 +955,42 @@ void komodo_configfile(char *symbol,uint16_t port) printf("Created (%s)\n",fname); } } + else + { + rpcuser = rpcpassword = rpcport = 0; + while ( fgets(line,sizeof(line),fp) != 0 ) + { + if ( line[0] == '#' ) + continue; + //printf("line.(%s) %p %p\n",line,strstr(line,"rpcuser"),strstr(line,"rpcpassword")); + if ( (str= strstr(line,"rpcuser")) != 0 ) + rpcuser = parse_conf_line(str,"rpcuser"); + else if ( (str= strstr(line,"rpcpassword")) != 0 ) + rpcpassword = parse_conf_line(str,"rpcpassword"); + else if ( (str= strstr(line,"rpcport")) != 0 ) + rpcport = parse_conf_line(str,"rpcport"); + } + if ( rpcuser != 0 && rpcpassword != 0 ) + { + sprintf(USERPASS,"%s:%s",rpcuser,rpcpassword); + } + if ( rpcport != 0 ) + { + if ( port != atoi(rpcport) ) + printf("port.%u mismatch (%s)\n",port,rpcport); + //if ( serverport[0] == 0 ) + // sprintf(serverport,"127.0.0.1:%s",rpcport); + free(rpcport); + } + if ( rpcuser != 0 ) + free(rpcuser); + if ( rpcpassword != 0 ) + free(rpcpassword); + fclose(fp); + } + if ( (retstr= komodo_issuemethod("getinfo",0)) != 0 ) + { + printf("GETINFO.%s (%s)\n",symbol,retstr); + free(retstr); + } }