From 2c804b74921ca9039f5160632f2dca73c17786fb Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 11 Jan 2016 16:20:28 -0300 Subject: [PATCH] bitcoinrpc --- README.md | 12 +++++++++--- iguana/SuperNET.h | 2 +- iguana/iguana_rpc.c | 4 +++- iguana/main.c | 11 ++++++++++- 4 files changed, 23 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 8962b01e1..a49136e18 100644 --- a/README.md +++ b/README.md @@ -66,7 +66,13 @@ by submitting API calls using the forms, you will see it go to some specific URL *http://127.0.0.1:7778/json/ramchain/block/height/0* -> JSON only ```curl --url "http://127.0.0.1:7778/ramchain/BTCD/block/height/0"``` --> full webpage returned (probably not what you want) -```curl --url "http://127.0.0.1:7778/json/ramchain/BTCD/block/height/0"``` --> returns just the json object from the api call +```curl --url "http://127.0.0.1:7778/api/ramchain/BTCD/block/height/0"``` --> returns just the json object from the api call -Internall, all paths convert the request into a standard SuperNET JSON request. you can use a POST command to directly submit such JSON requests: -```curl --url "http://127.0.0.1:7778/?" --data "{\"agent\":\"ramchain\",\"method\":\"block\",\"coin\":\"BTCD\",\"height\":0}"``` +Internally, all paths convert the request into a standard SuperNET JSON request. you can use a POST command to directly submit such JSON requests: +```curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"ramchain\",\"method\":\"block\",\"coin\":\"BTCD\",\"height\":0}"``` + +Another approach is to use the bitcoin RPC syntax via: + curl --url "http://127.0.0.1:7778" --data "{\"coin\":\"BTCD\",\"method\":\"getinfo\",\"params\":[]}" +the params:[] array is where the standard bitcoin parameters go, the only change that is needed is to specify the coin +alternatively {"agent":"SuperNET","method":"bitcoinrpc","coin":"BTCD"} will set the coin +to use for bitcoin RPC calls. this will suffice in single coin environments diff --git a/iguana/SuperNET.h b/iguana/SuperNET.h index 4b5deadd6..b1bd94022 100644 --- a/iguana/SuperNET.h +++ b/iguana/SuperNET.h @@ -60,7 +60,7 @@ struct supernet_agent struct supernet_info { char ipaddr[64],transport[8]; int32_t APISLEEP; int32_t iamrelay; uint64_t my64bits; uint64_t ipbits; - int32_t Debuglevel,readyflag,dead,POLLTIMEOUT; + int32_t Debuglevel,readyflag,dead,POLLTIMEOUT; char rpcsymbol[16]; //int32_t pullsock,subclient,lbclient,lbserver,servicesock,pubglobal,pubrelays,numservers; bits256 privkey,pubkey; uint16_t port,serviceport,acceptport; diff --git a/iguana/iguana_rpc.c b/iguana/iguana_rpc.c index 7bd3c50ad..d2d6ede4c 100755 --- a/iguana/iguana_rpc.c +++ b/iguana/iguana_rpc.c @@ -1060,7 +1060,9 @@ char *iguana_bitcoinRPC(struct supernet_info *myinfo,char *method,cJSON *json,ch memset(params,0,sizeof(params)); if ( json != 0 ) { - if ( method != 0 && (symbol= jstr(json,"coin")) != 0 && (coin= iguana_coinfind(symbol)) != 0 ) + if ( (symbol= jstr(json,"coin")) == 0 || symbol[0] == 0 ) + symbol = myinfo->rpcsymbol; + if ( method != 0 && symbol != 0 && (coin= iguana_coinfind(symbol)) != 0 ) { if ( (array= jarray(&n,json,"params")) == 0 ) { diff --git a/iguana/main.c b/iguana/main.c index 3dd7079d0..0a7625c07 100644 --- a/iguana/main.c +++ b/iguana/main.c @@ -94,7 +94,7 @@ char *pangea_parser(struct supernet_info *myinfo,char *method,cJSON *json,char * char *SuperNET_jsonstr(struct supernet_info *myinfo,char *jsonstr,char *remoteaddr) { - cJSON *json; char *agent,*method; + cJSON *json; char *agent,*method,*symbol; if ( (json= cJSON_Parse(jsonstr)) != 0 ) { method = jstr(json,"method"); @@ -112,6 +112,15 @@ char *SuperNET_jsonstr(struct supernet_info *myinfo,char *jsonstr,char *remotead return(jumblr_parser(myinfo,method,json,remoteaddr)); else if ( strcmp(agent,"hash") == 0 ) return(hash_parser(myinfo,method,json,remoteaddr)); + else if ( strcmp(agent,"SuperNET") == 0 ) + { + if ( strcmp(method,"bitcoinrpc") == 0 && (symbol= jstr(json,"coin")) != 0 && strlen(symbol) < 8 && iguana_coinfind(symbol) != 0) + { + strcpy(myinfo->rpcsymbol,symbol); + return(clonestr("{\"result\":\"set bitcoin RPC coin\"}")); + } + return(clonestr("{\"error\":\"unrecognized SuperNET method\"}")); + } } else if ( method != 0 && is_bitcoinrpc(method) ) return(iguana_bitcoinRPC(myinfo,method,json,remoteaddr));