Browse Source

Merge pull request #165 from jl777/dev

Dev
win-cross
jl777 8 years ago
committed by GitHub
parent
commit
b241b03f9c
  1. 3
      crypto777/bitcoind_RPC.c
  2. 16
      iguana/dPoW.h
  3. 287
      iguana/dpow/dpow_network.c
  4. 98
      iguana/dpow/dpow_rpc.c
  5. 16
      iguana/iguana777.c
  6. 4
      iguana/iguana_json.c
  7. 54
      iguana/iguana_notary.c
  8. 2
      iguana/tests/dexalladdresses
  9. 2
      iguana/tests/dexgetO
  10. 2
      iguana/tests/deximportaddress
  11. 2
      iguana/tests/dexlisttransactions
  12. 2
      iguana/tests/dexlistunspent
  13. 2
      iguana/tests/dexsendrawtransaction
  14. 2
      iguana/tests/dexvalidate
  15. 7
      includes/iguana_apideclares.h
  16. 2
      includes/iguana_apidefs.h
  17. 1
      includes/iguana_apiundefs.h

3
crypto777/bitcoind_RPC.c

@ -91,7 +91,10 @@ char *post_process_bitcoind_RPC(char *debugstr,char *command,char *rpcstr,char *
{
if ( strcmp(command,"signrawtransaction") != 0 )
printf("<<<<<<<<<<< bitcoind_RPC: %s post_process_bitcoind_RPC (%s) error.%s\n",debugstr,command,rpcstr);
retstr = rpcstr;
rpcstr = 0;
}
if ( rpcstr != 0 )
free(rpcstr);
} else retstr = rpcstr;
free_json(json);

16
iguana/dPoW.h

