Browse Source

Test

etomic
jl777 7 years ago
parent
commit
f086858c6d
  1. 9
      iguana/exchanges/LP_commands.c
  2. 7
      iguana/exchanges/LP_include.h
  3. 25
      iguana/exchanges/LP_ordermatch.c
  4. 10
      iguana/exchanges/LP_remember.c
  5. 30
      iguana/exchanges/LP_rpc.c
  6. 20
      iguana/exchanges/LP_socket.c
  7. 6
      iguana/exchanges/LP_transaction.c
  8. 6
      iguana/exchanges/LP_utxos.c
  9. 2
      iguana/exchanges/electrum
  10. 2
      iguana/exchanges/install

9
iguana/exchanges/LP_commands.c

@ -121,6 +121,7 @@ sendmessage(base=coin, rel="", pubkey=zero, <argjson method2>)\n\
getmessages(firsti=0, num=100)\n\
clearmessages(firsti=0, num=100)\n\
secretaddresses(passphrase, num=10, pubtype=60, taddr=0)\n\
electrum(coin, ipaddr, port)\n\
snapshot(coin, height)\n\
snapshot_balance(coin, height, addresses[])\n\
dividends(coin, height, <args>)\n\
@ -256,6 +257,14 @@ dividends(coin, height, <args>)\n\
ptr->inactive = (uint32_t)time(NULL);
return(jprint(LP_coinsjson(0),1));
}
else if ( strcmp(method,"electrum") == 0 )
{
if ( (ptr= LP_coinsearch(coin)) != 0 )
{
ptr->inactive = 0;
return(jprint(LP_electrumserver(ptr,ipaddr,port),1));
} else return(clonestr("{\"error\":\"cant find coind\"}"));
}
else if ( strcmp(method,"snapshot") == 0 )
{
if ( (ptr= LP_coinsearch(coin)) != 0 )

7
iguana/exchanges/LP_include.h

@ -188,11 +188,12 @@ struct iguana_info
portable_mutex_t txmutex; struct LP_transaction *transactions; struct LP_address *addresses;
uint64_t txfee;
int32_t longestchain,firstrefht,firstscanht,lastscanht,bussock; uint16_t busport;
uint32_t counter,inactive,lastmempool,lastgetinfo;
uint32_t counter,inactive,lastmempool,lastgetinfo,ratetime;
uint8_t pubtype,p2shtype,isPoS,wiftype,wiftaddr,taddr,noimportprivkey_flag;
char symbol[16],smartaddr[64],userpass[1024],serverport[128];
// portfolio
double price_kmd,force,perc,goal,goalperc,relvolume;
double price_kmd,force,perc,goal,goalperc,relvolume,rate;
void *electrum;
uint64_t maxamount,kmd_equiv,balanceA,balanceB,valuesumA,valuesumB;
uint8_t pubkey33[33];
};
@ -283,7 +284,7 @@ int32_t LP_coinbus(uint16_t coin_busport);
struct iguana_info *LP_coinfind(char *symbol);
int32_t LP_crc32find(int32_t *duplicatep,int32_t ind,uint32_t crc32);
char *LP_pricepings(void *ctx,char *myipaddr,int32_t pubsock,char *base,char *rel,double price);
uint64_t LP_txfeecalc(char *symbol,uint64_t txfee);
uint64_t LP_txfeecalc(struct iguana_info *coin,uint64_t txfee);
#endif

25
iguana/exchanges/LP_ordermatch.c

