From a7a5997f8fbc6d71eb3bceaafebd0f801ad63533 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 31 Oct 2016 12:35:28 -0300 Subject: [PATCH] test --- iguana/dpow/dpow_fsm.c | 33 +++++++++++++++++++++++---------- iguana/dpow/dpow_network.c | 3 +++ iguana/dpow/dpow_rpc.c | 38 ++++++++++++++++++++++++++++++++++++++ iguana/iguana_notary.c | 31 ++++++++++++++++++++----------- iguana/notaries.h | 2 +- 5 files changed, 85 insertions(+), 22 deletions(-) diff --git a/iguana/dpow/dpow_fsm.c b/iguana/dpow/dpow_fsm.c index ab8196d4d..687c8a9ac 100755 --- a/iguana/dpow/dpow_fsm.c +++ b/iguana/dpow/dpow_fsm.c @@ -383,17 +383,22 @@ void dpow_statemachinestart(void *ptr) { void **ptrs = ptr; struct supernet_info *myinfo; struct dpow_info *dp; struct dpow_checkpoint checkpoint; - int32_t i,n,numratified,myind = -1; cJSON *ratified,*item; struct iguana_info *src,*dest; char *jsonstr,*handle,*hexstr,str[65],str2[65],srcaddr[64],destaddr[64]; bits256 zero,srchash; struct dpow_block *bp; struct dpow_entry *ep = 0; uint32_t duration,minsigs,starttime; + int32_t i,numratified,kmdheight,myind = -1; uint8_t pubkeys[64][33]; cJSON *ratified,*item; struct iguana_info *src,*dest; char *jsonstr,*handle,*hexstr,str[65],str2[65],srcaddr[64],destaddr[64]; bits256 zero,srchash; struct dpow_block *bp; struct dpow_entry *ep = 0; uint32_t duration,minsigs,starttime; memset(&zero,0,sizeof(zero)); myinfo = ptrs[0]; dp = ptrs[1]; minsigs = (uint32_t)(long)ptrs[2]; duration = (uint32_t)(long)ptrs[3]; jsonstr = ptrs[4]; + kmdheight = -1; memcpy(&checkpoint,&ptrs[5],sizeof(checkpoint)); printf("statemachinestart %s->%s %s ht.%d minsigs.%d duration.%d\n",dp->symbol,dp->dest,bits256_str(str,checkpoint.blockhash.hash),checkpoint.blockhash.height,minsigs,duration); src = iguana_coinfind(dp->symbol); dest = iguana_coinfind(dp->dest); + if ( strcmp(src->symbol,"KMD") == 0 ) + kmdheight = checkpoint.blockhash.height; + else if ( strcmp(dest->symbol,"KMD") == 0 ) + kmdheight = dest->longestchain; if ( (bp= dp->blocks[checkpoint.blockhash.height]) == 0 ) { bp = calloc(1,sizeof(*bp)); @@ -445,20 +450,28 @@ void dpow_statemachinestart(void *ptr) dp->blocks[checkpoint.blockhash.height - 1000] = 0; } } - n = (int32_t)(sizeof(Notaries)/sizeof(*Notaries)); - bp->numnotaries = n; - for (i=0; i= 0 ) { - decode_hex(bp->notaries[i].pubkey,33,Notaries[i][1]); - if ( memcmp(bp->notaries[i].pubkey,dp->minerkey33,33) == 0 ) + bp->numnotaries = komodo_notaries(pubkeys,kmdheight); + for (i=0; inumnotaries; i++) { - myind = i; - ep = &bp->notaries[myind]; + memcpy(bp->notaries[i].pubkey,pubkeys[i],33); + if ( memcmp(bp->notaries[i].pubkey,dp->minerkey33,33) == 0 ) + { + myind = i; + ep = &bp->notaries[myind]; + } + } + if ( myind < 0 || ep == 0 ) + { + printf("statemachinestart this node %s %s is not official notary\n",srcaddr,destaddr); + free(ptr); + return; } } - if ( myind < 0 || ep == 0 ) + else { - printf("statemachinestart this node %s %s is not official notary\n",srcaddr,destaddr); + printf("statemachinestart no kmdheight.%d\n",kmdheight); free(ptr); return; } diff --git a/iguana/dpow/dpow_network.c b/iguana/dpow/dpow_network.c index 9d2d851d9..4c16b2891 100755 --- a/iguana/dpow/dpow_network.c +++ b/iguana/dpow/dpow_network.c @@ -390,6 +390,9 @@ void komodo_assetcoins() free_json(json); coin->FULLNODE = -1; coin->chain->rpcport = port + 1; + coin->chain->pubtype = 60; + coin->chain->p2shtype = 85; + coin->chain->wiftype = 188; sprintf(confstr,"%s.conf",CURRENCIES[i]); sprintf(path,"%s/.komodo/%s",userhome,CURRENCIES[i]); extract_userpass(coin->chain->serverport,coin->chain->userpass,CURRENCIES[i],coin->chain->userhome,path,confstr); diff --git a/iguana/dpow/dpow_rpc.c b/iguana/dpow/dpow_rpc.c index 86495512c..79b0196be 100755 --- a/iguana/dpow/dpow_rpc.c +++ b/iguana/dpow/dpow_rpc.c @@ -13,6 +13,42 @@ * * ******************************************************************************/ +int32_t komodo_notaries(uint8_t pubkeys[64][33],int32_t kmdheight) +{ + int32_t i,num=-1; struct iguana_info *coin; char params[256],*retstr,*pubkeystr; cJSON *retjson,*item,*result,*array; + if ( (coin= iguana_coinfind("KMD")) != 0 ) + { + if ( coin->FULLNODE < 0 ) + { + sprintf(params,"[%d]",kmdheight); + if ( (retstr= bitcoind_passthru(coin->symbol,coin->chain->serverport,coin->chain->userpass,"notaries",params)) != 0 ) + { + if ( (retjson= cJSON_Parse(retstr)) != 0 ) + { + printf("%s\n",retstr); + if ( (result= jobj(retjson,"result")) != 0 && (array= jarray(&num,result,"notaries")) != 0 ) + { + if ( num > 64 ) + { + printf("warning: numnotaries.%d? > 64?\n",num); + num = 64; + } + for (i=0; i coin->longestchain ) + coin->longestchain = height; if ( (array= jarray(&n,json,"tx")) != 0 ) { for (i=0; ilongestchain; + else kmdheight = 0; + numnotaries = komodo_notaries(pubkeys,kmdheight); + for (i=0; ilongestchain; + else kmdheight = 0; + numnotaries = komodo_notaries(pubkeys,kmdheight); if ( maskhex == 0 || maskhex[0] == 0 ) { mask = myinfo->DPOWS[0].lastrecvmask; - for (i=0; i<64; i++) + for (i=0; i