Browse Source

Test

etomic
jl777 8 years ago
parent
commit
1d343f8bd3
  1. 149
      iguana/exchanges/LP_swap.c
  2. 13
      iguana/exchanges/LP_transaction.c

149
iguana/exchanges/LP_swap.c

@ -1004,152 +1004,3 @@ struct basilisk_swap *LP_swapinit(int32_t iambob,int32_t optionduration,bits256
return(swap);
}
#ifdef notanymore
struct basilisk_swap *basilisk_thread_start(bits256 privkey,struct basilisk_request *rp,uint32_t statebits,int32_t optionduration,int32_t reinit)
{
int32_t i,m,n,iter; uint8_t pubkey33[33]; bits256 pubkey25519; uint32_t channel,starttime; cJSON *retarray,*item,*msgobj; struct iguana_info *coin; double pending=0.; struct basilisk_swap *swap = 0;
// statebits 1 -> client, 0 -> LP
/*if ( myinfo->numswaps > 0 )
{
if ( (coin= LP_coinfind(rp->src)) == 0 || coin->FULLNODE >= 0 )
{
printf("dont have SRC coin.%s or not native and already swap pending\n",rp->src);
return(0);
}
if ( (coin= LP_coinfind(rp->dest)) == 0 || coin->FULLNODE >= 0 )
{
printf("dont have DEST coin.%s or not native and already swap pending\n",rp->dest);
return(0);
}
}
portable_mutex_lock(&myinfo->DEX_swapmutex);
for (i=0; i<myinfo->numswaps; i++)
if ( myinfo->swaps[i]->I.req.requestid == rp->requestid )
{
printf("basilisk_thread_start error trying to start requestid.%u which is already started\n",rp->requestid);
break;
}
if ( i == myinfo->numswaps && i < sizeof(myinfo->swaps)/sizeof(*myinfo->swaps) )*/
{
swap = calloc(1,sizeof(*swap));
swap->ctx = bitcoin_ctx();
swap->subsock = swap->pushsock = -1;
vcalc_sha256(0,swap->I.orderhash.bytes,(uint8_t *)rp,sizeof(*rp));
swap->I.req = *rp;
//swap->myinfoptr = myinfo;
printf("basilisk_thread_start request.%u statebits.%d (%s/%s) reinit.%d\n",rp->requestid,statebits,rp->src,rp->dest,reinit);
bitcoin_pubkey33(swap->ctx,pubkey33,privkey);
pubkey25519 = curve25519(privkey,curve25519_basepoint9());
swap->persistent_pubkey = pubkey25519;
swap->persistent_privkey = privkey;
memcpy(swap->persistent_pubkey33,pubkey33,33);
m = n = 0;
if ( bitcoin_swapinit(privkey,pubkey33,pubkey25519,swap,optionduration,statebits,reinit) != 0 )
{
for (iter=0; iter<16; iter++)
{
basilisk_psockinit(swap,statebits == 0);
sleep(3);
if ( swap->connected > 0 )
break;
sleep(10);
/*basilisk_sendstate(swap,data,sizeof(data));
basilisk_swapget(swap,0x80000000,data,sizeof(data),basilisk_verify_statebits);
if ( swap->connected > 0 )
break;
printf("loopback didntwork with %d %d\n",swap->pushsock,swap->subsock);*/
}
if ( reinit != 0 )
{
if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)basilisk_swaploop,(void *)swap) != 0 )
{
}
//myinfo->swaps[myinfo->numswaps++] = swap;
}
else
{
starttime = (uint32_t)time(NULL);
printf("statebits.%x m.%d n.%d\n",statebits,m,n);
while ( statebits == 0 && m <= n/2 && time(NULL) < starttime+7*BASILISK_MSGDURATION )
{
uint32_t msgid; uint8_t data[1024]; int32_t datalen;
m = n = 0;
sleep(DEX_SLEEP);
printf("waiting for offer to be accepted\n");
channel = 'D' + ((uint32_t)'E' << 8) + ((uint32_t)'X' << 16);
datalen = basilisk_rwDEXquote(1,data,rp);
msgid = (uint32_t)time(NULL);
printf("other req.%d >>>>>>>>>>> send response (%llx -> %llx) r.%u quoteid.%u\n",i,(long long)rp->desthash.txid,(long long)rp->srchash.txid,rp->requestid,rp->quoteid);
LP_channelsend(rp->desthash,rp->srchash,channel,msgid,data,datalen);
if ( (retarray= basilisk_channelget(rp->srchash,rp->desthash,channel,0x4000000,30)) != 0 )
{
if ( is_cJSON_Array(retarray) != 0 && (n= cJSON_GetArraySize(retarray)) > 0 )
{
for (i=0; i<n; i++)
{
item = jitem(retarray,i);
if ( (msgobj= jarray(&n,item,"messages")) != 0 && n > 0 )
{
item = jitem(msgobj,0);
if ( jobj(item,"data") != 0 && jobj(item,"key") != 0 )
m++;
else printf("(%s)\n",jprint(item,0));
} //else printf("msgobj.%p m.%d n.%d\n",msgobj,m,n);
}
}
} else printf("no retarray\n");
}
printf("LAUNCH check.%d m.%d\n",statebits,m);
if ( statebits != 0 || m > 0 )//n/2 )
{
//for (i=0; i<sizeof(swap->I.req); i++)
// fprintf(stderr,"%02x",((uint8_t *)&swap->I.req)[i]);
if ( (swap->fp= basilisk_swap_save(swap,privkey,rp,statebits,optionduration,reinit)) != 0 )
{
}
if ( reinit == 0 )
{
static FILE *swapsfp;
if ( swapsfp == 0 )
{
char fname[512];
sprintf(fname,"%s/SWAPS/list",GLOBAL_DBDIR), OS_compatible_path(fname);
if ( (swapsfp= fopen(fname,"rb+")) == 0 )
swapsfp = fopen(fname,"wb+");
else fseek(swapsfp,0,SEEK_END);
printf("LIST fp.%p\n",swapsfp);
}
if ( swapsfp != 0 )
{
fwrite(&rp->requestid,1,sizeof(rp->requestid),swapsfp);
fwrite(&rp->quoteid,1,sizeof(rp->quoteid),swapsfp);
fflush(swapsfp);
}
}
if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)basilisk_swaploop,(void *)swap) != 0 )
{
}
//myinfo->swaps[myinfo->numswaps++] = swap;
}
else
{
if ( statebits != 0 )
{
if ( (coin= LP_coinfind(rp->src)) != 0 )
{
}
}
printf("%u/%u offer wasnt accepted statebits.%d m.%d n.%d pending %.8f\n",rp->requestid,rp->quoteid,statebits,m,n,pending);
}
}
}
}
//portable_mutex_unlock(&myinfo->DEX_swapmutex);
return(swap);
}
#endif

