Browse Source

Test

etomic
jl777 8 years ago
parent
commit
c1686c9208
  1. 125
      iguana/exchanges/LP_coins.c
  2. 2
      iguana/exchanges/LP_commands.c
  3. 2
      iguana/exchanges/LP_include.h
  4. 14
      iguana/exchanges/LP_nativeDEX.c
  5. 2
      iguana/exchanges/mm.c

125
iguana/exchanges/LP_coins.c

@ -18,7 +18,16 @@
// marketmaker // marketmaker
// //
char *portstrs[][2] = { { "BTC", "8332" }, { "KMD", "7771" }, { "LTC", "9332" }, { "REVS", "10196" }, { "JUMBLR", "15106" }, }; char *portstrs[][2] = { { "BTC", "8332" }, { "KMD", "7771" }, { "REVS", "10196" }, { "JUMBLR", "15106" }, };
uint16_t LP_rpcport(char *symbol)
{
int32_t i;
for (i=0; i<sizeof(portstrs)/sizeof(*portstrs); i++)
if ( strcmp(portstrs[i][0],symbol) == 0 )
return(atoi(portstrs[i][1]));
return(0);
}
char *parse_conf_line(char *line,char *field) char *parse_conf_line(char *line,char *field)
{ {
@ -132,15 +141,6 @@ int32_t LP_userpass(char *userpass,char *symbol,char *assetname,char *confroot)
return(-1); return(-1);
} }
uint16_t LP_rpcport(char *symbol)
{
int32_t i;
for (i=0; i<sizeof(portstrs)/sizeof(*portstrs); i++)
if ( strcmp(portstrs[i][0],symbol) == 0 )
return(atoi(portstrs[i][1]));
return(0);
}
cJSON *LP_coinjson(struct iguana_info *coin) cJSON *LP_coinjson(struct iguana_info *coin)
{ {
cJSON *item = cJSON_CreateObject(); cJSON *item = cJSON_CreateObject();
@ -162,46 +162,87 @@ cJSON *LP_coinsjson()
return(array); return(array);
} }
struct iguana_info *LP_coinfind(char *symbol) void LP_coininit(struct iguana_info *coin,char *symbol,char *name,uint16_t port,uint8_t pubtype,uint8_t p2shtype,uint8_t wiftype,uint64_t txfee,double estimatedrate,int32_t longestchain)
{
memset(coin,0,sizeof(*coin));
safecopy(coin->symbol,symbol,sizeof(coin->symbol));
sprintf(coin->serverport,"127.0.0.1:%u",port);
coin->longestchain = longestchain;
coin->txfee = txfee;
coin->estimatedrate = estimatedrate;
coin->pubtype = pubtype;
coin->p2shtype = p2shtype;
coin->wiftype = wiftype;
LP_userpass(coin->userpass,symbol,"",name);
}
struct iguana_info *LP_coinadd(struct iguana_info *cdata)
{ {
struct iguana_info *coin,cdata; int32_t i; uint16_t port; struct iguana_info *coin;
//printf("%s: (%s) (%s)\n",symbol,cdata.serverport,cdata.userpass);
LP_coins = realloc(LP_coins,sizeof(*LP_coins) * (LP_numcoins+1));
coin = &LP_coins[LP_numcoins];
*coin = *cdata;
LP_numcoins++;
return(coin);
}
struct iguana_info *LP_coinsearch(char *symbol)
{
int32_t i;
for (i=0; i<LP_numcoins; i++) for (i=0; i<LP_numcoins; i++)
if ( strcmp(LP_coins[i].symbol,symbol) == 0 ) if ( strcmp(LP_coins[i].symbol,symbol) == 0 )
return(&LP_coins[i]); return(&LP_coins[i]);
memset(&cdata,0,sizeof(cdata)); return(0);
coin = &cdata; }
safecopy(cdata.symbol,symbol,sizeof(cdata.symbol));
port = LP_rpcport(symbol); struct iguana_info *LP_coinfind(char *symbol)
sprintf(cdata.serverport,"127.0.0.1:%u",port); {
cdata.longestchain = 100000; struct iguana_info *coin,cdata; int32_t longestchain = 1000000; uint16_t port; uint64_t txfee; double estimatedrate; uint8_t pubtype,p2shtype,wiftype; char *name;
cdata.txfee = 10000; if ( (coin= LP_coinsearch(symbol)) != 0 )
cdata.estimatedrate = 20; return(coin);
if ( (port= LP_rpcport(symbol)) == 0 )
return(0);
txfee = 10000;
estimatedrate = 20;
pubtype = 60;
p2shtype = 85;
wiftype = 188;
if ( strcmp(symbol,"BTC") == 0 ) if ( strcmp(symbol,"BTC") == 0 )
{ {
cdata.txfee = 50000; txfee = 50000;
cdata.estimatedrate = 300; estimatedrate = 300;
cdata.p2shtype = 5; p2shtype = 5;
cdata.wiftype = 128; wiftype = 128;
LP_userpass(cdata.userpass,symbol,"","bitcoin"); name = "bitcoin";
} }
else if ( strcmp(symbol,"LTC") == 0 ) else name = (strcmp(symbol,"KMD") == 0) ? "komodo" : symbol;
{ LP_coininit(&cdata,symbol,name,port,pubtype,p2shtype,wiftype,txfee,estimatedrate,longestchain);
cdata.pubtype = 48; return(LP_coinadd(&cdata));
cdata.p2shtype = 5; }
cdata.wiftype = 176;
LP_userpass(cdata.userpass,symbol,"","litecoin"); // "coins":[{"coin":"<assetchain>", "rpcport":pppp}, {"coin":"LTC", "name":"litecoin", "rpcport":9332, "pubtype":48, "p2shtype":5, "wiftype":176, "txfee":100000 }]
}
else struct iguana_info *LP_coincreate(cJSON *item)
{
struct iguana_info cdata; int32_t longestchain = 1000000; uint16_t port; uint64_t txfee; double estimatedrate; uint8_t pubtype,p2shtype,wiftype; char *name,*symbol;
if ( (symbol= jstr(item,"coin")) != 0 && symbol[0] != 0 && strlen(symbol) < 16 && LP_coinfind(symbol) == 0 && (port= juint(item,"rpcport")) != 0 )
{ {
cdata.pubtype = 60; if ( (txfee= j64bits(item,"txfee")) == 0 )
cdata.p2shtype = 85; txfee = 10000;
cdata.wiftype = 188; if ( (estimatedrate= jdouble(item,"estimatedrate")) == 0. )
LP_userpass(cdata.userpass,symbol,symbol,strcmp(symbol,"KMD") == 0 ? "komodo" : symbol); estimatedrate = 20;
if ( (pubtype= juint(item,"pubtype")) == 0 )
pubtype = 60;
if ( (p2shtype= juint(item,"p2shtype")) == 0 )
p2shtype = 85;
if ( (wiftype= juint(item,"wiftype")) == 0 )
wiftype = 188;
if ( (name= jstr(item,"name")) == 0 )
name = symbol;
LP_coininit(&cdata,symbol,name,port,pubtype,p2shtype,wiftype,txfee,estimatedrate,longestchain);
return(LP_coinadd(&cdata));
} }
//printf("%s: (%s) (%s)\n",symbol,cdata.serverport,cdata.userpass); return(0);
LP_coins = realloc(LP_coins,sizeof(*LP_coins) * (LP_numcoins+1));
coin = &LP_coins[LP_numcoins++];
*coin = cdata;
return(coin);
} }

