|
|
@ -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; i<block->RO.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 |
|
|
|