Browse Source

Merge pull request #603 from jl777/dPoW

sync to dev
patch-1
jl777 7 years ago
committed by GitHub
parent
commit
7c5b57400d
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      .gitignore
  2. BIN
      OSlibs/win/x64/pthread_lib.lib
  3. 10
      iguana/dexscripts.win32/1-client.cmd
  4. 16
      iguana/dexscripts.win32/2-getuserpass.cmd
  5. 33
      iguana/dpow/dpow_fsm.c
  6. 2
      iguana/dpow/dpow_rpc.c
  7. 40
      iguana/exchanges/LP_commands.c
  8. 8
      iguana/exchanges/LP_include.h
  9. 2
      iguana/exchanges/LP_instantdex.c
  10. 77
      iguana/exchanges/LP_nativeDEX.c
  11. 4
      iguana/exchanges/LP_network.c
  12. 4
      iguana/exchanges/LP_ordermatch.c
  13. 2
      iguana/exchanges/LP_peers.c
  14. 8
      iguana/exchanges/LP_portfolio.c
  15. 14
      iguana/exchanges/LP_prices.c
  16. 19
      iguana/exchanges/LP_remember.c
  17. 31
      iguana/exchanges/LP_rpc.c
  18. 2
      iguana/exchanges/LP_secp.c
  19. 22
      iguana/exchanges/LP_socket.c
  20. 58
      iguana/exchanges/LP_swap.c
  21. 2
      iguana/exchanges/auto_chipsbtc
  22. 2
      iguana/exchanges/auto_chipskmd
  23. 3
      iguana/exchanges/calcaddress
  24. 3
      iguana/exchanges/coins
  25. 83
      iguana/exchanges/mm.c
  26. 2
      iguana/exchanges/mshark
  27. 4
      iguana/exchanges/prices/bet
  28. 2
      iguana/exchanges/run
  29. 15
      iguana/iguana_notary.c
  30. 2
      iguana/iguana_payments.c
  31. 13
      iguana/m_mm
  32. 89
      marketmaker_build_depends.cmd

1
.gitignore

@ -255,3 +255,4 @@ iguana/DB/UNSPENTS/.tmpmarker
iguana/DB/instantdex_RQ4z6KrMZeEnCSCsChv1ZoR9ExQitHjbpg_append.json iguana/DB/instantdex_RQ4z6KrMZeEnCSCsChv1ZoR9ExQitHjbpg_append.json
iguana/DB/instantdex_RQ4z6KrMZeEnCSCsChv1ZoR9ExQitHjbpg.json iguana/DB/instantdex_RQ4z6KrMZeEnCSCsChv1ZoR9ExQitHjbpg.json
Release/*

BIN
OSlibs/win/x64/pthread_lib.lib

Binary file not shown.

10
iguana/dexscripts.win32/1-client.cmd

@ -6,10 +6,16 @@ rem set COINS=[{\"coin\":\"REVS\",\"active\":1,\"asset\":\"REVS\",\"rpcport\":10
rem marketmaker "{\"gui\":\"nogui\",\"client\":1, \"userhome\":\"%USERHOME%\", \"passphrase\":\"mypassphrase\", \"coins\":%COINS%}" rem marketmaker "{\"gui\":\"nogui\",\"client\":1, \"userhome\":\"%USERHOME%\", \"passphrase\":\"mypassphrase\", \"coins\":%COINS%}"
set COINS=\"\" set COINS=\"\"
set /p PASSPHRASE=<passphrase rem set /p PASSPHRASE=<passphrase
rem , \"canbind\":1 rem , \"canbind\":1
rem marketmaker "{\"gui\":\"nogui\",\"client\":1, \"userhome\":\"%USERHOME%\", \"passphrase\":\"%PASSPHRASE%\"}" 1> marketmaker.log 2>&1 rem marketmaker "{\"gui\":\"nogui\",\"client\":1, \"userhome\":\"%USERHOME%\", \"passphrase\":\"%PASSPHRASE%\"}" 1> marketmaker.log 2>&1
marketmaker "{\"gui\":\"nogui\",\"client\":1, \"userhome\":\"%USERHOME%\", \"passphrase\":\"%PASSPHRASE%\"}" rem marketmaker "{\"gui\":\"nogui\",\"client\":1, \"userhome\":\"%USERHOME%\", \"passphrase\":\"%PASSPHRASE%\"}" 1> marketmaker.log 2>&1
rem echo "{\"gui\":\"nogui\",\"client\":1, \"userhome\":\"%USERHOME%\", \"passphrase\":\"%PASSPHRASE%\"}"
rem marketmaker "{\"gui\":\"nogui\",\"client\":1, \"userhome\":\"%USERHOME%\", \"passphrase\":\"%PASSPHRASE%\"}"
marketmaker "{\"gui\":\"nogui\",\"client\":1, \"userhome\":\"%USERHOME%\",\"passphrase\":\"default\"}"

16
iguana/dexscripts.win32/2-getuserpass.cmd

@ -1,7 +1,17 @@
@echo off @echo off
curl --url "http://127.0.0.1:7783" --data "{\"userpass\":null,\"method\":\"enable\",\"coin\":\" \"}" -s > userpass.json rem first time call to any method after started markemaker will return default userpass 1d8b27b21efabcd96571cd56f91a40fb9aa4cc623d273c63bf9223dc6f8cd81f
for /f "tokens=2 delims=:," %%a in (' find "userpass" "userpass.json" ') do ( rem by-default userpass is 1d8b27b21efabcd96571cd56f91a40fb9aa4cc623d273c63bf9223dc6f8cd81f from "default" passphrase
rem first time call to marketmaker don't return anything now, so we disable it
rem curl --url "http://127.0.0.1:7783" --data "{\"userpass\":null,\"method\":\"enable\",\"coin\":\"\"}" -s > default_userpass.json
rem curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"1d8b27b21efabcd96571cd56f91a40fb9aa4cc623d273c63bf9223dc6f8cd81f\",\"method\":\"hello\"}" -s > default_userpass.json
rem echo - First time call to MM API finished, default userpass received
set /p PASSPHRASE=<passphrase
echo - Pushing passphrase to login
curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"1d8b27b21efabcd96571cd56f91a40fb9aa4cc623d273c63bf9223dc6f8cd81f\",\"method\":\"passphrase\",\"passphrase\":\"%PASSPHRASE%\",\"gui\":\"nogui\"}" -s > userpass.json
echo Getting userpass related to your passphrase finished
for /f "tokens=4 delims=:," %%a in (' find "userpass" "userpass.json" ') do (
echo UserPass: %%~a echo UserPass: %%~a
echo %%~a > userpass echo %%~a > userpass
) )
del userpass.json

33
iguana/dpow/dpow_fsm.c

@ -155,11 +155,13 @@ int32_t dpow_checkutxo(struct supernet_info *myinfo,struct dpow_info *dp,struct
return(haveutxo); return(haveutxo);
} }
uint32_t Numallocated;
void dpow_statemachinestart(void *ptr) void dpow_statemachinestart(void *ptr)
{ {
void **ptrs = ptr; void **ptrs = ptr;
struct supernet_info *myinfo; struct dpow_info *dp; struct dpow_checkpoint checkpoint; struct supernet_info *myinfo; struct dpow_info *dp; struct dpow_checkpoint checkpoint;
int32_t i,j,ht,extralen,destprevvout0,srcprevvout0,numratified=0,kmdheight,myind = -1; uint8_t extras[10000],pubkeys[64][33]; cJSON *ratified=0,*item; struct iguana_info *src,*dest; char *jsonstr,*handle,*hexstr,str[65],str2[65],srcaddr[64],destaddr[64]; bits256 zero,srchash,destprevtxid0,srcprevtxid0; struct dpow_block *bp,*tmp; struct dpow_entry *ep = 0; uint32_t duration,minsigs,starttime,srctime; int32_t i,j,ht,extralen,destprevvout0,srcprevvout0,numratified=0,kmdheight,myind = -1; uint8_t extras[10000],pubkeys[64][33]; cJSON *ratified=0,*item; struct iguana_info *src,*dest; char *jsonstr,*handle,*hexstr,str[65],str2[65],srcaddr[64],destaddr[64]; bits256 zero,srchash,destprevtxid0,srcprevtxid0; struct dpow_block *bp; struct dpow_entry *ep = 0; uint32_t duration,minsigs,starttime,srctime;
memset(&zero,0,sizeof(zero)); memset(&zero,0,sizeof(zero));
srcprevtxid0 = destprevtxid0 = zero; srcprevtxid0 = destprevtxid0 = zero;
srcprevvout0 = destprevvout0 = -1; srcprevvout0 = destprevvout0 = -1;
@ -187,6 +189,7 @@ void dpow_statemachinestart(void *ptr)
if ( (bp= dp->blocks[checkpoint.blockhash.height]) == 0 ) if ( (bp= dp->blocks[checkpoint.blockhash.height]) == 0 )
{ {
bp = calloc(1,sizeof(*bp)); bp = calloc(1,sizeof(*bp));
Numallocated++;
bp->minsigs = minsigs; bp->minsigs = minsigs;
bp->duration = duration; bp->duration = duration;
bp->srccoin = src; bp->srccoin = src;
@ -202,6 +205,7 @@ void dpow_statemachinestart(void *ptr)
{ {
fprintf(stderr,"cant ratify more than 64 notaries ratified has %d\n",numratified); fprintf(stderr,"cant ratify more than 64 notaries ratified has %d\n",numratified);
free(ptr); free(ptr);
free_json(ratified);
return; return;
} }
for (i=0; i<numratified; i++) for (i=0; i<numratified; i++)
@ -240,24 +244,14 @@ void dpow_statemachinestart(void *ptr)
bp->numratified = numratified; bp->numratified = numratified;
bp->ratified = ratified; bp->ratified = ratified;
printf("numratified.%d %s\n",numratified,jprint(ratified,0)); printf("numratified.%d %s\n",numratified,jprint(ratified,0));
} } else printf("i.%d numratified.%d\n",i,numratified);
else
{
printf("i.%d numratified.%d\n",i,numratified);
free_json(ratified);
}
} }
free_json(ratified);
} }
bp->bestk = -1; bp->bestk = -1;
dp->blocks[checkpoint.blockhash.height] = bp; dp->blocks[checkpoint.blockhash.height] = bp;
bp->beacon = rand256(0); bp->beacon = rand256(0);
vcalc_sha256(0,bp->commit.bytes,bp->beacon.bytes,sizeof(bp->beacon)); vcalc_sha256(0,bp->commit.bytes,bp->beacon.bytes,sizeof(bp->beacon));
/*if ( checkpoint.blockhash.height >= DPOW_FIRSTRATIFY && dp->blocks[checkpoint.blockhash.height - DPOW_FIRSTRATIFY] != 0 )
{
printf("purge %s.%d\n",dp->dest,checkpoint.blockhash.height - DPOW_FIRSTRATIFY);
free(dp->blocks[checkpoint.blockhash.height - DPOW_FIRSTRATIFY]);
dp->blocks[checkpoint.blockhash.height - DPOW_FIRSTRATIFY] = 0;
}*/
} }
if ( bp->isratify != 0 && dp->ratifying != 0 ) if ( bp->isratify != 0 && dp->ratifying != 0 )
{ {
@ -462,22 +456,11 @@ void dpow_statemachinestart(void *ptr)
break; break;
} }
} }
printf("END isratify.%d:%d bestk.%d %llx sigs.%llx state.%x machine ht.%d completed state.%x %s.%s %s.%s recvmask.%llx paxwdcrc.%x %p %p\n",bp->isratify,dp->ratifying,bp->bestk,(long long)bp->bestmask,(long long)(bp->bestk>=0?bp->destsigsmasks[bp->bestk]:0),bp->state,bp->height,bp->state,dp->dest,bits256_str(str,bp->desttxid),dp->symbol,bits256_str(str2,bp->srctxid),(long long)bp->recvmask,bp->paxwdcrc,src,dest); printf("[%d] END isratify.%d:%d bestk.%d %llx sigs.%llx state.%x machine ht.%d completed state.%x %s.%s %s.%s recvmask.%llx paxwdcrc.%x %p %p\n",Numallocated,bp->isratify,dp->ratifying,bp->bestk,(long long)bp->bestmask,(long long)(bp->bestk>=0?bp->destsigsmasks[bp->bestk]:0),bp->state,bp->height,bp->state,dp->dest,bits256_str(str,bp->desttxid),dp->symbol,bits256_str(str2,bp->srctxid),(long long)bp->recvmask,bp->paxwdcrc,src,dest);
bp->state = 0xffffffff; bp->state = 0xffffffff;
dp->lastrecvmask = bp->recvmask; dp->lastrecvmask = bp->recvmask;
dp->ratifying -= bp->isratify; dp->ratifying -= bp->isratify;
// dp->blocks[bp->height] = 0; // dp->blocks[bp->height] = 0;
if ( bp->height > 100 )
{
for (i=bp->height-100; i>=0; i--)
{
if ( (tmp= dp->blocks[i]) != 0 )
{
dp->blocks[i] = 0;
free(tmp);
}
}
}
free(ptr); free(ptr);
} }

