diff --git a/iguana/exchanges/bitcoin.c b/iguana/exchanges/bitcoin.c index b2c854f41..8b123452b 100755 --- a/iguana/exchanges/bitcoin.c +++ b/iguana/exchanges/bitcoin.c @@ -208,14 +208,14 @@ char *bitcoin_address(char *coinaddr,uint8_t addrtype,uint8_t *pubkey,int32_t le int32_t bitcoin_validaddress(struct iguana_info *coin,char *coinaddr) { - uint8_t rmd160[20],addrtype; + uint8_t rmd160[20],addrtype; char checkaddr[128]; if ( coin == 0 || coinaddr == 0 || coinaddr[0] == 0 ) return(-1); else if ( bitcoin_addr2rmd160(&addrtype,rmd160,coinaddr) < 0 ) return(-1); else if ( addrtype != coin->chain->pubtype && addrtype != coin->chain->p2shtype ) return(-1); - else if ( bitcoin_address(coinaddr,addrtype,rmd160,sizeof(rmd160)) != coinaddr ) + else if ( bitcoin_address(checkaddr,addrtype,rmd160,sizeof(rmd160)) != checkaddr || strcmp(checkaddr,coinaddr) != 0 ) return(-1); return(0); } diff --git a/iguana/iguana_recv.c b/iguana/iguana_recv.c index 10e69a838..1a9b4bb4c 100755 --- a/iguana/iguana_recv.c +++ b/iguana/iguana_recv.c @@ -641,7 +641,7 @@ struct iguana_bundlereq *iguana_recvblockhashes(struct iguana_info *coin,struct //iguana_blockQ(coin,0,-1,blockhashes[1],0); //iguana_blockQ(coin,0,-4,blockhashes[1],1); char str[65]; - if ( 0 && num > 2 ) + //if ( 0 && num > 2 ) printf("blockhashes[%d] %d of %d %s bp.%d[%d]\n",num,bp==0?-1:bp->hdrsi,coin->bundlescount,bits256_str(str,blockhashes[1]),bp==0?-1:bp->bundleheight,bundlei); if ( bp != 0 ) { @@ -722,16 +722,10 @@ struct iguana_bundlereq *iguana_recvblockhashes(struct iguana_info *coin,struct { iguana_blockhashset(coin,-1,blockhashes[1],1); if ( (block= iguana_blockfind(coin,blockhashes[1])) != 0 ) - { - block->newtx = 1; iguana_blockQ("recvhash6",coin,0,-6,blockhashes[1],1); // should be RT block - } - } - else - { - block->newtx = 1; - iguana_blockQ("recvhash6",coin,0,-7,blockhashes[1],0); // should be RT block } + block->newtx = 1; + iguana_blockQ("recvhash6",coin,0,-7,blockhashes[1],0); // should be RT block } return(req); } @@ -798,7 +792,7 @@ struct iguana_bundlereq *iguana_recvblock(struct iguana_info *coin,struct iguana } if ( bp != 0 ) bp->dirty++; - if ( 0 )//&& bp != 0 && bp->hdrsi == coin->bundlescount-1 ) + if ( 1 )//&& bp != 0 && bp->hdrsi == coin->bundlescount-1 ) { int32_t i; static int32_t numrecv; numrecv++; diff --git a/iguana/iguana_unspents.c b/iguana/iguana_unspents.c index be31a7f50..6d7781094 100755 --- a/iguana/iguana_unspents.c +++ b/iguana/iguana_unspents.c @@ -267,7 +267,7 @@ cJSON *iguana_unspentjson(struct iguana_info *coin,int32_t hdrsi,uint32_t unspen jaddstr(item,"address",coinaddr); if ( (wacct= iguana_waddressfind(coin,&ind,coinaddr)) != 0 ) jaddstr(item,"account",wacct->account); - if ( iguana_scriptget(coin,scriptstr,asmstr,sizeof(scriptstr),hdrsi,unspentind,T[up->txidind].txid,up->vout,rmd160,up->type,pubkey33) != 0 ) + if ( bitcoin_pubkeylen(pubkey33) > 0 && iguana_scriptget(coin,scriptstr,asmstr,sizeof(scriptstr),hdrsi,unspentind,T[up->txidind].txid,up->vout,rmd160,up->type,pubkey33) != 0 ) jaddstr(item,"scriptPubKey",scriptstr); jaddnum(item,"amount",dstr(up->value)); if ( iguana_txidfind(coin,&height,&TX,T[up->txidind].txid,coin->bundlescount-1) != 0 ) @@ -1087,7 +1087,7 @@ int32_t iguana_realtime_update(struct iguana_info *coin) } if ( dest != 0 ) printf(">>>> RT.%d:%d hwm.%d L.%d T.%d U.%d S.%d P.%d X.%d -> size.%ld\n",coin->RTheight,n,coin->blocks.hwmchain.height,coin->longestchain,dest->H.txidind,dest->H.unspentind,dest->H.spendind,dest->pkind,dest->externalind,(long)dest->H.data->allocsize); - return(0); + return(flag); } int32_t iguana_balanceflush(struct iguana_info *coin,int32_t refhdrsi,int32_t purgedist) @@ -1294,7 +1294,31 @@ int32_t iguana_bundlevalidate(struct iguana_info *coin,struct iguana_bundle *bp) TWOSTRINGS_AND_INT(iguana,balance,activecoin,address,height) { - cJSON *retjson = cJSON_CreateObject(); + int32_t minconf=1,maxconf=SATOSHIDEN; int64_t total; uint8_t rmd160[20],pubkey33[33],addrtype; + struct iguana_pkhash *P; cJSON *array,*retjson = cJSON_CreateObject(); + if ( coin != 0 ) + { + jaddstr(retjson,"address",address); + if ( bitcoin_validaddress(coin,address) < 0 ) + { + jaddstr(retjson,"error","illegal address"); + return(jprint(retjson,1)); + } + if ( bitcoin_addr2rmd160(&addrtype,rmd160,address) < 0 ) + { + jaddstr(retjson,"error","cant convert address"); + return(jprint(retjson,1)); + } + if ( height != 0 ) + jaddnum(retjson,"height",height); + memset(pubkey33,0,sizeof(pubkey33)); + P = calloc(coin->bundlescount,sizeof(*P)); + array = cJSON_CreateArray(); + iguana_pkhasharray(coin,array,minconf,maxconf,&total,P,coin->bundlescount,rmd160,address,pubkey33); + free(P); + jadd(retjson,"unspents",array); + jaddnum(retjson,"balance",dstr(total)); + } return(jprint(retjson,1)); } #include "../includes/iguana_apiundefs.h" diff --git a/iguana/main.c b/iguana/main.c index 6c7cc79d2..d78dfd8e6 100755 --- a/iguana/main.c +++ b/iguana/main.c @@ -358,7 +358,11 @@ void mainloop(struct supernet_info *myinfo) if ( coin->active != 0 && coin->started != 0 ) { coin->RTramchain_busy = 1; - iguana_realtime_update(coin); + if ( iguana_realtime_update(coin) > 0 ) + { + printf("call RT update\n"); + flag++; + } if ( (ptr= queue_dequeue(&balancesQ,0)) != 0 ) { flag++; @@ -396,7 +400,7 @@ void mainloop(struct supernet_info *myinfo) iguana_jsonQ(); pangea_queues(SuperNET_MYINFO(0)); if ( flag == 0 ) - usleep(100000); + usleep(1000000); } } @@ -1152,12 +1156,12 @@ void iguana_main(void *arg) if ( (coinargs= SuperNET_keysinit(&MYINFO,arg)) != 0 ) iguana_launch(btcd,"iguana_coins",iguana_coins,coinargs,IGUANA_PERMTHREAD); #ifdef __APPLE__ - else if ( 1 ) + else if ( 0 ) { sleep(1); char *str; //iguana_launchcoin(MYINFO.rpcsymbol,cJSON_Parse("{}")); - if ( 1 && (str= SuperNET_JSON(&MYINFO,cJSON_Parse("{\"startpend\":512,\"endpend\":128,\"userhome\":\"/Users/jimbolaptop/Library/Application Support\",\"agent\":\"iguana\",\"method\":\"addcoin\",\"services\":129,\"maxpeers\":512,\"newcoin\":\"BTCD\",\"active\":1,\"numhelpers\":4,\"poll\":1}"),0)) != 0 ) + if ( 1 && (str= SuperNET_JSON(&MYINFO,cJSON_Parse("{\"startpend\":512,\"endpend\":128,\"userhome\":\"/Users/jimbolaptop/Library/Application Support\",\"agent\":\"iguana\",\"method\":\"addcoin\",\"services\":128,\"maxpeers\":512,\"newcoin\":\"BTCD\",\"active\":1,\"numhelpers\":4,\"poll\":1}"),0)) != 0 ) { free(str); if ( 0 && (str= SuperNET_JSON(&MYINFO,cJSON_Parse("{\"userhome\":\"/Users/jimbolaptop/Library/Application Support\",\"agent\":\"iguana\",\"method\":\"addcoin\",\"services\":1024,\"maxpeers\":256,\"newcoin\":\"BTCD\",\"active\":1}"),0)) != 0 )