|
|
@ -68,69 +68,6 @@ void dex_packet(struct supernet_info *myinfo,struct dex_nanomsghdr *dexp,int32_t |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
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->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); |
|
|
|
serialized[len++] = dexreq->func; |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
memcpy(dexreq->name,&serialized[len],sizeof(dexreq->name)), len += sizeof(dexreq->name); |
|
|
|
dexreq->func = serialized[len++]; |
|
|
|
} |
|
|
|
return(len); |
|
|
|
} |
|
|
|
|
|
|
|
char *dex_response(struct supernet_info *myinfo,struct dex_nanomsghdr *dexp) |
|
|
|
{ |
|
|
|
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 ) |
|
|
|
{ |
|
|
|
if ( dexreq.func == 'T' ) |
|
|
|
{ |
|
|
|
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\"}")); |
|
|
|
} |
|
|
|
return(retstr); |
|
|
|
} |
|
|
|
|
|
|
|
char *dex_reqsend(struct supernet_info *myinfo,char *handler,uint8_t *data,int32_t datalen) |
|
|
|
{ |
|
|
|
struct dex_nanomsghdr *dexp; char ipaddr[64],str[128]; int32_t timeout,i,n,size,recvbytes,sentbytes = 0,reqsock,subsock; uint32_t *retptr,ipbits; char *retstr = 0; |
|
|
@ -249,57 +186,240 @@ char *dex_reqsend(struct supernet_info *myinfo,char *handler,uint8_t *data,int32 |
|
|
|
return(retstr); |
|
|
|
} |
|
|
|
|
|
|
|
struct dex_request { bits256 hash; int32_t intarg; uint16_t shortarg; 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->hash),dexreq->hash.bytes); |
|
|
|
len += iguana_rwnum(rwflag,&serialized[len],sizeof(dexreq->intarg),&dexreq->intarg); |
|
|
|
len += iguana_rwnum(rwflag,&serialized[len],sizeof(dexreq->shortarg),&dexreq->shortarg); |
|
|
|
if ( rwflag != 0 ) |
|
|
|
{ |
|
|
|
memcpy(&serialized[len],dexreq->name,sizeof(dexreq->name)), len += sizeof(dexreq->name); |
|
|
|
serialized[len++] = dexreq->func; |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
memcpy(dexreq->name,&serialized[len],sizeof(dexreq->name)), len += sizeof(dexreq->name); |
|
|
|
dexreq->func = serialized[len++]; |
|
|
|
} |
|
|
|
return(len); |
|
|
|
} |
|
|
|
|
|
|
|
char *dex_response(int32_t *broadcastflagp,struct supernet_info *myinfo,struct dex_nanomsghdr *dexp) |
|
|
|
{ |
|
|
|
char buf[65],*retstr = 0; int32_t datalen; bits256 hash2; cJSON *retjson; struct iguana_info *coin; struct dex_request dexreq; |
|
|
|
*broadcastflagp = 0; |
|
|
|
if ( strcmp(dexp->handler,"request") == 0 ) |
|
|
|
{ |
|
|
|
datalen = dex_rwrequest(0,dexp->packet,&dexreq); |
|
|
|
//printf("dex_response.%s (%c)\n",dexreq.name,dexreq.func);
|
|
|
|
if ( (coin= iguana_coinfind(dexreq.name)) != 0 ) |
|
|
|
{ |
|
|
|
if ( dexreq.func == 'T' ) |
|
|
|
{ |
|
|
|
if ( (retjson= dpow_gettransaction(myinfo,coin,dexreq.hash)) != 0 ) |
|
|
|
retstr = jprint(retjson,1); |
|
|
|
} |
|
|
|
else if ( dexreq.func == 'O' ) |
|
|
|
{ |
|
|
|
if ( (retjson= dpow_gettxout(myinfo,coin,dexreq.hash,dexreq.shortarg)) != 0 ) |
|
|
|
retstr = jprint(retjson,1); |
|
|
|
} |
|
|
|
else if ( dexreq.func == 'H' ) |
|
|
|
{ |
|
|
|
hash2 = dpow_getblockhash(myinfo,coin,dexreq.intarg); |
|
|
|
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 == 'U' ) |
|
|
|
{ |
|
|
|
if ( (retjson= dpow_listunspent(myinfo,coin,(char *)&dexp->packet[datalen])) != 0 ) |
|
|
|
retstr = jprint(retjson,1); |
|
|
|
} |
|
|
|
else if ( dexreq.func == 'P' ) |
|
|
|
{ |
|
|
|
hash2 = dpow_getbestblockhash(myinfo,coin); |
|
|
|
bits256_str(buf,hash2); |
|
|
|
retstr = clonestr(buf); |
|
|
|
} |
|
|
|
else if ( dexreq.func == 'S' ) |
|
|
|
{ |
|
|
|
retstr = dpow_sendrawtransaction(myinfo,coin,(char *)&dexp->packet[datalen]); |
|
|
|
} |
|
|
|
else if ( dexreq.func == '*' ) |
|
|
|
{ |
|
|
|
retstr = dpow_alladdresses(myinfo,coin); |
|
|
|
} |
|
|
|
else if ( dexreq.func == 'L' ) |
|
|
|
{ |
|
|
|
//printf("call list.(%s %d %d)\n",(char *)&dexp->packet[datalen],dexreq.shortarg,dexreq.intarg);
|
|
|
|
if ( (retjson= dpow_listtransactions(myinfo,coin,(char *)&dexp->packet[datalen],dexreq.shortarg,dexreq.intarg)) != 0 ) |
|
|
|
retstr = jprint(retjson,1); |
|
|
|
} |
|
|
|
else if ( dexreq.func == 'A' ) |
|
|
|
{ |
|
|
|
retstr = dpow_importaddress(myinfo,coin,(char *)&dexp->packet[datalen]); |
|
|
|
*broadcastflagp = 1; |
|
|
|
if ( retstr == 0 ) |
|
|
|
retstr = dpow_validateaddress(myinfo,coin,(char *)&dexp->packet[datalen]); |
|
|
|
} |
|
|
|
else if ( dexreq.func == 'V' ) |
|
|
|
{ |
|
|
|
retstr = dpow_validateaddress(myinfo,coin,(char *)&dexp->packet[datalen]); |
|
|
|
} |
|
|
|
} |
|
|
|
if ( retstr == 0 ) |
|
|
|
return(clonestr("{\"error\":\"null return\"}")); |
|
|
|
} |
|
|
|
return(retstr); |
|
|
|
} |
|
|
|
|
|
|
|
char *_dex_sendrequest(struct supernet_info *myinfo,struct dex_request *dexreq) |
|
|
|
{ |
|
|
|
uint8_t packet[sizeof(*dexreq)]; int32_t datalen; |
|
|
|
datalen = dex_rwrequest(1,packet,dexreq); |
|
|
|
return(dex_reqsend(myinfo,"request",packet,datalen)); |
|
|
|
} |
|
|
|
|
|
|
|
char *_dex_sendrequeststr(struct supernet_info *myinfo,struct dex_request *dexreq,char *str) |
|
|
|
{ |
|
|
|
uint8_t *packet; int32_t datalen,slen; char *retstr; |
|
|
|
slen = (int32_t)strlen(str)+1; |
|
|
|
packet = calloc(1,sizeof(*dexreq)+slen); |
|
|
|
datalen = dex_rwrequest(1,packet,dexreq); |
|
|
|
strcpy((char *)&packet[datalen],str); |
|
|
|
datalen += slen; |
|
|
|
retstr = dex_reqsend(myinfo,"request",packet,datalen); |
|
|
|
free(packet); |
|
|
|
return(retstr); |
|
|
|
} |
|
|
|
|
|
|
|
char *_dex_getrawtransaction(struct supernet_info *myinfo,char *symbol,bits256 txid) |
|
|
|
{ |
|
|
|
struct dex_request dexreq; uint8_t packet[sizeof(dexreq)]; int32_t datalen; |
|
|
|
struct dex_request dexreq; |
|
|
|
memset(&dexreq,0,sizeof(dexreq)); |
|
|
|
safecopy(dexreq.name,symbol,sizeof(dexreq.name)); |
|
|
|
dexreq.hash = txid; |
|
|
|
dexreq.func = 'T'; |
|
|
|
datalen = dex_rwrequest(1,packet,&dexreq); |
|
|
|
return(dex_reqsend(myinfo,"request",packet,datalen)); |
|
|
|
return(_dex_sendrequest(myinfo,&dexreq)); |
|
|
|
} |
|
|
|
|
|
|
|
char *_dex_gettxout(struct supernet_info *myinfo,char *symbol,bits256 txid,int32_t vout) |
|
|
|
{ |
|
|
|
struct dex_request dexreq; |
|
|
|
char str[65]; printf("gettxout(%s %s %d)\n",symbol,bits256_str(str,txid),vout); |
|
|
|
memset(&dexreq,0,sizeof(dexreq)); |
|
|
|
safecopy(dexreq.name,symbol,sizeof(dexreq.name)); |
|
|
|
dexreq.hash = txid; |
|
|
|
dexreq.shortarg = vout; |
|
|
|
dexreq.func = 'O'; |
|
|
|
return(_dex_sendrequest(myinfo,&dexreq)); |
|
|
|
} |
|
|
|
|
|
|
|
char *_dex_getinfo(struct supernet_info *myinfo,char *symbol) |
|
|
|
{ |
|
|
|
struct dex_request dexreq; uint8_t packet[sizeof(dexreq)]; int32_t datalen; |
|
|
|
struct dex_request dexreq; |
|
|
|
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)); |
|
|
|
return(_dex_sendrequest(myinfo,&dexreq)); |
|
|
|
} |
|
|
|
|
|
|
|
char *_dex_alladdresses(struct supernet_info *myinfo,char *symbol) |
|
|
|
{ |
|
|
|
struct dex_request dexreq; |
|
|
|
memset(&dexreq,0,sizeof(dexreq)); |
|
|
|
safecopy(dexreq.name,symbol,sizeof(dexreq.name)); |
|
|
|
dexreq.func = '*'; |
|
|
|
return(_dex_sendrequest(myinfo,&dexreq)); |
|
|
|
} |
|
|
|
|
|
|
|
char *_dex_getblock(struct supernet_info *myinfo,char *symbol,bits256 hash2) |
|
|
|
{ |
|
|
|
struct dex_request dexreq; uint8_t packet[sizeof(dexreq)]; int32_t datalen; |
|
|
|
struct dex_request dexreq; |
|
|
|
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)); |
|
|
|
return(_dex_sendrequest(myinfo,&dexreq)); |
|
|
|
} |
|
|
|
|
|
|
|
char *_dex_getblockhash(struct supernet_info *myinfo,char *symbol,int32_t height) |
|
|
|
{ |
|
|
|
struct dex_request dexreq; uint8_t packet[sizeof(dexreq)]; int32_t datalen; |
|
|
|
struct dex_request dexreq; |
|
|
|
memset(&dexreq,0,sizeof(dexreq)); |
|
|
|
safecopy(dexreq.name,symbol,sizeof(dexreq.name)); |
|
|
|
dexreq.height = height; |
|
|
|
dexreq.intarg = height; |
|
|
|
dexreq.func = 'H'; |
|
|
|
datalen = dex_rwrequest(1,packet,&dexreq); |
|
|
|
return(dex_reqsend(myinfo,"request",packet,datalen)); |
|
|
|
return(_dex_sendrequest(myinfo,&dexreq)); |
|
|
|
} |
|
|
|
|
|
|
|
char *_dex_getbestblockhash(struct supernet_info *myinfo,char *symbol) |
|
|
|
{ |
|
|
|
struct dex_request dexreq; uint8_t packet[sizeof(dexreq)]; int32_t datalen; |
|
|
|
struct dex_request dexreq; |
|
|
|
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)); |
|
|
|
return(_dex_sendrequest(myinfo,&dexreq)); |
|
|
|
} |
|
|
|
|
|
|
|
char *_dex_sendrawtransaction(struct supernet_info *myinfo,char *symbol,char *signedtx) |
|
|
|
{ |
|
|
|
struct dex_request dexreq; |
|
|
|
memset(&dexreq,0,sizeof(dexreq)); |
|
|
|
safecopy(dexreq.name,symbol,sizeof(dexreq.name)); |
|
|
|
dexreq.func = 'S'; |
|
|
|
return(_dex_sendrequeststr(myinfo,&dexreq,signedtx)); |
|
|
|
} |
|
|
|
|
|
|
|
char *_dex_importaddress(struct supernet_info *myinfo,char *symbol,char *address) |
|
|
|
{ |
|
|
|
struct dex_request dexreq; |
|
|
|
memset(&dexreq,0,sizeof(dexreq)); |
|
|
|
safecopy(dexreq.name,symbol,sizeof(dexreq.name)); |
|
|
|
dexreq.func = 'A'; |
|
|
|
return(_dex_sendrequeststr(myinfo,&dexreq,address)); |
|
|
|
} |
|
|
|
|
|
|
|
char *_dex_validateaddress(struct supernet_info *myinfo,char *symbol,char *address) |
|
|
|
{ |
|
|
|
struct dex_request dexreq; |
|
|
|
memset(&dexreq,0,sizeof(dexreq)); |
|
|
|
safecopy(dexreq.name,symbol,sizeof(dexreq.name)); |
|
|
|
dexreq.func = 'V'; |
|
|
|
return(_dex_sendrequeststr(myinfo,&dexreq,address)); |
|
|
|
} |
|
|
|
|
|
|
|
char *_dex_listunspent(struct supernet_info *myinfo,char *symbol,char *address) |
|
|
|
{ |
|
|
|
struct dex_request dexreq; |
|
|
|
memset(&dexreq,0,sizeof(dexreq)); |
|
|
|
safecopy(dexreq.name,symbol,sizeof(dexreq.name)); |
|
|
|
dexreq.func = 'U'; |
|
|
|
return(_dex_sendrequeststr(myinfo,&dexreq,address)); |
|
|
|
} |
|
|
|
|
|
|
|
char *_dex_listtransactions(struct supernet_info *myinfo,char *symbol,char *address,int32_t count,int32_t skip) |
|
|
|
{ |
|
|
|
struct dex_request dexreq; |
|
|
|
memset(&dexreq,0,sizeof(dexreq)); |
|
|
|
safecopy(dexreq.name,symbol,sizeof(dexreq.name)); |
|
|
|
dexreq.intarg = skip; |
|
|
|
dexreq.shortarg = count; |
|
|
|
dexreq.func = 'L'; |
|
|
|
return(_dex_sendrequeststr(myinfo,&dexreq,address)); |
|
|
|
} |
|
|
|
|
|
|
|
int32_t dex_crc32find(struct supernet_info *myinfo,uint32_t crc32) |
|
|
@ -1072,7 +1192,7 @@ void dpow_ipbitsadd(struct supernet_info *myinfo,struct dpow_info *dp,uint32_t * |
|
|
|
|
|
|
|
int32_t dpow_nanomsg_update(struct supernet_info *myinfo) |
|
|
|
{ |
|
|
|
int32_t i,n=0,num=0,size,firstz = -1; char *retstr; uint32_t crc32,r,m; struct dpow_nanomsghdr *np=0; struct dpow_info *dp; struct dpow_block *bp; struct dex_nanomsghdr *dexp = 0; |
|
|
|
int32_t i,n=0,num=0,size,broadcastflag,firstz = -1; char *retstr; uint32_t crc32,r,m; struct dpow_nanomsghdr *np=0; struct dpow_info *dp; struct dpow_block *bp; struct dex_nanomsghdr *dexp = 0; |
|
|
|
if ( time(NULL) < myinfo->nanoinit+5 || (myinfo->dpowsock < 0 && myinfo->dexsock < 0 && myinfo->repsock < 0) ) |
|
|
|
return(-1); |
|
|
|
portable_mutex_lock(&myinfo->dpowmutex); |
|
|
@ -1158,10 +1278,15 @@ int32_t dpow_nanomsg_update(struct supernet_info *myinfo) |
|
|
|
{ |
|
|
|
num++; |
|
|
|
//printf("REP got %d\n",size);
|
|
|
|
if ( (retstr= dex_response(myinfo,dexp)) != 0 ) |
|
|
|
if ( (retstr= dex_response(&broadcastflag,myinfo,dexp)) != 0 ) |
|
|
|
{ |
|
|
|
nn_send(myinfo->repsock,retstr,(int32_t)strlen(retstr)+1,0); |
|
|
|
free(retstr); |
|
|
|
if ( broadcastflag != 0 ) |
|
|
|
{ |
|
|
|
printf("BROADCAST dexp request.[%d]\n",size); |
|
|
|
nn_send(myinfo->dexsock,dexp,size,0); |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|