2
iguana/dpow/dpow_rpc.c

@ -569,7 +569,7 @@ char *dpow_sendrawtransaction(struct supernet_info *myinfo,struct iguana_info *c
jaddistr(array,signedtx); jaddistr(array,signedtx);
paramstr = jprint(array,1); paramstr = jprint(array,1);
retstr = bitcoind_passthru(coin->symbol,coin->chain->serverport,coin->chain->userpass,"sendrawtransaction",paramstr); retstr = bitcoind_passthru(coin->symbol,coin->chain->serverport,coin->chain->userpass,"sendrawtransaction",paramstr);
printf(">>>>>>>>>>> %s dpow_sendrawtransaction.(%s) -> (%s)\n",coin->symbol,paramstr,retstr); printf(">>>>>>>>>>> %s dpow_sendrawtransaction (%s)\n",coin->symbol,retstr);
free(paramstr); free(paramstr);
return(retstr); return(retstr);
} }

40
iguana/exchanges/LP_commands.c

@ -159,6 +159,7 @@ bot_settings(botid, newprice, newvolume)\n\
bot_status(botid)\n\ bot_status(botid)\n\
bot_stop(botid)\n\ bot_stop(botid)\n\
bot_pause(botid)\n\ bot_pause(botid)\n\
calcaddress(passphrase)\n\
instantdex_deposit(weeks, amount, broadcast=1)\n\ instantdex_deposit(weeks, amount, broadcast=1)\n\
instantdex_claim()\n\ instantdex_claim()\n\
jpg(srcfile, destfile, power2=7, password, data="", required, ind=0)\n\ jpg(srcfile, destfile, power2=7, password, data="", required, ind=0)\n\
@ -177,14 +178,17 @@ jpg(srcfile, destfile, power2=7, password, data="", required, ind=0)\n\
{ {
char pub33str[67]; char pub33str[67];
G.USERPASS_COUNTER = 1; G.USERPASS_COUNTER = 1;
retjson = cJSON_CreateObject(); if ( 0 )
jaddstr(retjson,"userpass",G.USERPASS); {
jaddbits256(retjson,"mypubkey",G.LP_mypub25519); retjson = cJSON_CreateObject();
init_hexbytes_noT(pub33str,G.LP_pubsecp,33); jaddstr(retjson,"userpass",G.USERPASS);
jaddstr(retjson,"pubsecp",pub33str); jaddbits256(retjson,"mypubkey",G.LP_mypub25519);
jadd(retjson,"coins",LP_coinsjson(LP_showwif)); init_hexbytes_noT(pub33str,G.LP_pubsecp,33);
LP_cmdcount++; jaddstr(retjson,"pubsecp",pub33str);
return(jprint(retjson,1)); 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 // if passphrase api and passphrase is right, ignore userpass, use hass of passphrase
if ( strcmp(method,"passphrase") == 0 && (passphrase= jstr(argjson,"passphrase")) != 0 ) if ( strcmp(method,"passphrase") == 0 && (passphrase= jstr(argjson,"passphrase")) != 0 )
@ -195,7 +199,8 @@ jpg(srcfile, destfile, power2=7, password, data="", required, ind=0)\n\
authenticated = 1; authenticated = 1;
else printf("passhash %s != G %s\n",bits256_str(str,passhash),bits256_str(str2,G.LP_passhash)); else printf("passhash %s != G %s\n",bits256_str(str,passhash),bits256_str(str2,G.LP_passhash));
} }
if ( authenticated == 0 && ((userpass= jstr(argjson,"userpass")) == 0 || strcmp(userpass,G.USERPASS) != 0) ) char passhashstr[65]; bits256_str(passhashstr,G.LP_passhash);
if ( authenticated == 0 && ((userpass= jstr(argjson,"userpass")) == 0 || (strcmp(userpass,G.USERPASS) != 0 && strcmp(userpass,passhashstr) != 0)) )
return(clonestr("{\"error\":\"authentication error you need to make sure userpass is set\"}")); return(clonestr("{\"error\":\"authentication error you need to make sure userpass is set\"}"));
if ( jobj(argjson,"userpass") != 0 ) if ( jobj(argjson,"userpass") != 0 )
jdelete(argjson,"userpass"); jdelete(argjson,"userpass");
@ -300,6 +305,21 @@ jpg(srcfile, destfile, power2=7, password, data="", required, ind=0)\n\
{ {
return(LP_portfolio()); return(LP_portfolio());
} }
else if ( strcmp(method,"calcaddress") == 0 )
{
bits256 privkey,pub; uint8_t pubkey33[33]; char *passphrase,coinaddr[64];
if ( (passphrase= jstr(argjson,"passphrase")) != 0 )
{
conv_NXTpassword(privkey.bytes,pub.bytes,(uint8_t *)passphrase,(int32_t)strlen(passphrase));
privkey.bytes[0] &= 248, privkey.bytes[31] &= 127, privkey.bytes[31] |= 64;
bitcoin_priv2pub(ctx,"KMD",pubkey33,coinaddr,privkey,0,60);
retjson = cJSON_CreateObject();
jaddstr(retjson,"passphrase",passphrase);
jaddstr(retjson,"coinaddr",coinaddr);
jaddbits256(retjson,"privkey",privkey);
return(jprint(retjson,1));
} else return(clonestr("{\"error\":\"need to have passphrase\"}"));
}
else if ( strcmp(method,"statsdisp") == 0 ) else if ( strcmp(method,"statsdisp") == 0 )
{ {
return(jprint(LP_statslog_disp(juint(argjson,"starttime"),juint(argjson,"endtime"),jstr(argjson,"gui"),jbits256(argjson,"pubkey"),jstr(argjson,"base"),jstr(argjson,"rel")),1)); return(jprint(LP_statslog_disp(juint(argjson,"starttime"),juint(argjson,"endtime"),jstr(argjson,"gui"),jbits256(argjson,"pubkey"),jstr(argjson,"base"),jstr(argjson,"rel")),1));
@ -324,7 +344,7 @@ jpg(srcfile, destfile, power2=7, password, data="", required, ind=0)\n\
return(basilisk_swapentries(coin,0,jint(argjson,"limit"))); return(basilisk_swapentries(coin,0,jint(argjson,"limit")));
else if ( base[0] != 0 && rel[0] != 0 ) else if ( base[0] != 0 && rel[0] != 0 )
return(basilisk_swapentries(base,rel,jint(argjson,"limit"))); return(basilisk_swapentries(base,rel,jint(argjson,"limit")));
else return(basilisk_swaplist(0,0,0,jint(argjson,"pending"))); else return(basilisk_swaplist(0,0,1,jint(argjson,"pending")));
} }
else if ( strcmp(method,"dynamictrust") == 0 ) else if ( strcmp(method,"dynamictrust") == 0 )
{ {

8
iguana/exchanges/LP_include.h

@ -22,7 +22,7 @@
#define LP_INCLUDE_H #define LP_INCLUDE_H
#ifndef LP_TECHSUPPORT #ifndef LP_TECHSUPPORT
#define LP_TECHSUPPORT 1 #define LP_TECHSUPPORT 0
#endif #endif
#define LP_DONT_CMDCHANNEL #define LP_DONT_CMDCHANNEL
@ -35,7 +35,7 @@ voind dontprintf(char *formatstr,...) {}
#define LP_MAJOR_VERSION "0" #define LP_MAJOR_VERSION "0"
#define LP_MINOR_VERSION "1" #define LP_MINOR_VERSION "1"
#define LP_BUILD_NUMBER "17769" #define LP_BUILD_NUMBER "17770"
#define LP_BARTERDEX_VERSION 1 #define LP_BARTERDEX_VERSION 1
#define LP_MAGICBITS 1 #define LP_MAGICBITS 1
@ -305,7 +305,7 @@ struct iguana_info
int32_t numutxos,notarized,longestchain,firstrefht,firstscanht,lastscanht,height; uint16_t busport,did_addrutxo_reset; int32_t numutxos,notarized,longestchain,firstrefht,firstscanht,lastscanht,height; uint16_t busport,did_addrutxo_reset;
uint32_t txversion,dPoWtime,lastresetutxo,loadedcache,electrumlist,lastunspent,importedprivkey,lastpushtime,lastutxosync,addr_listunspent_requested,lastutxos,updaterate,counter,inactive,lastmempool,lastgetinfo,ratetime,heighttime,lastmonitor,obooktime; uint32_t txversion,dPoWtime,lastresetutxo,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; 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]; char symbol[128],smartaddr[64],userpass[1024],serverport[128],instantdex_address[64],estimatefeestr[32];
// portfolio // portfolio
double price_kmd,force,perc,goal,goalperc,relvolume,rate; double price_kmd,force,perc,goal,goalperc,relvolume,rate;
void *electrum; void *ctx; void *electrum; void *ctx;
@ -507,9 +507,11 @@ char *LP_pricepings(void *ctx,char *myipaddr,int32_t pubsock,char *base,char *re
int32_t LP_merkleproof(struct iguana_info *coin,char *coinaddr,struct electrum_info *ep,bits256 txid,int32_t height); int32_t LP_merkleproof(struct iguana_info *coin,char *coinaddr,struct electrum_info *ep,bits256 txid,int32_t height);
cJSON *electrum_address_gethistory(char *symbol,struct electrum_info *ep,cJSON **retjsonp,char *addr,bits256 reftxid); cJSON *electrum_address_gethistory(char *symbol,struct electrum_info *ep,cJSON **retjsonp,char *addr,bits256 reftxid);
cJSON *LP_myzdebits(); cJSON *LP_myzdebits();
void LP_pendswap_add(uint32_t expiration,uint32_t requestid,uint32_t quoteid);
int32_t _LP_utxos_remove(bits256 txid,int32_t vout); int32_t _LP_utxos_remove(bits256 txid,int32_t vout);
int32_t LP_utxos_remove(bits256 txid,int32_t vout); int32_t LP_utxos_remove(bits256 txid,int32_t vout);
struct LP_transaction *LP_transactionadd(struct iguana_info *coin,bits256 txid,int32_t height,int32_t numvouts,int32_t numvins); struct LP_transaction *LP_transactionadd(struct iguana_info *coin,bits256 txid,int32_t height,int32_t numvouts,int32_t numvins);
char *bitcoin_address(char *symbol,char *coinaddr,uint8_t taddr,uint8_t addrtype,uint8_t *pubkey_or_rmd160,int32_t len);
void LP_tradebot_finished(uint32_t tradeid,uint32_t requestid,uint32_t quoteid); void LP_tradebot_finished(uint32_t tradeid,uint32_t requestid,uint32_t quoteid);
uint64_t LP_txfeecalc(struct iguana_info *coin,uint64_t txfee,int32_t txlen); uint64_t LP_txfeecalc(struct iguana_info *coin,uint64_t txfee,int32_t txlen);
struct LP_address *_LP_address(struct iguana_info *coin,char *coinaddr); struct LP_address *_LP_address(struct iguana_info *coin,char *coinaddr);

2
iguana/exchanges/LP_instantdex.c

@ -98,7 +98,7 @@ void LP_instantdex_filescreate(char *coinaddr)
free_json(txobj); free_json(txobj);
else else
{ {
char str[65]; printf("%s/v%d is already spent\n",bits256_str(str,txid),0); //char str[65]; printf("%s/v%d is already spent\n",bits256_str(str,txid),0);
continue; continue;
} }
jaddibits256(newarray,txid); jaddibits256(newarray,txid);

77
iguana/exchanges/LP_nativeDEX.c

@ -85,7 +85,7 @@ void LP_millistats_update(struct LP_millistats *mp)
} }
#include "LP_include.h" #include "LP_include.h"
portable_mutex_t LP_peermutex,LP_UTXOmutex,LP_utxomutex,LP_commandmutex,LP_cachemutex,LP_swaplistmutex,LP_forwardmutex,LP_pubkeymutex,LP_networkmutex,LP_psockmutex,LP_coinmutex,LP_messagemutex,LP_portfoliomutex,LP_electrummutex,LP_butxomutex,LP_reservedmutex,LP_nanorecvsmutex,LP_tradebotsmutex,LP_gcmutex,LP_inusemutex,LP_cJSONmutex,LP_logmutex,LP_statslogmutex,LP_tradesmutex,LP_commandQmutex,LP_blockinit_mutex; portable_mutex_t LP_peermutex,LP_UTXOmutex,LP_utxomutex,LP_commandmutex,LP_cachemutex,LP_swaplistmutex,LP_forwardmutex,LP_pubkeymutex,LP_networkmutex,LP_psockmutex,LP_coinmutex,LP_messagemutex,LP_portfoliomutex,LP_electrummutex,LP_butxomutex,LP_reservedmutex,LP_nanorecvsmutex,LP_tradebotsmutex,LP_gcmutex,LP_inusemutex,LP_cJSONmutex,LP_logmutex,LP_statslogmutex,LP_tradesmutex,LP_commandQmutex,LP_blockinit_mutex,LP_pendswap_mutex;
int32_t LP_canbind; int32_t LP_canbind;
char *Broadcaststr,*Reserved_msgs[2][1000]; char *Broadcaststr,*Reserved_msgs[2][1000];
int32_t num_Reserved_msgs[2],max_Reserved_msgs[2]; int32_t num_Reserved_msgs[2],max_Reserved_msgs[2];
@ -520,11 +520,11 @@ void LP_coinsloop(void *_coins)
} }
while ( LP_STOP_RECEIVED == 0 ) while ( LP_STOP_RECEIVED == 0 )
{ {
if ( strcmp(G.USERPASS,"1d8b27b21efabcd96571cd56f91a40fb9aa4cc623d273c63bf9223dc6f8cd81f") == 0 ) /*if ( strcmp(G.USERPASS,"1d8b27b21efabcd96571cd56f91a40fb9aa4cc623d273c63bf9223dc6f8cd81f") == 0 )
{ {
sleep(10); sleep(10);
continue; continue;
} }*/
if ( strcmp("BTC",coins) == 0 ) if ( strcmp("BTC",coins) == 0 )
LP_millistats_update(&LP_coinsloopBTC_stats); LP_millistats_update(&LP_coinsloopBTC_stats);
else if ( strcmp("KMD",coins) == 0 ) else if ( strcmp("KMD",coins) == 0 )
@ -548,7 +548,7 @@ void LP_coinsloop(void *_coins)
} }
if ( coin->smartaddr[0] == 0 ) if ( coin->smartaddr[0] == 0 )
{ {
printf("%s has no smartaddress??\n",coin->symbol); //printf("%s has no smartaddress??\n",coin->symbol);
continue; continue;
} }
memset(&zero,0,sizeof(zero)); memset(&zero,0,sizeof(zero));
@ -904,7 +904,7 @@ void LP_pubkeysloop(void *ctx)
sleep(10); sleep(10);
while ( LP_STOP_RECEIVED == 0 ) while ( LP_STOP_RECEIVED == 0 )
{ {
if ( strcmp(G.USERPASS,"1d8b27b21efabcd96571cd56f91a40fb9aa4cc623d273c63bf9223dc6f8cd81f") != 0 ) //if ( strcmp(G.USERPASS,"1d8b27b21efabcd96571cd56f91a40fb9aa4cc623d273c63bf9223dc6f8cd81f") != 0 )
{ {
LP_millistats_update(&LP_pubkeysloop_stats); LP_millistats_update(&LP_pubkeysloop_stats);
if ( time(NULL) > lasttime+100 ) if ( time(NULL) > lasttime+100 )
@ -918,21 +918,57 @@ void LP_pubkeysloop(void *ctx)
} }
} }
struct LP_pendswap
{
struct LP_pendswap *next,*prev;
uint32_t expiration,requestid,quoteid,finished;
};
struct LP_pendswap *LP_pendingswaps;
void LP_pendswap_add(uint32_t expiration,uint32_t requestid,uint32_t quoteid)
{
struct LP_pendswap *sp;
printf("LP_pendswap_add expiration.%u %u-%u\n",expiration,requestid,quoteid);
portable_mutex_lock(&LP_pendswap_mutex);
sp = calloc(1,sizeof(*sp));
sp->expiration = expiration;
sp->requestid = requestid;
sp->quoteid = quoteid;
DL_APPEND(LP_pendingswaps,sp);
portable_mutex_unlock(&LP_pendswap_mutex);
}
void LP_swapsloop(void *ctx) void LP_swapsloop(void *ctx)
{ {
char *retstr; char *retstr; cJSON *retjson; uint32_t requestid,quoteid; int32_t nonz; struct LP_pendswap *sp,*tmp;
strcpy(LP_swapsloop_stats.name,"LP_swapsloop"); strcpy(LP_swapsloop_stats.name,"LP_swapsloop");
LP_swapsloop_stats.threshold = 605000.; LP_swapsloop_stats.threshold = 605000.;
sleep(50); if ( (retstr= basilisk_swapentry(0,0,1)) != 0 )
{
if ( (retjson= cJSON_Parse(retstr)) != 0 )
{
if ( (requestid= juint(retjson,"requestid")) != 0 && (quoteid= juint(retjson,"quoteid")) != 0 && jobj(retjson,"error") == 0 )
LP_pendswap_add(0,requestid,quoteid);
}
free(retstr);
}
while ( LP_STOP_RECEIVED == 0 ) while ( LP_STOP_RECEIVED == 0 )
{ {
if ( strcmp(G.USERPASS,"1d8b27b21efabcd96571cd56f91a40fb9aa4cc623d273c63bf9223dc6f8cd81f") != 0 ) LP_millistats_update(&LP_swapsloop_stats);
nonz = 0;
DL_FOREACH_SAFE(LP_pendingswaps,sp,tmp)
{ {
LP_millistats_update(&LP_swapsloop_stats); if ( sp->finished == 0 )
if ( (retstr= basilisk_swapentry(0,0,0)) != 0 ) {
free(retstr); nonz++;
sleep(600); if ( (sp->finished= LP_swapwait(0,sp->requestid,sp->quoteid,-1,0)) != 0 )
} else sleep(10); {
}
}
}
if ( nonz == 0 )
sleep(60);
} }
} }
@ -1148,8 +1184,8 @@ int32_t LP_reserved_msg(int32_t priority,char *base,char *rel,bits256 pubkey,cha
} }
if ( skip != 0 ) if ( skip != 0 )
return(-1); return(-1);
if ( strcmp(G.USERPASS,"1d8b27b21efabcd96571cd56f91a40fb9aa4cc623d273c63bf9223dc6f8cd81f") == 0 ) //if ( strcmp(G.USERPASS,"1d8b27b21efabcd96571cd56f91a40fb9aa4cc623d273c63bf9223dc6f8cd81f") == 0 )
return(-1); // return(-1);
if ( priority > 0 && bits256_nonz(pubkey) != 0 ) if ( priority > 0 && bits256_nonz(pubkey) != 0 )
{ {
if ( (pubp= LP_pubkeyfind(pubkey)) != 0 ) if ( (pubp= LP_pubkeyfind(pubkey)) != 0 )
@ -1268,6 +1304,7 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu
portable_mutex_init(&LP_tradesmutex); portable_mutex_init(&LP_tradesmutex);
portable_mutex_init(&LP_commandQmutex); portable_mutex_init(&LP_commandQmutex);
portable_mutex_init(&LP_blockinit_mutex); portable_mutex_init(&LP_blockinit_mutex);
portable_mutex_init(&LP_pendswap_mutex);
myipaddr = clonestr("127.0.0.1"); myipaddr = clonestr("127.0.0.1");
#ifndef _WIN32 #ifndef _WIN32
#ifndef FROM_JS #ifndef FROM_JS
@ -1403,14 +1440,14 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu
printf("error launching LP_tradessloop for ctx.%p\n",ctx); printf("error launching LP_tradessloop for ctx.%p\n",ctx);
exit(-1); exit(-1);
} }
if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_swapsloop,ctx) != 0 ) if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_commandQ_loop,ctx) != 0 )
{ {
printf("error launching LP_swapsloop for ctx.%p\n",ctx); printf("error launching LP_commandQ_loop for ctx.%p\n",ctx);
exit(-1); exit(-1);
} }
if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_commandQ_loop,ctx) != 0 ) if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_swapsloop,ctx) != 0 )
{ {
printf("error launching LP_commandQ_loop for ctx.%p\n",ctx); printf("error launching LP_swapsloop for ctx.%p\n",ctx);
exit(-1); exit(-1);
} }
int32_t nonz,didremote=0; int32_t nonz,didremote=0;
@ -1420,7 +1457,7 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu
{ {
nonz = 0; nonz = 0;
G.waiting = 1; G.waiting = 1;
while ( G.initializing != 0 && strcmp(G.USERPASS,"1d8b27b21efabcd96571cd56f91a40fb9aa4cc623d273c63bf9223dc6f8cd81f") == 0 ) while ( G.initializing != 0 ) //&& strcmp(G.USERPASS,"1d8b27b21efabcd96571cd56f91a40fb9aa4cc623d273c63bf9223dc6f8cd81f") == 0 )
{ {
//fprintf(stderr,"."); //fprintf(stderr,".");
sleep(3); sleep(3);

4
iguana/exchanges/LP_network.c

@ -613,7 +613,9 @@ void LP_psockloop(void *_ptr)
} // else printf("num pfds.%d retval.%d\n",n,retval); } // else printf("num pfds.%d retval.%d\n",n,retval);
} }
} }
if ( IAMLP != 0 && sendsock < 0 ) if ( sendsock < 0 )
usleep(10000);
if ( 0 && IAMLP != 0 && sendsock < 0 )
{ {
usleep(30000); usleep(30000);
for (i=nonz=0; i<Numpsocks; i++) for (i=nonz=0; i<Numpsocks; i++)

4
iguana/exchanges/LP_ordermatch.c

@ -434,13 +434,13 @@ struct LP_utxoinfo *LP_address_myutxopair(struct LP_utxoinfo *butxo,int32_t iamb
return(butxo); return(butxo);
} else printf("cant find utxos[mini %d]\n",mini); } else printf("cant find utxos[mini %d]\n",mini);
} //else printf("cant find targetval2 %.8f\n",dstr(targetval2)); } //else printf("cant find targetval2 %.8f\n",dstr(targetval2));
} else printf("failed ratio test %.8f\n",(double)up->U.value/targetval); } //else printf("failed ratio test %.8f\n",(double)up->U.value/targetval);
} else if ( targetval != 0 && mini >= 0 ) } else if ( targetval != 0 && mini >= 0 )
printf("targetval %.8f mini.%d\n",dstr(targetval),mini); printf("targetval %.8f mini.%d\n",dstr(targetval),mini);
if ( targetval == 0 || mini < 0 ) if ( targetval == 0 || mini < 0 )
break; break;
} }
} else printf("no %s %s utxos pass LP_address_utxo_ptrs filter\n",coin->symbol,coinaddr); } else printf("no %s %s utxos pass LP_address_utxo_ptrs filter %.8f %.8f\n",coin->symbol,coinaddr,dstr(targetval),dstr(targetval2));
} else printf("address_myutxopair couldnt find %s %s\n",coin->symbol,coinaddr); } else printf("address_myutxopair couldnt find %s %s\n",coin->symbol,coinaddr);
return(0); return(0);
} }

