Browse Source

test

release/v0.1
jl777 9 years ago
parent
commit
253057d915
  1. 2
      basilisk/basilisk.c
  2. 8
      basilisk/basilisk_MSG.c
  3. 23
      basilisk/basilisk_swap.c
  4. 2
      iguana/tests/decoderawtransaction

2
basilisk/basilisk.c

@ -644,7 +644,7 @@ void basilisk_msgprocess(struct supernet_info *myinfo,void *_addr,uint32_t sende
CMD[i] = toupper((int32_t)CMD[i]); CMD[i] = toupper((int32_t)CMD[i]);
cmd[i] = tolower((int32_t)CMD[i]); cmd[i] = tolower((int32_t)CMD[i]);
} }
if ( 1 && strcmp(CMD,"RID") != 0 && strcmp(CMD,"MSG") != 0 ) if ( 0 && strcmp(CMD,"RID") != 0 && strcmp(CMD,"MSG") != 0 )
printf("MSGPROCESS %s.(%s) tag.%d\n",CMD,(char *)data,basilisktag); printf("MSGPROCESS %s.(%s) tag.%d\n",CMD,(char *)data,basilisktag);
myinfo->basilisk_busy = 1; myinfo->basilisk_busy = 1;
if ( valsobj != 0 ) if ( valsobj != 0 )

8
basilisk/basilisk_MSG.c

@ -42,7 +42,7 @@ int32_t basilisk_ping_processMSG(struct supernet_info *myinfo,uint32_t senderipb
int32_t i,msglen,len=0; uint8_t num,keylen,*msg,*key; int32_t i,msglen,len=0; uint8_t num,keylen,*msg,*key;
if ( (num= data[len++]) > 0 ) if ( (num= data[len++]) > 0 )
{ {
printf("processMSG num.%d datalen.%d\n",num,datalen); //printf("processMSG num.%d datalen.%d\n",num,datalen);
for (i=0; i<num; i++) for (i=0; i<num; i++)
{ {
keylen = data[len++]; keylen = data[len++];
@ -64,7 +64,7 @@ int32_t basilisk_ping_processMSG(struct supernet_info *myinfo,uint32_t senderipb
printf("illegal msglen.%d or len.%d > %d\n",msglen,len,datalen); printf("illegal msglen.%d or len.%d > %d\n",msglen,len,datalen);
return(0); return(0);
} }
printf("i.%d: keylen.%d msglen.%d\n",i,keylen,msglen); //printf("i.%d: keylen.%d msglen.%d\n",i,keylen,msglen);
basilisk_respond_addmessage(myinfo,key,keylen,msg,msglen,0); basilisk_respond_addmessage(myinfo,key,keylen,msg,msglen,0);
} }
} }
@ -82,7 +82,7 @@ int32_t basilisk_ping_genMSG(struct supernet_info *myinfo,uint8_t *data,int32_t
datalen += iguana_rwnum(1,&data[datalen],sizeof(msg->datalen),&msg->datalen); datalen += iguana_rwnum(1,&data[datalen],sizeof(msg->datalen),&msg->datalen);
if ( maxlen > datalen+msg->datalen ) if ( maxlen > datalen+msg->datalen )
{ {
printf("SEND keylen.%d msglen.%d\n",msg->keylen,msg->datalen); //printf("SEND keylen.%d msglen.%d\n",msg->keylen,msg->datalen);
memcpy(&data[datalen],msg->data,msg->datalen), datalen += msg->datalen; memcpy(&data[datalen],msg->data,msg->datalen), datalen += msg->datalen;
} }
else else
@ -213,7 +213,7 @@ int32_t basilisk_message_returned(uint8_t *data,int32_t maxlen,cJSON *item)
if ( datalen < maxlen ) if ( datalen < maxlen )
{ {
decode_hex(data,datalen,hexstr); decode_hex(data,datalen,hexstr);
printf("decoded hexstr.[%d]\n",datalen); //printf("decoded hexstr.[%d]\n",datalen);
retval = datalen; retval = datalen;
} else printf("datalen.%d < maxlen.%d\n",datalen,maxlen); } else printf("datalen.%d < maxlen.%d\n",datalen,maxlen);
} else printf("no hexstr.%p or datalen.%d\n",hexstr,datalen); } else printf("no hexstr.%p or datalen.%d\n",hexstr,datalen);

