Browse Source

test

release/v0.1
jl777 9 years ago
parent
commit
276bb45c3e
  1. 2
      iguana/SuperNET.h
  2. 6
      iguana/SuperNET_category.c
  3. 7
      iguana/SuperNET_hexmsg.c
  4. 2
      iguana/exchanges/bitcoin.c
  5. 4
      iguana/exchanges777.h
  6. 3
      iguana/iguana_exchanges.c
  7. 18
      iguana/iguana_instantdex.c
  8. 38
      iguana/swaps/iguana_BTCswap.c

2
iguana/SuperNET.h

@ -153,7 +153,7 @@ void *category_info(bits256 categoryhash,bits256 subhash);
void *category_infoset(bits256 categoryhash,bits256 subhash,void *info); void *category_infoset(bits256 categoryhash,bits256 subhash,void *info);
struct category_info *category_find(bits256 categoryhash,bits256 subhash); struct category_info *category_find(bits256 categoryhash,bits256 subhash);
void SuperNET_hexmsgprocess(struct supernet_info *myinfo,cJSON *retjson,cJSON *json,char *hexmsg,char *remoteaddr); void SuperNET_hexmsgprocess(struct supernet_info *myinfo,cJSON *retjson,cJSON *json,char *hexmsg,char *remoteaddr);
struct category_info *category_processfunc(bits256 categoryhash,char *(*process_func)(struct supernet_info *myinfo,void *data,int32_t datalen,char *remoteaddr)); struct category_info *category_processfunc(bits256 categoryhash,bits256 subhash,char *(*process_func)(struct supernet_info *myinfo,void *data,int32_t datalen,char *remoteaddr));
char *pangea_hexmsg(struct supernet_info *myinfo,void *data,int32_t len,char *remoteaddr); char *pangea_hexmsg(struct supernet_info *myinfo,void *data,int32_t len,char *remoteaddr);
void pangea_queues(struct supernet_info *myinfo); void pangea_queues(struct supernet_info *myinfo);

6
iguana/SuperNET_category.c