2
iguana/exchanges/LP_peers.c

@ -63,7 +63,7 @@ void LP_cmdchannel(struct LP_peerinfo *peer)
#ifdef LP_DONT_CMDCHANNEL #ifdef LP_DONT_CMDCHANNEL
return; return;
#endif #endif
if ( bits256_nonz(G.LP_mypub25519) == 0 || strcmp(G.USERPASS,"1d8b27b21efabcd96571cd56f91a40fb9aa4cc623d273c63bf9223dc6f8cd81f") == 0 ) if ( bits256_nonz(G.LP_mypub25519) == 0 ) //|| strcmp(G.USERPASS,"1d8b27b21efabcd96571cd56f91a40fb9aa4cc623d273c63bf9223dc6f8cd81f") == 0 )
return; return;
if ( (cmdport= LP_psock_get(connectaddr,publicaddr,1,1,peer->ipaddr)) != 0 ) if ( (cmdport= LP_psock_get(connectaddr,publicaddr,1,1,peer->ipaddr)) != 0 )
{ {

8
iguana/exchanges/LP_portfolio.c

@ -540,7 +540,15 @@ void LP_autoprice_iter(void *ctx,struct LP_priceinfo *btcpp)
{ {
price = (bidprice + askprice) * 0.5; price = (bidprice + askprice) * 0.5;
bidprice = (1. / price * (1. + buymargin)); bidprice = (1. / price * (1. + buymargin));
if ( LP_autorefs[i].lastbid < SMALLVAL )
LP_autorefs[i].lastbid = bidprice;
else LP_autorefs[i].lastbid = (LP_autorefs[i].lastbid * 0.9) + (0.1 * bidprice);
bidprice = LP_autorefs[i].lastbid;
askprice = price * (1. + sellmargin); askprice = price * (1. + sellmargin);
if ( LP_autorefs[i].lastask < SMALLVAL )
LP_autorefs[i].lastask = askprice;
else LP_autorefs[i].lastask = (LP_autorefs[i].lastask * 0.9) + (0.1 * askprice);
askprice = LP_autorefs[i].lastask;
LP_mypriceset(&changed,rel,base,bidprice); LP_mypriceset(&changed,rel,base,bidprice);
LP_pricepings(ctx,LP_myipaddr,LP_mypubsock,rel,base,bidprice); LP_pricepings(ctx,LP_myipaddr,LP_mypubsock,rel,base,bidprice);
LP_mypriceset(&changed,base,rel,askprice); LP_mypriceset(&changed,base,rel,askprice);

14
iguana/exchanges/LP_prices.c

@ -512,7 +512,7 @@ char *LP_myprices()
int32_t LP_mypriceset(int32_t *changedp,char *base,char *rel,double price) int32_t LP_mypriceset(int32_t *changedp,char *base,char *rel,double price)
{ {
struct LP_priceinfo *basepp,*relpp; struct LP_pubkey_info *pubp; double minprice,maxprice; struct LP_priceinfo *basepp,*relpp; struct LP_pubkey_info *pubp; double minprice,maxprice,margin,buymargin,sellmargin;
*changedp = 0; *changedp = 0;
//if ( strcmp("DEX",base) == 0 || strcmp("DEX",rel) == 0 ) //if ( strcmp("DEX",base) == 0 || strcmp("DEX",rel) == 0 )
// printf("%s/%s setprice %.8f\n",base,rel,price); // printf("%s/%s setprice %.8f\n",base,rel,price);
@ -521,6 +521,9 @@ int32_t LP_mypriceset(int32_t *changedp,char *base,char *rel,double price)
if ( price == 0. || fabs(basepp->myprices[relpp->ind] - price)/price > 0.001 ) if ( price == 0. || fabs(basepp->myprices[relpp->ind] - price)/price > 0.001 )
*changedp = 1; *changedp = 1;
sellmargin = relpp->sellmargins[basepp->ind];
buymargin = relpp->buymargins[basepp->ind];
margin = (sellmargin + buymargin) * 0.5;
if ( price == 0. ) if ( price == 0. )
{ {
relpp->minprices[basepp->ind] = 0.; relpp->minprices[basepp->ind] = 0.;
@ -529,18 +532,19 @@ int32_t LP_mypriceset(int32_t *changedp,char *base,char *rel,double price)
relpp->sellmargins[basepp->ind] = 0.; relpp->sellmargins[basepp->ind] = 0.;
relpp->offsets[basepp->ind] = 0.; relpp->offsets[basepp->ind] = 0.;
relpp->factors[basepp->ind] = 0.; relpp->factors[basepp->ind] = 0.;
margin = 0.;
} }
else if ( (minprice= basepp->minprices[relpp->ind]) > SMALLVAL && price < minprice ) else if ( (minprice= basepp->minprices[relpp->ind]) > SMALLVAL && price < minprice )
{ {
printf("%s/%s price %.8f less than minprice %.8f\n",base,rel,price,minprice); //printf("%s/%s price %.8f less than minprice %.8f\n",base,rel,price,minprice);
price = minprice; price = minprice * (1. - margin);
} }
else if ( (maxprice= relpp->minprices[basepp->ind]) > SMALLVAL ) else if ( (maxprice= relpp->minprices[basepp->ind]) > SMALLVAL )
{ {
if ( price > (1. / maxprice) ) if ( price > (1. / maxprice) )
{ {
printf("%s/%s price %.8f less than maxprice %.8f, more than %.8f\n",base,rel,price,maxprice,1./maxprice); //printf("%s/%s price %.8f less than maxprice %.8f, more than %.8f\n",base,rel,price,maxprice,1./maxprice);
price = (1. / maxprice); price = (1. / maxprice) * (1. + margin);
} }
} }
/*else if ( basepp->myprices[relpp->ind] > SMALLVAL ) /*else if ( basepp->myprices[relpp->ind] > SMALLVAL )

19
iguana/exchanges/LP_remember.c

@ -395,7 +395,7 @@ int32_t basilisk_isbobcoin(int32_t iambob,int32_t ind)
} }
} }
int32_t basilisk_swap_isfinished(uint32_t expiration,int32_t iambob,bits256 *txids,int32_t *sentflags,bits256 paymentspent,bits256 Apaymentspent,bits256 depositspent) int32_t basilisk_swap_isfinished(uint32_t requestid,uint32_t quoteid,uint32_t expiration,int32_t iambob,bits256 *txids,int32_t *sentflags,bits256 paymentspent,bits256 Apaymentspent,bits256 depositspent)
{ {
int32_t i,n = 0; uint32_t now = (uint32_t)time(NULL); int32_t i,n = 0; uint32_t now = (uint32_t)time(NULL);
if ( bits256_nonz(paymentspent) != 0 && bits256_nonz(Apaymentspent) != 0 && bits256_nonz(depositspent) != 0 ) if ( bits256_nonz(paymentspent) != 0 && bits256_nonz(Apaymentspent) != 0 && bits256_nonz(depositspent) != 0 )
@ -404,7 +404,7 @@ int32_t basilisk_swap_isfinished(uint32_t expiration,int32_t iambob,bits256 *txi
{ {
if ( sentflags[BASILISK_ALICECLAIM] != 0 ) if ( sentflags[BASILISK_ALICECLAIM] != 0 )
{ {
printf("edge case unspendable alicepayment\n"); printf("edge case unspendable alicepayment %u-%u\n",requestid,quoteid);
return(1); return(1);
} }
else if ( iambob != 0 && sentflags[BASILISK_ALICECLAIM] != 0 ) else if ( iambob != 0 && sentflags[BASILISK_ALICECLAIM] != 0 )
@ -447,7 +447,7 @@ int32_t basilisk_swap_isfinished(uint32_t expiration,int32_t iambob,bits256 *txi
if ( bits256_nonz(depositspent) != 0 ) if ( bits256_nonz(depositspent) != 0 )
{ {
if ( bits256_nonz(Apaymentspent) == 0 && sentflags[BASILISK_BOBREFUND] == 0 ) if ( bits256_nonz(Apaymentspent) == 0 && sentflags[BASILISK_BOBREFUND] == 0 )
printf("bob was too late in claiming bobrefund\n"); printf("bob was too late in claiming bobrefund %u-%u\n",requestid,quoteid);
return(1); return(1);
} }
} }
@ -756,7 +756,7 @@ int32_t LP_rswap_init(struct LP_swap_remember *rswap,uint32_t requestid,uint32_t
} }
free_json(txobj); free_json(txobj);
} }
rswap->origfinishedflag = basilisk_swap_isfinished(rswap->expiration,rswap->iambob,rswap->txids,rswap->sentflags,rswap->paymentspent,rswap->Apaymentspent,rswap->depositspent); rswap->origfinishedflag = basilisk_swap_isfinished(requestid,quoteid,rswap->expiration,rswap->iambob,rswap->txids,rswap->sentflags,rswap->paymentspent,rswap->Apaymentspent,rswap->depositspent);
rswap->finishedflag = rswap->origfinishedflag; rswap->finishedflag = rswap->origfinishedflag;
if ( forceflag != 0 ) if ( forceflag != 0 )
rswap->finishedflag = rswap->origfinishedflag = 0; rswap->finishedflag = rswap->origfinishedflag = 0;
@ -983,6 +983,8 @@ cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requesti
if ( (retjson= cJSON_Parse(fstr)) != 0 ) if ( (retjson= cJSON_Parse(fstr)) != 0 )
{ {
free(fstr); free(fstr);
if ( pendingonly != 0 )
free_json(retjson), retjson = 0;
return(retjson); return(retjson);
} }
free(fstr); free(fstr);
@ -1005,6 +1007,7 @@ cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requesti
//printf("legacy r%u-q%u DB SWAPS.(%u %u) %llu files BOB.(%s) Alice.(%s) src.(%s) dest.(%s)\n",requestid,quoteid,rswap.requestid,rswap.quoteid,(long long)rswap.aliceid,rswap.bobcoin,rswap.alicecoin,rswap.src,rswap.dest); //printf("legacy r%u-q%u DB SWAPS.(%u %u) %llu files BOB.(%s) Alice.(%s) src.(%s) dest.(%s)\n",requestid,quoteid,rswap.requestid,rswap.quoteid,(long long)rswap.aliceid,rswap.bobcoin,rswap.alicecoin,rswap.src,rswap.dest);
cJSON *retjson = cJSON_CreateObject(); cJSON *retjson = cJSON_CreateObject();
jaddstr(retjson,"error","swap never started"); jaddstr(retjson,"error","swap never started");
jaddstr(retjson,"status","finished");
jaddstr(retjson,"bob",rswap.bobcoin); jaddstr(retjson,"bob",rswap.bobcoin);
jaddstr(retjson,"src",rswap.src); jaddstr(retjson,"src",rswap.src);
jaddstr(retjson,"alice",rswap.alicecoin); jaddstr(retjson,"alice",rswap.alicecoin);
@ -1115,7 +1118,7 @@ cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requesti
rswap.paymentspent = basilisk_swap_spendupdate(rswap.iambob,rswap.bobcoin,rswap.bobpaymentaddr,rswap.sentflags,rswap.txids,BASILISK_BOBPAYMENT,BASILISK_ALICESPEND,BASILISK_BOBRECLAIM,0,srcAdest,srcBdest,rswap.Adestaddr,rswap.destaddr); rswap.paymentspent = basilisk_swap_spendupdate(rswap.iambob,rswap.bobcoin,rswap.bobpaymentaddr,rswap.sentflags,rswap.txids,BASILISK_BOBPAYMENT,BASILISK_ALICESPEND,BASILISK_BOBRECLAIM,0,srcAdest,srcBdest,rswap.Adestaddr,rswap.destaddr);
rswap.Apaymentspent = basilisk_swap_spendupdate(rswap.iambob,rswap.alicecoin,rswap.alicepaymentaddr,rswap.sentflags,rswap.txids,BASILISK_ALICEPAYMENT,BASILISK_ALICERECLAIM,BASILISK_BOBSPEND,0,destAdest,destBdest,rswap.Adestaddr,rswap.destaddr); rswap.Apaymentspent = basilisk_swap_spendupdate(rswap.iambob,rswap.alicecoin,rswap.alicepaymentaddr,rswap.sentflags,rswap.txids,BASILISK_ALICEPAYMENT,BASILISK_ALICERECLAIM,BASILISK_BOBSPEND,0,destAdest,destBdest,rswap.Adestaddr,rswap.destaddr);
rswap.depositspent = basilisk_swap_spendupdate(rswap.iambob,rswap.bobcoin,rswap.bobdepositaddr,rswap.sentflags,rswap.txids,BASILISK_BOBDEPOSIT,BASILISK_ALICECLAIM,BASILISK_BOBREFUND,0,srcAdest,srcBdest,rswap.Adestaddr,rswap.destaddr); rswap.depositspent = basilisk_swap_spendupdate(rswap.iambob,rswap.bobcoin,rswap.bobdepositaddr,rswap.sentflags,rswap.txids,BASILISK_BOBDEPOSIT,BASILISK_ALICECLAIM,BASILISK_BOBREFUND,0,srcAdest,srcBdest,rswap.Adestaddr,rswap.destaddr);
rswap.finishedflag = basilisk_swap_isfinished(rswap.expiration,rswap.iambob,rswap.txids,rswap.sentflags,rswap.paymentspent,rswap.Apaymentspent,rswap.depositspent); rswap.finishedflag = basilisk_swap_isfinished(requestid,quoteid,rswap.expiration,rswap.iambob,rswap.txids,rswap.sentflags,rswap.paymentspent,rswap.Apaymentspent,rswap.depositspent);
LP_spends_set(&rswap); LP_spends_set(&rswap);
if ( rswap.iambob == 0 ) if ( rswap.iambob == 0 )
{ {
@ -1250,7 +1253,7 @@ cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requesti
free_json(txoutobj), flag = 0; free_json(txoutobj), flag = 0;
else flag = -1, rswap.paymentspent = deadtxid; else flag = -1, rswap.paymentspent = deadtxid;
} }
if ( flag == 0 && time(NULL) > rswap.expiration+777 ) if ( flag == 0 && time(NULL) > rswap.plocktime+777 )
{ {
// bobreclaim // 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); 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);
@ -1282,7 +1285,7 @@ cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requesti
free_json(txoutobj), flag = 0; free_json(txoutobj), flag = 0;
else flag = -1, rswap.depositspent = deadtxid; else flag = -1, rswap.depositspent = deadtxid;
} }
if ( flag == 0 && (bits256_nonz(rswap.paymentspent) != 0 || time(NULL) > rswap.plocktime+777+120) ) if ( flag == 0 && (bits256_nonz(rswap.Apaymentspent) != 0 || time(NULL) > rswap.dlocktime-777 || (bits256_nonz(rswap.txids[BASILISK_ALICEPAYMENT]) == 0 && time(NULL) > rswap.dlocktime-2*INSTANTDEX_LOCKTIME+777) || (bits256_nonz(rswap.txids[BASILISK_BOBPAYMENT]) == 0 && time(NULL) > rswap.dlocktime-3*INSTANTDEX_LOCKTIME/2)) )
{ {
//printf("do the refund! paymentspent.%s now.%u vs expiration.%u\n",bits256_str(str,rswap.paymentspent),(uint32_t)time(NULL),rswap.expiration); //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 ) //if ( txbytes[BASILISK_BOBREFUND] == 0 )
@ -1322,7 +1325,7 @@ cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requesti
LP_totals_update(rswap.iambob,rswap.alicecoin,rswap.bobcoin,KMDtotals,BTCtotals,rswap.sentflags,rswap.values); LP_totals_update(rswap.iambob,rswap.alicecoin,rswap.bobcoin,KMDtotals,BTCtotals,rswap.sentflags,rswap.values);
if ( (numspent= LP_spends_set(&rswap)) == 3 ) if ( (numspent= LP_spends_set(&rswap)) == 3 )
rswap.finishedflag = 1; rswap.finishedflag = 1;
else rswap.finishedflag = basilisk_swap_isfinished(rswap.expiration,rswap.iambob,rswap.txids,rswap.sentflags,rswap.paymentspent,rswap.Apaymentspent,rswap.depositspent); else rswap.finishedflag = basilisk_swap_isfinished(requestid,quoteid,rswap.expiration,rswap.iambob,rswap.txids,rswap.sentflags,rswap.paymentspent,rswap.Apaymentspent,rswap.depositspent);
if ( rswap.origfinishedflag == 0 && rswap.finishedflag != 0 ) if ( rswap.origfinishedflag == 0 && rswap.finishedflag != 0 )
{ {
char fname[1024],*itemstr; FILE *fp; char fname[1024],*itemstr; FILE *fp;

31
iguana/exchanges/LP_rpc.c

@ -602,14 +602,17 @@ cJSON *LP_importprivkey(char *symbol,char *wifstr,char *label,int32_t flag)
double _LP_getestimatedrate(struct iguana_info *coin) double _LP_getestimatedrate(struct iguana_info *coin)
{ {
char buf[512],*retstr=0; int32_t numblocks; cJSON *errjson,*retjson; double rate = 0.00000020; char buf[512],*retstr=0; int32_t numblocks,err=0; cJSON *errjson,*retjson; double rate = 0.00000020;
if ( coin->rate < 0. || time(NULL) > coin->ratetime+30 ) if ( coin->rate < 0. || time(NULL) > coin->ratetime+30 )
{ {
if ( coin->estimatefeestr[0] == 0 )
strcpy(coin->estimatefeestr,"estimatefee");
numblocks = strcmp(coin->symbol,"BTC") == 0 ? 6 : 2; numblocks = strcmp(coin->symbol,"BTC") == 0 ? 6 : 2;
again:
if ( coin->electrum == 0 ) if ( coin->electrum == 0 )
{ {
sprintf(buf,"[%d]",numblocks); sprintf(buf,"[%d]",numblocks);
retstr = LP_apicall(coin,"estimatefee",buf); retstr = LP_apicall(coin,coin->estimatefeestr,buf);
} }
else else
{ {
@ -621,13 +624,27 @@ double _LP_getestimatedrate(struct iguana_info *coin)
if ( retstr[0] == '{' && (errjson= cJSON_Parse(retstr)) != 0 ) if ( retstr[0] == '{' && (errjson= cJSON_Parse(retstr)) != 0 )
{ {
if ( jobj(errjson,"error") != 0 ) if ( jobj(errjson,"error") != 0 )
{
rate = 0.; rate = 0.;
err++;
}
if ( strcmp(coin->estimatefeestr,"estimatesmartfee") == 0 && (rate= jdouble(errjson,"feerate")) != 0 )
{
printf("extracted feerate %.8f from estimatesmartfee\n",rate);
rate /= 1024.;
}
free_json(errjson); free_json(errjson);
} }
else if ( retstr[0] != '-' ) else if ( retstr[0] != '-' )
{
rate = atof(retstr) / 1024.; rate = atof(retstr) / 1024.;
if ( rate < 0.00000020 ) if ( rate != 0. )
{
if ( strcmp("BTC",coin->symbol) == 0 )
{
if ( rate < 0.00000100 )
rate = 0.00000100;
}
else if ( rate < 0.00000020 )
rate = 0.00000020; rate = 0.00000020;
rate *= 1.5; rate *= 1.5;
if ( coin->electrum != 0 ) if ( coin->electrum != 0 )
@ -638,6 +655,12 @@ double _LP_getestimatedrate(struct iguana_info *coin)
coin->ratetime = (uint32_t)time(NULL); coin->ratetime = (uint32_t)time(NULL);
} }
free(retstr); free(retstr);
if ( err == 1 && coin->electrum == 0 && strcmp("BTC",coin->symbol) == 0 )
{
strcpy(coin->estimatefeestr,"estimatesmartfee");
err = 2;
goto again;
}
} else rate = coin->rate; } else rate = coin->rate;
} else rate = coin->rate; } else rate = coin->rate;
return(rate); return(rate);

2
iguana/exchanges/LP_secp.c

@ -99,7 +99,7 @@ int32_t bitcoin_sign(void *ctx,char *symbol,uint8_t *sig,bits256 txhash2,bits256
} }
if ( strcmp(symbol,"BCH") == 0 || strcmp(symbol,"BTG") == 0 ) if ( strcmp(symbol,"BCH") == 0 || strcmp(symbol,"BTG") == 0 )
{ {
char str[65]; printf("BCH/BTG deterministic signature %s\n",bits256_str(str,txhash2)); //char str[65]; printf("BCH/BTG deterministic signature %s\n",bits256_str(str,txhash2));
funcp = 0; funcp = 0;
entropy = 0; entropy = 0;
} else entropy = extra_entropy.bytes; } else entropy = extra_entropy.bytes;

22
iguana/exchanges/LP_socket.c

@ -527,12 +527,14 @@ cJSON *electrum_address_subscribe(char *symbol,struct electrum_info *ep,cJSON **
cJSON *electrum_scripthash_cmd(char *symbol,uint8_t taddr,struct electrum_info *ep,cJSON **retjsonp,char *cmd,char *coinaddr) cJSON *electrum_scripthash_cmd(char *symbol,uint8_t taddr,struct electrum_info *ep,cJSON **retjsonp,char *cmd,char *coinaddr)
{ {
uint8_t addrtype,rmd160[20]; char scripthash[51],rmdstr[41],cmdbuf[128]; uint8_t addrtype,rmd160[20]; char btcaddr[64],cmdbuf[128]; //char scripthash[51],rmdstr[41],;
bitcoin_addr2rmd160(symbol,taddr,&addrtype,rmd160,coinaddr); bitcoin_addr2rmd160(symbol,taddr,&addrtype,rmd160,coinaddr);
init_hexbytes_noT(rmdstr,rmd160,20); bitcoin_address("BTC",btcaddr,0,addrtype,rmd160,20);
sprintf(scripthash,"76a914%s88ac",rmdstr); //init_hexbytes_noT(rmdstr,rmd160,20);
sprintf(cmdbuf,"blockchain.scripthash.%s",cmd); //sprintf(scripthash,"%s",rmdstr);
return(electrum_strarg(symbol,ep,retjsonp,cmdbuf,scripthash,ELECTRUM_TIMEOUT)); //sprintf(cmdbuf,"blockchain.scripthash.%s",cmd);
sprintf(cmdbuf,"blockchain.address.%s",cmd);
return(electrum_strarg(symbol,ep,retjsonp,cmdbuf,btcaddr,ELECTRUM_TIMEOUT));
} }
cJSON *electrum_address_gethistory(char *symbol,struct electrum_info *ep,cJSON **retjsonp,char *addr,bits256 reftxid) cJSON *electrum_address_gethistory(char *symbol,struct electrum_info *ep,cJSON **retjsonp,char *addr,bits256 reftxid)
@ -637,17 +639,17 @@ cJSON *electrum_address_listunspent(char *symbol,struct electrum_info *ep,cJSON
retstr = jprint(retjson,0); retstr = jprint(retjson,0);
LP_unspents_cache(coin->symbol,addr,retstr,1); LP_unspents_cache(coin->symbol,addr,retstr,1);
free(retstr); free(retstr);
if ( ap != 0 )
{
ap->unspenttime = (uint32_t)time(NULL);
ap->unspentheight = height;
}
} }
else else
{ {
free_json(retjson); free_json(retjson);
retjson = 0; retjson = 0;
} }
if ( ap != 0 )
{
ap->unspenttime = (uint32_t)time(NULL);
ap->unspentheight = height;
}
} }
} }
if ( retjson == 0 ) if ( retjson == 0 )

58
iguana/exchanges/LP_swap.c

@ -725,14 +725,15 @@ uint32_t LP_swapdata_rawtxsend(int32_t pairsock,struct basilisk_swap *swap,uint3
return(0); return(0);
} }
int32_t LP_swapwait(struct basilisk_swap *swap,uint32_t requestid,uint32_t quoteid,int32_t duration,int32_t sleeptime) uint32_t LP_swapwait(uint32_t expiration,uint32_t requestid,uint32_t quoteid,int32_t duration,int32_t sleeptime)
{ {
char *retstr; cJSON *retjson=0; uint32_t expiration = (uint32_t)(time(NULL) + duration); char *retstr; uint32_t finished = 0; cJSON *retjson=0;
printf("wait %d:%d for SWAP.(r%u/q%u) to complete\n",duration,sleeptime,requestid,quoteid); if ( sleeptime != 0 )
sleep(sleeptime/3); {
//if ( sleeptime < divisor*60 ) printf("wait %d:%d for SWAP.(r%u/q%u) to complete\n",duration,sleeptime,requestid,quoteid);
// sleeptime = divisor * 60; sleep(sleeptime/3);
while ( time(NULL) < expiration ) }
while ( expiration == 0 || time(NULL) < expiration )
{ {
if ( (retstr= basilisk_swapentry(requestid,quoteid,1)) != 0 ) if ( (retstr= basilisk_swapentry(requestid,quoteid,1)) != 0 )
{ {
@ -740,31 +741,40 @@ int32_t LP_swapwait(struct basilisk_swap *swap,uint32_t requestid,uint32_t quote
{ {
if ( jstr(retjson,"status") != 0 && strcmp(jstr(retjson,"status"),"finished") == 0 ) if ( jstr(retjson,"status") != 0 && strcmp(jstr(retjson,"status"),"finished") == 0 )
{ {
swap->I.finished = (uint32_t)time(NULL); finished = (uint32_t)time(NULL);
free(retstr);
break; break;
} }
//else printf("NOT FINISHED.(%s)\n",jprint(retjson,0)); else if ( expiration != 0 && time(NULL) > expiration )
printf("NOT FINISHED.(%s)\n",jprint(retjson,0));
free_json(retjson); free_json(retjson);
retjson = 0; retjson = 0;
} }
free(retstr); free(retstr);
} }
sleep(sleeptime); if ( sleeptime != 0 )
//sleep(sleeptime/divisor); sleep(sleeptime);
//if ( divisor > 1 ) if ( duration < 0 )
// divisor--; break;
} }
if ( retjson != 0 ) if ( retjson != 0 )
{ {
printf("\n>>>>>>>>>>>>>>>>>>>>>>>>>\nSWAP completed! %u-%u %s\n",requestid,quoteid,jprint(retjson,0));
free_json(retjson); free_json(retjson);
if ( 0 && (retstr= basilisk_swapentry(requestid,quoteid,1)) != 0 ) if ( (retstr= basilisk_swapentry(requestid,quoteid,1)) != 0 )
{ {
printf("second call.(%s)\n",retstr); printf("\n>>>>>>>>>>>>>>>>>>>>>>>>>\nSWAP completed! %u-%u %s\n",requestid,quoteid,retstr);
free(retstr); free(retstr);
} }
return(finished);
}
else
{
if ( expiration != 0 && time(NULL) > expiration )
printf("\nSWAP did not complete! %u-%u %s\n",requestid,quoteid,jprint(retjson,0));
if ( duration > 0 )
LP_pendswap_add(expiration,requestid,quoteid);
return(0); return(0);
} else return(-1); }
} }
void LP_bobloop(void *_swap) void LP_bobloop(void *_swap)
@ -826,16 +836,17 @@ void LP_bobloop(void *_swap)
basilisk_bobpayment_reclaim(swap,swap->I.callduration); basilisk_bobpayment_reclaim(swap,swap->I.callduration);
if ( swap->N.pair >= 0 ) if ( swap->N.pair >= 0 )
nn_close(swap->N.pair), swap->N.pair = -1; nn_close(swap->N.pair), swap->N.pair = -1;
LP_swap_endcritical = (uint32_t)time(NULL);
LP_swapwait(swap,swap->I.req.requestid,swap->I.req.quoteid,LP_atomic_locktime(swap->I.bobstr,swap->I.alicestr)*2,swap->I.aliceconfirms == 0 ? 3 : 30);
} }
} }
} }
} else printf("swap timed out\n"); } else printf("swap timed out\n");
G.LP_pendingswaps--; LP_swap_endcritical = (uint32_t)time(NULL);
LP_pendswap_add(swap->I.expiration,swap->I.req.requestid,swap->I.req.quoteid);
//swap->I.finished = LP_swapwait(swap->I.expiration,swap->I.req.requestid,swap->I.req.quoteid,LP_atomic_locktime(swap->I.bobstr,swap->I.alicestr)*3,swap->I.aliceconfirms == 0 ? 3 : 30);
basilisk_swap_finished(swap); basilisk_swap_finished(swap);
free(swap); free(swap);
free(data); free(data);
G.LP_pendingswaps--;
} }
void LP_aliceloop(void *_swap) void LP_aliceloop(void *_swap)
@ -909,16 +920,17 @@ void LP_aliceloop(void *_swap)
}*/ }*/
if ( swap->N.pair >= 0 ) if ( swap->N.pair >= 0 )
nn_close(swap->N.pair), swap->N.pair = -1; nn_close(swap->N.pair), swap->N.pair = -1;
LP_swap_endcritical = (uint32_t)time(NULL);
LP_swapwait(swap,swap->I.req.requestid,swap->I.req.quoteid,LP_atomic_locktime(swap->I.bobstr,swap->I.alicestr)*2,swap->I.aliceconfirms == 0 ? 3 : 30);
} }
} }
} }
} }
} }
free(data); LP_swap_endcritical = (uint32_t)time(NULL);
LP_pendswap_add(swap->I.expiration,swap->I.req.requestid,swap->I.req.quoteid);
//swap->I.finished = LP_swapwait(swap->I.expiration,swap->I.req.requestid,swap->I.req.quoteid,LP_atomic_locktime(swap->I.bobstr,swap->I.alicestr)*3,swap->I.aliceconfirms == 0 ? 3 : 30);
basilisk_swap_finished(swap); basilisk_swap_finished(swap);
free(swap); free(swap);
free(data);
G.LP_pendingswaps--; G.LP_pendingswaps--;
} }

