From 1ab5a4eb3c64ee28d69d5274001de2b6fd1c1569 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 1 Jun 2017 10:51:25 +0300 Subject: [PATCH] Test --- iguana/exchanges/LP_commands.c | 17 +++++++++++++++-- iguana/exchanges/LP_include.h | 1 + iguana/exchanges/LP_nativeDEX.c | 5 +++-- iguana/exchanges/LP_swap.c | 24 +++++++++++------------- 4 files changed, 30 insertions(+), 17 deletions(-) diff --git a/iguana/exchanges/LP_commands.c b/iguana/exchanges/LP_commands.c index af337b933..dc0b68a5c 100644 --- a/iguana/exchanges/LP_commands.c +++ b/iguana/exchanges/LP_commands.c @@ -486,8 +486,21 @@ char *stats_JSON(cJSON *argjson,char *remoteaddr,uint16_t port) // from rpc port retstr = LP_quote(argjson); else if ( IAMCLIENT != 0 && strcmp(method,"connected") == 0 ) { - retstr = jprint(argjson,0); - printf("got connected! (%s)\n",retstr); + int32_t pairsock = -1; char *pairstr; + if ( (pairstr= jstr(argjson,"pair")) == 0 || (pairsock= nn_socket(AF_SP,NN_PAIR)) < 0 ) + printf("error creating pairsock\n"); + else if ( nn_connect(pairsock,pairstr) >= 0 ) + { + struct LP_quoteinfo *qp; int32_t DEXselector = 0; + qp = calloc(1,sizeof(*qp)); + LP_quoteparse(qp,argjson); + qp->pair = pairsock; + qp->privkey = LP_privkey(qp->destaddr); + LP_requestinit(&qp->R,qp->srchash,qp->desthash,qp->srccoin,qp->satoshis,qp->destcoin,qp->destsatoshis,qp->timestamp,qp->quotetime,DEXselector); + if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_aliceloop,(void *)qp) == 0 ) + { + } + } } else if ( IAMCLIENT == 0 && strcmp(method,"getprice") == 0 ) retstr = LP_pricestr(jstr(argjson,"base"),jstr(argjson,"rel")); diff --git a/iguana/exchanges/LP_include.h b/iguana/exchanges/LP_include.h index a7e239f2b..35c38051a 100644 --- a/iguana/exchanges/LP_include.h +++ b/iguana/exchanges/LP_include.h @@ -470,6 +470,7 @@ enum opcodetype void basilisk_dontforget_update(struct basilisk_swap *swap,struct basilisk_rawtx *rawtx); uint32_t basilisk_requestid(struct basilisk_request *rp); uint32_t basilisk_quoteid(struct basilisk_request *rp); +struct basilisk_swap *LP_swapinit(int32_t iambob,int32_t optionduration,bits256 privkey,struct basilisk_request *rp); char *bitcoind_passthru(char *coinstr,char *serverport,char *userpass,char *method,char *params); struct iguana_info *LP_coinfind(char *symbol); void *curl_post(void **cHandlep,char *url,char *userpass,char *postfields,char *hdr0,char *hdr1,char *hdr2,char *hdr3); diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index c31d69ece..29c81b18e 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -60,9 +60,10 @@ struct LP_utxoinfo struct LP_quoteinfo { - bits256 srchash,desthash,txid,txid2,desttxid; + struct basilisk_request R; + bits256 srchash,desthash,txid,txid2,desttxid,privkey; uint64_t satoshis,satoshis2,txfee,destsatoshis,desttxfee,change; - uint32_t timestamp,quotetime; int32_t vout,vout2,destvout; + uint32_t timestamp,quotetime; int32_t vout,vout2,destvout,pair; char srccoin[16],coinaddr[64],destcoin[16],destaddr[64]; }; diff --git a/iguana/exchanges/LP_swap.c b/iguana/exchanges/LP_swap.c index 86f1d0a0c..d70b78954 100644 --- a/iguana/exchanges/LP_swap.c +++ b/iguana/exchanges/LP_swap.c @@ -527,22 +527,21 @@ void LP_bobloop(void *_utxo) utxo->pair = -1; } -void LP_aliceloop(void *_utxo) +void LP_aliceloop(void *_qp) { - uint8_t *data; int32_t maxlen; uint32_t expiration; struct basilisk_swap *swap; struct LP_utxoinfo *utxo = _utxo; - fprintf(stderr,"start swap iambob\n"); + uint8_t *data; int32_t maxlen; uint32_t expiration; struct basilisk_swap *swap = 0; struct LP_quoteinfo *qp = _qp; + fprintf(stderr,"start swap iamalice\n"); maxlen = 1024*1024 + sizeof(*swap); data = malloc(maxlen); expiration = (uint32_t)time(NULL) + 10; - while ( (swap= utxo->swap) == 0 && time(NULL) < expiration ) - sleep(1); - if ( (utxo->swap= swap) != 0 ) + swap = LP_swapinit(1,0,qp->privkey,&qp->R); + if ( swap != 0 ) { - if ( LP_sendwait("pubkeys",10,utxo->pair,swap,data,maxlen,LP_pubkeys_verify,LP_pubkeys_data) < 0 ) + if ( LP_sendwait("pubkeys",10,qp->pair,swap,data,maxlen,LP_pubkeys_verify,LP_pubkeys_data) < 0 ) printf("error LP_sendwait pubkeys\n"); - else if ( LP_sendwait("choosei",10,utxo->pair,swap,data,maxlen,LP_choosei_verify,LP_choosei_data) < 0 ) + else if ( LP_sendwait("choosei",10,qp->pair,swap,data,maxlen,LP_choosei_verify,LP_choosei_data) < 0 ) printf("error LP_sendwait choosei\n"); - else if ( LP_sendwait("mostprivs",10,utxo->pair,swap,data,maxlen,LP_mostprivs_verify,LP_mostprivs_data) < 0 ) + else if ( LP_sendwait("mostprivs",10,qp->pair,swap,data,maxlen,LP_mostprivs_verify,LP_mostprivs_data) < 0 ) printf("error LP_sendwait mostprivs\n"); else if ( basilisk_alicetxs(swap,data,maxlen) != 0 ) printf("basilisk_alicetxs error\n"); @@ -558,10 +557,9 @@ void LP_aliceloop(void *_utxo) } } else printf("swap timed out\n"); basilisk_swap_finished(swap); - free(utxo->swap); - utxo->swap = 0; - nn_close(utxo->pair); - utxo->pair = -1; + free(swap); + nn_close(qp->pair); + free(qp); } #ifdef old