Browse Source

test

release/v0.1
jl777 9 years ago
parent
commit
9e5272b118
  1. 4
      iguana/exchanges777.h
  2. 53
      iguana/iguana_instantdex.c
  3. 7
      iguana/swaps/iguana_BTCswap.c

4
iguana/exchanges777.h

@ -22,7 +22,7 @@
#include <curl/easy.h> #include <curl/easy.h>
#endif #endif
#define INSTANTDEX_DECKSIZE 77 #define INSTANTDEX_DECKSIZE 777
#define INSTANTDEX_HOPS 2 #define INSTANTDEX_HOPS 2
#define INSTANTDEX_DURATION 60 #define INSTANTDEX_DURATION 60
@ -179,7 +179,7 @@ double fxcm_price(struct exchange_info *exchange,char *base,char *rel,struct exc
double instaforex_price(struct exchange_info *exchange,char *base,char *rel,struct exchange_quote *bidasks,int32_t maxdepth,double commission,cJSON *argjson,int32_t invert); double instaforex_price(struct exchange_info *exchange,char *base,char *rel,struct exchange_quote *bidasks,int32_t maxdepth,double commission,cJSON *argjson,int32_t invert);
char *instantdex_createaccept(struct supernet_info *myinfo,struct instantdex_accept **aptrp,struct exchange_info *exchange,char *base,char *rel,double price,double basevolume,int32_t acceptdir,char *mysidestr,int32_t duration,uint64_t offerer,int32_t queueflag,uint8_t minperc); char *instantdex_createaccept(struct supernet_info *myinfo,struct instantdex_accept **aptrp,struct exchange_info *exchange,char *base,char *rel,double price,double basevolume,int32_t acceptdir,char *mysidestr,int32_t duration,uint64_t offerer,int32_t queueflag,uint8_t minperc);
char *instantdex_sendcmd(struct supernet_info *myinfo,struct instantdex_offer *offer,cJSON *argjson,char *cmdstr,bits256 desthash,int32_t hops,void *extra,int32_t extralen); char *instantdex_sendcmd(struct supernet_info *myinfo,struct instantdex_offer *offer,cJSON *argjson,char *cmdstr,bits256 desthash,int32_t hops,void *extra,int32_t extralen,int32_t p2pflag);
char *instantdex_sendoffer(struct supernet_info *myinfo,struct exchange_info *exchange,struct instantdex_accept *ap,cJSON *argjson); // Bob sending to network (Alice) char *instantdex_sendoffer(struct supernet_info *myinfo,struct exchange_info *exchange,struct instantdex_accept *ap,cJSON *argjson); // Bob sending to network (Alice)
struct bitcoin_swapinfo *instantdex_statemachinefind(struct supernet_info *myinfo,struct exchange_info *exchange,uint64_t orderid,int32_t requeueflag); struct bitcoin_swapinfo *instantdex_statemachinefind(struct supernet_info *myinfo,struct exchange_info *exchange,uint64_t orderid,int32_t requeueflag);
char *instantdex_checkoffer(struct supernet_info *myinfo,uint64_t *txidp,struct exchange_info *exchange,struct instantdex_accept *ap,cJSON *json); char *instantdex_checkoffer(struct supernet_info *myinfo,uint64_t *txidp,struct exchange_info *exchange,struct instantdex_accept *ap,cJSON *json);

53
iguana/iguana_instantdex.c

@ -318,9 +318,9 @@ bits256 instantdex_rwoffer(int32_t rwflag,int32_t *lenp,uint8_t *serialized,stru
return(orderhash); return(orderhash);
} }
char *instantdex_sendcmd(struct supernet_info *myinfo,struct instantdex_offer *offer,cJSON *argjson,char *cmdstr,bits256 desthash,int32_t hops,void *extraser,int32_t extralen) char *instantdex_sendcmd(struct supernet_info *myinfo,struct instantdex_offer *offer,cJSON *argjson,char *cmdstr,bits256 desthash,int32_t hops,void *extraser,int32_t extralen,int32_t p2pflag)
{ {
char *reqstr; struct instantdex_msghdr *msg; bits256 orderhash; struct iguana_info *coin; struct iguana_peer *addr; int32_t i,j,r,olen,slen,datalen,max=-1; uint8_t serialized[sizeof(*offer) + sizeof(struct iguana_msghdr) + 4096 + INSTANTDEX_DECKSIZE*33]; uint64_t nxt64bits; char *reqstr,*hexstr,*retstr; struct instantdex_msghdr *msg; bits256 orderhash; struct iguana_info *coin; struct iguana_peer *addr; int32_t i,j,r,olen,slen,datalen,max=-1; uint8_t serialized[sizeof(*offer) + sizeof(struct iguana_msghdr) + 4096 + INSTANTDEX_DECKSIZE*33]; uint64_t nxt64bits;
category_subscribe(myinfo,myinfo->instantdex_category,GENESIS_PUBKEY); category_subscribe(myinfo,myinfo->instantdex_category,GENESIS_PUBKEY);
jaddstr(argjson,"cmd",cmdstr); jaddstr(argjson,"cmd",cmdstr);
jaddstr(argjson,"agent","SuperNET"); jaddstr(argjson,"agent","SuperNET");
@ -358,26 +358,33 @@ char *instantdex_sendcmd(struct supernet_info *myinfo,struct instantdex_offer *o
if ( instantdex_msgcreate(myinfo,msg,datalen) != 0 ) if ( instantdex_msgcreate(myinfo,msg,datalen) != 0 )
{ {
printf(">>>>>>>>>>>> instantdex send.(%s) datalen.%d allocsize.%d crc.%x\n",cmdstr,datalen,msg->sig.allocsize,calc_crc32(0,(void *)((long)msg + 8),datalen-8)); printf(">>>>>>>>>>>> instantdex send.(%s) datalen.%d allocsize.%d crc.%x\n",cmdstr,datalen,msg->sig.allocsize,calc_crc32(0,(void *)((long)msg + 8),datalen-8));
//hexstr = malloc(msg->sig.allocsize*2 + 1); if ( p2pflag != 0 )
//init_hexbytes_noT(hexstr,(uint8_t *)msg,msg->sig.allocsize);
//retstr = SuperNET_categorymulticast(myinfo,0,myinfo->instantdex_category,desthash,hexstr,0,hops,1,argjson,0);
memset(serialized,0,sizeof(struct iguana_msghdr));
memcpy(&serialized[sizeof(struct iguana_msghdr)],(uint8_t *)msg,msg->sig.allocsize);
if ( (coin= iguana_coinfind("BTCD")) != 0 && (max= coin->peers.numranked) > 0 )
{ {
r = (rand() % max); memset(serialized,0,sizeof(struct iguana_msghdr));
for (i=0; i<max; i++) memcpy(&serialized[sizeof(struct iguana_msghdr)],(uint8_t *)msg,msg->sig.allocsize);
if ( (coin= iguana_coinfind("BTCD")) != 0 && (max= coin->peers.numranked) > 0 )
{ {
j = (i + r) % max; r = (rand() % max);
if ( (addr= coin->peers.ranked[j]) != 0 && addr->supernet != 0 && addr->usock >= 0 ) for (i=0; i<max; i++)
{ {
printf("send.%d to (%s)\n",(int32_t)msg->sig.allocsize,addr->ipaddr); j = (i + r) % max;
iguana_queue_send(coin,addr,0,serialized,"InstantDEX",msg->sig.allocsize,0,0); if ( (addr= coin->peers.ranked[j]) != 0 && addr->supernet != 0 && addr->usock >= 0 )
if ( --hops <= 0 ) {
break; printf("send.%d to (%s)\n",(int32_t)msg->sig.allocsize,addr->ipaddr);
} //else printf("skip.%d addr.%p (%s) max.%d hops.%d\n",j,addr,addr!=0?addr->ipaddr:"",max,hops); iguana_queue_send(coin,addr,0,serialized,"InstantDEX",msg->sig.allocsize,0,0);
} if ( --hops <= 0 )
} else printf("cant find coin.%p or no ranked.%d\n",coin,max); break;
} //else printf("skip.%d addr.%p (%s) max.%d hops.%d\n",j,addr,addr!=0?addr->ipaddr:"",max,hops);
}
} else printf("cant find coin.%p or no ranked.%d\n",coin,max);
}
else
{
hexstr = malloc(msg->sig.allocsize*2 + 1);
init_hexbytes_noT(hexstr,(uint8_t *)msg,msg->sig.allocsize);
if ( (retstr= SuperNET_categorymulticast(myinfo,0,myinfo->instantdex_category,desthash,hexstr,0,hops,1,argjson,0)) != 0 )
free(retstr);
}
free(msg); //free(hexstr), free(msg); //free(hexstr),
return(jprint(argjson,1)); return(jprint(argjson,1));
} }
@ -1051,7 +1058,7 @@ char *instantdex_checkoffer(struct supernet_info *myinfo,uint64_t *txidp,struct
if ( (otherap= instantdex_acceptable(myinfo,exchange,myap,myap->offer.minperc)) == 0 ) if ( (otherap= instantdex_acceptable(myinfo,exchange,myap,myap->offer.minperc)) == 0 )
{ {
printf("add.%llu to acceptableQ\n",(long long)myap->orderid); printf("add.%llu to acceptableQ\n",(long long)myap->orderid);
if ( (retstr= instantdex_sendcmd(myinfo,&myap->offer,argjson,"BTCoffer",GENESIS_PUBKEY,INSTANTDEX_HOPS,0,0)) != 0 ) if ( (retstr= instantdex_sendcmd(myinfo,&myap->offer,argjson,"BTCoffer",GENESIS_PUBKEY,INSTANTDEX_HOPS,0,0,1)) != 0 )
free(retstr); free(retstr);
queue_enqueue("acceptableQ",&exchange->acceptableQ,&myap->DL,0); queue_enqueue("acceptableQ",&exchange->acceptableQ,&myap->DL,0);
return(jprint(instantdex_offerjson(&myap->offer,myap->orderid),1)); return(jprint(instantdex_offerjson(&myap->offer,myap->orderid),1));
@ -1066,7 +1073,7 @@ char *instantdex_checkoffer(struct supernet_info *myinfo,uint64_t *txidp,struct
queue_enqueue("statemachineQ",&exchange->statemachineQ,&swap->DL,0); queue_enqueue("statemachineQ",&exchange->statemachineQ,&swap->DL,0);
if ( (newjson= instantdex_parseargjson(myinfo,exchange,swap,argjson,1)) == 0 ) if ( (newjson= instantdex_parseargjson(myinfo,exchange,swap,argjson,1)) == 0 )
return(clonestr("{\"error\":\"instantdex_checkoffer null newjson\"}")); return(clonestr("{\"error\":\"instantdex_checkoffer null newjson\"}"));
return(instantdex_sendcmd(myinfo,&swap->mine.offer,newjson,"BTCoffer",GENESIS_PUBKEY,INSTANTDEX_HOPS,swap->deck,sizeof(swap->deck))); return(instantdex_sendcmd(myinfo,&swap->mine.offer,newjson,"BTCoffer",GENESIS_PUBKEY,INSTANTDEX_HOPS,swap->deck,sizeof(swap->deck),1));
} }
return(retstr); return(retstr);
} }
@ -1112,7 +1119,7 @@ char *instantdex_gotoffer(struct supernet_info *myinfo,struct exchange_info *exc
return(retstr); return(retstr);
else else
{ {
return(instantdex_sendcmd(myinfo,&swap->mine.offer,newjson,"BTCdeckC",traderpub,INSTANTDEX_HOPS,swap->deck,sizeof(swap->deck))); return(instantdex_sendcmd(myinfo,&swap->mine.offer,newjson,"BTCdeckC",traderpub,INSTANTDEX_HOPS,swap->deck,sizeof(swap->deck),0));
} }
} }
return(retstr); return(retstr);
@ -1371,7 +1378,7 @@ THREE_STRINGS(atomic,approve,myorderid,otherid,txname)
strcpy(virtualevent,txname); strcpy(virtualevent,txname);
strcat(virtualevent,"found"); strcat(virtualevent,"found");
newjson = cJSON_CreateObject(); newjson = cJSON_CreateObject();
if ( (retstr= instantdex_sendcmd(myinfo,&swap->mine.offer,newjson,virtualevent,myinfo->myaddr.persistent,0,0,0)) != 0 ) if ( (retstr= instantdex_sendcmd(myinfo,&swap->mine.offer,newjson,virtualevent,myinfo->myaddr.persistent,0,0,0,0)) != 0 )
return(retstr); return(retstr);
else return(clonestr("{\"result\":\"statemachine sent found event\"}")); else return(clonestr("{\"result\":\"statemachine sent found event\"}"));
} }