2
iguana/exchanges/auto_chipsbtc

@ -1,2 +1,2 @@
source userpass source userpass
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\"}" curl --url "http://127.0.0.1:7783" --data "{\"minprice\":0.0001,\"maxprice\":0.0002,\"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 source userpass
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\"}" curl --url "http://127.0.0.1:7783" --data "{\"minprice\":0.2,\"maxprice\":0.4,\"userpass\":\"$userpass\",\"method\":\"autoprice\",\"base\":\"CHIPS\",\"rel\":\"KMD\",\"margin\":0.05,\"refbase\":\"chips\",\"refrel\":\"coinmarketcap\"}"

3
iguana/exchanges/calcaddress

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

3
iguana/exchanges/coins

File diff suppressed because one or more lines are too long

83
iguana/exchanges/mm.c

@ -111,9 +111,52 @@ void LP_main(void *ptr)
} }
} }
int32_t ensure_writable(char *dirname)
{
char fname[512],str[65],str2[65]; bits256 r,check; FILE *fp;
OS_randombytes(r.bytes,sizeof(r));
sprintf(fname,"%s/checkval",dirname), OS_compatible_path(fname);
if ( (fp= fopen(fname,"wb")) == 0 )
{
printf("FATAL ERROR cant create %s\n",fname);
fprintf(stderr,"FATAL ERROR cant create %s\n",fname);
return(-1);
}
else if ( fwrite(r.bytes,1,sizeof(r),fp) != sizeof(r) )
{
printf("FATAL ERROR error writing %s\n",fname);
fprintf(stderr,"FATAL ERROR writing %s\n",fname);
return(-1);
}
else
{
fclose(fp);
if ( (fp= fopen(fname,"rb")) == 0 )
{
printf("FATAL ERROR cant open %s\n",fname);
fprintf(stderr,"FATAL ERROR cant open %s\n",fname);
return(-1);
}
else if ( fread(check.bytes,1,sizeof(check),fp) != sizeof(check) )
{
printf("FATAL ERROR error reading %s\n",fname);
fprintf(stderr,"FATAL ERROR reading %s\n",fname);
return(-1);
}
else if ( memcmp(check.bytes,r.bytes,sizeof(r)) != 0 )
{
printf("FATAL ERROR error comparint %s %s vs %s\n",fname,bits256_str(str,r),bits256_str(str2,check));
fprintf(stderr,"FATAL ERROR error comparint %s %s vs %s\n",fname,bits256_str(str,r),bits256_str(str2,check));
return(-1);
}
fclose(fp);
}
return(0);
}
int main(int argc, const char * argv[]) int main(int argc, const char * argv[])
{ {
char dirname[512],*passphrase; double incr; cJSON *retjson; char dirname[512]; double incr; cJSON *retjson;
OS_init(); OS_init();
if ( strstr(argv[0],"btc2kmd") != 0 && argv[1] != 0 ) if ( strstr(argv[0],"btc2kmd") != 0 && argv[1] != 0 )
{ {
@ -192,7 +235,7 @@ int main(int argc, const char * argv[])
} }
else if ( argv[1] != 0 && strcmp(argv[1],"airdropH") == 0 && argv[2] != 0 ) else if ( argv[1] != 0 && strcmp(argv[1],"airdropH") == 0 && argv[2] != 0 )
{ {
FILE *fp; double val,total = 0.; uint8_t checktype,addrtype,rmd160[21],checkrmd160[21]; char buf[256],checkaddr[64],coinaddr[64],manystrs[64][128],cmd[64*128]; int32_t n,i,num; char *flag; FILE *fp; double val,total = 0.; uint8_t checktype,addrtype,rmd160[21],checkrmd160[21]; char *floatstr,*addrstr,buf[256],checkaddr[64],coinaddr[64],manystrs[64][128],cmd[64*128]; int32_t n,i,num; char *flag;
if ( (fp= fopen(argv[2],"rb")) != 0 ) if ( (fp= fopen(argv[2],"rb")) != 0 )
{ {
num = 0; num = 0;
@ -212,22 +255,26 @@ int main(int argc, const char * argv[])
} }
if ( flag != 0 ) if ( flag != 0 )
{ {
bitcoin_addr2rmd160("HUSH",28,&addrtype,rmd160,buf); addrstr = flag, floatstr = buf;
bitcoin_address("KMD",coinaddr,0,addrtype == 184 ? 60 : 85,rmd160,20); //addrstr = buf, floatstr = flag;
//bitcoin_addr2rmd160("HUSH",28,&addrtype,rmd160,buf);
bitcoin_addr2rmd160("BTC",0,&addrtype,rmd160,addrstr);
bitcoin_address("KMD",coinaddr,0,addrtype == 0 ? 60 : 85,rmd160,20);
bitcoin_addr2rmd160("KMD",0,&checktype,checkrmd160,coinaddr); bitcoin_addr2rmd160("KMD",0,&checktype,checkrmd160,coinaddr);
bitcoin_address("HUSH",checkaddr,28,checktype == 60 ? 184 : 189,checkrmd160,20); //bitcoin_address("HUSH",checkaddr,28,checktype == 60 ? 184 : 189,checkrmd160,20);
if ( memcmp(rmd160,checkrmd160,20) != 0 || strcmp(buf,checkaddr) != 0 ) bitcoin_address("BTC",checkaddr,0,checktype == 60 ? 0 : 5,checkrmd160,20);
if ( memcmp(rmd160,checkrmd160,20) != 0 || strcmp(addrstr,checkaddr) != 0 )
{ {
for (i=0; i<20; i++) for (i=0; i<20; i++)
printf("%02x",rmd160[i]); printf("%02x",rmd160[i]);
printf(" vs. "); printf(" vs. ");
for (i=0; i<20; i++) for (i=0; i<20; i++)
printf("%02x",checkrmd160[i]); printf("%02x",checkrmd160[i]);
printf(" address calc error (%s).%d -> (%s).%d -> (%s) %.8f?\n",buf,addrtype,coinaddr,checktype,checkaddr,atof(flag)); printf(" address calc error (%s).%d -> (%s).%d -> (%s) %.8f?\n",addrstr,addrtype,coinaddr,checktype,checkaddr,atof(floatstr));
} }
else else
{ {
val = atof(flag); val = atof(floatstr);
sprintf(manystrs[num++],"\\\"%s\\\":%0.8f",coinaddr,val); sprintf(manystrs[num++],"\\\"%s\\\":%0.8f",coinaddr,val);
if ( num >= sizeof(manystrs)/sizeof(*manystrs) ) if ( num >= sizeof(manystrs)/sizeof(*manystrs) )
{ {
@ -235,12 +282,12 @@ int main(int argc, const char * argv[])
for (i=0; i<num; i++) for (i=0; i<num; i++)
sprintf(cmd + strlen(cmd),"%s%s",manystrs[i],i<num-1?",":""); sprintf(cmd + strlen(cmd),"%s%s",manystrs[i],i<num-1?",":"");
strcat(cmd,"}\" 0"); strcat(cmd,"}\" 0");
printf("%s\n",cmd); printf("%s\nsleep 3\n",cmd);
num = 0; num = 0;
memset(manystrs,0,sizeof(manystrs)); memset(manystrs,0,sizeof(manystrs));
} }
total += val; total += val;
//printf("(%s).%d (%s) <- %.8f total %.8f\n",buf,addrtype,coinaddr,val,total); //printf("(%s).%d (%s) <- %.8f (%s) total %.8f\n",addrstr,addrtype,coinaddr,val,floatstr,total);
} }
} else printf("parse error for (%s)\n",buf); } else printf("parse error for (%s)\n",buf);
} }
@ -260,9 +307,17 @@ int main(int argc, const char * argv[])
exit(0); exit(0);
} }
sprintf(dirname,"%s",GLOBAL_DBDIR), OS_ensure_directory(dirname); sprintf(dirname,"%s",GLOBAL_DBDIR), OS_ensure_directory(dirname);
if ( ensure_writable(dirname) < 0 )
exit(0);
sprintf(dirname,"%s/SWAPS",GLOBAL_DBDIR), OS_ensure_directory(dirname); sprintf(dirname,"%s/SWAPS",GLOBAL_DBDIR), OS_ensure_directory(dirname);
if ( ensure_writable(dirname) < 0 )
exit(0);
sprintf(dirname,"%s/PRICES",GLOBAL_DBDIR), OS_ensure_directory(dirname); sprintf(dirname,"%s/PRICES",GLOBAL_DBDIR), OS_ensure_directory(dirname);
if ( ensure_writable(dirname) < 0 )
exit(0);
sprintf(dirname,"%s/UNSPENTS",GLOBAL_DBDIR), OS_ensure_directory(dirname); sprintf(dirname,"%s/UNSPENTS",GLOBAL_DBDIR), OS_ensure_directory(dirname);
if ( ensure_writable(dirname) < 0 )
exit(0);
#ifdef FROM_JS #ifdef FROM_JS
argc = 2; argc = 2;
retjson = cJSON_Parse("{\"client\":1,\"passphrase\":\"test\"}"); retjson = cJSON_Parse("{\"client\":1,\"passphrase\":\"test\"}");
@ -283,10 +338,10 @@ int main(int argc, const char * argv[])
DOCKERFLAG = 1; DOCKERFLAG = 1;
else if ( jstr(retjson,"docker") != 0 ) else if ( jstr(retjson,"docker") != 0 )
DOCKERFLAG = (uint32_t)calc_ipbits(jstr(retjson,"docker")); DOCKERFLAG = (uint32_t)calc_ipbits(jstr(retjson,"docker"));
if ( jobj(retjson,"passphrase") != 0 ) //if ( jobj(retjson,"passphrase") != 0 )
jdelete(retjson,"passphrase"); // jdelete(retjson,"passphrase");
if ( (passphrase= jstr(retjson,"passphrase")) == 0 ) //if ( (passphrase= jstr(retjson,"passphrase")) == 0 )
jaddstr(retjson,"passphrase","default"); // jaddstr(retjson,"passphrase","default");
if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_main,(void *)retjson) != 0 ) 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)); printf("error launching LP_main (%s)\n",jprint(retjson,0));

