From 6cada72b491e6b7df6ad828c2e11e539d30f0721 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 17 Jun 2016 04:18:13 -0300 Subject: [PATCH] test --- iguana/iguana_json.c | 12 +++++++++++- iguana/iguana_rpc.c | 14 +++++++++++--- iguana/main.c | 6 ++++-- iguana/tests/getconnectioncount | 1 + iguana/tests/getdifficulty | 1 + includes/iguana_apideclares.h | 1 + 6 files changed, 29 insertions(+), 6 deletions(-) create mode 100755 iguana/tests/getconnectioncount create mode 100755 iguana/tests/getdifficulty diff --git a/iguana/iguana_json.c b/iguana/iguana_json.c index ebe27228d..7d3db0ddc 100755 --- a/iguana/iguana_json.c +++ b/iguana/iguana_json.c @@ -591,7 +591,7 @@ STRING_ARG(iguana,peers,activecoin) STRING_ARG(iguana,getconnectioncount,activecoin) { int32_t i,num = 0; char buf[512]; - if ( coin != 0 && coin->peers == 0 ) + if ( coin != 0 && coin->peers != 0 ) { for (i=0; ipeers->active)/sizeof(*coin->peers->active); i++) if ( coin->peers->active[i].usock >= 0 ) @@ -601,6 +601,16 @@ STRING_ARG(iguana,getconnectioncount,activecoin) } else return(clonestr("{\"error\":\"getconnectioncount needs coin\"}")); } +ZERO_ARGS(bitcoinrpc,getdifficulty) +{ + char buf[64]; + if ( coin != 0 ) + { + sprintf(buf,"{\"result\":\"%.8f\"}",PoW_from_compact(coin->blocks.hwmchain.RO.bits,coin->chain->unitval)); + return(clonestr(buf)); + } else return(clonestr("{\"error\":\"getdifficulty needs coin\"}")); +} + STRING_ARG(iguana,addcoin,newcoin) { char *symbol; int32_t retval; diff --git a/iguana/iguana_rpc.c b/iguana/iguana_rpc.c index 8da5046b8..e9d68c50c 100755 --- a/iguana/iguana_rpc.c +++ b/iguana/iguana_rpc.c @@ -23,7 +23,7 @@ char *sglue(GLUEARGS,char *agent,char *method) { - char *retstr,*rpcretstr,*walletstr,checkstr[64]; cJSON *retjson,*tmpjson,*result,*error,*wallet; int32_t i,j,len; int64_t val; + char *retstr,*rpcretstr,*walletstr,checkstr[64],dcheckstr[64]; cJSON *retjson,*tmpjson,*result,*error,*wallet; int32_t i,j,len; int64_t val; double dval; if ( json == 0 ) json = cJSON_CreateObject(); //printf("sglue.(%s)\n",jprint(json,0)); @@ -80,9 +80,11 @@ char *sglue(GLUEARGS,char *agent,char *method) } else { + dval = atof(rpcretstr); + sprintf(dcheckstr,"%.8f",dval); val = atol(rpcretstr); sprintf(checkstr,"%lld",(long long)val); - if ( strcmp(checkstr,rpcretstr) == 0 ) + if ( strcmp(checkstr,rpcretstr) == 0 || strcmp(dcheckstr,rpcretstr) == 0 ) { free_json(retjson); free(retstr); @@ -264,6 +266,11 @@ static char *getblockcount(RPCARGS) return(sglue(0,CALLGLUE,"bitcoinrpc","getblockcount")); } +static char *getdifficulty(RPCARGS) +{ + return(sglue(0,CALLGLUE,"bitcoinrpc","getdifficulty")); +} + static char *getblock(RPCARGS) { cJSON *obj; @@ -546,6 +553,7 @@ struct RPC_info { char *name; char *(*rpcfunc)(RPCARGS); int32_t flag0,remotefla { "stop", &stop, true, true }, { "getbestblockhash", &getbestblockhash, true, true }, { "getblockcount", &getblockcount, true, true }, + { "getdifficulty", &getdifficulty, true, true }, { "getconnectioncount", &getconnectioncount, true, true }, { "getpeerinfo", &getpeerinfo, true, true }, { "getinfo", &getinfo, true, true }, @@ -700,7 +708,7 @@ char *iguana_bitcoinRPC(struct supernet_info *myinfo,char *method,cJSON *json,ch { if ( (array= jarray(&n,json,"params")) == 0 ) { - i= 0, n = 0; + i = 0, n = 0; } else if ( n > 0 ) { diff --git a/iguana/main.c b/iguana/main.c index dace60bb3..8a2bdf8d6 100755 --- a/iguana/main.c +++ b/iguana/main.c @@ -1435,12 +1435,14 @@ void iguana_main(void *arg) int32_t i,max=10000000; FILE *fp; bits256 check,val,hash = rand256(0); if ( (fp= fopen("/tmp/seeds2","rb")) != 0 ) { - fread(&check,1,sizeof(check),fp); + if ( fread(&check,1,sizeof(check),fp) != sizeof(check) ) + printf("check read error\n"); for (i=1; i