Browse Source

Merge pull request #186 from jl777/dev

Dev
win-cross
jl777 8 years ago
committed by GitHub
parent
commit
a185bf5f09
  1. 2
      basilisk/basilisk_MSG.c
  2. 2
      gecko/gecko.c
  3. 2
      iguana/dPoW.h
  4. 198
      iguana/dpow/dpow_network.c
  5. 88
      iguana/dpow/dpow_rpc.c
  6. 2
      iguana/dpow/dpow_tx.c
  7. 25
      iguana/iguana777.c
  8. 2
      iguana/iguana_notary.c
  9. 3
      includes/iguana_structs.h

2
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);

2
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 )

2
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);

198
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; i<size; i++)
// printf("%02x",((uint8_t *)dexp)[i]);
printf(" uniq DEX_PACKET.[%d] crc.%x lag.%d (%d %d)\n",size,calc_crc32(0,dexp->packet,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; i<n; i++)
@ -167,11 +211,6 @@ char *dex_reqsend(struct supernet_info *myinfo,char *handler,uint8_t *data,int32
printf("%d: req connect (%s)\n",myinfo->numdexipbits,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 )
{
memcpy(&serialized[len],dexreq->name,sizeof(dexreq->name)), len += sizeof(dexreq->name);
serialized[len++] = dexreq->func;
}
else
int32_t m; uint32_t ipbits; char *coinstr;
if ( (m= myinfo->numdpowipbits) > 0 )
{
memcpy(dexreq->name,&serialized[len],sizeof(dexreq->name)), len += sizeof(dexreq->name);
dexreq->func = serialized[len++];
ipbits = myinfo->dpowipbits[(uint32_t)rand() % m];
jaddnum(retjson,"randipbits",ipbits);
//printf("add randipbits.%08x\n",ipbits);
}
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,8 +328,11 @@ 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' )
{
retstr = dpow_importaddress(myinfo,coin,(char *)&dexp->packet[datalen]);
@ -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; i<j; i++)
printf("(%s).%d\n",retstrs[i],i);
}
return(retstrs[0]);
}
char *_dex_sendrequest(struct supernet_info *myinfo,struct dex_request *dexreq,int32_t M)
{
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));
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,10 +1703,13 @@ void komodo_assetcoins(int32_t fullnode)
coin->chain->pubtype = 60;
coin->chain->p2shtype = 85;
coin->chain->wiftype = 188;
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);
}
printf("ports\n");

88
iguana/dpow/dpow_rpc.c

@ -436,7 +436,14 @@ 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;
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 ( (alljson= cJSON_Parse(alladdresses)) != 0 )
@ -445,72 +452,56 @@ void update_alladdresses(struct supernet_info *myinfo,struct iguana_info *coin,c
{
for (i=0; i<n; i++)
if ( strcmp(address,jstri(alljson,i)) == 0 )
break;
if ( i == n )
{
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);
saveflag = 0;
break;
}
}
free_json(alljson);
}
free(alladdresses);
}
else
}
if ( saveflag != 0 )
{
sprintf(buf,"[\"%s\"]",address);
FILE *fp;
alljson = cJSON_CreateArray();
HASH_ITER(hh,coin->alladdresses,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; i<n; i++)
if ( (retstr= dpow_importaddress(myinfo,coin,jstri(alljson,i))) != 0 )
free(retstr);
}
free_json(alljson);
}
free(alladdresses);
free(outstr);
}
}
char *dpow_importaddress(struct supernet_info *myinfo,struct iguana_info *coin,char *address)
{
char buf[1024],*retstr; cJSON *validatejson; int32_t doneflag = 0;
char buf[1024],*retstr; cJSON *validatejson; int32_t isvalid=0,doneflag = 0;
if ( (retstr= dpow_validateaddress(myinfo,coin,address)) != 0 )
{
if ( (validatejson= cJSON_Parse(retstr)) != 0 )
{
if ( (isvalid= is_cJSON_True(jobj(validatejson,"isvalid")) != 0) != 0 )
{
if ( is_cJSON_True(jobj(validatejson,"iswatchonly")) != 0 || is_cJSON_True(jobj(validatejson,"ismine")) != 0 )
doneflag = 1;
}
free_json(validatejson);
}
free(retstr);
retstr = 0;
}
if ( isvalid == 0 )
return(clonestr("{\"isvalid\":false}"));
update_alladdresses(myinfo,coin,address);
if ( doneflag != 0 )
return(0); // success
if ( coin->FULLNODE < 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<n; i++)
if ( (retstr= dpow_importaddress(myinfo,coin,jstri(alljson,i))) != 0 )
free(retstr);
}
free_json(alljson);
}
free(alladdresses);
}
}
int32_t dpow_getchaintip(struct supernet_info *myinfo,bits256 *blockhashp,uint32_t *blocktimep,bits256 *txs,uint32_t *numtxp,struct iguana_info *coin)
{
int32_t n,i,height = -1,maxtx = *numtxp; bits256 besthash,oldhash; cJSON *array,*json;

2
iguana/dpow/dpow_tx.c

@ -512,7 +512,7 @@ int32_t dpow_signedtxgen(struct supernet_info *myinfo,struct dpow_info *dp,struc
if ( useratified != 0 )
{
len = (int32_t)strlen(rawtx) >> 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;
}

25
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; j<IGUANA_MAXPEERS; j++)
{
@ -1144,13 +1146,6 @@ struct iguana_info *iguana_setcoin(char *symbol,void *launched,int32_t maxpeers,
coin->active = 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
@ -1201,11 +1205,14 @@ int32_t iguana_launchcoin(struct supernet_info *myinfo,char *symbol,cJSON *json,
iguana_coinargs(symbol,&maxrecvcache,&minconfirms,&maxpeers,&initialheight,&services,&maxrequests,&maxbundles,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 )
{
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);

2
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\"}"));

3
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]; };

Loading…
Cancel
Save