Browse Source

bitcoinrpc

release/v0.1
jl777 9 years ago
parent
commit
2c804b7492
  1. 12
      README.md
  2. 2
      iguana/SuperNET.h
  3. 4
      iguana/iguana_rpc.c
  4. 11
      iguana/main.c

12
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 *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/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: 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}"``` ```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

2
iguana/SuperNET.h

@ -60,7 +60,7 @@ struct supernet_agent
struct supernet_info struct supernet_info
{ {
char ipaddr[64],transport[8]; int32_t APISLEEP; int32_t iamrelay; uint64_t my64bits; uint64_t ipbits; 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; //int32_t pullsock,subclient,lbclient,lbserver,servicesock,pubglobal,pubrelays,numservers;
bits256 privkey,pubkey; bits256 privkey,pubkey;
uint16_t port,serviceport,acceptport; uint16_t port,serviceport,acceptport;

4
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)); memset(params,0,sizeof(params));
if ( json != 0 ) 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 ) if ( (array= jarray(&n,json,"params")) == 0 )
{ {

11
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) 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 ) if ( (json= cJSON_Parse(jsonstr)) != 0 )
{ {
method = jstr(json,"method"); 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)); return(jumblr_parser(myinfo,method,json,remoteaddr));
else if ( strcmp(agent,"hash") == 0 ) else if ( strcmp(agent,"hash") == 0 )
return(hash_parser(myinfo,method,json,remoteaddr)); 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) ) else if ( method != 0 && is_bitcoinrpc(method) )
return(iguana_bitcoinRPC(myinfo,method,json,remoteaddr)); return(iguana_bitcoinRPC(myinfo,method,json,remoteaddr));

Loading…
Cancel
Save