From 9f37743c73fde35293dd5b69a1d5193bca270c16 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 4 Mar 2017 18:59:34 +0200 Subject: [PATCH] Test --- basilisk/basilisk.c | 2 +- basilisk/basilisk.h | 15 ++------ basilisk/basilisk_DEX.c | 30 +++++++++------- basilisk/basilisk_bitcoin.c | 2 +- basilisk/basilisk_swap.c | 72 ++++++++++++++++++++----------------- basilisk/jumblr.c | 1 + iguana/iguana777.h | 11 ++++++ includes/iguana_funcs.h | 2 +- 8 files changed, 74 insertions(+), 61 deletions(-) diff --git a/basilisk/basilisk.c b/basilisk/basilisk.c index e4760e040..fe2150489 100755 --- a/basilisk/basilisk.c +++ b/basilisk/basilisk.c @@ -924,7 +924,7 @@ void basilisks_loop(void *arg) if ( myinfo->expiration != 0 && (myinfo->dexsock >= 0 || myinfo->IAMLP != 0 || myinfo->DEXactive > time(NULL)) ) { //fprintf(stderr,"H "); - basilisk_requests_poll(myinfo); + basilisk_requests_poll(myinfo,myinfo->persistent_priv); } //printf("RELAYID.%d endmilli %f vs now %f\n",myinfo->NOTARY.RELAYID,endmilli,startmilli); while ( OS_milliseconds() < endmilli ) diff --git a/basilisk/basilisk.h b/basilisk/basilisk.h index 45bbdd6b2..7ca809600 100755 --- a/basilisk/basilisk.h +++ b/basilisk/basilisk.h @@ -41,6 +41,8 @@ #define INSTANTDEX_BTC "1KRhTPvoxyJmVALwHFXZdeeWFbcJSbkFPu" #define INSTANTDEX_BTCD "RThtXup6Zo7LZAi8kRWgjAyi1s4u6U9Cpf" +struct basilisk_swap; + struct basilisk_rawtxinfo { char destaddr[64]; @@ -77,17 +79,6 @@ struct basilisk_swapinfo uint8_t secretAm256[32],secretBn256[32]; }; -struct basilisk_swap -{ - struct supernet_info *myinfo; struct iguana_info *bobcoin,*alicecoin; - void (*balancingtrade)(struct supernet_info *myinfo,struct basilisk_swap *swap,int32_t iambob); - struct basilisk_swapinfo I; - struct basilisk_rawtx bobdeposit,bobpayment,alicepayment,myfee,otherfee,aliceclaim,alicespend,bobreclaim,bobspend,bobrefund,alicereclaim; - bits256 privkeys[INSTANTDEX_DECKSIZE]; - uint64_t otherdeck[INSTANTDEX_DECKSIZE][2],deck[INSTANTDEX_DECKSIZE][2]; - uint8_t verifybuf[65536]; -}; - struct basilisk_value { bits256 txid; int64_t value; int32_t height; int16_t vout; char coinaddr[64]; }; struct basilisk_item @@ -135,7 +126,7 @@ int32_t basilisk_update(char *symbol,uint32_t reftimestamp); void basilisk_seqresult(struct supernet_info *myinfo,char *retstr); struct iguana_info *basilisk_geckochain(struct supernet_info *myinfo,char *symbol,char *chainname,cJSON *valsobj); void basilisk_alicepayment(struct supernet_info *myinfo,struct basilisk_swap *swap,struct iguana_info *coin,struct basilisk_rawtx *alicepayment,bits256 pubAm,bits256 pubBn); -void basilisk_rawtx_setparms(char *name,struct supernet_info *myinfo,struct basilisk_swap *swap,struct basilisk_rawtx *rawtx,struct iguana_info *coin,int32_t numconfirms,int32_t vintype,uint64_t satoshis,int32_t vouttype,uint8_t *pubkey33); +void basilisk_rawtx_setparms(char *name,struct basilisk_swap *swap,struct basilisk_rawtx *rawtx,struct iguana_info *coin,int32_t numconfirms,int32_t vintype,uint64_t satoshis,int32_t vouttype,uint8_t *pubkey33); void basilisk_setmyid(struct supernet_info *myinfo); int32_t basilisk_rwDEXquote(int32_t rwflag,uint8_t *serialized,struct basilisk_request *rp); cJSON *basilisk_requestjson(struct basilisk_request *rp); diff --git a/basilisk/basilisk_DEX.c b/basilisk/basilisk_DEX.c index 85b9c5376..7d0aafeb2 100755 --- a/basilisk/basilisk_DEX.c +++ b/basilisk/basilisk_DEX.c @@ -229,7 +229,7 @@ int32_t basilisk_request_create(struct basilisk_request *rp,cJSON *valsobj,bits2 return(-1); } -char *basilisk_start(struct supernet_info *myinfo,struct basilisk_request *_rp,uint32_t statebits,int32_t optionduration) +char *basilisk_start(struct supernet_info *myinfo,bits256 privkey,struct basilisk_request *_rp,uint32_t statebits,int32_t optionduration) { cJSON *retjson; struct basilisk_request *rp=0; int32_t i; if ( _rp->requestid == myinfo->lastdexrequestid ) @@ -251,7 +251,7 @@ char *basilisk_start(struct supernet_info *myinfo,struct basilisk_request *_rp,u *rp = *_rp; printf("START thread to complete %u/%u for (%s %.8f) <-> (%s %.8f) q.%u\n",rp->requestid,rp->quoteid,rp->src,dstr(rp->srcamount),rp->dest,dstr(rp->destamount),rp->quoteid); myinfo->lastdexrequestid = rp->requestid; - if ( basilisk_thread_start(myinfo,rp,statebits,optionduration) != 0 ) + if ( basilisk_thread_start(myinfo,privkey,rp,statebits,optionduration) != 0 ) { basilisk_request_enqueue(myinfo,rp); return(clonestr("{\"result\":\"started atomic swap thread\"}")); @@ -272,7 +272,7 @@ char *basilisk_start(struct supernet_info *myinfo,struct basilisk_request *_rp,u } else return(clonestr("{\"error\":\"unexpected basilisk_start not mine and amrelay\"}")); } -void basilisk_requests_poll(struct supernet_info *myinfo) +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.; @@ -315,7 +315,7 @@ void basilisk_requests_poll(struct supernet_info *myinfo) 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,&issueR,1,issueR.optionhours * 3600)) != 0 ) + 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 ) free(retstr); @@ -346,7 +346,7 @@ void basilisk_requests_poll(struct supernet_info *myinfo) dex_channelsend(myinfo,issueR.desthash,issueR.srchash,channel,msgid,data,datalen); //INSTANTDEX_LOCKTIME*2 dpow_nanomsg_update(myinfo); dex_updateclient(myinfo); - if ( (retstr= basilisk_start(myinfo,&issueR,0,issueR.optionhours * 3600)) != 0 ) + if ( (retstr= basilisk_start(myinfo,myinfo->persistent_priv,&issueR,0,issueR.optionhours * 3600)) != 0 ) free(retstr); /*crcs[0] = crcs[1] = 0; numiters = 0; @@ -489,7 +489,7 @@ char *basilisk_respond_requests(struct supernet_info *myinfo,bits256 hash,uint32 return(jprint(retjson,1)); } -char *basilisk_respond_accept(struct supernet_info *myinfo,uint32_t requestid,uint32_t quoteid,struct basilisk_request *refrp) +char *basilisk_respond_accept(struct supernet_info *myinfo,bits256 privkey,uint32_t requestid,uint32_t quoteid,struct basilisk_request *refrp) { int32_t i,num=0; char *retstr=0; struct basilisk_request *requests,*rp; uint8_t space[4096]; portable_mutex_lock(&myinfo->DEX_reqmutex); @@ -501,7 +501,7 @@ char *basilisk_respond_accept(struct supernet_info *myinfo,uint32_t requestid,ui if ( rp->requestid == requestid && rp->quoteid == quoteid ) { printf("start from accept\n"); - retstr = basilisk_start(myinfo,rp,1,0); + retstr = basilisk_start(myinfo,privkey,rp,1,0); break; } } @@ -637,7 +637,7 @@ STRING_ARG(InstantDEX,available,source) HASH_ARRAY_STRING(InstantDEX,request,hash,vals,hexstr) { - uint8_t serialized[512]; char buf[512]; struct basilisk_request R; int32_t iambob,optionhours; cJSON *reqjson; uint32_t datalen=0,DEX_channel; struct iguana_info *bobcoin,*alicecoin; + uint8_t serialized[512]; bits256 privkey; char buf[512],BTCaddr[64],KMDaddr[64]; struct basilisk_request R; int32_t iambob,optionhours; cJSON *reqjson; uint32_t datalen=0,DEX_channel; struct iguana_info *bobcoin,*alicecoin; myinfo->DEXactive = (uint32_t)time(NULL) + 3*BASILISK_TIMEOUT + 60; jadd64bits(vals,"minamount",jdouble(vals,"minprice") * jdouble(vals,"amount") * SATOSHIDEN * SATOSHIDEN); if ( jobj(vals,"srchash") == 0 ) @@ -647,12 +647,16 @@ HASH_ARRAY_STRING(InstantDEX,request,hash,vals,hexstr) jadd64bits(vals,"satoshis",jdouble(vals,"amount") * SATOSHIDEN); jadd64bits(vals,"destsatoshis",jdouble(vals,"destamount") * SATOSHIDEN); jaddnum(vals,"timestamp",time(NULL)); - hash = myinfo->myaddr.persistent; + if ( jint(vals,"usejumblr") != 0 ) + privkey = jumblr_privkey(myinfo,BTCaddr,KMDaddr,JUMBLR_DEPOSITPREFIX); + else privkey = myinfo->persistent_priv; + hash = curve25519(privkey,curve25519_basepoint9()); + //hash = myinfo->myaddr.persistent; printf("service.(%s)\n",jprint(vals,0)); memset(&R,0,sizeof(R)); if ( basilisk_request_create(&R,vals,hash,juint(vals,"timestamp")) == 0 ) { - iambob = bitcoin_coinptrs(myinfo,&bobcoin,&alicecoin,R.src,R.dest,myinfo->myaddr.persistent,GENESIS_PUBKEY); + iambob = bitcoin_coinptrs(hash,&bobcoin,&alicecoin,R.src,R.dest,privkey,GENESIS_PUBKEY); if ( (optionhours= jint(vals,"optionhours")) != 0 ) { printf("iambob.%d optionhours.%d R.requestid.%u vs calc %u, q.%u\n",iambob,R.optionhours,R.requestid,basilisk_requestid(&R),R.quoteid); @@ -681,11 +685,11 @@ HASH_ARRAY_STRING(InstantDEX,request,hash,vals,hexstr) } else printf("error creating request\n"); if ( datalen > 0 ) { - uint32_t msgid,crc=0;//,crcs[2],numiters = 0; uint8_t buf[4096]; + uint32_t msgid;//,crc=0,crcs[2],numiters = 0; uint8_t buf[4096]; memset(hash.bytes,0,sizeof(hash)); msgid = (uint32_t)time(NULL); DEX_channel = 'D' + ((uint32_t)'E' << 8) + ((uint32_t)'X' << 16); - basilisk_channelsend(myinfo,myinfo->myaddr.persistent,hash,DEX_channel,msgid,serialized,datalen,60); + basilisk_channelsend(myinfo,hash,hash,DEX_channel,msgid,serialized,datalen,60); sleep(3); /*while ( numiters < 10 && (crc= basilisk_crcsend(myinfo,0,buf,sizeof(buf),hash,myinfo->myaddr.persistent,DEX_channel,msgid,serialized,datalen,crcs)) == 0 ) { @@ -776,7 +780,7 @@ TWO_INTS(InstantDEX,accept,requestid,quoteid) cJSON *vals; char *retstr; myinfo->DEXactive = (uint32_t)time(NULL) + INSTANTDEX_LOCKTIME; if ( myinfo->IAMLP != 0 || myinfo->dexsock >= 0 || myinfo->subsock >= 0 ) - return(basilisk_respond_accept(myinfo,requestid,quoteid,&myinfo->DEXaccept)); + return(basilisk_respond_accept(myinfo,myinfo->persistent_priv,requestid,quoteid,&myinfo->DEXaccept)); else { vals = cJSON_CreateObject(); diff --git a/basilisk/basilisk_bitcoin.c b/basilisk/basilisk_bitcoin.c index 5864db483..e601c1e64 100755 --- a/basilisk/basilisk_bitcoin.c +++ b/basilisk/basilisk_bitcoin.c @@ -748,7 +748,7 @@ char *iguana_utxorawtx(struct supernet_info *myinfo,struct iguana_info *coin,int char *basilisk_bitcoinrawtx(struct supernet_info *myinfo,struct iguana_info *coin,char *remoteaddr,uint32_t basilisktag,int32_t timeoutmillis,cJSON *valsobj,struct vin_info *V) { - uint8_t buf[4096]; int32_t oplen,len,offset,minconf,spendlen; cJSON *vins,*addresses,*txobj = 0; uint32_t locktime; char *opreturn,*spendscriptstr,*changeaddr,*rawtx = 0; int64_t amount,txfee,burnamount; + uint8_t buf[4096]; int32_t oplen,offset,minconf,spendlen; cJSON *vins,*addresses,*txobj = 0; uint32_t locktime; char *opreturn,*spendscriptstr,*changeaddr,*rawtx = 0; int64_t amount,txfee,burnamount; if ( valsobj == 0 ) return(clonestr("{\"error\":\"null valsobj\"}")); //if ( myinfo->IAMNOTARY != 0 || myinfo->NOTARY.RELAYID >= 0 ) diff --git a/basilisk/basilisk_swap.c b/basilisk/basilisk_swap.c index 2b0c72d91..b9f785887 100755 --- a/basilisk/basilisk_swap.c +++ b/basilisk/basilisk_swap.c @@ -956,15 +956,15 @@ int32_t basilisk_privAm_extract(struct supernet_info *myinfo,struct basilisk_swa return(-1); } -bits256 instantdex_derivekeypair(struct supernet_info *myinfo,bits256 *newprivp,uint8_t pubkey[33],bits256 privkey,bits256 orderhash) +bits256 instantdex_derivekeypair(void *ctx,bits256 *newprivp,uint8_t pubkey[33],bits256 privkey,bits256 orderhash) { bits256 sharedsecret; sharedsecret = curve25519_shared(privkey,orderhash); vcalc_sha256cat(newprivp->bytes,orderhash.bytes,sizeof(orderhash),sharedsecret.bytes,sizeof(sharedsecret)); - return(bitcoin_pubkey33(myinfo->ctx,pubkey,*newprivp)); + return(bitcoin_pubkey33(ctx,pubkey,*newprivp)); } -int32_t instantdex_pubkeyargs(struct supernet_info *myinfo,struct basilisk_swap *swap,int32_t numpubs,bits256 privkey,bits256 hash,int32_t firstbyte) +int32_t instantdex_pubkeyargs(void *ctx,struct basilisk_swap *swap,int32_t numpubs,bits256 privkey,bits256 hash,int32_t firstbyte) { char buf[3]; int32_t i,n,m,len=0; bits256 pubi,reveal; uint64_t txid; uint8_t secret160[20],pubkey[33]; sprintf(buf,"%c0",'A' - 0x02 + firstbyte); @@ -976,7 +976,7 @@ int32_t instantdex_pubkeyargs(struct supernet_info *myinfo,struct basilisk_swap } for (i=n=m=0; iname,name); rawtx->coin = coin; @@ -1050,7 +1050,7 @@ void basilisk_rawtx_setparms(char *name,struct supernet_info *myinfo,struct basi } else printf("%s vouttype.%d destaddr.(%s)\n",name,rawtx->I.vouttype,rawtx->I.destaddr); } -int32_t bitcoin_coinptrs(struct supernet_info *myinfo,struct iguana_info **bobcoinp,struct iguana_info **alicecoinp,char *src,char *dest,bits256 srchash,bits256 desthash) +int32_t bitcoin_coinptrs(bits256 pubkey,struct iguana_info **bobcoinp,struct iguana_info **alicecoinp,char *src,char *dest,bits256 srchash,bits256 desthash) { struct iguana_info *coin = iguana_coinfind(src); if ( coin == 0 || iguana_coinfind(dest) == 0 ) @@ -1077,7 +1077,7 @@ int32_t bitcoin_coinptrs(struct supernet_info *myinfo,struct iguana_info **bobco *alicecoinp = iguana_coinfind(src); } else return(0); - if ( bits256_cmp(myinfo->myaddr.persistent,srchash) == 0 ) + if ( bits256_cmp(pubkey,srchash) == 0 ) { if ( strcmp(src,(*bobcoinp)->symbol) == 0 ) return(1); @@ -1085,7 +1085,7 @@ int32_t bitcoin_coinptrs(struct supernet_info *myinfo,struct iguana_info **bobco return(-1); else return(0); } - else if ( bits256_cmp(myinfo->myaddr.persistent,desthash) == 0 ) + else if ( bits256_cmp(pubkey,desthash) == 0 ) { if ( strcmp(src,(*bobcoinp)->symbol) == 0 ) return(-1); @@ -1096,7 +1096,7 @@ int32_t bitcoin_coinptrs(struct supernet_info *myinfo,struct iguana_info **bobco return(0); } -struct basilisk_swap *bitcoin_swapinit(struct supernet_info *myinfo,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) { struct iguana_info *coin,*bobcoin,*alicecoin; uint8_t *alicepub33=0,*bobpub33=0; int32_t x = -1; swap->I.putduration = swap->I.callduration = INSTANTDEX_LOCKTIME; @@ -1168,7 +1168,7 @@ struct basilisk_swap *bitcoin_swapinit(struct supernet_info *myinfo,struct basil swap->I.choosei = -swap->I.choosei; swap->I.choosei %= INSTANTDEX_DECKSIZE; swap->I.otherchoosei = -1; - swap->I.myhash = myinfo->myaddr.persistent; + swap->I.myhash = pubkey25519; if ( bits256_cmp(swap->I.myhash,swap->I.req.srchash) == 0 ) { swap->I.otherhash = swap->I.req.desthash; @@ -1186,46 +1186,46 @@ struct basilisk_swap *bitcoin_swapinit(struct supernet_info *myinfo,struct basil printf("neither src nor dest error\n"); return(0); } - if ( (bitcoin_coinptrs(myinfo,&bobcoin,&alicecoin,swap->I.req.src,swap->I.req.dest,swap->I.req.srchash,swap->I.req.desthash)+1)/2 != swap->I.iambob ) + 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(myinfo,&bobcoin,&alicecoin,swap->I.req.src,swap->I.req.dest,swap->I.req.srchash,swap->I.req.desthash)); + 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)); return(0); } - if ( bits256_nonz(myinfo->persistent_priv) == 0 || (x= instantdex_pubkeyargs(myinfo,swap,2 + INSTANTDEX_DECKSIZE,myinfo->persistent_priv,swap->I.orderhash,0x02+swap->I.iambob)) != 2 + INSTANTDEX_DECKSIZE ) + if ( bits256_nonz(privkey) == 0 || (x= instantdex_pubkeyargs(ctx,swap,2 + INSTANTDEX_DECKSIZE,privkey,swap->I.orderhash,0x02+swap->I.iambob)) != 2 + INSTANTDEX_DECKSIZE ) { printf("couldnt generate privkeys %d\n",x); return(0); } if ( swap->I.iambob != 0 ) { - basilisk_rawtx_setparms("myfee",myinfo,swap,&swap->myfee,swap->bobcoin,0,0,swap->I.bobsatoshis/INSTANTDEX_DECKSIZE,0,0); - basilisk_rawtx_setparms("otherfee",myinfo,swap,&swap->otherfee,swap->alicecoin,0,0,swap->I.alicesatoshis/INSTANTDEX_DECKSIZE,0,0); - bobpub33 = myinfo->persistent_pubkey33; + basilisk_rawtx_setparms("myfee",swap,&swap->myfee,swap->bobcoin,0,0,swap->I.bobsatoshis/INSTANTDEX_DECKSIZE,0,0); + basilisk_rawtx_setparms("otherfee",swap,&swap->otherfee,swap->alicecoin,0,0,swap->I.alicesatoshis/INSTANTDEX_DECKSIZE,0,0); + bobpub33 = pubkey33; } else { - basilisk_rawtx_setparms("otherfee",myinfo,swap,&swap->otherfee,swap->bobcoin,0,0,swap->I.bobsatoshis/INSTANTDEX_DECKSIZE,0,0); - basilisk_rawtx_setparms("myfee",myinfo,swap,&swap->myfee,swap->alicecoin,0,0,swap->I.alicesatoshis/INSTANTDEX_DECKSIZE,0,0); - alicepub33 = myinfo->persistent_pubkey33; + basilisk_rawtx_setparms("otherfee",swap,&swap->otherfee,swap->bobcoin,0,0,swap->I.bobsatoshis/INSTANTDEX_DECKSIZE,0,0); + basilisk_rawtx_setparms("myfee",swap,&swap->myfee,swap->alicecoin,0,0,swap->I.alicesatoshis/INSTANTDEX_DECKSIZE,0,0); + alicepub33 = pubkey33; } - basilisk_rawtx_setparms("bobdeposit",myinfo,swap,&swap->bobdeposit,swap->bobcoin,swap->I.bobconfirms,0,swap->I.bobsatoshis + (swap->I.bobsatoshis>>3) + swap->bobcoin->txfee,4,0); - basilisk_rawtx_setparms("bobrefund",myinfo,swap,&swap->bobrefund,swap->bobcoin,1,4,swap->I.bobsatoshis + (swap->I.bobsatoshis>>3),1,bobpub33); + basilisk_rawtx_setparms("bobdeposit",swap,&swap->bobdeposit,swap->bobcoin,swap->I.bobconfirms,0,swap->I.bobsatoshis + (swap->I.bobsatoshis>>3) + swap->bobcoin->txfee,4,0); + basilisk_rawtx_setparms("bobrefund",swap,&swap->bobrefund,swap->bobcoin,1,4,swap->I.bobsatoshis + (swap->I.bobsatoshis>>3),1,bobpub33); swap->bobrefund.I.suppress_pubkeys = 1; - basilisk_rawtx_setparms("aliceclaim",myinfo,swap,&swap->aliceclaim,swap->bobcoin,1,4,swap->I.bobsatoshis + (swap->I.bobsatoshis>>3),1,alicepub33); + basilisk_rawtx_setparms("aliceclaim",swap,&swap->aliceclaim,swap->bobcoin,1,4,swap->I.bobsatoshis + (swap->I.bobsatoshis>>3),1,alicepub33); swap->aliceclaim.I.suppress_pubkeys = 1; swap->aliceclaim.I.locktime = swap->I.started + swap->I.putduration+swap->I.callduration + 1; - basilisk_rawtx_setparms("bobpayment",myinfo,swap,&swap->bobpayment,swap->bobcoin,swap->I.bobconfirms,0,swap->I.bobsatoshis + swap->bobcoin->txfee,3,0); - basilisk_rawtx_setparms("alicespend",myinfo,swap,&swap->alicespend,swap->bobcoin,swap->I.bobconfirms,3,swap->I.bobsatoshis,1,alicepub33); + basilisk_rawtx_setparms("bobpayment",swap,&swap->bobpayment,swap->bobcoin,swap->I.bobconfirms,0,swap->I.bobsatoshis + swap->bobcoin->txfee,3,0); + basilisk_rawtx_setparms("alicespend",swap,&swap->alicespend,swap->bobcoin,swap->I.bobconfirms,3,swap->I.bobsatoshis,1,alicepub33); swap->alicespend.I.suppress_pubkeys = 1; - basilisk_rawtx_setparms("bobreclaim",myinfo,swap,&swap->bobreclaim,swap->bobcoin,swap->I.bobconfirms,3,swap->I.bobsatoshis,1,bobpub33); + basilisk_rawtx_setparms("bobreclaim",swap,&swap->bobreclaim,swap->bobcoin,swap->I.bobconfirms,3,swap->I.bobsatoshis,1,bobpub33); swap->bobreclaim.I.suppress_pubkeys = 1; swap->bobreclaim.I.locktime = swap->I.started + swap->I.putduration + 1; - basilisk_rawtx_setparms("alicepayment",myinfo,swap,&swap->alicepayment,swap->alicecoin,swap->I.aliceconfirms,0,swap->I.alicesatoshis+swap->alicecoin->txfee,2,0); - basilisk_rawtx_setparms("bobspend",myinfo,swap,&swap->bobspend,swap->alicecoin,swap->I.aliceconfirms,2,swap->I.alicesatoshis,1,bobpub33); + basilisk_rawtx_setparms("alicepayment",swap,&swap->alicepayment,swap->alicecoin,swap->I.aliceconfirms,0,swap->I.alicesatoshis+swap->alicecoin->txfee,2,0); + basilisk_rawtx_setparms("bobspend",swap,&swap->bobspend,swap->alicecoin,swap->I.aliceconfirms,2,swap->I.alicesatoshis,1,bobpub33); swap->bobspend.I.suppress_pubkeys = 1; - basilisk_rawtx_setparms("alicereclaim",myinfo,swap,&swap->alicereclaim,swap->alicecoin,swap->I.aliceconfirms,2,swap->I.alicesatoshis,1,alicepub33); + basilisk_rawtx_setparms("alicereclaim",swap,&swap->alicereclaim,swap->alicecoin,swap->I.aliceconfirms,2,swap->I.alicesatoshis,1,alicepub33); swap->alicereclaim.I.suppress_pubkeys = 1; printf("IAMBOB.%d\n",swap->I.iambob); return(swap); @@ -1756,7 +1756,7 @@ cJSON *swapjson(struct supernet_info *myinfo,struct basilisk_swap *swap) 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; - myinfo = swap->myinfo; + myinfo = &swap->myinfo; fprintf(stderr,"start swap\n"); maxlen = 1024*1024 + sizeof(*swap); data = malloc(maxlen); @@ -1933,9 +1933,9 @@ void basilisk_swaploop(void *_swap) free(data); } -struct basilisk_swap *basilisk_thread_start(struct supernet_info *myinfo,struct basilisk_request *rp,uint32_t statebits,int32_t optionduration) +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; uint32_t channel,starttime; cJSON *retarray,*item,*msgobj; struct basilisk_swap *swap = 0; + int32_t i,m,n; uint8_t pubkey33[33]; bits256 pubkey25519; uint32_t channel,starttime; cJSON *retarray,*item,*msgobj; struct basilisk_swap *swap = 0; portable_mutex_lock(&myinfo->DEX_swapmutex); for (i=0; inumswaps; i++) if ( myinfo->swaps[i]->I.req.requestid == rp->requestid ) @@ -1949,9 +1949,15 @@ struct basilisk_swap *basilisk_thread_start(struct supernet_info *myinfo,struct swap = calloc(1,sizeof(*swap)); vcalc_sha256(0,swap->I.orderhash.bytes,(uint8_t *)rp,sizeof(*rp)); swap->I.req = *rp; - swap->myinfo = myinfo; + //swap->myinfo = myinfo; + swap->myinfo.ctx = myinfo->ctx; + bitcoin_pubkey33(myinfo->ctx,pubkey33,privkey); + pubkey25519 = curve25519(privkey,curve25519_basepoint9()); + swap->myinfo.persistent_priv = privkey; + swap->myinfo.myaddr.persistent = pubkey25519; + memcpy(swap->myinfo.persistent_pubkey33,pubkey33,33); m = n = 0; - if ( bitcoin_swapinit(myinfo,swap,optionduration) != 0 ) + if ( bitcoin_swapinit(myinfo->ctx,privkey,pubkey33,pubkey25519,swap,optionduration) != 0 ) { starttime = (uint32_t)time(NULL); printf("statebits.%x m.%d n.%d\n",statebits,m,n); diff --git a/basilisk/jumblr.c b/basilisk/jumblr.c index 9f7e972c1..c09076a46 100755 --- a/basilisk/jumblr.c +++ b/basilisk/jumblr.c @@ -386,6 +386,7 @@ void jumblr_DEXcheck(struct supernet_info *myinfo,struct iguana_info *coinkmd,ch jaddstr(vals,"dest","KMD"); jaddnum(vals,"amount",btcavail*.95); jaddnum(vals,"minprice",kmdprice*.95); + jaddnum(vals,"usejumblr",1); memset(hash.bytes,0,sizeof(hash)); pending = btcavail; if ( (retstr= InstantDEX_request(myinfo,coinbtc,0,0,hash,vals,"")) != 0 ) diff --git a/iguana/iguana777.h b/iguana/iguana777.h index 89d25f734..e724e828b 100755 --- a/iguana/iguana777.h +++ b/iguana/iguana777.h @@ -152,6 +152,17 @@ struct supernet_info uint8_t notaries[64][33]; int32_t numnotaries,DEXEXPLORER; }; +struct basilisk_swap +{ + struct supernet_info myinfo; struct iguana_info *bobcoin,*alicecoin; + void (*balancingtrade)(struct supernet_info *myinfo,struct basilisk_swap *swap,int32_t iambob); + struct basilisk_swapinfo I; + struct basilisk_rawtx bobdeposit,bobpayment,alicepayment,myfee,otherfee,aliceclaim,alicespend,bobreclaim,bobspend,bobrefund,alicereclaim; + bits256 privkeys[INSTANTDEX_DECKSIZE]; + uint64_t otherdeck[INSTANTDEX_DECKSIZE][2],deck[INSTANTDEX_DECKSIZE][2]; + uint8_t verifybuf[65536]; +}; + #include "../includes/iguana_funcs.h" #include "../includes/iguana_globals.h" #include "../gecko/gecko.h" diff --git a/includes/iguana_funcs.h b/includes/iguana_funcs.h index 7d8e3b679..dffa53ed0 100755 --- a/includes/iguana_funcs.h +++ b/includes/iguana_funcs.h @@ -595,7 +595,7 @@ int32_t iguana_scriptdata(struct iguana_info *coin,uint8_t *scriptspace,long fil void basilisk_ensurerelay(struct supernet_info *myinfo,struct iguana_info *notaries,uint32_t ipbits); void dpow_nanomsginit(struct supernet_info *myinfo,char *ipaddr); int32_t iguana_datachain_scan(struct supernet_info *myinfo,struct iguana_info *coin,uint8_t rmd160[20]); -void basilisk_requests_poll(struct supernet_info *myinfo); +void basilisk_requests_poll(struct supernet_info *myinfo,bits256 privkey); void iguana_RTreset(struct iguana_info *coin); void iguana_RTpurge(struct iguana_info *coin,int32_t lastheight);