Browse Source

test

release/v0.1
jl777 9 years ago
parent
commit
d949b3e7db
  1. 2
      iguana/exchanges777.h
  2. 2
      iguana/iguana777.h
  3. 28
      iguana/iguana_instantdex.c
  4. 11
      iguana/iguana_payments.c
  5. 2
      iguana/iguana_sign.c
  6. 7
      iguana/iguana_unspents.c
  7. 28
      iguana/swaps/iguana_BTCswap.c

2
iguana/exchanges777.h

@ -158,7 +158,7 @@ struct bitcoin_eventitem { struct queueitem DL; cJSON *argjson,*newjson; int32_t
struct bitcoin_swapinfo
{
//struct queueitem DL;
queue_t eventsQ;
queue_t eventsQ; struct bitcoin_eventitem *pollevent;
struct bitcoin_swapinfo *next,*prev;
struct instantdex_accept mine,other;
bits256 privkeys[INSTANTDEX_DECKSIZE+2],mypubs[2],otherpubs[2],privAm,pubAm,privBn,pubBn;

2
iguana/iguana777.h

@ -992,6 +992,8 @@ char *iguana_pollrawtx(queue_t *Q,cJSON **vinsp,uint32_t rawtxtag,double expirat
bits256 scrypt_blockhash(const void *input);
bits256 iguana_calcblockhash(int32_t (*hashalgo)(uint8_t *blockhashp,uint8_t *serialized,int32_t len),uint8_t *serialized,int32_t len);
uint32_t iguana_targetbits(struct iguana_info *coin,struct iguana_block *hwmchain,struct iguana_block *prev,struct iguana_block *prev2,int32_t PoSflag);
struct bitcoin_eventitem *instantdex_event(char *cmdstr,cJSON *newjson,cJSON *argjson,uint8_t *serdata,int32_t serdatalen);
void instantdex_eventfree(struct bitcoin_eventitem *ptr);
extern int32_t HDRnet,netBLOCKS;

28
iguana/iguana_instantdex.c

@ -1285,6 +1285,21 @@ char *instantdex_gotoffer(struct supernet_info *myinfo,struct exchange_info *exc
return(retstr);
}
struct bitcoin_eventitem *instantdex_event(char *cmdstr,cJSON *newjson,cJSON *argjson,uint8_t *serdata,int32_t serdatalen)
{
struct bitcoin_eventitem *ptr;
ptr = calloc(1,sizeof(*ptr) + serdatalen);
strcpy(ptr->cmd,cmdstr);
ptr->newjson = jduplicate(newjson);
ptr->argjson = jduplicate(argjson);
if ( serdatalen != 0 )
{
memcpy(ptr->serdata,serdata,serdatalen);
ptr->serdatalen = serdatalen;
}
return(ptr);
}
char *instantdex_parse(struct supernet_info *myinfo,struct instantdex_msghdr *msg,cJSON *argjson,char *remoteaddr,uint64_t signerbits,struct instantdex_offer *offer,bits256 orderhash,uint8_t *serdata,int32_t serdatalen)
{
char cmdstr[16],*retstr; struct exchange_info *exchange; struct instantdex_accept A,*ap = 0; bits256 traderpub; cJSON *newjson; struct bitcoin_swapinfo *swap; struct bitcoin_eventitem *ptr;
@ -1317,16 +1332,9 @@ char *instantdex_parse(struct supernet_info *myinfo,struct instantdex_msghdr *ms
free_json(newjson);
return(retstr);
}
ptr = calloc(1,sizeof(*ptr) + serdatalen);
strcpy(ptr->cmd,cmdstr);
ptr->newjson = newjson;
ptr->argjson = jduplicate(argjson);
if ( serdatalen != 0 )
{
memcpy(ptr->serdata,serdata,serdatalen);
ptr->serdatalen = serdatalen;
}
queue_enqueue("eventQ",&swap->eventsQ,&ptr->DL,0);
if ( (ptr= instantdex_event(cmdstr,newjson,argjson,serdata,serdatalen)) != 0 )
queue_enqueue("eventQ",&swap->eventsQ,&ptr->DL,0);
free_json(newjson);
return(clonestr("{\"result\":\"updated statemachine\"}"));
//return(instantdex_statemachine(BTC_states,BTC_numstates,myinfo,exchange,swap,cmdstr,argjson,newjson,serdata,serdatalen));
}

11
iguana/iguana_payments.c

@ -367,11 +367,14 @@ char *iguana_calcrawtx(struct supernet_info *myinfo,struct iguana_info *coin,cJS
void iguana_unspentslock(struct supernet_info *myinfo,struct iguana_info *coin,cJSON *vins)
{
uint32_t spent_unspentind; char coinaddr[64]; int16_t spent_hdrsi; int32_t i,RTspentflag,num;
num = cJSON_GetArraySize(vins);
for (i=0; i<num; i++)
if ( coin->RELAYNODE != 0 || coin->VALIDATENODE != 0 )
{
if ( iguana_inputaddress(coin,coinaddr,&spent_hdrsi,&spent_unspentind,jitem(vins,i)) != 0 )
iguana_utxofind(coin,spent_hdrsi,spent_unspentind,&RTspentflag,1);
num = cJSON_GetArraySize(vins);
for (i=0; i<num; i++)
{
if ( iguana_inputaddress(coin,coinaddr,&spent_hdrsi,&spent_unspentind,jitem(vins,i)) != 0 )
iguana_utxofind(coin,spent_hdrsi,spent_unspentind,&RTspentflag,1);
}
}
}

2
iguana/iguana_sign.c

@ -357,7 +357,7 @@ int32_t iguana_rwmsgtx(struct iguana_info *coin,int32_t rwflag,cJSON *json,uint8
return(-1);
}
extralen -= (sizeof(struct iguana_msgvout) * msg->tx_out);
msg->vouts = (struct iguana_msgvout *)&serialized[extralen];
msg->vouts = (struct iguana_msgvout *)&extraspace[extralen];
memset(msg->vouts,0,sizeof(struct iguana_msgvout) * msg->tx_out);
}
for (i=0; i<msg->tx_out; i++)

7
iguana/iguana_unspents.c

@ -63,12 +63,17 @@ char *iguana_inputaddress(struct iguana_info *coin,char *coinaddr,int16_t *spent
{
txid = jbits256(vinobj,"txid");
vout = jint(vinobj,"vout");
if ( (checkind= iguana_unspentindfind(coin,coinaddr,0,0,0,&height,txid,vout,coin->bundlescount-1)) != 0 )
if ( (checkind= iguana_unspentindfind(coin,coinaddr,0,0,0,&height,txid,vout,coin->bundlescount-1)) > 0 )
{
*spent_hdrsip = (height / coin->chain->bundlesize);
*unspentindp = checkind;
return(coinaddr);
}
else
{
char str[65];
printf("error finding (%s/%d)\n",bits256_str(str,txid),vout);
}
}
return(0);
}

28
iguana/swaps/iguana_BTCswap.c

@ -999,6 +999,18 @@ struct instantdex_stateinfo *BTC_initFSM(int32_t *n)
return(s);
}
void instantdex_eventfree(struct bitcoin_eventitem *ptr)
{
if ( ptr != 0 )
{
if ( ptr->argjson != 0 )
free_json(ptr->argjson);
if ( ptr->newjson != 0 )
free_json(ptr->newjson);
free(ptr);
}
}
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=0,*coinbtc=0; struct instantdex_stateinfo *state=0; cJSON *origjson = newjson;
@ -1041,6 +1053,9 @@ char *instantdex_statemachine(struct instantdex_stateinfo *states,int32_t numsta
if ( state->events[i].nextstateind > 1 )
{
swap->state = &states[state->events[i].nextstateind];
if ( swap->pollevent != 0 )
instantdex_eventfree(swap->pollevent);
swap->pollevent = instantdex_event("poll",newjson,argjson,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("{\"result\":\"instantdex_statemachine: processed\"}"));
@ -1052,20 +1067,29 @@ char *instantdex_statemachine(struct instantdex_stateinfo *states,int32_t numsta
void instantdex_statemachine_iter(struct supernet_info *myinfo,struct exchange_info *exchange,struct bitcoin_swapinfo *swap)
{
char *str; struct bitcoin_eventitem *ptr; struct iguana_info *coinbtc;
char *str; struct bitcoin_eventitem *ptr; struct iguana_info *coinbtc; int32_t flag = 0;
coinbtc = iguana_coinfind("BTC");
if ( instantdex_isbob(swap) != 0 && swap->myfee == 0 )
swap->myfee = instantdex_feetx(myinfo,&swap->mine,swap,coinbtc);
else if ( instantdex_isbob(swap) == 0 && swap->otherfee == 0 )
swap->otherfee = instantdex_feetx(myinfo,&swap->mine,swap,coinbtc);
printf("state(%s) %llx/%llx\n",swap->state->name,(long long)swap->mine.orderid,(long long)swap->other.orderid);
while ( (ptr= queue_dequeue(&swap->eventsQ,0)) != 0 )
{
//printf("deQ arg.%p new.%p\n",ptr->argjson,ptr->newjson);
printf("dequeued (%s)\n",ptr->cmd);
if ( (str= instantdex_statemachine(BTC_states,BTC_numstates,myinfo,exchange,swap,ptr->cmd,ptr->argjson,ptr->newjson,ptr->serdata,ptr->serdatalen)) != 0 )
free(str);
instantdex_eventfree(ptr);
if ( ptr->argjson != 0 )
free_json(ptr->argjson);
free(ptr);
flag++;
}
if ( flag == 0 && swap->pollevent != 0 )
{
printf("send poll event\n");
if ( (str= instantdex_statemachine(BTC_states,BTC_numstates,myinfo,exchange,swap,"poll",swap->pollevent->argjson,jduplicate(swap->pollevent->newjson),swap->pollevent->serdata,swap->pollevent->serdatalen)) != 0 )
free(str);
}
}

Loading…
Cancel
Save