2
iguana/exchanges/LP_commands.c

@ -38,6 +38,8 @@ double LP_query(char *method,struct LP_quoteinfo *qp,char *ipaddr,uint16_t port,
if ( bits256_nonz(qp->desthash) != 0 ) if ( bits256_nonz(qp->desthash) != 0 )
flag = 1; flag = 1;
jaddstr(reqjson,"method",method); jaddstr(reqjson,"method",method);
if ( strcmp(method,"price") != 0 )
printf("QUERY.(%s)\n",jprint(reqjson,0));
LP_send(pushsock,jprint(reqjson,1),1); LP_send(pushsock,jprint(reqjson,1),1);
for (i=0; i<30; i++) for (i=0; i<30; i++)
{ {

2
iguana/exchanges/LP_include.h

@ -37,7 +37,7 @@
//#define BASILISK_DISABLEWAITTX //#define BASILISK_DISABLEWAITTX
//#define BASILISK_DISABLESENDTX //#define BASILISK_DISABLESENDTX
#define LP_PROPAGATION_SLACK 10 // txid ordering is not enforced, so getting extra recent txid #define LP_PROPAGATION_SLACK 100 // txid ordering is not enforced, so getting extra recent txid
#define LP_RESERVETIME 60 #define LP_RESERVETIME 60
#define LP_AVETXSIZE 200 #define LP_AVETXSIZE 200
#define LP_CACHEDURATION 60 #define LP_CACHEDURATION 60

14
iguana/exchanges/LP_nativeDEX.c

@ -54,6 +54,7 @@ void tradebot_pendingadd(cJSON *tradejson,char *base,double basevolume,char *rel
{ {
// add to trades // add to trades
} }
char *LP_getdatadir() char *LP_getdatadir()
{ {
return(USERHOME); return(USERHOME);
@ -77,10 +78,10 @@ char *blocktrail_listtransactions(char *symbol,char *coinaddr,int32_t num,int32_
#include "LP_quotes.c" #include "LP_quotes.c"
#include "LP_commands.c" #include "LP_commands.c"
void LP_mainloop(struct LP_peerinfo *mypeer,uint16_t mypubport,int32_t pubsock,int32_t pullsock,uint16_t myport,int32_t amclient,char *passphrase,double profitmargin) void LP_mainloop(struct LP_peerinfo *mypeer,uint16_t mypubport,int32_t pubsock,int32_t pullsock,uint16_t myport,int32_t amclient,char *passphrase,double profitmargin,cJSON *coins)
{ {
//static uint16_t tmpport; //static uint16_t tmpport;
char *retstr; uint8_t r; int32_t i,n,j,len,recvsize,counter=0,nonz,lastn; struct LP_peerinfo *peer,*tmp; uint32_t now; struct LP_utxoinfo *utxo,*utmp; void *ptr; cJSON *argjson; char *retstr; uint8_t r; int32_t i,n,j,len,recvsize,counter=0,nonz,lastn; struct LP_peerinfo *peer,*tmp; uint32_t now; struct LP_utxoinfo *utxo,*utmp; void *ptr; cJSON *argjson,*item;
if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)stats_rpcloop,(void *)&myport) != 0 ) if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)stats_rpcloop,(void *)&myport) != 0 )
{ {
printf("error launching stats rpcloop for port.%u\n",myport); printf("error launching stats rpcloop for port.%u\n",myport);
@ -112,6 +113,11 @@ void LP_mainloop(struct LP_peerinfo *mypeer,uint16_t mypubport,int32_t pubsock,i
LP_coinfind(activecoins[i]); LP_coinfind(activecoins[i]);
LP_priceinfoadd(activecoins[i]); LP_priceinfoadd(activecoins[i]);
} }
if ( (n= cJSON_GetArraySize(coins)) > 0 )
{
for (i=0; i<n; i++)
LP_coincreate(jitem(coins,i));
}
LP_privkey_updates(mypeer,pubsock,passphrase,amclient); LP_privkey_updates(mypeer,pubsock,passphrase,amclient);
HASH_ITER(hh,LP_peerinfos,peer,tmp) HASH_ITER(hh,LP_peerinfos,peer,tmp)
{ {
@ -262,7 +268,7 @@ void LP_mainloop(struct LP_peerinfo *mypeer,uint16_t mypubport,int32_t pubsock,i
} }
} }
void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,double profitmargin,char *passphrase,int32_t amclient,char *userhome) void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,double profitmargin,char *passphrase,int32_t amclient,char *userhome,cJSON *argjson)
{ {
char *myipaddr=0; long filesize,n; int32_t timeout,maxsize,pullsock=-1,pubsock=-1; struct LP_peerinfo *mypeer=0; char pushaddr[128],subaddr[128]; char *myipaddr=0; long filesize,n; int32_t timeout,maxsize,pullsock=-1,pubsock=-1; struct LP_peerinfo *mypeer=0; char pushaddr[128],subaddr[128];
IAMCLIENT = amclient; IAMCLIENT = amclient;
@ -327,7 +333,7 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,double profit
} }
//printf("utxos.(%s)\n",LP_utxos(mypeer,"",10000)); //printf("utxos.(%s)\n",LP_utxos(mypeer,"",10000));
} }
LP_mainloop(mypeer,mypubport,pubsock,pullsock,myport,amclient,passphrase,profitmargin); LP_mainloop(mypeer,mypubport,pubsock,pullsock,myport,amclient,passphrase,profitmargin,jobj(argjson,"coins"));
} }

2
iguana/exchanges/mm.c

@ -811,7 +811,7 @@ void LP_main(void *ptr)
if ( (passphrase= jstr(argjson,"passphrase")) != 0 ) if ( (passphrase= jstr(argjson,"passphrase")) != 0 )
{ {
profitmargin = jdouble(argjson,"profitmargin"); profitmargin = jdouble(argjson,"profitmargin");
LPinit(7779,7780,7781,profitmargin,passphrase,jint(argjson,"client"),jstr(argjson,"userhome")); LPinit(7779,7780,7781,profitmargin,passphrase,jint(argjson,"client"),jstr(argjson,"userhome"),argjson);
} }
} }

Loading…
Cancel
Save