Browse Source

test

etomic
jl777 8 years ago
parent
commit
a3fff75727
  1. 34
      basilisk/basilisk_bitcoin.c
  2. 1
      iguana/dPoW.h
  3. 16
      iguana/dpow/dpow_network.c
  4. 25
      iguana/dpow/dpow_rpc.c
  5. 2
      iguana/tests/value

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) 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 ) if ( vals == 0 )
return(clonestr("{\"error\":\"null valsobj\"}")); return(clonestr("{\"error\":\"null valsobj\"}"));
//if ( myinfo->IAMNOTARY != 0 || myinfo->NOTARY.RELAYID >= 0 ) //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 ( 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 ) if ( (txoutjson= cJSON_Parse(retstr)) != 0 )
{ {
printf("TX.(%s)\n",jprint(txoutjson,0)); //printf("TX.(%s)\n",jprint(txoutjson,0));
retjson = cJSON_CreateObject(); retjson = cJSON_CreateObject();
jaddstr(retjson,"result","success"); jaddstr(retjson,"result","success");
jaddnum(retjson,"numconfirms",jint(txoutjson,"confirmations"));
if ( (array= jarray(&n,txoutjson,"vout")) != 0 && vout < n && (txjson= jitem(array,vout)) != 0 ) if ( (array= jarray(&n,txoutjson,"vout")) != 0 && vout < n && (txjson= jitem(array,vout)) != 0 )
{ {
printf("txjson.(%s)\n",jprint(txjson,0)); //printf("txjson.(%s)\n",jprint(txjson,0));
if ( (coinaddr= jstr(txoutjson,"address")) != 0 && (value= j64bits(txjson,"value") * SATOSHIDEN) != 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); jadd64bits(retjson,"satoshis",value);
jaddnum(retjson,"value",dstr(value)); jaddnum(retjson,"value",dstr(value));
//height = dpow_getchaintip(myinfo,&blockhash,&blocktime,0,0,coin); if ( (infostr= dex_getinfo(myinfo,symbol)) != 0 )
//jaddnum(retjson,"height",height); {
jaddnum(retjson,"numconfirms",jint(txjson,"confirmations")); 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); jaddbits256(retjson,"txid",txid);
jaddnum(retjson,"vout",vout); jaddnum(retjson,"vout",vout);
jaddstr(retjson,"coin",coin->symbol); jaddstr(retjson,"coin",symbol);
free(retstr); free(retstr);
free_json(txoutjson); free_json(txoutjson);
return(jprint(retjson,1)); return(jprint(retjson,1));
} }
} }
jaddnum(retjson,"numconfirms",0);
free_json(txoutjson); free_json(txoutjson);
return(jprint(retjson,1)); return(jprint(retjson,1));
} }

1
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); int32_t dpow_nanomsg_update(struct supernet_info *myinfo);
char *dex_getrawtransaction(struct supernet_info *myinfo,char *symbol,bits256 txid); char *dex_getrawtransaction(struct supernet_info *myinfo,char *symbol,bits256 txid);
cJSON *dpow_gettransaction(struct supernet_info *myinfo,struct iguana_info *coin,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 #endif

16
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 ) if ( (retjson= dpow_gettransaction(myinfo,coin,dexreq.txid)) != 0 )
retstr = jprint(retjson,1); retstr = jprint(retjson,1);
} }
else if ( dexreq.func == 'I' )
{
}
} }
if ( retstr == 0 ) if ( retstr == 0 )
return(clonestr("{\"error\":\"null return\"}")); return(clonestr("{\"error\":\"null return\"}"));
@ -199,7 +203,7 @@ char *dex_reqsend(struct supernet_info *myinfo,char *handler,uint8_t *data,int32
else else
{ {
retstr = clonestr((char *)retptr); retstr = clonestr((char *)retptr);
printf("REQ got.%d (%s)\n",recvbytes,retstr); //printf("REQ got.%d (%s)\n",recvbytes,retstr);
} }
nn_freemsg(retptr); nn_freemsg(retptr);
portable_mutex_unlock(&myinfo->dexmutex); 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)); 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 dex_crc32find(struct supernet_info *myinfo,uint32_t crc32)
{ {
int32_t i,firstz = -1; int32_t i,firstz = -1;

25
iguana/dpow/dpow_rpc.c

@ -146,6 +146,31 @@ bits256 dpow_getblockhash(struct supernet_info *myinfo,struct iguana_info *coin,
return(blockhash); 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) cJSON *dpow_getblock(struct supernet_info *myinfo,struct iguana_info *coin,bits256 blockhash)
{ {
char buf[128],str[65],*retstr=0; cJSON *json = 0; char buf[128],str[65],*retstr=0; cJSON *json = 0;

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\"}}"
Loading…
Cancel
Save