Browse Source

Test

etomic
jl777 8 years ago
parent
commit
fe5f442749
  1. 2
      iguana/exchanges/LP_coins.c
  2. 3
      iguana/exchanges/LP_include.h
  3. 23
      iguana/exchanges/LP_nativeDEX.c
  4. 111
      iguana/exchanges/LP_portfolio.c
  5. 39
      iguana/exchanges/LP_rpc.c
  6. 53
      iguana/exchanges/LP_statemachine.c

2
iguana/exchanges/LP_coins.c

@ -158,7 +158,7 @@ int32_t LP_userpass(char *userpass,char *symbol,char *assetname,char *confroot,c
LP_userpassfp(symbol,username,password,fp);
sprintf(userpass,"%s:%s",username,password);
fclose(fp);
if ( 0 )
if ( 1 )
printf("LP_statefname.(%s) <- %s %s %s (%s)\n",fname,name,symbol,assetname,userpass);
return((int32_t)strlen(userpass));
} else printf("cant open.(%s)\n",fname);

3
iguana/exchanges/LP_include.h

@ -182,6 +182,9 @@ struct iguana_info
uint32_t counter,inactive,lastmempool,lastgetinfo;
uint8_t pubtype,p2shtype,isPoS,wiftype,wiftaddr,taddr,noimportprivkey_flag;
char symbol[16],smartaddr[64],userpass[1024],serverport[128];
// portfolio
double price_kmd;
uint64_t maxamount,kmd_equiv,goal,balanceA,balanceB,valuesumA,valuesumB;
};
struct _LP_utxoinfo { bits256 txid; uint64_t value; int32_t vout; };

23
iguana/exchanges/LP_nativeDEX.c

@ -23,11 +23,11 @@
// autoutxo
// fixes:
// -wiftaddr and no flag for importprivkey (VERGE)
// -wiftaddr and no flag for importprivkey (XVG)
// -avoid redundant importprivkey
// -put Atxfee and Btxfee into rememberfiles
// bugs"
// bugs:
// false detection of bobreclaim
// unduplicated bugs:
@ -37,7 +37,7 @@
#include <stdio.h>
#include "LP_include.h"
portable_mutex_t LP_peermutex,LP_UTXOmutex,LP_utxomutex,LP_commandmutex,LP_cachemutex,LP_swaplistmutex,LP_forwardmutex,LP_pubkeymutex,LP_networkmutex,LP_psockmutex,LP_coinmutex,LP_messagemutex;
portable_mutex_t LP_peermutex,LP_UTXOmutex,LP_utxomutex,LP_commandmutex,LP_cachemutex,LP_swaplistmutex,LP_forwardmutex,LP_pubkeymutex,LP_networkmutex,LP_psockmutex,LP_coinmutex,LP_messagemutex,LP_portfoliomutex;
int32_t LP_canbind;
struct LP_utxoinfo *LP_utxoinfos[2],*LP_utxoinfos2[2];
@ -98,6 +98,7 @@ char *blocktrail_listtransactions(char *symbol,char *coinaddr,int32_t num,int32_
#include "LP_utxos.c"
#include "LP_forwarding.c"
#include "LP_ordermatch.c"
#include "LP_portfolio.c"
#include "LP_messages.c"
#include "LP_commands.c"
@ -636,6 +637,7 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu
portable_mutex_init(&LP_coinmutex);
portable_mutex_init(&LP_pubkeymutex);
portable_mutex_init(&LP_messagemutex);
portable_mutex_init(&LP_portfoliomutex);
LP_sessionid = (uint32_t)time(NULL);
printf("getting myipaddr sessionid.%u\n",LP_sessionid);
if ( system("curl -s4 checkip.amazonaws.com > /tmp/myipaddr") == 0 )
@ -713,21 +715,6 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu
//fprintf(stderr,".");
if ( LP_mainloop_iter(ctx,myipaddr,mypeer,pubsock,pushaddr,myport,passphrase) == 0 )
usleep(1000000 / MAINLOOP_PERSEC);
/*if ( LP_canbind == 0 )
{
//printf("check deadman %u vs %u\n",LP_deadman_switch,(uint32_t)time(NULL));
if ( LP_deadman_switch < time(NULL)-PSOCK_KEEPALIVE )
{
printf("DEAD man's switch %u activated at %u lag.%d, register forwarding again\n",LP_deadman_switch,(uint32_t)time(NULL),(uint32_t)(time(NULL) - LP_deadman_switch));
if ( pullsock >= 0 )
nn_close(pullsock);
pullsock = LP_initpublicaddr(ctx,&mypullport,pushaddr,myipaddr,mypullport,0);
LP_deadman_switch = (uint32_t)time(NULL);
strcpy(LP_publicaddr,pushaddr);
LP_publicport = mypullport;
LP_forwarding_register(LP_mypubkey,pushaddr,mypullport,MAX_PSOCK_PORT);
}
}*/
}
}