2
iguana/exchanges/mshark

@ -1,4 +1,4 @@
#!/bin/bash #!/bin/bash
source userpass source userpass
# this will only work for watchonly addresses that have been rescanned and with active coins # this will only work for watchonly addresses that have been rescanned and with active coins
curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"fundvalue\",\"address\":\"RTu3JZZKLJTcfNwBa19dWRagEfQq49STqC\",\"holdings\":[{\"coin\":\"iota\",\"balance\":1500000}, {\"coin\":\"bitcoin-cash\",\"balance\":1200}, {\"coin\":\"bitcoin\",\"balance\":145}],\"divisor\":1400000}" curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"fundvalue\",\"address\":\"RTu3JZZKLJTcfNwBa19dWRagEfQq49STqC\",\"holdings\":[{\"coin\":\"iota\",\"balance\":1500000}, {\"coin\":\"bitcoin-cash\",\"balance\":1200}, {\"coin\":\"bitcoin\",\"balance\":137}, {\"coin\":\"chips\",\"balance\":100000}],\"divisor\":1400000}"

4
iguana/exchanges/prices/bet

@ -1,3 +1,3 @@
coin=BET coin=BET
price=0.0005 price=0.00075
invprice=2000 invprice=1333.33

2
iguana/exchanges/run

