From a5eaae009075c465c447e43c8e9ec4f874aa3bb3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 31 May 2017 19:58:12 +0300 Subject: [PATCH] Test --- iguana/exchanges/LP_commands.c | 8 ++++++-- iguana/exchanges/LP_nativeDEX.c | 9 ++++++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/iguana/exchanges/LP_commands.c b/iguana/exchanges/LP_commands.c index c34c69a85..4406189db 100644 --- a/iguana/exchanges/LP_commands.c +++ b/iguana/exchanges/LP_commands.c @@ -241,9 +241,9 @@ char *LP_quote(uint32_t reserved,char *base,char *rel,bits256 txid,int32_t vout, else return(clonestr("{\"error\":\"nullptr\"}")); } -void LP_command(struct LP_peerinfo *mypeer,int32_t pubsock,cJSON *argjson,uint8_t *data,int32_t datalen,double profitmargin) +int32_t LP_command(struct LP_peerinfo *mypeer,int32_t pubsock,cJSON *argjson,uint8_t *data,int32_t datalen,double profitmargin) { - char *method,*base,*rel,*retstr,pairstr[512]; cJSON *retjson; double price; bits256 srchash,desthash,pubkey,privkey,txid,desttxid; struct LP_utxoinfo *utxo; uint32_t timestamp,quotetime; int32_t destvout,DEXselector = 0; uint64_t txfee,satoshis,desttxfee,destsatoshis,value; struct basilisk_request R; + char *method,*base,*rel,*retstr,pairstr[512]; cJSON *retjson; double price; bits256 srchash,desthash,pubkey,privkey,txid,desttxid; struct LP_utxoinfo *utxo; uint32_t timestamp,quotetime; int32_t destvout,retval = -1,DEXselector = 0; uint64_t txfee,satoshis,desttxfee,destsatoshis,value; struct basilisk_request R; //LP_command.({"txid":"f5d5e2eb4ef85c78f95076d0d2d99af9e1b85968e57b3c7bdb282bd005f7c341","vout":1,"base":"KMD","rel":"BTC","method":"price"}) if ( (method= jstr(argjson,"method")) != 0 ) { @@ -255,6 +255,7 @@ void LP_command(struct LP_peerinfo *mypeer,int32_t pubsock,cJSON *argjson,uint8_ utxo->swappending = 0; if ( strcmp(method,"price") == 0 || strcmp(method,"request") == 0 ) { + retval = 1; if ( utxo->swappending == 0 && utxo->pair < 0 ) { if ( utxo->pair >= 0 ) @@ -283,6 +284,7 @@ void LP_command(struct LP_peerinfo *mypeer,int32_t pubsock,cJSON *argjson,uint8_ jadd64bits(retjson,"destsatoshis",price * (utxo->satoshis-txfee) + desttxfee); if ( strcmp(method,"request") == 0 ) { + retval |= 2; utxo->swappending = (uint32_t)(time(NULL) + LP_RESERVETIME); utxo->otherpubkey = jbits256(argjson,"mypub"); jaddbits256(retjson,"otherpubkey",utxo->otherpubkey); @@ -296,6 +298,7 @@ void LP_command(struct LP_peerinfo *mypeer,int32_t pubsock,cJSON *argjson,uint8_ } else if ( strcmp(method,"connect") == 0 ) { + retval = 4; if ( utxo->pair < 0 ) { if ( (price= LP_price(base,rel)) != 0. ) @@ -369,6 +372,7 @@ void LP_command(struct LP_peerinfo *mypeer,int32_t pubsock,cJSON *argjson,uint8_ } } } + return(retval); } char *stats_JSON(cJSON *argjson,char *remoteaddr,uint16_t port) // from rpc port diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index d06aaad8b..a444540fa 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -973,7 +973,14 @@ void LP_mainloop(struct LP_peerinfo *mypeer,uint16_t mypubport,int32_t pubsock,i { len = (int32_t)strlen((char *)ptr) + 1; portable_mutex_lock(&LP_commandmutex); - LP_command(mypeer,pubsock,argjson,&((uint8_t *)ptr)[len],recvsize - len,profitmargin); + if ( LP_command(mypeer,pubsock,argjson,&((uint8_t *)ptr)[len],recvsize - len,profitmargin) == 0 ) + { + if ( (retstr= stats_JSON(argjson,"127.0.0.1",mypubport)) != 0 ) + { + printf("%s RECV.[%d] %s\n",peer->ipaddr,recvsize,(char *)ptr); + free(retstr); + } + } portable_mutex_unlock(&LP_commandmutex); free_json(argjson); }