111
iguana/exchanges/LP_portfolio.c

@ -0,0 +1,111 @@
/******************************************************************************
* 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_portfolio.c
// marketmaker
//
cJSON *LP_portfolio_entry(struct iguana_info *coin,uint64_t kmdsum)
{
cJSON *item = cJSON_CreateObject();
jaddstr(item,"coin",coin->symbol);
jaddnum(item,"amount",dstr(coin->maxamount));
jaddnum(item,"price",coin->price_kmd);
jaddnum(item,"kmd_equiv",dstr(coin->kmd_equiv));
jaddnum(item,"kmdsum",dstr(kmdsum));
jaddnum(item,"goal",dstr(coin->goal));
if ( kmdsum > 0 )
jaddnum(item,"perc",(double)coin->kmd_equiv/ kmdsum);
jaddnum(item,"balanceA",dstr(coin->balanceA));
jaddnum(item,"valuesumA",dstr(coin->valuesumA));
jaddnum(item,"aliceutil",100. * (double)coin->balanceA/coin->valuesumA);
jaddnum(item,"balanceB",dstr(coin->balanceB));
jaddnum(item,"valuesumB",dstr(coin->valuesumB));
jaddnum(item,"bobutil",100. * (double)coin->balanceB/coin->valuesumB);
return(item);
}
uint64_t LP_balance(uint64_t *valuep,int32_t iambob,char *symbol,char *coinaddr)
{
cJSON *array,*item; int32_t i,n; uint64_t valuesum,satoshisum;
valuesum = satoshisum = 0;
if ( (array= LP_inventory(symbol,iambob)) != 0 )
{
if ( (n= cJSON_GetArraySize(array)) > 0 && is_cJSON_Array(array) != 0 )
{
for (i=0; i<n; i++)
{
item = jitem(array,i);
valuesum += j64bits(item,"value");
satoshisum += j64bits(item,"satoshis");
}
}
free_json(array);
}
*valuep = valuesum;
return(satoshisum);
}
char *LP_portfolio()
{
uint64_t kmdsum = 0; int32_t iter; cJSON *retjson,*array; struct iguana_info *coin,*tmp;
array = cJSON_CreateArray();
retjson = cJSON_CreateObject();
for (iter=0; iter<2; iter++)
{
HASH_ITER(hh,LP_coins,coin,tmp)
{
if ( iter == 0 )
{
coin->balanceA = LP_balance(&coin->valuesumA,0,coin->symbol,coin->smartaddr);
coin->balanceB = LP_balance(&coin->valuesumB,1,coin->symbol,coin->smartaddr);
if ( strcmp(coin->symbol,"KMD") != 0 )
coin->price_kmd = LP_price(coin->symbol,"KMD");
else coin->price_kmd = 1.;
coin->maxamount = coin->valuesumA;
if ( coin->valuesumB > coin->maxamount )
coin->maxamount = coin->valuesumB;
coin->kmd_equiv = coin->maxamount * coin->price_kmd;
kmdsum += coin->kmd_equiv;
} else jaddi(array,LP_portfolio_entry(coin,kmdsum));
}
}
jaddstr(retjson,"result","success");
jaddnum(retjson,"kmd_equiv",kmdsum);
jadd(retjson,"portfolio",array);
return(jprint(retjson,1));
}
struct LP_portfolioinfo *LP_portfoliofind(char *symbol)
{
struct LP_portfolioinfo *ptr;
portable_mutex_lock(&LP_portfoliomutex);
HASH_FIND(hh,LP_portfolios,symbol,strlen(symbol),ptr);
portable_mutex_unlock(&LP_portfoliomutex);
return(ptr);
}
struct LP_portfolioinfo *LP_portfolioadd(char *symbol,uint64_t goal)
{
struct LP_portfolioinfo *ptr = calloc(1,sizeof(*ptr));
safecopy(ptr->symbol,symbol,sizeof(ptr->symbol));
ptr->goal = goal;
portable_mutex_lock(&LP_portfoliomutex);
HASH_ADD_KEYPTR(hh,LP_portfolios,ptr->symbol,strlen(ptr->symbol),ptr);
portable_mutex_unlock(&LP_portfoliomutex);
return(ptr);
}

39
iguana/exchanges/LP_rpc.c

@ -94,43 +94,6 @@ char *issue_LP_notify(char *destip,uint16_t destport,char *ipaddr,uint16_t port,
//return(issue_curlt(url,LP_HTTP_TIMEOUT));
}
/*char *issue_LP_notifyutxo(char *destip,uint16_t destport,struct LP_utxoinfo *utxo)
{
char url[4096],str[65],str2[65],str3[65],*retstr; struct _LP_utxoinfo u; uint64_t val,val2;
if ( (retstr= LP_isitme(destip,destport)) != 0 )
return(retstr);
if ( utxo->iambob == 0 )
{
printf("issue_LP_notifyutxo trying to send Alice %s/v%d\n",bits256_str(str,utxo->payment.txid),utxo->payment.vout);
return(0);
}
u = (utxo->iambob != 0) ? utxo->deposit : utxo->fee;
if ( LP_iseligible(&val,&val2,utxo->iambob,utxo->coin,utxo->payment.txid,utxo->payment.vout,utxo->S.satoshis,u.txid,u.vout) > 0 )
{
sprintf(url,"http://%s:%u/api/stats/notified?iambob=%d&pubkey=%s&coin=%s&txid=%s&vout=%d&value=%llu&txid2=%s&vout2=%d&value2=%llu&script=%s&address=%s&timestamp=%u&gui=%s",destip,destport,utxo->iambob,bits256_str(str3,utxo->pubkey),utxo->coin,bits256_str(str,utxo->payment.txid),utxo->payment.vout,(long long)utxo->payment.value,bits256_str(str2,utxo->deposit.txid),utxo->deposit.vout,(long long)utxo->deposit.value,utxo->spendscript,utxo->coinaddr,(uint32_t)time(NULL),utxo->gui);
if ( strlen(url) > 1024 )
printf("WARNING long url.(%s)\n",url);
return(LP_issue_curl("notifyutxo",destip,destport,url));
//return(issue_curlt(url,LP_HTTP_TIMEOUT));
}
else
{
printf("issue_LP_notifyutxo: ineligible utxo iambob.%d %.8f %.8f\n",utxo->iambob,dstr(val),dstr(val2));
if ( utxo->T.spentflag == 0 )
utxo->T.spentflag = (uint32_t)time(NULL);
return(0);
}
}*/
/*char *issue_LP_lookup(char *destip,uint16_t destport,bits256 pubkey)
{
char url[512],str[65];
sprintf(url,"http://%s:%u/api/stats/lookup?client=%s",destip,destport,bits256_str(str,pubkey));
//printf("getutxo.(%s)\n",url);
return(LP_issue_curl("lookup",destip,destport,url));
//return(issue_curlt(url,LP_HTTP_TIMEOUT));
}*/
char *issue_LP_getprices(char *destip,uint16_t destport)
{
char url[512];
@ -330,7 +293,7 @@ cJSON *LP_importprivkey(char *symbol,char *wifstr,char *label,int32_t flag)
if ( doneflag == 0 )
{
if ( coin->noimportprivkey_flag != 0 )
sprintf(buf,"[\"%s\", \"%s\"]",wifstr,label);
sprintf(buf,"[\"%s\"]",wifstr);
else sprintf(buf,"[\"%s\", \"%s\", %s]",wifstr,label,flag < 0 ? "false" : "true");
return(bitcoin_json(coin,"importprivkey",buf));
} else return(cJSON_Parse("{\"result\":\"success\"}"));

53
iguana/exchanges/LP_statemachine.c

@ -113,6 +113,59 @@ FILE *basilisk_swap_save(struct basilisk_swap *swap,bits256 privkey,struct basil
}*/
return(fp);
}
/*char *issue_LP_notifyutxo(char *destip,uint16_t destport,struct LP_utxoinfo *utxo)
{
char url[4096],str[65],str2[65],str3[65],*retstr; struct _LP_utxoinfo u; uint64_t val,val2;
if ( (retstr= LP_isitme(destip,destport)) != 0 )
return(retstr);
if ( utxo->iambob == 0 )
{
printf("issue_LP_notifyutxo trying to send Alice %s/v%d\n",bits256_str(str,utxo->payment.txid),utxo->payment.vout);
return(0);
}
u = (utxo->iambob != 0) ? utxo->deposit : utxo->fee;
if ( LP_iseligible(&val,&val2,utxo->iambob,utxo->coin,utxo->payment.txid,utxo->payment.vout,utxo->S.satoshis,u.txid,u.vout) > 0 )
{
sprintf(url,"http://%s:%u/api/stats/notified?iambob=%d&pubkey=%s&coin=%s&txid=%s&vout=%d&value=%llu&txid2=%s&vout2=%d&value2=%llu&script=%s&address=%s&timestamp=%u&gui=%s",destip,destport,utxo->iambob,bits256_str(str3,utxo->pubkey),utxo->coin,bits256_str(str,utxo->payment.txid),utxo->payment.vout,(long long)utxo->payment.value,bits256_str(str2,utxo->deposit.txid),utxo->deposit.vout,(long long)utxo->deposit.value,utxo->spendscript,utxo->coinaddr,(uint32_t)time(NULL),utxo->gui);
if ( strlen(url) > 1024 )
printf("WARNING long url.(%s)\n",url);
return(LP_issue_curl("notifyutxo",destip,destport,url));
//return(issue_curlt(url,LP_HTTP_TIMEOUT));
}
else
{
printf("issue_LP_notifyutxo: ineligible utxo iambob.%d %.8f %.8f\n",utxo->iambob,dstr(val),dstr(val2));
if ( utxo->T.spentflag == 0 )
utxo->T.spentflag = (uint32_t)time(NULL);
return(0);
}
}*/
/*char *issue_LP_lookup(char *destip,uint16_t destport,bits256 pubkey)
{
char url[512],str[65];
sprintf(url,"http://%s:%u/api/stats/lookup?client=%s",destip,destport,bits256_str(str,pubkey));
//printf("getutxo.(%s)\n",url);
return(LP_issue_curl("lookup",destip,destport,url));
//return(issue_curlt(url,LP_HTTP_TIMEOUT));
}*/
/*if ( LP_canbind == 0 )
{
//printf("check deadman %u vs %u\n",LP_deadman_switch,(uint32_t)time(NULL));
if ( LP_deadman_switch < time(NULL)-PSOCK_KEEPALIVE )
{
printf("DEAD man's switch %u activated at %u lag.%d, register forwarding again\n",LP_deadman_switch,(uint32_t)time(NULL),(uint32_t)(time(NULL) - LP_deadman_switch));
if ( pullsock >= 0 )
nn_close(pullsock);
pullsock = LP_initpublicaddr(ctx,&mypullport,pushaddr,myipaddr,mypullport,0);
LP_deadman_switch = (uint32_t)time(NULL);
strcpy(LP_publicaddr,pushaddr);
LP_publicport = mypullport;
LP_forwarding_register(LP_mypubkey,pushaddr,mypullport,MAX_PSOCK_PORT);
}
}*/
/*if ( lastforward < now-3600 )
{
if ( (retstr= LP_registerall(0)) != 0 )

Loading…
Cancel
Save