Browse Source

test

release/v0.1
jl777 9 years ago
parent
commit
2890c37e4e
  1. 688
      basilisk/basilisk.c
  2. 17
      basilisk/basilisk.h
  3. 188
      basilisk/basilisk_CMD.c
  4. 10
      basilisk/basilisk_bitcoin.c
  5. 20
      deprecated/obsolete.h
  6. 10
      iguana/SuperNET.c
  7. 34
      iguana/SuperNET.h
  8. 73
      iguana/SuperNET_category.c
  9. 16
      iguana/SuperNET_hexmsg.c
  10. 17
      iguana/coins/extract_genesis.c
  11. 2
      iguana/coins/genbtc
  12. 1
      iguana/coins/gennmc
  13. 2
      iguana/coins/genzcash
  14. 1
      iguana/coins/m_extract_genesis
  15. 4
      iguana/confs/ZEC_peers.txt
  16. 72
      iguana/iguana777.c
  17. 28
      iguana/iguana777.h
  18. 24
      iguana/iguana_accept.c
  19. 16
      iguana/iguana_bitmap.c
  20. 2
      iguana/iguana_blocks.c
  21. 18
      iguana/iguana_bundles.c
  22. 23
      iguana/iguana_chains.c
  23. 35
      iguana/iguana_init.c
  24. 12
      iguana/iguana_instantdex.c
  25. 34
      iguana/iguana_json.c
  26. 10
      iguana/iguana_msg.c
  27. 12
      iguana/iguana_payments.c
  28. 66
      iguana/iguana_peers.c
  29. 10
      iguana/iguana_ramchain.c
  30. 16
      iguana/iguana_realtime.c
  31. 22
      iguana/iguana_recv.c
  32. 14
      iguana/iguana_sign.c
  33. 2
      iguana/iguana_spendvectors.c
  34. 11
      iguana/iguana_stake.c
  35. 8
      iguana/iguana_tx.c
  36. 2
      iguana/iguana_txidfind.c
  37. 2
      iguana/iguana_wallet.c
  38. 12
      iguana/main.c
  39. 20
      iguana/pangea_api.c
  40. 9
      iguana/pangea_hand.c
  41. 9
      iguana/pangea_json.c
  42. 2
      iguana/tests/get
  43. 2
      iguana/tests/set

688
basilisk/basilisk.c

