From 68c14b85fb696fdf82e21b677165350dd784640f Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 18 Oct 2017 15:13:15 +0300 Subject: [PATCH] Test --- iguana/dPoW.h | 1 + iguana/iguana_notary.c | 110 ++++++++++++++++++++++++++++++++++------- 2 files changed, 93 insertions(+), 18 deletions(-) diff --git a/iguana/dPoW.h b/iguana/dPoW.h index f2bd64821..b95c550f7 100755 --- a/iguana/dPoW.h +++ b/iguana/dPoW.h @@ -20,6 +20,7 @@ #define DPOW_CHECKPOINTFREQ 10 #define DPOW_MINSIGS 13 +#define DPOW_MIN_ASSETCHAIN_SIGS 11 //#define DPOW_M(bp) ((bp)->minsigs) // (((bp)->numnotaries >> 1) + 1) #define DPOW_MODIND(bp,offset) (((((bp)->height / DPOW_CHECKPOINTFREQ) % (bp)->numnotaries) + (offset)) % (bp)->numnotaries) #define DPOW_VERSION 0x0781 diff --git a/iguana/iguana_notary.c b/iguana/iguana_notary.c index 2bd00f340..5e61662f6 100755 --- a/iguana/iguana_notary.c +++ b/iguana/iguana_notary.c @@ -58,6 +58,77 @@ void dpow_checkpointset(struct supernet_info *myinfo,struct dpow_checkpoint *che checkpoint->blockhash.height = height; } +int32_t dpow_txhasnotarization(struct supernet_info *myinfo,struct iguana_info *coin,bits256 txid) +{ + cJSON *txobj,*vins,*vin,*vouts,*vout,*spentobj,*sobj; char *hexstr; uint8_t script[35]; bits256 spenttxid; int32_t i,j,numnotaries,len,spentvout,numvins,numvouts,hasnotarization = 0; + if ( (txobj= dpow_gettransaction(myinfo,coin,txid)) != 0 ) + { + if ( (vins= jarray(&numvins,txobj,"vin")) != 0 ) + { + if ( numvins >= DPOW_MIN_ASSETCHAIN_SIGS ) + { + numnotaries = 0; + for (i=0; i>= 1; + decode_hex(script,len,hexstr); + if ( script[0] == 33 && script[34] == 0xac ) + { + for (j=0; j 0 ) + { + if ( numnotaries >= DPOW_MIN_ASSETCHAIN_SIGS ) + hasnotarization = 1; + printf("numnotaries.%d hasnotarization.%d\n",numnotaries,hasnotarization); + } + } + } + free_json(txobj); + } + return(hasnotarization); +} + +int32_t dpow_hasnotarization(struct supernet_info *myinfo,struct iguana_info *coin,cJSON *blockjson) +{ + int32_t i,n,hasnotarization = 0; bits256 txid; cJSON *txarray; + if ( (txarray= jarray(&n,blockjson,"tx")) != 0 ) + { + for (i=0; isrcfifo,dp->last); if ( strcmp(dp->dest,"KMD") == 0 ) { - if ( dp->SRCREALTIME == 0 ) - return; + //if ( dp->SRCREALTIME == 0 ) + // return; if ( (coin= iguana_coinfind(dp->symbol)) != 0 ) { hash = dpow_getbestblockhash(myinfo,coin); @@ -85,22 +156,25 @@ void dpow_srcupdate(struct supernet_info *myinfo,struct dpow_info *dp,int32_t he { if ( (blockjson= dpow_getblock(myinfo,coin,hash)) != 0 ) { - height = jint(blockjson,"height"); - blocktime = juint(blockjson,"time"); - if ( height > 0 && blocktime > 0 ) - dpow_checkpointset(myinfo,&dp->last,height,hash,timestamp,blocktime); - free_json(blockjson); - if ( bits256_cmp(dp->activehash,checkpoint.blockhash.hash) == 0 ) + if ( dpow_hasnotarization(myinfo,coin,blockjson) <= 0 ) { - printf("activehash.(%s) is current checkpoint, skip\n",bits256_str(str,dp->activehash)); - return; - } - if ( bits256_nonz(dp->lastnotarized) != 0 && bits256_cmp(dp->lastnotarized,checkpoint.blockhash.hash) == 0 ) - { - printf("lastnotarized.(%s) is current checkpoint, skip\n",bits256_str(str,dp->lastnotarized)); - return; - } - printf("checkpoint.(%s) is not active and not lastnotarized\n",bits256_str(str,checkpoint.blockhash.hash)); + height = jint(blockjson,"height"); + blocktime = juint(blockjson,"time"); + if ( height > 0 && blocktime > 0 ) + dpow_checkpointset(myinfo,&dp->last,height,hash,timestamp,blocktime); + free_json(blockjson); + if ( bits256_cmp(dp->activehash,checkpoint.blockhash.hash) == 0 ) + { + printf("activehash.(%s) is current checkpoint, skip\n",bits256_str(str,dp->activehash)); + return; + } + if ( bits256_nonz(dp->lastnotarized) != 0 && bits256_cmp(dp->lastnotarized,checkpoint.blockhash.hash) == 0 ) + { + printf("lastnotarized.(%s) is current checkpoint, skip\n",bits256_str(str,dp->lastnotarized)); + return; + } + printf("checkpoint.(%s) is not active and not lastnotarized\n",bits256_str(str,checkpoint.blockhash.hash)); + } else return; } else return; } else return; } else return;