|
|
@ -270,13 +270,9 @@ char *dex_response(int32_t *broadcastflagp,struct supernet_info *myinfo,struct d |
|
|
|
else if ( dexreq.func == 'H' ) |
|
|
|
{ |
|
|
|
hash2 = dpow_getblockhash(myinfo,coin,dexreq.intarg); |
|
|
|
printf("getblockhash %d -> (%s)\n",dexreq.intarg,bits256_str(buf,hash2)); |
|
|
|
bits256_str(buf,hash2); |
|
|
|
if ( (retstr= clonestr(buf)) != 0 && (retjson= cJSON_Parse(retstr)) != 0 ) |
|
|
|
{ |
|
|
|
dpow_randipbits(myinfo,coin,retjson); |
|
|
|
free(retstr); |
|
|
|
retstr = jprint(retjson,1); |
|
|
|
} |
|
|
|
retstr = clonestr(buf); |
|
|
|
} |
|
|
|
else if ( dexreq.func == 'B' ) |
|
|
|
{ |
|
|
@ -306,22 +302,11 @@ char *dex_response(int32_t *broadcastflagp,struct supernet_info *myinfo,struct d |
|
|
|
{ |
|
|
|
hash2 = dpow_getbestblockhash(myinfo,coin); |
|
|
|
bits256_str(buf,hash2); |
|
|
|
if ( (retstr= clonestr(buf)) != 0 && (retjson= cJSON_Parse(retstr)) != 0 ) |
|
|
|
{ |
|
|
|
dpow_randipbits(myinfo,coin,retjson); |
|
|
|
free(retstr); |
|
|
|
retstr = jprint(retjson,1); |
|
|
|
} |
|
|
|
retstr = clonestr(buf); |
|
|
|
} |
|
|
|
else if ( dexreq.func == 'S' ) |
|
|
|
{ |
|
|
|
retstr = dpow_sendrawtransaction(myinfo,coin,(char *)&dexp->packet[datalen]); |
|
|
|
if ( retstr != 0 && (retjson= cJSON_Parse(retstr)) != 0 ) |
|
|
|
{ |
|
|
|
dpow_randipbits(myinfo,coin,retjson); |
|
|
|
free(retstr); |
|
|
|
retstr = jprint(retjson,1); |
|
|
|
} |
|
|
|
} |
|
|
|
else if ( dexreq.func == '*' ) |
|
|
|
{ |
|
|
@ -372,15 +357,16 @@ char *dex_response(int32_t *broadcastflagp,struct supernet_info *myinfo,struct d |
|
|
|
return(retstr); |
|
|
|
} |
|
|
|
|
|
|
|
char *dex_reqsend(struct supernet_info *myinfo,char *handler,uint8_t *data,int32_t datalen,int32_t M) |
|
|
|
char *dex_reqsend(struct supernet_info *myinfo,char *handler,uint8_t *data,int32_t datalen,int32_t M,char *field) |
|
|
|
{ |
|
|
|
char *retstrs[64]; int32_t i,j,max = myinfo->numdexipbits; |
|
|
|
char *retstrs[64],*origretstr0 = 0; cJSON *retjson; int32_t err,i,j,max = myinfo->numdexipbits; |
|
|
|
memset(retstrs,0,sizeof(retstrs)); |
|
|
|
for (i=j=0; i<=max; i++) |
|
|
|
{ |
|
|
|
if ( (retstrs[j]= _dex_reqsend(myinfo,handler,data,datalen)) != 0 ) |
|
|
|
{ |
|
|
|
if ( strncmp(retstrs[j],"{\"error\":\"null return\"}",strlen("{\"error\":\"null return\"}")) != 0 && strncmp(retstrs[j],"[]",strlen("[]")) != 0 ) |
|
|
|
printf("j.%d of max.%d (%s)\n",j,max,retstrs[j]); |
|
|
|
if ( strncmp(retstrs[j],"{\"error\":\"null return\"}",strlen("{\"error\":\"null return\"}")) != 0 && strncmp(retstrs[j],"[]",strlen("[]")) != 0 && strcmp("0",retstrs[j]) != 0 ) |
|
|
|
{ |
|
|
|
if ( ++j == M ) |
|
|
|
break; |
|
|
@ -393,24 +379,59 @@ char *dex_reqsend(struct supernet_info *myinfo,char *handler,uint8_t *data,int32 |
|
|
|
if ( j == 1 ) |
|
|
|
return(retstrs[0]); |
|
|
|
else |
|
|
|
{ |
|
|
|
err = 0; |
|
|
|
if ( strcmp(field,"*") != 0 ) |
|
|
|
{ |
|
|
|
for (i=0; i<j; i++) |
|
|
|
{ |
|
|
|
printf("%s ",retstrs[i]); |
|
|
|
if ( (retjson= cJSON_Parse(retstrs[i])) != 0 ) |
|
|
|
{ |
|
|
|
if ( i == 0 ) |
|
|
|
origretstr0 = retstrs[0]; |
|
|
|
else free(retstrs[i]); |
|
|
|
retstrs[i] = jprint(jobj(retjson,field),0); |
|
|
|
free_json(retjson); |
|
|
|
printf("(%s).%d\n",retstrs[i],i); |
|
|
|
} else err++; |
|
|
|
} |
|
|
|
} |
|
|
|
if ( err == 0 ) |
|
|
|
{ |
|
|
|
for (i=1; i<j; i++) |
|
|
|
if ( strcmp(retstrs[0],retstrs[i]) != 0 ) |
|
|
|
{ |
|
|
|
err = 1; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
if ( err != 0 ) |
|
|
|
{ |
|
|
|
for (i=0; i<j; i++) |
|
|
|
free(retstrs[i]); |
|
|
|
retstrs[0] = clonestr("{\"error\":\"couldnt get consensus\"}"); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
free(retstrs[0]); |
|
|
|
retstrs[0] = origretstr0; |
|
|
|
} |
|
|
|
} |
|
|
|
return(retstrs[0]); |
|
|
|
} |
|
|
|
|
|
|
|
char *_dex_sendrequest(struct supernet_info *myinfo,struct dex_request *dexreq,int32_t M) |
|
|
|
char *_dex_sendrequest(struct supernet_info *myinfo,struct dex_request *dexreq,int32_t M,char *field) |
|
|
|
{ |
|
|
|
uint8_t packet[sizeof(*dexreq)]; int32_t datalen; |
|
|
|
if ( iguana_isnotarychain(dexreq->name) >= 0 ) |
|
|
|
{ |
|
|
|
datalen = dex_rwrequest(1,packet,dexreq); |
|
|
|
return(dex_reqsend(myinfo,"request",packet,datalen,M)); |
|
|
|
return(dex_reqsend(myinfo,"request",packet,datalen,M,field)); |
|
|
|
} else return(clonestr("{\"error\":\"not notarychain\"}")); |
|
|
|
} |
|
|
|
|
|
|
|
char *_dex_sendrequeststr(struct supernet_info *myinfo,struct dex_request *dexreq,char *str,int32_t M) |
|
|
|
char *_dex_sendrequeststr(struct supernet_info *myinfo,struct dex_request *dexreq,char *str,int32_t M,char *field) |
|
|
|
{ |
|
|
|
uint8_t *packet; int32_t datalen,slen; char *retstr; |
|
|
|
if ( iguana_isnotarychain(dexreq->name) >= 0 ) |
|
|
@ -420,7 +441,7 @@ char *_dex_sendrequeststr(struct supernet_info *myinfo,struct dex_request *dexre |
|
|
|
datalen = dex_rwrequest(1,packet,dexreq); |
|
|
|
strcpy((char *)&packet[datalen],str); |
|
|
|
datalen += slen; |
|
|
|
retstr = dex_reqsend(myinfo,"request",packet,datalen,M); |
|
|
|
retstr = dex_reqsend(myinfo,"request",packet,datalen,M,field); |
|
|
|
free(packet); |
|
|
|
return(retstr); |
|
|
|
} else return(clonestr("{\"error\":\"not notarychain\"}")); |
|
|
@ -433,7 +454,7 @@ char *_dex_getrawtransaction(struct supernet_info *myinfo,char *symbol,bits256 t |
|
|
|
safecopy(dexreq.name,symbol,sizeof(dexreq.name)); |
|
|
|
dexreq.hash = txid; |
|
|
|
dexreq.func = 'T'; |
|
|
|
return(_dex_sendrequest(myinfo,&dexreq,1)); |
|
|
|
return(_dex_sendrequest(myinfo,&dexreq,1,"")); |
|
|
|
} |
|
|
|
|
|
|
|
char *_dex_gettxout(struct supernet_info *myinfo,char *symbol,bits256 txid,int32_t vout) |
|
|
@ -445,7 +466,7 @@ char *_dex_gettxout(struct supernet_info *myinfo,char *symbol,bits256 txid,int32 |
|
|
|
dexreq.hash = txid; |
|
|
|
dexreq.shortarg = vout; |
|
|
|
dexreq.func = 'O'; |
|
|
|
return(_dex_sendrequest(myinfo,&dexreq,3)); |
|
|
|
return(_dex_sendrequest(myinfo,&dexreq,3,"value")); |
|
|
|
} |
|
|
|
|
|
|
|
char *_dex_getinfo(struct supernet_info *myinfo,char *symbol) |
|
|
@ -454,7 +475,7 @@ char *_dex_getinfo(struct supernet_info *myinfo,char *symbol) |
|
|
|
memset(&dexreq,0,sizeof(dexreq)); |
|
|
|
safecopy(dexreq.name,symbol,sizeof(dexreq.name)); |
|
|
|
dexreq.func = 'I'; |
|
|
|
return(_dex_sendrequest(myinfo,&dexreq,1)); |
|
|
|
return(_dex_sendrequest(myinfo,&dexreq,1,"")); |
|
|
|
} |
|
|
|
|
|
|
|
char *_dex_alladdresses(struct supernet_info *myinfo,char *symbol) |
|
|
@ -463,7 +484,7 @@ char *_dex_alladdresses(struct supernet_info *myinfo,char *symbol) |
|
|
|
memset(&dexreq,0,sizeof(dexreq)); |
|
|
|
safecopy(dexreq.name,symbol,sizeof(dexreq.name)); |
|
|
|
dexreq.func = '*'; |
|
|
|
return(_dex_sendrequest(myinfo,&dexreq,1)); |
|
|
|
return(_dex_sendrequest(myinfo,&dexreq,1,"")); |
|
|
|
} |
|
|
|
|
|
|
|
char *_dex_getblock(struct supernet_info *myinfo,char *symbol,bits256 hash2) |
|
|
@ -473,7 +494,7 @@ char *_dex_getblock(struct supernet_info *myinfo,char *symbol,bits256 hash2) |
|
|
|
safecopy(dexreq.name,symbol,sizeof(dexreq.name)); |
|
|
|
dexreq.hash = hash2; |
|
|
|
dexreq.func = 'B'; |
|
|
|
return(_dex_sendrequest(myinfo,&dexreq,1)); |
|
|
|
return(_dex_sendrequest(myinfo,&dexreq,1,"")); |
|
|
|
} |
|
|
|
|
|
|
|
char *_dex_getblockhash(struct supernet_info *myinfo,char *symbol,int32_t height) |
|
|
@ -483,7 +504,7 @@ char *_dex_getblockhash(struct supernet_info *myinfo,char *symbol,int32_t height |
|
|
|
safecopy(dexreq.name,symbol,sizeof(dexreq.name)); |
|
|
|
dexreq.intarg = height; |
|
|
|
dexreq.func = 'H'; |
|
|
|
return(_dex_sendrequest(myinfo,&dexreq,1)); |
|
|
|
return(_dex_sendrequest(myinfo,&dexreq,3,"*")); |
|
|
|
} |
|
|
|
|
|
|
|
char *_dex_getbestblockhash(struct supernet_info *myinfo,char *symbol) |
|
|
@ -492,7 +513,7 @@ char *_dex_getbestblockhash(struct supernet_info *myinfo,char *symbol) |
|
|
|
memset(&dexreq,0,sizeof(dexreq)); |
|
|
|
safecopy(dexreq.name,symbol,sizeof(dexreq.name)); |
|
|
|
dexreq.func = 'P'; |
|
|
|
return(_dex_sendrequest(myinfo,&dexreq,3)); |
|
|
|
return(_dex_sendrequest(myinfo,&dexreq,1,"")); |
|
|
|
} |
|
|
|
|
|
|
|
char *_dex_sendrawtransaction(struct supernet_info *myinfo,char *symbol,char *signedtx) |
|
|
@ -501,7 +522,7 @@ char *_dex_sendrawtransaction(struct supernet_info *myinfo,char *symbol,char *si |
|
|
|
memset(&dexreq,0,sizeof(dexreq)); |
|
|
|
safecopy(dexreq.name,symbol,sizeof(dexreq.name)); |
|
|
|
dexreq.func = 'S'; |
|
|
|
return(_dex_sendrequeststr(myinfo,&dexreq,signedtx,3)); |
|
|
|
return(_dex_sendrequeststr(myinfo,&dexreq,signedtx,3,"*")); |
|
|
|
} |
|
|
|
|
|
|
|
char *_dex_importaddress(struct supernet_info *myinfo,char *symbol,char *address) |
|
|
@ -510,7 +531,7 @@ char *_dex_importaddress(struct supernet_info *myinfo,char *symbol,char *address |
|
|
|
memset(&dexreq,0,sizeof(dexreq)); |
|
|
|
safecopy(dexreq.name,symbol,sizeof(dexreq.name)); |
|
|
|
dexreq.func = 'A'; |
|
|
|
return(_dex_sendrequeststr(myinfo,&dexreq,address,1)); |
|
|
|
return(_dex_sendrequeststr(myinfo,&dexreq,address,1,"")); |
|
|
|
} |
|
|
|
|
|
|
|
char *_dex_validateaddress(struct supernet_info *myinfo,char *symbol,char *address) |
|
|
@ -519,7 +540,7 @@ char *_dex_validateaddress(struct supernet_info *myinfo,char *symbol,char *addre |
|
|
|
memset(&dexreq,0,sizeof(dexreq)); |
|
|
|
safecopy(dexreq.name,symbol,sizeof(dexreq.name)); |
|
|
|
dexreq.func = 'V'; |
|
|
|
return(_dex_sendrequeststr(myinfo,&dexreq,address,1)); |
|
|
|
return(_dex_sendrequeststr(myinfo,&dexreq,address,1,"")); |
|
|
|
} |
|
|
|
|
|
|
|
char *_dex_listunspent(struct supernet_info *myinfo,char *symbol,char *address) |
|
|
@ -528,7 +549,7 @@ char *_dex_listunspent(struct supernet_info *myinfo,char *symbol,char *address) |
|
|
|
memset(&dexreq,0,sizeof(dexreq)); |
|
|
|
safecopy(dexreq.name,symbol,sizeof(dexreq.name)); |
|
|
|
dexreq.func = 'U'; |
|
|
|
return(_dex_sendrequeststr(myinfo,&dexreq,address,1)); |
|
|
|
return(_dex_sendrequeststr(myinfo,&dexreq,address,1,"")); |
|
|
|
} |
|
|
|
|
|
|
|
char *_dex_listtransactions(struct supernet_info *myinfo,char *symbol,char *address,int32_t count,int32_t skip) |
|
|
@ -539,7 +560,7 @@ char *_dex_listtransactions(struct supernet_info *myinfo,char *symbol,char *addr |
|
|
|
dexreq.intarg = skip; |
|
|
|
dexreq.shortarg = count; |
|
|
|
dexreq.func = 'L'; |
|
|
|
return(_dex_sendrequeststr(myinfo,&dexreq,address,1)); |
|
|
|
return(_dex_sendrequeststr(myinfo,&dexreq,address,1,"")); |
|
|
|
} |
|
|
|
|
|
|
|
int32_t dex_crc32find(struct supernet_info *myinfo,uint32_t crc32) |
|
|
|