Browse Source

Merge pull request #477 from jl777/spvdex

enforce identical requestid and quoteid at start of atomic swap
etomic
jl777 8 years ago
committed by GitHub
parent
commit
15c8c5b674
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      crypto777/bitcoind_RPC.c
  2. 33
      crypto777/cJSON.c
  3. 7
      iguana/dexscripts.win32/bot_buy.cmd
  4. 7
      iguana/dexscripts.win32/bot_list.cmd
  5. 7
      iguana/dexscripts.win32/bot_statuslist.cmd
  6. 7
      iguana/dexscripts.win32/bot_stop.cmd
  7. 9
      iguana/dexscripts.win32/electrum.cmd
  8. 2
      iguana/dexscripts.win32/help.cmd
  9. 62
      iguana/dexscripts.win32/how_to_use.md
  10. BIN
      iguana/dexscripts.win32/images/conemu_jq.png
  11. 5
      iguana/dexscripts.win32/sendrawtransaction.cmd
  12. 8
      iguana/dexscripts.win32/withdraw.cmd
  13. 14
      iguana/dexscripts.win32/withdraw_10_send.cmd
  14. 14
      iguana/dexscripts.win32/withdraw_send.cmd
  15. 6
      iguana/exchanges/LP_cache.c
  16. 6
      iguana/exchanges/LP_commands.c
  17. 6
      iguana/exchanges/LP_include.h
  18. 25
      iguana/exchanges/LP_nativeDEX.c
  19. 11
      iguana/exchanges/LP_ordermatch.c
  20. 37
      iguana/exchanges/LP_remember.c
  21. 18
      iguana/exchanges/LP_swap.c
  22. 67
      iguana/exchanges/LP_utxo.c
  23. 1
      iguana/exchanges/invreset
  24. 10
      iguana/exchanges/mm.c
  25. 2
      iguana/m_mm
  26. 3
      includes/cJSON.h
  27. 47
      marketmaker_build_32_64.cmd

2
crypto777/bitcoind_RPC.c

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

33
crypto777/cJSON.c

@ -578,8 +578,6 @@ cJSON *cJSON_CreateFalse(void) {cJSON *item=cJSON_New_Item();if(item)item->t
cJSON *cJSON_CreateBool(int32_t b) {cJSON *item=cJSON_New_Item();if(item)item->type=b?cJSON_True:cJSON_False;return item;}
cJSON *cJSON_CreateNumber(double num) {cJSON *item=cJSON_New_Item();if(item){item->type=cJSON_Number;item->valuedouble=num;item->valueint=(int64_t)num;}return item;}
cJSON *cJSON_CreateString(const char *string) {cJSON *item=cJSON_New_Item();if(item){item->type=cJSON_String;item->valuestring=cJSON_strdup(string);}return item;}
cJSON *cJSON_CreateArray(void) {cJSON *item=cJSON_New_Item();if(item)item->type=cJSON_Array;return item;}
cJSON *cJSON_CreateObject(void) {cJSON *item=cJSON_New_Item();if(item)item->type=cJSON_Object;return item;}
/* Create Arrays: */
cJSON *cJSON_CreateIntArray(int64_t *numbers,int32_t count) {int32_t i;cJSON *n=0,*p=0,*a=cJSON_CreateArray();for(i=0;a && i<count;i++){n=cJSON_CreateNumber((double)numbers[i]);if(!i)a->child=n;else suffix_object(p,n);p=n;}return a;}
@ -1129,4 +1127,33 @@ cJSON *addrs_jsonarray(uint64_t *addrs,int32_t num)
return(array);
}
void free_json(cJSON *json) { if ( json != 0 ) cJSON_Delete(json); }
cJSON *cJSON_CreateArray(void)
{
cJSON *item = cJSON_New_Item();
if ( item )
item->type = cJSON_Array;
//#ifdef CJSON_GARBAGECOLLECTION
// cJSON_register(item);
//#endif
return(item);
}
cJSON *cJSON_CreateObject(void)
{
cJSON *item = cJSON_New_Item();
if ( item )
item->type = cJSON_Object;
//#ifdef CJSON_GARBAGECOLLECTION
// cJSON_register(item);
//#endif
return item;
}
void free_json(cJSON *item)
{
//#ifdef CJSON_GARBAGECOLLECTION
// cJSON_unregister(item);
//#endif
if ( item != 0 )
cJSON_Delete(item);
}