13
iguana/exchanges/LP_transaction.c

@ -776,11 +776,17 @@ char *basilisk_swap_bobtxspend(bits256 *signedtxidp,uint64_t txfee,char *name,ch
free_json(utxoobj);
return(0);
} else free_json(utxoobj);
if ( satoshis != 0 )
{
if ( destamount > satoshis+txfee )
change = destamount - (satoshis - txfee);
printf("utxo %.8f, destamount %.8f change %.8f txfee %.8f\n",dstr(destamount),dstr(satoshis),dstr(change),dstr(txfee));
destamount = satoshis;
}
*destamountp = destamount;
if ( satoshis != 0 && destamount > satoshis+txfee )
change = destamount - (satoshis - txfee);
if ( destamount > txfee )
destamount -= txfee;
else printf("unexpected too small destamount %.8f txfee %.8f\n",dstr(destamount),dstr(txfee));
timestamp = (uint32_t)time(NULL);
V = calloc(256,sizeof(*V));
privkeys = cJSON_CreateArray();
@ -848,6 +854,7 @@ char *basilisk_swap_bobtxspend(bits256 *signedtxidp,uint64_t txfee,char *name,ch
bitcoin_addr2rmd160(&changetype,changermd160,changeaddr);
changelen = bitcoin_standardspend(changescript,0,changermd160);
txobj = bitcoin_txoutput(txobj,changescript,changelen,change);
printf("add change.(%s)\n",jprint(txobj,0));
}
if ( (rawtxbytes= bitcoin_json2hex(isPoS,&txid,txobj,V)) != 0 )
{
@ -881,6 +888,7 @@ int32_t basilisk_rawtx_gen(void *ctx,char *str,uint32_t swapstarted,uint8_t *pub
{
changeaddr = _changeaddr;
bitcoin_address(changeaddr,coin->pubtype,changermd160,20);
printf("changeaddr.(%s)\n",changeaddr);
}
for (iter=0; iter<2; iter++)
{
@ -919,6 +927,7 @@ int32_t basilisk_rawtx_sign(char *symbol,uint8_t pubtype,uint8_t p2shtype,uint8_
{
changeaddr = _changeaddr;
bitcoin_address(changeaddr,pubtype,changermd160,20);
printf("changeaddr.(%s)\n",changeaddr);
}
for (iter=0; iter<2; iter++)
{

Loading…
Cancel
Save