@ -74,10 +74,10 @@ void *category_infoset(bits256 categoryhash,bits256 subhash,void *info)
return(0); return(0);
} }
struct category_info *category_processfunc(bits256 categoryhash,char *(*process_func)(struct supernet_info *myinfo,void *data,int32_t datalen,char *remoteaddr)) struct category_info *category_processfunc(bits256 categoryhash,bits256 subhash,char *(*process_func)(struct supernet_info *myinfo,void *data,int32_t datalen,char *remoteaddr))
{ {
struct category_info *cat; struct category_info *cat;
if ( (cat= category_find(categoryhash,GENESIS_PUBKEY)) != 0 ) if ( (cat= category_find(categoryhash,subhash)) != 0 )
{ {
cat->processfunc = process_func; cat->processfunc = process_func;
return(cat); return(cat);
@ -344,7 +344,7 @@ void category_init(struct supernet_info *myinfo)
category_subscribe(myinfo,GENESIS_PUBKEY,GENESIS_PUBKEY); category_subscribe(myinfo,GENESIS_PUBKEY,GENESIS_PUBKEY);
pangeahash = calc_categoryhashes(0,"pangea",0); pangeahash = calc_categoryhashes(0,"pangea",0);
category_subscribe(myinfo,pangeahash,GENESIS_PUBKEY); category_subscribe(myinfo,pangeahash,GENESIS_PUBKEY);
category_processfunc(pangeahash,pangea_hexmsg); category_processfunc(pangeahash,GENESIS_PUBKEY,pangea_hexmsg);
category_chain_functions(myinfo,pangeahash,GENESIS_PUBKEY,sizeof(bits256),sizeof(bits256),0,0,0,0); category_chain_functions(myinfo,pangeahash,GENESIS_PUBKEY,sizeof(bits256),sizeof(bits256),0,0,0,0);
exchanges777_init(myinfo,0,0); exchanges777_init(myinfo,0,0);
} }

7
iguana/SuperNET_hexmsg.c

@ -75,7 +75,7 @@ void SuperNET_hexmsgadd(struct supernet_info *myinfo,bits256 categoryhash,bits25
void SuperNET_hexmsgprocess(struct supernet_info *myinfo,cJSON *retjson,cJSON *json,char *hexmsg,char *remoteaddr) void SuperNET_hexmsgprocess(struct supernet_info *myinfo,cJSON *retjson,cJSON *json,char *hexmsg,char *remoteaddr)
{ {
int32_t len,flag=0; char *str; uint8_t _buf[8192],*buf = _buf; bits256 categoryhash; struct category_info *cat; int32_t len,flag=0; char *str; uint8_t _buf[8192],*buf = _buf; bits256 categoryhash,subhash; struct category_info *cat;
if ( hexmsg != 0 ) if ( hexmsg != 0 )
{ {
len = (int32_t)strlen(hexmsg); len = (int32_t)strlen(hexmsg);
@ -86,7 +86,10 @@ void SuperNET_hexmsgprocess(struct supernet_info *myinfo,cJSON *retjson,cJSON *j
buf = malloc(len); buf = malloc(len);
decode_hex(buf,len,hexmsg); decode_hex(buf,len,hexmsg);
categoryhash = jbits256(json,"categoryhash"); categoryhash = jbits256(json,"categoryhash");
if ( (cat= category_find(categoryhash,GENESIS_PUBKEY)) != 0 ) subhash = jbits256(json,"categoryhash");
if ( bits256_nonz(subhash) == 0 )
subhash = GENESIS_PUBKEY;
if ( (cat= category_find(categoryhash,subhash)) != 0 )
{ {
if ( cat->processfunc != 0 ) if ( cat->processfunc != 0 )
{ {

2
iguana/exchanges/bitcoin.c

@ -1537,7 +1537,7 @@ uint64_t TRADE(int32_t dotrade,char **retstrp,struct exchange_info *exchange,cha
jaddnum(json,"volume",volume); jaddnum(json,"volume",volume);
jaddstr(json,"BTC",myinfo->myaddr.BTC); jaddstr(json,"BTC",myinfo->myaddr.BTC);
//printf("trade dir.%d (%s/%s) %.6f vol %.8f\n",dir,base,"BTC",price,volume); //printf("trade dir.%d (%s/%s) %.6f vol %.8f\n",dir,base,"BTC",price,volume);
if ( (str= instantdex_sendcmd(myinfo,json,"BTCoffer",myinfo->ipaddr,hops)) != 0 ) if ( (str= instantdex_sendcmd(myinfo,json,"BTCoffer",GENESIS_PUBKEY,hops)) != 0 )
{ {
json = cJSON_CreateObject(); json = cJSON_CreateObject();
jaddstr(json,"BTCoffer",str); jaddstr(json,"BTCoffer",str);

4
iguana/exchanges777.h

@ -95,10 +95,10 @@ struct instantdex_accept { struct queueitem DL; void *info; uint64_t pendingvolu
struct instantdex_accept *instantdex_acceptablefind(struct supernet_info *myinfo,struct exchange_info *exchange,cJSON *bids,cJSON *asks,uint64_t orderid,char *base,char *rel); struct instantdex_accept *instantdex_acceptablefind(struct supernet_info *myinfo,struct exchange_info *exchange,cJSON *bids,cJSON *asks,uint64_t orderid,char *base,char *rel);
cJSON *instantdex_acceptjson(struct instantdex_accept *ap); cJSON *instantdex_acceptjson(struct instantdex_accept *ap);
struct instantdex_accept *instantdex_acceptable(struct supernet_info *myinfo,struct exchange_info *exchange,struct instantdex_accept *A,uint64_t offerbits); struct instantdex_accept *instantdex_acceptable(struct supernet_info *myinfo,struct exchange_info *exchange,struct instantdex_accept *A,uint64_t offerbits,double minperc);
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);
char *instantdex_sendcmd(struct supernet_info *myinfo,cJSON *argjson,char *cmdstr,char *ipaddr,int32_t hops); char *instantdex_sendcmd(struct supernet_info *myinfo,cJSON *argjson,char *cmdstr,bits256 desttrader,int32_t hops);
char *exchanges777_Qprices(struct exchange_info *exchange,char *base,char *rel,int32_t maxseconds,int32_t allfields,int32_t depth,cJSON *argjson,int32_t monitor,double commission); char *exchanges777_Qprices(struct exchange_info *exchange,char *base,char *rel,int32_t maxseconds,int32_t allfields,int32_t depth,cJSON *argjson,int32_t monitor,double commission);
struct exchange_info *exchanges777_info(char *exchangestr,int32_t sleepflag,cJSON *json,char *remoteaddr); struct exchange_info *exchanges777_info(char *exchangestr,int32_t sleepflag,cJSON *json,char *remoteaddr);
char *exchanges777_unmonitor(struct exchange_info *exchange,char *base,char *rel); char *exchanges777_unmonitor(struct exchange_info *exchange,char *base,char *rel);

3
iguana/iguana_exchanges.c

@ -951,7 +951,8 @@ void exchanges777_init(struct supernet_info *myinfo,cJSON *exchanges,int32_t sle
instantdexhash = calc_categoryhashes(0,"InstantDEX",0); instantdexhash = calc_categoryhashes(0,"InstantDEX",0);
printf("InstantDEX:\n"); printf("InstantDEX:\n");
category_subscribe(myinfo,instantdexhash,GENESIS_PUBKEY); category_subscribe(myinfo,instantdexhash,GENESIS_PUBKEY);
category_processfunc(instantdexhash,InstantDEX_hexmsg); category_processfunc(instantdexhash,GENESIS_PUBKEY,InstantDEX_hexmsg);
category_processfunc(instantdexhash,myinfo->myaddr.persistent,InstantDEX_hexmsg);
} }
#include "../includes/iguana_apidefs.h" #include "../includes/iguana_apidefs.h"

18
iguana/iguana_instantdex.c

@ -80,14 +80,12 @@ struct instantdex_msghdr *instantdex_msgcreate(struct supernet_info *myinfo,stru
return(0); return(0);
} }
char *instantdex_sendcmd(struct supernet_info *myinfo,cJSON *argjson,char *cmdstr,char *ipaddr,int32_t hops) char *instantdex_sendcmd(struct supernet_info *myinfo,cJSON *argjson,char *cmdstr,bits256 desthash,int32_t hops)
{ {
char *reqstr,*hexstr,*retstr; uint64_t nxt64bits; int32_t i,datalen; char *reqstr,*hexstr,*retstr; uint64_t nxt64bits; int32_t i,datalen;
bits256 instantdexhash; struct instantdex_msghdr *msg; bits256 instantdexhash; struct instantdex_msghdr *msg;
instantdexhash = calc_categoryhashes(0,"InstantDEX",0); instantdexhash = calc_categoryhashes(0,"InstantDEX",0);
category_subscribe(myinfo,instantdexhash,GENESIS_PUBKEY); category_subscribe(myinfo,instantdexhash,GENESIS_PUBKEY);
//if ( ipaddr == 0 || ipaddr[0] == 0 || strncmp(ipaddr,"127.0.0.1",strlen("127.0.0.1")) == 0 )
// return(clonestr("{\"error\":\"no ipaddr, need to send your ipaddr for now\"}"));
jaddstr(argjson,"cmd",cmdstr); jaddstr(argjson,"cmd",cmdstr);
jaddstr(argjson,"agent","SuperNET"); jaddstr(argjson,"agent","SuperNET");
jaddstr(argjson,"method","DHT"); jaddstr(argjson,"method","DHT");
@ -105,10 +103,10 @@ char *instantdex_sendcmd(struct supernet_info *myinfo,cJSON *argjson,char *cmdst
free(reqstr); free(reqstr);
if ( instantdex_msgcreate(myinfo,msg,datalen) != 0 ) if ( instantdex_msgcreate(myinfo,msg,datalen) != 0 )
{ {
//printf("instantdex send.(%s)\n",jprint(argjson,0)); printf("instantdex send.(%s)\n",cmdstr);
hexstr = malloc(msg->sig.allocsize*2 + 1); hexstr = malloc(msg->sig.allocsize*2 + 1);
init_hexbytes_noT(hexstr,(uint8_t *)msg,msg->sig.allocsize); init_hexbytes_noT(hexstr,(uint8_t *)msg,msg->sig.allocsize);
retstr = SuperNET_categorymulticast(myinfo,0,instantdexhash,GENESIS_PUBKEY,hexstr,0,hops,1,argjson,0); retstr = SuperNET_categorymulticast(myinfo,0,instantdexhash,desthash,hexstr,0,hops,1,argjson,0);
free_json(argjson); free_json(argjson);
free(hexstr); free(hexstr);
free(msg); free(msg);
@ -281,20 +279,21 @@ struct instantdex_accept *instantdex_acceptablefind(struct supernet_info *myinfo
return(retap); return(retap);
} }
struct instantdex_accept *instantdex_acceptable(struct supernet_info *myinfo,struct exchange_info *exchange,struct instantdex_accept *A,uint64_t offerbits) struct instantdex_accept *instantdex_acceptable(struct supernet_info *myinfo,struct exchange_info *exchange,struct instantdex_accept *A,uint64_t offerbits,double minperc)
{ {
struct instantdex_accept PAD,*ap,*retap = 0; uint64_t bestprice64 = 0; struct instantdex_accept PAD,*ap,*retap = 0; uint64_t minvol,bestprice64 = 0;
uint32_t now; int32_t offerdir; uint32_t now; int32_t offerdir;
now = (uint32_t)time(NULL); now = (uint32_t)time(NULL);
memset(&PAD,0,sizeof(PAD)); memset(&PAD,0,sizeof(PAD));
queue_enqueue("acceptableQ",&exchange->acceptableQ,&PAD.DL,0); queue_enqueue("acceptableQ",&exchange->acceptableQ,&PAD.DL,0);
offerdir = instantdex_bidaskdir(A); offerdir = instantdex_bidaskdir(A);
minvol = A->A.basevolume64 * minperc * .01;
while ( (ap= queue_dequeue(&exchange->acceptableQ,0)) != 0 && ap != &PAD ) while ( (ap= queue_dequeue(&exchange->acceptableQ,0)) != 0 && ap != &PAD )
{ {
if ( now < ap->A.expiration && ap->dead == 0 && (offerbits == 0 || offerbits != ap->A.offer64) ) if ( now < ap->A.expiration && ap->dead == 0 && (offerbits == 0 || offerbits != ap->A.offer64) )
{ {
printf("check offerbits.%llu vs %llu: %d %d %d %d %d %d %d %d\n",(long long)offerbits,(long long)ap->A.offer64,A->A.basevolume64 > 0.,strcmp(A->A.base,"*") == 0 ,strcmp(A->A.base,ap->A.base) == 0, strcmp(A->A.rel,"*") == 0 ,strcmp(A->A.rel,ap->A.rel) == 0,A->A.basevolume64 <= (ap->A.basevolume64 - ap->pendingvolume64),offerdir,instantdex_bidaskdir(ap)); printf("check offerbits.%llu vs %llu: %d %d %d %d %d %d %d %d\n",(long long)offerbits,(long long)ap->A.offer64,A->A.basevolume64 > 0.,strcmp(A->A.base,"*") == 0 ,strcmp(A->A.base,ap->A.base) == 0, strcmp(A->A.rel,"*") == 0 ,strcmp(A->A.rel,ap->A.rel) == 0,A->A.basevolume64 <= (ap->A.basevolume64 - ap->pendingvolume64),offerdir,instantdex_bidaskdir(ap));
if ( A->A.basevolume64 > 0. && (strcmp(A->A.base,"*") == 0 || strcmp(A->A.base,ap->A.base) == 0) && (strcmp(A->A.rel,"*") == 0 || strcmp(A->A.rel,ap->A.rel) == 0) && A->A.basevolume64 <= (ap->A.basevolume64 - ap->pendingvolume64) && offerdir*instantdex_bidaskdir(ap) < 0 ) if ( A->A.basevolume64 > 0. && (strcmp(A->A.base,"*") == 0 || strcmp(A->A.base,ap->A.base) == 0) && (strcmp(A->A.rel,"*") == 0 || strcmp(A->A.rel,ap->A.rel) == 0) && minvol <= (ap->A.basevolume64 - ap->pendingvolume64) && offerdir*instantdex_bidaskdir(ap) < 0 )
{ {
printf("passed first cmp: %d %d %d %d\n",offerdir == 0,A->A.price64 == 0,(offerdir > 0 && ap->A.price64 >= A->A.price64),(offerdir < 0 && ap->A.price64 <= A->A.price64)); printf("passed first cmp: %d %d %d %d\n",offerdir == 0,A->A.price64 == 0,(offerdir > 0 && ap->A.price64 >= A->A.price64),(offerdir < 0 && ap->A.price64 <= A->A.price64));
if ( offerdir == 0 || A->A.price64 == 0 || ((offerdir > 0 && ap->A.price64 >= A->A.price64) || (offerdir < 0 && ap->A.price64 <= A->A.price64)) ) if ( offerdir == 0 || A->A.price64 == 0 || ((offerdir > 0 && ap->A.price64 >= A->A.price64) || (offerdir < 0 && ap->A.price64 <= A->A.price64)) )
@ -349,8 +348,7 @@ bits256 instantdex_acceptset(struct instantdex_accept *ap,char *base,char *rel,i
int32_t instantdex_acceptextract(struct instantdex_accept *ap,cJSON *argjson) int32_t instantdex_acceptextract(struct instantdex_accept *ap,cJSON *argjson)
{ {
char *base,*rel; bits256 hash,traderpub; double price,volume; int32_t baserel,acceptdir,num; char *base,*rel; bits256 hash,traderpub; double price,volume; int32_t baserel,acceptdir;
struct supernet_info *myinfo;
memset(ap,0,sizeof(*ap)); memset(ap,0,sizeof(*ap));
if ( (base= jstr(argjson,"base")) != 0 ) if ( (base= jstr(argjson,"base")) != 0 )
{ {

38
iguana/swaps/iguana_BTCswap.c

@ -29,10 +29,11 @@ Tier Nolan's approach is followed with the following changes:
#define TIERNOLAN_RMD160 "daedddd8dbe7a2439841ced40ba9c3d375f98146" #define TIERNOLAN_RMD160 "daedddd8dbe7a2439841ced40ba9c3d375f98146"
#define INSTANTDEX_BTC "1KRhTPvoxyJmVALwHFXZdeeWFbcJSbkFPu" #define INSTANTDEX_BTC "1KRhTPvoxyJmVALwHFXZdeeWFbcJSbkFPu"
#define INSTANTDEX_BTCD "RThtXup6Zo7LZAi8kRWgjAyi1s4u6U9Cpf" #define INSTANTDEX_BTCD "RThtXup6Zo7LZAi8kRWgjAyi1s4u6U9Cpf"
#define INSTANTDEX_MINPERC 50.
struct bitcoin_swapinfo struct bitcoin_swapinfo
{ {
bits256 privkeys[777],mypubs[2],otherpubs[2],pubBn,pubAm,dtxid,ptxid,aptxid,astxid,stxid,ftxid; bits256 privkeys[777],mypubs[2],otherpubs[2],pubBn,pubAm,dtxid,ptxid,aptxid,astxid,stxid,ftxid,othertrader;
uint64_t otherscut[777][2]; uint64_t otherscut[777][2];
int32_t isbob,choosei,otherschoosei,state,cutverified,otherverifiedcut; int32_t isbob,choosei,otherschoosei,state,cutverified,otherverifiedcut;
char altmsigaddr[64],*deposit,*payment,*altpayment,*altspend,*spendtx,*feetx; char altmsigaddr[64],*deposit,*payment,*altpayment,*altspend,*spendtx,*feetx;
@ -478,6 +479,7 @@ char *instantdex_btcoffer(struct supernet_info *myinfo,struct exchange_info *exc
{ {
swap->state++; swap->state++;
ap->info = swap; ap->info = swap;
printf(">>>>>>>>>> PENDING ORDER %llu\n",(long long)A.orderid);
} }
} }
if ( ap == 0 ) if ( ap == 0 )
@ -485,13 +487,13 @@ char *instantdex_btcoffer(struct supernet_info *myinfo,struct exchange_info *exc
printf("couldnt find accept??\n"); printf("couldnt find accept??\n");
free(swap); free(swap);
return(clonestr("{\"error\":\"couldnt find order just created\"}")); return(clonestr("{\"error\":\"couldnt find order just created\"}"));
} else return(instantdex_sendcmd(myinfo,newjson,"BTCoffer",myinfo->ipaddr,INSTANTDEX_HOPS)); } else return(instantdex_sendcmd(myinfo,newjson,"BTCoffer",GENESIS_PUBKEY,INSTANTDEX_HOPS));
} }
char *instantdex_BTCswap(struct supernet_info *myinfo,struct exchange_info *exchange,struct instantdex_accept *A,char *cmdstr,struct instantdex_msghdr *msg,cJSON *argjson,char *remoteaddr,uint64_t signerbits,uint8_t *data,int32_t datalen) // receiving side char *instantdex_BTCswap(struct supernet_info *myinfo,struct exchange_info *exchange,struct instantdex_accept *A,char *cmdstr,struct instantdex_msghdr *msg,cJSON *argjson,char *remoteaddr,uint64_t signerbits,uint8_t *data,int32_t datalen) // receiving side
{ {
char *retstr=0; uint64_t satoshis[2]; int32_t reftime,offerdir = 0; char *retstr=0; uint64_t satoshis[2]; int32_t reftime,offerdir = 0; double minperc;
struct instantdex_accept *ap; struct bitcoin_swapinfo *swap = 0; bits256 hash; struct instantdex_accept *ap; struct bitcoin_swapinfo *swap = 0; bits256 hash,traderpub;
struct iguana_info *coinbtc,*altcoin; cJSON *newjson=0; uint8_t pubkey[33]; struct iguana_info *coinbtc,*altcoin; cJSON *newjson=0; uint8_t pubkey[33];
if ( exchange == 0 ) if ( exchange == 0 )
return(clonestr("{\"error\":\"instantdex_BTCswap null exchange ptr\"}")); return(clonestr("{\"error\":\"instantdex_BTCswap null exchange ptr\"}"));
@ -511,6 +513,8 @@ char *instantdex_BTCswap(struct supernet_info *myinfo,struct exchange_info *exch
satoshis[0] = A->A.basevolume64; satoshis[0] = A->A.basevolume64;
satoshis[1] = instantdex_relsatoshis(A->A.price64,A->A.basevolume64); satoshis[1] = instantdex_relsatoshis(A->A.price64,A->A.basevolume64);
swap = A->info; swap = A->info;
if ( (minperc= jdouble(argjson,"p")) < INSTANTDEX_MINPERC )
minperc = INSTANTDEX_MINPERC;
if ( swap == 0 && strcmp(cmdstr,"offer") != 0 ) if ( swap == 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\"}"));
printf("got offer.(%s) offerside.%d offerdir.%d swap.%p\n",jprint(argjson,0),A->A.myside,A->A.acceptdir,A->info); printf("got offer.(%s) offerside.%d offerdir.%d swap.%p\n",jprint(argjson,0),A->A.myside,A->A.acceptdir,A->info);
@ -518,14 +522,16 @@ char *instantdex_BTCswap(struct supernet_info *myinfo,struct exchange_info *exch
{ {
if ( A->A.expiration < (time(NULL) + INSTANTDEX_DURATION) ) if ( A->A.expiration < (time(NULL) + INSTANTDEX_DURATION) )
return(clonestr("{\"error\":\"instantdex_BTCswap offer too close to expiration\"}")); return(clonestr("{\"error\":\"instantdex_BTCswap offer too close to expiration\"}"));
if ( (ap= instantdex_acceptable(myinfo,exchange,A,myinfo->myaddr.nxt64bits)) != 0 ) if ( (ap= instantdex_acceptable(myinfo,exchange,A,myinfo->myaddr.nxt64bits,minperc)) != 0 )
{ {
printf("FOUND MATCH! %p (%s/%s)\n",A->info,A->A.base,A->A.rel); traderpub = jbits256(argjson,"traderpub");
char str[65]; printf("FOUND MATCH! %p (%s/%s) other.%s\n",A->info,A->A.base,A->A.rel,bits256_str(str,traderpub));
if ( A->info == 0 ) if ( A->info == 0 )
{ {
swap = calloc(1,sizeof(struct bitcoin_swapinfo)); swap = calloc(1,sizeof(struct bitcoin_swapinfo));
swap->choosei = swap->otherschoosei = -1; swap->choosei = swap->otherschoosei = -1;
swap->state++; swap->state++;
swap->othertrader = traderpub;
} }
if ( (A->info= swap) != 0 ) if ( (A->info= swap) != 0 )
{ {
@ -540,7 +546,7 @@ char *instantdex_BTCswap(struct supernet_info *myinfo,struct exchange_info *exch
printf("Choosei.%s\n",retstr); printf("Choosei.%s\n",retstr);
return(retstr); return(retstr);
} }
else return(instantdex_sendcmd(myinfo,newjson,"BTCstep1",myinfo->ipaddr,INSTANTDEX_HOPS)); else return(instantdex_sendcmd(myinfo,newjson,"BTCstep1",traderpub,INSTANTDEX_HOPS));
} }
} }
} }
@ -572,7 +578,7 @@ char *instantdex_BTCswap(struct supernet_info *myinfo,struct exchange_info *exch
// broadcast to network // broadcast to network
} }
} }
return(instantdex_sendcmd(myinfo,newjson,swap->isbob != 0 ? "BTCstep1" : "BTCstep2",myinfo->ipaddr,INSTANTDEX_HOPS)); return(instantdex_sendcmd(myinfo,newjson,swap->isbob != 0 ? "BTCstep1" : "BTCstep2",swap->othertrader,INSTANTDEX_HOPS));
} }
} }
else if ( strcmp(cmdstr,"step2") == 0 && swap->isbob != 0 && swap->state == 2 ) // Bob else if ( strcmp(cmdstr,"step2") == 0 && swap->isbob != 0 && swap->state == 2 ) // Bob
@ -592,7 +598,7 @@ char *instantdex_BTCswap(struct supernet_info *myinfo,struct exchange_info *exch
jaddbits256(newjson,"dtxid",swap->dtxid); jaddbits256(newjson,"dtxid",swap->dtxid);
jaddbits256(newjson,"pubBn",bitcoin_pubkey33(pubkey,swap->privkeys[swap->otherschoosei])); jaddbits256(newjson,"pubBn",bitcoin_pubkey33(pubkey,swap->privkeys[swap->otherschoosei]));
// broadcast to network // broadcast to network
return(instantdex_sendcmd(myinfo,newjson,"BTCstep3",myinfo->ipaddr,INSTANTDEX_HOPS)); return(instantdex_sendcmd(myinfo,newjson,"BTCstep3",swap->othertrader,INSTANTDEX_HOPS));
} else return(clonestr("{\"error\":\"instantdex_BTCswap Bob step2, cant create deposit\"}")); } else return(clonestr("{\"error\":\"instantdex_BTCswap Bob step2, cant create deposit\"}"));
} //else return(clonestr("{\"error\":\"instantdex_BTCswap step2 invalid fee\"}")); } //else return(clonestr("{\"error\":\"instantdex_BTCswap step2 invalid fee\"}"));
} }
@ -615,7 +621,7 @@ char *instantdex_BTCswap(struct supernet_info *myinfo,struct exchange_info *exch
jaddbits256(newjson,"aptxid",swap->aptxid); jaddbits256(newjson,"aptxid",swap->aptxid);
jaddbits256(newjson,"pubAm",swap->pubAm); jaddbits256(newjson,"pubAm",swap->pubAm);
// broadcast to network // broadcast to network
return(instantdex_sendcmd(myinfo,newjson,"BTCstep4",myinfo->ipaddr,INSTANTDEX_HOPS)); return(instantdex_sendcmd(myinfo,newjson,"BTCstep4",swap->othertrader,INSTANTDEX_HOPS));
} else return(clonestr("{\"error\":\"instantdex_BTCswap Alice step3, error making altpay\"}")); } else return(clonestr("{\"error\":\"instantdex_BTCswap Alice step3, error making altpay\"}"));
} else return(clonestr("{\"error\":\"instantdex_BTCswap Alice step3, invalid deposit\"}")); } else return(clonestr("{\"error\":\"instantdex_BTCswap Alice step3, invalid deposit\"}"));
} }
@ -634,7 +640,7 @@ char *instantdex_BTCswap(struct supernet_info *myinfo,struct exchange_info *exch
jaddstr(newjson,"payment",swap->payment); jaddstr(newjson,"payment",swap->payment);
jaddbits256(newjson,"ptxid",swap->ptxid); jaddbits256(newjson,"ptxid",swap->ptxid);
// broadcast to network // broadcast to network
return(instantdex_sendcmd(myinfo,newjson,"BTCstep5",myinfo->ipaddr,INSTANTDEX_HOPS)); return(instantdex_sendcmd(myinfo,newjson,"BTCstep5",swap->othertrader,INSTANTDEX_HOPS));
} else return(clonestr("{\"error\":\"instantdex_BTCswap Bob step4, cant create payment\"}")); } else return(clonestr("{\"error\":\"instantdex_BTCswap Bob step4, cant create payment\"}"));
} else return(clonestr("{\"error\":\"instantdex_BTCswap Alice step3, invalid deposit\"}")); } else return(clonestr("{\"error\":\"instantdex_BTCswap Alice step3, invalid deposit\"}"));
} }
@ -649,7 +655,7 @@ char *instantdex_BTCswap(struct supernet_info *myinfo,struct exchange_info *exch
/*if ( (swap->spendtx= instantdex_spendpayment(myinfo,coinbtc,&swap->stxid,swap,argjson,newjson)) != 0 ) /*if ( (swap->spendtx= instantdex_spendpayment(myinfo,coinbtc,&swap->stxid,swap,argjson,newjson)) != 0 )
{ {
// broadcast to network // broadcast to network
return(instantdex_sendcmd(myinfo,newjson,"BTCstep6",myinfo->ipaddr,INSTANTDEX_HOPS)); return(instantdex_sendcmd(myinfo,newjson,"BTCstep6",swap->othertrader,INSTANTDEX_HOPS));
} else return(clonestr("{\"error\":\"instantdex_BTCswap Alice step5, cant spend payment\"}"));*/ } else return(clonestr("{\"error\":\"instantdex_BTCswap Alice step5, cant spend payment\"}"));*/
} else return(clonestr("{\"error\":\"instantdex_BTCswap Bob step6, invalid payment\"}")); } else return(clonestr("{\"error\":\"instantdex_BTCswap Bob step6, invalid payment\"}"));
} }
@ -843,7 +849,7 @@ char *instantdex_bailinrefund(struct supernet_info *myinfo,struct iguana_info *c
sprintf(field,"bailintx%c",'A'+isbob), jaddbits256(A->statusjson,field,bailintxid); sprintf(field,"bailintx%c",'A'+isbob), jaddbits256(A->statusjson,field,bailintxid);
sprintf(field,"bailintxid%c",'A'+isbob), jaddbits256(newjson,field,bailintxid); sprintf(field,"bailintxid%c",'A'+isbob), jaddbits256(newjson,field,bailintxid);
free(spend); free(spend);
return(instantdex_sendcmd(myinfo,newjson,nextcmd,myinfo->ipaddr,INSTANTDEX_HOPS)); return(instantdex_sendcmd(myinfo,newjson,nextcmd,swap->othertrader,INSTANTDEX_HOPS));
} else return(clonestr("{\"error\":\"couldnt create bailintx\"}")); } else return(clonestr("{\"error\":\"couldnt create bailintx\"}"));
} else return(clonestr("{\"error\":\"dont have pubkey0 pair\"}")); } else return(clonestr("{\"error\":\"dont have pubkey0 pair\"}"));
} }
@ -875,7 +881,7 @@ char *instantdex_advance(struct supernet_info *myinfo,bits256 *sharedprivs,int32
{ {
jaddstr(newjson,addfield,jstr(A->statusjson,addfield)); jaddstr(newjson,addfield,jstr(A->statusjson,addfield));
if ( nextstate != 0 ) if ( nextstate != 0 )
return(instantdex_sendcmd(myinfo,newjson,nextstate,myinfo->ipaddr,INSTANTDEX_HOPS)); return(instantdex_sendcmd(myinfo,newjson,nextstate,swap->othertrader,INSTANTDEX_HOPS));
else return(clonestr("{\"result\":\"instantdex_BTCswap advance complete, wait or refund\"}")); else return(clonestr("{\"result\":\"instantdex_BTCswap advance complete, wait or refund\"}"));
} else return(clonestr("{\"error\":\"instantdex_BTCswap advance cant find statusjson\"}")); } else return(clonestr("{\"error\":\"instantdex_BTCswap advance cant find statusjson\"}"));
} }
@ -935,13 +941,13 @@ char *instantdex_BTCswap(struct supernet_info *myinfo,struct exchange_info *exch
{ {
isbob = 0; isbob = 0;
newjson = instantdex_payout(myinfo,other,exchange,A,secret160,isbob,&A0,&B0,sharedprivs,hash,satoshis,argjson); newjson = instantdex_payout(myinfo,other,exchange,A,secret160,isbob,&A0,&B0,sharedprivs,hash,satoshis,argjson);
return(instantdex_sendcmd(myinfo,newjson,"BTCconfirm",myinfo->ipaddr,INSTANTDEX_HOPS)); return(instantdex_sendcmd(myinfo,newjson,"BTCconfirm",swap->othertrader,INSTANTDEX_HOPS));
} }
else if ( strcmp(cmdstr,"confirm") == 0 ) // sender is Alice, receiver is Bob else if ( strcmp(cmdstr,"confirm") == 0 ) // sender is Alice, receiver is Bob
{ {
isbob = 1; isbob = 1;
newjson = instantdex_payout(myinfo,coinbtc,exchange,A,secret160,isbob,&A0,&B0,sharedprivs,hash,satoshis,argjson); newjson = instantdex_payout(myinfo,coinbtc,exchange,A,secret160,isbob,&A0,&B0,sharedprivs,hash,satoshis,argjson);
return(instantdex_sendcmd(myinfo,newjson,"BTCbroadcast",myinfo->ipaddr,INSTANTDEX_HOPS)); return(instantdex_sendcmd(myinfo,newjson,"BTCbroadcast",swap->othertrader,INSTANTDEX_HOPS));
} }
else if ( strcmp(cmdstr,"broadcast") == 0 ) // sender is Bob, receiver is Alice else if ( strcmp(cmdstr,"broadcast") == 0 ) // sender is Bob, receiver is Alice
{ {

Loading…
Cancel
Save