Browse Source

test

release/v0.1
jl777 9 years ago
parent
commit
8718b358c0
  1. 2
      iguana/exchanges777.h
  2. 8
      iguana/iguana777.c
  3. 19
      iguana/iguana_instantdex.c
  4. 9
      iguana/swaps/iguana_BTCswap.c

2
iguana/exchanges777.h

@ -200,7 +200,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);
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,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,struct iguana_peer *addr);
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,struct iguana_peer *addr,struct bitcoin_swapinfo *swap);
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);
char *instantdex_checkoffer(struct supernet_info *myinfo,int32_t *addedp,uint64_t *txidp,struct exchange_info *exchange,struct instantdex_accept *ap,cJSON *json);

8
iguana/iguana777.c

@ -561,10 +561,18 @@ int32_t iguana_utxogen(struct iguana_info *coin,int32_t helperid,int32_t convert
void iguana_helper(void *arg)
{
static int32_t maxhelperid;
cJSON *argjson=0; int32_t iter,i,n,j,polltimeout,type,helperid=rand(),flag,allcurrent,idle=0;
struct iguana_helper *ptr; struct iguana_info *coin; struct OS_memspace MEM,*MEMB; struct iguana_bundle *bp;
if ( arg != 0 && (argjson= cJSON_Parse(arg)) != 0 )
helperid = juint(argjson,"helperid");
if ( helperid > maxhelperid )
maxhelperid = helperid;
if ( helperid < maxhelperid )
{
printf("SKIP duplicate helper.%d\n",helperid);
return;
}
if ( IGUANA_NUMHELPERS < 2 )
type = 3;
else type = (1 << (helperid % 2));

19
iguana/iguana_instantdex.c

@ -387,7 +387,7 @@ bits256 instantdex_rwoffer(int32_t rwflag,int32_t *lenp,uint8_t *serialized,stru
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,struct iguana_peer *addr)
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,struct iguana_peer *addr,struct bitcoin_swapinfo *swap)
{
char *reqstr,*hexstr,*retstr; struct instantdex_msghdr *msg; bits256 orderhash; struct iguana_info *coin; int32_t i,olen,slen,datalen,max=-1; uint8_t serialized[sizeof(*offer) + sizeof(struct iguana_msghdr) + 4096 + INSTANTDEX_DECKSIZE*33]; uint64_t nxt64bits;
//if ( strcmp(cmdstr,"poll") == 0 )
@ -416,15 +416,24 @@ char *instantdex_sendcmd(struct supernet_info *myinfo,struct instantdex_offer *o
reqstr = jprint(argjson,0);
slen = (int32_t)(strlen(reqstr) + 1);
datalen = (int32_t)slen + extralen + olen;
msg = calloc(1,datalen + sizeof(*msg));
msg = calloc(1,datalen + sizeof(*msg) + sizeof(swap->deck));
for (i=0; i<sizeof(msg->cmd); i++)
if ( (msg->cmd[i]= cmdstr[i]) == 0 )
break;
memcpy(msg->serialized,reqstr,slen);
memcpy(&msg->serialized[slen],serialized,olen);
//printf("extralen.%d datalen.%d slen.%d olen.%d\n",extralen,datalen,slen,olen);
extraser = (void *)swap->deck;
extralen = (int32_t)sizeof(swap->deck);
if ( extralen > 0 )
{
//if ( swap->otherchoosei < 0 )
{
//serdata = (void *)swap->deck;
//serdatalen = (int32_t)sizeof(swap->deck);
}
memcpy(&msg->serialized[slen + olen],extraser,extralen);
}
free(reqstr);
if ( instantdex_msgcreate(myinfo,msg,datalen) != 0 )
{
@ -1233,7 +1242,7 @@ char *instantdex_checkoffer(struct supernet_info *myinfo,int32_t *addedp,uint64_
if ( swap->pollevent != 0 )
instantdex_eventfree(swap->pollevent);
swap->pollevent = instantdex_event("poll",argjson,newjson,(void *)swap->deck,sizeof(swap->deck));
retstr = instantdex_sendcmd(myinfo,&swap->mine.offer,newjson,"BTCoffer",GENESIS_PUBKEY,INSTANTDEX_HOPS,swap->deck,sizeof(swap->deck),0);
retstr = instantdex_sendcmd(myinfo,&swap->mine.offer,newjson,"BTCoffer",GENESIS_PUBKEY,INSTANTDEX_HOPS,swap->deck,sizeof(swap->deck),0,swap);
free_json(newjson);
} else printf("error creating statemachine\n");
portable_mutex_unlock(&swap->mutex);
@ -1295,7 +1304,7 @@ char *instantdex_gotoffer(struct supernet_info *myinfo,struct exchange_info *exc
if ( swap->pollevent != 0 )
instantdex_eventfree(swap->pollevent);
swap->pollevent = instantdex_event("poll",argjson,newjson,(void *)swap->deck,sizeof(swap->deck));
retstr = instantdex_sendcmd(myinfo,&swap->mine.offer,newjson,"BTCdeckC",traderpub,INSTANTDEX_HOPS,swap->deck,sizeof(swap->deck),0);
retstr = instantdex_sendcmd(myinfo,&swap->mine.offer,newjson,"BTCdeckC",traderpub,INSTANTDEX_HOPS,swap->deck,sizeof(swap->deck),0,swap);
free_json(newjson);
}
}
@ -1574,7 +1583,7 @@ THREE_STRINGS(atomic,approve,myorderid,otherid,txname)
strcpy(virtualevent,txname);
strcat(virtualevent,"found");
newjson = cJSON_CreateObject();
if ( (retstr= instantdex_sendcmd(myinfo,&swap->mine.offer,newjson,virtualevent,myinfo->myaddr.persistent,0,0,0,0)) != 0 )
if ( (retstr= instantdex_sendcmd(myinfo,&swap->mine.offer,newjson,virtualevent,myinfo->myaddr.persistent,0,0,0,0,swap)) != 0 )
return(retstr);
else
{

9
iguana/swaps/iguana_BTCswap.c

@ -730,7 +730,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 )
{
*numconfirmsp = confs;
if ( (retstr= instantdex_sendcmd(myinfo,&swap->mine.offer,newjson,virtualevent,myinfo->myaddr.persistent,0,0,0,0)) != 0 )
if ( (retstr= instantdex_sendcmd(myinfo,&swap->mine.offer,newjson,virtualevent,myinfo->myaddr.persistent,0,0,0,0,swap)) != 0 )
return(retstr);
}
}
@ -1262,12 +1262,7 @@ char *instantdex_statemachine(struct instantdex_stateinfo *states,int32_t numsta
instantdex_newjson(myinfo,swap,newjson);
printf("i.%d (%s) %s %s.%d -> %s.%d send.(%s) %p\n",i,jprint(newjson,0),cmdstr,swap->state->name,state->ind,states[state->events[i].nextstateind].name,state->events[i].nextstateind,state->events[i].sendcmd,&states[state->events[i].nextstateind]);
swap->state = &states[state->events[i].nextstateind];
if ( swap->otherchoosei < 0 )
{
serdata = (void *)swap->deck;
serdatalen = (int32_t)sizeof(swap->deck);
}
return(instantdex_sendcmd(myinfo,&swap->mine.offer,newjson,state->events[i].sendcmd,swap->othertrader,INSTANTDEX_HOPS,serdata,serdatalen,0));
return(instantdex_sendcmd(myinfo,&swap->mine.offer,newjson,state->events[i].sendcmd,swap->othertrader,INSTANTDEX_HOPS,serdata,serdatalen,0,swap));
} else return(clonestr("{\"error\":\"instantdex_statemachine: illegal state\"}"));
} else return(clonestr("{\"result\":\"instantdex_statemachine: processed\"}"));
}

Loading…
Cancel
Save