diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 4fe15c882..dcc65a31c 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -426,7 +426,13 @@ int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int memset(zero.bytes,0,sizeof(zero)); if ( time(NULL) > coin->lastgetinfo+LP_GETINFO_INCR ) { - if ( (obj= LP_getinfo(coin->symbol)) != 0 ) + if ( (height= LP_getheight(coin)) > coin->longestchain ) + { + coin->longestchain = height; + if ( coin->firstrefht != 0 ) + printf(">>>>>>>>>> set %s longestchain %d (ref.%d [%d, %d])\n",coin->symbol,height,coin->firstrefht,coin->firstscanht,coin->lastscanht); + } else LP_mempoolscan(coin->symbol,zero); + /*if ( (obj= LP_getinfo(coin->symbol)) != 0 ) { if ( (height= jint(obj,"blocks")) > coin->longestchain ) { @@ -435,7 +441,7 @@ int32_t LP_mainloop_iter(void *ctx,char *myipaddr,struct LP_peerinfo *mypeer,int printf(">>>>>>>>>> set %s longestchain %d (ref.%d [%d, %d])\n",coin->symbol,height,coin->firstrefht,coin->firstscanht,coin->lastscanht); } else LP_mempoolscan(coin->symbol,zero); free_json(obj); - } else printf("error getting info.%s\n",coin->symbol); + } else printf("error getting info.%s\n",coin->symbol);*/ coin->lastgetinfo = (uint32_t)time(NULL); } if ( coin->firstrefht == 0 ) diff --git a/iguana/exchanges/LP_rpc.c b/iguana/exchanges/LP_rpc.c index 579578611..217f434c0 100644 --- a/iguana/exchanges/LP_rpc.c +++ b/iguana/exchanges/LP_rpc.c @@ -105,9 +105,22 @@ char *issue_LP_getprices(char *destip,uint16_t destport) cJSON *bitcoin_json(struct iguana_info *coin,char *method,char *params) { - char *retstr; cJSON *retjson = 0; - //retstr = bitcoind_passthru("BTC","46.4.125.2:50001","",method,params); - //printf("%s %s -> %s\n",method,params,retstr); + static uint32_t stratumid; + char *retstr,stratumreq[8192]; cJSON *retjson = 0; + // "getinfo", "getrawmempool", "paxprice", "gettxout", "getrawtransaction", "getblock", "listunspent", "listtransactions", "validateaddress", "importprivkey" + // bitcoind_passthru callers: "importaddress", "estimatefee", "getblockhash", "sendrawtransaction", "signrawtransaction" + + //"server.version", "server.banner", "server.donation_address", "server.peers.subscribe", "--blockchain.numblocks.subscribe", "blockchain.headers.subscribe", "blockchain.address.subscribe", "blockchain.address.get_history", "blockchain.address.get_mempool", "blockchain.address.get_balance", "--blockchain.address.get_proof", "blockchain.address.listunspent", "--blockchain.utxo.get_address", "blockchain.block.get_header", "blockchain.block.get_chunk", "blockchain.transaction.broadcast", "blockchain.transaction.get_merkle", "blockchain.transaction.get", "blockchain.estimatefee" + + // 1.1: "blockchain.scripthash.get_balance", "blockchain.scripthash.get_history", "blockchain.scripthash.get_mempool", "blockchain.scripthash.listunspent", "blockchain.scripthash.subscribe", "server.features", "server.add_peer" + method = "server.version"; + params = "[]"; + sprintf(stratumreq,"{ \"id\": %u, \"method\":\"%s\", \"params\": %s }",stratumid++,method,params); + if ( (retstr= issue_curlt("46.4.125.2:50001",LP_HTTP_TIMEOUT*5)) != 0 ) + { + printf("%s %s -> %s\n",method,params,retstr); + free(retstr); + } if ( coin != 0 ) { //printf("issue.(%s, %s, %s, %s, %s)\n",coin->symbol,coin->serverport,coin->userpass,method,params); @@ -165,10 +178,15 @@ cJSON *LP_assethbla(char *assetid) return(retjson); } -cJSON *LP_getinfo(char *symbol) +int32_t LP_getheight(struct iguana_info *coin) { - struct iguana_info *coin = LP_coinfind(symbol); - return(bitcoin_json(coin,"getinfo","[]")); + cJSON *retjson; int32_t height = -1; //struct iguana_info *coin = LP_coinfind(symbol); + if ( (retjson= bitcoin_json(coin,"getinfo","[]")) != 0 ) + { + height = jint(retjson,"blocks"); + free_json(retjson); + } + return(height); } cJSON *LP_getmempool(char *symbol) @@ -207,6 +225,25 @@ cJSON *LP_getblock(char *symbol,bits256 txid) return(bitcoin_json(coin,"getblock",buf)); } +int32_t LP_txheight(uint32_t *timestampp,uint32_t *blocktimep,struct iguana_info *coin,bits256 txid) +{ + bits256 blockhash; cJSON *blockobj,*txobj; int32_t height = 0; + if ( (txobj= LP_gettx(coin->symbol,txid)) != 0 ) + { + *timestampp = juint(txobj,"locktime"); + *blocktimep = juint(txobj,"blocktime"); + blockhash = jbits256(txobj,"blockhash"); + if ( bits256_nonz(blockhash) != 0 && (blockobj= LP_getblock(coin->symbol,blockhash)) != 0 ) + { + height = jint(blockobj,"height"); + //printf("%s LP_txheight.%d\n",coin->symbol,height); + free_json(blockobj); + } //else printf("%s LP_txheight error (%s)\n",coin->symbol,jprint(txobj,0)); + free_json(txobj); + } + return(height); +} + cJSON *LP_getblockhashstr(char *symbol,char *blockhashstr) { char buf[128]; struct iguana_info *coin = LP_coinfind(symbol); @@ -331,6 +368,33 @@ char *LP_blockhashstr(char *symbol,int32_t height) return(retstr); } +cJSON *LP_blockjson(int32_t *heightp,char *symbol,char *blockhashstr,int32_t height) +{ + cJSON *json = 0; int32_t flag = 0; + if ( blockhashstr == 0 ) + blockhashstr = LP_blockhashstr(symbol,height), flag = 1; + if ( blockhashstr != 0 ) + { + if ( (json= LP_getblockhashstr(symbol,blockhashstr)) != 0 ) + { + if ( *heightp != 0 ) + { + *heightp = juint(json,"height"); + if ( height >= 0 && *heightp != height ) + { + printf("unexpected height %d vs %d for %s (%s)\n",*heightp,height,blockhashstr,jprint(json,0)); + *heightp = -1; + free_json(json); + json = 0; + } + } + } + if ( flag != 0 && blockhashstr != 0 ) + free(blockhashstr); + } + return(json); +} + char *LP_sendrawtransaction(char *symbol,char *signedtx) { cJSON *array; char *paramstr,*retstr; struct iguana_info *coin = LP_coinfind(symbol); @@ -384,31 +448,3 @@ char *LP_signrawtx(char *symbol,bits256 *signedtxidp,int32_t *completedp,cJSON * free(paramstr); return(signedtx); } - -cJSON *LP_blockjson(int32_t *heightp,char *symbol,char *blockhashstr,int32_t height) -{ - cJSON *json = 0; int32_t flag = 0; - if ( blockhashstr == 0 ) - blockhashstr = LP_blockhashstr(symbol,height), flag = 1; - if ( blockhashstr != 0 ) - { - if ( (json= LP_getblockhashstr(symbol,blockhashstr)) != 0 ) - { - if ( *heightp != 0 ) - { - *heightp = juint(json,"height"); - if ( height >= 0 && *heightp != height ) - { - printf("unexpected height %d vs %d for %s (%s)\n",*heightp,height,blockhashstr,jprint(json,0)); - *heightp = -1; - free_json(json); - json = 0; - } - } - } - if ( flag != 0 && blockhashstr != 0 ) - free(blockhashstr); - } - return(json); -} - diff --git a/iguana/exchanges/LP_scan.c b/iguana/exchanges/LP_scan.c index b4ff5e23e..4d0812a40 100644 --- a/iguana/exchanges/LP_scan.c +++ b/iguana/exchanges/LP_scan.c @@ -75,25 +75,6 @@ struct LP_transaction *LP_transactionadd(struct iguana_info *coin,bits256 txid,i return(tx); } -int32_t LP_txheight(uint32_t *timestampp,uint32_t *blocktimep,struct iguana_info *coin,bits256 txid) -{ - bits256 blockhash; cJSON *blockobj,*txobj; int32_t height = 0; - if ( (txobj= LP_gettx(coin->symbol,txid)) != 0 ) - { - *timestampp = juint(txobj,"locktime"); - *blocktimep = juint(txobj,"blocktime"); - blockhash = jbits256(txobj,"blockhash"); - if ( bits256_nonz(blockhash) != 0 && (blockobj= LP_getblock(coin->symbol,blockhash)) != 0 ) - { - height = jint(blockobj,"height"); - //printf("%s LP_txheight.%d\n",coin->symbol,height); - free_json(blockobj); - } //else printf("%s LP_txheight error (%s)\n",coin->symbol,jprint(txobj,0)); - free_json(txobj); - } - return(height); -} - int32_t LP_undospends(struct iguana_info *coin,int32_t lastheight) { int32_t i,ht,num = 0; uint32_t timestamp,blocktime; struct LP_transaction *tx,*tmp; diff --git a/iguana/exchanges/LP_statemachine.c b/iguana/exchanges/LP_statemachine.c index dcb67c8a9..860c796e1 100644 --- a/iguana/exchanges/LP_statemachine.c +++ b/iguana/exchanges/LP_statemachine.c @@ -446,7 +446,6 @@ void iguana_ensure_privkey(struct iguana_info *coin,bits256 privkey) } } } -#endif int32_t basilisk_rawtx_return(struct basilisk_rawtx *rawtx,cJSON *item,int32_t lockinputs,struct vin_info *V) @@ -484,6 +483,7 @@ int32_t basilisk_rawtx_return(struct basilisk_rawtx *rawtx,cJSON *item,int32_t l } return(retval); } +#endif cJSON *LP_createvins(struct basilisk_rawtx *dest,struct vin_info *V,struct basilisk_rawtx *rawtx,uint8_t *userdata,int32_t userdatalen,uint32_t sequenceid) {