7
iguana/swaps/iguana_BTCswap.c

@ -616,7 +616,7 @@ char *BTC_txconfirmed(struct supernet_info *myinfo,struct iguana_info *coin,stru
if ( (firstvout= iguana_unspentindfind(coin,0,0,0,0,&height,txid,0,coin->bundlescount-1)) != 0 && (confs= iguana_numconfs(coin,txid,height)) >= requiredconfs ) if ( (firstvout= iguana_unspentindfind(coin,0,0,0,0,&height,txid,0,coin->bundlescount-1)) != 0 && (confs= iguana_numconfs(coin,txid,height)) >= requiredconfs )
{ {
*numconfirmsp = confs; *numconfirmsp = confs;
if ( (retstr= instantdex_sendcmd(myinfo,&swap->mine.offer,newjson,virtualevent,myinfo->myaddr.persistent,0,0,0)) != 0 ) if ( (retstr= instantdex_sendcmd(myinfo,&swap->mine.offer,newjson,virtualevent,myinfo->myaddr.persistent,0,0,0,0)) != 0 )
return(retstr); return(retstr);
} }
} }
@ -1010,8 +1010,7 @@ char *instantdex_statemachine(struct instantdex_stateinfo *states,int32_t numsta
free_json(origjson); free_json(origjson);
if ( strcmp("poll",state->events[i].sendcmd) == 0 ) if ( strcmp("poll",state->events[i].sendcmd) == 0 )
{ {
printf("poll event\n"); return(instantdex_sendcmd(myinfo,&swap->mine.offer,newjson,state->events[i].sendcmd,myinfo->myaddr.persistent,0,serdata,serdatalen,0));
return(instantdex_sendcmd(myinfo,&swap->mine.offer,newjson,state->events[i].sendcmd,myinfo->myaddr.persistent,0,serdata,serdatalen));
} }
else else
{ {
@ -1027,7 +1026,7 @@ char *instantdex_statemachine(struct instantdex_stateinfo *states,int32_t numsta
if ( state->events[i].nextstateind > 1 ) if ( state->events[i].nextstateind > 1 )
{ {
swap->state = &states[state->events[i].nextstateind]; swap->state = &states[state->events[i].nextstateind];
return(instantdex_sendcmd(myinfo,&swap->mine.offer,newjson,state->events[i].sendcmd,swap->othertrader,INSTANTDEX_HOPS,serdata,serdatalen)); return(instantdex_sendcmd(myinfo,&swap->mine.offer,newjson,state->events[i].sendcmd,swap->othertrader,INSTANTDEX_HOPS,serdata,serdatalen,0));
} else return(clonestr("{\"error\":\"instantdex_statemachine: illegal state\"}")); } else return(clonestr("{\"error\":\"instantdex_statemachine: illegal state\"}"));
} else return(clonestr("{\"result\":\"instantdex_statemachine: processed\"}")); } else return(clonestr("{\"result\":\"instantdex_statemachine: processed\"}"));
} }

Loading…
Cancel
Save