@ -6,4 +6,4 @@ git pull;
cd ..; cd ..;
./m_mm; ./m_mm;
pkill -15 marketmaker; pkill -15 marketmaker;
$1 ./marketmaker "{\"gui\":\"nogui\", \"profitmargin\":0.01, \"userhome\":\"/${HOME#"/"}\", \"passphrase\":\"$passphrase\", \"coins\":$coins}" & stdbuf -oL $1 ./marketmaker "{\"gui\":\"nogui\", \"profitmargin\":0.01, \"userhome\":\"/${HOME#"/"}\", \"passphrase\":\"$passphrase\", \"coins\":$coins}" &

15
iguana/iguana_notary.c

@ -135,7 +135,7 @@ int32_t dpow_hasnotarization(struct supernet_info *myinfo,struct iguana_info *co
void dpow_srcupdate(struct supernet_info *myinfo,struct dpow_info *dp,int32_t height,bits256 hash,uint32_t timestamp,uint32_t blocktime) void dpow_srcupdate(struct supernet_info *myinfo,struct dpow_info *dp,int32_t height,bits256 hash,uint32_t timestamp,uint32_t blocktime)
{ {
void **ptrs; char str[65]; cJSON *blockjson; struct iguana_info *coin; struct dpow_checkpoint checkpoint; int32_t freq,minsigs; //uint8_t pubkeys[64][33]; void **ptrs; char str[65]; cJSON *blockjson; struct iguana_info *coin; struct dpow_checkpoint checkpoint; int32_t freq,minsigs,i,ht; struct dpow_block *bp;
dpow_checkpointset(myinfo,&dp->last,height,hash,timestamp,blocktime); dpow_checkpointset(myinfo,&dp->last,height,hash,timestamp,blocktime);
checkpoint = dp->srcfifo[dp->srcconfirms]; checkpoint = dp->srcfifo[dp->srcconfirms];
if ( strcmp("BTC",dp->dest) == 0 ) if ( strcmp("BTC",dp->dest) == 0 )
@ -203,9 +203,22 @@ void dpow_srcupdate(struct supernet_info *myinfo,struct dpow_info *dp,int32_t he
ptrs[4] = 0; ptrs[4] = 0;
memcpy(&ptrs[5],&checkpoint,sizeof(checkpoint)); memcpy(&ptrs[5],&checkpoint,sizeof(checkpoint));
dp->activehash = checkpoint.blockhash.hash; dp->activehash = checkpoint.blockhash.hash;
ht = checkpoint.blockhash.height;
if ( OS_thread_create((void *)((uint64_t)&ptrs[5] + sizeof(struct dpow_checkpoint)),NULL,(void *)dpow_statemachinestart,(void *)ptrs) != 0 ) if ( OS_thread_create((void *)((uint64_t)&ptrs[5] + sizeof(struct dpow_checkpoint)),NULL,(void *)dpow_statemachinestart,(void *)ptrs) != 0 )
{ {
} }
if ( ht > 100 )
{
for (i=ht-100; i>=0; i--)
{
if ( (bp= dp->blocks[i]) != 0 )
{
dp->blocks[i] = 0;
Numallocated--;
free(bp);
}
}
}
} }
} }