7
iguana/dexscripts.win32/bot_buy.cmd

@ -0,0 +1,7 @@
@echo off
set /p TMPUSERPASS=<userpass
set USERPASS=%TMPUSERPASS: =%
set /p PASSPHRASE=<passphrase
echo passphrase: "%PASSPHRASE%"
echo userpass: "%USERPASS%"
curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"%USERPASS%\",\"method\":\"bot_buy\",\"base\":\"MNZ\",\"rel\":\"KMD\",\"maxprice\":0.20,\"relvolume\":10.0}"

7
iguana/dexscripts.win32/bot_list.cmd

@ -0,0 +1,7 @@
@echo off
set /p TMPUSERPASS=<userpass
set USERPASS=%TMPUSERPASS: =%
set /p PASSPHRASE=<passphrase
rem echo passphrase: "%PASSPHRASE%"
rem echo userpass: "%USERPASS%"
curl -s --url "http://127.0.0.1:7783" --data "{\"userpass\":\"%USERPASS%\",\"method\":\"bot_list\"}"

7
iguana/dexscripts.win32/bot_statuslist.cmd

@ -0,0 +1,7 @@
@echo off
set /p TMPUSERPASS=<userpass
set USERPASS=%TMPUSERPASS: =%
set /p PASSPHRASE=<passphrase
rem echo passphrase: "%PASSPHRASE%"
rem echo userpass: "%USERPASS%"
curl -s --url "http://127.0.0.1:7783" --data "{\"userpass\":\"%USERPASS%\",\"method\":\"bot_statuslist\"}"

7
iguana/dexscripts.win32/bot_stop.cmd

@ -0,0 +1,7 @@
@echo off
set /p TMPUSERPASS=<userpass
set USERPASS=%TMPUSERPASS: =%
set /p PASSPHRASE=<passphrase
rem echo passphrase: "%PASSPHRASE%"
rem echo userpass: "%USERPASS%"
curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"%USERPASS%\",\"method\":\"bot_stop\",\"botid\":1376557535}"

9
iguana/dexscripts.win32/electrum.cmd

@ -0,0 +1,9 @@
@echo off
rem http://pad.supernet.org/electrum-servers
set /p TMPUSERPASS=<userpass
set USERPASS=%TMPUSERPASS: =%
set /p PASSPHRASE=<passphrase
echo passphrase: "%PASSPHRASE%"
echo userpass: "%USERPASS%"
curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"%USERPASS%\",\"method\":\"electrum\",\"coin\":\"KMD\",\"ipaddr\":\"electrum.cipig.net\",\"port\":10001}"
curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"%USERPASS%\",\"method\":\"electrum\",\"coin\":\"MNZ\",\"ipaddr\":\"electrum.cipig.net\",\"port\":10002}"

2
iguana/dexscripts.win32/help.cmd

@ -0,0 +1,2 @@
@echo off
curl --url "http://127.0.0.1:7783" --data "{\"method\":\"help\"}"

62
iguana/dexscripts.win32/how_to_use.md

