From 643254cdfa886f092175b78cb4e4501f9e6cdce6 Mon Sep 17 00:00:00 2001
From: jl777 <jameslee777@yahoo.com>
Date: Wed, 6 Dec 2017 00:11:40 +0400
Subject: [PATCH] Test

---
 iguana/exchanges/LP_commands.c     |  8 +++--
 iguana/exchanges/LP_statemachine.c | 57 ++++++++++++++++++++++++++++++
 iguana/exchanges/mm.c              | 56 -----------------------------
 3 files changed, 63 insertions(+), 58 deletions(-)

diff --git a/iguana/exchanges/LP_commands.c b/iguana/exchanges/LP_commands.c
index 0f1502df0..c7a0bb4ca 100644
--- a/iguana/exchanges/LP_commands.c
+++ b/iguana/exchanges/LP_commands.c
@@ -631,13 +631,17 @@ instantdex_claim()\n\
         return(jprint(LP_fundvalue(argjson),1));
     else if ( strcmp(method,"getprice") == 0 )
     {
-        double price;
-        price = LP_price(base,rel);
+        double price,bid,ask;
+        ask = LP_price(base,rel);
+        bid = LP_price(rel,base);
+        price = _pairaved(bid,ask);
         retjson = cJSON_CreateObject();
         jaddstr(retjson,"result","success");
         jaddstr(retjson,"base",base);
         jaddstr(retjson,"rel",rel);
         jaddnum(retjson,"timestamp",time(NULL));
+        jaddnum(retjson,"bid",bid);
+        jaddnum(retjson,"ask",ask);
         jaddnum(retjson,"price",price);
         return(jprint(retjson,1));
     }
diff --git a/iguana/exchanges/LP_statemachine.c b/iguana/exchanges/LP_statemachine.c
index d970974e8..733530943 100644
--- a/iguana/exchanges/LP_statemachine.c
+++ b/iguana/exchanges/LP_statemachine.c
@@ -2094,6 +2094,63 @@ char *LP_postutxos_recv(cJSON *argjson)
     }
     return(clonestr("{\"error\":\"sig failure\"}"));
 }
