Browse Source

test

release/v0.1
jl777 9 years ago
parent
commit
227f44df7c
  1. 6
      iguana/iguana_instantdex.c
  2. 25
      iguana/swaps/iguana_BTCswap.c

6
iguana/iguana_instantdex.c

@ -512,11 +512,7 @@ char *instantdex_parse(struct supernet_info *myinfo,struct instantdex_msghdr *ms
return(clonestr("{\"error\":\"orderhash mismatch\"}")); return(clonestr("{\"error\":\"orderhash mismatch\"}"));
} }
//char str[65],str2[65]; //char str[65],str2[65];
if ( bits256_cmp(traderpub,myinfo->myaddr.persistent) == 0 ) /**/
{
printf("got my own packet\n");
return(clonestr("{\"result\":\"got my own packet\"}"));
}
//else printf("got mismatched traderpub.%s vs %s\n",bits256_str(str,traderpub),bits256_str(str2,myinfo->myaddr.persistent)); //else printf("got mismatched traderpub.%s vs %s\n",bits256_str(str,traderpub),bits256_str(str2,myinfo->myaddr.persistent));
A.orderid = orderhash.txid; A.orderid = orderhash.txid;
if ( (ap= instantdex_offerfind(myinfo,exchange,0,0,A.orderid,"*","*")) != 0 ) if ( (ap= instantdex_offerfind(myinfo,exchange,0,0,A.orderid,"*","*")) != 0 )

25
iguana/swaps/iguana_BTCswap.c

