diff --git a/iguana/iguana_blocks.c b/iguana/iguana_blocks.c index 35442bf7b..fa6374d0f 100755 --- a/iguana/iguana_blocks.c +++ b/iguana/iguana_blocks.c @@ -17,7 +17,7 @@ #define iguana_blockfind(str,coin,hash2) iguana_blockhashset(str,coin,-1,hash2,0) -void iguana_blockconv(uint8_t zcash,uint8_t auxpow,struct iguana_zblock *zdest,struct iguana_msgzblock *zmsg,bits256 hash2,int32_t height) //uint32_t numtxids,uint32_t numunspents,uint32_t numspends,double PoW) +int32_t iguana_blockconv(uint8_t zcash,uint8_t auxpow,struct iguana_zblock *zdest,struct iguana_msgzblock *zmsg,bits256 hash2,int32_t height) //uint32_t numtxids,uint32_t numunspents,uint32_t numspends,double PoW) { int32_t i; struct iguana_block *dest = (void *)zdest; struct iguana_msgblock *msg = (void *)zmsg; if ( zcash == 0 ) @@ -32,6 +32,7 @@ void iguana_blockconv(uint8_t zcash,uint8_t auxpow,struct iguana_zblock *zdest,s dest->height = height; dest->RO.hash2 = hash2; dest->RO.nonce = msg->H.nonce; + return(msg->txn_count); } else { @@ -46,6 +47,7 @@ void iguana_blockconv(uint8_t zcash,uint8_t auxpow,struct iguana_zblock *zdest,s printf("unexpected varint size for zmsg.zH.numelements <- %d\n",zdest->zRO.numelements); for (i=0; izRO.solution[i] = zmsg->zH.solution[i]; + return(zmsg->txn_count); } } diff --git a/iguana/iguana_init.c b/iguana/iguana_init.c index 7a7919b89..5e98a8f34 100755 --- a/iguana/iguana_init.c +++ b/iguana/iguana_init.c @@ -108,7 +108,7 @@ bits256 iguana_genesis(struct supernet_info *myinfo,struct iguana_info *coin,str decode_hex(buf,(int32_t)strlen(chain->genesis_hex)/2,(char *)chain->genesis_hex); hash2 = iguana_calcblockhash(coin->symbol,coin->chain->hashalgo,buf,sizeof(struct iguana_msgblockhdr)); auxback = coin->chain->auxpow, coin->chain->auxpow = 0; - iguana_rwblock(myinfo,coin->symbol,coin->chain->zcash,coin->chain->auxpow,coin->chain->hashalgo,0,&hash2,buf,&zmsg,sizeof(buf)); + iguana_rwblock(myinfo,coin->symbol,coin->chain->zcash,coin->chain->auxpow,coin->chain->hashalgo,0,&hash2,buf,(void *)&zmsg,sizeof(buf)); coin->chain->auxpow = auxback; if ( coin->virtualchain == 0 && coin->MAXPEERS > 1 ) { @@ -123,7 +123,7 @@ bits256 iguana_genesis(struct supernet_info *myinfo,struct iguana_info *coin,str } else memcpy(hash2.bytes,chain->genesis_hashdata,sizeof(hash2)); bits256_str(str,hash2); printf("genesis.(%s) zcash.%d len.%d hash.%s\n",chain->genesis_hex,coin->chain->zcash,(int32_t)sizeof(zmsg.zH),str); - iguana_blockconv(coin->chain->zcash,coin->chain->auxpow,block,&zmsg,hash2,0); + iguana_blockconv(coin->chain->zcash,coin->chain->auxpow,(void *)block,&zmsg,hash2,0); block->RO.txn_count = 1; block->RO.numvouts = 1; if ( coin->chain->zcash != 0 ) @@ -543,7 +543,7 @@ struct iguana_info *iguana_coinstart(struct iguana_info *coin,int32_t initialhei } } } - if ( coin->FULLNODE != 0 && coin->rpcloop == 0 ) + if ( coin->rpcloop == 0 ) { myinfo->argport = coin->chain->rpcport; coin->rpcloop = malloc(sizeof(pthread_t)); diff --git a/iguana/iguana_msg.c b/iguana/iguana_msg.c index 469e37517..d53856a62 100755 --- a/iguana/iguana_msg.c +++ b/iguana/iguana_msg.c @@ -727,19 +727,31 @@ int32_t iguana_rwtx(struct supernet_info *myinfo,uint8_t zcash,int32_t rwflag,st char *iguana_txscan(struct supernet_info *myinfo,struct iguana_info *coin,cJSON *json,uint8_t *data,int32_t recvlen,bits256 txid) { - struct iguana_msgtx tx; bits256 hash2; struct iguana_block *block; struct iguana_msgblock msg; - int32_t i,n,len,extralen = 65356; char *txbytes,vpnstr[64]; uint8_t *extraspace,blockspace[sizeof(*block)+sizeof(struct iguana_zblock)]; + struct iguana_msgtx tx; bits256 hash2; struct iguana_zblock *zblock; struct iguana_block *block; struct iguana_msgzblock zmsg; struct iguana_msgblock msg; + int32_t i,n,len,txn_count,extralen = 65356; char *txbytes,vpnstr[64]; uint8_t *extraspace,blockspace[sizeof(*block)+sizeof(struct iguana_zblock)]; + zblock = (void *)blockspace; block = (void *)blockspace; + memset(&zmsg,0,sizeof(zmsg)); memset(&msg,0,sizeof(msg)); vpnstr[0] = 0; extraspace = calloc(1,extralen); - len = iguana_rwblock(myinfo,coin->symbol,coin->chain->zcash,coin->chain->auxpow,coin->chain->hashalgo,0,&hash2,data,&msg,recvlen); - iguana_blockconv(coin->chain->zcash,coin->chain->auxpow,block,&msg,hash2,-1); - for (i=0; ichain->zcash == 0 ) + { + len = iguana_rwblock(myinfo,coin->symbol,coin->chain->zcash,coin->chain->auxpow,coin->chain->hashalgo,0,&hash2,data,&msg,recvlen); + iguana_blockconv(coin->chain->zcash,coin->chain->auxpow,(void *)block,(void *)&msg,hash2,-1); + txn_count = msg.txn_count; + } + else + { + len = iguana_rwblock(myinfo,coin->symbol,coin->chain->zcash,coin->chain->auxpow,coin->chain->hashalgo,0,&hash2,data,(void *)&zmsg,recvlen); + iguana_blockconv(coin->chain->zcash,coin->chain->auxpow,zblock,&zmsg,hash2,-1); + txn_count = msg.txn_count; + } + for (i=0; iblocks.hwmchain.height,0,0,&data[len],recvlen - len,&tx,&tx.txid,vpnstr,extraspace,extralen,0,0)) < 0 ) break; - char str[65]; printf("%d of %d: %s len.%d\n",i,msg.txn_count,bits256_str(str,tx.txid),len); + char str[65]; printf("%d of %d: %s len.%d\n",i,txn_count,bits256_str(str,tx.txid),len); if ( bits256_cmp(txid,tx.txid) == 0 ) { if ( (n= iguana_rwmsgtx(coin,coin->blocks.hwmchain.height,0,json,&data[len],recvlen - len,&tx,&tx.txid,vpnstr,extraspace,extralen,0,0)) > 0 ) @@ -757,21 +769,21 @@ char *iguana_txscan(struct supernet_info *myinfo,struct iguana_info *coin,cJSON int32_t iguana_gentxarray(struct supernet_info *myinfo,struct iguana_info *coin,struct OS_memspace *mem,struct iguana_txblock *txdata,int32_t *lenp,uint8_t *data,int32_t recvlen) { - struct iguana_msgtx *tx; bits256 hash2; struct iguana_msgblock msg; int32_t i,n,hdrlen,len,numvouts,numvins; char str[65]; - memset(&msg,0,sizeof(msg)); - len = iguana_rwblock(myinfo,coin->symbol,coin->chain->zcash,coin->chain->auxpow,coin->chain->hashalgo,0,&hash2,data,&msg,recvlen); + struct iguana_msgtx *tx; bits256 hash2; struct iguana_msgzblock zmsg; int32_t txn_count,i,n,hdrlen,len,numvouts,numvins; char str[65]; + memset(&zmsg,0,sizeof(zmsg)); + len = iguana_rwblock(myinfo,coin->symbol,coin->chain->zcash,coin->chain->auxpow,coin->chain->hashalgo,0,&hash2,data,(void *)&zmsg,recvlen); hdrlen = len; if ( len > recvlen ) { printf("gentxarray error len.%d > recvlen.%d\n",len,recvlen); return(-1); } - iguana_blockconv(coin->chain->zcash,coin->chain->auxpow,(struct iguana_block *)&txdata->zblock,&msg,hash2,-1); + txn_count = iguana_blockconv(coin->chain->zcash,coin->chain->auxpow,(void *)&txdata->zblock,&zmsg,hash2,-1); numvins = numvouts = 0; - if ( msg.txn_count > 0 ) + if ( txn_count > 0 ) { - tx = iguana_memalloc(mem,msg.txn_count*sizeof(*tx),1); - for (i=0; i recvlen ) { @@ -798,9 +810,9 @@ int32_t iguana_gentxarray(struct supernet_info *myinfo,struct iguana_info *coin, } else txdata->extralen = 0; } if ( coin->chain->auxpow != 0 && len != recvlen ) - printf("numtx.%d %s hdrlen.%d len.%d vs recvlen.%d v.%08x\n",msg.txn_count,bits256_str(str,hash2),hdrlen,len,recvlen,txdata->zblock.RO.version); + printf("numtx.%d %s hdrlen.%d len.%d vs recvlen.%d v.%08x\n",txn_count,bits256_str(str,hash2),hdrlen,len,recvlen,txdata->zblock.RO.version); txdata->recvlen = len; - txdata->numtxids = msg.txn_count; + txdata->numtxids = txn_count; txdata->numunspents = numvouts; txdata->numspends = numvins; return(len); @@ -975,7 +987,7 @@ int32_t iguana_msgparser(struct supernet_info *myinfo,struct iguana_info *coin,s } else if ( (ishost= (strcmp(H->command,"getheaders") == 0)) || strcmp(H->command,"headers") == 0 ) { - struct iguana_msgblock msg; struct iguana_zblock *zblocks; uint32_t tmp,n=0; + struct iguana_msgzblock zmsg; struct iguana_zblock *zblocks; uint32_t tmp,n=0; len = 0; if ( addr != 0 && recvlen >= sizeof(bits256) && strcmp("BTCD",coin->symbol) != 0 ) { @@ -996,10 +1008,10 @@ int32_t iguana_msgparser(struct supernet_info *myinfo,struct iguana_info *coin,s { if ( coin->chain->auxpow != 0 ) { - tmp = iguana_rwblockhdr(0,coin->chain->zcash,&data[len],&msg); + tmp = iguana_rwblockhdr(0,coin->chain->zcash,&data[len],(void *)&zmsg); hash2 = iguana_calcblockhash(coin->symbol,coin->chain->hashalgo,&data[len],tmp); len += tmp; - if ( (msg.H.version & 0x100) != 0 ) + if ( (zmsg.zH.version & 0x100) != 0 ) { iguana_memreset(rawmem); tx = iguana_memalloc(rawmem,sizeof(*tx),1); @@ -1012,9 +1024,10 @@ int32_t iguana_msgparser(struct supernet_info *myinfo,struct iguana_info *coin,s len += iguana_rwvarint32(0,&data[len],&tmp); char str[65],str2[65]; if ( 0 && coin->chain->auxpow != 0 ) - printf("%d %d of %d: %s %s v.%08x numtx.%d cmp.%d\n",len,i,n,bits256_str(str,hash2),bits256_str(str2,msg.H.prev_block),msg.H.version,tmp,bits256_cmp(prevhash2,msg.H.prev_block)); - } else len += iguana_rwblock(myinfo,coin->chain->symbol,coin->chain->zcash,coin->chain->auxpow,coin->chain->hashalgo,0,&hash2,&data[len],&msg,recvlen); - iguana_blockconv(coin->chain->zcash,coin->chain->auxpow,(struct iguana_block *)&zblocks[i],&msg,hash2,-1); + printf("%d %d of %d: %s %s v.%08x numtx.%d cmp.%d\n",len,i,n,bits256_str(str,hash2),bits256_str(str2,zmsg.zH.prev_block),zmsg.zH.version,tmp,bits256_cmp(prevhash2,zmsg.zH.prev_block)); + } + else len += iguana_rwblock(myinfo,coin->chain->symbol,coin->chain->zcash,coin->chain->auxpow,coin->chain->hashalgo,0,&hash2,&data[len],(void *)&zmsg,recvlen); + iguana_blockconv(coin->chain->zcash,coin->chain->auxpow,(void *)&zblocks[i],&zmsg,hash2,-1); prevhash2 = hash2; } free(coinbase_branch); diff --git a/includes/iguana_funcs.h b/includes/iguana_funcs.h index 5c38ee4e7..7807c8c9b 100755 --- a/includes/iguana_funcs.h +++ b/includes/iguana_funcs.h @@ -43,7 +43,7 @@ int32_t iguana_rwvarint32(int32_t rwflag,uint8_t *serialized,uint32_t *int32p); int32_t iguana_rwbignum(int32_t rwflag,uint8_t *serialized,int32_t len,uint8_t *endianedp); int32_t iguana_rwblock(struct supernet_info *myinfo,char *symbol,uint8_t zcash,uint8_t auxpow,int32_t (*hashalgo)(uint8_t *blockhashp,uint8_t *serialized,int32_t len),int32_t rwflag,bits256 *hash2p,uint8_t *serialized,struct iguana_msgblock *msg,int32_t maxlen); int32_t iguana_serialize_block(struct supernet_info *myinfo,struct iguana_chain *chain,bits256 *hash2p,uint8_t serialized[sizeof(struct iguana_msgblock)],struct iguana_block *block); -void iguana_blockconv(uint8_t zcash,uint8_t auxpow,struct iguana_zblock *zdest,struct iguana_msgzblock *zmsg,bits256 hash2,int32_t height); +int32_t iguana_blockconv(uint8_t zcash,uint8_t auxpow,struct iguana_zblock *zdest,struct iguana_msgzblock *zmsg,bits256 hash2,int32_t height); int32_t iguana_msgparser(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_peer *addr,struct OS_memspace *rawmem,struct OS_memspace *txmem,struct OS_memspace *hashmem,struct iguana_msghdr *H,uint8_t *data,int32_t datalen,int32_t fromcache); // send message