Browse Source

Merge pull request #195 from jl777/dev

Dev
win-cross
jl777 8 years ago
committed by GitHub
parent
commit
7f59b74bf4
  1. 3
      iguana/dPoW.h
  2. 2
      iguana/dpow/dpow_fsm.c
  3. 95
      iguana/dpow/dpow_network.c
  4. 60
      iguana/dpow/dpow_rpc.c
  5. 2
      iguana/iguana777.c
  6. 2
      iguana/iguana777.h
  7. 6
      iguana/iguana_notary.c
  8. 25
      iguana/main.c
  9. 2
      iguana/tests/dexnotaries
  10. 1
      includes/iguana_apideclares.h

3
iguana/dPoW.h

@ -178,5 +178,8 @@ char *_dex_validateaddress(struct supernet_info *myinfo,char *symbol,char *addre
char *_dex_listunspent(struct supernet_info *myinfo,char *symbol,char *address); char *_dex_listunspent(struct supernet_info *myinfo,char *symbol,char *address);
char *_dex_listtransactions(struct supernet_info *myinfo,char *symbol,char *coinaddr,int32_t count,int32_t skip); char *_dex_listtransactions(struct supernet_info *myinfo,char *symbol,char *coinaddr,int32_t count,int32_t skip);
char *_dex_alladdresses(struct supernet_info *myinfo,char *symbol); char *_dex_alladdresses(struct supernet_info *myinfo,char *symbol);
int32_t _dex_getheight(struct supernet_info *myinfo,char *symbol);
char *_dex_getnotaries(struct supernet_info *myinfo,char *symbol);
int32_t komodo_notaries(char *symbol,uint8_t pubkeys[64][33],int32_t height);
#endif #endif

2
iguana/dpow/dpow_fsm.c

@ -293,7 +293,7 @@ void dpow_statemachinestart(void *ptr)
//printf(" <= pubkey[%d]\n",i); //printf(" <= pubkey[%d]\n",i);
memcpy(bp->notaries[i].pubkey,pubkeys[i],33); memcpy(bp->notaries[i].pubkey,pubkeys[i],33);
if ( strcmp("KMD",src->symbol) == 0 ) if ( strcmp("KMD",src->symbol) == 0 )
memcpy(myinfo->notaries[i].pubkey,pubkeys[i],33); memcpy(myinfo->notaries[i],pubkeys[i],33);
if ( memcmp(bp->notaries[i].pubkey,dp->minerkey33,33) == 0 ) if ( memcmp(bp->notaries[i].pubkey,dp->minerkey33,33) == 0 )
{ {
myind = i; myind = i;

95
iguana/dpow/dpow_network.c

@ -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++)
{ {

60
iguana/dpow/dpow_rpc.c

@ -15,11 +15,45 @@
#define issue_curl(cmdstr) bitcoind_RPC(0,"curl",cmdstr,0,0,0) #define issue_curl(cmdstr) bitcoind_RPC(0,"curl",cmdstr,0,0,0)
cJSON *dpow_getinfo(struct supernet_info *myinfo,struct iguana_info *coin)
{
char buf[128],*retstr=0; cJSON *json = 0;
if ( coin->FULLNODE < 0 )
{
buf[0] = 0;
retstr = bitcoind_passthru(coin->symbol,coin->chain->serverport,coin->chain->userpass,"getinfo",buf);
usleep(10000);
}
else if ( coin->FULLNODE > 0 || coin->VALIDATENODE > 0 )
{
retstr = bitcoinrpc_getinfo(myinfo,coin,0,0);
}
else
{
return(0);
}
if ( retstr != 0 )
{
json = cJSON_Parse(retstr);
free(retstr);
}
return(json);
}
int32_t komodo_notaries(char *symbol,uint8_t pubkeys[64][33],int32_t height) int32_t komodo_notaries(char *symbol,uint8_t pubkeys[64][33],int32_t height)
{ {
int32_t i,num=-1; struct iguana_info *coin; char params[256],*retstr,*pubkeystr; cJSON *retjson,*item,*array; int32_t i,num=-1; struct iguana_info *coin; char params[256],*retstr,*pubkeystr; cJSON *retjson,*item,*array;
if ( (coin= iguana_coinfind(symbol)) != 0 ) if ( (coin= iguana_coinfind(symbol)) != 0 )
{ {
if ( height < 0 )
{
if ( (retjson= dpow_getinfo(SuperNET_MYINFO(0),coin)) != 0 )
{
height = jint(retjson,"blocks") - 1;
free_json(retjson);
//printf("komodo_notaries height.%d\n",height);
}
}
if ( coin->FULLNODE < 0 ) if ( coin->FULLNODE < 0 )
{ {
sprintf(params,"[\"%d\"]",height); sprintf(params,"[\"%d\"]",height);
@ -50,6 +84,7 @@ int32_t komodo_notaries(char *symbol,uint8_t pubkeys[64][33],int32_t height)
} }
} }
} }
//printf("komodo_notaries returns.%d\n",num);
return(num); return(num);
} }
@ -146,31 +181,6 @@ bits256 dpow_getblockhash(struct supernet_info *myinfo,struct iguana_info *coin,
return(blockhash); return(blockhash);
} }
cJSON *dpow_getinfo(struct supernet_info *myinfo,struct iguana_info *coin)
{
char buf[128],*retstr=0; cJSON *json = 0;
if ( coin->FULLNODE < 0 )
{
buf[0] = 0;
retstr = bitcoind_passthru(coin->symbol,coin->chain->serverport,coin->chain->userpass,"getinfo",buf);
usleep(10000);
}
else if ( coin->FULLNODE > 0 || coin->VALIDATENODE > 0 )
{
retstr = bitcoinrpc_getinfo(myinfo,coin,0,0);
}
else
{
return(0);
}
if ( retstr != 0 )
{
json = cJSON_Parse(retstr);
free(retstr);
}
return(json);
}
cJSON *dpow_getblock(struct supernet_info *myinfo,struct iguana_info *coin,bits256 blockhash) cJSON *dpow_getblock(struct supernet_info *myinfo,struct iguana_info *coin,bits256 blockhash)
{ {
char buf[128],str[65],*retstr=0; cJSON *json = 0; char buf[128],str[65],*retstr=0; cJSON *json = 0;

2
iguana/iguana777.c

@ -902,7 +902,9 @@ void iguana_coinloop(void *arg)
init_alladdresses(myinfo,coin); init_alladdresses(myinfo,coin);
} }
if ( coin->FULLNODE < 0 || coin->notarychain >= 0 ) if ( coin->FULLNODE < 0 || coin->notarychain >= 0 )
{
continue; continue;
}
/*if ( strcmp(coin->symbol,"RELAY") == 0 ) /*if ( strcmp(coin->symbol,"RELAY") == 0 )
{ {
if ( myinfo->expiration != 0 && (myinfo->IAMLP != 0 || myinfo->DEXactive > now) ) if ( myinfo->expiration != 0 && (myinfo->IAMLP != 0 || myinfo->DEXactive > now) )

2
iguana/iguana777.h

@ -137,7 +137,7 @@ struct supernet_info
uint8_t logs[256],exps[510]; uint8_t logs[256],exps[510];
struct message_info msgids[8192]; struct message_info msgids[8192];
double *svmfeatures; double *svmfeatures;
struct dpow_entry notaries[64]; int32_t numnotaries; uint8_t notaries[64][33]; int32_t numnotaries;
}; };
#include "../includes/iguana_funcs.h" #include "../includes/iguana_funcs.h"

6
iguana/iguana_notary.c

@ -656,6 +656,12 @@ TWO_STRINGS_AND_TWO_DOUBLES(dex,listtransactions,symbol,address,count,skip)
{ {
return(_dex_listtransactions(myinfo,symbol,address,count,skip)); return(_dex_listtransactions(myinfo,symbol,address,count,skip));
} }
STRING_ARG(dex,getnotaries,symbol)
{
return(_dex_getnotaries(myinfo,symbol));
}
#include "../includes/iguana_apiundefs.h" #include "../includes/iguana_apiundefs.h"

25
iguana/main.c

@ -1643,8 +1643,31 @@ void iguana_main(void *arg)
#ifdef __APPLE__ #ifdef __APPLE__
iguana_appletests(myinfo); iguana_appletests(myinfo);
#endif #endif
char *retstr,*pubkeystr; cJSON *retjson,*array,*item; int32_t i,n;
if ( (retstr= _dex_getnotaries(myinfo,"KMD")) != 0 )
{
printf("INITIAL NOTARIES.(%s)\n",retstr);
if ( (retjson= cJSON_Parse(retstr)) != 0 )
{
if ( (myinfo->numnotaries= jint(retjson,"numnotaries")) != 0 && (array= jarray(&n,retjson,"notaries")) != 0 && n == myinfo->numnotaries )
{
for (i=0; i<n; i++)
{
item = jitem(array,i);
if ( (pubkeystr= jstr(item,"pubkey")) != 0 && strlen(pubkeystr) == 33*2 )
decode_hex(myinfo->notaries[i],33,pubkeystr);
}
}
free_json(retjson);
}
free(retstr);
}
}
}
else
{
basilisks_init(myinfo);
} }
} else basilisks_init(myinfo);
if ( 0 ) if ( 0 )
{ {
char *jsonstr = "[\"03b7621b44118017a16043f19b30cc8a4cfe068ac4e42417bae16ba460c80f3828\", \"02ebfc784a4ba768aad88d44d1045d240d47b26e248cafaf1c5169a42d7a61d344\", \"03750cf30d739cd7632f77c1c02812dd7a7181628b0558058d4755838117e05339\", \"0394f3529d2e8cc69ffa7a2b55f3761e7be978fa1896ef4c55dc9c275e77e5bf5e\", \"0243c1eeb3777af47187d542e5f8c84f0ac4b05cf5a7ad77faa8cb6d2d56db7823\", \"02bb298844175640a34e908ffdfa2839f77aba3d5edadefee16beb107826e00063\", \"02fa88e549b4b871498f892e527a5d57287916809f8cc3163f641d71c535e8df5a\", \"032f799e370f06476793a122fcd623db7804898fe5aef5572095cfee6353df34bf\", \"02c06fe5401faff4442ef87b7d1b56c2e5a214166615f9a2f2030c71b0cb067ae8\", \"038ac67ca49a8169bcc5de83fe020071095a2c3b2bc4d1c17386977329758956d5\"]"; char *jsonstr = "[\"03b7621b44118017a16043f19b30cc8a4cfe068ac4e42417bae16ba460c80f3828\", \"02ebfc784a4ba768aad88d44d1045d240d47b26e248cafaf1c5169a42d7a61d344\", \"03750cf30d739cd7632f77c1c02812dd7a7181628b0558058d4755838117e05339\", \"0394f3529d2e8cc69ffa7a2b55f3761e7be978fa1896ef4c55dc9c275e77e5bf5e\", \"0243c1eeb3777af47187d542e5f8c84f0ac4b05cf5a7ad77faa8cb6d2d56db7823\", \"02bb298844175640a34e908ffdfa2839f77aba3d5edadefee16beb107826e00063\", \"02fa88e549b4b871498f892e527a5d57287916809f8cc3163f641d71c535e8df5a\", \"032f799e370f06476793a122fcd623db7804898fe5aef5572095cfee6353df34bf\", \"02c06fe5401faff4442ef87b7d1b56c2e5a214166615f9a2f2030c71b0cb067ae8\", \"038ac67ca49a8169bcc5de83fe020071095a2c3b2bc4d1c17386977329758956d5\"]";

2
iguana/tests/dexnotaries

@ -0,0 +1,2 @@
#!/bin/bash
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"getnotaries\",\"symbol\":\"KMD\"}"

1
includes/iguana_apideclares.h

@ -29,6 +29,7 @@ ZERO_ARGS(iguana,paxfiats);
TWO_STRINGS(dex,send,hex,handler); TWO_STRINGS(dex,send,hex,handler);
HASH_AND_STRING(dex,gettransaction,txid,symbol); HASH_AND_STRING(dex,gettransaction,txid,symbol);
STRING_ARG(dex,getinfo,symbol); STRING_ARG(dex,getinfo,symbol);
STRING_ARG(dex,getnotaries,symbol);
STRING_ARG(dex,alladdresses,symbol); STRING_ARG(dex,alladdresses,symbol);
STRING_ARG(dex,getbestblockhash,symbol); STRING_ARG(dex,getbestblockhash,symbol);
STRING_AND_INT(dex,getblockhash,symbol,height); STRING_AND_INT(dex,getblockhash,symbol,height);

Loading…
Cancel
Save