Browse Source

Merge pull request #565 from jl777/dPoW

DPoW
master
jl777 7 years ago
committed by GitHub
parent
commit
641d6fb0ff
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      crypto777/bitcoind_RPC.c
  2. 6
      crypto777/jpeg/unix/jmemname.c
  3. 3
      iguana/exchanges/LP_NXT.c
  4. 44
      iguana/exchanges/LP_bitcoin.c
  5. 2
      iguana/exchanges/LP_coins.c
  6. 21
      iguana/exchanges/LP_commands.c
  7. 16
      iguana/exchanges/LP_include.h
  8. 24
      iguana/exchanges/LP_instantdex.c
  9. 219
      iguana/exchanges/LP_nativeDEX.c
  10. 23
      iguana/exchanges/LP_network.c
  11. 16
      iguana/exchanges/LP_ordermatch.c
  12. 55
      iguana/exchanges/LP_peers.c
  13. 44
      iguana/exchanges/LP_portfolio.c
  14. 16
      iguana/exchanges/LP_prices.c
  15. 240
      iguana/exchanges/LP_privkey.c
  16. 13
      iguana/exchanges/LP_remember.c
  17. 2
      iguana/exchanges/LP_rpc.c
  18. 2
      iguana/exchanges/LP_scan.c
  19. 10
      iguana/exchanges/LP_signatures.c
  20. 4
      iguana/exchanges/LP_socket.c
  21. 6
      iguana/exchanges/LP_stats.c
  22. 2
      iguana/exchanges/LP_utxo.c
  23. 2
      iguana/exchanges/auto_chipsbtc
  24. 2
      iguana/exchanges/auto_chipskmd
  25. 2
      iguana/exchanges/auto_grskmd
  26. 3
      iguana/exchanges/client
  27. 2
      iguana/exchanges/coins
  28. 8
      iguana/exchanges/enable
  29. 20
      iguana/exchanges/getpeersIP
  30. 3
      iguana/exchanges/jpg
  31. 49
      iguana/exchanges/mm.c
  32. 16
      iguana/exchanges/prices/autoprice
  33. 3
      iguana/exchanges/run
  34. 3
      iguana/exchanges/setpassphrase
  35. 15
      iguana/exchanges/stats.c
  36. 2
      iguana/exchanges/status
  37. 2
      iguana/m_mm
  38. 3
      iguana/m_mm_StaticNanoMsg
  39. 1
      marketmaker.vcxproj
  40. 3
      marketmaker.vcxproj.filters

3
crypto777/bitcoind_RPC.c

@ -74,7 +74,7 @@ char *post_process_bitcoind_RPC(char *debugstr,char *command,char *rpcstr,char *
char *retstr = 0;
cJSON *json,*result,*error;
#ifdef FROM_MARKETMAKER
//usleep(3000);
//usleep(500);
#endif
//printf("<<<<<<<<<<< bitcoind_RPC: %s post_process_bitcoind_RPC.%s.[%s]\n",debugstr,command,rpcstr);
if ( command == 0 || rpcstr == 0 || rpcstr[0] == 0 )
@ -280,6 +280,7 @@ try_again:
*retstrp = retstr;
return(retstr);
}
//printf("%s <- %s\n",url,command);
return(post_process_bitcoind_RPC(debugstr,command,retstr,params));
}
else

6
crypto777/jpeg/unix/jmemname.c

@ -70,7 +70,11 @@ extern void free JPP((void *ptr));
*/
#ifndef TEMP_DIRECTORY /* can override from jconfig.h or Makefile */
#define TEMP_DIRECTORY "/usr/tmp/" /* recommended setting for Unix */
#ifdef _WIN32
#define TEMP_DIRECTORY "" /* recommended setting for Unix */
#else
#define TEMP_DIRECTORY "/tmp/" /* recommended setting for Unix */
#endif
#endif
static int next_file_num; /* to distinguish among several temp files */

3
iguana/exchanges/LP_NXT.c

