Browse Source

test

release/v0.1
jl777 9 years ago
parent
commit
6cada72b49
  1. 12
      iguana/iguana_json.c
  2. 14
      iguana/iguana_rpc.c
  3. 6
      iguana/main.c
  4. 1
      iguana/tests/getconnectioncount
  5. 1
      iguana/tests/getdifficulty
  6. 1
      includes/iguana_apideclares.h

12
iguana/iguana_json.c

@ -591,7 +591,7 @@ STRING_ARG(iguana,peers,activecoin)
STRING_ARG(iguana,getconnectioncount,activecoin) STRING_ARG(iguana,getconnectioncount,activecoin)
{ {
int32_t i,num = 0; char buf[512]; int32_t i,num = 0; char buf[512];
if ( coin != 0 && coin->peers == 0 ) if ( coin != 0 && coin->peers != 0 )
{ {
for (i=0; i<sizeof(coin->peers->active)/sizeof(*coin->peers->active); i++) for (i=0; i<sizeof(coin->peers->active)/sizeof(*coin->peers->active); i++)
if ( coin->peers->active[i].usock >= 0 ) if ( coin->peers->active[i].usock >= 0 )
@ -601,6 +601,16 @@ STRING_ARG(iguana,getconnectioncount,activecoin)
} else return(clonestr("{\"error\":\"getconnectioncount needs coin\"}")); } 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) STRING_ARG(iguana,addcoin,newcoin)
{ {
char *symbol; int32_t retval; char *symbol; int32_t retval;

14
iguana/iguana_rpc.c

@ -23,7 +23,7 @@
char *sglue(GLUEARGS,char *agent,char *method) 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 ) if ( json == 0 )
json = cJSON_CreateObject(); json = cJSON_CreateObject();
//printf("sglue.(%s)\n",jprint(json,0)); //printf("sglue.(%s)\n",jprint(json,0));
@ -80,9 +80,11 @@ char *sglue(GLUEARGS,char *agent,char *method)
} }
else else
{ {
dval = atof(rpcretstr);
sprintf(dcheckstr,"%.8f",dval);
val = atol(rpcretstr); val = atol(rpcretstr);
sprintf(checkstr,"%lld",(long long)val); sprintf(checkstr,"%lld",(long long)val);
if ( strcmp(checkstr,rpcretstr) == 0 ) if ( strcmp(checkstr,rpcretstr) == 0 || strcmp(dcheckstr,rpcretstr) == 0 )
{ {
free_json(retjson); free_json(retjson);
free(retstr); free(retstr);
@ -264,6 +266,11 @@ static char *getblockcount(RPCARGS)
return(sglue(0,CALLGLUE,"bitcoinrpc","getblockcount")); return(sglue(0,CALLGLUE,"bitcoinrpc","getblockcount"));
} }
static char *getdifficulty(RPCARGS)
{
return(sglue(0,CALLGLUE,"bitcoinrpc","getdifficulty"));
}
static char *getblock(RPCARGS) static char *getblock(RPCARGS)
{ {
cJSON *obj; cJSON *obj;
@ -546,6 +553,7 @@ struct RPC_info { char *name; char *(*rpcfunc)(RPCARGS); int32_t flag0,remotefla
{ "stop", &stop, true, true }, { "stop", &stop, true, true },
{ "getbestblockhash", &getbestblockhash, true, true }, { "getbestblockhash", &getbestblockhash, true, true },
{ "getblockcount", &getblockcount, true, true }, { "getblockcount", &getblockcount, true, true },
{ "getdifficulty", &getdifficulty, true, true },
{ "getconnectioncount", &getconnectioncount, true, true }, { "getconnectioncount", &getconnectioncount, true, true },
{ "getpeerinfo", &getpeerinfo, true, true }, { "getpeerinfo", &getpeerinfo, true, true },
{ "getinfo", &getinfo, 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 ) if ( (array= jarray(&n,json,"params")) == 0 )
{ {
i= 0, n = 0; i = 0, n = 0;
} }
else if ( n > 0 ) else if ( n > 0 )
{ {

6
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); int32_t i,max=10000000; FILE *fp; bits256 check,val,hash = rand256(0);
if ( (fp= fopen("/tmp/seeds2","rb")) != 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<max; i++) for (i=1; i<max; i++)
{ {
if ( (i % 1000000) == 0 ) if ( (i % 1000000) == 0 )
fprintf(stderr,"."); fprintf(stderr,".");
fread(&val,1,sizeof(val),fp); if ( fread(&val,1,sizeof(val),fp) != sizeof(val) )
printf("val read error\n");
hash = bits256_sha256(val); hash = bits256_sha256(val);
hash = bits256_sha256(hash); hash = bits256_sha256(hash);
if ( bits256_cmp(hash,check) != 0 ) if ( bits256_cmp(hash,check) != 0 )

1
iguana/tests/getconnectioncount

@ -0,0 +1 @@
curl --url "http://127.0.0.1:14632" --data "{\"method\":\"getconnectioncount\",\"params\":[]}"

1
iguana/tests/getdifficulty

@ -0,0 +1 @@
curl --url "http://127.0.0.1:14632" --data "{\"method\":\"getdifficulty\",\"params\":[]}"

1
includes/iguana_apideclares.h

@ -42,6 +42,7 @@ HASH_ARRAY_STRING(basilisk,VPNlogout,hash,vals,hexstr);
ZERO_ARGS(bitcoinrpc,getinfo); ZERO_ARGS(bitcoinrpc,getinfo);
ZERO_ARGS(bitcoinrpc,getblockcount); ZERO_ARGS(bitcoinrpc,getblockcount);
ZERO_ARGS(bitcoinrpc,getdifficulty);
ZERO_ARGS(bitcoinrpc,getbestblockhash); ZERO_ARGS(bitcoinrpc,getbestblockhash);
INT_ARG(bitcoinrpc,getblockhash,height); INT_ARG(bitcoinrpc,getblockhash,height);
HASH_AND_TWOINTS(bitcoinrpc,getblock,blockhash,verbose,remoteonly); HASH_AND_TWOINTS(bitcoinrpc,getblock,blockhash,verbose,remoteonly);

Loading…
Cancel
Save