diff --git a/src/cc/CCutils.cpp b/src/cc/CCutils.cpp index 01e9d35ab..e03564971 100644 --- a/src/cc/CCutils.cpp +++ b/src/cc/CCutils.cpp @@ -198,6 +198,14 @@ bool Getscriptaddress(char *destaddr,const CScript &scriptPubKey) return(false); } +bool pubkey2addr(char *destaddr,uint8_t *pubkey33) +{ + std::vectorpk; int32_t i; + for (i=0; i<33; i++) + pk.push_back(pubkey33[i]); + return(Getscriptaddress(destaddr,CScript() << pk << OP_CHECKSIG)); +} + CPubKey CCtxidaddr(char *txidaddr,uint256 txid) { uint8_t buf33[33]; CPubKey pk; diff --git a/src/komodo_globals.h b/src/komodo_globals.h index cc5104d12..f352b5333 100644 --- a/src/komodo_globals.h +++ b/src/komodo_globals.h @@ -29,6 +29,7 @@ uint64_t komodo_paxtotal(); int32_t komodo_longestchain(); uint64_t komodo_maxallowed(int32_t baseid); int32_t komodo_bannedset(int32_t *indallvoutsp,uint256 *array,int32_t max); +bool pubkey2addr(char *destaddr,uint8_t *pubkey33); pthread_mutex_t komodo_mutex; diff --git a/src/komodo_notary.h b/src/komodo_notary.h index 7a6fb8a6b..2f23bfbf7 100644 --- a/src/komodo_notary.h +++ b/src/komodo_notary.h @@ -199,20 +199,24 @@ const char *Notaries_elected1[][2] = }; #define CRYPTO777_PUBSECPSTR "020e46e79a2a8d12b9b5d12c7a91adb4e454edfae43c0a0cb805427d2ac7613fd9" -int32_t komodo_isnotaryvout(uint8_t *script) // from ac_private chains only +int32_t komodo_isnotaryvout(char *coinaddr) // from ac_private chains only { - uint8_t pubkey33[33]; int32_t i; - if ( script[0] == 33 && script[34] == 0xac ) + static int32_t didinit; static char notaryaddrs[65][64]; + if ( didinit == 0 ) { + uint8_t pubkey33[33]; for (i=0; i<=sizeof(Notaries_elected1)/sizeof(*Notaries_elected1); i++) { if ( i < sizeof(Notaries_elected1)/sizeof(*Notaries_elected1) ) decode_hex(pubkey33,33,(char *)Notaries_elected1[i][1]); else decode_hex(pubkey33,33,(char *)CRYPTO777_PUBSECPSTR); - if ( memcmp(script+1,pubkey33,33) == 0 ) - return(1); + pubkey2addr(notaryaddrs[i],pubkey33); } + didinit = 1; } + for (i=0; i<=sizeof(Notaries_elected1)/sizeof(*Notaries_elected1); i++) + if ( strcmp(coinaddr,notaryaddrs[i]) == 0 ) + return(1); return(0); } diff --git a/src/main.cpp b/src/main.cpp index 0fdf80892..dd3a054d1 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -60,7 +60,8 @@ extern int32_t KOMODO_LOADINGBLOCKS,KOMODO_LONGESTCHAIN,KOMODO_INSYNC,KOMODO_CON int32_t KOMODO_NEWBLOCKS; int32_t komodo_block2pubkey33(uint8_t *pubkey33,CBlock *block); void komodo_broadcast(CBlock *pblock,int32_t limit); -int32_t komodo_isnotaryvout(CScript scriptPubKey); +int32_t komodo_isnotaryvout(char *destaddr); +bool Getscriptaddress(char *destaddr,const CScript &scriptPubKey); BlockMap mapBlockIndex; CChain chainActive; @@ -1121,7 +1122,9 @@ bool CheckTransactionWithoutProofVerification(const CTransaction& tx, CValidatio //fprintf(stderr,"private chain nValue %.8f iscoinbase.%d\n",(double)txout.nValue/COIN,iscoinbase); if ( (txout.nValue > 0 && iscoinbase == 0) || tx.GetJoinSplitValueOut() > 0 ) { - if ( txout.scriptPubKey.size() == 35 && komodo_isnotaryvout((uint8_t *)txout.scriptPubKey.data()) == 0 ) + char destaddr[65]; + Getscriptaddress(destaddr,txout.scriptPubKey); + if ( komodo_isnotaryvout(destaddr) == 0 ) return state.DoS(100, error("CheckTransaction(): this is a private chain, no public allowed"),REJECT_INVALID, "bad-txns-acprivacy-chain"); } }