@ -1,15 +1,15 @@
## DexScripts for Windows. How to use? ##
**1. ** Before start you should put scripts and following binaries into one folder:
**1.** Before start you should put scripts and following binaries into one folder:
- curl.exe (required for all scripts)
- marketmaker.exe
- libcurl.dll (required to run marketmaker)
- nanomsg.dll (required to run marketmaker)
**2. ** Don't forget to put `coins.json` file into a same folder. This file is available it this repo.
**2.** Don't forget to put `coins.json` file into a same folder. This file is available it this repo.
**3. ** Type your passphrase into passphrase file in this folder (you should create file with name `passphrase` and without extension) and run `1-client.cmd`. This will run marketmaker. Next step is to obtain userpass needed for other scripts, you can simply copy and paste it from marketmaker output on startup into userpass file.
**3.** Type your passphrase into passphrase file in this folder (you should create file with name `passphrase` and without extension) and run `1-client.cmd`. This will run marketmaker. Next step is to obtain userpass needed for other scripts, you can simply copy and paste it from marketmaker output on startup into userpass file.
![](./images/userpass.png)
@ -23,9 +23,41 @@ You should see your userpass on screen, and after it will automatically copied i
**4.** For using other scripts please refer to barterDEX API. Or **barterDEX API Summary by Category** document by *shossain*.
## Scripts List ##
**NB!** Before you use any script that do some actions with your coins (for example, withdraw and others) **edit it** and make sure that it have correct addresses, coin name and volumes inside. Don't run any scripts without looking on it's source and clearly understanding what it does.
* **1-client.cmd** - used to start Marketmaker. Make sure you already have filled a strong passphrase into `passphrase` file as described above.
* **2-getuserpass.cmd** - fills userpass in `userpass` file. this step needed to use any other scripts.
* **balance.cmd** - displays current balance of selected coin.
* **enable.cmd** - enables a selected coin for trading.
* **getcoin.cmd** - prints information about a selecting coin:
{"result":"success","enabled":2,"disabled":70,"coin":{"coin":"KMD","installed":true,"height":580716,"balance":72.68774305,"KMDvalue":72.68774305,"status":"active","electrum":"electrum.cipig.net:10001","smartaddress":"RTCVGuoSNehKG8YYxcoskC7LK1yZhgvQRV","rpc":"127.0.0.1:7771","pubtype":60,"p2shtype":85,"wiftype":188,"txfee":10000}}
* **getutxos.cmd** - seems alredy deprecated.
* **inventory.cmd** - prints your inventory.
* **listunspent.cmd** - prints your utxos.
* **orderbook.cmd** - prints base/rel orderbook.
* **portfolio.cmd** - prints porfolio information.
* **snapshot.cmd** - ...
* **electrum.cmd** - allows you to run coins in electum mode (!), example includes two coins - KMD and MNZ. if you need to run more coins in electrum mode, add needed electrum servers from here - [http://pad.supernet.org/electrum-servers](http://pad.supernet.org/electrum-servers).
* **help.cmd** - displays help about all available API commands.
* **bot_buy.cmd** - launches bot for buying. you'll need to set base and rel coin in script, and also maxprice and relvolume.
* **bot_list.cmd** - lists id of all running bots.
* **bot_statuslist.cmd** - list statuses of all running bots.
* **bot_stop.cmd** - stopt the bot with given bot_id.
* **withdraw.cmd** - example of withdraw method. you can send coins from your smartaddress to any other address using widthraw. as a result method generates signed raw tx in hex, which you can use with sendrawtransaction.cmd . remember, that withdraw only *prepares* transaction, but it doesn't broadcast (send) it to network. after tx is prepared we need to send it using sendrawtransaction method.
* **sendrawtransaction.cmd** - sends raw transaction. you'll need a signedtx in hex.
* **withdraw_send.cmd** - combines withdraw and send raw tx scripts. you can call it `send`, just specify coin, volume and addresses to which you wan send coins and it will prepare and broadcast transaction automatically.
* **withdraw_10_send.cmd** - example of inventory split: this split 10 KMD from your balance to Alice inventory in 10 utxos pairs (1.002, 0.00386871). Strongly recommended to read [http://pad.supernet.org/barterdex-readme](http://pad.supernet.org/barterdex-readme) -> UTXO PAIRS to understand the basics. This script is just for example how you can split your coins in (X, X/777) to start trading them.
## F.A.Q. ##
**Q.** Is any simple way how i can display JSON results returned by all scripts, like orderbook and others, in human readable form?
**A.** Yes, you can use this service [JSON Editor Online](http://jsoneditoronline.org/), just copy and paste output of script in left column and see structured output in right.
**Q.** I see an output like this when i'm start `1-client.cmd` :
@ -42,3 +74,27 @@ And nothing works.
**A.** Before run `1-client.cmd` make sure in Task Manager that you haven't already running `marketmaker.exe`. If have - kill this process via Task Manager or via command line command `taskkill /f /im taskkill.exe` .
**Q.** How can i pretty print JSON answers of marketmaker?
**A.** You can get best results with 2 tools - [conemu](https://conemu.github.io/) and [jq](https://stedolan.github.io/jq/), conemu supports ANSI X3.64 and Xterm 256 colors and jq allow you to pretty-print json output with colors, like this:
![](./images/conemu_jq.png)
Also i'm always recommend to install [Far Manager](https://www.farmanager.com/index.php?l=en) - this is powerful console file manager for Windows, like Midnight Commander in *nix.
**Q.** What additional dependencies required by marketmaker?
**A.** Currently marketmaker (Windows) used the following DLLs:
*32 bit:*
- libcrypto-1_1.dll
- libcurl.dll
- libssl-1_1.dll
- nanomsg.dll
- pthreadvc2.dll
*64-bit:*
- libcurl.dll
- nanomsg.dll
It already included in repo and in archive with release.

BIN
iguana/dexscripts.win32/images/conemu_jq.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 31 KiB

5
iguana/dexscripts.win32/sendrawtransaction.cmd

@ -0,0 +1,5 @@
@echo off
set /p TMPUSERPASS=<userpass
set USERPASS=%TMPUSERPASS: =%
set HEX=your_signed_raw_tx
curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"%USERPASS%\",\"method\":\"sendrawtransaction\",\"coin\":\"KMD\",\"signedtx\":%HEX%"\"}"

8
iguana/dexscripts.win32/withdraw.cmd

@ -0,0 +1,8 @@
@echo off
set /p TMPUSERPASS=<userpass
set USERPASS=%TMPUSERPASS: =%
rem *** Change coin and outputs before use (!) ***
set COIN=KMD
set OUTPUTS=[{\"RDecker69MM5dhDBosUXPNTzfoGqxPQqHu\":0.00007777}]
curl -s --url "http://127.0.0.1:7783" --data "{\"userpass\":\"%USERPASS%\",\"method\":\"withdraw\",\"coin\":\"%COIN%\",\"outputs\":%OUTPUTS%}" > withdraw.txt
type withdraw.txt

14
iguana/dexscripts.win32/withdraw_10_send.cmd

@ -0,0 +1,14 @@
@echo off
set /p TMPUSERPASS=<userpass
set USERPASS=%TMPUSERPASS: =%
rem *** Change coin and outputs before use (!) ***
set COIN=KMD
set SMARTADDRESS=RDecker69MM5dhDBosUXPNTzfoGqxPQqHu
set OUTPUTS=[{\"%SMARTADDRESS%\":1.002},{\"%SMARTADDRESS%\":0.00386871},{\"%SMARTADDRESS%\":1.002},{\"%SMARTADDRESS%\":0.00386871},{\"%SMARTADDRESS%\":1.002},{\"%SMARTADDRESS%\":0.00386871},{\"%SMARTADDRESS%\":1.002},{\"%SMARTADDRESS%\":0.00386871},{\"%SMARTADDRESS%\":1.002},{\"%SMARTADDRESS%\":0.00386871},{\"%SMARTADDRESS%\":1.002},{\"%SMARTADDRESS%\":0.00386871},{\"%SMARTADDRESS%\":1.002},{\"%SMARTADDRESS%\":0.00386871},{\"%SMARTADDRESS%\":1.002},{\"%SMARTADDRESS%\":0.00386871},{\"%SMARTADDRESS%\":1.002},{\"%SMARTADDRESS%\":0.00386871},{\"%SMARTADDRESS%\":1.002},{\"%SMARTADDRESS%\":0.00386871}]
curl -s --url "http://127.0.0.1:7783" --data "{\"userpass\":\"%USERPASS%\",\"method\":\"withdraw\",\"coin\":\"%COIN%\",\"outputs\":%OUTPUTS%}" > withdraw.txt
type withdraw.txt
timeout /t 5 /nobreak
for /f "tokens=4 delims=:," %%a in (' find "hex" "withdraw.txt" ') do (
rem echo [%%~a]
curl -s --url "http://127.0.0.1:7783" --data "{\"userpass\":\"%USERPASS%\",\"method\":\"sendrawtransaction\",\"coin\":\"%COIN%\",\"signedtx\":\"%%~a\"}"
)

14
iguana/dexscripts.win32/withdraw_send.cmd

@ -0,0 +1,14 @@
@echo off
set /p TMPUSERPASS=<userpass
set USERPASS=%TMPUSERPASS: =%
rem *** Change coin and outputs before use (!) ***
set COIN=KMD
set OUTPUTS=[{\"RDecker69MM5dhDBosUXPNTzfoGqxPQqHu\":0.00007777}]
curl -s --url "http://127.0.0.1:7783" --data "{\"userpass\":\"%USERPASS%\",\"method\":\"withdraw\",\"coin\":\"%COIN%\",\"outputs\":%OUTPUTS%}" > withdraw.txt
type withdraw.txt
timeout /t 5 /nobreak
for /f "tokens=4 delims=:," %%a in (' find "hex" "withdraw.txt" ') do (
rem echo [%%~a]
curl -s --url "http://127.0.0.1:7783" --data "{\"userpass\":\"%USERPASS%\",\"method\":\"sendrawtransaction\",\"coin\":\"%COIN%\",\"signedtx\":\"%%~a\"}"
)

6
iguana/exchanges/LP_cache.c

@ -45,10 +45,10 @@ struct LP_transaction *LP_create_transaction(struct iguana_info *coin,bits256 tx
vins = jarray(&numvins,txobj,"vin");
vouts = jarray(&numvouts,txobj,"vout");
tx = LP_transactionadd(coin,txid,height,numvouts,numvins);
tx->serialized = serialized;
//free(serialized);
tx->serialized = 0;//serialized;
free(serialized);
tx->fpos = fpos;
tx->len = tx->len;
tx->len = 0;//tx->len;
tx->SPV = tx->height = height;
//printf("tx.%s numvins.%d numvouts.%d\n",bits256_str(str,txid),numvins,numvouts);
for (i=0; i<numvouts; i++)

6
iguana/exchanges/LP_commands.c

@ -35,8 +35,12 @@ char *LP_numutxos()
char *stats_JSON(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson,char *remoteaddr,uint16_t port) // from rpc port
{
char *method,*userpass,*base,*rel,*coin,*retstr = 0; int32_t changed,flag = 0; cJSON *retjson,*reqjson = 0; struct iguana_info *ptr;
//printf("stats_JSON(%s)\n",jprint(argjson,0));
method = jstr(argjson,"method");
/*if ( //strcmp(method,"uitem") == 0 || strcmp(method,"postutxos") == 0 ||
strcmp(method,"notify") == 0
|| strcmp(method,"postprice") == 0
)
return(clonestr("{}"));*/
/*if ( (ipaddr= jstr(argjson,"ipaddr")) != 0 && (argport= juint(argjson,"port")) != 0 && (method == 0 || strcmp(method,"electrum") != 0) )
{
if ( strcmp(ipaddr,"127.0.0.1") != 0 && argport >= 1000 )

6
iguana/exchanges/LP_include.h

@ -23,7 +23,7 @@
#define LP_MAJOR_VERSION "0"
#define LP_MINOR_VERSION "1"
#define LP_BUILD_NUMBER "14414"
#define LP_BUILD_NUMBER "15000"
#ifdef FROM_JS
#include <emscripten.h>
@ -53,8 +53,8 @@ void emscripten_usleep(int32_t x); // returns immediate, no sense for sleeping
#define LP_MIN_PEERS 8
#define LP_MAX_PEERS 32
#define LP_MAXDESIRED_UTXOS 128
#define LP_MINDESIRED_UTXOS 32
#define LP_MAXDESIRED_UTXOS (IAMLP != 0 ? 128 : 64)
#define LP_MINDESIRED_UTXOS (IAMLP != 0 ? 32 : 16)
#define LP_DUSTCOMBINE_THRESHOLD 1000000
// RTmetrics

25
iguana/exchanges/LP_nativeDEX.c

@ -17,16 +17,14 @@
// LP_nativeDEX.c
// marketmaker
//
// single utxo allocations alice
// gc cJSON
// more retries for swap sendrawtransaction
// more retries for swap sendrawtransaction?
// pbca26 unfinished swaps
// alice waiting for bestprice
//if ( G.LP_pendingswaps != 0 )
//return(-1);
// if ( G.LP_pendingswaps != 0 ) return(-1);
// bot safe to exit?
//
// BCH signing
// single utxo allocations alice
// alice waiting for bestprice
// previously, it used to show amount, kmd equiv, perc
// dPoW security -> 4: KMD notarized, 5: BTC notarized, after next notary elections
// bigendian architectures need to use little endian for sighash calcs
@ -83,7 +81,7 @@ void LP_millistats_update(struct LP_millistats *mp)
}
#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;
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;
int32_t LP_canbind;
char *Broadcaststr,*Reserved_msgs[2][1000];
int32_t num_Reserved_msgs[2],max_Reserved_msgs[2];
@ -328,7 +326,7 @@ char *LP_process_message(void *ctx,char *typestr,char *myipaddr,int32_t pubsock,
int32_t LP_sock_check(char *typestr,void *ctx,char *myipaddr,int32_t pubsock,int32_t sock,char *remoteaddr,int32_t maxdepth)
{
int32_t recvlen=1,nonz = 0; cJSON *argjson; void *ptr; char methodstr[64],*retstr,*str; struct nn_pollfd pfd;
int32_t recvlen=1,nonz = 0; cJSON *argjson; void *ptr,*buf; char methodstr[64],*retstr,*str; struct nn_pollfd pfd;
if ( sock >= 0 )
{
while ( nonz < maxdepth && recvlen > 0 )
@ -340,8 +338,11 @@ int32_t LP_sock_check(char *typestr,void *ctx,char *myipaddr,int32_t pubsock,int
if ( nn_poll(&pfd,1,1) != 1 )
break;
ptr = 0;
if ( (recvlen= nn_recv(sock,&ptr,NN_MSG,0)) > 0 )
buf = malloc(1000000);
if ( (recvlen= nn_recv(sock,buf,1000000,0)) > 0 )
//if ( (recvlen= nn_recv(sock,&ptr,NN_MSG,0)) > 0 )
{
ptr = buf;
methodstr[0] = 0;
//printf("%s.(%s)\n",typestr,(char *)ptr);
if ( 0 )
@ -391,7 +392,10 @@ int32_t LP_sock_check(char *typestr,void *ctx,char *myipaddr,int32_t pubsock,int
}
}
if ( ptr != 0 )
nn_freemsg(ptr), ptr = 0;
{
//nn_freemsg(ptr), ptr = 0;
free(buf);
}
}
}
return(nonz);
@ -939,6 +943,7 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu
portable_mutex_init(&LP_reservedmutex);
portable_mutex_init(&LP_nanorecvsmutex);
portable_mutex_init(&LP_tradebotsmutex);
portable_mutex_init(&LP_cJSONmutex);
myipaddr = clonestr("127.0.0.1");
#ifndef _WIN32
#ifndef FROM_JS

11
iguana/exchanges/LP_ordermatch.c

@ -449,6 +449,11 @@ int32_t LP_connectstartbob(void *ctx,int32_t pubsock,cJSON *argjson,char *base,c
if ( bits256_nonz(privkey) != 0 && bits256_cmp(G.LP_mypub25519,qp->srchash) == 0 )
{
LP_requestinit(&qp->R,qp->srchash,qp->desthash,base,qp->satoshis-qp->txfee,rel,qp->destsatoshis-qp->desttxfee,qp->timestamp,qp->quotetime,DEXselector);
if ( LP_pendingswap(qp->R.requestid,qp->R.quoteid) > 0 )
{
printf("requestid.%u quoteid.%u is already in progres\n",qp->R.requestid,qp->R.quoteid);
return(-1);
}
if ( (swap= LP_swapinit(1,0,privkey,&qp->R,qp)) == 0 )
{
printf("cant initialize swap\n");
@ -611,6 +616,12 @@ char *LP_connectedalice(cJSON *argjson) // alice
{
retjson = cJSON_CreateObject();
LP_requestinit(&Q.R,Q.srchash,Q.desthash,Q.srccoin,Q.satoshis-Q.txfee,Q.destcoin,Q.destsatoshis-Q.desttxfee,Q.timestamp,Q.quotetime,DEXselector);
if ( LP_pendingswap(Q.R.requestid,Q.R.quoteid) > 0 )
{
printf("requestid.%u quoteid.%u is already in progres\n",Q.R.requestid,Q.R.quoteid);
jaddstr(retjson,"error","swap already in progress");
return(jprint(retjson,1));
}
if ( (swap= LP_swapinit(0,0,Q.privkey,&Q.R,&Q)) == 0 )
{
jaddstr(retjson,"error","couldnt swapinit");

37
iguana/exchanges/LP_remember.c

@ -1441,3 +1441,40 @@ char *basilisk_swapentries(char *refbase,char *refrel,int32_t limit)
return(jprint(retarray,1));
}
int32_t LP_pendingswap(uint32_t requestid,uint32_t quoteid)
{
cJSON *retjson,*array,*pending,*item; uint32_t r,q; char *retstr; int32_t i,n,retval = 0;
if ( (retstr= LP_recent_swaps(1000)) != 0 )
{
if ( (retjson= cJSON_Parse(retstr)) != 0 )
{
if ( (array= jarray(&n,retjson,"swaps")) != 0 )
{
for (i=0; i<n; i++)
{
item = jitem(array,i);
r = juint(jitem(item,0),0);
q = juint(jitem(item,1),0);
if ( r == requestid && q == quoteid )
{
retval = 1;
break;
}
}
}
if ( retval == 0 )
{
if ( (pending= jobj(retjson,"pending")) != 0 )
{
r = juint(pending,"requestid");
q = juint(pending,"quoteid");
if ( r == requestid && q == quoteid )
retval = 1;
}
}
free_json(retjson);
}
free(retstr);
}
return(retval);
}

18
iguana/exchanges/LP_swap.c

@ -187,6 +187,8 @@ uint32_t basilisk_requestid(struct basilisk_request *rp)
int32_t LP_pubkeys_data(struct basilisk_swap *swap,uint8_t *data,int32_t maxlen)
{
int32_t i,datalen = 0;
datalen += iguana_rwnum(1,&data[datalen],sizeof(swap->I.req.requestid),&swap->I.req.requestid);
datalen += iguana_rwnum(1,&data[datalen],sizeof(swap->I.req.quoteid),&swap->I.req.quoteid);
data[datalen++] = swap->I.aliceconfirms;
data[datalen++] = swap->I.bobconfirms;
data[datalen++] = swap->I.alicemaxconfirms;
@ -196,14 +198,22 @@ int32_t LP_pubkeys_data(struct basilisk_swap *swap,uint8_t *data,int32_t maxlen)
data[datalen++] = swap->persistent_pubkey33[i];
for (i=0; i<sizeof(swap->deck)/sizeof(swap->deck[0][0]); i++)
datalen += iguana_rwnum(1,&data[datalen],sizeof(swap->deck[i>>1][i&1]),&swap->deck[i>>1][i&1]);
printf("send >>>>>>>>> r.%u q.%u datalen.%d\n",swap->I.req.requestid,swap->I.req.quoteid,datalen);
return(datalen);
}
int32_t LP_pubkeys_verify(struct basilisk_swap *swap,uint8_t *data,int32_t datalen)
{
int32_t i,nonz=0,alicemaxconfirms,bobmaxconfirms,aliceconfirms,bobconfirms,len = 0; uint8_t other33[33];
if ( datalen == sizeof(swap->otherdeck)+38 )
uint32_t requestid,quoteid; int32_t i,nonz=0,alicemaxconfirms,bobmaxconfirms,aliceconfirms,bobconfirms,len = 0; uint8_t other33[33];
if ( datalen == sizeof(swap->otherdeck)+38+sizeof(uint32_t)*2 )
{
len += iguana_rwnum(0,&data[len],sizeof(requestid),&requestid);
len += iguana_rwnum(0,&data[len],sizeof(quoteid),&quoteid);
if ( requestid != swap->I.req.requestid || quoteid != swap->I.req.quoteid )
{
printf("SWAP requestid.%u quoteid.%u mismatch received r.%u q.%u\n",swap->I.req.requestid,swap->I.req.quoteid,requestid,quoteid);
return(-1);
}
aliceconfirms = data[len++];
bobconfirms = data[len++];
alicemaxconfirms = data[len++];
@ -243,7 +253,7 @@ int32_t LP_pubkeys_verify(struct basilisk_swap *swap,uint8_t *data,int32_t datal
len += iguana_rwnum(0,&data[len],sizeof(swap->otherdeck[i>>1][i&1]),&swap->otherdeck[i>>1][i&1]);
return(0);
}
printf("pubkeys verify size mismatch %d != %d\n",datalen,(int32_t)sizeof(swap->otherdeck)+36);
printf("pubkeys verify size mismatch %d != %d\n",datalen,(int32_t)(sizeof(swap->otherdeck)+38+sizeof(uint32_t)*2));
return(-1);
}
@ -895,7 +905,7 @@ void LP_aliceloop(void *_swap)
}
basilisk_swap_finished(swap);
printf("finish swap.%p\n",swap);
//free(swap);
free(swap);
G.LP_pendingswaps--;
}

67
iguana/exchanges/LP_utxo.c

@ -27,6 +27,73 @@ struct LP_inuse_info
} LP_inuse[1024];
int32_t LP_numinuse;
struct cJSON_list
{
struct cJSON_list *next,*prev;
cJSON *item;
uint32_t timestamp,cjsonid;
} *LP_cJSONlist;
void cJSON_register(cJSON *item)
{
struct cJSON_list *ptr;
ptr = calloc(1,sizeof(*ptr));
ptr->timestamp = (uint32_t)time(NULL);
ptr->item = item;
item->cjsonid = rand();
ptr->cjsonid = item->cjsonid;
portable_mutex_lock(&LP_cJSONmutex);
DL_APPEND(LP_cJSONlist,ptr);
portable_mutex_unlock(&LP_cJSONmutex);
}
char *mbstr(char *str,double n);
void cJSON_unregister(cJSON *item)
{
static uint32_t lasttime;
int32_t n; char *tmpstr; uint64_t total = 0; struct cJSON_list *ptr,*tmp; uint32_t now;
if ( (now= (uint32_t)time(NULL)) > lasttime+6 )
{
n = 0;
DL_FOREACH_SAFE(LP_cJSONlist,ptr,tmp)
{
if ( ptr->item != 0 && ptr->item->child != 0 && ptr->cjsonid != 0 )
{
if ( (tmpstr= jprint(ptr->item,0)) != 0 )
{
total += strlen(tmpstr);
free(tmpstr);
}
}
n++;
}
printf("total %d cJSON pending\n",n);
lasttime = (uint32_t)time(NULL);
}
DL_FOREACH_SAFE(LP_cJSONlist,ptr,tmp)
{
if ( ptr->cjsonid == item->cjsonid )
break;
else if ( now > ptr->timestamp+60 && item->cjsonid != 0 )
{
portable_mutex_lock(&LP_cJSONmutex);
DL_DELETE(LP_cJSONlist,ptr);
portable_mutex_unlock(&LP_cJSONmutex);
printf("free expired\n");
cJSON_Delete(ptr->item);
free(ptr);
}
ptr = 0;
}
if ( ptr != 0 )
{
portable_mutex_lock(&LP_cJSONmutex);
DL_DELETE(LP_cJSONlist,ptr);
free(ptr);
portable_mutex_unlock(&LP_cJSONmutex);
} //else printf("cJSON_unregister of unknown %p %u\n",item,item->cjsonid);
}
struct LP_inuse_info *_LP_inuse_find(bits256 txid,int32_t vout)
{
int32_t i;

1
iguana/exchanges/invreset

@ -1,3 +1,4 @@
#!/bin/bash
source userpass
source passphrase
curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"inventory\",\"coin\":\"KMD\",\"reset\":1,\"passphrase\":\"$passphrase\"}"

10
iguana/exchanges/mm.c

@ -19,11 +19,21 @@
// Copyright © 2017 SuperNET. All rights reserved.
//
/*
#define malloc(n) LP_alloc(n)
#define calloc(a,b) LP_alloc((uint64_t)(a) * (b))
#define free(ptr) LP_free(ptr)*/
void PNACL_message(char *arg,...)
{
}
#define FROM_MARKETMAKER
#ifndef CJSON_GARBAGECOLLECTION
#define CJSON_GARBAGECOLLECTION
#endif
#include <stdio.h>
#include <stdint.h>
#ifndef NATIVE_WINDOWS

2
iguana/m_mm

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

3
includes/cJSON.h

@ -73,6 +73,7 @@ extern "C"
double valuedouble; /* The item's number, if type==cJSON_Number */
char *string; /* The item's name string, if this item is the child of, or is in the list of subitems of an object. */
uint32_t cjsonid;
} cJSON;
typedef struct cJSON_Hooks {
@ -218,6 +219,8 @@ extern "C"
char *nxt64str2(uint64_t nxt64bits);
cJSON *addrs_jsonarray(uint64_t *addrs,int32_t num);
int32_t myatoi(char *str,int32_t range);
void cJSON_register(cJSON *item);
void cJSON_unregister(cJSON *item);
char *stringifyM(char *str);
#define replace_backslashquotes unstringify

47
marketmaker_build_32_64.cmd

@ -0,0 +1,47 @@
@echo off
@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
MSBuild marketmaker.sln /t:Rebuild /p:Configuration=Release /p:Platform=x64
MSBuild marketmaker.sln /t:Rebuild /p:Configuration=Release /p:Platform=x86
rem Using to add in marketmaker_release.7z
set host=%COMPUTERNAME%
IF "%host%"=="VM-81" (
mkdir package_content\win32
mkdir package_content\win64
copy /y Release\marketmaker.exe package_content\win32
copy /y x64\Release\marketmaker.exe package_content\win64
cd package_content
"C:\Program Files\7-Zip\7z.exe" a C:\komodo\marketmaker_release\marketmaker_release.7z win32\marketmaker.exe
"C:\Program Files\7-Zip\7z.exe" a C:\komodo\marketmaker_release\marketmaker_release.7z win64\marketmaker.exe
cd ..
rd package_content /s /q
)
Loading…
Cancel
Save