Browse Source

test

release/v0.1
jl777 9 years ago
parent
commit
0aa4af5cab
  1. 4
      iguana/iguana_instantdex.c
  2. 18
      iguana/swaps/iguana_BTCswap.c

4
iguana/iguana_instantdex.c

@ -371,10 +371,10 @@ struct instantdex_accept *instantdex_acceptable(struct supernet_info *myinfo,str
//printf("aveprice %.8f %.8f offerdir.%d first cmp: %d %d %d\n",aveprice,dstr(ap->offer.price64),offerdir,A->offer.price64 == 0,(offerdir > 0 && ap->offer.price64 >= A->offer.price64),(offerdir < 0 && ap->offer.price64 <= A->offer.price64)); //printf("aveprice %.8f %.8f offerdir.%d first cmp: %d %d %d\n",aveprice,dstr(ap->offer.price64),offerdir,A->offer.price64 == 0,(offerdir > 0 && ap->offer.price64 >= A->offer.price64),(offerdir < 0 && ap->offer.price64 <= A->offer.price64));
if ( offerdir == 0 || A->offer.price64 == 0 || ((offerdir < 0 && ap->offer.price64 >= A->offer.price64) || (offerdir > 0 && ap->offer.price64 <= A->offer.price64)) ) if ( offerdir == 0 || A->offer.price64 == 0 || ((offerdir < 0 && ap->offer.price64 >= A->offer.price64) || (offerdir > 0 && ap->offer.price64 <= A->offer.price64)) )
{ {
printf("passed second cmp: offerdir.%d best %.8f ap %.8f\n",offerdir,dstr(bestprice64),dstr(ap->offer.price64)); //printf("passed second cmp: offerdir.%d best %.8f ap %.8f\n",offerdir,dstr(bestprice64),dstr(ap->offer.price64));
if ( bestprice64 == 0 || (offerdir < 0 && ap->offer.price64 < bestprice64) || (offerdir > 0 && ap->offer.price64 > bestprice64) ) if ( bestprice64 == 0 || (offerdir < 0 && ap->offer.price64 < bestprice64) || (offerdir > 0 && ap->offer.price64 > bestprice64) )
{ {
printf("found better price %f vs %f\n",dstr(ap->offer.price64),dstr(bestprice64)); //printf("found better price %f vs %f\n",dstr(ap->offer.price64),dstr(bestprice64));
bestprice64 = ap->offer.price64; bestprice64 = ap->offer.price64;
retap = ap; retap = ap;
} }

18
iguana/swaps/iguana_BTCswap.c

@ -35,7 +35,7 @@ struct bitcoin_swapinfo
{ {
bits256 privkeys[777],mypubs[2],otherpubs[2]; bits256 privkeys[777],mypubs[2],otherpubs[2];
bits256 orderhash,privAm,pubAm,privBn,pubBn,dtxid,ptxid,aptxid,astxid,stxid,ftxid,othertrader; bits256 orderhash,privAm,pubAm,privBn,pubBn,dtxid,ptxid,aptxid,astxid,stxid,ftxid,othertrader;
uint64_t otherscut[777][2],deck[777][2],satoshis[2],insurance; uint64_t otherscut[777][2],deck[777][2],satoshis[2],insurance,bidid,askid;
int32_t isbob,choosei,otherschoosei,state,cutverified,otherverifiedcut; int32_t isbob,choosei,otherschoosei,state,cutverified,otherverifiedcut;
double minperc; double minperc;
char altmsigaddr[64],nextstate[16],*deposit,*payment,*altpayment,*altspend,*spendtx,*feetx; char altmsigaddr[64],nextstate[16],*deposit,*payment,*altpayment,*altspend,*spendtx,*feetx;
@ -312,7 +312,7 @@ char *instantdex_choosei(struct bitcoin_swapinfo *swap,cJSON *newjson,cJSON *arg
swap->choosei = -swap->choosei; swap->choosei = -swap->choosei;
swap->choosei %= max; swap->choosei %= max;
jaddnum(newjson,"mychoosei",swap->choosei); jaddnum(newjson,"mychoosei",swap->choosei);
printf("%s send mychoosei.%d of max.%d\n",swap->isbob!=0?"BOB":"alice",swap->choosei,max); printf("%llu/%llu %s send mychoosei.%d of max.%d\n",(long long)swap->bidid,(long long)swap->askid,swap->isbob!=0?"BOB":"alice",swap->choosei,max);
return(0); return(0);
} }
else else
@ -439,7 +439,7 @@ char *instantdex_statemachine(struct supernet_info *myinfo,struct exchange_info
} }
}*/ }*/
if ( swap->isbob != 0 ) if ( swap->isbob != 0 )
strcpy(swap->nextstate,"step4"); strcpy(swap->nextstate,"step2");
else strcpy(swap->nextstate,"step3"); else strcpy(swap->nextstate,"step3");
return(instantdex_sendcmd(myinfo,&A->offer,newjson,swap->isbob != 0 ? "BTCstep3" : "BTCstep2",swap->othertrader,INSTANTDEX_HOPS,swap->privkeys,sizeof(swap->privkeys))); return(instantdex_sendcmd(myinfo,&A->offer,newjson,swap->isbob != 0 ? "BTCstep3" : "BTCstep2",swap->othertrader,INSTANTDEX_HOPS,swap->privkeys,sizeof(swap->privkeys)));
} }
@ -647,8 +647,11 @@ char *instantdex_BTCswap(struct supernet_info *myinfo,struct exchange_info *exch
swap->choosei = swap->otherschoosei = -1; swap->choosei = swap->otherschoosei = -1;
swap->state++; swap->state++;
swap->othertrader = traderpub; swap->othertrader = traderpub;
if ( offerdir > 0 )
swap->bidid = A->orderid;
else swap->askid = A->orderid;
swap->isbob = (A->offer.myside ^ 1); swap->isbob = (A->offer.myside ^ 1);
printf("SET ISBOB.%d\n",swap->isbob); printf("SET ISBOB.%d orderid.%llu\n",swap->isbob,(long long)A->orderid);
strcpy(swap->nextstate,"step1"); strcpy(swap->nextstate,"step1");
} }
char str[65]; printf("FOUND MATCH! %p (%s/%s) other.%s myside.%d next.%s\n",A->info,A->offer.base,A->offer.rel,bits256_str(str,traderpub),swap->isbob,swap->nextstate); char str[65]; printf("FOUND MATCH! %p (%s/%s) other.%s myside.%d next.%s\n",A->info,A->offer.base,A->offer.rel,bits256_str(str,traderpub),swap->isbob,swap->nextstate);
@ -667,7 +670,9 @@ char *instantdex_BTCswap(struct supernet_info *myinfo,struct exchange_info *exch
else else
{ {
// generate feetx to send // generate feetx to send
printf(">>>> step1.(%s)\n",jprint(newjson,0)); if ( swap->isbob != 0 )
strcpy(swap->nextstate,"step2");
else strcpy(swap->nextstate,"step3");
return(instantdex_sendcmd(myinfo,&A->offer,newjson,"BTCstep1",traderpub,INSTANTDEX_HOPS,swap->deck,sizeof(swap->deck))); return(instantdex_sendcmd(myinfo,&A->offer,newjson,"BTCstep1",traderpub,INSTANTDEX_HOPS,swap->deck,sizeof(swap->deck)));
} }
} }
@ -687,6 +692,9 @@ char *instantdex_BTCswap(struct supernet_info *myinfo,struct exchange_info *exch
} }
else if ( swap == 0 ) else if ( swap == 0 )
return(clonestr("{\"error\":\"no swap info\"}")); return(clonestr("{\"error\":\"no swap info\"}"));
if ( offerdir > 0 )
swap->bidid = A->orderid;
else swap->askid = A->orderid;
swap->satoshis[0] = A->offer.basevolume64; swap->satoshis[0] = A->offer.basevolume64;
swap->satoshis[1] = relsatoshis; swap->satoshis[1] = relsatoshis;
swap->insurance = (relsatoshis * INSTANTDEX_INSURANCERATE + coinbtc->chain->txfee); // txfee swap->insurance = (relsatoshis * INSTANTDEX_INSURANCERATE + coinbtc->chain->txfee); // txfee

Loading…
Cancel
Save