Browse Source

test

release/v0.1
jl777 9 years ago
parent
commit
85ca3dcaff
  1. 1
      iguana/exchanges/bitcoin.c
  2. 4
      iguana/exchanges777.h
  3. 94
      iguana/iguana_instantdex.c
  4. 29
      iguana/swaps/iguana_BTCswap.c

1
iguana/exchanges/bitcoin.c

@ -1549,6 +1549,7 @@ uint64_t TRADE(int32_t dotrade,char **retstrp,struct exchange_info *exchange,cha
if ( (str= instantdex_sendoffer(myinfo,exchange,ap,json)) != 0 ) // adds to statemachine
{
json = cJSON_CreateObject();
printf("from TRADE\n");
jaddstr(json,"BTCoffer",instantdex_selectqueue(exchange,ap,str));
} else printf("null return from btcoffer\n");
free_json(tmp);

4
iguana/exchanges777.h

@ -94,8 +94,8 @@ struct instantdex_offer { char base[24],rel[24]; uint64_t price64,basevolume64,o
struct instantdex_accept
{
struct queueitem DL; void *info;
uint64_t pendingvolume64,orderid,matchid; uint32_t dead; int32_t didstate;
struct instantdex_offer offer;
uint64_t pendingvolume64,otherorderid,orderid,matchid; uint32_t dead; int32_t didstate;
struct instantdex_offer otheroffer,offer;
};
struct instantdex_accept *instantdex_offerfind(struct supernet_info *myinfo,struct exchange_info *exchange,cJSON *bids,cJSON *asks,uint64_t orderid,char *base,char *rel,int32_t requeue);

94
iguana/iguana_instantdex.c

@ -32,10 +32,10 @@ struct instantdex_event { char cmdstr[24],sendcmd[16]; struct instantdex_statein
struct instantdex_stateinfo
{
char name[24];
char name[24]; uint16_t ind,pad;
cJSON *(*process)(struct supernet_info *myinfo,struct exchange_info *exchange,struct instantdex_accept *A,cJSON *argjson,cJSON *newjson,uint8_t **serdatap,int32_t *serdatalenp);
cJSON *(*timeout)(struct supernet_info *myinfo,struct exchange_info *exchange,struct instantdex_accept *A,cJSON *argjson,cJSON *newjson,uint8_t **serdatap,int32_t *serdatalenp);
struct instantdex_stateinfo *timeoutevent,*errorevent;
uint16_t timeoutind,errorind;
struct instantdex_event *events; int32_t numevents;
};
@ -92,8 +92,8 @@ cJSON *instantdex_defaulttimeout(struct supernet_info *myinfo,struct exchange_in
return(newjson);
}
struct instantdex_stateinfo instantdex_errorstate = { "error", instantdex_defaultprocess, instantdex_defaulttimeout };
struct instantdex_stateinfo instantdex_timeoutstate = { "timeout", instantdex_defaultprocess, instantdex_defaulttimeout };
struct instantdex_stateinfo instantdex_errorstate = { "error", 0,0, instantdex_defaultprocess, instantdex_defaulttimeout };
struct instantdex_stateinfo instantdex_timeoutstate = { "timeout", 1,0, instantdex_defaultprocess, instantdex_defaulttimeout };
struct instantdex_stateinfo *instantdex_statefind(struct instantdex_stateinfo *states,int32_t numstates,char *statename)
{
@ -116,10 +116,11 @@ void instantdex_stateinit(struct instantdex_stateinfo *states,int32_t numstates,
strcpy(state->name,name);
if ( (errorstate= instantdex_statefind(states,numstates,errorstr)) == 0 )
errorstate = &instantdex_errorstate;
state->errorevent = errorstate;
state->errorind = errorstate->ind;
if ( (timeoutstate= instantdex_statefind(states,numstates,timeoutstr)) == 0 )
timeoutstate = &instantdex_timeoutstate;
state->timeoutevent = timeoutstate;
else printf("TS.%s ",timeoutstr);
state->timeoutind = timeoutstate->ind;
if ( (state->process= process_func) == 0 )
state->process = instantdex_defaultprocess;
if ( (state->timeout= timeout_func) == 0 )
@ -134,14 +135,26 @@ struct instantdex_stateinfo *instantdex_statecreate(struct instantdex_stateinfo
states = realloc(states,sizeof(*states) * (*numstatesp + 1));
state = &states[*numstatesp];
instantdex_stateinit(states,*numstatesp,state,name,errorstr,timeoutstr,process_func,timeout_func);
(*numstatesp)++;
state->ind = (*numstatesp)++;
printf("STATES[%d] %s %p %p %d %d\n",*numstatesp,state->name,state->process,state->timeout,state->timeoutind,state->errorind);
}
else
{
instantdex_stateinit(states,*numstatesp,&S,name,errorstr,timeoutstr,process_func,timeout_func);
if ( memcmp(&S,state,sizeof(S)) != 0 )
S.ind = state->ind;
if ( memcmp(&S,state,sizeof(S) - sizeof(void *) - sizeof(int)) != 0 )
{
int32_t i;
for (i=0; i<sizeof(S); i++)
printf("%02x ",((uint8_t *)&S)[i]);
printf("S\n");
for (i=0; i<sizeof(S); i++)
printf("%02x ",((uint8_t *)state)[i]);
printf("state\n");
printf("%s %p %p %d %d vs %s %p %p %d %d\n",state->name,state->process,state->timeout,state->timeoutind,state->errorind,S.name,S.process,S.timeout,S.timeoutind,S.errorind);
printf("statecreate error!!! (%s) already exists\n",name);
}
}
return(states);
}
@ -464,7 +477,7 @@ cJSON *instantdex_acceptjson(struct instantdex_accept *ap)
return(item);
}
struct instantdex_accept *instantdex_statemachinefind(struct supernet_info *myinfo,struct exchange_info *exchange,uint64_t orderid)
struct instantdex_accept *instantdex_statemachinefind(struct supernet_info *myinfo,struct exchange_info *exchange,uint64_t orderid,int32_t requeueflag)
{
struct instantdex_accept PAD,*ap,*retap = 0; uint32_t now;
now = (uint32_t)time(NULL);
@ -475,13 +488,18 @@ struct instantdex_accept *instantdex_statemachinefind(struct supernet_info *myin
if ( now < ap->offer.expiration && ap->dead == 0 )
{
if ( orderid == ap->orderid )
{
if ( retap != 0 && requeueflag == 0 )
queue_enqueue("statemachineQ",&exchange->statemachineQ,&retap->DL,0);
retap = ap;
}
}
else
{
printf("expired pending, need to take action\n");
printf("expired pending, need to take action, send timeout event\n");
}
queue_enqueue("statemachineQ",&exchange->statemachineQ,&PAD.DL,0);
if ( ap != retap || requeueflag != 0 )
queue_enqueue("statemachineQ",&exchange->statemachineQ,&ap->DL,0);
}
return(retap);
}
@ -489,6 +507,8 @@ struct instantdex_accept *instantdex_statemachinefind(struct supernet_info *myin
struct instantdex_accept *instantdex_offerfind(struct supernet_info *myinfo,struct exchange_info *exchange,cJSON *bids,cJSON *asks,uint64_t orderid,char *base,char *rel,int32_t requeue)
{
struct instantdex_accept PAD,*ap,*retap = 0; uint32_t now; cJSON *item; char *type;
if ( (retap= instantdex_statemachinefind(myinfo,exchange,orderid,requeue)) != 0 )
return(retap);
now = (uint32_t)time(NULL);
memset(&PAD,0,sizeof(PAD));
queue_enqueue("acceptableQ",&exchange->acceptableQ,&PAD.DL,0);
@ -656,29 +676,36 @@ int32_t instantdex_acceptextract(struct instantdex_accept *ap,cJSON *argjson)
#include "swaps/iguana_NXTswap.c"
#include "swaps/iguana_PAXswap.c"
char *instantdex_swapset(struct supernet_info *myinfo,struct instantdex_accept *A,cJSON *argjson)
char *instantdex_swapset(struct supernet_info *myinfo,struct instantdex_accept *ap,cJSON *argjson)
{
uint64_t satoshis[2]; int32_t offerdir = 0; double minperc; uint64_t insurance,relsatoshis;
struct bitcoin_swapinfo *swap; bits256 orderhash,traderpub; struct iguana_info *coinbtc;
if ( (swap= A->info) == 0 )
if ( (swap= ap->info) == 0 )
return(clonestr("{\"error\":\"no swapinfo set\"}"));
relsatoshis = instantdex_BTCsatoshis(A->offer.price64,A->offer.basevolume64);
relsatoshis = instantdex_BTCsatoshis(ap->offer.price64,ap->offer.basevolume64);
traderpub = jbits256(argjson,"traderpub");
if ( (minperc= jdouble(argjson,"p")) < INSTANTDEX_MINPERC )
minperc = INSTANTDEX_MINPERC;
if ( (coinbtc= iguana_coinfind("BTC")) == 0 )
return(clonestr("{\"error\":\"no BTC found\"}"));
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(A->offer));
offerdir = instantdex_bidaskdir(ap);
vcalc_sha256(0,orderhash.bytes,(void *)&ap->offer,sizeof(ap->offer));
if ( offerdir > 0 )
swap->bidid = A->orderid;
else swap->askid = A->orderid;
{
swap->bidid = ap->orderid;
swap->askid = ap->otherorderid;
}
else
{
swap->askid = ap->orderid;
swap->bidid = ap->otherorderid;
}
if ( bits256_nonz(swap->othertrader) == 0 )
swap->othertrader = traderpub;
else if ( bits256_cmp(traderpub,swap->othertrader) != 0 )
{
printf("competing offer received for (%s/%s) %.8f %.8f\n",A->offer.base,A->offer.rel,dstr(A->offer.price64),dstr(A->offer.basevolume64));
printf("competing offer received for (%s/%s) %.8f %.8f\n",ap->offer.base,ap->offer.rel,dstr(ap->offer.price64),dstr(ap->offer.basevolume64));
return(clonestr("{\"error\":\"no competing offers for now\"}"));
}
if ( bits256_nonz(swap->orderhash) == 0 )
@ -688,7 +715,7 @@ char *instantdex_swapset(struct supernet_info *myinfo,struct instantdex_accept *
printf("orderhash %llx mismatch %llx\n",(long long)swap->orderhash.txid,(long long)orderhash.txid);
return(clonestr("{\"error\":\"orderhash mismatch???\"}"));
}
swap->satoshis[0] = A->offer.basevolume64;
swap->satoshis[0] = ap->offer.basevolume64;
swap->satoshis[1] = relsatoshis;
swap->insurance = (relsatoshis * INSTANTDEX_INSURANCERATE + coinbtc->chain->txfee); // txfee
if ( swap->minperc < minperc )
@ -724,6 +751,7 @@ char *instantdex_sendoffer(struct supernet_info *myinfo,struct exchange_info *ex
swap->choosei = swap->otherschoosei = -1;
swap->depositconfirms = swap->paymentconfirms = swap->altpaymentconfirms = swap->myfeeconfirms = swap->otherfeeconfirms = -1;
ap->info = swap;
printf("sendoffer SETSWAP for orderid.%llu\n",(long long)ap->orderid);
if ( (retstr= instantdex_swapset(myinfo,ap,argjson)) != 0 )
return(retstr);
ap->orderid = swap->orderhash.txid;
@ -744,7 +772,7 @@ char *instantdex_gotoffer(struct supernet_info *myinfo,struct exchange_info *exc
traderpub = jbits256(argjson,"traderpub");
if ( bits256_cmp(traderpub,myinfo->myaddr.persistent) == 0 )
{
printf("got my own packet\n");
printf("got my own gotoffer packet orderid.%llu\n",(long long)ap->orderid);
return(clonestr("{\"result\":\"got my own packet\"}"));
}
printf("T.%d got (%s/%s) %.8f vol %.8f %llu offerside.%d offerdir.%d swap.%p decksize.%ld/datalen.%d\n",bits256_cmp(traderpub,myinfo->myaddr.persistent),ap->offer.base,ap->offer.rel,dstr(ap->offer.price64),dstr(ap->offer.basevolume64),(long long)ap->orderid,ap->offer.myside,ap->offer.acceptdir,ap->info,sizeof(swap->deck),serdatalen);
@ -759,6 +787,7 @@ char *instantdex_gotoffer(struct supernet_info *myinfo,struct exchange_info *exc
if ( ap->info == 0 )
{
ap->info = swap = calloc(1,sizeof(struct bitcoin_swapinfo));
printf("gotoffer SETSWAP for orderid.%llu\n",(long long)ap->orderid);
swap->choosei = swap->otherschoosei = -1;
swap->depositconfirms = swap->paymentconfirms = swap->altpaymentconfirms = swap->myfeeconfirms = swap->otherfeeconfirms = -1;
swap->isbob = (ap->offer.myside ^ 1);
@ -766,7 +795,7 @@ char *instantdex_gotoffer(struct supernet_info *myinfo,struct exchange_info *exc
return(retstr);
if ( instantdex_pubkeyargs(swap,newjson,2+777,myinfo->persistent_priv,swap->orderhash,0x02 + swap->isbob) != 2+777 )
return(clonestr("{\"error\":\"instantdex_BTCswap error creating pubkeyargs\"}"));
char str[65]; printf("GOT OFFER! %p (%s/%s) other.%s myside.%d\n",ap->info,ap->offer.base,ap->offer.rel,bits256_str(str,traderpub),swap->isbob);
char str[65]; printf("GOT OFFER! orderid.%llu %p (%s/%s) other.%s myside.%d\n",(long long)ap->orderid,ap->info,ap->offer.base,ap->offer.rel,bits256_str(str,traderpub),swap->isbob);
if ( (newjson= instantdex_parseargjson(myinfo,exchange,ap,argjson,1)) == 0 )
return(clonestr("{\"error\":\"instantdex_BTCswap offer null newjson\"}"));
else if ( (retstr= instantdex_addfeetx(myinfo,newjson,ap,swap,"BOB_gotoffer","ALICE_gotoffer")) == 0 )
@ -779,7 +808,7 @@ char *instantdex_gotoffer(struct supernet_info *myinfo,struct exchange_info *exc
return(instantdex_sendcmd(myinfo,&ap->offer,newjson,"BTCchose",traderpub,INSTANTDEX_HOPS,swap->deck,sizeof(swap->deck)));
}
} else return(retstr);
} else return(clonestr("{\"error\":\"couldnt allocate swap info\"}"));
} else return(clonestr("{\"error\":\"swap info already there\"}"));
}
char *instantdex_selectqueue(struct exchange_info *exchange,struct instantdex_accept *ap,char *retstr)
@ -829,9 +858,17 @@ char *instantdex_parse(struct supernet_info *myinfo,struct instantdex_msghdr *ms
minperc = INSTANTDEX_MINPERC;
if ( (ap= instantdex_acceptable(myinfo,exchange,&A,acct777_nxt64bits(traderpub),minperc)) != 0 )
{
if ( ap->otherorderid == 0 )
{
ap->otherorderid = A.orderid;
ap->otheroffer = A.offer;
}
if ( (retstr= instantdex_gotoffer(myinfo,exchange,ap,msg,argjson,remoteaddr,signerbits,serdata,serdatalen)) != 0 ) // adds to statemachine if no error
{
printf("from GOTOFFER\n");
return(instantdex_selectqueue(exchange,ap,retstr));
}
}
else
{
printf("no matching trade for %llu -> InstantDEX_minaccept isbob.%d\n",(long long)A.orderid,A.offer.myside);
@ -844,7 +881,7 @@ char *instantdex_parse(struct supernet_info *myinfo,struct instantdex_msghdr *ms
} else return(clonestr("{\"result\":\"order was already in orderbook\"}"));
}
}
else if ( (ap= instantdex_statemachinefind(myinfo,exchange,A.orderid)) != 0 )
else if ( (ap= instantdex_statemachinefind(myinfo,exchange,A.orderid,1)) != 0 )
{
if ( ap->info == 0 )
{
@ -852,7 +889,7 @@ char *instantdex_parse(struct supernet_info *myinfo,struct instantdex_msghdr *ms
return(clonestr("{\"error\":\"no swap for orderid\"}"));
}
newjson = instantdex_parseargjson(myinfo,exchange,ap,argjson,0);
return(instantdex_statemachine(myinfo,exchange,ap,cmdstr,argjson,newjson,serdata,serdatalen));
return(instantdex_statemachine(BTC_states,BTC_numstates,myinfo,exchange,ap,cmdstr,argjson,newjson,serdata,serdatalen));
}
else
{
@ -867,8 +904,8 @@ char *InstantDEX_hexmsg(struct supernet_info *myinfo,void *ptr,int32_t len,char
{
struct instantdex_msghdr *msg = ptr; int32_t i,olen,slen,num,datalen,newlen,flag = 0;
uint8_t *serdata; struct supernet_info *myinfos[64]; struct instantdex_offer rawoffer;
bits256 orderhash; uint64_t signerbits; uint8_t tmp[sizeof(msg->sig)]; char *retstr = 0;
cJSON *retjson,*item,*argjson = 0;
uint64_t signerbits; uint8_t tmp[sizeof(msg->sig)]; char *retstr = 0;
bits256 orderhash,traderpub; cJSON *retjson,*item,*argjson = 0;
if ( BTC_states == 0 )
BTC_states = BTC_initFSM(&BTC_numstates);
datalen = len - (int32_t)sizeof(msg->sig);
@ -921,6 +958,9 @@ char *InstantDEX_hexmsg(struct supernet_info *myinfo,void *ptr,int32_t len,char
{
myinfo = myinfos[i];
//char str[65]; printf("i.%d of %d: %s\n",i,num,bits256_str(str,myinfo->myaddr.persistent));
traderpub = jbits256(argjson,"traderpub");
if ( bits256_cmp(traderpub,myinfo->myaddr.persistent) == 0 )
continue;
if ( (retstr= instantdex_parse(myinfo,msg,argjson,remoteaddr,signerbits,&rawoffer,orderhash,serdata,newlen)) != 0 )
{
item = cJSON_CreateObject();

29
iguana/swaps/iguana_BTCswap.c

@ -684,7 +684,7 @@ cJSON *BTC_cleanupfunc(struct supernet_info *myinfo,struct exchange_info *exchan
struct instantdex_stateinfo *BTC_initFSM(int32_t *n)
{
struct instantdex_stateinfo *s = 0;
*n = 0;
*n = 2;
// Four initial states are BOB_sentoffer, ALICE_gotoffer, ALICE_sentoffer, BOB_gotoffer
// the initiator includes signed feetx and deck of 777 keypairs
//
@ -717,13 +717,13 @@ struct instantdex_stateinfo *BTC_initFSM(int32_t *n)
s = instantdex_statecreate(s,n,"BOB_sentprivs",BTC_waitprivsfunc,0,"BTC_cleanup",0);
s = instantdex_statecreate(s,n,"BOB_waitfee",BOB_waitfeefunc,0,"BTC_cleanup",0);
s = instantdex_statecreate(s,n,"BOB_sentdeposit",BOB_waitBTCalttxfunc,0,"BOB_reclaim",0);
s = instantdex_statecreate(s,n,"BOB_altconfirm",BOB_waitaltconfirmfunc,0,"BTC_claimdeposit",0);
s = instantdex_statecreate(s,n,"BOB_sentpayment",BOB_waitprivMfunc,0,"BTC_claimdeposit",0);
s = instantdex_statecreate(s,n,"BOB_altconfirm",BOB_waitaltconfirmfunc,0,"BOB_reclaim",0);
s = instantdex_statecreate(s,n,"BOB_sentpayment",BOB_waitprivMfunc,0,"BOB_reclaim",0);
s = instantdex_statecreate(s,n,"ALICE_sentprivs",BTC_waitprivsfunc,0,"BTC_cleanup",0);
s = instantdex_statecreate(s,n,"Alice_waitfee",ALICE_waitfeefunc,0,"BTC_cleanup",0);
s = instantdex_statecreate(s,n,"ALICE_waitdeposit",ALICE_waitdepositfunc,0,"BTC_cleanup",0);
s = instantdex_statecreate(s,n,"ALICE_sentalt",ALICE_waitBTCpaytxfunc,0,"BTC_claimdeposit",0);
s = instantdex_statecreate(s,n,"ALICE_waitconfirms",ALICE_waitpayconf_or_bobreclaimfunc,0,"BTC_claimdeposit",0);
s = instantdex_statecreate(s,n,"ALICE_sentalt",ALICE_waitBTCpaytxfunc,0,"ALICE_reclaim",0);
s = instantdex_statecreate(s,n,"ALICE_waitconfirms",ALICE_waitpayconf_or_bobreclaimfunc,0,"ALICE_reclaim",0);
// events instantdex_addevent(s,*n,<Current State>,<event>,<message to send>,<Next State>)
if ( 0 ) // following are implicit states and events handled externally to setup datastructures
@ -772,28 +772,28 @@ struct instantdex_stateinfo *BTC_initFSM(int32_t *n)
s = instantdex_statecreate(s,n,"BOB_sentdeposit",BOB_waitBTCalttxfunc,0,"BOB_reclaim",0);
instantdex_addevent(s,*n,"BOB_sentdeposit","BTCalttx","poll","BOB_altconfirm");
s = instantdex_statecreate(s,n,"BOB_altconfirm",BOB_waitaltconfirmfunc,0,"BTC_claimdeposit",0);
s = instantdex_statecreate(s,n,"BOB_altconfirm",BOB_waitaltconfirmfunc,0,"BOB_reclaim",0);
instantdex_addevent(s,*n,"BOB_altconfirm","altfound","BTCpaytx","BOB_sentpayment");
instantdex_addevent(s,*n,"BOB_altconfirm","poll","poll","BOB_altconfirm");
// now Alice's turn to make sure payment is confrmed and send in claim or see bob's reclaim and reclaim
s = instantdex_statecreate(s,n,"ALICE_sentalt",ALICE_waitBTCpaytxfunc,0,"BTC_claimdeposit",0);
s = instantdex_statecreate(s,n,"ALICE_sentalt",ALICE_waitBTCpaytxfunc,0,"ALICE_reclaim",0);
instantdex_addevent(s,*n,"ALICE_sentalt","BTCpaytx","poll","ALICE_waitconfirms");
s = instantdex_statecreate(s,n,"ALICE_waitconfirms",ALICE_waitpayconf_or_bobreclaimfunc,0,"BTC_claimdeposit",0);
s = instantdex_statecreate(s,n,"ALICE_waitconfirms",ALICE_waitpayconf_or_bobreclaimfunc,0,"ALICE_reclaim",0);
instantdex_addevent(s,*n,"ALICE_waitconfirms","bobfound","poll","ALICE_reclaim");
instantdex_addevent(s,*n,"ALICE_waitconfirms","payfound","BTCprivM","ALICE_claimedbtc");
instantdex_addevent(s,*n,"ALICE_waitconfirms","poll","poll","ALICE_waitconfirms");
// Bob waits for privM either from Alice or alt blockchain
s = instantdex_statecreate(s,n,"BOB_sentpayment",BOB_waitprivMfunc,0,"BTC_claimdeposit",0);
s = instantdex_statecreate(s,n,"BOB_sentpayment",BOB_waitprivMfunc,0,"BOB_reclaim",0);
instantdex_addevent(s,*n,"BOB_sentpayment","btcfound","BTCdone","BOB_claimedalt");
instantdex_addevent(s,*n,"BOB_sentpayment","BTCprivM","BTCdone","BOB_claimedalt");
instantdex_addevent(s,*n,"BOB_sentpayment","poll","poll","BOB_sentpayment");
return(s);
}
char *instantdex_statemachine(struct supernet_info *myinfo,struct exchange_info *exchange,struct instantdex_accept *A,char *cmdstr,cJSON *argjson,cJSON *newjson,uint8_t *serdata,int32_t serdatalen)
char *instantdex_statemachine(struct instantdex_stateinfo *states,int32_t numstates,struct supernet_info *myinfo,struct exchange_info *exchange,struct instantdex_accept *A,char *cmdstr,cJSON *argjson,cJSON *newjson,uint8_t *serdata,int32_t serdatalen)
{
uint32_t i; struct iguana_info *altcoin,*coinbtc; struct bitcoin_swapinfo *swap; struct instantdex_stateinfo *state; cJSON *origjson = newjson;
if ( (swap= A->info) == 0 || (state= swap->state) == 0 || (coinbtc= iguana_coinfind("BTC")) == 0 || (altcoin= iguana_coinfind(A->offer.base)) == 0 )
@ -801,7 +801,7 @@ char *instantdex_statemachine(struct supernet_info *myinfo,struct exchange_info
printf("%llu/%llu cmd.(%s) state.(%s)\n",(long long)swap->bidid,(long long)swap->askid,cmdstr,swap->state->name);
if ( swap->expiration != 0 && time(NULL) > swap->expiration )
{
swap->state = state->timeoutevent;
swap->state = &states[state->timeoutind];
if ( (newjson= (*state->timeout)(myinfo,exchange,A,argjson,newjson,&serdata,&serdatalen)) == 0 )
return(clonestr("{\"error\":\"instantdex_BTCswap null return from timeoutfunc\"}"));
return(jprint(newjson,1));
@ -821,7 +821,7 @@ char *instantdex_statemachine(struct supernet_info *myinfo,struct exchange_info
else
{
printf("null return from non-poll event\n");
swap->state = state->errorevent;
swap->state = &states[state->errorind];
return(clonestr("{\"error\":\"instantdex_statemachine: null return\"}"));
}
}
@ -829,8 +829,11 @@ char *instantdex_statemachine(struct supernet_info *myinfo,struct exchange_info
{
if ( state->events[i].sendcmd != 0 )
{
swap->state = state->events[i].nextstate;
if ( state->events[i].nextstate->ind > 1 )
{
swap->state = &states[state->events[i].nextstate->ind];
return(instantdex_sendcmd(myinfo,&A->offer,newjson,state->events[i].sendcmd,swap->othertrader,INSTANTDEX_HOPS,serdata,serdatalen));
} else return(clonestr("{\"error\":\"instantdex_statemachine: illegal state\"}"));
} else return(clonestr("{\"result\":\"instantdex_statemachine: processed\"}"));
}
}

Loading…
Cancel
Save