@ -143,8 +143,6 @@ int32_t dpow_paxpending(uint8_t *hex,uint32_t *paxwdcrcp);
void dex_updateclient(struct supernet_info *myinfo);
char *dex_reqsend(struct supernet_info *myinfo,char *handler,uint8_t *data,int32_t datalen);
char *basilisk_respond_addmessage(struct supernet_info *myinfo,uint8_t *key,int32_t keylen,uint8_t *data,int32_t datalen,int32_t sendping,uint32_t duration);
char *dpow_sendrawtransaction(struct supernet_info *myinfo,struct iguana_info *coin,char *signedtx);
cJSON *dpow_gettxout(struct supernet_info *myinfo,struct iguana_info *coin,bits256 txid,int32_t vout);
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);
@ -154,11 +152,25 @@ cJSON *dpow_gettransaction(struct supernet_info *myinfo,struct iguana_info *coin
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 *dpow_sendrawtransaction(struct supernet_info *myinfo,struct iguana_info *coin,char *signedtx);
cJSON *dpow_gettxout(struct supernet_info *myinfo,struct iguana_info *coin,bits256 txid,int32_t vout);
char *dpow_importaddress(struct supernet_info *myinfo,struct iguana_info *coin,char *address);
char *dpow_validateaddress(struct supernet_info *myinfo,struct iguana_info *coin,char *address);
cJSON *dpow_listunspent(struct supernet_info *myinfo,struct iguana_info *coin,char *coinaddr);
cJSON *dpow_listtransactions(struct supernet_info *myinfo,struct iguana_info *coin,char *coinaddr,int32_t count,int32_t skip);
char *dpow_alladdresses(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);
char *_dex_sendrawtransaction(struct supernet_info *myinfo,char *symbol,char *signedtx);
char *_dex_gettxout(struct supernet_info *myinfo,char *symbol,bits256 txid,int32_t vout);
char *_dex_importaddress(struct supernet_info *myinfo,char *symbol,char *address);
char *_dex_validateaddress(struct supernet_info *myinfo,char *symbol,char *address);
char *_dex_listunspent(struct supernet_info *myinfo,char *symbol,char *address);
char *_dex_listtransactions(struct supernet_info *myinfo,char *symbol,char *coinaddr,int32_t count,int32_t skip);
char *_dex_alladdresses(struct supernet_info *myinfo,char *symbol);
#endif

287
iguana/dpow/dpow_network.c

@ -68,69 +68,6 @@ void dex_packet(struct supernet_info *myinfo,struct dex_nanomsghdr *dexp,int32_t
}
}
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->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);
serialized[len++] = dexreq->func;
}
else
{
memcpy(dexreq->name,&serialized[len],sizeof(dexreq->name)), len += sizeof(dexreq->name);
dexreq->func = serialized[len++];
}
return(len);
}
char *dex_response(struct supernet_info *myinfo,struct dex_nanomsghdr *dexp)
{
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 )
{
if ( dexreq.func == 'T' )
{
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\"}"));
}
return(retstr);
}
char *dex_reqsend(struct supernet_info *myinfo,char *handler,uint8_t *data,int32_t datalen)
{
struct dex_nanomsghdr *dexp; char ipaddr[64],str[128]; int32_t timeout,i,n,size,recvbytes,sentbytes = 0,reqsock,subsock; uint32_t *retptr,ipbits; char *retstr = 0;
@ -249,57 +186,240 @@ char *dex_reqsend(struct supernet_info *myinfo,char *handler,uint8_t *data,int32
return(retstr);
}
struct dex_request { bits256 hash; int32_t intarg; uint16_t shortarg; 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->hash),dexreq->hash.bytes);
len += iguana_rwnum(rwflag,&serialized[len],sizeof(dexreq->intarg),&dexreq->intarg);
len += iguana_rwnum(rwflag,&serialized[len],sizeof(dexreq->shortarg),&dexreq->shortarg);
if ( rwflag != 0 )
{
memcpy(&serialized[len],dexreq->name,sizeof(dexreq->name)), len += sizeof(dexreq->name);
serialized[len++] = dexreq->func;
}
else
{
memcpy(dexreq->name,&serialized[len],sizeof(dexreq->name)), len += sizeof(dexreq->name);
dexreq->func = serialized[len++];
}
return(len);
}
char *dex_response(int32_t *broadcastflagp,struct supernet_info *myinfo,struct dex_nanomsghdr *dexp)
{
char buf[65],*retstr = 0; int32_t datalen; bits256 hash2; cJSON *retjson; struct iguana_info *coin; struct dex_request dexreq;
*broadcastflagp = 0;
if ( strcmp(dexp->handler,"request") == 0 )
{
datalen = dex_rwrequest(0,dexp->packet,&dexreq);
//printf("dex_response.%s (%c)\n",dexreq.name,dexreq.func);
if ( (coin= iguana_coinfind(dexreq.name)) != 0 )
{
if ( dexreq.func == 'T' )
{
if ( (retjson= dpow_gettransaction(myinfo,coin,dexreq.hash)) != 0 )
retstr = jprint(retjson,1);
}
else if ( dexreq.func == 'O' )
{
if ( (retjson= dpow_gettxout(myinfo,coin,dexreq.hash,dexreq.shortarg)) != 0 )
retstr = jprint(retjson,1);
}
else if ( dexreq.func == 'H' )
{
hash2 = dpow_getblockhash(myinfo,coin,dexreq.intarg);
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 == 'U' )
{
if ( (retjson= dpow_listunspent(myinfo,coin,(char *)&dexp->packet[datalen])) != 0 )
retstr = jprint(retjson,1);
}
else if ( dexreq.func == 'P' )
{
hash2 = dpow_getbestblockhash(myinfo,coin);
bits256_str(buf,hash2);
retstr = clonestr(buf);
}
else if ( dexreq.func == 'S' )
{
retstr = dpow_sendrawtransaction(myinfo,coin,(char *)&dexp->packet[datalen]);
}
else if ( dexreq.func == '*' )
{
retstr = dpow_alladdresses(myinfo,coin);
}
else if ( dexreq.func == 'L' )
{
//printf("call list.(%s %d %d)\n",(char *)&dexp->packet[datalen],dexreq.shortarg,dexreq.intarg);
if ( (retjson= dpow_listtransactions(myinfo,coin,(char *)&dexp->packet[datalen],dexreq.shortarg,dexreq.intarg)) != 0 )
retstr = jprint(retjson,1);
}
else if ( dexreq.func == 'A' )
{
retstr = dpow_importaddress(myinfo,coin,(char *)&dexp->packet[datalen]);
*broadcastflagp = 1;
if ( retstr == 0 )
retstr = dpow_validateaddress(myinfo,coin,(char *)&dexp->packet[datalen]);
}
else if ( dexreq.func == 'V' )
{
retstr = dpow_validateaddress(myinfo,coin,(char *)&dexp->packet[datalen]);
}
}
if ( retstr == 0 )
return(clonestr("{\"error\":\"null return\"}"));
}
return(retstr);
}
char *_dex_sendrequest(struct supernet_info *myinfo,struct dex_request *dexreq)
{
uint8_t packet[sizeof(*dexreq)]; int32_t datalen;
datalen = dex_rwrequest(1,packet,dexreq);
return(dex_reqsend(myinfo,"request",packet,datalen));
}
char *_dex_sendrequeststr(struct supernet_info *myinfo,struct dex_request *dexreq,char *str)
{
uint8_t *packet; int32_t datalen,slen; char *retstr;
slen = (int32_t)strlen(str)+1;
packet = calloc(1,sizeof(*dexreq)+slen);
datalen = dex_rwrequest(1,packet,dexreq);
strcpy((char *)&packet[datalen],str);
datalen += slen;
retstr = dex_reqsend(myinfo,"request",packet,datalen);
free(packet);
return(retstr);
}
char *_dex_getrawtransaction(struct supernet_info *myinfo,char *symbol,bits256 txid)
{
struct dex_request dexreq; uint8_t packet[sizeof(dexreq)]; int32_t datalen;
struct dex_request dexreq;
memset(&dexreq,0,sizeof(dexreq));
safecopy(dexreq.name,symbol,sizeof(dexreq.name));
dexreq.hash = txid;
dexreq.func = 'T';
datalen = dex_rwrequest(1,packet,&dexreq);
return(dex_reqsend(myinfo,"request",packet,datalen));
return(_dex_sendrequest(myinfo,&dexreq));
}
char *_dex_gettxout(struct supernet_info *myinfo,char *symbol,bits256 txid,int32_t vout)
{
struct dex_request dexreq;
char str[65]; printf("gettxout(%s %s %d)\n",symbol,bits256_str(str,txid),vout);
memset(&dexreq,0,sizeof(dexreq));
safecopy(dexreq.name,symbol,sizeof(dexreq.name));
dexreq.hash = txid;
dexreq.shortarg = vout;
dexreq.func = 'O';
return(_dex_sendrequest(myinfo,&dexreq));
}
char *_dex_getinfo(struct supernet_info *myinfo,char *symbol)
{
struct dex_request dexreq; uint8_t packet[sizeof(dexreq)]; int32_t datalen;
struct dex_request dexreq;
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));
return(_dex_sendrequest(myinfo,&dexreq));
}
char *_dex_alladdresses(struct supernet_info *myinfo,char *symbol)
{
struct dex_request dexreq;
memset(&dexreq,0,sizeof(dexreq));
safecopy(dexreq.name,symbol,sizeof(dexreq.name));
dexreq.func = '*';
return(_dex_sendrequest(myinfo,&dexreq));
}
char *_dex_getblock(struct supernet_info *myinfo,char *symbol,bits256 hash2)
{
struct dex_request dexreq; uint8_t packet[sizeof(dexreq)]; int32_t datalen;
struct dex_request dexreq;
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));
return(_dex_sendrequest(myinfo,&dexreq));
}
char *_dex_getblockhash(struct supernet_info *myinfo,char *symbol,int32_t height)
{
struct dex_request dexreq; uint8_t packet[sizeof(dexreq)]; int32_t datalen;
struct dex_request dexreq;
memset(&dexreq,0,sizeof(dexreq));
safecopy(dexreq.name,symbol,sizeof(dexreq.name));
dexreq.height = height;
dexreq.intarg = height;
dexreq.func = 'H';
datalen = dex_rwrequest(1,packet,&dexreq);
return(dex_reqsend(myinfo,"request",packet,datalen));
return(_dex_sendrequest(myinfo,&dexreq));
}
char *_dex_getbestblockhash(struct supernet_info *myinfo,char *symbol)
{
struct dex_request dexreq; uint8_t packet[sizeof(dexreq)]; int32_t datalen;
struct dex_request dexreq;
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));
return(_dex_sendrequest(myinfo,&dexreq));
}
char *_dex_sendrawtransaction(struct supernet_info *myinfo,char *symbol,char *signedtx)
{
struct dex_request dexreq;
memset(&dexreq,0,sizeof(dexreq));
safecopy(dexreq.name,symbol,sizeof(dexreq.name));
dexreq.func = 'S';
return(_dex_sendrequeststr(myinfo,&dexreq,signedtx));
}
char *_dex_importaddress(struct supernet_info *myinfo,char *symbol,char *address)
{
struct dex_request dexreq;
memset(&dexreq,0,sizeof(dexreq));
safecopy(dexreq.name,symbol,sizeof(dexreq.name));
dexreq.func = 'A';
return(_dex_sendrequeststr(myinfo,&dexreq,address));
}
char *_dex_validateaddress(struct supernet_info *myinfo,char *symbol,char *address)
{
struct dex_request dexreq;
memset(&dexreq,0,sizeof(dexreq));
safecopy(dexreq.name,symbol,sizeof(dexreq.name));
dexreq.func = 'V';
return(_dex_sendrequeststr(myinfo,&dexreq,address));
}
char *_dex_listunspent(struct supernet_info *myinfo,char *symbol,char *address)
{
struct dex_request dexreq;
memset(&dexreq,0,sizeof(dexreq));
safecopy(dexreq.name,symbol,sizeof(dexreq.name));
dexreq.func = 'U';
return(_dex_sendrequeststr(myinfo,&dexreq,address));
}
char *_dex_listtransactions(struct supernet_info *myinfo,char *symbol,char *address,int32_t count,int32_t skip)
{
struct dex_request dexreq;
memset(&dexreq,0,sizeof(dexreq));
safecopy(dexreq.name,symbol,sizeof(dexreq.name));
dexreq.intarg = skip;
dexreq.shortarg = count;
dexreq.func = 'L';
return(_dex_sendrequeststr(myinfo,&dexreq,address));
}
int32_t dex_crc32find(struct supernet_info *myinfo,uint32_t crc32)
@ -1072,7 +1192,7 @@ void dpow_ipbitsadd(struct supernet_info *myinfo,struct dpow_info *dp,uint32_t *
int32_t dpow_nanomsg_update(struct supernet_info *myinfo)
{
int32_t i,n=0,num=0,size,firstz = -1; char *retstr; uint32_t crc32,r,m; struct dpow_nanomsghdr *np=0; struct dpow_info *dp; struct dpow_block *bp; struct dex_nanomsghdr *dexp = 0;
int32_t i,n=0,num=0,size,broadcastflag,firstz = -1; char *retstr; uint32_t crc32,r,m; struct dpow_nanomsghdr *np=0; struct dpow_info *dp; struct dpow_block *bp; struct dex_nanomsghdr *dexp = 0;
if ( time(NULL) < myinfo->nanoinit+5 || (myinfo->dpowsock < 0 && myinfo->dexsock < 0 && myinfo->repsock < 0) )
return(-1);
portable_mutex_lock(&myinfo->dpowmutex);
@ -1158,10 +1278,15 @@ int32_t dpow_nanomsg_update(struct supernet_info *myinfo)
{
num++;
//printf("REP got %d\n",size);
if ( (retstr= dex_response(myinfo,dexp)) != 0 )
if ( (retstr= dex_response(&broadcastflag,myinfo,dexp)) != 0 )
{
nn_send(myinfo->repsock,retstr,(int32_t)strlen(retstr)+1,0);
free(retstr);
if ( broadcastflag != 0 )
{
printf("BROADCAST dexp request.[%d]\n",size);
nn_send(myinfo->dexsock,dexp,size,0);
}
}
else
{

98
iguana/dpow/dpow_rpc.c

@ -198,9 +198,9 @@ cJSON *dpow_getblock(struct supernet_info *myinfo,struct iguana_info *coin,bits2
return(json);
}
int32_t dpow_validateaddress(struct supernet_info *myinfo,struct iguana_info *coin,char *address)
char *dpow_validateaddress(struct supernet_info *myinfo,struct iguana_info *coin,char *address)
{
char buf[128],*retstr=0; cJSON *ismine,*json = 0; int32_t retval = -1;
char buf[128],*retstr=0;
if ( coin->FULLNODE < 0 )
{
sprintf(buf,"\"%s\"",address);
@ -215,16 +215,7 @@ int32_t dpow_validateaddress(struct supernet_info *myinfo,struct iguana_info *co
{
return(0);
}
if ( retstr != 0 )
{
json = cJSON_Parse(retstr);
if ( (ismine= jobj(json,"ismine")) != 0 && is_cJSON_True(ismine) != 0 )
retval = 1;
else retval = 0;
free(retstr);
}
return(retval);
return(retstr);
}
cJSON *dpow_gettxout(struct supernet_info *myinfo,struct iguana_info *coin,bits256 txid,int32_t vout)
@ -306,7 +297,7 @@ cJSON *dpow_gettransaction(struct supernet_info *myinfo,struct iguana_info *coin
cJSON *dpow_listunspent(struct supernet_info *myinfo,struct iguana_info *coin,char *coinaddr)
{
char buf[128],*retstr; cJSON *json = 0;
char buf[128],*retstr; cJSON *array,*json = 0;
if ( coin->FULLNODE < 0 )
{
sprintf(buf,"0, 99999999, [\"%s\"]",coinaddr);
@ -319,7 +310,10 @@ cJSON *dpow_listunspent(struct supernet_info *myinfo,struct iguana_info *coin,ch
}
else if ( coin->FULLNODE > 0 || coin->VALIDATENODE > 0 )
{
json = iguana_listunspents(myinfo,coin,0,1,coin->longestchain,"");
array = cJSON_CreateArray();
jaddistr(array,coinaddr);
json = iguana_listunspents(myinfo,coin,array,1,coin->longestchain,"");
free_json(array);
}
else
{
@ -328,6 +322,25 @@ cJSON *dpow_listunspent(struct supernet_info *myinfo,struct iguana_info *coin,ch
return(json);
}
cJSON *dpow_listtransactions(struct supernet_info *myinfo,struct iguana_info *coin,char *coinaddr,int32_t count,int32_t skip)
{
char buf[128],*retstr; cJSON *json = 0;
if ( coin->FULLNODE < 0 )
{
if ( count == 0 )
count = 100;
sprintf(buf,"[\"%s\", %d, %d, true]",coinaddr,count,skip);
if ( (retstr= bitcoind_passthru(coin->symbol,coin->chain->serverport,coin->chain->userpass,"listtransactions",buf)) != 0 )
{
//printf("LIST.(%s)\n",retstr);
json = cJSON_Parse(retstr);
free(retstr);
return(json);
} else printf("%s null retstr from (%s)n",coin->symbol,buf);
}
return(0);
}
char *dpow_signrawtransaction(struct supernet_info *myinfo,struct iguana_info *coin,char *rawtx,cJSON *vins)
{
cJSON *array,*privkeys,*item; char *wifstr,*str,*paramstr,*retstr; uint8_t script[256]; int32_t i,n,len,hashtype; struct vin_info V; struct iguana_waddress *waddr; struct iguana_waccount *wacct;
@ -413,6 +426,63 @@ char *dpow_sendrawtransaction(struct supernet_info *myinfo,struct iguana_info *c
}
}
char *dpow_alladdresses(struct supernet_info *myinfo,struct iguana_info *coin)
{
char *retstr,fname[1024]; long filesize;
sprintf(fname,"%s/alladdresses.%s",GLOBAL_CONFSDIR,coin->symbol), OS_compatible_path(fname);
retstr = OS_filestr(&filesize,fname);
return(retstr);
}
char *dpow_importaddress(struct supernet_info *myinfo,struct iguana_info *coin,char *address)
{
char buf[1024],*retstr,*alladdresses,*outstr,fname[1024]; cJSON *alljson; int32_t i,n; FILE *fp;
if ( coin->FULLNODE < 0 )
{
sprintf(buf,"[\"%s\", \"%s\", false]",address,address);
retstr = bitcoind_passthru(coin->symbol,coin->chain->serverport,coin->chain->userpass,"importaddress",buf);
if ( (alladdresses= dpow_alladdresses(myinfo,coin)) != 0 )
{
if ( (alljson= cJSON_Parse(alladdresses)) != 0 )
{
if ( is_cJSON_Array(alljson) != 0 && (n= cJSON_GetArraySize(alljson)) > 0 )
{
for (i=0; i<n; i++)
if ( strcmp(address,jstri(alljson,i)) == 0 )
break;
if ( i == n )
{
jaddistr(alljson,address);
outstr = jprint(alljson,0);
sprintf(fname,"%s/alladdresses.%s",GLOBAL_CONFSDIR,coin->symbol), OS_compatible_path(fname);
if ( (fp= fopen(fname,"wb")) != 0 )
{
fwrite(outstr,1,strlen(outstr)+1,fp);
fclose(fp);
printf("importaddress.(%s) -> alladdresses.%s\n",address,coin->symbol);
}
free(outstr);
}
}
free_json(alljson);
}
free(alladdresses);
}
else
{
sprintf(buf,"[\"%s\"]",address);
sprintf(fname,"%s/alladdresses.%s",GLOBAL_CONFSDIR,coin->symbol), OS_compatible_path(fname);
if ( (fp= fopen(fname,"wb")) != 0 )
{
fwrite(buf,1,strlen(buf)+1,fp);
fclose(fp);
}
}
return(retstr);
}
else return(0);
}
int32_t dpow_getchaintip(struct supernet_info *myinfo,bits256 *blockhashp,uint32_t *blocktimep,bits256 *txs,uint32_t *numtxp,struct iguana_info *coin)
{
int32_t n,i,height = -1,maxtx = *numtxp; bits256 besthash,oldhash; cJSON *array,*json;

16
iguana/iguana777.c

@ -877,12 +877,26 @@ void iguana_callcoinstart(struct supernet_info *myinfo,struct iguana_info *coin)
void iguana_coinloop(void *arg)
{
struct supernet_info *myinfo; int32_t flag,i,j,n; struct iguana_peer *addr; bits256 zero; uint32_t now; struct iguana_info *coin,**coins = arg;
struct supernet_info *myinfo; int32_t flag,i,j,n; cJSON *alljson; struct iguana_peer *addr; bits256 zero; uint32_t now; char *alladdresses,*retstr; struct iguana_info *coin,**coins = arg;
myinfo = SuperNET_MYINFO(0);
n = (int32_t)(long)coins[0];
coins++;
coin = coins[0];
printf("begin coinloop[%d] %s\n",n,coin->symbol);
if ( myinfo->IAMNOTARY != 0 && (alladdresses= _dex_alladdresses(myinfo,coin->symbol)) != 0 )
{
if ( (alljson= cJSON_Parse(alladdresses)) != 0 )
{
if ( is_cJSON_Array(alljson) != 0 && (n= cJSON_GetArraySize(alljson)) > 0 )
{
for (i=0; i<n; i++)
if ( (retstr= dpow_importaddress(myinfo,coin,jstri(alljson,i))) != 0 )
free(retstr);
}
free_json(alljson);
}
free(alladdresses);
}
memset(zero.bytes,0,sizeof(zero));
while ( 1 )
{

4
iguana/iguana_json.c

@ -128,6 +128,7 @@ cJSON *SuperNET_helpjson()
#define IGUANA_HELP_HH(agent,name,hash,hash2) array = helpjson(IGUANA_ARGS,#agent,#name,helparray2(cJSON_CreateArray(),helpitem(#hash,"hash"),helpitem(#hash2,"hash")))
#define IGUANA_HELP_HA(agent,name,hash,obj) array = helpjson(IGUANA_ARGS,#agent,#name,helparray2(cJSON_CreateArray(),helpitem(#hash,"hash"),helpitem(#obj,"array")))
#define IGUANA_HELP_HS(agent,name,hash,str) array = helpjson(IGUANA_ARGS,#agent,#name,helparray2(cJSON_CreateArray(),helpitem(#hash,"hash"),helpitem(#str,"str")))
#define IGUANA_HELP_HSI(agent,name,hash,str,val) array = helpjson(IGUANA_ARGS,#agent,#name,helparray3(cJSON_CreateArray(),helpitem(#hash,"hash"),helpitem(#str,"str"),helpitem(#val,"int")))
#define IGUANA_HELP_HII(agent,name,hash,val,val2) array = helpjson(IGUANA_ARGS,#agent,#name,helparray3(cJSON_CreateArray(),helpitem(#hash,"hash"),helpitem(#val,"int"),helpitem(#val2,"int")))
#define IGUANA_HELP_HHS(agent,name,hash,hash2,str) array = helpjson(IGUANA_ARGS,#agent,#name,helparray3(cJSON_CreateArray(),helpitem(#hash,"hash"),helpitem(#hash2,"hash"),helpitem(#str,"str")))
#define IGUANA_HELP_HAS(agent,name,hash,obj,str) array = helpjson(IGUANA_ARGS,#agent,#name,helparray3(cJSON_CreateArray(),helpitem(#hash,"hash"),helpitem(#obj,"array"),helpitem(#str,"str")))
@ -152,6 +153,7 @@ cJSON *SuperNET_helpjson()
#define STRING_AND_INT IGUANA_HELP_SI
#define STRING_AND_TWOINTS IGUANA_HELP_SII
#define HASH_AND_STRING IGUANA_HELP_HS
#define HASH_AND_STRING_AND_INT IGUANA_HELP_HSI
#define HASH_AND_INT IGUANA_HELP_HI
#define HASH_AND_TWOINTS IGUANA_HELP_HII
#define DOUBLE_ARG IGUANA_HELP_D
@ -960,6 +962,7 @@ char *SuperNET_parser(struct supernet_info *myinfo,char *agentstr,char *method,c
#define IGUANA_DISPATCH_HH(agent,name,hash,hash2) else if ( strcmp(#agent,agentstr) == 0 && strcmp(method,#name) == 0 ) return(agent ## _ ## name(IGUANA_ARGS,jbits256(json,#hash),jbits256(json,#hash2)))
#define IGUANA_DISPATCH_HA(agent,name,hash,array) else if ( strcmp(#agent,agentstr) == 0 && strcmp(method,#name) == 0 ) return(agent ## _ ## name(IGUANA_ARGS,jbits256(json,#hash),jobj(json,#array)))
#define IGUANA_DISPATCH_HS(agent,name,hash,str) else if ( strcmp(#agent,agentstr) == 0 && strcmp(method,#name) == 0 ) return(agent ## _ ## name(IGUANA_ARGS,jbits256(json,#hash),jstr(json,#str)))
#define IGUANA_DISPATCH_HSI(agent,name,hash,str,val) else if ( strcmp(#agent,agentstr) == 0 && strcmp(method,#name) == 0 ) return(agent ## _ ## name(IGUANA_ARGS,jbits256(json,#hash),jstr(json,#str),jint(json,#val)))
#define IGUANA_DISPATCH_HII(agent,name,hash,val,val2) else if ( strcmp(#agent,agentstr) == 0 && strcmp(method,#name) == 0 ) return(agent ## _ ## name(IGUANA_ARGS,jbits256(json,#hash),juint(json,#val),juint(json,#val2)))
#define IGUANA_DISPATCH_HHS(agent,name,hash,hash2,str) else if ( strcmp(#agent,agentstr) == 0 && strcmp(method,#name) == 0 ) return(agent ## _ ## name(IGUANA_ARGS,jbits256(json,#hash),jbits256(json,#hash2),jstr(json,#str)))
#define IGUANA_DISPATCH_HAS(agent,name,hash,array,str) else if ( strcmp(#agent,agentstr) == 0 && strcmp(method,#name) == 0 ) return(agent ## _ ## name(IGUANA_ARGS,jbits256(json,#hash),jobj(json,#array),jstr(json,#str)))
@ -985,6 +988,7 @@ char *SuperNET_parser(struct supernet_info *myinfo,char *agentstr,char *method,c
#define STRING_AND_TWOINTS IGUANA_DISPATCH_SII
#define HASH_AND_INT IGUANA_DISPATCH_HI
#define HASH_AND_STRING IGUANA_DISPATCH_HS
#define HASH_AND_STRING_AND_INT IGUANA_DISPATCH_HSI
#define HASH_AND_TWOINTS IGUANA_DISPATCH_HII
#define DOUBLE_ARG IGUANA_DISPATCH_D
#define STRING_AND_ARRAY IGUANA_DISPATCH_SA

54
iguana/iguana_notary.c

@ -215,7 +215,7 @@ void dpow_addresses()
TWO_STRINGS(iguana,dpow,symbol,pubkey)
{
char *retstr,srcaddr[64],destaddr[64]; struct iguana_info *src,*dest; int32_t i,srcvalid,destvalid; struct dpow_info *dp = &myinfo->DPOWS[myinfo->numdpows];
char *retstr,srcaddr[64],destaddr[64]; struct iguana_info *src,*dest; cJSON *ismine; int32_t i,srcvalid,destvalid; struct dpow_info *dp = &myinfo->DPOWS[myinfo->numdpows];
if ( myinfo->NOTARY.RELAYID < 0 )
{
if ( (retstr= basilisk_addrelay_info(myinfo,0,(uint32_t)calc_ipbits(myinfo->ipaddr),myinfo->myaddr.persistent)) != 0 )
@ -278,9 +278,25 @@ TWO_STRINGS(iguana,dpow,symbol,pubkey)
safecopy(tmp,pubkey,sizeof(tmp));
decode_hex(dp->minerkey33,33,tmp);
bitcoin_address(srcaddr,src->chain->pubtype,dp->minerkey33,33);
srcvalid = dpow_validateaddress(myinfo,src,srcaddr);
if ( (retstr= dpow_validateaddress(myinfo,src,srcaddr)) != 0 )
{
json = cJSON_Parse(retstr);
if ( (ismine= jobj(json,"ismine")) != 0 && is_cJSON_True(ismine) != 0 )
srcvalid = 1;
else srcvalid = 0;
free(retstr);
retstr = 0;
}
bitcoin_address(destaddr,dest->chain->pubtype,dp->minerkey33,33);
destvalid = dpow_validateaddress(myinfo,dest,destaddr);
if ( (retstr= dpow_validateaddress(myinfo,dest,destaddr)) != 0 )
{
json = cJSON_Parse(retstr);
if ( (ismine= jobj(json,"ismine")) != 0 && is_cJSON_True(ismine) != 0 )
destvalid = 1;
else destvalid = 0;
free(retstr);
retstr = 0;
}
for (i=0; i<33; i++)
printf("%02x",dp->minerkey33[i]);
printf(" DPOW with pubkey.(%s) %s.valid%d %s -> %s %s.valid%d\n",tmp,srcaddr,srcvalid,dp->symbol,dp->dest,destaddr,destvalid);
@ -508,6 +524,11 @@ HASH_AND_STRING(dex,gettransaction,txid,symbol)
return(_dex_getrawtransaction(myinfo,symbol,txid));
}
HASH_AND_STRING_AND_INT(dex,gettxout,txid,symbol,vout)
{
return(_dex_gettxout(myinfo,symbol,txid,vout));
}
STRING_ARG(dex,getinfo,symbol)
{
return(_dex_getinfo(myinfo,symbol));
@ -518,6 +539,11 @@ STRING_ARG(dex,getbestblockhash,symbol)
return(_dex_getbestblockhash(myinfo,symbol));
}
STRING_ARG(dex,alladdresses,symbol)
{
return(_dex_alladdresses(myinfo,symbol));
}
STRING_AND_INT(dex,getblockhash,symbol,height)
{
return(_dex_getblockhash(myinfo,symbol,height));
@ -528,8 +554,30 @@ HASH_AND_STRING(dex,getblock,hash,symbol)
return(_dex_getblock(myinfo,symbol,hash));
}
TWO_STRINGS(dex,sendrawtransaction,symbol,signedtx)
{
return(_dex_sendrawtransaction(myinfo,symbol,signedtx));
}
TWO_STRINGS(dex,importaddress,symbol,address)
{
return(_dex_importaddress(myinfo,symbol,address));
}
TWO_STRINGS(dex,validateaddress,symbol,address)
{
return(_dex_validateaddress(myinfo,symbol,address));
}
TWO_STRINGS(dex,listunspent,symbol,address)
{
return(_dex_listunspent(myinfo,symbol,address));
}
TWO_STRINGS_AND_TWO_DOUBLES(dex,listtransactions,symbol,address,count,skip)
{
return(_dex_listtransactions(myinfo,symbol,address,count,skip));
}
#include "../includes/iguana_apiundefs.h"

2
iguana/tests/dexalladdresses

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

2
iguana/tests/dexgetO

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

2
iguana/tests/deximportaddress

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

2
iguana/tests/dexlisttransactions

@ -0,0 +1,2 @@
#!/bin/bash
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"dex\",\"method\":\"listtransactions\",\"address\":\"15R3C2ZKmak5pCc4duLY2jLtFD3o1jaeNd\",\"count\":100,\"skip\":0,\"symbol\":\"BTC\"}"

2
iguana/tests/dexlistunspent

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

2
iguana/tests/dexsendrawtransaction

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

2
iguana/tests/dexvalidate

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

7
includes/iguana_apideclares.h

@ -23,9 +23,16 @@ 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,alladdresses,symbol);
STRING_ARG(dex,getbestblockhash,symbol);
STRING_AND_INT(dex,getblockhash,symbol,height);
HASH_AND_STRING(dex,getblock,hash,symbol);
TWO_STRINGS(dex,sendrawtransaction,symbol,signedtx);
HASH_AND_STRING_AND_INT(dex,gettxout,txid,symbol,vout);
TWO_STRINGS(dex,importaddress,symbol,address);
TWO_STRINGS(dex,validateaddress,symbol,address);
TWO_STRINGS(dex,listunspent,symbol,address);
TWO_STRINGS_AND_TWO_DOUBLES(dex,listtransactions,symbol,address,count,skip);
TWO_STRINGS(zcash,passthru,function,hex);
TWO_STRINGS(komodo,passthru,function,hex);

2
includes/iguana_apidefs.h

@ -39,6 +39,7 @@
#define IGUANA_CFUNC_HI(agent,name,hash,val) char *agent ## _ ## name(IGUANA_ARGS,bits256 hash,int32_t val)
#define IGUANA_CFUNC_H(agent,name,hash) char *agent ## _ ## name(IGUANA_ARGS,bits256 hash)
#define IGUANA_CFUNC_HS(agent,name,hash,str) char *agent ## _ ## name(IGUANA_ARGS,bits256 hash,char *str)
#define IGUANA_CFUNC_HSI(agent,name,hash,str,val) char *agent ## _ ## name(IGUANA_ARGS,bits256 hash,char *str,int32_t val)
#define IGUANA_CFUNC_HA(agent,name,hash,array) char *agent ## _ ## name(IGUANA_ARGS,bits256 hash,cJSON *array)
#define IGUANA_CFUNC_HH(agent,name,hash,hash2) char *agent ## _ ## name(IGUANA_ARGS,bits256 hash,bits256 hash2)
#define IGUANA_CFUNC_HHS(agent,name,hash,hash2,str) char *agent ## _ ## name(IGUANA_ARGS,bits256 hash,bits256 hash2,char *str)
@ -65,6 +66,7 @@
#define STRING_AND_TWOINTS IGUANA_CFUNC_SII
#define HASH_AND_INT IGUANA_CFUNC_HI
#define HASH_AND_STRING IGUANA_CFUNC_HS
#define HASH_AND_STRING_AND_INT IGUANA_CFUNC_HSI
#define TWOHASHES_AND_STRING IGUANA_CFUNC_HHS
#define HASH_AND_TWOINTS IGUANA_CFUNC_HII
#define DOUBLE_ARG IGUANA_CFUNC_D

1
includes/iguana_apiundefs.h

@ -12,6 +12,7 @@
#undef STRING_AND_INT
#undef STRING_AND_TWOINTS
#undef HASH_AND_STRING
#undef HASH_AND_STRING_AND_INT
#undef HASH_AND_INT
#undef HASH_AND_TWOINTS
#undef DOUBLE_ARG

Loading…
Cancel
Save