2
iguana/iguana_payments.c

@ -462,6 +462,8 @@ char *iguana_calcrawtx(struct supernet_info *myinfo,struct iguana_info *coin,cJS
printf("no spendscriptstr %d.(%s)\n",i,jprint(array,0)); printf("no spendscriptstr %d.(%s)\n",i,jprint(array,0));
continue; continue;
} }
if ( strlen(spendscriptstr) != 50 || strncmp("76a914",spendscriptstr,6) != 0 || strcmp("88ac",&spendscriptstr[50-4]) != 0 )
continue;
unspents = realloc(unspents,(1 + max) * sizeof(*unspents)); unspents = realloc(unspents,(1 + max) * sizeof(*unspents));
value = jdouble(item,"amount") * SATOSHIDEN; value = jdouble(item,"amount") * SATOSHIDEN;
if ( (0) && jdouble(item,"interest") != 0 ) if ( (0) && jdouble(item,"interest") != 0 )

13
iguana/m_mm

@ -1,14 +1,11 @@
#!/bin/bash
cd secp256k1; ./m_unix; cd .. cd secp256k1; ./m_unix; cd ..
cd ../crypto777; ./m_LP; cd ../iguana cd ../crypto777; ./m_LP; cd ../iguana
if [[ "$OSTYPE" == "linux-gnu" ]]; then nanomsg_lib="-lnanomsg"
echo "Linux"
# Default is dynamic nanomsg for linux using this script # Build static libnanomsg on macOS
nanomsg_lib="-lnanomsg" if [[ "$OSTYPE" == "darwin"* ]]; then
elif [[ "$OSTYPE" == "darwin"* ]]; then
# Mac OSX
echo "Mac OSX"
# on osx this script generates static libnanomsg and uses it to compile static marketmaker binary
./build_static_nanomsg.sh ./build_static_nanomsg.sh
nanomsg_lib="../OSlibs/osx/$(uname -m)/libnanomsg-static.a" nanomsg_lib="../OSlibs/osx/$(uname -m)/libnanomsg-static.a"
fi fi

