From 99a5389331a36ac52742adbfb4b0bef30834a729 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 14 Jan 2017 13:17:24 +0200 Subject: [PATCH 01/15] dex_notaries --- iguana/dPoW.h | 3 ++ iguana/dpow/dpow_fsm.c | 2 +- iguana/dpow/dpow_network.c | 74 +++++++++++++++++++++++++++++++------- iguana/dpow/dpow_rpc.c | 2 ++ iguana/iguana777.h | 2 +- iguana/main.c | 18 ++++++++++ 6 files changed, 87 insertions(+), 14 deletions(-) diff --git a/iguana/dPoW.h b/iguana/dPoW.h index b0a933f02..4da6722d7 100755 --- a/iguana/dPoW.h +++ b/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_listtransactions(struct supernet_info *myinfo,char *symbol,char *coinaddr,int32_t count,int32_t skip); char *_dex_alladdresses(struct supernet_info *myinfo,char *symbol); +int32_t _dex_getheight(struct supernet_info *myinfo,char *symbol); +char *_dex_notaries(struct supernet_info *myinfo,char *symbol); +int32_t komodo_notaries(char *symbol,uint8_t pubkeys[64][33],int32_t height); #endif diff --git a/iguana/dpow/dpow_fsm.c b/iguana/dpow/dpow_fsm.c index 3a6bf95a3..6a4b8340d 100755 --- a/iguana/dpow/dpow_fsm.c +++ b/iguana/dpow/dpow_fsm.c @@ -293,7 +293,7 @@ void dpow_statemachinestart(void *ptr) //printf(" <= pubkey[%d]\n",i); memcpy(bp->notaries[i].pubkey,pubkeys[i],33); 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 ) { myind = i; diff --git a/iguana/dpow/dpow_network.c b/iguana/dpow/dpow_network.c index d2cded61d..144522533 100755 --- a/iguana/dpow/dpow_network.c +++ b/iguana/dpow/dpow_network.c @@ -13,9 +13,6 @@ * * ******************************************************************************/ -// 1. add rpc hooks, debug -// 2. sig validate in fsm - struct signed_nnpacket { uint8_t sig64[64]; @@ -52,8 +49,8 @@ int32_t signed_nn_send(void *ctx,bits256 privkey,int32_t sock,void *packet,int32 } 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; *(void **)packetp = 0; @@ -66,9 +63,9 @@ 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 ) { - for (i=0; inonce,sigpacket->packetlen); } else printf("hash mismatch or bad nonce.%u packetlen.%d\n",sigpacket->nonce,sigpacket->packetlen); } //else printf("recvbytes.%d mismatched packetlen.%d + %ld\n",recvbytes,sigpacket!=0?sigpacket->packetlen:-1,sizeof(*sigpacket)); @@ -325,7 +322,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 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; if ( strcmp(dexp->handler,"request") == 0 ) { @@ -432,6 +429,34 @@ char *dex_response(int32_t *broadcastflagp,struct supernet_info *myinfo,struct d 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; ilongestchain; if ( coin->FULLNODE < 0 ) { sprintf(params,"[\"%d\"]",height); diff --git a/iguana/iguana777.h b/iguana/iguana777.h index dfa7132b2..bfcbbff1b 100755 --- a/iguana/iguana777.h +++ b/iguana/iguana777.h @@ -137,7 +137,7 @@ struct supernet_info uint8_t logs[256],exps[510]; struct message_info msgids[8192]; double *svmfeatures; - struct dpow_entry notaries[64]; int32_t numnotaries; + uint8_t notaries[64][33]; int32_t numnotaries; }; #include "../includes/iguana_funcs.h" diff --git a/iguana/main.c b/iguana/main.c index 0dfeabc7e..25dc7a292 100755 --- a/iguana/main.c +++ b/iguana/main.c @@ -1644,6 +1644,24 @@ void iguana_main(void *arg) iguana_appletests(myinfo); #endif } + char *retstr,*pubkeystr; cJSON *retjson,*array,*item; int32_t i,n; + if ( (retstr= _dex_notaries(myinfo,"KMD")) != 0 ) + { + 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; inotaries[i],33,pubkeystr); + } + } + free_json(retjson); + } + free(retstr); + } } else basilisks_init(myinfo); if ( 0 ) { From 5dfc9fb4b4efad0dfb7f3da3dc589d51608e0652 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 14 Jan 2017 13:22:29 +0200 Subject: [PATCH 02/15] test --- iguana/main.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/iguana/main.c b/iguana/main.c index 25dc7a292..5c7db3761 100755 --- a/iguana/main.c +++ b/iguana/main.c @@ -1644,25 +1644,25 @@ void iguana_main(void *arg) iguana_appletests(myinfo); #endif } - char *retstr,*pubkeystr; cJSON *retjson,*array,*item; int32_t i,n; - if ( (retstr= _dex_notaries(myinfo,"KMD")) != 0 ) + } else basilisks_init(myinfo); + char *retstr,*pubkeystr; cJSON *retjson,*array,*item; int32_t i,n; + if ( (retstr= _dex_notaries(myinfo,"KMD")) != 0 ) + { + if ( (retjson= cJSON_Parse(retstr)) != 0 ) { - if ( (retjson= cJSON_Parse(retstr)) != 0 ) + if ( (myinfo->numnotaries= jint(retjson,"numnotaries")) != 0 && (array= jarray(&n,retjson,"notaries")) != 0 && n == myinfo->numnotaries ) { - if ( (myinfo->numnotaries= jint(retjson,"numnotaries")) != 0 && (array= jarray(&n,retjson,"notaries")) != 0 && n == myinfo->numnotaries ) + for (i=0; inotaries[i],33,pubkeystr); - } + 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); + free_json(retjson); } - } else basilisks_init(myinfo); + free(retstr); + } if ( 0 ) { char *jsonstr = "[\"03b7621b44118017a16043f19b30cc8a4cfe068ac4e42417bae16ba460c80f3828\", \"02ebfc784a4ba768aad88d44d1045d240d47b26e248cafaf1c5169a42d7a61d344\", \"03750cf30d739cd7632f77c1c02812dd7a7181628b0558058d4755838117e05339\", \"0394f3529d2e8cc69ffa7a2b55f3761e7be978fa1896ef4c55dc9c275e77e5bf5e\", \"0243c1eeb3777af47187d542e5f8c84f0ac4b05cf5a7ad77faa8cb6d2d56db7823\", \"02bb298844175640a34e908ffdfa2839f77aba3d5edadefee16beb107826e00063\", \"02fa88e549b4b871498f892e527a5d57287916809f8cc3163f641d71c535e8df5a\", \"032f799e370f06476793a122fcd623db7804898fe5aef5572095cfee6353df34bf\", \"02c06fe5401faff4442ef87b7d1b56c2e5a214166615f9a2f2030c71b0cb067ae8\", \"038ac67ca49a8169bcc5de83fe020071095a2c3b2bc4d1c17386977329758956d5\"]"; From d5eef3a8e70a58e541a55102677bf8756ac7a896 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 14 Jan 2017 13:32:59 +0200 Subject: [PATCH 03/15] test --- iguana/dpow/dpow_network.c | 11 ++++++++++- iguana/main.c | 34 ++++++++++++++++++++-------------- 2 files changed, 30 insertions(+), 15 deletions(-) diff --git a/iguana/dpow/dpow_network.c b/iguana/dpow/dpow_network.c index 144522533..09a7f1a61 100755 --- a/iguana/dpow/dpow_network.c +++ b/iguana/dpow/dpow_network.c @@ -52,7 +52,7 @@ int32_t signed_nn_send(void *ctx,bits256 privkey,int32_t sock,void *packet,int32 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; *freeptrp = 0; recvbytes = nn_recv(sock,&sigpacket,NN_MSG,0); @@ -63,6 +63,14 @@ int32_t signed_nn_recv(void **freeptrp,void *ctx,uint8_t notaries[64][33],int32_ { if ( bitcoin_recoververify(ctx,"nnrecv",sigpacket->sig64,sigpacket->packethash,pubkey33,33) == 0 ) { + char *notary0 = "03b7621b44118017a16043f19b30cc8a4cfe068ac4e42417bae16ba460c80f3828"; + decode_hex(pubkey0,33,notary0); + if ( memcmp(pubkey0,pubkey33,33) == 0 ) + { + *(void **)packetp = (void **)((uint64_t)sigpacket + sizeof(*sigpacket)); + *freeptrp = sigpacket; + return((int32_t)(recvbytes - sizeof(*sigpacket))); + } for (i=0; inumnotaries= jint(retjson,"numnotaries")) != 0 && (array= jarray(&n,retjson,"notaries")) != 0 && n == myinfo->numnotaries ) + char *retstr,*pubkeystr; cJSON *retjson,*array,*item; int32_t i,n; + if ( (retstr= _dex_notaries(myinfo,"KMD")) != 0 ) { - for (i=0; inotaries[i],33,pubkeystr); + if ( (myinfo->numnotaries= jint(retjson,"numnotaries")) != 0 && (array= jarray(&n,retjson,"notaries")) != 0 && n == myinfo->numnotaries ) + { + for (i=0; inotaries[i],33,pubkeystr); + } + } + free_json(retjson); } + free(retstr); } - free_json(retjson); } - free(retstr); + } + else + { + basilisks_init(myinfo); + myinfo->numnotaries = komodo_notaries("KMD",myinfo->notaries,-1); } if ( 0 ) { From 1828f58a620c4852ce1fd95b605cf4cc4409bad3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 14 Jan 2017 13:37:41 +0200 Subject: [PATCH 04/15] test --- iguana/dpow/dpow_network.c | 2 ++ iguana/main.c | 1 + 2 files changed, 3 insertions(+) diff --git a/iguana/dpow/dpow_network.c b/iguana/dpow/dpow_network.c index 09a7f1a61..bb74ee702 100755 --- a/iguana/dpow/dpow_network.c +++ b/iguana/dpow/dpow_network.c @@ -64,6 +64,7 @@ int32_t signed_nn_recv(void **freeptrp,void *ctx,uint8_t notaries[64][33],int32_ if ( bitcoin_recoververify(ctx,"nnrecv",sigpacket->sig64,sigpacket->packethash,pubkey33,33) == 0 ) { char *notary0 = "03b7621b44118017a16043f19b30cc8a4cfe068ac4e42417bae16ba460c80f3828"; + // expand to official notaries decode_hex(pubkey0,33,notary0); if ( memcmp(pubkey0,pubkey33,33) == 0 ) { @@ -465,6 +466,7 @@ char *dex_response(int32_t *broadcastflagp,struct supernet_info *myinfo,struct d free(retstr); retstr = jprint(retjson,1); } + printf("DEX NOTARIES -> (%s)\n",retstr); } } else printf("(%s) not active\n",dexreq.name); if ( retstr == 0 ) diff --git a/iguana/main.c b/iguana/main.c index 5b36b3a53..412d7635a 100755 --- a/iguana/main.c +++ b/iguana/main.c @@ -1668,6 +1668,7 @@ void iguana_main(void *arg) { basilisks_init(myinfo); myinfo->numnotaries = komodo_notaries("KMD",myinfo->notaries,-1); + printf("INIT with %d notaries\n",myinfo->numnotaries); } if ( 0 ) { From 8915eecebd7c4cb87659340a5c3f3699b6b70d37 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 14 Jan 2017 13:40:28 +0200 Subject: [PATCH 05/15] test --- iguana/iguana777.c | 5 +++++ iguana/main.c | 2 -- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/iguana/iguana777.c b/iguana/iguana777.c index 03c6de357..6ca58bd4f 100755 --- a/iguana/iguana777.c +++ b/iguana/iguana777.c @@ -875,6 +875,11 @@ void iguana_callcoinstart(struct supernet_info *myinfo,struct iguana_info *coin) coin->notarychain = -1; addr = &coin->peers->active[IGUANA_MAXPEERS-2]; iguana_initpeer(coin,addr,(uint32_t)calc_ipbits(coin->seedipaddr)); + if ( strcmp(coin->symbol,"KMD") == 0 && myinfo->IAMNOTARY != 0 ) + { + myinfo->numnotaries = komodo_notaries("KMD",myinfo->notaries,-1); + printf("INIT with %d notaries\n",myinfo->numnotaries); + } printf("SEED_IPADDR initpeer.(%s) notarychain.%d\n",addr->ipaddr,coin->notarychain); iguana_launch(coin,"connection",iguana_startconnection,addr,IGUANA_CONNTHREAD); } diff --git a/iguana/main.c b/iguana/main.c index 412d7635a..30544eaab 100755 --- a/iguana/main.c +++ b/iguana/main.c @@ -1667,8 +1667,6 @@ void iguana_main(void *arg) else { basilisks_init(myinfo); - myinfo->numnotaries = komodo_notaries("KMD",myinfo->notaries,-1); - printf("INIT with %d notaries\n",myinfo->numnotaries); } if ( 0 ) { From eeb4497e442fb5b67f70ff894a360907ab719c77 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 14 Jan 2017 13:43:56 +0200 Subject: [PATCH 06/15] test --- iguana/iguana777.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/iguana/iguana777.c b/iguana/iguana777.c index 6ca58bd4f..c6dd57f57 100755 --- a/iguana/iguana777.c +++ b/iguana/iguana777.c @@ -875,11 +875,6 @@ void iguana_callcoinstart(struct supernet_info *myinfo,struct iguana_info *coin) coin->notarychain = -1; addr = &coin->peers->active[IGUANA_MAXPEERS-2]; iguana_initpeer(coin,addr,(uint32_t)calc_ipbits(coin->seedipaddr)); - if ( strcmp(coin->symbol,"KMD") == 0 && myinfo->IAMNOTARY != 0 ) - { - myinfo->numnotaries = komodo_notaries("KMD",myinfo->notaries,-1); - printf("INIT with %d notaries\n",myinfo->numnotaries); - } printf("SEED_IPADDR initpeer.(%s) notarychain.%d\n",addr->ipaddr,coin->notarychain); iguana_launch(coin,"connection",iguana_startconnection,addr,IGUANA_CONNTHREAD); } @@ -907,7 +902,14 @@ void iguana_coinloop(void *arg) init_alladdresses(myinfo,coin); } if ( coin->FULLNODE < 0 || coin->notarychain >= 0 ) + { + if ( myinfo->IAMNOTARY != 0 && strcmp("KMD",coin->symbol) == 0 && myinfo->numnotaries <= 0 ) + { + myinfo->numnotaries = komodo_notaries("KMD",myinfo->notaries,-1); + printf("INIT with %d notaries\n",myinfo->numnotaries); + } continue; + } /*if ( strcmp(coin->symbol,"RELAY") == 0 ) { if ( myinfo->expiration != 0 && (myinfo->IAMLP != 0 || myinfo->DEXactive > now) ) From a99ff62af376eaa0260e60ae32e9c5f2f8ac7637 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 14 Jan 2017 13:47:27 +0200 Subject: [PATCH 07/15] test --- iguana/dpow/dpow_network.c | 5 +++++ iguana/iguana777.c | 5 ----- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/iguana/dpow/dpow_network.c b/iguana/dpow/dpow_network.c index bb74ee702..ae93f7806 100755 --- a/iguana/dpow/dpow_network.c +++ b/iguana/dpow/dpow_network.c @@ -1544,6 +1544,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; if ( time(NULL) < myinfo->nanoinit+5 || (myinfo->dpowsock < 0 && myinfo->dexsock < 0 && myinfo->repsock < 0) ) 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); /*for (i=0; i<100; i++) { diff --git a/iguana/iguana777.c b/iguana/iguana777.c index c6dd57f57..b36c93803 100755 --- a/iguana/iguana777.c +++ b/iguana/iguana777.c @@ -903,11 +903,6 @@ void iguana_coinloop(void *arg) } if ( coin->FULLNODE < 0 || coin->notarychain >= 0 ) { - if ( myinfo->IAMNOTARY != 0 && strcmp("KMD",coin->symbol) == 0 && myinfo->numnotaries <= 0 ) - { - myinfo->numnotaries = komodo_notaries("KMD",myinfo->notaries,-1); - printf("INIT with %d notaries\n",myinfo->numnotaries); - } continue; } /*if ( strcmp(coin->symbol,"RELAY") == 0 ) From 717cbc3516f84c88148e76f8b0265e48848511bb Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 14 Jan 2017 14:01:04 +0200 Subject: [PATCH 08/15] test --- iguana/dpow/dpow_rpc.c | 58 +++++++++++++++++++++++------------------- 1 file changed, 32 insertions(+), 26 deletions(-) diff --git a/iguana/dpow/dpow_rpc.c b/iguana/dpow/dpow_rpc.c index 9645e528f..a9cc6d07c 100755 --- a/iguana/dpow/dpow_rpc.c +++ b/iguana/dpow/dpow_rpc.c @@ -15,13 +15,44 @@ #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 i,num=-1; struct iguana_info *coin; char params[256],*retstr,*pubkeystr; cJSON *retjson,*item,*array; if ( (coin= iguana_coinfind(symbol)) != 0 ) { if ( height < 0 ) - height = coin->longestchain; + { + if ( (retjson= dpow_getinfo(SuperNET_MYINFO(0),coin)) != 0 ) + { + height = jint(retjson,"blocks") - 1; + free_json(retjson); + } + } if ( coin->FULLNODE < 0 ) { sprintf(params,"[\"%d\"]",height); @@ -148,31 +179,6 @@ bits256 dpow_getblockhash(struct supernet_info *myinfo,struct iguana_info *coin, 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) { char buf[128],str[65],*retstr=0; cJSON *json = 0; From 6e0893cc97ff2f60a9386930e93adcc6c6b99bab Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 14 Jan 2017 14:13:39 +0200 Subject: [PATCH 09/15] test --- iguana/dPoW.h | 2 +- iguana/dpow/dpow_network.c | 6 +++--- iguana/dpow/dpow_rpc.c | 3 ++- iguana/iguana_notary.c | 6 ++++++ iguana/main.c | 2 +- iguana/tests/dexnotaries | 2 ++ includes/iguana_apideclares.h | 1 + 7 files changed, 16 insertions(+), 6 deletions(-) create mode 100755 iguana/tests/dexnotaries diff --git a/iguana/dPoW.h b/iguana/dPoW.h index 4da6722d7..41283f8ce 100755 --- a/iguana/dPoW.h +++ b/iguana/dPoW.h @@ -179,7 +179,7 @@ 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_alladdresses(struct supernet_info *myinfo,char *symbol); int32_t _dex_getheight(struct supernet_info *myinfo,char *symbol); -char *_dex_notaries(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 diff --git a/iguana/dpow/dpow_network.c b/iguana/dpow/dpow_network.c index ae93f7806..b8993d3a9 100755 --- a/iguana/dpow/dpow_network.c +++ b/iguana/dpow/dpow_network.c @@ -259,7 +259,7 @@ char *_dex_reqsend(struct supernet_info *myinfo,char *handler,uint8_t *data,int3 // printf("%02x",((uint8_t *)data)[i]); 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); ipbits = 0; if ( strcmp(handler,"DEX") == 0 ) @@ -267,7 +267,7 @@ char *_dex_reqsend(struct supernet_info *myinfo,char *handler,uint8_t *data,int3 else if ( retptr != 0 ) { retstr = clonestr((char *)retptr); - printf("GOT.(%s)\n",retstr); + //printf("GOT.(%s)\n",retstr); if ( (retjson= cJSON_Parse(retstr)) != 0 ) { ipbits = juint(retjson,"randipbits"); @@ -619,7 +619,7 @@ int32_t _dex_getheight(struct supernet_info *myinfo,char *symbol) return(height); } -char *_dex_notaries(struct supernet_info *myinfo,char *symbol) +char *_dex_getnotaries(struct supernet_info *myinfo,char *symbol) { struct dex_request dexreq; memset(&dexreq,0,sizeof(dexreq)); diff --git a/iguana/dpow/dpow_rpc.c b/iguana/dpow/dpow_rpc.c index a9cc6d07c..9fd5a92ef 100755 --- a/iguana/dpow/dpow_rpc.c +++ b/iguana/dpow/dpow_rpc.c @@ -51,6 +51,7 @@ int32_t komodo_notaries(char *symbol,uint8_t pubkeys[64][33],int32_t height) { height = jint(retjson,"blocks") - 1; free_json(retjson); +printf("komodo_notaries height.%d\n",height); } } if ( coin->FULLNODE < 0 ) @@ -60,7 +61,7 @@ int32_t komodo_notaries(char *symbol,uint8_t pubkeys[64][33],int32_t height) { if ( (retjson= cJSON_Parse(retstr)) != 0 ) { - //printf("%s\n",retstr); +printf("%s\n",retstr); if ( (array= jarray(&num,retjson,"notaries")) != 0 ) { if ( num > 64 ) diff --git a/iguana/iguana_notary.c b/iguana/iguana_notary.c index 5f98f1bb8..bf1829b5a 100755 --- a/iguana/iguana_notary.c +++ b/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)); } + +STRING_ARG(dex,getnotaries,symbol) +{ + return(_dex_getnotaries(myinfo,symbol)); +} + #include "../includes/iguana_apiundefs.h" diff --git a/iguana/main.c b/iguana/main.c index 30544eaab..839a0e164 100755 --- a/iguana/main.c +++ b/iguana/main.c @@ -1644,7 +1644,7 @@ void iguana_main(void *arg) iguana_appletests(myinfo); #endif char *retstr,*pubkeystr; cJSON *retjson,*array,*item; int32_t i,n; - if ( (retstr= _dex_notaries(myinfo,"KMD")) != 0 ) + if ( (retstr= _dex_getnotaries(myinfo,"KMD")) != 0 ) { printf("INITIAL NOTARIES.(%s)\n",retstr); if ( (retjson= cJSON_Parse(retstr)) != 0 ) diff --git a/iguana/tests/dexnotaries b/iguana/tests/dexnotaries new file mode 100755 index 000000000..1da169442 --- /dev/null +++ b/iguana/tests/dexnotaries @@ -0,0 +1,2 @@ +#!/bin/bash +curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"getnotaries\",\"symbol\":\"KMD\"}" diff --git a/includes/iguana_apideclares.h b/includes/iguana_apideclares.h index bbb9b1bfa..c45f295f4 100755 --- a/includes/iguana_apideclares.h +++ b/includes/iguana_apideclares.h @@ -29,6 +29,7 @@ ZERO_ARGS(iguana,paxfiats); TWO_STRINGS(dex,send,hex,handler); HASH_AND_STRING(dex,gettransaction,txid,symbol); STRING_ARG(dex,getinfo,symbol); +STRING_ARG(dex,getnotaries,symbol); STRING_ARG(dex,alladdresses,symbol); STRING_ARG(dex,getbestblockhash,symbol); STRING_AND_INT(dex,getblockhash,symbol,height); From f04f46a77cac813803fc626ce495f79b63e3dc10 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 14 Jan 2017 14:18:36 +0200 Subject: [PATCH 10/15] test --- iguana/dpow/dpow_network.c | 3 ++- iguana/dpow/dpow_rpc.c | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/iguana/dpow/dpow_network.c b/iguana/dpow/dpow_network.c index b8993d3a9..c164eadf7 100755 --- a/iguana/dpow/dpow_network.c +++ b/iguana/dpow/dpow_network.c @@ -451,6 +451,7 @@ char *dex_response(int32_t *broadcastflagp,struct supernet_info *myinfo,struct d 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); @@ -459,11 +460,11 @@ char *dex_response(int32_t *broadcastflagp,struct supernet_info *myinfo,struct d } jadd(retjson,"notaries",array); jaddnum(retjson,"numnotaries",numnotaries); + printf("numnotaries.%d\n",numnotaries); } if ( retjson != 0 ) { dpow_randipbits(myinfo,coin,retjson); - free(retstr); retstr = jprint(retjson,1); } printf("DEX NOTARIES -> (%s)\n",retstr); diff --git a/iguana/dpow/dpow_rpc.c b/iguana/dpow/dpow_rpc.c index 9fd5a92ef..5ce751885 100755 --- a/iguana/dpow/dpow_rpc.c +++ b/iguana/dpow/dpow_rpc.c @@ -51,7 +51,7 @@ int32_t komodo_notaries(char *symbol,uint8_t pubkeys[64][33],int32_t height) { height = jint(retjson,"blocks") - 1; free_json(retjson); -printf("komodo_notaries height.%d\n",height); +//printf("komodo_notaries height.%d\n",height); } } if ( coin->FULLNODE < 0 ) From 129e809a03eff0a1b23324f6a35f7a4951d8122c Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 14 Jan 2017 14:22:16 +0200 Subject: [PATCH 11/15] test --- iguana/dpow/dpow_network.c | 2 +- iguana/dpow/dpow_rpc.c | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/iguana/dpow/dpow_network.c b/iguana/dpow/dpow_network.c index c164eadf7..2fcc6ee3a 100755 --- a/iguana/dpow/dpow_network.c +++ b/iguana/dpow/dpow_network.c @@ -442,7 +442,7 @@ char *dex_response(int32_t *broadcastflagp,struct supernet_info *myinfo,struct d 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 ) + if ( (numnotaries= komodo_notaries("KMD",pubkeys,-1)) > 0 && numnotaries <= 64 ) { retjson = cJSON_CreateObject(); array = cJSON_CreateArray(); diff --git a/iguana/dpow/dpow_rpc.c b/iguana/dpow/dpow_rpc.c index 5ce751885..2067e8b86 100755 --- a/iguana/dpow/dpow_rpc.c +++ b/iguana/dpow/dpow_rpc.c @@ -61,7 +61,7 @@ int32_t komodo_notaries(char *symbol,uint8_t pubkeys[64][33],int32_t height) { if ( (retjson= cJSON_Parse(retstr)) != 0 ) { -printf("%s\n",retstr); +//printf("%s\n",retstr); if ( (array= jarray(&num,retjson,"notaries")) != 0 ) { if ( num > 64 ) @@ -84,6 +84,7 @@ printf("%s\n",retstr); } } } + printf("komodo_notaries returns.%d\n",num); return(num); } From d4e1d2b1bf0e848c9ca792202ad9b8ed2b0d40ea Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 14 Jan 2017 14:27:28 +0200 Subject: [PATCH 12/15] test --- iguana/dpow/dpow_network.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/dpow/dpow_network.c b/iguana/dpow/dpow_network.c index 2fcc6ee3a..2de876479 100755 --- a/iguana/dpow/dpow_network.c +++ b/iguana/dpow/dpow_network.c @@ -451,7 +451,7 @@ char *dex_response(int32_t *broadcastflagp,struct supernet_info *myinfo,struct d item = cJSON_CreateObject(); init_hexbytes_noT(str,pubkeys[i],33); jaddstr(item,"pubkey",str); - printf("[%s %d] ",str,i); + //printf("[%s %d] ",str,i); bitcoin_address(str,0,pubkeys[i],33); jaddstr(item,"BTCaddress",str); bitcoin_address(str,60,pubkeys[i],33); @@ -460,7 +460,7 @@ char *dex_response(int32_t *broadcastflagp,struct supernet_info *myinfo,struct d } jadd(retjson,"notaries",array); jaddnum(retjson,"numnotaries",numnotaries); - printf("numnotaries.%d\n",numnotaries); + //printf("numnotaries.%d\n",numnotaries); } if ( retjson != 0 ) { From 566eb3c9a981f88e337922af05a9dc123c8dedb9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 14 Jan 2017 14:41:03 +0200 Subject: [PATCH 13/15] test --- iguana/dpow/dpow_network.c | 7 +++++-- iguana/dpow/dpow_rpc.c | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/iguana/dpow/dpow_network.c b/iguana/dpow/dpow_network.c index 2de876479..1bdac90a7 100755 --- a/iguana/dpow/dpow_network.c +++ b/iguana/dpow/dpow_network.c @@ -467,7 +467,7 @@ char *dex_response(int32_t *broadcastflagp,struct supernet_info *myinfo,struct d dpow_randipbits(myinfo,coin,retjson); retstr = jprint(retjson,1); } - printf("DEX NOTARIES -> (%s)\n",retstr); + //printf("DEX NOTARIES -> (%s)\n",retstr); } } else printf("(%s) not active\n",dexreq.name); if ( retstr == 0 ) @@ -484,7 +484,7 @@ char *dex_reqsend(struct supernet_info *myinfo,char *handler,uint8_t *data,int32 { 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 ( ++j == M ) @@ -496,7 +496,10 @@ char *dex_reqsend(struct supernet_info *myinfo,char *handler,uint8_t *data,int32 //printf("automatic retry.%d of %d\n",i,max); } if ( j == 1 ) + { + //printf("return.(%s)\n",retstrs[0]); return(retstrs[0]); + } else if ( j >= M ) { origretstr0 = retstrs[0]; diff --git a/iguana/dpow/dpow_rpc.c b/iguana/dpow/dpow_rpc.c index 2067e8b86..6283e4839 100755 --- a/iguana/dpow/dpow_rpc.c +++ b/iguana/dpow/dpow_rpc.c @@ -84,7 +84,7 @@ int32_t komodo_notaries(char *symbol,uint8_t pubkeys[64][33],int32_t height) } } } - printf("komodo_notaries returns.%d\n",num); + //printf("komodo_notaries returns.%d\n",num); return(num); } From 1a531afec66651a80d8952dece647adb2e3ef1c3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 14 Jan 2017 14:46:51 +0200 Subject: [PATCH 14/15] test --- iguana/dpow/dpow_network.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/iguana/dpow/dpow_network.c b/iguana/dpow/dpow_network.c index 1bdac90a7..34717cb77 100755 --- a/iguana/dpow/dpow_network.c +++ b/iguana/dpow/dpow_network.c @@ -70,6 +70,7 @@ int32_t signed_nn_recv(void **freeptrp,void *ctx,uint8_t notaries[64][33],int32_ { *(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; inonce,sigpacket->packetlen); } else printf("hash mismatch or bad nonce.%u packetlen.%d\n",sigpacket->nonce,sigpacket->packetlen); } //else printf("recvbytes.%d mismatched packetlen.%d + %ld\n",recvbytes,sigpacket!=0?sigpacket->packetlen:-1,sizeof(*sigpacket)); From b89bc4f7dec99925481ef9c4ddb1c1c8fdcbb03b Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 14 Jan 2017 14:56:09 +0200 Subject: [PATCH 15/15] test --- iguana/dpow/dpow_network.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/dpow/dpow_network.c b/iguana/dpow/dpow_network.c index 34717cb77..fe0d1655b 100755 --- a/iguana/dpow/dpow_network.c +++ b/iguana/dpow/dpow_network.c @@ -70,7 +70,7 @@ int32_t signed_nn_recv(void **freeptrp,void *ctx,uint8_t notaries[64][33],int32_ { *(void **)packetp = (void **)((uint64_t)sigpacket + sizeof(*sigpacket)); *freeptrp = sigpacket; - printf("got signed packet from notary0\n"); + //printf("got signed packet from notary0\n"); return((int32_t)(recvbytes - sizeof(*sigpacket))); } for (i=0; i