Browse Source

Merge pull request #588 from jl777/dPoW

swap recovery
master
jl777 7 years ago
committed by GitHub
parent
commit
62a48de2f8
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      .gitignore
  2. 2
      crypto777/bitcoind_RPC.c
  3. 45
      iguana/build_static_nanomsg.sh
  4. 6
      iguana/exchanges/LP_commands.c
  5. 5
      iguana/exchanges/LP_include.h
  6. 30
      iguana/exchanges/LP_nativeDEX.c
  7. 46
      iguana/exchanges/LP_network.c
  8. 3
      iguana/exchanges/LP_ordermatch.c
  9. 232
      iguana/exchanges/LP_remember.c
  10. 2
      iguana/exchanges/LP_scan.c
  11. 33
      iguana/exchanges/LP_socket.c
  12. 2
      iguana/exchanges/LP_stats.c
  13. 3
      iguana/exchanges/LP_transaction.c
  14. 2
      iguana/exchanges/LP_utxo.c
  15. 11
      iguana/exchanges/client_static
  16. 2
      iguana/exchanges/coins
  17. 1
      iguana/exchanges/enable
  18. 2
      iguana/exchanges/fundLP
  19. 2
      iguana/exchanges/install
  20. 1
      iguana/exchanges/prices/autoprice
  21. 4
      iguana/exchanges/to_etomic
  22. 4
      iguana/exchanges/to_zcash
  23. 1
      iguana/m_LP_StaticNanoMsg
  24. 15
      iguana/m_mm

5
.gitignore

