From ea3226e721ad772e2d0287e0f0ea6c210dd07db8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 5 Mar 2017 15:09:54 +0200 Subject: [PATCH] Test --- basilisk/basilisk_DEX.c | 20 +++- basilisk/basilisk_swap.c | 195 +++++++++++++++++++++++++++-------- basilisk/basilisk_tradebot.c | 8 ++ iguana/dpow/dpow_network.c | 13 +-- iguana/iguana777.h | 7 +- iguana/tests/dexkvupdate | 4 +- iguana/tests/dexpsock | 2 + 7 files changed, 192 insertions(+), 57 deletions(-) create mode 100755 iguana/tests/dexpsock diff --git a/basilisk/basilisk_DEX.c b/basilisk/basilisk_DEX.c index 688ebc169..7cadc124c 100755 --- a/basilisk/basilisk_DEX.c +++ b/basilisk/basilisk_DEX.c @@ -276,7 +276,7 @@ void basilisk_requests_poll(struct supernet_info *myinfo,bits256 privkey) { static uint32_t lastpoll; char *retstr; uint8_t data[32768]; cJSON *outerarray,*retjson; uint32_t msgid,channel; int32_t datalen,i,n; struct basilisk_request issueR; double hwm = 0.; - if ( myinfo->IAMNOTARY != 0 || time(NULL) < lastpoll+20 || (myinfo->IAMLP == 0 && myinfo->DEXactive == 0) ) + if ( myinfo->IAMNOTARY != 0 || time(NULL) < lastpoll+20 || (myinfo->IAMLP == 0 && myinfo->DEXactive < time(NULL)) ) return; lastpoll = (uint32_t)time(NULL); memset(&issueR,0,sizeof(issueR)); @@ -317,7 +317,23 @@ void basilisk_requests_poll(struct supernet_info *myinfo,bits256 privkey) dex_updateclient(myinfo); if ( (retstr= basilisk_start(myinfo,myinfo->persistent_priv,&issueR,1,issueR.optionhours * 3600)) != 0 ) free(retstr); - /*if ( (retstr= InstantDEX_accept(myinfo,0,0,0,issueR.requestid,issueR.quoteid)) != 0 ) + } + else if ( bits256_cmp(myinfo->jumblr_pubkey,issueR.srchash) == 0 ) + { + dex_channelsend(myinfo,issueR.srchash,issueR.desthash,channel,0x4000000,(void *)&issueR.requestid,sizeof(issueR.requestid)); // 60 + dpow_nanomsg_update(myinfo); + dex_updateclient(myinfo); + if ( (retstr= basilisk_start(myinfo,myinfo->jumblr_pubkey,&issueR,1,issueR.optionhours * 3600)) != 0 ) + free(retstr); + } + else if ( bits256_cmp(myinfo->jumblr_depositkey,issueR.srchash) == 0 ) + { + dex_channelsend(myinfo,issueR.srchash,issueR.desthash,channel,0x4000000,(void *)&issueR.requestid,sizeof(issueR.requestid)); // 60 + dpow_nanomsg_update(myinfo); + dex_updateclient(myinfo); + if ( (retstr= basilisk_start(myinfo,myinfo->jumblr_depositkey,&issueR,1,issueR.optionhours * 3600)) != 0 ) + free(retstr); + /*if ( (retstr= InstantDEX_accept(myinfo,0,0,0,issueR.requestid,issueR.quoteid)) != 0 ) free(retstr); printf("my req hwm %f -> %u\n",hwm,issueR.requestid); basilisk_channelsend(myinfo,issueR.srchash,issueR.desthash,channel,0x4000000,(void *)&issueR.requestid,sizeof(issueR.requestid),60); diff --git a/basilisk/basilisk_swap.c b/basilisk/basilisk_swap.c index d77843148..7f935e2d7 100755 --- a/basilisk/basilisk_swap.c +++ b/basilisk/basilisk_swap.c @@ -245,7 +245,7 @@ int32_t basilisk_confirmsobj(cJSON *item) return(-1); } -int32_t basilisk_numconfirms(struct supernet_info *myinfo,struct basilisk_rawtx *rawtx) +int32_t basilisk_numconfirms(struct supernet_info *myinfo,struct basilisk_swap *swap,struct basilisk_rawtx *rawtx) { cJSON *argjson,*valuearray=0; char *valstr; int32_t i,n,retval = -1; #ifdef BASILISK_DISABLEWAITTX @@ -255,7 +255,7 @@ int32_t basilisk_numconfirms(struct supernet_info *myinfo,struct basilisk_rawtx jaddbits256(argjson,"txid",rawtx->I.actualtxid); jaddnum(argjson,"vout",0); jaddstr(argjson,"coin",rawtx->coin->symbol); - if ( (valstr= basilisk_value(myinfo,rawtx->coin,0,0,myinfo->myaddr.persistent,argjson,0)) != 0 ) + if ( (valstr= basilisk_value(myinfo,rawtx->coin,0,0,swap->persistent_pubkey,argjson,0)) != 0 ) { //char str[65]; printf("%s %s valstr.(%s)\n",rawtx->name,bits256_str(str,rawtx->I.actualtxid),valstr); if ( (valuearray= cJSON_Parse(valstr)) != 0 ) @@ -704,7 +704,7 @@ int32_t basilisk_rawtx_gen(char *str,struct supernet_info *myinfo,struct basilis //bitcoin_address(coinaddr,rawtx->coin->chain->pubtype,myinfo->persistent_pubkey33,33); if ( rawtx->coin->changeaddr[0] == 0 ) { - bitcoin_address(rawtx->coin->changeaddr,rawtx->coin->chain->pubtype,myinfo->persistent_pubkey33,33); + bitcoin_address(rawtx->coin->changeaddr,rawtx->coin->chain->pubtype,swap->persistent_pubkey33,33); printf("set change address.(%s)\n",rawtx->coin->changeaddr); } init_hexbytes_noT(scriptstr,script,scriptlen); @@ -720,7 +720,7 @@ int32_t basilisk_rawtx_gen(char *str,struct supernet_info *myinfo,struct basilis jaddnum(valsobj,"timeout",30000); jaddnum(valsobj,"timestamp",swap->I.started+delay); addresses = cJSON_CreateArray(); - bitcoin_address(coinaddr,rawtx->coin->chain->pubtype,myinfo->persistent_pubkey33,33); + bitcoin_address(coinaddr,rawtx->coin->chain->pubtype,swap->persistent_pubkey33,33); jaddistr(addresses,coinaddr); jadd(valsobj,"addresses",addresses); rawtx->I.locktime = locktime; @@ -1123,15 +1123,21 @@ int32_t bitcoin_coinptrs(bits256 pubkey,struct iguana_info **bobcoinp,struct igu return(0); } -struct basilisk_swap *bitcoin_swapinit(void *ctx,bits256 privkey,uint8_t *pubkey33,bits256 pubkey25519,struct basilisk_swap *swap,int32_t optionduration) +struct basilisk_swap *bitcoin_swapinit(void *ctx,bits256 privkey,uint8_t *pubkey33,bits256 pubkey25519,struct basilisk_swap *swap,int32_t optionduration,uint32_t statebits) { - struct iguana_info *coin,*bobcoin,*alicecoin; uint8_t *alicepub33=0,*bobpub33=0; int32_t x = -1; + struct iguana_info *bobcoin,*alicecoin; uint8_t *alicepub33=0,*bobpub33=0; int32_t x = -1; swap->I.putduration = swap->I.callduration = INSTANTDEX_LOCKTIME; if ( optionduration < 0 ) swap->I.putduration -= optionduration; else if ( optionduration > 0 ) swap->I.callduration += optionduration; - if ( strcmp("BTC",swap->I.req.src) == 0 ) + swap->bobcoin = iguana_coinfind(swap->I.req.dest); + swap->I.bobsatoshis = swap->I.req.destamount; + swap->I.bobconfirms = (1*0 + sqrt(dstr(swap->I.bobsatoshis) * .1)); + swap->alicecoin = iguana_coinfind(swap->I.req.src); + swap->I.alicesatoshis = swap->I.req.srcamount; + swap->I.aliceconfirms = swap->I.bobconfirms * 3; + /*if ( strcmp("BTC",swap->I.req.src) == 0 ) { swap->bobcoin = iguana_coinfind("BTC"); swap->I.bobsatoshis = swap->I.req.srcamount; @@ -1171,7 +1177,7 @@ struct basilisk_swap *bitcoin_swapinit(void *ctx,bits256 privkey,uint8_t *pubkey } else printf("neither coin handles ctlv %s %s\n",swap->I.req.src,swap->I.req.dest); } else printf("cant find src or dest coin.(%s %s)\n",swap->I.req.src,swap->I.req.dest); } else printf("cant find src coin.(%s)\n",swap->I.req.src); - } + }*/ if ( swap->bobcoin == 0 || swap->alicecoin == 0 ) { printf("missing bobcoin.%p or missing alicecoin.%p src.%p dest.%p\n",swap->bobcoin,swap->alicecoin,iguana_coinfind(swap->I.req.src),iguana_coinfind(swap->I.req.dest)); @@ -1196,7 +1202,17 @@ struct basilisk_swap *bitcoin_swapinit(void *ctx,bits256 privkey,uint8_t *pubkey swap->I.choosei %= INSTANTDEX_DECKSIZE; swap->I.otherchoosei = -1; swap->I.myhash = pubkey25519; - if ( bits256_cmp(swap->I.myhash,swap->I.req.srchash) == 0 ) + if ( statebits != 0 ) + { + swap->I.iambob = 0; + swap->I.otherhash = swap->I.req.desthash; + } + else + { + swap->I.iambob = 1; + swap->I.otherhash = swap->I.req.srchash; + } + /*if ( bits256_cmp(swap->I.myhash,swap->I.req.srchash) == 0 ) { swap->I.otherhash = swap->I.req.desthash; if ( strcmp(swap->I.req.src,swap->I.bobstr) == 0 ) @@ -1212,7 +1228,7 @@ struct basilisk_swap *bitcoin_swapinit(void *ctx,bits256 privkey,uint8_t *pubkey { printf("neither src nor dest error\n"); return(0); - } + }*/ if ( (bitcoin_coinptrs(pubkey25519,&bobcoin,&alicecoin,swap->I.req.src,swap->I.req.dest,swap->I.req.srchash,swap->I.req.desthash)+1)/2 != swap->I.iambob ) { printf("error iambob.%d != %d\n",swap->I.iambob,bitcoin_coinptrs(pubkey25519,&bobcoin,&alicecoin,swap->I.req.src,swap->I.req.dest,swap->I.req.srchash,swap->I.req.desthash)); @@ -1607,7 +1623,7 @@ int32_t basilisk_swapiteration(struct supernet_info *myinfo,struct basilisk_swap } else if ( (swap->I.statebits & 0x2000) == 0 ) { - if ( basilisk_numconfirms(myinfo,&swap->alicepayment) >= swap->I.aliceconfirms ) + if ( basilisk_numconfirms(myinfo,swap,&swap->alicepayment) >= swap->I.aliceconfirms ) { swap->I.statebits |= 0x2000; printf("alicepayment confirmed\n"); @@ -1633,7 +1649,7 @@ int32_t basilisk_swapiteration(struct supernet_info *myinfo,struct basilisk_swap tradebot_swap_balancingtrade(myinfo,swap,1); printf("Bob spends alicepayment\n"); swap->I.statebits |= 0x40000; - while ( basilisk_numconfirms(myinfo,&swap->bobspend) < swap->I.aliceconfirms ) + while ( basilisk_numconfirms(myinfo,swap,&swap->bobspend) < swap->I.aliceconfirms ) { printf("bobspend confirmed\n"); swap->I.statebits |= 0x80000; @@ -1656,7 +1672,7 @@ int32_t basilisk_swapiteration(struct supernet_info *myinfo,struct basilisk_swap printf("Bob reclaimed own payment\n"); while ( 0 && (swap->I.statebits & 0x100000) == 0 ) // why wait for own tx? { - if ( basilisk_numconfirms(myinfo,&swap->bobreclaim) >= 1 ) + if ( basilisk_numconfirms(myinfo,swap,&swap->bobreclaim) >= 1 ) { printf("bobreclaim confirmed\n"); swap->I.statebits |= 0x100000; @@ -1684,7 +1700,7 @@ int32_t basilisk_swapiteration(struct supernet_info *myinfo,struct basilisk_swap } else if ( (swap->I.statebits & 0x400) == 0 ) { - if ( basilisk_numconfirms(myinfo,&swap->bobdeposit) >= swap->I.bobconfirms ) + if ( basilisk_numconfirms(myinfo,swap,&swap->bobdeposit) >= swap->I.bobconfirms ) { printf("bobdeposit confirmed\n"); swap->I.statebits |= 0x400; @@ -1708,7 +1724,7 @@ int32_t basilisk_swapiteration(struct supernet_info *myinfo,struct basilisk_swap } else if ( (swap->I.statebits & 0x10000) == 0 ) { - if ( basilisk_numconfirms(myinfo,&swap->bobpayment) >= swap->I.bobconfirms ) + if ( basilisk_numconfirms(myinfo,swap,&swap->bobpayment) >= swap->I.bobconfirms ) { printf("bobpayment confirmed\n"); swap->I.statebits |= 0x10000; @@ -1717,7 +1733,7 @@ int32_t basilisk_swapiteration(struct supernet_info *myinfo,struct basilisk_swap else if ( (swap->I.statebits & 0x20000) == 0 ) { printf("alicespend bobpayment\n"); - if ( basilisk_swapdata_rawtxsend(myinfo,swap,0,data,maxlen,&swap->alicespend,0x20000) != 0 && basilisk_numconfirms(myinfo,&swap->alicespend) > 0 ) + if ( basilisk_swapdata_rawtxsend(myinfo,swap,0,data,maxlen,&swap->alicespend,0x20000) != 0 && basilisk_numconfirms(myinfo,swap,&swap->alicespend) > 0 ) { for (j=datalen=0; j<32; j++) data[datalen++] = swap->I.privAm.bytes[j]; @@ -1727,7 +1743,7 @@ int32_t basilisk_swapiteration(struct supernet_info *myinfo,struct basilisk_swap } else if ( (swap->I.statebits & 0x40000) == 0 ) { - if ( basilisk_numconfirms(myinfo,&swap->alicespend) >= swap->I.bobconfirms ) + if ( basilisk_numconfirms(myinfo,swap,&swap->alicespend) >= swap->I.bobconfirms ) { swap->I.statebits |= 0x40000; printf("Alice confirms spend of Bob's payment\n"); @@ -1780,6 +1796,68 @@ cJSON *swapjson(struct supernet_info *myinfo,struct basilisk_swap *swap) return(retjson); } +void basilisk_psockinit(struct supernet_info *myinfo,struct basilisk_swap *swap,char *pushaddr,char *subaddr) +{ + char keystr[64],databuf[1024],*retstr,*datastr; cJSON *retjson,*addrjson; uint8_t data[512]; int32_t datalen,timeout,pushsock = -1,subsock = -1; + if ( swap->connected == 1 ) + return; + if ( swap->pushsock < 0 && swap->subsock < 0 && (pushsock= nn_socket(AF_SP,NN_PUSH)) >= 0 && (subsock= nn_socket(AF_SP,NN_SUB)) >= 0 ) + { + timeout = 100; + nn_setsockopt(pushsock,NN_SOL_SOCKET,NN_SNDTIMEO,&timeout,sizeof(timeout)); + timeout = 1; + nn_setsockopt(subsock,NN_SOL_SOCKET,NN_RCVTIMEO,&timeout,sizeof(timeout)); + nn_setsockopt(subsock,NN_SUB,NN_SUB_SUBSCRIBE,"",0); + swap->pushsock = pushsock; + swap->subsock = subsock; + } + sprintf(keystr,"%08x-%08x",swap->I.req.requestid,swap->I.req.quoteid); + if ( pushaddr != 0 && subaddr != 0 ) + { + if ( nn_connect(pushsock,pushaddr) >= 0 && nn_connect(subsock,subaddr) >= 0 ) + swap->connected = 1; + sprintf(databuf,"{\"push\":\"%s\",\"sub\":\"%s\"}",pushaddr,subaddr); + datalen = (int32_t)strlen(databuf) + 1; + decode_hex(data,datalen,databuf); + init_hexbytes_noT(databuf,data,datalen); + printf("%s -> %s\n",keystr,databuf); + if ( (retstr= _dex_kvupdate(myinfo,"KV",keystr,databuf,1)) != 0 ) + { + printf("KVupdate.(%s)\n",retstr); + free(retstr); + } + } + else + { + if ( (retstr= _dex_kvsearch(myinfo,"KV",keystr)) != 0 ) + { + if ( (retjson= cJSON_Parse(retstr)) != 0 ) + { + if ( (datastr= jstr(retjson,"value")) != 0 ) + { + datalen = (int32_t)strlen(datastr) >> 1; + decode_hex((uint8_t *)databuf,datalen,datastr); + if ( (addrjson= cJSON_Parse(databuf)) != 0 ) + { + pushaddr = jstr(addrjson,"push"); + subaddr = jstr(addrjson,"sub"); + if ( pushaddr != 0 && subaddr != 0 ) + { + printf("KV decoded (%s and %s)\n",pushaddr,subaddr); + if ( nn_connect(pushsock,pushaddr) >= 0 && nn_connect(subsock,subaddr) >= 0 ) + swap->connected = 1; + } + free_json(addrjson); + } + } + free_json(retjson); + } + printf("KVsearch.(%s)\n",retstr); + free(retstr); + } + } +} + void basilisk_swaploop(void *_swap) { uint8_t *data; uint32_t expiration; uint32_t channel; int32_t retval=0,i,j,datalen,maxlen; struct supernet_info *myinfo; struct basilisk_swap *swap = _swap; @@ -1792,21 +1870,30 @@ void basilisk_swaploop(void *_swap) channel = 'D' + ((uint32_t)'E' << 8) + ((uint32_t)'X' << 16); while ( (swap->I.statebits & (0x08|0x02)) != (0x08|0x02) && time(NULL) < expiration ) { - printf("A r%u/q%u swapstate.%x\n",swap->I.req.requestid,swap->I.req.quoteid,swap->I.statebits); - //basilisk_channelsend(myinfo,swap->I.req.srchash,swap->I.req.desthash,channel,0x4000000,(void *)&swap->I.req.requestid,sizeof(swap->I.req.requestid),60); dex_channelsend(myinfo,swap->I.req.srchash,swap->I.req.desthash,channel,0x4000000,(void *)&swap->I.req.requestid,sizeof(swap->I.req.requestid)); //,60); - basilisk_sendstate(myinfo,swap,data,maxlen); - basilisk_sendpubkeys(myinfo,swap,data,maxlen); // send pubkeys - if ( basilisk_checkdeck(myinfo,swap,data,maxlen) == 0) // check for other deck 0x02 - basilisk_sendchoosei(myinfo,swap,data,maxlen); - basilisk_waitchoosei(myinfo,swap,data,maxlen); // wait for choosei 0x08 - if ( (swap->I.statebits & (0x08|0x02)) == (0x08|0x02) ) - break; + if ( swap->I.iambob == 0 && swap->connected == 0 ) + basilisk_psockinit(myinfo,swap,0,0); + if ( swap->connected != 0 ) + { + printf("A r%u/q%u swapstate.%x\n",swap->I.req.requestid,swap->I.req.quoteid,swap->I.statebits); + basilisk_sendstate(myinfo,swap,data,maxlen); + basilisk_sendpubkeys(myinfo,swap,data,maxlen); // send pubkeys + if ( basilisk_checkdeck(myinfo,swap,data,maxlen) == 0) // check for other deck 0x02 + basilisk_sendchoosei(myinfo,swap,data,maxlen); + basilisk_waitchoosei(myinfo,swap,data,maxlen); // wait for choosei 0x08 + if ( (swap->I.statebits & (0x08|0x02)) == (0x08|0x02) ) + break; + } sleep(10); - dpow_nanomsg_update(myinfo); - dex_updateclient(myinfo); + //dpow_nanomsg_update(myinfo); + //dex_updateclient(myinfo); + } + if ( swap->connected == 0 ) + { + printf("couldnt establish connection\n"); + retval = -1; } - while ( (swap->I.statebits & 0x20) == 0 && time(NULL) < expiration ) + while ( retval == 0 && (swap->I.statebits & 0x20) == 0 && time(NULL) < expiration ) { printf("B r%u/q%u swapstate.%x\n",swap->I.req.requestid,swap->I.req.quoteid,swap->I.statebits); basilisk_sendstate(myinfo,swap,data,maxlen); @@ -1818,17 +1905,20 @@ void basilisk_swaploop(void *_swap) break; } sleep(13 + (swap->I.iambob == 0)*1); - dpow_nanomsg_update(myinfo); - dex_updateclient(myinfo); + //dpow_nanomsg_update(myinfo); + //dex_updateclient(myinfo); } + myinfo->DEXactive = swap->I.expiration; if ( time(NULL) >= expiration ) + { retval = -1; - myinfo->DEXactive = swap->I.expiration; + myinfo->DEXactive = 0; + } printf("C r%u/q%u swapstate.%x retval.%d\n",swap->I.req.requestid,swap->I.req.quoteid,swap->I.statebits,retval); while ( retval == 0 && (swap->I.statebits & 0x40) == 0 ) // send fee { - dpow_nanomsg_update(myinfo); - dex_updateclient(myinfo); + //dpow_nanomsg_update(myinfo); + //dex_updateclient(myinfo); printf("sendstate.%x\n",swap->I.statebits); basilisk_sendstate(myinfo,swap,data,maxlen); printf("swapget\n"); @@ -1929,8 +2019,8 @@ void basilisk_swaploop(void *_swap) basilisk_swapget(myinfo,swap,0x80000000,data,maxlen,basilisk_verify_otherstatebits); if ( time(NULL) > swap->I.expiration ) break; - dpow_nanomsg_update(myinfo); - dex_updateclient(myinfo); + //dpow_nanomsg_update(myinfo); + //dex_updateclient(myinfo); } printf("end of atomic swap\n"); if ( swap->I.iambob != 0 && swap->bobdeposit.txbytes != 0 ) @@ -1962,7 +2052,8 @@ void basilisk_swaploop(void *_swap) struct basilisk_swap *basilisk_thread_start(struct supernet_info *myinfo,bits256 privkey,struct basilisk_request *rp,uint32_t statebits,int32_t optionduration) { - int32_t i,m,n; uint8_t pubkey33[33]; bits256 pubkey25519; uint32_t channel,starttime; cJSON *retarray,*item,*msgobj; struct basilisk_swap *swap = 0; + int32_t i,m,n; char *retstr; uint8_t pubkey33[33]; bits256 pubkey25519; uint32_t channel,starttime; cJSON *retarray,*item,*msgobj,*retjson; struct basilisk_swap *swap = 0; + // statebits 1 -> client, 0 -> LP portable_mutex_lock(&myinfo->DEX_swapmutex); for (i=0; inumswaps; i++) if ( myinfo->swaps[i]->I.req.requestid == rp->requestid ) @@ -1974,25 +2065,39 @@ struct basilisk_swap *basilisk_thread_start(struct supernet_info *myinfo,bits256 { printf("basilisk_thread_start request.%u statebits.%d\n",rp->requestid,statebits); swap = calloc(1,sizeof(*swap)); + swap->subsock = swap->pushsock = -1; vcalc_sha256(0,swap->I.orderhash.bytes,(uint8_t *)rp,sizeof(*rp)); swap->I.req = *rp; swap->myinfoptr = myinfo; - //swap->myinfo.ctx = myinfo->ctx; bitcoin_pubkey33(myinfo->ctx,pubkey33,privkey); - pubkey25519 = myinfo->myaddr.persistent;//curve25519(privkey,curve25519_basepoint9()); - //swap->myinfo.persistent_priv = privkey; - //swap->myinfo.myaddr.persistent = pubkey25519; - //memcpy(swap->myinfo.persistent_pubkey33,pubkey33,33); + pubkey25519 = curve25519(privkey,curve25519_basepoint9()); + swap->persistent_pubkey = pubkey25519; + swap->persistent_privkey = privkey; + memcpy(swap->persistent_pubkey33,pubkey33,33); m = n = 0; - if ( bitcoin_swapinit(myinfo->ctx,privkey,pubkey33,pubkey25519,swap,optionduration) != 0 ) + if ( bitcoin_swapinit(myinfo->ctx,privkey,pubkey33,pubkey25519,swap,optionduration,statebits) != 0 ) { + if ( statebits == 0 ) + { + if ( (retstr= _dex_psock(myinfo,"{}")) != 0 ) + { + // {"result":"success","pushaddr":"tcp://5.9.102.210:30002","subaddr":"tcp://5.9.102.210:30003","randipbits":3606291758,"coin":"KMD","tag":"6952562460568228137"} + if ( (retjson= cJSON_Parse(retstr)) != 0 ) + { + basilisk_psockinit(myinfo,swap,jstr(retjson,"pushaddr"),jstr(retjson,"subaddr")); + free_json(retjson); + } + free(retstr); + } + } else basilisk_psockinit(myinfo,swap,0,0); + starttime = (uint32_t)time(NULL); printf("statebits.%x m.%d n.%d\n",statebits,m,n); while ( statebits == 0 && m <= n/2 && time(NULL) < starttime+BASILISK_MSGDURATION ) { m = n = 0; - dpow_nanomsg_update(myinfo); - dex_updateclient(myinfo); + //dpow_nanomsg_update(myinfo); + //dex_updateclient(myinfo); sleep(3); printf("waiting for offer to be accepted\n"); channel = 'D' + ((uint32_t)'E' << 8) + ((uint32_t)'X' << 16); diff --git a/basilisk/basilisk_tradebot.c b/basilisk/basilisk_tradebot.c index d98bc1200..dbb6ca742 100755 --- a/basilisk/basilisk_tradebot.c +++ b/basilisk/basilisk_tradebot.c @@ -290,6 +290,10 @@ double basilisk_request_listprocess(struct supernet_info *myinfo,struct basilisk } if ( bits256_cmp(myinfo->myaddr.persistent,list[0].srchash) == 0 ) // my request myrequest = 1; + else if ( bits256_cmp(myinfo->jumblr_pubkey,list[0].srchash) == 0 ) // my request + myrequest = 1; + else if ( bits256_cmp(myinfo->jumblr_depositkey,list[0].srchash) == 0 ) // my request + myrequest = 1; for (i=0; imyaddr.persistent,list[i].desthash) == 0 ) // my quoteid myrequest |= 2; + else if ( bits256_cmp(myinfo->jumblr_pubkey,list[i].desthash) == 0 ) // my quoteid + myrequest |= 2; + else if ( bits256_cmp(myinfo->jumblr_depositkey,list[i].desthash) == 0 ) // my quoteid + myrequest |= 2; havequoteflag++; if ( pendingid == 0 ) { diff --git a/iguana/dpow/dpow_network.c b/iguana/dpow/dpow_network.c index 73d6054e7..a0b99d84a 100755 --- a/iguana/dpow/dpow_network.c +++ b/iguana/dpow/dpow_network.c @@ -303,6 +303,7 @@ cJSON *dpow_psock(struct supernet_info *myinfo,char *jsonstr) subport = myinfo->psockport++; for (i=0; i<100; i++) { + pullsock = pubsock = -1; nanomsg_tcpname(myinfo,pushaddr,myinfo->ipaddr,pushport), pushport += 2; nanomsg_tcpname(myinfo,subaddr,myinfo->ipaddr,subport), subport += 2; if ( (pullsock= nn_socket(AF_SP,NN_PULL)) >= 0 && (pubsock= nn_socket(AF_SP,NN_PUB)) >= 0 ) @@ -322,6 +323,10 @@ cJSON *dpow_psock(struct supernet_info *myinfo,char *jsonstr) jaddstr(retjson,"subaddr",subaddr); break; } + if ( pullsock >= 0 ) + nn_close(pullsock); + if ( pubsock >= 0 ) + nn_close(pubsock); } if ( pushport < 1000 ) pushport = 1001; @@ -329,13 +334,7 @@ cJSON *dpow_psock(struct supernet_info *myinfo,char *jsonstr) subport = 1001; } if ( i == 100 ) - { jaddstr(retjson,"error","cant find psock ports"); - if ( pullsock >= 0 ) - nn_close(pullsock); - if ( pubsock >= 0 ) - nn_close(pubsock); - } return(retjson); } @@ -1139,6 +1138,8 @@ char *_dex_sendmessage(struct supernet_info *myinfo,char *jsonstr) char *_dex_psock(struct supernet_info *myinfo,char *jsonstr) { struct dex_request dexreq; + if ( jsonstr == 0 ) + jsonstr = "{}"; memset(&dexreq,0,sizeof(dexreq)); safecopy(dexreq.name,"KMD",sizeof(dexreq.name)); dexreq.func = 'Z'; diff --git a/iguana/iguana777.h b/iguana/iguana777.h index 5beb12130..e9b6a5f23 100755 --- a/iguana/iguana777.h +++ b/iguana/iguana777.h @@ -116,7 +116,7 @@ struct message_info { int32_t msgcount; bits256 refhash,msghashes[64]; uint32_t struct supernet_info { struct supernet_address myaddr; - bits256 persistent_priv,privkey; + bits256 persistent_priv,privkey,jumblr_pubkey,jumblr_depositkey; uint8_t persistent_pubkey33[33]; char ipaddr[64],NXTAPIURL[512],secret[4096],password[4096],rpcsymbol[64],handle[1024],permanentfile[1024],jumblr_passphrase[1024]; char *decryptstr; @@ -162,11 +162,14 @@ struct basilisk_swap { struct supernet_info *myinfoptr; struct iguana_info *bobcoin,*alicecoin; void (*balancingtrade)(struct supernet_info *myinfo,struct basilisk_swap *swap,int32_t iambob); + bits256 persistent_privkey,persistent_pubkey; struct basilisk_swapinfo I; struct basilisk_rawtx bobdeposit,bobpayment,alicepayment,myfee,otherfee,aliceclaim,alicespend,bobreclaim,bobspend,bobrefund,alicereclaim; bits256 privkeys[INSTANTDEX_DECKSIZE]; + int32_t subsock,pushsock,connected; uint64_t otherdeck[INSTANTDEX_DECKSIZE][2],deck[INSTANTDEX_DECKSIZE][2]; - uint8_t verifybuf[65536]; + uint8_t persistent_pubkey33[33],pad[15],verifybuf[65536]; + }; #include "../includes/iguana_funcs.h" diff --git a/iguana/tests/dexkvupdate b/iguana/tests/dexkvupdate index a98240995..a6792a142 100755 --- a/iguana/tests/dexkvupdate +++ b/iguana/tests/dexkvupdate @@ -1,3 +1,3 @@ #!/bin/bash -curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"kvupdate\",\"key\":\"test\",\"value\":\"$1\",\"flags\":0,\"symbol\":\"KMD\"}" -curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"kvupdate\",\"key\":\"test\",\"value\":\"$1\",\"flags\":0,\"symbol\":\"KV\"}" +#curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"kvupdate\",\"key\":\"test\",\"value\":\"$1\",\"flags\":0,\"symbol\":\"KMD\"}" +curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"kvupdate\",\"key\":\"testtest\",\"value\":\"$1\",\"flags\":0,\"symbol\":\"KV\"}" diff --git a/iguana/tests/dexpsock b/iguana/tests/dexpsock new file mode 100755 index 000000000..0a0e6fb16 --- /dev/null +++ b/iguana/tests/dexpsock @@ -0,0 +1,2 @@ +#!/bin/bash +curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"psock\"}"