@ -19,25 +19,26 @@
// marketmaker
//
uint64_t LP_txfeecalc(char *symbol,uint64_t txfee)
uint64_t LP_txfeecalc(struct iguana_info *coin,uint64_t txfee)
{
struct iguana_info *coin;
if ( strcmp(symbol,"BTC") == 0 )
if ( coin != 0 )
{
if ( txfee == 0 && (txfee= LP_getestimatedrate(symbol) * LP_AVETXSIZE) < LP_MIN_TXFEE )
if ( strcmp(coin->symbol,"BTC") == 0 )
{
if ( txfee == 0 && (txfee= LP_getestimatedrate(coin) * LP_AVETXSIZE) < LP_MIN_TXFEE )
txfee = LP_MIN_TXFEE;
}
else txfee = coin->txfee;
if ( txfee < LP_MIN_TXFEE )
txfee = LP_MIN_TXFEE;
}
else if ( (coin= LP_coinfind(symbol)) != 0 )
txfee = coin->txfee;
if ( txfee < LP_MIN_TXFEE )
txfee = LP_MIN_TXFEE;
return(txfee);
}
void LP_txfees(uint64_t *txfeep,uint64_t *desttxfeep,char *base,char *rel)
{
*txfeep = LP_txfeecalc(base,0);
*desttxfeep = LP_txfeecalc(rel,0);
*txfeep = LP_txfeecalc(LP_coinfind(base),0);
*desttxfeep = LP_txfeecalc(LP_coinfind(rel),0);
}
double LP_qprice_calc(int64_t *destsatoshisp,int64_t *satoshisp,double price,uint64_t b_satoshis,uint64_t txfee,uint64_t a_value,uint64_t maxdestsatoshis,uint64_t desttxfee)
@ -709,8 +710,8 @@ char *LP_bestfit(char *rel,double relvolume)
char *LP_ordermatch(char *base,int64_t txfee,double maxprice,double maxvolume,char *rel,bits256 txid,int32_t vout,bits256 feetxid,int32_t feevout,int64_t desttxfee,int32_t duration)
{
struct LP_quoteinfo Q; int64_t bestsatoshis=0,bestdestsatoshis = 0; double ordermatchprice = 0.; struct LP_utxoinfo *autxo,*bestutxo;
txfee = LP_txfeecalc(base,txfee);
desttxfee = LP_txfeecalc(rel,desttxfee);
txfee = LP_txfeecalc(LP_coinfind(base),txfee);
desttxfee = LP_txfeecalc(LP_coinfind(rel),desttxfee);
if ( (autxo= LP_utxopairfind(0,txid,vout,feetxid,feevout)) == 0 )
return(clonestr("{\"error\":\"cant find alice utxopair\"}"));
if ( (bestutxo= LP_bestutxo(&ordermatchprice,&bestsatoshis,&bestdestsatoshis,autxo,base,maxprice,duration,txfee,desttxfee,SATOSHIDEN*maxvolume)) == 0 || ordermatchprice == 0. || bestdestsatoshis == 0 )

10
iguana/exchanges/LP_remember.c

@ -615,8 +615,10 @@ cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requesti
Adest = Bdest = AAdest = ABdest = 0;
if ( bobcoin[0] == 0 || alicecoin[0] == 0 )
return(0);
Atxfee = LP_txfeecalc(alicecoin,Atxfee);
Btxfee = LP_txfeecalc(bobcoin,Btxfee);
alice = LP_coinfind(alicecoin);
bob = LP_coinfind(bobcoin);
Atxfee = LP_txfeecalc(alice,Atxfee);
Btxfee = LP_txfeecalc(bob,Btxfee);
//printf("%s %.8f txfee, %s %.8f txfee\n",alicecoin,dstr(Atxfee),bobcoin,dstr(Btxfee));
//printf("privAm.(%s) %p/%p\n",bits256_str(str,privAm),Adest,AAdest);
//printf("privBn.(%s) %p/%p\n",bits256_str(str,privBn),Bdest,ABdest);
@ -624,7 +626,7 @@ cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requesti
{
if ( iambob == 0 )
{
if ( (alice= LP_coinfind(alicecoin)) != 0 )
if ( alice != 0 )
{
bitcoin_address(Adestaddr,alice->taddr,alice->pubtype,pubkey33,33);
AAdest = Adestaddr;
@ -637,7 +639,7 @@ cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requesti
}
else
{
if ( (bob= LP_coinfind(bobcoin)) != 0 )
if ( bob != 0 )
{
bitcoin_address(destaddr,bob->taddr,bob->pubtype,pubkey33,33);
Bdest = destaddr;

30
iguana/exchanges/LP_rpc.c

@ -315,21 +315,33 @@ int32_t LP_importaddress(char *symbol,char *address)
return(1);
}
double LP_getestimatedrate(char *symbol)
char *LP_apicall(struct iguana_info *coin,char *method,char *params)
{
char buf[512],*retstr; double rate = 20; struct iguana_info *coin = LP_coinfind(symbol);
if ( coin->electrum != 0 )
return(jprint(electrum_submit(coin->symbol,coin->electrum,0,method,params,LP_HTTP_TIMEOUT),1));
else return(bitcoind_passthru(coin->symbol,coin->serverport,coin->userpass,method,params));
}
double LP_getestimatedrate(struct iguana_info *coin)
{
char buf[512],*retstr; double rate = 20;
if ( coin != 0 && (strcmp(coin->symbol,"BTC") == 0 || coin->txfee == 0) )
{
sprintf(buf,"[%d]",3);
if ( (retstr= bitcoind_passthru(symbol,coin->serverport,coin->userpass,"estimatefee",buf)) != 0 )
if ( coin->rate != 0. && time(NULL) > coin->ratetime+60 )
{
if ( retstr[0] != '-' )
sprintf(buf,"[%d]",3);
if ( (retstr= LP_apicall(coin,"estimatefee",buf)) != 0 )
{
rate = atof(retstr) / 1024.;
//printf("estimated rate.(%s) %s -> %.8f\n",symbol,retstr,rate);
if ( retstr[0] != '-' )
{
rate = atof(retstr) / 1024.;
coin->rate = rate;
coin->ratetime = (uint32_t)time(NULL);
printf("estimated rate.(%s) %s -> %.8f\n",coin->symbol,retstr,rate);
}
free(retstr);
}
free(retstr);
}
} else rate = coin->rate;
} else return((double)coin->txfee / LP_AVETXSIZE);
return(SATOSHIDEN * rate);
}

20
iguana/exchanges/LP_socket.c

@ -421,6 +421,26 @@ void LP_dedicatedloop(void *arg)
free(ep);
}
cJSON *LP_electrumserver(struct iguana_info *coin,char *ipaddr,uint16_t port)
{
struct electrum_info *ep; cJSON *retjson = cJSON_CreateObject();
jaddstr(retjson,"ipaddr",ipaddr);
jaddnum(retjson,"port",port);
ep = LP_electrum_info(coin->symbol,ipaddr,port,IGUANA_MAXPACKETSIZE * 10);
if ( ep != 0 && OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_dedicatedloop,(void *)ep) != 0 )
{
printf("error launching LP_dedicatedloop %s.(%s:%u)\n",coin->symbol,ep->ipaddr,ep->port);
jaddstr(retjson,"error","couldnt launch electrum thread");
}
else
{
printf("launched.(%s:%u)\n",ep->ipaddr,ep->port);
jaddstr(retjson,"result","success");
coin->electrum = ep;
}
return(retjson);
}
/*
if ( (retjson= electrum_address_listunspent(symbol,ep,0,addr)) != 0 )
you can call it like the above, where symbol is the coin, ep is the electrum server info pointer, the 0 is a callback ptr where 0 means to block till it is done

6
iguana/exchanges/LP_transaction.c

@ -703,7 +703,7 @@ int32_t basilisk_rawtx_gen(void *ctx,char *str,uint32_t swapstarted,uint8_t *pub
if ( strcmp(coin->symbol,"BTC") != 0 )
return(retval);
len = rawtx->I.datalen;
newtxfee = LP_txfeecalc(coin->symbol,0);
newtxfee = LP_txfeecalc(coin,0);
printf("txfee %.8f -> newtxfee %.8f\n",dstr(txfee),dstr(newtxfee));
} else break;
if ( strcmp(str,"myfee") == 0 )
@ -742,7 +742,7 @@ int32_t basilisk_rawtx_sign(char *symbol,uint8_t wiftaddr,uint8_t taddr,uint8_t
free(signedtx);
if ( strcmp(symbol,"BTC") != 0 )
return(retval);
estimatedrate = LP_getestimatedrate(symbol);
estimatedrate = LP_getestimatedrate(LP_coinfind(symbol));
newtxfee = estimatedrate * dest->I.datalen;
} else break;
}
@ -786,7 +786,7 @@ char *basilisk_swap_Aspend(char *name,char *symbol,uint64_t Atxfee,uint8_t wifta
privBn.bytes[i] = rev.bytes[31 - i];*/
if ( (txfee= Atxfee) == 0 )
{
if ( (txfee= LP_getestimatedrate(symbol) * LP_AVETXSIZE) < LP_MIN_TXFEE )
if ( (txfee= LP_getestimatedrate(LP_coinfind(symbol)) * LP_AVETXSIZE) < LP_MIN_TXFEE )
txfee = LP_MIN_TXFEE;
}
//txfee = LP_txfee(symbol);

6
iguana/exchanges/LP_utxos.c

@ -296,7 +296,7 @@ int32_t LP_iseligible(uint64_t *valp,uint64_t *val2p,int32_t iambob,char *symbol
if ( bypass != 0 )
val = satoshis;
else val = LP_txvalue(destaddr,symbol,txid,vout);
txfee = LP_txfeecalc(symbol,0);
txfee = LP_txfeecalc(LP_coinfind(symbol),0);
if ( val >= satoshis && val > (1+LP_MINSIZE_TXFEEMULT)*txfee )
{
threshold = (iambob != 0) ? LP_DEPOSITSATOSHIS(satoshis) : (LP_DEXFEE(satoshis) + txfee);
@ -524,7 +524,7 @@ struct LP_utxoinfo *LP_utxoadd(int32_t iambob,int32_t mypubsock,char *symbol,bit
printf("LP_utxoadd reject inactive %s\n",symbol);
return(0);
}
txfee = LP_txfeecalc(coin->symbol,0);
txfee = LP_txfeecalc(coin,0);
if ( iambob != 0 && value2 < 9 * (value >> 3) + 2*txfee ) // big txfee padding
{
if ( value2 > 2*txfee )
@ -817,7 +817,7 @@ uint64_t LP_privkey_init(int32_t mypubsock,struct iguana_info *coin,bits256 mypr
//printf("privkey init.(%s) %s\n",coin->symbol,coin->smartaddr);
if ( coin->inactive == 0 && (array= LP_listunspent(coin->symbol,coin->smartaddr)) != 0 )
{
txfee = LP_txfeecalc(coin->symbol,0);
txfee = LP_txfeecalc(coin,0);
if ( is_cJSON_Array(array) != 0 && (n= cJSON_GetArraySize(array)) > 0 )
{
for (iambob=0; iambob<=1; iambob++)

2
iguana/exchanges/electrum

@ -0,0 +1,2 @@
source userpass
curl --url "http://127.0.0.1:7779" --data "{\"userpass\":\"$userpass\",\"method\":\"electrum\",\"coin\":\"BTC\",\"ipaddr\":\"88.198.241.196\",\"port\":50001}"

2
iguana/exchanges/install

@ -1,4 +1,4 @@
cp snapshot_balance snapshot_loop secretaddresses dividends snapshot goals goal portfolio autoprice deletemessages getmessages debug register registerall trade ordermatch bestfit orderbook autotrade client run_osx client_osx run coins disable enable myprice myprices getcoins getpeers getpeersIP getprices getutxos help inv setprice status utxos ../dexscripts
cp electrum snapshot_balance snapshot_loop secretaddresses dividends snapshot goals goal portfolio autoprice deletemessages getmessages debug register registerall trade ordermatch bestfit orderbook autotrade client run_osx client_osx run coins disable enable myprice myprices getcoins getpeers getpeersIP getprices getutxos help inv setprice status utxos ../dexscripts
cd ../dexscripts
#cp ../exchanges/passphrase ../exchanges/userpass .
echo you will need to have a passphrase file with your passphrase and userpass file with userpass value in dexscripts dir

Loading…
Cancel
Save