23
basilisk/basilisk_swap.c

@ -53,7 +53,7 @@
Alice timeout event is triggered if INSTANTDEX_LOCKTIME elapses from the start of a FSM instance. Bob timeout event is triggered after INSTANTDEX_LOCKTIME*2 Alice timeout event is triggered if INSTANTDEX_LOCKTIME elapses from the start of a FSM instance. Bob timeout event is triggered after INSTANTDEX_LOCKTIME*2
*/ */
//#define BASILISK_DISABLETX #define BASILISK_DISABLETX
#define SCRIPT_OP_IF 0x63 #define SCRIPT_OP_IF 0x63
#define SCRIPT_OP_ELSE 0x67 #define SCRIPT_OP_ELSE 0x67
#define SCRIPT_OP_ENDIF 0x68 #define SCRIPT_OP_ENDIF 0x68
@ -164,14 +164,16 @@ bits256 basilisk_swap_broadcast(char *name,struct supernet_info *myinfo,struct b
memset(txid.bytes,0,sizeof(txid)); memset(txid.bytes,0,sizeof(txid));
if ( data != 0 && datalen != 0 ) if ( data != 0 && datalen != 0 )
{ {
char str[65];
#ifdef BASILISK_DISABLETX #ifdef BASILISK_DISABLETX
txid = bits256_doublesha256(0,data,datalen); txid = bits256_doublesha256(0,data,datalen);
printf("%s <- dont sendrawtransaction (%s)\n",name,bits256_str(str,txid));
return(txid); return(txid);
#endif #endif
signedtx = malloc(datalen*2 + 1); signedtx = malloc(datalen*2 + 1);
init_hexbytes_noT(signedtx,data,datalen); init_hexbytes_noT(signedtx,data,datalen);
txid = iguana_sendrawtransaction(myinfo,coin,signedtx); txid = iguana_sendrawtransaction(myinfo,coin,signedtx);
char str[65]; printf("%s <- sendrawtransaction %s.(%s)\n",name,signedtx,bits256_str(str,txid)); printf("%s <- sendrawtransaction %s.(%s)\n",name,signedtx,bits256_str(str,txid));
free(signedtx); free(signedtx);
} }
return(txid); return(txid);
@ -1026,12 +1028,13 @@ void basilisk_alicepayment(struct supernet_info *myinfo,struct iguana_info *coin
void basilisk_swaploop(void *_swap) void basilisk_swaploop(void *_swap)
{ {
uint8_t *data; int32_t retval=0,i,j,maxlen,datalen; struct supernet_info *myinfo; struct basilisk_swap *swap = _swap; uint8_t *data; uint32_t expiration; int32_t retval=0,i,j,maxlen,datalen; struct supernet_info *myinfo; struct basilisk_swap *swap = _swap;
myinfo = swap->myinfo; myinfo = swap->myinfo;
fprintf(stderr,"start swap\n"); fprintf(stderr,"start swap\n");
maxlen = 1024*1024 + sizeof(*swap); maxlen = 1024*1024 + sizeof(*swap);
data = malloc(maxlen); data = malloc(maxlen);
while ( time(NULL) < swap->expiration ) expiration = (uint32_t)time(NULL) + 300;
while ( time(NULL) < expiration )
{ {
printf("A r%u/q%u swapstate.%x\n",swap->req.requestid,swap->req.quoteid,swap->statebits); printf("A r%u/q%u swapstate.%x\n",swap->req.requestid,swap->req.quoteid,swap->statebits);
basilisk_sendpubkeys(myinfo,swap,data,maxlen); // send pubkeys basilisk_sendpubkeys(myinfo,swap,data,maxlen); // send pubkeys
@ -1043,7 +1046,7 @@ void basilisk_swaploop(void *_swap)
break; break;
sleep(1); sleep(1);
} }
while ( time(NULL) < swap->expiration ) while ( time(NULL) < expiration )
{ {
printf("B r%u/q%u swapstate.%x\n",swap->req.requestid,swap->req.quoteid,swap->statebits); printf("B r%u/q%u swapstate.%x\n",swap->req.requestid,swap->req.quoteid,swap->statebits);
basilisk_sendmostprivs(myinfo,swap,data,maxlen); basilisk_sendmostprivs(myinfo,swap,data,maxlen);
@ -1054,8 +1057,10 @@ void basilisk_swaploop(void *_swap)
} }
sleep(1); sleep(1);
} }
if ( time(NULL) >= expiration )
retval = -9;
printf("C r%u/q%u swapstate.%x\n",swap->req.requestid,swap->req.quoteid,swap->statebits); printf("C r%u/q%u swapstate.%x\n",swap->req.requestid,swap->req.quoteid,swap->statebits);
if ( (swap->statebits & 0x40) == 0 ) // send fee if ( retval == 0 && (swap->statebits & 0x40) == 0 ) // send fee
{ {
if ( swap->myfee.txbytes == 0 ) if ( swap->myfee.txbytes == 0 )
{ {
@ -1137,6 +1142,8 @@ void basilisk_swaploop(void *_swap)
} }
while ( retval == 0 && time(NULL) < swap->expiration ) // both sides have setup required data and paid txfee while ( retval == 0 && time(NULL) < swap->expiration ) // both sides have setup required data and paid txfee
{ {
basilisk_sendstate(myinfo,swap,data,maxlen);
basilisk_swapget(myinfo,swap,0x80000000,data,maxlen,basilisk_verify_otherstatebits);
printf("E r%u/q%u swapstate.%x otherstate.%x\n",swap->req.requestid,swap->req.quoteid,swap->statebits,swap->otherstatebits); printf("E r%u/q%u swapstate.%x otherstate.%x\n",swap->req.requestid,swap->req.quoteid,swap->statebits,swap->otherstatebits);
if ( swap->iambob != 0 ) if ( swap->iambob != 0 )
{ {
@ -1312,8 +1319,8 @@ void basilisk_swaploop(void *_swap)
} }
} }
} }
printf("finished swapstate.%x\n",swap->statebits); //printf("finished swapstate.%x\n",swap->statebits);
sleep(3); sleep(30);
} }
if ( swap->iambob != 0 ) if ( swap->iambob != 0 )
{ {

2
iguana/tests/decoderawtransaction

@ -1 +1 @@
curl --url "http://127.0.0.1:7778" --data "{\"coin\":\"BTCD\",\"method\":\"decoderawtransaction\",\"params\":[\"010000000132a253010000000000000000000000000000000000000000000000000000000000000000ffffffff4100012a3d3138204a756e652032303134202d204269746f696e20796f75722077617920746f206120646f75626c6520657370726573736f202d20636e6e2e636f6dffffffff010000000000000000000000000000\"]}" curl --url "http://127.0.0.1:7778" --data "{\"coin\":\"BTCD\",\"method\":\"decoderawtransaction\",\"params\":[\"01000000ed90a05701f027ab1d26989537b26c46ac627b201856953dabfa80fff0cb130562f6f2aae6010000006a473044022030890a0f9ac78c5064e2424360f34bae9bf4a37210285877f6942988210c23800220505750ab15cc32b6417a4a80c4f3daca26397095b30ee6f11a631da51a02e8030121020ce8ffc263769bfa15579b2757873ea5690107acfafb6dc1b77cd7057ac38349ffffffff02809698000000000047522102cc92c413b0eb7656936cc3b7c3c22a7e411de7dd4cf9d33f3cb886b6e3652bf72103c5556a290b9b66b90e4730a99581b037c71999829ae54353321c37bb8d9e03fe52aee08ded03000000001976a91421e112f4211cbc612bc5f3de86acf0017b88b67d88ac00000000\"]}"

Loading…
Cancel
Save