From 43235cf745fd57d83a1c202438af925b98d6f56a Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 27 Dec 2016 10:29:38 +0200 Subject: [PATCH] test --- basilisk/basilisk_bitcoin.c | 4 +- iguana/dPoW.h | 14 +++++-- iguana/dpow/dpow_network.c | 64 ++++++++++++++++++++++++++++---- iguana/iguana_notary.c | 25 ++++++++++++- iguana/tests/dexgetB | 2 + iguana/tests/dexgetH | 2 + iguana/tests/dexgetbestblockhash | 2 + iguana/tests/dexgetinfo | 2 + includes/iguana_apideclares.h | 4 ++ 9 files changed, 106 insertions(+), 13 deletions(-) create mode 100755 iguana/tests/dexgetB create mode 100755 iguana/tests/dexgetH create mode 100755 iguana/tests/dexgetbestblockhash create mode 100755 iguana/tests/dexgetinfo diff --git a/basilisk/basilisk_bitcoin.c b/basilisk/basilisk_bitcoin.c index 665f3c9d7..dcc261f89 100755 --- a/basilisk/basilisk_bitcoin.c +++ b/basilisk/basilisk_bitcoin.c @@ -938,7 +938,7 @@ HASH_ARRAY_STRING(basilisk,value,hash,vals,hexstr) } if ( myinfo->reqsock >= 0 ) { - if ( (retstr= dex_getrawtransaction(myinfo,symbol,txid)) != 0 ) + if ( (retstr= _dex_getrawtransaction(myinfo,symbol,txid)) != 0 ) { if ( (txoutjson= cJSON_Parse(retstr)) != 0 ) { @@ -955,7 +955,7 @@ HASH_ARRAY_STRING(basilisk,value,hash,vals,hexstr) jaddstr(retjson,"address",coinaddr); jadd64bits(retjson,"satoshis",value); jaddnum(retjson,"value",dstr(value)); - if ( (infostr= dex_getinfo(myinfo,symbol)) != 0 ) + if ( (infostr= _dex_getinfo(myinfo,symbol)) != 0 ) { if ( (info= cJSON_Parse(infostr)) != 0 ) { diff --git a/iguana/dPoW.h b/iguana/dPoW.h index 195597767..63b9e2f2c 100755 --- a/iguana/dPoW.h +++ b/iguana/dPoW.h @@ -148,9 +148,17 @@ cJSON *dpow_gettxout(struct supernet_info *myinfo,struct iguana_info *coin,bits2 int32_t dpow_getchaintip(struct supernet_info *myinfo,bits256 *blockhashp,uint32_t *blocktimep,bits256 *txs,uint32_t *numtxp,struct iguana_info *coin); void dpow_send(struct supernet_info *myinfo,struct dpow_info *dp,struct dpow_block *bp,bits256 srchash,bits256 desthash,uint32_t channel,uint32_t msgbits,uint8_t *data,int32_t datalen); 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); + cJSON *dpow_getinfo(struct supernet_info *myinfo,struct iguana_info *coin); +cJSON *dpow_gettransaction(struct supernet_info *myinfo,struct iguana_info *coin,bits256 txid); +cJSON *dpow_getblock(struct supernet_info *myinfo,struct iguana_info *coin,bits256 blockhash); +bits256 dpow_getblockhash(struct supernet_info *myinfo,struct iguana_info *coin,int32_t height); +bits256 dpow_getbestblockhash(struct supernet_info *myinfo,struct iguana_info *coin); + +char *_dex_getinfo(struct supernet_info *myinfo,char *symbol); +char *_dex_getrawtransaction(struct supernet_info *myinfo,char *symbol,bits256 txid); +char *_dex_getblock(struct supernet_info *myinfo,char *symbol,bits256 hash2); +char *_dex_getblockhash(struct supernet_info *myinfo,char *symbol,int32_t height); +char *_dex_getbestblockhash(struct supernet_info *myinfo,char *symbol); #endif diff --git a/iguana/dpow/dpow_network.c b/iguana/dpow/dpow_network.c index 6dbc62e9e..119f36a6c 100755 --- a/iguana/dpow/dpow_network.c +++ b/iguana/dpow/dpow_network.c @@ -68,12 +68,13 @@ void dex_packet(struct supernet_info *myinfo,struct dex_nanomsghdr *dexp,int32_t } } -struct dex_request { bits256 txid; char name[15]; uint8_t func; }; +struct dex_request { bits256 hash; int32_t height; char name[15]; uint8_t func; }; int32_t dex_rwrequest(int32_t rwflag,uint8_t *serialized,struct dex_request *dexreq) { int32_t len = 0; - len += iguana_rwbignum(rwflag,&serialized[len],sizeof(dexreq->txid),dexreq->txid.bytes); + len += iguana_rwbignum(rwflag,&serialized[len],sizeof(dexreq->hash),dexreq->hash.bytes); + len += iguana_rwnum(rwflag,&serialized[len],sizeof(dexreq->height),&dexreq->height); if ( rwflag != 0 ) { memcpy(&serialized[len],dexreq->name,sizeof(dexreq->name)), len += sizeof(dexreq->name); @@ -89,7 +90,7 @@ int32_t dex_rwrequest(int32_t rwflag,uint8_t *serialized,struct dex_request *dex char *dex_response(struct supernet_info *myinfo,struct dex_nanomsghdr *dexp) { - char *retstr = 0; cJSON *retjson; struct iguana_info *coin; struct dex_request dexreq; + char buf[65],*retstr = 0; bits256 hash2; cJSON *retjson; struct iguana_info *coin; struct dex_request dexreq; dex_rwrequest(0,dexp->packet,&dexreq); printf("(%s) dex_response.%s (%c)\n",dexp->handler,dexreq.name,dexreq.func); if ( strcmp(dexp->handler,"request") == 0 ) @@ -100,7 +101,18 @@ char *dex_response(struct supernet_info *myinfo,struct dex_nanomsghdr *dexp) { if ( dexreq.func == 'T' ) { - if ( (retjson= dpow_gettransaction(myinfo,coin,dexreq.txid)) != 0 ) + if ( (retjson= dpow_gettransaction(myinfo,coin,dexreq.hash)) != 0 ) + retstr = jprint(retjson,1); + } + else if ( dexreq.func == 'H' ) + { + hash2 = dpow_getblockhash(myinfo,coin,dexreq.height); + bits256_str(buf,hash2); + retstr = clonestr(buf); + } + else if ( dexreq.func == 'B' ) + { + if ( (retjson= dpow_getblock(myinfo,coin,dexreq.hash)) != 0 ) retstr = jprint(retjson,1); } else if ( dexreq.func == 'I' ) @@ -108,6 +120,12 @@ char *dex_response(struct supernet_info *myinfo,struct dex_nanomsghdr *dexp) if ( (retjson= dpow_getinfo(myinfo,coin)) != 0 ) retstr = jprint(retjson,1); } + else if ( dexreq.func == 'P' ) + { + hash2 = dpow_getbestblockhash(myinfo,coin); + bits256_str(buf,hash2); + retstr = clonestr(buf); + } } if ( retstr == 0 ) return(clonestr("{\"error\":\"null return\"}")); @@ -233,18 +251,18 @@ char *dex_reqsend(struct supernet_info *myinfo,char *handler,uint8_t *data,int32 return(retstr); } -char *dex_getrawtransaction(struct supernet_info *myinfo,char *symbol,bits256 txid) +char *_dex_getrawtransaction(struct supernet_info *myinfo,char *symbol,bits256 txid) { 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.txid = txid; + dexreq.hash = txid; dexreq.func = 'T'; datalen = dex_rwrequest(1,packet,&dexreq); return(dex_reqsend(myinfo,"request",packet,datalen)); } -char *dex_getinfo(struct supernet_info *myinfo,char *symbol) +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)); @@ -254,6 +272,38 @@ char *dex_getinfo(struct supernet_info *myinfo,char *symbol) return(dex_reqsend(myinfo,"request",packet,datalen)); } +char *_dex_getblock(struct supernet_info *myinfo,char *symbol,bits256 hash2) +{ + 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.hash = hash2; + dexreq.func = 'B'; + datalen = dex_rwrequest(1,packet,&dexreq); + return(dex_reqsend(myinfo,"request",packet,datalen)); +} + +char *_dex_getblockhash(struct supernet_info *myinfo,char *symbol,int32_t height) +{ + 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.height = height; + dexreq.func = 'H'; + datalen = dex_rwrequest(1,packet,&dexreq); + return(dex_reqsend(myinfo,"request",packet,datalen)); +} + +char *_dex_getbestblockhash(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 = 'P'; + 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/iguana_notary.c b/iguana/iguana_notary.c index 13acf7414..0a20a5356 100755 --- a/iguana/iguana_notary.c +++ b/iguana/iguana_notary.c @@ -505,8 +505,31 @@ TWOINTS_AND_ARRAY(dpow,ratify,minsigs,timestamp,ratified) HASH_AND_STRING(dex,gettransaction,txid,symbol) { - return(dex_getrawtransaction(myinfo,symbol,txid)); + return(_dex_getrawtransaction(myinfo,symbol,txid)); } + +STRING_ARG(dex,getinfo,symbol) +{ + return(_dex_getinfo(myinfo,symbol)); +} + +STRING_ARG(dex,getbestblockhash,symbol) +{ + return(_dex_getbestblockhash(myinfo,symbol)); +} + +STRING_AND_INT(dex,getblockhash,symbol,height) +{ + return(_dex_getblockhash(myinfo,symbol,height)); +} + +HASH_AND_STRING(dex,getblock,hash,symbol) +{ + return(_dex_getblock(myinfo,symbol,hash)); +} + + + #include "../includes/iguana_apiundefs.h" diff --git a/iguana/tests/dexgetB b/iguana/tests/dexgetB new file mode 100755 index 000000000..6de5f1e08 --- /dev/null +++ b/iguana/tests/dexgetB @@ -0,0 +1,2 @@ +#!/bin/bash +curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"getblock\",\"hash\":\"0000000000000000033245c0bd104a80c2a7ed7e04330e034d4833f9928d18e7\",\"symbol\":\"BTC\"}" diff --git a/iguana/tests/dexgetH b/iguana/tests/dexgetH new file mode 100755 index 000000000..8b1963442 --- /dev/null +++ b/iguana/tests/dexgetH @@ -0,0 +1,2 @@ +#!/bin/bash +curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"getblockhash\",\"height\":400000,\"symbol\":\"BTC\"}" diff --git a/iguana/tests/dexgetbestblockhash b/iguana/tests/dexgetbestblockhash new file mode 100755 index 000000000..45b501dcc --- /dev/null +++ b/iguana/tests/dexgetbestblockhash @@ -0,0 +1,2 @@ +#!/bin/bash +curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"getbestblockhash\",\"symbol\":\"BTC\"}" diff --git a/iguana/tests/dexgetinfo b/iguana/tests/dexgetinfo new file mode 100755 index 000000000..d31b736a6 --- /dev/null +++ b/iguana/tests/dexgetinfo @@ -0,0 +1,2 @@ +#!/bin/bash +curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"getinfo\",\"symbol\":\"BTC\"}" diff --git a/includes/iguana_apideclares.h b/includes/iguana_apideclares.h index 2c3ec351c..4e4ce4927 100755 --- a/includes/iguana_apideclares.h +++ b/includes/iguana_apideclares.h @@ -22,6 +22,10 @@ THREE_STRINGS(iguana,passthru,asset,function,hex); STRING_ARG(dpow,bindaddr,ipaddr); TWO_STRINGS(dex,send,hex,handler); HASH_AND_STRING(dex,gettransaction,txid,symbol); +STRING_ARG(dex,getinfo,symbol); +STRING_ARG(dex,getbestblockhash,symbol); +STRING_AND_INT(dex,getblockhash,symbol,height); +HASH_AND_STRING(dex,getblock,hash,symbol); TWO_STRINGS(zcash,passthru,function,hex); TWO_STRINGS(komodo,passthru,function,hex);