#include"json_rpc.h" /* addmultisigaddress <'["key","key"]'> [account] addnode backupwallet createmultisig <'["key","key"]'> createrawtransaction [{"txid":txid,"vout":n},...] {address:amount,...} decoderawtransaction dumpprivkey encryptwallet getaccount getaccountaddress getaddednodeinfo [node] getaddressesbyaccount getbalance [account] [minconf=1] getbestblockhash getblock [verbose=true] getblockcount getblockhash getblocktemplate [params] getconnectioncount getdifficulty getgenerate gethashespersec getinfo getmininginfo getnetworkhashps [blocks] [height] getnewaddress [account] getpeerinfo getrawmempool getrawtransaction [verbose=0] getreceivedbyaccount [minconf=1] getreceivedbyaddress [minconf=1] gettransaction gettxout [includemempool=true] gettxoutsetinfo getwork [data] getworkex [data, coinbase] help [command] importprivkey [label] [rescan=true] keypoolrefill listaccounts [minconf=1] listaddressgroupings listlockunspent listreceivedbyaccount [minconf=1] [includeempty=false] listreceivedbyaddress [minconf=1] [includeempty=false] listsinceblock [blockhash] [target-confirmations] listtransactions [account] [count=10] [from=0] listunspent [minconf=1] [maxconf=9999999] ["address",...] lockunspent unlock? [array-of-Objects] move [minconf=1] [comment] sendfrom [minconf=1] [comment] [comment-to] sendmany {address:amount,...} [minconf=1] [comment] sendrawtransaction sendtoaddress [comment] [comment-to] setaccount setgenerate [genproclimit] setmininput settxfee signmessage signrawtransaction [{"txid":txid,"vout":n,"scriptPubKey":hex,"redeemScript":hex},...] [,...] [sighashtype="ALL"] stop submitblock [optional-params-obj] validateaddress verifychain [check level] [num blocks] verifymessage */ //#define RPCBUFMAX 2056 json_t * brpc_prepare_params(char * data,...){ json_t * ret = json_array(); va_list ap; va_start(ap,data); while(data != NULL){ json_array_append(ret, json_string(data) ); data = va_arg(ap, char*); } va_end(ap); return ret; } void brpc_get_json(struct bitcoin_rpc_data * data){ char* s = NULL; json_t *root = json_object(); json_t * params = data->params; json_object_set_new( root, "jsonrpc", json_integer( 1 ) ); json_object_set_new( root, "id", json_string("bacteria") ); json_object_set_new( root, "method", json_string( data->method )); json_object_set_new( root, "params", params ); s = json_dumps(root, 0); //puts(s); data->json_ret = calloc( sizeof(char), strlen(s)+1); strcpy(data->json_ret,s); json_decref(root); } void brpc_clear_bdata(struct bitcoin_rpc_data * data){ free(data->json_ret); } extern void init_string(struct string *s); extern size_t writefunc(void *ptr, size_t size, size_t nmemb, struct string *s); json_t * brpc_json_request(struct cryptocoin * c, struct bitcoin_rpc_data * bdata){ CURL *curl = curl_easy_init(); struct curl_slist *headers = NULL; json_t * ret = NULL; json_error_t error; if (curl) { char userpwd[ strlen(c->rpcuser) + strlen(c->rpcpassword) + 2]; char url[ strlen(c->rpchost) + sizeof("http://") + sizeof("65535") + 2]; sprintf(userpwd, "%s:%s\0", c->rpcuser, c->rpcpassword); sprintf(url, "http://%s:%d\0", c->rpchost, c->rpcport); struct string s; init_string(&s); const char *data=bdata->json_ret; headers = curl_slist_append(headers, "content-type: text/plain;"); curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers); curl_easy_setopt(curl, CURLOPT_URL, url); curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, (long) strlen(data)); curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data); curl_easy_setopt(curl, CURLOPT_USERPWD, userpwd); curl_easy_setopt(curl, CURLOPT_USE_SSL, CURLUSESSL_TRY); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writefunc); curl_easy_setopt(curl, CURLOPT_WRITEDATA, &s); curl_easy_perform(curl); brpc_clear_bdata(bdata); //printf("%s\n", s.ptr); ret = json_loads(s.ptr, 0, &error); free(s.ptr); s.len=0; if(!ret){ fprintf(stderr, "JSON-RPC; Error decode; Maybe unathorized %d -> %s\n", error.line, error.text); } } curl_slist_free_all(headers); curl_easy_cleanup(curl); return ret; }