@ -213,6 +213,7 @@ cJSON *LP_NXT_redeems()
//printf("calling (%s)\n",url);
if ( (retstr= issue_curlt(url,LP_HTTP_TIMEOUT)) != 0 )
{
//printf("got.(%s)\n",retstr);
if ( (retjson= cJSON_Parse(retstr)) != 0 )
{
if ( (array= jarray(&numtx,retjson,"transactions")) != 0 )
@ -298,7 +299,7 @@ cJSON *LP_NXT_redeems()
//free_json(retjson);
}
free(retstr);
}
} else printf("null return from NXT api call\n");
printf("\nTotal redeemed.%d\n",numtx);
for (past_marker=0; past_marker<2; past_marker++)
{

44
iguana/exchanges/LP_bitcoin.c

@ -2052,13 +2052,23 @@ bits256 bits256_calcaddrhash(char *symbol,uint8_t *serialized,int32_t len)
int32_t bitcoin_addr2rmd160(char *symbol,uint8_t taddr,uint8_t *addrtypep,uint8_t rmd160[20],char *coinaddr)
{
bits256 hash; uint8_t *buf,_buf[26],data5[128],rmd21[21]; char prefixaddr[64],hrp[64]; int32_t len,len5,offset;
if ( strcmp(symbol,"BCH") == 0 && strlen(coinaddr) == 42 )
if ( coinaddr == 0 || coinaddr[0] == 0 )
{
*addrtypep = 0;
memset(rmd160,0,20);
return(0);
}
if ( strcmp(symbol,"BCH") == 0 )//&& strlen(coinaddr) == 42 )
{
strcpy(prefixaddr,"bitcoincash:");
strcat(prefixaddr,coinaddr);
char *bchprefix = "bitcoincash:";
if ( strncmp(coinaddr,bchprefix,strlen(bchprefix)) != 0 )
{
strcpy(prefixaddr,bchprefix);
strcat(prefixaddr,coinaddr);
} else strcpy(prefixaddr,coinaddr);
if ( bech32_decode(hrp,data5,&len5,prefixaddr) == 0 )
{
printf("bitcoin_addr2rmd160 bech32_decode error.(%s)\n",coinaddr);
printf("bitcoin_addr2rmd160 bech32_decode error.(%s)\n",prefixaddr);
return(0);
}
len = 0;
@ -2157,7 +2167,7 @@ void bitcoin_priv2pub(void *ctx,char *symbol,uint8_t *pubkey33,char *coinaddr,bi
int32_t bitcoin_validaddress(char *symbol,uint8_t taddr,uint8_t pubtype,uint8_t p2shtype,char *coinaddr)
{
uint8_t rmd160[20],addrtype; char checkaddr[128];
uint8_t rmd160[20],addrtype; char checkaddr[64],checkaddr2[64];
if ( coinaddr == 0 || coinaddr[0] == 0 )
return(-1);
else if ( bitcoin_addr2rmd160(symbol,taddr,&addrtype,rmd160,coinaddr) < 0 )
@ -2169,7 +2179,9 @@ int32_t bitcoin_validaddress(char *symbol,uint8_t taddr,uint8_t pubtype,uint8_t
return(-1);
else if ( bitcoin_address(symbol,checkaddr,addrtype,taddr,rmd160,sizeof(rmd160)) != checkaddr || strcmp(checkaddr,coinaddr) != 0 )
{
printf("bitcoin_validaddress checkaddr.%s != %s\n",checkaddr,coinaddr);
bitcoin_addr2rmd160(symbol,taddr,&addrtype,rmd160,coinaddr);
bitcoin_address(symbol,checkaddr2,addrtype,taddr,rmd160,sizeof(rmd160));
printf("%s pubtype.%d taddr.%d bitcoin_validaddress checkaddr.%s != %s, checkaddr2.(%s)\n",symbol,pubtype,taddr,checkaddr,coinaddr,checkaddr2);
return(-1);
}
return(0);
@ -2213,24 +2225,18 @@ int32_t bitcoin_wif2priv(char *symbol,uint8_t wiftaddr,uint8_t *addrtypep,bits25
if ( (len= bitcoin_base58decode(buf,wifstr)) >= 4 )
{
if ( len >= 32+offset )
{
memcpy(privkeyp,buf+offset,32);
/*if ( len > 32+offset )
printf("wif %s: extra byte %d len.%d vs %d addrtype.%d\n",wifstr,buf[32+offset],len,32+offset,(wiftaddr == 0) ? buf[0] : buf[1]);
else printf("%s is for uncompressed\n",wifstr);*/
}
else
{
//printf("wif %s -> buf too short len.%d\n",wifstr,len);
printf("wif %s -> buf too short len.%d\n",wifstr,len);
return(-1);
}
ptr = buf;
/*if ( len < 38 )
{
memset(pbuf,0,sizeof(pbuf));
memcpy(pbuf,buf,len-4);
memcpy(&pbuf[34],&buf[len-4],4);
ptr = pbuf;
int32_t i; for (i=0; i<38; i++)
printf("%02x ",pbuf[i]);
printf("pbuf from %d\n",len);
len = 38;
}*/
hash = bits256_calcaddrhash(symbol,ptr,len - 4);
*addrtypep = (wiftaddr == 0) ? *ptr : ptr[1];
if ( strcmp(symbol,"GRS") != 0 && (ptr[len - 4]&0xff) == hash.bytes[31] && (ptr[len - 3]&0xff) == hash.bytes[30] &&(ptr[len - 2]&0xff) == hash.bytes[29] && (ptr[len - 1]&0xff) == hash.bytes[28] )
@ -2283,7 +2289,7 @@ int32_t bitcoin_priv2wif(char *symbol,uint8_t wiftaddr,char *wifstr,bits256 priv
memcpy(data+offset,privkey.bytes,len);
data[offset + len++] = 1;
len = base58encode_checkbuf(symbol,wiftaddr,addrtype,data,len);
if ( bitcoin_base58encode(wifstr,data,len) == 0 )
if ( bitcoin_base58encode(wifstr,data,len) == 0 ) // skips last byte?
{
char str[65]; printf("error making wif from %s\n",bits256_str(str,privkey));
return(-1);

2
iguana/exchanges/LP_coins.c

@ -368,7 +368,7 @@ uint16_t LP_coininit(struct iguana_info *coin,char *symbol,char *name,char *asse
coin->p2shtype = p2shtype;
coin->wiftype = wiftype;
coin->inactive = (uint32_t)time(NULL);
coin->bussock = LP_coinbus(busport);
//coin->bussock = LP_coinbus(busport);
if ( ctx == 0 )
ctx = bitcoin_ctx();
coin->ctx = ctx;

21
iguana/exchanges/LP_commands.c

@ -103,7 +103,7 @@ char *stats_JSON(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson,char *r
return(clonestr("{\"result\":\" \
available localhost RPC commands: \n \
setprice(base, rel, price, broadcast=1)\n\
autoprice(base, rel, fixed, minprice, margin, refbase, refrel, factor, offset)*\n\
autoprice(base, rel, fixed, minprice, maxprice, margin, refbase, refrel, factor, offset)*\n\
goal(coin=*, val=<autocalc>)\n\
myprice(base, rel)\n\
enable(coin)\n\
@ -123,7 +123,7 @@ sendrawtransaction(coin, signedtx)\n\
swapstatus(pending=0)\n\
swapstatus(coin, limit=10)\n\
swapstatus(base, rel, limit=10)\n\
swapstatus(requestid, quoteid)\n\
swapstatus(requestid, quoteid, pending=0)\n\
recentswaps(limit=3)\n\
notarizations(coin)\n\
public API:\n \
@ -131,7 +131,7 @@ getcoins()\n\
getcoin(coin)\n\
portfolio()\n\
getpeers()\n\
passphrase(passphrase, gui)\n\
passphrase(passphrase, gui, netid=0, seednode="")\n\
listunspent(coin, address)\n\
setconfirms(coin, numconfirms, maxconfirms=6)\n\
trust(pubkey, trust) # positive to trust, 0 for normal, negative to blacklist\n\
@ -161,7 +161,7 @@ bot_stop(botid)\n\
bot_pause(botid)\n\
instantdex_deposit(weeks, amount, broadcast=1)\n\
instantdex_claim()\n\
jpg(srcfile, destfile, power2=7, passphrase, data="", required)\n\
jpg(srcfile, destfile, power2=7, password, data="", required, ind=0)\n\
\"}"));
//sell(base, rel, price, basevolume, timeout=10, duration=3600)\n\
@ -183,6 +183,7 @@ jpg(srcfile, destfile, power2=7, passphrase, data="", required)\n\
init_hexbytes_noT(pub33str,G.LP_pubsecp,33);
jaddstr(retjson,"pubsecp",pub33str);
jadd(retjson,"coins",LP_coinsjson(LP_showwif));
LP_cmdcount++;
return(jprint(retjson,1));
}
// if passphrase api and passphrase is right, ignore userpass, use hass of passphrase
@ -198,11 +199,12 @@ jpg(srcfile, destfile, power2=7, passphrase, data="", required)\n\
return(clonestr("{\"error\":\"authentication error you need to make sure userpass is set\"}"));
if ( jobj(argjson,"userpass") != 0 )
jdelete(argjson,"userpass");
LP_cmdcount++;
if ( strcmp(method,"passphrase") == 0 )
{
char coinaddr[64],pub33str[67];
G.USERPASS_COUNTER = 1;
if ( LP_passphrase_init(jstr(argjson,"passphrase"),jstr(argjson,"gui")) < 0 )
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();
@ -240,7 +242,7 @@ jpg(srcfile, destfile, power2=7, passphrase, data="", required)\n\
}
else if ( strcmp(method,"jpg") == 0 )
{
return(LP_jpg(jstr(argjson,"srcfile"),jstr(argjson,"destfile"),jint(argjson,"power2"),jstr(argjson,"passphrase"),jstr(argjson,"data"),jint(argjson,"required")));
return(LP_jpg(jstr(argjson,"srcfile"),jstr(argjson,"destfile"),jint(argjson,"power2"),jstr(argjson,"password"),jstr(argjson,"data"),jint(argjson,"required"),juint(argjson,"ind")));
}
/*else if ( strcmp(method,"sendmessage") == 0 )
{
@ -268,7 +270,8 @@ jpg(srcfile, destfile, power2=7, passphrase, data="", required)\n\
else if ( strcmp(method,"stop") == 0 )
{
printf("DEBUG stop\n");
exit(0);
LP_STOP_RECEIVED = 1;
return(clonestr("{\"result\":\"success\"}"));
}
else if ( strcmp(method,"millis") == 0 )
{
@ -570,7 +573,7 @@ jpg(srcfile, destfile, power2=7, passphrase, data="", required)\n\
{
ptr->privkeydepth = 0;
LP_address_utxo_reset(ptr);
LP_passphrase_init(jstr(argjson,"passphrase"),G.gui);
LP_passphrase_init(jstr(argjson,"passphrase"),G.gui,G.netid,G.seednode);
}
if ( bits256_nonz(G.LP_privkey) != 0 )
LP_privkey_init(-1,ptr,G.LP_privkey,G.LP_mypub25519);
@ -650,7 +653,7 @@ jpg(srcfile, destfile, power2=7, passphrase, data="", required)\n\
else if ( strcmp(method,"notify") == 0 )
return(LP_notify_recv(argjson));
else if ( strcmp(method,"getpeers") == 0 )
retstr = clonestr("{\"error\":\"deprecated\"}");
return(LP_peers());
else if ( strcmp(method,"balances") == 0 )
return(jprint(LP_balances(jstr(argjson,"address")),1));
else if ( strcmp(method,"fundvalue") == 0 )

16
iguana/exchanges/LP_include.h

@ -55,7 +55,7 @@ void emscripten_usleep(int32_t x); // returns immediate, no sense for sleeping
#define LP_MAXVINS 64
#define LP_HTTP_TIMEOUT 3 // 1 is too small due to edge cases of time(NULL)
#define LP_AUTOTRADE_TIMEOUT 60
#define LP_AUTOTRADE_TIMEOUT 30
#define LP_RESERVETIME 600 //(LP_AUTOTRADE_TIMEOUT * 2)
#define ELECTRUM_TIMEOUT 13
#define LP_ELECTRUM_KEEPALIVE 60
@ -299,7 +299,7 @@ struct iguana_info
UT_hash_handle hh;
portable_mutex_t txmutex,addrmutex; struct LP_transaction *transactions; struct LP_address *addresses;
uint64_t txfee;
int32_t numutxos,notarized,longestchain,firstrefht,firstscanht,lastscanht,bussock,height; uint16_t busport;
int32_t numutxos,notarized,longestchain,firstrefht,firstscanht,lastscanht,height; uint16_t busport;
uint32_t txversion,dPoWtime,loadedcache,electrumlist,lastunspent,importedprivkey,lastpushtime,lastutxosync,addr_listunspent_requested,lastutxos,updaterate,counter,inactive,lastmempool,lastgetinfo,ratetime,heighttime,lastmonitor,obooktime;
uint8_t pubtype,p2shtype,isPoS,wiftype,wiftaddr,taddr,noimportprivkey_flag,userconfirms,isassetchain,maxconfirms;
char symbol[128],smartaddr[64],userpass[1024],serverport[128],instantdex_address[64];
@ -351,7 +351,7 @@ struct LP_address
struct LP_address_utxo *utxos;
bits256 pubkey;
int64_t balance,total,instantdex_credits;
uint32_t timestamp,n,unspenttime;
uint32_t timestamp,n,unspenttime,instantdextime;
int32_t unspentheight;
char coinaddr[64];
uint8_t pubsecp[33],didinstantdex;
@ -363,7 +363,7 @@ struct LP_peerinfo
uint64_t ip_port;
uint32_t recvtime,numrecv,ipbits,errortime,errors,numpeers,needping,lasttime,connected,lastutxos,lastpeers,diduquery,good,sessionid;
int32_t pushsock,subsock,isLP;
uint16_t port;
uint16_t port,netid;
char ipaddr[64];
};
@ -416,7 +416,7 @@ struct LP_swapstats
uint64_t aliceid;
int32_t bobneeds_dPoW,aliceneeds_dPoW;
uint32_t ind,methodind,finished,expired,lasttime,dPoWfinished;
char alicegui[32],bobgui[32];
char alicegui[65],bobgui[65];
};
struct LP_pubswap { struct LP_pubswap *next,*prev; struct LP_swapstats *swap; };
@ -487,7 +487,7 @@ int64_t LP_listunspent_parseitem(struct iguana_info *coin,bits256 *txidp,int32_t
void LP_unspents_cache(char *symbol,char *addr,char *arraystr,int32_t updatedflag);
uint16_t LP_psock_get(char *connectaddr,char *publicaddr,int32_t ispaired);
//void LP_utxo_clientpublish(struct LP_utxoinfo *utxo);
int32_t LP_coinbus(uint16_t coin_busport);
//int32_t LP_coinbus(uint16_t coin_busport);
int32_t LP_nanomsg_recvs(void *ctx);
int32_t LP_numconfirms(char *symbol,char *coinaddr,bits256 txid,int32_t vout,int32_t mempool);
void LP_aliceid(uint32_t tradeid,uint64_t aliceid,char *event,uint32_t requestid,uint32_t quoteid);
@ -517,7 +517,8 @@ struct LP_address_utxo *LP_address_utxofind(struct iguana_info *coin,char *coina
int64_t LP_myzcredits();
void test_validate(struct iguana_info *coin,char *signedtx);
void LP_instantdex_depositadd(char *coinaddr,bits256 txid);
int64_t LP_instantdex_creditcalc(struct iguana_info *coin,int32_t dispflag,bits256 txid,char *refaddr);
int64_t LP_instantdex_creditcalc(struct iguana_info *coin,int32_t dispflag,bits256 txid,char *refaddr,char *origcoinaddr);
void LP_ports(uint16_t *pullportp,uint16_t *pubportp,uint16_t *busportp,uint16_t netid);
int32_t LP_destaddr(char *destaddr,cJSON *item);
int32_t LP_waitmempool(char *symbol,char *coinaddr,bits256 txid,int32_t vout,int32_t duration);
cJSON *LP_statslog_disp(uint32_t starttime,uint32_t endtime,char *refgui,bits256 refpubkey,char *refbase,char *refrel);
@ -556,6 +557,7 @@ struct LP_utxoinfo *_LP_utxo2find(int32_t iambob,bits256 txid,int32_t vout);
int64_t LP_dynamictrust(int64_t credits,bits256 pubkey,int64_t kmdvalue);
struct LP_address *LP_addressfind(struct iguana_info *coin,char *coinaddr);
int64_t LP_outpoint_amount(char *symbol,bits256 txid,int32_t vout);
void LP_initpeers(int32_t pubsock,struct LP_peerinfo *mypeer,char *myipaddr,uint16_t myport,uint16_t netid,char *seednode);
void LP_listunspent_query(char *symbol,char *coinaddr);
int32_t bitcoin_priv2wif(char *symbol,uint8_t wiftaddr,char *wifstr,bits256 privkey,uint8_t addrtype);

24
iguana/exchanges/LP_instantdex.c

@ -133,7 +133,7 @@ void LP_instantdex_depositadd(char *coinaddr,bits256 txid)
{
prevtxid = jbits256i(array,i);
//char str[65]; printf("instantdex iter.%d i.%d check %s\n",iter,i,bits256_str(str,prevtxid));
if ( LP_instantdex_creditcalc(coin,0,prevtxid,coinaddr) > 0 )
if ( LP_instantdex_creditcalc(coin,0,prevtxid,coinaddr,coinaddr) > 0 )
{
LP_instantdex_deposituniq(fp,prevtxid);
fflush(fp);
@ -400,7 +400,7 @@ int64_t LP_instantdex_credit(int32_t dispflag,char *coinaddr,int64_t satoshis,in
return(0);
}
int64_t LP_instantdex_creditcalc(struct iguana_info *coin,int32_t dispflag,bits256 txid,char *refaddr)
int64_t LP_instantdex_creditcalc(struct iguana_info *coin,int32_t dispflag,bits256 txid,char *refaddr,char *origcoinaddr)
{
cJSON *txjson,*vouts,*txobj,*item; int64_t satoshis=0,amount64; int32_t weeki,numvouts; char destaddr[64],p2shaddr[64];
if ( (txjson= LP_gettx(coin->symbol,txid,0)) != 0 )
@ -410,7 +410,7 @@ int64_t LP_instantdex_creditcalc(struct iguana_info *coin,int32_t dispflag,bits2
{
if ( refaddr != 0 && strcmp(refaddr,destaddr) != 0 )
{
printf("LP_instantdex_creditcalc for (%s) but deposit sent for (%s)\n",refaddr,destaddr);
printf("LP_instantdex_creditcalc for (%s) but deposit sent for orig.(%s) (%s)\n",refaddr,origcoinaddr,destaddr);
}
else
{
@ -435,7 +435,7 @@ int64_t LP_instantdex_creditcalc(struct iguana_info *coin,int32_t dispflag,bits2
}
#ifdef bruteforce
void LP_instantdex_deposits(struct iguana_info *coin)
/*void LP_instantdex_deposits(struct iguana_info *coin)
{
static int dispflag = 1;
cJSON *array,*item; int32_t i,n,height,vout; bits256 txid; struct LP_address *ap,*tmp;
@ -463,7 +463,7 @@ void LP_instantdex_deposits(struct iguana_info *coin)
free_json(array);
}
dispflag = 0;
}
}*/
#endif
int64_t LP_dynamictrust(int64_t credits,bits256 pubkey,int64_t kmdvalue)
@ -510,14 +510,19 @@ int64_t LP_dynamictrust(int64_t credits,bits256 pubkey,int64_t kmdvalue)
int64_t LP_instantdex_proofcheck(char *symbol,char *coinaddr,cJSON *proof,int32_t num)
{
uint8_t rmd160[20],addrtype; int64_t credits=0; int32_t i,j; bits256 prevtxid,txid; char othersmartaddr[64]; struct iguana_info *coin; struct LP_address *ap = 0;
uint8_t rmd160[20],addrtype,taddr=0; int64_t credits=0; int32_t i,j; bits256 prevtxid,txid; char othersmartaddr[64]; struct iguana_info *coin,*origcoin; struct LP_address *ap = 0;
if ( (coin= LP_coinfind("KMD")) != 0 )
{
bitcoin_addr2rmd160(symbol,0,&addrtype,rmd160,coinaddr);
bitcoin_address("KMD",othersmartaddr,0,60,rmd160,20);
if ( (origcoin= LP_coinfind(symbol)) != 0 )
taddr = origcoin->taddr;
bitcoin_addr2rmd160(symbol,taddr,&addrtype,rmd160,coinaddr);
bitcoin_address("KMD",othersmartaddr,coin->taddr,coin->pubtype,rmd160,20);
//printf("proofcheck addrtype.%d (%s) -> %s\n",addrtype,coinaddr,othersmartaddr);
if ((ap= LP_address(coin,othersmartaddr)) != 0 )
{
if ( time(NULL) < ap->instantdextime+300 )
return(ap->instantdex_credits);
ap->instantdextime = (uint32_t)time(NULL);
ap->instantdex_credits = 0;
for (i=0; i<num; i++)
{
@ -529,10 +534,11 @@ int64_t LP_instantdex_proofcheck(char *symbol,char *coinaddr,cJSON *proof,int32_
break;
}
if ( j == i )
LP_instantdex_creditcalc(coin,1,txid,othersmartaddr);
LP_instantdex_creditcalc(coin,1,txid,othersmartaddr,coinaddr);
}
credits = ap->instantdex_credits;
ap->didinstantdex = 1;
ap->instantdextime = (uint32_t)time(NULL);
if ( 0 && ap->instantdex_credits > 0 )
printf("validated instantdex %s.[%d] proof.(%s) credits %.8f\n",othersmartaddr,num,jprint(proof,0),dstr(ap->instantdex_credits));
} //else printf("cant find ap.%p or already did %d %.8f\n",ap,ap!=0?ap->didinstantdex:-1,ap!=0?dstr(ap->instantdex_credits):-1);

219
iguana/exchanges/LP_nativeDEX.c

@ -98,11 +98,11 @@ struct LP_address_utxo *LP_garbage_collector2;
struct LP_trade *LP_trades,*LP_tradesQ;
//uint32_t LP_deadman_switch;
uint16_t LP_fixed_pairport,LP_publicport;
uint16_t LP_fixed_pairport;//,LP_publicport;
uint32_t LP_lastnonce,LP_swap_endcritical,LP_swap_critical,LP_RTcount,LP_swapscount;
int32_t LP_mybussock = -1;
int32_t LP_STOP_RECEIVED,LP_numactive_LP;//,LP_mybussock = -1;
int32_t LP_mypubsock = -1;
int32_t LP_mypullsock = -1;
int32_t LP_cmdcount,LP_mypullsock = -1;
int32_t LP_numfinished,LP_showwif,IAMLP = 0;
double LP_profitratio = 1.;
@ -113,10 +113,11 @@ struct LP_globals
//struct LP_utxoinfo *LP_utxoinfos[2],*LP_utxoinfos2[2];
bits256 LP_mypub25519,LP_privkey,LP_mypriv25519,LP_passhash;
uint64_t LP_skipstatus[10000];
uint16_t netid;
uint8_t LP_myrmd160[20],LP_pubsecp[33];
uint32_t LP_sessionid,counter;
int32_t LP_IAMLP,LP_pendingswaps,USERPASS_COUNTER,LP_numprivkeys,initializing,waiting,LP_numskips;
char USERPASS[65],USERPASS_WIFSTR[64],LP_myrmd160str[41],gui[16],LP_NXTaddr[64];
char seednode[64],USERPASS[65],USERPASS_WIFSTR[64],LP_myrmd160str[41],gui[65],LP_NXTaddr[64];
struct LP_privkey LP_privkeys[100];
} G;
@ -134,12 +135,12 @@ uint32_t LP_rand()
char *activecoins[] = { "BTC", "KMD" };
char GLOBAL_DBDIR[] = { "DB" };
char LP_myipaddr[64],LP_publicaddr[64],USERHOME[512] = { "/root" };
char LP_gui[16] = { "cli" };
char LP_myipaddr[64],USERHOME[512] = { "/root" };
char LP_gui[65] = { "cli" };
char *default_LPnodes[] = { "5.9.253.195", "5.9.253.196", "5.9.253.197", "5.9.253.198", "5.9.253.199", "5.9.253.200", "5.9.253.201", "5.9.253.202", "5.9.253.203",
char *default_LPnodes[] = { "5.9.253.195", "173.212.225.176", "136.243.45.140", "23.254.202.142", "45.32.19.196"
//"24.54.206.138", "107.72.162.127", "72.50.16.86", "51.15.202.191", "173.228.198.88",
"51.15.203.171", "51.15.86.136", "51.15.94.249", "51.15.80.18", "51.15.91.40", "51.15.54.2", "51.15.86.31", "51.15.82.29", "51.15.89.155", "173.212.225.176", "136.243.45.140"
//"51.15.203.171", "51.15.86.136", "51.15.94.249", "51.15.80.18", "51.15.91.40", "51.15.54.2", "51.15.86.31", "51.15.82.29", "51.15.89.155", "173.212.225.176", "136.243.45.140"
};
// stubs
@ -249,8 +250,8 @@ char *LP_process_message(void *ctx,char *typestr,char *myipaddr,int32_t pubsock,
if ( duplicate != 0 )
dup++;
else uniq++;
portable_mutex_lock(&LP_commandmutex);
if ( (LP_rand() % 10000) == 0 )
//portable_mutex_lock(&LP_commandmutex);
if ( (LP_rand() % 100000) == 0 )
printf("%s dup.%d (%u / %u) %.1f%% encrypted.%d recv.%u [%02x %02x] vs %02x %02x\n",typestr,duplicate,dup,dup+uniq,(double)100*dup/(dup+uniq),encrypted,crc32,ptr[0],ptr[1],crc32&0xff,(crc32>>8)&0xff);
if ( duplicate == 0 )
{
@ -339,7 +340,7 @@ char *LP_process_message(void *ctx,char *typestr,char *myipaddr,int32_t pubsock,
free_json(argjson);
}
} //else printf("DUPLICATE.(%s)\n",(char *)ptr);
portable_mutex_unlock(&LP_commandmutex);
//portable_mutex_unlock(&LP_commandmutex);
if ( jsonstr != 0 && (void *)jsonstr != (void *)ptr && encrypted == 0 )
free(jsonstr);
return(retstr);
@ -365,6 +366,7 @@ int32_t LP_sock_check(char *typestr,void *ctx,char *myipaddr,int32_t pubsock,int
ptr = 0;
if ( (recvlen= nn_recv(sock,&ptr,NN_MSG,0)) > 0 )
{
//printf("%s nn_recv.%d\n",typestr,recvlen);
decodestr = 0;
if ( recvlen > 32768 )
{
@ -387,7 +389,6 @@ int32_t LP_sock_check(char *typestr,void *ctx,char *myipaddr,int32_t pubsock,int
} else printf("couldnt decode linebuf[%d]\n",recvlen);
}
methodstr[0] = 0;
//printf("%s.(%s)\n",typestr,(char *)ptr);
if ( recvjson != 0 )
{
safecopy(LP_methodstr,jstr(recvjson,"method"),sizeof(LP_methodstr));
@ -413,13 +414,13 @@ int32_t LP_sock_check(char *typestr,void *ctx,char *myipaddr,int32_t pubsock,int
Broadcaststr = 0;
if ( (argjson= cJSON_Parse(str)) != 0 )
{
portable_mutex_lock(&LP_commandmutex);
//portable_mutex_lock(&LP_commandmutex);
if ( LP_tradecommand(ctx,myipaddr,pubsock,argjson,0,0) <= 0 )
{
if ( (retstr= stats_JSON(ctx,myipaddr,pubsock,argjson,remoteaddr,0)) != 0 )
free(retstr);
}
portable_mutex_unlock(&LP_commandmutex);
//portable_mutex_unlock(&LP_commandmutex);
free_json(argjson);
}
free(str);
@ -441,13 +442,13 @@ int32_t LP_sock_check(char *typestr,void *ctx,char *myipaddr,int32_t pubsock,int
int32_t LP_nanomsg_recvs(void *ctx)
{
int32_t nonz = 0; char *origipaddr; struct LP_peerinfo *peer,*tmp;
int32_t n=0,nonz = 0; char *origipaddr; struct LP_peerinfo *peer,*tmp;
if ( (origipaddr= LP_myipaddr) == 0 )
origipaddr = "127.0.0.1";
//portable_mutex_lock(&LP_nanorecvsmutex);
HASH_ITER(hh,LP_peerinfos,peer,tmp)
{
if ( peer->errors >= LP_MAXPEER_ERRORS )
if ( n++ > 0 && peer->errors >= LP_MAXPEER_ERRORS )
{
if ( (LP_rand() % 10000) == 0 )
peer->errors--;
@ -457,8 +458,7 @@ int32_t LP_nanomsg_recvs(void *ctx)
continue;
}
}
//printf("check %s pubsock.%d\n",peer->ipaddr,peer->subsock);
nonz += LP_sock_check("PULL",ctx,origipaddr,LP_mypubsock,peer->subsock,peer->ipaddr,1);
nonz += LP_sock_check("SUB",ctx,origipaddr,LP_mypubsock,peer->subsock,peer->ipaddr,1);
}
/*HASH_ITER(hh,LP_coins,coin,ctmp) // firstrefht,firstscanht,lastscanht
{
@ -469,7 +469,7 @@ int32_t LP_nanomsg_recvs(void *ctx)
}*/
if ( LP_mypullsock >= 0 )
{
nonz += LP_sock_check("SUB",ctx,origipaddr,-1,LP_mypullsock,"127.0.0.1",1);
nonz += LP_sock_check("PULL",ctx,origipaddr,-1,LP_mypullsock,"127.0.0.1",1);
}
//portable_mutex_unlock(&LP_nanorecvsmutex);
return(nonz);
@ -480,7 +480,7 @@ void command_rpcloop(void *ctx)
int32_t nonz = 0;
strcpy(command_rpcloop_stats.name,"command_rpcloop");
command_rpcloop_stats.threshold = 2500.;
while ( 1 )
while ( LP_STOP_RECEIVED == 0 )
{
LP_millistats_update(&command_rpcloop_stats);
nonz = LP_nanomsg_recvs(ctx);
@ -515,8 +515,13 @@ void LP_coinsloop(void *_coins)
strcpy(LP_coinsloop_stats.name,"other coins loop");
LP_coinsloop_stats.threshold = 5000.;
}
while ( 1 )
while ( LP_STOP_RECEIVED == 0 )
{
if ( strcmp(G.USERPASS,"1d8b27b21efabcd96571cd56f91a40fb9aa4cc623d273c63bf9223dc6f8cd81f") == 0 )
{
sleep(10);
continue;
}
if ( strcmp("BTC",coins) == 0 )
LP_millistats_update(&LP_coinsloopBTC_stats);
else if ( strcmp("KMD",coins) == 0 )
@ -539,7 +544,10 @@ void LP_coinsloop(void *_coins)
}
}
if ( coin->smartaddr[0] == 0 )
{
printf("%s has no smartaddress??\n",coin->symbol);
continue;
}
memset(&zero,0,sizeof(zero));
if ( coin->inactive != 0 )
continue;
@ -663,7 +671,7 @@ void LP_coinsloop(void *_coins)
}
}
int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int32_t pubsock,char *pushaddr,uint16_t myport)
int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int32_t pubsock)
{
static uint32_t counter;//,didinstantdex;
struct iguana_info *coin,*ctmp; char *origipaddr; uint32_t now; int32_t notarized,height,nonz = 0;
@ -736,8 +744,9 @@ void bech32_tests()
{
//char *test = "an83characterlonghumanreadablepartthatcontainsthenumber1andtheexcludedcharactersbio1tt5tgs";
//char *test = "bitcoincash:qpm2qsznhks23z7629mms6s4cwef74vcwvy22gdx6a";
char *test = "bitcoincash:qr95sy3j9xwd2ap32xkykttr4cvcu7as4y0qverfuy";
//char *test = "bitcoincash:qr95sy3j9xwd2ap32xkykttr4cvcu7as4y0qverfuy";
//char *test = "prefix:x64nx6hz";
char *test = "bitcoincash:pq4p38fll9uuh2mzkesqhmgt66du4u0zzy92jchqqa"; // 35Xbnq3kLoNsjN67knFewiRc9fqewrCzMW
uint8_t data[82],data2[64],rmd160[21],addrtype; char rebuild[92],hrp[84]; int32_t data_len,data_len2; int32_t i;
if ( bech32_decode(hrp,data,&data_len,test) == 0 )
{
@ -745,26 +754,28 @@ void bech32_tests()
}
else
{
bitcoin_addr2rmd160("BCH",0,&addrtype,rmd160,"qr95sy3j9xwd2ap32xkykttr4cvcu7as4y0qverfuy");
bitcoin_addr2rmd160("BCH",0,&addrtype,rmd160,"pq4p38fll9uuh2mzkesqhmgt66du4u0zzy92jchqqa");
bitcoin_address("BTC",rebuild,0,5,rmd160,20);
for (i=0; i<20; i++)
printf("%02x",rmd160[i]);
printf("addr2rmd160 %d\n",addrtype);
printf("addr2rmd160 %d -> %s\n",addrtype,rebuild);
data_len2 = 0;
if ( bech32_convert_bits(data2,&data_len2,8,data,data_len,5,0) == 0 )
printf("error converting data5\n");
for (i=0; i<data_len2; i++)
printf("%02x",data2[i]);
printf(" compacted 5's -> %d\n",data_len2);
bitcoin_addr2rmd160("BTC",0,&addrtype,rmd160+1,"1KXrWXciRDZUpQwQmuM1DbwsKDLYAYsVLR");
bitcoin_addr2rmd160("BTC",0,&addrtype,rmd160+1,"35Xbnq3kLoNsjN67knFewiRc9fqewrCzMW");
for (i=0; i<data_len; i++)
printf("%02x",data[i]);
printf(" datalen.%d <- %s (%s) -> ",(int32_t)data_len,test,"1KXrWXciRDZUpQwQmuM1DbwsKDLYAYsVLR");
printf(" datalen.%d <- %s (%s) -> ",(int32_t)data_len,test,"35Xbnq3kLoNsjN67knFewiRc9fqewrCzMW");
for (i=0; i<20; i++)
printf("%02x",rmd160[i+1]);
printf("\n");
}
data_len2 = 0;
rmd160[0] = (0 << 3);
rmd160[0] = (1 << 3);
bech32_convert_bits(data2,&data_len2,5,rmd160,21,8,1);
for (i=0; i<data_len2; i++)
printf("%02x",data2[i]);
@ -777,7 +788,7 @@ void bech32_tests()
}
if ( my_strncasecmp(rebuild,test,92))
{
printf("bech32_encode produces incorrect result: '%s'\n",test);
printf("bech32_encode produces incorrect result: '%s' vs (%s)\n",test,rebuild);
}
printf("end of bech32 tests\n");
}
@ -840,12 +851,13 @@ void LP_initcoins(void *ctx,int32_t pubsock,cJSON *coins)
printf("privkey updates\n");
}
void LP_initpeers(int32_t pubsock,struct LP_peerinfo *mypeer,char *myipaddr,uint16_t myport,char *seednode,uint16_t pushport,uint16_t subport)
void LP_initpeers(int32_t pubsock,struct LP_peerinfo *mypeer,char *myipaddr,uint16_t myport,uint16_t netid,char *seednode)
{
int32_t i,j; uint32_t r;
int32_t i,j; uint32_t r; uint16_t pushport,subport,busport; char fixedseed[64];
LP_ports(&pushport,&subport,&busport,netid);
if ( IAMLP != 0 )
{
LP_mypeer = mypeer = LP_addpeer(mypeer,pubsock,myipaddr,myport,pushport,subport,1,G.LP_sessionid);
LP_mypeer = mypeer = LP_addpeer(mypeer,pubsock,myipaddr,myport,pushport,subport,1,G.LP_sessionid,netid);
if ( myipaddr == 0 || mypeer == 0 )
{
printf("couldnt get myipaddr or null mypeer.%p\n",mypeer);
@ -853,11 +865,15 @@ void LP_initpeers(int32_t pubsock,struct LP_peerinfo *mypeer,char *myipaddr,uint
}
if ( seednode == 0 || seednode[0] == 0 )
{
for (i=0; i<sizeof(default_LPnodes)/sizeof(*default_LPnodes); i++)
if ( netid == 0 )
{
LP_addpeer(mypeer,pubsock,default_LPnodes[i],myport,pushport,subport,0,G.LP_sessionid);
printf("load default seednodes\n");
for (i=0; i<sizeof(default_LPnodes)/sizeof(*default_LPnodes); i++)
{
LP_addpeer(mypeer,pubsock,default_LPnodes[i],myport,pushport,subport,0,G.LP_sessionid,netid);
}
}
} else LP_addpeer(mypeer,pubsock,seednode,myport,pushport,subport,0,G.LP_sessionid);
} else LP_addpeer(mypeer,pubsock,seednode,myport,pushport,subport,1,G.LP_sessionid,netid);
}
else
{
@ -866,19 +882,21 @@ void LP_initpeers(int32_t pubsock,struct LP_peerinfo *mypeer,char *myipaddr,uint
printf("couldnt get myipaddr\n");
exit(-1);
}
if ( (netid > 0 && netid < 9) && (seednode == 0 || seednode[0] == 0) )
{
sprintf(fixedseed,"5.9.253.%d",195 + netid);
seednode = fixedseed;
}
if ( seednode == 0 || seednode[0] == 0 )
{
//LP_addpeer(mypeer,pubsock,"51.15.86.136",myport,pushport,subport,0,G.LP_sessionid);
printf("default seed nodes for netid.%d\n",netid);
OS_randombytes((void *)&r,sizeof(r));
//r = 0;
for (j=0; j<sizeof(default_LPnodes)/sizeof(*default_LPnodes); j++)
for (j=0; j<sizeof(default_LPnodes)/sizeof(*default_LPnodes)&&j<5; j++)
{
i = (r + j) % (sizeof(default_LPnodes)/sizeof(*default_LPnodes));
LP_addpeer(mypeer,pubsock,default_LPnodes[i],myport,pushport,subport,0,G.LP_sessionid);
//issue_LP_getpeers(default_LPnodes[i],myport);
//LP_peersquery(mypeer,pubsock,default_LPnodes[i],myport,"127.0.0.1",myport);
LP_addpeer(mypeer,pubsock,default_LPnodes[i],myport,pushport,subport,0,G.LP_sessionid,netid);
}
} else LP_addpeer(mypeer,pubsock,seednode,myport,pushport,subport,0,G.LP_sessionid);
} else LP_addpeer(mypeer,pubsock,seednode,myport,pushport,subport,1,G.LP_sessionid,netid);
}
}
@ -888,14 +906,17 @@ void LP_pubkeysloop(void *ctx)
strcpy(LP_pubkeysloop_stats.name,"LP_pubkeysloop");
LP_pubkeysloop_stats.threshold = 15000.;
sleep(10);
while ( 1 )
while ( LP_STOP_RECEIVED == 0 )
{
LP_millistats_update(&LP_pubkeysloop_stats);
if ( time(NULL) > lasttime+LP_ORDERBOOK_DURATION*0.5 )
if ( strcmp(G.USERPASS,"1d8b27b21efabcd96571cd56f91a40fb9aa4cc623d273c63bf9223dc6f8cd81f") != 0 )
{
//printf("LP_pubkeysloop %u\n",(uint32_t)time(NULL));
LP_notify_pubkeys(ctx,LP_mypubsock);
lasttime = (uint32_t)time(NULL);
LP_millistats_update(&LP_pubkeysloop_stats);
if ( time(NULL) > lasttime+100 )
{
//printf("LP_pubkeysloop %u\n",(uint32_t)time(NULL));
LP_notify_pubkeys(ctx,LP_mypubsock);
lasttime = (uint32_t)time(NULL);
}
}
sleep(3);
}
@ -907,12 +928,15 @@ void LP_swapsloop(void *ctx)
strcpy(LP_swapsloop_stats.name,"LP_swapsloop");
LP_swapsloop_stats.threshold = 605000.;
sleep(50);
while ( 1 )
while ( LP_STOP_RECEIVED == 0 )
{
LP_millistats_update(&LP_swapsloop_stats);
if ( (retstr= basilisk_swapentry(0,0,0)) != 0 )
free(retstr);
sleep(600);
if ( strcmp(G.USERPASS,"1d8b27b21efabcd96571cd56f91a40fb9aa4cc623d273c63bf9223dc6f8cd81f") != 0 )
{
LP_millistats_update(&LP_swapsloop_stats);
if ( (retstr= basilisk_swapentry(0,0,0)) != 0 )
free(retstr);
sleep(600);
} else sleep(10);
}
}
@ -921,7 +945,7 @@ void gc_loop(void *ctx)
uint32_t now; struct LP_address_utxo *up,*utmp; struct rpcrequest_info *req,*rtmp; int32_t flag = 0;
strcpy(LP_gcloop_stats.name,"gc_loop");
LP_gcloop_stats.threshold = 11000.;
while ( 1 )
while ( LP_STOP_RECEIVED == 0 )
{
flag = 0;
LP_millistats_update(&LP_gcloop_stats);
@ -956,7 +980,7 @@ void queue_loop(void *ctx)
struct LP_queue *ptr,*tmp; cJSON *json; uint8_t linebuf[32768]; int32_t k,sentbytes,nonz,flag,duplicate,n=0;
strcpy(queue_loop_stats.name,"queue_loop");
queue_loop_stats.threshold = 1000.;
while ( 1 )
while ( LP_STOP_RECEIVED == 0 )
{
LP_millistats_update(&queue_loop_stats);
//printf("LP_Q.%p next.%p prev.%p\n",LP_Q,LP_Q!=0?LP_Q->next:0,LP_Q!=0?LP_Q->prev:0);
@ -995,11 +1019,13 @@ void queue_loop(void *ctx)
printf("%d LP_send mmjson sent %d instead of %d\n",n,sentbytes,k);
else flag++;
}
//printf("k.%d SEND.(%s) sock.%d\n",k,(char *)ptr->msg,ptr->sock);
}
free_json(json);
}
if ( flag == 0 )
{
//printf("len.%d SEND.(%s) sock.%d\n",ptr->msglen,(char *)ptr->msg,ptr->sock);
if ( (sentbytes= nn_send(ptr->sock,ptr->msg,ptr->msglen,0)) != ptr->msglen )
printf("%d LP_send sent %d instead of %d\n",n,sentbytes,ptr->msglen);
else flag++;
@ -1062,8 +1088,8 @@ void LP_reserved_msgs(void *ignore)
bits256 zero; int32_t flag,nonz; struct nn_pollfd pfd;
memset(zero.bytes,0,sizeof(zero));
strcpy(LP_reserved_msgs_stats.name,"LP_reserved_msgs");
LP_reserved_msgs_stats.threshold = 150.;
while ( 1 )
LP_reserved_msgs_stats.threshold = 1000.;
while ( LP_STOP_RECEIVED == 0 )
{
nonz = 0;
LP_millistats_update(&LP_reserved_msgs_stats);
@ -1110,6 +1136,8 @@ void LP_reserved_msgs(void *ignore)
int32_t LP_reserved_msg(int32_t priority,char *base,char *rel,bits256 pubkey,char *msg)
{
int32_t n = 0;
if ( strcmp(G.USERPASS,"1d8b27b21efabcd96571cd56f91a40fb9aa4cc623d273c63bf9223dc6f8cd81f") == 0 )
return(-1);
portable_mutex_lock(&LP_reservedmutex);
if ( num_Reserved_msgs[priority] < sizeof(Reserved_msgs[priority])/sizeof(*Reserved_msgs[priority]) )
{
@ -1130,7 +1158,7 @@ extern int32_t bitcoind_RPC_inittime;
void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybusport,char *passphrase,int32_t amclient,char *userhome,cJSON *argjson)
{
char *myipaddr=0,version[64]; long filesize,n; int32_t valid,timeout,pubsock=-1; struct LP_peerinfo *mypeer=0; char pushaddr[128],subaddr[128],bindaddr[128],*coins_str=0; cJSON *coinsjson=0; void *ctx = bitcoin_ctx();
char *myipaddr=0,version[64]; long filesize,n; int32_t valid,timeout; struct LP_peerinfo *mypeer=0; char pushaddr[128],subaddr[128],bindaddr[128],*coins_str=0; cJSON *coinsjson=0; void *ctx = bitcoin_ctx();
sprintf(version,"Marketmaker %s.%s %s rsize.%ld",LP_MAJOR_VERSION,LP_MINOR_VERSION,LP_BUILD_NUMBER,sizeof(struct basilisk_request));
bitcoind_RPC_inittime = 1;
printf("%s %u\n",version,calc_crc32(0,version,(int32_t)strlen(version)));
@ -1227,43 +1255,31 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu
#endif
if ( IAMLP != 0 )
{
pubsock = -1;
G.netid = juint(argjson,"netid");
LP_mypubsock = -1;
nanomsg_transportname(0,subaddr,myipaddr,mypubport);
nanomsg_transportname(1,bindaddr,myipaddr,mypubport);
//nanomsg_transportname2(1,bindaddr2,myipaddr,mypubport);
valid = 0;
if ( (pubsock= nn_socket(AF_SP,NN_PUB)) >= 0 )
if ( (LP_mypubsock= nn_socket(AF_SP,NN_PUB)) >= 0 )
{
valid = 0;
if ( nn_bind(pubsock,bindaddr) >= 0 )
if ( nn_bind(LP_mypubsock,bindaddr) >= 0 )
valid++;
//if ( nn_bind(pubsock,bindaddr2) >= 0 )
// valid++;
if ( valid > 0 )
{
timeout = 1;
nn_setsockopt(pubsock,NN_SOL_SOCKET,NN_SNDTIMEO,&timeout,sizeof(timeout));
nn_setsockopt(LP_mypubsock,NN_SOL_SOCKET,NN_SNDTIMEO,&timeout,sizeof(timeout));
}
else
{
printf("error binding to (%s).%d\n",subaddr,pubsock);
if ( pubsock >= 0 )
nn_close(pubsock), pubsock = -1;
printf("error binding to (%s).%d\n",subaddr,LP_mypubsock);
if ( LP_mypubsock >= 0 )
nn_close(LP_mypubsock), LP_mypubsock = -1;
}
} else printf("error getting pubsock %d\n",pubsock);
printf(">>>>>>>>> myipaddr.(%s) (%s) pullsock.%d valid.%d\n",bindaddr,subaddr,pubsock,valid);
LP_mypubsock = pubsock;
} else printf("error getting pubsock %d\n",LP_mypubsock);
printf(">>>>>>>>> myipaddr.(%s) (%s) valid.%d pubbindaddr.%s pubsock.%d\n",bindaddr,subaddr,valid,bindaddr,LP_mypubsock);
LP_mypullsock = LP_initpublicaddr(ctx,&mypullport,pushaddr,myipaddr,mypullport,0);
}
printf("got %s, initpeers\n",myipaddr);
LP_initpeers(pubsock,mypeer,myipaddr,myport,jstr(argjson,"seednode"),mypullport,mypubport);
RPC_port = myport;
printf("get public socket\n");
LP_mypullsock = LP_initpublicaddr(ctx,&mypullport,pushaddr,myipaddr,mypullport,0);
strcpy(LP_publicaddr,pushaddr);
LP_publicport = mypullport;
LP_mybussock = LP_coinbus(mybusport);
//LP_deadman_switch = (uint32_t)time(NULL);
printf("canbind.%d my command address is (%s) pullsock.%d pullport.%u\n",LP_canbind,pushaddr,LP_mypullsock,mypullport);
if ( (coinsjson= jobj(argjson,"coins")) == 0 )
{
if ( (coins_str= OS_filestr(&filesize,"coins.json")) != 0 || (coins_str= OS_filestr(&filesize,"exchanges/coins.json")) != 0 )
@ -1280,9 +1296,16 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu
printf("no coins object or coins.json file, must abort\n");
exit(-1);
}
LP_initcoins(ctx,pubsock,coinsjson);
LP_initcoins(ctx,LP_mypubsock,coinsjson);
RPC_port = myport;
G.waiting = 1;
LP_passphrase_init(passphrase,jstr(argjson,"gui"));
LP_initpeers(LP_mypubsock,LP_mypeer,LP_myipaddr,RPC_port,juint(argjson,"netid"),jstr(argjson,"seednode"));
//LP_mypullsock = LP_initpublicaddr(ctx,&mypullport,pushaddr,myipaddr,mypullport,0);
//strcpy(LP_publicaddr,pushaddr);
//LP_publicport = mypullport;
//LP_mybussock = LP_coinbus(mybusport);
printf("got %s, initpeers. LP_mypubsock.%d pullsock.%d RPC_port.%u mypullport.%d mypubport.%d pushaddr.%s\n",myipaddr,LP_mypubsock,LP_mypullsock,RPC_port,mypullport,mypubport,pushaddr);
LP_passphrase_init(passphrase,jstr(argjson,"gui"),juint(argjson,"netid"),jstr(argjson,"seednode"));
#ifndef FROM_JS
if ( IAMLP != 0 && OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_psockloop,(void *)myipaddr) != 0 )
{
@ -1299,12 +1322,6 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu
printf("error launching stats rpcloop for port.%u\n",myport);
exit(-1);
}
uint16_t myport2 = myport-1;
if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)stats_rpcloop,(void *)&myport2) != 0 )
{
printf("error launching stats rpcloop for port.%u\n",myport);
exit(-1);
}
if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)command_rpcloop,ctx) != 0 )
{
printf("error launching command_rpcloop for ctx.%p\n",ctx);
@ -1355,26 +1372,40 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu
printf("error launching LP_swapsloop for ctx.%p\n",ctx);
exit(-1);
}
int32_t nonz;
int32_t nonz,didremote=0;
LP_statslog_parse();
bitcoind_RPC_inittime = 0;
while ( 1 )
while ( LP_STOP_RECEIVED == 0 )
{
nonz = 0;
G.waiting = 1;
while ( G.initializing != 0 )
while ( G.initializing != 0 && strcmp(G.USERPASS,"1d8b27b21efabcd96571cd56f91a40fb9aa4cc623d273c63bf9223dc6f8cd81f") == 0 )
{
//fprintf(stderr,".");
sleep(3);
}
if ( LP_mainloop_iter(ctx,myipaddr,mypeer,pubsock,pushaddr,myport) != 0 )
if ( LP_mainloop_iter(ctx,myipaddr,mypeer,LP_mypubsock) != 0 )
nonz++;
if ( didremote == 0 && LP_cmdcount > 0 )
{
didremote = 1;
uint16_t myport2 = RPC_port-1;
printf("start remote port\n");
if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)stats_rpcloop,(void *)&myport2) != 0 )
{
printf("error launching stats rpcloop for port.%u\n",myport);
exit(-1);
}
}
if ( nonz == 0 )
usleep(1000);
else if ( IAMLP == 0 )
usleep(1000);
}
#endif
printf("marketmaker exiting in 5 seconds\n");
sleep(5);
exit(0);
}
#ifdef FROM_JS
@ -1429,7 +1460,7 @@ void LP_fromjs_iter()
//LP_pubkeys_query();
//LP_utxosQ_process();
//LP_nanomsg_recvs(ctx);
LP_mainloop_iter(ctx,LP_myipaddr,0,LP_mypubsock,LP_publicaddr,LP_RPCPORT);
LP_mainloop_iter(ctx,LP_myipaddr,0,LP_mypubsock);
//queue_loop(0);
if ( 0 ) // 10 seconds
{

23
iguana/exchanges/LP_network.c

@ -156,7 +156,7 @@ void _LP_sendqueueadd(uint32_t crc32,int32_t sock,uint8_t *msg,int32_t msglen,in
memcpy(ptr->msg,msg,msglen); // sizeof(bits256) at the end all zeroes
DL_APPEND(LP_Q,ptr);
LP_Qenqueued++;
//printf("Q.%p: peerind.%d msglen.%d\n",ptr,peerind,msglen);
//printf("Q.%p: peerind.%d msglen.%d sock.%d\n",ptr,peerind,msglen,sock);
}
uint32_t _LP_magic_check(bits256 hash,bits256 magic)
@ -213,7 +213,7 @@ int32_t LP_magic_check(uint8_t *msg,int32_t recvlen,char *remoteaddr)
int32_t LP_crc32find(int32_t *duplicatep,int32_t ind,uint32_t crc32)
{
static uint32_t crcs[4096]; static unsigned long dup,total;
static uint32_t crcs[16384]; static unsigned long dup,total;
int32_t i;
*duplicatep = 0;
if ( ind < 0 )
@ -304,10 +304,11 @@ void LP_broadcast_finish(int32_t pubsock,char *base,char *rel,uint8_t *msg,cJSON
msglen = (int32_t)strlen((char *)msg) + 1;
if ( crc32 == 0 )
crc32 = calc_crc32(0,&msg[2],msglen - 2);
//printf("crc32.%x IAMLP.%d pubsock.%d\n",crc32,G.LP_IAMLP,pubsock);
#ifdef FROM_MARKETMAKER
if ( G.LP_IAMLP == 0 )
if ( G.LP_IAMLP == 0 || pubsock < 0 )
#else
if ( IAMLP == 0 )
if ( IAMLP == 0 || pubsock < 0 )
#endif
{
free(msg);
@ -320,7 +321,13 @@ void LP_broadcast_finish(int32_t pubsock,char *base,char *rel,uint8_t *msg,cJSON
msg = (void *)jprint(argjson,0);
msglen = (int32_t)strlen((char *)msg) + 1;
LP_queuesend(crc32,-1,base,rel,msg,msglen);
} else LP_queuesend(crc32,pubsock,base,rel,msg,msglen);
if ( pubsock >= 0 )
LP_queuesend(crc32,pubsock,base,rel,msg,msglen);
}
else
{
LP_queuesend(crc32,pubsock,base,rel,msg,msglen);
}
free(msg);
}
@ -410,8 +417,8 @@ void LP_psockloop(void *_ptr) // printouts seem to be needed for forwarding to w
static struct nn_pollfd *pfds;
int32_t i,n,nonz,iter,retval,sentbytes,size=0,sendsock = -1; uint32_t now; struct psock *ptr=0; void *buf=0; char keepalive[512];
strcpy(LP_psockloop_stats.name,"LP_psockloop");
LP_psockloop_stats.threshold = 200.;
while ( 1 )
LP_psockloop_stats.threshold = 1000.;
while ( LP_STOP_RECEIVED == 0 )
{
LP_millistats_update(&LP_psockloop_stats);
now = (uint32_t)time(NULL);
@ -733,7 +740,7 @@ int32_t LP_initpublicaddr(void *ctx,uint16_t *mypullportp,char *publicaddr,char
*mypullportp = 0;
if ( ispaired == 0 )
{
strcpy(publicaddr,"127.0.0.1");
sprintf(publicaddr,"127.0.0.1:%u",mypullport);
return(-1);
}
while ( *mypullportp == 0 )

16
iguana/exchanges/LP_ordermatch.c

@ -481,11 +481,9 @@ int32_t LP_connectstartbob(void *ctx,int32_t pubsock,char *base,char *rel,double
bits256 zero;
memset(zero.bytes,0,sizeof(zero));
LP_reserved_msg(1,base,rel,zero,jprint(reqjson,0));
//if ( IAMLP == 0 )
{
sleep(1);
LP_reserved_msg(1,qp->srccoin,qp->destcoin,qp->desthash,jprint(reqjson,0));
}
sleep(1);
LP_reserved_msg(1,qp->srccoin,qp->destcoin,qp->desthash,jprint(reqjson,0));
sleep(1);
LP_reserved_msg(0,base,rel,zero,jprint(reqjson,0));
free_json(reqjson);
LP_importaddress(qp->destcoin,qp->destaddr);
@ -910,12 +908,12 @@ struct LP_quoteinfo *LP_trades_gotrequest(void *ctx,struct LP_quoteinfo *qp,stru
bits256 zero;
memset(zero.bytes,0,sizeof(zero));
LP_reserved_msg(1,qp->srccoin,qp->destcoin,zero,jprint(reqjson,0));
//if ( IAMLP == 0 )
if ( 0 )//if ( IAMLP == 0 )
{
sleep(1);
LP_reserved_msg(1,qp->srccoin,qp->destcoin,qp->desthash,jprint(reqjson,0));
}
LP_reserved_msg(0,qp->srccoin,qp->destcoin,zero,jprint(reqjson,0));
//LP_reserved_msg(0,qp->srccoin,qp->destcoin,zero,jprint(reqjson,0));
free_json(reqjson);
return(qp);
} else printf("request processing selected ineligible utxos?\n");
@ -1016,7 +1014,7 @@ void LP_tradesloop(void *ctx)
strcpy(LP_tradesloop_stats.name,"LP_tradesloop");
LP_tradesloop_stats.threshold = 10000;
sleep(5);
while ( 1 )
while ( LP_STOP_RECEIVED == 0 )
{
LP_millistats_update(&LP_tradesloop_stats);
nonz = 0;
@ -1169,7 +1167,7 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson,
LP_quoteparse(&Q,argjson);
LP_requestinit(&Q.R,Q.srchash,Q.desthash,Q.srccoin,Q.satoshis-Q.txfee,Q.destcoin,Q.destsatoshis-Q.desttxfee,Q.timestamp,Q.quotetime,DEXselector);
LP_tradecommand_log(argjson);
printf("%-4d (%-10u %10u) %12s id.%22llu %5s/%-5s %12.8f -> %11.8f price %11.8f | RT.%d %d\n",(uint32_t)time(NULL) % 3600,Q.R.requestid,Q.R.quoteid,method,(long long)Q.aliceid,Q.srccoin,Q.destcoin,dstr(Q.satoshis),dstr(Q.destsatoshis),(double)Q.destsatoshis/Q.satoshis,LP_RTcount,LP_swapscount);
printf("%-4d (%-10u %10u) %12s id.%-20llu %5s/%-5s %12.8f -> %12.8f (%11.8f) | RT.%d %d n%d\n",(uint32_t)time(NULL) % 3600,Q.R.requestid,Q.R.quoteid,method,(long long)Q.aliceid,Q.srccoin,Q.destcoin,dstr(Q.satoshis),dstr(Q.destsatoshis),(double)Q.destsatoshis/Q.satoshis,LP_RTcount,LP_swapscount,G.netid);
//LP_autoprices_update(method,Q.srccoin,dstr(Q.satoshis),Q.destcoin,dstr(Q.destsatoshis));
retval = 1;
aliceid = j64bits(argjson,"aliceid");

55
iguana/exchanges/LP_peers.c

@ -32,7 +32,8 @@ cJSON *LP_peerjson(struct LP_peerinfo *peer)
{
cJSON *item = cJSON_CreateObject();
jaddstr(item,"isLP",peer->ipaddr);
jaddnum(item,"port",peer->port);
jaddnum(item,"remoteport",peer->port-1);
jaddnum(item,"netid",peer->netid);
if ( strcmp(peer->ipaddr,LP_myipaddr) == 0 )
{
jaddnum(item,"session",G.LP_sessionid);
@ -55,7 +56,7 @@ char *LP_peers()
return(jprint(peersjson,1));
}
struct LP_peerinfo *LP_addpeer(struct LP_peerinfo *mypeer,int32_t mypubsock,char *ipaddr,uint16_t port,uint16_t pushport,uint16_t subport,int32_t isLP,uint32_t sessionid)
struct LP_peerinfo *LP_addpeer(struct LP_peerinfo *mypeer,int32_t mypubsock,char *ipaddr,uint16_t port,uint16_t pushport,uint16_t subport,int32_t isLP,uint32_t sessionid,uint16_t netid)
{
uint32_t ipbits; int32_t valid,pushsock,subsock,timeout; char checkip[64],pushaddr[64],subaddr[64]; struct LP_peerinfo *peer = 0;
#ifdef LP_STRICTPEERS
@ -68,8 +69,16 @@ struct LP_peerinfo *LP_addpeer(struct LP_peerinfo *mypeer,int32_t mypubsock,char
{
if ( (peer= LP_peerfind(ipbits,port)) != 0 )
{
if ( isLP != 0 )
peer->isLP = isLP;
if ( peer->netid != netid )
{
printf("netid mismatch for %s? %d vs %d\n",peer->ipaddr,peer->netid,G.netid);
return(0);
}
if ( isLP != 0 && peer->isLP == 0 )
{
if ( (peer->isLP= isLP) != 0 )
LP_numactive_LP++;
}
/*if ( numpeers > peer->numpeers )
peer->numpeers = numpeers;
if ( numutxos > peer->numutxos )
@ -77,7 +86,7 @@ struct LP_peerinfo *LP_addpeer(struct LP_peerinfo *mypeer,int32_t mypubsock,char
if ( peer->sessionid == 0 )
peer->sessionid = sessionid;*/
}
else
else if ( IAMLP != 0 || LP_numactive_LP < 3 )
{
//printf("addpeer (%s:%u) pushport.%u subport.%u\n",ipaddr,port,pushport,subport);
peer = calloc(1,sizeof(*peer));
@ -86,9 +95,11 @@ struct LP_peerinfo *LP_addpeer(struct LP_peerinfo *mypeer,int32_t mypubsock,char
else peer->sessionid = sessionid;
peer->pushsock = peer->subsock = pushsock = subsock = -1;
strcpy(peer->ipaddr,ipaddr);
peer->netid = netid;
//peer->profitmargin = profitmargin;
peer->ipbits = ipbits;
peer->isLP = isLP;
if ( (peer->isLP= isLP) != 0 )
LP_numactive_LP++;
peer->port = port;
peer->ip_port = ((uint64_t)port << 32) | ipbits;
if ( pushport != 0 && subport != 0 && (pushsock= nn_socket(AF_SP,NN_PUSH)) >= 0 )
@ -124,7 +135,7 @@ struct LP_peerinfo *LP_addpeer(struct LP_peerinfo *mypeer,int32_t mypubsock,char
if ( valid > 0 )
{
peer->subsock = subsock;
printf("connected to sub.(%s) subsock.%d valid.%d\n",subaddr,peer->subsock,valid);
printf("connected to sub.(%s) subsock.%d valid.%d numactive.%d\n",subaddr,peer->subsock,valid,LP_numactive_LP);
}
else
{
@ -140,10 +151,10 @@ struct LP_peerinfo *LP_addpeer(struct LP_peerinfo *mypeer,int32_t mypubsock,char
pushsock = -1;
printf("error connecting to push.(%s)\n",pushaddr);
}
} else printf("%s pushport.%u subport.%u pushsock.%d\n",ipaddr,pushport,subport,pushsock);
} else printf("%s pushport.%u subport.%u pushsock.%d isLP.%d\n",ipaddr,pushport,subport,pushsock,isLP);
if ( peer->pushsock >= 0 && peer->subsock >= 0 )
{
//printf("add peer %s\n",peer->ipaddr);
//printf("add peer %s isLP.%d\n",peer->ipaddr,peer->isLP);
portable_mutex_lock(&LP_peermutex);
HASH_ADD(hh,LP_peerinfos,ip_port,sizeof(peer->ip_port),peer);
if ( mypeer != 0 )
@ -152,9 +163,9 @@ struct LP_peerinfo *LP_addpeer(struct LP_peerinfo *mypeer,int32_t mypubsock,char
printf("_LPaddpeer %s -> numpeers.%d mypubsock.%d other.(%d)\n",ipaddr,mypeer->numpeers,mypubsock,isLP);
} else peer->numpeers = 1; // will become mypeer
portable_mutex_unlock(&LP_peermutex);
if ( IAMLP != 0 && mypubsock >= 0 )
/*if ( IAMLP != 0 && mypubsock >= 0 )
{
struct iguana_info *coin,*ctmp; char busaddr[64]; //
//struct iguana_info *coin,*ctmp; char busaddr[64]; //
//memset(zero.bytes,0,sizeof(zero));
//LP_send(mypubsock,msg,(int32_t)strlen(msg)+1,1);
//LP_reserved_msg(0,"","",zero,jprint(LP_peerjson(peer),1));
@ -169,14 +180,30 @@ struct LP_peerinfo *LP_addpeer(struct LP_peerinfo *mypeer,int32_t mypubsock,char
}
}
}
}
}*/
} else printf("%s invalid pushsock.%d or subsock.%d\n",peer->ipaddr,peer->pushsock,peer->subsock);
}
} else printf("LP_addpeer: checkip.(%s) vs (%s)\n",checkip,ipaddr);
return(peer);
}
int32_t LP_coinbus(uint16_t coin_busport)
void LP_closepeers()
{
struct LP_peerinfo *peer,*tmp;
HASH_ITER(hh,LP_peerinfos,peer,tmp)
{
portable_mutex_lock(&LP_peermutex);
HASH_DELETE(hh,LP_peerinfos,peer);
portable_mutex_unlock(&LP_peermutex);
if ( peer->pushsock >= 0 )
nn_close(peer->pushsock), peer->pushsock = -1;
if ( peer->subsock >= 0 )
nn_close(peer->subsock), peer->subsock = -1;
// free(peer); a small memleak to avoid freein inflight requests
}
}
/*int32_t LP_coinbus(uint16_t coin_busport)
{
struct LP_peerinfo *peer,*tmp; char busaddr[64]; int32_t timeout,bussock = -1;
return(-1);
@ -204,7 +231,7 @@ int32_t LP_coinbus(uint16_t coin_busport)
}
}
return(bussock);
}
}*/
void LP_peer_recv(char *ipaddr,int32_t ismine)
{

44
iguana/exchanges/LP_portfolio.c

@ -300,7 +300,7 @@ void LP_autopriceset(int32_t ind,void *ctx,int32_t dir,struct LP_priceinfo *base
{
if ( LP_autorefs[ind].lastask < SMALLVAL )
LP_autorefs[ind].lastask = newprice;
else LP_autorefs[ind].lastask = (LP_autorefs[ind].lastask * 0.9) + (0.1 *newprice);
else LP_autorefs[ind].lastask = (LP_autorefs[ind].lastask * 0.99) + (0.01 *newprice);
newprice = LP_autorefs[ind].lastask;
//printf("autopriceset %s/%s <- %.8f %.8f (%.8f %.8f)\n",basepp->symbol,relpp->symbol,price,newprice,LP_autorefs[ind].lastbid,LP_autorefs[ind].lastask);
}
@ -547,36 +547,6 @@ void LP_autoprice_iter(void *ctx,struct LP_priceinfo *btcpp)
LP_pricepings(ctx,LP_myipaddr,LP_mypubsock,base,rel,askprice);
//printf("price %.8f -> %.8f %.8f\n",price,bidprice,askprice);
}
/*if ( LP_autorefs[i].fundbid[0] != 0 && (price= jdouble(fundjson,LP_autorefs[i].fundbid)) > SMALLVAL )
{
printf("%s/%s %s %.8f -> %.8f or %.8f",base,rel,LP_autorefs[i].fundbid,price,(1. / (price * (1. + buymargin))),(1. / (price * (1. - buymargin))));
if ( tickerjson != 0 && LP_autorefs[i].count == 0 )
price = LP_tickered_price(0,base,rel,price,tickerjson);
newprice = (1. / (price * (1. + buymargin)));
//if ( LP_autorefs[i].lastbid < SMALLVAL )
LP_autorefs[i].lastbid = newprice;
//else LP_autorefs[i].lastbid = (LP_autorefs[i].lastbid * 0.9) + (0.1 *newprice);
newprice = LP_autorefs[i].lastbid;
LP_mypriceset(&changed,rel,base,newprice);
LP_pricepings(ctx,LP_myipaddr,LP_mypubsock,rel,base,newprice);
printf("fundbid %.8f margin %.8f newprice %.8f\n",price,buymargin,newprice);
}
if ( LP_autorefs[i].fundask[0] != 0 && (price= jdouble(fundjson,LP_autorefs[i].fundask)) > SMALLVAL )
{
printf("%s/%s %s %.8f -> ",base,rel,LP_autorefs[i].fundask,price);
if ( tickerjson != 0 && LP_autorefs[i].count == 0 )
price = LP_tickered_price(1,base,rel,price,tickerjson);
newprice = (price * (1. + sellmargin));
//if ( LP_autorefs[i].lastask < SMALLVAL )
LP_autorefs[i].lastask = newprice;
//else LP_autorefs[i].lastask = (LP_autorefs[i].lastask * 0.9) + (0.1 *newprice);
if ( LP_autorefs[i].lastbid < SMALLVAL || LP_autorefs[i].lastask >= LP_autorefs[i].lastbid/(1. + sellmargin) )
newprice = LP_autorefs[i].lastask;
else newprice = LP_autorefs[i].lastbid * (1. + sellmargin);
LP_mypriceset(&changed,base,rel,newprice);
LP_pricepings(ctx,LP_myipaddr,LP_mypubsock,base,rel,newprice);
printf("fundask %.8f margin %.8f newprice %.8f\n",price,sellmargin,newprice);
}*/
LP_autorefs[i].count++;
}
free_json(fundjson);
@ -596,18 +566,18 @@ void LP_autoprice_iter(void *ctx,struct LP_priceinfo *btcpp)
else continue;
if ( factor > 0. )
price = (price * factor) + offset;
newprice = (price * (1. - buymargin));
newprice = (price * (1. + buymargin));
if ( LP_autorefs[i].lastbid < SMALLVAL )
LP_autorefs[i].lastbid = newprice;
else LP_autorefs[i].lastbid = (LP_autorefs[i].lastbid * 0.9) + (0.1 *newprice);
else LP_autorefs[i].lastbid = (LP_autorefs[i].lastbid * 0.99) + (0.01 * newprice);
newprice = LP_autorefs[i].lastbid;
LP_mypriceset(&changed,rel,base,newprice);
LP_pricepings(ctx,LP_myipaddr,LP_mypubsock,rel,base,newprice);
//printf("%s/%s price %.8f margin %.8f/%.8f newprice %.8f %.8f\n",base,rel,price,buymargin,sellmargin,newprice,(1. / newprice) * (1. + sellmargin));
newprice = (1. / newprice) * (1. + sellmargin);
newprice = (1. / price) * (1. + sellmargin);
if ( LP_autorefs[i].lastask < SMALLVAL )
LP_autorefs[i].lastask = newprice;
else LP_autorefs[i].lastask = (LP_autorefs[i].lastask * 0.9) + (0.1 *newprice);
else LP_autorefs[i].lastask = (LP_autorefs[i].lastask * 0.99) + (0.01 * newprice);
newprice = LP_autorefs[i].lastask;
LP_mypriceset(&changed,base,rel,newprice);
LP_pricepings(ctx,LP_myipaddr,LP_mypubsock,base,rel,newprice);
@ -681,6 +651,8 @@ int32_t LP_autoprice(void *ctx,char *base,char *rel,cJSON *argjson)
fixedprice = jdouble(argjson,"fixed");
basepp->fixedprices[relpp->ind] = fixedprice;
basepp->minprices[relpp->ind] = minprice;
if ( jobj(argjson,"maxprice") != 0 )
relpp->minprices[basepp->ind] = 1. / jdouble(argjson,"maxprice");
basepp->buymargins[relpp->ind] = buymargin;
basepp->sellmargins[relpp->ind] = sellmargin;
basepp->offsets[relpp->ind] = offset;
@ -869,7 +841,7 @@ void prices_loop(void *ctx)
char *retstr; cJSON *retjson,*array; char *buycoin,*sellcoin; struct iguana_info *buy,*sell; uint32_t requestid,quoteid; int32_t i,n,m; struct LP_portfoliotrade trades[256]; struct LP_priceinfo *btcpp;
strcpy(prices_loop_stats.name,"prices_loop");
prices_loop_stats.threshold = 191000.;
while ( 1 )
while ( LP_STOP_RECEIVED == 0 )
{
//printf("prices loop autoprices.%d autorefs.%d\n",LP_autoprices,num_LP_autorefs);
LP_millistats_update(&prices_loop_stats);

16
iguana/exchanges/LP_prices.c

@ -511,7 +511,7 @@ char *LP_myprices()
int32_t LP_mypriceset(int32_t *changedp,char *base,char *rel,double price)
{
struct LP_priceinfo *basepp,*relpp; struct LP_pubkey_info *pubp;
struct LP_priceinfo *basepp,*relpp; struct LP_pubkey_info *pubp; double minprice,maxprice;
*changedp = 0;
//if ( strcmp("DEX",base) == 0 || strcmp("DEX",rel) == 0 )
// printf("%s/%s setprice %.8f\n",base,rel,price);
@ -529,6 +529,19 @@ int32_t LP_mypriceset(int32_t *changedp,char *base,char *rel,double price)
relpp->offsets[basepp->ind] = 0.;
relpp->factors[basepp->ind] = 0.;
}
else if ( (minprice= basepp->minprices[relpp->ind]) > SMALLVAL && price < minprice )
{
printf("%s/%s price %.8f less than minprice %.8f\n",base,rel,price,minprice);
price = minprice;
}
else if ( (maxprice= relpp->minprices[basepp->ind]) > SMALLVAL )
{
if ( price > (1. / maxprice) )
{
printf("%s/%s price %.8f less than maxprice %.8f, more than %.8f\n",base,rel,price,maxprice,1./maxprice);
price = (1. / maxprice);
}
}
/*else if ( basepp->myprices[relpp->ind] > SMALLVAL )
{
price = (basepp->myprices[relpp->ind] * 0.9) + (0.1 * price);
@ -936,6 +949,7 @@ char *LP_orderbook(char *base,char *rel,int32_t duration)
jaddstr(retjson,"base",base);
jaddstr(retjson,"rel",rel);
jaddnum(retjson,"timestamp",now);
jaddnum(retjson,"netid",G.netid);
if ( bids != 0 )
free(bids);
if ( asks != 0 )

240
iguana/exchanges/LP_privkey.c

@ -206,27 +206,48 @@ static const char base58_chars[] = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijk
int32_t LP_wifstr_valid(char *symbol,char *wifstr)
{
bits256 privkey,cmpkey; uint8_t wiftype; char cmpstr[128],cmpstr2[128]; int32_t i;
bits256 privkey,cmpkey; uint8_t wiftype; char cmpstr[128],cmpstr2[128]; int32_t i,len,n,a,A;
if ( (len= (int32_t)strlen(wifstr)) < 50 || len > 54 )
{
//printf("len.%d is wrong for wif %s\n",len,wifstr);
return(0);
}
memset(privkey.bytes,0,sizeof(privkey));
memset(cmpkey.bytes,0,sizeof(cmpkey));
for (i=0; wifstr[i]!=0; i++)
for (i=n=a=A=0; wifstr[i]!=0; i++)
{
if ( strchr(base58_chars,wifstr[i]) == 0 )
return(0);
if ( wifstr[i] >= '1' && wifstr[i] <= '9' )
n++;
else if ( wifstr[i] >= 'A' && wifstr[i] <= 'Z' )
A++;
else if ( wifstr[i] >= 'a' && wifstr[i] <= 'z' )
a++;
}
if ( n == 0 || A == 0 || a == 0 )
return(0);
if ( A > 5*a || a > 5*A || a > n*20 || A > n*20 ) // unlikely it is a real wif
{
printf("reject wif %s due to n.%d a.%d A.%d (%d %d %d %d)\n",wifstr,n,a,A,A > 5*a,a < 5*A,a > n*20,A > n*20);
return(0);
}
bitcoin_wif2priv(symbol,0,&wiftype,&privkey,wifstr);
bitcoin_priv2wif(symbol,0,cmpstr,privkey,wiftype);
if ( strcmp(cmpstr,wifstr) == 0 )
{
printf("%s is valid wif\n",wifstr);
//printf("%s is valid wif\n",wifstr);
return(1);
}
else if ( bits256_nonz(privkey) != 0 )
{
bitcoin_wif2priv(symbol,0,&wiftype,&cmpkey,cmpstr);
bitcoin_priv2wiflong(symbol,0,cmpstr2,privkey,wiftype);
char str[65],str2[65]; printf("mismatched wifstr %s -> %s -> %s %s %s\n",wifstr,bits256_str(str,privkey),cmpstr,bits256_str(str2,cmpkey),cmpstr2);
if ( bits256_cmp(privkey,cmpkey) == 0 )
return(1);
char str[65],str2[65]; printf("%s mismatched wifstr %s -> %s -> %s %s %s\n",symbol,wifstr,bits256_str(str,privkey),cmpstr,bits256_str(str2,cmpkey),cmpstr2);
}
char str[65]; printf("%s is not a wif, privkey.%s\n",wifstr,bits256_str(str,privkey));
return(0);
}
@ -261,8 +282,12 @@ bits256 LP_privkeycalc(void *ctx,uint8_t *pubkey33,bits256 *pubkeyp,struct iguan
bitcoin_priv2wif(coin->symbol,coin->wiftaddr,tmpstr,privkey,tmptype);
if ( strcmp(tmpstr,wifstr) != 0 )
{
printf("error reproducing the wifstr, likely edge case like non-supported uncompressed pubkey\n");
exit(1);
bitcoin_wif2priv(coin->symbol,coin->wiftaddr,&tmptype,&tmpkey,tmpstr);
if ( bits256_cmp(tmpkey,privkey) != 0 )
{
char str[65]; printf("%s error reproducing the wifstr, likely edge case like non-supported uncompressed pubkey privkey.%s\n",coin->symbol,bits256_str(str,privkey));
exit(1);
}
}
tmpkey = privkey;
nxtaddr = conv_NXTpassword(tmpkey.bytes,pubkeyp->bytes,0,0);
@ -345,23 +370,43 @@ void LP_privkey_updates(void *ctx,int32_t pubsock,char *passphrase)
}
}
int32_t LP_passphrase_init(char *passphrase,char *gui)
int32_t LP_passphrase_init(char *passphrase,char *gui,uint16_t netid,char *seednode)
{
static void *ctx; int32_t counter; //iambob,; struct LP_utxoinfo *utxo,*tmp;
static void *ctx; struct iguana_info *coin,*tmp; int32_t counter;
if ( ctx == 0 )
ctx = bitcoin_ctx();
if ( G.LP_pendingswaps != 0 )
return(-1);
if ( netid != G.netid )
{
if ( IAMLP != 0 )
{
printf("sorry, LP nodes can only set netid during startup\n");
return(-1);
}
else
{
printf(">>>>>>>>>>>>> netid.%d vs G.netid %d\n",netid,G.netid);
LP_closepeers();
LP_initpeers(LP_mypubsock,LP_mypeer,LP_myipaddr,RPC_port,netid,seednode);
}
}
G.initializing = 1;
if ( gui == 0 )
gui = "cli";
counter = G.USERPASS_COUNTER;
HASH_ITER(hh,LP_coins,coin,tmp)
{
coin->importedprivkey = 0;
}
while ( G.waiting == 0 )
{
printf("waiting for G.waiting\n");
sleep(5);
}
memset(&G,0,sizeof(G));
G.netid = netid;
safecopy(G.seednode,seednode,sizeof(G.seednode));
vcalc_sha256(0,G.LP_passhash.bytes,(uint8_t *)passphrase,(int32_t)strlen(passphrase));
LP_privkey_updates(ctx,LP_mypubsock,passphrase);
init_hexbytes_noT(G.LP_myrmd160str,G.LP_myrmd160,20);
@ -395,10 +440,59 @@ void LP_privkey_tests()
}
#define JPG_ENCRYPTED_MAXSIZE 32768
int32_t JPG_encrypt(uint16_t ind,uint8_t encoded[JPG_ENCRYPTED_MAXSIZE],uint8_t *msg,int32_t msglen,bits256 privkey)
{
bits256 pubkey; int32_t len = 2; uint8_t space[JPG_ENCRYPTED_MAXSIZE],*nonce,*cipher;
pubkey = acct777_pubkey(privkey);
encoded[len++] = ind & 0xff;
encoded[len++] = (ind >> 8) & 0xff;
nonce = &encoded[len];
OS_randombytes(nonce,crypto_box_NONCEBYTES);
cipher = &encoded[len + crypto_box_NONCEBYTES];
msglen = _SuperNET_cipher(nonce,&encoded[len + crypto_box_NONCEBYTES],msg,msglen,pubkey,privkey,space);
msglen += crypto_box_NONCEBYTES;
msg = encoded;
msglen += len;
encoded[0] = msglen & 0xff;
encoded[1] = (msglen >> 8) & 0xff;
int32_t i; for (i=0; i<msglen; i++)
printf("%02x",encoded[i]);
printf(" encoded.%d\n",msglen);
return(msglen);
}
uint8_t *JPG_decrypt(uint16_t *indp,int32_t *recvlenp,uint8_t space[JPG_ENCRYPTED_MAXSIZE + crypto_box_ZEROBYTES],uint8_t *encoded,bits256 privkey)
{
bits256 pubkey; uint8_t *extracted=0,*nonce,*cipher; uint16_t msglen,ind; int32_t cipherlen,len = 4;
*recvlenp = 0;
*indp = -1;
pubkey = acct777_pubkey(privkey);
msglen = ((int32_t)encoded[1] << 8) | encoded[0];
ind = ((int32_t)encoded[3] << 8) | encoded[2];
nonce = &encoded[len];
cipher = &encoded[len + crypto_box_NONCEBYTES];
cipherlen = msglen - (len + crypto_box_NONCEBYTES);
if ( cipherlen > 0 && cipherlen <= JPG_ENCRYPTED_MAXSIZE + crypto_box_ZEROBYTES )
{
if ( (extracted= _SuperNET_decipher(nonce,cipher,space,cipherlen,pubkey,privkey)) != 0 )
{
int32_t i; for (i=0; i<msglen; i++)
printf("%02x",encoded[i]);
printf(" restored\n");
msglen = (cipherlen - crypto_box_ZEROBYTES);
*recvlenp = msglen;
*indp = ind;
}
} //else printf("cipher.%d too big for %d\n",cipherlen,JPG_ENCRYPTED_MAXSIZE + crypto_box_ZEROBYTES);
return(extracted);
}
// from https://github.com/owencm/C-Steganography-Framework
#include "../../crypto777/jpeg/cdjpeg.h" // Common decls for compressing and decompressing jpegs
int32_t LP_jpg_process(int32_t *capacityp,char *inputfname,char *outputfname,uint8_t *decoded,uint8_t *data,int32_t required,int32_t power2,char *passphrase)
int32_t LP_jpg_process(int32_t *capacityp,char *inputfname,char *outputfname,uint8_t *decoded,uint8_t *origdata,int32_t origrequired,int32_t power2,char *password,uint16_t *indp)
{
struct jpeg_decompress_struct inputinfo;
struct jpeg_compress_struct outputinfo;
@ -407,19 +501,47 @@ int32_t LP_jpg_process(int32_t *capacityp,char *inputfname,char *outputfname,uin
JDIMENSION i,compnum,rownum,blocknum;
JBLOCKARRAY coef_buffers[MAX_COMPONENTS];
JBLOCKARRAY row_ptrs[MAX_COMPONENTS];
FILE *input_file,*output_file; int32_t val,modified,emit,totalrows,limit;
if ( power2 < 0 || power2 > 16 )
power2 = 4;
bits256 privkey; FILE *input_file,*output_file; int32_t recvlen,msglen,val,modified,emit,totalrows,limit,required; uint16_t checkind; uint8_t *decrypted,*space,*data=0;
if ((input_file = fopen(inputfname, READ_BINARY)) == NULL)
{
fprintf(stderr, "Can't open %s\n", inputfname);
//exit(EXIT_FAILURE);
return(-1);
}
required = origrequired;
memset(privkey.bytes,0,sizeof(privkey));
if ( password != 0 && password[0] != 0 )
{
if ( required/8 > JPG_ENCRYPTED_MAXSIZE-60 )
return(-1);
data = calloc(1,required/8+512);
vcalc_sha256(0,privkey.bytes,(uint8_t *)password,(int32_t)strlen(password));
if ( origdata != 0 )
{
msglen = JPG_encrypt(*indp,data,origdata,required/8,privkey);
required = msglen * 8;
{
space = calloc(1,JPG_ENCRYPTED_MAXSIZE);
if ( (decrypted= JPG_decrypt(&checkind,&recvlen,space,data,privkey)) == 0 || recvlen != origrequired/8 || checkind != *indp || memcmp(decrypted,origdata,origrequired/8) != 0 )
printf("A decryption error: checkind.%d vs %d, recvlen.%d vs %d, decrypted.%p\n",checkind,*indp,recvlen,origrequired/8,decrypted);
else
{
for (i=0; i<recvlen; i++)
printf("%02x",decrypted[i]);
printf(" VERIFIED decryption.%d ind.%d msglen.%d required.%d\n",recvlen,*indp,msglen,required);
}
free(space);
}
} else required += 60 * 8;
} else data = origdata;
if ( power2 < 0 || power2 > 30 )
power2 = 7;
limit = 1;
while ( power2 > 0 )
{
limit <<= 1;
power2--;
}
if ((input_file = fopen(inputfname, READ_BINARY)) == NULL) {
fprintf(stderr, "Can't open %s\n", inputfname);
exit(EXIT_FAILURE);
}
// Initialize the JPEG compression and decompression objects with default error handling
inputinfo.err = jpeg_std_error(&jerr);
jpeg_create_decompress(&inputinfo);
@ -453,10 +575,14 @@ int32_t LP_jpg_process(int32_t *capacityp,char *inputfname,char *outputfname,uin
for (i=0; i<DCTSIZE2; i++)
{
val = row_ptrs[compnum][0][blocknum][i];
if ( val < -power2 || val > power2 )
if ( val < -limit || val >= limit )
{
if ( decoded != 0 && (val & 1) != 0 && *capacityp < required )
decoded[*capacityp >> 3] |= (1 << (*capacityp & 7));
if ( (*capacityp) < required )
{
if ( (val & 1) != 0 )
SETBIT(decoded,(*capacityp));
//printf("%c",(val&1)!=0?'1':'0');
}
(*capacityp)++;
}
coef_buffers[compnum][rownum][blocknum][i] = val;
@ -464,12 +590,28 @@ int32_t LP_jpg_process(int32_t *capacityp,char *inputfname,char *outputfname,uin
}
}
}
printf("capacity %d required.%d\n",*capacityp,required);
if ( password != 0 && password[0] != 0 )
{
space = calloc(1,JPG_ENCRYPTED_MAXSIZE);
if ( (decrypted= JPG_decrypt(indp,&recvlen,space,decoded,privkey)) != 0 && recvlen == origrequired/8 )
{
for (i=0; i<recvlen; i++)
{
//printf("%02x",decrypted[i]);
decoded[i] = decrypted[i];
}
//printf(" decrypted.%d ind.%d\n",recvlen,*indp);
}
free(space);
}
//printf(" capacity %d required.%d power2.%d limit.%d\n",*capacityp,required,power2,limit);
if ( *capacityp > required && outputfname != 0 && outputfname[0] != 0 )
{
if ((output_file = fopen(outputfname, WRITE_BINARY)) == NULL) {
fprintf(stderr, "Can't open %s\n", outputfname);
exit(EXIT_FAILURE);
if ( data != origdata )
free(data);
return(-1);
}
outputinfo.err = jpeg_std_error(&jerr);
jpeg_create_compress(&outputinfo);
@ -483,25 +625,25 @@ int32_t LP_jpg_process(int32_t *capacityp,char *inputfname,char *outputfname,uin
for (blocknum=0; blocknum<width_in_blocks[compnum]; blocknum++)
{
//printf("\n\nComponent: %i, Row:%i, Column: %i\n", compnum, rownum, blocknum);
for (i=0; i<DCTSIZE2; i++)
for (i=0; i<DCTSIZE2&&emit<required; i++)
{
val = coef_buffers[compnum][rownum][blocknum][i];
if ( val < -power2 || val > power2 )
if ( val < -limit || val >= limit )
{
val &= ~1;
if ( (data[emit >> 3] & (1 << (emit&7))) != 0 )
if (GETBIT(data,emit) != 0 )//|| (emit >= required && (rand() & 1) != 0) )
val |= 1;
//printf("%c",(val&1)!=0?'1':'0');
coef_buffers[compnum][rownum][blocknum][i] = val;
emit++;
}
coef_buffers[compnum][rownum][blocknum][i] = val;
//printf("%i,", coef_buffers[compnum][rownum][blocknum][i]);
}
}
}
}
//printf("\n\n");
/* Output the new DCT coeffs to a JPEG file */
//printf(" emit.%d\n",emit);
// Output the new DCT coeffs to a JPEG file
modified = 0;
for (compnum=0; compnum<num_components; compnum++)
{
@ -533,16 +675,17 @@ int32_t LP_jpg_process(int32_t *capacityp,char *inputfname,char *outputfname,uin
free(block_row_size);
free(width_in_blocks);
free(height_in_blocks);
if ( data != origdata )
free(data);
return(modified);
}
char *LP_jpg(char *srcfile,char *destfile,int32_t power2,char *passphrase,char *datastr,int32_t required)
char *LP_jpg(char *srcfile,char *destfile,int32_t power2,char *passphrase,char *datastr,int32_t required,uint16_t ind)
{
cJSON *retjson; int32_t len=0,modified,capacity; char *decodedstr; uint8_t *data=0,*decoded=0;
if ( srcfile != 0 && srcfile[0] != 0 )
{
retjson = cJSON_CreateObject();
jaddstr(retjson,"result","success");
if ( datastr != 0 && datastr[0] != 0 )
{
if ( (len= is_hexstr(datastr,0)) > 0 )
@ -551,23 +694,36 @@ char *LP_jpg(char *srcfile,char *destfile,int32_t power2,char *passphrase,char *
data = calloc(1,len);
decode_hex(data,len,datastr);
required = len * 8;
//int32_t i; for (i=0; i<required; i++)
// printf("%c",'0'+(GETBIT(data,i)!=0));
//printf(" datastr.%d %s\n",required,datastr);
}
}
if ( required > 0 )
decoded = calloc(1,len);
modified = LP_jpg_process(&capacity,srcfile,destfile,decoded,data,required,power2,passphrase);
jaddnum(retjson,"modifiedrows",modified);
if ( modified != 0 )
jaddstr(retjson,"outputfile",destfile);
jaddnum(retjson,"power2",power2);
jaddnum(retjson,"capacity",capacity);
jaddnum(retjson,"required",required);
decoded = calloc(1,len+required);
if ( (modified= LP_jpg_process(&capacity,srcfile,destfile,decoded,data,required,power2,passphrase,&ind)) < 0 )
jaddstr(retjson,"error","file not found");
else
{
jaddstr(retjson,"result","success");
jaddnum(retjson,"modifiedrows",modified);
if ( modified != 0 )
jaddstr(retjson,"outputfile",destfile);
jaddnum(retjson,"power2",power2);
jaddnum(retjson,"capacity",capacity);
jaddnum(retjson,"required",required);
jaddnum(retjson,"ind",ind);
}
if ( decoded != 0 )
{
decodedstr = calloc(1,len*2+1);
init_hexbytes_noT(decodedstr,decoded,len);
jaddstr(retjson,"decoded",decodedstr);
free(decodedstr);
if ( capacity > 0 )
{
//printf("len.%d required.%d capacity.%d\n",len,required,capacity);
decodedstr = calloc(1,(len+required)*2+1);
init_hexbytes_noT(decodedstr,decoded,required/8);
jaddstr(retjson,"decoded",decodedstr);
free(decodedstr);
}
free(decoded);
}
if ( data != 0 )

13
iguana/exchanges/LP_remember.c

@ -489,7 +489,7 @@ cJSON *LP_swap_json(struct LP_swap_remember *rswap)
item = cJSON_CreateObject();
if ( LP_swap_endcritical < LP_swap_critical )
{
jaddstr(item,"warning","swaps in critical section");
jaddstr(item,"warning","swaps in critical section, dont exit now");
jaddnum(item,"critical",LP_swap_critical);
jaddnum(item,"endcritical",LP_swap_endcritical);
}
@ -1044,7 +1044,7 @@ cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requesti
free_json(txoutobj), flag = 0;
else flag = -1, rswap.depositspent = deadtxid;
}
if ( flag == 0 )
//if ( flag == 0 )
{
if ( rswap.Dredeemlen != 0 )
redeemlen = rswap.Dredeemlen, memcpy(redeemscript,rswap.Dredeemscript,rswap.Dredeemlen);
@ -1119,7 +1119,7 @@ cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requesti
free_json(txoutobj), flag = 0;
else flag = -1, rswap.paymentspent = deadtxid;
}
if ( flag == 0 && time(NULL) > rswap.expiration+777 )
if ( time(NULL) > rswap.expiration+777 )
{
// bobreclaim
redeemlen = basilisk_swap_bobredeemscript(0,&secretstart,redeemscript,rswap.plocktime,rswap.pubA0,rswap.pubB0,rswap.pubB1,zero,rswap.privBn,rswap.secretAm,rswap.secretAm256,rswap.secretBn,rswap.secretBn256);
@ -1148,7 +1148,7 @@ cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requesti
free_json(txoutobj), flag = 0;
else flag = -1, rswap.depositspent = deadtxid;
}
if ( flag == 0 && (bits256_nonz(rswap.Apaymentspent) != 0 || time(NULL) > rswap.expiration+777) )
if ( bits256_nonz(rswap.Apaymentspent) != 0 || time(NULL) > rswap.expiration+777 )
{
printf("do the refund! paymentspent.%s now.%u vs expiration.%u\n",bits256_str(str,rswap.paymentspent),(uint32_t)time(NULL),rswap.expiration);
//if ( txbytes[BASILISK_BOBREFUND] == 0 )
@ -1202,7 +1202,8 @@ cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requesti
{
jaddstr(item,"method","tradestatus");
jaddnum(item,"finishtime",rswap.finishtime);
jaddstr(item,"gui",G.gui);
if ( jobj(item,"gui") == 0 )
jaddstr(item,"gui",G.gui);
//jaddbits256(item,"srchash",rswap.Q.srchash);
//jaddbits256(item,"desthash",rswap.desthash);
itemstr = jprint(item,0);
@ -1401,7 +1402,7 @@ char *LP_recent_swaps(int32_t limit)
jaddnum(subitem,"price",-destamount/srcamount);
jaddi(item,subitem);
}
} else printf("base.%p rel.%p statusstr.%p baseind.%d relind.%d\n",base,rel,statusstr,baseind,relind);
} //else printf("base.%p rel.%p statusstr.%p baseind.%d relind.%d\n",base,rel,statusstr,baseind,relind);
free_json(swapjson);
} else printf("error parsing.(%s)\n",retstr);
free(retstr);

2
iguana/exchanges/LP_rpc.c

@ -104,7 +104,7 @@ int32_t LP_getheight(int32_t *notarizedp,struct iguana_info *coin)
coin->height = height = jint(retjson,"blocks");
if ( (*notarizedp= jint(retjson,"notarized")) != 0 && *notarizedp != coin->notarized )
{
printf("new notarized %s %d -> %d\n",coin->symbol,coin->notarized,*notarizedp);
//printf("new notarized %s %d -> %d\n",coin->symbol,coin->notarized,*notarizedp);
coin->notarized = *notarizedp;
coin->notarizationtxid = jbits256(retjson,"notarizedtxid");
coin->notarizedhash = jbits256(retjson,"notarizedhash");

2
iguana/exchanges/LP_scan.c

@ -453,7 +453,7 @@ int32_t LP_waitmempool(char *symbol,char *coinaddr,bits256 txid,int32_t vout,int
return(-1);
}
expiration = (uint32_t)time(NULL) + duration;
while ( 1 )
while ( LP_STOP_RECEIVED == 0 )
{
if ( LP_gettx_presence(symbol,txid) != 0 )
numconfirms = 0;

10
iguana/exchanges/LP_signatures.c

@ -42,7 +42,8 @@ struct basilisk_request *LP_requestinit(struct basilisk_request *rp,bits256 srch
cJSON *LP_quotejson(struct LP_quoteinfo *qp)
{
double price; cJSON *retjson = cJSON_CreateObject();
jaddstr(retjson,"gui",qp->gui[0] != 0 ? qp->gui : LP_gui);
if ( jobj(retjson,"gui") == 0 )
jaddstr(retjson,"gui",qp->gui[0] != 0 ? qp->gui : LP_gui);
jadd64bits(retjson,"aliceid",qp->aliceid);
jaddnum(retjson,"tradeid",qp->tradeid);
jaddstr(retjson,"base",qp->srccoin);
@ -542,8 +543,8 @@ void LP_notify_pubkeys(void *ctx,int32_t pubsock)
jaddstr(reqjson,"isLP",LPipaddr);
if ( strcmp(LPipaddr,LP_myipaddr) == 0 )
jaddnum(reqjson,"ismine",1);
}
else printf("no LPipaddr\n");
//printf("notify send isLP.%s ismine.%d\n",LPipaddr,strcmp(LPipaddr,LP_myipaddr) == 0);
} else printf("no LPipaddr\n");
}
jaddnum(reqjson,"session",G.LP_sessionid);
LP_reserved_msg(0,"","",zero,jprint(reqjson,1));
@ -569,7 +570,7 @@ char *LP_notify_recv(cJSON *argjson)
G.LP_IAMLP = 1;
}
}
LP_addpeer(LP_mypeer,LP_mypubsock,ipaddr,RPC_port,RPC_port+10,RPC_port+20,1,juint(argjson,"session"));
LP_addpeer(LP_mypeer,LP_mypubsock,ipaddr,RPC_port,RPC_port+10,RPC_port+20,1,juint(argjson,"session"),G.netid);
}
//char str[65]; printf("%.3f NOTIFIED pub %s rmd160 %s\n",OS_milliseconds()-millis,bits256_str(str,pub),rmd160str);
}
@ -676,6 +677,7 @@ void LP_query(void *ctx,char *myipaddr,int32_t mypubsock,char *method,struct LP_
memset(&zero,0,sizeof(zero));
LP_reserved_msg(1,qp->srccoin,qp->destcoin,zero,clonestr(msg));
//if ( strcmp(method,"request") == 0 )
if ( 0 )
{
sleep(1);
LP_reserved_msg(1,qp->srccoin,qp->destcoin,zero,clonestr(msg));

4
iguana/exchanges/LP_socket.c

@ -433,7 +433,9 @@ cJSON *electrum_submit(char *symbol,struct electrum_info *ep,cJSON **retjsonp,ch
if ( *retjsonp == 0 || jobj(*retjsonp,"error") != 0 )
{
if ( ++ep->numerrors >= LP_ELECTRUM_MAXERRORS )
electrum_kickstart(ep);
{
// electrum_kickstart(ep); seems to hurt more than help
}
} else if ( ep->numerrors > 0 )
ep->numerrors--;
if ( ep->prev == 0 )

6
iguana/exchanges/LP_stats.c

@ -201,9 +201,11 @@ int32_t LP_statslog_parse()
struct LP_swapstats *LP_swapstats_find(uint64_t aliceid)
{
struct LP_swapstats *sp;
portable_mutex_lock(&LP_statslogmutex);
HASH_FIND(hh,LP_RTstats,&aliceid,sizeof(aliceid),sp);
if ( sp == 0 )
HASH_FIND(hh,LP_swapstats,&aliceid,sizeof(aliceid),sp);
portable_mutex_unlock(&LP_statslogmutex);
return(sp);
}
@ -214,9 +216,11 @@ struct LP_swapstats *LP_swapstats_add(uint64_t aliceid,int32_t RTflag)
{
sp = calloc(1,sizeof(*sp));
sp->aliceid = aliceid;
portable_mutex_lock(&LP_statslogmutex);
if ( RTflag != 0 )
HASH_ADD(hh,LP_RTstats,aliceid,sizeof(aliceid),sp);
else HASH_ADD(hh,LP_swapstats,aliceid,sizeof(aliceid),sp);
portable_mutex_unlock(&LP_statslogmutex);
}
return(LP_swapstats_find(aliceid));
}
@ -742,8 +746,10 @@ cJSON *LP_statslog_disp(uint32_t starttime,uint32_t endtime,char *refgui,bits256
{
if ( LP_stats_dispiter(array,sp,starttime,endtime,refbase,refrel,refgui,refpubkey) > 0 )
{
portable_mutex_lock(&LP_statslogmutex);
HASH_DELETE(hh,LP_RTstats,sp);
HASH_ADD(hh,LP_swapstats,aliceid,sizeof(sp->aliceid),sp);
portable_mutex_unlock(&LP_statslogmutex);
}
else
{

2
iguana/exchanges/LP_utxo.c

@ -635,7 +635,7 @@ cJSON *LP_balances(char *coinaddr)
strcpy(address,coin->smartaddr);
else
{
bitcoin_addr2rmd160(coin->symbol,taddr,&addrtype,rmd160,coinaddr);
bitcoin_addr2rmd160("KMD",taddr,&addrtype,rmd160,coinaddr);
bitcoin_address(coin->symbol,address,coin->taddr,coin->pubtype,rmd160,20);
//printf("%s taddr.%d addrtype.%u %s -> %s [%c %c].%d\n",coin->symbol,taddr,addrtype,coinaddr,address,coinaddr[0],coinaddr[1],coinaddr[0] == 't' && (coinaddr[1] == '1' || coinaddr[1] == '3'));
}

2
iguana/exchanges/auto_chipsbtc

@ -1,2 +1,2 @@
source userpass
curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"autoprice\",\"base\":\"CHIPS\",\"rel\":\"BTC\",\"margin\":0.05,\"refbase\":\"chips\",\"refrel\":\"coinmarketcap\"}"
curl --url "http://127.0.0.1:7783" --data "{\"minprice\":0.00002,\"maxprice\":0.0001,\"userpass\":\"$userpass\",\"method\":\"autoprice\",\"base\":\"CHIPS\",\"rel\":\"BTC\",\"margin\":0.05,\"refbase\":\"chips\",\"refrel\":\"coinmarketcap\"}"

2
iguana/exchanges/auto_chipskmd

@ -1,2 +1,2 @@
source userpass
curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"autoprice\",\"base\":\"CHIPS\",\"rel\":\"KMD\",\"margin\":0.05,\"refbase\":\"chips\",\"refrel\":\"coinmarketcap\"}"
curl --url "http://127.0.0.1:7783" --data "{\"minprice\":0.04,\"maxprice\":0.1,\"userpass\":\"$userpass\",\"method\":\"autoprice\",\"base\":\"CHIPS\",\"rel\":\"KMD\",\"margin\":0.05,\"refbase\":\"chips\",\"refrel\":\"coinmarketcap\"}"

2
iguana/exchanges/auto_grskmd

@ -1,2 +1,2 @@
source userpass
curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"autoprice\",\"base\":\"GRS\",\"rel\":\"KMD\",\"margin\":0.05,\"refbase\":\"groestlcoin\",\"refrel\":\"coinmarketcap\"}"
curl --url "http://127.0.0.1:7783" --data "{\"minprice\":0.05,\"maxprice\":0.2,\"userpass\":\"$userpass\",\"method\":\"autoprice\",\"base\":\"GRS\",\"rel\":\"KMD\",\"margin\":0.05,\"refbase\":\"groestlcoin\",\"refrel\":\"coinmarketcap\"}"

3
iguana/exchanges/client

@ -1,9 +1,10 @@
#!/bin/bash
source passphrase
source coins
pkill -15 marketmaker;
./stop
git pull;
cd ..;
./m_mm;
pkill -15 marketmaker;
./marketmaker "{\"gui\":\"nogui\",\"client\":1, \"userhome\":\"/${HOME#"/"}\", \"passphrase\":\"$passphrase\", \"coins\":$coins}" &

2
iguana/exchanges/coins

File diff suppressed because one or more lines are too long

8
iguana/exchanges/enable

@ -1,8 +1,11 @@
#!/bin/bash
source userpass
curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"enable\",\"coin\":\"BEER\"}"
curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"enable\",\"coin\":\"PIZZA\"}"
curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"enable\",\"coin\":\"REVS\"}"
curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"enable\",\"coin\":\"KMD\"}"
curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"enable\",\"coin\":\"BTC\"}"
#curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"enable\",\"coin\":\"BTC\"}"
curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"enable\",\"coin\":\"CHIPS\"}"
curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"enable\",\"coin\":\"SUPERNET\"}"
curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"enable\",\"coin\":\"CRYPTO\"}"
curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"enable\",\"coin\":\"DEX\"}"
@ -15,6 +18,7 @@ curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\
curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"enable\",\"coin\":\"JUMBLR\"}"
curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"enable\",\"coin\":\"HUSH\"}"
curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"enable\",\"coin\":\"BTCH\"}"
#curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"electrum\",\"coin\":\"HUSH\",\"ipaddr\":\"173.212.225.176\",\"port\":50013}"
curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"electrum\",\"coin\":\"HUSH\",\"ipaddr\":\"173.212.225.176\",\"port\":50013}"
#curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"electrum\",\"coin\":\"BTCH\",\"ipaddr\":\"electrum1.cipig.net\",\"port\":10020}"
curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"electrum\",\"coin\":\"BTC\",\"ipaddr\":\"node1.komodo.rocks\",\"port\":50001}"

20
iguana/exchanges/getpeersIP

@ -1,11 +1,11 @@
#!/bin/bash
curl --url "http://5.9.253.195:7783" --data "{\"method\":\"getpeers\"}"
curl --url "http://5.9.253.196:7783" --data "{\"method\":\"getpeers\"}"
curl --url "http://5.9.253.197:7783" --data "{\"method\":\"getpeers\"}"
curl --url "http://5.9.253.198:7783" --data "{\"method\":\"getpeers\"}"
curl --url "http://5.9.253.199:7783" --data "{\"method\":\"getpeers\"}"
curl --url "http://5.9.253.200:7783" --data "{\"method\":\"getpeers\"}"
curl --url "http://5.9.253.201:7783" --data "{\"method\":\"getpeers\"}"
curl --url "http://5.9.253.202:7783" --data "{\"method\":\"getpeers\"}"
curl --url "http://5.9.253.203:7783" --data "{\"method\":\"getpeers\"}"
curl --url "http://5.9.253.204:7783" --data "{\"method\":\"getpeers\"}"
curl --url "http://5.9.253.195:7782" --data "{\"method\":\"getpeers\"}"
curl --url "http://5.9.253.196:7782" --data "{\"method\":\"getpeers\"}"
curl --url "http://5.9.253.197:7782" --data "{\"method\":\"getpeers\"}"
curl --url "http://5.9.253.198:7782" --data "{\"method\":\"getpeers\"}"
curl --url "http://5.9.253.199:7782" --data "{\"method\":\"getpeers\"}"
curl --url "http://5.9.253.200:7782" --data "{\"method\":\"getpeers\"}"
curl --url "http://5.9.253.201:7782" --data "{\"method\":\"getpeers\"}"
curl --url "http://5.9.253.202:7782" --data "{\"method\":\"getpeers\"}"
curl --url "http://5.9.253.203:7782" --data "{\"method\":\"getpeers\"}"
curl --url "http://5.9.253.204:7782" --data "{\"method\":\"getpeers\"}"

3
iguana/exchanges/jpg

@ -0,0 +1,3 @@
source userpass
curl --url "http://127.0.0.1:7783" --data "{\"password\":\"123\",\"ind\":3453,\"userpass\":\"$userpass\",\"method\":\"jpg\",\"srcfile\":\"/root/boost_1_64_0/libs/gil/doc/doxygen/images/monkey_steps.jpg\",\"destfile\":\"dest.jpg\",\"power2\":3,\"data\":\"68656c6c6f20776f726c64\",\"required\":88}"
curl --url "http://127.0.0.1:7783" --data "{\"password\":\"123\",\"userpass\":\"$userpass\",\"method\":\"jpg\",\"srcfile\":\"dest.jpg\",\"power2\":3,\"required\":88}"

49
iguana/exchanges/mm.c

@ -69,11 +69,35 @@ void LP_priceupdate(char *base,char *rel,double price,double avebid,double aveas
#endif
#endif
#include "LP_nativeDEX.c"
void LP_ports(uint16_t *pullportp,uint16_t *pubportp,uint16_t *busportp,uint16_t netid)
{
int32_t netmod,netdiv; uint16_t otherports;
*pullportp = *pubportp = *busportp = 0;
if ( netid < 0 )
netid = 0;
else if ( netid > (65535-40-LP_RPCPORT)/4 )
{
printf("netid.%d overflow vs max netid.%d 14420?\n",netid,(65535-40-LP_RPCPORT)/4);
exit(-1);
}
if ( netid != 0 )
{
netmod = (netid % 10);
netdiv = (netid / 10);
otherports = (netdiv * 40) + (LP_RPCPORT + netmod);
} else otherports = LP_RPCPORT;
*pullportp = otherports + 10;
*pubportp = otherports + 20;
*busportp = otherports + 30;
printf("RPCport.%d remoteport.%d, nanoports %d %d %d\n",RPC_port,RPC_port-1,*pullportp,*pubportp,*busportp);
}
void LP_main(void *ptr)
{
char *passphrase; double profitmargin; int32_t netmod,netdiv,netid=0; uint16_t port,otherports; cJSON *argjson = ptr;
char *passphrase; double profitmargin; uint16_t netid=0,port,pullport,pubport,busport; cJSON *argjson = ptr;
if ( (passphrase= jstr(argjson,"passphrase")) != 0 )
{
profitmargin = jdouble(argjson,"profitmargin");
@ -82,21 +106,8 @@ void LP_main(void *ptr)
port = LP_RPCPORT;
if ( jobj(argjson,"netid") != 0 )
netid = juint(argjson,"netid");
if ( netid < 0 )
netid = 0;
else if ( netid > (65535-40-LP_RPCPORT)/4 )
{
printf("netid.%d overflow vs max netid.%d 14420?\n",netid,(65535-40-LP_RPCPORT)/4);
exit(-1);
}
if ( netid != 0 )
{
netmod = (netid % 10);
netdiv = (netid / 10);
otherports = (netdiv * 40) + (LP_RPCPORT + netmod);
} else otherports = LP_RPCPORT;
printf("RPCport.%d remoteport.%d, nanoports %d %d %d\n",port,port-1,otherports+10,otherports+20,otherports+30);
LPinit(port,otherports+10,otherports+20,otherports+30,passphrase,jint(argjson,"client"),jstr(argjson,"userhome"),argjson);
LP_ports(&pullport,&pubport,&busport,netid);
LPinit(port,pullport,pubport,busport,passphrase,jint(argjson,"client"),jstr(argjson,"userhome"),argjson);
}
}
@ -203,15 +214,17 @@ int main(int argc, const char * argv[])
DOCKERFLAG = 1;
else if ( jstr(retjson,"docker") != 0 )
DOCKERFLAG = (uint32_t)calc_ipbits(jstr(retjson,"docker"));
if ( jobj(retjson,"passphrase") != 0 )
jdelete(retjson,"passphrase");
if ( (passphrase= jstr(retjson,"passphrase")) == 0 )
jaddstr(retjson,"passphrase","test");
jaddstr(retjson,"passphrase","default");
if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_main,(void *)retjson) != 0 )
{
printf("error launching LP_main (%s)\n",jprint(retjson,0));
exit(-1);
} //else printf("(%s) launched.(%s)\n",argv[1],passphrase);
incr = 100.;
while ( (1) )
while ( LP_STOP_RECEIVED == 0 )
sleep(100000);
}
#endif

16
iguana/exchanges/prices/autoprice

@ -12,11 +12,13 @@ curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\
curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"autoprice\",\"base\":\"KMD\",\"rel\":\"BTCH\",\"offset\":0.0,\"refbase\":\"KMD\",\"refrel\":\"HUSH\",\"factor\":1.44,\"buymargin\":0.05,\"sellmargin\":0.05}"
curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"autoprice\",\"base\":\"BTCH\",\"rel\":\"KMD\",\"offset\":0.0,\"refbase\":\"HUSH\",\"refrel\":\"KMD\",\"factor\":0.7,\"buymargin\":0.05,\"sellmargin\":0.05}"
curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"autoprice\",\"base\":\"BEER\",\"rel\":\"PIZZA\",\"fixed\":0.0001,\"margin\":0.00001}"
source crypto
source trackbtc
source jumblr
source trackbtc
#source jumblr
#source trackbtc
source pangea
source trackbtc
@ -24,8 +26,8 @@ source trackbtc
source bet
source trackbtc
source revs
source trackbtc
#source revs
#source trackbtc
sharkholdings="{\"coin\":\"iota\",\"balance\":1500000}, {\"coin\":\"bitcoin-cash\",\"balance\":1200}, {\"coin\":\"bitcoin\",\"balance\":145}"
curl --url "http://127.0.0.1:7783" --data "{\"base\":\"MSHARK\",\"rel\":\"KMD\",\"fundvalue_bid\":\"NAV_KMD\",\"fundvalue_ask\":\"assetNAV_KMD\",\"userpass\":\"$userpass\",\"method\":\"autoprice\",\"margin\":$margin,\"address\":\"RTu3JZZKLJTcfNwBa19dWRagEfQq49STqC\",\"holdings\":[$sharkholdings],\"divisor\":1400000}"
@ -40,4 +42,8 @@ curl --url "http://127.0.0.1:7783" --data "{\"base\":\"DEX\",\"rel\":\"KMD\",\"m
curl --url "http://127.0.0.1:7783" --data "{\"base\":\"BOTS\",\"rel\":\"KMD\",\"margin\":$margin,\"fundvalue_bid\":\"assetNAV_KMD\",\"fundvalue_ask\":\"assetNAV_KMD\",\"userpass\":\"$userpass\",\"method\":\"autoprice\",\"address\":\"RNdqHx26GWy9bk8MtmH1UiXjQcXE4RKK2P\",\"holdings\":[$dexholdings],\"divisor\":3333333}"
curl --url "http://127.0.0.1:7783" --data "{\"base\":\"MGW\",\"rel\":\"KMD\",\"margin\":$margin,\"fundvalue_bid\":\"assetNAV_KMD\",\"fundvalue_ask\":\"assetNAV_KMD\",\"userpass\":\"$userpass\",\"method\":\"autoprice\",\"holdings\":[$dexholdings],\"divisor\":10000000}"
curl --url "http://127.0.0.1:7783" --data "{\"base\":\"JUMBLR\",\"rel\":\"KMD\",\"margin\":$margin,\"fundvalue_bid\":\"assetNAV_KMD\",\"fundvalue_ask\":\"assetNAV_KMD\",\"userpass\":\"$userpass\",\"method\":\"autoprice\",\"address\":\"RGhxXpXSSBTBm9EvNsXnTQczthMCxHX91t\",\"holdings\":[$dexholdings],\"divisor\":3333333}"
curl --url "http://127.0.0.1:7783" --data "{\"base\":\"MGW\",\"rel\":\"KMD\",\"margin\":$margin,\"fundvalue_bid\":\"assetNAV_KMD\",\"fundvalue_ask\":\"assetNAV_KMD\",\"userpass\":\"$userpass\",\"method\":\"autoprice\",\"holdings\":[$dexholdings],\"divisor\":13000000}"
curl --url "http://127.0.0.1:7783" --data "{\"base\":\"REVS\",\"rel\":\"KMD\",\"margin\":$margin,\"fundvalue_bid\":\"assetNAV_KMD\",\"fundvalue_ask\":\"assetNAV_KMD\",\"userpass\":\"$userpass\",\"method\":\"autoprice\",\"holdings\":[$dexholdings],\"divisor\":9000000}"

3
iguana/exchanges/run

@ -1,8 +1,9 @@
#!/bin/bash
source passphrase
source coins
pkill -15 marketmaker;
./stop
git pull;
cd ..;
./m_mm;
pkill -15 marketmaker;
$1 ./marketmaker "{\"gui\":\"nogui\", \"profitmargin\":0.01, \"userhome\":\"/${HOME#"/"}\", \"passphrase\":\"$passphrase\", \"coins\":$coins}" &

3
iguana/exchanges/setpassphrase

@ -1,3 +1,4 @@
#!/bin/bash
source userpass
curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"passphrase\",\"passphrase\":\"put the passphrase here\",\"gui\":\"buildog\"}"
source passphrase
curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"1d8b27b21efabcd96571cd56f91a40fb9aa4cc623d273c63bf9223dc6f8cd81f\",\"method\":\"passphrase\",\"passphrase\":\"$passphrase\",\"gui\":\"nogui\"}"

15
iguana/exchanges/stats.c

@ -29,6 +29,7 @@
#define STATS_DEST "/var/www/html/DEXstats.json"
#include "DEXstats.h"
char *stats_JSON(void *ctx,char *myipaddr,int32_t mypubsock,cJSON *argjson,char *remoteaddr,uint16_t port);
extern uint32_t DOCKERFLAG;
char *stats_validmethods[] =
{
@ -46,6 +47,7 @@ int32_t LP_valid_remotemethod(cJSON *argjson)
for (i=0; i<sizeof(stats_validmethods)/sizeof(*stats_validmethods); i++)
if ( strcmp(method,stats_validmethods[i]) == 0 )
return(1);
printf("got invalid method.%s remotely\n",method);
}
return(-1);
}
@ -681,9 +683,9 @@ void LP_rpc_processreq(void *_ptr)
if ( recvlen > 0 )
{
jsonflag = postflag = 0;
portable_mutex_lock(&LP_commandmutex);
//portable_mutex_lock(&LP_commandmutex);
retstr = stats_rpcparse(space,size,&jsonflag,&postflag,jsonbuf,remoteaddr,filetype,req->port);
portable_mutex_unlock(&LP_commandmutex);
//portable_mutex_unlock(&LP_commandmutex);
if ( filetype[0] != 0 )
{
static cJSON *mimejson; char *tmp,*typestr=0; long tmpsize;
@ -771,7 +773,7 @@ void LP_rpc_processreq(void *_ptr)
spawned--;
}
extern int32_t IAMLP;
extern int32_t IAMLP,LP_STOP_RECEIVED;
//int32_t LP_bindsock_reset,LP_bindsock = -1;
void stats_rpcloop(void *args)
@ -782,7 +784,7 @@ void stats_rpcloop(void *args)
printf("Start stats_rpcloop.%u\n",port);
localhostbits = (uint32_t)calc_ipbits("127.0.0.1");
//initial_bindsock_reset = LP_bindsock_reset;
while ( 1 )//LP_bindsock_reset == initial_bindsock_reset )
while ( LP_STOP_RECEIVED == 0 )//LP_bindsock_reset == initial_bindsock_reset )
{
//printf("LP_bindsock.%d\n",LP_bindsock);
if ( bindsock < 0 )
@ -817,6 +819,7 @@ void stats_rpcloop(void *args)
}
#endif*/
memcpy(&ipbits,&cli_addr.sin_addr.s_addr,sizeof(ipbits));
//printf("port.%u got incoming from %x\n",port,ipbits);
if ( DOCKERFLAG != 0 && (DOCKERFLAG == 1 || ipbits == DOCKERFLAG) )
ipbits = localhostbits;
if ( port == RPC_port && ipbits != localhostbits )
@ -858,7 +861,7 @@ continue;
#ifndef FROM_MARKETMAKER
portable_mutex_t LP_commandmutex;
uint16_t LP_RPCPORT;
uint16_t LP_RPCPORT = 7763;
void stats_kvjson(FILE *logfp,int32_t height,int32_t savedheight,uint32_t timestamp,char *key,cJSON *kvjson,bits256 pubkey,bits256 sigprev)
{
@ -1196,7 +1199,7 @@ int main(int argc, const char * argv[])
exit(-1);
}
printf("DEX stats running\n");
while ( 1 )
while ( LP_STOP_RECEIVED == 0 )
{
if ( (filestr= stats_update(logfp,STATS_DEST,statefname,komodofile)) != 0 )
{

2
iguana/exchanges/status

@ -1,3 +1,3 @@
#!/bin/bash
source userpass
curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"swapstatus\"}"
curl --url "http://127.0.0.1:7783" --data "{\"pending\":1,\"userpass\":\"$userpass\",\"method\":\"swapstatus\"}"

2
iguana/m_mm

@ -1,3 +1,3 @@
cd secp256k1; ./m_unix; cd ..
cd ../crypto777; ./m_LP; cd ../iguana
gcc -g -o marketmaker -I../crypto777 exchanges/mm.c ../crypto777/cJSON.c mini-gmp.c groestl.c segwit_addr.c secp256k1.o ../agents/libcrypto777.a -lnanomsg -lcurl -lpthread -lm
gcc -g -o marketmaker -I../crypto777 exchanges/mm.c ../crypto777/cJSON.c mini-gmp.c groestl.c segwit_addr.c secp256k1.o ../agents/libcrypto777.a -lnanomsg -lcurl -lpthread -lm

3
iguana/m_mm_StaticNanoMsg

@ -19,10 +19,9 @@ all:
+$(MAKE) -C secp256k1 -f m_unix_Makefile all
+$(MAKE) -C ../crypto777 -f m_LP_StaticNanoMsg all
+$(MAKE) -C ../crypto777 -f m_LP_StaticNanoMsg clean
$(CC) -o ../agents/marketmaker -I../crypto777 exchanges/mm.c ../crypto777/cJSON.c mini-gmp.c secp256k1.o ../agents/libcrypto777.a ../OSlibs/linux/$(shell uname -m)/libnanomsg-static.a -lcurl -lpthread -lm -lanl
$(CC) -o ../agents/marketmaker -I../crypto777 exchanges/mm.c ../crypto777/cJSON.c mini-gmp.c groestl.c segwit_addr.c secp256k1.o ../agents/libcrypto777.a ../OSlibs/linux/$(shell uname -m)/libnanomsg-static.a -lcurl -lpthread -lm -lanl
@echo "==========================="
@echo " marketmaker -> `pwd`/../agents/marketmaker"
@echo "==========================="

1
marketmaker.vcxproj

@ -248,6 +248,7 @@
<ClCompile Include="crypto777\scrypt.c" />
<ClCompile Include="crypto777\tweetnacl.c" />
<ClCompile Include="iguana\exchanges\mm.c" />
<ClCompile Include="iguana\groestl.c" />
<ClCompile Include="iguana\mini-gmp.c" />
<ClCompile Include="iguana\secp256k1\src\secp256k1.c" />
<ClCompile Include="iguana\segwit_addr.c" />

3
marketmaker.vcxproj.filters

@ -293,6 +293,9 @@
<ClCompile Include="iguana\segwit_addr.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="iguana\groestl.c">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<Text Include="ReadMe.txt" />

Loading…
Cancel
Save