Browse Source

Test

etomic
jl777 8 years ago
parent
commit
1ab5a4eb3c
  1. 17
      iguana/exchanges/LP_commands.c
  2. 1
      iguana/exchanges/LP_include.h
  3. 5
      iguana/exchanges/LP_nativeDEX.c
  4. 24
      iguana/exchanges/LP_swap.c

17
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); retstr = LP_quote(argjson);
else if ( IAMCLIENT != 0 && strcmp(method,"connected") == 0 ) else if ( IAMCLIENT != 0 && strcmp(method,"connected") == 0 )
{ {
retstr = jprint(argjson,0); int32_t pairsock = -1; char *pairstr;
printf("got connected! (%s)\n",retstr); 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 ) else if ( IAMCLIENT == 0 && strcmp(method,"getprice") == 0 )
retstr = LP_pricestr(jstr(argjson,"base"),jstr(argjson,"rel")); retstr = LP_pricestr(jstr(argjson,"base"),jstr(argjson,"rel"));

1
iguana/exchanges/LP_include.h

@ -470,6 +470,7 @@ enum opcodetype
void basilisk_dontforget_update(struct basilisk_swap *swap,struct basilisk_rawtx *rawtx); void basilisk_dontforget_update(struct basilisk_swap *swap,struct basilisk_rawtx *rawtx);
uint32_t basilisk_requestid(struct basilisk_request *rp); uint32_t basilisk_requestid(struct basilisk_request *rp);
uint32_t basilisk_quoteid(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); char *bitcoind_passthru(char *coinstr,char *serverport,char *userpass,char *method,char *params);
struct iguana_info *LP_coinfind(char *symbol); 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); void *curl_post(void **cHandlep,char *url,char *userpass,char *postfields,char *hdr0,char *hdr1,char *hdr2,char *hdr3);

5
iguana/exchanges/LP_nativeDEX.c

@ -60,9 +60,10 @@ struct LP_utxoinfo
struct LP_quoteinfo 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; 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]; char srccoin[16],coinaddr[64],destcoin[16],destaddr[64];
}; };

24
iguana/exchanges/LP_swap.c

@ -527,22 +527,21 @@ void LP_bobloop(void *_utxo)
utxo->pair = -1; 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; uint8_t *data; int32_t maxlen; uint32_t expiration; struct basilisk_swap *swap = 0; struct LP_quoteinfo *qp = _qp;
fprintf(stderr,"start swap iambob\n"); fprintf(stderr,"start swap iamalice\n");
maxlen = 1024*1024 + sizeof(*swap); maxlen = 1024*1024 + sizeof(*swap);
data = malloc(maxlen); data = malloc(maxlen);
expiration = (uint32_t)time(NULL) + 10; expiration = (uint32_t)time(NULL) + 10;
while ( (swap= utxo->swap) == 0 && time(NULL) < expiration ) swap = LP_swapinit(1,0,qp->privkey,&qp->R);
sleep(1); if ( swap != 0 )
if ( (utxo->swap= 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"); 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"); 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"); printf("error LP_sendwait mostprivs\n");
else if ( basilisk_alicetxs(swap,data,maxlen) != 0 ) else if ( basilisk_alicetxs(swap,data,maxlen) != 0 )
printf("basilisk_alicetxs error\n"); printf("basilisk_alicetxs error\n");
@ -558,10 +557,9 @@ void LP_aliceloop(void *_utxo)
} }
} else printf("swap timed out\n"); } else printf("swap timed out\n");
basilisk_swap_finished(swap); basilisk_swap_finished(swap);
free(utxo->swap); free(swap);
utxo->swap = 0; nn_close(qp->pair);
nn_close(utxo->pair); free(qp);
utxo->pair = -1;
} }
#ifdef old #ifdef old

Loading…
Cancel
Save