|
@ -13,9 +13,6 @@ |
|
|
* * |
|
|
* * |
|
|
******************************************************************************/ |
|
|
******************************************************************************/ |
|
|
|
|
|
|
|
|
// 1. add rpc hooks, debug
|
|
|
|
|
|
// 2. sig validate in fsm
|
|
|
|
|
|
|
|
|
|
|
|
struct signed_nnpacket |
|
|
struct signed_nnpacket |
|
|
{ |
|
|
{ |
|
|
uint8_t sig64[64]; |
|
|
uint8_t sig64[64]; |
|
@ -52,10 +49,10 @@ int32_t signed_nn_send(void *ctx,bits256 privkey,int32_t sock,void *packet,int32 |
|
|
} |
|
|
} |
|
|
return(-1); |
|
|
return(-1); |
|
|
} |
|
|
} |
|
|
//dex* api
|
|
|
|
|
|
int32_t signed_nn_recv(void **freeptrp,void *ctx,struct dpow_entry *notaries,int32_t n,int32_t sock,void *packetp) |
|
|
int32_t signed_nn_recv(void **freeptrp,void *ctx,uint8_t notaries[64][33],int32_t n,int32_t sock,void *packetp) |
|
|
{ |
|
|
{ |
|
|
int32_t i,recvbytes; uint8_t pubkey33[33]; bits256 packethash; struct signed_nnpacket *sigpacket=0; |
|
|
int32_t i,recvbytes; uint8_t pubkey33[33],pubkey0[33]; bits256 packethash; struct signed_nnpacket *sigpacket=0; |
|
|
*(void **)packetp = 0; |
|
|
*(void **)packetp = 0; |
|
|
*freeptrp = 0; |
|
|
*freeptrp = 0; |
|
|
recvbytes = nn_recv(sock,&sigpacket,NN_MSG,0); |
|
|
recvbytes = nn_recv(sock,&sigpacket,NN_MSG,0); |
|
@ -66,9 +63,19 @@ int32_t signed_nn_recv(void **freeptrp,void *ctx,struct dpow_entry *notaries,int |
|
|
{ |
|
|
{ |
|
|
if ( bitcoin_recoververify(ctx,"nnrecv",sigpacket->sig64,sigpacket->packethash,pubkey33,33) == 0 ) |
|
|
if ( bitcoin_recoververify(ctx,"nnrecv",sigpacket->sig64,sigpacket->packethash,pubkey33,33) == 0 ) |
|
|
{ |
|
|
{ |
|
|
for (i=0; i<n; i++) |
|
|
char *notary0 = "03b7621b44118017a16043f19b30cc8a4cfe068ac4e42417bae16ba460c80f3828"; |
|
|
|
|
|
// expand to official notaries
|
|
|
|
|
|
decode_hex(pubkey0,33,notary0); |
|
|
|
|
|
if ( memcmp(pubkey0,pubkey33,33) == 0 ) |
|
|
|
|
|
{ |
|
|
|
|
|
*(void **)packetp = (void **)((uint64_t)sigpacket + sizeof(*sigpacket)); |
|
|
|
|
|
*freeptrp = sigpacket; |
|
|
|
|
|
//printf("got signed packet from notary0\n");
|
|
|
|
|
|
return((int32_t)(recvbytes - sizeof(*sigpacket))); |
|
|
|
|
|
} |
|
|
|
|
|
for (i=0; i<n && i<64; i++) |
|
|
{ |
|
|
{ |
|
|
if ( memcmp(pubkey33,notaries[i].pubkey,33) == 0 ) |
|
|
if ( memcmp(pubkey33,notaries[i],33) == 0 ) |
|
|
{ |
|
|
{ |
|
|
*(void **)packetp = (void **)((uint64_t)sigpacket + sizeof(*sigpacket)); |
|
|
*(void **)packetp = (void **)((uint64_t)sigpacket + sizeof(*sigpacket)); |
|
|
//printf("got signed packet from notary.%d\n",i);
|
|
|
//printf("got signed packet from notary.%d\n",i);
|
|
@ -79,7 +86,7 @@ int32_t signed_nn_recv(void **freeptrp,void *ctx,struct dpow_entry *notaries,int |
|
|
{ |
|
|
{ |
|
|
int32_t j; |
|
|
int32_t j; |
|
|
for (j=0; j<33; j++) |
|
|
for (j=0; j<33; j++) |
|
|
printf("%02x",notaries[i].pubkey[j]); |
|
|
printf("%02x",notaries[i][j]); |
|
|
printf(" pubkey[%d]\n",i); |
|
|
printf(" pubkey[%d]\n",i); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
@ -253,7 +260,7 @@ char *_dex_reqsend(struct supernet_info *myinfo,char *handler,uint8_t *data,int3 |
|
|
// printf("%02x",((uint8_t *)data)[i]);
|
|
|
// printf("%02x",((uint8_t *)data)[i]);
|
|
|
if ( (recvbytes= signed_nn_recv(&freeptr,myinfo->ctx,myinfo->notaries,myinfo->numnotaries,myinfo->reqsock,&retptr)) >= 0 ) |
|
|
if ( (recvbytes= signed_nn_recv(&freeptr,myinfo->ctx,myinfo->notaries,myinfo->numnotaries,myinfo->reqsock,&retptr)) >= 0 ) |
|
|
{ |
|
|
{ |
|
|
printf("req returned.[%d]\n",recvbytes); |
|
|
//printf("req returned.[%d]\n",recvbytes);
|
|
|
portable_mutex_lock(&myinfo->dexmutex); |
|
|
portable_mutex_lock(&myinfo->dexmutex); |
|
|
ipbits = 0; |
|
|
ipbits = 0; |
|
|
if ( strcmp(handler,"DEX") == 0 ) |
|
|
if ( strcmp(handler,"DEX") == 0 ) |
|
@ -261,6 +268,7 @@ char *_dex_reqsend(struct supernet_info *myinfo,char *handler,uint8_t *data,int3 |
|
|
else if ( retptr != 0 ) |
|
|
else if ( retptr != 0 ) |
|
|
{ |
|
|
{ |
|
|
retstr = clonestr((char *)retptr); |
|
|
retstr = clonestr((char *)retptr); |
|
|
|
|
|
//printf("GOT.(%s)\n",retstr);
|
|
|
if ( (retjson= cJSON_Parse(retstr)) != 0 ) |
|
|
if ( (retjson= cJSON_Parse(retstr)) != 0 ) |
|
|
{ |
|
|
{ |
|
|
ipbits = juint(retjson,"randipbits"); |
|
|
ipbits = juint(retjson,"randipbits"); |
|
@ -325,7 +333,7 @@ void dpow_randipbits(struct supernet_info *myinfo,struct iguana_info *coin,cJSON |
|
|
|
|
|
|
|
|
char *dex_response(int32_t *broadcastflagp,struct supernet_info *myinfo,struct dex_nanomsghdr *dexp) |
|
|
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; |
|
|
char buf[65],*retstr = 0; int32_t i,datalen; bits256 hash2; cJSON *retjson=0; struct iguana_info *coin; struct dex_request dexreq; |
|
|
*broadcastflagp = 0; |
|
|
*broadcastflagp = 0; |
|
|
if ( strcmp(dexp->handler,"request") == 0 ) |
|
|
if ( strcmp(dexp->handler,"request") == 0 ) |
|
|
{ |
|
|
{ |
|
@ -432,6 +440,36 @@ char *dex_response(int32_t *broadcastflagp,struct supernet_info *myinfo,struct d |
|
|
retstr = jprint(retjson,1); |
|
|
retstr = jprint(retjson,1); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
else if ( dexreq.func == 'N' ) |
|
|
|
|
|
{ |
|
|
|
|
|
uint8_t pubkeys[64][33]; char str[128]; int32_t numnotaries; cJSON *array,*item; |
|
|
|
|
|
if ( (numnotaries= komodo_notaries("KMD",pubkeys,-1)) > 0 && numnotaries <= 64 ) |
|
|
|
|
|
{ |
|
|
|
|
|
retjson = cJSON_CreateObject(); |
|
|
|
|
|
array = cJSON_CreateArray(); |
|
|
|
|
|
for (i=0; i<numnotaries; i++) |
|
|
|
|
|
{ |
|
|
|
|
|
item = cJSON_CreateObject(); |
|
|
|
|
|
init_hexbytes_noT(str,pubkeys[i],33); |
|
|
|
|
|
jaddstr(item,"pubkey",str); |
|
|
|
|
|
//printf("[%s %d] ",str,i);
|
|
|
|
|
|
bitcoin_address(str,0,pubkeys[i],33); |
|
|
|
|
|
jaddstr(item,"BTCaddress",str); |
|
|
|
|
|
bitcoin_address(str,60,pubkeys[i],33); |
|
|
|
|
|
jaddstr(item,"KMDaddress",str); |
|
|
|
|
|
jaddi(array,item); |
|
|
|
|
|
} |
|
|
|
|
|
jadd(retjson,"notaries",array); |
|
|
|
|
|
jaddnum(retjson,"numnotaries",numnotaries); |
|
|
|
|
|
//printf("numnotaries.%d\n",numnotaries);
|
|
|
|
|
|
} |
|
|
|
|
|
if ( retjson != 0 ) |
|
|
|
|
|
{ |
|
|
|
|
|
dpow_randipbits(myinfo,coin,retjson); |
|
|
|
|
|
retstr = jprint(retjson,1); |
|
|
|
|
|
} |
|
|
|
|
|
//printf("DEX NOTARIES -> (%s)\n",retstr);
|
|
|
|
|
|
} |
|
|
} else printf("(%s) not active\n",dexreq.name); |
|
|
} else printf("(%s) not active\n",dexreq.name); |
|
|
if ( retstr == 0 ) |
|
|
if ( retstr == 0 ) |
|
|
return(clonestr("{\"error\":\"null return\"}")); |
|
|
return(clonestr("{\"error\":\"null return\"}")); |
|
@ -447,7 +485,7 @@ char *dex_reqsend(struct supernet_info *myinfo,char *handler,uint8_t *data,int32 |
|
|
{ |
|
|
{ |
|
|
if ( (retstrs[j]= _dex_reqsend(myinfo,handler,data,datalen)) != 0 ) |
|
|
if ( (retstrs[j]= _dex_reqsend(myinfo,handler,data,datalen)) != 0 ) |
|
|
{ |
|
|
{ |
|
|
//printf("j.%d of max.%d (%s)\n",j,max,retstrs[j]);
|
|
|
//printf("j.%d of max.%d M.%d (%s)\n",j,max,M,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 ( strncmp(retstrs[j],"{\"error\":\"null return\"}",strlen("{\"error\":\"null return\"}")) != 0 && strncmp(retstrs[j],"[]",strlen("[]")) != 0 && strcmp("0",retstrs[j]) != 0 ) |
|
|
{ |
|
|
{ |
|
|
if ( ++j == M ) |
|
|
if ( ++j == M ) |
|
@ -459,7 +497,10 @@ char *dex_reqsend(struct supernet_info *myinfo,char *handler,uint8_t *data,int32 |
|
|
//printf("automatic retry.%d of %d\n",i,max);
|
|
|
//printf("automatic retry.%d of %d\n",i,max);
|
|
|
} |
|
|
} |
|
|
if ( j == 1 ) |
|
|
if ( j == 1 ) |
|
|
|
|
|
{ |
|
|
|
|
|
//printf("return.(%s)\n",retstrs[0]);
|
|
|
return(retstrs[0]); |
|
|
return(retstrs[0]); |
|
|
|
|
|
} |
|
|
else if ( j >= M ) |
|
|
else if ( j >= M ) |
|
|
{ |
|
|
{ |
|
|
origretstr0 = retstrs[0]; |
|
|
origretstr0 = retstrs[0]; |
|
@ -568,6 +609,31 @@ char *_dex_getinfo(struct supernet_info *myinfo,char *symbol) |
|
|
return(_dex_sendrequest(myinfo,&dexreq,1,"")); |
|
|
return(_dex_sendrequest(myinfo,&dexreq,1,"")); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
int32_t _dex_getheight(struct supernet_info *myinfo,char *symbol) |
|
|
|
|
|
{ |
|
|
|
|
|
char *retstr; cJSON *retjson; int32_t height = -1; |
|
|
|
|
|
if ( (retstr= _dex_getinfo(myinfo,symbol)) != 0 ) |
|
|
|
|
|
{ |
|
|
|
|
|
if ( (retjson= cJSON_Parse(retstr)) != 0 ) |
|
|
|
|
|
{ |
|
|
|
|
|
height = jint(retjson,"blocks") - 1; |
|
|
|
|
|
free_json(retjson); |
|
|
|
|
|
} |
|
|
|
|
|
free(retstr); |
|
|
|
|
|
} |
|
|
|
|
|
return(height); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
char *_dex_getnotaries(struct supernet_info *myinfo,char *symbol) |
|
|
|
|
|
{ |
|
|
|
|
|
struct dex_request dexreq; |
|
|
|
|
|
memset(&dexreq,0,sizeof(dexreq)); |
|
|
|
|
|
safecopy(dexreq.name,symbol,sizeof(dexreq.name)); |
|
|
|
|
|
dexreq.func = 'N'; |
|
|
|
|
|
dexreq.intarg = -1; |
|
|
|
|
|
return(_dex_sendrequest(myinfo,&dexreq,1,"")); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
char *_dex_alladdresses(struct supernet_info *myinfo,char *symbol) |
|
|
char *_dex_alladdresses(struct supernet_info *myinfo,char *symbol) |
|
|
{ |
|
|
{ |
|
|
struct dex_request dexreq; |
|
|
struct dex_request dexreq; |
|
@ -1483,6 +1549,11 @@ int32_t dpow_nanomsg_update(struct supernet_info *myinfo) |
|
|
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; void *freeptr; |
|
|
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; void *freeptr; |
|
|
if ( time(NULL) < myinfo->nanoinit+5 || (myinfo->dpowsock < 0 && myinfo->dexsock < 0 && myinfo->repsock < 0) ) |
|
|
if ( time(NULL) < myinfo->nanoinit+5 || (myinfo->dpowsock < 0 && myinfo->dexsock < 0 && myinfo->repsock < 0) ) |
|
|
return(-1); |
|
|
return(-1); |
|
|
|
|
|
if ( myinfo->IAMNOTARY != 0 && myinfo->numnotaries <= 0 ) |
|
|
|
|
|
{ |
|
|
|
|
|
myinfo->numnotaries = komodo_notaries("KMD",myinfo->notaries,-1); |
|
|
|
|
|
printf("INIT with %d notaries\n",myinfo->numnotaries); |
|
|
|
|
|
} |
|
|
portable_mutex_lock(&myinfo->dpowmutex); |
|
|
portable_mutex_lock(&myinfo->dpowmutex); |
|
|
/*for (i=0; i<100; i++)
|
|
|
/*for (i=0; i<100; i++)
|
|
|
{ |
|
|
{ |
|
|