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.

1049 lines
46 KiB

8 years ago
/******************************************************************************
* Copyright © 2014-2018 The SuperNET Developers. *
8 years ago
* *
* 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_commands.c
// marketmaker
//
8 years ago
char *LP_numutxos()
{
cJSON *retjson = cJSON_CreateObject();
if ( LP_mypeer != 0 )
{
8 years ago
jaddstr(retjson,"ipaddr",LP_mypeer->ipaddr);
jaddnum(retjson,"port",LP_mypeer->port);
7 years ago
//jaddnum(retjson,"numutxos",LP_mypeer->numutxos);
8 years ago
jaddnum(retjson,"numpeers",LP_mypeer->numpeers);
7 years ago
jaddnum(retjson,"session",G.LP_sessionid);
8 years ago
} else jaddstr(retjson,"error","client node");
8 years ago
return(jprint(retjson,1));
}
8 years ago
7 years ago
char *stats_JSON(void *ctx,int32_t fastflag,char *myipaddr,int32_t pubsock,cJSON *argjson,char *remoteaddr,uint16_t port) // from rpc port
8 years ago
{
char *method,*userpass,*base,*rel,*coin,*passphrase,*retstr = 0; int32_t authenticated=0,changed,flag = 0; cJSON *retjson,*reqjson = 0; struct iguana_info *ptr;
7 years ago
method = jstr(argjson,"method");
7 years ago
if ( method != 0 && (strcmp(method,"addr_unspents") == 0 || strcmp(method,"uitem") == 0 || strcmp(method,"postutxos") == 0) )
7 years ago
return(0);
7 years ago
//printf("stats_JSON.(%s)\n",jprint(argjson,0));
7 years ago
/*if ( (ipaddr= jstr(argjson,"ipaddr")) != 0 && (argport= juint(argjson,"port")) != 0 && (method == 0 || strcmp(method,"electrum") != 0) )
8 years ago
{
8 years ago
if ( strcmp(ipaddr,"127.0.0.1") != 0 && argport >= 1000 )
8 years ago
{
flag = 1;
if ( (pushport= juint(argjson,"push")) == 0 )
pushport = argport + 1;
if ( (subport= juint(argjson,"sub")) == 0 )
subport = argport + 2;
if ( (peer= LP_peerfind((uint32_t)calc_ipbits(ipaddr),argport)) != 0 )
{
if ( 0 && (otherpeers= jint(argjson,"numpeers")) > peer->numpeers )
peer->numpeers = otherpeers;
8 years ago
if ( peer->sessionid == 0 )
peer->sessionid = juint(argjson,"session");
8 years ago
//printf("peer.(%s) found (%d %d) (%d %d) (%s)\n",peer->ipaddr,peer->numpeers,peer->numutxos,otherpeers,othernumutxos,jprint(argjson,0));
8 years ago
} else LP_addpeer(LP_mypeer,LP_mypubsock,ipaddr,argport,pushport,subport,jint(argjson,"numpeers"),jint(argjson,"numutxos"),juint(argjson,"session"));
8 years ago
}
7 years ago
}*/
7 years ago
if ( method == 0 )
8 years ago
{
7 years ago
if ( is_cJSON_Array(argjson) != 0 )
printf("RAWARRAY command? %s\n",jprint(argjson,0));
8 years ago
if ( flag == 0 || jobj(argjson,"result") != 0 )
7 years ago
printf("stats_JSON no method: (%s)\n",jprint(argjson,0));
8 years ago
return(0);
8 years ago
}
7 years ago
if ( strcmp(method,"hello") == 0 )
{
7 years ago
//int32_t i; cJSON *array = cJSON_CreateArray();
7 years ago
retjson = cJSON_CreateObject();
jaddstr(retjson,"result","success");
jaddstr(retjson,"status","got hello");
7 years ago
//for (i=0; i<10000; i++)
// jaddinum(array,i);
//jadd(retjson,"array",array);
7 years ago
return(jprint(retjson,1));
7 years ago
//printf("got hello from %s:%u\n",ipaddr!=0?ipaddr:"",argport);
7 years ago
//return(clonestr("{\"result\":\"success\",\"status\":\"got hello\"}"));
7 years ago
}
7 years ago
/*else if ( strcmp(method,"sendmessage") == 0 && jobj(argjson,"userpass") == 0 )
{
static char *laststr;
char *newstr; bits256 pubkey = jbits256(argjson,"pubkey");
if ( bits256_nonz(pubkey) == 0 || bits256_cmp(pubkey,G.LP_mypub25519) == 0 )
{
newstr = jprint(argjson,0);
if ( laststr == 0 || strcmp(laststr,newstr) != 0 )
{
printf("got message.(%s) from %s:%u\n",newstr,ipaddr!=0?ipaddr:"",argport);
if ( laststr != 0 )
free(laststr);
laststr = newstr;
LP_gotmessage(argjson);
retstr = clonestr(laststr);
}
} else retstr = clonestr("{\"error\":\"duplicate message\"}");
7 years ago
}*/
8 years ago
//else if ( strcmp(method,"nn_tests") == 0 )
// return(clonestr("{\"result\":\"success\"}"));
else if ( strcmp(method,"help") == 0 )
return(clonestr("{\"result\":\" \
7 years ago
available localhost RPC commands: \n \
7 years ago
setprice(base, rel, price, broadcast=1)\n\
7 years ago
autoprice(base, rel, fixed, minprice, maxprice, margin, refbase, refrel, factor, offset)*\n\
7 years ago
goal(coin=*, val=<autocalc>)\n\
8 years ago
myprice(base, rel)\n\
7 years ago
enable(coin)\n\
disable(coin)\n\
7 years ago
notarizations(coin)\n\
7 years ago
statsdisp(starttime=0, endtime=0, gui="", pubkey="", base="", rel="")\n\
7 years ago
ticker(base="", rel="")\n\
7 years ago
tradesarray(base, rel, starttime=<now>-timescale*1024, endtime=<now>, timescale=60) -> [timestamp, high, low, open, close, relvolume, basevolume, aveprice, numtrades]\n\
7 years ago
pricearray(base, rel, starttime=0, endtime=0, timescale=60) -> [timestamp, avebid, aveask, highbid, lowask]\n\
getrawtransaction(coin, txid)\n\
7 years ago
inventory(coin, reset=0, [passphrase=])\n\
7 years ago
lastnonce()\n\
cancel(uuid)\n\
7 years ago
buy(base, rel, price, relvolume, timeout=10, duration=3600, nonce)\n\
sell(base, rel, price, basevolume, timeout=10, duration=3600, nonce)\n\
withdraw(coin, outputs[], broadcast=0)\n\
eth_withdraw(coin, to, amount, gas, gas_price, broadcast=0)\n\
txblast(coin, utxotxid, utxovout, utxovalue, txfee, passphrase, outputs[], broadcast=0)\n\
7 years ago
sendrawtransaction(coin, signedtx)\n\
7 years ago
swapstatus(pending=0, fast=0)\n\
7 years ago
swapstatus(coin, limit=10)\n\
swapstatus(base, rel, limit=10)\n\
7 years ago
swapstatus(requestid, quoteid, pending=0, fast=0)\n\
7 years ago
recentswaps(limit=3)\n\
kickstart(requestid, quoteid)\n\
7 years ago
notarizations(coin)\n\
8 years ago
public API:\n \
getcoins()\n\
8 years ago
getcoin(coin)\n\
8 years ago
portfolio()\n\
8 years ago
getpeers()\n\
passphrase(passphrase, gui, netid=0, seednode="")\n\
7 years ago
listunspent(coin, address)\n\
7 years ago
setconfirms(coin, numconfirms, maxconfirms=6)\n\
7 years ago
trust(pubkey, trust) # positive to trust, 0 for normal, negative to blacklist\n\
7 years ago
balance(coin, address)\n\
7 years ago
balances(address)\n\
7 years ago
fundvalue(address="", holdings=[], divisor=0)\n\
8 years ago
orderbook(base, rel, duration=3600)\n\
7 years ago
getprices()\n\
7 years ago
inuse()\n\
7 years ago
movecoinbases(coin)\n\
7 years ago
getmyprice(base, rel)\n\
7 years ago
getprice(base, rel)\n\
7 years ago
//sendmessage(base=coin, rel="", pubkey=zero, <argjson method2>)\n\
//getmessages(firsti=0, num=100)\n\
//deletemessages(firsti=0, num=100)\n\
secretaddresses(prefix='secretaddress', passphrase, num=10, pubtype=60, taddr=0)\n\
7 years ago
gen64addrs(passphrase, taddr=0, pubtype=60)\n\
7 years ago
electrum(coin, ipaddr, port)\n\
7 years ago
snapshot(coin, height)\n\
7 years ago
snapshot_balance(coin, height, addresses[])\n\
7 years ago
dividends(coin, height, <args>)\n\
7 years ago
stop()\n\
bot_list()\n\
7 years ago
bot_statuslist()\n\
bot_buy(base, rel, maxprice, relvolume) -> botid\n\
bot_sell(base, rel, minprice, basevolume) -> botid\n\
bot_settings(botid, newprice, newvolume)\n\
bot_status(botid)\n\
bot_stop(botid)\n\
bot_pause(botid)\n\
7 years ago
calcaddress(passphrase, coin=KMD)\n\
7 years ago
convaddress(coin, address, destcoin)\n\
instantdex_deposit(weeks, amount, broadcast=1)\n\
instantdex_claim()\n\
7 years ago
timelock(coin, duration, destaddr=(tradeaddr), amount)\n\
unlockedspend(coin, txid)\n\
opreturndecrypt(coin, txid, passphrase)\n\
getendpoint(port=5555)\n\
7 years ago
getfee(coin)\n\
mpnet(onoff)\n\
7 years ago
sleep(seconds=60)\n\
7 years ago
listtransactions(coin, address, count=10, skip=0)\n\
7 years ago
jpg(srcfile, destfile, power2=7, password, data="", required, ind=0)\n\
version\n\
8 years ago
\"}"));
if ( strcmp(method,"version") == 0 ) {
retjson = cJSON_CreateObject();
jaddstr(retjson,"result",MM_VERSION);
return(jprint(retjson,1));
}
7 years ago
if ( (base= jstr(argjson,"base")) == 0 )
base = "";
if ((rel= jstr(argjson,"rel")) == 0 )
rel = "";
if ( (coin= jstr(argjson,"coin")) == 0 )
coin = "";
7 years ago
if ( G.USERPASS[0] != 0 && strcmp(remoteaddr,"127.0.0.1") == 0 && port != 0 && strcmp(method,"psock") != 0 ) // protected localhost
8 years ago
{
7 years ago
if ( G.USERPASS_COUNTER == 0 )
8 years ago
{
7 years ago
G.USERPASS_COUNTER = 1;
7 years ago
LP_cmdcount++;
8 years ago
}
// if passphrase api and passphrase is right, ignore userpass, use hass of passphrase
if ( strcmp(method,"passphrase") == 0 && (passphrase= jstr(argjson,"passphrase")) != 0 )
{
bits256 passhash; char str[65],str2[65];
vcalc_sha256(0,passhash.bytes,(uint8_t *)passphrase,(int32_t)strlen(passphrase));
if ( bits256_cmp(passhash,G.LP_passhash) == 0 )
authenticated = 1;
7 years ago
else printf("passhash %s != G %s\n",bits256_str(str,passhash),bits256_str(str2,G.LP_passhash));
}
char passhashstr[65]; bits256_str(passhashstr,G.LP_passhash);
if ( authenticated == 0 && ((userpass= jstr(argjson,"userpass")) == 0 || (strcmp(userpass,G.USERPASS) != 0 && strcmp(userpass,passhashstr) != 0)) )
7 years ago
return(clonestr("{\"error\":\"authentication error you need to make sure userpass is set\"}"));
if ( jobj(argjson,"userpass") != 0 )
jdelete(argjson,"userpass");
7 years ago
LP_cmdcount++;
if ( strcmp(method,"passphrase") == 0 )
{
7 years ago
char coinaddr[64],pub33str[67];
7 years ago
G.USERPASS_COUNTER = 1;
if ( LP_passphrase_init(jstr(argjson,"passphrase"),jstr(argjson,"gui"),juint(argjson,"netid"),jstr(argjson,"seednode")) < 0 )
return(clonestr("{\"error\":\"couldnt change passphrase\"}"));
{
retjson = cJSON_CreateObject();
jaddstr(retjson,"result","success");
jaddstr(retjson,"userpass",G.USERPASS);
jaddbits256(retjson,"mypubkey",G.LP_mypub25519);
7 years ago
init_hexbytes_noT(pub33str,G.LP_pubsecp,33);
jaddstr(retjson,"pubsecp",pub33str);
bitcoin_address("KMD",coinaddr,0,60,G.LP_myrmd160,20);
7 years ago
jaddstr(retjson,"KMD",coinaddr);
bitcoin_address("BTC",coinaddr,0,0,G.LP_myrmd160,20);
7 years ago
jaddstr(retjson,"BTC",coinaddr);
jaddstr(retjson,"NXT",G.LP_NXTaddr);
jadd(retjson,"coins",LP_coinsjson(LP_showwif));
return(jprint(retjson,1));
}
}
else if ( strcmp(method,"instantdex_deposit") == 0 )
7 years ago
{
if ( (ptr= LP_coinsearch("KMD")) != 0 )
{
if ( jint(argjson,"weeks") <= 0 ) {
return(clonestr("{\"error\":\"instantdex_deposit weeks param must be greater than zero\"}"));
}
if ( jdouble(argjson,"amount") < 10. ) {
return(clonestr("{\"error\":\"instantdex_deposit amount param must be equal or greater than 10\"}"));
}
return(LP_instantdex_deposit(ptr,juint(argjson,"weeks"),jdouble(argjson,"amount"),jobj(argjson,"broadcast") != 0 ? jint(argjson,"broadcast") : 1));
7 years ago
}
return(clonestr("{\"error\":\"cant find KMD\"}"));
}
else if ( strcmp(method,"mpnet") == 0 )
{
G.mpnet = jint(argjson,"onoff");
printf("MPNET onoff.%d\n",G.mpnet);
return(clonestr("{\"status\":\"success\"}"));
}
7 years ago
else if ( strcmp(method,"getendpoint") == 0 )
{
int32_t err,mode; uint16_t wsport = 5555; char endpoint[64],bindpoint[64];
if ( juint(argjson,"port") != 0 )
wsport = juint(argjson,"port");
7 years ago
retjson = cJSON_CreateObject();
if ( IPC_ENDPOINT >= 0 )
{
jaddstr(retjson,"error","IPC endpoint already exists");
7 years ago
jaddnum(retjson,"socket",IPC_ENDPOINT);
7 years ago
}
else
{
7 years ago
if ( (IPC_ENDPOINT= nn_socket(AF_SP,NN_PAIR)) >= 0 )
7 years ago
{
7 years ago
sprintf(bindpoint,"ws://*:%u",wsport);
sprintf(endpoint,"ws://127.0.0.1:%u",wsport);
if ( (err= nn_bind(IPC_ENDPOINT,bindpoint)) >= 0 )
7 years ago
{
jaddstr(retjson,"result","success");
jaddstr(retjson,"endpoint",endpoint);
7 years ago
jaddnum(retjson,"socket",IPC_ENDPOINT);
7 years ago
mode = NN_WS_MSG_TYPE_TEXT;
err = nn_setsockopt(IPC_ENDPOINT,NN_SOL_SOCKET,NN_WS_MSG_TYPE,&mode,sizeof(mode));
jaddnum(retjson,"sockopt",err);
7 years ago
}
else
{
jaddstr(retjson,"error",(char *)nn_strerror(nn_errno()));
7 years ago
jaddstr(retjson,"bind",bindpoint);
7 years ago
jaddnum(retjson,"err",err);
7 years ago
jaddnum(retjson,"socket",IPC_ENDPOINT);
7 years ago
nn_close(IPC_ENDPOINT);
IPC_ENDPOINT = -1;
7 years ago
}
7 years ago
} else jaddstr(retjson,"error","couldnt get NN_PAIR socket");
7 years ago
}
return(jprint(retjson,1));
}
7 years ago
else if ( strcmp(method,"verus") == 0 )
{
return(verusblocks());
}
else if ( strcmp(method,"instantdex_claim") == 0 )
7 years ago
{
if ( (ptr= LP_coinsearch("KMD")) != 0 )
{
7 years ago
return(LP_instantdex_claim(ptr));
7 years ago
}
return(clonestr("{\"error\":\"cant find KMD\"}"));
}
7 years ago
else if ( strcmp(method,"jpg") == 0 )
{
7 years ago
return(LP_jpg(jstr(argjson,"srcfile"),jstr(argjson,"destfile"),jint(argjson,"power2"),jstr(argjson,"password"),jstr(argjson,"data"),jint(argjson,"required"),juint(argjson,"ind")));
7 years ago
}
7 years ago
/*else if ( strcmp(method,"sendmessage") == 0 )
8 years ago
{
8 years ago
if ( jobj(argjson,"method2") == 0 )
{
7 years ago
LP_broadcast_message(LP_mypubsock,base!=0?base:coin,rel,jbits256(argjson,"pubkey"),jprint(argjson,0));
8 years ago
}
return(clonestr("{\"result\":\"success\"}"));
}
7 years ago
else if ( strcmp(method,"getmessages") == 0 )
{
if ( (retjson= LP_getmessages(jint(argjson,"firsti"),jint(argjson,"num"))) != 0 )
return(jprint(retjson,1));
else return(clonestr("{\"error\":\"null messages\"}"));
}
else if ( strcmp(method,"deletemessages") == 0 )
{
LP_deletemessages(jint(argjson,"firsti"),jint(argjson,"num"));
return(clonestr("{\"result\":\"success\"}"));
}*/
else if ( strcmp(method,"cancel") == 0 )
{
return(LP_cancel_order(jstr(argjson,"uuid")));
}
7 years ago
else if ( strcmp(method,"recentswaps") == 0 )
{
return(LP_recent_swaps(jint(argjson,"limit"),0));
7 years ago
}
7 years ago
else if ( strcmp(method,"stop") == 0 )
{
printf("DEBUG stop\n");
LP_STOP_RECEIVED = 1;
return(clonestr("{\"result\":\"success\"}"));
7 years ago
}
7 years ago
else if ( strcmp(method,"millis") == 0 )
{
LP_millistats_update(0);
return(clonestr("{\"result\":\"success\"}"));
}
7 years ago
else if ( strcmp(method,"sleep") == 0 )
{
if ( jint(argjson,"seconds") == 0 )
sleep(60);
else sleep(jint(argjson,"seconds"));
return(clonestr("{\"result\":\"success\",\"status\":\"feeling good after sleeping\"}"));
}
7 years ago
else if ( strcmp(method,"getprices") == 0 )
return(LP_prices());
else if ( strcmp(method,"getpeers") == 0 )
return(LP_peers());
else if ( strcmp(method,"getcoins") == 0 )
return(jprint(LP_coinsjson(0),1));
7 years ago
else if ( strcmp(method,"notarizations") == 0 )
{
if ( (ptr= LP_coinsearch(coin)) != 0 )
{
retjson = cJSON_CreateObject();
jaddstr(retjson,"result","success");
7 years ago
jaddstr(retjson,"coin",coin);
7 years ago
jaddnum(retjson,"lastnotarization",ptr->notarized);
jaddnum(retjson,"bestheight",ptr->height);
7 years ago
return(jprint(retjson,1));
} else return(clonestr("{\"error\":\"cant find coin\"}"));
}
8 years ago
else if ( strcmp(method,"portfolio") == 0 )
{
return(LP_portfolio());
}
7 years ago
else if ( strcmp(method,"calcaddress") == 0 )
{
bits256 privkey,pub; uint8_t pubtype,wiftaddr,p2shtype,taddr,wiftype,pubkey33[33]; char *passphrase,coinaddr[64],wifstr[64],pubsecp[67];
7 years ago
if ( (passphrase= jstr(argjson,"passphrase")) != 0 )
{
conv_NXTpassword(privkey.bytes,pub.bytes,(uint8_t *)passphrase,(int32_t)strlen(passphrase));
7 years ago
privkey.bytes[0] &= 248, privkey.bytes[31] &= 127, privkey.bytes[31] |= 64;
if ( (coin= jstr(argjson,"coin")) == 0 || (ptr= LP_coinfind(coin)) == 0 )
{
coin = "KMD";
taddr = 0;
pubtype = 60;
p2shtype = 85;
wiftype = 188;
wiftaddr = 0;
}
else
{
coin = ptr->symbol;
taddr = ptr->taddr;
pubtype = ptr->pubtype;
p2shtype = ptr->p2shtype;
wiftype = ptr->wiftype;
wiftaddr = ptr->wiftaddr;
}
7 years ago
retjson = cJSON_CreateObject();
jaddstr(retjson,"passphrase",passphrase);
bitcoin_priv2pub(ctx,coin,pubkey33,coinaddr,privkey,taddr,pubtype);
init_hexbytes_noT(pubsecp,pubkey33,33);
jaddstr(retjson,"pubsecp",pubsecp);
7 years ago
jaddstr(retjson,"coinaddr",coinaddr);
bitcoin_priv2pub(ctx,coin,pubkey33,coinaddr,privkey,taddr,p2shtype);
jaddstr(retjson,"p2shaddr",coinaddr);
7 years ago
jaddbits256(retjson,"privkey",privkey);
bitcoin_priv2wif(coin,wiftaddr,wifstr,privkey,wiftype);
jaddstr(retjson,"wif",wifstr);
7 years ago
return(jprint(retjson,1));
} else return(clonestr("{\"error\":\"need to have passphrase\"}"));
}
7 years ago
else if ( strcmp(method,"statsdisp") == 0 )
7 years ago
{
7 years ago
return(jprint(LP_statslog_disp(juint(argjson,"starttime"),juint(argjson,"endtime"),jstr(argjson,"gui"),jbits256(argjson,"pubkey"),jstr(argjson,"base"),jstr(argjson,"rel")),1));
7 years ago
}
7 years ago
else if ( strcmp(method,"ticker") == 0 )
{
return(LP_ticker(jstr(argjson,"base"),jstr(argjson,"rel")));
}
7 years ago
else if ( strcmp(method,"gen64addrs") == 0 )
{
uint8_t taddr,pubtype;
pubtype = (jobj(argjson,"pubtype") == 0) ? 60 : juint(argjson,"pubtype");
taddr = (jobj(argjson,"taddr") == 0) ? 0 : juint(argjson,"taddr");
return(LP_gen64addrs(ctx,jstr(argjson,"passphrase"),taddr,pubtype));
}
7 years ago
else if ( strcmp(method,"secretaddresses") == 0 )
{
uint8_t taddr,pubtype;
pubtype = (jobj(argjson,"pubtype") == 0) ? 60 : juint(argjson,"pubtype");
taddr = (jobj(argjson,"taddr") == 0) ? 0 : juint(argjson,"taddr");
return(LP_secretaddresses(ctx,jstr(argjson,"prefix"),jstr(argjson,"passphrase"),juint(argjson,"num"),taddr,pubtype));
7 years ago
}
else if ( strcmp(method,"kickstart") == 0 )
{
uint32_t requestid,quoteid;
if ( (requestid= juint(argjson,"requestid")) != 0 && (quoteid= juint(argjson,"quoteid")) != 0 )
return(LP_kickstart(requestid,quoteid));
else return(clonestr("{\"error\":\"kickstart needs requestid and quoteid\"}"));
}
7 years ago
else if ( strcmp(method,"swapstatus") == 0 )
{
uint32_t requestid,quoteid;
if ( (requestid= juint(argjson,"requestid")) != 0 && (quoteid= juint(argjson,"quoteid")) != 0 )
return(basilisk_swapentry(jint(argjson,"fast"),requestid,quoteid,1));
7 years ago
else if ( coin[0] != 0 )
7 years ago
return(basilisk_swapentries(1,coin,0,jint(argjson,"limit")));
7 years ago
else if ( base[0] != 0 && rel[0] != 0 )
7 years ago
return(basilisk_swapentries(1,base,rel,jint(argjson,"limit")));
else return(basilisk_swaplist(jint(argjson,"fast"),0,0,1,jint(argjson,"pending")));
7 years ago
}
7 years ago
else if ( strcmp(method,"dynamictrust") == 0 )
7 years ago
{
struct LP_address *ap; char *coinaddr;
if ( (ptr= LP_coinsearch("KMD")) != 0 && (coinaddr= jstr(argjson,"address")) != 0 )
{
7 years ago
//LP_zeroconf_deposits(ptr);
7 years ago
if ( (ap= LP_addressfind(ptr,coinaddr)) != 0 )
{
retjson = cJSON_CreateObject();
jaddstr(retjson,"result","success");
jaddstr(retjson,"address",coinaddr);
7 years ago
jaddnum(retjson,"zcredits",dstr(ap->instantdex_credits));
7 years ago
return(jprint(retjson,1));
}
}
return(clonestr("{\"error\":\"cant find address\"}"));
7 years ago
}
7 years ago
else if ( strcmp(method,"inuse") == 0 )
return(jprint(LP_inuse_json(),1));
#ifndef NOTETOMIC
else if ( strcmp(method,"eth_gas_price") == 0 )
{
return LP_eth_gas_price();
}
#endif
7 years ago
else if ( (retstr= LP_istradebots_command(ctx,pubsock,method,argjson)) != 0 )
return(retstr);
7 years ago
if ( base[0] != 0 && rel[0] != 0 )
8 years ago
{
8 years ago
double price,bid,ask;
if ( strcmp(method,"autoprice") == 0 )
{
7 years ago
if ( LP_autoprice(ctx,base,rel,argjson) < 0 )
return(clonestr("{\"error\":\"couldnt set autoprice\"}"));
else return(clonestr("{\"result\":\"success\"}"));
}
8 years ago
else if ( strcmp(method,"pricearray") == 0 )
8 years ago
{
7 years ago
uint32_t firsttime;
if ( base[0] != 0 && rel[0] != 0 )
{
7 years ago
if ( (firsttime= juint(argjson,"starttime")) < time(NULL)-30*24*3600 )
7 years ago
firsttime = (uint32_t)(time(NULL)-30*24*3600);
7 years ago
return(jprint(LP_pricearray(base,rel,firsttime,juint(argjson,"endtime"),jint(argjson,"timescale")),1));
7 years ago
} else return(clonestr("{\"error\":\"pricearray needs base and rel\"}"));
8 years ago
}
7 years ago
else if ( strcmp(method,"tradesarray") == 0 )
7 years ago
{
7 years ago
return(jprint(LP_tradesarray(base,rel,juint(argjson,"starttime"),juint(argjson,"endtime"),jint(argjson,"timescale")),1));
}
else if ( strcmp(method,"getprice") == 0 || strcmp(method,"getmyprice") == 0 )
{
double price,bid,ask;
if ( strcmp(method,"getprice") == 0 )
{
ask = LP_price(1,base,rel);
if ( (bid= LP_price(1,rel,base)) > SMALLVAL )
bid = 1./bid;
}
else
{
ask = LP_getmyprice(1,base,rel);
if ( (bid= LP_getmyprice(1,rel,base)) > SMALLVAL )
bid = 1./bid;
}
price = _pairaved(bid,ask);
retjson = cJSON_CreateObject();
jaddstr(retjson,"result","success");
jaddstr(retjson,"base",base);
jaddstr(retjson,"rel",rel);
jaddnum(retjson,"timestamp",time(NULL));
jaddnum(retjson,"bid",bid);
jaddnum(retjson,"ask",ask);
jaddnum(retjson,"price",price);
return(jprint(retjson,1));
}
else if ( strcmp(method,"orderbook") == 0 )
return(LP_orderbook(base,rel,jint(argjson,"duration")));
7 years ago
if ( IAMLP == 0 && LP_isdisabled(base,rel) != 0 )
return(clonestr("{\"error\":\"at least one of coins disabled\"}"));
price = jdouble(argjson,"price");
if ( strcmp(method,"setprice") == 0 )
{
if ( LP_mypriceset(1,&changed,base,rel,price) < 0 )
7 years ago
return(clonestr("{\"error\":\"couldnt set price\"}"));
//else if ( LP_mypriceset(1,&changed,rel,base,1./price) < 0 )
7 years ago
// return(clonestr("{\"error\":\"couldnt set price\"}"));
7 years ago
else if ( price == 0. || jobj(argjson,"broadcast") == 0 || jint(argjson,"broadcast") != 0 )
7 years ago
return(LP_pricepings(ctx,myipaddr,LP_mypubsock,base,rel,price * LP_profitratio));
else return(clonestr("{\"result\":\"success\"}"));
}
8 years ago
else if ( strcmp(method,"myprice") == 0 )
{
if ( LP_myprice(1,&bid,&ask,base,rel) > SMALLVAL )
8 years ago
{
retjson = cJSON_CreateObject();
jaddstr(retjson,"base",base);
jaddstr(retjson,"rel",rel);
jaddnum(retjson,"bid",bid);
jaddnum(retjson,"ask",ask);
return(jprint(retjson,1));
} else return(clonestr("{\"error\":\"no price set\"}"));
}
7 years ago
else if ( strcmp(method,"buy") == 0 )
{
7 years ago
int32_t fomo = 0; double vol;
if ( jobj(argjson,"fomo") != 0 )
{
fomo = 1;
price = 1.;
vol = jdouble(argjson,"fomo");
} else vol = jdouble(argjson,"relvolume");
7 years ago
if ( price > SMALLVAL )
{
return(LP_autobuy(ctx,fomo,myipaddr,pubsock,base,rel,price,vol,jint(argjson,"timeout"),jint(argjson,"duration"),jstr(argjson,"gui"),juint(argjson,"nonce"),jbits256(argjson,"destpubkey"),0,jstr(argjson,"uuid"),jint(argjson,"fill"),jint(argjson,"gtc")));
7 years ago
} else return(clonestr("{\"error\":\"no price set\"}"));
}
else if ( strcmp(method,"sell") == 0 )
{
7 years ago
int32_t fomo = 0; double vol;
if ( jobj(argjson,"dump") != 0 )
{
fomo = 1;
price = 1.;
7 years ago
vol = jdouble(argjson,"dump");
7 years ago
} else vol = jdouble(argjson,"basevolume");
7 years ago
if ( price > SMALLVAL )
{
return(LP_autobuy(ctx,fomo,myipaddr,pubsock,rel,base,1./price,vol,jint(argjson,"timeout"),jint(argjson,"duration"),jstr(argjson,"gui"),juint(argjson,"nonce"),jbits256(argjson,"destpubkey"),0,jstr(argjson,"uuid"),jint(argjson,"fill"),jint(argjson,"gtc")));
7 years ago
} else return(clonestr("{\"error\":\"no price set\"}"));
8 years ago
}
8 years ago
}
7 years ago
/*else if ( rel[0] != 0 && strcmp(method,"bestfit") == 0 )
8 years ago
{
double relvolume;
if ( (relvolume= jdouble(argjson,"relvolume")) > SMALLVAL )
return(LP_bestfit(rel,relvolume));
else return(clonestr("{\"error\":\"no relvolume set\"}"));
7 years ago
}*/
7 years ago
else if ( coin[0] != 0 )
8 years ago
{
8 years ago
if ( strcmp(method,"enable") == 0 )
8 years ago
{
7 years ago
//*
8 years ago
if ( (ptr= LP_coinsearch(coin)) != 0 )
{
if ( ptr->userpass[0] == 0 && ptr->etomic[0] == 0 )
7 years ago
{
cJSON *retjson = cJSON_CreateObject();
7 years ago
jaddstr(retjson,"error",LP_DONTCHANGE_ERRMSG0);
7 years ago
jaddstr(retjson,"coin",coin);
return(jprint(retjson,1));
}
#ifndef NOTETOMIC
if (strcmp(coin, "ETOMIC") == 0 && LP_RTsmartbalance(ptr) < 20 * SATOSHIDEN) {
if (get_etomic_from_faucet(ptr->smartaddr) != 1) {
return(clonestr("{\"error\":\"Could not get ETOMIC from faucet!\"}"));
}
}
if (ptr->etomic[0] != 0) {
if (isValidAddress(ptr->etomic) == 0) {
return(clonestr("{\"error\":\"'etomic' field is not valid address!\"}"));
}
struct iguana_info *etomic_coin = LP_coinsearch("ETOMIC");
if (etomic_coin->inactive != 0) {
return(clonestr("{\"error\":\"Enable ETOMIC first to use ETH/ERC20!\"}"));
}
if (ptr->decimals == 0 && strcmp(coin, "ETH") != 0) {
ptr->decimals = getErc20DecimalsZeroOnError(ptr->etomic);
if (ptr->decimals == 0) {
return(clonestr("{\"error\":\"Could not get token decimals or token has zero decimals which is not supported!\"}"));
}
} else if (strcmp(coin, "ETH") == 0) {
ptr->decimals = 18;
}
}
#endif
if ( LP_conflicts_find(ptr) == 0 )
7 years ago
{
cJSON *array;
ptr->inactive = 0;
#ifndef NOTETOMIC
if (ptr->etomic[0] != 0 && OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_etomic_txhistory_loop,(void *)ptr) != 0 )
{
printf("error launching LP_etomic_txhistory_loop %s\n",ptr->symbol);
ptr->inactive = (uint32_t)time(NULL);
return(clonestr("{\"error\":\"couldnt launch tx history thread\"}"));
}
#endif
LP_unspents_load(coin,ptr->smartaddr);
if ( strcmp(ptr->symbol,"KMD") == 0 )
LP_importaddress("KMD",BOTS_BONDADDRESS);
7 years ago
array = cJSON_CreateArray();
7 years ago
jaddi(array,LP_coinjson(ptr,0));
return(jprint(array,1));
} else return(clonestr("{\"error\":\"coin port conflicts with existing coin\"}"));
} else return(clonestr("{\"error\":\"couldnt find coin\"}"));
8 years ago
}
else if ( strcmp(method,"disable") == 0 )
{
7 years ago
//*
8 years ago
if ( (ptr= LP_coinsearch(coin)) != 0 )
7 years ago
{
8 years ago
ptr->inactive = (uint32_t)time(NULL);
7 years ago
cJSON *array = cJSON_CreateArray();
jaddi(array,LP_coinjson(ptr,0));
return(jprint(array,1));
} else return(clonestr("{\"error\":\"couldnt find coin\"}"));
8 years ago
}
7 years ago
else if ( strcmp(method,"listunspent") == 0 )
{
if ( (ptr= LP_coinsearch(coin)) != 0 )
{
7 years ago
char *coinaddr; bits256 zero;
memset(zero.bytes,0,sizeof(zero));
7 years ago
if ( (coinaddr= jstr(argjson,"address")) != 0 )
{
if ( coinaddr[0] != 0 )
{
LP_address(ptr,coinaddr);
if ( strcmp(coinaddr,ptr->smartaddr) == 0 && bits256_nonz(G.LP_privkey) != 0 )
{
7 years ago
LP_listunspent_issue(coin,coinaddr,2,zero,zero);
7 years ago
//LP_privkey_init(-1,ptr,G.LP_privkey,G.LP_mypub25519);
7 years ago
}
7 years ago
return(jprint(LP_listunspent(coin,coinaddr,zero,zero),1));
7 years ago
}
7 years ago
}
return(clonestr("{\"error\":\"no address specified\"}"));
7 years ago
} else return(clonestr("{\"error\":\"cant find coind\"}"));
}
else if ( strcmp(method,"balance") == 0 )
{
if ( (ptr= LP_coinsearch(coin)) != 0 )
return(jprint(LP_address_balance(ptr,jstr(argjson,"address"),1),1));
else return(clonestr("{\"error\":\"cant find coind\"}"));
}
7 years ago
else if ( strcmp(method,"getfee") == 0 )
{
uint64_t txfee;
if ( (ptr= LP_coinsearch(coin)) != 0 )
{
txfee = LP_txfeecalc(ptr,0,0);
retjson = cJSON_CreateObject();
jaddstr(retjson,"result","success");
jaddstr(retjson,"coin",coin);
jaddnum(retjson,"txfee",dstr(txfee));
return(jprint(retjson,1));
} else return(clonestr("{\"error\":\"cant find coind\"}"));
}
7 years ago
else if ( strcmp(method,"electrum") == 0 )
{
if ( (ptr= LP_coinsearch(coin)) != 0 )
{
ptr->inactive = 0;
ptr->cache_history = juint(argjson, "cache_history");
7 years ago
return(jprint(LP_electrumserver(ptr,jstr(argjson,"ipaddr"),juint(argjson,"port")),1));
7 years ago
} else return(clonestr("{\"error\":\"cant find coind\"}"));
7 years ago
}
7 years ago
else if ( strcmp(method,"sendrawtransaction") == 0 )
{
return(LP_sendrawtransaction(coin,jstr(argjson,"signedtx"),jint(argjson,"needjson")));
7 years ago
}
7 years ago
else if ( strcmp(method,"convaddress") == 0 )
{
return(LP_convaddress(coin,jstr(argjson,"address"),jstr(argjson,"destcoin")));
}
7 years ago
else if ( strcmp(method,"timelock") == 0 )
{
return(LP_timelock(coin,juint(argjson,"duration"),jstr(argjson,"destaddr"),jdouble(argjson,"amount")*SATOSHIDEN));
}
else if ( strcmp(method,"opreturndecrypt") == 0 )
{
return(LP_opreturndecrypt(ctx,coin,jbits256(argjson,"txid"),jstr(argjson,"passphrase")));
}
else if ( strcmp(method,"unlockedspend") == 0 )
{
return(LP_unlockedspend(ctx,coin,jbits256(argjson,"txid")));
}
7 years ago
// cJSON *LP_listtransactions(char *symbol,char *coinaddr,int32_t count,int32_t skip)
else if ( strcmp(method,"listtransactions") == 0 )
{
if ( (ptr= LP_coinfind(coin)) != 0 )
7 years ago
return(jprint(LP_listtransactions(coin,jstr(argjson,"address"),juint(argjson,"count"),juint(argjson,"skip")),1));
7 years ago
}
else if ( strcmp(method,"getrawtransaction") == 0 )
{
7 years ago
return(jprint(LP_gettx("stats_JSON",coin,jbits256(argjson,"txid"),0),1));
}
else if ( strcmp(method,"txblast") == 0 )
{
if ( (ptr= LP_coinsearch(coin)) != 0 )
return(LP_txblast(ptr,argjson));
else return(clonestr("{\"error\":\"cant find coind\"}"));
}
7 years ago
else if ( strcmp(method,"movecoinbases") == 0 )
{
return(LP_movecoinbases(coin));
}
7 years ago
else if ( strcmp(method,"withdraw") == 0 )
{
7 years ago
if ( (ptr= LP_coinsearch(coin)) != 0 )
{
7 years ago
if ( jobj(argjson,"outputs") == 0 && jstr(argjson,"opreturn") == 0 )
7 years ago
return(clonestr("{\"error\":\"withdraw needs to have outputs\"}"));
7 years ago
else if ( ptr->etomic[0] != 0 )
return(clonestr("{\"error\":\"use eth_withdraw for ETH/ERC20\"}"));
7 years ago
else return(LP_withdraw(ptr,argjson));
7 years ago
}
return(clonestr("{\"error\":\"cant find coind\"}"));
7 years ago
}
#ifndef NOTETOMIC
else if ( strcmp(method,"eth_withdraw") == 0 )
{
if ( (ptr= LP_coinsearch(coin)) != 0 ) {
return LP_eth_withdraw(ptr, argjson);
}
}
#endif
7 years ago
else if ( strcmp(method,"setconfirms") == 0 )
{
int32_t n;
n = jint(argjson,"numconfirms");
if ( n < 0 )
return(clonestr("{\"error\":\"illegal numconfirms\"}"));
if ( (ptr= LP_coinsearch(coin)) != 0 )
{
ptr->userconfirms = n;
if ( (n= jint(argjson,"maxconfirms")) > 0 )
ptr->maxconfirms = n;
if ( ptr->maxconfirms > 0 && ptr->userconfirms > ptr->maxconfirms )
ptr->userconfirms = ptr->maxconfirms;
return(clonestr("{\"result\":\"success\"}"));
} else return(clonestr("{\"error\":\"cant find coind\"}"));
}
7 years ago
else if ( strcmp(method,"snapshot") == 0 )
{
if ( (ptr= LP_coinsearch(coin)) != 0 )
7 years ago
return(jprint(LP_snapshot(ptr,juint(argjson,"height")),1));
else return(clonestr("{\"error\":\"cant find coind\"}"));
7 years ago
}
7 years ago
else if ( strcmp(method,"dividends") == 0 )
{
if ( (ptr= LP_coinsearch(coin)) != 0 )
return(LP_dividends(ptr,juint(argjson,"height"),argjson));
else return(clonestr("{\"error\":\"cant find coind\"}"));
}
7 years ago
else if ( strcmp(method,"snapshot_balance") == 0 )
7 years ago
{
if ( (ptr= LP_coinsearch(coin)) != 0 )
return(LP_snapshot_balance(ptr,juint(argjson,"height"),argjson));
else return(clonestr("{\"error\":\"cant find coind\"}"));
}
8 years ago
if ( LP_isdisabled(coin,0) != 0 )
7 years ago
{
retjson = cJSON_CreateObject();
jaddstr(retjson,"error",LP_DONTCHANGE_ERRMSG1);
return(jprint(retjson,1));
}
8 years ago
if ( strcmp(method,"inventory") == 0 )
{
7 years ago
struct iguana_info *ptr; int32_t num;
8 years ago
if ( (ptr= LP_coinfind(coin)) != 0 )
{
7 years ago
LP_address(ptr,ptr->smartaddr);
7 years ago
if ( jint(argjson,"reset") != 0 )
7 years ago
{
7 years ago
ptr->privkeydepth = 0;
7 years ago
LP_address_utxo_reset(&num,ptr);
LP_passphrase_init(jstr(argjson,"passphrase"),G.gui,G.netid,G.seednode);
7 years ago
}
7 years ago
if ( bits256_nonz(G.LP_privkey) != 0 )
LP_privkey_init(-1,ptr,G.LP_privkey,G.LP_mypub25519);
else printf("no LP_privkey\n");
8 years ago
retjson = cJSON_CreateObject();
jaddstr(retjson,"result","success");
8 years ago
jaddstr(retjson,"coin",coin);
jaddnum(retjson,"timestamp",time(NULL));
7 years ago
jadd(retjson,"alice",cJSON_Parse("[]"));
//jadd(retjson,"alice",LP_inventory(coin));
7 years ago
//jadd(retjson,"bob",LP_inventory(coin,1));
7 years ago
//LP_smartutxos_push(ptr);
7 years ago
LP_address_utxo_reset(&num,ptr);
8 years ago
return(jprint(retjson,1));
}
8 years ago
}
8 years ago
else if ( strcmp(method,"goal") == 0 )
8 years ago
return(LP_portfolio_goal(coin,jdouble(argjson,"val")));
8 years ago
else if ( strcmp(method,"getcoin") == 0 )
return(LP_getcoin(coin));
8 years ago
}
8 years ago
else if ( strcmp(method,"goal") == 0 )
return(LP_portfolio_goal("*",100.));
7 years ago
else if ( strcmp(method,"lastnonce") == 0 )
{
cJSON *retjson = cJSON_CreateObject();
jaddstr(retjson,"result","success");
jaddnum(retjson,"lastnonce",LP_lastnonce);
return(jprint(retjson,1));
}
8 years ago
else if ( strcmp(method,"myprices") == 0 )
return(LP_myprices(1));
8 years ago
else if ( strcmp(method,"trust") == 0 )
return(LP_pubkey_trustset(jbits256(argjson,"pubkey"),jint(argjson,"trust")));
7 years ago
else if ( strcmp(method,"trusted") == 0 )
return(LP_pubkey_trusted());
7 years ago
} // end of protected localhost commands
8 years ago
if ( IAMLP == 0 )
8 years ago
{
if ( (reqjson= LP_dereference(argjson,"broadcast")) != 0 )
{
8 years ago
if ( jobj(reqjson,"method2") != 0 )
8 years ago
{
8 years ago
jdelete(reqjson,"method");
method = jstr(reqjson,"method2");
jaddstr(reqjson,"method",method);
8 years ago
}
8 years ago
argjson = reqjson;
8 years ago
}
7 years ago
if ( strcmp(method,"getdPoW") == 0 )
7 years ago
retstr = clonestr("{\"result\":\"success\"}");
8 years ago
}
7 years ago
else
{
7 years ago
if ( strcmp(method,"tradesarray") == 0 )
7 years ago
{
return(jprint(LP_tradesarray(base,rel,juint(argjson,"starttime"),juint(argjson,"endtime"),jint(argjson,"timescale")),1));
}
7 years ago
else if ( strcmp(method,"getdPoW") == 0 )
{
if ( (ptr= LP_coinfind(jstr(argjson,"coin"))) != 0 )
LP_dPoW_broadcast(ptr);
retstr = clonestr("{\"result\":\"success\"}");
}
7 years ago
}
7 years ago
// received response
7 years ago
if ( strcmp(method,"swapstatus") == 0 )
return(LP_swapstatus_recv(argjson));
7 years ago
else if ( strcmp(method,"gettradestatus") == 0 )
7 years ago
{
retstr = clonestr("{\"error\":\"deprecated\"}");
//return(LP_gettradestatus(j64bits(argjson,"aliceid"),juint(argjson,"requestid"),juint(argjson,"quoteid")));
}
7 years ago
else if ( strcmp(method,"postprice") == 0 )
7 years ago
return(LP_postprice_recv(argjson));
7 years ago
else if ( strcmp(method,"uitem") == 0 )
7 years ago
return(LP_uitem_recv(argjson));
7 years ago
else if ( strcmp(method,"dPoW") == 0 )
return(LP_dPoW_recv(argjson));
7 years ago
else if ( strcmp(method,"notify") == 0 )
7 years ago
return(LP_notify_recv(argjson));
7 years ago
else if ( strcmp(method,"getpeers") == 0 )
7 years ago
return(LP_peers());
7 years ago
else if ( strcmp(method,"balances") == 0 )
return(jprint(LP_balances(jstr(argjson,"address")),1));
7 years ago
else if ( strcmp(method,"fundvalue") == 0 )
return(jprint(LP_fundvalue(argjson),1));
7 years ago
else if ( strcmp(method,"getprice") == 0 || strcmp(method,"getmyprice") == 0 )
7 years ago
{
7 years ago
double price,bid,ask;
7 years ago
if ( strcmp(method,"getprice") == 0 )
{
7 years ago
ask = LP_price(1,base,rel);
if ( (bid= LP_price(1,rel,base)) > SMALLVAL )
7 years ago
bid = 1./bid;
}
else
{
ask = LP_getmyprice(1,base,rel);
7 years ago
if ( (bid= LP_getmyprice(1,rel,base)) > SMALLVAL )
7 years ago
bid = 1./bid;
}
7 years ago
price = _pairaved(bid,ask);
7 years ago
retjson = cJSON_CreateObject();
jaddstr(retjson,"result","success");
jaddstr(retjson,"base",base);
jaddstr(retjson,"rel",rel);
jaddnum(retjson,"timestamp",time(NULL));
7 years ago
jaddnum(retjson,"bid",bid);
jaddnum(retjson,"ask",ask);
7 years ago
jaddnum(retjson,"price",price);
7 years ago
return(jprint(retjson,1));
}
7 years ago
/*else if ( strcmp(method,"getpeers") == 0 )
7 years ago
{
7 years ago
char *tmpstr;
7 years ago
if ( (tmpstr= jstr(argjson,"LPnode")) != 0 )
LP_addpeer(LP_mypeer,LP_mypubsock,tmpstr,RPC_port,RPC_port+10,RPC_port+20,1,G.LP_sessionid);
7 years ago
if ( IAMLP != 0 )
{
7 years ago
printf("send peers list %s\n",LP_peers());
7 years ago
bits256 zero; memset(zero.bytes,0,sizeof(zero));
LP_reserved_msg(0,"","",zero,LP_peers());
}
7 years ago
retstr = clonestr("{\"result\":\"success\"}");
7 years ago
}*/
7 years ago
// end received response
7 years ago
else if ( strcmp(method,"tradestatus") == 0 )
{
7 years ago
LP_tradecommand_log(argjson);
7 years ago
//printf("%-4d tradestatus | aliceid.%llu RT.%d %d\n",(uint32_t)time(NULL) % 3600,(long long)j64bits(argjson,"aliceid"),LP_RTcount,LP_swapscount);
7 years ago
retstr = clonestr("{\"result\":\"success\"}");
}
7 years ago
else if ( strcmp(method,"wantnotify") == 0 )
{
7 years ago
bits256 pub; static uint32_t lastnotify;
7 years ago
pub = jbits256(argjson,"pub");
7 years ago
//char str[65]; printf("got wantnotify.(%s) vs %s\n",jprint(argjson,0),bits256_str(str,G.LP_mypub25519));
7 years ago
if ( bits256_cmp(pub,G.LP_mypub25519) == 0 && time(NULL) > lastnotify+60 )
7 years ago
{
7 years ago
lastnotify = (uint32_t)time(NULL);
7 years ago
//printf("wantnotify for me!\n");
7 years ago
LP_notify_pubkeys(ctx,LP_mypubsock);
}
retstr = clonestr("{\"result\":\"success\"}");
}
7 years ago
else if ( strcmp(method,"addr_unspents") == 0 )
{
7 years ago
//printf("GOT ADDR_UNSPENTS %s %s\n",jstr(argjson,"coin"),jstr(argjson,"address"));
7 years ago
if ( (ptr= LP_coinsearch(coin)) != 0 )
7 years ago
{
7 years ago
char *coinaddr;
7 years ago
if ( (coinaddr= jstr(argjson,"address")) != 0 )
{
if ( coinaddr[0] != 0 )
{
7 years ago
LP_address(ptr,coinaddr);
7 years ago
if ( strcmp(coinaddr,ptr->smartaddr) == 0 && bits256_nonz(G.LP_privkey) != 0 )
7 years ago
{
7 years ago
//printf("ADDR_UNSPENTS %s %s is my address being asked for!\n",ptr->symbol,coinaddr);
7 years ago
if ( ptr->lastpushtime > 0 && ptr->addr_listunspent_requested > (uint32_t)time(NULL)-10 )
ptr->lastpushtime -= LP_ORDERBOOK_DURATION*0.1;
7 years ago
ptr->addr_listunspent_requested = (uint32_t)time(NULL);
7 years ago
}
}
}
}
7 years ago
retstr = clonestr("{\"result\":\"success\"}");
7 years ago
}
8 years ago
else if ( strcmp(method,"encrypted") == 0 )
retstr = clonestr("{\"result\":\"success\"}");
7 years ago
else // psock requests/response
8 years ago
{
7 years ago
if ( IAMLP != 0 )
8 years ago
{
if ( strcmp(method,"psock") == 0 )
{
7 years ago
int32_t psock;
if ( myipaddr == 0 || myipaddr[0] == 0 || strcmp(myipaddr,"127.0.0.1") == 0 )
{
if ( LP_mypeer != 0 )
myipaddr = LP_mypeer->ipaddr;
else printf("LP_psock dont have actual ipaddr?\n");
}
7 years ago
if ( jint(argjson,"ispaired") != 0 && jobj(argjson,"netid") != 0 && juint(argjson,"netid") == G.netid )
7 years ago
{
7 years ago
retstr = LP_psock(&psock,myipaddr,1,jint(argjson,"cmdchannel"),jbits256(argjson,"pubkey"));
7 years ago
//printf("LP_commands.(%s)\n",retstr);
7 years ago
return(retstr);
}
7 years ago
else return(clonestr("{\"error\":\"you are running an obsolete version, update\"}"));
}
8 years ago
}
8 years ago
else
8 years ago
{
8 years ago
if ( strcmp(method,"psock") == 0 )
8 years ago
{
8 years ago
//printf("nonLP got (%s)\n",jprint(argjson,0));
8 years ago
retstr = clonestr("{\"result\":\"success\"}");
}
8 years ago
}
8 years ago
}
8 years ago
if ( retstr == 0 )
printf("ERROR.(%s)\n",jprint(argjson,0));
8 years ago
if ( reqjson != 0 )
free_json(reqjson);
8 years ago
if ( retstr != 0 )
8 years ago
{
free(retstr);
return(0);
}
return(0);
8 years ago
}