Browse Source

Merge pull request #164 from jl777/dev

Dev
win-cross
jl777 8 years ago
committed by GitHub
parent
commit
ae575c854d
  1. 34
      basilisk/basilisk_bitcoin.c
  2. 12
      iguana/dPoW.h
  3. 101
      iguana/dpow/dpow_network.c
  4. 31
      iguana/dpow/dpow_rpc.c
  5. 28
      iguana/iguana_notary.c
  6. 2
      iguana/tests/dexgetB
  7. 2
      iguana/tests/dexgetH
  8. 2
      iguana/tests/dexgetT
  9. 2
      iguana/tests/dexgetbestblockhash
  10. 2
      iguana/tests/dexgetinfo
  11. 2
      iguana/tests/value
  12. 5
      includes/iguana_apideclares.h

34
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));
}

12
iguana/dPoW.h

@ -148,7 +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_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

101
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,18 +90,40 @@ 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;
if ( strcmp(dexp->handler,"request") == 0 )
{
dex_rwrequest(0,dexp->packet,&dexreq);
//printf("dex_response.%s (%c)\n",dexreq.name,dexreq.func);
if ( (coin= iguana_coinfind(dexreq.name)) != 0 )
{
printf("dex_response.%s (%c)\n",dexreq.name,dexreq.func);
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' )
{
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\"}"));
@ -164,18 +187,29 @@ char *dex_reqsend(struct supernet_info *myinfo,char *handler,uint8_t *data,int32
dexp->version1 = (DEX_VERSION >> 8) & 0xff;
memcpy(dexp->packet,data,datalen);
dexp->crc32 = calc_crc32(0,data,datalen);
sentbytes = nn_send(myinfo->reqsock,dexp,size,0);
for (i=0; i<100; i++)
{
struct nn_pollfd pfd;
pfd.fd = myinfo->reqsock;
pfd.events = NN_POLLOUT;
if ( nn_poll(&pfd,1,100) > 0 )
{
sentbytes = nn_send(myinfo->reqsock,dexp,size,0);
//printf(" sent.%d:%d datalen.%d\n",sentbytes,size,datalen);
break;
}
usleep(1000);
}
//for (i=0; i<datalen; i++)
// printf("%02x",((uint8_t *)data)[i]);
//printf(" sent.%d:%d datalen.%d\n",sentbytes,size,datalen);
if ( (recvbytes= nn_recv(myinfo->reqsock,&retptr,NN_MSG,0)) >= 0 )
{
//printf("req returned.[%d]\n",recvbytes);
portable_mutex_lock(&myinfo->dexmutex);
if ( strcmp(handler,"DEX") == 0 )
{
ipbits = *retptr;
expand_ipbits(ipaddr,ipbits);
//printf("req returned.[%d] %08x %s\n",recvbytes,*retptr,ipaddr);
n = myinfo->numdexipbits;
for (i=0; i<n; i++)
if ( ipbits == myinfo->dexipbits[i] )
@ -192,14 +226,14 @@ char *dex_reqsend(struct supernet_info *myinfo,char *handler,uint8_t *data,int32
printf("%d: subscribe connect (%s)\n",myinfo->numdexipbits,str);
}
}
nn_connect(myinfo->reqsock,nanomsg_tcpname(0,str,ipaddr,REP_SOCK));
//nn_connect(myinfo->reqsock,nanomsg_tcpname(0,str,ipaddr,REP_SOCK));
printf("%d: req connect (%s)\n",myinfo->numdexipbits,str);
}
}
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);
@ -215,17 +249,59 @@ 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)
{
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));
}
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;
@ -1081,6 +1157,7 @@ int32_t dpow_nanomsg_update(struct supernet_info *myinfo)
if ( (size= nn_recv(myinfo->repsock,&dexp,NN_MSG,0)) >= 0 )
{
num++;
//printf("REP got %d\n",size);
if ( (retstr= dex_response(myinfo,dexp)) != 0 )
{
nn_send(myinfo->repsock,retstr,(int32_t)strlen(retstr)+1,0);

31
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;
@ -254,14 +279,12 @@ char *dpow_decoderawtransaction(struct supernet_info *myinfo,struct iguana_info
cJSON *dpow_gettransaction(struct supernet_info *myinfo,struct iguana_info *coin,bits256 txid)
{
char buf[128],str[65],*retstr=0,*rawtx=0; cJSON *json = 0;
char buf[128],str[65],*retstr=0; cJSON *json = 0;
if ( coin->FULLNODE < 0 )
{
sprintf(buf,"[\"%s\", 1]",bits256_str(str,txid));
if ( (rawtx= bitcoind_passthru(coin->symbol,coin->chain->serverport,coin->chain->userpass,"getrawtransaction",buf)) != 0 )
if ( (retstr= bitcoind_passthru(coin->symbol,coin->chain->serverport,coin->chain->userpass,"getrawtransaction",buf)) != 0 )
{
retstr = dpow_decoderawtransaction(myinfo,coin,rawtx);
free(rawtx);
}
usleep(10000);
}

28
iguana/iguana_notary.c

@ -502,6 +502,34 @@ TWOINTS_AND_ARRAY(dpow,ratify,minsigs,timestamp,ratified)
}
return(clonestr("{\"result\":\"started ratification\"}"));
}
HASH_AND_STRING(dex,gettransaction,txid,symbol)
{
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/dexgetT

@ -0,0 +1,2 @@
#!/bin/bash
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"gettransaction\",\"txid\":\"aa82ebd1c5bd2a9e19214cbc959df1745378676fddfd6f4903930ac16485c7ae\",\"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\"}"

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

5
includes/iguana_apideclares.h

@ -21,6 +21,11 @@ ZERO_ARGS(dpow,cancelratify);
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