@ -3,6 +3,11 @@ x64
agents/iguana.exe agents/iguana.exe
Debug/* Debug/*
iguana/nanomsglib
iguana/nanomsgsrc
OSlibs/linux
OSlibs/osx
iguana/pnacl/Release/iguana_unstripped.pexe iguana/pnacl/Release/iguana_unstripped.pexe
iguana/pnacl/Release/iguana.pexe iguana/pnacl/Release/iguana.pexe

2
crypto777/bitcoind_RPC.c

@ -74,7 +74,7 @@ char *post_process_bitcoind_RPC(char *debugstr,char *command,char *rpcstr,char *
char *retstr = 0; char *retstr = 0;
cJSON *json,*result,*error; cJSON *json,*result,*error;
#ifdef FROM_MARKETMAKER #ifdef FROM_MARKETMAKER
//usleep(500); //usleep(1000);
#endif #endif
//printf("<<<<<<<<<<< bitcoind_RPC: %s post_process_bitcoind_RPC.%s.[%s]\n",debugstr,command,rpcstr); //printf("<<<<<<<<<<< bitcoind_RPC: %s post_process_bitcoind_RPC.%s.[%s]\n",debugstr,command,rpcstr);
if ( command == 0 || rpcstr == 0 || rpcstr[0] == 0 ) if ( command == 0 || rpcstr == 0 || rpcstr[0] == 0 )

45
iguana/build_static_nanomsg.sh

@ -0,0 +1,45 @@
#!/bin/bash
#Check if libnanomsg-static.a file is already exists or not
if [[ "$OSTYPE" == "linux-gnu" ]]; then
echo "Linux"
file="../OSlibs/linux/$(uname -m)/libnanomsg-static.a"
makedir="../OSlibs/linux/$(uname -m)/"
copytarget="../OSlibs/linux/$(uname -m)/libnanomsg-static.a"
elif [[ "$OSTYPE" == "darwin"* ]]; then
# Mac OSX
echo "Mac OSX"
file="../OSlibs/osx/$(uname -m)/libnanomsg-static.a"
makedir="../OSlibs/osx/$(uname -m)/"
copytarget="../OSlibs/osx/$(uname -m)/libnanomsg-static.a"
fi
if [ ! -f "$file" ]
then
echo "$0: File '${file}' not found."
#Download nanomsg library 1.0 stable
rm -rf nanomsgsrc
git clone https://github.com/nanomsg/nanomsg.git nanomsgsrc
#Create destination folder
mkdir nanomsglib
#Switch into nanomsgsrc folder
cd nanomsgsrc
#Create build directory and switch into it
mkdir build && cd build
#Compile
cmake .. -DCMAKE_INSTALL_PREFIX=../../nanomsglib/ -DCMAKE_BUILD_TYPE=Debug -DNN_STATIC_LIB=1
cmake --build .
ctest -C Debug .
cmake --build . --target install
cd ../..
pwd
mkdir -p $makedir
cp -av nanomsglib/lib/libnanomsg.a $copytarget
fi

6
iguana/exchanges/LP_commands.c

@ -426,7 +426,7 @@ jpg(srcfile, destfile, power2=7, password, data="", required, ind=0)\n\
//* //*
if ( (ptr= LP_coinsearch(coin)) != 0 ) if ( (ptr= LP_coinsearch(coin)) != 0 )
{ {
if ( ptr->userpass[0] == 0 ) if ( ptr->userpass[0] == 0 && strcmp(ptr->symbol,"ETH") != 0 )
{ {
cJSON *retjson = cJSON_CreateObject(); cJSON *retjson = cJSON_CreateObject();
jaddstr(retjson,"error",LP_DONTCHANGE_ERRMSG0); jaddstr(retjson,"error",LP_DONTCHANGE_ERRMSG0);
@ -437,7 +437,7 @@ jpg(srcfile, destfile, power2=7, password, data="", required, ind=0)\n\
{ {
ptr->inactive = 0; ptr->inactive = 0;
cJSON *array; int32_t notarized; cJSON *array; int32_t notarized;
if ( LP_getheight(&notarized,ptr) <= 0 ) if ( strcmp(ptr->symbol,"ETH") != 0 && LP_getheight(&notarized,ptr) <= 0 )
{ {
ptr->inactive = (uint32_t)time(NULL); ptr->inactive = (uint32_t)time(NULL);
return(clonestr("{\"error\":\"coin cant be activated till synced\"}")); return(clonestr("{\"error\":\"coin cant be activated till synced\"}"));
@ -450,8 +450,6 @@ jpg(srcfile, destfile, power2=7, password, data="", required, ind=0)\n\
if ( strcmp(ptr->symbol,"KMD") == 0 ) if ( strcmp(ptr->symbol,"KMD") == 0 )
LP_importaddress("KMD",BOTS_BONDADDRESS); LP_importaddress("KMD",BOTS_BONDADDRESS);
} }
if ( 0 && strcmp(coin,"BCH") == 0 )
test_validate(ptr,"010000000110b365ea6b8a9f2d56dc12de868e382dc787b2e29355f9b357dcf764c5e29cb1010000006b483045022100c605b993f1db5f31046ebb9065bea0a047f478342bbad8fcfc6af81d05236bd502206e9993a737a8814b935b5e522e750c915e7d37e3bd8367f087d4510f66acac47412102ebc786cb83de8dc3922ab83c21f3f8a2f3216940c3bf9da43ce39e2a3a882c92ffffffff014bc22900000000001976a91459fdba29ea85c65ad90f6d38f7a6646476b26b1688ac00000000");
array = cJSON_CreateArray(); array = cJSON_CreateArray();
jaddi(array,LP_coinjson(ptr,0)); jaddi(array,LP_coinjson(ptr,0));
return(jprint(array,1)); return(jprint(array,1));

5
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 0 #define LP_TECHSUPPORT 1
#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 "17763" #define LP_BUILD_NUMBER "17769"
#define LP_BARTERDEX_VERSION 1 #define LP_BARTERDEX_VERSION 1
#define LP_MAGICBITS 1 #define LP_MAGICBITS 1
@ -547,6 +547,7 @@ int32_t LP_listunspent_both(char *symbol,char *coinaddr,int32_t fullflag);
uint16_t LP_randpeer(char *destip); uint16_t LP_randpeer(char *destip);
void LP_tradebot_pauseall(); void LP_tradebot_pauseall();
void LP_portfolio_reset(); void LP_portfolio_reset();
int32_t bitcoin_addr2rmd160(char *symbol,uint8_t taddr,uint8_t *addrtypep,uint8_t rmd160[20],char *coinaddr);
struct LP_pubkey_info *LP_pubkeyadd(bits256 pubkey); struct LP_pubkey_info *LP_pubkeyadd(bits256 pubkey);
uint32_t LP_atomic_locktime(char *base,char *rel); uint32_t LP_atomic_locktime(char *base,char *rel);
struct LP_pubkey_info *LP_pubkeyfind(bits256 pubkey); struct LP_pubkey_info *LP_pubkeyfind(bits256 pubkey);

30
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; 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;
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];
@ -502,7 +502,7 @@ void command_rpcloop(void *ctx)
void LP_coinsloop(void *_coins) void LP_coinsloop(void *_coins)
{ {
struct LP_address *ap=0,*atmp; struct LP_transaction *tx; cJSON *retjson; struct LP_address_utxo *up,*tmp; struct iguana_info *coin,*ctmp; char str[65]; struct electrum_info *ep,*backupep=0; bits256 zero; int32_t notarized,oldht,j,nonz; char *coins = _coins; struct LP_address *ap=0; struct LP_transaction *tx; cJSON *retjson; struct LP_address_utxo *up,*tmp; struct iguana_info *coin,*ctmp; char str[65]; struct electrum_info *ep,*backupep=0; bits256 zero; int32_t notarized,oldht,j,nonz; char *coins = _coins;
if ( strcmp("BTC",coins) == 0 ) if ( strcmp("BTC",coins) == 0 )
{ {
strcpy(LP_coinsloopBTC_stats.name,"BTC coin loop"); strcpy(LP_coinsloopBTC_stats.name,"BTC coin loop");
@ -563,22 +563,10 @@ void LP_coinsloop(void *_coins)
coin->longestchain = LP_getheight(&notarized,coin); coin->longestchain = LP_getheight(&notarized,coin);
if ( (ep= coin->electrum) != 0 ) if ( (ep= coin->electrum) != 0 )
{ {
/*if ( strcmp("KMD",coin->symbol) == 0 && coin->electrumzeroconf == 0 )
{
LP_zeroconf_deposits(coin);
coin->electrumzeroconf = (uint32_t)time(NULL);
}*/
if ( (backupep= ep->prev) == 0 ) if ( (backupep= ep->prev) == 0 )
backupep = ep; backupep = ep;
if ( (retjson= electrum_address_listunspent(coin->symbol,ep,&retjson,coin->smartaddr,1,zero,zero)) != 0 ) if ( (retjson= electrum_address_listunspent(coin->symbol,ep,&retjson,coin->smartaddr,1,zero,zero)) != 0 )
free_json(retjson); free_json(retjson);
HASH_ITER(hh,coin->addresses,ap,atmp)
{
break;
//printf("call unspent %s\n",ap->coinaddr);
if ( strcmp(coin->smartaddr,ap->coinaddr) != 0 && (retjson= electrum_address_listunspent(coin->symbol,ep,&retjson,ap->coinaddr,1,zero,zero)) != 0 )
free_json(retjson);
}
if ( (ap= LP_addressfind(coin,coin->smartaddr)) != 0 ) if ( (ap= LP_addressfind(coin,coin->smartaddr)) != 0 )
{ {
DL_FOREACH_SAFE(ap->utxos,up,tmp) DL_FOREACH_SAFE(ap->utxos,up,tmp)
@ -650,18 +638,17 @@ void LP_coinsloop(void *_coins)
coin->lastscanht = coin->firstscanht; coin->lastscanht = coin->firstscanht;
continue; continue;
} }
if ( strcmp(coin->symbol,"BTC") != 0 && strcmp(coin->symbol,"KMD") != 0 ) // SPV as backup //if ( strcmp(coin->symbol,"BTC") != 0 && strcmp(coin->symbol,"KMD") != 0 ) // SPV as backup
{ {
nonz++; nonz++;
if ( strcmp("BTC",coins) == 0 )//&& coin->lastscanht < coin->longestchain-3 ) if ( strcmp("BTC",coins) == 0 )//&& coin->lastscanht < coin->longestchain-3 )
printf("[%s]: %s ref.%d scan.%d to %d, longest.%d\n",coins,coin->symbol,coin->firstrefht,coin->firstscanht,coin->lastscanht,coin->longestchain); printf("[%s]: %s ref.%d scan.%d to %d, longest.%d\n",coins,coin->symbol,coin->firstrefht,coin->firstscanht,coin->lastscanht,coin->longestchain);
for (j=0; j<100; j++) for (j=0; j<1000; j++)
{ {
if ( LP_blockinit(coin,coin->lastscanht) < 0 ) if ( LP_blockinit(coin,coin->lastscanht) < 0 )
{ {
static uint32_t counter; printf("blockinit.%s %d error\n",coin->symbol,coin->lastscanht);
if ( counter++ < 3 ) sleep(10);
printf("blockinit.%s %d error\n",coin->symbol,coin->lastscanht);
break; break;
} }
coin->lastscanht++; coin->lastscanht++;
@ -674,7 +661,7 @@ void LP_coinsloop(void *_coins)
} }
if ( coins == 0 ) if ( coins == 0 )
return; return;
if ( nonz == 0 ) //if ( nonz == 0 )
usleep(100000); usleep(100000);
} }
} }
@ -1280,6 +1267,7 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu
portable_mutex_init(&LP_statslogmutex); portable_mutex_init(&LP_statslogmutex);
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);
myipaddr = clonestr("127.0.0.1"); myipaddr = clonestr("127.0.0.1");
#ifndef _WIN32 #ifndef _WIN32
#ifndef FROM_JS #ifndef FROM_JS
@ -1439,7 +1427,7 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu
} }
if ( LP_mainloop_iter(ctx,myipaddr,mypeer,LP_mypubsock) != 0 ) if ( LP_mainloop_iter(ctx,myipaddr,mypeer,LP_mypubsock) != 0 )
nonz++; nonz++;
if ( didremote == 0 && LP_cmdcount > 0 ) if ( IAMLP != 0 && didremote == 0 && LP_cmdcount > 0 )
{ {
didremote = 1; didremote = 1;
uint16_t myport2 = RPC_port-1; uint16_t myport2 = RPC_port-1;

46
iguana/exchanges/LP_network.c

@ -522,6 +522,7 @@ void LP_psockloop(void *_ptr)
{ {
if ( pfds == 0 ) if ( pfds == 0 )
pfds = calloc(MAX_PSOCK_PORT,sizeof(*pfds)); pfds = calloc(MAX_PSOCK_PORT,sizeof(*pfds));
nexti = (rand() % Numpsocks);
portable_mutex_lock(&LP_psockmutex); portable_mutex_lock(&LP_psockmutex);
memset(pfds,0,sizeof(*pfds) * ((Numpsocks*2 <= MAX_PSOCK_PORT) ? Numpsocks*2 : MAX_PSOCK_PORT)); memset(pfds,0,sizeof(*pfds) * ((Numpsocks*2 <= MAX_PSOCK_PORT) ? Numpsocks*2 : MAX_PSOCK_PORT));
for (iter=j=0; iter<2; iter++) for (iter=j=0; iter<2; iter++)
@ -541,7 +542,6 @@ void LP_psockloop(void *_ptr)
if ( pfds[n].fd != ptr->publicsock ) if ( pfds[n].fd != ptr->publicsock )
{ {
printf("unexpected fd.%d mismatched publicsock.%d\n",pfds[n].fd,ptr->publicsock); printf("unexpected fd.%d mismatched publicsock.%d\n",pfds[n].fd,ptr->publicsock);
nexti = i+1;
break; break;
} }
else if ( (pfds[n].revents & POLLIN) != 0 ) else if ( (pfds[n].revents & POLLIN) != 0 )
@ -552,12 +552,12 @@ void LP_psockloop(void *_ptr)
{ {
ptr->lasttime = now; ptr->lasttime = now;
if ( ptr->cmdchannel == 0 ) if ( ptr->cmdchannel == 0 )
{
sendsock = ptr->sendsock; sendsock = ptr->sendsock;
else LP_queuecommand(0,(char *)buf,ptr->publicsock,0); break;
nexti = i+1; } else LP_queuecommand(0,(char *)buf,ptr->publicsock,0);
break;
} }
else if ( buf != 0 ) if ( buf != 0 )
{ {
nn_freemsg(buf); nn_freemsg(buf);
buf = 0; buf = 0;
@ -578,7 +578,6 @@ void LP_psockloop(void *_ptr)
if ( pfds[n].fd != ptr->sendsock ) if ( pfds[n].fd != ptr->sendsock )
{ {
printf("unexpected fd.%d mismatched sendsock.%d\n",pfds[n].fd,ptr->sendsock); printf("unexpected fd.%d mismatched sendsock.%d\n",pfds[n].fd,ptr->sendsock);
nexti = i+1;
break; break;
} }
else if ( (pfds[n].revents & POLLIN) != 0 ) else if ( (pfds[n].revents & POLLIN) != 0 )
@ -590,7 +589,6 @@ void LP_psockloop(void *_ptr)
if ( ptr->ispaired != 0 ) if ( ptr->ispaired != 0 )
{ {
sendsock = ptr->publicsock; sendsock = ptr->publicsock;
nexti = i+1;
break; break;
} }
} }
@ -615,23 +613,20 @@ 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 ( sendsock < 0 ) if ( IAMLP != 0 && sendsock < 0 )
{ {
usleep(30000); usleep(30000);
for (i=nonz=0; i<Numpsocks; i++) for (i=nonz=0; i<Numpsocks; i++)
{ {
if ( i < Numpsocks ) ptr = &PSOCKS[i];
if ( ptr->cmdchannel == 0 && now > ptr->lasttime+PSOCK_KEEPALIVE )
{ {
ptr = &PSOCKS[i]; printf("PSOCKS[%d] of %d (%u %u) lag.%d IDLETIMEOUT\n",i,Numpsocks,ptr->publicport,ptr->sendport,now - ptr->lasttime);
if ( ptr->cmdchannel == 0 && now > ptr->lasttime+PSOCK_KEEPALIVE ) if ( ptr->sendsock != ptr->publicsock && ptr->sendsock >= 0 )
{ nn_close(ptr->sendsock), ptr->sendsock = -1;
printf("PSOCKS[%d] of %d (%u %u) lag.%d IDLETIMEOUT\n",i,Numpsocks,ptr->publicport,ptr->sendport,now - ptr->lasttime); if ( ptr->publicsock >= 0 )
if ( ptr->sendsock != ptr->publicsock && ptr->sendsock >= 0 ) nn_close(ptr->publicsock), ptr->publicsock = -1;
mynn_close(ptr->sendsock), ptr->sendsock = -1; nonz++;
if ( ptr->publicsock >= 0 )
mynn_close(ptr->publicsock), ptr->publicsock = -1;
nonz++;
}
} }
} }
if ( nonz > 0 ) if ( nonz > 0 )
@ -662,6 +657,7 @@ void LP_psockadd(int32_t ispaired,int32_t publicsock,uint16_t recvport,int32_t s
portable_mutex_lock(&LP_psockmutex); portable_mutex_lock(&LP_psockmutex);
PSOCKS = realloc(PSOCKS,sizeof(*PSOCKS) * (Numpsocks + 1)); PSOCKS = realloc(PSOCKS,sizeof(*PSOCKS) * (Numpsocks + 1));
ptr = &PSOCKS[Numpsocks++]; ptr = &PSOCKS[Numpsocks++];
memset(ptr,0,sizeof(*ptr));
ptr->ispaired = ispaired; ptr->ispaired = ispaired;
ptr->cmdchannel = cmdchannel; ptr->cmdchannel = cmdchannel;
ptr->publicsock = publicsock; ptr->publicsock = publicsock;
@ -698,14 +694,18 @@ char *_LP_psock_create(int32_t *pullsockp,int32_t *pubsockp,char *ipaddr,uint16_
int32_t i,pullsock,bindflag=(IAMLP != 0),pubsock,arg; struct LP_pubkey_info *pubp; char pushaddr[128],subaddr[128]; cJSON *retjson = 0; int32_t i,pullsock,bindflag=(IAMLP != 0),pubsock,arg; struct LP_pubkey_info *pubp; char pushaddr[128],subaddr[128]; cJSON *retjson = 0;
pullsock = pubsock = -1; pullsock = pubsock = -1;
*pullsockp = *pubsockp = -1; *pullsockp = *pubsockp = -1;
if ( cmdchannel != 0 && bits256_nonz(pubkey) == 0 )
{
printf("ignore cmdchannel request without pubkey\n");
return(clonestr("{\"error\":\"cmdchannel needs pubkey\"}"));
}
if ( IAMLP != 0 && bits256_nonz(pubkey) != 0 ) if ( IAMLP != 0 && bits256_nonz(pubkey) != 0 )
{ {
char str[65];
if ( (pubp= LP_pubkeyadd(pubkey)) != 0 ) if ( (pubp= LP_pubkeyadd(pubkey)) != 0 )
{ {
if ( pubp->pairsock >= 0 ) if ( pubp->pairsock >= 0 )
{ {
printf("%s already has pairsock.%d\n",bits256_str(str,pubkey),pubp->pairsock); //printf("%s already has pairsock.%d\n",bits256_str(str,pubkey),pubp->pairsock);
portable_mutex_lock(&LP_psockmutex); portable_mutex_lock(&LP_psockmutex);
for (i=0; i<Numpsocks; i++) for (i=0; i<Numpsocks; i++)
if ( PSOCKS[i].publicsock == pubp->pairsock ) if ( PSOCKS[i].publicsock == pubp->pairsock )
@ -762,7 +762,9 @@ char *_LP_psock_create(int32_t *pullsockp,int32_t *pubsockp,char *ipaddr,uint16_
jaddnum(retjson,"cmdchannel",cmdchannel); jaddnum(retjson,"cmdchannel",cmdchannel);
jaddstr(retjson,"publicaddr",pushaddr); jaddstr(retjson,"publicaddr",pushaddr);
jaddnum(retjson,"publicport",publicport); jaddnum(retjson,"publicport",publicport);
//printf("cmd.%d publicaddr.(%s) for subaddr.(%s), pullsock.%d pubsock.%d\n",cmdchannel,pushaddr,subaddr,pullsock,pubsock); if ( bits256_nonz(pubkey) != 0 && (pubp= LP_pubkeyadd(pubkey)) != 0 )
pubp->pairsock = pullsock;
char str[65]; printf("PSOCK %s cmd.%d publicaddr.(%s) for subaddr.(%s), pullsock.%d pubsock.%d\n",bits256_str(str,pubkey),cmdchannel,pushaddr,subaddr,pullsock,pubsock);
*pullsockp = pullsock; *pullsockp = pullsock;
*pubsockp = pubsock; *pubsockp = pubsock;
return(jprint(retjson,1)); return(jprint(retjson,1));

3
iguana/exchanges/LP_ordermatch.c

@ -440,7 +440,7 @@ struct LP_utxoinfo *LP_address_myutxopair(struct LP_utxoinfo *butxo,int32_t iamb
if ( targetval == 0 || mini < 0 ) if ( targetval == 0 || mini < 0 )
break; break;
} }
} else printf("no %s utxos pass LP_address_utxo_ptrs filter\n",coinaddr); } else printf("no %s %s utxos pass LP_address_utxo_ptrs filter\n",coin->symbol,coinaddr);
} 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);
} }
@ -1201,6 +1201,7 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson,
printf("aliceid.%llu is expired by %d\n",(long long)Q.aliceid,(uint32_t)time(NULL) - (Q.timestamp + LP_AUTOTRADE_TIMEOUT*20)); printf("aliceid.%llu is expired by %d\n",(long long)Q.aliceid,(uint32_t)time(NULL) - (Q.timestamp + LP_AUTOTRADE_TIMEOUT*20));
return(1); return(1);
} }
//printf("%s\n",jprint(argjson,0));
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); 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);
retval = 1; retval = 1;
aliceid = j64bits(argjson,"aliceid"); aliceid = j64bits(argjson,"aliceid");

232
iguana/exchanges/LP_remember.c

@ -256,7 +256,7 @@ bits256 basilisk_swap_privBn_extract(bits256 *bobrefundp,char *bobcoin,bits256 b
bits256 basilisk_swap_spendupdate(int32_t iambob,char *symbol,char *spentaddr,int32_t *sentflags,bits256 *txids,int32_t utxoind,int32_t alicespent,int32_t bobspent,int32_t utxovout,char *aliceaddr,char *bobaddr,char *Adest,char *dest) bits256 basilisk_swap_spendupdate(int32_t iambob,char *symbol,char *spentaddr,int32_t *sentflags,bits256 *txids,int32_t utxoind,int32_t alicespent,int32_t bobspent,int32_t utxovout,char *aliceaddr,char *bobaddr,char *Adest,char *dest)
{ {
bits256 spendtxid,txid; char destaddr[64],str[65]; int32_t i,n; struct iguana_info *coin; cJSON *array,*txobj; bits256 spendtxid,txid; char destaddr[64],str[65]; int32_t i,n,j,numvins,numvouts; struct iguana_info *coin; cJSON *array,*txobj,*vins,*vin,*vouts;
memset(&spendtxid,0,sizeof(spendtxid)); memset(&spendtxid,0,sizeof(spendtxid));
destaddr[0] = 0; destaddr[0] = 0;
if ( (coin= LP_coinfind(symbol)) == 0 ) if ( (coin= LP_coinfind(symbol)) == 0 )
@ -271,11 +271,47 @@ bits256 basilisk_swap_spendupdate(int32_t iambob,char *symbol,char *spentaddr,in
for (i=0; i<n; i++) for (i=0; i<n; i++)
{ {
txid = jbits256(jitem(array,i),"tx_hash"); txid = jbits256(jitem(array,i),"tx_hash");
//printf("i.%d of %d: %s\n",i,n,bits256_str(str,txid)); if ( 0 && utxoind == BASILISK_BOBPAYMENT )
printf("i.%d of %d: %s\n",i,n,bits256_str(str,txid));
if ( bits256_cmp(txid,txids[utxoind]) != 0 ) if ( bits256_cmp(txid,txids[utxoind]) != 0 )
{ {
if ( (txobj= LP_gettx(symbol,txid,1)) != 0 ) // good side effects if ( (txobj= LP_gettx(symbol,txid,1)) != 0 )
{
if ( (vins= jarray(&numvins,txobj,"vin")) != 0 )
{
for (j=0; j<numvins; j++)
{
vin = jitem(vins,j);
if ( 0 && utxoind == BASILISK_BOBPAYMENT )
printf("vini.%d %s\n",j,jprint(vin,0));
if ( utxovout == jint(vin,"vout") && bits256_cmp(txids[utxoind],jbits256(vin,"txid")) == 0 )
{
if ( (vouts= jarray(&numvouts,txobj,"vout")) != 0 )
LP_destaddr(destaddr,jitem(vouts,0));
free_json(txobj);
if ( bobaddr != 0 && (strcmp(destaddr,bobaddr) == 0 || strcmp(dest,destaddr) == 0) )
{
sentflags[bobspent] = 1;
sentflags[alicespent] = 0;
txids[bobspent] = spendtxid;
//printf("bobspent.[%d] <- 1\n",bobspent);
}
else if ( aliceaddr != 0 && (strcmp(destaddr,aliceaddr) == 0 || strcmp(Adest,destaddr) == 0) )
{
sentflags[alicespent] = 1;
sentflags[bobspent] = 0;
txids[alicespent] = spendtxid;
}
//else printf("unknown spender\n");
sentflags[utxoind] = 1;
if ( 0 && utxoind == BASILISK_BOBPAYMENT )
printf("found match destaddr.(%s)\n",destaddr);
return(txid);
}
}
}
free_json(txobj); free_json(txobj);
}
} }
} }
} }
@ -296,24 +332,28 @@ bits256 basilisk_swap_spendupdate(int32_t iambob,char *symbol,char *spentaddr,in
if ( bits256_nonz(spendtxid) != 0 ) if ( bits256_nonz(spendtxid) != 0 )
{ {
sentflags[utxoind] = 1; sentflags[utxoind] = 1;
//printf("utxoind.%d Alice.(%s %s) Bob.(%s %s) vs destaddr.(%s)\n",utxoind,aliceaddr,Adest,bobaddr,dest,destaddr); if ( 0 && utxoind == BASILISK_BOBPAYMENT )
printf("utxoind.%d Alice.(%s %s) Bob.(%s %s) vs destaddr.(%s)\n",utxoind,aliceaddr,Adest,bobaddr,dest,destaddr);
if ( aliceaddr != 0 && (strcmp(destaddr,aliceaddr) == 0 || strcmp(Adest,destaddr) == 0) ) if ( aliceaddr != 0 && (strcmp(destaddr,aliceaddr) == 0 || strcmp(Adest,destaddr) == 0) )
{ {
//printf("ALICE spent.(%s) -> %s\n",bits256_str(str,txid),destaddr); if ( 0 && utxoind == BASILISK_BOBPAYMENT )
printf("ALICE spent.(%s) -> %s\n",bits256_str(str,txid),destaddr);
sentflags[alicespent] = 1; sentflags[alicespent] = 1;
sentflags[bobspent] = 0; sentflags[bobspent] = 0;
txids[alicespent] = spendtxid; txids[alicespent] = spendtxid;
} }
else if ( bobaddr != 0 && (strcmp(destaddr,bobaddr) == 0 || strcmp(dest,destaddr) == 0) ) else if ( bobaddr != 0 && (strcmp(destaddr,bobaddr) == 0 || strcmp(dest,destaddr) == 0) )
{ {
//printf("BOB spent.(%s) -> %s\n",bits256_str(str,txid),destaddr); if ( 0 && utxoind == BASILISK_BOBPAYMENT )
printf("BOB spent.(%s) -> %s\n",bits256_str(str,txid),destaddr);
sentflags[bobspent] = 1; sentflags[bobspent] = 1;
sentflags[alicespent] = 0; sentflags[alicespent] = 0;
txids[bobspent] = spendtxid; txids[bobspent] = spendtxid;
} }
else else
{ {
printf("OTHER dest spent.(%s) -> %s\n",bits256_str(str,txid),destaddr); if ( 0 && utxoind == BASILISK_BOBPAYMENT )
printf("OTHER dest spent.(%s) -> %s\n",bits256_str(str,txid),destaddr);
if ( iambob == 0 ) if ( iambob == 0 )
{ {
sentflags[bobspent] = 1; sentflags[bobspent] = 1;
@ -327,7 +367,9 @@ bits256 basilisk_swap_spendupdate(int32_t iambob,char *symbol,char *spentaddr,in
txids[alicespent] = spendtxid; txids[alicespent] = spendtxid;
} }
} }
} //else printf("no spend of %s/v%d detected\n",bits256_str(str,txid),vout); }
else if ( 0 && utxoind == BASILISK_BOBPAYMENT )
printf("no spend of %s/v%d detected\n",bits256_str(str,txid),utxovout);
} //else printf("utxoind.%d null txid\n",utxoind); } //else printf("utxoind.%d null txid\n",utxoind);
return(spendtxid); return(spendtxid);
} }
@ -353,46 +395,90 @@ int32_t basilisk_isbobcoin(int32_t iambob,int32_t ind)
} }
} }
int32_t basilisk_swap_isfinished(int32_t iambob,bits256 *txids,int32_t *sentflags,bits256 paymentspent,bits256 Apaymentspent,bits256 depositspent) int32_t basilisk_swap_isfinished(uint32_t expiration,int32_t iambob,bits256 *txids,int32_t *sentflags,bits256 paymentspent,bits256 Apaymentspent,bits256 depositspent)
{ {
int32_t i,n = 0; int32_t i,n = 0; uint32_t now = (uint32_t)time(NULL);
for (i=0; i<sizeof(txnames)/sizeof(*txnames); i++) if ( bits256_nonz(paymentspent) != 0 && bits256_nonz(Apaymentspent) != 0 && bits256_nonz(depositspent) != 0 )
if ( i != BASILISK_OTHERFEE && i != BASILISK_MYFEE && sentflags[i] != 0 )
n++;
if ( n == 0 )
{
//printf("if nothing sent, it is finished\n");
return(1); return(1);
} else if ( sentflags[BASILISK_BOBPAYMENT] != 0 && sentflags[BASILISK_ALICEPAYMENT] != 0 && sentflags[BASILISK_BOBDEPOSIT] != 0 && sentflags[BASILISK_BOBRECLAIM] != 0 )
if ( iambob != 0 )
{ {
if ( bits256_nonz(txids[BASILISK_BOBDEPOSIT]) == 0 && sentflags[BASILISK_BOBDEPOSIT] == 0 ) if ( sentflags[BASILISK_ALICECLAIM] != 0 )
return(1);
else if ( bits256_nonz(txids[BASILISK_BOBPAYMENT]) == 0 || sentflags[BASILISK_BOBPAYMENT] == 0 )
{ {
if ( bits256_nonz(depositspent) != 0 ) printf("edge case unspendable alicepayment\n");
return(1); return(1);
} }
else if ( bits256_nonz(Apaymentspent) != 0 ) else if ( iambob != 0 && sentflags[BASILISK_ALICECLAIM] != 0 )
return(1); return(1);
else if ( bits256_nonz(paymentspent) != 0 && bits256_nonz(depositspent) != 0 ) }
if ( now > expiration - INSTANTDEX_LOCKTIME )
{
if ( bits256_nonz(paymentspent) != 0 )
n++;
if ( bits256_nonz(Apaymentspent) != 0 )
n++;
if ( bits256_nonz(depositspent) != 0 )
n++;
for (i=0; i<sizeof(txnames)/sizeof(*txnames); i++)
{
if ( i != BASILISK_OTHERFEE && i != BASILISK_MYFEE && sentflags[i] != 0 )
{
if ( bits256_nonz(txids[i]) != 0 )
n++;
}
}
if ( n == 0 )
{
//printf("if nothing sent, it is finished\n");
return(1); return(1);
}
} }
else if ( iambob != 0 )
{ {
if ( sentflags[BASILISK_ALICEPAYMENT] == 0 ) if ( (sentflags[BASILISK_BOBSPEND] != 0 || sentflags[BASILISK_BOBRECLAIM] != 0) && sentflags[BASILISK_BOBREFUND] != 0 )
return(1);
else if ( (bits256_nonz(txids[BASILISK_BOBPAYMENT]) == 0 || sentflags[BASILISK_BOBPAYMENT] == 0) && sentflags[BASILISK_BOBREFUND] != 0 )
return(1);
else if ( now > expiration )
{ {
if ( bits256_nonz(txids[BASILISK_ALICEPAYMENT]) == 0 ) if ( bits256_nonz(txids[BASILISK_BOBDEPOSIT]) == 0 && sentflags[BASILISK_BOBDEPOSIT] == 0 )
return(1); return(1);
else if ( sentflags[BASILISK_BOBPAYMENT] != 0 && sentflags[BASILISK_BOBREFUND] != 0 ) else if ( bits256_nonz(txids[BASILISK_BOBPAYMENT]) == 0 || sentflags[BASILISK_BOBPAYMENT] == 0 )
{
if ( bits256_nonz(depositspent) != 0 )
{
if ( bits256_nonz(Apaymentspent) == 0 && sentflags[BASILISK_BOBREFUND] == 0 )
printf("bob was too late in claiming bobrefund\n");
return(1);
}
}
//else if ( bits256_nonz(Apaymentspent) != 0 )
// return(1);
else if ( bits256_nonz(Apaymentspent) != 0 && bits256_nonz(paymentspent) != 0 && bits256_nonz(depositspent) != 0 )
return(1); return(1);
} }
else }
else
{
if ( sentflags[BASILISK_ALICESPEND] != 0 || sentflags[BASILISK_ALICERECLAIM] != 0 || sentflags[BASILISK_ALICECLAIM] != 0 )
return(1);
else if ( now > expiration )
{ {
if ( sentflags[BASILISK_ALICERECLAIM] != 0 || sentflags[BASILISK_ALICESPEND] != 0 ) if ( sentflags[BASILISK_ALICEPAYMENT] == 0 )
return(1); {
else if ( sentflags[BASILISK_BOBSPEND] != 0 ) // without ALICECLAIM this is loss due to inactivity if ( bits256_nonz(txids[BASILISK_ALICEPAYMENT]) == 0 )
return(1); return(1);
else if ( sentflags[BASILISK_BOBREFUND] != 0 ) //sentflags[BASILISK_BOBPAYMENT] != 0
return(1);
}
else
{
if ( sentflags[BASILISK_ALICESPEND] != 0 )
return(1);
else if ( sentflags[BASILISK_ALICERECLAIM] != 0 )
return(1);
else if ( sentflags[BASILISK_ALICECLAIM] != 0 ) //got deposit! happy alice
return(1);
}
} }
} }
return(0); return(0);
@ -637,9 +723,9 @@ int32_t LP_rswap_init(struct LP_swap_remember *rswap,uint32_t requestid,uint32_t
rswap->txids[BASILISK_MYFEE] = jbits256(item,"myfee"); rswap->txids[BASILISK_MYFEE] = jbits256(item,"myfee");
rswap->txids[BASILISK_OTHERFEE] = jbits256(item,"otherfee"); rswap->txids[BASILISK_OTHERFEE] = jbits256(item,"otherfee");
free_json(item); free_json(item);
} } else printf("couldnt parse.(%s)\n",fstr);
free(fstr); free(fstr);
} } // else printf("cant open.(%s)\n",fname);
sprintf(fname,"%s/SWAPS/%u-%u.finished",GLOBAL_DBDIR,requestid,quoteid), OS_compatible_path(fname); sprintf(fname,"%s/SWAPS/%u-%u.finished",GLOBAL_DBDIR,requestid,quoteid), OS_compatible_path(fname);
if ( (fstr= OS_filestr(&fsize,fname)) != 0 ) if ( (fstr= OS_filestr(&fsize,fname)) != 0 )
{ {
@ -670,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->iambob,rswap->txids,rswap->sentflags,rswap->paymentspent,rswap->Apaymentspent,rswap->depositspent); rswap->origfinishedflag = basilisk_swap_isfinished(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;
@ -890,7 +976,17 @@ int32_t LP_spends_set(struct LP_swap_remember *rswap)
cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requestid,uint32_t quoteid,int32_t forceflag,int32_t pendingonly) cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requestid,uint32_t quoteid,int32_t forceflag,int32_t pendingonly)
{ {
static void *ctx; static void *ctx;
struct LP_swap_remember rswap; int32_t i,j,flag,numspent,len,secretstart,redeemlen; char str[65],*srcAdest,*srcBdest,*destAdest,*destBdest,otheraddr[64]; cJSON *item,*txoutobj; bits256 rev,signedtxid,zero,deadtxid; uint32_t claimtime; struct iguana_info *bob=0,*alice=0; uint8_t redeemscript[1024],userdata[1024]; struct LP_swap_remember rswap; int32_t i,j,flag,numspent,len,secretstart,redeemlen; char str[65],*srcAdest,*srcBdest,*destAdest,*destBdest,otheraddr[64],*fstr,fname[512]; cJSON *item,*txoutobj,*retjson; bits256 rev,signedtxid,zero,deadtxid; uint32_t claimtime; struct iguana_info *bob=0,*alice=0; uint8_t redeemscript[1024],userdata[1024]; long fsize;
sprintf(fname,"%s/SWAPS/%u-%u.finished",GLOBAL_DBDIR,requestid,quoteid), OS_compatible_path(fname);
if ( (fstr= OS_filestr(&fsize,fname)) != 0 )
{
if ( (retjson= cJSON_Parse(fstr)) != 0 )
{
free(fstr);
return(retjson);
}
free(fstr);
}
if ( ctx == 0 ) if ( ctx == 0 )
ctx = bitcoin_ctx(); ctx = bitcoin_ctx();
if ( requestid == 0 || quoteid == 0 ) if ( requestid == 0 || quoteid == 0 )
@ -903,11 +999,16 @@ cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requesti
otheraddr[0] = 0; otheraddr[0] = 0;
claimtime = (uint32_t)time(NULL) - 777; claimtime = (uint32_t)time(NULL) - 777;
srcAdest = srcBdest = destAdest = destBdest = 0; srcAdest = srcBdest = destAdest = destBdest = 0;
//printf("request.%u quoteid.%u\n",requestid,quoteid);
if ( rswap.bobcoin[0] == 0 || rswap.alicecoin[0] == 0 || strcmp(rswap.bobcoin,rswap.src) != 0 || strcmp(rswap.alicecoin,rswap.dest) != 0 ) if ( rswap.bobcoin[0] == 0 || rswap.alicecoin[0] == 0 || strcmp(rswap.bobcoin,rswap.src) != 0 || strcmp(rswap.alicecoin,rswap.dest) != 0 )
{ {
//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,"bob",rswap.bobcoin);
jaddstr(retjson,"src",rswap.src);
jaddstr(retjson,"alice",rswap.alicecoin);
jaddstr(retjson,"dest",rswap.dest);
jaddnum(retjson,"requestid",requestid); jaddnum(retjson,"requestid",requestid);
jaddnum(retjson,"quoteid",quoteid); jaddnum(retjson,"quoteid",quoteid);
return(retjson); return(retjson);
@ -915,6 +1016,7 @@ cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requesti
} }
alice = LP_coinfind(rswap.alicecoin); alice = LP_coinfind(rswap.alicecoin);
bob = LP_coinfind(rswap.bobcoin); bob = LP_coinfind(rswap.bobcoin);
//printf("request.%u quoteid.%u alice.%s bob.%s\n",requestid,quoteid,alice!=0?alice->symbol:"",bob!=0?bob->symbol:"");
rswap.Atxfee = LP_txfeecalc(alice,rswap.Atxfee,0); rswap.Atxfee = LP_txfeecalc(alice,rswap.Atxfee,0);
rswap.Btxfee = LP_txfeecalc(bob,rswap.Btxfee,0); rswap.Btxfee = LP_txfeecalc(bob,rswap.Btxfee,0);
if ( rswap.iambob == 0 ) if ( rswap.iambob == 0 )
@ -933,6 +1035,18 @@ cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requesti
jaddnum(retjson,"quoteid",quoteid); jaddnum(retjson,"quoteid",quoteid);
return(retjson); return(retjson);
} }
if ( 0 && alice->electrum == 0 && alice->lastscanht < alice->longestchain+1 )
{
printf("need to scan %s first\n",alice->symbol);
cJSON *retjson = cJSON_CreateObject();
jaddstr(retjson,"error","need to scan coin first");
jaddstr(retjson,"coin",alice->symbol);
jaddnum(retjson,"scanned",alice->lastscanht);
jaddnum(retjson,"longest",alice->longestchain);
jaddnum(retjson,"requestid",requestid);
jaddnum(retjson,"quoteid",quoteid);
return(retjson);
}
} }
if ( (bob= LP_coinfind(rswap.bobcoin)) != 0 ) if ( (bob= LP_coinfind(rswap.bobcoin)) != 0 )
{ {
@ -957,6 +1071,18 @@ cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requesti
jaddnum(retjson,"quoteid",quoteid); jaddnum(retjson,"quoteid",quoteid);
return(retjson); return(retjson);
} }
if ( 0 && bob->electrum == 0 && bob->lastscanht < bob->longestchain+1 )
{
printf("need to scan %s first\n",bob->symbol);
cJSON *retjson = cJSON_CreateObject();
jaddstr(retjson,"error","need to scan coin first");
jaddstr(retjson,"coin",bob->symbol);
jaddnum(retjson,"scanned",bob->lastscanht);
jaddnum(retjson,"longest",bob->longestchain);
jaddnum(retjson,"requestid",requestid);
jaddnum(retjson,"quoteid",quoteid);
return(retjson);
}
} }
if ( (alice= LP_coinfind(rswap.alicecoin)) != 0 ) if ( (alice= LP_coinfind(rswap.alicecoin)) != 0 )
{ {
@ -989,7 +1115,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.iambob,rswap.txids,rswap.sentflags,rswap.paymentspent,rswap.Apaymentspent,rswap.depositspent); rswap.finishedflag = basilisk_swap_isfinished(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 )
{ {
@ -1035,7 +1161,7 @@ cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requesti
} }
} }
} }
if ( rswap.sentflags[BASILISK_ALICECLAIM] == 0 && rswap.sentflags[BASILISK_BOBDEPOSIT] != 0 && bits256_nonz(rswap.txids[BASILISK_BOBDEPOSIT]) != 0 && bits256_nonz(rswap.depositspent) == 0 ) if ( rswap.sentflags[BASILISK_ALICECLAIM] == 0 && (rswap.sentflags[BASILISK_BOBDEPOSIT] != 0 || bits256_nonz(rswap.txids[BASILISK_BOBDEPOSIT]) != 0) && bits256_nonz(rswap.depositspent) == 0 )
{ {
if ( time(NULL) > rswap.expiration+777 ) if ( time(NULL) > rswap.expiration+777 )
{ {
@ -1046,7 +1172,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 ) if ( flag == 0 )
{ {
if ( rswap.Dredeemlen != 0 ) if ( rswap.Dredeemlen != 0 )
redeemlen = rswap.Dredeemlen, memcpy(redeemscript,rswap.Dredeemscript,rswap.Dredeemlen); redeemlen = rswap.Dredeemlen, memcpy(redeemscript,rswap.Dredeemscript,rswap.Dredeemlen);
@ -1061,7 +1187,7 @@ cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requesti
} }
} else printf("now %u before expiration %u\n",(uint32_t)time(NULL),rswap.expiration); } else printf("now %u before expiration %u\n",(uint32_t)time(NULL),rswap.expiration);
} }
if ( rswap.sentflags[BASILISK_ALICEPAYMENT] != 0 && bits256_nonz(rswap.Apaymentspent) == 0 && rswap.sentflags[BASILISK_ALICECLAIM] == 0 ) if ( (rswap.sentflags[BASILISK_ALICEPAYMENT] != 0 || bits256_nonz(rswap.txids[BASILISK_ALICEPAYMENT]) != 0)&& bits256_nonz(rswap.Apaymentspent) == 0 && rswap.sentflags[BASILISK_ALICERECLAIM] == 0 )
{ {
flag = 0; flag = 0;
if ( alice->electrum == 0 ) if ( alice->electrum == 0 )
@ -1086,8 +1212,8 @@ cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requesti
{ {
if ( rswap.sentflags[BASILISK_BOBSPEND] == 0 && bits256_nonz(rswap.Apaymentspent) == 0 ) if ( rswap.sentflags[BASILISK_BOBSPEND] == 0 && bits256_nonz(rswap.Apaymentspent) == 0 )
{ {
//printf("try to bobspend aspend.%s have privAm.%d\n",bits256_str(str,rswap.txids[BASILISK_ALICESPEND]),bits256_nonz(rswap.privAm)); //printf("try to bobspend aspend.%s have privAm.%d aspent.%d\n",bits256_str(str,rswap.txids[BASILISK_ALICESPEND]),bits256_nonz(rswap.privAm),rswap.sentflags[BASILISK_ALICESPEND]);
if ( bits256_nonz(rswap.txids[BASILISK_ALICESPEND]) != 0 || bits256_nonz(rswap.privAm) != 0 ) if ( rswap.sentflags[BASILISK_ALICESPEND] != 0 || bits256_nonz(rswap.paymentspent) != 0 || bits256_nonz(rswap.privAm) != 0 )
{ {
flag = 0; flag = 0;
if ( alice->electrum == 0 ) if ( alice->electrum == 0 )
@ -1096,12 +1222,13 @@ 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.Apaymentspent = deadtxid; else flag = -1, rswap.Apaymentspent = deadtxid;
} }
//printf("flag.%d apayment.%s\n",flag,bits256_str(str,rswap.paymentspent));
if ( flag == 0 ) if ( flag == 0 )
{ {
if ( bits256_nonz(rswap.privAm) == 0 ) if ( bits256_nonz(rswap.privAm) == 0 )
{ {
rswap.privAm = basilisk_swap_privbob_extract(rswap.bobcoin,rswap.txids[BASILISK_ALICESPEND],0,1); rswap.privAm = basilisk_swap_privbob_extract(rswap.bobcoin,rswap.paymentspent,0,1);
//printf("try to bobspend aspend.%s have privAm.%d\n",bits256_str(str,rswap.txids[BASILISK_ALICESPEND]),bits256_nonz(rswap.privAm)); //printf("try to bobspend aspend.%s have privAm.%d\n",bits256_str(str,rswap.paymentspent),bits256_nonz(rswap.privAm));
} }
if ( bits256_nonz(rswap.privAm) != 0 && bits256_nonz(rswap.privBn) != 0 ) if ( bits256_nonz(rswap.privAm) != 0 && bits256_nonz(rswap.privBn) != 0 )
{ {
@ -1114,7 +1241,7 @@ cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requesti
} }
} }
} }
if ( rswap.sentflags[BASILISK_BOBRECLAIM] == 0 && rswap.sentflags[BASILISK_BOBPAYMENT] != 0 && bits256_nonz(rswap.txids[BASILISK_BOBPAYMENT]) != 0 && bits256_nonz(rswap.paymentspent) == 0 ) if ( rswap.sentflags[BASILISK_BOBRECLAIM] == 0 && (rswap.sentflags[BASILISK_BOBPAYMENT] != 0 || bits256_nonz(rswap.txids[BASILISK_BOBPAYMENT]) != 0) && bits256_nonz(rswap.paymentspent) == 0 )
{ {
flag = 0; flag = 0;
if ( bob->electrum == 0 ) if ( bob->electrum == 0 )
@ -1123,14 +1250,14 @@ 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 ( time(NULL) > rswap.expiration+777 ) if ( flag == 0 && time(NULL) > rswap.expiration+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);
if ( redeemlen > 0 ) if ( redeemlen > 0 )
{ {
len = basilisk_swapuserdata(userdata,zero,1,rswap.myprivs[1],redeemscript,redeemlen); len = basilisk_swapuserdata(userdata,zero,1,rswap.myprivs[1],redeemscript,redeemlen);
if ( (rswap.txbytes[BASILISK_BOBRECLAIM]= basilisk_swap_bobtxspend(&signedtxid,rswap.Btxfee,"bobrefund",rswap.bobcoin,bob->wiftaddr,bob->taddr,bob->pubtype,bob->p2shtype,bob->isPoS,bob->wiftype,ctx,rswap.myprivs[1],0,redeemscript,redeemlen,userdata,len,rswap.txids[BASILISK_BOBPAYMENT],0,0,rswap.pubkey33,0,claimtime,&rswap.values[BASILISK_BOBRECLAIM],0,0,rswap.bobpaymentaddr,1,bob->zcash)) != 0 ) if ( (rswap.txbytes[BASILISK_BOBRECLAIM]= basilisk_swap_bobtxspend(&signedtxid,rswap.Btxfee,"bobreclaim",rswap.bobcoin,bob->wiftaddr,bob->taddr,bob->pubtype,bob->p2shtype,bob->isPoS,bob->wiftype,ctx,rswap.myprivs[1],0,redeemscript,redeemlen,userdata,len,rswap.txids[BASILISK_BOBPAYMENT],0,0,rswap.pubkey33,0,claimtime,&rswap.values[BASILISK_BOBRECLAIM],0,0,rswap.bobpaymentaddr,1,bob->zcash)) != 0 )
{ {
//int32_t z; //int32_t z;
//for (z=0; z<20; z++) //for (z=0; z<20; z++)
@ -1145,8 +1272,9 @@ cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requesti
//printf("bobpayment: now.%u < expiration %u\n",(uint32_t)time(NULL),rswap.expiration); //printf("bobpayment: now.%u < expiration %u\n",(uint32_t)time(NULL),rswap.expiration);
} }
} }
if ( rswap.sentflags[BASILISK_BOBREFUND] == 0 && rswap.sentflags[BASILISK_BOBDEPOSIT] != 0 && bits256_nonz(rswap.txids[BASILISK_BOBDEPOSIT]) != 0 && bits256_nonz(rswap.depositspent) == 0 ) if ( rswap.sentflags[BASILISK_BOBREFUND] == 0 && (rswap.sentflags[BASILISK_BOBDEPOSIT] != 0 || bits256_nonz(rswap.txids[BASILISK_BOBDEPOSIT]) != 0) && bits256_nonz(rswap.depositspent) == 0 )
{ {
//printf("bobdeposit.%d depositspent.%d paymentspent.%d\n",rswap.sentflags[BASILISK_BOBDEPOSIT],bits256_nonz(rswap.depositspent),bits256_nonz(rswap.paymentspent));
flag = 0; flag = 0;
if ( bob->electrum == 0 ) if ( bob->electrum == 0 )
{ {
@ -1154,7 +1282,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 ( bits256_nonz(rswap.Apaymentspent) != 0 || time(NULL) > rswap.expiration+777 ) if ( flag == 0 && (bits256_nonz(rswap.paymentspent) != 0 || time(NULL) > rswap.plocktime+777+120) )
{ {
//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 )
@ -1194,7 +1322,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.iambob,rswap.txids,rswap.sentflags,rswap.paymentspent,rswap.Apaymentspent,rswap.depositspent); else rswap.finishedflag = basilisk_swap_isfinished(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;

2
iguana/exchanges/LP_scan.c

@ -22,6 +22,7 @@
int32_t LP_blockinit(struct iguana_info *coin,int32_t height) int32_t LP_blockinit(struct iguana_info *coin,int32_t height)
{ {
int32_t i,iter,numtx,checkht=-1; cJSON *blockobj,*txs,*txobj; bits256 txid; struct LP_transaction *tx; int32_t i,iter,numtx,checkht=-1; cJSON *blockobj,*txs,*txobj; bits256 txid; struct LP_transaction *tx;
portable_mutex_lock(&LP_blockinit_mutex);
if ( (blockobj= LP_blockjson(&checkht,coin->symbol,0,height)) != 0 && checkht == height ) if ( (blockobj= LP_blockjson(&checkht,coin->symbol,0,height)) != 0 && checkht == height )
{ {
if ( (txs= jarray(&numtx,blockobj,"tx")) != 0 ) if ( (txs= jarray(&numtx,blockobj,"tx")) != 0 )
@ -52,6 +53,7 @@ int32_t LP_blockinit(struct iguana_info *coin,int32_t height)
} }
free_json(blockobj); free_json(blockobj);
} }
portable_mutex_unlock(&LP_blockinit_mutex);
if ( checkht == height ) if ( checkht == height )
return(0); return(0);
else return(-1); else return(-1);

33
iguana/exchanges/LP_socket.c

@ -525,10 +525,24 @@ cJSON *electrum_address_subscribe(char *symbol,struct electrum_info *ep,cJSON **
return(retjson); return(retjson);
} }
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];
bitcoin_addr2rmd160(symbol,taddr,&addrtype,rmd160,coinaddr);
init_hexbytes_noT(rmdstr,rmd160,20);
sprintf(scripthash,"76a914%s88ac",rmdstr);
sprintf(cmdbuf,"blockchain.scripthash.%s",cmd);
return(electrum_strarg(symbol,ep,retjsonp,cmdbuf,scripthash,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)
{ {
char str[65]; struct LP_transaction *tx; cJSON *retjson,*txobj,*item; int32_t i,n,height; bits256 txid; struct iguana_info *coin = LP_coinfind(symbol); char str[65]; struct LP_transaction *tx; cJSON *retjson,*txobj,*item; int32_t i,n,height; bits256 txid; struct iguana_info *coin = LP_coinfind(symbol);
retjson = electrum_strarg(symbol,ep,retjsonp,"blockchain.address.get_history",addr,ELECTRUM_TIMEOUT); if ( coin == 0 )
return(0);
if ( strcmp(symbol,"BCH") == 0 )
retjson = electrum_scripthash_cmd(symbol,coin->taddr,ep,retjsonp,"get_history",addr);
else retjson = electrum_strarg(symbol,ep,retjsonp,"blockchain.address.get_history",addr,ELECTRUM_TIMEOUT);
//printf("history.(%s)\n",jprint(retjson,0)); //printf("history.(%s)\n",jprint(retjson,0));
if ( retjson != 0 && (n= cJSON_GetArraySize(retjson)) > 0 ) if ( retjson != 0 && (n= cJSON_GetArraySize(retjson)) > 0 )
{ {
@ -574,7 +588,11 @@ int32_t LP_txheight_check(struct iguana_info *coin,char *coinaddr,bits256 txid)
cJSON *electrum_address_getmempool(char *symbol,struct electrum_info *ep,cJSON **retjsonp,char *addr,bits256 reftxid,bits256 reftxid2) cJSON *electrum_address_getmempool(char *symbol,struct electrum_info *ep,cJSON **retjsonp,char *addr,bits256 reftxid,bits256 reftxid2)
{ {
cJSON *retjson; struct iguana_info *coin = LP_coinfind(symbol); cJSON *retjson; struct iguana_info *coin = LP_coinfind(symbol);
retjson = electrum_strarg(symbol,ep,retjsonp,"blockchain.address.get_mempool",addr,ELECTRUM_TIMEOUT); if ( coin == 0 )
return(0);
if ( strcmp(symbol,"BCH") == 0 )
retjson = electrum_scripthash_cmd(symbol,coin->taddr,ep,retjsonp,"get_mempool",addr);
else retjson = electrum_strarg(symbol,ep,retjsonp,"blockchain.address.get_mempool",addr,ELECTRUM_TIMEOUT);
//printf("MEMPOOL.(%s)\n",jprint(retjson,0)); //printf("MEMPOOL.(%s)\n",jprint(retjson,0));
electrum_process_array(coin,ep,addr,retjson,1,reftxid,reftxid2); electrum_process_array(coin,ep,addr,retjson,1,reftxid,reftxid2);
return(retjson); return(retjson);
@ -601,7 +619,10 @@ cJSON *electrum_address_listunspent(char *symbol,struct electrum_info *ep,cJSON
} }
if ( usecache == 0 || electrumflag > 1 ) if ( usecache == 0 || electrumflag > 1 )
{ {
if ( (retjson= electrum_strarg(symbol,ep,retjsonp,"blockchain.address.listunspent",addr,ELECTRUM_TIMEOUT)) != 0 ) if ( strcmp(symbol,"BCH") == 0 )
retjson = electrum_scripthash_cmd(symbol,coin->taddr,ep,retjsonp,"listunspent",addr);
else retjson = electrum_strarg(symbol,ep,retjsonp,"blockchain.address.listunspent",addr,ELECTRUM_TIMEOUT);
if ( retjson != 0 )
{ {
if ( jobj(retjson,"error") == 0 && is_cJSON_Array(retjson) != 0 ) if ( jobj(retjson,"error") == 0 && is_cJSON_Array(retjson) != 0 )
{ {
@ -642,7 +663,9 @@ cJSON *electrum_address_listunspent(char *symbol,struct electrum_info *ep,cJSON
cJSON *electrum_address_getbalance(char *symbol,struct electrum_info *ep,cJSON **retjsonp,char *addr) cJSON *electrum_address_getbalance(char *symbol,struct electrum_info *ep,cJSON **retjsonp,char *addr)
{ {
return(electrum_strarg(symbol,ep,retjsonp,"blockchain.address.get_balance",addr,ELECTRUM_TIMEOUT)); if ( strcmp(symbol,"BCH") == 0 )
return(electrum_scripthash_cmd(symbol,0,ep,retjsonp,"get_balance",addr));
else return(electrum_strarg(symbol,ep,retjsonp,"blockchain.address.get_balance",addr,ELECTRUM_TIMEOUT));
} }
cJSON *electrum_addpeer(char *symbol,struct electrum_info *ep,cJSON **retjsonp,char *endpoint) { return(electrum_strarg(symbol,ep,retjsonp,"server.add_peer",endpoint,ELECTRUM_TIMEOUT)); } cJSON *electrum_addpeer(char *symbol,struct electrum_info *ep,cJSON **retjsonp,char *endpoint) { return(electrum_strarg(symbol,ep,retjsonp,"server.add_peer",endpoint,ELECTRUM_TIMEOUT)); }
@ -750,6 +773,8 @@ cJSON *electrum_transaction(int32_t *heightp,char *symbol,struct electrum_info *
{ {
cJSON *retjson,*array; bits256 zero; struct LP_transaction *tx=0; struct iguana_info *coin; cJSON *retjson,*array; bits256 zero; struct LP_transaction *tx=0; struct iguana_info *coin;
coin = LP_coinfind(symbol); coin = LP_coinfind(symbol);
if ( coin == 0 )
return(0);
*heightp = 0; *heightp = 0;
if ( ep != 0 ) if ( ep != 0 )
portable_mutex_lock(&ep->txmutex); portable_mutex_lock(&ep->txmutex);

2
iguana/exchanges/LP_stats.c

@ -500,7 +500,7 @@ int32_t LP_statslog_parsequote(char *method,cJSON *lineobj)
satoshis = j64bits(lineobj,"satoshis"); satoshis = j64bits(lineobj,"satoshis");
if ( base == 0 || rel == 0 || satoshis == 0 ) if ( base == 0 || rel == 0 || satoshis == 0 )
{ {
printf("quoteparse_error.(%s)\n",jprint(lineobj,0)); //printf("quoteparse_error.(%s)\n",jprint(lineobj,0));
LP_parse_errors++; LP_parse_errors++;
return(-1); return(-1);
} }

3
iguana/exchanges/LP_transaction.c

@ -124,8 +124,7 @@ bits256 LP_broadcast(char *txname,char *symbol,char *txbytes,bits256 expectedtxi
totalretries++; totalretries++;
i--; i--;
} }
} } else printf("broadcast error.(%s)\n",retstr);
else printf("broadcast error.(%s)\n",retstr);
} }
free_json(retjson); free_json(retjson);
} }

2
iguana/exchanges/LP_utxo.c

@ -483,6 +483,8 @@ struct LP_address *LP_address_utxo_reset(struct iguana_info *coin)
//{"tx_hash":"38d1b7c73015e1b1d6cb7fc314cae402a635b7d7ea294970ab857df8777a66f4","tx_pos":0,"height":577975,"value":238700} //{"tx_hash":"38d1b7c73015e1b1d6cb7fc314cae402a635b7d7ea294970ab857df8777a66f4","tx_pos":0,"height":577975,"value":238700}
item = jitem(array,i); item = jitem(array,i);
value = LP_listunspent_parseitem(coin,&txid,&vout,&height,item); value = LP_listunspent_parseitem(coin,&txid,&vout,&height,item);
if ( bits256_nonz(txid) == 0 )
continue;
if ( 1 ) if ( 1 )
{ {
if ( (txobj= LP_gettxout(coin->symbol,coin->smartaddr,txid,vout)) == 0 ) if ( (txobj= LP_gettxout(coin->symbol,coin->smartaddr,txid,vout)) == 0 )

11
iguana/exchanges/client_static

@ -0,0 +1,11 @@
#!/bin/bash
source passphrase
source coins
pkill -15 marketmaker;
git pull;
cd ..;
make -f m_mm_StaticNanoMsg -j2 all;
rm -rf ./marketmaker
cp -av ../agents/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

1
iguana/exchanges/enable

@ -1,6 +1,7 @@
#!/bin/bash #!/bin/bash
source userpass 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\":\"BEER\"}"
curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"enable\",\"coin\":\"ETOMIC\"}"
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\":\"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\":\"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\":\"KMD\"}"

2
iguana/exchanges/fundLP

@ -0,0 +1,2 @@
fiat/$1 sendmany \"\" "{\"RMfQwu5ey23eWJ4as2ckd8dqsQJwo836ny\":$2,\"RQzkkncY8ehpRg8M4kvKmDMcbFxcJvohgk\":$2,\"RXUF132uyPVTVUdLn16zCgvYoFXya3pyVb\":$2,\"RNyBS6ryQtPPQnJhavKn9o94U2RNExLZon\":$2,\"RPMpwKpzWyg5KoMcsuy3mZucUWNdcP2ndD\":$2,\"RVPcbafNSi6uMaKDyss9epGpHCHbbzUFMd\":$2,\"RAzheh3L7QtBL7oNKByVa43CtgALht6bbT\":$2,\"RMdjuxKBhyr87yhKp6BLUg2p9673NMcPAu\":$2,\"RUPX5RWQL1qurMLmF4fFB4JAgRfwcNww4b\":$2,\"RQLn2QYwXDemFN3DNigU5qv3wUrA3WqquA\":$2,\"RMfQwu5ey23eWJ4as2ckd8dqsQJwo836ny\":$2,\"RQzkkncY8ehpRg8M4kvKmDMcbFxcJvohgk\":$2,\"RXUF132uyPVTVUdLn16zCgvYoFXya3pyVb\":$2,\"RNyBS6ryQtPPQnJhavKn9o94U2RNExLZon\":$2,\"RPMpwKpzWyg5KoMcsuy3mZucUWNdcP2ndD\":$2,\"RVPcbafNSi6uMaKDyss9epGpHCHbbzUFMd\":$2,\"RAzheh3L7QtBL7oNKByVa43CtgALht6bbT\":$2,\"RMdjuxKBhyr87yhKp6BLUg2p9673NMcPAu\":$2,\"RUPX5RWQL1qurMLmF4fFB4JAgRfwcNww4b\":$2,\"RQLn2QYwXDemFN3DNigU5qv3wUrA3WqquA\":$2,\"RMfQwu5ey23eWJ4as2ckd8dqsQJwo836ny\":$2,\"RQzkkncY8ehpRg8M4kvKmDMcbFxcJvohgk\":$2,\"RXUF132uyPVTVUdLn16zCgvYoFXya3pyVb\":$2,\"RNyBS6ryQtPPQnJhavKn9o94U2RNExLZon\":$2,\"RPMpwKpzWyg5KoMcsuy3mZucUWNdcP2ndD\":$2,\"RVPcbafNSi6uMaKDyss9epGpHCHbbzUFMd\":$2,\"RAzheh3L7QtBL7oNKByVa43CtgALht6bbT\":$2,\"RMdjuxKBhyr87yhKp6BLUg2p9673NMcPAu\":$2,\"RUPX5RWQL1qurMLmF4fFB4JAgRfwcNww4b\":$2,\"RQLn2QYwXDemFN3DNigU5qv3wUrA3WqquA\":$2,\"RMfQwu5ey23eWJ4as2ckd8dqsQJwo836ny\":$2,\"RQzkkncY8ehpRg8M4kvKmDMcbFxcJvohgk\":$2,\"RXUF132uyPVTVUdLn16zCgvYoFXya3pyVb\":$2,\"RNyBS6ryQtPPQnJhavKn9o94U2RNExLZon\":$2,\"RPMpwKpzWyg5KoMcsuy3mZucUWNdcP2ndD\":$2,\"RVPcbafNSi6uMaKDyss9epGpHCHbbzUFMd\":$2,\"RAzheh3L7QtBL7oNKByVa43CtgALht6bbT\":$2,\"RMdjuxKBhyr87yhKp6BLUg2p9673NMcPAu\":$2,\"RUPX5RWQL1qurMLmF4fFB4JAgRfwcNww4b\":$2,\"RQLn2QYwXDemFN3DNigU5qv3wUrA3WqquA\":$2,\"RMfQwu5ey23eWJ4as2ckd8dqsQJwo836ny\":$2,\"RQzkkncY8ehpRg8M4kvKmDMcbFxcJvohgk\":$2,\"RXUF132uyPVTVUdLn16zCgvYoFXya3pyVb\":$2,\"RNyBS6ryQtPPQnJhavKn9o94U2RNExLZon\":$2,\"RPMpwKpzWyg5KoMcsuy3mZucUWNdcP2ndD\":$2,\"RVPcbafNSi6uMaKDyss9epGpHCHbbzUFMd\":$2,\"RAzheh3L7QtBL7oNKByVa43CtgALht6bbT\":$2,\"RMdjuxKBhyr87yhKp6BLUg2p9673NMcPAu\":$2,\"RUPX5RWQL1qurMLmF4fFB4JAgRfwcNww4b\":$2,\"RQLn2QYwXDemFN3DNigU5qv3wUrA3WqquA\":$2,\"RMfQwu5ey23eWJ4as2ckd8dqsQJwo836ny\":$2,\"RQzkkncY8ehpRg8M4kvKmDMcbFxcJvohgk\":$2,\"RXUF132uyPVTVUdLn16zCgvYoFXya3pyVb\":$2,\"RNyBS6ryQtPPQnJhavKn9o94U2RNExLZon\":$2,\"RPMpwKpzWyg5KoMcsuy3mZucUWNdcP2ndD\":$2,\"RVPcbafNSi6uMaKDyss9epGpHCHbbzUFMd\":$2,\"RAzheh3L7QtBL7oNKByVa43CtgALht6bbT\":$2,\"RMdjuxKBhyr87yhKp6BLUg2p9673NMcPAu\":$2,\"RUPX5RWQL1qurMLmF4fFB4JAgRfwcNww4b\":$2,\"RQLn2QYwXDemFN3DNigU5qv3wUrA3WqquA\":$2,\"RMfQwu5ey23eWJ4as2ckd8dqsQJwo836ny\":$2,\"RQzkkncY8ehpRg8M4kvKmDMcbFxcJvohgk\":$2,\"RXUF132uyPVTVUdLn16zCgvYoFXya3pyVb\":$2,\"RNyBS6ryQtPPQnJhavKn9o94U2RNExLZon\":$2,\"RPMpwKpzWyg5KoMcsuy3mZucUWNdcP2ndD\":$2,\"RVPcbafNSi6uMaKDyss9epGpHCHbbzUFMd\":$2,\"RAzheh3L7QtBL7oNKByVa43CtgALht6bbT\":$2,\"RMdjuxKBhyr87yhKp6BLUg2p9673NMcPAu\":$2,\"RUPX5RWQL1qurMLmF4fFB4JAgRfwcNww4b\":$2,\"RQLn2QYwXDemFN3DNigU5qv3wUrA3WqquA\":$2,\"RMfQwu5ey23eWJ4as2ckd8dqsQJwo836ny\":$2,\"RQzkkncY8ehpRg8M4kvKmDMcbFxcJvohgk\":$2,\"RXUF132uyPVTVUdLn16zCgvYoFXya3pyVb\":$2,\"RNyBS6ryQtPPQnJhavKn9o94U2RNExLZon\":$2,\"RPMpwKpzWyg5KoMcsuy3mZucUWNdcP2ndD\":$2,\"RVPcbafNSi6uMaKDyss9epGpHCHbbzUFMd\":$2,\"RAzheh3L7QtBL7oNKByVa43CtgALht6bbT\":$2,\"RMdjuxKBhyr87yhKp6BLUg2p9673NMcPAu\":$2,\"RUPX5RWQL1qurMLmF4fFB4JAgRfwcNww4b\":$2,\"RQLn2QYwXDemFN3DNigU5qv3wUrA3WqquA\":$2,\"RMfQwu5ey23eWJ4as2ckd8dqsQJwo836ny\":$2,\"RQzkkncY8ehpRg8M4kvKmDMcbFxcJvohgk\":$2,\"RXUF132uyPVTVUdLn16zCgvYoFXya3pyVb\":$2,\"RNyBS6ryQtPPQnJhavKn9o94U2RNExLZon\":$2,\"RPMpwKpzWyg5KoMcsuy3mZucUWNdcP2ndD\":$2,\"RVPcbafNSi6uMaKDyss9epGpHCHbbzUFMd\":$2,\"RAzheh3L7QtBL7oNKByVa43CtgALht6bbT\":$2,\"RMdjuxKBhyr87yhKp6BLUg2p9673NMcPAu\":$2,\"RUPX5RWQL1qurMLmF4fFB4JAgRfwcNww4b\":$2,\"RQLn2QYwXDemFN3DNigU5qv3wUrA3WqquA\":$2,\"RMfQwu5ey23eWJ4as2ckd8dqsQJwo836ny\":$2,\"RQzkkncY8ehpRg8M4kvKmDMcbFxcJvohgk\":$2,\"RXUF132uyPVTVUdLn16zCgvYoFXya3pyVb\":$2,\"RNyBS6ryQtPPQnJhavKn9o94U2RNExLZon\":$2,\"RPMpwKpzWyg5KoMcsuy3mZucUWNdcP2ndD\":$2,\"RVPcbafNSi6uMaKDyss9epGpHCHbbzUFMd\":$2,\"RAzheh3L7QtBL7oNKByVa43CtgALht6bbT\":$2,\"RMdjuxKBhyr87yhKp6BLUg2p9673NMcPAu\":$2,\"RUPX5RWQL1qurMLmF4fFB4JAgRfwcNww4b\":$2,\"RQLn2QYwXDemFN3DNigU5qv3wUrA3WqquA\":$2,\"RMfQwu5ey23eWJ4as2ckd8dqsQJwo836ny\":$2,\"RQzkkncY8ehpRg8M4kvKmDMcbFxcJvohgk\":$2,\"RXUF132uyPVTVUdLn16zCgvYoFXya3pyVb\":$2,\"RNyBS6ryQtPPQnJhavKn9o94U2RNExLZon\":$2,\"RPMpwKpzWyg5KoMcsuy3mZucUWNdcP2ndD\":$2,\"RVPcbafNSi6uMaKDyss9epGpHCHbbzUFMd\":$2,\"RAzheh3L7QtBL7oNKByVa43CtgALht6bbT\":$2,\"RMdjuxKBhyr87yhKp6BLUg2p9673NMcPAu\":$2,\"RUPX5RWQL1qurMLmF4fFB4JAgRfwcNww4b\":$2,\"RQLn2QYwXDemFN3DNigU5qv3wUrA3WqquA\":$2}" 0

2
iguana/exchanges/install

@ -1,5 +1,5 @@
#!/bin/bash #!/bin/bash
cp install get_supernet trackbtc auto_chipskmd auto_chipsbtc pendingswaps fundvalue balances dynamictrust getcoin kickstart tradesarray claim deposit10 deposit1 invreset sendrawtransaction processfiles stop millis mnzservers bot_buy bot_list bot_statuslist bot_pause bot_resume bot_sell bot_settings bot_status bot_stop guistats pubkeystats pendings coinswaps baserelswaps setpassphrase notarizations getrawtransaction parselog statsdisp m_js trust trusted setconfirms balance listunspent electrum snapshot_balance snapshot_loop secretaddresses dividends snapshot goals goal portfolio autoprice deletemessages getmessages debug buy sell bestfit orderbook client run_osx client_osx run coins disable enable myprice myprices getcoins getpeers getpeersIP getprices help inv setprice status ../dexscripts cp install get_supernet trackbtc auto_chipskmd auto_chipsbtc pendingswaps fundvalue balances dynamictrust getcoin kickstart tradesarray claim deposit10 deposit1 invreset sendrawtransaction processfiles stop millis mnzservers bot_buy bot_list bot_statuslist bot_pause bot_resume bot_sell bot_settings bot_status bot_stop guistats pubkeystats pendings coinswaps baserelswaps setpassphrase notarizations getrawtransaction parselog statsdisp m_js trust trusted setconfirms balance listunspent electrum snapshot_balance snapshot_loop secretaddresses dividends snapshot goals goal portfolio autoprice deletemessages getmessages debug buy sell bestfit orderbook client run_osx client_osx client_static run coins disable enable myprice myprices getcoins getpeers getpeersIP getprices help inv setprice status ../dexscripts
cp coins.json .. cp coins.json ..
cd ../dexscripts cd ../dexscripts
#cp ../exchanges/passphrase ../exchanges/userpass . #cp ../exchanges/passphrase ../exchanges/userpass .

1
iguana/exchanges/prices/autoprice

@ -13,6 +13,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\":\"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\":\"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}" curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"autoprice\",\"base\":\"BEER\",\"rel\":\"PIZZA\",\"fixed\":0.0001,\"margin\":0.00001}"
curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"autoprice\",\"base\":\"BEER\",\"rel\":\"ETOMIC\",\"fixed\":10,\"margin\":0.00001}"
source crypto source crypto
source trackbtc source trackbtc

4
iguana/exchanges/to_etomic

@ -0,0 +1,4 @@
rm /usr/bin/g++
ln /usr/bin/g++-7 /usr/bin/g++
rm /usr/bin/gcc
ln /usr/bin/gcc-7 /usr/bin/gcc

4
iguana/exchanges/to_zcash

@ -0,0 +1,4 @@
rm /usr/bin/g++
ln /usr/bin/g++-5 /usr/bin/g++
rm /usr/bin/gcc
ln /usr/bin/gcc-5 /usr/bin/gcc

1
iguana/m_LP_StaticNanoMsg

@ -2,6 +2,7 @@
#./configure --enable-endomorphism --enable-module-ecdh --enable-module-schnorr --enable-module-rangeproof --enable-experimental --enable-module_recovery #./configure --enable-endomorphism --enable-module-ecdh --enable-module-schnorr --enable-module-rangeproof --enable-experimental --enable-module_recovery
rm -f ../agents/iguana *.o rm -f ../agents/iguana *.o
git pull git pull
./build_static_nanomsg.sh
cd secp256k1; ./m_unix; cd .. cd secp256k1; ./m_unix; cd ..
cd ../crypto777; make -f m_LP_StaticNanoMsg all; make -f m_LP_StaticNanoMsg clean; cd ../iguana cd ../crypto777; make -f m_LP_StaticNanoMsg all; make -f m_LP_StaticNanoMsg clean; cd ../iguana

15
iguana/m_mm

@ -1,3 +1,16 @@
cd secp256k1; ./m_unix; cd .. cd secp256k1; ./m_unix; cd ..
cd ../crypto777; ./m_LP; cd ../iguana 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
if [[ "$OSTYPE" == "linux-gnu" ]]; then
echo "Linux"
# Default is dynamic nanomsg for linux using this script
nanomsg_lib="-lnanomsg"
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
nanomsg_lib="../OSlibs/osx/$(uname -m)/libnanomsg-static.a"
fi
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 $nanomsg_lib -lcurl -lpthread -lm

Loading…
Cancel
Save