diff --git a/basilisk/basilisk_bitcoin.c b/basilisk/basilisk_bitcoin.c index 89a8d23d7..665f3c9d7 100755 --- a/basilisk/basilisk_bitcoin.c +++ b/basilisk/basilisk_bitcoin.c @@ -882,7 +882,7 @@ cJSON *BTC_makeclaimfunc(struct supernet_info *myinfo,struct exchange_info *exch HASH_ARRAY_STRING(basilisk,value,hash,vals,hexstr) { - char *retstr=0,*symbol,*coinaddr; cJSON *retjson,*txoutjson,*txjson,*array; uint32_t basilisktag,blocktime; bits256 txid,blockhash; struct basilisk_item *ptr,Lptr; uint64_t value; int32_t timeoutmillis,vout,height,n; + char *retstr=0,*symbol,*coinaddr,*infostr; cJSON *retjson,*sobj,*info,*addrs,*txoutjson,*txjson,*array; uint32_t basilisktag,blocktime; bits256 txid,blockhash; struct basilisk_item *ptr,Lptr; uint64_t value; int32_t timeoutmillis,vout,height,n,m; if ( vals == 0 ) return(clonestr("{\"error\":\"null valsobj\"}")); //if ( myinfo->IAMNOTARY != 0 || myinfo->NOTARY.RELAYID >= 0 ) @@ -938,34 +938,44 @@ HASH_ARRAY_STRING(basilisk,value,hash,vals,hexstr) } if ( myinfo->reqsock >= 0 ) { - if ( coin != 0 && (retstr= dex_getrawtransaction(myinfo,coin->symbol,txid)) != 0 ) + if ( (retstr= dex_getrawtransaction(myinfo,symbol,txid)) != 0 ) { if ( (txoutjson= cJSON_Parse(retstr)) != 0 ) { - printf("TX.(%s)\n",jprint(txoutjson,0)); + //printf("TX.(%s)\n",jprint(txoutjson,0)); retjson = cJSON_CreateObject(); jaddstr(retjson,"result","success"); + jaddnum(retjson,"numconfirms",jint(txoutjson,"confirmations")); if ( (array= jarray(&n,txoutjson,"vout")) != 0 && vout < n && (txjson= jitem(array,vout)) != 0 ) { - printf("txjson.(%s)\n",jprint(txjson,0)); - if ( (coinaddr= jstr(txoutjson,"address")) != 0 && (value= j64bits(txjson,"value") * SATOSHIDEN) != 0 ) + //printf("txjson.(%s)\n",jprint(txjson,0)); + if ( (value= jdouble(txjson,"value") * SATOSHIDEN) != 0 ) { - jaddstr(retjson,"address",coinaddr); + if ( (sobj= jobj(txjson,"scriptPubKey")) != 0 && (addrs= jarray(&m,sobj,"addresses")) != 0 && (coinaddr= jstri(addrs,0)) != 0 ) + jaddstr(retjson,"address",coinaddr); jadd64bits(retjson,"satoshis",value); jaddnum(retjson,"value",dstr(value)); - //height = dpow_getchaintip(myinfo,&blockhash,&blocktime,0,0,coin); - //jaddnum(retjson,"height",height); - jaddnum(retjson,"numconfirms",jint(txjson,"confirmations")); - + if ( (infostr= dex_getinfo(myinfo,symbol)) != 0 ) + { + if ( (info= cJSON_Parse(infostr)) != 0 ) + { + if ( (height= jint(info,"blocks")) > 0 ) + { + height -= jint(txoutjson,"confirmations"); + jaddnum(retjson,"height",height); + } + free_json(info); + } + free(infostr); + } jaddbits256(retjson,"txid",txid); jaddnum(retjson,"vout",vout); - jaddstr(retjson,"coin",coin->symbol); + jaddstr(retjson,"coin",symbol); free(retstr); free_json(txoutjson); return(jprint(retjson,1)); } } - jaddnum(retjson,"numconfirms",0); free_json(txoutjson); return(jprint(retjson,1)); } diff --git a/iguana/dPoW.h b/iguana/dPoW.h index eb94a0057..15a481784 100755 --- a/iguana/dPoW.h +++ b/iguana/dPoW.h @@ -150,5 +150,6 @@ void dpow_send(struct supernet_info *myinfo,struct dpow_info *dp,struct dpow_blo int32_t dpow_nanomsg_update(struct supernet_info *myinfo); char *dex_getrawtransaction(struct supernet_info *myinfo,char *symbol,bits256 txid); cJSON *dpow_gettransaction(struct supernet_info *myinfo,struct iguana_info *coin,bits256 txid); +char *dex_getinfo(struct supernet_info *myinfo,char *symbol); #endif diff --git a/iguana/dpow/dpow_network.c b/iguana/dpow/dpow_network.c index c7aabe834..6c3c32814 100755 --- a/iguana/dpow/dpow_network.c +++ b/iguana/dpow/dpow_network.c @@ -101,6 +101,10 @@ char *dex_response(struct supernet_info *myinfo,struct dex_nanomsghdr *dexp) if ( (retjson= dpow_gettransaction(myinfo,coin,dexreq.txid)) != 0 ) retstr = jprint(retjson,1); } + else if ( dexreq.func == 'I' ) + { + + } } if ( retstr == 0 ) return(clonestr("{\"error\":\"null return\"}")); @@ -199,7 +203,7 @@ char *dex_reqsend(struct supernet_info *myinfo,char *handler,uint8_t *data,int32 else { retstr = clonestr((char *)retptr); - printf("REQ got.%d (%s)\n",recvbytes,retstr); + //printf("REQ got.%d (%s)\n",recvbytes,retstr); } nn_freemsg(retptr); portable_mutex_unlock(&myinfo->dexmutex); @@ -226,6 +230,16 @@ char *dex_getrawtransaction(struct supernet_info *myinfo,char *symbol,bits256 tx return(dex_reqsend(myinfo,"request",packet,datalen)); } +char *dex_getinfo(struct supernet_info *myinfo,char *symbol) +{ + struct dex_request dexreq; uint8_t packet[sizeof(dexreq)]; int32_t datalen; + memset(&dexreq,0,sizeof(dexreq)); + safecopy(dexreq.name,symbol,sizeof(dexreq.name)); + dexreq.func = 'I'; + datalen = dex_rwrequest(1,packet,&dexreq); + return(dex_reqsend(myinfo,"request",packet,datalen)); +} + int32_t dex_crc32find(struct supernet_info *myinfo,uint32_t crc32) { int32_t i,firstz = -1; diff --git a/iguana/dpow/dpow_rpc.c b/iguana/dpow/dpow_rpc.c index a2c9fd3a1..2d32d6c34 100755 --- a/iguana/dpow/dpow_rpc.c +++ b/iguana/dpow/dpow_rpc.c @@ -146,6 +146,31 @@ bits256 dpow_getblockhash(struct supernet_info *myinfo,struct iguana_info *coin, return(blockhash); } +cJSON *dpow_getinfo(struct supernet_info *myinfo,struct iguana_info *coin) +{ + char buf[128],*retstr=0; cJSON *json = 0; + if ( coin->FULLNODE < 0 ) + { + buf[0] = 0; + retstr = bitcoind_passthru(coin->symbol,coin->chain->serverport,coin->chain->userpass,"getinfo",buf); + usleep(10000); + } + else if ( coin->FULLNODE > 0 || coin->VALIDATENODE > 0 ) + { + retstr = bitcoinrpc_getinfo(myinfo,coin,0,0); + } + else + { + return(0); + } + if ( retstr != 0 ) + { + json = cJSON_Parse(retstr); + free(retstr); + } + return(json); +} + cJSON *dpow_getblock(struct supernet_info *myinfo,struct iguana_info *coin,bits256 blockhash) { char buf[128],str[65],*retstr=0; cJSON *json = 0; diff --git a/iguana/tests/value b/iguana/tests/value new file mode 100755 index 000000000..e6e38ee74 --- /dev/null +++ b/iguana/tests/value @@ -0,0 +1,2 @@ +#!/bin/bash +curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"basilisk\",\"method\":\"value\",\"vals\":{\"vout\":0,\"txid\":\"aa82ebd1c5bd2a9e19214cbc959df1745378676fddfd6f4903930ac16485c7ae\",\"symbol\":\"BTC\"}}"