You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

614 lines
23 KiB

9 years ago
/******************************************************************************
* Copyright © 2014-2015 The SuperNET Developers. *
* *
* See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at *
* the top-level directory of this distribution for the individual copyright *
* holder information and the developer policies on copyright and licensing. *
* *
* Unless otherwise agreed in a custom licensing agreement, no part of the *
* SuperNET software, including this file may be copied, modified, propagated *
* or distributed except according to the terms contained in the LICENSE file *
* *
* Removal or modification of this copyright notice is prohibited. *
* *
******************************************************************************/
#include "iguana777.h"
9 years ago
#include "SuperNET.h"
9 years ago
9 years ago
#define RPCARGS struct supernet_info *myinfo,struct iguana_info *coin,cJSON *params[],int32_t n,cJSON *json,char *remoteaddr
char *sglue(cJSON *json,struct supernet_info *myinfo,struct iguana_info *coin,char *remoteaddr,char *agent,char *method)
9 years ago
{
9 years ago
char *retstr,*rpcretstr; cJSON *retjson,*result,*error; int32_t i,j,len;
if ( json == 0 )
json = cJSON_CreateObject();
jaddstr(json,"agent",agent);
jaddstr(json,"method",method);
jaddstr(json,"coin",coin->symbol);
if ( (retstr= SuperNET_JSON(myinfo,json,remoteaddr)) != 0 )
9 years ago
{
9 years ago
if ( (retjson= cJSON_Parse(retstr)) != 0 )
9 years ago
{
9 years ago
jdelete(retjson,"tag");
//printf("RPCret.(%s) n.%d\n",jprint(retjson,0),cJSON_GetArraySize(retjson));
result = cJSON_GetObjectItem(retjson,"result");
error = cJSON_GetObjectItem(retjson,"error");
if ( result != 0 && cJSON_GetArraySize(retjson) == 1 )
9 years ago
{
9 years ago
if ( (error == 0 || (error->type&0xff) == cJSON_NULL) && (result->type&0xff) != cJSON_NULL )
9 years ago
{
9 years ago
rpcretstr = cJSON_Print(result);
len = (int32_t)strlen(rpcretstr);
if ( rpcretstr[0] == '"' && rpcretstr[len-1] == '"' )
{
for (i=1,j=0; i<len-1; i++,j++)
rpcretstr[j] = rpcretstr[i];
rpcretstr[j] = '\n';
free_json(json);
free_json(retjson);
free(retstr);
return(rpcretstr);
}
free(rpcretstr);
}
else if ( (error->type&0xff) != cJSON_NULL || (result->type&0xff) != cJSON_NULL )
printf("<<<<<<<<<<< bitcoind_RPC: post_process_bitcoind_RPC error.%s\n",retstr);
}
free_json(retjson);
9 years ago
}
}
9 years ago
free_json(json);
return(retstr);
9 years ago
}
9 years ago
char *sglue1(cJSON *json,struct supernet_info *myinfo,struct iguana_info *coin,char *remoteaddr,char *agent,char *method,char *field,cJSON *obj)
9 years ago
{
9 years ago
if ( json == 0 )
json = cJSON_CreateObject();
if ( obj != 0 )
jadd(json,field,obj);
return(sglue(json,myinfo,coin,remoteaddr,agent,method));
9 years ago
}
9 years ago
char *sglueN(cJSON *json,struct supernet_info *myinfo,struct iguana_info *coin,char *remoteaddr,char *agent,char *method,char *field,double num)
9 years ago
{
9 years ago
if ( json == 0 )
json = cJSON_CreateObject();
jaddnum(json,field,num);
return(sglue(json,myinfo,coin,remoteaddr,agent,method));
9 years ago
}
9 years ago
char *sglue2(cJSON *json,struct supernet_info *myinfo,struct iguana_info *coin,char *remoteaddr,char *agent,char *method,char *field0,cJSON *obj0,char *field1,cJSON *obj1)
9 years ago
{
9 years ago
if ( json == 0 )
json = cJSON_CreateObject();
if ( obj1 != 0 )
jadd(json,field1,obj1);
return(sglue1(json,myinfo,coin,remoteaddr,agent,method,field0,obj0));
9 years ago
}
9 years ago
char *sglue3(cJSON *json,struct supernet_info *myinfo,struct iguana_info *coin,char *remoteaddr,char *agent,char *method,char *field0,cJSON *obj0,char *field1,cJSON *obj1,char *field2,cJSON *obj2)
9 years ago
{
9 years ago
if ( json == 0 )
json = cJSON_CreateObject();
if ( obj2 != 0 )
jadd(json,field2,obj2);
return(sglue2(json,myinfo,coin,remoteaddr,agent,method,field0,obj0,field1,obj1));
9 years ago
}
9 years ago
char *sglue4(cJSON *json,struct supernet_info *myinfo,struct iguana_info *coin,char *remoteaddr,char *agent,char *method,char *field0,cJSON *obj0,char *field1,cJSON *obj1,char *field2,cJSON *obj2,char *field3,cJSON *obj3)
9 years ago
{
9 years ago
if ( json == 0 )
json = cJSON_CreateObject();
if ( obj3 != 0 )
jadd(json,field3,obj3);
return(sglue3(json,myinfo,coin,remoteaddr,agent,method,field0,obj0,field1,obj1,field2,obj2));
9 years ago
}
9 years ago
char *sglue5(cJSON *json,struct supernet_info *myinfo,struct iguana_info *coin,char *remoteaddr,char *agent,char *method,char *field0,cJSON *obj0,char *field1,cJSON *obj1,char *field2,cJSON *obj2,char *field3,cJSON *obj3,char *field4,cJSON *obj4)
9 years ago
{
9 years ago
if ( json == 0 )
json = cJSON_CreateObject();
if ( obj4 != 0 )
jadd(json,field4,obj4);
return(sglue4(json,myinfo,coin,remoteaddr,agent,method,field0,obj0,field1,obj1,field2,obj2,field3,obj3));
9 years ago
}
9 years ago
9 years ago
char *sglue6(cJSON *json,struct supernet_info *myinfo,struct iguana_info *coin,char *remoteaddr,char *agent,char *method,char *field0,cJSON *obj0,char *field1,cJSON *obj1,char *field2,cJSON *obj2,char *field3,cJSON *obj3,char *field4,cJSON *obj4,char *field5,cJSON *obj5)
{
if ( json == 0 )
json = cJSON_CreateObject();
if ( obj5 != 0 )
jadd(json,field5,obj5);
return(sglue5(json,myinfo,coin,remoteaddr,agent,method,field0,obj0,field1,obj1,field2,obj2,field3,obj3,field4,obj4));
}
9 years ago
9 years ago
// misc
static char *help(RPCARGS)
{
9 years ago
return(sglue(0,myinfo,coin,remoteaddr,"SuperNET","help"));
9 years ago
}
static char *stop(RPCARGS)
{
9 years ago
return(sglue(0,myinfo,coin,remoteaddr,"iguana","pausecoin"));
9 years ago
}
static char *sendalert(RPCARGS)
{
9 years ago
return(sglue1(0,myinfo,coin,remoteaddr,"iguana","sendalert","message",params[0]));
9 years ago
}
static char *SuperNET(RPCARGS)
{
9 years ago
return(SuperNET_JSON(myinfo,json,remoteaddr));
9 years ago
}
static char *getrawmempool(RPCARGS)
{
9 years ago
return(sglue(0,myinfo,coin,remoteaddr,"iguana","getrawmempool"));
9 years ago
}
// peers
static char *getconnectioncount(RPCARGS)
{
9 years ago
return(sglue(0,myinfo,coin,remoteaddr,"iguana","getconnectioncount"));
9 years ago
}
static char *getpeerinfo(RPCARGS)
{
9 years ago
return(sglue(0,myinfo,coin,remoteaddr,"iguana","peers"));
9 years ago
}
static char *addnode(RPCARGS)
{
9 years ago
char *mode,*cmd = 0;
if ( (mode= jstr(params[1],0)) != 0 )
9 years ago
{
9 years ago
if ( strcmp(mode,"add") == 0 )
cmd = "addnode";
else if ( strcmp(mode,"remove") == 0 )
cmd = "removenode";
else if ( strcmp(mode,"onetry") == 0 )
cmd = "onetry";
if ( cmd != 0 )
return(sglue1(0,myinfo,coin,remoteaddr,"iguana",cmd,"ipaddr",params[0]));
9 years ago
}
9 years ago
// addnode <node> <add/remove/onetry> version 0.8 Attempts add or remove <node> from the addnode list or try a connection to <node> once. N
return(clonestr("{\"error\":\"invalid addnode parameter\"}"));
9 years ago
}
9 years ago
// address and pubkeys
9 years ago
static char *validateaddress(RPCARGS)
{
9 years ago
return(sglue1(0,myinfo,coin,remoteaddr,"ramchain","validateaddress","address",params[0]));
9 years ago
}
static char *validatepubkey(RPCARGS)
{
9 years ago
return(sglue1(0,myinfo,coin,remoteaddr,"ramchain","validatepubkey","pubkey",params[0]));
9 years ago
}
static char *createmultisig(RPCARGS)
{
9 years ago
return(sglue2(0,myinfo,coin,remoteaddr,"ramchain","createmultisig","M",params[0],"pubkeys",params[1]));
}
static char *addmultisigaddress(RPCARGS)
{
return(sglue3(0,myinfo,coin,remoteaddr,"ramchain","createmultisig","M",params[0],"pubkeys",params[1],"account",params[2]));
9 years ago
}
// blockchain
static char *getinfo(RPCARGS)
{
9 years ago
return(sglue(0,myinfo,coin,remoteaddr,"ramchain","status"));
9 years ago
}
static char *getbestblockhash(RPCARGS)
{
9 years ago
return(sglue(0,myinfo,coin,remoteaddr,"ramchain","getbestblockhash"));
9 years ago
}
static char *getblockcount(RPCARGS)
{
9 years ago
return(sglue(0,myinfo,coin,remoteaddr,"ramchain","getblockcount"));
9 years ago
}
static char *getblock(RPCARGS)
{
9 years ago
return(sglue1(0,myinfo,coin,remoteaddr,"ramchain","getblock","blockhash",params[0]));
9 years ago
}
static char *getblockhash(RPCARGS)
{
9 years ago
return(sglue1(0,myinfo,coin,remoteaddr,"ramchain","getblockhash","height",params[0]));
9 years ago
}
static char *gettransaction(RPCARGS)
{
9 years ago
return(sglue1(0,myinfo,coin,remoteaddr,"ramchain","tx","txid",params[0]));
9 years ago
}
static char *listtransactions(RPCARGS)
{
9 years ago
return(sglue3(0,myinfo,coin,remoteaddr,"ramchain","listtransactions","account",params[0],"count",params[1],"from",params[2]));
9 years ago
}
static char *getreceivedbyaddress(RPCARGS)
{
9 years ago
return(sglue2(0,myinfo,coin,remoteaddr,"ramchain","getreceivedbyaddress","address",params[0],"minconfs",params[1]));
9 years ago
}
static char *listreceivedbyaddress(RPCARGS)
{
9 years ago
return(sglue2(0,myinfo,coin,remoteaddr,"ramchain","listreceivedbyaddress","minconf",params[0],"includeempty",params[1]));
9 years ago
}
static char *listsinceblock(RPCARGS)
{
9 years ago
return(sglue2(0,myinfo,coin,remoteaddr,"ramchain","listsinceblock","blockhash",params[0],"target",params[1]));
9 years ago
}
// waccount and waddress funcs
static char *getreceivedbyaccount(RPCARGS)
{
9 years ago
return(sglue2(0,myinfo,coin,remoteaddr,"ramchain","getreceivedbyaccount","account",params[0],"minconfs",params[1]));
9 years ago
}
static char *listreceivedbyaccount(RPCARGS)
{
9 years ago
return(sglue2(0,myinfo,coin,remoteaddr,"ramchain","listreceivedbyaccount","account",params[0],"includeempty",params[1]));
9 years ago
}
9 years ago
static char *getnewaddress(RPCARGS)
9 years ago
{
9 years ago
return(sglue1(0,myinfo,coin,remoteaddr,"ramchain","getnewaddress","account",params[0]));
9 years ago
}
9 years ago
static char *vanitygen(RPCARGS)
9 years ago
{
9 years ago
return(sglue1(0,myinfo,coin,remoteaddr,"ramchain","vanitygen","vanity",params[0]));
9 years ago
}
static char *makekeypair(RPCARGS)
{
9 years ago
return(sglue(0,myinfo,coin,remoteaddr,"ramchain","makekeypair"));
9 years ago
}
static char *getaccountaddress(RPCARGS)
{
9 years ago
return(sglue1(0,myinfo,coin,remoteaddr,"ramchain","getaccountaddress","account",params[0]));
9 years ago
}
static char *setaccount(RPCARGS)
{
9 years ago
return(sglue2(0,myinfo,coin,remoteaddr,"ramchain","setaccount","address",params[0],"account",params[1]));
9 years ago
}
static char *getaccount(RPCARGS)
{
9 years ago
return(sglue1(0,myinfo,coin,remoteaddr,"ramchain","getaccount","address",params[0]));
9 years ago
}
static char *getaddressesbyaccount(RPCARGS)
{
9 years ago
return(sglue1(0,myinfo,coin,remoteaddr,"ramchain","getaddressesbyaccount","account",params[0]));
9 years ago
}
static char *listaddressgroupings(RPCARGS)
{
9 years ago
return(sglue(0,myinfo,coin,remoteaddr,"ramchain","listaddressgroupings"));
9 years ago
}
static char *getbalance(RPCARGS)
{
9 years ago
return(sglue2(0,myinfo,coin,remoteaddr,"ramchain","getbalance","account",params[0],"minconf",params[1]));
9 years ago
}
// wallet
static char *listaccounts(RPCARGS)
{
9 years ago
return(sglue1(0,myinfo,coin,remoteaddr,"ramchain","listaccounts","minconf",params[0]));
9 years ago
}
static char *dumpprivkey(RPCARGS)
{
9 years ago
return(sglue1(0,myinfo,coin,remoteaddr,"ramchain","dumpprivkey","address",params[0]));
9 years ago
}
static char *importprivkey(RPCARGS)
{
9 years ago
return(sglue1(0,myinfo,coin,remoteaddr,"ramchain","importprivkey","wip",params[0]));
9 years ago
}
static char *dumpwallet(RPCARGS)
{
9 years ago
return(sglue(0,myinfo,coin,remoteaddr,"ramchain","dumpwallet"));
9 years ago
}
static char *importwallet(RPCARGS)
{
9 years ago
return(sglue1(0,myinfo,coin,remoteaddr,"ramchain","importwallet","wallet",params[0]));
9 years ago
}
static char *walletpassphrase(RPCARGS)
{
9 years ago
return(sglue2(0,myinfo,coin,remoteaddr,"ramchain","walletpassphrase","passphrase",params[0],"timeout",params[1]));
9 years ago
}
static char *walletpassphrasechange(RPCARGS)
{
9 years ago
return(sglue2(0,myinfo,coin,remoteaddr,"ramchain","walletpassphrasechange","oldpassphrase",params[0],"newpassphrase",params[1]));
9 years ago
}
static char *walletlock(RPCARGS)
{
9 years ago
return(sglue(0,myinfo,coin,remoteaddr,"ramchain","walletlock"));
9 years ago
}
static char *encryptwallet(RPCARGS)
{
9 years ago
return(sglue1(0,myinfo,coin,remoteaddr,"ramchain","encryptwallet","passphrase",params[0]));
9 years ago
}
static char *checkwallet(RPCARGS)
{
9 years ago
return(sglue(0,myinfo,coin,remoteaddr,"ramchain","checkwallet"));
9 years ago
}
static char *repairwallet(RPCARGS)
{
9 years ago
return(sglue(0,myinfo,coin,remoteaddr,"ramchain","repairwallet"));
9 years ago
}
static char *backupwallet(RPCARGS)
{
9 years ago
return(sglue1(0,myinfo,coin,remoteaddr,"ramchain","backupwallet","filename",params[0]));
9 years ago
}
// messages
static char *signmessage(RPCARGS)
{
9 years ago
return(sglue2(0,myinfo,coin,remoteaddr,"ramchain","signmessage","address",params[0],"message",params[1]));
9 years ago
}
static char *verifymessage(RPCARGS)
{
9 years ago
return(sglue3(0,myinfo,coin,remoteaddr,"ramchain","verifymessage","address",params[0],"sig",params[1],"message",params[2]));
9 years ago
}
// unspents
static char *listunspent(RPCARGS)
{
9 years ago
return(sglue2(0,myinfo,coin,remoteaddr,"ramchain","listunspent","minconf",params[0],"maxconf",params[1]));
9 years ago
}
static char *lockunspent(RPCARGS)
{
9 years ago
return(sglue2(0,myinfo,coin,remoteaddr,"ramchain","lockunspent","flag",params[0],"array",params[1]));
9 years ago
}
static char *listlockunspent(RPCARGS)
{
9 years ago
return(sglue(0,myinfo,coin,remoteaddr,"ramchain","listlockunspent"));
9 years ago
}
static char *gettxout(RPCARGS)
{
9 years ago
return(sglue3(0,myinfo,coin,remoteaddr,"ramchain","gettxout","txid",params[0],"vout",params[1],"mempool",params[2]));
9 years ago
}
static char *gettxoutsetinfo(RPCARGS)
{
9 years ago
return(sglue(0,myinfo,coin,remoteaddr,"ramchain","gettxoutsetinfo"));
9 years ago
}
// payments
static char *sendtoaddress(RPCARGS)
{
9 years ago
return(sglue4(0,myinfo,coin,remoteaddr,"ramchain","sendtoaddress","address",params[0],"amount",params[1],"comment",params[2],"comment2",params[3]));
9 years ago
}
9 years ago
static char *movecmd(RPCARGS)
9 years ago
{
9 years ago
return(sglue5(0,myinfo,coin,remoteaddr,"ramchain","move","fromaccount",params[0],"toaccount",params[1],"amount",params[2],"minconf",params[3],"comment",params[4]));
9 years ago
}
static char *sendfrom(RPCARGS)
{
9 years ago
return(sglue6(0,myinfo,coin,remoteaddr,"ramchain","sendfrom","fromaccount",params[0],"toaddress",params[1],"amount",params[2],"minconf",params[3],"comment",params[4],"comment2",params[5]));
9 years ago
}
static char *sendmany(RPCARGS)
{
9 years ago
return(sglue4(0,myinfo,coin,remoteaddr,"ramchain","sendmany","fromaccount",params[0],"payments",params[1],"minconf",params[2],"comment",params[3]));
9 years ago
}
static char *settxfee(RPCARGS)
{
9 years ago
return(sglue1(0,myinfo,coin,remoteaddr,"ramchain","settxfee","amount",params[0]));
9 years ago
}
// rawtransaction
static char *getrawtransaction(RPCARGS)
{
9 years ago
return(sglue2(0,myinfo,coin,remoteaddr,"ramchain","getrawtransaction","txid",params[0],"verbose",params[1]));
9 years ago
}
static char *createrawtransaction(RPCARGS)
{
9 years ago
return(sglue2(0,myinfo,coin,remoteaddr,"ramchain","createrawtransaction","vins",params[0],"vouts",params[1]));
9 years ago
}
static char *decoderawtransaction(RPCARGS)
{
9 years ago
return(sglue1(0,myinfo,coin,remoteaddr,"ramchain","decoderawtransaction","rawtx",params[0]));
9 years ago
}
static char *decodescript(RPCARGS)
{
9 years ago
return(sglue1(0,myinfo,coin,remoteaddr,"ramchain","decodescript","script",params[0]));
9 years ago
}
static char *signrawtransaction(RPCARGS)
{
9 years ago
return(sglue3(0,myinfo,coin,remoteaddr,"ramchain","signrawtransaction","rawtx",params[0],"vins",params[1],"privkeys",params[2]));
9 years ago
}
static char *sendrawtransaction(RPCARGS)
{
9 years ago
return(sglue1(0,myinfo,coin,remoteaddr,"ramchain","sendrawtransaction","rawtx",params[0]));
9 years ago
}
static char *getrawchangeaddress(RPCARGS)
{
9 years ago
return(sglue1(0,myinfo,coin,remoteaddr,"ramchain","getrawchangeaddress","account",params[0]));
9 years ago
}
9 years ago
#define true 1
#define false 0
9 years ago
struct RPC_info { char *name; char *(*rpcfunc)(RPCARGS); int32_t flag0,flag1; } RPCcalls[] =
{
{ "help", &help, true, true },
{ "stop", &stop, true, true },
{ "getbestblockhash", &getbestblockhash, true, false },
{ "getblockcount", &getblockcount, true, false },
{ "getconnectioncount", &getconnectioncount, true, false },
{ "getpeerinfo", &getpeerinfo, true, false },
{ "getinfo", &getinfo, true, false },
{ "getnewaddress", &getnewaddress, true, false },
{ "getnewpubkey", &makekeypair, true, false },
{ "getaccountaddress", &getaccountaddress, true, false },
{ "setaccount", &setaccount, true, false },
{ "getaccount", &getaccount, false, false },
{ "getaddressesbyaccount", &getaddressesbyaccount, true, false },
{ "sendtoaddress", &sendtoaddress, false, false },
{ "getreceivedbyaddress", &getreceivedbyaddress, false, false },
{ "getreceivedbyaccount", &getreceivedbyaccount, false, false },
{ "listreceivedbyaddress", &listreceivedbyaddress, false, false },
{ "listreceivedbyaccount", &listreceivedbyaccount, false, false },
{ "backupwallet", &backupwallet, true, false },
{ "walletpassphrase", &walletpassphrase, true, false },
{ "walletpassphrasechange", &walletpassphrasechange, false, false },
{ "walletlock", &walletlock, true, false },
{ "encryptwallet", &encryptwallet, false, false },
{ "validateaddress", &validateaddress, true, false },
{ "validatepubkey", &validatepubkey, true, false },
{ "getbalance", &getbalance, false, false },
{ "move", &movecmd, false, false },
{ "sendfrom", &sendfrom, false, false },
{ "sendmany", &sendmany, false, false },
{ "addmultisigaddress", &addmultisigaddress, false, false },
{ "getblock", &getblock, false, false },
{ "getblockhash", &getblockhash, false, false },
{ "gettransaction", &gettransaction, false, false },
{ "listtransactions", &listtransactions, false, false },
{ "listaddressgroupings", &listaddressgroupings, false, false },
{ "signmessage", &signmessage, false, false },
{ "verifymessage", &verifymessage, false, false },
9 years ago
{ "listaccounts", &listaccounts, false, false },
9 years ago
{ "settxfee", &settxfee, false, false },
{ "listsinceblock", &listsinceblock, false, false },
{ "dumpprivkey", &dumpprivkey, false, false },
{ "SuperNET", &SuperNET, false, false },
{ "dumpwallet", &dumpwallet, true, false },
{ "importwallet", &importwallet, false, false },
{ "importprivkey", &importprivkey, false, false },
{ "listunspent", &listunspent, false, false },
{ "getrawtransaction", &getrawtransaction, false, false },
{ "createrawtransaction", &createrawtransaction, false, false },
{ "decoderawtransaction", &decoderawtransaction, false, false },
{ "decodescript", &decodescript, false, false },
{ "signrawtransaction", &signrawtransaction, false, false },
{ "sendrawtransaction", &sendrawtransaction, false, false },
{ "checkwallet", &checkwallet, false, true},
{ "repairwallet", &repairwallet, false, true},
{ "makekeypair", &makekeypair, false, true},
{ "sendalert", &sendalert, false, false},
//
9 years ago
{ "createmultisig", &createmultisig, false, false},
{ "addnode", &addnode, false, false},
9 years ago
{ "getrawmempool", &getrawmempool, false, false},
{ "getrawchangeaddress", &getrawchangeaddress, false, false},
{ "listlockunspent", &listlockunspent, false, false},
{ "lockunspent", &lockunspent, false, false},
{ "gettxout", &gettxout, false, false},
9 years ago
{ "gettxoutsetinfo", &gettxoutsetinfo, false, false},
{ "vanitygen", &vanitygen, false, false}
9 years ago
#ifdef PEGGY
//{ "peggytx", &peggytx, true, false },
//{ "peggypayments", &peggypayments, true, false },
//{ "getpeggyblock", &getpeggyblock, true, false },
#endif
9 years ago
//{ "resendtx", &resendtx, false, true},
// { "addredeemscript", &addredeemscript, false, false },
9 years ago
// { "getrawmempool", &getrawmempool, true, false },
// { "getdifficulty", &getdifficulty, true, false },
// { "getsubsidy", &getsubsidy, true, false },
// { "getmininginfo", &getmininginfo, true, false },
// { "getstakinginfo", &getstakinginfo, true, false },
// { "getblockbynumber", &getblockbynumber, false, false },
//{ "getwork", &getwork, true, false },
//{ "getworkex", &getworkex, true, false },
// { "keypoolrefill", &keypoolrefill, true, false },
//{ "getblocktemplate", &getblocktemplate, true, false },
//{ "submitblock", &submitblock, false, false },
// { "getcheckpoint", &getcheckpoint, true, false },
// { "reservebalance", &reservebalance, false, true},
};
9 years ago
int32_t is_bitcoinrpc(char *method)
{
int32_t i;
for (i=0; i<sizeof(RPCcalls)/sizeof(*RPCcalls); i++)
{
if ( strcmp(RPCcalls[i].name,method) == 0 )
return(i);
}
return(-1);
}
9 years ago
char *iguana_bitcoinrpc(struct supernet_info *myinfo,struct iguana_info *coin,char *method,cJSON *params[16],int32_t n,cJSON *json,char *remoteaddr)
9 years ago
{
int32_t i;
for (i=0; i<sizeof(RPCcalls)/sizeof(*RPCcalls); i++)
{
if ( strcmp(RPCcalls[i].name,method) == 0 )
9 years ago
return((*RPCcalls[i].rpcfunc)(myinfo,coin,params,n,json,remoteaddr));
9 years ago
}
return(clonestr("{\"error\":\"invalid coin address\"}"));
}
9 years ago
char *iguana_bitcoinRPC(struct supernet_info *myinfo,char *method,cJSON *json,char *remoteaddr)
9 years ago
{
9 years ago
cJSON *params[16],*array; struct iguana_info *coin; char *symbol; int32_t i,n; char *retstr = 0;
9 years ago
memset(params,0,sizeof(params));
9 years ago
if ( json != 0 )
9 years ago
{
9 years ago
if ( (symbol= jstr(json,"coin")) == 0 || symbol[0] == 0 )
symbol = myinfo->rpcsymbol;
if ( method != 0 && symbol != 0 && (coin= iguana_coinfind(symbol)) != 0 )
9 years ago
{
9 years ago
if ( (array= jarray(&n,json,"params")) == 0 )
9 years ago
{
n = 1;
params[0] = jobj(json,"params");
}
else
{
9 years ago
params[0] = jitem(array,0);
9 years ago
if ( n > 1 )
for (i=1; i<n; i++)
9 years ago
params[i] = jitem(array,i);
9 years ago
}
9 years ago
retstr = iguana_bitcoinrpc(myinfo,coin,method,params,n,json,remoteaddr);
9 years ago
}
free_json(json);
}
if ( retstr == 0 )
retstr = clonestr("{\"error\":\"cant parse jsonstr\"}");
return(retstr);
}