@ -19,6 +19,390 @@ typedef char *basilisk_coinfunc(struct supernet_info *myinfo,struct iguana_info
typedef char *basilisk_servicefunc(struct supernet_info *myinfo,char *CMD,struct iguana_peer *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 pubkey,int32_t from_basilisk); typedef char *basilisk_servicefunc(struct supernet_info *myinfo,char *CMD,struct iguana_peer *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 pubkey,int32_t from_basilisk);
typedef struct basilisk_item *basilisk_requestfunc(struct basilisk_item *Lptr,struct supernet_info *myinfo,bits256 pubkey,cJSON *valsobj,uint8_t *data,int32_t datalen); typedef struct basilisk_item *basilisk_requestfunc(struct basilisk_item *Lptr,struct supernet_info *myinfo,bits256 pubkey,cJSON *valsobj,uint8_t *data,int32_t datalen);
uint32_t basilisk_calcnonce(struct supernet_info *myinfo,uint8_t *data,int32_t datalen,uint32_t nBits)
{
int32_t i,numiters = 0; bits256 hash,hash2,threshold; uint32_t basilisktag;
vcalc_sha256(0,hash.bytes,data,datalen);
threshold = bits256_from_compact(nBits);
for (i=0; i<numiters; i++)
{
//OS_randombytes((void *)hash.uints,sizeof(basilisktag));
hash.uints[0] = rand();
vcalc_sha256(0,hash2.bytes,hash.bytes,sizeof(hash));
if ( bits256_cmp(threshold,hash2) > 0 )
break;
}
iguana_rwnum(0,(void *)hash.uints,sizeof(basilisktag),&basilisktag);
iguana_rwnum(1,&data[-sizeof(basilisktag)],sizeof(basilisktag),&basilisktag);
char str[65],str2[65]; printf("found hash after numiters.%d %s vs %s basilisktag.%u\n",numiters,bits256_str(str,threshold),bits256_str(str2,hash2),basilisktag);
return(basilisktag);
}
char *basilisk_addhexstr(char **ptrp,cJSON *valsobj,char *strbuf,int32_t strsize,uint8_t *data,int32_t datalen)
{
*ptrp = 0;
if ( data != 0 && datalen > 0 )
{
if ( jobj(valsobj,"data") != 0 )
{
printf("basilisk_addhexstr warning: already have data object\n");
jdelete(valsobj,"data");
}
if ( (datalen<<1)+1 > strsize )
{
strbuf = calloc(1,(datalen << 1) + 1);
*ptrp = (void *)strbuf;
}
init_hexbytes_noT(strbuf,data,datalen);
jaddstr(valsobj,"data",strbuf);
} else return(0);
return(strbuf);
}
uint8_t *get_dataptr(uint8_t **ptrp,int32_t *datalenp,uint8_t *space,int32_t spacesize,char *hexstr)
{
*ptrp = 0; uint8_t *data = 0;
if ( hexstr != 0 && (*datalenp= is_hexstr(hexstr,0)) > 0 )
{
*datalenp >>= 1;
if ( *datalenp <= spacesize )
data = space;
else *ptrp = data = calloc(1,*datalenp);
decode_hex(data,*datalenp,hexstr);
}
return(data);
}
uint8_t *basilisk_jsondata(void **ptrp,uint8_t *space,int32_t spacesize,int32_t *datalenp,char *symbol,cJSON *sendjson,uint32_t basilisktag)
{
char *sendstr,*hexstr; uint8_t *data; bits256 pubkey; int32_t i,datalen,hexlen=0,extrasize,havepubkey=1;
if ( jobj(sendjson,"coin") == 0 )
jaddstr(sendjson,"coin",symbol);
if ( jobj(sendjson,"pubkey") != 0 )
{
havepubkey = 1;
pubkey = jbits256(sendjson,"pubkey");
}
if ( (hexstr= jstr(sendjson,"data")) != 0 && (hexlen= is_hexstr(hexstr,0)) > 0 )
hexlen >>= 1;
extrasize = (int32_t)(sizeof(struct iguana_msghdr) + sizeof(basilisktag));
*ptrp = 0;
sendstr = jprint(sendjson,0);
datalen = (int32_t)strlen(sendstr) + 1;
if ( (datalen + extrasize + hexlen + havepubkey*(sizeof(pubkey)+1)) <= spacesize )
data = space;
else
{
data = calloc(1,datalen + extrasize + hexlen + havepubkey*(sizeof(pubkey)+1));
*ptrp = data;
}
data += extrasize;
memcpy(data,sendstr,datalen);
free(sendstr);
if ( havepubkey != 0 || hexlen != 0 )
{
if ( (data[datalen++]= havepubkey) != 0 )
{
for (i=0; i<32; i++)
data[datalen++] = pubkey.bytes[i];
}
}
if ( hexlen > 0 )
{
decode_hex(&data[datalen],hexlen,hexstr);
datalen += hexlen;
}
*datalenp = datalen;
return(data);
}
char *basilisk_coinbase(struct supernet_info *myinfo,struct iguana_info *coin,bits256 *txidp,uint8_t *data,int32_t datalen,bits256 coinbasespend,cJSON *txjson)
{
char *rawtx; struct vin_info V;
if ( txjson == 0 )
txjson = bitcoin_txcreate(1,0);
bitcoin_txinput(coin,txjson,coinbasespend,-1,0xffffffff,0,0,data,datalen,0,0);
rawtx = bitcoin_json2hex(myinfo,coin,txidp,txjson,&V);
free_json(txjson);
return(rawtx);
}
cJSON *basilisk_paymentsobj(cJSON *txjson,cJSON *valsobj)
{
cJSON *item,*array; char *coinaddr; uint64_t satoshis; uint8_t addrtype,rmd160[20],outputscript[512]; int32_t i,n,scriptlen;
if ( txjson == 0 )
txjson = bitcoin_txcreate(1,juint(valsobj,"locktime"));
if ( (array= jarray(&n,valsobj,"payments")) != 0 && n > 0 )
{
for (i=0; i<n; i++)
{
item = jitem(array,i);
if ( (coinaddr= jfieldname(item)) != 0 && (satoshis= j64bits(item,coinaddr)) > 0 )
{
bitcoin_addr2rmd160(&addrtype,rmd160,coinaddr);
scriptlen = bitcoin_standardspend(outputscript,0,rmd160);
bitcoin_txoutput(txjson,outputscript,scriptlen,satoshis);
}
}
}
return(txjson);
}
char *basilisk_block(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_block *block,int32_t version,uint32_t timestamp,uint32_t *noncep,bits256 prevblock,uint32_t nBits,int32_t height,char **txptrs,int32_t txn_count,uint8_t *coinbase,int32_t coinbaselen,bits256 coinbasespend,cJSON *txjson)
{
struct iguana_info *btcd; uint8_t serialized[sizeof(*block)],space[16384],*txdata,*allocptr = 0; int32_t i,n,totaltxlen=0,txlen,numiters=1000000; char *coinbasestr,*blockstr=0; bits256 *txids=0,txspace[256],threshold;
if ( (btcd= iguana_coinfind("BTCD")) == 0 )
{
printf("basilisk needs BTCD\n");
return(0);
}
if ( txn_count+2 < sizeof(space)/sizeof(*space) )
{
txids = txspace;
memset(txids,0,sizeof(*txids) * (txn_count+2));
} else txids = calloc(txn_count+2,sizeof(*txids));
if ( txn_count > 0 )
{
for (i=0; i<txn_count; i++)
{
if ( (txdata= get_dataptr(&allocptr,&txlen,space,sizeof(space),txptrs[i])) == 0 )
{
printf("basilisk_block error tx.%d\n",i);
if ( txids != txspace )
free(txids);
return(0);
}
totaltxlen += txlen;
txids[i+1] = bits256_doublesha256(0,txdata,txlen);
if ( allocptr != 0 )
free(allocptr);
}
}
if ( (coinbasestr= basilisk_coinbase(myinfo,coin,&txids[0],coinbase,coinbaselen,coinbasespend,txjson)) != 0 )
{
memset(&block,0,sizeof(block));
block->RO.version = version;
block->RO.prev_block = prevblock;
block->RO.merkle_root = iguana_merkle(txids,txn_count + 1);
block->RO.timestamp = timestamp;
block->RO.bits = nBits;
block->RO.txn_count = (txn_count + 1);
block->height = height;
threshold = bits256_from_compact(nBits);
if ( (block->RO.nonce= *noncep) == 0 )
{
for (i=0; i<numiters; i++)
{
block->RO.nonce = rand();
n = iguana_serialize_block(coin->chain,&block->RO.hash2,serialized,block);
if ( bits256_cmp(threshold,block->RO.hash2) > 0 )
break;
}
}
*noncep = block->RO.nonce;
n = iguana_serialize_block(coin->chain,&block->RO.hash2,serialized,block);
if ( bits256_cmp(threshold,block->RO.hash2) > 0 )
{
blockstr = calloc(1,strlen(coinbasestr) + (totaltxlen+n)*2 + 1);
init_hexbytes_noT(blockstr,serialized,n);
strcat(blockstr,coinbasestr);
for (i=0; i<txn_count; i++)
strcat(blockstr,txptrs[i]);
}
free(coinbasestr);
}
if ( txids != txspace )
free(txids);
return(blockstr);
}
int32_t basilisk_hashstampsfind(struct hashstamp *stamps,int32_t max,struct basilisk_sequence *seq,bits256 hash,uint32_t reftimestamp)
{
int32_t j,i = 0,foundflag = -1,gap = -1; uint32_t timestamp;
if ( seq->stamps[seq->lasti].timestamp < reftimestamp && seq->lasti >= 3 )
i = seq->lasti - 3;
for (; i<seq->numstamps; i++)
{
if ( (timestamp= seq->stamps[i].timestamp) == 0 || timestamp > reftimestamp )
{
memset(stamps,0,sizeof(*stamps) * max);
for (j=0; j<max && (i - j)>=0; j++)
stamps[j] = seq->stamps[i - j];
return(gap);
}
if ( foundflag < 0 && bits256_cmp(hash,seq->stamps[i].hash2) == 0 )
{
seq->lasti = i;
foundflag = i;
gap = 0;
}
else if ( foundflag >= 0 )
gap++;
}
return(-1);
}
bits256 basilisk_hashstampscalc(struct iguana_info *btcd,bits256 *btchashp,uint32_t reftimestamp)
{
struct hashstamp BTCDstamps[BASILISK_MAXBTCDGAP],BTCstamps[BASILISK_MAXBTCGAP]; bits256 btcdhash;
memset(btcdhash.bytes,0,sizeof(btcdhash));
memset(btchashp,0,sizeof(*btchashp));
if ( basilisk_hashstampsfind(BTCDstamps,BASILISK_MAXBTCDGAP,&btcd->SEQ.BTCD,btcdhash,reftimestamp) < 0 )
{
btcdhash = BTCDstamps[BASILISK_MAXBTCDGAP >> 1].hash2;
if ( basilisk_hashstampsfind(BTCstamps,BASILISK_MAXBTCGAP,&btcd->SEQ.BTC,*btchashp,reftimestamp) < 0 )
*btchashp = BTCstamps[BASILISK_MAXBTCGAP >> 1].hash2;
}
return(btcdhash);
}
// have local coin
int32_t basilisk_hashstampsreverse(struct iguana_info *coin,struct basilisk_sequence *seq,int32_t firstpossible,int32_t max,struct iguana_block *block,uint32_t reftimestamp)
{
uint32_t timestamp; int32_t j,offset;
while ( block != 0 && (timestamp= block->RO.timestamp) > reftimestamp )
block = iguana_blockfind("hashstamps",coin,block->RO.prev_block);
if ( block == 0 )
return(-1);
offset = (block->height - firstpossible);
for (j=0; j<max; j++,offset--)
{
seq->stamps[offset].hash2 = block->RO.hash2;
seq->stamps[offset].timestamp = block->RO.timestamp;
seq->stamps[offset].height = block->height;
if ( offset-- < 0 || (block= iguana_blockfind("revstamp",coin,block->RO.prev_block)) == 0 )
return(block == 0 ? -1 : j);
}
return(j);
}
int32_t basilisk_hashstampset(struct iguana_info *coin,struct hashstamp *stamp,int32_t height)
{
struct iguana_block *block; struct iguana_bundle *bp;
if ( height >= 0 && height < coin->bundlescount && (bp= coin->bundles[height / coin->chain->bundlesize]) != 0 )
{
if ( (block= bp->blocks[height % coin->chain->bundlesize]) != 0 )
{
stamp->hash2 = block->RO.hash2;
stamp->timestamp = block->RO.timestamp;
stamp->height = block->height;
return(0);
}
}
return(-1);
}
int32_t basilisk_hashstampsupdate(struct iguana_info *coin,struct basilisk_sequence *seq,int32_t firstpossible)
{
while ( (firstpossible + seq->numstamps) < coin->blocks.hwmchain.height )
{
if ( seq->numstamps >= seq->maxstamps )
{
seq->maxstamps += coin->chain->bundlesize;
seq->stamps = realloc(seq->stamps,sizeof(*seq->stamps) * seq->maxstamps);
memset(&seq->stamps[seq->numstamps],0,sizeof(*seq->stamps) * (seq->maxstamps - seq->numstamps));
}
if ( basilisk_hashstampset(coin,&seq->stamps[seq->numstamps],firstpossible + seq->numstamps) < 0 )
break;
else seq->numstamps++;
}
seq->longestchain = coin->longestchain;
seq->lastupdate = (uint32_t)time(NULL);
return(seq->numstamps);
}
int32_t basilisk_update(char *symbol,uint32_t reftimestamp)
{
struct basilisk_sequence *seq=0; int32_t max=0,firstpossible=0; struct iguana_info *coin; struct iguana_block *block;
if ( (coin= iguana_coinfind(symbol)) != 0 && (coin->RELAYNODE != 0 || coin->VALIDATENODE != 0) )
{
if ( strcmp(symbol,"BTCD") == 0 )
{
seq = &coin->SEQ.BTCD;
firstpossible = BASILISK_FIRSTPOSSIBLEBTCD;
}
else if ( strcmp(symbol,"BTC") == 0 )
{
seq = &coin->SEQ.BTC;
firstpossible = BASILISK_FIRSTPOSSIBLEBTC;
} else return(-1);
printf("basilisk update.%s %u lag.%d\n",symbol,reftimestamp,(uint32_t)time(NULL)-seq->lastupdate);
if ( basilisk_hashstampsupdate(coin,seq,firstpossible) > 0 )
{
if ( (block= iguana_blockfind("SEQupdate",coin,coin->blocks.hwmchain.RO.hash2)) != 0 )
basilisk_hashstampsreverse(coin,seq,firstpossible,max,block,reftimestamp);
return(0);
}
}
return(-1);
}
/*int32_t basilist_validateblock(cJSON *valsobj)
{
uint32_t now,timestamp;
now = (uint32_t)time(NULL);
if ( (timestamp= juint(valsobj,"timestamp")) < now-BASILISK_MAXBLOCKLAG || timestamp > now+BASILISK_MAXFUTUREBLOCK )
return(-1);
if ( bits256_nonz(prevhash) == 0 )
prevhash = coin->blocks.hwmchain.RO.hash2;
if ( (prevblock= iguana_blockfind("setfield",coin,prevhash)) == 0 )
return(clonestr("{\"error\":\"couldnt find prevhash\"}"));
if ( (prev2= iguana_blockfind("setfield",coin,prevblock->RO.prev_block)) == 0 )
return(clonestr("{\"error\":\"couldnt find prevhash2\"}"));
nonce = juint(valsobj,"nonce");
nBits = iguana_targetbits(coin,&coin->blocks.hwmchain,prevblock,prev2,1,coin->chain->targetspacing,coin->chain->targettimespan);
blocktx = basilisk_block(myinfo,coin,&block,1,timestamp,&nonce,prevhash,nBits,prevblock->height+1,0,0,data,datalen,btcdhash,jobj(valsobj,"coinbase"));
return(0);
}*/
cJSON *basilisk_genesisjson(struct supernet_info *myinfo,struct iguana_info *btcd,char *chainname,cJSON *valsobj)
{
char str[64],str2[64],argbuf[1024],*blockstr; bits256 btchash,btcdhash,zero; uint8_t coinbase[512]; int32_t coinbaselen; uint32_t nonce; struct iguana_block genesis; uint32_t timestamp; cJSON *txjson;
timestamp = (uint32_t)time(NULL);
btcdhash = basilisk_hashstampscalc(btcd,(bits256 *)coinbase,timestamp);
coinbaselen = (int32_t)strlen(chainname);
memcpy(&coinbase[sizeof(btchash)],chainname,coinbaselen);
memset(zero.bytes,0,sizeof(zero));
nonce = 0;
txjson = basilisk_paymentsobj(0,jobj(valsobj,"payments"));
blockstr = basilisk_block(myinfo,btcd,&genesis,BASILISK_DEFAULTVERSION,timestamp,&nonce,zero,BASILISK_DEFAULTDIFF,0,0,0,coinbase,coinbaselen,btcdhash,txjson);
sprintf(argbuf,"(\"privatechain\":\"%s\",\"unitval\":%02x,\"genesishash\":\"%s\",\"genesis\":{\"hashalgo\":\"sha256\",\"version\":1,\"timestamp\":%u,\"nbits\":\"%s\",\"nonce\":%d,\"merkle_root\":\"%s\"},\"genesis_block\":\"%s\"}",chainname,(BASILISK_DEFAULTDIFF >> 24) & 0xff,bits256_str(str,genesis.RO.hash2),timestamp,BASILISK_DEFAULTDIFFSTR,genesis.RO.nonce,bits256_str(str2,genesis.RO.merkle_root),blockstr);
free(blockstr);
return(cJSON_Parse(argbuf));
}
struct iguana_info *basilisk_chain(struct supernet_info *myinfo,cJSON *valsobj)
{
struct iguana_info *btcd; char chainname[64],*chainstr,*keystr; bits256 keyhash,chainhash; struct private_chain *chain; cJSON *argjson;
if ( (chainstr= jstr(valsobj,"chain")) == 0 )
return(0);
if ( (keystr= jstr(valsobj,"key")) != 0 )
vcalc_sha256(0,keyhash.bytes,(uint8_t *)keystr,(int32_t)strlen(keystr));
else keyhash = GENESIS_PUBKEY;
vcalc_sha256(0,chainhash.bytes,(uint8_t *)chainstr,(int32_t)strlen(chainstr));
if ( (chain= category_subscribe(myinfo,chainhash,keyhash)) == 0 )
return(0);
safecopy(chainname,chainstr,30), chainname[30] = 0;
if ( keystr != 0 )
{
strcat(chainname,".");
safecopy(chainname+strlen(chainname),keystr,sizeof(chainname)-1-strlen(chainname));
}
if ( chain->info == 0 )
{
if ( (btcd= iguana_coinfind("BTCD")) != 0 )
{
argjson = basilisk_genesisjson(myinfo,btcd,chainname,valsobj);
if ( (chain->info= iguana_coinadd(chainname,argjson)) != 0 )
iguana_genesis(chain->info,chain->info->chain);
if ( argjson != 0 )
free_json(argjson);
}
}
return(chain->info);
}
char *basilisk_finish(struct basilisk_item *ptr,int32_t besti,char *errstr) char *basilisk_finish(struct basilisk_item *ptr,int32_t besti,char *errstr)
{ {
char *retstr = 0; struct basilisk_item *parent; char *retstr = 0; struct basilisk_item *parent;
@ -95,7 +479,7 @@ struct basilisk_item *basilisk_itemcreate(struct supernet_info *myinfo,char *CMD
int32_t basilisk_sendcmd(struct supernet_info *myinfo,char *destipaddr,char *type,uint32_t *basilisktagp,int32_t encryptflag,int32_t delaymillis,uint8_t *data,int32_t datalen,int32_t fanout,uint32_t nBits) // data must be offset by sizeof(iguana_msghdr)+sizeof(basilisktag) int32_t basilisk_sendcmd(struct supernet_info *myinfo,char *destipaddr,char *type,uint32_t *basilisktagp,int32_t encryptflag,int32_t delaymillis,uint8_t *data,int32_t datalen,int32_t fanout,uint32_t nBits) // data must be offset by sizeof(iguana_msghdr)+sizeof(basilisktag)
{ {
int32_t i,j,r,r2,k,l,s,numiters,val,n=0,offset,havepubkey=0,retval = -1; char cmd[12]; struct iguana_info *coin; struct iguana_peer *addr; bits256 pubkey,threshold,hash,hash2; uint32_t *alreadysent; int32_t i,j,r,r2,k,l,s,val,n=0,offset,havepubkey=0,retval = -1; char cmd[12]; struct iguana_info *coin; struct iguana_peer *addr; bits256 pubkey; uint32_t *alreadysent;
if ( fanout <= 0 ) if ( fanout <= 0 )
fanout = BASILISK_MINFANOUT; fanout = BASILISK_MINFANOUT;
else if ( fanout > BASILISK_MAXFANOUT ) else if ( fanout > BASILISK_MAXFANOUT )
@ -130,21 +514,8 @@ int32_t basilisk_sendcmd(struct supernet_info *myinfo,char *destipaddr,char *typ
} }
alreadysent = calloc(IGUANA_MAXPEERS * IGUANA_MAXCOINS,sizeof(*alreadysent)); alreadysent = calloc(IGUANA_MAXPEERS * IGUANA_MAXCOINS,sizeof(*alreadysent));
iguana_rwnum(1,&data[-sizeof(*basilisktagp)],sizeof(*basilisktagp),basilisktagp); iguana_rwnum(1,&data[-sizeof(*basilisktagp)],sizeof(*basilisktagp),basilisktagp);
if ( *basilisktagp == 0 ) if ( nBits != 0 && *basilisktagp == 0 )
{ *basilisktagp = basilisk_calcnonce(myinfo,data,datalen,nBits);
numiters = 0;
vcalc_sha256(0,hash.bytes,data,datalen);
threshold = bits256_from_compact(nBits);
while ( numiters++ < 1000000 )
{
OS_randombytes((void *)hash.uints,sizeof(*basilisktagp));
vcalc_sha256(0,hash2.bytes,hash.bytes,sizeof(hash));
if ( bits256_cmp(threshold,hash2) > 0 )
break;
}
iguana_rwnum(0,(void *)hash.uints,sizeof(*basilisktagp),basilisktagp);
char str[65],str2[65]; printf("found hash after numiters.%d %s vs %s basilisktag.%u\n",numiters,bits256_str(str,threshold),bits256_str(str2,hash2),*basilisktagp);
}
data -= sizeof(*basilisktagp), datalen += sizeof(*basilisktagp); data -= sizeof(*basilisktagp), datalen += sizeof(*basilisktagp);
memset(cmd,0,sizeof(cmd)); memset(cmd,0,sizeof(cmd));
sprintf(cmd,"SuperNET%s",type); sprintf(cmd,"SuperNET%s",type);
@ -152,16 +523,15 @@ int32_t basilisk_sendcmd(struct supernet_info *myinfo,char *destipaddr,char *typ
for (k=0; k<IGUANA_MAXCOINS; k++) for (k=0; k<IGUANA_MAXCOINS; k++)
{ {
j = (r2 + k) % IGUANA_MAXCOINS; j = (r2 + k) % IGUANA_MAXCOINS;
if ( (coin= Coins[j]) == 0 ) if ( (coin= Coins[j]) == 0 || coin->peers == 0 )
continue; continue;
printf("check coin.%s\n",coin->symbol);
if ( coin->RELAYNODE == 0 && coin->VALIDATENODE == 0 ) if ( coin->RELAYNODE == 0 && coin->VALIDATENODE == 0 )
cmd[0] = 's'; cmd[0] = 's';
else cmd[0] = 'S'; else cmd[0] = 'S';
for (l=0; l<IGUANA_MAXPEERS; l++) for (l=0; l<IGUANA_MAXPEERS; l++)
{ {
i = (l + r) % IGUANA_MAXPEERS; i = (l + r) % IGUANA_MAXPEERS;
if ( (addr= &coin->peers.active[i]) != 0 && addr->usock >= 0 ) if ( (addr= &coin->peers->active[i]) != 0 && addr->usock >= 0 )
{ {
for (s=0; s<n; s++) for (s=0; s<n; s++)
if ( alreadysent[s] == addr->ipbits ) if ( alreadysent[s] == addr->ipbits )
@ -244,47 +614,48 @@ void basilisk_p2p(void *_myinfo,void *_addr,int32_t *delaymillisp,char *senderip
free(ptr); free(ptr);
} }
uint8_t *basilisk_jsondata(void **ptrp,uint8_t *space,int32_t spacesize,int32_t *datalenp,char *symbol,cJSON *sendjson,uint32_t basilisktag) void basilisk_sendback(struct supernet_info *myinfo,char *symbol,char *remoteaddr,uint32_t basilisktag,char *retstr)
{ {
char *sendstr,*hexstr; uint8_t *data; bits256 pubkey; int32_t i,datalen,hexlen=0,extrasize,havepubkey=1; uint8_t *data,space[4096]; void *allocptr; cJSON *valsobj; int32_t datalen,encryptflag=0,delaymillis=0;
if ( jobj(sendjson,"coin") == 0 ) printf("retstr.(%s) -> remote.(%s) basilisktag.%u\n",retstr,remoteaddr,basilisktag);
jaddstr(sendjson,"coin",symbol); if ( retstr != 0 && remoteaddr != 0 && remoteaddr[0] != 0 && strcmp(remoteaddr,"127.0.0.1") != 0 )
if ( jobj(sendjson,"pubkey") != 0 )
{ {
havepubkey = 1; if ( (valsobj= cJSON_Parse(retstr)) != 0 )
pubkey = jbits256(sendjson,"pubkey");
}
if ( (hexstr= jstr(sendjson,"data")) != 0 && (hexlen= is_hexstr(hexstr,0)) > 0 )
hexlen >>= 1;
extrasize = (int32_t)(sizeof(struct iguana_msghdr) + sizeof(basilisktag));
*ptrp = 0;
sendstr = jprint(sendjson,0);
datalen = (int32_t)strlen(sendstr) + 1;
if ( (datalen + extrasize + hexlen + havepubkey*(sizeof(pubkey)+1)) <= spacesize )
data = space;
else
{ {
data = calloc(1,datalen + extrasize + hexlen + havepubkey*(sizeof(pubkey)+1)); data = basilisk_jsondata(&allocptr,space,sizeof(space),&datalen,symbol,valsobj,basilisktag);
*ptrp = data; basilisk_sendcmd(myinfo,remoteaddr,"RET",&basilisktag,encryptflag,delaymillis,data,datalen,0,0);
if ( allocptr != 0 )
free(allocptr);
free_json(valsobj);
} }
data += extrasize; }
memcpy(data,sendstr,datalen); }
free(sendstr);
if ( havepubkey != 0 || hexlen != 0 ) char *basilisk_waitresponse(struct supernet_info *myinfo,char *CMD,char *symbol,char *remoteaddr,struct basilisk_item *Lptr,struct basilisk_item *ptr)
{ {
if ( (data[datalen++]= havepubkey) != 0 ) char *retstr = 0;
if ( ptr == Lptr )
{ {
for (i=0; i<32; i++) if ( (retstr= Lptr->retstr) == 0 )
data[datalen++] = pubkey.bytes[i]; retstr = clonestr("{\"result\":\"null return from local basilisk_issuecmd\"}");
} ptr = basilisk_itemcreate(myinfo,CMD,symbol,Lptr->basilisktag,Lptr->numrequired,Lptr->vals,OS_milliseconds() - Lptr->expiration,Lptr->metricfunc);
queue_enqueue("submitQ",&myinfo->basilisks.submitQ,&ptr->DL,0);
} }
if ( hexlen > 0 ) else
{ {
decode_hex(&data[datalen],hexlen,hexstr); queue_enqueue("submitQ",&myinfo->basilisks.submitQ,&ptr->DL,0);
datalen += hexlen; while ( OS_milliseconds() < ptr->expiration )
{
//if ( (retstr= basilisk_iscomplete(ptr)) != 0 )
if ( (retstr= ptr->retstr) != 0 )
break;
usleep(50000);
} }
*datalenp = datalen; if ( retstr == 0 )
return(data); retstr = basilisk_finish(ptr,-1,"{\"error\":\"basilisk timeout\"}");
}
basilisk_sendback(myinfo,symbol,remoteaddr,ptr->basilisktag,retstr);
return(retstr);
} }
struct basilisk_item *basilisk_issueremote(struct supernet_info *myinfo,int32_t *numsentp,char *CMD,char *symbol,cJSON *valsobj,int32_t fanout,int32_t minresults,uint32_t basilisktag,int32_t timeoutmillis,void *_metricfunc,char *retstr,int32_t encryptflag,int32_t delaymillis,uint32_t nBits) struct basilisk_item *basilisk_issueremote(struct supernet_info *myinfo,int32_t *numsentp,char *CMD,char *symbol,cJSON *valsobj,int32_t fanout,int32_t minresults,uint32_t basilisktag,int32_t timeoutmillis,void *_metricfunc,char *retstr,int32_t encryptflag,int32_t delaymillis,uint32_t nBits)
@ -303,21 +674,20 @@ struct basilisk_item *basilisk_issueremote(struct supernet_info *myinfo,int32_t
else else
{ {
data = basilisk_jsondata(&allocptr,space,sizeof(space),&datalen,symbol,valsobj,basilisktag); data = basilisk_jsondata(&allocptr,space,sizeof(space),&datalen,symbol,valsobj,basilisktag);
*numsentp = ptr->numsent = basilisk_sendcmd(myinfo,0,CMD,&ptr->basilisktag,encryptflag,delaymillis,data,datalen,0,ptr->nBits); *numsentp = ptr->numsent = basilisk_sendcmd(myinfo,0,CMD,&ptr->basilisktag,encryptflag,delaymillis,data,datalen,1,ptr->nBits);
if ( allocptr != 0 ) if ( allocptr != 0 )
free(allocptr); free(allocptr);
} }
if ( timeoutmillis > 0 )
queue_enqueue("submitQ",&myinfo->basilisks.submitQ,&ptr->DL,0);
return(ptr); return(ptr);
} }
struct basilisk_item *basilisk_requestservice(struct basilisk_item *Lptr,struct supernet_info *myinfo,char *CMD,uint32_t basilisktag,cJSON *valsobj,bits256 pubkey,uint32_t nBits) struct basilisk_item *basilisk_requestservice(struct supernet_info *myinfo,char *CMD,cJSON *valsobj,bits256 pubkey,uint8_t *data,int32_t datalen,uint32_t nBits)
{ {
int32_t minresults,timeoutmillis,numsent,delaymillis,encryptflag; int32_t minresults,timeoutmillis,numsent,delaymillis,encryptflag; struct basilisk_item *ptr; char buf[4096],*str = 0;
basilisk_addhexstr(&str,valsobj,buf,sizeof(buf),data,datalen);
if ( jobj(valsobj,"pubkey") != 0 ) if ( jobj(valsobj,"pubkey") != 0 )
jdelete(valsobj,"pubkey"); jdelete(valsobj,"pubkey");
if ( bits256_cmp(pubkey,GENESIS_PUBKEY) != 0 ) if ( bits256_cmp(pubkey,GENESIS_PUBKEY) != 0 && bits256_nonz(pubkey) != 0 )
jaddbits256(valsobj,"pubkey",pubkey); jaddbits256(valsobj,"pubkey",pubkey);
if ( (minresults= jint(valsobj,"minresults")) <= 0 ) if ( (minresults= jint(valsobj,"minresults")) <= 0 )
minresults = 1; minresults = 1;
@ -325,83 +695,69 @@ struct basilisk_item *basilisk_requestservice(struct basilisk_item *Lptr,struct
timeoutmillis = BASILISK_TIMEOUT; timeoutmillis = BASILISK_TIMEOUT;
encryptflag = jint(valsobj,"encrypt"); encryptflag = jint(valsobj,"encrypt");
delaymillis = jint(valsobj,"delay"); delaymillis = jint(valsobj,"delay");
return(basilisk_issueremote(myinfo,&numsent,CMD,"BTCD",valsobj,1,minresults,basilisktag,timeoutmillis,0,0,encryptflag,delaymillis,nBits)); ptr = basilisk_issueremote(myinfo,&numsent,CMD,"BTCD",valsobj,1,minresults,0,timeoutmillis,0,0,encryptflag,delaymillis,nBits);
return(ptr);
} }
void basilisk_sendback(struct supernet_info *myinfo,char *symbol,char *remoteaddr,uint32_t basilisktag,char *retstr) char *basilisk_standardservice(char *CMD,struct supernet_info *myinfo,bits256 hash,cJSON *valsobj,char *hexstr,int32_t blockflag) // client side
{ {
uint8_t *data,space[4096]; void *allocptr; cJSON *valsobj; int32_t datalen,encryptflag=0,delaymillis=0; struct iguana_info *coin,*btcd,*btc; bits256 prevhash; uint32_t nBits = 0; char chainname[64],str[65]; uint8_t space[8192],*allocptr=0,*data = 0; struct basilisk_item *ptr,Lptr; int32_t doneflag,datalen = 0; struct iguana_block *block; cJSON *retjson;
printf("retstr.(%s) -> remote.(%s) basilisktag.%u\n",retstr,remoteaddr,basilisktag); retjson = cJSON_CreateObject();
if ( retstr != 0 && remoteaddr != 0 && remoteaddr[0] != 0 && strcmp(remoteaddr,"127.0.0.1") != 0 ) if ( strcmp(CMD,"SET") == 0 || strcmp(CMD,"GET") == 0 )
{ {
if ( (valsobj= cJSON_Parse(retstr)) != 0 ) if ( (coin= basilisk_chain(myinfo,valsobj)) == 0 )
clonestr("{\"error\":\"cant find private chain\"}");
if ( strcmp(CMD,"SET") == 0 )
{ {
data = basilisk_jsondata(&allocptr,space,sizeof(space),&datalen,symbol,valsobj,basilisktag); hash = GENESIS_PUBKEY;
printf("send data.%d\n",datalen); if ( jobj(valsobj,"prev") != 0 )
basilisk_sendcmd(myinfo,remoteaddr,"RET",&basilisktag,encryptflag,delaymillis,data,datalen,0,0x1efffff0);
if ( allocptr != 0 )
free(allocptr);
free_json(valsobj);
}
}
}
char *basilisk_block(struct supernet_info *myinfo,char *CMD,char *symbol,char *remoteaddr,struct basilisk_item *Lptr,struct basilisk_item *ptr)
{ {
char *retstr = 0; prevhash = jbits256(valsobj,"prev");
if ( ptr == Lptr ) if ( (block= iguana_blockfind("basilisk",coin,prevhash)) == 0 )
{ {
if ( (retstr= Lptr->retstr) == 0 ) printf("warning couldnt find %s in %s\n",bits256_str(str,prevhash),chainname);
retstr = clonestr("{\"result\":\"null return from local basilisk_issuecmd\"}"); prevhash = coin->blocks.hwmchain.RO.hash2;
ptr = basilisk_itemcreate(myinfo,CMD,symbol,Lptr->basilisktag,Lptr->numrequired,Lptr->vals,OS_milliseconds() - Lptr->expiration,Lptr->metricfunc);
queue_enqueue("submitQ",&myinfo->basilisks.submitQ,&ptr->DL,0);
} }
else } else prevhash = coin->blocks.hwmchain.RO.hash2;
{ hash = prevhash;
queue_enqueue("submitQ",&myinfo->basilisks.submitQ,&ptr->DL,0); if ( jobj(valsobj,"prev") != 0 )
while ( OS_milliseconds() < ptr->expiration ) jdelete(valsobj,"prev");
{
//if ( (retstr= basilisk_iscomplete(ptr)) != 0 )
if ( (retstr= ptr->retstr) != 0 )
break;
usleep(50000);
} }
if ( retstr == 0 )
retstr = basilisk_finish(ptr,-1,"{\"error\":\"basilisk timeout\"}");
}
basilisk_sendback(myinfo,symbol,remoteaddr,ptr->basilisktag,retstr);
return(retstr);
} }
else if ( strcmp(CMD,"SEQ") == 0 )
uint8_t *get_dataptr(void **ptrp,int32_t *datalenp,uint8_t *space,int32_t spacesize,char *hexstr)
{ {
*ptrp = 0; uint8_t *data = 0; doneflag = 0;
if ( hexstr != 0 && (*datalenp= is_hexstr(hexstr,0)) > 0 ) if ( (btcd= iguana_coinfind("BTCD")) != 0 )
{ {
*datalenp >>= 1; if ( btcd->RELAYNODE != 0 || btcd->VALIDATENODE != 0 )
if ( *datalenp <= spacesize ) doneflag |= (btcd->SEQ.BTCD.numstamps+BASILISK_FIRSTPOSSIBLEBTCD+1 >= btcd->longestchain);
data = space; if ( (btc= iguana_coinfind("BTC")) != 0 && (btc->RELAYNODE != 0 || btc->VALIDATENODE != 0) )
else *ptrp = data = calloc(1,*datalenp); doneflag |= (btcd->SEQ.BTC.numstamps+BASILISK_FIRSTPOSSIBLEBTC+1 >= btcd->SEQ.BTC.longestchain) << 1;
decode_hex(data,*datalenp,hexstr); if ( doneflag == 3 )
return(clonestr("{\"result\":\"both BTC and BTCD in full relay mode and current\"}"));
} }
return(data); if ( jobj(valsobj,"done") != 0 )
jdelete(valsobj,"done");
jaddnum(valsobj,"done",doneflag);
if ( (doneflag & 1) == 0 )
jaddnum(valsobj,"BTCD",btcd->SEQ.BTCD.numstamps+BASILISK_FIRSTPOSSIBLEBTCD);
if ( (doneflag & 2) == 0 )
jaddnum(valsobj,"BTC",btcd->SEQ.BTC.numstamps+BASILISK_FIRSTPOSSIBLEBTC);
} }
char *basilisk_standardservice(char *CMD,basilisk_requestfunc *func,struct supernet_info *myinfo,bits256 pubkey,cJSON *vals,char *hexstr,int32_t blockflag)
{
uint8_t space[8192],*data = 0; struct basilisk_item *ptr,Lptr; void *allocptr = 0; int32_t datalen = 0; cJSON *retjson= cJSON_CreateObject();
data = get_dataptr(&allocptr,&datalen,space,sizeof(space),hexstr); data = get_dataptr(&allocptr,&datalen,space,sizeof(space),hexstr);
ptr = (*func)(&Lptr,myinfo,pubkey,vals,data,datalen); ptr = basilisk_requestservice(myinfo,CMD,valsobj,hash,data,datalen,nBits);
if ( allocptr != 0 ) if ( allocptr != 0 )
free(allocptr); free(allocptr);
if ( ptr != 0 ) if ( ptr != 0 )
{ {
if ( blockflag != 0 ) if ( blockflag != 0 )
{ {
ptr->vals = jduplicate(vals); if ( ptr->expiration <= OS_milliseconds() )
ptr->expiration = OS_milliseconds() + BASILISK_TIMEOUT;
ptr->vals = jduplicate(valsobj);
strcpy(ptr->symbol,"BTCD"); strcpy(ptr->symbol,"BTCD");
strcpy(ptr->CMD,CMD); strcpy(ptr->CMD,CMD);
return(basilisk_block(myinfo,CMD,"BTCD",0,&Lptr,ptr)); return(basilisk_waitresponse(myinfo,CMD,"BTCD",0,&Lptr,ptr));
} }
else if ( ptr->numsent > 0 ) else if ( ptr->numsent > 0 )
{ {
@ -548,7 +904,7 @@ char *basilisk_standardcmd(struct supernet_info *myinfo,char *CMD,char *activeco
if ( (coin= iguana_coinfind(activecoin)) != 0 ) if ( (coin= iguana_coinfind(activecoin)) != 0 )
{ {
if ( (ptr= basilisk_issuecmd(&Lptr,func,metric,myinfo,remoteaddr,basilisktag,activecoin,timeoutmillis,vals)) != 0 ) if ( (ptr= basilisk_issuecmd(&Lptr,func,metric,myinfo,remoteaddr,basilisktag,activecoin,timeoutmillis,vals)) != 0 )
return(basilisk_block(myinfo,CMD,coin->symbol,remoteaddr,&Lptr,ptr)); return(basilisk_waitresponse(myinfo,CMD,coin->symbol,remoteaddr,&Lptr,ptr));
else return(clonestr("{\"error\":\"null return from basilisk_issuecmd\"}")); else return(clonestr("{\"error\":\"null return from basilisk_issuecmd\"}"));
} else return(clonestr("{\"error\":\"couldnt get coin\"}")); } else return(clonestr("{\"error\":\"couldnt get coin\"}"));
} else return(retstr); } else return(retstr);
@ -566,32 +922,22 @@ char *_basilisk_balances(struct supernet_info *myinfo,struct iguana_info *coin,s
char *_basilisk_rawtx(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_peer *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen) char *_basilisk_rawtx(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_peer *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen)
{ {
char *hexstr=0,*retstr; char *retstr,strbuf[4096],*str = 0;
printf("remote rawtx.(%s)\n",jprint(valsobj,0)); printf("remote rawtx.(%s)\n",jprint(valsobj,0));
if ( data != 0 ) basilisk_addhexstr(&str,valsobj,strbuf,sizeof(strbuf),data,datalen);
{
hexstr = calloc(1,(datalen<<1) + 1);
init_hexbytes_noT(hexstr,data,datalen);
jaddstr(valsobj,"data",hexstr);
}
retstr = basilisk_rawtx(myinfo,coin,0,remoteaddr,basilisktag,valsobj,coin->symbol); retstr = basilisk_rawtx(myinfo,coin,0,remoteaddr,basilisktag,valsobj,coin->symbol);
if ( hexstr != 0 ) if ( str != 0 )
free(hexstr); free(str);
return(retstr); return(retstr);
} }
char *_basilisk_result(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_peer *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen) char *_basilisk_result(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_peer *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen)
{ {
char *hexstr=0,*retstr; char *retstr,strbuf[4096],*str = 0;
if ( data != 0 ) basilisk_addhexstr(&str,valsobj,strbuf,sizeof(strbuf),data,datalen);
{
hexstr = calloc(1,(datalen<<1) + 1);
init_hexbytes_noT(hexstr,data,datalen);
jaddstr(valsobj,"data",hexstr);
}
retstr = basilisk_result(myinfo,coin,0,remoteaddr,basilisktag,valsobj); retstr = basilisk_result(myinfo,coin,0,remoteaddr,basilisktag,valsobj);
if ( hexstr != 0 ) if ( str != 0 )
free(hexstr); free(str);
return(retstr); return(retstr);
} }
@ -644,7 +990,7 @@ INT_ARRAY_STRING(basilisk,rawtx,basilisktag,vals,activecoin)
ptr->numrequired = 1; ptr->numrequired = 1;
ptr->uniqueflag = 1; ptr->uniqueflag = 1;
ptr->metricdir = -1; ptr->metricdir = -1;
return(basilisk_block(myinfo,"RAW",coin->symbol,remoteaddr,&Lptr,ptr)); return(basilisk_waitresponse(myinfo,"RAW",coin->symbol,remoteaddr,&Lptr,ptr));
} else return(clonestr("{\"error\":\"error issuing basilisk rawtx\"}")); } else return(clonestr("{\"error\":\"error issuing basilisk rawtx\"}"));
} else return(retstr); } else return(retstr);
} }
@ -657,83 +1003,86 @@ INT_AND_ARRAY(basilisk,result,basilisktag,vals)
ptr = calloc(1,sizeof(*ptr)); ptr = calloc(1,sizeof(*ptr));
ptr->retstr = jprint(vals,0); ptr->retstr = jprint(vals,0);
ptr->basilisktag = basilisktag; ptr->basilisktag = basilisktag;
//printf("Q.%u results vals.(%s)\n",basilisktag,ptr->retstr); printf("(%s) -> Q.%u results vals.(%s)\n",ptr->CMD,basilisktag,ptr->retstr);
queue_enqueue("resultsQ",&myinfo->basilisks.resultsQ,&ptr->DL,0); queue_enqueue("resultsQ",&myinfo->basilisks.resultsQ,&ptr->DL,0);
return(clonestr("{\"result\":\"queued basilisk return\"}")); return(clonestr("{\"result\":\"queued basilisk return\"}"));
} else printf("null vals.(%s) or no hexmsg.%p\n",jprint(vals,0),vals); } else printf("null vals.(%s) or no hexmsg.%p\n",jprint(vals,0),vals);
return(clonestr("{\"error\":\"no hexmsg to return\"}")); return(clonestr("{\"error\":\"no hexmsg to return\"}"));
} }
HASH_ARRAY_STRING(basilisk,sequence,pubkey,vals,hexstr)
{
return(basilisk_standardservice("SEQ",myinfo,pubkey,vals,hexstr,1));
}
HASH_ARRAY_STRING(basilisk,addrelay,pubkey,vals,hexstr) HASH_ARRAY_STRING(basilisk,addrelay,pubkey,vals,hexstr)
{ {
return(basilisk_standardservice("ADD",&basilisk_request_addrelay,myinfo,pubkey,vals,hexstr,0)); return(basilisk_standardservice("ADD",myinfo,pubkey,vals,hexstr,1));
} }
HASH_ARRAY_STRING(basilisk,dispatch,pubkey,vals,hexstr) HASH_ARRAY_STRING(basilisk,dispatch,pubkey,vals,hexstr)
{ {
return(basilisk_standardservice("RUN",&basilisk_request_dispatch,myinfo,pubkey,vals,hexstr,1)); return(basilisk_standardservice("RUN",myinfo,pubkey,vals,hexstr,1));
} }
HASH_ARRAY_STRING(basilisk,publish,pubkey,vals,hexstr) HASH_ARRAY_STRING(basilisk,publish,pubkey,vals,hexstr)
{ {
return(basilisk_standardservice("PUB",&basilisk_request_publish,myinfo,pubkey,vals,hexstr,0)); return(basilisk_standardservice("PUB",myinfo,pubkey,vals,hexstr,1));
} }
HASH_ARRAY_STRING(basilisk,subscribe,pubkey,vals,hexstr) HASH_ARRAY_STRING(basilisk,subscribe,pubkey,vals,hexstr)
{ {
return(basilisk_standardservice("SUB",&basilisk_request_subscribe,myinfo,pubkey,vals,hexstr,1)); return(basilisk_standardservice("SUB",myinfo,pubkey,vals,hexstr,1));
} }
HASH_ARRAY_STRING(basilisk,setfield,pubkey,vals,hexstr) HASH_ARRAY_STRING(basilisk,setfield,pubkey,vals,hexstr)
{ {
return(basilisk_standardservice("SET",&basilisk_request_setfield,myinfo,pubkey,vals,hexstr,0)); return(basilisk_standardservice("SET",myinfo,pubkey,vals,hexstr,1));
} }
HASH_ARRAY_STRING(basilisk,getfield,pubkey,vals,hexstr) HASH_ARRAY_STRING(basilisk,getfield,pubkey,vals,hexstr)
{ {
if ( jobj(vals,"timeout") == 0 ) return(basilisk_standardservice("GET",myinfo,pubkey,vals,hexstr,1));
jaddnum(vals,"timeout",BASILISK_TIMEOUT);
return(basilisk_standardservice("GET",&basilisk_request_getfield,myinfo,pubkey,vals,hexstr,1));
} }
HASH_ARRAY_STRING(basilisk,forward,pubkey,vals,hexstr) HASH_ARRAY_STRING(basilisk,forward,pubkey,vals,hexstr)
{ {
return(basilisk_standardservice("HOP",&basilisk_request_forward,myinfo,pubkey,vals,hexstr,0)); return(basilisk_standardservice("HOP",myinfo,pubkey,vals,hexstr,0));
} }
HASH_ARRAY_STRING(basilisk,mailbox,pubkey,vals,hexstr) HASH_ARRAY_STRING(basilisk,mailbox,pubkey,vals,hexstr)
{ {
return(basilisk_standardservice("BOX",&basilisk_request_mailbox,myinfo,pubkey,vals,hexstr,1)); return(basilisk_standardservice("BOX",myinfo,pubkey,vals,hexstr,1));
} }
HASH_ARRAY_STRING(basilisk,VPNcreate,pubkey,vals,hexstr) HASH_ARRAY_STRING(basilisk,VPNcreate,pubkey,vals,hexstr)
{ {
return(basilisk_standardservice("HUB",&basilisk_request_VPNcreate,myinfo,pubkey,vals,hexstr,1)); return(basilisk_standardservice("VPN",myinfo,pubkey,vals,hexstr,1));
} }
HASH_ARRAY_STRING(basilisk,VPNjoin,pubkey,vals,hexstr) HASH_ARRAY_STRING(basilisk,VPNjoin,pubkey,vals,hexstr)
{ {
return(basilisk_standardservice("ARC",&basilisk_request_VPNjoin,myinfo,pubkey,vals,hexstr,1)); return(basilisk_standardservice("ARC",myinfo,pubkey,vals,hexstr,1));
} }
HASH_ARRAY_STRING(basilisk,VPNmessage,pubkey,vals,hexstr) HASH_ARRAY_STRING(basilisk,VPNmessage,pubkey,vals,hexstr)
{ {
return(basilisk_standardservice("GAB",&basilisk_request_VPNmessage,myinfo,pubkey,vals,hexstr,1)); return(basilisk_standardservice("GAB",myinfo,pubkey,vals,hexstr,0));
} }
HASH_ARRAY_STRING(basilisk,VPNbroadcast,pubkey,vals,hexstr) HASH_ARRAY_STRING(basilisk,VPNbroadcast,pubkey,vals,hexstr)
{ {
return(basilisk_standardservice("SAY",&basilisk_request_VPNbroadcast,myinfo,pubkey,vals,hexstr,1)); return(basilisk_standardservice("SAY",myinfo,pubkey,vals,hexstr,0));
} }
HASH_ARRAY_STRING(basilisk,VPNreceive,pubkey,vals,hexstr) HASH_ARRAY_STRING(basilisk,VPNreceive,pubkey,vals,hexstr)
{ {
return(basilisk_standardservice("EAR",&basilisk_request_VPNreceive,myinfo,pubkey,vals,hexstr,1)); return(basilisk_standardservice("EAR",myinfo,pubkey,vals,hexstr,1));
} }
HASH_ARRAY_STRING(basilisk,VPNlogout,pubkey,vals,hexstr) HASH_ARRAY_STRING(basilisk,VPNlogout,pubkey,vals,hexstr)
{ {
return(basilisk_standardservice("END",&basilisk_request_VPNlogout,myinfo,pubkey,vals,hexstr,0)); return(basilisk_standardservice("END",myinfo,pubkey,vals,hexstr,0));
} }
#include "../includes/iguana_apiundefs.h" #include "../includes/iguana_apiundefs.h"
@ -745,9 +1094,10 @@ void basilisk_msgprocess(struct supernet_info *myinfo,void *addr,uint32_t sender
{ {
{ (void *)"RUN", &basilisk_respond_dispatch }, // higher level protocol handler, pass through { (void *)"RUN", &basilisk_respond_dispatch }, // higher level protocol handler, pass through
{ (void *)"BYE", &basilisk_respond_goodbye }, // disconnect { (void *)"BYE", &basilisk_respond_goodbye }, // disconnect
{ (void *)"SEQ", &basilisk_respond_hashstamps }, // "done" BTCD | BTC
// unencrypted low level functions, used by higher level protocols and virtual network funcs // unencrypted low level functions, used by higher level protocols and virtual network funcs
{ (void *)"ADD", &basilisk_respond_addrelay }, // relays register with each other and make a bus { (void *)"ADD", &basilisk_respond_addrelay }, // relays register with each other bus
{ (void *)"PUB", &basilisk_respond_publish }, // adds to global list of published items { (void *)"PUB", &basilisk_respond_publish }, // adds to global list of published items
{ (void *)"SUB", &basilisk_respond_subscribe }, // subscribes to one or all published items { (void *)"SUB", &basilisk_respond_subscribe }, // subscribes to one or all published items
{ (void *)"SET", &basilisk_respond_setfield }, // adding field to one relay propagates to all others { (void *)"SET", &basilisk_respond_setfield }, // adding field to one relay propagates to all others
@ -758,7 +1108,7 @@ void basilisk_msgprocess(struct supernet_info *myinfo,void *addr,uint32_t sender
{ (void *)"BOX", &basilisk_respond_mailbox }, // create/send/check mailbox pubkey { (void *)"BOX", &basilisk_respond_mailbox }, // create/send/check mailbox pubkey
// small virtual private network // small virtual private network
{ (void *)"HUB", &basilisk_respond_VPNcreate }, // create virtual network's hub via privkey { (void *)"VPN", &basilisk_respond_VPNcreate }, // create virtual network's hub via privkey
{ (void *)"ARC", &basilisk_respond_VPNjoin }, // join { (void *)"ARC", &basilisk_respond_VPNjoin }, // join
{ (void *)"GAB", &basilisk_respond_VPNmessage }, // private message { (void *)"GAB", &basilisk_respond_VPNmessage }, // private message
{ (void *)"SAY", &basilisk_respond_VPNbroadcast }, // broadcast { (void *)"SAY", &basilisk_respond_VPNbroadcast }, // broadcast
@ -802,14 +1152,14 @@ void basilisk_msgprocess(struct supernet_info *myinfo,void *addr,uint32_t sender
if ( senderipbits != 0 ) if ( senderipbits != 0 )
expand_ipbits(remoteaddr,senderipbits); expand_ipbits(remoteaddr,senderipbits);
else remoteaddr[0] = 0; else remoteaddr[0] = 0;
for (i=0; i<sizeof(basilisk_services)/sizeof(*basilisk_services); i++) for (i=0; i<sizeof(basilisk_services)/sizeof(*basilisk_services); i++) // iguana node
{ {
if ( strcmp((char *)basilisk_services[i][0],type) == 0 ) if ( strcmp((char *)basilisk_services[i][0],type) == 0 )
{ {
if ( myinfo->IAMRELAY != 0 ) // iguana node if ( myinfo->IAMRELAY != 0 ) // iguana node
{ {
if ( from_basilisk != 0 ) if ( from_basilisk != 0 )
basilisk_sendcmd(myinfo,0,cmd,&basilisktag,0,0,origdata,origlen,-1,0x1efffff0); // to other iguanas basilisk_sendcmd(myinfo,0,cmd,&basilisktag,0,0,origdata,origlen,-1,0); // to other iguanas
if ( (retstr= (*basilisk_services[i][1])(myinfo,type,addr,remoteaddr,basilisktag,valsobj,data,datalen,pubkey,from_basilisk)) != 0 ) if ( (retstr= (*basilisk_services[i][1])(myinfo,type,addr,remoteaddr,basilisktag,valsobj,data,datalen,pubkey,from_basilisk)) != 0 )
{ {
printf("from_basilisk.%d ret.(%s)\n",from_basilisk,retstr); printf("from_basilisk.%d ret.(%s)\n",from_basilisk,retstr);
@ -825,7 +1175,7 @@ void basilisk_msgprocess(struct supernet_info *myinfo,void *addr,uint32_t sender
} }
if ( coin != 0 ) if ( coin != 0 )
{ {
if ( coin->RELAYNODE != 0 || coin->VALIDATENODE != 0 ) if ( coin->RELAYNODE != 0 || coin->VALIDATENODE != 0 ) // iguana node
{ {
for (i=0; i<sizeof(basilisk_coinservices)/sizeof(*basilisk_coinservices); i++) for (i=0; i<sizeof(basilisk_coinservices)/sizeof(*basilisk_coinservices); i++)
if ( strcmp((char *)basilisk_coinservices[i][0],type) == 0 ) if ( strcmp((char *)basilisk_coinservices[i][0],type) == 0 )
@ -840,7 +1190,9 @@ void basilisk_msgprocess(struct supernet_info *myinfo,void *addr,uint32_t sender
else // basilisk node else // basilisk node
{ {
if ( strcmp(type,"RET") == 0 ) if ( strcmp(type,"RET") == 0 )
{
retstr = _basilisk_result(myinfo,coin,addr,remoteaddr,basilisktag,valsobj,data,datalen); retstr = _basilisk_result(myinfo,coin,addr,remoteaddr,basilisktag,valsobj,data,datalen);
}
else if ( strcmp(type,"ADD") == 0 ) else if ( strcmp(type,"ADD") == 0 )
{ {
printf("new relay ADD.(%s) datalen.%d\n",jprint(valsobj,0),datalen); printf("new relay ADD.(%s) datalen.%d\n",jprint(valsobj,0),datalen);
@ -856,7 +1208,7 @@ void basilisk_msgprocess(struct supernet_info *myinfo,void *addr,uint32_t sender
void basilisks_loop(void *arg) void basilisks_loop(void *arg)
{ {
basilisk_metricfunc metricfunc; struct basilisk_item *ptr,*tmp,*pending,*parent; int32_t i,iter,flag,n; struct supernet_info *myinfo = arg; basilisk_metricfunc metricfunc; struct iguana_info *btcd; struct basilisk_item *ptr,*tmp,*pending,*parent; int32_t i,iter,done,flag,n; cJSON *valsobj,*retjson; uint32_t now; struct supernet_info *myinfo = arg;
//uint8_t *blockspace; struct OS_memspace RAWMEM; //uint8_t *blockspace; struct OS_memspace RAWMEM;
//memset(&RAWMEM,0,sizeof(RAWMEM)); //memset(&RAWMEM,0,sizeof(RAWMEM));
//blockspace = calloc(1,IGUANA_MAXPACKETSIZE); //blockspace = calloc(1,IGUANA_MAXPACKETSIZE);
@ -864,6 +1216,27 @@ void basilisks_loop(void *arg)
while ( 1 ) while ( 1 )
{ {
iter++; iter++;
if ( (btcd= iguana_coinfind("BTCD")) != 0 )
{
done = 0;
if ( btcd->RELAYNODE != 0 || btcd->VALIDATENODE != 0 )
{
if ( (now= (uint32_t)time(NULL)) > btcd->SEQ.BTCD.lastupdate+10 )
if ( basilisk_update("BTCD",now) >= 0 )
done = 1;
}
if ( (now= (uint32_t)time(NULL)) > btcd->SEQ.BTC.lastupdate+30 )
{
if ( basilisk_update("BTC",now) >= 0 )
done |= 2;
}
if ( done != 3 )
{
valsobj = cJSON_CreateObject();
basilisk_standardservice("SEQ",myinfo,GENESIS_PUBKEY,valsobj,0,0);
free_json(valsobj);
}
}
//for (i=0; i<IGUANA_MAXCOINS; i++) //for (i=0; i<IGUANA_MAXCOINS; i++)
// if ( (coin= Coins[i]) != 0 && coin->RELAYNODE == 0 && coin->VALIDATENODE == 0 && coin->active != 0 && coin->chain->userpass[0] != 0 && coin->MAXPEERS == 1 ) // if ( (coin= Coins[i]) != 0 && coin->RELAYNODE == 0 && coin->VALIDATENODE == 0 && coin->active != 0 && coin->chain->userpass[0] != 0 && coin->MAXPEERS == 1 )
// basilisk_bitcoinscan(coin,blockspace,&RAWMEM); // basilisk_bitcoinscan(coin,blockspace,&RAWMEM);
@ -888,6 +1261,13 @@ void basilisks_loop(void *arg)
pending->childrendone++; pending->childrendone++;
printf("%u Add results[%d] <- (%s) metric %f\n",pending->basilisktag,n,ptr->retstr,pending->metrics[n]); printf("%u Add results[%d] <- (%s) metric %f\n",pending->basilisktag,n,ptr->retstr,pending->metrics[n]);
pending->results[n] = ptr->retstr; pending->results[n] = ptr->retstr;
if ( strcmp(ptr->CMD,"SEQ") == 0 )
{
if ( (retjson= cJSON_Parse(ptr->retstr)) != 0 )
{
free_json(retjson);
}
}
} }
} }
free(ptr); free(ptr);

17
basilisk/basilisk.h

@ -22,6 +22,22 @@
#define BASILISK_MINFANOUT 8 #define BASILISK_MINFANOUT 8
#define BASILISK_MAXFANOUT 64 #define BASILISK_MAXFANOUT 64
#define BASILISK_MAXFUTUREBLOCK 60
#define BASILISK_MAXBLOCKLAG 600
#define BASILISK_MAXBTCGAP 9
#define BASILISK_MAXBTCDGAP 18
#define BASILISK_DEFAULTVERSION 1
#define BASILISK_DEFAULTDIFF 0x1effffff
#define BASILISK_DEFAULTDIFFSTR "1effffff"
#define BASILISK_FIRSTPOSSIBLEBTC 414000
#define BASILISK_FIRSTPOSSIBLEBTCD 1100000
struct hashstamp { bits256 hash2; uint32_t timestamp; int32_t height; };
struct basilisk_sequence { struct hashstamp *stamps; int32_t lastupdate,maxstamps,numstamps,lasti,longestchain; };
struct basilisk_sequences { struct basilisk_sequence BTC,BTCD; };
struct basilisk_value { bits256 txid; int64_t value; int32_t height; int16_t vout; char coinaddr[64]; }; struct basilisk_value { bits256 txid; int64_t value; int32_t height; int16_t vout; char coinaddr[64]; };
struct basilisk_item struct basilisk_item
@ -42,7 +58,6 @@ struct basilisk_info
void basilisk_msgprocess(struct supernet_info *myinfo,void *addr,uint32_t senderipbits,char *type,uint32_t basilisktag,uint8_t *data,int32_t datalen,bits256 pubkey); void basilisk_msgprocess(struct supernet_info *myinfo,void *addr,uint32_t senderipbits,char *type,uint32_t basilisktag,uint8_t *data,int32_t datalen,bits256 pubkey);
void basilisks_init(struct supernet_info *myinfo); void basilisks_init(struct supernet_info *myinfo);
int32_t basilisk_sendcmd(struct supernet_info *myinfo,char *destipaddr,char *type,uint32_t *basilisktagp,int32_t encryptflag,int32_t delaymillis,uint8_t *data,int32_t datalen,int32_t fanout,uint32_t nBits); // data must be offset by sizeof(iguana_msghdr)
void basilisk_p2p(void *myinfo,void *_addr,int32_t *delaymillisp,char *ipaddr,uint8_t *data,int32_t datalen,char *type,int32_t encrypted); void basilisk_p2p(void *myinfo,void *_addr,int32_t *delaymillisp,char *ipaddr,uint8_t *data,int32_t datalen,char *type,int32_t encrypted);
uint8_t *basilisk_jsondata(void **ptrp,uint8_t *space,int32_t spacesize,int32_t *datalenp,char *symbol,cJSON *sendjson,uint32_t basilisktag); uint8_t *basilisk_jsondata(void **ptrp,uint8_t *space,int32_t spacesize,int32_t *datalenp,char *symbol,cJSON *sendjson,uint32_t basilisktag);

188
basilisk/basilisk_CMD.c

@ -25,86 +25,94 @@ char *basilisk_respond_goodbye(struct supernet_info *myinfo,char *CMD,struct igu
void basilisk_request_goodbye(struct supernet_info *myinfo) void basilisk_request_goodbye(struct supernet_info *myinfo)
{ {
struct basilisk_item Lptr; cJSON *valsobj = cJSON_CreateObject(); cJSON *valsobj = cJSON_CreateObject();
jaddnum(valsobj,"timeout",-1); jaddnum(valsobj,"timeout",-1);
basilisk_requestservice(&Lptr,myinfo,"BYE",0,valsobj,GENESIS_PUBKEY,0x1efffff0); basilisk_requestservice(myinfo,"BYE",valsobj,GENESIS_PUBKEY,0,0,0);
free_json(valsobj); free_json(valsobj);
} }
char *basilisk_respond_setfield(struct supernet_info *myinfo,char *CMD,struct iguana_peer *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 prevhash,int32_t from_basilisk) int32_t iguana_rwhashstamp(int32_t rwflag,uint8_t *serialized,struct hashstamp *stamp)
{
bits256 hash,cathash; struct category_info *rootcat,*cat,*prevcat=0; char *category; char str[65];
printf("from.(%s) SET.(%s) datalen.%d\n",remoteaddr,jprint(valsobj,0),datalen);
if ( datalen <= 0 || (category= jstr(valsobj,"category")) == 0 )
return(0);
vcalc_sha256(0,cathash.bytes,(uint8_t *)category,(int32_t)strlen(category));
vcalc_sha256(0,hash.bytes,data,datalen);
category_subscribe(myinfo,cathash,hash,data,datalen);
if ( bits256_cmp(prevhash,GENESIS_PUBKEY) != 0 && bits256_nonz(prevhash) != 0 )
{
if ( (prevcat= category_find(cathash,prevhash)) == 0 )
{ {
printf("basilisk_respond_publish: cant find prevhash.%s\n",bits256_str(str,prevhash)); int32_t len = 0;
} len += iguana_rwbignum(rwflag,&serialized[len],sizeof(stamp->hash2),stamp->hash2.bytes);
} else memset(prevhash.bytes,0,sizeof(prevhash)); len += iguana_rwnum(rwflag,&serialized[len],sizeof(stamp->timestamp),&stamp->timestamp);
if ( (rootcat= category_find(cathash,GENESIS_PUBKEY)) == 0 ) len += iguana_rwnum(rwflag,&serialized[len],sizeof(stamp->height),&stamp->height);
printf("error finding category.(%s)\n",category); return(len);
else if ( (cat= category_find(cathash,hash)) == 0 )
printf("error finding just added category\n");
else
{
rootcat->lasthash = hash;
cat->prevhash = prevhash;
if ( prevcat != 0 )
prevcat->next = cat;
}
return(0);
} }
struct basilisk_item *basilisk_request_setfield(struct basilisk_item *Lptr,struct supernet_info *myinfo,bits256 pubkey,cJSON *valsobj,uint8_t *data,int32_t datalen) cJSON *basilisk_sequencejson(struct basilisk_sequence *seq,int32_t startheight,int32_t firstpossible)
{ {
return(basilisk_requestservice(Lptr,myinfo,"SET",0,valsobj,pubkey,0x1efffff0)); int32_t i,n,len=0,num = 0; cJSON *item; uint8_t *data;
} if ( startheight < firstpossible )
startheight = firstpossible;
char *basilisk_respond_getfield(struct supernet_info *myinfo,char *CMD,struct iguana_peer *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 prevhash,int32_t from_basilisk) if ( (i= (startheight - firstpossible) ) < 0 || i >= seq->numstamps )
{
bits256 cathash; struct category_info *cat; char *category,*hexstr; cJSON *retjson;
if ( (category= jstr(valsobj,"category")) == 0 )
return(0); return(0);
vcalc_sha256(0,cathash.bytes,(uint8_t *)category,(int32_t)strlen(category)); item = cJSON_CreateObject();
char str[65]; printf("from.(%s) GET.(%s) datalen.%d %s\n",remoteaddr,jprint(valsobj,0),datalen,bits256_str(str,cathash)); n = (seq->numstamps - i);
retjson = cJSON_CreateObject(); data = calloc(n,sizeof(*seq->stamps));
if ( bits256_nonz(prevhash) == 0 || bits256_cmp(GENESIS_PUBKEY,prevhash) == 0 ) for (; i<seq->numstamps && num<n; i++,num++)
{
if ( (cat= category_find(cathash,GENESIS_PUBKEY)) == 0 )
jaddstr(retjson,"error","cant find category");
else
{ {
jaddbits256(retjson,"genesis",cat->hash); if ( seq->stamps[i].timestamp == 0 )
jaddbits256(retjson,"last",cat->lasthash); break;
len += iguana_rwhashstamp(1,&data[len],&seq->stamps[i]);
} }
jaddnum(item,"start",startheight);
jaddnum(item,"num",num);
jaddnum(item,"lastupdate",seq->lastupdate);
jaddnum(item,"longest",seq->longestchain);
return(item);
} }
else
char *basilisk_respond_hashstamps(struct supernet_info *myinfo,char *CMD,struct iguana_peer *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 prevhash,int32_t from_basilisk)
{ {
if ( (cat= category_find(cathash,prevhash)) == 0 ) int32_t doneflag; struct iguana_info *btcd; cJSON *retjson = cJSON_CreateObject();
printf("error finding just added category\n"); if ( (btcd= iguana_coinfind("BTCD")) != 0 && (doneflag= juint(valsobj,"done")) != 3 )
if ( cat->datalen > 0 )
{ {
hexstr = calloc(1,(cat->datalen << 1) + 1); if ( (doneflag & 1) == 0 )
init_hexbytes_noT(hexstr,cat->data,cat->datalen); jadd(retjson,"BTCD",basilisk_sequencejson(&btcd->SEQ.BTCD,juint(valsobj,"BTCD"),BASILISK_FIRSTPOSSIBLEBTCD));
jaddstr(retjson,"data",hexstr); else if ( (doneflag & 2) == 0 )
jadd(retjson,"BTC",basilisk_sequencejson(&btcd->SEQ.BTC,juint(valsobj,"BTC"),BASILISK_FIRSTPOSSIBLEBTC));
} }
return(jprint(retjson,1));
} }
char *basilisk_respond_setfield(struct supernet_info *myinfo,char *CMD,struct iguana_peer *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 prevhash,int32_t from_basilisk)
{
struct iguana_info *coin; struct iguana_block *prevblock,*prev2,*newblock,block; char str[65],*blocktx; uint32_t nBits,timestamp,nonce; cJSON *retjson; bits256 btcdhash;
if ( datalen <= 0 )
return(clonestr("{\"error\":\"no data specified\"}"));
if ( (coin= basilisk_chain(myinfo,valsobj)) == 0 )
return(clonestr("{\"error\":\"couldnt get basilisk_chain\"}"));
printf("from.(%s) SET.(%s) datalen.%d prev.%s\n",remoteaddr,jprint(valsobj,0),datalen,bits256_str(str,prevhash));
if ( bits256_nonz(prevhash) == 0 )
prevhash = coin->blocks.hwmchain.RO.hash2;
if ( (prevblock= iguana_blockfind("setfield",coin,prevhash)) == 0 )
return(clonestr("{\"error\":\"couldnt find prevhash\"}"));
if ( (prev2= iguana_blockfind("setfield",coin,prevblock->RO.prev_block)) == 0 )
return(clonestr("{\"error\":\"couldnt find prevhash2\"}"));
timestamp = juint(valsobj,"timestamp");
nonce = juint(valsobj,"nonce");
nBits = iguana_targetbits(coin,&coin->blocks.hwmchain,prevblock,prev2,1,coin->chain->targetspacing,coin->chain->targettimespan);
blocktx = basilisk_block(myinfo,coin,&block,1,timestamp,&nonce,prevhash,nBits,prevblock->height+1,0,0,data,datalen,btcdhash,jobj(valsobj,"coinbase"));
retjson = cJSON_CreateObject();
jaddbits256(retjson,"hash",block.RO.hash2);
jaddstr(retjson,"data",blocktx);
if ( (newblock= _iguana_chainlink(coin,&block)) != 0 )
{
jaddstr(retjson,"result","chain extended");
jaddnum(retjson,"ht",block.height);
} else jaddstr(retjson,"error","couldnt extend chain");
free(blocktx);
return(jprint(retjson,1)); return(jprint(retjson,1));
} }
struct basilisk_item *basilisk_request_getfield(struct basilisk_item *Lptr,struct supernet_info *myinfo,bits256 prevhash,cJSON *valsobj,uint8_t *data,int32_t datalen) char *basilisk_respond_getfield(struct supernet_info *myinfo,char *CMD,struct iguana_peer *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 prevhash,int32_t from_basilisk)
{ {
bits256 cathash; char *category; struct iguana_info *coin; cJSON *retjson;
if ( (category= jstr(valsobj,"category")) == 0 ) if ( (coin= basilisk_chain(myinfo,valsobj)) == 0 )
return(0); return(clonestr("{\"error\":\"couldnt get basilisk_chain\"}"));
vcalc_sha256(0,cathash.bytes,(uint8_t *)category,(int32_t)strlen(category)); retjson = cJSON_CreateObject();
return(basilisk_requestservice(Lptr,myinfo,"GET",0,valsobj,prevhash,0x1efffff0)); return(jprint(retjson,1));
} }
char *basilisk_respond_publish(struct supernet_info *myinfo,char *CMD,struct iguana_peer *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 pubkey,int32_t from_basilisk) char *basilisk_respond_publish(struct supernet_info *myinfo,char *CMD,struct iguana_peer *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 pubkey,int32_t from_basilisk)
@ -114,11 +122,6 @@ char *basilisk_respond_publish(struct supernet_info *myinfo,char *CMD,struct igu
return(retstr); return(retstr);
} }
struct basilisk_item *basilisk_request_publish(struct basilisk_item *Lptr,struct supernet_info *myinfo,bits256 pubkey,cJSON *valsobj,uint8_t *data,int32_t datalen)
{
return(basilisk_requestservice(Lptr,myinfo,"PUB",0,valsobj,pubkey,0x1efffff0));
}
char *basilisk_respond_subscribe(struct supernet_info *myinfo,char *CMD,struct iguana_peer *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 pubkey,int32_t from_basilisk) char *basilisk_respond_subscribe(struct supernet_info *myinfo,char *CMD,struct iguana_peer *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 pubkey,int32_t from_basilisk)
{ {
char *retstr=0; char *retstr=0;
@ -126,119 +129,64 @@ char *basilisk_respond_subscribe(struct supernet_info *myinfo,char *CMD,struct i
return(retstr); return(retstr);
} }
struct basilisk_item *basilisk_request_subscribe(struct basilisk_item *Lptr,struct supernet_info *myinfo,bits256 pubkey,cJSON *valsobj,uint8_t *data,int32_t datalen)
{
return(basilisk_requestservice(Lptr,myinfo,"SUB",0,valsobj,pubkey,0x1efffff0));
}
char *basilisk_respond_dispatch(struct supernet_info *myinfo,char *CMD,struct iguana_peer *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 pubkey,int32_t from_basilisk) char *basilisk_respond_dispatch(struct supernet_info *myinfo,char *CMD,struct iguana_peer *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 pubkey,int32_t from_basilisk)
{ {
char *retstr=0; char *retstr=0;
return(retstr); return(retstr);
} }
struct basilisk_item *basilisk_request_dispatch(struct basilisk_item *Lptr,struct supernet_info *myinfo,bits256 pubkey,cJSON *valsobj,uint8_t *data,int32_t datalen)
{
return(basilisk_requestservice(Lptr,myinfo,"RUN",0,valsobj,pubkey,0x1efffff0));
}
char *basilisk_respond_addrelay(struct supernet_info *myinfo,char *CMD,struct iguana_peer *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 pubkey,int32_t from_basilisk) char *basilisk_respond_addrelay(struct supernet_info *myinfo,char *CMD,struct iguana_peer *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 pubkey,int32_t from_basilisk)
{ {
char *retstr=0; char *retstr=0;
return(retstr); return(retstr);
} }
struct basilisk_item *basilisk_request_addrelay(struct basilisk_item *Lptr,struct supernet_info *myinfo,bits256 pubkey,cJSON *valsobj,uint8_t *data,int32_t datalen)
{
return(basilisk_requestservice(Lptr,myinfo,"ADD",0,valsobj,pubkey,0x1efffff0));
}
char *basilisk_respond_forward(struct supernet_info *myinfo,char *CMD,struct iguana_peer *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 pubkey,int32_t from_basilisk) char *basilisk_respond_forward(struct supernet_info *myinfo,char *CMD,struct iguana_peer *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 pubkey,int32_t from_basilisk)
{ {
char *retstr=0; char *retstr=0;
return(retstr); return(retstr);
} }
struct basilisk_item *basilisk_request_forward(struct basilisk_item *Lptr,struct supernet_info *myinfo,bits256 pubkey,cJSON *valsobj,uint8_t *data,int32_t datalen)
{
return(basilisk_requestservice(Lptr,myinfo,"HOP",0,valsobj,pubkey,0x1efffff0));
}
char *basilisk_respond_mailbox(struct supernet_info *myinfo,char *CMD,struct iguana_peer *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 pubkey,int32_t from_basilisk) char *basilisk_respond_mailbox(struct supernet_info *myinfo,char *CMD,struct iguana_peer *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 pubkey,int32_t from_basilisk)
{ {
char *retstr=0; char *retstr=0;
return(retstr); return(retstr);
} }
struct basilisk_item *basilisk_request_mailbox(struct basilisk_item *Lptr,struct supernet_info *myinfo,bits256 pubkey,cJSON *valsobj,uint8_t *data,int32_t datalen)
{
return(basilisk_requestservice(Lptr,myinfo,"BOX",0,valsobj,pubkey,0x1efffff0));
}
char *basilisk_respond_VPNcreate(struct supernet_info *myinfo,char *CMD,struct iguana_peer *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 pubkey,int32_t from_basilisk) char *basilisk_respond_VPNcreate(struct supernet_info *myinfo,char *CMD,struct iguana_peer *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 pubkey,int32_t from_basilisk)
{ {
char *retstr=0; char *retstr=0;
return(retstr); return(retstr);
} }
struct basilisk_item *basilisk_request_VPNcreate(struct basilisk_item *Lptr,struct supernet_info *myinfo,bits256 pubkey,cJSON *valsobj,uint8_t *data,int32_t datalen)
{
return(basilisk_requestservice(Lptr,myinfo,"HUB",0,valsobj,pubkey,0x1efffff0));
}
char *basilisk_respond_VPNjoin(struct supernet_info *myinfo,char *CMD,struct iguana_peer *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 pubkey,int32_t from_basilisk) char *basilisk_respond_VPNjoin(struct supernet_info *myinfo,char *CMD,struct iguana_peer *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 pubkey,int32_t from_basilisk)
{ {
char *retstr=0; char *retstr=0;
return(retstr); return(retstr);
} }
struct basilisk_item *basilisk_request_VPNjoin(struct basilisk_item *Lptr,struct supernet_info *myinfo,bits256 pubkey,cJSON *valsobj,uint8_t *data,int32_t datalen)
{
return(basilisk_requestservice(Lptr,myinfo,"ARC",0,valsobj,pubkey,0x1efffff0));
}
char *basilisk_respond_VPNlogout(struct supernet_info *myinfo,char *CMD,struct iguana_peer *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 pubkey,int32_t from_basilisk) char *basilisk_respond_VPNlogout(struct supernet_info *myinfo,char *CMD,struct iguana_peer *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 pubkey,int32_t from_basilisk)
{ {
char *retstr=0; char *retstr=0;
return(retstr); return(retstr);
} }
struct basilisk_item *basilisk_request_VPNlogout(struct basilisk_item *Lptr,struct supernet_info *myinfo,bits256 pubkey,cJSON *valsobj,uint8_t *data,int32_t datalen)
{
return(basilisk_requestservice(Lptr,myinfo,"END",0,valsobj,pubkey,0x1efffff0));
}
char *basilisk_respond_VPNbroadcast(struct supernet_info *myinfo,char *CMD,struct iguana_peer *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 pubkey,int32_t from_basilisk) char *basilisk_respond_VPNbroadcast(struct supernet_info *myinfo,char *CMD,struct iguana_peer *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 pubkey,int32_t from_basilisk)
{ {
char *retstr=0; char *retstr=0;
return(retstr); return(retstr);
} }
struct basilisk_item *basilisk_request_VPNbroadcast(struct basilisk_item *Lptr,struct supernet_info *myinfo,bits256 pubkey,cJSON *valsobj,uint8_t *data,int32_t datalen)
{
return(basilisk_requestservice(Lptr,myinfo,"SAY",0,valsobj,pubkey,0x1efffff0));
}
char *basilisk_respond_VPNreceive(struct supernet_info *myinfo,char *CMD,struct iguana_peer *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 pubkey,int32_t from_basilisk) char *basilisk_respond_VPNreceive(struct supernet_info *myinfo,char *CMD,struct iguana_peer *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 pubkey,int32_t from_basilisk)
{ {
char *retstr=0; char *retstr=0;
return(retstr); return(retstr);
} }
struct basilisk_item *basilisk_request_VPNreceive(struct basilisk_item *Lptr,struct supernet_info *myinfo,bits256 pubkey,cJSON *valsobj,uint8_t *data,int32_t datalen)
{
return(basilisk_requestservice(Lptr,myinfo,"EAR",0,valsobj,pubkey,0x1efffff0));
}
char *basilisk_respond_VPNmessage(struct supernet_info *myinfo,char *CMD,struct iguana_peer *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 pubkey,int32_t from_basilisk) char *basilisk_respond_VPNmessage(struct supernet_info *myinfo,char *CMD,struct iguana_peer *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 pubkey,int32_t from_basilisk)
{ {
char *retstr=0; char *retstr=0;
return(retstr); return(retstr);
} }
struct basilisk_item *basilisk_request_VPNmessage(struct basilisk_item *Lptr,struct supernet_info *myinfo,bits256 pubkey,cJSON *valsobj,uint8_t *data,int32_t datalen)
{
return(basilisk_requestservice(Lptr,myinfo,"GAP",0,valsobj,pubkey,0x1efffff0));
}

10
basilisk/basilisk_bitcoin.c

@ -362,12 +362,12 @@ void *basilisk_bitcoinvalue(struct basilisk_item *Lptr,struct supernet_info *myi
if ( v->vout == vout && bits256_cmp(txid,v->txid) == 0 && strcmp(v->coinaddr,coinaddr) == 0 ) if ( v->vout == vout && bits256_cmp(txid,v->txid) == 0 && strcmp(v->coinaddr,coinaddr) == 0 )
{ {
printf("bitcoinvalue local ht.%d %s %.8f\n",v->height,v->coinaddr,dstr(v->value)); printf("bitcoinvalue local ht.%d %s %.8f\n",v->height,v->coinaddr,dstr(v->value));
return(basilisk_issueremote(myinfo,&numsent,"VAL",coin->symbol,valsobj,juint(valsobj,"fanout"),juint(valsobj,"minresults"),basilisktag,timeoutmillis,coin->basilisk_valuemetric,basilisk_valuestr(coin,v->coinaddr,v->value,v->height,txid,vout),0,0,0x1efffff0)); return(basilisk_issueremote(myinfo,&numsent,"VAL",coin->symbol,valsobj,juint(valsobj,"fanout"),juint(valsobj,"minresults"),basilisktag,timeoutmillis,coin->basilisk_valuemetric,basilisk_valuestr(coin,v->coinaddr,v->value,v->height,txid,vout),0,0,BASILISK_DEFAULTDIFF));
} }
} }
} }
printf("bitcoinvalue issue remote\n"); printf("bitcoinvalue issue remote\n");
return(basilisk_issueremote(myinfo,&numsent,"VAL",coin->symbol,valsobj,juint(valsobj,"fanout"),juint(valsobj,"minresults"),basilisktag,timeoutmillis,coin->basilisk_valuemetric,0,0,0,0x1efffff0)); return(basilisk_issueremote(myinfo,&numsent,"VAL",coin->symbol,valsobj,juint(valsobj,"fanout"),juint(valsobj,"minresults"),basilisktag,timeoutmillis,coin->basilisk_valuemetric,0,0,0,BASILISK_DEFAULTDIFF));
} }
double basilisk_bitcoin_rawtxmetric_dependents(struct supernet_info *myinfo,struct iguana_info *coin,struct basilisk_item *ptr,struct bitcoin_rawtxdependents *dependents) double basilisk_bitcoin_rawtxmetric_dependents(struct supernet_info *myinfo,struct iguana_info *coin,struct basilisk_item *ptr,struct bitcoin_rawtxdependents *dependents)
@ -593,11 +593,11 @@ void *basilisk_bitcoinrawtx(struct basilisk_item *Lptr,struct supernet_info *myi
{ {
if ( coin->VALIDATENODE != 0 || coin->RELAYNODE != 0 ) if ( coin->VALIDATENODE != 0 || coin->RELAYNODE != 0 )
{ {
if ( (txobj= bitcoin_txcreate(coin,locktime)) != 0 ) if ( (txobj= bitcoin_txcreate(coin->chain->txhastimestamp,locktime)) != 0 )
{ {
spendlen = (int32_t)strlen(spendscriptstr) >> 1; spendlen = (int32_t)strlen(spendscriptstr) >> 1;
decode_hex(buf,spendlen,spendscriptstr); decode_hex(buf,spendlen,spendscriptstr);
bitcoin_txoutput(coin,txobj,buf,spendlen,amount); bitcoin_txoutput(txobj,buf,spendlen,amount);
rawtx = iguana_calcrawtx(myinfo,coin,&vins,txobj,amount,changeaddr,txfee,addresses,minconf); rawtx = iguana_calcrawtx(myinfo,coin,&vins,txobj,amount,changeaddr,txfee,addresses,minconf);
//printf("generated.(%s) vins.(%s)\n",rawtx,vins!=0?jprint(vins,0):""); //printf("generated.(%s) vins.(%s)\n",rawtx,vins!=0?jprint(vins,0):"");
} }
@ -628,6 +628,6 @@ void *basilisk_bitcoinrawtx(struct basilisk_item *Lptr,struct supernet_info *myi
Lptr->retstr = clonestr("{\"error\":\"couldnt create rawtx\"}"); Lptr->retstr = clonestr("{\"error\":\"couldnt create rawtx\"}");
return(Lptr); return(Lptr);
} }
return(basilisk_issueremote(myinfo,&numsent,"RAW",coin->symbol,valsobj,juint(valsobj,"fanout"),juint(valsobj,"minresults"),basilisktag,timeoutmillis,coin->basilisk_rawtxmetric,0,0,0,0x1efffff0)); return(basilisk_issueremote(myinfo,&numsent,"RAW",coin->symbol,valsobj,juint(valsobj,"fanout"),juint(valsobj,"minresults"),basilisktag,timeoutmillis,coin->basilisk_rawtxmetric,0,0,0,BASILISK_DEFAULTDIFF));
} }

20
deprecated/obsolete.h

@ -17293,5 +17293,25 @@ len = 0;
printf("unhandled bitcoin_hexmsg.(%d) from %s (%s)\n",len,remoteaddr,(char *)ptr); printf("unhandled bitcoin_hexmsg.(%d) from %s (%s)\n",len,remoteaddr,(char *)ptr);
return(retstr); return(retstr);
} }
int32_t basilisk_hashstamps(struct iguana_info *btcd,struct hashstamp *BTCDstamps,struct basilisk_sequence *seq,int32_t max,uint32_t reftimestamp)
{
uint32_t i,timestamp; struct iguana_block *block;
block = &btcd->blocks.hwmchain;
while ( block != 0 && (timestamp= block->RO.timestamp) > reftimestamp )
block = iguana_blockfind("hashstamps",btcd,block->RO.prev_block);
if ( block == 0 )
return(-1);
for (i=0; i<max; i++)
{
BTCDstamps[i].hash2 = block->RO.hash2;
BTCDstamps[i].timestamp = block->RO.timestamp;
BTCDstamps[i].height = block->height;
if ( (block= iguana_blockfind("hashstamps",btcd,block->RO.prev_block)) == 0 )
return(i+1);
}
return(i);
}
#endif #endif
#endif #endif

10
iguana/SuperNET.c

@ -86,7 +86,7 @@ int32_t SuperNET_confirmip(struct supernet_info *myinfo,uint32_t ipbits)
{ {
for (j=0; j<IGUANA_MAXPEERS; j++) for (j=0; j<IGUANA_MAXPEERS; j++)
{ {
if ( (x= Coins[i]->peers.active[j].myipbits) != 0 ) if ( (x= Coins[i]->peers->active[j].myipbits) != 0 )
{ {
if ( x == ipbits ) if ( x == ipbits )
total++; total++;
@ -113,7 +113,7 @@ void SuperNET_checkipaddr(struct supernet_info *myinfo,struct iguana_info *coin,
if ( addr->myipbits == myinfo->myaddr.myipbits ) if ( addr->myipbits == myinfo->myaddr.myipbits )
myinfo->myaddr.confirmed++; myinfo->myaddr.confirmed++;
else myinfo->myaddr.confirmed--; else myinfo->myaddr.confirmed--;
if ( (myinfo->myaddr.totalconfirmed= SuperNET_confirmip(myinfo,addr->myipbits)) >= coin->peers.numranked ) if ( (myinfo->myaddr.totalconfirmed= SuperNET_confirmip(myinfo,addr->myipbits)) >= coin->peers->numranked )
myinfo->myaddr.selfipbits = addr->myipbits; myinfo->myaddr.selfipbits = addr->myipbits;
if ( myinfo->myaddr.selfipbits == myinfo->myaddr.myipbits ) if ( myinfo->myaddr.selfipbits == myinfo->myaddr.myipbits )
{ {
@ -885,7 +885,7 @@ cJSON *SuperNET_peerarray(struct iguana_info *coin,int32_t max,int32_t supernetf
for (j=0; j<IGUANA_MAXPEERS; j++) for (j=0; j<IGUANA_MAXPEERS; j++)
{ {
i = (r + j) % IGUANA_MAXPEERS; i = (r + j) % IGUANA_MAXPEERS;
addr = &coin->peers.active[i]; addr = &coin->peers->active[i];
if ( addr->usock >= 0 && supernetflag == (addr->supernet != 0) ) if ( addr->usock >= 0 && supernetflag == (addr->supernet != 0) )
{ {
jaddistr(array,addr->ipaddr); jaddistr(array,addr->ipaddr);
@ -1281,14 +1281,14 @@ TWO_STRINGS(SuperNET,subscribe,category,subcategory)
if ( remoteaddr != 0 ) if ( remoteaddr != 0 )
return(clonestr("{\"error\":\"no remote\"}")); return(clonestr("{\"error\":\"no remote\"}"));
categoryhash = calc_categoryhashes(&subhash,category,subcategory); categoryhash = calc_categoryhashes(&subhash,category,subcategory);
if ( category_subscribe(myinfo,categoryhash,subhash,0,0) != 0 ) if ( category_subscribe(myinfo,categoryhash,subhash) != 0 )
return(clonestr("{\"result\":\"subscribed\"}")); return(clonestr("{\"result\":\"subscribed\"}"));
else return(clonestr("{\"error\":\"couldnt subscribe\"}")); else return(clonestr("{\"error\":\"couldnt subscribe\"}"));
} }
TWO_STRINGS(SuperNET,gethexmsg,category,subcategory) TWO_STRINGS(SuperNET,gethexmsg,category,subcategory)
{ {
bits256 categoryhash,subhash; struct category_msg *m; char *hexstr; cJSON *retjson; struct category_info *cat; bits256 categoryhash,subhash; struct category_msg *m; char *hexstr; cJSON *retjson; struct private_chain *cat;
if ( remoteaddr != 0 ) if ( remoteaddr != 0 )
return(clonestr("{\"error\":\"no remote\"}")); return(clonestr("{\"error\":\"no remote\"}"));
categoryhash = calc_categoryhashes(&subhash,category,subcategory); categoryhash = calc_categoryhashes(&subhash,category,subcategory);

34
iguana/SuperNET.h

@ -126,15 +126,14 @@ struct crypto777_msghdr
uint8_t serialized[]; uint8_t serialized[];
} __attribute__((packed)); } __attribute__((packed));
struct category_info struct private_chain
{ {
UT_hash_handle hh; queue_t Q; UT_hash_handle hh; queue_t Q;
char *(*processfunc)(struct supernet_info *myinfo,struct category_info *cat,void *data,int32_t datalen,char *remoteaddr); char *(*processfunc)(struct supernet_info *myinfo,struct private_chain *cat,void *data,int32_t datalen,char *remoteaddr);
struct category_chain *catchain; bits256 hash,prevhash,lasthash; void *info; struct category_info *sub,*next; bits256 hash; struct private_chain *subchains; struct iguana_info *info;
int32_t datalen; uint8_t data[];
}; };
extern struct category_info *Categories; extern struct private_chain *Categories;
struct category_msg { struct queueitem DL; struct tai t; uint64_t remoteipbits; int32_t len; uint8_t msg[]; }; struct category_msg { struct queueitem DL; struct tai t; uint64_t remoteipbits; int32_t len; uint8_t msg[]; };
struct exchange_quote { uint64_t satoshis,orderid,offerNXT,exchangebits; double price,volume; uint32_t timestamp,val; }; struct exchange_quote { uint64_t satoshis,orderid,offerNXT,exchangebits; double price,volume; uint32_t timestamp,val; };
@ -157,12 +156,12 @@ bits256 SuperNET_sharedseed(bits256 privkey,bits256 otherpub);
int32_t SuperNET_decrypt(bits256 *senderpubp,uint64_t *senderbitsp,uint32_t *timestampp,bits256 mypriv,bits256 mypub,uint8_t *dest,int32_t maxlen,uint8_t *src,int32_t len); int32_t SuperNET_decrypt(bits256 *senderpubp,uint64_t *senderbitsp,uint32_t *timestampp,bits256 mypriv,bits256 mypub,uint8_t *dest,int32_t maxlen,uint8_t *src,int32_t len);
cJSON *SuperNET_argjson(cJSON *json); cJSON *SuperNET_argjson(cJSON *json);
void *category_info(bits256 categoryhash,bits256 subhash); void *private_chain(bits256 categoryhash,bits256 subhash);
void *category_infoset(bits256 categoryhash,bits256 subhash,void *info); void *private_chainset(bits256 categoryhash,bits256 subhash,void *info);
struct category_info *category_find(bits256 categoryhash,bits256 subhash); struct private_chain *category_find(bits256 categoryhash,bits256 subhash);
void SuperNET_hexmsgprocess(struct supernet_info *myinfo,cJSON *retjson,cJSON *json,char *hexmsg,char *remoteaddr); void SuperNET_hexmsgprocess(struct supernet_info *myinfo,cJSON *retjson,cJSON *json,char *hexmsg,char *remoteaddr);
struct category_info *category_processfunc(bits256 categoryhash,bits256 subhash,char *(*process_func)(struct supernet_info *myinfo,struct category_info *cat,void *data,int32_t datalen,char *remoteaddr)); struct private_chain *category_processfunc(bits256 categoryhash,bits256 subhash,char *(*process_func)(struct supernet_info *myinfo,struct private_chain *cat,void *data,int32_t datalen,char *remoteaddr));
char *pangea_hexmsg(struct supernet_info *myinfo,struct category_info *cat,void *data,int32_t len,char *remoteaddr); char *pangea_hexmsg(struct supernet_info *myinfo,struct private_chain *cat,void *data,int32_t len,char *remoteaddr);
void pangea_queues(struct supernet_info *myinfo); void pangea_queues(struct supernet_info *myinfo);
int32_t SuperNET_str2hex(uint8_t *hex,char *str); int32_t SuperNET_str2hex(uint8_t *hex,char *str);
@ -170,20 +169,20 @@ void SuperNET_hex2str(char *str,uint8_t *hex,int32_t len);
void SuperNET_hexmsgadd(struct supernet_info *myinfo,bits256 categoryhash,bits256 subhash,char *hexmsg,struct tai now,char *remoteaddr); void SuperNET_hexmsgadd(struct supernet_info *myinfo,bits256 categoryhash,bits256 subhash,char *hexmsg,struct tai now,char *remoteaddr);
int32_t SuperNET_hexmsgfind(struct supernet_info *myinfo,bits256 category,bits256 subhash,char *hexmsg,int32_t addflag); int32_t SuperNET_hexmsgfind(struct supernet_info *myinfo,bits256 category,bits256 subhash,char *hexmsg,int32_t addflag);
void category_posthexmsg(struct supernet_info *myinfo,bits256 categoryhash,bits256 subhash,char *hexmsg,struct tai now,char *remoteaddr); void category_posthexmsg(struct supernet_info *myinfo,bits256 categoryhash,bits256 subhash,char *hexmsg,struct tai now,char *remoteaddr);
void *category_subscribe(struct supernet_info *myinfo,bits256 category,bits256 subhash,uint8_t *data,int32_t datalen); void *category_subscribe(struct supernet_info *myinfo,bits256 category,bits256 keyhash);
struct category_msg *category_gethexmsg(struct supernet_info *myinfo,struct category_info **catptrp,bits256 categoryhash,bits256 subhash); struct category_msg *category_gethexmsg(struct supernet_info *myinfo,struct private_chain **catptrp,bits256 categoryhash,bits256 subhash);
char *SuperNET_htmlstr(char *fname,char *htmlstr,int32_t maxsize,char *agentstr); char *SuperNET_htmlstr(char *fname,char *htmlstr,int32_t maxsize,char *agentstr);
queue_t *category_Q(struct category_info **catptrp,bits256 categoryhash,bits256 subhash); queue_t *category_Q(struct private_chain **catptrp,bits256 categoryhash,bits256 subhash);
char *SuperNET_categorymulticast(struct supernet_info *myinfo,int32_t surveyflag,bits256 categoryhash,bits256 subhash,char *message,int32_t maxdelay,int32_t broadcastflag,int32_t plaintext,cJSON *argjson,char *remoteaddr); char *SuperNET_categorymulticast(struct supernet_info *myinfo,int32_t surveyflag,bits256 categoryhash,bits256 subhash,char *message,int32_t maxdelay,int32_t broadcastflag,int32_t plaintext,cJSON *argjson,char *remoteaddr);
bits256 calc_categoryhashes(bits256 *subhashp,char *category,char *subcategory); bits256 calc_categoryhashes(bits256 *subhashp,char *category,char *subcategory);
struct category_chain *category_chain_functions(struct supernet_info *myinfo,bits256 categoryhash,bits256 subhash,int32_t hashlen,int32_t addrlen,void *hash_func,void *stake_func,void *hit_func,void *default_func,void *ishwm_func,void *payment_func); //struct category_chain *category_chain_functions(struct supernet_info *myinfo,bits256 categoryhash,bits256 subhash,int32_t hashlen,int32_t addrlen,void *hash_func,void *stake_func,void *hit_func,void *default_func,void *ishwm_func,void *payment_func);
#define category_default_latest() (*catchain->default_func)(catchain,'L',0,0,0,0,zero) #define category_default_latest() (*catchain->default_func)(catchain,'L',0,0,0,0,zero)
void category_init(struct supernet_info *myinfo); void category_init(struct supernet_info *myinfo);
char *SuperNET_keysinit(struct supernet_info *myinfo,char *jsonstr); char *SuperNET_keysinit(struct supernet_info *myinfo,char *jsonstr);
double instantdex_aveprice(struct supernet_info *myinfo,struct exchange_quote *sortbuf,int32_t max,double *totalvolp,char *base,char *rel,double volume,cJSON *argjson); double instantdex_aveprice(struct supernet_info *myinfo,struct exchange_quote *sortbuf,int32_t max,double *totalvolp,char *base,char *rel,double volume,cJSON *argjson);
void SuperNET_setkeys(struct supernet_info *myinfo,void *pass,int32_t passlen,int32_t dosha256); void SuperNET_setkeys(struct supernet_info *myinfo,void *pass,int32_t passlen,int32_t dosha256);
char *InstantDEX_hexmsg(struct supernet_info *myinfo,struct category_info *cat,void *data,int32_t len,char *remoteaddr); char *InstantDEX_hexmsg(struct supernet_info *myinfo,struct private_chain *cat,void *data,int32_t len,char *remoteaddr);
bits256 bitcoin_pubkey33(void *ctx,uint8_t data[33],bits256 privkey); bits256 bitcoin_pubkey33(void *ctx,uint8_t data[33],bits256 privkey);
char *bitcoin_address(char *coinaddr,uint8_t addrtype,uint8_t *pubkey,int32_t len); char *bitcoin_address(char *coinaddr,uint8_t addrtype,uint8_t *pubkey,int32_t len);
@ -197,7 +196,10 @@ int32_t SuperNET_MYINFOS(struct supernet_info **myinfos,int32_t max);
FILE *myfopen(char *fname,char *mode); FILE *myfopen(char *fname,char *mode);
int32_t myfclose(FILE *fp); int32_t myfclose(FILE *fp);
cJSON *SuperNET_rosettajson(bits256 privkey,int32_t showprivs); cJSON *SuperNET_rosettajson(bits256 privkey,int32_t showprivs);
char *basilisk_hexmsg(struct supernet_info *myinfo,struct category_info *cat,void *ptr,int32_t len,char *remoteaddr); char *basilisk_hexmsg(struct supernet_info *myinfo,struct private_chain *cat,void *ptr,int32_t len,char *remoteaddr);
int32_t basilisk_sendcmd(struct supernet_info *myinfo,char *destipaddr,char *type,uint32_t *basilisktagp,int32_t encryptflag,int32_t delaymillis,uint8_t *data,int32_t datalen,int32_t fanout,uint32_t nBits); // data must be offset by sizeof(iguana_msghdr)
#endif #endif

73
iguana/SuperNET_category.c

@ -38,15 +38,16 @@ bits256 calc_categoryhashes(bits256 *subhashp,char *category,char *subcategory)
return(categoryhash); return(categoryhash);
} }
struct category_info *category_find(bits256 categoryhash,bits256 subhash) struct private_chain *category_find(bits256 categoryhash,bits256 subhash)
{ {
struct category_info *cat=0,*sub = 0; struct private_chain *cat=0,*sub = 0; bits256 hash;
HASH_FIND(hh,Categories,categoryhash.bytes,sizeof(categoryhash),cat); HASH_FIND(hh,Categories,categoryhash.bytes,sizeof(categoryhash),cat);
if ( cat != 0 ) if ( cat != 0 )
{ {
if ( bits256_nonz(subhash) > 0 && memcmp(GENESIS_PUBKEY.bytes,subhash.bytes,sizeof(subhash)) != 0 ) if ( bits256_nonz(subhash) > 0 && memcmp(GENESIS_PUBKEY.bytes,subhash.bytes,sizeof(subhash)) != 0 )
{ {
HASH_FIND(hh,cat->sub,subhash.bytes,sizeof(subhash),sub); hash = subhash;
HASH_FIND(hh,cat->subchains,hash.bytes,sizeof(hash),sub);
if ( sub != 0 ) if ( sub != 0 )
return(sub); return(sub);
} }
@ -55,9 +56,9 @@ struct category_info *category_find(bits256 categoryhash,bits256 subhash)
return(0); return(0);
} }
queue_t *category_Q(struct category_info **catptrp,bits256 categoryhash,bits256 subhash) queue_t *category_Q(struct private_chain **catptrp,bits256 categoryhash,bits256 subhash)
{ {
struct category_info *cat; struct private_chain *cat;
*catptrp = 0; *catptrp = 0;
if ( (cat= category_find(categoryhash,subhash)) != 0 ) if ( (cat= category_find(categoryhash,subhash)) != 0 )
{ {
@ -67,17 +68,17 @@ queue_t *category_Q(struct category_info **catptrp,bits256 categoryhash,bits256
else return(0); else return(0);
} }
void *category_info(bits256 categoryhash,bits256 subhash) void *private_chain(bits256 categoryhash,bits256 subhash)
{ {
struct category_info *cat; struct private_chain *cat;
if ( (cat= category_find(categoryhash,subhash)) != 0 ) if ( (cat= category_find(categoryhash,subhash)) != 0 )
return(cat->info); return(cat->info);
else return(0); else return(0);
} }
void *category_infoset(bits256 categoryhash,bits256 subhash,void *info) void *private_chainset(bits256 categoryhash,bits256 subhash,void *info)
{ {
struct category_info *cat; struct private_chain *cat;
if ( (cat= category_find(categoryhash,subhash)) != 0 ) if ( (cat= category_find(categoryhash,subhash)) != 0 )
{ {
cat->info = info; cat->info = info;
@ -86,9 +87,9 @@ void *category_infoset(bits256 categoryhash,bits256 subhash,void *info)
return(0); return(0);
} }
struct category_info *category_processfunc(bits256 categoryhash,bits256 subhash,char *(*process_func)(struct supernet_info *myinfo,struct category_info *cat,void *data,int32_t datalen,char *remoteaddr)) struct private_chain *category_processfunc(bits256 categoryhash,bits256 subhash,char *(*process_func)(struct supernet_info *myinfo,struct private_chain *cat,void *data,int32_t datalen,char *remoteaddr))
{ {
struct category_info *cat; struct private_chain *cat;
if ( (cat= category_find(categoryhash,subhash)) != 0 ) if ( (cat= category_find(categoryhash,subhash)) != 0 )
{ {
cat->processfunc = process_func; cat->processfunc = process_func;
@ -97,7 +98,7 @@ struct category_info *category_processfunc(bits256 categoryhash,bits256 subhash,
return(0); return(0);
} }
struct category_msg *category_gethexmsg(struct supernet_info *myinfo,struct category_info **catptrp,bits256 categoryhash,bits256 subhash) struct category_msg *category_gethexmsg(struct supernet_info *myinfo,struct private_chain **catptrp,bits256 categoryhash,bits256 subhash)
{ {
queue_t *Q; queue_t *Q;
//char str[65]; printf("getmsg.(%s) %llx\n",bits256_str(str,categoryhash),(long long)subhash.txid); //char str[65]; printf("getmsg.(%s) %llx\n",bits256_str(str,categoryhash),(long long)subhash.txid);
@ -108,7 +109,7 @@ struct category_msg *category_gethexmsg(struct supernet_info *myinfo,struct cate
void category_posthexmsg(struct supernet_info *myinfo,bits256 categoryhash,bits256 subhash,char *hexmsg,struct tai now,char *remoteaddr) void category_posthexmsg(struct supernet_info *myinfo,bits256 categoryhash,bits256 subhash,char *hexmsg,struct tai now,char *remoteaddr)
{ {
int32_t len; struct category_msg *m; queue_t *Q = 0; struct category_info *cat; int32_t len; struct category_msg *m; queue_t *Q = 0; struct private_chain *cat;
if ( (Q= category_Q(&cat,categoryhash,subhash)) != 0 ) if ( (Q= category_Q(&cat,categoryhash,subhash)) != 0 )
{ {
len = (int32_t)strlen(hexmsg) >> 1; len = (int32_t)strlen(hexmsg) >> 1;
@ -124,33 +125,29 @@ void category_posthexmsg(struct supernet_info *myinfo,bits256 categoryhash,bits2
// char str[65]; printf("no subscription for category.(%s) %llx\n",bits256_str(str,categoryhash),(long long)subhash.txid); // char str[65]; printf("no subscription for category.(%s) %llx\n",bits256_str(str,categoryhash),(long long)subhash.txid);
} }
void *category_subscribe(struct supernet_info *myinfo,bits256 categoryhash,bits256 subhash,uint8_t *data,int32_t datalen) void *category_subscribe(struct supernet_info *myinfo,bits256 chainhash,bits256 keyhash)
{ {
struct category_info *cat,*sub; bits256 hash; struct private_chain *chain,*subchain; bits256 hash;
HASH_FIND(hh,Categories,categoryhash.bytes,sizeof(categoryhash),cat); HASH_FIND(hh,Categories,chainhash.bytes,sizeof(chainhash),chain);
if ( cat == 0 ) if ( chain == 0 )
{ {
cat = mycalloc('c',1,sizeof(*cat) + datalen); chain = mycalloc('c',1,sizeof(*chain));
cat->hash = hash = categoryhash; chain->hash = hash = chainhash;
if ( (cat->datalen= datalen) > 0 ) char str[65]; printf("ADD cat.(%s)\n",bits256_str(str,chainhash));
memcpy(cat->data,data,datalen); HASH_ADD(hh,Categories,hash,sizeof(hash),chain);
char str[65]; printf("ADD cat.(%s)\n",bits256_str(str,categoryhash));
HASH_ADD(hh,Categories,hash,sizeof(hash),cat);
} }
if ( bits256_nonz(subhash) > 0 && memcmp(GENESIS_PUBKEY.bytes,subhash.bytes,sizeof(subhash)) != 0 && cat != 0 ) if ( bits256_nonz(keyhash) > 0 && memcmp(GENESIS_PUBKEY.bytes,keyhash.bytes,sizeof(keyhash)) != 0 && chain != 0 )
{ {
HASH_FIND(hh,cat->sub,subhash.bytes,sizeof(subhash),sub); HASH_FIND(hh,chain->subchains,keyhash.bytes,sizeof(keyhash),subchain);
if ( sub == 0 ) if ( subchain == 0 )
{ {
sub = mycalloc('c',1,sizeof(*sub) + datalen); subchain = mycalloc('c',1,sizeof(*subchain));
sub->hash = hash = subhash; subchain->hash = hash = keyhash;
if ( (sub->datalen= datalen) > 0 ) char str[65],str2[65]; printf("subadd.(%s) -> (%s)\n",bits256_str(str,keyhash),bits256_str(str2,chainhash));
memcpy(sub->data,data,datalen); HASH_ADD(hh,chain->subchains,hash,sizeof(hash),subchain);
char str[65],str2[65]; printf("subadd.(%s) -> (%s) datalen.%d\n",bits256_str(str,subhash),bits256_str(str2,categoryhash),datalen);
HASH_ADD(hh,cat->sub,hash,sizeof(hash),sub);
} }
} }
return(cat); return(chain);
} }
int32_t category_peer(struct supernet_info *myinfo,struct iguana_peer *addr,bits256 category,bits256 subhash) int32_t category_peer(struct supernet_info *myinfo,struct iguana_peer *addr,bits256 category,bits256 subhash)
@ -207,21 +204,21 @@ char *SuperNET_categorymulticast(struct supernet_info *myinfo,int32_t surveyflag
void category_init(struct supernet_info *myinfo) void category_init(struct supernet_info *myinfo)
{ {
bits256 pangeahash,instantdexhash,baseliskhash; bits256 pangeahash,instantdexhash,baseliskhash;
category_subscribe(myinfo,GENESIS_PUBKEY,GENESIS_PUBKEY,0,0); category_subscribe(myinfo,GENESIS_PUBKEY,GENESIS_PUBKEY);
pangeahash = calc_categoryhashes(0,"pangea",0); pangeahash = calc_categoryhashes(0,"pangea",0);
myinfo->pangea_category = pangeahash; myinfo->pangea_category = pangeahash;
category_subscribe(myinfo,pangeahash,GENESIS_PUBKEY,0,0); category_subscribe(myinfo,pangeahash,GENESIS_PUBKEY);
category_processfunc(pangeahash,GENESIS_PUBKEY,pangea_hexmsg); category_processfunc(pangeahash,GENESIS_PUBKEY,pangea_hexmsg);
category_chain_functions(myinfo,pangeahash,GENESIS_PUBKEY,sizeof(bits256),sizeof(bits256),0,0,0,0,0,0); //category_chain_functions(myinfo,pangeahash,GENESIS_PUBKEY,sizeof(bits256),sizeof(bits256),0,0,0,0,0,0);
instantdexhash = calc_categoryhashes(0,"InstantDEX",0); instantdexhash = calc_categoryhashes(0,"InstantDEX",0);
myinfo->instantdex_category = instantdexhash; myinfo->instantdex_category = instantdexhash;
category_subscribe(myinfo,instantdexhash,GENESIS_PUBKEY,0,0); category_subscribe(myinfo,instantdexhash,GENESIS_PUBKEY);
category_processfunc(instantdexhash,GENESIS_PUBKEY,InstantDEX_hexmsg); category_processfunc(instantdexhash,GENESIS_PUBKEY,InstantDEX_hexmsg);
category_processfunc(instantdexhash,myinfo->myaddr.persistent,InstantDEX_hexmsg); category_processfunc(instantdexhash,myinfo->myaddr.persistent,InstantDEX_hexmsg);
baseliskhash = calc_categoryhashes(0,"baselisk",0); baseliskhash = calc_categoryhashes(0,"baselisk",0);
myinfo->basilisk_category = baseliskhash; myinfo->basilisk_category = baseliskhash;
category_subscribe(myinfo,baseliskhash,GENESIS_PUBKEY,0,0); category_subscribe(myinfo,baseliskhash,GENESIS_PUBKEY);
basilisks_init(myinfo); basilisks_init(myinfo);
} }

16
iguana/SuperNET_hexmsg.c

@ -75,7 +75,7 @@ void SuperNET_hexmsgadd(struct supernet_info *myinfo,bits256 categoryhash,bits25
void SuperNET_hexmsgprocess(struct supernet_info *myinfo,cJSON *retjson,cJSON *json,char *hexmsg,char *remoteaddr) void SuperNET_hexmsgprocess(struct supernet_info *myinfo,cJSON *retjson,cJSON *json,char *hexmsg,char *remoteaddr)
{ {
int32_t len,flag=0; char *str; uint8_t _buf[8192],*buf = _buf; bits256 categoryhash,subhash; struct category_info *cat; int32_t len,flag=0; char *str; uint8_t _buf[8192],*buf = _buf; bits256 categoryhash,subhash; struct private_chain *cat;
if ( hexmsg != 0 ) if ( hexmsg != 0 )
{ {
len = (int32_t)strlen(hexmsg); len = (int32_t)strlen(hexmsg);
@ -116,6 +116,7 @@ void SuperNET_hexmsgprocess(struct supernet_info *myinfo,cJSON *retjson,cJSON *j
} }
} }
#ifdef later
int32_t category_default_blockhash(struct category_chain *catchain,void *blockhashp,void *data,int32_t datalen) int32_t category_default_blockhash(struct category_chain *catchain,void *blockhashp,void *data,int32_t datalen)
{ {
bits256 hash; bits256 hash;
@ -235,7 +236,7 @@ int32_t category_default_payment(struct category_chain *catchain,void *src,void
struct category_chain *category_chain_functions(struct supernet_info *myinfo,bits256 categoryhash,bits256 subhash,int32_t hashlen,int32_t addrlen,void *hash_func,void *stake_func,void *hit_func,void *default_func,void *ishwm_func,void *payment_func) struct category_chain *category_chain_functions(struct supernet_info *myinfo,bits256 categoryhash,bits256 subhash,int32_t hashlen,int32_t addrlen,void *hash_func,void *stake_func,void *hit_func,void *default_func,void *ishwm_func,void *payment_func)
{ {
struct category_info *cat; struct category_chain *catchain = calloc(1,sizeof(*catchain)); struct private_chain *cat; struct category_chain *catchain = calloc(1,sizeof(*catchain));
if ( (cat= category_find(categoryhash,subhash)) != 0 ) if ( (cat= category_find(categoryhash,subhash)) != 0 )
{ {
catchain->maxblocknum = -1; catchain->maxblocknum = -1;
@ -270,11 +271,12 @@ struct category_chain *category_chain_functions(struct supernet_info *myinfo,bit
return(0); return(0);
} }
} }
cat->catchain = catchain; //cat->catchain = catchain;
return(catchain); return(catchain);
} }
return(0); return(0);
} }
#endif
struct crypto777_msghdr *crypto777_msgcreate(struct supernet_info *myinfo,struct crypto777_msghdr *msg,int32_t datalen) struct crypto777_msghdr *crypto777_msgcreate(struct supernet_info *myinfo,struct crypto777_msghdr *msg,int32_t datalen)
{ {
@ -300,20 +302,20 @@ struct crypto777_msghdr *crypto777_msgcreate(struct supernet_info *myinfo,struct
return(0); return(0);
} }
void crypto777_catchain(struct supernet_info *myinfo,struct category_info *cat,bits256 *prevhashp,bits256 *btchashp) void crypto777_catchain(struct supernet_info *myinfo,struct private_chain *cat,bits256 *prevhashp,bits256 *btchashp)
{ {
*btchashp = myinfo->BTCmarkerhash; *btchashp = myinfo->BTCmarkerhash;
*prevhashp = cat->catchain->hwmhash; //*prevhashp = cat->catchain->hwmhash;
} }
char *crypto777_sendmsg(struct supernet_info *myinfo,bits256 category,bits256 subhash,uint8_t *data,int32_t datalen,int32_t hops,char cmdstr[8]) char *crypto777_sendmsg(struct supernet_info *myinfo,bits256 category,bits256 subhash,uint8_t *data,int32_t datalen,int32_t hops,char cmdstr[8])
{ {
char *hexstr,*retstr; int32_t i; struct crypto777_msghdr *msg; bits256 prevhash,btchash; struct category_info *cat; char *hexstr,*retstr; int32_t i; struct crypto777_msghdr *msg; bits256 prevhash,btchash; struct private_chain *cat;
msg = calloc(1,datalen + sizeof(*msg)); msg = calloc(1,datalen + sizeof(*msg));
for (i=0; i<sizeof(msg->cmd); i++) for (i=0; i<sizeof(msg->cmd); i++)
if ( (msg->cmd[i]= cmdstr[i]) == 0 ) if ( (msg->cmd[i]= cmdstr[i]) == 0 )
break; break;
cat = category_info(category,subhash); cat = private_chain(category,subhash);
crypto777_catchain(myinfo,cat,&prevhash,&btchash); crypto777_catchain(myinfo,cat,&prevhash,&btchash);
iguana_rwbignum(1,msg->prevhash.bytes,sizeof(bits256),prevhash.bytes); iguana_rwbignum(1,msg->prevhash.bytes,sizeof(bits256),prevhash.bytes);
iguana_rwbignum(1,msg->btchash.bytes,sizeof(bits256),btchash.bytes); iguana_rwbignum(1,msg->btchash.bytes,sizeof(bits256),btchash.bytes);

17
iguana/coins/extract_genesis.c

@ -0,0 +1,17 @@
#include <stdio.h>
int main()
{
FILE *fp;
if ( (fp= fopen("blk00000.dat","rb")) != 0 )
{
int i,c;
for (i=0; i<88; i++)
{
c = fgetc(fp);
if ( i >= 8 )
printf("%02x",c);
}
printf("\n");
fclose(fp);
}
}

2
iguana/coins/genbtc

@ -1 +1 @@
curl --url "http://127.0.0.1:7778" --data "{\"prefetchlag\":5,\"poll\":1,\"active\":1,\"agent\":\"iguana\",\"method\":\"addcoin\",\"newcoin\":\"BTC\",\"startpend\":8,\"endpend\":8,\"services\":128,\"maxpeers\":512,\"RELAY\":1,\"VALIDATE\":1,\"portp2p\":8333}" curl --url "http://127.0.0.1:7778" --data "{\"prefetchlag\":5,\"poll\":1,\"active\":1,\"agent\":\"iguana\",\"method\":\"addcoin\",\"newcoin\":\"BTC\",\"startpend\":8,\"endpend\":8,\"services\":129,\"maxpeers\":512,\"RELAY\":1,\"VALIDATE\":1,\"portp2p\":8333}"

1
iguana/coins/gennmc

@ -0,0 +1 @@
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"iguana\",\"method\":\"addcoin\",\"newcoin\":\"NMC\",\"active\":1,\"maxpeers\":128,\"services\":0,\"poll\":1,\"minconfirms\":3,\"estblocktime\":600,\"txfee_satoshis\":500000,\"useaddmultisig\":1,\"hastimestamp\":0,\"pubval\":\"00\",\"scriptval\":\"05\",\"wiftype\":\"80\",\"netmagic\":\"fba4c795\",\"genesishash\":\"000000000062b72c5e2ceb45fbc8587e807c155b0da735e6483dfba2f0a9c770\",\"genesis\":{\"hashalgo\":\"sha256\",\"version\":1,\"timestamp\":1303000001,\"nbits\":\"1c007fff\",\"nonce\":2719916434,\"merkle_root\":\"41c62dbd9068c89a449525e3cd5ac61b20ece28c3c38b3f35b2161f0e6d3cb0d\"},\"p2p\":8334,\"rpc\":8836}"

2
iguana/coins/genzcash

@ -0,0 +1,2 @@
curl --url "http://127.0.0.1:7778" --data "{\"RELAY\":1,\"VALIDATE\":1,\"prefetchlag\":-1,\"poll\":10,\"active\":1,\"agent\":\"iguana\",\"method\":\"addcoin\",\"startpend\":8,\"endpend\":8,\"services\":129,\"maxpeers\":256,\"newcoin\":\"ZEC\",\"name\":\"Zcash\",\"hasheaders\":1,\"useaddmultisig\":0,\"netmagic\":\"6df6e755\",\"p2p\":18333,\"rpc\":18332,\"pubval\":111,\"p2shval\":196,\"wifval\":239,\"txfee_satoshis\":\"10000\",\"isPoS\":0,\"minoutput\":10000,\"minconfirms\":2,\"genesishash\":\"27d1f4ce03fc473c9dd6e1e307c682c8f802eae1f5a2f61402aa1ae8702ed3b6\",\"protover\":70002,\"genesisblock\":\"0100000000000000000000000000000000000000000000000000000000000000000000003ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4adae5494dffff7f2000000000\"}"

1
iguana/coins/m_extract_genesis

@ -0,0 +1 @@
gcc -o extract_genesis extract_genesis.c

4
iguana/confs/ZEC_peers.txt

@ -0,0 +1,4 @@
198.100.147.192
159.203.60.92
188.166.31.56
46.105.126.215

72
iguana/iguana777.c

@ -80,6 +80,8 @@ struct iguana_info *iguana_coinadd(const char *symbol,cJSON *argjson)
safecopy(coin->name,jstr(argjson,"name"),sizeof(coin->name)); safecopy(coin->name,jstr(argjson,"name"),sizeof(coin->name));
else strcpy(coin->name,symbol); else strcpy(coin->name,symbol);
} }
if ( jstr(argjson,"privatechain") == 0 )
coin->peers = calloc(1,sizeof(*coin->peers));
coin->chain = iguana_chainfind((char *)symbol,argjson,1); coin->chain = iguana_chainfind((char *)symbol,argjson,1);
coin->ctx = secp256k1_context_create(SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY); coin->ctx = secp256k1_context_create(SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY);
secp256k1_pedersen_context_initialize(coin->ctx); secp256k1_pedersen_context_initialize(coin->ctx);
@ -158,7 +160,7 @@ int32_t iguana_inv2poll(struct supernet_info *myinfo,struct iguana_info *coin)
coin->lastinv2 = (uint32_t)time(NULL); coin->lastinv2 = (uint32_t)time(NULL);
for (i=n=0; i<coin->MAXPEERS; i++) for (i=n=0; i<coin->MAXPEERS; i++)
{ {
addr = &coin->peers.active[i]; addr = &coin->peers->active[i];
if ( addr->supernet != 0 ) if ( addr->supernet != 0 )
{ {
//printf("iguana_inv2poll (%s) usock.%d dead.%u ready.%u ipbits.%u supernet.%d\n",addr->ipaddr,addr->usock,addr->dead,addr->ready,(uint32_t)addr->ipbits,addr->supernet); //printf("iguana_inv2poll (%s) usock.%d dead.%u ready.%u ipbits.%u supernet.%d\n",addr->ipaddr,addr->usock,addr->dead,addr->ready,(uint32_t)addr->ipbits,addr->supernet);
@ -179,16 +181,16 @@ int32_t iguana_peermetrics(struct supernet_info *myinfo,struct iguana_info *coin
int32_t i,ind,n; double *sortbuf,sum; uint32_t now; struct iguana_peer *addr,*slowest = 0; int32_t i,ind,n; double *sortbuf,sum; uint32_t now; struct iguana_peer *addr,*slowest = 0;
//printf("peermetrics\n"); //printf("peermetrics\n");
sortbuf = mycalloc('s',coin->MAXPEERS,sizeof(double)*2); sortbuf = mycalloc('s',coin->MAXPEERS,sizeof(double)*2);
coin->peers.mostreceived = 0; coin->peers->mostreceived = 0;
now = (uint32_t)time(NULL); now = (uint32_t)time(NULL);
for (i=n=0; i<coin->MAXPEERS; i++) for (i=n=0; i<coin->MAXPEERS; i++)
{ {
addr = &coin->peers.active[i]; addr = &coin->peers->active[i];
if ( addr->usock < 0 || addr->dead != 0 || addr->ready == 0 || addr->ipbits == 0 ) if ( addr->usock < 0 || addr->dead != 0 || addr->ready == 0 || addr->ipbits == 0 )
continue; continue;
addr->pendblocks = 0; addr->pendblocks = 0;
if ( addr->recvblocks > coin->peers.mostreceived ) if ( addr->recvblocks > coin->peers->mostreceived )
coin->peers.mostreceived = addr->recvblocks; coin->peers->mostreceived = addr->recvblocks;
//printf("[%.0f %.0f] ",addr->recvblocks,addr->recvtotal); //printf("[%.0f %.0f] ",addr->recvblocks,addr->recvtotal);
sortbuf[n*2 + 0] = iguana_metric(addr,now,.995); sortbuf[n*2 + 0] = iguana_metric(addr,now,.995);
sortbuf[n*2 + 1] = i; sortbuf[n*2 + 1] = i;
@ -202,31 +204,31 @@ int32_t iguana_peermetrics(struct supernet_info *myinfo,struct iguana_info *coin
{ {
if ( i < coin->MAXPEERS ) if ( i < coin->MAXPEERS )
{ {
coin->peers.topmetrics[i] = sortbuf[i*2]; coin->peers->topmetrics[i] = sortbuf[i*2];
ind = (int32_t)sortbuf[i*2 +1]; ind = (int32_t)sortbuf[i*2 +1];
coin->peers.ranked[i] = &coin->peers.active[ind]; coin->peers->ranked[i] = &coin->peers->active[ind];
if ( sortbuf[i*2] > SMALLVAL && (double)i/n > .8 && (time(NULL) - addr->ready) > 77 ) if ( sortbuf[i*2] > SMALLVAL && (double)i/n > .8 && (time(NULL) - addr->ready) > 77 )
slowest = coin->peers.ranked[i]; slowest = coin->peers->ranked[i];
//printf("(%.5f %s) ",sortbuf[i*2],coin->peers.ranked[i]->ipaddr); //printf("(%.5f %s) ",sortbuf[i*2],coin->peers->ranked[i]->ipaddr);
coin->peers.ranked[i]->rank = i + 1; coin->peers->ranked[i]->rank = i + 1;
sum += coin->peers.topmetrics[i]; sum += coin->peers->topmetrics[i];
} }
} }
coin->peers.numranked = n; coin->peers->numranked = n;
portable_mutex_unlock(&coin->peers_mutex); portable_mutex_unlock(&coin->peers_mutex);
//printf("NUMRANKED.%d\n",n); //printf("NUMRANKED.%d\n",n);
if ( i > 0 ) if ( i > 0 )
{ {
coin->peers.avemetric = (sum / i); coin->peers->avemetric = (sum / i);
if ( i >= 7*(coin->MAXPEERS/8) && slowest != 0 ) if ( i >= 7*(coin->MAXPEERS/8) && slowest != 0 )
{ {
printf("prune slowest peer.(%s) numranked.%d MAXPEERS.%d\n",slowest->ipaddr,n,coin->MAXPEERS); printf("prune slowest peer.(%s) numranked.%d MAXpeers->%d\n",slowest->ipaddr,n,coin->MAXPEERS);
slowest->dead = 1; slowest->dead = 1;
} }
} }
} }
myfree(sortbuf,coin->MAXPEERS * sizeof(double) * 2); myfree(sortbuf,coin->MAXPEERS * sizeof(double) * 2);
return(coin->peers.mostreceived); return(coin->peers->mostreceived);
} }
void *iguana_kviAddriterator(struct iguana_info *coin,struct iguanakv *kv,struct iguana_kvitem *item,uint64_t args,void *key,void *value,int32_t valuesize) void *iguana_kviAddriterator(struct iguana_info *coin,struct iguanakv *kv,struct iguana_kvitem *item,uint64_t args,void *key,void *value,int32_t valuesize)
@ -234,10 +236,10 @@ void *iguana_kviAddriterator(struct iguana_info *coin,struct iguanakv *kv,struct
char ipaddr[64]; int32_t i; FILE *fp = (FILE *)(long)args; struct iguana_peer *addr; struct iguana_iAddr *iA = value; char ipaddr[64]; int32_t i; FILE *fp = (FILE *)(long)args; struct iguana_peer *addr; struct iguana_iAddr *iA = value;
if ( fp != 0 && iA != 0 && iA->numconnects > 0 && iA->lastconnect > time(NULL)-IGUANA_RECENTPEER ) if ( fp != 0 && iA != 0 && iA->numconnects > 0 && iA->lastconnect > time(NULL)-IGUANA_RECENTPEER )
{ {
for (i=0; i<coin->peers.numranked; i++) for (i=0; i<coin->peers->numranked; i++)
if ( (addr= coin->peers.ranked[i]) != 0 && addr->ipbits == iA->ipbits ) if ( (addr= coin->peers->ranked[i]) != 0 && addr->ipbits == iA->ipbits )
break; break;
if ( i == coin->peers.numranked ) if ( i == coin->peers->numranked )
{ {
expand_ipbits(ipaddr,iA->ipbits); expand_ipbits(ipaddr,iA->ipbits);
fprintf(fp,"%s\n",ipaddr); fprintf(fp,"%s\n",ipaddr);
@ -255,16 +257,16 @@ uint32_t iguana_updatemetrics(struct supernet_info *myinfo,struct iguana_info *c
sprintf(tmpfname,"%s/%s/peers.txt",GLOBAL_TMPDIR,coin->symbol), OS_compatible_path(tmpfname); sprintf(tmpfname,"%s/%s/peers.txt",GLOBAL_TMPDIR,coin->symbol), OS_compatible_path(tmpfname);
if ( (fp= fopen(tmpfname,"w")) != 0 ) if ( (fp= fopen(tmpfname,"w")) != 0 )
{ {
for (i=0; i<coin->peers.numranked; i++) for (i=0; i<coin->peers->numranked; i++)
{ {
if ( (addr= coin->peers.ranked[i]) != 0 && addr->relayflag != 0 && strcmp(addr->ipaddr,"127.0.0.1") != 0 ) if ( (addr= coin->peers->ranked[i]) != 0 && addr->relayflag != 0 && strcmp(addr->ipaddr,"127.0.0.1") != 0 )
{ {
for (j=0; j<coin->peers.numranked; j++) for (j=0; j<coin->peers->numranked; j++)
{ {
if ( i != j && (tmpaddr= coin->peers.ranked[j]) != 0 && (uint32_t)addr->ipbits == (uint32_t)tmpaddr->ipbits ) if ( i != j && (tmpaddr= coin->peers->ranked[j]) != 0 && (uint32_t)addr->ipbits == (uint32_t)tmpaddr->ipbits )
break; break;
} }
if ( j == coin->peers.numranked ) if ( j == coin->peers->numranked )
{ {
expand_ipbits(ipaddr,(uint32_t)addr->ipbits); expand_ipbits(ipaddr,(uint32_t)addr->ipbits);
fprintf(fp,"%s\n",ipaddr); fprintf(fp,"%s\n",ipaddr);
@ -670,7 +672,7 @@ void iguana_helper(void *arg)
//printf("bundlesQ allcurrent\n"); //printf("bundlesQ allcurrent\n");
usleep(polltimeout * 10000); usleep(polltimeout * 10000);
} }
else usleep(polltimeout * 1000); else usleep(polltimeout * 5000);
} }
} }
@ -718,7 +720,7 @@ void iguana_coinloop(void *arg)
coin->idletime = 0; coin->idletime = 0;
if ( coin->started != 0 && coin->active != 0 ) if ( coin->started != 0 && coin->active != 0 )
{ {
if ( coin->peers.numranked > 4 && coin->isRT == 0 && now > coin->startutc+77 && coin->numsaved >= (coin->longestchain/coin->chain->bundlesize)*coin->chain->bundlesize && coin->blocks.hwmchain.height >= coin->longestchain-30 ) if ( coin->peers->numranked > 4 && coin->isRT == 0 && now > coin->startutc+77 && coin->numsaved >= (coin->longestchain/coin->chain->bundlesize)*coin->chain->bundlesize && coin->blocks.hwmchain.height >= coin->longestchain-30 )
{ {
fprintf(stderr,">>>>>>> %s isRT blockrecv.%d vs longest.%d\n",coin->symbol,coin->blocksrecv,coin->longestchain); fprintf(stderr,">>>>>>> %s isRT blockrecv.%d vs longest.%d\n",coin->symbol,coin->blocksrecv,coin->longestchain);
coin->isRT = 1; coin->isRT = 1;
@ -735,27 +737,27 @@ void iguana_coinloop(void *arg)
} }
if ( coin->bindsock >= 0 ) if ( coin->bindsock >= 0 )
{ {
if ( coin->MAXPEERS > 1 && coin->peers.numranked < (coin->MAXPEERS/2) && now > coin->lastpossible ) if ( coin->MAXPEERS > 1 && coin->peers->numranked < (coin->MAXPEERS/2) && now > coin->lastpossible )
{ {
//fprintf(stderr,"check possible\n"); //fprintf(stderr,"check possible\n");
if ( coin->peers.numranked > 0 && (now % 60) == 0 ) if ( coin->peers->numranked > 0 && (now % 60) == 0 )
iguana_send_ping(coin,coin->peers.ranked[rand() % coin->peers.numranked]); iguana_send_ping(coin,coin->peers->ranked[rand() % coin->peers->numranked]);
coin->lastpossible = iguana_possible_peer(coin,0); // tries to connect to new peers coin->lastpossible = iguana_possible_peer(coin,0); // tries to connect to new peers
} }
} }
else else
{ {
if ( coin->MAXPEERS > 1 && coin->peers.numranked < ((7*coin->MAXPEERS)>>3) && now > coin->lastpossible ) if ( coin->MAXPEERS > 1 && coin->peers->numranked < ((7*coin->MAXPEERS)>>3) && now > coin->lastpossible )
{ {
if ( coin->peers.numranked > 0 && (now % 60) == 0 ) if ( coin->peers->numranked > 0 && (now % 60) == 0 )
iguana_send_ping(coin,coin->peers.ranked[rand() % coin->peers.numranked]); iguana_send_ping(coin,coin->peers->ranked[rand() % coin->peers->numranked]);
coin->lastpossible = iguana_possible_peer(coin,0); // tries to connect to new peers coin->lastpossible = iguana_possible_peer(coin,0); // tries to connect to new peers
} }
} }
if ( coin->MAXPEERS > 1 && now > coin->peers.lastmetrics+10 ) if ( coin->MAXPEERS > 1 && now > coin->peers->lastmetrics+10 )
{ {
//fprintf(stderr,"metrics\n"); //fprintf(stderr,"metrics\n");
coin->peers.lastmetrics = iguana_updatemetrics(myinfo,coin); // ranks peers coin->peers->lastmetrics = iguana_updatemetrics(myinfo,coin); // ranks peers
} }
if ( coin->longestchain+10000 > coin->blocks.maxbits ) if ( coin->longestchain+10000 > coin->blocks.maxbits )
iguana_recvalloc(coin,coin->longestchain + 100000); iguana_recvalloc(coin,coin->longestchain + 100000);
@ -767,9 +769,9 @@ void iguana_coinloop(void *arg)
} }
} }
if ( flag == 0 && coin->isRT == 0 ) if ( flag == 0 && coin->isRT == 0 )
usleep(coin->polltimeout*1000 + (coin->peers.numranked == 0)*1000000); usleep(coin->polltimeout*1000 + (coin->peers->numranked == 0)*1000000);
else if ( coin->current != 0 && coin->current->hdrsi == coin->longestchain/coin->chain->bundlesize ) else if ( coin->current != 0 && coin->current->hdrsi == coin->longestchain/coin->chain->bundlesize )
usleep(coin->polltimeout*1000 + 90000 + (coin->peers.numranked == 0)*1000000); usleep(coin->polltimeout*1000 + 90000 + (coin->peers->numranked == 0)*1000000);
else usleep(coin->polltimeout*1000); else usleep(coin->polltimeout*1000);
} }
} }

28
iguana/iguana777.h

@ -96,6 +96,7 @@ struct iguana_txdatabits { uint64_t addrind:IGUANA_LOG2MAXPEERS,filecount:10,fpo
#endif #endif
#define IGUANA_SUBDIRDIVISOR 28000 #define IGUANA_SUBDIRDIVISOR 28000
#define NTARGETSPACING 60
#define IGUANA_PROTOCOL_BITCOIN 'b' #define IGUANA_PROTOCOL_BITCOIN 'b'
#define IGUANA_PROTOCOL_NXT 'n' #define IGUANA_PROTOCOL_NXT 'n'
@ -216,7 +217,7 @@ struct iguana_chain
uint8_t pubtype,p2shtype,wiftype,netmagic[4]; uint8_t pubtype,p2shtype,wiftype,netmagic[4];
char *genesis_hash,*genesis_hex; // hex string char *genesis_hash,*genesis_hex; // hex string
uint16_t portp2p,rpcport; uint16_t portp2p,rpcport;
uint8_t hastimestamp,unitval; uint8_t txhastimestamp,unitval;
uint64_t rewards[512][2]; uint64_t rewards[512][2];
uint8_t genesis_hashdata[32],minconfirms; uint8_t genesis_hashdata[32],minconfirms;
uint16_t ramchainport,bundlesize,hasheaders; uint16_t ramchainport,bundlesize,hasheaders;
@ -228,6 +229,7 @@ struct iguana_chain
int32_t estblocktime,protover; int32_t estblocktime,protover;
bits256 PoWtarget,PoStargets[16]; int32_t numPoStargets,PoSheights[16]; bits256 PoWtarget,PoStargets[16]; int32_t numPoStargets,PoSheights[16];
uint8_t auxpow,alertpubkey[65]; uint8_t auxpow,alertpubkey[65];
int32_t targetspacing,targettimespan;
}; };
struct iguana_msgaddress { uint32_t nTime; uint64_t nServices; uint8_t ip[16]; uint16_t port; } __attribute__((packed)); struct iguana_msgaddress { uint32_t nTime; uint64_t nServices; uint8_t ip[16]; uint16_t port; } __attribute__((packed));
@ -354,11 +356,7 @@ struct iguana_block
struct iguana_counts struct iguana_counts
{ {
uint32_t firsttxidind,firstunspentind,firstspendind,firstpkind; uint32_t firsttxidind,firstunspentind,firstspendind,firstpkind;
//bits256 lhashes[IGUANA_NUMAPPENDS],ledgerhash; struct sha256_vstate states[IGUANA_NUMAPPENDS];
//bits256 blockhash,merkle_root;
uint64_t credits,debits; uint64_t credits,debits;
//uint32_t timestamp,height;
//struct iguana_prevdep dep;
struct iguana_block block; struct iguana_block block;
} __attribute__((packed)); } __attribute__((packed));
@ -522,8 +520,8 @@ typedef double (*basilisk_metricfunc)(struct supernet_info *myinfo,struct basili
struct iguana_info struct iguana_info
{ {
char name[64],symbol[8],protocol,statusstr[512],scriptsfname[2][512]; char name[64],symbol[64],protocol,statusstr[512],scriptsfname[2][512];
struct iguana_peers peers; struct iguana_peer internaladdr; struct iguana_peers *peers; struct iguana_peer internaladdr;
basilisk_func basilisk_rawtx,basilisk_balances,basilisk_value; basilisk_func basilisk_rawtx,basilisk_balances,basilisk_value;
basilisk_metricfunc basilisk_rawtxmetric,basilisk_balancesmetric,basilisk_valuemetric; basilisk_metricfunc basilisk_rawtxmetric,basilisk_balancesmetric,basilisk_valuemetric;
@ -538,14 +536,11 @@ struct iguana_info
struct iguana_chain *chain; struct iguana_chain *chain;
struct iguana_iAddr *iAddrs; struct iguana_iAddr *iAddrs;
void *ctx; void *ctx;
struct iguana_bitmap screen; struct iguana_bitmap *screen;
//struct pollfd fds[IGUANA_MAXPEERS]; struct iguana_peer bindaddr; int32_t numsocks;
struct OS_memspace TXMEM,MEM,MEMB[IGUANA_MAXBUNDLESIZE]; struct OS_memspace TXMEM,MEM,MEMB[IGUANA_MAXBUNDLESIZE];
queue_t acceptQ,hdrsQ,blocksQ,priorityQ,possibleQ,cacheQ,recvQ,msgrequestQ; queue_t acceptQ,hdrsQ,blocksQ,priorityQ,possibleQ,cacheQ,recvQ,msgrequestQ;
double parsemillis,avetime; uint32_t Launched[8],Terminated[8]; double parsemillis,avetime; uint32_t Launched[8],Terminated[8];
portable_mutex_t peers_mutex,blocks_mutex; portable_mutex_t peers_mutex,blocks_mutex;
//portable_mutex_t scripts_mutex[2]; FILE *scriptsfp[2]; void *scriptsptr[2]; long scriptsfilesize[2];
//struct scriptinfo *scriptstable[2];
char changeaddr[64]; char changeaddr[64];
struct iguana_bundle *bundles[IGUANA_MAXBUNDLES],*current,*lastpending; struct iguana_bundle *bundles[IGUANA_MAXBUNDLES],*current,*lastpending;
struct iguana_ramchain RTramchain; struct OS_memspace RTmem,RThashmem; bits256 RThash1; struct iguana_ramchain RTramchain; struct OS_memspace RTmem,RThashmem; bits256 RThash1;
@ -560,6 +555,7 @@ struct iguana_info
struct iguana_hhutxo *utxotable; struct iguana_hhaccount *accountstable; char lastdispstr[2048]; struct iguana_hhutxo *utxotable; struct iguana_hhaccount *accountstable; char lastdispstr[2048];
double txidfind_totalmillis,txidfind_num,spendtxid_totalmillis,spendtxid_num; double txidfind_totalmillis,txidfind_num,spendtxid_totalmillis,spendtxid_num;
struct iguana_monitorinfo monitoring[256]; struct iguana_monitorinfo monitoring[256];
struct basilisk_sequences SEQ;
}; };
struct vin_signer { bits256 privkey; char coinaddr[64]; uint8_t siglen,sig[80],rmd160[20],pubkey[66]; }; struct vin_signer { bits256 privkey; char coinaddr[64]; uint8_t siglen,sig[80],rmd160[20],pubkey[66]; };
@ -661,7 +657,7 @@ bits256 iguana_blockhash(struct iguana_info *coin,int32_t height);
#define iguana_blockfind(str,coin,hash2) iguana_blockhashset(str,coin,-1,hash2,0) #define iguana_blockfind(str,coin,hash2) iguana_blockhashset(str,coin,-1,hash2,0)
struct iguana_block *iguana_blockhashset(char *debugstr,struct iguana_info *coin,int32_t height,bits256 hash2,int32_t createflag); struct iguana_block *iguana_blockhashset(char *debugstr,struct iguana_info *coin,int32_t height,bits256 hash2,int32_t createflag);
struct iguana_block *iguana_prevblock(struct iguana_info *coin,struct iguana_block *block,int32_t PoSflag); struct iguana_block *iguana_prevblock(struct iguana_info *coin,struct iguana_block *block,int32_t PoSflag);
uint32_t iguana_targetbits(struct iguana_info *coin,struct iguana_block *hwmchain,struct iguana_block *prev,struct iguana_block *prev2,int32_t PoSflag); uint32_t iguana_targetbits(struct iguana_info *coin,struct iguana_block *hwmchain,struct iguana_block *prev,struct iguana_block *prev2,int32_t PoSflag,int32_t targetspacing,int32_t targettimespan);
uint32_t iguana_syncs(struct iguana_info *coin); uint32_t iguana_syncs(struct iguana_info *coin);
void iguana_gotdata(struct iguana_info *coin,struct iguana_peer *addr,int32_t height); void iguana_gotdata(struct iguana_info *coin,struct iguana_peer *addr,int32_t height);
@ -865,9 +861,10 @@ struct bitcoin_spend *iguana_spendset(struct supernet_info *myinfo,struct iguana
cJSON *bitcoin_hex2json(struct iguana_info *coin,bits256 *txidp,struct iguana_msgtx *msgtx,char *txbytes,uint8_t *extrapace,int32_t extralen,uint8_t *serialized); cJSON *bitcoin_hex2json(struct iguana_info *coin,bits256 *txidp,struct iguana_msgtx *msgtx,char *txbytes,uint8_t *extrapace,int32_t extralen,uint8_t *serialized);
cJSON *iguana_signtx(struct supernet_info *myinfo,struct iguana_info *coin,bits256 *txidp,char **signedtxp,struct bitcoin_spend *spend,cJSON *txobj,cJSON *vins); cJSON *iguana_signtx(struct supernet_info *myinfo,struct iguana_info *coin,bits256 *txidp,char **signedtxp,struct bitcoin_spend *spend,cJSON *txobj,cJSON *vins);
void iguana_addscript(struct iguana_info *coin,cJSON *dest,uint8_t *script,int32_t scriptlen,char *fieldname); void iguana_addscript(struct iguana_info *coin,cJSON *dest,uint8_t *script,int32_t scriptlen,char *fieldname);
bits256 iguana_genesis(struct iguana_info *coin,struct iguana_chain *chain);
cJSON *bitcoin_txcreate(struct iguana_info *coin,int64_t locktime); cJSON *bitcoin_txcreate(int32_t txhastimestamp,int64_t locktime);
cJSON *bitcoin_txoutput(struct iguana_info *coin,cJSON *txobj,uint8_t *paymentscript,int32_t len,uint64_t satoshis); cJSON *bitcoin_txoutput(cJSON *txobj,uint8_t *paymentscript,int32_t len,uint64_t satoshis);
cJSON *bitcoin_txinput(struct iguana_info *coin,cJSON *txobj,bits256 txid,int32_t vout,uint32_t sequenceid,uint8_t *spendscript,int32_t spendlen,uint8_t *redeemscript,int32_t p2shlen,uint8_t *pubkeys[],int32_t numpubkeys); cJSON *bitcoin_txinput(struct iguana_info *coin,cJSON *txobj,bits256 txid,int32_t vout,uint32_t sequenceid,uint8_t *spendscript,int32_t spendlen,uint8_t *redeemscript,int32_t p2shlen,uint8_t *pubkeys[],int32_t numpubkeys);
int32_t bitcoin_changescript(struct iguana_info *coin,uint8_t *changescript,int32_t n,uint64_t *changep,char *changeaddr,uint64_t inputsatoshis,uint64_t satoshis,uint64_t txfee); int32_t bitcoin_changescript(struct iguana_info *coin,uint8_t *changescript,int32_t n,uint64_t *changep,char *changeaddr,uint64_t inputsatoshis,uint64_t satoshis,uint64_t txfee);
@ -959,7 +956,7 @@ int32_t iguana_bundlefname(struct iguana_info *coin,struct iguana_bundle *bp,cha
int32_t iguana_bundleremove(struct iguana_info *coin,int32_t hdrsi,int32_t tmpfiles); int32_t iguana_bundleremove(struct iguana_info *coin,int32_t hdrsi,int32_t tmpfiles);
int32_t iguana_voutsfname(struct iguana_info *coin,int32_t roflag,char *fname,int32_t slotid); int32_t iguana_voutsfname(struct iguana_info *coin,int32_t roflag,char *fname,int32_t slotid);
int32_t iguana_vinsfname(struct iguana_info *coin,int32_t roflag,char *fname,int32_t slotid); int32_t iguana_vinsfname(struct iguana_info *coin,int32_t roflag,char *fname,int32_t slotid);
bits256 iguana_merkle(struct iguana_info *coin,bits256 *tree,int32_t txn_count); bits256 iguana_merkle(bits256 *tree,int32_t txn_count);
int32_t iguana_bundleready(struct iguana_info *coin,struct iguana_bundle *bp,int32_t requiredflag); int32_t iguana_bundleready(struct iguana_info *coin,struct iguana_bundle *bp,int32_t requiredflag);
int32_t iguana_blast(struct iguana_info *coin,struct iguana_peer *addr); int32_t iguana_blast(struct iguana_info *coin,struct iguana_peer *addr);
int32_t iguana_validated(struct iguana_info *coin); int32_t iguana_validated(struct iguana_info *coin);
@ -1029,7 +1026,6 @@ char *iguana_calcrawtx(struct supernet_info *myinfo,struct iguana_info *coin,cJS
char *iguana_signrawtx(struct supernet_info *myinfo,struct iguana_info *coin,bits256 *signedtxidp,int32_t *completedp,cJSON *vins,char *rawtx,cJSON *privkey); char *iguana_signrawtx(struct supernet_info *myinfo,struct iguana_info *coin,bits256 *signedtxidp,int32_t *completedp,cJSON *vins,char *rawtx,cJSON *privkey);
bits256 scrypt_blockhash(const void *input); bits256 scrypt_blockhash(const void *input);
bits256 iguana_calcblockhash(char *symbol,int32_t (*hashalgo)(uint8_t *blockhashp,uint8_t *serialized,int32_t len),uint8_t *serialized,int32_t len); bits256 iguana_calcblockhash(char *symbol,int32_t (*hashalgo)(uint8_t *blockhashp,uint8_t *serialized,int32_t len),uint8_t *serialized,int32_t len);
uint32_t iguana_targetbits(struct iguana_info *coin,struct iguana_block *hwmchain,struct iguana_block *prev,struct iguana_block *prev2,int32_t PoSflag);
struct bitcoin_eventitem *instantdex_event(char *cmdstr,cJSON *argjson,cJSON *newjson,uint8_t *serdata,int32_t serdatalen); struct bitcoin_eventitem *instantdex_event(char *cmdstr,cJSON *argjson,cJSON *newjson,uint8_t *serdata,int32_t serdatalen);
void instantdex_eventfree(struct bitcoin_eventitem *ptr); void instantdex_eventfree(struct bitcoin_eventitem *ptr);
struct iguana_monitorinfo *iguana_txidmonitor(struct iguana_info *coin,bits256 txid); struct iguana_monitorinfo *iguana_txidmonitor(struct iguana_info *coin,bits256 txid);

24
iguana/iguana_accept.c

@ -68,7 +68,7 @@ void iguana_acceptloop(void *args)
socklen_t clilen; struct sockaddr_in cli_addr; char ipaddr[64]; uint32_t i,ipbits,flag; socklen_t clilen; struct sockaddr_in cli_addr; char ipaddr[64]; uint32_t i,ipbits,flag;
while ( (coin->bindsock= iguana_socket(1,"0.0.0.0",port)) < 0 ) while ( (coin->bindsock= iguana_socket(1,"0.0.0.0",port)) < 0 )
{ {
if ( coin->peers.localaddr != 0 ) if ( coin->peers->localaddr != 0 )
{ {
printf("another daemon running, no need to have iguana accept connections\n"); printf("another daemon running, no need to have iguana accept connections\n");
return; return;
@ -99,17 +99,17 @@ void iguana_acceptloop(void *args)
printf("incoming (%s:%u)\n",ipaddr,cli_addr.sin_port); printf("incoming (%s:%u)\n",ipaddr,cli_addr.sin_port);
for (i=flag=0; i<IGUANA_MAXPEERS; i++) for (i=flag=0; i<IGUANA_MAXPEERS; i++)
{ {
if ( coin->peers.active[i].ipbits == (uint32_t)ipbits && coin->peers.active[i].usock >= 0 ) if ( coin->peers->active[i].ipbits == (uint32_t)ipbits && coin->peers->active[i].usock >= 0 )
{ {
printf("found existing peer.(%s) in slot[%d]\n",ipaddr,i); printf("found existing peer.(%s) in slot[%d]\n",ipaddr,i);
close(coin->peers.active[i].usock); close(coin->peers->active[i].usock);
coin->peers.active[i].dead = 0; coin->peers->active[i].dead = 0;
coin->peers.active[i].usock = sock; coin->peers->active[i].usock = sock;
coin->peers.active[i].A.port = cli_addr.sin_port; coin->peers->active[i].A.port = cli_addr.sin_port;
coin->peers.active[i].ready = (uint32_t)time(NULL); coin->peers->active[i].ready = (uint32_t)time(NULL);
flag = 1; flag = 1;
instantdex_peerhas_clear(coin,&coin->peers.active[i]); instantdex_peerhas_clear(coin,&coin->peers->active[i]);
//iguana_iAkill(coin,&coin->peers.active[i],0); //iguana_iAkill(coin,&coin->peers->active[i],0);
//sleep(1); //sleep(1);
break; break;
} }
@ -352,15 +352,15 @@ int32_t iguana_peeraddrrequest(struct iguana_info *coin,struct iguana_peer *addr
int32_t i,iter,n,max,sendlen; uint64_t x; struct iguana_peer *tmpaddr,tmp; char ipaddr[65]; int32_t i,iter,n,max,sendlen; uint64_t x; struct iguana_peer *tmpaddr,tmp; char ipaddr[65];
sendlen = 0; sendlen = 0;
max = (IGUANA_MINPEERS + IGUANA_MAXPEERS) / 2; max = (IGUANA_MINPEERS + IGUANA_MAXPEERS) / 2;
if ( max > coin->peers.numranked ) if ( max > coin->peers->numranked )
max = coin->peers.numranked; max = coin->peers->numranked;
x = 0; x = 0;
sendlen = iguana_rwvarint(1,&space[sendlen],&x); sendlen = iguana_rwvarint(1,&space[sendlen],&x);
for (iter=0; iter<2; iter++) for (iter=0; iter<2; iter++)
{ {
for (i=n=0; i<max; i++) for (i=n=0; i<max; i++)
{ {
if ( (tmpaddr= coin->peers.ranked[i]) != 0 && ((iter == 0 && tmpaddr->supernet != 0) || (iter == 1 && tmpaddr->supernet == 0)) && tmpaddr->ipbits != 0 ) if ( (tmpaddr= coin->peers->ranked[i]) != 0 && ((iter == 0 && tmpaddr->supernet != 0) || (iter == 1 && tmpaddr->supernet == 0)) && tmpaddr->ipbits != 0 )
{ {
tmp = *tmpaddr; tmp = *tmpaddr;
iguana_rwnum(1,&tmp.A.ip[12],sizeof(uint32_t),&tmp.ipbits); iguana_rwnum(1,&tmp.A.ip[12],sizeof(uint32_t),&tmp.ipbits);

16
iguana/iguana_bitmap.c

@ -1084,13 +1084,13 @@ void iguana_bitmapbundle(struct iguana_info *coin,uint8_t *rect,int32_t rowwidth
struct iguana_bitmap *iguana_bitmapfind(char *name) struct iguana_bitmap *iguana_bitmapfind(char *name)
{ {
struct iguana_info *coin; int32_t width,height,n,hdrsi,x,y; struct iguana_info *coin; int32_t width,height,n,hdrsi,x,y;
if ( (coin= iguana_coinfind(name)) != 0 || (coin= iguana_coinfind("BTCD")) != 0 ) if ( ((coin= iguana_coinfind(name)) != 0 || (coin= iguana_coinfind("BTCD")) != 0) && coin->screen != 0 )
{ {
strcpy(coin->screen.name,coin->symbol); strcpy(coin->screen->name,coin->symbol);
coin->screen.amplitude = 255; coin->screen->amplitude = 255;
coin->screen.width = IGUANA_WIDTH; coin->screen->width = IGUANA_WIDTH;
coin->screen.height = IGUANA_HEIGHT; coin->screen->height = IGUANA_HEIGHT;
memset(coin->screen.data,0xff,sizeof(coin->screen.data)); memset(coin->screen->data,0xff,sizeof(coin->screen->data));
if ( coin->bundlescount > 0 ) if ( coin->bundlescount > 0 )
{ {
n = 100; n = 100;
@ -1109,11 +1109,11 @@ struct iguana_bitmap *iguana_bitmapfind(char *name)
{ {
if ( hdrsi >= coin->bundlescount ) if ( hdrsi >= coin->bundlescount )
break; break;
iguana_bitmapbundle(coin,&coin->screen.data[3*(y*coin->screen.width*n + x*n)],coin->screen.width,n,n,coin->bundles[hdrsi]); iguana_bitmapbundle(coin,&coin->screen->data[3*(y*coin->screen->width*n + x*n)],coin->screen->width,n,n,coin->bundles[hdrsi]);
} }
} }
} }
return(&coin->screen); return(coin->screen);
} }
return(0); return(0);
} }

2
iguana/iguana_blocks.c

@ -15,7 +15,7 @@
#include "iguana777.h" #include "iguana777.h"
bits256 iguana_merkle(struct iguana_info *coin,bits256 *tree,int32_t txn_count) bits256 iguana_merkle(bits256 *tree,int32_t txn_count)
{ {
int32_t i,n=0,prev; uint8_t serialized[sizeof(bits256) * 2]; int32_t i,n=0,prev; uint8_t serialized[sizeof(bits256) * 2];
if ( txn_count == 1 ) if ( txn_count == 1 )

18
iguana/iguana_bundles.c

@ -469,7 +469,7 @@ void iguana_bundlepurgefiles(struct iguana_info *coin,struct iguana_bundle *bp)
//printf("purge.(%s)\n",fname); //printf("purge.(%s)\n",fname);
fclose(fp); fclose(fp);
if ( OS_removefile(fname,0) > 0 ) if ( OS_removefile(fname,0) > 0 )
coin->peers.numfiles--, m++; coin->peers->numfiles--, m++;
} }
} }
else printf("error removing.(%s)\n",fname); else printf("error removing.(%s)\n",fname);
@ -496,10 +496,10 @@ void iguana_bundlepurgefiles(struct iguana_info *coin,struct iguana_bundle *bp)
uint8_t iguana_recentpeers(struct iguana_info *coin,int32_t *capacityp,struct iguana_peer *peers[]) uint8_t iguana_recentpeers(struct iguana_info *coin,int32_t *capacityp,struct iguana_peer *peers[])
{ {
struct iguana_peer *addr; uint8_t m; int32_t capacity,i,n = coin->peers.numranked; struct iguana_peer *addr; uint8_t m; int32_t capacity,i,n = coin->peers->numranked;
for (i=m=capacity=0; i<n&&m<0xff; i++) for (i=m=capacity=0; i<n&&m<0xff; i++)
{ {
if ( (addr= coin->peers.ranked[i]) != 0 && addr->dead == 0 && addr->usock >= 0 && addr->msgcounts.verack != 0 && addr->pendblocks < coin->MAXPENDINGREQUESTS ) if ( (addr= coin->peers->ranked[i]) != 0 && addr->dead == 0 && addr->usock >= 0 && addr->msgcounts.verack != 0 && addr->pendblocks < coin->MAXPENDINGREQUESTS )
{ {
if ( peers != 0 ) if ( peers != 0 )
peers[m] = addr; peers[m] = addr;
@ -606,7 +606,7 @@ int32_t iguana_bundleissuemissing(struct iguana_info *coin,struct iguana_bundle
else if ( lag < 60 ) else if ( lag < 60 )
lag = 60; lag = 60;
} }
if ( (num= coin->peers.numranked) != 0 ) if ( (num= coin->peers->numranked) != 0 )
{ {
if ( num > 64 ) if ( num > 64 )
max = log2(num * num) + 1; max = log2(num * num) + 1;
@ -630,7 +630,7 @@ int32_t iguana_bundleissuemissing(struct iguana_info *coin,struct iguana_bundle
iguana_bundleblock(coin,&hash2,bp,i); iguana_bundleblock(coin,&hash2,bp,i);
if ( bits256_nonz(hash2) != 0 ) if ( bits256_nonz(hash2) != 0 )
{ {
if ( (addr= coin->peers.ranked[rand() % max]) != 0 && addr->usock >= 0 && addr->dead == 0 ) if ( (addr= coin->peers->ranked[rand() % max]) != 0 && addr->usock >= 0 && addr->dead == 0 )
{ {
struct iguana_blockreq *req = 0; struct iguana_blockreq *req = 0;
//if ( bp == coin->current ) //if ( bp == coin->current )
@ -658,7 +658,7 @@ int32_t iguana_bundleissuemissing(struct iguana_info *coin,struct iguana_bundle
iguana_bundleblock(coin,&hash2,bp,firsti); iguana_bundleblock(coin,&hash2,bp,firsti);
if ( bits256_nonz(hash2) != 0 ) if ( bits256_nonz(hash2) != 0 )
{ {
if ( (addr= coin->peers.ranked[rand() % max]) != 0 && addr->usock >= 0 && addr->dead == 0 ) if ( (addr= coin->peers->ranked[rand() % max]) != 0 && addr->usock >= 0 && addr->dead == 0 )
{ {
//if ( bp == coin->current ) //if ( bp == coin->current )
// printf("iguana_bundleissuemissing.[%d:%d]\n",bp->hdrsi,i); // printf("iguana_bundleissuemissing.[%d:%d]\n",bp->hdrsi,i);
@ -1123,10 +1123,10 @@ int32_t iguana_cacheprocess(struct iguana_info *coin,struct iguana_bundle *bp,in
void iguana_unstickhdr(struct iguana_info *coin,struct iguana_bundle *bp,int32_t lag) void iguana_unstickhdr(struct iguana_info *coin,struct iguana_bundle *bp,int32_t lag)
{ {
int32_t datalen,m,i; uint8_t serialized[512]; char str[65]; struct iguana_peer *addr; int32_t datalen,m,i; uint8_t serialized[512]; char str[65]; struct iguana_peer *addr;
if ( (m= coin->peers.numranked) > 0 && bp->numhashes < bp->n && bp->hdrsi < coin->longestchain/coin->chain->bundlesize && time(NULL) > bp->unsticktime+lag ) if ( (m= coin->peers->numranked) > 0 && bp->numhashes < bp->n && bp->hdrsi < coin->longestchain/coin->chain->bundlesize && time(NULL) > bp->unsticktime+lag )
{ {
for (i=0; i<10; i++) for (i=0; i<10; i++)
if ( (addr= coin->peers.ranked[rand() % m]) != 0 && addr->usock >= 0 && addr->dead == 0 && (datalen= iguana_gethdrs(coin,serialized,coin->chain->gethdrsmsg,bits256_str(str,bp->hashes[0]))) > 0 ) if ( (addr= coin->peers->ranked[rand() % m]) != 0 && addr->usock >= 0 && addr->dead == 0 && (datalen= iguana_gethdrs(coin,serialized,coin->chain->gethdrsmsg,bits256_str(str,bp->hashes[0]))) > 0 )
{ {
//printf("UNSTICK HDR.[%d]\n",bp->hdrsi); //printf("UNSTICK HDR.[%d]\n",bp->hdrsi);
iguana_send(coin,addr,serialized,datalen); iguana_send(coin,addr,serialized,datalen);
@ -1313,7 +1313,7 @@ void iguana_bundlestats(struct iguana_info *coin,char *str,int32_t lag)
coin->blocksrecv = numrecv; coin->blocksrecv = numrecv;
uint64_t tmp; int32_t diff,p = 0; struct tai difft,t = tai_now(); uint64_t tmp; int32_t diff,p = 0; struct tai difft,t = tai_now();
for (i=0; i<IGUANA_MAXPEERS; i++) for (i=0; i<IGUANA_MAXPEERS; i++)
if ( coin->peers.active[i].usock >= 0 ) if ( coin->peers->active[i].usock >= 0 )
p++; p++;
diff = (int32_t)time(NULL) - coin->startutc; diff = (int32_t)time(NULL) - coin->startutc;
difft.x = (t.x - coin->starttime.x), difft.millis = (t.millis - coin->starttime.millis); difft.x = (t.x - coin->starttime.x), difft.millis = (t.millis - coin->starttime.millis);

23
iguana/iguana_chains.c

@ -82,6 +82,7 @@ static struct iguana_chain Chains[] =
"\xfb\xc0\xb6\xdb", // pchMessageStart main.cpp "\xfb\xc0\xb6\xdb", // pchMessageStart main.cpp
//"12a765e31ffd4059bada1e25190f6e98c99d9714d334efa41a195a7e7e04bfe2", //"12a765e31ffd4059bada1e25190f6e98c99d9714d334efa41a195a7e7e04bfe2",
"12a765e31ffd4059bada1e25190f6e98c99d9714d334efa41a195a7e7e04bfe2", "12a765e31ffd4059bada1e25190f6e98c99d9714d334efa41a195a7e7e04bfe2",
//010000000000000000000000000000000000000000000000000000000000000000000000d9ced4ed1130f7b7faad9be25323ffafa33232a17c3edf6cfd97bee6bafbdd97b9aa8e4ef0ff0f1ecd513f7c
"010000000000000000000000000000000000000000000000000000000000000000000000d9ced4ed1130f7b7faad9be25323ffafa33232a17c3edf6cfd97bee6bafbdd97b9aa8e4ef0ff0f1ecd513f7c0101000000010000000000000000000000000000000000000000000000000000000000000000ffffffff4804ffff001d0104404e592054696d65732030352f4f63742f32303131205374657665204a6f62732c204170706c65e280997320566973696f6e6172792c2044696573206174203536ffffffff0100f2052a010000004341040184710fa689ad5023690c80f3a49c8f13f8d45b8c857fbcbc8bc4a8e4d3eb4b10f4d4604fa08dce601aaf0f470216fe1b51850b4acf21b179c45070ac7b03a9ac00000000", "010000000000000000000000000000000000000000000000000000000000000000000000d9ced4ed1130f7b7faad9be25323ffafa33232a17c3edf6cfd97bee6bafbdd97b9aa8e4ef0ff0f1ecd513f7c0101000000010000000000000000000000000000000000000000000000000000000000000000ffffffff4804ffff001d0104404e592054696d65732030352f4f63742f32303131205374657665204a6f62732c204170706c65e280997320566973696f6e6172792c2044696573206174203536ffffffff0100f2052a010000004341040184710fa689ad5023690c80f3a49c8f13f8d45b8c857fbcbc8bc4a8e4d3eb4b10f4d4604fa08dce601aaf0f470216fe1b51850b4acf21b179c45070ac7b03a9ac00000000",
9333,9334,0,0x1e // port and rpcport litecoin.conf 9333,9334,0,0x1e // port and rpcport litecoin.conf
},*/ },*/
@ -219,8 +220,9 @@ char *default_coindir(char *confname,char *coinstr)
void set_coinconfname(char *fname,char *coinstr,char *userhome,char *coindir,char *confname) void set_coinconfname(char *fname,char *coinstr,char *userhome,char *coindir,char *confname)
{ {
char buf[64]; char buf[64];
if ( coindir == 0 || coindir[0] == 0 ) if ( coindir == 0 || coindir[0] == 0 || confname == 0 || confname[0] == 0 )
coindir = default_coindir(buf,coinstr); coindir = default_coindir(buf,coinstr);
else buf[0] = 0;
if ( confname == 0 || confname[0] == 0 ) if ( confname == 0 || confname[0] == 0 )
{ {
confname = buf; confname = buf;
@ -238,7 +240,7 @@ uint16_t extract_userpass(char *serverport,char *userpass,char *coinstr,char *us
return(0); return(0);
serverport[0] = userpass[0] = 0; serverport[0] = userpass[0] = 0;
set_coinconfname(fname,coinstr,userhome,coindir,confname); set_coinconfname(fname,coinstr,userhome,coindir,confname);
printf("set_coinconfname.(%s)\n",fname); printf("set_coinconfname.(%s) <- (%s)\n",fname,confname);
if ( (fp= fopen(OS_compatible_path(fname),"r")) != 0 ) if ( (fp= fopen(OS_compatible_path(fname),"r")) != 0 )
{ {
if ( Debuglevel > 1 ) if ( Debuglevel > 1 )
@ -282,7 +284,7 @@ uint16_t extract_userpass(char *serverport,char *userpass,char *coinstr,char *us
void iguana_chainparms(struct iguana_chain *chain,cJSON *argjson) void iguana_chainparms(struct iguana_chain *chain,cJSON *argjson)
{ {
extern char Userhome[]; extern char Userhome[];
char *path,*conf,*hexstr,genesisblock[1024]; bits256 hash; uint16_t port; cJSON *rpair,*genesis,*rewards,*item; int32_t i,n,m; uint32_t nBits; uint8_t tmp[4]; char *path,conf[512],*hexstr,genesisblock[1024]; bits256 hash; uint16_t port; cJSON *rpair,*genesis,*rewards,*item; int32_t i,n,m; uint32_t nBits; uint8_t tmp[4];
if ( strcmp(chain->symbol,"NXT") != 0 ) if ( strcmp(chain->symbol,"NXT") != 0 )
{ {
if ( strcmp(chain->symbol,"BTCD") == 0 ) if ( strcmp(chain->symbol,"BTCD") == 0 )
@ -304,7 +306,10 @@ void iguana_chainparms(struct iguana_chain *chain,cJSON *argjson)
chain->minconfirms = juint(argjson,"minconfirms"); chain->minconfirms = juint(argjson,"minconfirms");
chain->estblocktime = juint(argjson,"estblocktime"); chain->estblocktime = juint(argjson,"estblocktime");
path = jstr(argjson,"path"); path = jstr(argjson,"path");
conf = jstr(argjson,"conf"); if ( jobj(argjson,"conf") == 0 )
conf[0] = 0;
else safecopy(conf,jstr(argjson,"conf"),sizeof(conf));
printf("CONF.(%s)\n",conf);
safecopy(chain->name,jstr(argjson,"name"),sizeof(chain->name)); safecopy(chain->name,jstr(argjson,"name"),sizeof(chain->name));
//chain->dust = j64bits(argjson,"dust"); //chain->dust = j64bits(argjson,"dust");
if ( jobj(argjson,"txfee_satoshis") != 0 ) if ( jobj(argjson,"txfee_satoshis") != 0 )
@ -321,17 +326,21 @@ void iguana_chainparms(struct iguana_chain *chain,cJSON *argjson)
if ( (chain->rpcport= juint(argjson,"rpc")) == 0 ) if ( (chain->rpcport= juint(argjson,"rpc")) == 0 )
chain->rpcport = chain->portp2p - 1; chain->rpcport = chain->portp2p - 1;
if ( jobj(argjson,"isPoS") != 0 ) if ( jobj(argjson,"isPoS") != 0 )
chain->hastimestamp = juint(argjson,"isPoS"); chain->txhastimestamp = juint(argjson,"isPoS");
else if ( jobj(argjson,"oldtx_format") != 0 ) else if ( jobj(argjson,"oldtx_format") != 0 )
chain->hastimestamp = !juint(argjson,"oldtx_format"); chain->txhastimestamp = !juint(argjson,"oldtx_format");
else if ( jobj(argjson,"txhastimestamp") != 0 ) else if ( jobj(argjson,"txhastimestamp") != 0 )
chain->hastimestamp = !juint(argjson,"txhastimestamp"); chain->txhastimestamp = !juint(argjson,"txhastimestamp");
if ( jstr(argjson,"userhome") != 0 ) if ( jstr(argjson,"userhome") != 0 )
strcpy(chain->userhome,jstr(argjson,"userhome")); strcpy(chain->userhome,jstr(argjson,"userhome"));
else strcpy(chain->userhome,Userhome); else strcpy(chain->userhome,Userhome);
if ( (chain->protover= juint(argjson,"protover")) == 0 ) if ( (chain->protover= juint(argjson,"protover")) == 0 )
chain->protover = PROTOCOL_VERSION; chain->protover = PROTOCOL_VERSION;
chain->auxpow = juint(argjson,"auxpow"); chain->auxpow = juint(argjson,"auxpow");
if ( (chain->targetspacing= jint(argjson,"targetspacing")) == 0 )
chain->targetspacing = NTARGETSPACING;
if ( (chain->targettimespan= jint(argjson,"targettimespan")) == 0 )
chain->targettimespan = NTARGETSPACING * 60;
if ( (port= extract_userpass(chain->serverport,chain->userpass,chain->symbol,chain->userhome,path,conf)) != 0 ) if ( (port= extract_userpass(chain->serverport,chain->userpass,chain->symbol,chain->userhome,path,conf)) != 0 )
chain->rpcport = port; chain->rpcport = port;
if ( chain->serverport[0] == 0 ) if ( chain->serverport[0] == 0 )

35
iguana/iguana_init.c

@ -27,7 +27,7 @@ void iguana_initQ(queue_t *Q,char *name)
void iguana_initQs(struct iguana_info *coin) void iguana_initQs(struct iguana_info *coin)
{ {
int32_t i; int32_t i; struct iguana_info *btcd;
iguana_initQ(&coin->acceptQ,"acceptQ"); iguana_initQ(&coin->acceptQ,"acceptQ");
iguana_initQ(&coin->hdrsQ,"hdrsQ"); iguana_initQ(&coin->hdrsQ,"hdrsQ");
iguana_initQ(&coin->blocksQ,"blocksQ"); iguana_initQ(&coin->blocksQ,"blocksQ");
@ -36,8 +36,11 @@ void iguana_initQs(struct iguana_info *coin)
iguana_initQ(&coin->msgrequestQ,"msgrequestQ"); iguana_initQ(&coin->msgrequestQ,"msgrequestQ");
iguana_initQ(&coin->cacheQ,"cacheQ"); iguana_initQ(&coin->cacheQ,"cacheQ");
iguana_initQ(&coin->recvQ,"recvQ"); iguana_initQ(&coin->recvQ,"recvQ");
if ( (btcd= iguana_coinfind("BTCD")) == 0 || coin->peers != btcd->peers )
{
for (i=0; i<IGUANA_MAXPEERS; i++) for (i=0; i<IGUANA_MAXPEERS; i++)
iguana_initQ(&coin->peers.active[i].sendQ,"addrsendQ"); iguana_initQ(&coin->peers->active[i].sendQ,"addrsendQ");
}
} }
void iguana_initpeer(struct iguana_info *coin,struct iguana_peer *addr,uint64_t ipbits) void iguana_initpeer(struct iguana_info *coin,struct iguana_peer *addr,uint64_t ipbits)
@ -71,8 +74,11 @@ void iguana_initcoin(struct iguana_info *coin,cJSON *argjson)
coin->startmillis = OS_milliseconds(), coin->starttime = tai_now(); coin->startmillis = OS_milliseconds(), coin->starttime = tai_now();
coin->avetime = 1 * 100; coin->avetime = 1 * 100;
//coin->R.maxrecvbundles = IGUANA_INITIALBUNDLES; //coin->R.maxrecvbundles = IGUANA_INITIALBUNDLES;
if ( coin->peers != 0 )
{
for (i=0; i<IGUANA_MAXPEERS; i++) for (i=0; i<IGUANA_MAXPEERS; i++)
coin->peers.active[i].usock = -1; coin->peers->active[i].usock = -1;
}
} }
bits256 iguana_genesis(struct iguana_info *coin,struct iguana_chain *chain) bits256 iguana_genesis(struct iguana_info *coin,struct iguana_chain *chain)
@ -275,13 +281,13 @@ void iguana_parseline(struct iguana_info *coin,int32_t iter,FILE *fp)
{ {
if ( 0 && m == 0 ) if ( 0 && m == 0 )
{ {
addr = &coin->peers.active[m++]; addr = &coin->peers->active[m++];
iguana_initpeer(coin,addr,(uint32_t)calc_ipbits("127.0.0.1")); iguana_initpeer(coin,addr,(uint32_t)calc_ipbits("127.0.0.1"));
//printf("call initpeer.(%s)\n",addr->ipaddr); //printf("call initpeer.(%s)\n",addr->ipaddr);
iguana_launch(coin,"connection",iguana_startconnection,addr,IGUANA_CONNTHREAD); iguana_launch(coin,"connection",iguana_startconnection,addr,IGUANA_CONNTHREAD);
} }
#ifndef IGUANA_DISABLEPEERS #ifndef IGUANA_DISABLEPEERS
addr = &coin->peers.active[m++]; addr = &coin->peers->active[m++];
iguana_initpeer(coin,addr,(uint32_t)calc_ipbits(line)); iguana_initpeer(coin,addr,(uint32_t)calc_ipbits(line));
//printf("call initpeer.(%s)\n",addr->ipaddr); //printf("call initpeer.(%s)\n",addr->ipaddr);
iguana_launch(coin,"connection",iguana_startconnection,addr,IGUANA_CONNTHREAD); iguana_launch(coin,"connection",iguana_startconnection,addr,IGUANA_CONNTHREAD);
@ -456,6 +462,11 @@ void iguana_coinpurge(struct iguana_info *coin)
struct iguana_info *iguana_coinstart(struct iguana_info *coin,int32_t initialheight,int32_t mapflags) struct iguana_info *iguana_coinstart(struct iguana_info *coin,int32_t initialheight,int32_t mapflags)
{ {
FILE *fp; char fname[512],*symbol; int32_t iter; long fpos; bits256 lastbundle; struct supernet_info *myinfo = SuperNET_MYINFO(0); FILE *fp; char fname[512],*symbol; int32_t iter; long fpos; bits256 lastbundle; struct supernet_info *myinfo = SuperNET_MYINFO(0);
if ( coin->peers == 0 )
{
printf("cant start privatechain directly\n");
return(0);
}
coin->sleeptime = 10000; coin->sleeptime = 10000;
symbol = coin->symbol; symbol = coin->symbol;
if ( iguana_peerslotinit(coin,&coin->internaladdr,IGUANA_MAXPEERS,calc_ipbits("127.0.0.1:7777")) < 0 ) if ( iguana_peerslotinit(coin,&coin->internaladdr,IGUANA_MAXPEERS,calc_ipbits("127.0.0.1:7777")) < 0 )
@ -473,13 +484,13 @@ struct iguana_info *iguana_coinstart(struct iguana_info *coin,int32_t initialhei
printf("%s MYSERVICES.%llx\n",coin->symbol,(long long)coin->myservices); printf("%s MYSERVICES.%llx\n",coin->symbol,(long long)coin->myservices);
if ( (coin->myservices & NODE_NETWORK) != 0 ) if ( (coin->myservices & NODE_NETWORK) != 0 )
{ {
if ( coin->peers.acceptloop == 0 && coin->peers.localaddr == 0 ) if ( coin->peers->acceptloop == 0 && coin->peers->localaddr == 0 )
{ {
coin->peers.acceptloop = malloc(sizeof(pthread_t)); coin->peers->acceptloop = malloc(sizeof(pthread_t));
if ( OS_thread_create(coin->peers.acceptloop,NULL,(void *)iguana_acceptloop,(void *)coin) != 0 ) if ( OS_thread_create(coin->peers->acceptloop,NULL,(void *)iguana_acceptloop,(void *)coin) != 0 )
{ {
free(coin->peers.acceptloop); free(coin->peers->acceptloop);
coin->peers.acceptloop = 0; coin->peers->acceptloop = 0;
printf("error launching accept thread for port.%u\n",coin->chain->portp2p); printf("error launching accept thread for port.%u\n",coin->chain->portp2p);
} }
} }
@ -498,7 +509,7 @@ struct iguana_info *iguana_coinstart(struct iguana_info *coin,int32_t initialhei
//coin->firstblock = coin->blocks.parsedblocks + 1; //coin->firstblock = coin->blocks.parsedblocks + 1;
iguana_genesis(coin,coin->chain); iguana_genesis(coin,coin->chain);
memset(&lastbundle,0,sizeof(lastbundle)); memset(&lastbundle,0,sizeof(lastbundle));
for (iter=coin->peers.numranked>8; iter<2; iter++) for (iter=coin->peers->numranked>8; iter<2; iter++)
{ {
#ifdef __PNACL__ #ifdef __PNACL__
if ( iter == 0 ) if ( iter == 0 )
@ -564,7 +575,7 @@ struct iguana_info *iguana_coinstart(struct iguana_info *coin,int32_t initialhei
printf("done parsefile.%d (%s) size.%ld\n",iter,fname,fpos); printf("done parsefile.%d (%s) size.%ld\n",iter,fname,fpos);
} }
#ifndef IGUANA_DEDICATED_THREADS #ifndef IGUANA_DEDICATED_THREADS
coin->peers.peersloop = iguana_launch("peersloop",iguana_peersloop,coin,IGUANA_PERMTHREAD); coin->peers->peersloop = iguana_launch("peersloop",iguana_peersloop,coin,IGUANA_PERMTHREAD);
#endif #endif
printf("started.%s %p active.%d\n",coin->symbol,coin->started,coin->active); printf("started.%s %p active.%d\n",coin->symbol,coin->started,coin->active);
return(coin); return(coin);

12
iguana/iguana_instantdex.c

@ -474,7 +474,7 @@ char *instantdex_sendcmd(struct supernet_info *myinfo,struct instantdex_offer *o
jaddbits256(sendjson,"categoryhash",myinfo->instantdex_category); jaddbits256(sendjson,"categoryhash",myinfo->instantdex_category);
jaddbits256(sendjson,"traderpub",myinfo->myaddr.persistent); jaddbits256(sendjson,"traderpub",myinfo->myaddr.persistent);
data = basilisk_jsondata(&allocptr,space,sizeof(space),&datalen,swap->mine.offer.base,sendjson,basilisktag); data = basilisk_jsondata(&allocptr,space,sizeof(space),&datalen,swap->mine.offer.base,sendjson,basilisktag);
basilisk_sendcmd(myinfo,addr->ipaddr,dir > 0 ? "BID" : "ASK",&basilisktag,encryptflag,delaymillis,data,datalen,1,0x1efffff0); basilisk_sendcmd(myinfo,addr->ipaddr,dir > 0 ? "BID" : "ASK",&basilisktag,encryptflag,delaymillis,data,datalen,1,BASILISK_DEFAULTDIFF);
free_json(sendjson); free_json(sendjson);
if ( allocptr != 0 ) if ( allocptr != 0 )
free(allocptr); free(allocptr);
@ -1078,10 +1078,10 @@ void instantdex_propagate(struct supernet_info *myinfo,struct exchange_info *exc
{ {
bits256 orderhash; uint8_t serialized[8192]; int32_t i,len; struct iguana_peer *addr; struct iguana_info *coin; bits256 orderhash; uint8_t serialized[8192]; int32_t i,len; struct iguana_peer *addr; struct iguana_info *coin;
orderhash = instantdex_rwoffer(1,&len,&serialized[sizeof(struct iguana_msghdr)],&ap->offer); orderhash = instantdex_rwoffer(1,&len,&serialized[sizeof(struct iguana_msghdr)],&ap->offer);
if ( (coin= iguana_coinfind("BTCD")) != 0 && coin->peers.numranked > 0 ) if ( (coin= iguana_coinfind("BTCD")) != 0 && coin->peers->numranked > 0 )
{ {
for (i=0; i<coin->peers.numranked; i++) for (i=0; i<coin->peers->numranked; i++)
if ( (addr= coin->peers.ranked[i]) != 0 && addr->supernet != 0 && addr->usock >= 0 && GETBIT(ap->peerhas,addr->addrind) == 0 && strcmp("0.0.0.0",addr->ipaddr) != 0 && strcmp("127.0.0.1",addr->ipaddr) != 0 ) if ( (addr= coin->peers->ranked[i]) != 0 && addr->supernet != 0 && addr->usock >= 0 && GETBIT(ap->peerhas,addr->addrind) == 0 && strcmp("0.0.0.0",addr->ipaddr) != 0 && strcmp("127.0.0.1",addr->ipaddr) != 0 )
{ {
char str[65]; printf("send quote.(%s) <- [%d] %s %llx\n",addr->ipaddr,len,bits256_str(str,orderhash),(long long)orderhash.txid); char str[65]; printf("send quote.(%s) <- [%d] %s %llx\n",addr->ipaddr,len,bits256_str(str,orderhash),(long long)orderhash.txid);
iguana_queue_send(addr,0,serialized,"quote",len); iguana_queue_send(addr,0,serialized,"quote",len);
@ -1445,7 +1445,7 @@ char *instantdex_parse(struct supernet_info *myinfo,struct instantdex_msghdr *ms
return(clonestr("{\"error\":\"request needs argjson\"}")); return(clonestr("{\"error\":\"request needs argjson\"}"));
} }
char *InstantDEX_hexmsg(struct supernet_info *myinfo,struct category_info *cat,void *ptr,int32_t len,char *remoteaddr) char *InstantDEX_hexmsg(struct supernet_info *myinfo,struct private_chain *cat,void *ptr,int32_t len,char *remoteaddr)
{ {
struct instantdex_msghdr *msg = ptr; int32_t olen,slen,datalen,newlen,flag = 0; struct instantdex_msghdr *msg = ptr; int32_t olen,slen,datalen,newlen,flag = 0;
uint8_t *serdata; struct instantdex_offer rawoffer; // struct supernet_info *myinfos[64]; uint8_t *serdata; struct instantdex_offer rawoffer; // struct supernet_info *myinfos[64];
@ -1554,7 +1554,7 @@ char *instantdex_createaccept(struct supernet_info *myinfo,struct instantdex_acc
void instantdex_update(struct supernet_info *myinfo) void instantdex_update(struct supernet_info *myinfo)
{ {
struct instantdex_msghdr *pm; struct category_msg *m; char *str,remote[64]; queue_t *Q; struct queueitem *item; struct category_info *cat; struct instantdex_msghdr *pm; struct category_msg *m; char *str,remote[64]; queue_t *Q; struct queueitem *item; struct private_chain *cat;
//char str2[65]; printf("myinfo->instantdex_category.(%s)\n",bits256_str(str2,myinfo->instantdex_category)); //char str2[65]; printf("myinfo->instantdex_category.(%s)\n",bits256_str(str2,myinfo->instantdex_category));
if ( (Q= category_Q(&cat,myinfo->instantdex_category,myinfo->myaddr.persistent)) != 0 && queue_size(Q) > 0 && (item= Q->list) != 0 ) if ( (Q= category_Q(&cat,myinfo->instantdex_category,myinfo->myaddr.persistent)) != 0 && queue_size(Q) > 0 && (item= Q->list) != 0 )
{ {

34
iguana/iguana_json.c

@ -560,7 +560,7 @@ cJSON *iguana_peersjson(struct iguana_info *coin,int32_t addronly)
array = cJSON_CreateArray(); array = cJSON_CreateArray();
for (i=0; i<coin->MAXPEERS; i++) for (i=0; i<coin->MAXPEERS; i++)
{ {
addr = &coin->peers.active[i]; addr = &coin->peers->active[i];
if ( addr->usock >= 0 && addr->ipbits != 0 && addr->ipaddr[0] != 0 ) if ( addr->usock >= 0 && addr->ipbits != 0 && addr->ipaddr[0] != 0 )
{ {
if ( addronly != 0 ) if ( addronly != 0 )
@ -593,8 +593,8 @@ STRING_ARG(iguana,getconnectioncount,activecoin)
int32_t i,num = 0; char buf[512]; int32_t i,num = 0; char buf[512];
if ( coin != 0 ) if ( coin != 0 )
{ {
for (i=0; i<sizeof(coin->peers.active)/sizeof(*coin->peers.active); i++) for (i=0; i<sizeof(coin->peers->active)/sizeof(*coin->peers->active); i++)
if ( coin->peers.active[i].usock >= 0 ) if ( coin->peers->active[i].usock >= 0 )
num++; num++;
sprintf(buf,"{\"result\":\"%d\"}",num); sprintf(buf,"{\"result\":\"%d\"}",num);
return(clonestr(buf)); return(clonestr(buf));
@ -669,22 +669,22 @@ TWO_STRINGS(iguana,addnode,activecoin,ipaddr)
addr->supernet = 1; addr->supernet = 1;
if ( addr->usock >= 0 ) if ( addr->usock >= 0 )
{ {
if ( (n= coin->peers.numranked) != 0 ) if ( (n= coin->peers->numranked) != 0 )
{ {
for (i=0; i<n; i++) for (i=0; i<n; i++)
{ {
if ( addr == coin->peers.ranked[i] ) if ( addr == coin->peers->ranked[i] )
break; break;
} }
if ( i == n ) if ( i == n )
{ {
if ( i == IGUANA_MAXPEERS ) if ( i == IGUANA_MAXPEERS )
i--; i--;
else coin->peers.numranked = n+1; else coin->peers->numranked = n+1;
coin->peers.ranked[i] = addr; coin->peers->ranked[i] = addr;
addr->recvblocks = coin->peers.ranked[0]->recvblocks + 100; addr->recvblocks = coin->peers->ranked[0]->recvblocks + 100;
addr->recvtotal = coin->peers.ranked[0]->recvtotal*1.1 + 100; addr->recvtotal = coin->peers->ranked[0]->recvtotal*1.1 + 100;
printf("set (%s) -> slot.%d numranked.%d\n",ipaddr,i,coin->peers.numranked); printf("set (%s) -> slot.%d numranked.%d\n",ipaddr,i,coin->peers->numranked);
} else printf("(%s) is already peer.%d\n",ipaddr,i); } else printf("(%s) is already peer.%d\n",ipaddr,i);
} }
return(clonestr("{\"result\":\"peer was already connected\"}")); return(clonestr("{\"result\":\"peer was already connected\"}"));
@ -709,9 +709,9 @@ TWO_STRINGS(iguana,persistent,activecoin,ipaddr)
{ {
for (i=0; i<IGUANA_MAXPEERS; i++) for (i=0; i<IGUANA_MAXPEERS; i++)
{ {
if ( strcmp(coin->peers.active[i].ipaddr,ipaddr) == 0 ) if ( strcmp(coin->peers->active[i].ipaddr,ipaddr) == 0 )
{ {
coin->peers.active[i].persistent_peer = juint(json,"interval")+3; coin->peers->active[i].persistent_peer = juint(json,"interval")+3;
return(clonestr("{\"result\":\"node marked as persistent\"}")); return(clonestr("{\"result\":\"node marked as persistent\"}"));
} }
} }
@ -726,10 +726,10 @@ TWO_STRINGS(iguana,removenode,activecoin,ipaddr)
{ {
for (i=0; i<IGUANA_MAXPEERS; i++) for (i=0; i<IGUANA_MAXPEERS; i++)
{ {
if ( strcmp(coin->peers.active[i].ipaddr,ipaddr) == 0 ) if ( strcmp(coin->peers->active[i].ipaddr,ipaddr) == 0 )
{ {
coin->peers.active[i].rank = 0; coin->peers->active[i].rank = 0;
coin->peers.active[i].dead = (uint32_t)time(NULL); coin->peers->active[i].dead = (uint32_t)time(NULL);
return(clonestr("{\"result\":\"node marked as dead\"}")); return(clonestr("{\"result\":\"node marked as dead\"}"));
} }
} }
@ -753,7 +753,7 @@ TWO_STRINGS(iguana,nodestatus,activecoin,ipaddr)
{ {
for (i=0; i<coin->MAXPEERS; i++) for (i=0; i<coin->MAXPEERS; i++)
{ {
addr = &coin->peers.active[i]; addr = &coin->peers->active[i];
if ( strcmp(addr->ipaddr,ipaddr) == 0 ) if ( strcmp(addr->ipaddr,ipaddr) == 0 )
return(jprint(iguana_peerjson(coin,addr),1)); return(jprint(iguana_peerjson(coin,addr),1));
} }
@ -772,7 +772,7 @@ STRING_AND_INT(iguana,maxpeers,activecoin,max)
if ( max > coin->MAXPEERS ) if ( max > coin->MAXPEERS )
{ {
for (i=max; i<coin->MAXPEERS; i++) for (i=max; i<coin->MAXPEERS; i++)
if ( (addr= coin->peers.ranked[i]) != 0 ) if ( (addr= coin->peers->ranked[i]) != 0 )
addr->dead = 1; addr->dead = 1;
} }
coin->MAXPEERS = max; coin->MAXPEERS = max;

10
iguana/iguana_msg.c

@ -120,7 +120,7 @@ int32_t iguana_eatauxpow(int32_t rwflag,char *symbol,uint8_t *serialized)
memset(&MEM,0,sizeof(MEM)); memset(&MEM,0,sizeof(MEM));
ptr = calloc(1,1000000); ptr = calloc(1,1000000);
iguana_meminit(&MEM,"auxpow",ptr,1000000,0); iguana_meminit(&MEM,"auxpow",ptr,1000000,0);
len += iguana_rwtx(rwflag,&MEM,&serialized[len],&msg,(int32_t)MEM.totalsize,&coinbasetxid,coin->chain->hastimestamp,0); len += iguana_rwtx(rwflag,&MEM,&serialized[len],&msg,(int32_t)MEM.totalsize,&coinbasetxid,coin->chain->txhastimestamp,0);
len += iguana_rwbignum(rwflag,&serialized[len],sizeof(auxhash2),auxhash2.bytes); len += iguana_rwbignum(rwflag,&serialized[len],sizeof(auxhash2),auxhash2.bytes);
len += iguana_rwmerklebranch(rwflag,&serialized[len],&coinbase_branch); len += iguana_rwmerklebranch(rwflag,&serialized[len],&coinbase_branch);
len += iguana_rwmerklebranch(rwflag,&serialized[len],&blockchain_branch); len += iguana_rwmerklebranch(rwflag,&serialized[len],&blockchain_branch);
@ -566,13 +566,13 @@ int32_t iguana_gentxarray(struct iguana_info *coin,struct OS_memspace *mem,struc
{ {
if ( len > recvlen ) if ( len > recvlen )
break; break;
if ( (n= iguana_rwtx(0,mem,&data[len],&tx[i],recvlen - len,&tx[i].txid,coin->chain->hastimestamp,strcmp(coin->symbol,"VPN")==0)) < 0 ) if ( (n= iguana_rwtx(0,mem,&data[len],&tx[i],recvlen - len,&tx[i].txid,coin->chain->txhastimestamp,strcmp(coin->symbol,"VPN")==0)) < 0 )
break; break;
numvouts += tx[i].tx_out; numvouts += tx[i].tx_out;
numvins += tx[i].tx_in; numvins += tx[i].tx_in;
len += n; len += n;
} }
if ( coin->chain->hastimestamp != 0 && len != recvlen && data[len] == (recvlen - len - 1) ) if ( coin->chain->txhastimestamp != 0 && len != recvlen && data[len] == (recvlen - len - 1) )
{ {
//printf("\n>>>>>>>>>>> len.%d vs recvlen.%d [%d]\n",len,recvlen,data[len]); //printf("\n>>>>>>>>>>> len.%d vs recvlen.%d [%d]\n",len,recvlen,data[len]);
memcpy(txdata->space,&data[len],recvlen-len); memcpy(txdata->space,&data[len],recvlen-len);
@ -782,7 +782,7 @@ int32_t iguana_msgparser(struct iguana_info *coin,struct iguana_peer *addr,struc
{ {
iguana_memreset(rawmem); iguana_memreset(rawmem);
tx = iguana_memalloc(rawmem,sizeof(*tx),1); tx = iguana_memalloc(rawmem,sizeof(*tx),1);
len += iguana_rwtx(0,rawmem,&data[len],tx,recvlen-len,&tx->txid,coin->chain->hastimestamp,strcmp(coin->symbol,"VPN")==0); len += iguana_rwtx(0,rawmem,&data[len],tx,recvlen-len,&tx->txid,coin->chain->txhastimestamp,strcmp(coin->symbol,"VPN")==0);
len += iguana_rwbignum(0,&data[len],sizeof(auxhash2),auxhash2.bytes); len += iguana_rwbignum(0,&data[len],sizeof(auxhash2),auxhash2.bytes);
len += iguana_rwmerklebranch(0,&data[len],&coinbase_branch); len += iguana_rwmerklebranch(0,&data[len],&coinbase_branch);
len += iguana_rwmerklebranch(0,&data[len],&blockchain_branch); len += iguana_rwmerklebranch(0,&data[len],&blockchain_branch);
@ -931,7 +931,7 @@ int32_t iguana_msgparser(struct iguana_info *coin,struct iguana_peer *addr,struc
struct iguana_msgtx *tx; struct iguana_msgtx *tx;
iguana_memreset(rawmem); iguana_memreset(rawmem);
tx = iguana_memalloc(rawmem,sizeof(*tx),1);//mycalloc('u',1,sizeof(*tx)); tx = iguana_memalloc(rawmem,sizeof(*tx),1);//mycalloc('u',1,sizeof(*tx));
len = iguana_rwtx(0,rawmem,data,tx,recvlen,&tx->txid,coin->chain->hastimestamp,strcmp(coin->symbol,"VPN")==0); len = iguana_rwtx(0,rawmem,data,tx,recvlen,&tx->txid,coin->chain->txhastimestamp,strcmp(coin->symbol,"VPN")==0);
if ( addr != 0 ) if ( addr != 0 )
{ {
iguana_gotunconfirmedM(coin,addr,tx,data,recvlen); iguana_gotunconfirmedM(coin,addr,tx,data,recvlen);

12
iguana/iguana_payments.c

@ -299,14 +299,14 @@ char *iguana_signrawtx(struct supernet_info *myinfo,struct iguana_info *coin,bit
bits256 iguana_sendrawtransaction(struct supernet_info *myinfo,struct iguana_info *coin,char *signedtx) bits256 iguana_sendrawtransaction(struct supernet_info *myinfo,struct iguana_info *coin,char *signedtx)
{ {
bits256 txid; uint8_t *serialized; int32_t i,len; struct iguana_peer *addr; bits256 txid; uint8_t *serialized; int32_t i,len; struct iguana_peer *addr;
if ( coin->peers.numranked >= 8 ) if ( coin->peers->numranked >= 8 )
{ {
len = (int32_t)strlen(signedtx) >> 1; len = (int32_t)strlen(signedtx) >> 1;
serialized = calloc(1,sizeof(struct iguana_msghdr) + len); serialized = calloc(1,sizeof(struct iguana_msghdr) + len);
decode_hex(&serialized[sizeof(struct iguana_msghdr)],len,signedtx); decode_hex(&serialized[sizeof(struct iguana_msghdr)],len,signedtx);
for (i=0; i<8; i++) for (i=0; i<8; i++)
{ {
if ( (addr= coin->peers.ranked[i]) != 0 && addr->dead == 0 && addr->usock >= 0 ) if ( (addr= coin->peers->ranked[i]) != 0 && addr->dead == 0 && addr->usock >= 0 )
iguana_queue_send(addr,0,serialized,"tx",len); iguana_queue_send(addr,0,serialized,"tx",len);
} }
free(serialized); free(serialized);
@ -356,7 +356,7 @@ char *iguana_calcrawtx(struct supernet_info *myinfo,struct iguana_info *coin,cJS
} }
bitcoin_addr2rmd160(&addrtype,rmd160,changeaddr); bitcoin_addr2rmd160(&addrtype,rmd160,changeaddr);
spendlen = bitcoin_standardspend(spendscript,0,rmd160); spendlen = bitcoin_standardspend(spendscript,0,rmd160);
bitcoin_txoutput(coin,txobj,spendscript,spendlen,change); bitcoin_txoutput(txobj,spendscript,spendlen,change);
} }
if ( vins != 0 ) if ( vins != 0 )
V = calloc(cJSON_GetArraySize(vins),sizeof(*V)); V = calloc(cJSON_GetArraySize(vins),sizeof(*V));
@ -974,7 +974,7 @@ ARRAY_OBJ_INT(bitcoinrpc,createrawtransaction,vins,vouts,locktime)
bits256 txid; int32_t offset,spendlen=0,n; uint8_t addrtype,rmd160[20],spendscript[IGUANA_MAXSCRIPTSIZE]; uint64_t satoshis; char *hexstr,*field,*txstr; cJSON *txobj,*item,*obj,*retjson = cJSON_CreateObject(); bits256 txid; int32_t offset,spendlen=0,n; uint8_t addrtype,rmd160[20],spendscript[IGUANA_MAXSCRIPTSIZE]; uint64_t satoshis; char *hexstr,*field,*txstr; cJSON *txobj,*item,*obj,*retjson = cJSON_CreateObject();
if ( remoteaddr != 0 ) if ( remoteaddr != 0 )
return(clonestr("{\"error\":\"no remote\"}")); return(clonestr("{\"error\":\"no remote\"}"));
if ( coin != 0 && (txobj= bitcoin_txcreate(coin,locktime)) != 0 ) if ( coin != 0 && (txobj= bitcoin_txcreate(coin->chain->txhastimestamp,locktime)) != 0 )
{ {
iguana_createvins(myinfo,coin,txobj,vins); iguana_createvins(myinfo,coin,txobj,vins);
if ( (n= cJSON_GetArraySize(vouts)) > 0 ) if ( (n= cJSON_GetArraySize(vouts)) > 0 )
@ -1025,7 +1025,7 @@ ARRAY_OBJ_INT(bitcoinrpc,createrawtransaction,vins,vouts,locktime)
if ( (obj= jobj(item,"amount")) != 0 ) if ( (obj= jobj(item,"amount")) != 0 )
satoshis = jdouble(obj,0) * SATOSHIDEN; satoshis = jdouble(obj,0) * SATOSHIDEN;
else satoshis = 0; else satoshis = 0;
bitcoin_txoutput(coin,txobj,spendscript+offset,spendlen,satoshis); bitcoin_txoutput(txobj,spendscript+offset,spendlen,satoshis);
} }
} }
break; break;
@ -1036,7 +1036,7 @@ ARRAY_OBJ_INT(bitcoinrpc,createrawtransaction,vins,vouts,locktime)
{ {
spendlen = bitcoin_standardspend(spendscript,0,rmd160); spendlen = bitcoin_standardspend(spendscript,0,rmd160);
satoshis = jdouble(item,0) * SATOSHIDEN; satoshis = jdouble(item,0) * SATOSHIDEN;
bitcoin_txoutput(coin,txobj,spendscript,spendlen,satoshis); bitcoin_txoutput(txobj,spendscript,spendlen,satoshis);
} }
} }
} }

66
iguana/iguana_peers.c

@ -285,8 +285,8 @@ void iguana_iAkill(struct iguana_info *coin,struct iguana_peer *addr,int32_t mar
strcpy(ipaddr,addr->ipaddr); strcpy(ipaddr,addr->ipaddr);
if ( addr->usock >= 0 ) if ( addr->usock >= 0 )
closesocket(addr->usock), addr->usock = -1; closesocket(addr->usock), addr->usock = -1;
if ( addr == coin->peers.localaddr ) if ( addr == coin->peers->localaddr )
coin->peers.localaddr = 0; coin->peers->localaddr = 0;
//printf("iAkill.(%s)\n",addr->ipaddr); //printf("iAkill.(%s)\n",addr->ipaddr);
if ( (iA= iguana_iAddrhashfind(coin,addr->ipbits,1)) != 0 ) if ( (iA= iguana_iAddrhashfind(coin,addr->ipbits,1)) != 0 )
{ {
@ -410,7 +410,7 @@ int32_t iguana_send(struct iguana_info *coin,struct iguana_peer *addr,uint8_t *s
r = rand(); r = rand();
for (i=0; i<IGUANA_MAXPEERS; i++) for (i=0; i<IGUANA_MAXPEERS; i++)
{ {
addr = &coin->peers.active[(i + r) % IGUANA_MAXPEERS]; addr = &coin->peers->active[(i + r) % IGUANA_MAXPEERS];
if ( addr->usock >= 0 && addr->msgcounts.verack > 0 ) if ( addr->usock >= 0 && addr->msgcounts.verack > 0 )
break; break;
} }
@ -438,7 +438,7 @@ int32_t iguana_send(struct iguana_info *coin,struct iguana_peer *addr,uint8_t *s
printf("sending too big! %d\n",len); printf("sending too big! %d\n",len);
while ( remains > 0 ) while ( remains > 0 )
{ {
if ( coin->peers.shuttingdown != 0 ) if ( coin->peers->shuttingdown != 0 )
return(-1); return(-1);
if ( (numsent= (int32_t)send(usock,serialized,remains,MSG_NOSIGNAL)) < 0 ) if ( (numsent= (int32_t)send(usock,serialized,remains,MSG_NOSIGNAL)) < 0 )
{ {
@ -556,12 +556,12 @@ void iguana_parsebuf(struct iguana_info *coin,struct iguana_peer *addr,struct ig
void _iguana_processmsg(struct iguana_info *coin,int32_t usock,struct iguana_peer *addr,uint8_t *_buf,int32_t maxlen) void _iguana_processmsg(struct iguana_info *coin,int32_t usock,struct iguana_peer *addr,uint8_t *_buf,int32_t maxlen)
{ {
int32_t len,recvlen; void *buf = _buf; struct iguana_msghdr H; int32_t len,recvlen; void *buf = _buf; struct iguana_msghdr H;
if ( coin->peers.shuttingdown != 0 || addr->dead != 0 ) if ( coin->peers->shuttingdown != 0 || addr->dead != 0 )
return; return;
memset(&H,0,sizeof(H)); memset(&H,0,sizeof(H));
if ( (recvlen= (int32_t)iguana_recv(addr->ipaddr,usock,(uint8_t *)&H,sizeof(H))) == sizeof(H) ) if ( (recvlen= (int32_t)iguana_recv(addr->ipaddr,usock,(uint8_t *)&H,sizeof(H))) == sizeof(H) )
{ {
if ( coin->peers.shuttingdown != 0 || addr->dead != 0 ) if ( coin->peers->shuttingdown != 0 || addr->dead != 0 )
return; return;
{ {
iguana_rwnum(0,H.serdatalen,sizeof(H.serdatalen),(uint32_t *)&len); iguana_rwnum(0,H.serdatalen,sizeof(H.serdatalen),(uint32_t *)&len);
@ -633,7 +633,7 @@ void iguana_startconnection(void *arg)
printf("iguana_startconnection nullptrs addr.%p coin.%p\n",addr,coin); printf("iguana_startconnection nullptrs addr.%p coin.%p\n",addr,coin);
return; return;
} }
addr->addrind = (int32_t)(((long)addr - (long)&coin->peers.active[0]) / sizeof(*addr)); addr->addrind = (int32_t)(((long)addr - (long)&coin->peers->active[0]) / sizeof(*addr));
if ( addr->usock >= 0 ) if ( addr->usock >= 0 )
{ {
printf("%s usock.%d skip connection\n",addr->ipaddr,addr->usock); printf("%s usock.%d skip connection\n",addr->ipaddr,addr->usock);
@ -657,10 +657,10 @@ void iguana_startconnection(void *arg)
port = coin->chain->portp2p; port = coin->chain->portp2p;
if ( addr->usock < 0 ) if ( addr->usock < 0 )
addr->usock = iguana_socket(0,addr->ipaddr,port); addr->usock = iguana_socket(0,addr->ipaddr,port);
if ( addr->usock < 0 || coin->peers.shuttingdown != 0 ) if ( addr->usock < 0 || coin->peers->shuttingdown != 0 )
{ {
strcpy(ipaddr,addr->ipaddr); strcpy(ipaddr,addr->ipaddr);
//printf("refused PEER KILLED. slot.%d for %s:%d usock.%d\n",addr->addrind,ipaddr,coin->chain->portp2p,addr->usock); printf("%s refused PEER KILLED. slot.%d for %s:%d usock.%d\n",coin->symbol,addr->addrind,ipaddr,coin->chain->portp2p,addr->usock);
iguana_iAkill(coin,addr,1); iguana_iAkill(coin,addr,1);
} }
else else
@ -672,17 +672,17 @@ void iguana_startconnection(void *arg)
addr->height = iguana_iAddrheight(coin,addr->ipbits); addr->height = iguana_iAddrheight(coin,addr->ipbits);
strcpy(addr->symbol,coin->symbol); strcpy(addr->symbol,coin->symbol);
strcpy(addr->coinstr,coin->name); strcpy(addr->coinstr,coin->name);
coin->peers.lastpeer = (uint32_t)time(NULL); coin->peers->lastpeer = (uint32_t)time(NULL);
for (i=n=0; i<coin->MAXPEERS; i++) for (i=n=0; i<coin->MAXPEERS; i++)
if ( coin->peers.active[i].usock > 0 ) if ( coin->peers->active[i].usock > 0 )
n++; n++;
iguana_iAconnected(coin,addr); iguana_iAconnected(coin,addr);
coin->peers.numconnected++; coin->peers->numconnected++;
//printf("%s.PEER CONNECTED.%d:%d of max.%d! %s:%d usock.%d\n",coin->symbol,coin->peers.numconnected,n,coin->MAXPEERS,addr->ipaddr,coin->chain->portp2p,addr->usock); printf("%s.PEER CONNECTED.%d:%d of max.%d! %s:%d usock.%d\n",coin->symbol,coin->peers->numconnected,n,coin->MAXPEERS,addr->ipaddr,coin->chain->portp2p,addr->usock);
if ( strcmp("127.0.0.1",addr->ipaddr) == 0 ) if ( strcmp("127.0.0.1",addr->ipaddr) == 0 )
coin->peers.localaddr = addr; coin->peers->localaddr = addr;
else if ( coin->peers.numranked == 0 ) else if ( coin->peers->numranked == 0 )
coin->peers.ranked[0] = addr; coin->peers->ranked[0] = addr;
#ifdef IGUANA_DEDICATED_THREADS #ifdef IGUANA_DEDICATED_THREADS
//iguana_launch("recv",iguana_dedicatedrecv,addr,IGUANA_RECVTHREAD); //iguana_launch("recv",iguana_dedicatedrecv,addr,IGUANA_RECVTHREAD);
iguana_dedicatedloop(SuperNET_MYINFO(0),coin,addr); iguana_dedicatedloop(SuperNET_MYINFO(0),coin,addr);
@ -693,9 +693,9 @@ void iguana_startconnection(void *arg)
void iguana_peerkill(struct iguana_info *coin) void iguana_peerkill(struct iguana_info *coin)
{ {
struct iguana_peer *addr; struct iguana_peer *addr;
if ( coin->peers.numranked > 0 && (addr= coin->peers.ranked[coin->peers.numranked-1]) != 0 ) if ( coin->peers->numranked > 0 && (addr= coin->peers->ranked[coin->peers->numranked-1]) != 0 )
{ {
printf("mark rank.%d as dead.(%s)\n",coin->peers.numranked,addr->ipaddr); printf("mark rank.%d as dead.(%s)\n",coin->peers->numranked,addr->ipaddr);
addr->dead = (uint32_t)time(NULL); addr->dead = (uint32_t)time(NULL);
} }
} }
@ -704,8 +704,8 @@ struct iguana_peer *iguana_peerslot(struct iguana_info *coin,uint64_t ipbits,int
{ {
int32_t i; struct iguana_peer *addr; char ipaddr[64]; int32_t i; struct iguana_peer *addr; char ipaddr[64];
for (i=0; i<IGUANA_MAXPEERS; i++) for (i=0; i<IGUANA_MAXPEERS; i++)
if ( ipbits == coin->peers.active[i].ipbits ) if ( ipbits == coin->peers->active[i].ipbits )
return(forceflag!=0 ? &coin->peers.active[i] : 0); return(forceflag!=0 ? &coin->peers->active[i] : 0);
expand_ipbits(ipaddr,ipbits); expand_ipbits(ipaddr,ipbits);
#ifdef IGUANA_DISABLEPEERS #ifdef IGUANA_DISABLEPEERS
if ( strcmp("127.0.0.1",ipaddr) != 0 ) if ( strcmp("127.0.0.1",ipaddr) != 0 )
@ -716,7 +716,7 @@ struct iguana_peer *iguana_peerslot(struct iguana_info *coin,uint64_t ipbits,int
{ {
if ( i < coin->MAXPEERS || forceflag != 0 ) if ( i < coin->MAXPEERS || forceflag != 0 )
{ {
addr = &coin->peers.active[i]; addr = &coin->peers->active[i];
addr->addrind = i; addr->addrind = i;
if ( addr->usock >= 0 || addr->pending != 0 || addr->ipbits == ipbits || strcmp(ipaddr,addr->ipaddr) == 0 ) if ( addr->usock >= 0 || addr->pending != 0 || addr->ipbits == ipbits || strcmp(ipaddr,addr->ipaddr) == 0 )
{ {
@ -786,9 +786,9 @@ uint32_t iguana_possible_peer(struct iguana_info *coin,char *ipaddr)
if ( strcmp(ipaddr,"0.0.0.0") == 0 || strcmp(ipaddr,"127.0.0.1") == 0 ) if ( strcmp(ipaddr,"0.0.0.0") == 0 || strcmp(ipaddr,"127.0.0.1") == 0 )
return(0); return(0);
for (i=n=0; i<coin->MAXPEERS; i++) for (i=n=0; i<coin->MAXPEERS; i++)
if ( strcmp(ipaddr,coin->peers.active[i].ipaddr) == 0 ) if ( strcmp(ipaddr,coin->peers->active[i].ipaddr) == 0 )
{ {
printf("%s possible peer.(%s) %x already there\n",coin->symbol,ipaddr,(uint32_t)coin->peers.active[i].ipbits); printf("%s possible peer.(%s) %x already there\n",coin->symbol,ipaddr,(uint32_t)coin->peers->active[i].ipbits);
return(0); return(0);
} }
//printf("Q possible.(%s)\n",ipaddr); //printf("Q possible.(%s)\n",ipaddr);
@ -809,16 +809,16 @@ uint32_t iguana_possible_peer(struct iguana_info *coin,char *ipaddr)
//printf("check possible peer.(%s)\n",ipaddr); //printf("check possible peer.(%s)\n",ipaddr);
for (i=n=0; i<coin->MAXPEERS; i++) for (i=n=0; i<coin->MAXPEERS; i++)
{ {
if ( strcmp(ipaddr,coin->peers.active[i].ipaddr) == 0 ) if ( strcmp(ipaddr,coin->peers->active[i].ipaddr) == 0 )
{ {
//printf("(%s) already active\n",ipaddr); //printf("(%s) already active\n",ipaddr);
free_queueitem(ipaddr); free_queueitem(ipaddr);
return((uint32_t)time(NULL)); return((uint32_t)time(NULL));
} }
else if ( coin->peers.active[i].ipaddr[0] != 0 ) else if ( coin->peers->active[i].ipaddr[0] != 0 )
n++; n++;
} }
if ( n >= coin->MAXPEERS-(coin->MAXPEERS>>3)-1 || coin->peers.numranked >= coin->MAXPEERS ) if ( n >= coin->MAXPEERS-(coin->MAXPEERS>>3)-1 || coin->peers->numranked >= coin->MAXPEERS )
return((uint32_t)time(NULL)); return((uint32_t)time(NULL));
if ( strncmp("0.0.0",ipaddr,5) != 0 && strcmp("0.0.255.255",ipaddr) != 0 && strcmp("1.0.0.0",ipaddr) != 0 ) if ( strncmp("0.0.0",ipaddr,5) != 0 && strcmp("0.0.255.255",ipaddr) != 0 && strcmp("1.0.0.0",ipaddr) != 0 )
{ {
@ -897,7 +897,7 @@ int32_t iguana_pollrecv(struct iguana_info *coin,struct iguana_peer *addr,uint8_
{ {
#ifndef IGUANA_DEDICATED_THREADS #ifndef IGUANA_DEDICATED_THREADS
strcpy(addr->symbol,coin->symbol); strcpy(addr->symbol,coin->symbol);
if ( addr != coin->peers.localaddr ) if ( addr != coin->peers->localaddr )
{ {
addr->startrecv = (uint32_t)time(NULL); addr->startrecv = (uint32_t)time(NULL);
iguana_launch("processmsg",iguana_processmsg,addr,IGUANA_RECVTHREAD); iguana_launch("processmsg",iguana_processmsg,addr,IGUANA_RECVTHREAD);
@ -1063,7 +1063,7 @@ void iguana_dedicatedloop(struct supernet_info *myinfo,struct iguana_info *coin,
static uint32_t lastping; static uint32_t lastping;
struct pollfd fds; struct iguana_bundlereq *req; uint8_t *buf; uint32_t ipbits; struct pollfd fds; struct iguana_bundlereq *req; uint8_t *buf; uint32_t ipbits;
int32_t bufsize,flag,run,timeout = coin->polltimeout == 0 ? 10 : coin->polltimeout; int32_t bufsize,flag,run,timeout = coin->polltimeout == 0 ? 10 : coin->polltimeout;
if ( iguana_peerslotinit(coin,addr,(int32_t)(((long)addr - (long)&coin->peers.active[0]) / sizeof(*addr)),calc_ipbits(addr->ipaddr)) < 0 ) if ( iguana_peerslotinit(coin,addr,(int32_t)(((long)addr - (long)&coin->peers->active[0]) / sizeof(*addr)),calc_ipbits(addr->ipaddr)) < 0 )
{ {
printf("error creating peer's files\n"); printf("error creating peer's files\n");
return; return;
@ -1104,7 +1104,7 @@ void iguana_dedicatedloop(struct supernet_info *myinfo,struct iguana_info *coin,
} }
//sleep(1+(rand()%5)); //sleep(1+(rand()%5));
run = 0; run = 0;
while ( addr->usock >= 0 && addr->dead == 0 && coin->peers.shuttingdown == 0 ) while ( addr->usock >= 0 && addr->dead == 0 && coin->peers->shuttingdown == 0 )
{ {
if ( 0 && (req= queue_dequeue(&coin->cacheQ,0)) != 0 ) if ( 0 && (req= queue_dequeue(&coin->cacheQ,0)) != 0 )
{ {
@ -1228,7 +1228,7 @@ void iguana_dedicatedloop(struct supernet_info *myinfo,struct iguana_info *coin,
} }
} }
#endif #endif
coin->peers.numconnected--; coin->peers->numconnected--;
} }
void iguana_dedicatedglue(void *arg) void iguana_dedicatedglue(void *arg)
@ -1253,7 +1253,7 @@ void iguana_peersloop(void *ptr)
memset(bufsizes,0,sizeof(bufsizes)); memset(bufsizes,0,sizeof(bufsizes));
while ( 1 ) while ( 1 )
{ {
while ( coin->peers.shuttingdown != 0 ) while ( coin->peers->shuttingdown != 0 )
{ {
printf("peers shuttingdown\n"); printf("peers shuttingdown\n");
sleep(3); sleep(3);
@ -1263,7 +1263,7 @@ void iguana_peersloop(void *ptr)
for (j=n=nonz=0; j<coin->MAXPEERS; j++) for (j=n=nonz=0; j<coin->MAXPEERS; j++)
{ {
i = (j + r) % coin->MAXPEERS; i = (j + r) % coin->MAXPEERS;
addr = &coin->peers.active[i]; addr = &coin->peers->active[i];
fds[i].fd = -1; fds[i].fd = -1;
if ( addr->usock >= 0 && addr->dead == 0 && addr->ready != 0 && (addr->startrecv+addr->startsend) != 0 ) if ( addr->usock >= 0 && addr->dead == 0 && addr->ready != 0 && (addr->startrecv+addr->startsend) != 0 )
{ {
@ -1277,7 +1277,7 @@ void iguana_peersloop(void *ptr)
for (j=0; j<coin->MAXPEERS; j++) for (j=0; j<coin->MAXPEERS; j++)
{ {
i = (j + r) % coin->MAXPEERS; i = (j + r) % coin->MAXPEERS;
addr = &coin->peers.active[i]; addr = &coin->peers->active[i];
if ( addr->usock < 0 || addr->dead != 0 || addr->ready == 0 ) if ( addr->usock < 0 || addr->dead != 0 || addr->ready == 0 )
continue; continue;
if ( addr->startrecv == 0 && (fds[i].revents & POLLIN) != 0 && iguana_numthreads(1 << IGUANA_RECVTHREAD) < IGUANA_MAXRECVTHREADS ) if ( addr->startrecv == 0 && (fds[i].revents & POLLIN) != 0 && iguana_numthreads(1 << IGUANA_RECVTHREAD) < IGUANA_MAXRECVTHREADS )

10
iguana/iguana_ramchain.c

@ -1059,7 +1059,7 @@ long iguana_ramchain_save(struct iguana_info *coin,RAMCHAIN_FUNC,uint32_t ipbits
#endif #endif
if ( (fp= fopen(fname,"wb")) == 0 ) if ( (fp= fopen(fname,"wb")) == 0 )
printf("iguana_ramchain_save: couldnt create.(%s) errno.%d\n",fname,errno); printf("iguana_ramchain_save: couldnt create.(%s) errno.%d\n",fname,errno);
else coin->peers.numfiles++; else coin->peers->numfiles++;
if ( fp != 0 ) if ( fp != 0 )
{ {
fpos = ftell(fp); fpos = ftell(fp);
@ -1839,7 +1839,7 @@ long iguana_ramchain_data(struct iguana_info *coin,struct iguana_peer *addr,stru
iguana_memreset(&addr->TXDATA); iguana_memreset(&addr->TXDATA);
for (i=0; i<txn_count; i++) for (i=0; i<txn_count; i++)
tree[i] = txarray[i].txid; tree[i] = txarray[i].txid;
merkle_root = iguana_merkle(coin,tree,txn_count); merkle_root = iguana_merkle(tree,txn_count);
if ( bits256_cmp(merkle_root,origtxdata->block.RO.merkle_root) != 0 ) if ( bits256_cmp(merkle_root,origtxdata->block.RO.merkle_root) != 0 )
{ {
char str[65],str2[65]; char str[65],str2[65];
@ -2331,9 +2331,9 @@ struct iguana_ramchain *iguana_bundleload(struct iguana_info *coin,struct iguana
// bp->hashes[i] = B[i].hash2; // bp->hashes[i] = B[i].hash2;
if ( (prev= block->hh.prev) != 0 ) if ( (prev= block->hh.prev) != 0 )
prev2 = prev->hh.prev; prev2 = prev->hh.prev;
if ( strcmp(coin->symbol,"BTCD") == 0 && bp->bundleheight > 20000 && prev != 0 && iguana_targetbits(coin,block,prev,prev2,1) != block->RO.bits ) if ( strcmp(coin->symbol,"BTCD") == 0 && bp->bundleheight > 20000 && prev != 0 && iguana_targetbits(coin,block,prev,prev2,1,coin->chain->targetspacing,coin->chain->targettimespan) != block->RO.bits )
{ {
printf("nbits target error %x != %x ht.%d\n",iguana_targetbits(coin,block,prev,prev2,1),block->RO.bits,block->height); printf("nbits target error %x != %x ht.%d\n",iguana_targetbits(coin,block,prev,prev2,1,coin->chain->targetspacing,coin->chain->targettimespan),block->RO.bits,block->height);
} //else printf(">>>>>>>>>> matched nbits %x ht.%d\n",block->RO.bits,block->height); } //else printf(">>>>>>>>>> matched nbits %x ht.%d\n",block->RO.bits,block->height);
if ( bp->bundleheight+i == coin->blocks.hwmchain.height+1 ) if ( bp->bundleheight+i == coin->blocks.hwmchain.height+1 )
{ {
@ -2625,7 +2625,7 @@ int32_t iguana_bundlesaveHT(struct iguana_info *coin,struct OS_memspace *mem,str
for (j=starti; j<=endi; j++) for (j=starti; j<=endi; j++)
{ {
if ( iguana_peerfname(coin,&hdrsi,GLOBAL_TMPDIR,fname,0,bp->hashes[j],zero,1,1) >= 0 ) if ( iguana_peerfname(coin,&hdrsi,GLOBAL_TMPDIR,fname,0,bp->hashes[j],zero,1,1) >= 0 )
coin->peers.numfiles -= OS_removefile(fname,0); coin->peers->numfiles -= OS_removefile(fname,0);
else printf("error removing.(%s)\n",fname); else printf("error removing.(%s)\n",fname);
} }
//sprintf(dirname,"%s/%s/%d",GLOBAL_TMPDIR,coin->symbol,bp->bundleheight), OS_portable_rmdir(dirname,1); //sprintf(dirname,"%s/%s/%d",GLOBAL_TMPDIR,coin->symbol,bp->bundleheight), OS_portable_rmdir(dirname,1);

16
iguana/iguana_realtime.c

@ -139,10 +139,10 @@ void iguana_rdatarestore(struct iguana_ramchain *dest,struct iguana_ramchaindata
void iguana_RThdrs(struct iguana_info *coin,struct iguana_bundle *bp,int32_t numaddrs) void iguana_RThdrs(struct iguana_info *coin,struct iguana_bundle *bp,int32_t numaddrs)
{ {
int32_t datalen,i; uint8_t serialized[512]; char str[65]; struct iguana_peer *addr; int32_t datalen,i; uint8_t serialized[512]; char str[65]; struct iguana_peer *addr;
for (i=0; i<numaddrs && i<coin->peers.numranked; i++) for (i=0; i<numaddrs && i<coin->peers->numranked; i++)
{ {
queue_enqueue("hdrsQ",&coin->hdrsQ,queueitem(bits256_str(str,bp->hashes[0])),1); queue_enqueue("hdrsQ",&coin->hdrsQ,queueitem(bits256_str(str,bp->hashes[0])),1);
if ( (addr= coin->peers.ranked[i]) != 0 && addr->usock >= 0 && addr->dead == 0 && (datalen= iguana_gethdrs(coin,serialized,coin->chain->gethdrsmsg,bits256_str(str,bp->hashes[0]))) > 0 ) if ( (addr= coin->peers->ranked[i]) != 0 && addr->usock >= 0 && addr->dead == 0 && (datalen= iguana_gethdrs(coin,serialized,coin->chain->gethdrsmsg,bits256_str(str,bp->hashes[0]))) > 0 )
{ {
iguana_send(coin,addr,serialized,datalen); iguana_send(coin,addr,serialized,datalen);
addr->pendhdrs++; addr->pendhdrs++;
@ -251,7 +251,7 @@ int32_t iguana_realtime_update(struct iguana_info *coin)
bp->issued[0] = 0; bp->issued[0] = 0;
hash2 = bp->hashes[0]; hash2 = bp->hashes[0];
//char str[65]; printf("RT[0] [%d:%d] %s %p\n",bp->hdrsi,0,bits256_str(str,hash2),block); //char str[65]; printf("RT[0] [%d:%d] %s %p\n",bp->hdrsi,0,bits256_str(str,hash2),block);
addr = coin->peers.ranked[rand() % 8]; addr = coin->peers->ranked[rand() % 8];
if ( addr != 0 && addr->usock >= 0 && addr->dead == 0 ) if ( addr != 0 && addr->usock >= 0 && addr->dead == 0 )
iguana_sendblockreqPT(coin,addr,bp,0,hash2,0); iguana_sendblockreqPT(coin,addr,bp,0,hash2,0);
} }
@ -261,13 +261,13 @@ int32_t iguana_realtime_update(struct iguana_info *coin)
if ( bits256_cmp(coin->RThash1,bp->hashes[1]) != 0 ) if ( bits256_cmp(coin->RThash1,bp->hashes[1]) != 0 )
coin->RThash1 = bp->hashes[1]; coin->RThash1 = bp->hashes[1];
bp->lastRT = (uint32_t)time(NULL); bp->lastRT = (uint32_t)time(NULL);
if ( coin->RTheight <= coin->longestchain-offset && coin->peers.numranked > 0 && time(NULL) > coin->RThdrstime+60 ) if ( coin->RTheight <= coin->longestchain-offset && coin->peers->numranked > 0 && time(NULL) > coin->RThdrstime+60 )
{ {
iguana_RThdrs(coin,bp,coin->peers.numranked); iguana_RThdrs(coin,bp,coin->peers->numranked);
coin->RThdrstime = bp->lastRT; coin->RThdrstime = bp->lastRT;
for (i=0; i<coin->peers.numranked; i++) for (i=0; i<coin->peers->numranked; i++)
{ {
if ( (addr= coin->peers.ranked[i]) != 0 && addr->usock >= 0 && addr->dead == 0 ) if ( (addr= coin->peers->ranked[i]) != 0 && addr->usock >= 0 && addr->dead == 0 )
{ {
//printf("%d ",addr->numRThashes); //printf("%d ",addr->numRThashes);
} }
@ -306,7 +306,7 @@ int32_t iguana_realtime_update(struct iguana_info *coin)
{ {
uint8_t serialized[512]; int32_t len; struct iguana_peer *addr; uint8_t serialized[512]; int32_t len; struct iguana_peer *addr;
//char str[65]; printf("RT error [%d:%d] %s %p\n",bp->hdrsi,i,bits256_str(str,hash2),block); //char str[65]; printf("RT error [%d:%d] %s %p\n",bp->hdrsi,i,bits256_str(str,hash2),block);
addr = coin->peers.ranked[rand() % 8]; addr = coin->peers->ranked[rand() % 8];
if ( addr != 0 && addr->usock >= 0 && addr->dead == 0 && (len= iguana_getdata(coin,serialized,MSG_BLOCK,&hash2,1)) > 0 ) if ( addr != 0 && addr->usock >= 0 && addr->dead == 0 && (len= iguana_getdata(coin,serialized,MSG_BLOCK,&hash2,1)) > 0 )
iguana_send(coin,addr,serialized,len); iguana_send(coin,addr,serialized,len);
coin->RTgenesis = 0; coin->RTgenesis = 0;

22
iguana/iguana_recv.c

@ -123,8 +123,8 @@ int32_t iguana_sendtxidreq(struct iguana_info *coin,struct iguana_peer *addr,bit
for (i=0; i<coin->MAXPEERS; i++) for (i=0; i<coin->MAXPEERS; i++)
{ {
j = (i + r) % coin->MAXPEERS; j = (i + r) % coin->MAXPEERS;
addr = &coin->peers.active[j]; addr = &coin->peers->active[j];
if ( coin->peers.active[j].usock >= 0 && coin->peers.active[j].dead == 0 ) if ( coin->peers->active[j].usock >= 0 && coin->peers->active[j].dead == 0 )
{ {
iguana_send(coin,addr,serialized,len); iguana_send(coin,addr,serialized,len);
break; break;
@ -147,8 +147,8 @@ int32_t iguana_txidreq(struct iguana_info *coin,char **retstrp,bits256 txid)
char str[65]; printf("txidreq.%s\n",bits256_str(str,txid)); char str[65]; printf("txidreq.%s\n",bits256_str(str,txid));
coin->reqtxids[coin->numreqtxids++] = txid; coin->reqtxids[coin->numreqtxids++] = txid;
for (i=0; i<coin->MAXPEERS; i++) for (i=0; i<coin->MAXPEERS; i++)
if ( coin->peers.active[i].usock >= 0 ) if ( coin->peers->active[i].usock >= 0 )
iguana_sendtxidreq(coin,coin->peers.ranked[i],txid); iguana_sendtxidreq(coin,coin->peers->ranked[i],txid);
return(0); return(0);
} }
@ -770,8 +770,8 @@ void iguana_checklongestchain(struct iguana_info *coin,struct iguana_bundle *bp,
coin->badlongestchain = coin->longestchain; coin->badlongestchain = coin->longestchain;
coin->longestchain = bp->bundleheight+num; coin->longestchain = bp->bundleheight+num;
coin->longestchain_strange = 0; coin->longestchain_strange = 0;
for (i=0; i<coin->peers.numranked; i++) for (i=0; i<coin->peers->numranked; i++)
if ( (addr= coin->peers.ranked[i]) != 0 && addr->height >= coin->badlongestchain ) if ( (addr= coin->peers->ranked[i]) != 0 && addr->height >= coin->badlongestchain )
{ {
printf("blacklist addr.(%s) height %d\n",addr->ipaddr,addr->height); printf("blacklist addr.(%s) height %d\n",addr->ipaddr,addr->height);
addr->dead = 1; addr->dead = 1;
@ -973,7 +973,7 @@ struct iguana_bundlereq *iguana_recvblockhashes(struct iguana_info *coin,struct
//block->blockhashes = blockhashes, req->hashes = 0; //block->blockhashes = blockhashes, req->hashes = 0;
//printf("set block->blockhashes[%d]\n",num); //printf("set block->blockhashes[%d]\n",num);
} }
/*if ( (addr= coin->peers.ranked[0]) != 0 ) /*if ( (addr= coin->peers->ranked[0]) != 0 )
{ {
if ( (len= iguana_getdata(coin,serialized,MSG_BLOCK,&blockhashes[1],1)) > 0 ) if ( (len= iguana_getdata(coin,serialized,MSG_BLOCK,&blockhashes[1],1)) > 0 )
{ {
@ -1439,11 +1439,11 @@ int32_t iguana_blockQ(char *argstr,struct iguana_info *coin,struct iguana_bundle
req->height = height; req->height = height;
req->bundlei = bundlei; req->bundlei = bundlei;
char str2[65]; char str2[65];
//printf("%s %s %s [%d:%d] %d %s %d numranked.%d qsize.%d\n",coin->symbol,argstr,str,bp!=0?bp->hdrsi:-1,bundlei,req->height,bits256_str(str2,hash2),coin->blocks.recvblocks,coin->peers.numranked,queue_size(Q)); //printf("%s %s %s [%d:%d] %d %s %d numranked.%d qsize.%d\n",coin->symbol,argstr,str,bp!=0?bp->hdrsi:-1,bundlei,req->height,bits256_str(str2,hash2),coin->blocks.recvblocks,coin->peers->numranked,queue_size(Q));
if ( (n= queue_size(Q)) > 100000 ) if ( (n= queue_size(Q)) > 100000 )
{ {
if ( 1 && n > 200000 ) if ( 1 && n > 200000 )
printf("%s %s %s [%d:%d] %d %s %d numranked.%d qsize.%d\n",coin->symbol,argstr,str,bp!=0?bp->hdrsi:-1,bundlei,req->height,bits256_str(str2,hash2),coin->blocks.recvblocks,coin->peers.numranked,queue_size(Q)); printf("%s %s %s [%d:%d] %d %s %d numranked.%d qsize.%d\n",coin->symbol,argstr,str,bp!=0?bp->hdrsi:-1,bundlei,req->height,bits256_str(str2,hash2),coin->blocks.recvblocks,coin->peers->numranked,queue_size(Q));
while ( (ptr= queue_dequeue(Q,0)) != 0 ) while ( (ptr= queue_dequeue(Q,0)) != 0 )
myfree(ptr,sizeof(*ptr)); myfree(ptr,sizeof(*ptr));
coin->backlog = n*10 + 1000000; coin->backlog = n*10 + 1000000;
@ -1527,9 +1527,9 @@ int32_t iguana_pollQsPT(struct iguana_info *coin,struct iguana_peer *addr)
if ( flag == 0 && req == 0 && addr->pendblocks < limit ) if ( flag == 0 && req == 0 && addr->pendblocks < limit )
{ {
priority = 0; priority = 0;
for (i=m=pend=0; i<coin->peers.numranked; i++) for (i=m=pend=0; i<coin->peers->numranked; i++)
{ {
if ( (ptr= coin->peers.ranked[i]) != 0 && ptr->msgcounts.verack > 0 ) if ( (ptr= coin->peers->ranked[i]) != 0 && ptr->msgcounts.verack > 0 )
pend += ptr->pendblocks, m++; pend += ptr->pendblocks, m++;
} }
if ( pend < coin->MAXPENDINGREQUESTS*m ) if ( pend < coin->MAXPENDINGREQUESTS*m )

14
iguana/iguana_sign.c

@ -344,7 +344,7 @@ int32_t iguana_rwmsgtx(struct iguana_info *coin,int32_t rwflag,cJSON *json,uint8
//printf("json.%p array.%p sigser.%p\n",json,array,sigser); //printf("json.%p array.%p sigser.%p\n",json,array,sigser);
} }
//printf("version.%d\n",msg->version); //printf("version.%d\n",msg->version);
if ( coin->chain->hastimestamp != 0 ) if ( coin->chain->txhastimestamp != 0 )
{ {
len += iguana_rwnum(rwflag,&serialized[len],sizeof(msg->timestamp),&msg->timestamp); len += iguana_rwnum(rwflag,&serialized[len],sizeof(msg->timestamp),&msg->timestamp);
//char str[65]; printf("version.%d timestamp.%08x %u %s\n",msg->version,msg->timestamp,msg->timestamp,utc_str(str,msg->timestamp)); //char str[65]; printf("version.%d timestamp.%08x %u %s\n",msg->version,msg->timestamp,msg->timestamp,utc_str(str,msg->timestamp));
@ -481,7 +481,7 @@ bits256 iguana_parsetxobj(struct supernet_info *myinfo,struct iguana_info *coin,
vpnstr[0] = 0; vpnstr[0] = 0;
if ( (msg->version= juint(txobj,"version")) == 0 ) if ( (msg->version= juint(txobj,"version")) == 0 )
msg->version = 1; msg->version = 1;
if ( coin->chain->hastimestamp != 0 ) if ( coin->chain->txhastimestamp != 0 )
{ {
if ( (msg->timestamp= juint(txobj,"timestamp")) == 0 ) if ( (msg->timestamp= juint(txobj,"timestamp")) == 0 )
msg->timestamp = (uint32_t)time(NULL); msg->timestamp = (uint32_t)time(NULL);
@ -806,7 +806,7 @@ int32_t bitcoin_txaddspend(struct iguana_info *coin,cJSON *txobj,char *destaddre
{ {
bitcoin_addr2rmd160(&addrtype,rmd160,destaddress); bitcoin_addr2rmd160(&addrtype,rmd160,destaddress);
scriptlen = bitcoin_standardspend(outputscript,0,rmd160); scriptlen = bitcoin_standardspend(outputscript,0,rmd160);
bitcoin_txoutput(coin,txobj,outputscript,scriptlen,satoshis); bitcoin_txoutput(txobj,outputscript,scriptlen,satoshis);
return(0); return(0);
} else return(-1); } else return(-1);
} }
@ -911,7 +911,7 @@ cJSON *bitcoin_txinput(struct iguana_info *coin,cJSON *txobj,bits256 txid,int32_
return(txobj); return(txobj);
} }
cJSON *bitcoin_txcreate(struct iguana_info *coin,int64_t locktime) cJSON *bitcoin_txcreate(int32_t txhastimestamp,int64_t locktime)
{ {
cJSON *json = cJSON_CreateObject(); cJSON *json = cJSON_CreateObject();
if ( locktime == 0 ) if ( locktime == 0 )
@ -924,14 +924,14 @@ cJSON *bitcoin_txcreate(struct iguana_info *coin,int64_t locktime)
jaddnum(json,"version",4); jaddnum(json,"version",4);
jadd64bits(json,"locktime",locktime); jadd64bits(json,"locktime",locktime);
} }
if ( coin->chain->hastimestamp != 0 ) if ( txhastimestamp != 0 )
jaddnum(json,"timestamp",time(NULL)); jaddnum(json,"timestamp",time(NULL));
jadd(json,"vin",cJSON_CreateArray()); jadd(json,"vin",cJSON_CreateArray());
jadd(json,"vout",cJSON_CreateArray()); jadd(json,"vout",cJSON_CreateArray());
return(json); return(json);
} }
cJSON *bitcoin_txoutput(struct iguana_info *coin,cJSON *txobj,uint8_t *paymentscript,int32_t len,uint64_t satoshis) cJSON *bitcoin_txoutput(cJSON *txobj,uint8_t *paymentscript,int32_t len,uint64_t satoshis)
{ {
char *hexstr; cJSON *item,*skey,*vouts = jduplicate(jobj(txobj,"vout")); char *hexstr; cJSON *item,*skey,*vouts = jduplicate(jobj(txobj,"vout"));
jdelete(txobj,"vout"); jdelete(txobj,"vout");
@ -1004,7 +1004,7 @@ P2SH_SPENDAPI(iguana,spendmsig,activecoin,vintxid,vinvout,destaddress,destamount
if ( M > N || N > 3 ) if ( M > N || N > 3 )
return(clonestr("{\"error\":\"illegal M or N\"}")); return(clonestr("{\"error\":\"illegal M or N\"}"));
memset(&V,0,sizeof(V)); memset(&V,0,sizeof(V));
txobj = bitcoin_txcreate(active,0); txobj = bitcoin_txcreate(active->chain->txhastimestamp,0);
if ( destaddress[0] != 0 && destamount > 0. ) if ( destaddress[0] != 0 && destamount > 0. )
bitcoin_txaddspend(active,txobj,destaddress,destamount * SATOSHIDEN); bitcoin_txaddspend(active,txobj,destaddress,destamount * SATOSHIDEN);
if ( destaddress2[0] != 0 && destamount2 > 0. ) if ( destaddress2[0] != 0 && destamount2 > 0. )

2
iguana/iguana_spendvectors.c

@ -882,7 +882,7 @@ int32_t iguana_balanceflush(struct iguana_info *coin,int32_t refhdrsi)
coin->active = 0; coin->active = 0;
coin->started = 0; coin->started = 0;
for (i=0; i<IGUANA_MAXPEERS; i++) for (i=0; i<IGUANA_MAXPEERS; i++)
coin->peers.active[i].dead = (uint32_t)time(NULL); coin->peers->active[i].dead = (uint32_t)time(NULL);
#ifdef __linux__ #ifdef __linux__
char cmd[1024]; char cmd[1024];
sprintf(cmd,"mksquashfs %s/%s %s.%d -comp xz",GLOBAL_DBDIR,coin->symbol,coin->symbol,coin->balanceswritten); sprintf(cmd,"mksquashfs %s/%s %s.%d -comp xz",GLOBAL_DBDIR,coin->symbol,coin->symbol,coin->balanceswritten);

11
iguana/iguana_stake.c

@ -69,12 +69,15 @@ uint32_t iguana_minstake(struct iguana_info *coin,int32_t height,uint32_t nBits,
return(iguana_maxbits(iguana_targetval(coin,height,1),nBits,nTime)); return(iguana_maxbits(iguana_targetval(coin,height,1),nBits,nTime));
} }
uint32_t iguana_targetbits(struct iguana_info *coin,struct iguana_block *hwmchain,struct iguana_block *prev,struct iguana_block *prev2,int32_t PoSflag) uint32_t iguana_targetbits(struct iguana_info *coin,struct iguana_block *hwmchain,struct iguana_block *prev,struct iguana_block *prev2,int32_t PoSflag,int32_t targetspacing,int32_t targettimespan)
{ {
// targetspacing NTARGETSPACING, mspacing NINTERVAL_MSPACING, pspacing NINTERVAL_PSPACING
bits256 mpz_muldivcmp(bits256 oldval,int32_t mulval,int32_t divval,bits256 cmpval); bits256 mpz_muldivcmp(bits256 oldval,int32_t mulval,int32_t divval,bits256 cmpval);
bits256 targetval; int32_t gap; bits256 targetval; int32_t gap,mspacing,pspacing;
if ( hwmchain->height <= 2 ) if ( hwmchain->height <= 2 )
return(hwmchain->RO.bits); return(hwmchain->RO.bits);
mspacing = (((targettimespan / targetspacing) - 1) * targetspacing);
pspacing = (((targettimespan / targetspacing) + 1) * targetspacing);
targetval = iguana_targetval(coin,hwmchain->height,PoSflag); targetval = iguana_targetval(coin,hwmchain->height,PoSflag);
if ( prev != 0 ) if ( prev != 0 )
{ {
@ -83,10 +86,10 @@ uint32_t iguana_targetbits(struct iguana_info *coin,struct iguana_block *hwmchai
//if ( prev->RO.timestamp != 0 && prev2->RO.timestamp != 0 ) skip check for compatiblity //if ( prev->RO.timestamp != 0 && prev2->RO.timestamp != 0 ) skip check for compatiblity
{ {
if ( (gap= prev->RO.timestamp - prev2->RO.timestamp) < 0 ) if ( (gap= prev->RO.timestamp - prev2->RO.timestamp) < 0 )
gap = NTARGETSPACING; gap = targetspacing;
// ppcoin: target change every block, retarget with exponential moving toward target spacing // ppcoin: target change every block, retarget with exponential moving toward target spacing
//printf("MSPACING.%d gap.%d\n",NINTERVAL_MSPACING,gap); //printf("MSPACING.%d gap.%d\n",NINTERVAL_MSPACING,gap);
targetval = mpz_muldivcmp(bits256_from_compact(prev->RO.bits),NINTERVAL_MSPACING + (gap << 1),NINTERVAL_PSPACING,targetval); targetval = mpz_muldivcmp(bits256_from_compact(prev->RO.bits),mspacing + (gap << 1),pspacing,targetval);
} }
} }
} }

8
iguana/iguana_tx.c

@ -88,7 +88,7 @@ int32_t iguana_vinset(struct iguana_info *coin,uint8_t *scriptspace,int32_t heig
if ( s->scriptpos != 0 && s->scriptlen > 0 ) if ( s->scriptpos != 0 && s->scriptlen > 0 )
{ {
iguana_vinsfname(coin,bp->ramchain.from_ro,fname,s->fileid); iguana_vinsfname(coin,bp->ramchain.from_ro,fname,s->fileid);
if ( (scriptlen= iguana_scriptdata(coin,scriptspace,coin->peers.vinptrs[s->fileid],fname,s->scriptpos,s->scriptlen)) != s->scriptlen ) if ( (scriptlen= iguana_scriptdata(coin,scriptspace,coin->peers->vinptrs[s->fileid],fname,s->scriptpos,s->scriptlen)) != s->scriptlen )
printf("err.%d getting %d bytes from fileid.%llu[%d] %s for s%d\n",err,s->scriptlen,(long long)s->scriptpos,s->fileid,fname,spendind); printf("err.%d getting %d bytes from fileid.%llu[%d] %s for s%d\n",err,s->scriptlen,(long long)s->scriptpos,s->fileid,fname,spendind);
} }
vin->scriptlen = s->scriptlen; vin->scriptlen = s->scriptlen;
@ -107,7 +107,7 @@ int32_t iguana_voutscript(struct iguana_info *coin,struct iguana_bundle *bp,uint
if ( u->scriptpos > 0 && u->scriptlen > 0 ) if ( u->scriptpos > 0 && u->scriptlen > 0 )
{ {
iguana_voutsfname(coin,bp->ramchain.from_ro,fname,u->fileid); iguana_voutsfname(coin,bp->ramchain.from_ro,fname,u->fileid);
if ( (scriptlen= iguana_scriptdata(coin,scriptspace,coin->peers.voutptrs[u->fileid],fname,u->scriptpos,u->scriptlen)) != u->scriptlen ) if ( (scriptlen= iguana_scriptdata(coin,scriptspace,coin->peers->voutptrs[u->fileid],fname,u->scriptpos,u->scriptlen)) != u->scriptlen )
printf("%d bytes from fileid.%d[%d] %s for type.%d\n",u->scriptlen,u->fileid,u->scriptpos,fname,u->type); printf("%d bytes from fileid.%d[%d] %s for type.%d\n",u->scriptlen,u->fileid,u->scriptpos,fname,u->type);
} }
else else
@ -174,7 +174,7 @@ int32_t iguana_ramtxbytes(struct iguana_info *coin,uint8_t *serialized,int32_t m
int32_t i,rwflag=1,len = 0; char asmstr[512],txidstr[65]; int32_t i,rwflag=1,len = 0; char asmstr[512],txidstr[65];
uint32_t numvins,numvouts; struct iguana_msgvin vin; struct iguana_msgvout vout; uint8_t space[IGUANA_MAXSCRIPTSIZE]; uint32_t numvins,numvouts; struct iguana_msgvin vin; struct iguana_msgvout vout; uint8_t space[IGUANA_MAXSCRIPTSIZE];
len += iguana_rwnum(rwflag,&serialized[len],sizeof(tx->version),&tx->version); len += iguana_rwnum(rwflag,&serialized[len],sizeof(tx->version),&tx->version);
if ( coin->chain->hastimestamp != 0 ) if ( coin->chain->txhastimestamp != 0 )
len += iguana_rwnum(rwflag,&serialized[len],sizeof(tx->timestamp),&tx->timestamp); len += iguana_rwnum(rwflag,&serialized[len],sizeof(tx->timestamp),&tx->timestamp);
numvins = tx->numvins, numvouts = tx->numvouts; numvins = tx->numvins, numvouts = tx->numvouts;
len += iguana_rwvarint32(rwflag,&serialized[len],&numvins); len += iguana_rwvarint32(rwflag,&serialized[len],&numvins);
@ -276,7 +276,7 @@ int32_t iguana_peerblockrequest(struct iguana_info *coin,uint8_t *blockspace,int
} }
if ( i == block->RO.txn_count ) if ( i == block->RO.txn_count )
{ {
merkle_root = iguana_merkle(coin,tree,block->RO.txn_count); merkle_root = iguana_merkle(tree,block->RO.txn_count);
if ( bits256_cmp(merkle_root,block->RO.merkle_root) == 0 ) if ( bits256_cmp(merkle_root,block->RO.merkle_root) == 0 )
{ {
if ( addr != 0 ) if ( addr != 0 )

2
iguana/iguana_txidfind.c

@ -649,7 +649,7 @@ struct iguana_monitorinfo *iguana_txidmonitor(struct iguana_info *coin,bits256 t
double iguana_txidstatus(struct iguana_info *coin,bits256 txid) double iguana_txidstatus(struct iguana_info *coin,bits256 txid)
{ {
int32_t height,firstvout,numranked; struct iguana_monitorinfo *ptr; char str[65]; int32_t height,firstvout,numranked; struct iguana_monitorinfo *ptr; char str[65];
if ( coin != 0 && (numranked= coin->peers.numranked) > 0 ) if ( coin != 0 && (numranked= coin->peers->numranked) > 0 )
{ {
if ( (firstvout= iguana_unspentindfind(coin,0,0,0,0,&height,txid,0,coin->bundlescount-1)) != 0 ) if ( (firstvout= iguana_unspentindfind(coin,0,0,0,0,&height,txid,0,coin->bundlescount-1)) != 0 )
{ {

2
iguana/iguana_wallet.c

@ -955,7 +955,7 @@ ZERO_ARGS(bitcoinrpc,getinfo)
jaddnum(retjson,"blocks",coin->blocks.hwmchain.height); jaddnum(retjson,"blocks",coin->blocks.hwmchain.height);
jaddnum(retjson,"longestchain",coin->longestchain); jaddnum(retjson,"longestchain",coin->longestchain);
jaddnum(retjson,"port",coin->chain->portp2p); jaddnum(retjson,"port",coin->chain->portp2p);
jaddnum(retjson,"connections",coin->peers.numranked); jaddnum(retjson,"connections",coin->peers->numranked);
jaddnum(retjson,"difficulty",coin->blocks.hwmchain.PoW); jaddnum(retjson,"difficulty",coin->blocks.hwmchain.PoW);
jaddstr(retjson,"status",coin->statusstr); jaddstr(retjson,"status",coin->statusstr);
jaddstr(retjson,"coin",coin->symbol); jaddstr(retjson,"coin",coin->symbol);

12
iguana/main.c

@ -59,7 +59,7 @@ char *Iguana_validcommands[] =
}; };
int32_t Showmode,Autofold,PANGEA_MAXTHREADS = 1; int32_t Showmode,Autofold,PANGEA_MAXTHREADS = 1;
struct category_info *Categories; struct private_chain *Categories;
struct iguana_info *Coins[IGUANA_MAXCOINS]; struct iguana_info *Coins[IGUANA_MAXCOINS];
char Userhome[512]; char Userhome[512];
int32_t USE_JAY,FIRST_EXTERNAL,IGUANA_disableNXT,Debuglevel,IGUANA_BIGENDIAN; int32_t USE_JAY,FIRST_EXTERNAL,IGUANA_disableNXT,Debuglevel,IGUANA_BIGENDIAN;
@ -359,10 +359,10 @@ void iguana_exit()
{ {
switch ( iter ) switch ( iter )
{ {
case 1: Coins[i]->peers.active[j].dead = (uint32_t)time(NULL); break; case 1: Coins[i]->peers->active[j].dead = (uint32_t)time(NULL); break;
case 2: case 2:
if ( Coins[i]->peers.active[j].usock >= 0 ) if ( Coins[i]->peers->active[j].usock >= 0 )
closesocket(Coins[i]->peers.active[j].usock); closesocket(Coins[i]->peers->active[j].usock);
break; break;
} }
} }
@ -444,7 +444,7 @@ void mainloop(struct supernet_info *myinfo)
if ( coin->active != 0 && coin->started != 0 ) if ( coin->active != 0 && coin->started != 0 )
{ {
isRT *= coin->isRT; isRT *= coin->isRT;
numpeers += coin->peers.numranked; numpeers += coin->peers->numranked;
if ( time(NULL) > coin->startutc+10 && coin->spendvectorsaved == 0 && coin->blocks.hwmchain.height/coin->chain->bundlesize >= (coin->longestchain-coin->minconfirms)/coin->chain->bundlesize ) if ( time(NULL) > coin->startutc+10 && coin->spendvectorsaved == 0 && coin->blocks.hwmchain.height/coin->chain->bundlesize >= (coin->longestchain-coin->minconfirms)/coin->chain->bundlesize )
{ {
n = coin->bundlescount-1; n = coin->bundlescount-1;
@ -1164,7 +1164,7 @@ void iguana_appletests(struct supernet_info *myinfo)
//printf("shash -> %s sha256x2 %s\n",bits256_str(str,shash),bits256_str(str2,hash2)); //printf("shash -> %s sha256x2 %s\n",bits256_str(str,shash),bits256_str(str2,hash2));
getchar(); getchar();
} }
if ( 1 ) if ( 0 )
{ {
/*int32_t i; ;bits256 hash2; uint8_t pubkey[33]; /*int32_t i; ;bits256 hash2; uint8_t pubkey[33];
double startmillis = OS_milliseconds(); double startmillis = OS_milliseconds();

20
iguana/pangea_api.c

@ -184,7 +184,7 @@ struct table_info *pangea_tablealloc(struct table_info *tp,int32_t N)
struct table_info *pangea_table(struct supernet_info *myinfo,bits256 tablehash,int32_t N) struct table_info *pangea_table(struct supernet_info *myinfo,bits256 tablehash,int32_t N)
{ {
struct table_info *tp; char str[65]; struct table_info *tp; char str[65];
if ( (tp= category_info(myinfo->pangea_category,tablehash)) == 0 && N > 0 ) if ( (tp= private_chain(myinfo->pangea_category,tablehash)) == 0 && N > 0 )
{ {
tp = pangea_tablealloc(0,N); tp = pangea_tablealloc(0,N);
memset(tp,0,sizeof(*tp)); memset(tp,0,sizeof(*tp));
@ -196,8 +196,8 @@ struct table_info *pangea_table(struct supernet_info *myinfo,bits256 tablehash,i
} }
if ( tp != 0 ) if ( tp != 0 )
{ {
category_subscribe(SuperNET_MYINFO(0),myinfo->pangea_category,tablehash,0,0); category_subscribe(SuperNET_MYINFO(0),myinfo->pangea_category,tablehash);
if ( category_infoset(myinfo->pangea_category,tablehash,tp) == 0 ) if ( private_chainset(myinfo->pangea_category,tablehash,tp) == 0 )
printf("error: couldnt set table.(%s)\n",bits256_str(str,tablehash)), tp = 0; printf("error: couldnt set table.(%s)\n",bits256_str(str,tablehash)), tp = 0;
//else tp->G.allocsize = allocsize; //else tp->G.allocsize = allocsize;
} }
@ -220,8 +220,8 @@ struct player_info *pangea_playerfind(struct supernet_info *myinfo,struct table_
char *pangea_jsondatacmd(struct supernet_info *myinfo,bits256 tablehash,struct pangea_msghdr *pm,cJSON *json,char *cmdstr,char *ipaddr) char *pangea_jsondatacmd(struct supernet_info *myinfo,bits256 tablehash,struct pangea_msghdr *pm,cJSON *json,char *cmdstr,char *ipaddr)
{ {
cJSON *argjson; char *reqstr,hexstr[8192]; uint64_t nxt64bits; struct table_info *tp; int32_t i,datalen; cJSON *argjson; char *reqstr,hexstr[8192]; uint64_t nxt64bits; struct table_info *tp; int32_t i,datalen;
category_subscribe(myinfo,myinfo->pangea_category,GENESIS_PUBKEY,0,0); category_subscribe(myinfo,myinfo->pangea_category,GENESIS_PUBKEY);
category_subscribe(myinfo,myinfo->pangea_category,tablehash,0,0); category_subscribe(myinfo,myinfo->pangea_category,tablehash);
argjson = json != 0 ? jduplicate(json) : cJSON_CreateObject(); argjson = json != 0 ? jduplicate(json) : cJSON_CreateObject();
jaddstr(argjson,"cmd",cmdstr); jaddstr(argjson,"cmd",cmdstr);
if ( myinfo->ipaddr[0] == 0 || strncmp(myinfo->ipaddr,"127.0.0.1",strlen("127.0.0.1")) == 0 ) if ( myinfo->ipaddr[0] == 0 || strncmp(myinfo->ipaddr,"127.0.0.1",strlen("127.0.0.1")) == 0 )
@ -451,7 +451,7 @@ void pangea_addfunds(PANGEA_HANDARGS)
printf("got remote addfunds\n"); printf("got remote addfunds\n");
} }
char *pangea_hexmsg(struct supernet_info *myinfo,struct category_info *cat,void *data,int32_t len,char *remoteaddr) char *pangea_hexmsg(struct supernet_info *myinfo,struct private_chain *cat,void *data,int32_t len,char *remoteaddr)
{ {
static struct { char *cmdstr; void (*func)(PANGEA_HANDARGS); uint64_t cmdbits; } tablecmds[] = static struct { char *cmdstr; void (*func)(PANGEA_HANDARGS); uint64_t cmdbits; } tablecmds[] =
{ {
@ -511,7 +511,7 @@ char *pangea_hexmsg(struct supernet_info *myinfo,struct category_info *cat,void
allocsize = pangea_allocsize(tp,9,0); allocsize = pangea_allocsize(tp,9,0);
if ( tp->G.allocsize < allocsize ) if ( tp->G.allocsize < allocsize )
tp = pangea_tablealloc(tp,9); tp = pangea_tablealloc(tp,9);
category_infoset(tp->G.gamehash,tp->G.tablehash,tp); private_chainset(tp->G.gamehash,tp->G.tablehash,tp);
if ( strcmp(tablecmds[i].cmdstr,"newhand") == 0 ) if ( strcmp(tablecmds[i].cmdstr,"newhand") == 0 )
{ {
tp->G.numactive = pm->turni; tp->G.numactive = pm->turni;
@ -538,7 +538,7 @@ char *pangea_hexmsg(struct supernet_info *myinfo,struct category_info *cat,void
void pangea_update(struct supernet_info *myinfo) void pangea_update(struct supernet_info *myinfo)
{ {
struct pangea_msghdr *pm; struct category_msg *m; char remoteaddr[64],*str; struct category_info *cat = 0; struct pangea_msghdr *pm; struct category_msg *m; char remoteaddr[64],*str; struct private_chain *cat = 0;
while ( (m= category_gethexmsg(myinfo,&cat,myinfo->pangea_category,GENESIS_PUBKEY)) != 0 ) while ( (m= category_gethexmsg(myinfo,&cat,myinfo->pangea_category,GENESIS_PUBKEY)) != 0 )
{ {
pm = (struct pangea_msghdr *)m->msg; pm = (struct pangea_msghdr *)m->msg;
@ -808,7 +808,7 @@ ZERO_ARGS(pangea,lobby)
//cJSON *retjson,*argjson; char *retstr,*result; uint8_t *buf; int32_t flag,len; struct pangea_msghdr *pm; //cJSON *retjson,*argjson; char *retstr,*result; uint8_t *buf; int32_t flag,len; struct pangea_msghdr *pm;
if ( remoteaddr != 0 ) if ( remoteaddr != 0 )
return(clonestr("{\"error\":\"no remote\"}")); return(clonestr("{\"error\":\"no remote\"}"));
category_subscribe(myinfo,myinfo->pangea_category,GENESIS_PUBKEY,0,0); category_subscribe(myinfo,myinfo->pangea_category,GENESIS_PUBKEY);
pangea_update(myinfo); pangea_update(myinfo);
return(jprint(pangea_lobbyjson(myinfo),1)); return(jprint(pangea_lobbyjson(myinfo),1));
} }
@ -865,7 +865,7 @@ HASH_ARG(pangea,start,tablehash)
if ( tp->G.allocsize < allocsize ) if ( tp->G.allocsize < allocsize )
{ {
tp = pangea_tablealloc(tp,9); tp = pangea_tablealloc(tp,9);
category_infoset(tp->G.gamehash,tp->G.tablehash,tp); private_chainset(tp->G.gamehash,tp->G.tablehash,tp);
} }
if ( tp->G.creatorbits == myinfo->myaddr.nxt64bits ) if ( tp->G.creatorbits == myinfo->myaddr.nxt64bits )
pangea_newdeck(myinfo,tp); pangea_newdeck(myinfo,tp);

9
iguana/pangea_hand.c

@ -418,14 +418,15 @@ int32_t pangea_queueprocess(struct supernet_info *myinfo,struct table_info *tp)
void pangea_queues(struct supernet_info *myinfo) void pangea_queues(struct supernet_info *myinfo)
{ {
struct category_info *cat,*sub,*tmp; struct table_info *tp; struct private_chain *cat,*subchain,*tmp; //struct table_info *tp;
pangea_update(myinfo); pangea_update(myinfo);
if ( (cat= category_find(calc_categoryhashes(0,"pangea",0),GENESIS_PUBKEY)) != 0 ) if ( (cat= category_find(calc_categoryhashes(0,"pangea",0),GENESIS_PUBKEY)) != 0 )
{ {
HASH_ITER(hh,cat->sub,sub,tmp) HASH_ITER(hh,cat->subchains,subchain,tmp)
{ {
if ( (tp= sub->info) != 0 ) printf("undeprecate\n");
pangea_queueprocess(myinfo,tp); //if ( (tp= sub->info) != 0 )
// pangea_queueprocess(myinfo,tp);
} }
} }
} }

9
iguana/pangea_json.c

@ -107,15 +107,16 @@ int32_t pangea_opentable(struct game_info *gp)
cJSON *pangea_lobbyjson(struct supernet_info *myinfo) cJSON *pangea_lobbyjson(struct supernet_info *myinfo)
{ {
struct category_info *cat,*sub,*tmp; struct table_info *tp; cJSON *array,*retjson; struct private_chain *cat,*subchain,*tmp; cJSON *array,*retjson; //struct table_info *tp;
retjson = cJSON_CreateObject(); retjson = cJSON_CreateObject();
array = cJSON_CreateArray(); array = cJSON_CreateArray();
if ( (cat= category_find(calc_categoryhashes(0,"pangea",0),GENESIS_PUBKEY)) != 0 ) if ( (cat= category_find(calc_categoryhashes(0,"pangea",0),GENESIS_PUBKEY)) != 0 )
{ {
HASH_ITER(hh,cat->sub,sub,tmp) HASH_ITER(hh,cat->subchains,subchain,tmp)
{ {
if ( (tp= sub->info) != 0 && pangea_opentable(&tp->G) > 0 ) printf("undeprecate\n");
jaddi(array,pangea_tablestatus(myinfo,tp)); //if ( (tp= sub->info) != 0 && pangea_opentable(&tp->G) > 0 )
// jaddi(array,pangea_tablestatus(myinfo,tp));
} }
} }
jadd(retjson,"tables",array); jadd(retjson,"tables",array);

2
iguana/tests/get

@ -1 +1 @@
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"basilisk\",\"method\":\"getfield\",\"vals\":{\"category\":\"test\"}}" curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"basilisk\",\"method\":\"get\",\"vals\":{\"chain\":\"test\"}}"

2
iguana/tests/set

@ -1 +1 @@
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"basilisk\",\"method\":\"setfield\",\"vals\":{\"setfield\":\"setthis\",\"category\":\"test\"},\"hexstr\":\"beefdead\"}" curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"basilisk\",\"method\":\"set\",\"vals\":{\"key\":\"testkey\",\"chain\":\"test\"},\"hexstr\":\"beefdead\"}"

Loading…
Cancel
Save