+
+/*MERK d6071f9b03d1428b648d51ae1268f1605d97f44422ed55ad0335b13fa655f61a ht.518777 -> {"pos":1,"merkle":["526f8be81718beccc16a541a2c550b612123218d80fa884d9f080f18284e2bd8", "f68b03a7b6e418c9b306d8d8b21917ae5a584696f9b0b8cb0741733d7097fdfd"],"block_height":518777} root.(0000000000000000000000000000000000000000000000000000000000000000)
+ MERK c007e9c1881a83be453cb6ed3d1bd3bda85efd3b5ce60532c2e20ae3f8a82543 ht.518777 -> {"pos":2,"merkle":["fdff0962fb95120a86a07ddf1ec784fcc5554a2d0a3791a8db2083d593920501", "8c116e974c842ad3ad8b3ddbd71da3debb150e3fe692f5bd628381bc167311a7"],"block_height":518777} root.(0000000000000000000000000000000000000000000000000000000000000000)*/
+/*526f8be81718beccc16a541a2c550b612123218d80fa884d9f080f18284e2bd8
+ d6071f9b03d1428b648d51ae1268f1605d97f44422ed55ad0335b13fa655f61a
+ c007e9c1881a83be453cb6ed3d1bd3bda85efd3b5ce60532c2e20ae3f8a82543
+ fdff0962fb95120a86a07ddf1ec784fcc5554a2d0a3791a8db2083d593920501*/
+
+/*0: 526f8be81718beccc16a541a2c550b612123218d80fa884d9f080f18284e2bd8
+ 1: d6071f9b03d1428b648d51ae1268f1605d97f44422ed55ad0335b13fa655f61a
+ 2: c007e9c1881a83be453cb6ed3d1bd3bda85efd3b5ce60532c2e20ae3f8a82543
+ 3: fdff0962fb95120a86a07ddf1ec784fcc5554a2d0a3791a8db2083d593920501
+ 4: 8c116e974c842ad3ad8b3ddbd71da3debb150e3fe692f5bd628381bc167311a7
+ 5: f68b03a7b6e418c9b306d8d8b21917ae5a584696f9b0b8cb0741733d7097fdfd
+ 6: a87ee259560f20b20182760c0e7cc7896d44381f0ad58a2e755a2b6b895b01ec*/
+
+/*
+ 0 1 2 3
+ 4   5
+ 6
+ 
+ 1 -> [0, 5]
+ 2 -> [3, 4]
+ 
+ if odd -> right, else left
+ then /= 2
+ */
+
+/*void testmerk()
+ {
+ bits256 tree[256],roothash,txid; int32_t i; char str[65];
+ memset(tree,0,sizeof(tree));
+ decode_hex(tree[0].bytes,32,"526f8be81718beccc16a541a2c550b612123218d80fa884d9f080f18284e2bd8");
+ decode_hex(tree[1].bytes,32,"d6071f9b03d1428b648d51ae1268f1605d97f44422ed55ad0335b13fa655f61a");
+ decode_hex(tree[2].bytes,32,"c007e9c1881a83be453cb6ed3d1bd3bda85efd3b5ce60532c2e20ae3f8a82543");
+ decode_hex(tree[3].bytes,32,"fdff0962fb95120a86a07ddf1ec784fcc5554a2d0a3791a8db2083d593920501");
+ roothash = iguana_merkle(tree,4);
+ for (i=0; i<256; i++)
+ {
+ if ( bits256_nonz(tree[i]) == 0 )
+ break;
+ printf("%d: %s\n",i,bits256_str(str,tree[i]));
+ }
+ memset(tree,0,sizeof(tree));
+ decode_hex(tree[0].bytes,32,"526f8be81718beccc16a541a2c550b612123218d80fa884d9f080f18284e2bd8");
+ decode_hex(tree[1].bytes,32,"f68b03a7b6e418c9b306d8d8b21917ae5a584696f9b0b8cb0741733d7097fdfd");
+ decode_hex(txid.bytes,32,"d6071f9b03d1428b648d51ae1268f1605d97f44422ed55ad0335b13fa655f61a");
+ roothash = validate_merkle(1,txid,tree,2);
+ printf("validate 1: %s\n",bits256_str(str,roothash));
+ memset(tree,0,sizeof(tree));
+ decode_hex(tree[0].bytes,32,"fdff0962fb95120a86a07ddf1ec784fcc5554a2d0a3791a8db2083d593920501");
+ decode_hex(tree[1].bytes,32,"8c116e974c842ad3ad8b3ddbd71da3debb150e3fe692f5bd628381bc167311a7");
+ decode_hex(txid.bytes,32,"c007e9c1881a83be453cb6ed3d1bd3bda85efd3b5ce60532c2e20ae3f8a82543");
+ roothash = validate_merkle(2,txid,tree,2);
+ printf("validate 2: %s\n",bits256_str(str,roothash));
+ }*/
+
 /*else if ( (retstr= LP_orderbook(coin->symbol,"KMD",-1)) != 0 )
  {
  if ( (orderbook= cJSON_Parse(retstr)) != 0 )
diff --git a/iguana/exchanges/mm.c b/iguana/exchanges/mm.c
index b67f345b9..5382b33c3 100644
--- a/iguana/exchanges/mm.c
+++ b/iguana/exchanges/mm.c
@@ -806,62 +806,6 @@ void marketmaker(double minask,double maxbid,char *baseaddr,char *reladdr,double
 
 #include "LP_nativeDEX.c"
 
-/*MERK d6071f9b03d1428b648d51ae1268f1605d97f44422ed55ad0335b13fa655f61a ht.518777 -> {"pos":1,"merkle":["526f8be81718beccc16a541a2c550b612123218d80fa884d9f080f18284e2bd8", "f68b03a7b6e418c9b306d8d8b21917ae5a584696f9b0b8cb0741733d7097fdfd"],"block_height":518777} root.(0000000000000000000000000000000000000000000000000000000000000000)
- MERK c007e9c1881a83be453cb6ed3d1bd3bda85efd3b5ce60532c2e20ae3f8a82543 ht.518777 -> {"pos":2,"merkle":["fdff0962fb95120a86a07ddf1ec784fcc5554a2d0a3791a8db2083d593920501", "8c116e974c842ad3ad8b3ddbd71da3debb150e3fe692f5bd628381bc167311a7"],"block_height":518777} root.(0000000000000000000000000000000000000000000000000000000000000000)*/
-/*526f8be81718beccc16a541a2c550b612123218d80fa884d9f080f18284e2bd8
-d6071f9b03d1428b648d51ae1268f1605d97f44422ed55ad0335b13fa655f61a
-c007e9c1881a83be453cb6ed3d1bd3bda85efd3b5ce60532c2e20ae3f8a82543
-fdff0962fb95120a86a07ddf1ec784fcc5554a2d0a3791a8db2083d593920501*/
-
-/*0: 526f8be81718beccc16a541a2c550b612123218d80fa884d9f080f18284e2bd8
-1: d6071f9b03d1428b648d51ae1268f1605d97f44422ed55ad0335b13fa655f61a
-2: c007e9c1881a83be453cb6ed3d1bd3bda85efd3b5ce60532c2e20ae3f8a82543
-3: fdff0962fb95120a86a07ddf1ec784fcc5554a2d0a3791a8db2083d593920501
-4: 8c116e974c842ad3ad8b3ddbd71da3debb150e3fe692f5bd628381bc167311a7
-5: f68b03a7b6e418c9b306d8d8b21917ae5a584696f9b0b8cb0741733d7097fdfd
-6: a87ee259560f20b20182760c0e7cc7896d44381f0ad58a2e755a2b6b895b01ec*/
-
-/*
-0 1 2 3
- 4   5
-   6
-
-1 -> [0, 5]
-2 -> [3, 4]
-
-if odd -> right, else left
-then /= 2
-*/
-
-/*void testmerk()
-{
-    bits256 tree[256],roothash,txid; int32_t i; char str[65];
-    memset(tree,0,sizeof(tree));
-    decode_hex(tree[0].bytes,32,"526f8be81718beccc16a541a2c550b612123218d80fa884d9f080f18284e2bd8");
-    decode_hex(tree[1].bytes,32,"d6071f9b03d1428b648d51ae1268f1605d97f44422ed55ad0335b13fa655f61a");
-    decode_hex(tree[2].bytes,32,"c007e9c1881a83be453cb6ed3d1bd3bda85efd3b5ce60532c2e20ae3f8a82543");
-    decode_hex(tree[3].bytes,32,"fdff0962fb95120a86a07ddf1ec784fcc5554a2d0a3791a8db2083d593920501");
-    roothash = iguana_merkle(tree,4);
-    for (i=0; i<256; i++)
-    {
-        if ( bits256_nonz(tree[i]) == 0 )
-            break;
-        printf("%d: %s\n",i,bits256_str(str,tree[i]));
-    }
-    memset(tree,0,sizeof(tree));
-    decode_hex(tree[0].bytes,32,"526f8be81718beccc16a541a2c550b612123218d80fa884d9f080f18284e2bd8");
-    decode_hex(tree[1].bytes,32,"f68b03a7b6e418c9b306d8d8b21917ae5a584696f9b0b8cb0741733d7097fdfd");
-    decode_hex(txid.bytes,32,"d6071f9b03d1428b648d51ae1268f1605d97f44422ed55ad0335b13fa655f61a");
-    roothash = validate_merkle(1,txid,tree,2);
-    printf("validate 1: %s\n",bits256_str(str,roothash));
-    memset(tree,0,sizeof(tree));
-    decode_hex(tree[0].bytes,32,"fdff0962fb95120a86a07ddf1ec784fcc5554a2d0a3791a8db2083d593920501");
-    decode_hex(tree[1].bytes,32,"8c116e974c842ad3ad8b3ddbd71da3debb150e3fe692f5bd628381bc167311a7");
-    decode_hex(txid.bytes,32,"c007e9c1881a83be453cb6ed3d1bd3bda85efd3b5ce60532c2e20ae3f8a82543");
-    roothash = validate_merkle(2,txid,tree,2);
-    printf("validate 2: %s\n",bits256_str(str,roothash));
-}*/
-
 void LP_main(void *ptr)
 {
     char *passphrase; double profitmargin; uint16_t port; cJSON *argjson = ptr;