|
|
@ -68,12 +68,13 @@ void dex_packet(struct supernet_info *myinfo,struct dex_nanomsghdr *dexp,int32_t |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
struct dex_request { bits256 txid; char name[15]; uint8_t func; }; |
|
|
|
struct dex_request { bits256 hash; int32_t height; char name[15]; uint8_t func; }; |
|
|
|
|
|
|
|
int32_t dex_rwrequest(int32_t rwflag,uint8_t *serialized,struct dex_request *dexreq) |
|
|
|
{ |
|
|
|
int32_t len = 0; |
|
|
|
len += iguana_rwbignum(rwflag,&serialized[len],sizeof(dexreq->txid),dexreq->txid.bytes); |
|
|
|
len += iguana_rwbignum(rwflag,&serialized[len],sizeof(dexreq->hash),dexreq->hash.bytes); |
|
|
|
len += iguana_rwnum(rwflag,&serialized[len],sizeof(dexreq->height),&dexreq->height); |
|
|
|
if ( rwflag != 0 ) |
|
|
|
{ |
|
|
|
memcpy(&serialized[len],dexreq->name,sizeof(dexreq->name)), len += sizeof(dexreq->name); |
|
|
@ -89,18 +90,40 @@ int32_t dex_rwrequest(int32_t rwflag,uint8_t *serialized,struct dex_request *dex |
|
|
|
|
|
|
|
char *dex_response(struct supernet_info *myinfo,struct dex_nanomsghdr *dexp) |
|
|
|
{ |
|
|
|
char *retstr = 0; cJSON *retjson; struct iguana_info *coin; struct dex_request dexreq; |
|
|
|
char buf[65],*retstr = 0; bits256 hash2; cJSON *retjson; struct iguana_info *coin; struct dex_request dexreq; |
|
|
|
if ( strcmp(dexp->handler,"request") == 0 ) |
|
|
|
{ |
|
|
|
dex_rwrequest(0,dexp->packet,&dexreq); |
|
|
|
//printf("dex_response.%s (%c)\n",dexreq.name,dexreq.func);
|
|
|
|
if ( (coin= iguana_coinfind(dexreq.name)) != 0 ) |
|
|
|
{ |
|
|
|
printf("dex_response.%s (%c)\n",dexreq.name,dexreq.func); |
|
|
|
if ( dexreq.func == 'T' ) |
|
|
|
{ |
|
|
|
if ( (retjson= dpow_gettransaction(myinfo,coin,dexreq.txid)) != 0 ) |
|
|
|
if ( (retjson= dpow_gettransaction(myinfo,coin,dexreq.hash)) != 0 ) |
|
|
|
retstr = jprint(retjson,1); |
|
|
|
} |
|
|
|
else if ( dexreq.func == 'H' ) |
|
|
|
{ |
|
|
|
hash2 = dpow_getblockhash(myinfo,coin,dexreq.height); |
|
|
|
bits256_str(buf,hash2); |
|
|
|
retstr = clonestr(buf); |
|
|
|
} |
|
|
|
else if ( dexreq.func == 'B' ) |
|
|
|
{ |
|
|
|
if ( (retjson= dpow_getblock(myinfo,coin,dexreq.hash)) != 0 ) |
|
|
|
retstr = jprint(retjson,1); |
|
|
|
} |
|
|
|
else if ( dexreq.func == 'I' ) |
|
|
|
{ |
|
|
|
if ( (retjson= dpow_getinfo(myinfo,coin)) != 0 ) |
|
|
|
retstr = jprint(retjson,1); |
|
|
|
} |
|
|
|
else if ( dexreq.func == 'P' ) |
|
|
|
{ |
|
|
|
hash2 = dpow_getbestblockhash(myinfo,coin); |
|
|
|
bits256_str(buf,hash2); |
|
|
|
retstr = clonestr(buf); |
|
|
|
} |
|
|
|
} |
|
|
|
if ( retstr == 0 ) |
|
|
|
return(clonestr("{\"error\":\"null return\"}")); |
|
|
@ -164,18 +187,29 @@ char *dex_reqsend(struct supernet_info *myinfo,char *handler,uint8_t *data,int32 |
|
|
|
dexp->version1 = (DEX_VERSION >> 8) & 0xff; |
|
|
|
memcpy(dexp->packet,data,datalen); |
|
|
|
dexp->crc32 = calc_crc32(0,data,datalen); |
|
|
|
sentbytes = nn_send(myinfo->reqsock,dexp,size,0); |
|
|
|
for (i=0; i<100; i++) |
|
|
|
{ |
|
|
|
struct nn_pollfd pfd; |
|
|
|
pfd.fd = myinfo->reqsock; |
|
|
|
pfd.events = NN_POLLOUT; |
|
|
|
if ( nn_poll(&pfd,1,100) > 0 ) |
|
|
|
{ |
|
|
|
sentbytes = nn_send(myinfo->reqsock,dexp,size,0); |
|
|
|
//printf(" sent.%d:%d datalen.%d\n",sentbytes,size,datalen);
|
|
|
|
break; |
|
|
|
} |
|
|
|
usleep(1000); |
|
|
|
} |
|
|
|
//for (i=0; i<datalen; i++)
|
|
|
|
// printf("%02x",((uint8_t *)data)[i]);
|
|
|
|
//printf(" sent.%d:%d datalen.%d\n",sentbytes,size,datalen);
|
|
|
|
if ( (recvbytes= nn_recv(myinfo->reqsock,&retptr,NN_MSG,0)) >= 0 ) |
|
|
|
{ |
|
|
|
//printf("req returned.[%d]\n",recvbytes);
|
|
|
|
portable_mutex_lock(&myinfo->dexmutex); |
|
|
|
if ( strcmp(handler,"DEX") == 0 ) |
|
|
|
{ |
|
|
|
ipbits = *retptr; |
|
|
|
expand_ipbits(ipaddr,ipbits); |
|
|
|
//printf("req returned.[%d] %08x %s\n",recvbytes,*retptr,ipaddr);
|
|
|
|
n = myinfo->numdexipbits; |
|
|
|
for (i=0; i<n; i++) |
|
|
|
if ( ipbits == myinfo->dexipbits[i] ) |
|
|
@ -192,14 +226,14 @@ char *dex_reqsend(struct supernet_info *myinfo,char *handler,uint8_t *data,int32 |
|
|
|
printf("%d: subscribe connect (%s)\n",myinfo->numdexipbits,str); |
|
|
|
} |
|
|
|
} |
|
|
|
nn_connect(myinfo->reqsock,nanomsg_tcpname(0,str,ipaddr,REP_SOCK)); |
|
|
|
//nn_connect(myinfo->reqsock,nanomsg_tcpname(0,str,ipaddr,REP_SOCK));
|
|
|
|
printf("%d: req connect (%s)\n",myinfo->numdexipbits,str); |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
retstr = clonestr((char *)retptr); |
|
|
|
printf("REQ got.%d (%s)\n",recvbytes,retstr); |
|
|
|
//printf("REQ got.%d (%s)\n",recvbytes,retstr);
|
|
|
|
} |
|
|
|
nn_freemsg(retptr); |
|
|
|
portable_mutex_unlock(&myinfo->dexmutex); |
|
|
@ -215,17 +249,59 @@ char *dex_reqsend(struct supernet_info *myinfo,char *handler,uint8_t *data,int32 |
|
|
|
return(retstr); |
|
|
|
} |
|
|
|
|
|
|
|
char *dex_getrawtransaction(struct supernet_info *myinfo,char *symbol,bits256 txid) |
|
|
|
char *_dex_getrawtransaction(struct supernet_info *myinfo,char *symbol,bits256 txid) |
|
|
|
{ |
|
|
|
struct dex_request dexreq; uint8_t packet[sizeof(dexreq)]; int32_t datalen; |
|
|
|
memset(&dexreq,0,sizeof(dexreq)); |
|
|
|
safecopy(dexreq.name,symbol,sizeof(dexreq.name)); |
|
|
|
dexreq.txid = txid; |
|
|
|
dexreq.hash = txid; |
|
|
|
dexreq.func = 'T'; |
|
|
|
datalen = dex_rwrequest(1,packet,&dexreq); |
|
|
|
return(dex_reqsend(myinfo,"request",packet,datalen)); |
|
|
|
} |
|
|
|
|
|
|
|
char *_dex_getinfo(struct supernet_info *myinfo,char *symbol) |
|
|
|
{ |
|
|
|
struct dex_request dexreq; uint8_t packet[sizeof(dexreq)]; int32_t datalen; |
|
|
|
memset(&dexreq,0,sizeof(dexreq)); |
|
|
|
safecopy(dexreq.name,symbol,sizeof(dexreq.name)); |
|
|
|
dexreq.func = 'I'; |
|
|
|
datalen = dex_rwrequest(1,packet,&dexreq); |
|
|
|
return(dex_reqsend(myinfo,"request",packet,datalen)); |
|
|
|
} |
|
|
|
|
|
|
|
char *_dex_getblock(struct supernet_info *myinfo,char *symbol,bits256 hash2) |
|
|
|
{ |
|
|
|
struct dex_request dexreq; uint8_t packet[sizeof(dexreq)]; int32_t datalen; |
|
|
|
memset(&dexreq,0,sizeof(dexreq)); |
|
|
|
safecopy(dexreq.name,symbol,sizeof(dexreq.name)); |
|
|
|
dexreq.hash = hash2; |
|
|
|
dexreq.func = 'B'; |
|
|
|
datalen = dex_rwrequest(1,packet,&dexreq); |
|
|
|
return(dex_reqsend(myinfo,"request",packet,datalen)); |
|
|
|
} |
|
|
|
|
|
|
|
char *_dex_getblockhash(struct supernet_info *myinfo,char *symbol,int32_t height) |
|
|
|
{ |
|
|
|
struct dex_request dexreq; uint8_t packet[sizeof(dexreq)]; int32_t datalen; |
|
|
|
memset(&dexreq,0,sizeof(dexreq)); |
|
|
|
safecopy(dexreq.name,symbol,sizeof(dexreq.name)); |
|
|
|
dexreq.height = height; |
|
|
|
dexreq.func = 'H'; |
|
|
|
datalen = dex_rwrequest(1,packet,&dexreq); |
|
|
|
return(dex_reqsend(myinfo,"request",packet,datalen)); |
|
|
|
} |
|
|
|
|
|
|
|
char *_dex_getbestblockhash(struct supernet_info *myinfo,char *symbol) |
|
|
|
{ |
|
|
|
struct dex_request dexreq; uint8_t packet[sizeof(dexreq)]; int32_t datalen; |
|
|
|
memset(&dexreq,0,sizeof(dexreq)); |
|
|
|
safecopy(dexreq.name,symbol,sizeof(dexreq.name)); |
|
|
|
dexreq.func = 'P'; |
|
|
|
datalen = dex_rwrequest(1,packet,&dexreq); |
|
|
|
return(dex_reqsend(myinfo,"request",packet,datalen)); |
|
|
|
} |
|
|
|
|
|
|
|
int32_t dex_crc32find(struct supernet_info *myinfo,uint32_t crc32) |
|
|
|
{ |
|
|
|
int32_t i,firstz = -1; |
|
|
@ -1081,6 +1157,7 @@ int32_t dpow_nanomsg_update(struct supernet_info *myinfo) |
|
|
|
if ( (size= nn_recv(myinfo->repsock,&dexp,NN_MSG,0)) >= 0 ) |
|
|
|
{ |
|
|
|
num++; |
|
|
|
//printf("REP got %d\n",size);
|
|
|
|
if ( (retstr= dex_response(myinfo,dexp)) != 0 ) |
|
|
|
{ |
|
|
|
nn_send(myinfo->repsock,retstr,(int32_t)strlen(retstr)+1,0); |
|
|
|