From d90f4224eea5a1dcc9ed75873028c90726ddbfd8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 27 Dec 2016 13:29:18 +0200 Subject: [PATCH] test --- iguana/dPoW.h | 2 ++ iguana/dpow/dpow_network.c | 24 +++++++++++++++++++++++- iguana/dpow/dpow_rpc.c | 15 +++------------ iguana/iguana_notary.c | 27 ++++++++++++++++++++++++--- includes/iguana_apideclares.h | 1 + 5 files changed, 53 insertions(+), 16 deletions(-) diff --git a/iguana/dPoW.h b/iguana/dPoW.h index 1e9485558..5cb428525 100755 --- a/iguana/dPoW.h +++ b/iguana/dPoW.h @@ -155,6 +155,7 @@ bits256 dpow_getbestblockhash(struct supernet_info *myinfo,struct iguana_info *c 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); char *_dex_getinfo(struct supernet_info *myinfo,char *symbol); char *_dex_getrawtransaction(struct supernet_info *myinfo,char *symbol,bits256 txid); @@ -164,5 +165,6 @@ 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); #endif diff --git a/iguana/dpow/dpow_network.c b/iguana/dpow/dpow_network.c index 6c79023f3..5a1a24a2b 100755 --- a/iguana/dpow/dpow_network.c +++ b/iguana/dpow/dpow_network.c @@ -256,9 +256,15 @@ char *dex_response(int32_t *broadcastflagp,struct supernet_info *myinfo,struct d } else if ( dexreq.func == 'A' ) { - printf("address.(%s) datalen.%d strlen.%ld\n",(char *)&dexp->packet[datalen],datalen,strlen((char *)&dexp->packet[datalen])); retstr = dpow_importaddress(myinfo,coin,(char *)&dexp->packet[datalen]); *broadcastflagp = 1; + printf("address.(%s) datalen.%d strlen.%ld ->(%s)\n",(char *)&dexp->packet[datalen],datalen,strlen((char *)&dexp->packet[datalen]),retstr); + 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 ) @@ -366,6 +372,22 @@ char *_dex_importaddress(struct supernet_info *myinfo,char *symbol,char *address return(retstr); } +char *_dex_validateaddress(struct supernet_info *myinfo,char *symbol,char *address) +{ + struct dex_request dexreq; uint8_t *packet; int32_t datalen; char *retstr; + packet = calloc(1,sizeof(dexreq)+strlen(address)+1); + memset(&dexreq,0,sizeof(dexreq)); + safecopy(dexreq.name,symbol,sizeof(dexreq.name)); + dexreq.func = 'V'; + datalen = dex_rwrequest(1,packet,&dexreq); + strcpy((char *)&packet[datalen],address); + printf("address.(%s) datalen.%d strlen.%ld\n",(char *)&packet[datalen],datalen,strlen(address)); + datalen += strlen(address) + 1; + retstr = dex_reqsend(myinfo,"request",packet,datalen); + free(packet); + return(retstr); +} + int32_t dex_crc32find(struct supernet_info *myinfo,uint32_t crc32) { int32_t i,firstz = -1; diff --git a/iguana/dpow/dpow_rpc.c b/iguana/dpow/dpow_rpc.c index f2638c758..255571671 100755 --- a/iguana/dpow/dpow_rpc.c +++ b/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) diff --git a/iguana/iguana_notary.c b/iguana/iguana_notary.c index aa43a3f38..3d873ca2a 100755 --- a/iguana/iguana_notary.c +++ b/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,src,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); @@ -542,6 +558,11 @@ TWO_STRINGS(dex,importaddress,symbol,address) { return(_dex_importaddress(myinfo,symbol,address)); } + +TWO_STRINGS(dex,validateaddress,symbol,address) +{ + return(_dex_validateaddress(myinfo,symbol,address)); +} #include "../includes/iguana_apiundefs.h" diff --git a/includes/iguana_apideclares.h b/includes/iguana_apideclares.h index c46bc2f3f..2cd303632 100755 --- a/includes/iguana_apideclares.h +++ b/includes/iguana_apideclares.h @@ -29,6 +29,7 @@ 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(zcash,passthru,function,hex); TWO_STRINGS(komodo,passthru,function,hex);