Browse Source

test

etomic
jl777 8 years ago
parent
commit
43235cf745
  1. 4
      basilisk/basilisk_bitcoin.c
  2. 14
      iguana/dPoW.h
  3. 64
      iguana/dpow/dpow_network.c
  4. 25
      iguana/iguana_notary.c
  5. 2
      iguana/tests/dexgetB
  6. 2
      iguana/tests/dexgetH
  7. 2
      iguana/tests/dexgetbestblockhash
  8. 2
      iguana/tests/dexgetinfo
  9. 4
      includes/iguana_apideclares.h

4
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 )
{

14
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

64
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;

25
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"

2
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\"}"

2
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\"}"

2
iguana/tests/dexgetbestblockhash

@ -0,0 +1,2 @@
#!/bin/bash
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"getbestblockhash\",\"symbol\":\"BTC\"}"

2
iguana/tests/dexgetinfo

@ -0,0 +1,2 @@
#!/bin/bash
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"getinfo\",\"symbol\":\"BTC\"}"

4
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);

Loading…
Cancel
Save