diff --git a/basilisk/basilisk_bitcoin.c b/basilisk/basilisk_bitcoin.c index dae74758b..1954ade88 100755 --- a/basilisk/basilisk_bitcoin.c +++ b/basilisk/basilisk_bitcoin.c @@ -505,10 +505,10 @@ char *basilisk_bitcoinrawtx(struct supernet_info *myinfo,struct iguana_info *coi jadd(valsobj,"addresses",addresses); } //printf("use addresses.(%s)\n",jprint(addresses,0)); - //printf("(%s) vals.(%s) change.(%s) spend.%s\n",coin->symbol,jprint(valsobj,0),changeaddr,spendscriptstr); + printf("(%s) vals.(%s) change.(%s) spend.%s\n",coin->symbol,jprint(valsobj,0),changeaddr,spendscriptstr); if ( changeaddr == 0 || changeaddr[0] == 0 || spendscriptstr == 0 || spendscriptstr[0] == 0 ) return(clonestr("{\"error\":\"invalid changeaddr or spendscript or addresses\"}")); - if ( coin != 0 )//&& basilisk_bitcoinavail(coin) != 0 ) + if ( coin != 0 ) { if ( (txobj= bitcoin_txcreate(coin->chain->isPoS,locktime,locktime==0?coin->chain->normal_txversion:coin->chain->locktime_txversion)) != 0 ) { @@ -530,7 +530,7 @@ char *basilisk_bitcoinrawtx(struct supernet_info *myinfo,struct iguana_info *coi } else oplen = datachain_opreturnscript(coin,buf,opreturn,oplen); } rawtx = iguana_calcrawtx(myinfo,coin,&vins,txobj,amount,changeaddr,txfee,addresses,minconf,oplen!=0?buf:0,oplen+offset,burnamount,remoteaddr); - //printf("generated.(%s) vins.(%s)\n",rawtx!=0?rawtx:"",vins!=0?jprint(vins,0):""); + printf("generated.(%s) vins.(%s)\n",rawtx!=0?rawtx:"",vins!=0?jprint(vins,0):""); } if ( rawtx != 0 ) { @@ -552,7 +552,6 @@ char *basilisk_bitcoinrawtx(struct supernet_info *myinfo,struct iguana_info *coi return(clonestr("{\"error\":\"couldnt create rawtx\"}")); } return(clonestr("{\"error\":\"dont have coin to create rawtx\"}")); - //return(basilisk_issueremote(myinfo,0,&numsent,"RAW",coin->symbol,1,valsobj,juint(valsobj,"fanout"),juint(valsobj,"minresults"),basilisktag,timeoutmillis,0,0,0,0,BASILISK_DEFAULTDIFF)); } /* @@ -808,18 +807,18 @@ HASH_ARRAY_STRING(basilisk,value,hash,vals,hexstr) return(basilisk_standardservice("VAL",myinfo,0,hash,vals,hexstr,1)); } -/*HASH_ARRAY_STRING(basilisk,rawtx,hash,vals,hexstr) +HASH_ARRAY_STRING(basilisk,rawtx,hash,vals,hexstr) { - char *retstr=0,*symbol; uint32_t basilisktag; struct basilisk_item *ptr,Lptr; int32_t timeoutmillis,i,retval = -1; uint64_t amount,txfee; cJSON *retarray; + char *retstr=0,*symbol; uint32_t basilisktag; int32_t timeoutmillis,i,retval = -1; uint64_t amount,txfee; cJSON *retarray; //if ( coin == 0 ) { if ( (symbol= jstr(vals,"symbol")) != 0 || (symbol= jstr(vals,"coin")) != 0 ) coin = iguana_coinfind(symbol); } if ( jobj(vals,"numrequired") == 0 ) - jaddnum(vals,"numrequired",myinfo->numrelays); + jaddnum(vals,"numrequired",NUMRELAYS); if ( jobj(vals,"fanout") == 0 ) - jaddnum(vals,"fanout",(int32_t)sqrt(myinfo->numrelays)); + jaddnum(vals,"fanout",(int32_t)sqrt(NUMRELAYS)); if ( coin != 0 ) { if ( juint(vals,"burn") == 0 ) @@ -828,44 +827,39 @@ HASH_ARRAY_STRING(basilisk,value,hash,vals,hexstr) basilisktag = rand(); if ( (timeoutmillis= juint(vals,"timeout")) <= 0 ) timeoutmillis = BASILISK_TIMEOUT; - if ( (ptr= basilisk_bitcoinrawtx(&Lptr,myinfo,coin,remoteaddr,basilisktag,timeoutmillis,vals)) != 0 ) + if ( (retstr= basilisk_bitcoinrawtx(myinfo,coin,remoteaddr,basilisktag,timeoutmillis,vals)) != 0 ) { - if ( (retstr= ptr->retstr) != 0 ) + if ( (amount= j64bits(vals,"satoshis")) == 0 ) + amount = jdouble(vals,"value") * SATOSHIDEN; + if ( (txfee= j64bits(vals,"txfee")) == 0 ) + txfee = coin->chain->txfee; + if ( txfee == 0 ) + txfee = 10000; + retval = -1; + if ( (retarray= cJSON_Parse(retstr)) != 0 ) { - if ( (amount= j64bits(vals,"satoshis")) == 0 ) - amount = jdouble(vals,"value") * SATOSHIDEN; - if ( (txfee= j64bits(vals,"txfee")) == 0 ) - txfee = coin->chain->txfee; - if ( txfee == 0 ) - txfee = 10000; - retval = -1; - if ( (retarray= cJSON_Parse(retstr)) != 0 ) + if ( is_cJSON_Array(retarray) != 0 ) { - if ( is_cJSON_Array(retarray) != 0 ) + for (i=0; iretstr = 0; - ptr->finished = (uint32_t)time(NULL); } } - } + } else retstr = clonestr("{\"error\":\"no coin specified or found\"}"); return(retstr); -}*/ +} cJSON *basilisk_history_item(struct iguana_info *coin,int64_t *totalp,char *coinaddr,int64_t value,uint32_t timestamp,bits256 txid,char *vinvoutstr,int32_t vinvout,int32_t height,char *otherheightstr,int32_t otherheight,uint64_t relaymask,int32_t ismine) { @@ -873,7 +867,8 @@ cJSON *basilisk_history_item(struct iguana_info *coin,int64_t *totalp,char *coin item = cJSON_CreateObject(); jaddstr(item,"address",coinaddr); jaddnum(item,"amount",dstr(value)); - jaddnum(item,"numseconds",time(NULL) - timestamp); + if ( timestamp > 0 ) + jaddnum(item,"numseconds",time(NULL) - timestamp); details = cJSON_CreateObject(); if ( ismine > 0 ) { @@ -1024,7 +1019,7 @@ void basilisk_unspent_update(struct supernet_info *myinfo,struct iguana_info *co //printf("allocate max.%d for %s\n",waddr->maxunspents,waddr->coinaddr); } waddr->numunspents++; - //printf("new unspent.%s %d script.%p [%d] (%s)\n",waddr->coinaddr,waddr->numunspents,bu.script,bu.spendlen,jprint(item,0)); + printf("new %s unspent.%s %d script.%p [%d] (%s)\n",coin->symbol,waddr->coinaddr,waddr->numunspents,bu.script,bu.spendlen,jprint(item,0)); if ( bu.spentheight != 0 && (dest= jobj(item,"dest")) != 0 ) { struct basilisk_spend *s; @@ -1051,7 +1046,7 @@ void basilisk_unspent_update(struct supernet_info *myinfo,struct iguana_info *co //printf("(%s %.8f) ",s->destaddr,dstr(s->value)); } } - //char str[65]; printf("SPEND dest.(%s) ratio %.8f (%s/v%d)\n",jprint(dest,0),ratio,bits256_str(str,s->txid),s->vini); + char str[65]; printf("SPEND dest.(%s) ratio %.8f (%s/v%d)\n",jprint(dest,0),ratio,bits256_str(str,s->txid),s->vini); } } } diff --git a/gecko/gecko_mempool.c b/gecko/gecko_mempool.c index ce953211d..9916205a5 100755 --- a/gecko/gecko_mempool.c +++ b/gecko/gecko_mempool.c @@ -229,7 +229,7 @@ char *gecko_txarrived(struct supernet_info *myinfo,struct iguana_info *virt,char struct gecko_mempool *pool; int64_t txfee,vinstotal,voutstotal; uint64_t value; int32_t i,numvins,numvouts,txlen,spentheight,minconf,maxconf,unspentind; struct iguana_msgtx msg; char *rawtx; struct gecko_memtx *memtx; struct iguana_info *btcd; struct iguana_outpoint outpt; memset(&msg,0,sizeof(msg)); iguana_memreset(&virt->TXMEM); - txlen = iguana_rwtx(virt->chain->zcash,0,&virt->TXMEM,serialized,&msg,datalen,&txid,virt->chain->isPoS,strcmp("VPN",virt->symbol) == 0); + txlen = iguana_rwtx(virt->chain->zcash,0,virt,&virt->TXMEM,serialized,&msg,datalen,&txid,virt->chain->isPoS,strcmp("VPN",virt->symbol) == 0); vinstotal = voutstotal = 0; maxconf = virt->longestchain; minconf = virt->chain->minconfirms; diff --git a/iguana/coins/genbtc.json b/iguana/coins/genbtc.json index a45c9ba8d..8658b8b19 100755 --- a/iguana/coins/genbtc.json +++ b/iguana/coins/genbtc.json @@ -1 +1 @@ -{"numhelpers":8,"prefetchlag":-1,"poll":1,"active":1,"agent":"iguana","method":"addcoin","newcoin":"BTC","startpend":512,"endpend":512,"services":129,"maxpeers":512,"RELAY":1,"VALIDATE":1,"portp2p":8333} +{"numhelpers":8,"prefetchlag":-1,"poll":1,"active":1,"agent":"iguana","method":"addcoin","newcoin":"BTC","startpend":16,"endpend":16,"services":129,"maxpeers":512,"RELAY":1,"VALIDATE":1,"portp2p":8333} diff --git a/iguana/exchanges/bitcoin.c b/iguana/exchanges/bitcoin.c index 89b6ce232..8370f9523 100755 --- a/iguana/exchanges/bitcoin.c +++ b/iguana/exchanges/bitcoin.c @@ -144,14 +144,6 @@ int32_t bitcoin_priv2wif(char *wifstr,bits256 privkey,uint8_t addrtype) return((int32_t)strlen(wifstr)); } -int32_t iguana_validatesigs(struct iguana_info *coin,struct iguana_msgvin *vin) -{ - // multiple coins - // ro -> vouts collision, purgeable - // - return(0); -} - #ifdef bitcoincancalulatebalances uint64_t bitcoin_parseunspent(struct iguana_info *coin,struct bitcoin_unspent *unspent,double minconfirms,char *account,cJSON *item) { diff --git a/iguana/iguana_msg.c b/iguana/iguana_msg.c index 8db7a25b9..7cffff165 100755 --- a/iguana/iguana_msg.c +++ b/iguana/iguana_msg.c @@ -142,7 +142,7 @@ int32_t iguana_eatauxpow(int32_t rwflag,char *symbol,uint8_t zcash,uint8_t *seri memset(&MEM,0,sizeof(MEM)); ptr = calloc(1,1000000); iguana_meminit(&MEM,"auxpow",ptr,1000000,0); - len += iguana_rwtx(coin->chain->zcash,rwflag,&MEM,&serialized[len],&msg,(int32_t)MEM.totalsize,&coinbasetxid,coin->chain->isPoS,0); + len += iguana_rwtx(coin->chain->zcash,rwflag,coin,&MEM,&serialized[len],&msg,(int32_t)MEM.totalsize,&coinbasetxid,coin->chain->isPoS,0); if ( len > maxlen ) return(-1); len += iguana_rwbignum(rwflag,&serialized[len],sizeof(auxhash2),auxhash2.bytes); @@ -507,7 +507,7 @@ int32_t iguana_getdata(struct iguana_info *coin,uint8_t *serialized,int32_t type } int32_t debugtest; -int32_t iguana_rwvin(int32_t rwflag,struct OS_memspace *mem,uint8_t *serialized,struct iguana_msgvin *msg) +int32_t iguana_rwvin(int32_t rwflag,struct iguana_info *coin,struct OS_memspace *mem,uint8_t *serialized,struct iguana_msgvin *msg,int32_t vini) { int32_t len = 0; uint32_t tmp; len += iguana_rwbignum(rwflag,&serialized[len],sizeof(msg->prev_hash),msg->prev_hash.bytes); @@ -529,6 +529,8 @@ int32_t iguana_rwvin(int32_t rwflag,struct OS_memspace *mem,uint8_t *serialized, printf("%02x ",msg->vinscript[i]); printf(" vinscriptlen.%d, prevhash.%llx prev_vout.%d | ",msg->scriptlen,(long long)msg->prev_hash.txid,msg->prev_vout); } + if ( coin->RTheight > 0 && iguana_validatesigs(coin,msg,vini) < 0 ) + printf("%s vin.%d error validatesigs\n",coin->symbol,vini); return(len); } @@ -577,7 +579,7 @@ int32_t iguana_rwjoinsplit(int32_t rwflag,uint8_t *serialized,struct iguana_msgj return(len); } -int32_t iguana_rwtx(uint8_t zcash,int32_t rwflag,struct OS_memspace *mem,uint8_t *serialized,struct iguana_msgtx *msg,int32_t maxsize,bits256 *txidp,int32_t hastimestamp,int32_t isvpncoin) +int32_t iguana_rwtx(uint8_t zcash,int32_t rwflag,struct iguana_info *coin,struct OS_memspace *mem,uint8_t *serialized,struct iguana_msgtx *msg,int32_t maxsize,bits256 *txidp,int32_t hastimestamp,int32_t isvpncoin) { int32_t i,n,len = 0; uint8_t *txstart = serialized; char txidstr[65]; if ( maxsize < sizeof(msg->version) ) @@ -604,7 +606,7 @@ int32_t iguana_rwtx(uint8_t zcash,int32_t rwflag,struct OS_memspace *mem,uint8_t return(-1); } } - if ( (n= iguana_rwvin(rwflag,mem,&serialized[len],&msg->vins[i])) >= 0 ) + if ( (n= iguana_rwvin(rwflag,coin,mem,&serialized[len],&msg->vins[i],i)) >= 0 ) len += n; if ( n < 0 || len+sizeof(int32_t) > maxsize ) { @@ -719,7 +721,7 @@ int32_t iguana_gentxarray(struct iguana_info *coin,struct OS_memspace *mem,struc printf("gentxarrayB error len.%d > recvlen.%d\n",len,recvlen); return(-1); } - if ( (n= iguana_rwtx(coin->chain->zcash,0,mem,&data[len],&tx[i],recvlen - len,&tx[i].txid,coin->chain->isPoS,strcmp(coin->symbol,"VPN")==0)) < 0 ) + if ( (n= iguana_rwtx(coin->chain->zcash,0,coin,mem,&data[len],&tx[i],recvlen - len,&tx[i].txid,coin->chain->isPoS,strcmp(coin->symbol,"VPN")==0)) < 0 ) { //for (i=0; ichain->zcash,0,rawmem,&data[len],tx,recvlen-len,&tx->txid,coin->chain->isPoS,strcmp(coin->symbol,"VPN")==0); + len += iguana_rwtx(coin->chain->zcash,0,coin,rawmem,&data[len],tx,recvlen-len,&tx->txid,coin->chain->isPoS,strcmp(coin->symbol,"VPN")==0); len += iguana_rwbignum(0,&data[len],sizeof(auxhash2),auxhash2.bytes); len += iguana_rwmerklebranch(0,&data[len],coinbase_branch); len += iguana_rwmerklebranch(0,&data[len],blockchain_branch); @@ -1093,7 +1095,7 @@ int32_t iguana_msgparser(struct iguana_info *coin,struct iguana_peer *addr,struc struct iguana_msgtx *tx; iguana_memreset(rawmem); tx = iguana_memalloc(rawmem,sizeof(*tx),1);//mycalloc('u',1,sizeof(*tx)); - len = iguana_rwtx(coin->chain->zcash,0,rawmem,data,tx,recvlen,&tx->txid,coin->chain->isPoS,strcmp(coin->symbol,"VPN")==0); + len = iguana_rwtx(coin->chain->zcash,0,coin,rawmem,data,tx,recvlen,&tx->txid,coin->chain->isPoS,strcmp(coin->symbol,"VPN")==0); if ( addr != 0 ) { iguana_gotunconfirmedM(coin,addr,tx,data,recvlen); diff --git a/iguana/iguana_payments.c b/iguana/iguana_payments.c index d811bfdf8..0ae0de8be 100755 --- a/iguana/iguana_payments.c +++ b/iguana/iguana_payments.c @@ -442,25 +442,25 @@ void iguana_RTunspentslock(struct supernet_info *myinfo,struct iguana_info *coin } } -char *sendtoaddress(struct supernet_info *myinfo,struct iguana_info *coin,char *remoteaddr,char *coinaddr,uint64_t satoshis,uint64_t txfee,char *comment,char *comment2,int32_t minconf,char *account) +char *sendtoaddress(struct supernet_info *myinfo,struct iguana_info *coin,char *remoteaddr,char *destaddr,uint64_t satoshis,uint64_t txfee,char *comment,char *comment2,int32_t minconf,char *account) { uint8_t addrtype,spendscript[1024],rmd160[20]; int32_t completed; char *retstr,spendscriptstr[4096],*rawtx=0,*signedtx = 0; bits256 signedtxid,senttxid; cJSON *retjson,*vins,*addresses,*valsobj; uint32_t spendlen,locktime = 0; uint32_t basilisktag; //sendtoaddress [comment] [comment-to] is a real and is rounded to 8 decimal places. Returns the transaction ID if successful. Y + if ( coin->RTheight == 0 ) + return(clonestr("{\"error\":\"need to get to realtime blocks to send transaction\"}")); if ( account == 0 || account[0] == 0 ) account = "*"; addresses = iguana_getaddressesbyaccount(myinfo,coin,account); if ( coin->changeaddr[0] == 0 ) { - //if ( (waddr= iguana_getaccountaddress(myinfo,coin,0,0,coin->changeaddr,"change")) == 0 ) - // return(clonestr("{\"error\":\"no change address specified\"}")); bitcoin_address(coin->changeaddr,coin->chain->pubtype,myinfo->persistent_pubkey33,33); printf("%s change %s\n",coin->symbol,coin->changeaddr); } - if ( coinaddr != 0 && coinaddr[0] != 0 && satoshis != 0 ) + if ( destaddr != 0 && destaddr[0] != 0 && satoshis != 0 ) { - if ( iguana_addressvalidate(coin,&addrtype,coinaddr) < 0 ) + if ( iguana_addressvalidate(coin,&addrtype,destaddr) < 0 ) return(clonestr("{\"error\":\"invalid coin address\"}")); - bitcoin_addr2rmd160(&addrtype,rmd160,coinaddr); + bitcoin_addr2rmd160(&addrtype,rmd160,destaddr); spendlen = bitcoin_standardspend(spendscript,0,rmd160); init_hexbytes_noT(spendscriptstr,spendscript,spendlen); basilisktag = (uint32_t)rand(); @@ -849,10 +849,14 @@ int64_t iguana_txdetails(struct supernet_info *myinfo,struct iguana_info *coin,c jaddnum(item,"vout",vout); if ( (amount= iguana_txidamount(myinfo,coin,txid,vout)) != 0 ) jaddnum(item,"amount",dstr(amount)); + jaddstr(item,"category",iguana_txidcategory(myinfo,coin,account,coinaddr,txid,vout)); + } + else + { + if ( vout == -1 ) + jadd(item,"coinbase",jtrue()); + vout = 0; } - else if ( vout == -1 ) - jadd(item,"coinbase",jtrue()); - jaddstr(item,"category",iguana_txidcategory(myinfo,coin,account,coinaddr,txid,vout)); if ( account[0] != 0 && jobj(item,"account") == 0 ) jaddstr(item,"account",account); if ( coinaddr[0] != 0 ) @@ -896,7 +900,7 @@ HASH_AND_INT(bitcoinrpc,getrawtransaction,txid,verbose) free(txbytes); if ( txobj != 0 ) { - iguana_txdetails(myinfo,coin,txobj,tx->txid,-2,height); + iguana_txdetails(myinfo,coin,txobj,txid,-2,height); return(jprint(txobj,1)); } } diff --git a/iguana/iguana_realtime.c b/iguana/iguana_realtime.c index 3d37ef46a..db14480ba 100755 --- a/iguana/iguana_realtime.c +++ b/iguana/iguana_realtime.c @@ -649,7 +649,7 @@ void iguana_RTunspent(struct iguana_info *coin,struct iguana_RTtxid *RTptr,struc void iguana_RTspend(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_RTtxid *RTptr,struct iguana_block *block,int64_t polarity,uint8_t *script,int32_t scriptlen,bits256 txid,int32_t vini,bits256 prev_hash,int32_t prev_vout) { struct iguana_RTspend *spend; struct iguana_RTtxid *spentRTptr; struct iguana_RTunspent *unspent=0; char str[65],str2[65],coinaddr[64]; uint8_t addrtype,rmd160[20],spendscript[IGUANA_MAXSCRIPTSIZE]; uint32_t unspentind; int32_t spendlen,height; uint64_t value; struct iguana_outpoint spentpt; - //printf("RTspend %s vini.%d spend.(%s/v%d) %lld\n",bits256_str(str,txid),vini,bits256_str(str2,prev_hash),prev_vout,(long long)polarity); + printf("RTspend %s vini.%d spend.(%s/v%d) %lld\n",bits256_str(str,txid),vini,bits256_str(str2,prev_hash),prev_vout,(long long)polarity); if ( vini == 0 && bits256_nonz(prev_hash) == 0 && prev_vout < 0 ) return; //fprintf(stderr,"-"); @@ -778,7 +778,7 @@ int64_t _RTgettxout(struct iguana_info *coin,int32_t *heightp,int32_t *scriptlen if ( vout >= 0 && vout < RTptr->txn_count && (unspent= RTptr->unspents[vout]) != 0 ) { *heightp = RTptr->height; - if ( unspent->spend == 0 && (*scriptlenp= unspent->scriptlen) > 0 ) + if ( script != 0 && unspent->spend == 0 && (*scriptlenp= unspent->scriptlen) > 0 ) memcpy(script,unspent->script,*scriptlenp); memcpy(rmd160,unspent->rmd160,sizeof(unspent->rmd160)); bitcoin_address(coinaddr,coin->chain->pubtype,rmd160,sizeof(unspent->rmd160)); @@ -1001,7 +1001,7 @@ int32_t iguana_RTiterate(struct supernet_info *myinfo,struct iguana_info *coin,i return(-1); } } - char str[65]; printf("%s RTiterate.%lld offset.%d numtx.%d len.%d %s\n",coin->symbol,(long long)polarity,offset,coin->RTnumtx[offset],coin->RTrecvlens[offset],bits256_str(str,block->RO.hash2)); + char str[65]; printf("%s RTiterate.%lld %d tx.%d len.%d %s\n",coin->symbol,(long long)polarity,offset,coin->RTnumtx[offset],coin->RTrecvlens[offset],bits256_str(str,block->RO.hash2)); if ( coin->RTrawmem.ptr == 0 ) iguana_meminit(&coin->RTrawmem,"RTrawmem",0,IGUANA_MAXPACKETSIZE * 2,0); if ( coin->RTmem.ptr == 0 ) diff --git a/iguana/iguana_sign.c b/iguana/iguana_sign.c index 5578e76ea..1b8680985 100755 --- a/iguana/iguana_sign.c +++ b/iguana/iguana_sign.c @@ -1305,6 +1305,17 @@ int32_t iguana_signrawtransaction(struct supernet_info *myinfo,struct iguana_inf *signedtxp = signedtx; return(complete); } +int32_t iguana_validatesigs(struct iguana_info *coin,struct iguana_msgvin *vin,int32_t vini) +{ + //int32_t i; + if ( vin->vinscript != 0 && vin->scriptlen >= 70 ) + { + //for (i=0; iscriptlen; i++) + // printf("%02x",vin->vinscript[i]); + } + //printf(" vin.[%d] validate len.%d\n",vini,vin->scriptlen); + return(0); +} STRING_ARRAY_OBJ_STRING(bitcoinrpc,signrawtransaction,rawtx,vins,privkeys,sighash) { diff --git a/iguana/iguana_tx.c b/iguana/iguana_tx.c index 36df86655..2d4b6407e 100755 --- a/iguana/iguana_tx.c +++ b/iguana/iguana_tx.c @@ -195,12 +195,12 @@ int32_t iguana_ramtxbytes(struct iguana_info *coin,uint8_t *serialized,int32_t m if ( vins == 0 ) iguana_vinset(coin,space,height,&vin,tx,i); else vin = vins[i]; - if ( validatesigs != 0 && iguana_validatesigs(coin,&vin) < 0 ) + len += iguana_rwvin(rwflag,coin,0,&serialized[len],&vin,i); + if ( validatesigs != 0 && iguana_validatesigs(coin,&vin,i) < 0 ) { - printf("error validating vin.%d ht.%d\n",i,height); - return(0); + char str[65]; printf("error %s validating vin.%d ht.%d\n",bits256_str(str,tx->txid),i,height); + //return(0); } - len += iguana_rwvin(rwflag,0,&serialized[len],&vin); } if ( len > maxlen ) { diff --git a/iguana/iguana_unspents.c b/iguana/iguana_unspents.c index 88d252043..a05e7901d 100755 --- a/iguana/iguana_unspents.c +++ b/iguana/iguana_unspents.c @@ -243,7 +243,7 @@ cJSON *iguana_RTunspentjson(struct supernet_info *myinfo,struct iguana_info *coi "spendable" : true },*/ //struct iguana_unspent { uint64_t value; uint32_t txidind,pkind,prevunspentind; uint16_t hdrsi:12,type:4,vout; } __attribute__((packed)); - struct iguana_waccount *wacct; struct iguana_waddress *waddr; int32_t height; char scriptstr[8192],asmstr[sizeof(scriptstr)+1024]; cJSON *item; uint32_t checkind; struct iguana_RTunspent *unspent; + struct iguana_waccount *wacct; struct iguana_waddress *waddr; int32_t height; char scriptstr[8192],asmstr[sizeof(scriptstr)+1024]; cJSON *item; uint32_t checkind; struct iguana_RTunspent *unspent; struct iguana_block *block; item = cJSON_CreateObject(); jaddbits256(item,"txid",txid); jaddnum(item,"vout",vout); @@ -265,6 +265,8 @@ cJSON *iguana_RTunspentjson(struct supernet_info *myinfo,struct iguana_info *coi //jaddnum(item,"timestamp",T[up->txidind].timestamp); if ( (checkind= iguana_RTunspentindfind(myinfo,coin,0,0,0,0,&height,txid,vout,coin->bundlescount-1,0)) != 0 ) { + if ( (block= iguana_blockfind("unspentjson",coin,iguana_blockhash(coin,height))) != 0 && block->RO.timestamp != 0 ) + jaddnum(item,"timestamp",block->RO.timestamp); jaddnum(item,"height",height); jaddnum(item,"confirmations",coin->blocks.hwmchain.height - height + 1); jaddnum(item,"checkind",checkind); @@ -459,6 +461,7 @@ int64_t iguana_RTpkhashbalance(struct supernet_info *myinfo,struct iguana_info * uheight = iguana_uheight(coin,ramchain->height,T,rdata->numtxids,&U[unspentind]); if ( lastheight <= 0 || uheight < lastheight ) { + //printf("u%u ",unspentind); deposits += U[unspentind].value; memset(&outpt,0,sizeof(outpt)); outpt.hdrsi = lastpt.hdrsi; @@ -507,7 +510,7 @@ int64_t iguana_RTpkhashbalance(struct supernet_info *myinfo,struct iguana_info * printf("spend %s: [%d] deposits %.8f spent %.8f check %.8f (%.8f) vs A2[%u] %.8f\n",lastheight==IGUANA_MAXHEIGHT?"checkerr":"",lastpt.hdrsi,dstr(deposits),dstr(spent),dstr(checkval)+dstr(RTspend),dstr(*spentp),pkind,dstr(A2[pkind].total)); } (*spentp) = spent; - //printf("(%s) spent %.8f, RTspent %.8f deposits %.8f\n",coinaddr,dstr(spent),dstr(RTspend),dstr(deposits)); + //printf("[%d] (%s) spent %.8f, RTspent %.8f deposits %.8f\n",ramchain->height/coin->chain->bundlesize,coinaddr,dstr(spent),dstr(RTspend),dstr(deposits)); return(deposits - spent); } @@ -532,7 +535,7 @@ int32_t iguana_RTpkhasharray(struct supernet_info *myinfo,struct iguana_info *co if ( i != max && (bp= coin->bundles[i]) == 0 ) continue; else bp = 0; - if ( 0 && bp != 0 ) + if ( bp != 0 ) { if ( lastheight > 0 && bp->bundleheight > lastheight ) { @@ -583,7 +586,7 @@ int32_t iguana_RTpkhasharray(struct supernet_info *myinfo,struct iguana_info *co int64_t iguana_RTunspents(struct supernet_info *myinfo,struct iguana_info *coin,cJSON *array,int32_t minconf,int32_t maxconf,uint8_t *rmdarray,int32_t numrmds,int32_t lastheight,struct iguana_outpoint *unspents,int32_t *numunspentsp,char *remoteaddr,int32_t includespent) { - uint64_t total=0,sum=0; struct iguana_pkhash *P; uint8_t *addrtypes,*pubkeys; int32_t i,numunspents,maxunspents,flag = 0; char coinaddr[64]; + uint64_t total=0,sum=0; struct iguana_pkhash *P; uint8_t *addrtypes,*pubkeys; int32_t i,j,numunspents,maxunspents,flag = 0; char coinaddr[64]; //portable_mutex_lock(&coin->RTmutex); while ( 0 && coin->RTramchain_busy != 0 ) { @@ -600,6 +603,11 @@ int64_t iguana_RTunspents(struct supernet_info *myinfo,struct iguana_info *coin, P = calloc(coin->bundlescount,sizeof(*P)); for (i=0; ibundlescount,&rmdarray[i * 20],coinaddr,&pubkeys[33*i],lastheight,&unspents[numunspents],numunspentsp,maxunspents,remoteaddr,includespent); @@ -648,7 +656,7 @@ uint8_t *iguana_rmdarray(struct supernet_info *myinfo,struct iguana_info *coin,i int64_t *iguana_PoS_weights(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_pkhash **Ptrp,int64_t *supplyp,int32_t *numacctsp,int32_t *nonzp,int32_t *errsp,int32_t lastheight) { - int64_t balance,total,supply,*weights=0; uint32_t pkind; int32_t numrmds,minconf,neg,numunspents,nonz,num=0; struct iguana_bundle *bp; struct iguana_ramchaindata *rdata; struct iguana_pkhash *refP; uint8_t rmd160[20],*rmdarray; cJSON *array; char coinaddr[64]; //struct iguana_account *A2; struct iguana_utxo *U2; + int64_t balance,total,supply,*weights=0; uint32_t pkind; int32_t j,numrmds,minconf,neg,numunspents,nonz,num=0; struct iguana_bundle *bp; struct iguana_ramchaindata *rdata; struct iguana_pkhash *refP; uint8_t rmd160[20],*rmdarray; cJSON *array; char coinaddr[64]; //struct iguana_account *A2; struct iguana_utxo *U2; *supplyp = 0; *numacctsp = *nonzp = 0; *errsp = 1; @@ -666,6 +674,11 @@ int64_t *iguana_PoS_weights(struct supernet_info *myinfo,struct iguana_info *coi { total = 0; memcpy(rmd160,refP[pkind].rmd160,sizeof(rmd160)); + for (j=0; j<20; j++) + if ( rmd160[j] != 0 ) + break; + if ( j == 20 ) + continue; array = cJSON_CreateArray(); bitcoin_address(coinaddr,coin->chain->pubtype,rmd160,sizeof(rmd160)); jaddistr(array,coinaddr); @@ -779,7 +792,7 @@ int32_t iguana_RTaddr_unspents(struct supernet_info *myinfo,struct iguana_info * int32_t iguana_RTunspentslists(struct supernet_info *myinfo,struct iguana_info *coin,uint64_t *totalp,struct iguana_outpoint *unspents,int32_t max,uint64_t required,int32_t minconf,cJSON *addresses,char *remoteaddr) { - uint64_t sum = 0; int32_t k,i,j,r,numunspents,numaddrs; uint8_t pubkey[65]; char *coinaddr,str[65]; struct iguana_waddress *waddr; struct iguana_waccount *wacct; struct basilisk_unspent *bu; struct iguana_outpoint outpt; + uint64_t sum = 0; int32_t k,i,j,r,numunspents,numaddrs; uint8_t addrtype,rmd160[20],pubkey[65]; char *coinaddr,str[65]; struct iguana_waddress *waddr; struct iguana_waccount *wacct; struct basilisk_unspent *bu; struct iguana_outpoint outpt; *totalp = 0; if ( (numaddrs= cJSON_GetArraySize(addresses)) == 0 ) { @@ -792,7 +805,17 @@ int32_t iguana_RTunspentslists(struct supernet_info *myinfo,struct iguana_info * { if ( (coinaddr= jstri(addresses,i)) != 0 ) { - //printf("i.%d coinaddr.(%s) minconf.%d longest.%d diff.%d\n",i,coinaddr,minconf,coin->longestchain,coin->blocks.hwmchain.height - minconf); + if ( iguana_addressvalidate(coin,&addrtype,coinaddr) < 0 ) + { + printf("i.%d illegal coinaddr.(%s) minconf.%d longest.%d diff.%d\n",i,coinaddr,minconf,coin->longestchain,coin->blocks.hwmchain.height - minconf); + continue; + } + bitcoin_addr2rmd160(&addrtype,rmd160,coinaddr); + for (j=0; j<20; j++) + if ( rmd160[j] != 0 ) + break; + if ( j == 20 ) + continue; if ( coin->FULLNODE != 0 || coin->VALIDATENODE != 0 ) { numunspents += iguana_RTaddr_unspents(myinfo,coin,&sum,&unspents[numunspents],max-numunspents,coinaddr,remoteaddr,coin->blocks.hwmchain.height - minconf,0); diff --git a/iguana/iguana_wallet.c b/iguana/iguana_wallet.c index 34318df97..6ee087cb0 100755 --- a/iguana/iguana_wallet.c +++ b/iguana/iguana_wallet.c @@ -899,7 +899,7 @@ void iguana_walletlock(struct supernet_info *myinfo,struct iguana_info *coin) myinfo->expiration = 0; portable_mutex_lock(&myinfo->bu_mutex); if ( myinfo->spends != 0 ) - free(myinfo->spends), myinfo->numspends = 0; + /*free(myinfo->spends),*/ myinfo->numspends = 0; portable_mutex_unlock(&myinfo->bu_mutex); iguana_walletiterate(myinfo,coin,-2,0,0,0,0); } @@ -1051,6 +1051,15 @@ STRING_ARG(bitcoinrpc,validateaddress,address) return(jprint(retjson,1)); } +double _max100(double val) +{ + if ( val < 0. ) + return(0.); + else if ( val > 100. ) + return(100.); + else return(val); +} + ZERO_ARGS(bitcoinrpc,getinfo) { cJSON *retjson; @@ -1065,10 +1074,10 @@ ZERO_ARGS(bitcoinrpc,getinfo) jaddnum(retjson,"txfee",dstr(coin->txfee)); if ( coin->bundlescount > 1 ) { - jaddnum(retjson,"bundles",100. * (double)(coin->chain->bundlesize *iguana_emitfinished(coin,0))/(coin->longestchain+1)); - jaddnum(retjson,"utxo",100. * (double)(coin->chain->bundlesize *iguana_utxofinished(coin))/(coin->longestchain+1)); - jaddnum(retjson,"balances",100. * (double)(coin->chain->bundlesize *iguana_balancefinished(coin))/(coin->longestchain+1)); - jaddnum(retjson,"validated",100. * (double)(coin->chain->bundlesize *iguana_validated(coin))/(coin->longestchain+1)); + jaddnum(retjson,"bundles",_max100(100. * (double)(iguana_emitfinished(coin,0))/(coin->longestchain/coin->chain->bundlesize))); + jaddnum(retjson,"utxo",_max100(100. * (double)(iguana_utxofinished(coin))/(coin->longestchain/coin->chain->bundlesize))); + jaddnum(retjson,"balances",_max100(100. * (double)(iguana_balancefinished(coin))/(coin->longestchain/coin->chain->bundlesize))); + jaddnum(retjson,"validated",_max100(100. * (double)(iguana_validated(coin))/(coin->longestchain/coin->chain->bundlesize))); } jaddnum(retjson,"firstRTheight",coin->firstRTheight); jaddnum(retjson,"RTheight",coin->RTheight); diff --git a/iguana/main.c b/iguana/main.c index 569d51147..d14e9fb4f 100755 --- a/iguana/main.c +++ b/iguana/main.c @@ -542,7 +542,7 @@ void iguana_appletests(struct supernet_info *myinfo) bitcoin_sharedsecret(myinfo->ctx,hash2,pubkey,33); printf("secp256k1 elapsed %.3f for %d iterations\n",OS_milliseconds() - startmillis,i); getchar();**/ - if ( 1 && (str= SuperNET_JSON(myinfo,iguana_coinfind("BTCD"),cJSON_Parse("{\"protover\":70002,\"RELAY\":1,\"VALIDATE\":1,\"portp2p\":14631,\"rpc\":14632,\"agent\":\"iguana\",\"method\":\"addcoin\",\"startpend\":512,\"endpend\":512,\"services\":129,\"maxpeers\":8,\"newcoin\":\"BTCD\",\"active\":1,\"numhelpers\":1,\"poll\":100}"),0,myinfo->rpcport)) != 0 ) + if ( 0 && (str= SuperNET_JSON(myinfo,iguana_coinfind("BTCD"),cJSON_Parse("{\"protover\":70002,\"RELAY\":1,\"VALIDATE\":1,\"portp2p\":14631,\"rpc\":14632,\"agent\":\"iguana\",\"method\":\"addcoin\",\"startpend\":512,\"endpend\":512,\"services\":129,\"maxpeers\":8,\"newcoin\":\"BTCD\",\"active\":1,\"numhelpers\":1,\"poll\":100}"),0,myinfo->rpcport)) != 0 ) { free(str); if ( 1 && (str= SuperNET_JSON(myinfo,iguana_coinfind("BTC"),cJSON_Parse("{\"portp2p\":8333,\"RELAY\":0,\"VALIDATE\":0,\"agent\":\"iguana\",\"method\":\"addcoin\",\"startpend\":1,\"endpend\":1,\"services\":128,\"maxpeers\":8,\"newcoin\":\"BTC\",\"active\":0,\"numhelpers\":1,\"poll\":100}"),0,myinfo->rpcport)) != 0 ) diff --git a/iguana/tests/decoderawtransaction b/iguana/tests/decoderawtransaction index 721eacfe1..f52a76c07 100755 --- a/iguana/tests/decoderawtransaction +++ b/iguana/tests/decoderawtransaction @@ -1 +1 @@ -curl --url "http://127.0.0.1:7778" --data "{\"coin\":\"BTCD\",\"method\":\"decoderawtransaction\",\"params\":[\"010000004522cd570100d17d847b7096cdd9b79e4df4b74aabb9ac34b7abd4f9fce19d761e97cca0e800000000fd0000ffffffff0240420f00000000001976a91410acba3a841fae68aba4b5ff162714c493bcc04e88acd0300e00000000001976a914d8b8c039206af6cec82bca950f592801e62808cb88ac00000000\", 1]}" +curl --url "http://127.0.0.1:7778" --data "{\"coin\":\"BTCD\",\"method\":\"decoderawtransaction\",\"params\":[\"010000004831cd5701af9e98186fa255729e89a0c7670ff1d9b99ae2bd10b6cc31f55864dd99a2ca00010000006a473044022057cd04e3948a8b92cab4524e2a78ae7ff470d00d654a6c36086d07ca8afa65dd022074c7eb31998b204725d4b2ce6f756a477e5e27d59285479b7c9c8dfd095eca8a012102743d2afdb88ede68fb5938e961b1f41c2b6267b3286516543eb4e4ab87ad0d0affffffff02c0d40100000000001976a9145da2ae69885741a6946e01ad8aa8b5312eed856088ac6059e50b000000001976a9142f4c0f91fc06ac228c120aee41741d0d3909683288ac00000000\", 1]}" diff --git a/iguana/tests/getinfo b/iguana/tests/getinfo index 755bee524..6f8a1f590 100755 --- a/iguana/tests/getinfo +++ b/iguana/tests/getinfo @@ -1 +1 @@ -curl --url "http://127.0.0.1:7778" --data "{\"method\":\"getinfo\",\"params\":[]}" +curl --url "http://127.0.0.1:7778" --data "{\"coin\":\"BTCD\",\"method\":\"getinfo\",\"params\":[]}" diff --git a/iguana/tests/gettransaction b/iguana/tests/gettransaction index a03d7fd7a..071a20a97 100755 --- a/iguana/tests/gettransaction +++ b/iguana/tests/gettransaction @@ -1,2 +1,2 @@ -curl --url "http://127.0.0.1:7778" --data "{\"method\":\"gettransaction\",\"coin\":\"BTCD\",\"params\":[\"f19aa5e469be3864030f44f184638d55ddc6bf66c7eecf1697c22092421901e7\"]}" +curl --url "http://127.0.0.1:7778" --data "{\"method\":\"gettransaction\",\"coin\":\"BTCD\",\"params\":[\"8091ecac0b6796bac05fed2838c1951a25b86c4ced31f9f711b0711c839dbbea\"]}" diff --git a/iguana/tests/listunspent b/iguana/tests/listunspent index e5ce5c0d9..4d650562d 100755 --- a/iguana/tests/listunspent +++ b/iguana/tests/listunspent @@ -1 +1 @@ -curl --url "http://127.0.0.1:7778" --data "{\"coin\":\"BTCD\",\"method\":\"listunspent\",\"params\":[1, 9999999, [\"RThtXup6Zo7LZAi8kRWgjAyi1s4u6U9Cpf\"]]}" +curl --url "http://127.0.0.1:7778" --data "{\"coin\":\"BTCD\",\"method\":\"listunspent\",\"params\":[1, 9999999, []]}" diff --git a/includes/iguana_apideclares.h b/includes/iguana_apideclares.h index c600ac69e..b31d27db8 100755 --- a/includes/iguana_apideclares.h +++ b/includes/iguana_apideclares.h @@ -39,7 +39,7 @@ HASH_ARRAY_STRING(basilisk,history,hash,vals,hexstr); HASH_ARRAY_STRING(basilisk,balances,hash,vals,hexstr); HASH_ARRAY_STRING(basilisk,value,hash,vals,hexstr); -//HASH_ARRAY_STRING(basilisk,rawtx,hash,vals,hexstr); +HASH_ARRAY_STRING(basilisk,rawtx,hash,vals,hexstr); HASH_ARRAY_STRING(basilisk,getmessage,hash,vals,hexstr); HASH_ARRAY_STRING(basilisk,sendmessage,hash,vals,hexstr); diff --git a/includes/iguana_funcs.h b/includes/iguana_funcs.h index f1d5f066d..8828f42a6 100755 --- a/includes/iguana_funcs.h +++ b/includes/iguana_funcs.h @@ -56,7 +56,7 @@ int32_t iguana_gethdrs(struct iguana_info *coin,uint8_t *serialized,char *cmd,ch int32_t iguana_getdata(struct iguana_info *coin,uint8_t *serialized,int32_t type,bits256 *hashes,int32_t n); void iguana_blockunconv(uint8_t zcash,uint8_t auxpow,struct iguana_msgblock *msg,struct iguana_block *src,int32_t cleartxn_count); int32_t iguana_peerblockrequest(struct iguana_info *coin,uint8_t *blockspace,int32_t max,struct iguana_peer *addr,bits256 hash2,int32_t validatesigs); -int32_t iguana_validatesigs(struct iguana_info *coin,struct iguana_msgvin *vin); +int32_t iguana_validatesigs(struct iguana_info *coin,struct iguana_msgvin *vin,int32_t vini); // ramchain int64_t iguana_verifyaccount(struct iguana_info *coin,struct iguana_account *acct,uint32_t pkind); @@ -79,7 +79,7 @@ int32_t iguana_chainextend(struct supernet_info *myinfo,struct iguana_info *coin uint64_t iguana_miningreward(struct iguana_info *coin,uint32_t blocknum); // tx -int32_t iguana_rwtx(uint8_t zcash,int32_t rwflag,struct OS_memspace *mem,uint8_t *serialized,struct iguana_msgtx *msg,int32_t maxsize,bits256 *txidp,int32_t hastimestamp,int32_t isvpncoin); +int32_t iguana_rwtx(uint8_t zcash,int32_t rwflag,struct iguana_info *coin,struct OS_memspace *mem,uint8_t *serialized,struct iguana_msgtx *msg,int32_t maxsize,bits256 *txidp,int32_t hastimestamp,int32_t isvpncoin); void iguana_gottxidsM(struct iguana_info *coin,struct iguana_peer *addr,bits256 *txids,int32_t n); void iguana_gotquotesM(struct iguana_info *coin,struct iguana_peer *addr,bits256 *quotes,int32_t n); void iguana_gotunconfirmedM(struct iguana_info *coin,struct iguana_peer *addr,struct iguana_msgtx *tx,uint8_t *data,int32_t datalen); @@ -286,7 +286,7 @@ char *iguana_rawtxbytes(struct iguana_info *coin,int32_t height,cJSON *json,stru int32_t iguana_send_VPNversion(struct iguana_info *coin,struct iguana_peer *addr,uint64_t myservices); void exchanges777_init(struct supernet_info *myinfo,cJSON *exchanges,int32_t sleepflag); int32_t iguana_rwvout(int32_t rwflag,struct OS_memspace *mem,uint8_t *serialized,struct iguana_msgvout *msg); -int32_t iguana_rwvin(int32_t rwflag,struct OS_memspace *mem,uint8_t *serialized,struct iguana_msgvin *msg); +int32_t iguana_rwvin(int32_t rwflag,struct iguana_info *coin,struct OS_memspace *mem,uint8_t *serialized,struct iguana_msgvin *msg,int32_t vini); int32_t iguana_rwmsgtx(struct iguana_info *coin,int32_t height,int32_t rwflag,cJSON *json,uint8_t *serialized,int32_t maxsize,struct iguana_msgtx *msg,bits256 *txidp,char *vpnstr,uint8_t *extraspace,int32_t extralen,cJSON *vins,int32_t suppress_pubkeys); int32_t iguana_ramtxbytes(struct iguana_info *coin,uint8_t *serialized,int32_t maxlen,bits256 *txidp,struct iguana_txid *tx,int32_t height,struct iguana_msgvin *vins,struct iguana_msgvout *vouts,int32_t validatesigs); cJSON *bitcoin_txtest(struct iguana_info *coin,char *rawtxstr,bits256 txid);