diff --git a/basilisk/basilisk_MSG.c b/basilisk/basilisk_MSG.c index 76e019031..c6cb0afa9 100755 --- a/basilisk/basilisk_MSG.c +++ b/basilisk/basilisk_MSG.c @@ -309,7 +309,7 @@ HASH_ARRAY_STRING(basilisk,sendmessage,hash,vals,hexstr) memcpy(space2,key,BASILISK_KEYSIZE); if ( data != 0 && datalen != 0 ) memcpy(&space2[BASILISK_KEYSIZE],data,datalen); - dex_reqsend(myinfo,"DEX",space2,datalen+BASILISK_KEYSIZE); + dex_reqsend(myinfo,"DEX",space2,datalen+BASILISK_KEYSIZE,1); } else printf("sendmessage space too small error for %d\n",datalen); free(space); free(space2); diff --git a/gecko/gecko.c b/gecko/gecko.c index 5a0c2dbaa..8de1611bf 100755 --- a/gecko/gecko.c +++ b/gecko/gecko.c @@ -180,6 +180,8 @@ struct iguana_info *basilisk_geckochain(struct supernet_info *myinfo,char *symbo virt->enableCACHE = 1; serialized = get_dataptr(BASILISK_HDROFFSET,&ptr,&datalen,hexbuf,sizeof(hexbuf),hexstr); iguana_chaininit(myinfo,virt->chain,1,valsobj); + //if ( virt->FULLNODE >= 0 ) + // virt->chain->userpass[0] = 0; virt->chain->isPoS = 1; hdrsize = (virt->chain->zcash != 0) ? sizeof(struct iguana_msgzblockhdr) : sizeof(struct iguana_msgblockhdr); if ( gecko_blocknonce_verify(virt,serialized,hdrsize,virt->chain->nBits,0,0) > 0 ) diff --git a/iguana/dPoW.h b/iguana/dPoW.h index da8db86e2..b1118a7d6 100755 --- a/iguana/dPoW.h +++ b/iguana/dPoW.h @@ -143,7 +143,7 @@ struct dpow_info uint64_t dpow_notarybestk(uint64_t refmask,struct dpow_block *bp,int8_t *lastkp); int32_t dpow_paxpending(uint8_t *hex,uint32_t *paxwdcrcp); void dex_updateclient(struct supernet_info *myinfo); -char *dex_reqsend(struct supernet_info *myinfo,char *handler,uint8_t *data,int32_t datalen); +char *dex_reqsend(struct supernet_info *myinfo,char *handler,uint8_t *data,int32_t datalen,int32_t M); char *basilisk_respond_addmessage(struct supernet_info *myinfo,uint8_t *key,int32_t keylen,uint8_t *data,int32_t datalen,int32_t sendping,uint32_t duration); int32_t dpow_getchaintip(struct supernet_info *myinfo,bits256 *blockhashp,uint32_t *blocktimep,bits256 *txs,uint32_t *numtxp,struct iguana_info *coin); void dpow_send(struct supernet_info *myinfo,struct dpow_info *dp,struct dpow_block *bp,bits256 srchash,bits256 desthash,uint32_t channel,uint32_t msgbits,uint8_t *data,int32_t datalen); diff --git a/iguana/dpow/dpow_network.c b/iguana/dpow/dpow_network.c index ca093a82f..76994cb2e 100755 --- a/iguana/dpow/dpow_network.c +++ b/iguana/dpow/dpow_network.c @@ -23,6 +23,27 @@ struct dex_nanomsghdr uint8_t version0,version1,packet[]; } PACKED; +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); +} + void dex_init(struct supernet_info *myinfo) { strcpy(myinfo->dexseed_ipaddr,"78.47.196.146"); @@ -57,20 +78,30 @@ static int _increasing_ipbits(const void *a,const void *b) void dex_packet(struct supernet_info *myinfo,struct dex_nanomsghdr *dexp,int32_t size) { - char *retstr; + char *retstr; int32_t datalen; struct iguana_info *coin; struct dex_request dexreq; //for (i=0; ipacket,dexp->datalen),(int32_t)(time(NULL)-dexp->timestamp),dexp->size,dexp->datalen); - if ( dexp->datalen > BASILISK_KEYSIZE ) + if ( strcmp(dexp->handler,"DEX") == 0 )//dexp->datalen > BASILISK_KEYSIZE ) { if ( (retstr= basilisk_respond_addmessage(myinfo,dexp->packet,BASILISK_KEYSIZE,&dexp->packet[BASILISK_KEYSIZE],dexp->datalen-BASILISK_KEYSIZE,0,BASILISK_DEXDURATION)) != 0 ) free(retstr); } + else if ( strcmp(dexp->handler,"request") == 0 ) + { + datalen = dex_rwrequest(0,dexp->packet,&dexreq); + if ( myinfo->IAMNOTARY != 0 && dexreq.func == 'A' && (coin= iguana_coinfind(dexreq.name)) != 0 ) + { + if ( (retstr= dpow_importaddress(myinfo,coin,(char *)&dexp->packet[datalen])) != 0 ) + free(retstr); + printf("process broadcast importaddress.(%s) [%s]\n",(char *)&dexp->packet[datalen],dexreq.name); + } + } } -char *dex_reqsend(struct supernet_info *myinfo,char *handler,uint8_t *data,int32_t datalen) +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; + struct dex_nanomsghdr *dexp; cJSON *retjson; char ipaddr[64],str[128]; int32_t timeout,i,n,size,recvbytes,sentbytes = 0,reqsock,subsock; uint32_t *retptr,ipbits; char *retstr = 0; portable_mutex_lock(&myinfo->dexmutex); subsock = myinfo->subsock; reqsock = myinfo->reqsock; @@ -85,7 +116,7 @@ char *dex_reqsend(struct supernet_info *myinfo,char *handler,uint8_t *data,int32 { timeout = 100; nn_setsockopt(reqsock,NN_SOL_SOCKET,NN_SNDTIMEO,&timeout,sizeof(timeout)); - timeout = 2000; + timeout = 1000; nn_setsockopt(reqsock,NN_SOL_SOCKET,NN_RCVTIMEO,&timeout,sizeof(timeout)); //nn_setsockopt(reqsock,NN_TCP,NN_RECONNECT_IVL,&timeout,sizeof(timeout)); if ( myinfo->IAMNOTARY == 0 && subsock < 0 && (subsock= nn_socket(AF_SP,NN_SUB)) >= 0 ) @@ -143,9 +174,22 @@ char *dex_reqsend(struct supernet_info *myinfo,char *handler,uint8_t *data,int32 { //printf("req returned.[%d]\n",recvbytes); portable_mutex_lock(&myinfo->dexmutex); + ipbits = 0; if ( strcmp(handler,"DEX") == 0 ) - { ipbits = *retptr; + else + { + retstr = clonestr((char *)retptr); + if ( (retjson= cJSON_Parse(retstr)) != 0 ) + { + ipbits = juint(retjson,"randipbits"); + free_json(retjson); + if ( 0 && ipbits != 0 ) + printf("GOT randipbits.%08x\n",ipbits); + } + } + if ( ipbits != 0 ) + { expand_ipbits(ipaddr,ipbits); n = myinfo->numdexipbits; for (i=0; inumdexipbits,str); } } - else - { - retstr = clonestr((char *)retptr); - //printf("REQ got.%d (%s)\n",recvbytes,retstr); - } nn_freemsg(retptr); portable_mutex_unlock(&myinfo->dexmutex); } @@ -186,25 +225,17 @@ 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) +void dpow_randipbits(struct supernet_info *myinfo,struct iguana_info *coin,cJSON *retjson) { - 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 ) + int32_t m; uint32_t ipbits; char *coinstr; + if ( (m= myinfo->numdpowipbits) > 0 ) { - memcpy(&serialized[len],dexreq->name,sizeof(dexreq->name)), len += sizeof(dexreq->name); - serialized[len++] = dexreq->func; + ipbits = myinfo->dpowipbits[(uint32_t)rand() % m]; + jaddnum(retjson,"randipbits",ipbits); + //printf("add randipbits.%08x\n",ipbits); } - else - { - memcpy(dexreq->name,&serialized[len],sizeof(dexreq->name)), len += sizeof(dexreq->name); - dexreq->func = serialized[len++]; - } - return(len); + if ( (coinstr= jstr(retjson,"coin")) == 0 ) + jaddstr(retjson,"coin",coin->symbol); } char *dex_response(int32_t *broadcastflagp,struct supernet_info *myinfo,struct dex_nanomsghdr *dexp) @@ -220,43 +251,74 @@ char *dex_response(int32_t *broadcastflagp,struct supernet_info *myinfo,struct d if ( dexreq.func == 'T' ) { if ( (retjson= dpow_gettransaction(myinfo,coin,dexreq.hash)) != 0 ) + { + dpow_randipbits(myinfo,coin,retjson); retstr = jprint(retjson,1); + } } else if ( dexreq.func == 'O' ) { if ( (retjson= dpow_gettxout(myinfo,coin,dexreq.hash,dexreq.shortarg)) != 0 ) + { + dpow_randipbits(myinfo,coin,retjson); retstr = jprint(retjson,1); + } } else if ( dexreq.func == 'H' ) { hash2 = dpow_getblockhash(myinfo,coin,dexreq.intarg); bits256_str(buf,hash2); - retstr = clonestr(buf); + if ( (retstr= clonestr(buf)) != 0 && (retjson= cJSON_Parse(retstr)) != 0 ) + { + dpow_randipbits(myinfo,coin,retjson); + free(retstr); + retstr = jprint(retjson,1); + } } else if ( dexreq.func == 'B' ) { if ( (retjson= dpow_getblock(myinfo,coin,dexreq.hash)) != 0 ) + { + dpow_randipbits(myinfo,coin,retjson); retstr = jprint(retjson,1); + } } else if ( dexreq.func == 'I' ) { if ( (retjson= dpow_getinfo(myinfo,coin)) != 0 ) + { + dpow_randipbits(myinfo,coin,retjson); retstr = jprint(retjson,1); + } } else if ( dexreq.func == 'U' ) { if ( (retjson= dpow_listunspent(myinfo,coin,(char *)&dexp->packet[datalen])) != 0 ) + { + dpow_randipbits(myinfo,coin,retjson); retstr = jprint(retjson,1); + } } else if ( dexreq.func == 'P' ) { hash2 = dpow_getbestblockhash(myinfo,coin); bits256_str(buf,hash2); - retstr = clonestr(buf); + if ( (retstr= clonestr(buf)) != 0 && (retjson= cJSON_Parse(retstr)) != 0 ) + { + dpow_randipbits(myinfo,coin,retjson); + free(retstr); + retstr = jprint(retjson,1); + } } 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 == '*' ) { @@ -266,7 +328,10 @@ char *dex_response(int32_t *broadcastflagp,struct supernet_info *myinfo,struct d { //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 ) + { + dpow_randipbits(myinfo,coin,retjson); retstr = jprint(retjson,1); + } } else if ( dexreq.func == 'A' ) { @@ -280,10 +345,22 @@ char *dex_response(int32_t *broadcastflagp,struct supernet_info *myinfo,struct d { printf("funcA.(%s)\n",retstr); } + if ( retstr != 0 && (retjson= cJSON_Parse(retstr)) != 0 ) + { + dpow_randipbits(myinfo,coin,retjson); + free(retstr); + retstr = jprint(retjson,1); + } } else if ( dexreq.func == 'V' ) { retstr = dpow_validateaddress(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 printf("(%s) not active\n",dexreq.name); if ( retstr == 0 ) @@ -292,17 +369,45 @@ char *dex_response(int32_t *broadcastflagp,struct supernet_info *myinfo,struct d return(retstr); } -char *_dex_sendrequest(struct supernet_info *myinfo,struct dex_request *dexreq) +char *dex_reqsend(struct supernet_info *myinfo,char *handler,uint8_t *data,int32_t datalen,int32_t M) +{ + char *retstrs[64]; int32_t 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 ) + { + if ( ++j == M ) + break; + } + else if ( i < max ) + free(retstrs[j]); + } + //printf("automatic retry.%d of %d\n",i,max); + } + if ( j == 1 ) + return(retstrs[0]); + else + { + for (i=0; iname) >= 0 ) { datalen = dex_rwrequest(1,packet,dexreq); - return(dex_reqsend(myinfo,"request",packet,datalen)); + return(dex_reqsend(myinfo,"request",packet,datalen,M)); } else return(clonestr("{\"error\":\"not notarychain\"}")); } -char *_dex_sendrequeststr(struct supernet_info *myinfo,struct dex_request *dexreq,char *str) +char *_dex_sendrequeststr(struct supernet_info *myinfo,struct dex_request *dexreq,char *str,int32_t M) { uint8_t *packet; int32_t datalen,slen; char *retstr; if ( iguana_isnotarychain(dexreq->name) >= 0 ) @@ -312,7 +417,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); + retstr = dex_reqsend(myinfo,"request",packet,datalen,M); free(packet); return(retstr); } else return(clonestr("{\"error\":\"not notarychain\"}")); @@ -325,7 +430,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)); + return(_dex_sendrequest(myinfo,&dexreq,1)); } char *_dex_gettxout(struct supernet_info *myinfo,char *symbol,bits256 txid,int32_t vout) @@ -337,7 +442,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)); + return(_dex_sendrequest(myinfo,&dexreq,3)); } char *_dex_getinfo(struct supernet_info *myinfo,char *symbol) @@ -346,7 +451,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)); + return(_dex_sendrequest(myinfo,&dexreq,1)); } char *_dex_alladdresses(struct supernet_info *myinfo,char *symbol) @@ -355,7 +460,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)); + return(_dex_sendrequest(myinfo,&dexreq,1)); } char *_dex_getblock(struct supernet_info *myinfo,char *symbol,bits256 hash2) @@ -365,7 +470,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)); + return(_dex_sendrequest(myinfo,&dexreq,1)); } char *_dex_getblockhash(struct supernet_info *myinfo,char *symbol,int32_t height) @@ -375,7 +480,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)); + return(_dex_sendrequest(myinfo,&dexreq,1)); } char *_dex_getbestblockhash(struct supernet_info *myinfo,char *symbol) @@ -384,7 +489,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)); + return(_dex_sendrequest(myinfo,&dexreq,3)); } char *_dex_sendrawtransaction(struct supernet_info *myinfo,char *symbol,char *signedtx) @@ -393,7 +498,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)); + return(_dex_sendrequeststr(myinfo,&dexreq,signedtx,3)); } char *_dex_importaddress(struct supernet_info *myinfo,char *symbol,char *address) @@ -402,7 +507,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)); + return(_dex_sendrequeststr(myinfo,&dexreq,address,1)); } char *_dex_validateaddress(struct supernet_info *myinfo,char *symbol,char *address) @@ -411,7 +516,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)); + return(_dex_sendrequeststr(myinfo,&dexreq,address,1)); } char *_dex_listunspent(struct supernet_info *myinfo,char *symbol,char *address) @@ -420,7 +525,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)); + return(_dex_sendrequeststr(myinfo,&dexreq,address,1)); } char *_dex_listtransactions(struct supernet_info *myinfo,char *symbol,char *address,int32_t count,int32_t skip) @@ -431,7 +536,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)); + return(_dex_sendrequeststr(myinfo,&dexreq,address,1)); } int32_t dex_crc32find(struct supernet_info *myinfo,uint32_t crc32) @@ -1598,9 +1703,12 @@ void komodo_assetcoins(int32_t fullnode) coin->chain->pubtype = 60; coin->chain->p2shtype = 85; coin->chain->wiftype = 188; - sprintf(confstr,"%s.conf",CURRENCIES[i]); - sprintf(path,"%s/.komodo/%s",userhome,CURRENCIES[i]); - extract_userpass(coin->chain->serverport,coin->chain->userpass,CURRENCIES[i],coin->chain->userhome,path,confstr); + if ( fullnode < 0 ) + { + sprintf(confstr,"%s.conf",CURRENCIES[i]); + sprintf(path,"%s/.komodo/%s",userhome,CURRENCIES[i]); + extract_userpass(coin->chain->serverport,coin->chain->userpass,CURRENCIES[i],coin->chain->userhome,path,confstr); + } } printf("(%s %u) ",CURRENCIES[i],port); } diff --git a/iguana/dpow/dpow_rpc.c b/iguana/dpow/dpow_rpc.c index 48eac3fc9..33045a8c8 100755 --- a/iguana/dpow/dpow_rpc.c +++ b/iguana/dpow/dpow_rpc.c @@ -436,81 +436,72 @@ char *dpow_alladdresses(struct supernet_info *myinfo,struct iguana_info *coin) void update_alladdresses(struct supernet_info *myinfo,struct iguana_info *coin,char *address) { - char *alladdresses,*outstr,fname[1024],buf[512]; cJSON *alljson; int32_t i,n; FILE *fp; - if ( (alladdresses= dpow_alladdresses(myinfo,coin)) != 0 ) - { - if ( (alljson= cJSON_Parse(alladdresses)) != 0 ) + struct hashstr_item *hashstr,*tmp; cJSON *alljson; char *alladdresses,*outstr,fname[1024]; int32_t i,n,saveflag = 0; + HASH_FIND(hh,coin->alladdresses,address,strlen(address),hashstr); + if ( hashstr == 0 ) + { + hashstr = calloc(1,sizeof(*hashstr)); + strncpy(hashstr->address,address,sizeof(hashstr->address)); + HASH_ADD_KEYPTR(hh,coin->alladdresses,hashstr->address,strlen(address),hashstr); + saveflag = 1; + if ( (alladdresses= dpow_alladdresses(myinfo,coin)) != 0 ) { - if ( is_cJSON_Array(alljson) != 0 && (n= cJSON_GetArraySize(alljson)) > 0 ) + if ( (alljson= cJSON_Parse(alladdresses)) != 0 ) { - for (i=0; i 0 ) { - jaddistr(alljson,address); - outstr = jprint(alljson,0); - sprintf(fname,"%s/alladdresses.%s",GLOBAL_CONFSDIR,coin->symbol), OS_compatible_path(fname); - if ( (fp= fopen(fname,"wb")) != 0 ) - { - fwrite(outstr,1,strlen(outstr)+1,fp); - fclose(fp); - printf("importaddress.(%s) -> alladdresses.%s\n",address,coin->symbol); - } - free(outstr); + for (i=0; ialladdresses,hashstr,tmp) + { + jaddistr(alljson,hashstr->address); + } + outstr = jprint(alljson,0); sprintf(fname,"%s/alladdresses.%s",GLOBAL_CONFSDIR,coin->symbol), OS_compatible_path(fname); - printf("%s first importaddress.(%s) -> %s\n",coin->symbol,address,fname); if ( (fp= fopen(fname,"wb")) != 0 ) { - fwrite(buf,1,strlen(buf)+1,fp); + fwrite(outstr,1,strlen(outstr)+1,fp); fclose(fp); + printf("importaddress.(%s) -> alladdresses.%s\n",address,coin->symbol); } - } -} - -void init_alladdresses(struct supernet_info *myinfo,struct iguana_info *coin) -{ - char *alladdresses,*retstr; cJSON *alljson; int32_t i,n; - if ( (alladdresses= _dex_alladdresses(myinfo,coin->symbol)) != 0 ) - { - printf("(%s) ALL.(%s)\n",coin->symbol,alladdresses); - if ( (alljson= cJSON_Parse(alladdresses)) != 0 ) - { - if ( is_cJSON_Array(alljson) != 0 && (n= cJSON_GetArraySize(alljson)) > 0 ) - { - for (i=0; iFULLNODE < 0 ) @@ -518,12 +509,31 @@ char *dpow_importaddress(struct supernet_info *myinfo,struct iguana_info *coin,c sprintf(buf,"[\"%s\", \"%s\", false]",address,address); retstr = bitcoind_passthru(coin->symbol,coin->chain->serverport,coin->chain->userpass,"importaddress",buf); printf("%s importaddress.(%s) -> (%s)\n",coin->symbol,address,retstr); - update_alladdresses(myinfo,coin,address); return(retstr); } else return(0); } +void init_alladdresses(struct supernet_info *myinfo,struct iguana_info *coin) +{ + char *alladdresses,*retstr; cJSON *alljson; int32_t i,n; + if ( (alladdresses= dpow_alladdresses(myinfo,coin)) != 0 ) + { + printf("(%s) ALL.(%s)\n",coin->symbol,alladdresses); + if ( (alljson= cJSON_Parse(alladdresses)) != 0 ) + { + if ( is_cJSON_Array(alljson) != 0 && (n= cJSON_GetArraySize(alljson)) > 0 ) + { + for (i=0; i> 1; - if ( len <= sizeof(bp->ratifyrawtx[0]) ) + if ( len <= sizeof(bp->ratifyrawtx[src_or_dest]) ) { decode_hex(bp->ratifyrawtx[src_or_dest],len,rawtx),bp->rawratifiedlens[src_or_dest] = len; } diff --git a/iguana/iguana777.c b/iguana/iguana777.c index bde87f374..03c6de357 100755 --- a/iguana/iguana777.c +++ b/iguana/iguana777.c @@ -27,10 +27,10 @@ struct iguana_info *iguana_coinfind(char *symbol) struct iguana_info *coin=0; uint32_t symbolcrc; struct supernet_info *myinfo = SuperNET_MYINFO(0); while ( myinfo->allcoins_being_added != 0 ) { - sleep(3); + sleep(1); if ( myinfo->allcoins_being_added != 0 ) printf("wait for coinadd to complete, OK if rare\n"); - sleep(3); + sleep(1); } symbolcrc = calc_crc32(0,symbol,(int32_t)strlen(symbol)); //portable_mutex_lock(&myinfo->allcoins_mutex); @@ -58,6 +58,8 @@ struct iguana_info *iguana_coinadd(char *symbol,char *name,cJSON *argjson,int32_ else { coin->chain = iguana_chainfind(myinfo,(char *)symbol,argjson,1); + //if ( coin->FULLNODE >= 0 ) + // coin->chain->userpass[0] = 0; coin->peers = calloc(1,sizeof(*coin->peers)); for (j=0; jactive = juint(json,"active"); if ( (coin->minconfirms= minconfirms) == 0 ) coin->minconfirms = (strcmp(symbol,"BTC") == 0) ? 3 : 10; - if ( coin->chain == 0 && (coin->chain= iguana_createchain(json)) == 0 ) - { - printf("cant initialize chain.(%s)\n",jstr(json,0)); - strcpy(coin->name,"illegalcoin"); - coin->symbol[0] = 0; - return(0); - } if ( jobj(json,"RELAY") != 0 ) coin->FULLNODE = jint(json,"RELAY"); else coin->FULLNODE = (strcmp(coin->symbol,"BTCD") == 0); @@ -1159,6 +1154,15 @@ struct iguana_info *iguana_setcoin(char *symbol,void *launched,int32_t maxpeers, else coin->VALIDATENODE = (strcmp(coin->symbol,"BTCD") == 0); if ( coin->VALIDATENODE > 0 || coin->FULLNODE > 0 ) SuperNET_MYINFO(0)->IAMRELAY++; + if ( coin->chain == 0 && (coin->chain= iguana_createchain(json)) == 0 ) + { + printf("cant initialize chain.(%s)\n",jstr(json,0)); + strcpy(coin->name,"illegalcoin"); + //if ( coin->FULLNODE >= 0 ) + // coin->chain->userpass[0] = 0; + coin->symbol[0] = 0; + return(0); + } #ifdef __PNACL coin->VALIDATENODE = coin->FULLNODE = 0; #endif @@ -1202,10 +1206,13 @@ int32_t iguana_launchcoin(struct supernet_info *myinfo,char *symbol,cJSON *json, coins = mycalloc('A',1+1,sizeof(*coins)); if ( (coin= iguana_setcoin(symbol,coins,maxpeers,maxrecvcache,services,initialheight,maphash,minconfirms,maxrequests,maxbundles,json,virtcoin)) != 0 ) { - coins[0] = (void *)((long)1); - coins[1] = coin; - printf("launch.%p coinloop for.%s services.%llx started.%p peers.%p\n",coin,coin->symbol,(long long)services,coin->started,coin->peers); - coin->launched = iguana_launch(coin,"iguana_coinloop",iguana_coinloop,coins,IGUANA_PERMTHREAD); + if ( iguana_isnotarychain(coin->symbol) < 0 ) + { + coins[0] = (void *)((long)1); + coins[1] = coin; + printf("launch.%p coinloop for.%s services.%llx started.%p peers.%p\n",coin,coin->symbol,(long long)services,coin->started,coin->peers); + coin->launched = iguana_launch(coin,"iguana_coinloop",iguana_coinloop,coins,IGUANA_PERMTHREAD); + } coin->active = 1; coin->started = 0; return(1); diff --git a/iguana/iguana_notary.c b/iguana/iguana_notary.c index 3f76a9aa4..4eaff6fe7 100755 --- a/iguana/iguana_notary.c +++ b/iguana/iguana_notary.c @@ -381,7 +381,7 @@ TWO_STRINGS(dex,send,hex,handler) decode_hex(data,datalen,hex); if ( handler == 0 || handler[0] == 0 ) handler = "DEX"; - if ( (retstr= dex_reqsend(myinfo,handler,data,datalen)) == 0 ) + if ( (retstr= dex_reqsend(myinfo,handler,data,datalen,1)) == 0 ) return(clonestr("{\"result\":\"success\"}")); else return(retstr); } else return(clonestr("{\"error\":\"dex send: invalid hex\"}")); diff --git a/includes/iguana_structs.h b/includes/iguana_structs.h index 0552c6854..e1a0d61bc 100755 --- a/includes/iguana_structs.h +++ b/includes/iguana_structs.h @@ -464,6 +464,8 @@ struct iguana_RTtxid struct iguana_RTspend *spends[]; }; +struct hashstr_item { UT_hash_handle hh; char address[40]; }; + struct iguana_info { UT_hash_handle hh; @@ -533,6 +535,7 @@ struct iguana_info uint32_t lastbesthashtime; bits256 lastbesthash; int32_t lastbestheight; struct iguana_block *RTblocks[65536]; uint8_t *RTrawdata[65536]; int32_t RTrecvlens[65536],RTnumtx[65536]; struct iguana_RTtxid *RTdataset; struct iguana_RTaddr *RTaddrs; + struct hashstr_item *alladdresses; }; struct vin_signer { bits256 privkey; char coinaddr[64]; uint8_t siglen,sig[80],rmd160[20],pubkey[66]; };