@ -411,7 +411,7 @@ char *instantdex_statemachine(struct supernet_info *myinfo,struct exchange_info
{ {
uint32_t reftime; cJSON *newjson; char *retstr = 0; uint32_t reftime; cJSON *newjson; char *retstr = 0;
reftime = (uint32_t)(A->offer.expiration - INSTANTDEX_LOCKTIME*2); reftime = (uint32_t)(A->offer.expiration - INSTANTDEX_LOCKTIME*2);
//printf("cmd.(%s) vs next.(%s)\n",cmdstr,swap->nextstate); printf("%llu/%llu cmd.(%s) vs next.(%s)\n",(long long)swap->bidid,(long long)swap->askid,cmdstr,swap->nextstate);
if ( strcmp(cmdstr,"step1") == 0 && strcmp(swap->nextstate,cmdstr) == 0 ) // either if ( strcmp(cmdstr,"step1") == 0 && strcmp(swap->nextstate,cmdstr) == 0 ) // either
{ {
printf("%s got step1, should have other's choosei\n",swap->isbob!=0?"BOB":"alice"); printf("%s got step1, should have other's choosei\n",swap->isbob!=0?"BOB":"alice");
@ -613,10 +613,18 @@ char *instantdex_BTCswap(struct supernet_info *myinfo,struct exchange_info *exch
uint64_t satoshis[2]; int32_t offerdir = 0; double minperc; uint64_t insurance,relsatoshis; uint64_t satoshis[2]; int32_t offerdir = 0; double minperc; uint64_t insurance,relsatoshis;
struct instantdex_accept *ap; struct bitcoin_swapinfo *swap = 0; bits256 orderhash,traderpub; struct instantdex_accept *ap; struct bitcoin_swapinfo *swap = 0; bits256 orderhash,traderpub;
struct iguana_info *coinbtc,*altcoin; cJSON *newjson=0; char *retstr=0; struct iguana_info *coinbtc,*altcoin; cJSON *newjson=0; char *retstr=0;
relsatoshis = instantdex_relsatoshis(A->offer.price64,A->offer.basevolume64);
traderpub = jbits256(argjson,"traderpub");
if ( (minperc= jdouble(argjson,"p")) < INSTANTDEX_MINPERC )
minperc = INSTANTDEX_MINPERC;
coinbtc = iguana_coinfind("BTC");
insurance = (satoshis[1] * INSTANTDEX_INSURANCERATE + coinbtc->chain->txfee); // txfee prevents papercut attack
offerdir = instantdex_bidaskdir(A);
vcalc_sha256(0,orderhash.bytes,(void *)&A->offer,sizeof(ap->offer));
swap = A->info;
printf("T.%d [%s] got %s.(%s/%s) %.8f vol %.8f %llu offerside.%d offerdir.%d swap.%p decksize.%ld\n",bits256_cmp(traderpub,myinfo->myaddr.persistent),swap!=0?swap->nextstate:"",cmdstr,A->offer.base,A->offer.rel,dstr(A->offer.price64),dstr(A->offer.basevolume64),(long long)A->orderid,A->offer.myside,A->offer.acceptdir,A->info,sizeof(swap->deck));
if ( exchange == 0 ) if ( exchange == 0 )
return(clonestr("{\"error\":\"instantdex_BTCswap null exchange ptr\"}")); return(clonestr("{\"error\":\"instantdex_BTCswap null exchange ptr\"}"));
offerdir = instantdex_bidaskdir(A);
coinbtc = iguana_coinfind("BTC");
if ( (altcoin= iguana_coinfind(A->offer.base)) == 0 || coinbtc == 0 ) if ( (altcoin= iguana_coinfind(A->offer.base)) == 0 || coinbtc == 0 )
{ {
printf("other.%p coinbtc.%p (%s/%s)\n",altcoin,coinbtc,A->offer.base,A->offer.rel); printf("other.%p coinbtc.%p (%s/%s)\n",altcoin,coinbtc,A->offer.base,A->offer.rel);
@ -624,17 +632,10 @@ char *instantdex_BTCswap(struct supernet_info *myinfo,struct exchange_info *exch
} }
if ( strcmp(A->offer.rel,"BTC") != 0 ) if ( strcmp(A->offer.rel,"BTC") != 0 )
return(clonestr("{\"error\":\"instantdex_BTCswap offer non BTC rel\"}")); return(clonestr("{\"error\":\"instantdex_BTCswap offer non BTC rel\"}"));
vcalc_sha256(0,orderhash.bytes,(void *)&A->offer,sizeof(ap->offer));
if ( orderhash.txid != A->orderid ) if ( orderhash.txid != A->orderid )
return(clonestr("{\"error\":\"txid mismatches orderid\"}")); return(clonestr("{\"error\":\"txid mismatches orderid\"}"));
if ( (swap= A->info) == 0 && strcmp(cmdstr,"offer") != 0 ) //if ( (swap= A->info) == 0 && strcmp(cmdstr,"offer") != 0 )
return(clonestr("{\"error\":\"instantdex_BTCswap no swap info after offer\"}")); // return(clonestr("{\"error\":\"instantdex_BTCswap no swap info after offer\"}"));
relsatoshis = instantdex_relsatoshis(A->offer.price64,A->offer.basevolume64);
traderpub = jbits256(argjson,"traderpub");
if ( (minperc= jdouble(argjson,"p")) < INSTANTDEX_MINPERC )
minperc = INSTANTDEX_MINPERC;
insurance = (satoshis[1] * INSTANTDEX_INSURANCERATE + coinbtc->chain->txfee); // txfee prevents papercut attack
printf("T.%d [%s] got %s.(%s/%s) %.8f vol %.8f %llu offerside.%d offerdir.%d swap.%p decksize.%ld\n",bits256_cmp(traderpub,myinfo->myaddr.persistent),swap!=0?swap->nextstate:"",cmdstr,A->offer.base,A->offer.rel,dstr(A->offer.price64),dstr(A->offer.basevolume64),(long long)A->orderid,A->offer.myside,A->offer.acceptdir,A->info,sizeof(swap->deck));
if ( strcmp(cmdstr,"offer") == 0 && A->info == 0 ) // receiver is networkwide if ( strcmp(cmdstr,"offer") == 0 && A->info == 0 ) // receiver is networkwide
{ {
if ( A->offer.expiration < (time(NULL) + INSTANTDEX_DURATION) ) if ( A->offer.expiration < (time(NULL) + INSTANTDEX_DURATION) )

Loading…
Cancel
Save