From aca793eb2af4f1823d7b69088561e6d8a113df8a Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 20 Apr 2016 21:37:47 -0500 Subject: [PATCH] test --- deprecated/obsolete.h | 194 +++++++++++++++++++++++++++++++++++++++ iguana/iguana_bundles.c | 4 +- iguana/iguana_tx.c | 194 --------------------------------------- iguana/iguana_unspents.c | 4 +- iguana/ramchain_api.c | 11 +-- 5 files changed, 203 insertions(+), 204 deletions(-) diff --git a/deprecated/obsolete.h b/deprecated/obsolete.h index a8048fe5c..28ac3bf4c 100755 --- a/deprecated/obsolete.h +++ b/deprecated/obsolete.h @@ -15978,6 +15978,200 @@ len = 0; return(0); } //else printf("SCRIPT.%d MATCHED!\n",u->scriptlen); } // else would need to get from HDD to verify*/ + + /* + //char *hashstr,*txidstr,*coinaddr,*txbytes,rmd160str[41],str[65]; int32_t len,height,i,n,valid = 0; + //cJSON *addrs,*retjson,*retitem; uint8_t rmd160[20],addrtype; bits256 hash2,checktxid; + //memset(&hash2,0,sizeof(hash2)); struct iguana_txid *tx,T; struct iguana_block *block = 0; + + if ( (coinaddr= jstr(json,"address")) != 0 ) + { + if ( btc_addr2univ(&addrtype,rmd160,coinaddr) == 0 ) + { + if ( addrtype == coin->chain->pubval || addrtype == coin->chain->p2shval ) + valid = 1; + else return(clonestr("{\"error\":\"invalid addrtype\"}")); + } else return(clonestr("{\"error\":\"cant convert address to rmd160\"}")); + } + if ( strcmp(method,"block") == 0 ) + { + height = -1; + if ( ((hashstr= jstr(json,"blockhash")) != 0 || (hashstr= jstr(json,"hash")) != 0) && strlen(hashstr) == sizeof(bits256)*2 ) + decode_hex(hash2.bytes,sizeof(hash2),hashstr); + else + { + height = juint(json,"height"); + hash2 = iguana_blockhash(coin,height); + } + retitem = cJSON_CreateObject(); + if ( (block= iguana_blockfind(coin,hash2)) != 0 ) + { + if ( (height >= 0 && block->height == height) || memcmp(hash2.bytes,block->RO.hash2.bytes,sizeof(hash2)) == 0 ) + { + char str[65],str2[65]; printf("hash2.(%s) -> %s\n",bits256_str(str,hash2),bits256_str(str2,block->RO.hash2)); + return(jprint(iguana_blockjson(coin,block,juint(json,"txids")),1)); + } + } + else return(clonestr("{\"error\":\"cant find block\"}")); + } + else if ( strcmp(method,"tx") == 0 ) + { + if ( ((txidstr= jstr(json,"txid")) != 0 || (txidstr= jstr(json,"hash")) != 0) && strlen(txidstr) == sizeof(bits256)*2 ) + { + retitem = cJSON_CreateObject(); + decode_hex(hash2.bytes,sizeof(hash2),txidstr); + if ( (tx= iguana_txidfind(coin,&height,&T,hash2)) != 0 ) + { + jadd(retitem,"tx",iguana_txjson(coin,tx,height)); + return(jprint(retitem,1)); + } + return(clonestr("{\"error\":\"cant find txid\"}")); + } + else return(clonestr("{\"error\":\"invalid txid\"}")); + } + else if ( strcmp(method,"rawtx") == 0 ) + { + if ( ((txidstr= jstr(json,"txid")) != 0 || (txidstr= jstr(json,"hash")) != 0) && strlen(txidstr) == sizeof(bits256)*2 ) + { + decode_hex(hash2.bytes,sizeof(hash2),txidstr); + if ( (tx= iguana_txidfind(coin,&height,&T,hash2)) != 0 ) + { + if ( (len= iguana_txbytes(coin,coin->blockspace,sizeof(coin->blockspace),&checktxid,tx,height,0,0)) > 0 ) + { + txbytes = mycalloc('x',1,len*2+1); + init_hexbytes_noT(txbytes,coin->blockspace,len*2+1); + retitem = cJSON_CreateObject(); + jaddstr(retitem,"txid",bits256_str(str,hash2)); + jaddnum(retitem,"height",height); + jaddstr(retitem,"rawtx",txbytes); + myfree(txbytes,len*2+1); + return(jprint(retitem,1)); + } else return(clonestr("{\"error\":\"couldnt generate txbytes\"}")); + } + return(clonestr("{\"error\":\"cant find txid\"}")); + } + else return(clonestr("{\"error\":\"invalid txid\"}")); + } + else if ( strcmp(method,"txs") == 0 ) + { + if ( ((hashstr= jstr(json,"block")) != 0 || (hashstr= jstr(json,"blockhash")) != 0) && strlen(hashstr) == sizeof(bits256)*2 ) + { + decode_hex(hash2.bytes,sizeof(hash2),hashstr); + if ( (block= iguana_blockfind(coin,hash2)) == 0 ) + return(clonestr("{\"error\":\"cant find blockhash\"}")); + } + else if ( jobj(json,"height") != 0 ) + { + height = juint(json,"height"); + hash2 = iguana_blockhash(coin,height); + if ( (block= iguana_blockfind(coin,hash2)) == 0 ) + return(clonestr("{\"error\":\"cant find block at height\"}")); + } + else if ( valid == 0 ) + return(clonestr("{\"error\":\"txs needs blockhash or height or address\"}")); + retitem = cJSON_CreateArray(); + if ( block != 0 ) + { + for (i=0; iRO.txn_count; i++) + { + if ( (tx= iguana_blocktx(coin,&T,block,i)) != 0 ) + jaddi(retitem,iguana_txjson(coin,tx,-1)); + } + } + else + { + init_hexbytes_noT(rmd160str,rmd160,20); + jaddnum(retitem,"addrtype",addrtype); + jaddstr(retitem,"rmd160",rmd160str); + jaddstr(retitem,"txlist","get list of all tx for this address"); + } + return(jprint(retitem,1)); + } + + else + { + n = 0; + if ( valid == 0 ) + { + if ( (addrs= jarray(&n,json,"addrs")) == 0 ) + return(clonestr("{\"error\":\"need address or addrs\"}")); + } + for (i=0; i<=n; i++) + { + retitem = cJSON_CreateObject(); + if ( i > 0 ) + retjson = cJSON_CreateArray(); + if ( i > 0 ) + { + if ( (coinaddr= jstr(jitem(addrs,i-1),0)) == 0 ) + return(clonestr("{\"error\":\"missing address in addrs\"}")); + if ( btc_addr2univ(&addrtype,rmd160,coinaddr) < 0 ) + { + free_json(retjson); + return(clonestr("{\"error\":\"illegal address in addrs\"}")); + } + if ( addrtype != coin->chain->pubval && addrtype != coin->chain->p2shval ) + return(clonestr("{\"error\":\"invalid addrtype in addrs\"}")); + } + if ( strcmp(method,"utxo") == 0 ) + { + jaddstr(retitem,"utxo","utxo entry"); + } + else if ( strcmp(method,"unconfirmed") == 0 ) + { + jaddstr(retitem,"unconfirmed","unconfirmed entry"); + } + else if ( strcmp(method,"balance") == 0 ) + { + jaddstr(retitem,"balance","balance entry"); + } + else if ( strcmp(method,"totalreceived") == 0 ) + { + jaddstr(retitem,"totalreceived","totalreceived entry"); + } + else if ( strcmp(method,"totalsent") == 0 ) + { + jaddstr(retitem,"totalsent","totalsent entry"); + } + else if ( strcmp(method,"validateaddress") == 0 ) + { + jaddstr(retitem,"validate",coinaddr); + } + if ( n == 0 ) + return(jprint(retitem,1)); + else jaddi(retjson,retitem); + } + return(jprint(retjson,1)); + } + */ + + /* + char *iguana_listsinceblock(struct supernet_info *myinfo,struct iguana_info *coin,bits256 blockhash,int32_t target) + { + cJSON *retitem = cJSON_CreateObject(); + return(jprint(retitem,1)); + } + + char *iguana_getinfo(struct supernet_info *myinfo,struct iguana_info *coin) + { + cJSON *retitem = cJSON_CreateObject(); + jaddstr(retitem,"result",coin->statusstr); + return(jprint(retitem,1)); + } + + char *iguana_getbestblockhash(struct supernet_info *myinfo,struct iguana_info *coin) + { + cJSON *retitem = cJSON_CreateObject(); + char str[65]; jaddstr(retitem,"result",bits256_str(str,coin->blocks.hwmchain.RO.hash2)); + return(jprint(retitem,1)); + } + + char *iguana_getblockcount(struct supernet_info *myinfo,struct iguana_info *coin) + { + cJSON *retitem = cJSON_CreateObject(); + jaddnum(retitem,"result",coin->blocks.hwmchain.height); + return(jprint(retitem,1)); + }*/ #endif #endif diff --git a/iguana/iguana_bundles.c b/iguana/iguana_bundles.c index e4982903e..6aecd4fa9 100755 --- a/iguana/iguana_bundles.c +++ b/iguana/iguana_bundles.c @@ -729,7 +729,7 @@ int32_t iguana_bundleready(struct iguana_info *coin,struct iguana_bundle *bp,int } else { -#ifndef __PNACL__ +//#ifndef __PNACL__ int32_t checki,hdrsi; FILE *fp; fname[0] = 0; checki = iguana_peerfname(coin,&hdrsi,GLOBAL_TMPDIR,fname,0,block->RO.hash2,zero,1,0); @@ -744,7 +744,7 @@ int32_t iguana_bundleready(struct iguana_info *coin,struct iguana_bundle *bp,int fclose(fp); } else -#endif +//#endif { iguana_blockunmark(coin,block,bp,i,1); if ( requiredflag != 0 ) diff --git a/iguana/iguana_tx.c b/iguana/iguana_tx.c index 99621976a..a5005e651 100755 --- a/iguana/iguana_tx.c +++ b/iguana/iguana_tx.c @@ -325,197 +325,3 @@ cJSON *iguana_blockjson(struct iguana_info *coin,struct iguana_block *block,int3 return(json); } - -/* - //char *hashstr,*txidstr,*coinaddr,*txbytes,rmd160str[41],str[65]; int32_t len,height,i,n,valid = 0; - //cJSON *addrs,*retjson,*retitem; uint8_t rmd160[20],addrtype; bits256 hash2,checktxid; - //memset(&hash2,0,sizeof(hash2)); struct iguana_txid *tx,T; struct iguana_block *block = 0; - - if ( (coinaddr= jstr(json,"address")) != 0 ) - { - if ( btc_addr2univ(&addrtype,rmd160,coinaddr) == 0 ) - { - if ( addrtype == coin->chain->pubval || addrtype == coin->chain->p2shval ) - valid = 1; - else return(clonestr("{\"error\":\"invalid addrtype\"}")); - } else return(clonestr("{\"error\":\"cant convert address to rmd160\"}")); - } - if ( strcmp(method,"block") == 0 ) - { - height = -1; - if ( ((hashstr= jstr(json,"blockhash")) != 0 || (hashstr= jstr(json,"hash")) != 0) && strlen(hashstr) == sizeof(bits256)*2 ) - decode_hex(hash2.bytes,sizeof(hash2),hashstr); - else - { - height = juint(json,"height"); - hash2 = iguana_blockhash(coin,height); - } - retitem = cJSON_CreateObject(); - if ( (block= iguana_blockfind(coin,hash2)) != 0 ) - { - if ( (height >= 0 && block->height == height) || memcmp(hash2.bytes,block->RO.hash2.bytes,sizeof(hash2)) == 0 ) - { - char str[65],str2[65]; printf("hash2.(%s) -> %s\n",bits256_str(str,hash2),bits256_str(str2,block->RO.hash2)); - return(jprint(iguana_blockjson(coin,block,juint(json,"txids")),1)); - } - } - else return(clonestr("{\"error\":\"cant find block\"}")); - } - else if ( strcmp(method,"tx") == 0 ) - { - if ( ((txidstr= jstr(json,"txid")) != 0 || (txidstr= jstr(json,"hash")) != 0) && strlen(txidstr) == sizeof(bits256)*2 ) - { - retitem = cJSON_CreateObject(); - decode_hex(hash2.bytes,sizeof(hash2),txidstr); - if ( (tx= iguana_txidfind(coin,&height,&T,hash2)) != 0 ) - { - jadd(retitem,"tx",iguana_txjson(coin,tx,height)); - return(jprint(retitem,1)); - } - return(clonestr("{\"error\":\"cant find txid\"}")); - } - else return(clonestr("{\"error\":\"invalid txid\"}")); - } - else if ( strcmp(method,"rawtx") == 0 ) - { - if ( ((txidstr= jstr(json,"txid")) != 0 || (txidstr= jstr(json,"hash")) != 0) && strlen(txidstr) == sizeof(bits256)*2 ) - { - decode_hex(hash2.bytes,sizeof(hash2),txidstr); - if ( (tx= iguana_txidfind(coin,&height,&T,hash2)) != 0 ) - { - if ( (len= iguana_txbytes(coin,coin->blockspace,sizeof(coin->blockspace),&checktxid,tx,height,0,0)) > 0 ) - { - txbytes = mycalloc('x',1,len*2+1); - init_hexbytes_noT(txbytes,coin->blockspace,len*2+1); - retitem = cJSON_CreateObject(); - jaddstr(retitem,"txid",bits256_str(str,hash2)); - jaddnum(retitem,"height",height); - jaddstr(retitem,"rawtx",txbytes); - myfree(txbytes,len*2+1); - return(jprint(retitem,1)); - } else return(clonestr("{\"error\":\"couldnt generate txbytes\"}")); - } - return(clonestr("{\"error\":\"cant find txid\"}")); - } - else return(clonestr("{\"error\":\"invalid txid\"}")); - } - else if ( strcmp(method,"txs") == 0 ) - { - if ( ((hashstr= jstr(json,"block")) != 0 || (hashstr= jstr(json,"blockhash")) != 0) && strlen(hashstr) == sizeof(bits256)*2 ) - { - decode_hex(hash2.bytes,sizeof(hash2),hashstr); - if ( (block= iguana_blockfind(coin,hash2)) == 0 ) - return(clonestr("{\"error\":\"cant find blockhash\"}")); - } - else if ( jobj(json,"height") != 0 ) - { - height = juint(json,"height"); - hash2 = iguana_blockhash(coin,height); - if ( (block= iguana_blockfind(coin,hash2)) == 0 ) - return(clonestr("{\"error\":\"cant find block at height\"}")); - } - else if ( valid == 0 ) - return(clonestr("{\"error\":\"txs needs blockhash or height or address\"}")); - retitem = cJSON_CreateArray(); - if ( block != 0 ) - { - for (i=0; iRO.txn_count; i++) - { - if ( (tx= iguana_blocktx(coin,&T,block,i)) != 0 ) - jaddi(retitem,iguana_txjson(coin,tx,-1)); - } - } - else - { - init_hexbytes_noT(rmd160str,rmd160,20); - jaddnum(retitem,"addrtype",addrtype); - jaddstr(retitem,"rmd160",rmd160str); - jaddstr(retitem,"txlist","get list of all tx for this address"); - } - return(jprint(retitem,1)); - } - - else - { - n = 0; - if ( valid == 0 ) - { - if ( (addrs= jarray(&n,json,"addrs")) == 0 ) - return(clonestr("{\"error\":\"need address or addrs\"}")); - } - for (i=0; i<=n; i++) - { - retitem = cJSON_CreateObject(); - if ( i > 0 ) - retjson = cJSON_CreateArray(); - if ( i > 0 ) - { - if ( (coinaddr= jstr(jitem(addrs,i-1),0)) == 0 ) - return(clonestr("{\"error\":\"missing address in addrs\"}")); - if ( btc_addr2univ(&addrtype,rmd160,coinaddr) < 0 ) - { - free_json(retjson); - return(clonestr("{\"error\":\"illegal address in addrs\"}")); - } - if ( addrtype != coin->chain->pubval && addrtype != coin->chain->p2shval ) - return(clonestr("{\"error\":\"invalid addrtype in addrs\"}")); - } - if ( strcmp(method,"utxo") == 0 ) - { - jaddstr(retitem,"utxo","utxo entry"); - } - else if ( strcmp(method,"unconfirmed") == 0 ) - { - jaddstr(retitem,"unconfirmed","unconfirmed entry"); - } - else if ( strcmp(method,"balance") == 0 ) - { - jaddstr(retitem,"balance","balance entry"); - } - else if ( strcmp(method,"totalreceived") == 0 ) - { - jaddstr(retitem,"totalreceived","totalreceived entry"); - } - else if ( strcmp(method,"totalsent") == 0 ) - { - jaddstr(retitem,"totalsent","totalsent entry"); - } - else if ( strcmp(method,"validateaddress") == 0 ) - { - jaddstr(retitem,"validate",coinaddr); - } - if ( n == 0 ) - return(jprint(retitem,1)); - else jaddi(retjson,retitem); - } - return(jprint(retjson,1)); - } -*/ - -/* - char *iguana_listsinceblock(struct supernet_info *myinfo,struct iguana_info *coin,bits256 blockhash,int32_t target) - { - cJSON *retitem = cJSON_CreateObject(); - return(jprint(retitem,1)); - } - - char *iguana_getinfo(struct supernet_info *myinfo,struct iguana_info *coin) - { - cJSON *retitem = cJSON_CreateObject(); - jaddstr(retitem,"result",coin->statusstr); - return(jprint(retitem,1)); - } - - char *iguana_getbestblockhash(struct supernet_info *myinfo,struct iguana_info *coin) - { - cJSON *retitem = cJSON_CreateObject(); - char str[65]; jaddstr(retitem,"result",bits256_str(str,coin->blocks.hwmchain.RO.hash2)); - return(jprint(retitem,1)); - } - - char *iguana_getblockcount(struct supernet_info *myinfo,struct iguana_info *coin) - { - cJSON *retitem = cJSON_CreateObject(); - jaddnum(retitem,"result",coin->blocks.hwmchain.height); - return(jprint(retitem,1)); - }*/ diff --git a/iguana/iguana_unspents.c b/iguana/iguana_unspents.c index dccdf5ab5..39e2dac69 100755 --- a/iguana/iguana_unspents.c +++ b/iguana/iguana_unspents.c @@ -149,7 +149,7 @@ int32_t iguana_alloccacheT(struct iguana_info *coin,struct iguana_ramchain *ramc void iguana_volatilesalloc(struct iguana_info *coin,struct iguana_ramchain *ramchain,int32_t copyflag) { - struct iguana_ramchaindata *rdata; + struct iguana_ramchaindata *rdata = 0; if ( ramchain != 0 && (rdata= ramchain->H.data) != 0 ) { if ( ramchain->allocatedA == 0 ) @@ -178,7 +178,7 @@ void iguana_volatilesalloc(struct iguana_info *coin,struct iguana_ramchain *ramc ramchain->lastspendsfileptr = 0; ramchain->lastspendsfilesize = 0; } - } else printf("illegal ramchain.%p\n",ramchain); + } else printf("illegal ramchain.%p rdata.%p\n",ramchain,rdata); } void iguana_volatilespurge(struct iguana_info *coin,struct iguana_ramchain *ramchain) diff --git a/iguana/ramchain_api.c b/iguana/ramchain_api.c index 70b5539e6..01520d011 100755 --- a/iguana/ramchain_api.c +++ b/iguana/ramchain_api.c @@ -187,12 +187,11 @@ HASH_AND_INT(bitcoinrpc,getrawtransaction,txid,verbose) STRING_ARG(bitcoinrpc,decoderawtransaction,rawtx) { - uint8_t *data; int32_t datalen; cJSON *retjson = cJSON_CreateObject(); // struct iguana_msgtx msgtx; char *str; - datalen = (int32_t)strlen(rawtx) >> 1; - data = malloc(datalen); - decode_hex(data,datalen,rawtx); - free(data); - return(jprint(retjson,1)); + cJSON *txobj; bits256 txid; + if ( rawtx != 0 && rawtx[0] != 0 ) + txobj = bitcoin_hex2json(coin,&txid,0,rawtx); + else txobj = cJSON_CreateObject(); + return(jprint(txobj,1)); } HASH_ARG(bitcoinrpc,gettransaction,txid)