89
marketmaker_build_depends.cmd

@ -0,0 +1,89 @@
@echo off
rem [ Decker] Automatically download and build depends script for marketmaker.
rem
rem 1. Requires installed CMake for Windows (!)
rem 2. Currently build only 64-bit release versions of .lib and .dll
rem 3. Libraries available: pthreads, nanomsg, curl
@REM Check for Visual Studio
call set "VSPATH="
if defined VS140COMNTOOLS ( if not defined VSPATH (
call set "VSPATH=%%VS140COMNTOOLS%%"
) )
@REM check if we already have the tools in the environment
if exist "%VCINSTALLDIR%" (
goto compile
)
if not defined VSPATH (
echo You need Microsoft Visual Studio 15 installed
pause
exit
)
@REM set up the environment
if exist "%VSPATH%..\..\vc\vcvarsall.bat" (
call "%%VSPATH%%..\..\vc\vcvarsall.bat" amd64
goto compile
)
echo Unable to set up the environment
pause
exit
:compile
rem MSBuild /help
echo.
echo Decker will automatically download and build all needed *.dll and *.lib for you ;)
timeout /t 5 /nobreak
mkdir marketmaker_depends
mkdir x64\Release
rem --- pthreads ---
:compile_pthreads
cd marketmaker_depends
git clone https://github.com/DeckerSU/pthread-win32
cd pthread-win32
MSBuild pthread.2015.sln /t:Rebuild /p:Configuration=Release /p:Platform=Win32
MSBuild pthread.2015.sln /t:Rebuild /p:Configuration=Release /p:Platform=x64
cd ../..
copy marketmaker_depends\pthread-win32\bin\x64_MSVC2015.Release\pthread_lib.lib OSlibs\win\x64\pthread_lib.lib
rem --- nanomsg ---
:compile_nanomsg
cd marketmaker_depends
git clone https://github.com/nanomsg/nanomsg
cd nanomsg
mkdir build_msvc_2015_win32
mkdir build_msvc_2015_win64
cd build_msvc_2015_win64
cmake -G "Visual Studio 14 2015 Win64" ..
cmake --build . --config Release --target nanomsg
cd ../../..
copy marketmaker_depends\nanomsg\build_msvc_2015_win64\Release\nanomsg.lib OSlibs\win\x64\release\nanomsg.lib
copy marketmaker_depends\nanomsg\build_msvc_2015_win64\Release\nanomsg.exp OSlibs\win\x64\release\nanomsg.exp
copy marketmaker_depends\nanomsg\build_msvc_2015_win64\Release\nanomsg.dll x64\Release\nanomsg.dll
rem --- curl ---
:compile_curl
cd marketmaker_depends
git clone https://github.com/curl/curl
cd curl
mkdir build_msvc_2015_win32
mkdir build_msvc_2015_win64
cd build_msvc_2015_win64
cmake -G "Visual Studio 14 2015 Win64" ..
cmake --build . --config Release --target libcurl
rem cmake .. -G"Visual Studio 14 2015 Win64" -DCURL_STATICLIB=ON -DCURL_DISABLE_LDAP=ON -DCURL_STATIC_CRT=ON
rem cmake .. -G"Visual Studio 14 2015 Win64" -DCURL_STATICLIB:BOOL=ON -DCURL_STATIC_CRT:BOOL=ON -DHTTP_ONLY:BOOL=ON -DCMAKE_BUILD_TYPE:STRING=RELEASE ..
rem cmake --build . --config Release
rem cmake --build . --config Release --target libcurl
cd ../../..
copy marketmaker_depends\curl\build_msvc_2015_win64\lib\Release\libcurl_imp.lib OSlibs\win\x64\release\libcurl.lib
copy marketmaker_depends\curl\build_msvc_2015_win64\lib\Release\libcurl_imp.exp OSlibs\win\x64\release\libcurl.exp
copy marketmaker_depends\curl\build_msvc_2015_win64\lib\Release\libcurl.dll x64\Release\libcurl.dll
Loading…
Cancel
Save