Browse Source

test

release/v0.1
jl777 9 years ago
parent
commit
808d3bfd26
  1. 17
      iguana/iguana_instantdex.c
  2. 5
      iguana/swaps/iguana_BTCswap.c

17
iguana/iguana_instantdex.c

@ -662,12 +662,12 @@ struct bitcoin_swapinfo *instantdex_statemachinefind(struct supernet_info *myinf
strcpy(swap->status,"expired");
printf("expired pending, need to take action, send timeout event\n");
queue_enqueue("historyQ",&exchange->historyQ,&swap->DL,0);
//bitcoin_freeswap(swap);
continue;
}
if ( swap != retswap || requeueflag != 0 )
queue_enqueue("statemachineQ",&exchange->statemachineQ,&swap->DL,0);
}
printf("found statemachine.%p\n",retswap);
return(retswap);
}
@ -861,10 +861,11 @@ int32_t instantdex_acceptextract(struct instantdex_accept *ap,cJSON *argjson)
#include "swaps/iguana_NXTswap.c"
#include "swaps/iguana_PAXswap.c"
struct bitcoin_swapinfo *bitcoin_swapinit(struct supernet_info *myinfo,struct exchange_info *exchange,struct instantdex_accept *myap,struct instantdex_accept *otherap,int32_t aminitiator,cJSON *argjson)
struct bitcoin_swapinfo *bitcoin_swapinit(struct supernet_info *myinfo,struct exchange_info *exchange,struct instantdex_accept *myap,struct instantdex_accept *otherap,int32_t aminitiator,cJSON *argjson,char *statename)
{
struct bitcoin_swapinfo *swap = 0; struct iguana_info *coinbtc,*altcoin;
swap = calloc(1,sizeof(struct bitcoin_swapinfo));
swap->state = instantdex_statefind(BTC_states,BTC_numstates,statename);
swap->mine = *myap, swap->other = *otherap;
if ( (swap->isinitiator= aminitiator) != 0 )
{
@ -901,7 +902,7 @@ struct bitcoin_swapinfo *bitcoin_swapinit(struct supernet_info *myinfo,struct ex
char *instantdex_checkoffer(struct supernet_info *myinfo,uint64_t *txidp,struct exchange_info *exchange,struct instantdex_accept *myap,cJSON *argjson)
{
char *retstr = 0; struct instantdex_accept *otherap; struct bitcoin_swapinfo *swap; cJSON *newjson;
char *retstr = 0; struct instantdex_accept *otherap; struct bitcoin_swapinfo *swap; cJSON *newjson; int32_t isbob = 0;
*txidp = myap->orderid;
if ( (otherap= instantdex_acceptable(myinfo,exchange,myap,myap->offer.minperc)) == 0 )
{
@ -913,7 +914,8 @@ char *instantdex_checkoffer(struct supernet_info *myinfo,uint64_t *txidp,struct
}
else
{
swap = bitcoin_swapinit(myinfo,exchange,myap,otherap,1,argjson);
isbob = myap->offer.myside;
swap = bitcoin_swapinit(myinfo,exchange,myap,otherap,1,argjson,isbob != 0 ? "BOB_sentoffer" : "ALICE_sentoffer");
printf("STATEMACHINEQ.(%llu / %llu)\n",(long long)swap->mine.orderid,(long long)swap->other.orderid);
queue_enqueue("statemachineQ",&exchange->statemachineQ,&swap->DL,0);
if ( (newjson= instantdex_parseargjson(myinfo,exchange,swap,argjson,1)) == 0 )
@ -925,7 +927,7 @@ char *instantdex_checkoffer(struct supernet_info *myinfo,uint64_t *txidp,struct
char *instantdex_gotoffer(struct supernet_info *myinfo,struct exchange_info *exchange,struct instantdex_accept *myap,struct instantdex_accept *otherap,struct instantdex_msghdr *msg,cJSON *argjson,char *remoteaddr,uint64_t signerbits,uint8_t *serdata,int32_t serdatalen) // receiving side
{
struct bitcoin_swapinfo *swap = 0; bits256 traderpub; struct iguana_info *coinbtc,*altcoin; cJSON *newjson=0; char *retstr=0;
struct bitcoin_swapinfo *swap = 0; bits256 traderpub; struct iguana_info *coinbtc,*altcoin; cJSON *newjson=0; char *retstr=0; int32_t isbob;
coinbtc = iguana_coinfind("BTC");
traderpub = jbits256(argjson,"traderpub");
if ( bits256_cmp(traderpub,myinfo->myaddr.persistent) == 0 )
@ -949,7 +951,8 @@ char *instantdex_gotoffer(struct supernet_info *myinfo,struct exchange_info *exc
return(clonestr("{\"error\":\"instantdex_BTCswap offer non BTC rel\"}"));
if ( myap->offer.expiration < (time(NULL) + INSTANTDEX_DURATION) || otherap->offer.expiration < (time(NULL) + INSTANTDEX_DURATION) )
return(clonestr("{\"error\":\"instantdex_BTCswap offer too close to expiration\"}"));
swap = bitcoin_swapinit(myinfo,exchange,myap,otherap,0,argjson);
isbob = myap->offer.myside;
swap = bitcoin_swapinit(myinfo,exchange,myap,otherap,0,argjson,isbob != 0 ? "BOB_sentoffer" : "ALICE_sentoffer");
if ( (newjson= instantdex_parseargjson(myinfo,exchange,swap,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 )
@ -990,6 +993,7 @@ char *instantdex_parse(struct supernet_info *myinfo,struct instantdex_msghdr *ms
A.offer.minperc = 100;
if ( strcmp(cmdstr,"BTCoffer") == 0 ) // incoming
{
printf("BTCoffer state\n");
if ( (ap= instantdex_acceptable(myinfo,exchange,&A,A.offer.minperc)) != 0 )
{
if ( (retstr= instantdex_gotoffer(myinfo,exchange,ap,&A,msg,argjson,remoteaddr,signerbits,serdata,serdatalen)) != 0 ) // adds to statemachine if no error
@ -1013,6 +1017,7 @@ char *instantdex_parse(struct supernet_info *myinfo,struct instantdex_msghdr *ms
}
else if ( (swap= instantdex_statemachinefind(myinfo,exchange,A.orderid,1)) != 0 )
{
printf("found existing state machine %llu\n",(long long)A.orderid);
newjson = instantdex_parseargjson(myinfo,exchange,swap,argjson,0);
return(instantdex_statemachine(BTC_states,BTC_numstates,myinfo,exchange,swap,cmdstr,argjson,newjson,serdata,serdatalen));
}

5
iguana/swaps/iguana_BTCswap.c

@ -903,9 +903,12 @@ struct instantdex_stateinfo *BTC_initFSM(int32_t *n)
char *instantdex_statemachine(struct instantdex_stateinfo *states,int32_t numstates,struct supernet_info *myinfo,struct exchange_info *exchange,struct bitcoin_swapinfo *swap,char *cmdstr,cJSON *argjson,cJSON *newjson,uint8_t *serdata,int32_t serdatalen)
{
uint32_t i; struct iguana_info *altcoin,*coinbtc; struct instantdex_stateinfo *state; cJSON *origjson = newjson;
uint32_t i; struct iguana_info *altcoin=0,*coinbtc=0; struct instantdex_stateinfo *state=0; cJSON *origjson = newjson;
if ( swap == 0 || (state= swap->state) == 0 || (coinbtc= iguana_coinfind("BTC")) == 0 || (altcoin= iguana_coinfind(swap->mine.offer.base)) == 0 )
{
printf("state.%s btc.%p altcoin.%p\n",state->name,coinbtc,altcoin);
return(clonestr("{\"error\":\"instantdex_BTCswap missing coin info\"}"));
}
printf("%llu/%llu cmd.(%s) state.(%s)\n",(long long)swap->mine.orderid,(long long)swap->other.orderid,cmdstr,swap->state->name);
if ( swap->expiration != 0 && time(NULL) > swap->expiration )
{

Loading…
Cancel
Save