Browse Source

test

release/v0.1
jl777 9 years ago
parent
commit
991b4602de
  1. 6
      basilisk/basilisk.c
  2. 18
      basilisk/basilisk_DEX.c
  3. 16
      basilisk/basilisk_swap.c
  4. 4
      iguana/main.c

6
basilisk/basilisk.c

@ -291,7 +291,7 @@ struct basilisk_item *basilisk_issueremote(struct supernet_info *myinfo,struct i
else else
{ {
data = basilisk_jsondata(sizeof(struct iguana_msghdr),&allocptr,space,sizeof(space),&datalen,symbol,valsobj,basilisktag); data = basilisk_jsondata(sizeof(struct iguana_msghdr),&allocptr,space,sizeof(space),&datalen,symbol,valsobj,basilisktag);
*numsentp = pending->numsent = basilisk_sendcmd(myinfo,addr != 0 ? addr->ipaddr : 0,CMD,&pending->basilisktag,encryptflag,delaymillis,data,datalen,1,pending->nBits); *numsentp = pending->numsent = basilisk_sendcmd(myinfo,addr != 0 ? addr->ipaddr : 0,CMD,&pending->basilisktag,encryptflag,delaymillis,data,datalen,fanout,pending->nBits);
if ( blockflag != 0 ) if ( blockflag != 0 )
{ {
portable_mutex_lock(&myinfo->basilisk_mutex); portable_mutex_lock(&myinfo->basilisk_mutex);
@ -382,6 +382,7 @@ char *basilisk_standardservice(char *CMD,struct supernet_info *myinfo,void *_add
} }
ptr->finished = (uint32_t)time(NULL); ptr->finished = (uint32_t)time(NULL);
} }
if ( strcmp("RID",CMD) != 0 )
printf("%s.(%s) -> (%s)\n",CMD,jprint(valsobj,0),retstr!=0?retstr:""); printf("%s.(%s) -> (%s)\n",CMD,jprint(valsobj,0),retstr!=0?retstr:"");
return(retstr); return(retstr);
} }
@ -505,6 +506,7 @@ void basilisk_result(struct supernet_info *myinfo,char *remoteaddr,uint32_t basi
{ {
retstr = jprint(vals,0); retstr = jprint(vals,0);
safecopy(CMD,jstr(vals,"origcmd"),sizeof(CMD)); safecopy(CMD,jstr(vals,"origcmd"),sizeof(CMD));
if ( strcmp("RID",CMD) != 0 )
printf("(%s) -> Q.%u results vals.(%s)\n",CMD,basilisktag,retstr); printf("(%s) -> Q.%u results vals.(%s)\n",CMD,basilisktag,retstr);
if ( strcmp(CMD,"GET") == 0 ) if ( strcmp(CMD,"GET") == 0 )
basilisk_geckoresult(myinfo,remoteaddr,retstr,data,datalen); basilisk_geckoresult(myinfo,remoteaddr,retstr,data,datalen);
@ -878,7 +880,7 @@ void basilisks_loop(void *arg)
portable_mutex_lock(&myinfo->basilisk_mutex); portable_mutex_lock(&myinfo->basilisk_mutex);
HASH_ITER(hh,myinfo->basilisks.issued,pending,tmp) HASH_ITER(hh,myinfo->basilisks.issued,pending,tmp)
{ {
if ( pending != 0 && (pending->finished != 0 || OS_milliseconds() > pending->expiration+60) ) if ( pending != 0 && (pending->finished != 0 || OS_milliseconds() > pending->expiration+60000) )
{ {
HASH_DELETE(hh,myinfo->basilisks.issued,pending); HASH_DELETE(hh,myinfo->basilisks.issued,pending);
free(pending); free(pending);

18
basilisk/basilisk_DEX.c

@ -225,17 +225,17 @@ char *basilisk_start(struct supernet_info *myinfo,struct basilisk_request *rp,ui
{ {
cJSON *retjson; //char msgjsonstr[64]; cJSON *retjson; //char msgjsonstr[64];
//sprintf(rp->message,"{\"state\":%u\"}",statebits); //sprintf(rp->message,"{\"state\":%u\"}",statebits);
if ( myinfo->RELAYID >= 0 && (bits256_cmp(rp->hash,myinfo->myaddr.persistent) == 0 || bits256_cmp(rp->desthash,myinfo->myaddr.persistent) == 0) ) if ( myinfo->RELAYID < 0 && (bits256_cmp(rp->hash,myinfo->myaddr.persistent) == 0 || bits256_cmp(rp->desthash,myinfo->myaddr.persistent) == 0) )
{ {
printf("START thread to complete %u/%u for (%s %.8f) <- (%s %.8f) q.%u\n",rp->requestid,rp->quoteid,rp->src,dstr(rp->srcamount),rp->dest,dstr(rp->destamount),rp->quoteid); printf("START thread to complete %u/%u for (%s %.8f) <-> (%s %.8f) q.%u\n",rp->requestid,rp->quoteid,rp->src,dstr(rp->srcamount),rp->dest,dstr(rp->destamount),rp->quoteid);
if ( basilisk_thread_start(myinfo,rp) != 0 ) if ( basilisk_thread_start(myinfo,rp,statebits) != 0 )
{ {
basilisk_request_enqueue(myinfo,rp); basilisk_request_enqueue(myinfo,rp);
return(clonestr("{\"result\":\"started atomic swap thread\"}")); return(clonestr("{\"result\":\"started atomic swap thread\"}"));
} }
else return(clonestr("{\"error\":\"couldnt atomic swap thread\"}")); else return(clonestr("{\"error\":\"couldnt atomic swap thread\"}"));
} }
else if ( myinfo->RELAYID < 0 ) else if ( myinfo->RELAYID >= 0 )
{ {
retjson = cJSON_CreateObject(); retjson = cJSON_CreateObject();
jaddstr(retjson,"result","basilisk node needs to start atomic thread locally"); jaddstr(retjson,"result","basilisk node needs to start atomic thread locally");
@ -572,7 +572,7 @@ INT_ARG(InstantDEX,incoming,requestid)
else else
{ {
vals = cJSON_CreateObject(); vals = cJSON_CreateObject();
jaddnum(vals,"requestid",requestid); jaddnum(vals,"requestid",(uint32_t)requestid);
jaddbits256(vals,"hash",myinfo->myaddr.persistent); jaddbits256(vals,"hash",myinfo->myaddr.persistent);
retstr = basilisk_standardservice("RID",myinfo,0,myinfo->myaddr.persistent,vals,"",1); retstr = basilisk_standardservice("RID",myinfo,0,myinfo->myaddr.persistent,vals,"",1);
free_json(vals); free_json(vals);
@ -589,8 +589,8 @@ TWO_INTS(InstantDEX,swapstatus,requestid,quoteid)
else else
{ {
vals = cJSON_CreateObject(); vals = cJSON_CreateObject();
jaddnum(vals,"requestid",requestid); jaddnum(vals,"requestid",(uint32_t)requestid);
jaddnum(vals,"quoteid",quoteid); jaddnum(vals,"quoteid",(uint32_t)quoteid);
jaddbits256(vals,"hash",myinfo->myaddr.persistent); jaddbits256(vals,"hash",myinfo->myaddr.persistent);
retstr = basilisk_standardservice("SWP",myinfo,0,myinfo->myaddr.persistent,vals,"",1); retstr = basilisk_standardservice("SWP",myinfo,0,myinfo->myaddr.persistent,vals,"",1);
free_json(vals); free_json(vals);
@ -607,8 +607,8 @@ TWO_INTS(InstantDEX,accept,requestid,quoteid)
else else
{ {
vals = cJSON_CreateObject(); vals = cJSON_CreateObject();
jaddnum(vals,"quoteid",quoteid); jaddnum(vals,"quoteid",(uint32_t)quoteid);
jaddnum(vals,"requestid",requestid); jaddnum(vals,"requestid",(uint32_t)requestid);
if ( (retstr= basilisk_standardservice("ACC",myinfo,0,myinfo->myaddr.persistent,vals,"",1)) != 0 ) if ( (retstr= basilisk_standardservice("ACC",myinfo,0,myinfo->myaddr.persistent,vals,"",1)) != 0 )
{ {
/*if ( (retjson= cJSON_Parse(retstr)) != 0 ) /*if ( (retjson= cJSON_Parse(retstr)) != 0 )

16
basilisk/basilisk_swap.c

@ -212,7 +212,7 @@ void basilisk_rawtx_setparms(struct supernet_info *myinfo,struct basilisk_swap *
if ( rawtx->vouttype <= 1 && rawtx->destaddr[0] != 0 ) if ( rawtx->vouttype <= 1 && rawtx->destaddr[0] != 0 )
{ {
rawtx->spendlen = bitcoin_standardspend(rawtx->spendscript,0,rawtx->rmd160); rawtx->spendlen = bitcoin_standardspend(rawtx->spendscript,0,rawtx->rmd160);
if ( vintype == 0 && basilisk_rawtx_gen("setparms",myinfo,swap,1,rawtx,0,rawtx->spendscript,rawtx->spendlen,coin->chain->txfee,1) < 0 ) if ( 0 && vintype == 0 && basilisk_rawtx_gen("setparms",myinfo,swap,1,rawtx,0,rawtx->spendscript,rawtx->spendlen,coin->chain->txfee,1) < 0 )
printf("error generating vintype.%d vouttype.%d -> %s\n",vintype,vouttype,rawtx->destaddr); printf("error generating vintype.%d vouttype.%d -> %s\n",vintype,vouttype,rawtx->destaddr);
} }
} }
@ -289,7 +289,7 @@ struct basilisk_swap *bitcoin_swapinit(struct supernet_info *myinfo,struct basil
swap->otherhash = swap->req.desthash; swap->otherhash = swap->req.desthash;
if ( strcmp(swap->req.src,swap->bobstr) == 0 ) if ( strcmp(swap->req.src,swap->bobstr) == 0 )
swap->iambob = 1; swap->iambob = 1;
else if ( strcmp(swap->req.dest,swap->alicestr) != 0 ) else if ( strcmp(swap->req.dest,swap->alicestr) == 0 )
{ {
printf("neither bob nor alice error\n"); printf("neither bob nor alice error\n");
return(0); return(0);
@ -525,16 +525,12 @@ void basilisk_swaploop(void *_swap)
uint8_t *data; int32_t i,j,maxlen,datalen,numconfirms; struct supernet_info *myinfo; struct basilisk_swap *swap = _swap; uint8_t *data; int32_t i,j,maxlen,datalen,numconfirms; struct supernet_info *myinfo; struct basilisk_swap *swap = _swap;
myinfo = swap->myinfo; myinfo = swap->myinfo;
printf("start swap\n"); printf("start swap\n");
#ifndef __APPLE__
getchar();
#endif
if ( bitcoin_swapinit(myinfo,swap) == 0 ) if ( bitcoin_swapinit(myinfo,swap) == 0 )
{ {
printf("bitcoin_swapinit error\n"); printf("bitcoin_swapinit error\n");
return; return;
} }
printf("back from swapinit\n"); printf("back from swapinit\n");
maxlen = sizeof(*swap); maxlen = sizeof(*swap);
data = malloc(maxlen); data = malloc(maxlen);
while ( time(NULL) < swap->expiration ) while ( time(NULL) < swap->expiration )
@ -706,7 +702,7 @@ getchar();
basilisk_swap_purge(myinfo,swap); basilisk_swap_purge(myinfo,swap);
} }
struct basilisk_swap *basilisk_thread_start(struct supernet_info *myinfo,struct basilisk_request *rp) struct basilisk_swap *basilisk_thread_start(struct supernet_info *myinfo,struct basilisk_request *rp,uint32_t statebits)
{ {
int32_t i; struct basilisk_swap *swap = 0; int32_t i; struct basilisk_swap *swap = 0;
portable_mutex_lock(&myinfo->DEX_swapmutex); portable_mutex_lock(&myinfo->DEX_swapmutex);
@ -721,9 +717,13 @@ struct basilisk_swap *basilisk_thread_start(struct supernet_info *myinfo,struct
swap = calloc(1,sizeof(*swap)); swap = calloc(1,sizeof(*swap));
swap->req = *rp; swap->req = *rp;
swap->myinfo = myinfo; swap->myinfo = myinfo;
swap->statebits = statebits;
printf("START swap requestid.%u\n",rp->requestid); printf("START swap requestid.%u\n",rp->requestid);
//if ( bitcoin_swapinit(myinfo,swap) != 0 )
{
myinfo->swaps[myinfo->numswaps++] = swap; myinfo->swaps[myinfo->numswaps++] = swap;
//iguana_launch(iguana_coinfind("BTCD"),"basilisk_swaploop",basilisk_swaploop,swap,IGUANA_PERMTHREAD); iguana_launch(iguana_coinfind("BTCD"),"basilisk_swaploop",basilisk_swaploop,swap,IGUANA_PERMTHREAD);
}
} }
portable_mutex_unlock(&myinfo->DEX_swapmutex); portable_mutex_unlock(&myinfo->DEX_swapmutex);
return(swap); return(swap);

4
iguana/main.c

@ -1155,10 +1155,10 @@ void iguana_appletests(struct supernet_info *myinfo)
bitcoin_sharedsecret(myinfo->ctx,hash2,pubkey,33); bitcoin_sharedsecret(myinfo->ctx,hash2,pubkey,33);
printf("secp256k1 elapsed %.3f for %d iterations\n",OS_milliseconds() - startmillis,i); printf("secp256k1 elapsed %.3f for %d iterations\n",OS_milliseconds() - startmillis,i);
getchar();**/ getchar();**/
if ( 1 && (str= SuperNET_JSON(myinfo,cJSON_Parse("{\"protover\":70002,\"RELAY\":1,\"VALIDATE\":1,\"portp2p\":14631,\"rpc\":14632,\"agent\":\"iguana\",\"method\":\"addcoin\",\"startpend\":64,\"endpend\":64,\"services\":129,\"maxpeers\":128,\"newcoin\":\"BTCD\",\"active\":1,\"numhelpers\":4,\"poll\":1}"),0,myinfo->rpcport)) != 0 ) if ( 1 && (str= SuperNET_JSON(myinfo,cJSON_Parse("{\"protover\":70002,\"RELAY\":1,\"VALIDATE\":1,\"portp2p\":14631,\"rpc\":14632,\"agent\":\"iguana\",\"method\":\"addcoin\",\"startpend\":64,\"endpend\":64,\"services\":129,\"maxpeers\":8,\"newcoin\":\"BTCD\",\"active\":1,\"numhelpers\":1,\"poll\":1}"),0,myinfo->rpcport)) != 0 )
{ {
free(str); free(str);
if ( 0 && (str= SuperNET_JSON(myinfo,cJSON_Parse("{\"portp2p\":8333,\"RELAY\":0,\"VALIDATE\":0,\"agent\":\"iguana\",\"method\":\"addcoin\",\"startpend\":1,\"endpend\":1,\"services\":128,\"maxpeers\":64,\"newcoin\":\"BTC\",\"active\":0,\"numhelpers\":4,\"poll\":100}"),0,myinfo->rpcport)) != 0 ) if ( 1 && (str= SuperNET_JSON(myinfo,cJSON_Parse("{\"portp2p\":8333,\"RELAY\":0,\"VALIDATE\":0,\"agent\":\"iguana\",\"method\":\"addcoin\",\"startpend\":1,\"endpend\":1,\"services\":128,\"maxpeers\":8,\"newcoin\":\"BTC\",\"active\":0,\"numhelpers\":1,\"poll\":100}"),0,myinfo->rpcport)) != 0 )
{ {
free(str); free(str);
if ( 0 && (str= SuperNET_JSON(myinfo,cJSON_Parse("{\"agent\":\"SuperNET\",\"method\":\"login\",\"handle\":\"alice\",\"password\":\"alice\",\"passphrase\":\"alice\"}"),0,myinfo->rpcport)) != 0 ) if ( 0 && (str= SuperNET_JSON(myinfo,cJSON_Parse("{\"agent\":\"SuperNET\",\"method\":\"login\",\"handle\":\"alice\",\"password\":\"alice\",\"passphrase\":\"alice\"}"),0,myinfo->rpcport)) != 0 )

Loading…
Cancel
Save