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.

223 lines
7.5 KiB

8 years ago
/******************************************************************************
* Copyright © 2014-2017 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. *
* *
******************************************************************************/
//
// LP_rpc.c
// marketmaker
//
8 years ago
char *LP_getdatadir()
{
return("/root");
}
8 years ago
cJSON *basilisk_nullretjson(cJSON *retjson)
{
8 years ago
/*char *outstr;
8 years ago
if ( retjson != 0 )
{
outstr = jprint(retjson,0);
8 years ago
if ( strcmp(outstr,"{}") == 0 || strcmp(outstr,"[]") == 0 )
8 years ago
{
free_json(retjson);
retjson = 0;
}
free(outstr);
8 years ago
}*/
8 years ago
return(retjson);
}
8 years ago
char *blocktrail_listtransactions(char *symbol,char *coinaddr,int32_t num,int32_t skip)
8 years ago
{
return(0);
}
8 years ago
cJSON *bitcoin_json(struct iguana_info *coin,char *method,char *params)
8 years ago
{
8 years ago
char *retstr; cJSON *retjson = 0;
if ( coin != 0 )
{
8 years ago
//printf("issue.(%s, %s, %s, %s, %s)\n",coin->symbol,coin->serverport,coin->userpass,method,params);
8 years ago
retstr = bitcoind_passthru(coin->symbol,coin->serverport,coin->userpass,method,params);
8 years ago
if ( retstr != 0 && retstr[0] != 0 )
{
8 years ago
//printf("%s: %s.%s -> (%s)\n",coin->symbol,method,params,retstr);
8 years ago
retjson = cJSON_Parse(retstr);
free(retstr);
}
//printf("dpow_gettxout.(%s)\n",retstr);
}
return(basilisk_nullretjson(retjson));
8 years ago
}
void LP_unspents_mark(char *symbol,cJSON *vins)
{
8 years ago
printf("LOCK (%s)\n",jprint(vins,0));
8 years ago
}
8 years ago
cJSON *LP_getinfo(char *symbol)
{
struct iguana_info *coin = LP_coinfind(symbol);
return(bitcoin_json(coin,"getinfo","[]"));
}
8 years ago
cJSON *LP_gettxout(char *symbol,bits256 txid,int32_t vout)
8 years ago
{
8 years ago
char buf[128],str[65]; struct iguana_info *coin = LP_coinfind(symbol);
8 years ago
sprintf(buf,"\"%s\", %d",bits256_str(str,txid),vout);
8 years ago
return(bitcoin_json(coin,"gettxout",buf));
8 years ago
}
8 years ago
cJSON *LP_gettx(char *symbol,bits256 txid)
8 years ago
{
8 years ago
char buf[128],str[65]; struct iguana_info *coin = LP_coinfind(symbol);
8 years ago
sprintf(buf,"[\"%s\", 1]",bits256_str(str,txid));
8 years ago
return(bitcoin_json(coin,"getrawtransaction",buf));
8 years ago
}
8 years ago
cJSON *LP_listunspent(char *symbol,char *coinaddr)
8 years ago
{
8 years ago
char buf[128]; struct iguana_info *coin = LP_coinfind(symbol);
8 years ago
sprintf(buf,"0, 99999999, [\"%s\"]",coinaddr);
8 years ago
return(bitcoin_json(coin,"listunspent",buf));
8 years ago
}
8 years ago
cJSON *LP_listtransactions(char *symbol,char *coinaddr,int32_t count,int32_t skip)
8 years ago
{
8 years ago
char buf[128]; struct iguana_info *coin = LP_coinfind(symbol);
8 years ago
if ( count == 0 )
count = 100;
sprintf(buf,"[\"%s\", %d, %d, true]",coinaddr,count,skip);
8 years ago
return(bitcoin_json(coin,"listtransactions",buf));
8 years ago
}
8 years ago
cJSON *LP_validateaddress(char *symbol,char *address)
8 years ago
{
8 years ago
char buf[512]; struct iguana_info *coin = LP_coinfind(symbol);
sprintf(buf,"\"%s\"",address);
return(bitcoin_json(coin,"validateaddress",buf));
8 years ago
}
8 years ago
cJSON *LP_importprivkey(char *symbol,char *wifstr,char *label,int32_t flag)
8 years ago
{
char buf[512]; struct iguana_info *coin = LP_coinfind(symbol);
8 years ago
sprintf(buf,"[\"%s\", \"%s\", %s]",wifstr,label,flag < 0 ? "false" : "true");
8 years ago
return(bitcoin_json(coin,"importprivkey",buf));
}
8 years ago
int32_t LP_importaddress(char *symbol,char *address)
8 years ago
{
8 years ago
char buf[1024],*retstr; cJSON *validatejson; int32_t isvalid=0,doneflag = 0; struct iguana_info *coin = LP_coinfind(symbol);
8 years ago
if ( coin == 0 )
return(-2);
if ( (validatejson= LP_validateaddress(symbol,address)) != 0 )
8 years ago
{
8 years ago
if ( (isvalid= is_cJSON_True(jobj(validatejson,"isvalid")) != 0) != 0 )
8 years ago
{
8 years ago
if ( is_cJSON_True(jobj(validatejson,"iswatchonly")) != 0 || is_cJSON_True(jobj(validatejson,"ismine")) != 0 )
doneflag = 1;
8 years ago
}
8 years ago
free_json(validatejson);
8 years ago
}
if ( isvalid == 0 )
8 years ago
return(-1);
8 years ago
if ( doneflag != 0 )
return(0); // success
8 years ago
sprintf(buf,"[\"%s\", \"%s\", false]",address,address);
8 years ago
if ( (retstr= bitcoind_passthru(symbol,coin->serverport,coin->userpass,"importaddress",buf)) != 0 )
8 years ago
{
printf("importaddress.(%s %s) -> (%s)\n",symbol,address,retstr);
8 years ago
free(retstr);
8 years ago
} else printf("importaddress.(%s %s)\n",symbol,address);
8 years ago
return(1);
8 years ago
}
8 years ago
double LP_getestimatedrate(char *symbol)
8 years ago
{
8 years ago
char buf[512],*retstr; double rate = 200; struct iguana_info *coin = LP_coinfind(symbol);
8 years ago
if ( coin != 0 )
8 years ago
{
8 years ago
sprintf(buf,"[%d]",3);
8 years ago
if ( (retstr= bitcoind_passthru(symbol,coin->serverport,coin->userpass,"estimatefee",buf)) != 0 )
8 years ago
{
8 years ago
if ( retstr[0] != '-' )
{
8 years ago
rate = atof(retstr) / 1024.;
8 years ago
printf("estimated rate.(%s) %s -> %.8f\n",symbol,retstr,rate);
8 years ago
}
8 years ago
free(retstr);
}
}
8 years ago
return(rate);
8 years ago
}
8 years ago
uint64_t LP_txfee(char *symbol)
8 years ago
{
8 years ago
uint64_t txfee = 0;
if ( strcmp(symbol,"BTC") != 0 )
8 years ago
txfee = 10000;
8 years ago
return(txfee);
8 years ago
}
8 years ago
char *LP_sendrawtransaction(char *symbol,char *signedtx)
8 years ago
{
8 years ago
cJSON *array; char *paramstr,*retstr; struct iguana_info *coin = LP_coinfind(symbol);
if ( coin == 0 )
return(0);
array = cJSON_CreateArray();
jaddistr(array,signedtx);
paramstr = jprint(array,1);
retstr = bitcoind_passthru(symbol,coin->serverport,coin->userpass,"sendrawtransaction",paramstr);
printf(">>>>>>>>>>> %s dpow_sendrawtransaction.(%s) -> (%s)\n",coin->symbol,paramstr,retstr);
free(paramstr);
return(retstr);
8 years ago
}
8 years ago
char *LP_signrawtx(char *symbol,bits256 *signedtxidp,int32_t *completedp,cJSON *vins,char *rawtx,cJSON *privkeys,struct vin_info *V)
8 years ago
{
8 years ago
cJSON *array,*json; int32_t len; uint8_t *data; char *paramstr,*retstr,*hexstr,*signedtx=0; struct iguana_info *coin = LP_coinfind(symbol);
memset(signedtxidp,0,sizeof(*signedtxidp));
*completedp = 0;
if ( coin == 0 )
return(0);
array = cJSON_CreateArray();
jaddistr(array,rawtx);
jaddi(array,jduplicate(vins));
jaddi(array,jduplicate(privkeys));
paramstr = jprint(array,1);
//printf("signrawtransaction\n");
if ( (retstr= bitcoind_passthru(symbol,coin->serverport,coin->userpass,"signrawtransaction",paramstr)) != 0 )
8 years ago
{
8 years ago
printf("%s signrawtransaction.(%s) params.(%s)\n",coin->symbol,retstr,paramstr);
if ( (json= cJSON_Parse(retstr)) != 0 )
8 years ago
{
8 years ago
if ( (hexstr= jstr(json,"hex")) != 0 )
8 years ago
{
8 years ago
len = (int32_t)strlen(hexstr);
signedtx = calloc(1,len+1);
strcpy(signedtx,hexstr);
*completedp = jint(json,"completed");
data = malloc(len >> 1);
decode_hex(data,len>>1,hexstr);
*signedtxidp = bits256_doublesha256(0,data,len >> 1);
}
free_json(json);
}
free(retstr);
8 years ago
}
8 years ago
free(paramstr);
return(signedtx);
8 years ago
}